1
SFML projects / Re:creation - a top down action adventure about undeads
« on: October 16, 2016, 08:29:09 pm »SushiKru, thank you!
Here's one important thing: using ECS doesn't mean you have to build everything with ECS in mind. In my game, states are implemented as a bunch of classes which have enter, exit, update, draw, handleEvent virtual functions. I also have a stack of game states, so I can have PlayingState and then push GUIPausedState on top of it.
The StateManager calls update from top to bottom (GUIPausedState, PlayingState) and if one of the current states returns false, it stops. GUIPausedState can return false and then PlayingState update won't be called and this is what achieves pause.
On the other hand, draw is called from bottom to the to (PlayingState and then GUIPausedState). In GUIPausedState you can draw your overlay menu, for example.
All systems are created at the start of the game, but their update functions are called from PlayingState::update only (well, I also have RenderingSystem::draw and PlayingState::draw calls that, but for others update call is enough).
Transitions between states can be accomplished by making some states like FadeOutFromBlackState or something like that. And then you'll just have LoadingState pushing PlayingState and FadeOutFromBlackState to state stack after it's done loading stuff (and popping itself from it). And once FadeOutFromBlackState finishes, it can pop itself from stack (possibly sending an event which PlayingState and other things can catch, so it'll start processing player input and updating stuff...)
Yeah this is what i read on few topics in stackoverflow or gamedev. I think the RenderSystem is a special case, i can't imagine how it could work if the render is done in update(), the idea of having a draw() function that is called at a specific time is probably a better solution. You can even call it on a different thread so you will use 2 cpus core (well it's overkill for a 2D game probably )
Thank you for the answer, so a state machine above everything, and depending on the state i could create different ECS. It's really hard to understand fully ECS, when you start using it, you want to do everything with it but it's probably not a good idea.