Actors and DataSources

In this sample, we create a DataSource, which is a class that can be used for large-scale data sets.  It provides hooks into the system's spatial index, memory cache, and background data threads.  Data from the DataSource will only be requested when it is in view, and will be automatically cached according to how often it is used and how much memory it consumes.  The DataSource we create is a purely generated one consisting of a large number of animated bunnies spread evenly across the globe, and would be impossibly large to try to deal with all at once.

Bunny Sample

See it in action! 

When the PlugIn is Activated, the ActorDataSource is created and added to the system.  When we create the DataSource we set up its Ontology, which is a system for defining the type of data the DataSource contains.

The next time the Camera Query runs, a set of areas in the Spatial Index that are in view are determined, called tiles.  Each tile is sent as a lat/long bounding box to the Data Threads, which call all added DataSources, including ours.  The entry point here is QueryPrimitivesInternal.  In this function we would normally do some sort of query to a backend, such as a SQL database or the network, but for simplicity we simply create a BunnyPrimitive in the center of the query region.  A primitive is a piece of data that represents a thing in the world, in the case a Bunny, but is not itself an Actor.  When we return the Primitive, it is passed to our ActorBuilder, called BunnyBuilder.  This creates actual Actors which can render or react to the data represented by each Primitive.  Each Actor also needs an ActorBounds, which represents a spatial area that, when in view, should cause it to render.  When this happens each Actor's Update and Render functions are called on the Render Thread just like normal Actors.

Get the code!