diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/crepe/facade/SDLContext.cpp | 14 | ||||
-rw-r--r-- | src/crepe/facade/SDLContext.h | 4 | ||||
-rw-r--r-- | src/crepe/system/InputSystem.cpp | 14 | ||||
-rw-r--r-- | src/test/EventTest.cpp | 74 |
4 files changed, 53 insertions, 53 deletions
diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index 8ed3654..063be41 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -316,19 +316,19 @@ std::vector<SDLContext::EventData> SDLContext::get_events() { switch (event.type) { case SDL_QUIT: event_list.push_back(EventData{ - .event_type = SDLContext::Event::SHUTDOWN, + .event_type = SDLContext::EventType::SHUTDOWN, }); break; case SDL_KEYDOWN: event_list.push_back(EventData{ - .event_type = SDLContext::Event::KEYDOWN, + .event_type = SDLContext::EventType::KEYDOWN, .key = sdl_to_keycode(event.key.keysym.scancode), .key_repeat = (event.key.repeat != 0), }); break; case SDL_KEYUP: event_list.push_back(EventData{ - .event_type = SDLContext::Event::KEYUP, + .event_type = SDLContext::EventType::KEYUP, .key = sdl_to_keycode(event.key.keysym.scancode), }); break; @@ -336,7 +336,7 @@ std::vector<SDLContext::EventData> SDLContext::get_events() { int x, y; SDL_GetMouseState(&x, &y); event_list.push_back(EventData{ - .event_type = SDLContext::Event::MOUSEDOWN, + .event_type = SDLContext::EventType::MOUSEDOWN, .mouse_button = sdl_to_mousebutton(event.button.button), .mouse_position = {event.button.x, event.button.y}, }); @@ -345,7 +345,7 @@ std::vector<SDLContext::EventData> SDLContext::get_events() { int x, y; SDL_GetMouseState(&x, &y); event_list.push_back(EventData{ - .event_type = SDLContext::Event::MOUSEUP, + .event_type = SDLContext::EventType::MOUSEUP, .mouse_button = sdl_to_mousebutton(event.button.button), .mouse_position = {event.button.x, event.button.y}, }); @@ -353,14 +353,14 @@ std::vector<SDLContext::EventData> SDLContext::get_events() { case SDL_MOUSEMOTION: { event_list.push_back( - EventData{.event_type = SDLContext::Event::MOUSEMOVE, + EventData{.event_type = SDLContext::EventType::MOUSEMOVE, .mouse_position = {event.motion.x, event.motion.y}, .rel_mouse_move = {event.motion.xrel, event.motion.yrel}}); } break; case SDL_MOUSEWHEEL: { event_list.push_back(EventData{ - .event_type = SDLContext::Event::MOUSEWHEEL, + .event_type = SDLContext::EventType::MOUSEWHEEL, .mouse_position = {event.motion.x, event.motion.y}, .wheel_delta = event.wheel.y, }); diff --git a/src/crepe/facade/SDLContext.h b/src/crepe/facade/SDLContext.h index 7ec11fd..5892d5c 100644 --- a/src/crepe/facade/SDLContext.h +++ b/src/crepe/facade/SDLContext.h @@ -36,7 +36,7 @@ class InputSystem; class SDLContext { public: - enum Event { + enum EventType { NONE = 0, MOUSEDOWN, MOUSEUP, @@ -48,7 +48,7 @@ public: }; struct EventData { - SDLContext::Event event_type = SDLContext::Event::NONE; + SDLContext::EventType event_type = SDLContext::EventType::NONE; Keycode key = Keycode::NONE; bool key_repeat = false; MouseButton mouse_button = MouseButton::NONE; diff --git a/src/crepe/system/InputSystem.cpp b/src/crepe/system/InputSystem.cpp index 7f7f9ec..2a47bdd 100644 --- a/src/crepe/system/InputSystem.cpp +++ b/src/crepe/system/InputSystem.cpp @@ -13,20 +13,20 @@ void InputSystem::update() { for (const SDLContext::EventData & event : event_list) { switch (event.event_type) { - case SDLContext::Event::KEYDOWN: { + case SDLContext::EventType::KEYDOWN: { event_mgr.queue_event<KeyPressEvent>(KeyPressEvent{ .repeat = event.key_repeat, .key = event.key, }); break; } - case SDLContext::Event::KEYUP: { + case SDLContext::EventType::KEYUP: { event_mgr.queue_event<KeyReleaseEvent>(KeyReleaseEvent{ .key = event.key, }); break; } - case SDLContext::Event::MOUSEDOWN: { + case SDLContext::EventType::MOUSEDOWN: { event_mgr.queue_event<MousePressEvent>(MousePressEvent{ .mouse_x = event.mouse_position.first, .mouse_y = event.mouse_position.second, @@ -36,7 +36,7 @@ void InputSystem::update() { last_mouse_button = event.mouse_button; break; } - case SDLContext::Event::MOUSEUP: { + case SDLContext::EventType::MOUSEUP: { MouseReleaseEvent mouse_release_event = MouseReleaseEvent{ .mouse_x = event.mouse_position.first, .mouse_y = event.mouse_position.second, @@ -61,7 +61,7 @@ void InputSystem::update() { } break; } - case SDLContext::Event::MOUSEMOVE: { + case SDLContext::EventType::MOUSEMOVE: { event_mgr.queue_event<MouseMoveEvent>(MouseMoveEvent{ .mouse_x = event.mouse_position.first, .mouse_y = event.mouse_position.second, @@ -71,7 +71,7 @@ void InputSystem::update() { handle_move(event); break; } - case SDLContext::Event::MOUSEWHEEL: { + case SDLContext::EventType::MOUSEWHEEL: { event_mgr.queue_event<MouseScrollEvent>(MouseScrollEvent{ .scroll_x = event.wheel_delta, .scroll_y = 0, @@ -79,7 +79,7 @@ void InputSystem::update() { }); break; } - case SDLContext::Event::SHUTDOWN: { + case SDLContext::EventType::SHUTDOWN: { event_mgr.queue_event<ShutDownEvent>(ShutDownEvent{}); break; } diff --git a/src/test/EventTest.cpp b/src/test/EventTest.cpp index c75bcc1..4af0830 100644 --- a/src/test/EventTest.cpp +++ b/src/test/EventTest.cpp @@ -154,45 +154,45 @@ TEST_F(EventManagerTest, EventManagerTest_callback_propagation) { } TEST_F(EventManagerTest, EventManagerTest_queue_dispatch) { - EventManager & event_manager = EventManager::get_instance(); - bool triggered1 = false; - bool triggered2 = false; - int test_channel = 1; - - // Adjusted to use KeyPressEvent with repeat as the first variable - EventHandler<KeyPressEvent> key_handler1 = [&](const KeyPressEvent & e) { - triggered1 = true; - EXPECT_EQ(e.repeat, false); // Expecting repeat to be false - EXPECT_EQ(e.key, Keycode::A); // Adjust expected key code - return false; // Allows propagation - }; - - EventHandler<KeyPressEvent> key_handler2 = [&](const KeyPressEvent & e) { - triggered2 = true; - EXPECT_EQ(e.repeat, false); // Expecting repeat to be false - EXPECT_EQ(e.key, Keycode::A); // Adjust expected key code - return false; // Allows propagation - }; - - // Subscribe handlers to KeyPressEvent - event_manager.subscribe<KeyPressEvent>(key_handler1); - event_manager.subscribe<KeyPressEvent>(key_handler2, test_channel); - - // Queue a KeyPressEvent instead of KeyDownEvent - event_manager.queue_event<KeyPressEvent>(KeyPressEvent{ - .repeat = false, .key = Keycode::A}); // Adjust event with repeat flag first - - event_manager.queue_event<KeyPressEvent>( - KeyPressEvent{.repeat = false, - .key = Keycode::A}, // Adjust event for second subscription - test_channel); - - event_manager.dispatch_events(); - - EXPECT_TRUE(triggered1); - EXPECT_TRUE(triggered2); + EventManager & event_manager = EventManager::get_instance(); + bool triggered1 = false; + bool triggered2 = false; + int test_channel = 1; + + // Adjusted to use KeyPressEvent with repeat as the first variable + EventHandler<KeyPressEvent> key_handler1 = [&](const KeyPressEvent & e) { + triggered1 = true; + EXPECT_EQ(e.repeat, false); // Expecting repeat to be false + EXPECT_EQ(e.key, Keycode::A); // Adjust expected key code + return false; // Allows propagation + }; + + EventHandler<KeyPressEvent> key_handler2 = [&](const KeyPressEvent & e) { + triggered2 = true; + EXPECT_EQ(e.repeat, false); // Expecting repeat to be false + EXPECT_EQ(e.key, Keycode::A); // Adjust expected key code + return false; // Allows propagation + }; + + // Subscribe handlers to KeyPressEvent + event_manager.subscribe<KeyPressEvent>(key_handler1); + event_manager.subscribe<KeyPressEvent>(key_handler2, test_channel); + + // Queue a KeyPressEvent instead of KeyDownEvent + event_manager.queue_event<KeyPressEvent>( + KeyPressEvent{.repeat = false, .key = Keycode::A}); // Adjust event with repeat flag first + + event_manager.queue_event<KeyPressEvent>( + KeyPressEvent{.repeat = false, .key = Keycode::A}, // Adjust event for second subscription + test_channel); + + event_manager.dispatch_events(); + + EXPECT_TRUE(triggered1); + EXPECT_TRUE(triggered2); } + TEST_F(EventManagerTest, EventManagerTest_unsubscribe) { EventManager & event_manager = EventManager::get_instance(); |