0
\$\begingroup\$

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)
        {

        }
    }
} 
\$\endgroup\$
3
  • 1
    \$\begingroup\$ Recommended reading: game design patterns: event queue. I find (re)reading them useful, even if I don't always go full pattern on the problem at hand. \$\endgroup\$ Commented 18 hours ago
  • 1
    \$\begingroup\$ "what are ways..." is a bit broad. How have you tried implementing a non-singleton event system with a single input event so far, and where did you run into a specific hurdle or point of dissatisfaction with that approach that we could help you with? \$\endgroup\$ Commented 10 hours ago
  • \$\begingroup\$ @DMGregory Well, the only other thing I've tried is giving the Platform references to every system and calling an HandleEvent() method, but I can't imagine coupling systems like that is a sane way to do this. \$\endgroup\$ Commented 5 hours ago

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.