I am designing window management for my engine and I have a dilemma. I don't know if I should make the Window Manager part of the engine, or keep Window Manager as an gateway between user and the engine which sends window events to the engine. And the engine does all the work.
In my current design, there is an Engine object, which on its own is a FiniteStateMachine, so its responsible for changing the game states. It also performs the main loop in my game. Then I attach a WindowInterface to my engine (can be SFML or SDL or whatever). The MainLoop of an engine is implemented this way:
int Engine::run() {
Timer timer;
while(running) {
auto event = window->pollEvents();
if(event) {
if(event->getName() == "closed") stopRunning();
peekState()->sendBeforeUpdateEvent(event);
}
peekState()->update(timer.getElapsedTime<Timer::seconds>());
window->preRender();
peekState()->render();
window->postRender();
timer.reset();
}
return 0;
}
But I am thinking maybe this design would be vise-versa, where the window sends events to the Engine instead of Engine receiving them from the Window, and the loop happens through the window instead of the engine.
So, every simple implementation (whether its SDL or SFML or something else), the "run" function must be implemented over and over; from programmer point of view it sounds more work. But It makes more sense to have something similar to that from Engine Design point of view, instead of more code writing point of view.
Please give me advice on this situation. I don't know how to keep it. Its not about anything but the actual Engine design.
Thanks,
Gasim Gasimzada