Results 1 to 6 of 6

Thread: RTTI-based streaming system

  1. #1

    RTTI-based streaming system

    Lately I've been working on a RTTI streaming system.

    Similar in to the VCL streaming system, it allows for the loading & saving of an object's published properties.

    The code is inspirered by Superpig's "Enginuity" article series on gamedev.net

    This is still in the early stages, and really isnt ready for a public release.

    Features:
    • Allows the streaming of published properties
    • Correctly detects if a property are readable and/or writeable!
    • Delayed biulding of an object's property list till the object is actually touched/used
    • Handles nil object properties properly.
    • Allows the setting of an objects properties or the object itself
    • Creation of 'virtual' properties. Which dont actual map to a real property.
    • Does not require an object inherites from a class, only that it has published properties with typeinfo
    • Supports non-object variables.
    • Does not use the VCL.


    Code:
    type
      TMyObject = class
      protected
        fz : boolean;
        ftest : TMyObject;
      Published
        Property test : TMyObject read ftest write ftest;
        Property z : boolean read fz write fz;
      end; {TMyObject}
    
    SettingsManager.Variable[ 'MyObject.test' ] := 'MyObject';
    SettingsManager.Variable[ 'MyObject.z' ] := 'true';
    SettingsManager.Variable[ 'MyObject.test.z' ] := 'false';
    SettingsManager.Variable[ 'MyObject' ] := '( z = true; test = ( z = false; ) )';
    Limtations:
    • Makes the assumption that any published object properties are managed by the class. And if they are writeable, then they can be assigned with a different object! So dont make the published property writable if it will cause a memory leak if you assign an object to it.
    • Any virtual properties are destroyed when an object refreshes its propery list (ie "MyObject.text := MyObject" will destroy any virtual properties on "MyObject.text") and NOT assign any virtual properties "MyObject" has.
      Working on this issue.
    • Does not allow for array based properties.
    • If an object which is wrapped is destroyed, the wrapping system probable will implode.
    • Cant clear all the wrapper's at once atm (next version will have this)
    • Outputs/reads a flexible, but fixed format. Want to change this.
    • Collections cant be streamed atm. Planing on designing a way. Probable an interface which allows the system to itterate of child objects the parent object owns & create new child objects.
    • Published interfaces?
    • Published event handlers?


    Planned features:
    • Allow name resolution for non-object types ie "MyObject.test.z = MyObject.z"
    • Allow array types to be properly handled
    • Allow array indexing to be handled
    • Some way to detected/informed when underlying object gets destroyed (preferable someway that doesnt require active registration)
    • Allow the streaming system to itterate over collections (will require the collection class to implement somethign to allow for this)
    • Allow resolution of published events from object -> name in settings tree if possible.


    Link.

    Comments?

    :edit2: Updated link to newest version.

  2. #2

    RTTI-based streaming system

    I'll take a look at this tonight, hopefully. I assume that this is going to be used in your engine for a console and/or scripting language? Am I close?

    I realise that you've probably answered this question in your summary, but does it deal nicely with things requiring finalization (esp. dynamic arrays and interfaces?).

    But it certainly sounds impressive! Where do you find the time for this?!
    "All paid jobs absorb and degrade the mind."
    <br />-- Aristotle

  3. #3

    RTTI-based streaming system

    Quote Originally Posted by Alimonster
    I'll take a look at this tonight, hopefully. I assume that this is going to be used in your engine for a console and/or scripting language? Am I close?
    Console & GUI/object streaming code. I've got a proper scripting language (IFPS3) I'm planning on using for my scripting in this engine I'm biulding.

    I realise that you've probably answered this question in your summary, but does it deal nicely with things requiring finalization (esp. dynamic arrays and interfaces?).
    I havent actually gotten around to this one yet, so it just doesnt touch those yet. But since I'm using mostly RTTI, I would guess it shouldnt be too hard.

    The biggest problem is you can destroy the objects which its currently wrapping, and the system implodes.

    If I inlined abunch of stuff into the class hierarchy itself, it solves several issues but creates even more.

    At the moment, the dators should be created, used to manipulate the various structures, then all destroyed. This is due to the inflexibility of the design in handling went an object is destroyed while a wrapper around it exists.

    Maybe I can write a hack, which hooks the BeforeDestruction method of the class & inserts a call to the Dator class that the wrapper object that the wrapper class is about to be destroyed.

    One this that will definiatly require the wrapper class to cooperate is implementing custom streaming. Till now, the class didnt even need to know about the streaming system, which is want I want to keep as much as posible.

    But it certainly sounds impressive! Where do you find the time for this?!


    I started this project about went Superpig's Enginuity Part 3 came out. On & Off for a bit.

    While there is a lot in the zip, I've been working on the framework it uses for almost a year now. It used to use a system similar to the kernel & task system. But I ripped that out & replace it.

    Helps that I had already had experience with RTTI.

    But I've practically runout of time to work on it till next year. I've got exams on at the moment, then a 1.5 month long holidays.

  4. #4

    RTTI-based streaming system

    Some updates on the current version I'm working on:

    Currently data types supported:
    • Class
    • Integers
    • Int64
    • Floats
    • Short String
    • AnsiString
    • AnsiChar
    • Widetring
    • WideChar
    • Enumeration


    Currently I'm bolting on support for ranged values.

    ie
    Code:
    type
      TMyInt = 1..5;
    Data types which I havent yet added support for(planning on adding support in this order):
    • Variants
    • Sets
    • Records
    • Arrays
    • Dynamic Arrays
    • Interfaces
    • Method pointers


    Here is a list of datatypes that cant be published properties or just dont cause any RTTI about the published properties to be generated(Or at least with delphi5):
    • Arrays
    • Records
    • Dynamic Arrays


    RTTI in delphi can be so frustratingly limited at times.

  5. #5

    RTTI-based streaming system

    New version.
    • Cleanup the sourcecode a bit.
    • Refactored the dator operation code.
    • Added name resolution.
    • More documentation on what various units do
    • Added "Time" & "CPUDetection" by LoreKeeper to the win32 implementation.
    • Misc fixes.


    Link

  6. #6

    RTTI-based streaming system

    New version.

    • Dators can now be streamed (to & from!)
    • Created a class to wrap dator output(instead of just manipulating a raw string).
    • Refactored the dator operation code again.
    • Misc fixes.


    Link

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •