Ah, I see!
I try to explain shortly (but I can't... :) ).
I want to implement an entity/component system (based losely on the Artemis-Entity-Framework:
http://gamadu.com/artemis/ ) for my (hobby) game engine . I have already implemented two working entity/component-systems, but in these systems I have to cast the components when I want to use them and I want to avoid that by the macro.
An entity in the system is a "game-object" (the player, an enemy, whatever) and is represented by an int-value.
Components are properties of the entities (like position, velocity, a bitmap, etc) and are linked to the entities (see below).
The ComponentManager manages the associations between entities and components.
so, basically in my systems I do something like this:
var entityId : Int = componentManager.createEntity();
var position : PositionComponent = new PositionComponent( 0, 0 );
var velocity : VelocityComponent = new VelocityComponent( 1, 0 );
componentManager.set( entityId, position ); // this links the position with the entity
componentManager.set( entityId, velocity );and so on. That works, because PositionComponent and VelocityComponent implement the interface IComponent and the ComponentManager saves them here:
var components : IntHash<Array<IComponent>>; The keys of this IntHash are internally managed typeIds of the components and the indexes (or indices) of the Arrays of IComponents are the entityIds.
All that (and much more) works, BUT when I want to get() a component later in a system I have to do something like this:
// lets say I want the position of entity 2
var posComponent : PositionComponent = cast( componentManager.get( 2, PositionComponent ), PositionComponent );
I want to avoid this need to cast (because it's slow). I don't find any 'architectural' solutions to this (most EntitySystems I have read about have the same 'problem'), so I thought of a macro solution. Basically I want to generate all necessary Arrays and getters/setters for the components in the ComponentManager and then rewrite all set() and get()-calls from my systems to the generated methods.
Thanks for reading!
Stefan