InputManager class

This commit is contained in:
Tulpen 2023-07-30 18:06:47 +02:00
parent 7d3ccdb15f
commit e74a21b365
No known key found for this signature in database
GPG key ID: 12294D73B907E784
5 changed files with 61 additions and 1 deletions

26
core/input/manager.cpp Normal file
View file

@ -0,0 +1,26 @@
#include "manager.hpp"
namespace hibis {
InputManager::InputManager() {}
InputManager::~InputManager() {}
bool InputManager::isKeyPressed(int scancode) {
if (mKeyScancodes.find(scancode) != mKeyScancodes.end()) return (mKeyScancodes[scancode] == Pressed || mKeyScancodes[scancode] == Held);
else return false;
}
bool InputManager::isKeyJustPressed(int scancode) {
if (mKeyScancodes.find(scancode) != mKeyScancodes.end()) return mKeyScancodes[scancode] == Pressed;
else return false;
}
bool InputManager::isKeyJustReleased(int scancode) {
if (mKeyScancodes.find(scancode) != mKeyScancodes.end()) return mKeyScancodes[scancode] == Released;
else return false;
}
void InputManager::setKeyPressState(int scancode, PressTypes type) {
mKeyScancodes[scancode] = type;
}
}

21
core/input/manager.hpp Normal file
View file

@ -0,0 +1,21 @@
#pragma once
#include <map>
#include "presstypes.hpp"
namespace hibis {
class InputManager final {
public:
InputManager();
~InputManager();
bool isKeyPressed(int scancode);
bool isKeyJustPressed(int scancode);
bool isKeyJustReleased(int scancode);
void setKeyPressState(int scancode, PressTypes type);
private:
std::map<int, PressTypes> mKeyScancodes;
};
}

11
core/input/presstypes.hpp Normal file
View file

@ -0,0 +1,11 @@
#pragma once
namespace hibis {
enum PressTypes {
Unpressed,
Pressed,
Held,
Released,
Unknown = __INT32_MAX__
};
}

View file

@ -1,5 +1,5 @@
#include "renderer.hpp"
namespace hibis {
Renderer::Renderer(LoggerCallback logger) : mLogger(logger) {}
Renderer::Renderer(LoggerCallback logger) : mLogger(logger), mInputManager() {}
}

View file

@ -2,6 +2,7 @@
#include <string>
#include "../input/manager.hpp"
#include "../math/types.hpp"
#include "../resources/resource.hpp"
#include "../resources/shader.hpp"
@ -36,6 +37,7 @@ namespace hibis {
bool mKeepOpen = true;
LoggerCallback mLogger;
InputManager mInputManager;
protected:
bool mIsWireframeMode = false;
};