1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-09-15 06:52:34 +02:00

Fix Control enum order which was causing excessive aliasing

This commit is contained in:
Daniel Evans 2016-11-18 00:56:42 +00:00
parent f0e0e6e747
commit 9c8690bfae
3 changed files with 44 additions and 6 deletions

View File

@ -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,
};
/**

View File

@ -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)

35
tests/test_Input.cpp Normal file
View File

@ -0,0 +1,35 @@
#include <boost/test/unit_test.hpp>
#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()