From b3426526995f3895b7ac6eb66936961ef7c2950c Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Sat, 21 Dec 2024 11:01:39 +0400 Subject: [PATCH] Run onUpdate when the game is paused --- CMakeLists.txt | 2 +- apps/openmw/mwlua/luamanagerimp.cpp | 13 ++++++------- .../reference/lua-scripting/engine_handlers.rst | 2 +- files/data/scripts/omw/camera/camera.lua | 4 ++++ .../scripts/omw/mechanics/animationcontroller.lua | 4 ++++ .../data/scripts/omw/mechanics/playercontroller.lua | 6 +++++- files/data/scripts/omw/music/actor.lua | 6 +++--- files/lua_api/openmw/core.lua | 2 +- files/lua_api/openmw/world.lua | 2 +- 9 files changed, 26 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 170a56aade..1805ea6fea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,7 +82,7 @@ message(STATUS "Configuring OpenMW...") set(OPENMW_VERSION_MAJOR 0) set(OPENMW_VERSION_MINOR 49) set(OPENMW_VERSION_RELEASE 0) -set(OPENMW_LUA_API_REVISION 70) +set(OPENMW_LUA_API_REVISION 71) set(OPENMW_POSTPROCESSING_API_REVISION 2) set(OPENMW_VERSION_COMMITHASH "") diff --git a/apps/openmw/mwlua/luamanagerimp.cpp b/apps/openmw/mwlua/luamanagerimp.cpp index 780ddaf9a9..2c014c3d72 100644 --- a/apps/openmw/mwlua/luamanagerimp.cpp +++ b/apps/openmw/mwlua/luamanagerimp.cpp @@ -203,13 +203,12 @@ namespace MWLua // Run engine handlers mEngineEvents.callEngineHandlers(); - if (!timeManager.isPaused()) - { - float frameDuration = MWBase::Environment::get().getFrameDuration(); - for (LocalScripts* scripts : mActiveLocalScripts) - scripts->update(frameDuration); - mGlobalScripts.update(frameDuration); - } + bool isPaused = timeManager.isPaused(); + + float frameDuration = MWBase::Environment::get().getFrameDuration(); + for (LocalScripts* scripts : mActiveLocalScripts) + scripts->update(isPaused ? 0 : frameDuration); + mGlobalScripts.update(isPaused ? 0 : frameDuration); mLua.protectedCall([&](LuaUtil::LuaView& lua) { mScriptTracker.unloadInactiveScripts(lua); }); } diff --git a/docs/source/reference/lua-scripting/engine_handlers.rst b/docs/source/reference/lua-scripting/engine_handlers.rst index ac6979a236..aac64b5e39 100644 --- a/docs/source/reference/lua-scripting/engine_handlers.rst +++ b/docs/source/reference/lua-scripting/engine_handlers.rst @@ -24,7 +24,7 @@ Engine handler is a function defined by a script, that can be called by the engi | `assigned to a script in openmw-cs (not yet implemented).` | ``onInterfaceOverride`` can be called before ``onInit``. * - onUpdate(dt) - - | Called every frame if the game is not paused. `dt` is + - | Called every frame in the Lua thread (even if the game is paused). `dt` is | the simulation time from the last update in seconds. * - onSave() -> savedData - | Called when the game is saving. May be called in inactive state, diff --git a/files/data/scripts/omw/camera/camera.lua b/files/data/scripts/omw/camera/camera.lua index 5cd04239f7..bb0d4da6de 100644 --- a/files/data/scripts/omw/camera/camera.lua +++ b/files/data/scripts/omw/camera/camera.lua @@ -182,6 +182,10 @@ local function updateCrosshair() end local function onUpdate(dt) + if dt <=0 then + return + end + camera.setExtraPitch(0) camera.setExtraYaw(0) camera.setExtraRoll(0) diff --git a/files/data/scripts/omw/mechanics/animationcontroller.lua b/files/data/scripts/omw/mechanics/animationcontroller.lua index c7a9182a8e..0324b412ee 100644 --- a/files/data/scripts/omw/mechanics/animationcontroller.lua +++ b/files/data/scripts/omw/mechanics/animationcontroller.lua @@ -41,6 +41,10 @@ end local initialized = false local function onUpdate(dt) + if dt <= 0 then + return + end + -- The script is loaded before the actor's CharacterController object is initialized, therefore -- we have to delay this initialization step or the call won't have any effect. if not initialized then diff --git a/files/data/scripts/omw/mechanics/playercontroller.lua b/files/data/scripts/omw/mechanics/playercontroller.lua index 870f24415c..189d4ddd34 100644 --- a/files/data/scripts/omw/mechanics/playercontroller.lua +++ b/files/data/scripts/omw/mechanics/playercontroller.lua @@ -96,7 +96,11 @@ local function skillUsedHandler(skillid, params) end end -local function onUpdate() +local function onUpdate(dt) + if dt <=0 then + return + end + if self.cell ~= cell then cell = self.cell onCellChange() diff --git a/files/data/scripts/omw/music/actor.lua b/files/data/scripts/omw/music/actor.lua index 8f3ac7915a..02cded7904 100755 --- a/files/data/scripts/omw/music/actor.lua +++ b/files/data/scripts/omw/music/actor.lua @@ -11,7 +11,7 @@ local function emitTargetsChanged() end end -local function onUpdate() +local function onUpdate(dt) if types.Actor.isDeathFinished(self) or not types.Actor.isInActorsProcessingRange(self) then if next(targets) ~= nil then targets = {} @@ -21,10 +21,10 @@ local function onUpdate() return end - -- Early-out for actors without targets and without combat state + -- Early-out for actors without targets and without combat state when the game is not paused -- TODO: use events or engine handlers to detect when targets change local isStanceNothing = types.Actor.getStance(self) == types.Actor.STANCE.Nothing - if isStanceNothing and next(targets) == nil and not AI.isFleeing() then + if isStanceNothing and next(targets) == nil and not AI.isFleeing() and dt > 0 then return end diff --git a/files/lua_api/openmw/core.lua b/files/lua_api/openmw/core.lua index 8a78a52441..888d1503f7 100644 --- a/files/lua_api/openmw/core.lua +++ b/files/lua_api/openmw/core.lua @@ -42,7 +42,7 @@ -- @return #number --- --- Whether the world is paused (onUpdate doesn't work when the world is paused). +-- Whether the world is paused. -- @function [parent=#core] isWorldPaused -- @return #boolean diff --git a/files/lua_api/openmw/world.lua b/files/lua_api/openmw/world.lua index b72120a8e5..6afc835960 100644 --- a/files/lua_api/openmw/world.lua +++ b/files/lua_api/openmw/world.lua @@ -119,7 +119,7 @@ -- @param #number ratio --- --- Whether the world is paused (onUpdate doesn't work when the world is paused). +-- Whether the world is paused. -- @function [parent=#world] isWorldPaused -- @return #boolean