From 4fd56166cdefbf9b76e8c232ca35dfe05c7c28cf Mon Sep 17 00:00:00 2001 From: Brues <5278969+brues-code@users.noreply.github.com> Date: Tue, 10 Nov 2026 17:12:40 -0600 Subject: [PATCH] feat(model): a paused scene stops movement and spell visuals too scene:SetPaused stopped only what runs on the M2 scene clock (scene +0x0C): the animations, GetSceneTime and the scene timers. The mover ticked on the OS clock, as the client's does, and the casts stepped by the frame's elapsed time. A paused scene therefore still moved its actors in a frozen pose and flew its missiles. The scene clock is the scene's world time, so the actors now run on it: - The mover (Mover::Init, Mover::Tick) and the body-facing stamps (the catch-up turn of 0x600CD0) read the scene clock through the new Model::Scene::ClockMs. The spline start (b.clock) stays in the same base. Mover::Tick does nothing for a zero window, so a paused scene holds every body. On unpause the body sees only the time the scene ran, so nothing jumps ahead. - Actor::Update takes the ms the scene clock moved this frame, as seconds, for Casts::Update (precasts, missiles, impacts, stuck arrows). That is 0 while paused. OnUpdate keeps the frame's elapsed time. - The move marker's pulse (0x611400's sine over 0x860AE0 ms) reads the scene clock where the world's reads the OS clock, so it holds too. FUN_SIMPLEMODEL_GET_SCENE (0x76CFC0) makes the scene on first use, so a scene frame always has a clock to read. A hidden scene runs no update, so its clock and its actors stop as before. --- docs/API.md | 19 +++++++++++++++---- src/model/Scene.cpp | 31 ++++++++++++++++++------------- src/model/Scene.h | 9 ++++++++- src/model/SceneActor.cpp | 15 +++++++-------- 4 files changed, 48 insertions(+), 26 deletions(-) diff --git a/docs/API.md b/docs/API.md index d301d8d6..3c690c62 100644 --- a/docs/API.md +++ b/docs/API.md @@ -19337,13 +19337,24 @@ current frame. `false` starts the animations again from the same frame. `affectsGlobalPause` has no effect. To pause one actor, use [`actor:SetPaused`](#actorsetpausedpaused--affectsglobalpause--actorgetpaused). -The clock of the scene ([`scene:GetSceneTime`](#scenegetscenetime)) and -the timers of the scene stop with the animations. +These also stop with the animations: + +- The clock of the scene ([`scene:GetSceneTime`](#scenegetscenetime)) and + the timers of the scene. +- The movement of all the actors: walking, running, jumping, falling, + swimming and `MoveTo`. A movement command that you give while the scene is + paused starts when the scene starts again. +- The spell visuals of `PlaySpellVisual`, and missiles in flight. +- The click-to-move marker of `scene:SetMoveMarker`. + +When the scene starts again, each of these continues from where it stopped. +The `OnUpdate` scripts of the actors continue to run while the scene is +paused. ### `scene:GetSceneTime()` Returns the time on the clock of the scene, in seconds. The clock starts -at 0 when the scene is made. The actors animate by this clock. +at 0 when the scene is made. The actors animate and move by this clock. The clock stops while the scene is paused (`scene:SetPaused`) and while the scene is hidden. This is a ClassicAPI extension. @@ -19701,7 +19712,7 @@ scene shows one marker. A new call moves it to the new point. - In a scene with a WMO, the marker lies on the faces of the WMO near the point. In a scene with no WMO, it lies flat at the height of the point. - The marker pulses between 0.5 and 0.75 yards in size, two times each - second. It pulses also while the scene is paused. + second. It stops while the scene is paused. - The marker stays until you call `ClearMoveMarker`. It does not go away when an actor gets to the point. diff --git a/src/model/Scene.cpp b/src/model/Scene.cpp index 75cf9657..ede0092a 100644 --- a/src/model/Scene.cpp +++ b/src/model/Scene.cpp @@ -125,7 +125,6 @@ #include "gx/Matrix.h" #include "model/Camera.h" #include "model/M2.h" -#include "time/Clock.h" #include "time/Timer.h" #include "xml/FrameLoad.h" @@ -547,7 +546,8 @@ void DrawShadowWithStates(Actor &actor, World::Backdrop *world, const float (&ey // ObjectSelectionCircle cvar is on, as the world's (0x00614ADA). Drawn per // actor before its shadow, as the world's per-entity step draws it before // the blob. The marker: the auto-move target's pulsing box (Offsets:: -// VAR_AUTOMOVE_MARKER_*), on the OS clock as the world's, after the actors'. +// VAR_AUTOMOVE_MARKER_*), after the actors', on the scene clock where the +// world's runs on the OS clock: the scene clock is the scene's world time. bool SelectionDecalReady() { return Game::Read(Offsets::VAR_SELECTION_CIRCLE_TEXTURE) != nullptr && @@ -613,7 +613,7 @@ void DrawMoveMarker(void *frame, World::Backdrop *world, const float (&eye)[3]) if (!f.moveMarkerShown) return; const uint32_t period = Game::Read(Offsets::VAR_AUTOMOVE_MARKER_PERIOD_MS); - const uint32_t t = Time::Clock::NowMs() % period; + const uint32_t t = ClockMs(frame) % period; const float low = Game::Read(Offsets::VAR_AUTOMOVE_MARKER_MIN); const float high = Game::Read(Offsets::VAR_AUTOMOVE_MARKER_MAX); const float wave = (std::sin(static_cast(t) * Game::Read(Offsets::VAR_HEADING_TWO_PI) / @@ -990,22 +990,20 @@ void __fastcall OnFrameUpdate(void *self, void *, float elapsedSec) { if (actor->model != nullptr && M2::Parent(actor->model) == nullptr && M2::IsLoaded(actor->model, 0, 0)) World::Settle(*world, *actor->ambience, self, actor->model, elapsedSec); } - void *m2Scene = Model::Pane::Scene(self); - const uint32_t before = m2Scene != nullptr ? Game::Read(m2Scene, Offsets::OFF_M2SCENE_TIME) : 0; + const uint32_t before = ClockMs(self); if (F(self).paused) FrameBase(Offsets::VTBL_FRAME_ON_FRAME_UPDATE)(self, nullptr, elapsedSec); else g_class.Base(Offsets::VTBL_FRAME_ON_FRAME_UPDATE)(self, nullptr, elapsedSec); - // The scene's timers run on its clock, once it has moved this frame. - if (m2Scene != nullptr) { - const uint32_t advancedMs = Game::Read(m2Scene, Offsets::OFF_M2SCENE_TIME) - before; - F(self).clock += advancedMs / 1000.0; - } + // The scene's timers, movement and casts run on its clock, once it has + // moved this frame. + const uint32_t advancedMs = ClockMs(self) - before; + F(self).clock += advancedMs / 1000.0; Time::Timer::Fire(self, F(self).clock); // By index: an actor's script may create another. std::vector &actors = *F(self).actors; for (size_t i = 0; i < actors.size(); ++i) - actors[i]->Update(elapsedSec); + actors[i]->Update(elapsedSec, static_cast(advancedMs) / 1000.0f); UpdateHover(self); } @@ -1944,11 +1942,14 @@ const Game::Doc::Field kFarFogRet[] = {Req("far", "number")}; const Game::Doc::Function kSetDrawLayer{"Sets the layer the scene draws in.", kLayerArg, {}}; const Game::Doc::Function kGetDrawLayer{"Returns the layer the scene draws in.", {}, kLayerRets}; -const Game::Doc::Function kSetPaused{"Stops or restarts the actors' animations.", kPausedArgs, {}}; +const Game::Doc::Function kSetPaused{ + "Stops or restarts the scene: the actors' animations, movement and spell visuals, and the clock and timers " + "of the scene.", + kPausedArgs, {}}; const Game::Doc::Field kSceneTimeRet[] = {Req("seconds", "number")}; const Game::Doc::Function kGetSceneTime{ "Returns the seconds that the clock of the scene has run since the scene was made. The clock " - "stops while the scene is paused or hidden. The actors' animations use this clock.", + "stops while the scene is paused or hidden. The actors animate and move by this clock.", {}, kSceneTimeRet, nullptr, true}; const Game::Doc::Field kTimerArgs[] = {Req("seconds", "number", "On the clock of the scene."), Req("callback", "function")}; @@ -2279,6 +2280,10 @@ Actor *SoundListener(void *sceneFrame) { return F(sceneFrame).listener; } const float *LightAmbient(void *sceneFrame) { return AmbientOf(sceneFrame); } +uint32_t ClockMs(void *sceneFrame) { + return Game::Read(Model::Pane::Scene(sceneFrame), Offsets::OFF_M2SCENE_TIME); +} + View CameraView(void *sceneFrame) { const Fields &f = F(sceneFrame); return {{f.position.x, f.position.y, f.position.z}, diff --git a/src/model/Scene.h b/src/model/Scene.h index b3ff1c50..0bd71dbc 100644 --- a/src/model/Scene.h +++ b/src/model/Scene.h @@ -115,7 +115,9 @@ class Actor : public Animation::Object { // ready model on the scene's animate list. void Link(); // From the scene frame's update walk: load and dress state, scripts. - void Update(float elapsedSec); + // `elapsedSec` is the frame's time (OnUpdate), `sceneSec` the time the + // scene clock moved (casts; 0 while the scene is paused). + void Update(float elapsedSec, float sceneSec); // From the scene's paint, before the scene animates: the model's // placement matrix. void Place(); @@ -471,6 +473,11 @@ World::Backdrop *WorldOf(void *sceneFrame); // takes, as a unit's takes the world light state's ambient. const float *LightAmbient(void *sceneFrame); +// The scene clock in milliseconds (the M2 scene's): the actors' movement runs +// on it as a unit's runs on the OS clock, so it stops while the scene is +// paused or hidden, with the animations. +uint32_t ClockMs(void *sceneFrame); + // The actor the scene's sounds are heard at (SetSoundListenerActor), or null. Actor *SoundListener(void *sceneFrame); diff --git a/src/model/SceneActor.cpp b/src/model/SceneActor.cpp index 78c52dab..3951ae60 100644 --- a/src/model/SceneActor.cpp +++ b/src/model/SceneActor.cpp @@ -175,7 +175,6 @@ #include "model/SceneMover.h" #include "model/VisualKit.h" #include "object/Resolve.h" -#include "time/Clock.h" #include "unit/Identity.h" #include "xml/FrameLoad.h" #include "xml/Mixin.h" @@ -706,7 +705,7 @@ void Advance(Actor &actor) { Mover::Body &body = *actor.mover; World::Backdrop *world = WorldOf(actor.SceneFrame()); body.facets.context = world; - if (!Mover::Tick(body, Time::Clock::NowMs())) + if (!Mover::Tick(body, ClockMs(actor.SceneFrame()))) return; uint32_t type = 0; float surface = 0.0f; @@ -815,7 +814,7 @@ float TurnBody(Actor &actor) { if (absGap > kHalfPi) turn = std::copysign(static_cast(D(absGap) - kHalfPi), gap); if (!(b.flags & 0xC) && !(f.bits & kTurning)) { - const uint32_t ms = Time::Clock::NowMs() - f.stamp; + const uint32_t ms = ClockMs(actor.SceneFrame()) - f.stamp; double catchUp = ((D(ms) * kMsToSec) * b.turnRate) * 8.0; if (catchUp > absGap) catchUp = absGap; @@ -859,7 +858,7 @@ void FaceDisplay(Actor &actor) { f.bits |= kTurning; } else { f.bits &= ~kTurning; - f.stamp = Time::Clock::NowMs(); + f.stamp = ClockMs(actor.SceneFrame()); } } @@ -869,7 +868,7 @@ void ResetFacings(Actor &actor) { Actor::Facings &f = actor.facings; f.display = f.body = actor.mover->facing; f.bits &= ~kTurning; - f.stamp = Time::Clock::NowMs(); + f.stamp = ClockMs(actor.SceneFrame()); } } // namespace @@ -904,7 +903,7 @@ void Actor::ApplyHighlight() { reinterpret_cast(Offsets::FUN_M2MODEL_SET_EMISSIVE)(model, rgb); } -void Actor::Update(float elapsedSec) { +void Actor::Update(float elapsedSec, float sceneSec) { if (mover != nullptr) { Advance(*this); std::memcpy(position, mover->position, sizeof position); @@ -975,7 +974,7 @@ void Actor::Update(float elapsedSec) { } } WriteStringUnit(*this); - Casts::Update(*this, elapsedSec); + Casts::Update(*this, sceneSec); // The casts that reached their target, with (spellID, target, castID). // Taken first: a script may cast again, and its impact waits for the next // update. @@ -1759,7 +1758,7 @@ int __fastcall Script_SetMovementEnabled(void *L) { } if (actor->mover == nullptr) { actor->mover = std::make_unique(); - Mover::Init(*actor->mover, actor->position, actor->yaw, Time::Clock::NowMs()); + Mover::Init(*actor->mover, actor->position, actor->yaw, ClockMs(actor->SceneFrame())); actor->mover->facets.query = &World::QueryFacets; actor->mover->facets.liquidQuery = &World::QueryLiquidFacets; actor->mover->stepped = &Locomotion::OnStep;