diff --git a/rwengine/src/engine/GameInputState.hpp b/rwengine/src/engine/GameInputState.hpp index 85c1ea86..739e38a4 100644 --- a/rwengine/src/engine/GameInputState.hpp +++ b/rwengine/src/engine/GameInputState.hpp @@ -10,9 +10,7 @@ struct GameInputState { /* On Foot */ FireWeapon = 0, NextWeapon, - NextTarget = NextWeapon, LastWeapon, - LastTarget = LastWeapon, GoForward, GoBackwards, GoLeft, @@ -29,11 +27,8 @@ struct GameInputState { LookBehind, /* In Vehicle */ - VehicleFireWeapon = FireWeapon, VehicleAccelerate, VehicleBrake, - VehicleLeft = GoLeft, - VehicleRight = GoRight, VehicleDown, VehicleUp, ChangeRadio, @@ -47,7 +42,13 @@ struct GameInputState { VehicleAimUp, VehicleAimDown, - _MaxControls + _MaxControls, + + NextTarget = NextWeapon, + LastTarget = LastWeapon, + VehicleLeft = GoLeft, + VehicleRight = GoRight, + VehicleFireWeapon = FireWeapon, }; /** diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index cb0dc2b4..e91c2c3a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -25,6 +25,7 @@ set(TEST_SOURCES "test_GameWorld.cpp" "test_globals.hpp" "test_items.cpp" + "test_Input.cpp" "test_lifetime.cpp" "test_loaderdff.cpp" "test_Logger.cpp" @@ -49,6 +50,7 @@ set(TEST_SOURCES # Hack in rwgame sources until there's a per-target test suite "${CMAKE_SOURCE_DIR}/rwgame/GameConfig.cpp" "${CMAKE_SOURCE_DIR}/rwgame/GameWindow.cpp" + "${CMAKE_SOURCE_DIR}/rwgame/GameInput.cpp" ) ADD_DEFINITIONS(-DBOOST_TEST_DYN_LINK) diff --git a/tests/test_Input.cpp b/tests/test_Input.cpp new file mode 100644 index 00000000..67e7c042 --- /dev/null +++ b/tests/test_Input.cpp @@ -0,0 +1,35 @@ +#include +#include "GameInput.hpp" +#include "test_globals.hpp" + +BOOST_AUTO_TEST_SUITE(InputTests) + +BOOST_AUTO_TEST_CASE(TestStateUpdate) { + BOOST_CHECK(GameInputState::Handbrake != GameInputState::Submission); + BOOST_CHECK(GameInputState::Jump != GameInputState::Sprint); + { + // Currently tests against hard-coded input + GameInputState state; + + SDL_Event ev; + ev.type = SDL_KEYDOWN; + ev.key.keysym.sym = SDLK_SPACE; + + GameInput::updateGameInputState(&state, ev); + + // Check that the correct inputs report pressed + for (int c = 0; c < GameInputState::_MaxControls; ++c) { + switch ((GameInputState::Control)c) { + case GameInputState::Jump: + case GameInputState::Handbrake: + BOOST_CHECK(state.pressed((GameInputState::Control)c)); + break; + default: + BOOST_CHECK(!state.pressed((GameInputState::Control)c)); + break; + } + } + } +} + +BOOST_AUTO_TEST_SUITE_END()