Merge branch 'lua_onframe' into 'master'

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

See merge request OpenMW/openmw!1852
pull/3227/head
uramer 3 years ago
commit be100749f8

@ -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();

@ -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();

@ -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" };

@ -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 <openmw_input.html##(KeyboardEvent)>`_ is pressed.
| Usage example:

@ -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

@ -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.

Loading…
Cancel
Save