diff --git a/apps/openmw/mwlua/luabindings.cpp b/apps/openmw/mwlua/luabindings.cpp index 3c2023ff5f..dc50d093ca 100644 --- a/apps/openmw/mwlua/luabindings.cpp +++ b/apps/openmw/mwlua/luabindings.cpp @@ -41,7 +41,7 @@ namespace MWLua { auto* lua = context.mLua; sol::table api(lua->sol(), sol::create); - api["API_REVISION"] = 21; + api["API_REVISION"] = 22; api["quit"] = [lua]() { Log(Debug::Warning) << "Quit requested by a Lua script.\n" << lua->debugTraceback(); diff --git a/apps/openmw/mwlua/luamanagerimp.cpp b/apps/openmw/mwlua/luamanagerimp.cpp index 602f32710f..3c458bd7b8 100644 --- a/apps/openmw/mwlua/luamanagerimp.cpp +++ b/apps/openmw/mwlua/luamanagerimp.cpp @@ -234,8 +234,8 @@ namespace MWLua playerScripts->processInputEvent(event); } mInputEvents.clear(); - if (playerScripts && !mWorldView.isPaused()) - playerScripts->inputUpdate(MWBase::Environment::get().getFrameDuration()); + if (playerScripts) + playerScripts->onFrame(mWorldView.isPaused() ? 0.0 : MWBase::Environment::get().getFrameDuration()); mProcessingInputEvents = false; MWBase::WindowManager* windowManager = MWBase::Environment::get().getWindowManager(); diff --git a/apps/openmw/mwlua/playerscripts.hpp b/apps/openmw/mwlua/playerscripts.hpp index 1e909dc72c..eb248ccc40 100644 --- a/apps/openmw/mwlua/playerscripts.hpp +++ b/apps/openmw/mwlua/playerscripts.hpp @@ -20,7 +20,7 @@ namespace MWLua registerEngineHandlers({ &mConsoleCommandHandlers, &mKeyPressHandlers, &mKeyReleaseHandlers, &mControllerButtonPressHandlers, &mControllerButtonReleaseHandlers, - &mActionHandlers, &mInputUpdateHandlers, + &mActionHandlers, &mOnFrameHandlers, &mTouchpadPressed, &mTouchpadReleased, &mTouchpadMoved }); } @@ -57,7 +57,7 @@ namespace MWLua } } - void inputUpdate(float dt) { callEngineHandlers(mInputUpdateHandlers, dt); } + void onFrame(float dt) { callEngineHandlers(mOnFrameHandlers, dt); } bool consoleCommand(const std::string& consoleMode, const std::string& command, const sol::object& selectedObject) { @@ -72,7 +72,7 @@ namespace MWLua EngineHandlerList mControllerButtonPressHandlers{"onControllerButtonPress"}; EngineHandlerList mControllerButtonReleaseHandlers{"onControllerButtonRelease"}; EngineHandlerList mActionHandlers{"onInputAction"}; - EngineHandlerList mInputUpdateHandlers{"onInputUpdate"}; + EngineHandlerList mOnFrameHandlers{"onFrame"}; EngineHandlerList mTouchpadPressed{ "onTouchPress" }; EngineHandlerList mTouchpadReleased{ "onTouchRelease" }; EngineHandlerList mTouchpadMoved{ "onTouchMove" }; diff --git a/docs/source/reference/lua-scripting/engine_handlers.rst b/docs/source/reference/lua-scripting/engine_handlers.rst index 6f24750736..524314341c 100644 --- a/docs/source/reference/lua-scripting/engine_handlers.rst +++ b/docs/source/reference/lua-scripting/engine_handlers.rst @@ -15,8 +15,8 @@ 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 the time - | from the last update in seconds. + - | Called every frame if the game is not 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, | so it shouldn't use `openmw.nearby`. @@ -69,9 +69,11 @@ Engine handler is a function defined by a script, that can be called by the engi .. list-table:: :widths: 20 80 - * - onInputUpdate(dt) - - | Called every frame (if the game is not paused) right after - | processing user input. Use it only for latency-critical stuff. + * - onFrame(dt) + - | Called every frame (even if the game is paused) right after + | processing user input. Use it only for latency-critical stuff + | and for UI that should work on pause. + | `dt` is simulation time delta (0 when on pause). * - onKeyPress(key) - | `Key `_ is pressed. | Usage example: diff --git a/files/builtin_scripts/scripts/omw/camera.lua b/files/builtin_scripts/scripts/omw/camera.lua index 9845135f50..8a614c9ac3 100644 --- a/files/builtin_scripts/scripts/omw/camera.lua +++ b/files/builtin_scripts/scripts/omw/camera.lua @@ -155,7 +155,8 @@ local function onUpdate(dt) updateSmoothedSpeed(dt) end -local function onInputUpdate(dt) +local function onFrame(dt) + if core.isWorldPaused() then return end local mode = camera.getMode() if mode == MODE.FirstPerson or mode == MODE.ThirdPerson then primaryMode = mode @@ -232,7 +233,7 @@ return { }, engineHandlers = { onUpdate = onUpdate, - onInputUpdate = onInputUpdate, + onFrame = onFrame, onInputAction = function(action) if core.isWorldPaused() then return end if action == input.ACTION.ZoomIn then diff --git a/files/lua_api/openmw/nearby.lua b/files/lua_api/openmw/nearby.lua index f290992f33..076d5cebbd 100644 --- a/files/lua_api/openmw/nearby.lua +++ b/files/lua_api/openmw/nearby.lua @@ -74,7 +74,7 @@ --- -- Cast ray from one point to another and find the first visual intersection with anything in the scene. -- As opposite to `castRay` can find an intersection with an object without collisions. --- In order to avoid threading issues can be used only in player scripts only in `onInputUpdate` or +-- In order to avoid threading issues can be used only in player scripts only in `onFrame` or -- in engine handlers for user input. In other cases use `asyncCastRenderingRay` instead. -- @function [parent=#nearby] castRenderingRay -- @param openmw.util#Vector3 from Start point of the ray.