Entity e = entity_system.CreateNewEntity();
entity_system.AttachComponent( e, COMPONENT_XFORM );
/* e can now have position, scale and rotation, but how to initialize it? It
* feels kludgy to dispatch a message or fire an event *after*
* creating/attaching the component to initialize it, so I'm thinking of adding
* a parameter to AttachComponent() to pass a struct of initialization data.
* I don't really want to derive all component data structs from a base type,
* but templates don't feel right either. Le sigh...
[/source]I guess I'll spend some time pondering my approach.
For the moment, I've changed my approach somewhat, to this:
Entity entity = entity_system.CreateNewEntity();
BaseComponent* bc = entity_system.CreateComponent( COMPONENT_RENDERABLE );
dynamic_cast< RenderableComponent* >( bc )->SetData( data );
entity_system.AttachComponent( test_entity, bc );
[/source]I don't really like the idea of handing out pointers to components, but it is workable enough for me to move forward until I can come up with a cleaner solution. I guess what I really need to do is something like [font="Lucida Sans Unicode"]entity_system.CreateAndAttachComponent( entity, COMPONENT_TYPE, component_type_data_struct )[/font]. After thinking about it, it really seems the cleanest way from an interface perspective. Unless someone has a better idea.
But it's 1a.m. and I really need to try to resume a more normal sleep schedule or I'm going to sleep through my early morning Important Doctor's Appointment on Monday. So no more coding for me tonight