I am making a c++ sdl based game engine, currently doing the EventManager, help me…
- User
I am making a c++ sdl based game engine, currently doing the EventManager, help me design it:
OK I got this in mind, this is my design: I want to make a pub/sub pattern, EventManager is going to follow an event-driven architecture, there will be event producers that are just using the SDL backend so the producers will be implicitly, the consumers will subscribe to an event, I don't know if it will be the Event object or an specific sub class of the Event, this is the part that need to be worked on. Then the Event class will be an abstract class that will be sub-divided into the specific SDL_Event classes.
This is my diagram:
->EventManager - Publish? - Subscribe? - PollEvent?
->Event (similar to SDL_Event but without being an union of events) ->SDL_CommonEvent common common event data -> ... ->SDL_DisplayEvent display display event data -> ... ->SDL_WindowEvent window window event data -> ... ->SDL_KeyboardEvent key keyboard event data -> ... ->SDL_TextEditingEvent edit text editing event data -> ... ->SDL_TextInputEvent text text input event data -> ... ->SDL_MouseMotionEvent motion mouse motion event data -> ... ->SDL_MouseButtonEvent button mouse button event data -> SDL_MOUSEBUTTONDOWN -> SDL_MOUSEBUTTONUP ->SDL_MouseWheelEvent wheel mouse wheel event data -> ... ->SDL_JoyAxisEvent jaxis joystick axis event data -> ... ->SDL_JoyBallEvent jball joystick ball event data -> ... ->SDL_JoyHatEvent jhat joystick hat event data -> ... ->SDL_JoyButtonEvent jbutton joystick button event data -> ... ->SDL_JoyDeviceEvent jdevice joystick device event data -> ... ->SDL_ControllerAxisEvent caxis game controller axis event data -> ... ->SDL_ControllerButtonEvent cbutton game controller button event data -> ... ->SDL_ControllerDeviceEvent cdevice game controller device event data -> ... ->SDL_AudioDeviceEvent adevice audio device event data (>= SDL 2.0.4) -> ... ->SDL_QuitEvent quit quit request event data -> ... ->SDL_UserEvent user custom event data -> ... ->SDL_SysWMEvent syswm system dependent window event data -> ... ->SDL_TouchFingerEvent tfinger touch finger event data -> ... ->SDL_MultiGestureEvent mgesture multi finger gesture data -> ... ->SDL_DollarGestureEvent dgesture multi finger gesture data -> ... ->SDL_DropEvent drop drag and drop event data -> ...
Maybe some of them shouldn't be needed, but those will be Event sub classes of the main Event Class.
An example of its usage will be like this: The InputManager will subscribe to the input events, and work it out in its Update function.
Originally the Input Manager Update method is like this: void InputManager::Update() { SDL_Event event; while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_MOUSEBUTTONUP: // this will { //... } case SDL_MOUSEBUTTONDOWN: { //... } case SDL_CONTROLLERDEVICEADDED: { //... } case SDL_CONTROLLERDEVICEREMOVED: { //... } case SDL_CONTROLLERBUTTONDOWN: case SDL_CONTROLLERBUTTONUP: { //... } } } }
Now it will change that there won't be any SDL, now there could be two alternatives, on this.
- Assistant
- User
I like this idea, in a general and broad way, can you diagram what methods each one should have?
- Assistant