From 73f8d5c558ebc0820ede241e64a876ff1c5ccefb Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Thu, 12 Dec 2024 07:57:24 +0100 Subject: seperat ints converted to float --- src/crepe/system/InputSystem.cpp | 77 ++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 43 deletions(-) (limited to 'src/crepe/system/InputSystem.cpp') diff --git a/src/crepe/system/InputSystem.cpp b/src/crepe/system/InputSystem.cpp index f5d8536..e76b1ec 100644 --- a/src/crepe/system/InputSystem.cpp +++ b/src/crepe/system/InputSystem.cpp @@ -2,7 +2,6 @@ #include "../api/Button.h" #include "../manager/ComponentManager.h" #include "../manager/EventManager.h" - #include "InputSystem.h" using namespace crepe; @@ -41,15 +40,15 @@ void InputSystem::update() { || event.event_type == SDLContext::EventType::MOUSEMOVE || event.event_type == SDLContext::EventType::MOUSEWHEEL) { - int adjusted_mouse_x = event.mouse_data.mouse_position.x + camera_origin.x; - int adjusted_mouse_y = event.mouse_data.mouse_position.y + camera_origin.y; - + ivec2 adjusted_mouse; + adjusted_mouse.x = event.mouse_data.mouse_position.x + camera_origin.x; + adjusted_mouse.y = event.mouse_data.mouse_position.y + camera_origin.y; // Check if the mouse is within the viewport bool mouse_in_viewport - = !(adjusted_mouse_x < camera_origin.x - || adjusted_mouse_x > camera_origin.x + current_cam.viewport_size.x - || adjusted_mouse_y < camera_origin.y - || adjusted_mouse_y > camera_origin.y + current_cam.viewport_size.y); + = !(adjusted_mouse.x < camera_origin.x + || adjusted_mouse.x > camera_origin.x + current_cam.viewport_size.x + || adjusted_mouse.y < camera_origin.y + || adjusted_mouse.y > camera_origin.y + current_cam.viewport_size.y); if (!mouse_in_viewport) continue; @@ -57,45 +56,44 @@ void InputSystem::update() { switch (event.event_type) { case SDLContext::EventType::MOUSEDOWN: event_mgr.queue_event({ - .mouse_pos = {adjusted_mouse_x, adjusted_mouse_y}, + .mouse_pos = {adjusted_mouse.x, adjusted_mouse.y}, .button = event.mouse_data.mouse_button, }); - this->last_mouse_down_position = {adjusted_mouse_x, adjusted_mouse_y}; + this->last_mouse_down_position = {adjusted_mouse.x, adjusted_mouse.y}; this->last_mouse_button = event.mouse_data.mouse_button; break; case SDLContext::EventType::MOUSEUP: { event_mgr.queue_event({ - .mouse_pos = {adjusted_mouse_x, adjusted_mouse_y}, + .mouse_pos = {adjusted_mouse.x, adjusted_mouse.y}, .button = event.mouse_data.mouse_button, }); - int delta_x = adjusted_mouse_x - this->last_mouse_down_position.x; - int delta_y = adjusted_mouse_y - this->last_mouse_down_position.y; + int delta_x = adjusted_mouse.x - this->last_mouse_down_position.x; + int delta_y = adjusted_mouse.y - this->last_mouse_down_position.y; if (this->last_mouse_button == event.mouse_data.mouse_button && std::abs(delta_x) <= click_tolerance && std::abs(delta_y) <= click_tolerance) { event_mgr.queue_event({ - .mouse_pos = {adjusted_mouse_x, adjusted_mouse_y}, + .mouse_pos = {adjusted_mouse.x, adjusted_mouse.y}, .button = event.mouse_data.mouse_button, }); - this->handle_click(event.mouse_data.mouse_button, adjusted_mouse_x, - adjusted_mouse_y); + this->handle_click(event.mouse_data.mouse_button, adjusted_mouse); } break; } case SDLContext::EventType::MOUSEMOVE: event_mgr.queue_event({ - .mouse_pos = {adjusted_mouse_x, adjusted_mouse_y}, + .mouse_pos = {adjusted_mouse.x, adjusted_mouse.y}, .mouse_delta = event.mouse_data.rel_mouse_move, }); - this->handle_move(event, adjusted_mouse_x, adjusted_mouse_y); + this->handle_move(event, adjusted_mouse); break; case SDLContext::EventType::MOUSEWHEEL: event_mgr.queue_event({ - .mouse_pos = {adjusted_mouse_x, adjusted_mouse_y}, + .mouse_pos = {adjusted_mouse.x, adjusted_mouse.y}, .scroll_direction = event.mouse_data.scroll_direction, .scroll_delta = event.mouse_data.scroll_delta, }); @@ -148,54 +146,57 @@ void InputSystem::update() { } void InputSystem::handle_move(const SDLContext::EventData & event_data, - const int adjusted_mouse_x, const int adjusted_mouse_y) { + const ivec2& mouse_pos) { ComponentManager & mgr = this->mediator.component_manager; RefVector