2
\$\begingroup\$

I'm currently working on my first game engine and decided to use the entity/component model with services.

Background: My GameEngine class is an Entity and has multiple services that are Components, like the RenderService and the PhysicsService. Other Entities in my game have components that communicate with services, like the RenderComponent and the PhysicsComponent.

Question: How do I get these components to communicate with their respective services?

Note: I have thought about having a call to the respective service create the components, but I would like to hear about other solutions you guys have. I'm open to adding/removing classes and changing my whole architecture. It is my first attempt, so I'm willing to take advice and learn. Time is not the concern.

Let me know if you need more information.

Thank you in advance.

\$\endgroup\$
2
\$\begingroup\$

I think you might be overengineering, or at least abstracting too much away. While the GameEngine can certainly utilize composition in the form of services, I wouldn't treat the GameEngine as an Entity along with the rest of your game objects. If you are planning to have a 1:1 mapping of component types and services, I would definitely let each service manage the lifetimes of their respective components, by letting your Entity constructors or factories request the creation of components.

Personally, I don't like to compartmentalize that much. I use more of a property-centric approach to components, where components are little bits of data such as a position, a mesh, an AI script, etc. The behaviour associated with this data (drawing, simulating, etc.) lives in systems that can operate on more than one component type. For example, the rendering system might be interested in both the position and the sprite of an object. I like to store all my components in contiguous arrays and have my systems be free functions. I've already written a couple of articles about this so I'll link them for if you want to know more.

Understanding Entity Component Systems

Implementing Entity Component Systems

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.