From 5ec61a4243ad6a6db69a231cfe7813f0eda0dd36 Mon Sep 17 00:00:00 2001 From: Stavrin Date: Sun, 8 Nov 2026 12:18:24 +0000 Subject: [PATCH 1/2] Free look: mouse control, Free Look Everywhere, smoother orbit; Return skips dialogue Free look - Free Look Mouse: turn the free look camera with the mouse. The mouse is captured while playing (menu or F2 frees it), with sensitivity and per-axis invert options. Any mouse movement enters free look, like the right stick past its threshold; a C-button camera control hands back. - Free Look Everywhere (default on): free look can also take over from the underwater camera and the camera-node (fixed/pivot) cameras, through two new hooks, VB_CAMERA_FIXED_NODE and VB_CAMERA_UNDERWATER. - The orbit no longer uses the follow camera's line-of-sight rescue (func_802BC84C): it kept jumping the camera beside the player, and free look pulled it straight back, so the view snapped back and forth. Frame interpolation - World matrices with no usable previous partner (unpaired, or turned more than 90 degrees) are now moved with the sub-frame's camera, the way the camera-relative fixups already are. Fast camera moves (free look orbit) made the player model jump against the rest of the world for a frame. The world pass in gsworld_draw is marked with WorldRelativePush/Pop. - GetInterpolationFPS falls back to 60 when the window reports a refresh rate of 0 (window saved off-screen), instead of dividing by zero. Cutscenes - Return Skips Dialogue: Return skips the dialogue on screen up to the next question or the end, through the game's own skip (dialog state 6). --- src/core2/ba/ba_camera.c | 9 ++ src/core2/gc/dialog.c | 6 +- src/core2/map/gsworld.c | 2 + src/port/Engine.cpp | 6 + .../Enhancements/Camera/FreeLookCamera.cpp | 152 +++++++++++++++++- src/port/Enhancements/Camera/FreeLookCamera.h | 4 + .../Enhancements/Cutscenes/CutsceneSkips.cpp | 35 ++++ src/port/Enhancements/Events/Hooks/Events.h | 18 +++ src/port/Interpolation/FrameInterpolation.cpp | 50 +++++- src/port/Interpolation/FrameInterpolation.h | 2 + src/port/Interpolation/FramePacing.cpp | 18 ++- src/port/UI/LighthouseMenuEnhancements.cpp | 37 +++++ 12 files changed, 324 insertions(+), 15 deletions(-) diff --git a/src/core2/ba/ba_camera.c b/src/core2/ba/ba_camera.c index f3fa5e615..7beb43445 100644 --- a/src/core2/ba/ba_camera.c +++ b/src/core2/ba/ba_camera.c @@ -69,6 +69,11 @@ int func_80290D48(void){ camera_node_index = func_802903CC(); + // [port] False when the port's camera keeps (or takes) the camera in a fixed-camera area. + if(!EventSystem_Should(VB_CAMERA_FIXED_NODE, true)){ + func_80290BC0(0); + return false; + } if(camera_node_index == -1 || !ncCameraNodeList_nodeIsValid(camera_node_index)){ func_80290BC0(0); return false; @@ -108,6 +113,10 @@ int func_80290E8C(void){ if(player_getWaterState() != BSWATERGROUP_2_UNDERWATER) return false; + // [port] False when the port's camera keeps (or takes) the camera underwater. + if(!EventSystem_Should(VB_CAMERA_UNDERWATER, true)) + return false; + ncDynamicCamera_setState(3); func_80291488(0xB); if( gsworld_getMap() == MAP_B_CC_CLANKERS_CAVERN diff --git a/src/core2/gc/dialog.c b/src/core2/gc/dialog.c index 557165bc7..cc61476e1 100644 --- a/src/core2/gc/dialog.c +++ b/src/core2/gc/dialog.c @@ -7,6 +7,8 @@ #include "core2/gc/zoombox.h" #include "port/ResourceHelpers.h" +int port_dialogueSkipPressed(void); + extern void func_803114D0(void); extern int gcdialog_hasCurrentTextId(void); extern char *dialogBin_get(enum asset_e text_id); @@ -388,6 +390,7 @@ void dialog_update(void) { char *sp4C[8]; ret = -1; + const s32 portSkipPressed = port_dialogueSkipPressed(); // [port] Skip Dialogue (CutsceneSkips.cpp) if (g_Dialog.u8_s.unk128_31 & 0x80) { controller_copyFaceButtonsPrimary(0, controller_face_buttons); @@ -636,7 +639,8 @@ void dialog_update(void) { break; case DIALOG_STATE_3: - if ((g_Dialog.u8_s.unk128_31 & 1) && controller_face_buttons[FACE_BUTTON(BUTTON_B)] == 1u) { + if (((g_Dialog.u8_s.unk128_31 & 1) && controller_face_buttons[FACE_BUTTON(BUTTON_B)] == 1u) || + portSkipPressed) { dialog_setState(DIALOG_STATE_6); break; } diff --git a/src/core2/map/gsworld.c b/src/core2/map/gsworld.c index 79cdd9758..2374a36ea 100644 --- a/src/core2/map/gsworld.c +++ b/src/core2/map/gsworld.c @@ -53,6 +53,7 @@ void gsworld_draw(Gfx** gfx, Mtx **mtx, Vtx **vtx) { core2_34790_getClipDistances(&near, &far); viewport_setNearAndFar(near, far); viewport_setRenderViewportAndPerspectiveMatrix(gfx, mtx); + FrameInterpolation_WorldRelativePush(); // [port] see FrameInterpolation.cpp if (mapModel_has_xlu_bin()) { FrameInterpolation_RecordOpenChild("map_opa", 0); @@ -133,6 +134,7 @@ void gsworld_draw(Gfx** gfx, Mtx **mtx, Vtx **vtx) { if (!game_is_frozen()) { func_802BBD0C(gfx, mtx, vtx); } + FrameInterpolation_WorldRelativePop(); spawnQueue_lock(); } diff --git a/src/port/Engine.cpp b/src/port/Engine.cpp index dbe45ff7e..9118a7b9f 100644 --- a/src/port/Engine.cpp +++ b/src/port/Engine.cpp @@ -474,6 +474,8 @@ void GameEngine::ArchivesChanged() { port_spriteDisplayCache_clear(); } +extern "C" void port_dialogueSkipKey(void); + void GameEngine::StartFrame() const { using Ship::KbScancode; const int32_t dwScancode = this->context->GetWindow()->GetLastScancode(); @@ -490,6 +492,10 @@ void GameEngine::StartFrame() const { // gNextGameState = GSTATE_BOOT; break; } + // Skip Dialogue (Enhancements/Cutscenes/CutsceneSkips.cpp) + case KbScancode::LUS_KB_ENTER: + port_dialogueSkipKey(); + break; default: break; } diff --git a/src/port/Enhancements/Camera/FreeLookCamera.cpp b/src/port/Enhancements/Camera/FreeLookCamera.cpp index 234c3e78d..da7cd4835 100644 --- a/src/port/Enhancements/Camera/FreeLookCamera.cpp +++ b/src/port/Enhancements/Camera/FreeLookCamera.cpp @@ -1,8 +1,11 @@ // Free look camera +#include #include #include +#include +#include #include "port/UI/cvar_prefixes.h" #include "port/Controller/ControlSchemes.h" @@ -11,6 +14,8 @@ #include "port/Enhancements/Events/Hooks/Events.h" #include "port/ShipInit.hpp" +extern "C" int globalTimer_getTime(void); + namespace { using namespace PortCamera; @@ -20,6 +25,11 @@ using namespace PortCamera; #define CVAR_FREELOOK_INVERT_X CVAR_ENHANCEMENT("Camera.FreeLook.InvertX") #define CVAR_FREELOOK_INVERT_Y CVAR_ENHANCEMENT("Camera.FreeLook.InvertY") #define CVAR_FREELOOK_SMOOTH_RATE CVAR_ENHANCEMENT("Camera.FreeLook.SmoothRate") +#define CVAR_FREELOOK_MOUSE CVAR_ENHANCEMENT("Camera.FreeLook.Mouse") +#define CVAR_FREELOOK_MOUSE_SENS CVAR_ENHANCEMENT("Camera.FreeLook.MouseSensitivity") +#define CVAR_FREELOOK_MOUSE_INVERT_X CVAR_ENHANCEMENT("Camera.FreeLook.MouseInvertX") +#define CVAR_FREELOOK_MOUSE_INVERT_Y CVAR_ENHANCEMENT("Camera.FreeLook.MouseInvertY") +#define CVAR_FREELOOK_EVERYWHERE CVAR_ENHANCEMENT("Camera.FreeLook.Everywhere") constexpr float kDeadzone = 0.15f; constexpr float kEnterThreshold = 0.30f; @@ -36,11 +46,26 @@ constexpr float kDampRatio = 4.0f; constexpr float kRadToDeg = 57.29577951308232f; +// Mouse free look turns the camera by a fixed angle per pixel the mouse moves (not a speed, like +// the stick), so a given hand movement always turns it the same amount: degrees per pixel at 100% +// Mouse Sensitivity. +constexpr float kMouseDegreesPerPixel = 0.2f; +constexpr int kDefaultMouseSensitivity = 50; +// Mouse movement older than this when the camera next asks (a cutscene, a menu, a load) is dropped +// rather than turning the camera all at once. +constexpr double kMouseStaleSeconds = 0.1; + bool sActive = false; bool sAimValid = false; float sPitch = 0.0f; float sAimY = 0.0f; +float sMouseYaw = 0.0f; // degrees the mouse has turned since the last camera update +float sMousePitch = 0.0f; +bool sMouseCaptureApplied = false; +int sPolledFrame = -1; // the game frame the mouse was last read in +bool sMouseMovedThisFrame = false; + float SpringGain() { return CVarGetFloat(CVAR_FREELOOK_SMOOTH_RATE, kDefaultSmooth) * kSmoothToGain; } @@ -76,6 +101,78 @@ float CapturePitch() { return clampf(std::asin(clampf(-diff[1] / dist, -1.0f, 1.0f)) * kRadToDeg, kMinPitch, kMaxPitch); } +// --- mouse ------------------------------------------------------------------------------------- + +bool MouseEnabled() { + return port_freeLook_isEnabled() && CVarGetInteger(CVAR_FREELOOK_MOUSE, 0) != 0; +} + +// Keeps the window's mouse capture in step with the setting: the mouse is captured (pointer hidden, +// raw movement read) while playing. libultraship frees it while a menu is open and F2 toggles it. +void SyncMouseCapture() { + const bool want = MouseEnabled(); + if (want == sMouseCaptureApplied) { + return; + } + sMouseCaptureApplied = want; + auto window = Ship::Context::GetRawInstance()->GetWindow(); + window->SetAutoCaptureMouse(want); + window->GetMouseStateManager()->UpdateMouseCapture(); +} + +void ClearMouse() { + sMouseYaw = 0.0f; + sMousePitch = 0.0f; +} + +// Adds the mouse's movement since the last call to sMouseYaw/sMousePitch. Returns true if it moved. +bool PollMouse() { + using Clock = std::chrono::steady_clock; + static Clock::time_point sLastPoll; + auto window = Ship::Context::GetRawInstance()->GetWindow(); + const Ship::Coords delta = window->GetMouseDelta(); // read every time, so movement doesn't pile up + const Clock::time_point now = Clock::now(); + const bool stale = std::chrono::duration(now - sLastPoll).count() > kMouseStaleSeconds; + sLastPoll = now; + if (!MouseEnabled() || !window->IsMouseCaptured() || stale || (delta.x == 0 && delta.y == 0)) { + return false; + } + const float perPixel = + kMouseDegreesPerPixel * CVarGetInteger(CVAR_FREELOOK_MOUSE_SENS, kDefaultMouseSensitivity) / 100.0f; + const bool invertX = CVarGetInteger(CVAR_FREELOOK_MOUSE_INVERT_X, 0) != 0; + const bool invertY = CVarGetInteger(CVAR_FREELOOK_MOUSE_INVERT_Y, 0) != 0; + // Mouse right turns the view right (the orbit yaw goes down); mouse up looks up (the pitch goes up, + // taking the camera lower). + sMouseYaw += -delta.x * perPixel * (invertX ? -1.0f : 1.0f); + sMousePitch += -delta.y * perPixel * (invertY ? -1.0f : 1.0f); + return true; +} + +// Reads the mouse once per game frame (the swivel check and the fixed-camera checks all ask). +bool MouseMovedThisFrame() { + const int frame = globalTimer_getTime(); + if (frame != sPolledFrame) { + sPolledFrame = frame; + sMouseMovedThisFrame = PollMouse(); + } + return sMouseMovedThisFrame; +} + +// --- entering and leaving --------------------------------------------------------------------- + +bool Everywhere() { + return CVarGetInteger(CVAR_FREELOOK_EVERYWHERE, 1) != 0; +} + +// Camera states free look can take over from: the follow cameras, and with Free Look Everywhere, +// the underwater camera (3) and the fixed cameras of camera-node areas (8: pivot, 0x11: zoom). +bool CanEnterFrom(int state) { + if (state == 0xB || state == 0x1 || state == 0xA) { + return true; + } + return Everywhere() && (state == 0x3 || state == 0x8 || state == 0x11); +} + void EnterOrbit() { func_802C0150(2); func_802BE230(SpringGain(), SpringGain() * kDampRatio); @@ -97,10 +194,14 @@ void ExitOrbit() { } bool HandleInput() { + SyncMouseCapture(); + const bool mouseMoved = MouseMovedThisFrame(); + if (!port_freeLook_isEnabled()) { if (sActive) { ExitOrbit(); } + ClearMouse(); return false; } @@ -109,32 +210,55 @@ bool HandleInput() { if (sActive) { if (state != FREELOOK_CAM_STATE) { sActive = false; + ClearMouse(); return false; } if (ManualCameraControl()) { ExitOrbit(); + ClearMouse(); return false; } return true; } if (ManualCameraControl()) { + ClearMouse(); return false; } - if (state != 0xB && state != 0x1 && state != 0xA) { + if (!CanEnterFrom(state)) { + ClearMouse(); return false; } + // The stick takes over past a threshold; any mouse movement takes over at once. float stick[2]; - if (ReadStick(stick) >= kEnterThreshold) { + if (ReadStick(stick) >= kEnterThreshold || mouseMoved) { EnterOrbit(); return true; } + ClearMouse(); return false; } +// Free Look Everywhere: asked by the underwater camera and the camera-node (fixed camera) areas +// before they take the camera. True while free look holds the camera, or when the stick or mouse +// asks for it this frame, so they leave it to free look. A C-button camera control hands it back. +bool TakesOverFixedCamera() { + if (!port_freeLook_isEnabled() || !Everywhere()) { + return false; + } + if (sActive && ncDynamicCamera_getState() == FREELOOK_CAM_STATE) { + return !ManualCameraControl(); + } + if (ManualCameraControl()) { + return false; + } + float stick[2]; + return ReadStick(stick) >= kEnterThreshold || MouseMovedThisFrame(); +} + void UpdateOrbit() { float dt = time_getDelta(); @@ -149,6 +273,11 @@ void UpdateOrbit() { D_8037DB70 = mlNormalizeAngle(D_8037DB70 + (invertX ? -stick[0] : stick[0]) * kYawSpeed * yawSens * dt); sPitch = clampf(sPitch + (invertY ? stick[1] : -stick[1]) * kPitchSpeed * pitchSens * dt, kMinPitch, kMaxPitch); + // The mouse: the angle it moved since the last update, whatever the frame time. + D_8037DB70 = mlNormalizeAngle(D_8037DB70 + sMouseYaw); + sPitch = clampf(sPitch + sMousePitch, kMinPitch, kMaxPitch); + ClearMouse(); + float focus[3]; float offset[3]; float target[3]; @@ -161,10 +290,12 @@ void UpdateOrbit() { func_802C0394(target); func_802BE190(target); + // Keep the camera out of walls, but don't use the follow camera's line-of-sight rescue + // (func_802BC84C): when the player has been hidden from the camera for a few frames it jumps the + // camera to a spot beside them, and free look pulls it straight back to where the player put it, + // over and over, so the view (and the player in it) kept jumping and snapping back. if (func_802BE60C()) { - if (!func_802BC84C(1)) { - func_802C03BC(); - } + func_802C03BC(); func_802C04B0(); } @@ -195,6 +326,17 @@ void RegisterFreeLookCamera_Init() { UpdateOrbit(); } }); + // Free Look Everywhere: the fixed-camera areas and the underwater camera leave the camera to free look. + COND_VB_SHOULD(VB_CAMERA_FIXED_NODE, EVENT_PRIORITY_NORMAL, true, { + if (TakesOverFixedCamera()) { + *should = false; + } + }); + COND_VB_SHOULD(VB_CAMERA_UNDERWATER, EVENT_PRIORITY_NORMAL, true, { + if (TakesOverFixedCamera()) { + *should = false; + } + }); } static RegisterShipInitFunc initFreeLookCamera(RegisterFreeLookCamera_Init, {}); diff --git a/src/port/Enhancements/Camera/FreeLookCamera.h b/src/port/Enhancements/Camera/FreeLookCamera.h index 7007e23c1..6202fa19f 100644 --- a/src/port/Enhancements/Camera/FreeLookCamera.h +++ b/src/port/Enhancements/Camera/FreeLookCamera.h @@ -15,6 +15,10 @@ // tracks the vanilla zoom level (shared with the modern-scheme camera), so the // zoom controls re-zoom in place. Returns to the normal camera when the player // rotates or enters first-person via a C-button camera control. +// +// The mouse can turn it too (Free Look Mouse), and with Free Look Everywhere it can also take over +// from the underwater camera and the fixed cameras of camera-node areas (VB_CAMERA_FIXED_NODE, +// VB_CAMERA_UNDERWATER). #define FREELOOK_CAM_STATE 0x14 diff --git a/src/port/Enhancements/Cutscenes/CutsceneSkips.cpp b/src/port/Enhancements/Cutscenes/CutsceneSkips.cpp index 7f2cc65b2..2b7ef5e19 100644 --- a/src/port/Enhancements/Cutscenes/CutsceneSkips.cpp +++ b/src/port/Enhancements/Cutscenes/CutsceneSkips.cpp @@ -9,6 +9,10 @@ #include "port/Romhack/RomhackConfig.h" #include "port/ShipInit.hpp" +#include +#include +#include + extern "C" { #include "enums.h" int getGameMode(void); @@ -28,6 +32,37 @@ s32 globalTimer_getTime(void); #define CVAR_SKIP_CLUCKER_CUTSCENE CVAR_ENHANCEMENT("Cutscenes.SkipCluckerCutscene") #define CVAR_SKIP_NOTEDOOR_DANCE CVAR_ENHANCEMENT("Cutscenes.SkipNoteDoorDance") #define CVAR_TRIGGER_FF_PARADE CVAR_DEVELOPER_TOOLS("TriggerFFParade") +#define CVAR_SKIP_DIALOGUE CVAR_ENHANCEMENT("Cutscenes.SkipDialogueWithReturn") + +// Skip Dialogue: Return skips the rest of the dialogue on screen, the way the game's own B skip does +// for dialogue it lets you skip: up to the next question, or to the end. The key comes from the +// window (Engine.cpp, like the save state keys); dialog_update (dialog.c) takes it on the game +// thread. A press that no dialogue takes soon after is dropped, so it can't skip a later one. +namespace { +std::atomic sSkipPressedAt{ 0 }; + +int64_t NowMs() { + return std::chrono::duration_cast( + std::chrono::steady_clock::now().time_since_epoch()) + .count(); +} +} // namespace + +extern "C" void port_dialogueSkipKey(void) { + if (CVarGetInteger(CVAR_SKIP_DIALOGUE, 0) == 0) { + return; + } + // Not while using the menus. + if (ImGui::GetCurrentContext() != nullptr && ImGui::GetIO().WantCaptureKeyboard) { + return; + } + sSkipPressedAt = NowMs(); +} + +extern "C" int port_dialogueSkipPressed(void) { + const int64_t at = sSkipPressedAt.exchange(0); + return at != 0 && NowMs() - at < 300 ? 1 : 0; +} // Vanilla holds back Start-to-skip on the Rareware logo at first boot. This lets it through 30 frames after boot. void RegisterSkipBootLogos_Init() { diff --git a/src/port/Enhancements/Events/Hooks/Events.h b/src/port/Enhancements/Events/Hooks/Events.h index 143f03e2a..8716d4823 100644 --- a/src/port/Enhancements/Events/Hooks/Events.h +++ b/src/port/Enhancements/Events/Hooks/Events.h @@ -71,6 +71,24 @@ typedef enum VBehaviorID { // - None VB_CAMERA_SWIVEL, + // A camera-node area (fixed or pivoting camera) is about to take the camera. + // #### `result` + // ```c + // true + // ``` + // #### `args` + // - None + VB_CAMERA_FIXED_NODE, + + // The underwater camera is about to take the camera. + // #### `result` + // ```c + // true + // ``` + // #### `args` + // - None + VB_CAMERA_UNDERWATER, + // Cutscene and celebration skips // #### `result` diff --git a/src/port/Interpolation/FrameInterpolation.cpp b/src/port/Interpolation/FrameInterpolation.cpp index a8d4fd90f..1ed65b3f8 100644 --- a/src/port/Interpolation/FrameInterpolation.cpp +++ b/src/port/Interpolation/FrameInterpolation.cpp @@ -29,6 +29,7 @@ struct ToMtxData { uint64_t pathSig; bool noInterpolate; bool camRelFixup; + bool worldRel; // drawn by the world pass relative to the camera (gsworld.c) bool ambiguousSig; }; @@ -140,6 +141,9 @@ struct InterpolationCache { std::vector pairedAnimVtxs; std::vector pairedProjRots; std::vector camRelFixups; + // World matrices with no usable previous partner (unpaired, or turned too far to blend): drawn + // at this tick's position, moved by the sub-frame's camera so they stay put in the world. + std::vector worldFixups; float cameraDelta[3] = { 0.0f, 0.0f, 0.0f }; bool hasCameraDelta = false; bool prevHasCameraPos = false; @@ -153,6 +157,7 @@ struct InterpolationCache { pairedAnimVtxs.clear(); pairedProjRots.clear(); camRelFixups.clear(); + worldFixups.clear(); hasCameraDelta = false; prevHasCameraPos = false; } @@ -172,6 +177,7 @@ bool gRecording = false; bool gShouldInterpolate = true; int gNoInterpolateDepth = 0; int gCameraRelativeDepth = 0; +int gWorldDepth = 0; std::unordered_map gIdMap; uint64_t gNextId = 1; @@ -249,6 +255,7 @@ void FrameInterpolation_StartRecord(void) { gShouldInterpolate = true; gNoInterpolateDepth = 0; gCameraRelativeDepth = 0; + gWorldDepth = 0; gRecording = true; } @@ -370,6 +377,7 @@ void FrameInterpolation_RecordMatrixToMtx(void* dst, const float src[4][4]) { d.pathSig = sig; d.noInterpolate = (gNoInterpolateDepth > 0 || gCameraRelativeDepth > 0); d.camRelFixup = (gCameraRelativeDepth > 0); + d.worldRel = (gWorldDepth > 0); d.ambiguousSig = false; recordSigCollision(gRecord->sigToToMtx, gRecord->toMtxs, sig, idx, gRecord->sigCollisions, gRecord->scopeStack); } @@ -418,6 +426,18 @@ void FrameInterpolation_NoInterpolatePop(void) { } } +// The world pass (gsworld.c): its matrices hold positions relative to the camera, so one drawn +// without blending must still follow the blended camera or it jumps against everything else. +void FrameInterpolation_WorldRelativePush(void) { + gWorldDepth++; +} + +void FrameInterpolation_WorldRelativePop(void) { + if (gWorldDepth > 0) { + gWorldDepth--; + } +} + void FrameInterpolation_CameraRelativePush(void) { gCameraRelativeDepth++; } @@ -611,18 +631,33 @@ void BuildInterpolationCache() { } continue; } - if (c.noInterpolate || c.ambiguousSig) { + if (c.noInterpolate) { + continue; + } + const bool fixWorld = c.worldRel && gCache.hasCameraDelta; + if (c.ambiguousSig) { + if (fixWorld) { + gCache.worldFixups.push_back(i); + } continue; } auto it = prevSigMap.find(c.pathSig); if (it == prevSigMap.end() || it->second >= prevToMtxs.size()) { + if (fixWorld) { + gCache.worldFixups.push_back(i); + } continue; } const ToMtxData& p = prevToMtxs[it->second]; if (std::memcmp(p.src, c.src, sizeof(c.src)) == 0) { continue; } - gCache.pairedToMtxs.push_back({ i, it->second, shouldSnap(p.src, c.src) }); + const bool snap = shouldSnap(p.src, c.src); + if (snap && fixWorld) { + gCache.worldFixups.push_back(i); + continue; + } + gCache.pairedToMtxs.push_back({ i, it->second, snap }); } // Sprites whose inputs didn't move at all are dropped for the same @@ -854,7 +889,7 @@ void FrameInterpolation_Interpolate(float t, std::unordered_map& rep const std::vector& prevSpritesData = gRenderPrev->sprites; const std::vector& currSpritesData = gRenderCurr->sprites; - replacements.reserve(gCache.pairedToMtxs.size() + gCache.pairedSprites.size() + gCache.camRelFixups.size() + + replacements.reserve(gCache.pairedToMtxs.size() + gCache.pairedSprites.size() + gCache.camRelFixups.size() + gCache.worldFixups.size() + gRenderCurr->projRots.size() * 3); const float w = 1.0f - t; @@ -868,6 +903,15 @@ void FrameInterpolation_Interpolate(float t, std::unordered_map& rep } } + for (uint32_t idx : gCache.worldFixups) { + const ToMtxData& c = currToMtxs[idx]; + MtxF& out = replacements[reinterpret_cast(c.dst)]; + std::memcpy(out.mf, c.src, sizeof(out.mf)); + for (int k = 0; k < 3; k++) { + out.mf[3][k] += w * gCache.cameraDelta[k]; + } + } + for (const PairedToMtx& pair : gCache.pairedToMtxs) { const ToMtxData& c = currToMtxs[pair.currIdx]; const ToMtxData& p = prevToMtxs[pair.prevIdx]; diff --git a/src/port/Interpolation/FrameInterpolation.h b/src/port/Interpolation/FrameInterpolation.h index 0f1999a22..1f4af79ae 100644 --- a/src/port/Interpolation/FrameInterpolation.h +++ b/src/port/Interpolation/FrameInterpolation.h @@ -60,6 +60,8 @@ void FrameInterpolation_NoInterpolatePush(void); void FrameInterpolation_NoInterpolatePop(void); // Like NoInterpolatePush, but keeps the camera half of the transform live. +void FrameInterpolation_WorldRelativePush(void); +void FrameInterpolation_WorldRelativePop(void); void FrameInterpolation_CameraRelativePush(void); void FrameInterpolation_CameraRelativePop(void); diff --git a/src/port/Interpolation/FramePacing.cpp b/src/port/Interpolation/FramePacing.cpp index 07d37a4b9..31cb77681 100644 --- a/src/port/Interpolation/FramePacing.cpp +++ b/src/port/Interpolation/FramePacing.cpp @@ -299,14 +299,20 @@ void GameEngine::ProcessGfxCommands(Gfx* commands) { } uint32_t GameEngine::GetInterpolationFPS() { + // The window can report a refresh rate of 0 (e.g. when it starts off-screen or minimized, from a + // saved position of -32000): fall back to 60 rather than divide by zero when pacing frames. + uint32_t refresh = Ship::Context::GetRawInstance()->GetWindow()->GetCurrentRefreshRate(); + if (refresh == 0) { + refresh = 60; + } + uint32_t fps; if (CVarGetInteger(CVAR_SETTING("MatchRefreshRate"), 0)) { - return Ship::Context::GetRawInstance()->GetWindow()->GetCurrentRefreshRate(); - + fps = refresh; } else if (CVarGetInteger(CVAR_VSYNC_ENABLED, 1) || !Ship::Context::GetRawInstance()->GetWindow()->CanDisableVerticalSync()) { - return std::min(Ship::Context::GetRawInstance()->GetWindow()->GetCurrentRefreshRate(), - CVarGetInteger(CVAR_SETTING("InterpolationFPS"), 60)); + fps = std::min(refresh, CVarGetInteger(CVAR_SETTING("InterpolationFPS"), 60)); + } else { + fps = CVarGetInteger(CVAR_SETTING("InterpolationFPS"), 30); } - - return CVarGetInteger(CVAR_SETTING("InterpolationFPS"), 30); + return fps > 0 ? fps : 30; } diff --git a/src/port/UI/LighthouseMenuEnhancements.cpp b/src/port/UI/LighthouseMenuEnhancements.cpp index 552dbdfb7..4c792c81e 100644 --- a/src/port/UI/LighthouseMenuEnhancements.cpp +++ b/src/port/UI/LighthouseMenuEnhancements.cpp @@ -117,6 +117,12 @@ void LighthouseMenu::AddMenuEnhancements() { .RaceDisable(false) .Options(CheckboxOptions().Tooltip("Skips Banjo's dance when a note door opens, opening it immediately.")); + AddWidget(path, "Return Skips Dialogue", WIDGET_CVAR_CHECKBOX) + .CVar(CVAR_ENHANCEMENT("Cutscenes.SkipDialogueWithReturn")) + .RaceDisable(false) + .Options(CheckboxOptions().Tooltip("Press Return (Enter) to skip the rest of the dialogue on screen, up to the " + "next question or the end.")); + // Enhancements -> Graphics path = { "Enhancements", "Graphics", SECTION_COLUMN_1 }; AddSidebarEntry("Enhancements", path.sidebarName, 2); @@ -217,6 +223,37 @@ void LighthouseMenu::AddMenuEnhancements() { .RaceDisable(false) .Options(CheckboxOptions().Tooltip("Inverts the vertical free look direction.")); + AddWidget(path, "Free Look Everywhere", WIDGET_CVAR_CHECKBOX) + .CVar(CVAR_ENHANCEMENT("Camera.FreeLook.Everywhere")) + .RaceDisable(false) + .Options(CheckboxOptions().DefaultValue(true).Tooltip( + "Free look also works underwater and in rooms with a fixed camera. The game's camera stays until " + "you move the stick or mouse; a C-button camera control gives it back.")); + + AddWidget(path, "Free Look Mouse", WIDGET_CVAR_CHECKBOX) + .CVar(CVAR_ENHANCEMENT("Camera.FreeLook.Mouse")) + .RaceDisable(false) + .Options(CheckboxOptions().Tooltip( + "Turn the free look camera with the mouse (needs Free Look on). The mouse is captured while " + "you play: open the menu or press F2 to free it. Like the right stick, a C-button camera " + "control returns to the normal camera until the mouse moves again.")); + + AddWidget(path, "Mouse Sensitivity", WIDGET_CVAR_SLIDER_INT) + .CVar(CVAR_ENHANCEMENT("Camera.FreeLook.MouseSensitivity")) + .RaceDisable(false) + .Options(IntSliderOptions().Min(1).Max(200).DefaultValue(50).ShowButtons(true).Format("%d%%").Tooltip( + "How far the camera turns for each bit of mouse movement: 100% is 0.2 degrees a pixel.")); + + AddWidget(path, "Mouse Invert X", WIDGET_CVAR_CHECKBOX) + .CVar(CVAR_ENHANCEMENT("Camera.FreeLook.MouseInvertX")) + .RaceDisable(false) + .Options(CheckboxOptions().Tooltip("Inverts the horizontal mouse direction.")); + + AddWidget(path, "Mouse Invert Y", WIDGET_CVAR_CHECKBOX) + .CVar(CVAR_ENHANCEMENT("Camera.FreeLook.MouseInvertY")) + .RaceDisable(false) + .Options(CheckboxOptions().Tooltip("Inverts the vertical mouse direction.")); + AddWidget(path, "Free Look Smoothing", WIDGET_CVAR_SLIDER_FLOAT) .CVar(CVAR_ENHANCEMENT("Camera.FreeLook.SmoothRate")) .RaceDisable(false) From 8a54ee44ab1c5dd39e97fd69aa056e5d4b7a19d5 Mon Sep 17 00:00:00 2001 From: Stavrin Date: Sun, 8 Nov 2026 16:16:41 +0000 Subject: [PATCH 2/2] =?UTF-8?q?Stopped=20it=20being=20possible=20to=20free?= =?UTF-8?q?=20look=20control=20the=20camera=20in=20the=20demo=20that=20run?= =?UTF-8?q?s=20behind=20=E2=80=9CPress=20Start=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Enhancements/Camera/FreeLookCamera.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/port/Enhancements/Camera/FreeLookCamera.cpp b/src/port/Enhancements/Camera/FreeLookCamera.cpp index da7cd4835..1adc7fe09 100644 --- a/src/port/Enhancements/Camera/FreeLookCamera.cpp +++ b/src/port/Enhancements/Camera/FreeLookCamera.cpp @@ -14,7 +14,11 @@ #include "port/Enhancements/Events/Hooks/Events.h" #include "port/ShipInit.hpp" -extern "C" int globalTimer_getTime(void); +extern "C" { +#include "enums.h" +int globalTimer_getTime(void); +int getGameMode(void); +} namespace { using namespace PortCamera; @@ -160,6 +164,12 @@ bool MouseMovedThisFrame() { // --- entering and leaving --------------------------------------------------------------------- +// Free look only starts while the player is playing: not in the attract demo behind "Press Start" +// or the file select playback, where the game is moving Banjo, nor in the pause menu. +bool Playing() { + return getGameMode() == GAME_MODE_3_NORMAL; +} + bool Everywhere() { return CVarGetInteger(CVAR_FREELOOK_EVERYWHERE, 1) != 0; } @@ -205,6 +215,11 @@ bool HandleInput() { return false; } + if (!Playing()) { + ClearMouse(); + return sActive; // paused mid-orbit: keep it for when play resumes, but never start one + } + int state = ncDynamicCamera_getState(); if (sActive) { @@ -246,7 +261,7 @@ bool HandleInput() { // before they take the camera. True while free look holds the camera, or when the stick or mouse // asks for it this frame, so they leave it to free look. A C-button camera control hands it back. bool TakesOverFixedCamera() { - if (!port_freeLook_isEnabled() || !Everywhere()) { + if (!port_freeLook_isEnabled() || !Everywhere() || !Playing()) { return false; } if (sActive && ncDynamicCamera_getState() == FREELOOK_CAM_STATE) {