diff --git a/CMakeLists.txt b/CMakeLists.txt index 4554a85..332bba3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -116,4 +116,6 @@ if (SK_IS_MAIN) # Create seika test exe # add_executable(${PROJECT_NAME}_test test/main.c) # target_link_libraries(${PROJECT_NAME}_test ${PROJECT_NAME} unity) + add_executable(${PROJECT_NAME}_test test/new_main.c) + target_link_libraries(${PROJECT_NAME}_test ${PROJECT_NAME} unity) endif() diff --git a/new-seika/input.c b/new-seika/input.c index 69345f9..a974654 100644 --- a/new-seika/input.c +++ b/new-seika/input.c @@ -242,8 +242,8 @@ void ska_input_register_input_event(SkaInputSourceType sourceType, SkaInputKey k } else { keyState->isJustPressed = false; } - keyState->isJustPressed = false; keyState->isPressed = true; + keyState->isJustReleased = false; keyState->strength = 1.0f; break; } diff --git a/new-seika/input.h b/new-seika/input.h index a3032ca..b0c1ac6 100644 --- a/new-seika/input.h +++ b/new-seika/input.h @@ -4,7 +4,7 @@ extern "C" { #endif -#include "new-seika/math.h" +#include "../new-seika/math.h" typedef int32 SkaInputDeviceIndex; typedef uint32 SkaInputSubscriberHandle; @@ -217,8 +217,8 @@ typedef enum SkaInputKey { #define SKA_INPUT_KEY_MOUSE_COUNT (SKA_INPUT_KEY_MOUSE_ENUM_END - SKA_INPUT_KEY_MOUSE_ENUM_START) #define SKA_INPUT_KEY_GAMEPAD_FOR_EACH(KeyName) for(SkaInputKey KeyName = SKA_INPUT_KEY_GAMEPAD_ENUM_START; KeyName <= SKA_INPUT_KEY_GAMEPAD_ENUM_END; KeyName++) -#define SKA_INPUT_KEY_KEYBOARD_FOR_EACH(KeyName) for(SkaInputKey KeyName = SKA_INPUT_KEY_KEYBOARD_ENUM_START; keyName <= SKA_INPUT_KEY_KEYBOARD_ENUM_END; KeyName++) -#define SKA_INPUT_KEY_MOUSE_FOR_EACH(KeyName) for(SkaInputKey KeyName = SKA_INPUT_KEY_MOUSE_ENUM_START; keyName <= SKA_INPUT_KEY_MOUSE_ENUM_END; KeyName++) +#define SKA_INPUT_KEY_KEYBOARD_FOR_EACH(KeyName) for(SkaInputKey KeyName = SKA_INPUT_KEY_KEYBOARD_ENUM_START; KeyName <= SKA_INPUT_KEY_KEYBOARD_ENUM_END; KeyName++) +#define SKA_INPUT_KEY_MOUSE_FOR_EACH(KeyName) for(SkaInputKey KeyName = SKA_INPUT_KEY_MOUSE_ENUM_START; KeyName <= SKA_INPUT_KEY_MOUSE_ENUM_END; KeyName++) typedef enum SkaInputAxis { SkaInputAxis_LEFT, diff --git a/test/new_main.c b/test/new_main.c new file mode 100644 index 0000000..17072e3 --- /dev/null +++ b/test/new_main.c @@ -0,0 +1,46 @@ +#include + +#include "../new-seika/input.h" + +#define RESOURCES_PATH "test/resources" +#define RESOURCES_PACK_PATH "test/resources/test.pck" + +void setUp() {} +void tearDown() {} + +void seika_input_test(void); + +int main(int argv, char** args) { + UNITY_BEGIN(); + RUN_TEST(seika_input_test); + return UNITY_END(); +} + +void seika_input_test(void) { + TEST_MESSAGE("Testing 'for each' and checking input type"); + SKA_INPUT_KEY_GAMEPAD_FOR_EACH(key) { + TEST_ASSERT_TRUE(ska_input_is_gamepad_key(key)); + } + SKA_INPUT_KEY_KEYBOARD_FOR_EACH(key) { + TEST_ASSERT_TRUE(ska_input_is_keyboard_key(key)); + } + SKA_INPUT_KEY_MOUSE_FOR_EACH(key) { + TEST_ASSERT_TRUE(ska_input_is_mouse_key(key)); + } + + TEST_MESSAGE("Testing events"); + ska_input_register_input_event3(SkaInputSourceType_KEYBOARD, SkaInputKey_KEYBOARD_BACKSPACE, SkaInputTriggerType_PRESSED); + TEST_ASSERT_TRUE(ska_input_is_key_pressed(SkaInputKey_KEYBOARD_BACKSPACE, SKA_INPUT_FIRST_PLAYER_DEVICE_INDEX)); + TEST_ASSERT_TRUE(ska_input_is_key_just_pressed(SkaInputKey_KEYBOARD_BACKSPACE, SKA_INPUT_FIRST_PLAYER_DEVICE_INDEX)); + TEST_ASSERT_FALSE(ska_input_is_key_just_released(SkaInputKey_KEYBOARD_BACKSPACE, SKA_INPUT_FIRST_PLAYER_DEVICE_INDEX)); + + ska_input_register_input_event3(SkaInputSourceType_KEYBOARD, SkaInputKey_KEYBOARD_BACKSPACE, SkaInputTriggerType_PRESSED); + TEST_ASSERT_TRUE(ska_input_is_key_pressed(SkaInputKey_KEYBOARD_BACKSPACE, SKA_INPUT_FIRST_PLAYER_DEVICE_INDEX)); + TEST_ASSERT_FALSE(ska_input_is_key_just_pressed(SkaInputKey_KEYBOARD_BACKSPACE, SKA_INPUT_FIRST_PLAYER_DEVICE_INDEX)); + TEST_ASSERT_FALSE(ska_input_is_key_just_released(SkaInputKey_KEYBOARD_BACKSPACE, SKA_INPUT_FIRST_PLAYER_DEVICE_INDEX)); + + ska_input_register_input_event3(SkaInputSourceType_KEYBOARD, SkaInputKey_KEYBOARD_BACKSPACE, SkaInputTriggerType_RELEASED); + TEST_ASSERT_FALSE(ska_input_is_key_pressed(SkaInputKey_KEYBOARD_BACKSPACE, SKA_INPUT_FIRST_PLAYER_DEVICE_INDEX)); + TEST_ASSERT_FALSE(ska_input_is_key_just_pressed(SkaInputKey_KEYBOARD_BACKSPACE, SKA_INPUT_FIRST_PLAYER_DEVICE_INDEX)); + TEST_ASSERT_TRUE(ska_input_is_key_just_released(SkaInputKey_KEYBOARD_BACKSPACE, SKA_INPUT_FIRST_PLAYER_DEVICE_INDEX)); +}