Huge stuff. camera, input manager (mouse + keyboard), can move around scene now
This commit is contained in:
61
src/InputManager.h
Normal file
61
src/InputManager.h
Normal file
@@ -0,0 +1,61 @@
|
||||
//
|
||||
// Created by slinky on 5/3/26.
|
||||
//
|
||||
|
||||
#ifndef B_ENGINE_INPUTMANAGER_H
|
||||
#define B_ENGINE_INPUTMANAGER_H
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <initializer_list>
|
||||
#include <memory>
|
||||
|
||||
#include "GLFW/glfw3.h"
|
||||
|
||||
using MouseDeltaCallback = std::function<void(float, float)>;
|
||||
|
||||
enum KeyState {
|
||||
KEY_PRESSED,
|
||||
KEY_HELD,
|
||||
KEY_DOWN,
|
||||
KEY_RELEASED,
|
||||
};
|
||||
|
||||
struct InputRequirement {
|
||||
int key;
|
||||
KeyState state;
|
||||
};
|
||||
|
||||
struct InputAction {
|
||||
std::vector<InputRequirement> requirements{};
|
||||
};
|
||||
|
||||
class InputManager {
|
||||
public:
|
||||
static bool mouseInit;
|
||||
static float lastMousePositionX;
|
||||
static float lastMousePositionY;
|
||||
|
||||
static bool* currentKeyStates;
|
||||
static bool* previousKeyStates;
|
||||
|
||||
static std::unordered_map<std::string, std::unique_ptr<InputAction>> registeredActions;
|
||||
|
||||
static void mouse_pos_callback(GLFWwindow* window, double x, double y);
|
||||
static void add_mouse_listener(MouseDeltaCallback callback);
|
||||
|
||||
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods);
|
||||
static void generate_input_action(std::string_view actionName, std::initializer_list<InputRequirement> requirements);
|
||||
static bool check_action_performed(std::string_view actionName);
|
||||
|
||||
static bool key_pressed(int key);
|
||||
static bool key_held(int key);
|
||||
static bool key_released(int key);
|
||||
static bool key_down(int key);
|
||||
static bool key_up(int key);
|
||||
private:
|
||||
static std::vector<MouseDeltaCallback> mouse_listeners;
|
||||
static void set_key_state(int key, bool state);
|
||||
};
|
||||
|
||||
#endif //B_ENGINE_INPUTMANAGER_H
|
||||
Reference in New Issue
Block a user