Some backstory:
I decided it was time to start making a game. I've got a bachelor degree in computer sciences, but I didn't really get to code much during my studies.
I've started making a quick prototype with libgdx, checking how the library worked et al. Then at some point I decided I knew enough of the basics and that it was time to move on and start doing something more complex and flexible.
I've started wondering how organize the logic and the data, and so I found out about Entity-Component-System
architecture.
Basically my implementation is something like this:
- Entity: just an id (UUID).
- Component: data. It can be a
PositionComponent
(float x, y),VelocityComponent
(float x, y),RenderableComponent
(texture t), ... - System: Has an update() function that runs the logic every frame, and listens to message..
I've then discovered the EventManager
, and have been struggling in implementing it propely.
Right now, it has an evergrowing enum to identify the different types of events. I can feel it is a bad thing since every class that listesns to / receives events need to include that, but I can't figure out another way to handle it.
Question:
What does this eventmanager really do? It doesn't send any message other than "hey, wake up, something you care about happened, can't tell you what tho, check it yourself".
Every type of event needs custom data to work with.
So the question is, how to append data (of different types) to an event message?
Practical example:
I would have liked to change the Entity-Component-System
architecture a bit. Basically Systems may require more than a component to work with.
For example the MovementSystem
will need both PositionComponent
and VelocityComponent
,
RenderSystem
will need PositionComponent
and TextureComponent
.
So I wanted to create another object, the Node
to hold all the components that a System
requires, if the Entity
has them.
To do so I need to keep a list of Node
s for every System
, wich can be achived (I guess) with messages on ComponentAdded / Component events telling wich component has been added/removed and check if a node needs to be added/removed.
Conclusion:
I don't know if this architecture I tried to describe is actually any good, so I'm open for any complete refactoring suggestions.
My ultimate goal is to make a game, but I'm really interested in learning design patterns and techniques aswell, so I don't mind if I'm overengineering it.
There's no design behind the game yet, so for now I just want to do something 'general'.
It's my first post here, so sorry for my excessive usage of ThisThingIObviouslyDontKnowHowToUsePropely
.