I am new to C++, so please take me easy. I want to make a low-level game engine only using C++, OpenGL and GLFW. This is a continuation of Event System using C++ ; I added the suggesteionssuggestions. Here's a diagram of the improved event system:
I know I could implement a FSM for the InputManager, but for the moment, i do not need it -instead of the bool textInputMode.
I would appreciate very much some feedback.
Here's the source code for the event system:I would appreciate very much some feedback.
Event.h Event.h:
KeyboardEvent.h KeyboardEvent.h:
MouseEvent.h MouseEvent.h:
WindowEvent.h WindowEvent.h:
EventQueue.h EventQueue.h:
EventListenerID.h EventListenerID.h:
EventListener EventListener.h:
EventListenerRegister.h EventListenerRegister.h:
EventBus.h EventBus.h:
EventManager.h EventManager.h:
Here's the InputManager:
MouseState.h MouseState.h:
KeyboardState.h KeyboardState.h:
CharState.h CharState.h:
InputManager.h InputManager.h:
InputManager.h InputManager.cpp:
#include "InputManager.h"
#include <iostream>
InputManager::InputManager(EventManager& eventManager)
{
registerListener(eventManager, &InputManager::handleKeyboardPressEvent);
registerListener(eventManager, &InputManager::handleKeyboardRepeatEvent);
registerListener(eventManager, &InputManager::handleKeyboardReleaseEvent);
registerListener(eventManager, &InputManager::handleCharPressEvent);
registerListener(eventManager, &InputManager::handleMouseButtonPressEvent);
registerListener(eventManager, &InputManager::handleMouseButtonReleaseEvent);
registerListener(eventManager, &InputManager::handleMouseMoveEvent);
}
void InputManager::handleKeyboardPressEvent(const KeyboardPressEvent& event)
{
keyboardState.keyPress(event.getKeyCode());
}
void InputManager::handleKeyboardRepeatEvent(const KeyboardRepeatEvent& event)
{
keyboardState.keyRepeat(event.getKeyCode());
}
void InputManager::handleKeyboardReleaseEvent(const KeyboardReleaseEvent& event)
{
keyboardState.keyRelease(event.getKeyCode());
}
void InputManager::handleCharPressEvent(const CharPressEvent& event)
{
if(textInputMode)
charState.charDown(event.getCodePoint());
}
void InputManager::handleMouseButtonPressEvent(const MousePressEvent& event)
{
mouseState.keyDown(event.getButton());
}
void InputManager::handleMouseButtonReleaseEvent(const MouseReleaseEvent& event)
{
mouseState.keyRelease(event.getButton());
}
void InputManager::handleMouseMoveEvent(const MouseMoveEvent& event)
{
mouseState.setPosition({ event.getMouseX(), event.getMouseY() });
}