From fa8d8c9b0fc20e66c296e1cd053600e80dd0b304 Mon Sep 17 00:00:00 2001 From: Agent X <44549182+AgentXLP@users.noreply.github.com> Date: Sat, 1 Jun 2024 13:30:41 -0400 Subject: [PATCH] Fixes and overhaul mouse locking --- src/game/first_person_cam.c | 6 ------ src/game/ingame_menu.c | 4 ++-- src/pc/controller/controller_sdl2.c | 29 +++++++++-------------------- src/pc/debug_context.c | 1 + src/pc/djui/djui_hud_utils.c | 9 +-------- src/pc/pc_main.c | 18 +++++++++--------- 6 files changed, 22 insertions(+), 45 deletions(-) diff --git a/src/game/first_person_cam.c b/src/game/first_person_cam.c index 2161147f..680f112f 100644 --- a/src/game/first_person_cam.c +++ b/src/game/first_person_cam.c @@ -77,10 +77,6 @@ void first_person_camera_update(void) { } else { gFirstPersonCamera.yaw += sensX * (invX * m->controller->extStickX - 1.5f * mouse_x); } - - gDjuiHudLockMouse = true; - } else { - gDjuiHudLockMouse = false; } // fix yaw for some specific actions @@ -181,8 +177,6 @@ void first_person_update(void) { } first_person_camera_update(); - } else if (!camera_config_is_mouse_look_enabled()) { - gDjuiHudLockMouse = false; } } diff --git a/src/game/ingame_menu.c b/src/game/ingame_menu.c index 5e7686da..895244c7 100644 --- a/src/game/ingame_menu.c +++ b/src/game/ingame_menu.c @@ -2393,7 +2393,7 @@ void change_dialog_camera_angle(void) { } void shade_screen(void) { - create_dl_translation_matrix(MENU_MTX_PUSH, gfx_dimensions_rect_from_left_edge(0), 240.0f, 0); + create_dl_translation_matrix(MENU_MTX_PUSH, GFX_DIMENSIONS_RECT_FROM_LEFT_EDGE(0), 240.0f, 0); // This is a bit weird. It reuses the dialog text box (width 130, height -80), // so scale to at least fit the screen. @@ -2449,7 +2449,7 @@ void render_pause_red_coins(void) { if (gCurrentArea->numRedCoins > 0) { u8 collected = gCurrentArea->numRedCoins - count_objects_with_behavior(bhvRedCoin); - s16 x = gfx_dimensions_rect_from_left_edge(38); + s16 x = GFX_DIMENSIONS_RECT_FROM_LEFT_EDGE(38); print_animated_red_coin(x - 8, 20); gSPDisplayList(gDisplayListHead++, dl_rgba16_text_begin); gDPSetEnvColor(gDisplayListHead++, 255, 255, 255, gDialogTextAlpha); diff --git a/src/pc/controller/controller_sdl2.c b/src/pc/controller/controller_sdl2.c index 9d7c1f50..dcd64d2f 100644 --- a/src/pc/controller/controller_sdl2.c +++ b/src/pc/controller/controller_sdl2.c @@ -11,21 +11,19 @@ #include -// Analog camera movement by Pathétique (github.com/vrmiguel), y0shin and Mors -// Contribute or communicate bugs at github.com/vrmiguel/sm64-analog-camera - #include #include "controller_api.h" #include "controller_sdl.h" #include "controller_mouse.h" -#include "../configfile.h" -#include "../platform.h" -#include "../fs/fs.h" +#include "pc/pc_main.h" +#include "pc/configfile.h" +#include "pc/platform.h" +#include "pc/fs/fs.h" #include "game/level_update.h" +#include "game/first_person_cam.h" #include "pc/lua/utils/smlua_misc_utils.h" - #include "pc/djui/djui.h" #include "pc/djui/djui_panel_pause.h" #include "pc/djui/djui_hud_utils.h" @@ -170,20 +168,15 @@ static inline void update_button(const int i, const bool new) { } extern s16 gMenuMode; -bool ignore_lock = false; static void controller_sdl_read(OSContPad *pad) { if (!init_ok) { return; } - if (!gDjuiHudLockMouse) { - if (newcam_mouse == 1 && gMenuMode == -1 && !gDjuiInMainMenu && !gDjuiChatBoxFocus && !gDjuiConsoleFocus) { - SDL_SetRelativeMouseMode(SDL_TRUE); - ignore_lock = true; - } else { - SDL_SetRelativeMouseMode(SDL_FALSE); - ignore_lock = false; - } + if ((newcam_mouse == 1 || gFirstPersonCamera.enabled || gDjuiHudLockMouse) && gMenuMode == -1 && !gDjuiInMainMenu && !gDjuiChatBoxFocus && !gDjuiConsoleFocus) { + SDL_SetRelativeMouseMode(SDL_TRUE); + } else { + SDL_SetRelativeMouseMode(SDL_FALSE); } u32 mouse = SDL_GetRelativeMouseState(&mouse_x, &mouse_y); @@ -197,10 +190,6 @@ static void controller_sdl_read(OSContPad *pad) { last_mouse = (mouse_buttons ^ mouse) & mouse; mouse_buttons = mouse; - if (!ignore_lock && gMenuMode == -1 && !gDjuiInMainMenu && !gDjuiChatBoxFocus && !gDjuiConsoleFocus) { - SDL_SetRelativeMouseMode(gDjuiHudLockMouse ? SDL_TRUE : SDL_FALSE); - } - if (configBackgroundGamepad != sBackgroundGamepad) { sBackgroundGamepad = configBackgroundGamepad; SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, sBackgroundGamepad ? "1" : "0"); diff --git a/src/pc/debug_context.c b/src/pc/debug_context.c index a2ac307d..9f09b748 100644 --- a/src/pc/debug_context.c +++ b/src/pc/debug_context.c @@ -4,6 +4,7 @@ #include "debuglog.h" #include "game/print.h" #include "game/hud.h" +#include "gfx_dimensions.h" static u32 sCtxDepth[CTX_MAX] = { 0 }; diff --git a/src/pc/djui/djui_hud_utils.c b/src/pc/djui/djui_hud_utils.c index 3e339cf0..8761d98f 100644 --- a/src/pc/djui/djui_hud_utils.c +++ b/src/pc/djui/djui_hud_utils.c @@ -218,15 +218,8 @@ u32 djui_hud_get_screen_width(void) { u32 windowWidth, windowHeight; wm_api->get_dimensions(&windowWidth, &windowHeight); - if (use_forced_4by3() && sResolution == RESOLUTION_DJUI) { - windowWidth -= (GFX_DIMENSIONS_FROM_LEFT_EDGE(0) + GFX_DIMENSIONS_FROM_RIGHT_EDGE(0)); - } - if (sResolution == RESOLUTION_N64) { - f32 aspect = use_forced_4by3() - ? (4.0f / 3.0f) - : GFX_DIMENSIONS_ASPECT_RATIO; - return (aspect) * SCREEN_HEIGHT; + return (GFX_DIMENSIONS_ASPECT_RATIO) * SCREEN_HEIGHT; } else { return (windowWidth / djui_gfx_get_scale()); } diff --git a/src/pc/pc_main.c b/src/pc/pc_main.c index e120c7b6..5f30aec2 100644 --- a/src/pc/pc_main.c +++ b/src/pc/pc_main.c @@ -217,18 +217,18 @@ void produce_interpolation_frames_and_delay(void) { } inline static void buffer_audio(void) { - const f32 master_mod = (f32)configMasterVolume / 127.0f; - set_sequence_player_volume(SEQ_PLAYER_LEVEL, (f32)configMusicVolume / 127.0f * master_mod); - set_sequence_player_volume(SEQ_PLAYER_SFX, (f32)configSfxVolume / 127.0f * master_mod); - set_sequence_player_volume(SEQ_PLAYER_ENV, (f32)configEnvVolume / 127.0f * master_mod); + const f32 masterMod = (f32)configMasterVolume / 127.0f; + set_sequence_player_volume(SEQ_PLAYER_LEVEL, (f32)configMusicVolume / 127.0f * masterMod); + set_sequence_player_volume(SEQ_PLAYER_SFX, (f32)configSfxVolume / 127.0f * masterMod); + set_sequence_player_volume(SEQ_PLAYER_ENV, (f32)configEnvVolume / 127.0f * masterMod); - int samples_left = audio_api->buffered(); - u32 num_audio_samples = samples_left < audio_api->get_desired_buffered() ? SAMPLES_HIGH : SAMPLES_LOW; - s16 audio_buffer[SAMPLES_HIGH * 2 * 2]; + int samplesLeft = audio_api->buffered(); + u32 numAudioSamples = samplesLeft < audio_api->get_desired_buffered() ? SAMPLES_HIGH : SAMPLES_LOW; + s16 audioBuffer[SAMPLES_HIGH * 2 * 2]; for (s32 i = 0; i < 2; i++) { - create_next_audio_buffer(audio_buffer + i * (num_audio_samples * 2), num_audio_samples); + create_next_audio_buffer(audioBuffer + i * (numAudioSamples * 2), numAudioSamples); } - audio_api->play((u8 *)audio_buffer, 2 * num_audio_samples * 4); + audio_api->play((u8 *)audioBuffer, 2 * numAudioSamples * 4); } void produce_one_frame(void) {