From 0626862a8c19407a77d06552feff8cfa4ecc17dd Mon Sep 17 00:00:00 2001 From: Tyler Wilding Date: Thu, 7 Mar 2024 23:35:38 -0500 Subject: [PATCH] Fix issues with camera movement with controller when mouse tracking is also enabled (#3409) Fixes #3408 --- game/system/hid/devices/mouse.cpp | 12 ++++++++++-- game/system/hid/devices/mouse.h | 2 ++ game/system/hid/display_manager.cpp | 5 +++++ goal_src/jak2/pc/progress/progress-static-pc.gc | 1 + 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/game/system/hid/devices/mouse.cpp b/game/system/hid/devices/mouse.cpp index bf14c67b72..078d071e5e 100644 --- a/game/system/hid/devices/mouse.cpp +++ b/game/system/hid/devices/mouse.cpp @@ -39,11 +39,13 @@ void MouseDevice::poll_state(std::shared_ptr data) { int curr_mouse_relx; int curr_mouse_rely; const auto mouse_state_rel = SDL_GetRelativeMouseState(&curr_mouse_relx, &curr_mouse_rely); - if (m_last_xcoord == curr_mouse_x && curr_mouse_relx == 0) { + if (m_mouse_moved_x && m_last_xcoord == curr_mouse_x && curr_mouse_relx == 0) { data->analog_data.at(2) = 127; + m_mouse_moved_x = false; } - if (m_last_ycoord == curr_mouse_y && curr_mouse_rely == 0) { + if (m_mouse_moved_y && m_last_ycoord == curr_mouse_y && curr_mouse_rely == 0) { data->analog_data.at(3) = 127; + m_mouse_moved_y = false; } m_last_xcoord = curr_mouse_x; m_last_ycoord = curr_mouse_y; @@ -139,9 +141,15 @@ void MouseDevice::process_event(const SDL_Event& event, if (m_control_camera) { const auto xrel_amount = float(event.motion.xrel); const auto xadjust = std::clamp(127 + int(xrel_amount * m_xsens), 0, 255); + if (xadjust > 0) { + m_mouse_moved_x = true; + } data->analog_data.at(2) = xadjust; const auto yrel_amount = float(event.motion.yrel); const auto yadjust = std::clamp(127 + int(yrel_amount * m_ysens), 0, 255); + if (yadjust > 0) { + m_mouse_moved_y = true; + } data->analog_data.at(3) = yadjust; } } else if (event.type == SDL_MOUSEBUTTONDOWN || event.type == SDL_MOUSEBUTTONUP) { diff --git a/game/system/hid/devices/mouse.h b/game/system/hid/devices/mouse.h index 9cbaab6822..a1159b86fe 100644 --- a/game/system/hid/devices/mouse.h +++ b/game/system/hid/devices/mouse.h @@ -59,6 +59,8 @@ class MouseDevice : public InputDevice { // Tracking motion int m_last_xcoord = 0; int m_last_ycoord = 0; + bool m_mouse_moved_x = false; + bool m_mouse_moved_y = false; int m_frame_counter = 0; bool is_action_already_active(const u32 sdl_keycode, const bool player_movement); diff --git a/game/system/hid/display_manager.cpp b/game/system/hid/display_manager.cpp index 8c02b82b81..8b536803bf 100644 --- a/game/system/hid/display_manager.cpp +++ b/game/system/hid/display_manager.cpp @@ -202,6 +202,7 @@ void DisplayManager::set_window_display_mode(WindowDisplayMode mode) { case WindowDisplayMode::Windowed: result = SDL_SetWindowFullscreen(m_window, 0); if (result == 0) { + lg::info("windowed mode - resizing window to {}x{}", m_window_width, m_window_height); SDL_SetWindowSize(m_window, m_window_width, m_window_height); } else { sdl_util::log_error("unable to change window to windowed mode"); @@ -219,6 +220,8 @@ void DisplayManager::set_window_display_mode(WindowDisplayMode mode) { m_selected_fullscreen_display_id)); } else { // 2. move it to the right monitor + lg::info("preparing fullscreen - moving window to {},{} on display id {}", + display_bounds.x + 50, display_bounds.y + 50, m_selected_fullscreen_display_id); SDL_SetWindowPosition(m_window, display_bounds.x + 50, display_bounds.y + 50); if (mode == WindowDisplayMode::Fullscreen) { update_video_modes(); @@ -227,6 +230,8 @@ void DisplayManager::set_window_display_mode(WindowDisplayMode mode) { // Some people are weird and don't use the monitor's maximum supported resolution // in which case, we use what the user actually has selected. const auto& display_res = m_current_display_modes.at(m_selected_fullscreen_display_id); + lg::info("preparing fullscreen - setting window resolution to {}x{}", + display_res.screen_width, display_res.screen_height); set_window_size(display_res.screen_width, display_res.screen_height); } // 3. fullscreen it! diff --git a/goal_src/jak2/pc/progress/progress-static-pc.gc b/goal_src/jak2/pc/progress/progress-static-pc.gc index e06a972c09..388f7ef6f0 100644 --- a/goal_src/jak2/pc/progress/progress-static-pc.gc +++ b/goal_src/jak2/pc/progress/progress-static-pc.gc @@ -194,6 +194,7 @@ This gives us more freedom to write code how we want. :get-value-fn (lambda () (-> *pc-settings* mouse-enabled?)) :on-confirm (lambda ((val symbol)) (set! (-> *pc-settings* mouse-enabled?) val) + (update-mouse-controls! *pc-settings*) (pc-settings-save))) (progress-new-generic-link-to-scrolling-page (text-id progress-menu-mouse-options) :should-disable? (lambda () (not (-> *pc-settings* mouse-enabled?))) (new 'static 'menu-generic-boolean-option