diff --git a/source/code/HelpGamepadState.cpp b/source/code/HelpGamepadState.cpp index 2880885..e42afae 100644 --- a/source/code/HelpGamepadState.cpp +++ b/source/code/HelpGamepadState.cpp @@ -55,7 +55,7 @@ HelpGamepadState::~HelpGamepadState() { } void HelpGamepadState::ProcessInput(const SDL_Event& event, bool& processed) { - if (isGameControllerConnectionEvent(event)) { + if (GameControllerIsConnectionEvent(event)) { UnInitGameControllers(); InitGameControllers(); std::string s = getLabelForSupportedControllerNames(); diff --git a/source/code/MenuSystem.cpp b/source/code/MenuSystem.cpp index 722d811..4ec2c5d 100644 --- a/source/code/MenuSystem.cpp +++ b/source/code/MenuSystem.cpp @@ -192,7 +192,7 @@ bool isUpEvent(const SDL_Event& event) { return true; } } - return isControllerUpEvent(event); + return GameControllerIsUpEvent(event); } bool isDownEvent(const SDL_Event& event) { @@ -201,7 +201,7 @@ bool isDownEvent(const SDL_Event& event) { return true; } } - return isControllerDownEvent(event); + return GameControllerIsDownEvent(event); } bool isLeftEvent(const SDL_Event& event) { @@ -210,7 +210,7 @@ bool isLeftEvent(const SDL_Event& event) { return true; } } - return isControllerLeftEvent(event); + return GameControllerIsLeftEvent(event); } bool isRightEvent(const SDL_Event& event) { @@ -219,7 +219,7 @@ bool isRightEvent(const SDL_Event& event) { return true; } } - return isControllerRightEvent(event); + return GameControllerIsRightEvent(event); } bool isEscapeEvent(const SDL_Event& event) { @@ -277,7 +277,7 @@ void Menu::Draw(SDL_Renderer* target) { #endif } void Menu::ProcessInput(const SDL_Event& event, bool& processed) { - if (isGameControllerConnectionEvent(event)) { + if (GameControllerIsConnectionEvent(event)) { UnInitGameControllers(); InitGameControllers(); processed = true; diff --git a/source/code/gamecontroller.cpp b/source/code/gamecontroller.cpp index 2470246..fa2ae91 100644 --- a/source/code/gamecontroller.cpp +++ b/source/code/gamecontroller.cpp @@ -57,7 +57,7 @@ static const char* GameControllerGetName(SDL_GameController* gamecontroller) { static std::string GetGuidAsHex(const SDL_JoystickGUID& guid) { std::string ret; char buffer[3]; - for (size_t j = 0; j < 16; j++) { + for (size_t j = 0; j < sizeof(guid.data); j++) { snprintf(buffer, sizeof(buffer), "%02X", guid.data[j]); ret += buffer; } @@ -128,7 +128,7 @@ const std::vector& GetSupportedControllerNames() { return supportedControllers; } -void checkDeadZone(const SDL_Event& event) { +void GameControllerCheckDeadZone(const SDL_Event& event) { if (event.type != SDL_CONTROLLERAXISMOTION) { return; //assert? } @@ -138,15 +138,15 @@ void checkDeadZone(const SDL_Event& event) { } } -bool getDeadZone(SDL_JoystickID id, int axis) { +bool GameControllerIsInDeadZone(SDL_JoystickID id, int axis) { return controllerStatusMap[id].AxisInDeadZone[axis]; } -void setDeadZone(SDL_JoystickID id, int axis, bool value) { +void GameControllerSetIsInDeadZone(SDL_JoystickID id, int axis, bool value) { controllerStatusMap[id].AxisInDeadZone[axis] = value; } -static bool skipThisPlayer(int playerNumber, const SDL_Event& event) { +static bool GameControllerExtSkipThisPlayer(int playerNumber, const SDL_Event& event) { if (event.type == SDL_CONTROLLERBUTTONDOWN) { ControllerStatus& cs = controllerStatusMap[event.cbutton.which]; @@ -164,7 +164,7 @@ static bool skipThisPlayer(int playerNumber, const SDL_Event& event) { } -bool isGameControllerConnectionEvent(const SDL_Event& event) { +bool GameControllerIsConnectionEvent(const SDL_Event& event) { if ( event.type == SDL_CONTROLLERDEVICEADDED || event.type == SDL_CONTROLLERDEVICEREMOVED || event.type == SDL_CONTROLLERDEVICEREMAPPED ) { @@ -175,14 +175,14 @@ bool isGameControllerConnectionEvent(const SDL_Event& event) { -bool isPlayerDownEvent(int playerNumber, const SDL_Event& event) { - if (skipThisPlayer(playerNumber, event)) { +bool GameControllerExtIsPlayerDownEvent(int playerNumber, const SDL_Event& event) { + if (GameControllerExtSkipThisPlayer(playerNumber, event)) { return false; } - return isControllerDownEvent(event); + return GameControllerIsDownEvent(event); } -bool isControllerDirectionEvent(const SDL_Event& event, SDL_GameControllerButton dpad_direction, SDL_GameControllerAxis axis, float axis_mod = 1.0f) { +bool GameControllerIsControllerDirectionEvent(const SDL_Event& event, SDL_GameControllerButton dpad_direction, SDL_GameControllerAxis axis, float axis_mod = 1.0f) { if (event.type == SDL_CONTROLLERBUTTONDOWN) { if (event.cbutton.button == dpad_direction ) { return true; @@ -190,10 +190,10 @@ bool isControllerDirectionEvent(const SDL_Event& event, SDL_GameControllerButton } if (event.type == SDL_CONTROLLERAXISMOTION && event.caxis.axis == axis ) { const SDL_ControllerAxisEvent& a = event.caxis; - checkDeadZone(event); - if (getDeadZone(a.which, a.axis)) { + GameControllerCheckDeadZone(event); + if (GameControllerIsInDeadZone(a.which, a.axis)) { if (event.caxis.value * axis_mod > deadZoneLimit) { - setDeadZone(a.which,a.axis,false); + GameControllerSetIsInDeadZone(a.which,a.axis,false); return true; } } @@ -201,45 +201,45 @@ bool isControllerDirectionEvent(const SDL_Event& event, SDL_GameControllerButton return false; } -bool isControllerDownEvent(const SDL_Event& event) { - return isControllerDirectionEvent(event, SDL_CONTROLLER_BUTTON_DPAD_DOWN, SDL_CONTROLLER_AXIS_LEFTY); +bool GameControllerIsDownEvent(const SDL_Event& event) { + return GameControllerIsControllerDirectionEvent(event, SDL_CONTROLLER_BUTTON_DPAD_DOWN, SDL_CONTROLLER_AXIS_LEFTY); } -bool isControllerUpEvent(const SDL_Event& event) { - return isControllerDirectionEvent(event, SDL_CONTROLLER_BUTTON_DPAD_UP, SDL_CONTROLLER_AXIS_LEFTY, -1.0f); +bool GameControllerIsUpEvent(const SDL_Event& event) { + return GameControllerIsControllerDirectionEvent(event, SDL_CONTROLLER_BUTTON_DPAD_UP, SDL_CONTROLLER_AXIS_LEFTY, -1.0f); } -bool isControllerLeftEvent(const SDL_Event& event) { - return isControllerDirectionEvent(event, SDL_CONTROLLER_BUTTON_DPAD_LEFT, SDL_CONTROLLER_AXIS_LEFTX, -1.0f); +bool GameControllerIsLeftEvent(const SDL_Event& event) { + return GameControllerIsControllerDirectionEvent(event, SDL_CONTROLLER_BUTTON_DPAD_LEFT, SDL_CONTROLLER_AXIS_LEFTX, -1.0f); } -bool isControllerRightEvent(const SDL_Event& event) { - return isControllerDirectionEvent(event, SDL_CONTROLLER_BUTTON_DPAD_LEFT, SDL_CONTROLLER_AXIS_LEFTX); +bool GameControllerIsRightEvent(const SDL_Event& event) { + return GameControllerIsControllerDirectionEvent(event, SDL_CONTROLLER_BUTTON_DPAD_LEFT, SDL_CONTROLLER_AXIS_LEFTX); } -bool isPlayerUpEvent(int playerNumber, const SDL_Event& event) { - if (skipThisPlayer(playerNumber, event)) { +bool GameControllerExtIsPlayerUpEvent(int playerNumber, const SDL_Event& event) { + if (GameControllerExtSkipThisPlayer(playerNumber, event)) { return false; } - return isControllerUpEvent(event); + return GameControllerIsUpEvent(event); } -bool isPlayerLeftEvent(int playerNumber, const SDL_Event& event) { - if (skipThisPlayer(playerNumber, event)) { +bool GameControllerExtIsPlayerLeftEvent(int playerNumber, const SDL_Event& event) { + if (GameControllerExtSkipThisPlayer(playerNumber, event)) { return false; } - return isControllerLeftEvent(event); + return GameControllerIsLeftEvent(event); } -bool isPlayerRightEvent(int playerNumber, const SDL_Event& event) { - if (skipThisPlayer(playerNumber, event)) { +bool GameControllerExtIsPlayerRightEvent(int playerNumber, const SDL_Event& event) { + if (GameControllerExtSkipThisPlayer(playerNumber, event)) { return false; } - return isControllerRightEvent(event); + return GameControllerIsRightEvent(event); } -bool isPlayerSwitchEvent(int playerNumber, const SDL_Event& event) { - if (skipThisPlayer(playerNumber, event)) { +bool GameControllerExtIsPlayerSwitchEvent(int playerNumber, const SDL_Event& event) { + if (GameControllerExtSkipThisPlayer(playerNumber, event)) { return false; } if (event.type == SDL_CONTROLLERBUTTONDOWN) { @@ -250,8 +250,8 @@ bool isPlayerSwitchEvent(int playerNumber, const SDL_Event& event) { return false; } -bool isPlayerPushEvent(int playerNumber, const SDL_Event& event) { - if (skipThisPlayer(playerNumber, event)) { +bool GameControllerExtIsPlayerPushEvent(int playerNumber, const SDL_Event& event) { + if (GameControllerExtSkipThisPlayer(playerNumber, event)) { return false; } if (event.type == SDL_CONTROLLERBUTTONDOWN) { @@ -260,11 +260,11 @@ bool isPlayerPushEvent(int playerNumber, const SDL_Event& event) { } } if (event.type == SDL_CONTROLLERAXISMOTION && (event.caxis.axis == SDL_CONTROLLER_AXIS_TRIGGERLEFT || event.caxis.axis == SDL_CONTROLLER_AXIS_TRIGGERRIGHT ) ) { - checkDeadZone(event); + GameControllerCheckDeadZone(event); const SDL_ControllerAxisEvent& a = event.caxis; - if (getDeadZone(a.which, a.axis)) { + if (GameControllerIsInDeadZone(a.which, a.axis)) { if (event.caxis.value > deadZoneLimit) { - setDeadZone(a.which,a.axis,false); + GameControllerSetIsInDeadZone(a.which,a.axis,false); return true; } } diff --git a/source/code/gamecontroller.h b/source/code/gamecontroller.h index 823f1b4..79e5dee 100644 --- a/source/code/gamecontroller.h +++ b/source/code/gamecontroller.h @@ -33,18 +33,18 @@ const int deadZoneLimit = 20000; void InitGameControllers(); void UnInitGameControllers(); -bool isControllerDownEvent(const SDL_Event& event); -bool isControllerUpEvent(const SDL_Event& event); -bool isControllerLeftEvent(const SDL_Event& event); -bool isControllerRightEvent(const SDL_Event& event); +bool GameControllerIsDownEvent(const SDL_Event& event); +bool GameControllerIsUpEvent(const SDL_Event& event); +bool GameControllerIsLeftEvent(const SDL_Event& event); +bool GameControllerIsRightEvent(const SDL_Event& event); -bool isPlayerDownEvent(int playerNumber, const SDL_Event& event); -bool isPlayerUpEvent(int playerNumber, const SDL_Event& event); -bool isPlayerLeftEvent(int playerNumber, const SDL_Event& event); -bool isPlayerRightEvent(int playerNumber, const SDL_Event& event); -bool isPlayerSwitchEvent(int playerNumber, const SDL_Event& event); -bool isPlayerPushEvent(int playerNumber, const SDL_Event& event); -bool isGameControllerConnectionEvent(const SDL_Event& event); +bool GameControllerExtIsPlayerDownEvent(int playerNumber, const SDL_Event& event); +bool GameControllerExtIsPlayerUpEvent(int playerNumber, const SDL_Event& event); +bool GameControllerExtIsPlayerLeftEvent(int playerNumber, const SDL_Event& event); +bool GameControllerExtIsPlayerRightEvent(int playerNumber, const SDL_Event& event); +bool GameControllerExtIsPlayerSwitchEvent(int playerNumber, const SDL_Event& event); +bool GameControllerExtIsPlayerPushEvent(int playerNumber, const SDL_Event& event); +bool GameControllerIsConnectionEvent(const SDL_Event& event); void GameControllerSetVerbose(bool value); const std::vector& GetSupportedControllerNames(); @@ -54,7 +54,7 @@ const std::vector& GetSupportedControllerNames(); * Otherwise nothing is done * @param event An SDL */ -void checkDeadZone(const SDL_Event& event); +void GameControllerCheckDeadZone(const SDL_Event& event); /** * Checks that the given axis on a given gamepad was in a dead zone last time checked. @@ -62,7 +62,7 @@ void checkDeadZone(const SDL_Event& event); * @param axis The axis on the gamepad * @return true if the axis has been in the dead zone */ -bool getDeadZone(SDL_JoystickID id, int axis); +bool GameControllerIsInDeadZone(SDL_JoystickID id, int axis); /** * Sets dead zone status on a given axis on a given gamepad @@ -70,6 +70,6 @@ bool getDeadZone(SDL_JoystickID id, int axis); * @param axis The axis on the gamepad * @param value Value to set. Should normally be false as true will be set by checkDeadZone */ -void setDeadZone(SDL_JoystickID id, int axis, bool value); +void GameControllerSetIsInDeadZone(SDL_JoystickID id, int axis, bool value); #endif //GAMECONTROLLER diff --git a/source/code/main.cpp b/source/code/main.cpp index ee7736d..806c751 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp @@ -1575,59 +1575,59 @@ int runGame(Gametype gametype, int level) { } } - if (isPlayerUpEvent(1, event)) { + if (GameControllerExtIsPlayerUpEvent(1, event)) { a.action = BlockGameAction::Action::MOVE; a.way = 'N'; theGame.DoAction(a); } - if (isPlayerDownEvent(1, event)) { + if (GameControllerExtIsPlayerDownEvent(1, event)) { a.action = BlockGameAction::Action::MOVE; a.way = 'S'; theGame.DoAction(a); } - if (isPlayerLeftEvent(1, event)) { + if (GameControllerExtIsPlayerLeftEvent(1, event)) { a.action = BlockGameAction::Action::MOVE; a.way = 'W'; theGame.DoAction(a); } - if (isPlayerRightEvent (1, event)) { + if (GameControllerExtIsPlayerRightEvent (1, event)) { a.action = BlockGameAction::Action::MOVE; a.way = 'E'; theGame.DoAction(a); } - if (isPlayerSwitchEvent(1, event)) { + if (GameControllerExtIsPlayerSwitchEvent(1, event)) { a.action = BlockGameAction::Action::SWITCH; theGame.DoAction(a); } - if (isPlayerPushEvent(1, event)) { + if (GameControllerExtIsPlayerPushEvent(1, event)) { a.action = BlockGameAction::Action::PUSH; theGame.DoAction(a); } - if (isPlayerUpEvent(2, event)) { + if (GameControllerExtIsPlayerUpEvent(2, event)) { a.action = BlockGameAction::Action::MOVE; a.way = 'N'; theGame2.DoAction(a); } - if (isPlayerDownEvent(2, event)) { + if (GameControllerExtIsPlayerDownEvent(2, event)) { a.action = BlockGameAction::Action::MOVE; a.way = 'S'; theGame2.DoAction(a); } - if (isPlayerLeftEvent(2, event)) { + if (GameControllerExtIsPlayerLeftEvent(2, event)) { a.action = BlockGameAction::Action::MOVE; a.way = 'W'; theGame2.DoAction(a); } - if (isPlayerRightEvent (2, event)) { + if (GameControllerExtIsPlayerRightEvent (2, event)) { a.action = BlockGameAction::Action::MOVE; a.way = 'E'; theGame2.DoAction(a); } - if (isPlayerSwitchEvent(2, event)) { + if (GameControllerExtIsPlayerSwitchEvent(2, event)) { a.action = BlockGameAction::Action::SWITCH; theGame2.DoAction(a); } - if (isPlayerPushEvent(2, event)) { + if (GameControllerExtIsPlayerPushEvent(2, event)) { a.action = BlockGameAction::Action::PUSH; theGame2.DoAction(a); }