From 5b47f455a8bda1b2c71b8d3c889bc9dcb0fee907 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Tue, 7 Dec 2021 21:12:49 +0200 Subject: [PATCH] general refactoring --- abstractAppState.cpp | 9 +++++---- abstractAppState.h | 17 +++++++++-------- inputManager.cpp | 8 ++++---- mapping.h | 45 +------------------------------------------- 4 files changed, 19 insertions(+), 60 deletions(-) diff --git a/abstractAppState.cpp b/abstractAppState.cpp index 0e27678..61222d8 100644 --- a/abstractAppState.cpp +++ b/abstractAppState.cpp @@ -20,7 +20,7 @@ namespace gameBase { int trigger = atoi(bindingsLines[i].substr(semicolon + 5, string::npos).c_str()); Mapping *m = new Mapping; - m->bind = (Mapping::Bind)(3 + i); + m->bind = 3 + i; m->type = type; m->action = action; m->trigger = trigger; @@ -30,11 +30,12 @@ namespace gameBase { void AbstractAppState::onDettached(){ attached = false; + + while(!mappings.empty()) + mappings.pop_back(); } - void AbstractAppState::update(){} - - void AbstractAppState::removeMapping(Mapping::Bind bind){ + void AbstractAppState::removeMapping(int bind){ int id = -1; for(int i = 0; i < mappings.size(); i++) diff --git a/abstractAppState.h b/abstractAppState.h index e3a62f3..68b7e95 100644 --- a/abstractAppState.h +++ b/abstractAppState.h @@ -9,7 +9,7 @@ namespace gameBase { class AbstractAppState{ public: - virtual void update(); + virtual void update(){} virtual void onAttached(); virtual void onDettached(); inline int getType(){return type;} @@ -17,16 +17,17 @@ namespace gameBase { inline std::vector& getMappings(){return mappings;} inline int getNumMappings(){return mappings.size();} inline bool isAttached(){return attached;} - void removeMapping(Mapping::Bind); - virtual void onAction(Mapping::Bind,bool){} - virtual void onAnalog(Mapping::Bind,float){} - virtual void onRawKeyButton(short){} - virtual void onRawMouseButton(short){} - virtual void onRawJoystickAxis(short,float){} - virtual void onRawJoystickButton(short){} + void removeMapping(int); + virtual void onAction(int, bool){} + virtual void onAnalog(int, float){} + virtual void onRawKeyPress(int){} + virtual void onRawMousePress(int){} + virtual void onRawJoystickMove(int, float){} + virtual void onRawJoystickPress(int){} protected: AbstractAppState(){} ~AbstractAppState(){} + std::vector mappings; std::vector bindingsLines; int type; diff --git a/inputManager.cpp b/inputManager.cpp index c59d747..72ba69d 100644 --- a/inputManager.cpp +++ b/inputManager.cpp @@ -101,9 +101,9 @@ namespace gameBase{ for(int i = 0; i < 350; i++){ if(glfwGetKey(window, i)) - a->onRawKeyButton(i); + a->onRawKeyPress(i); else if(glfwGetMouseButton(window, i)) - a->onRawMouseButton(i); + a->onRawMousePress(i); } glfwSetCursorPosCallback(window, foo); @@ -111,11 +111,11 @@ namespace gameBase{ if(glfwJoystickPresent(GLFW_JOYSTICK_1)){ for(int i = 0; i < numAxis; i++) if(abs(axis[i]) == 1) - a->onRawJoystickAxis(i, axis[i]); + a->onRawJoystickMove(i, axis[i]); for(int i = 0; i < numButtons; i++) if(buttons[i]) - a->onRawJoystickButton(i); + a->onRawJoystickPress(i); } } } diff --git a/mapping.h b/mapping.h index b3e37a9..b426ac9 100755 --- a/mapping.h +++ b/mapping.h @@ -4,53 +4,10 @@ namespace gameBase{ struct Mapping{ - enum Bind{ - LEFT_CLICK, - SCROLLING_UP, - SCROLLING_DOWN, - LEFT, - RIGHT, - DELETE_CHAR, - CAPS_LOCK, - SHIFT_CAPS, - SPACE, - PLUS, - MINUS, - DEVSTERISK, - TOGGLE_MAIN_MENU, - HALT, - ZOOM_IN, - ZOOM_OUT, - LOOK_AROUND, - LOOK_UP, - LOOK_DOWN, - LOOK_LEFT, - LOOK_RIGHT, - DRAG_BOX, - DESELECT, - LEFT_CONTROL, - LEFT_SHIFT, - SELECT_PATROL_POINTS, - LAUNCH, - TOGGLE_SUB, - INSTALL_AWM, - INSTALL_AAM, - GROUP_0, - GROUP_1, - GROUP_2, - GROUP_3, - GROUP_4, - GROUP_5, - GROUP_6, - GROUP_7, - GROUP_8, - GROUP_9, - LAST_BIND - }; enum BindType{KEYBOARD, MOUSE_KEY, MOUSE_AXIS, JOYSTICK_KEY, JOYSTICK_AXIS}; enum AuxTriggers{MOUSE_AXIS_LEFT = 310, MOUSE_AXIS_RIGHT = 311, MOUSE_AXIS_UP = 312, MOUSE_AXIS_DOWN = 313}; - Bind bind; + int bind; BindType type; int trigger; bool action, pressed = false;