For my project I would like to use a component-based entities in C++. My current implementation is split to these parts:
- Systems - Contain a map of components of certain class and operate on these. For example PhysicsSystem has a vector of PhysicsComponents.
- Components - A component contains some public variables and a maybe a constructor to initialize them.
- Entities - An entity for me is just an Id. It is however not stored anywhere, instead only its components are stored in systems in map (where key is entityId and value is pointer to the component).
My problem is creating instances of different objects in my game. I would like to define objects in XML (could be any text file format). For performance reasons this file should be parsed only once when the program is run.
That means I should create some template from it in my ObjectFactory and associate it with a name. Then I would simply call factory.CreateObject("Player")
to add new entity to the game.
I am not really sure how to implement this without too much overhead code. Another concern is, that the I don't want my factory to know about the systems themselves. But because my components are stored in the systems and not an Entity object, I will need to use some messaging system to pass new components to their appropriate system.
My question is, how would I implement the object spawning with template for each object type? And how do some engines describe their objects with configuration files?