I'm writing a C++ game engine using SDL2 and I have an SDL event loop, but I'm not really sure what I want to do with these events. I know that I'll have systems that will be interested in these events and I know I can have a pub/sub mechanism to send events around, but the only way I can make this work is by having a singleton event system (something similar to this post), but I want to explore other approaches before going with the singleton. Another thing, too, is I don't want to just have KeyDownEvent, KeyUpEvent, etc. I feel like it's more intuitive to just have a single input event which has all the state which I think would work well with a signal/slot input.connect(...). So I'm just curious what are ways to implement events in a program?
void Application::Run()
{
Start();
while (mRunning)
{
mPlatform->PollInput();
Update();
mRenderer->RenderScene();
}
Shutdown();
}
void Platform::PollInput()
{
SDL_Event event;
while (SDL_PollEvent(&event))
{
switch (event.type)
{
}
}
}
Platformreferences to every system and calling anHandleEvent()method, but I can't imagine coupling systems like that is a sane way to do this. \$\endgroup\$