[Lua] Rename onInputUpdate -> onFrame and call it even when the game is on pause (#6745)

pull/3227/head
Petr Mikheev 3 years ago
parent 91c32e65c2
commit 0643685ea5

@ -41,7 +41,7 @@ namespace MWLua
{ {
auto* lua = context.mLua; auto* lua = context.mLua;
sol::table api(lua->sol(), sol::create); sol::table api(lua->sol(), sol::create);
api["API_REVISION"] = 21; api["API_REVISION"] = 22;
api["quit"] = [lua]() api["quit"] = [lua]()
{ {
Log(Debug::Warning) << "Quit requested by a Lua script.\n" << lua->debugTraceback(); Log(Debug::Warning) << "Quit requested by a Lua script.\n" << lua->debugTraceback();

@ -234,8 +234,8 @@ namespace MWLua
playerScripts->processInputEvent(event); playerScripts->processInputEvent(event);
} }
mInputEvents.clear(); mInputEvents.clear();
if (playerScripts && !mWorldView.isPaused()) if (playerScripts)
playerScripts->inputUpdate(MWBase::Environment::get().getFrameDuration()); playerScripts->onFrame(mWorldView.isPaused() ? 0.0 : MWBase::Environment::get().getFrameDuration());
mProcessingInputEvents = false; mProcessingInputEvents = false;
MWBase::WindowManager* windowManager = MWBase::Environment::get().getWindowManager(); MWBase::WindowManager* windowManager = MWBase::Environment::get().getWindowManager();

@ -20,7 +20,7 @@ namespace MWLua
registerEngineHandlers({ registerEngineHandlers({
&mConsoleCommandHandlers, &mKeyPressHandlers, &mKeyReleaseHandlers, &mConsoleCommandHandlers, &mKeyPressHandlers, &mKeyReleaseHandlers,
&mControllerButtonPressHandlers, &mControllerButtonReleaseHandlers, &mControllerButtonPressHandlers, &mControllerButtonReleaseHandlers,
&mActionHandlers, &mInputUpdateHandlers, &mActionHandlers, &mOnFrameHandlers,
&mTouchpadPressed, &mTouchpadReleased, &mTouchpadMoved &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) bool consoleCommand(const std::string& consoleMode, const std::string& command, const sol::object& selectedObject)
{ {
@ -72,7 +72,7 @@ namespace MWLua
EngineHandlerList mControllerButtonPressHandlers{"onControllerButtonPress"}; EngineHandlerList mControllerButtonPressHandlers{"onControllerButtonPress"};
EngineHandlerList mControllerButtonReleaseHandlers{"onControllerButtonRelease"}; EngineHandlerList mControllerButtonReleaseHandlers{"onControllerButtonRelease"};
EngineHandlerList mActionHandlers{"onInputAction"}; EngineHandlerList mActionHandlers{"onInputAction"};
EngineHandlerList mInputUpdateHandlers{"onInputUpdate"}; EngineHandlerList mOnFrameHandlers{"onFrame"};
EngineHandlerList mTouchpadPressed{ "onTouchPress" }; EngineHandlerList mTouchpadPressed{ "onTouchPress" };
EngineHandlerList mTouchpadReleased{ "onTouchRelease" }; EngineHandlerList mTouchpadReleased{ "onTouchRelease" };
EngineHandlerList mTouchpadMoved{ "onTouchMove" }; EngineHandlerList mTouchpadMoved{ "onTouchMove" };

@ -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).` | `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 the time - | Called every frame if the game is not paused. `dt` is
| 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,
| so it shouldn't use `openmw.nearby`. | 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:: .. list-table::
:widths: 20 80 :widths: 20 80
* - onInputUpdate(dt) * - onFrame(dt)
- | Called every frame (if the game is not paused) right after - | Called every frame (even if the game is paused) right after
| processing user input. Use it only for latency-critical stuff. | 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) * - onKeyPress(key)
- | `Key <openmw_input.html##(KeyboardEvent)>`_ is pressed. - | `Key <openmw_input.html##(KeyboardEvent)>`_ is pressed.
| Usage example: | Usage example:

@ -155,7 +155,8 @@ local function onUpdate(dt)
updateSmoothedSpeed(dt) updateSmoothedSpeed(dt)
end end
local function onInputUpdate(dt) local function onFrame(dt)
if core.isWorldPaused() then return end
local mode = camera.getMode() local mode = camera.getMode()
if mode == MODE.FirstPerson or mode == MODE.ThirdPerson then if mode == MODE.FirstPerson or mode == MODE.ThirdPerson then
primaryMode = mode primaryMode = mode
@ -232,7 +233,7 @@ return {
}, },
engineHandlers = { engineHandlers = {
onUpdate = onUpdate, onUpdate = onUpdate,
onInputUpdate = onInputUpdate, onFrame = onFrame,
onInputAction = function(action) onInputAction = function(action)
if core.isWorldPaused() then return end if core.isWorldPaused() then return end
if action == input.ACTION.ZoomIn then if action == input.ACTION.ZoomIn then

@ -74,7 +74,7 @@
--- ---
-- Cast ray from one point to another and find the first visual intersection with anything in the scene. -- 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. -- 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. -- in engine handlers for user input. In other cases use `asyncCastRenderingRay` instead.
-- @function [parent=#nearby] castRenderingRay -- @function [parent=#nearby] castRenderingRay
-- @param openmw.util#Vector3 from Start point of the ray. -- @param openmw.util#Vector3 from Start point of the ray.

Loading…
Cancel
Save