Skip to main content
added 11 characters in body
Source Link
Andrei Rost
  • 195
  • 1
  • 10

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 suggestions from there. Here's a diagram of the improved event system:

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 suggestions. Here's a diagram of the improved event system:

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 suggestions from there. Here's a diagram of the improved event system:

deleted 241 characters in body; edited tags
Source Link
G. Sliepen
  • 69.5k
  • 3
  • 75
  • 180

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() });
}

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 suggesteions. 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:

Event.h

KeyboardEvent.h

MouseEvent.h

WindowEvent.h

EventQueue.h

EventListenerID.h

EventListener

EventListenerRegister.h

EventBus.h

EventManager.h

Here's the InputManager:

MouseState.h

KeyboardState.h

CharState.h

InputManager.h

InputManager.h

#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() });
}

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 suggestions. 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.

Event.h:

KeyboardEvent.h:

MouseEvent.h:

WindowEvent.h:

EventQueue.h:

EventListenerID.h:

EventListener.h:

EventListenerRegister.h:

EventBus.h:

EventManager.h:

MouseState.h:

KeyboardState.h:

CharState.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() });
}
deleted 54 characters in body
Source Link
Andrei Rost
  • 195
  • 1
  • 10
#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)
{
    std::cout << (char)event.getCodePoint() << '\n';
    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() });
}
#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)
{
    std::cout << (char)event.getCodePoint() << '\n';
    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() });
}
#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() });
}
deleted 3 characters in body
Source Link
Andrei Rost
  • 195
  • 1
  • 10
Loading
Source Link
Andrei Rost
  • 195
  • 1
  • 10
Loading