1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-14 19:21:50 +00:00

Merge branch 'onUpdate' into 'master'

Run onUpdate when the game is paused

Closes 

See merge request 
This commit is contained in:
Andrei Kortunov 2025-03-10 07:09:31 +00:00
commit f040cb41fd
8 changed files with 25 additions and 14 deletions
apps/openmw/mwlua
docs/source/reference/lua-scripting
files

@ -203,13 +203,12 @@ namespace MWLua
// Run engine handlers // Run engine handlers
mEngineEvents.callEngineHandlers(); mEngineEvents.callEngineHandlers();
if (!timeManager.isPaused()) bool isPaused = timeManager.isPaused();
{
float frameDuration = MWBase::Environment::get().getFrameDuration(); float frameDuration = MWBase::Environment::get().getFrameDuration();
for (LocalScripts* scripts : mActiveLocalScripts) for (LocalScripts* scripts : mActiveLocalScripts)
scripts->update(frameDuration); scripts->update(isPaused ? 0 : frameDuration);
mGlobalScripts.update(frameDuration); mGlobalScripts.update(isPaused ? 0 : frameDuration);
}
mLua.protectedCall([&](LuaUtil::LuaView& lua) { mScriptTracker.unloadInactiveScripts(lua); }); mLua.protectedCall([&](LuaUtil::LuaView& lua) { mScriptTracker.unloadInactiveScripts(lua); });
} }

@ -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).` | `assigned to a script in openmw-cs (not yet implemented).`
| ``onInterfaceOverride`` can be called before ``onInit``. | ``onInterfaceOverride`` can be called before ``onInit``.
* - onUpdate(dt) * - 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. | the simulation time from the last update in seconds.
* - onSave() -> savedData * - onSave() -> savedData
- | Called when the game is saving. May be called in inactive state, - | Called when the game is saving. May be called in inactive state,

@ -182,6 +182,10 @@ local function updateCrosshair()
end end
local function onUpdate(dt) local function onUpdate(dt)
if dt <=0 then
return
end
camera.setExtraPitch(0) camera.setExtraPitch(0)
camera.setExtraYaw(0) camera.setExtraYaw(0)
camera.setExtraRoll(0) camera.setExtraRoll(0)

@ -41,6 +41,10 @@ end
local initialized = false local initialized = false
local function onUpdate(dt) local function onUpdate(dt)
if dt <= 0 then
return
end
-- The script is loaded before the actor's CharacterController object is initialized, therefore -- 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. -- we have to delay this initialization step or the call won't have any effect.
if not initialized then if not initialized then

@ -96,7 +96,11 @@ local function skillUsedHandler(skillid, params)
end end
end end
local function onUpdate() local function onUpdate(dt)
if dt <=0 then
return
end
if self.cell ~= cell then if self.cell ~= cell then
cell = self.cell cell = self.cell
onCellChange() onCellChange()

@ -11,7 +11,7 @@ local function emitTargetsChanged()
end end
end end
local function onUpdate() local function onUpdate(dt)
if types.Actor.isDeathFinished(self) or not types.Actor.isInActorsProcessingRange(self) then if types.Actor.isDeathFinished(self) or not types.Actor.isInActorsProcessingRange(self) then
if next(targets) ~= nil then if next(targets) ~= nil then
targets = {} targets = {}
@ -21,10 +21,10 @@ local function onUpdate()
return return
end 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 -- TODO: use events or engine handlers to detect when targets change
local isStanceNothing = types.Actor.getStance(self) == types.Actor.STANCE.Nothing 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 return
end end

@ -42,7 +42,7 @@
-- @return #number -- @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 -- @function [parent=#core] isWorldPaused
-- @return #boolean -- @return #boolean

@ -119,7 +119,7 @@
-- @param #number ratio -- @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 -- @function [parent=#world] isWorldPaused
-- @return #boolean -- @return #boolean