Behavior Table Properties and Caching

December 9th, 2005 by Patrick Boucher - Viewed 9004 times -

The Piccolo language has this neat little function called AddPropertyTable which you can call on pretty much any object. This attaches a table of userdefined properties on the object that you can then fill with whatever you wish. This table of course goes whereever the object goes and is accessible through dot notation.

var world = engine.GetCurrentWorld();
world.ChanceOfRainInWorld = 0.8;

I use this profusely, especially with my actors. This way I can tack on actor characteristics (i.e.: agression level, strength, sight distance, etc) and refer to these characteristics later in the code.

Actor Caching

Once you’ve distributed your actors in the world and you’ve given them characteristics you may need to save these characteristics for future simulations. I built a little helper file that contains two functions to save and retrieve an actor cache. You can then, in your Piccolo startup, load a world with only your environment, and load your actors from this cache that will recreate the property table as it was when you saved the cache. Right now the code only supports saving and retrieving String, Integer and Float values because that’s what I needed. If you build on this code and add types, I’d appreciate your contributing back to the community.

The other benefit of this is that you can create your population distribution in XSI along with your actor characteristics, output an actor cache that can then be read back into Behavior as the initial state of your simulation.

Motion Caching

There are also two functions to do home-brewed motion caching. The same kind of thing Behavior does with DrvMotion. The only advantage is that it takes the black out of black-box and you know how the cache is built and what the file format is. It’s more of a Behavior/Piccolo exercise than anything else. It is definitely slower than DrvMotion because it is pure Piccolo.

You can download an example project (Behavior 2.1) and check out the code.
Any comments would be very welcome!

One Response to “Behavior Table Properties and Caching”

  1. Carlos Valcarcel says:

    I agree on the utility of the AddPropertyTable function. It”s so fast and easy to add properties, it saves you from creating your own object classes and editing them everytime.

    Thanks for sharing your caching functions, very instructive ;)