1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-29 22:20:33 +00:00

Merge branch 'camera_script' into 'master'

[Lua] Support tags in I.Camera.disable*, I.Camera.enable* in the same way as in world.pause

Closes #6652

See merge request OpenMW/openmw!3419
This commit is contained in:
psi29a 2023-10-05 17:24:24 +00:00
commit 68684d3d0d
3 changed files with 87 additions and 49 deletions

View File

@ -39,10 +39,10 @@ end
local primaryMode local primaryMode
local noModeControl = 0 local noModeControl = {}
local noStandingPreview = 0 local noStandingPreview = {}
local noHeadBobbing = 0 local noHeadBobbing = {}
local noZoom = 0 local noZoom = {}
local function init() local function init()
camera.setFieldOfView(camera.getBaseFieldOfView()) camera.setFieldOfView(camera.getBaseFieldOfView())
@ -117,19 +117,19 @@ local maxDistance = 800
local function zoom(delta) local function zoom(delta)
if not input.getControlSwitch(input.CONTROL_SWITCH.ViewMode) or if not input.getControlSwitch(input.CONTROL_SWITCH.ViewMode) or
not input.getControlSwitch(input.CONTROL_SWITCH.Controls) or not input.getControlSwitch(input.CONTROL_SWITCH.Controls) or
camera.getMode() == MODE.Static or noZoom > 0 then camera.getMode() == MODE.Static or next(noZoom) then
return return
end end
if camera.getMode() ~= MODE.FirstPerson then if camera.getMode() ~= MODE.FirstPerson then
local obstacleDelta = third_person.preferredDistance - camera.getThirdPersonDistance() local obstacleDelta = third_person.preferredDistance - camera.getThirdPersonDistance()
if delta > 0 and third_person.baseDistance == minDistance and if delta > 0 and third_person.baseDistance == minDistance and
(camera.getMode() ~= MODE.Preview or third_person.standingPreview) and noModeControl == 0 then (camera.getMode() ~= MODE.Preview or third_person.standingPreview) and not next(noModeControl) then
primaryMode = MODE.FirstPerson primaryMode = MODE.FirstPerson
camera.setMode(primaryMode) camera.setMode(primaryMode)
elseif delta > 0 or obstacleDelta < -delta then elseif delta > 0 or obstacleDelta < -delta then
third_person.baseDistance = util.clamp(third_person.baseDistance - delta - obstacleDelta, minDistance, maxDistance) third_person.baseDistance = util.clamp(third_person.baseDistance - delta - obstacleDelta, minDistance, maxDistance)
end end
elseif delta < 0 and noModeControl == 0 then elseif delta < 0 and not next(noModeControl) then
primaryMode = MODE.ThirdPerson primaryMode = MODE.ThirdPerson
camera.setMode(primaryMode) camera.setMode(primaryMode)
third_person.baseDistance = minDistance third_person.baseDistance = minDistance
@ -149,7 +149,7 @@ end
local function updateStandingPreview() local function updateStandingPreview()
local mode = camera.getMode() local mode = camera.getMode()
if not previewIfStandStill or noStandingPreview > 0 if not previewIfStandStill or next(noStandingPreview)
or mode == MODE.FirstPerson or mode == MODE.Static or mode == MODE.Vanity then or mode == MODE.FirstPerson or mode == MODE.Static or mode == MODE.Vanity then
third_person.standingPreview = false third_person.standingPreview = false
return return
@ -197,7 +197,7 @@ local function onFrame(dt)
primaryMode = mode primaryMode = mode
end end
if mode ~= MODE.Static then if mode ~= MODE.Static then
if noModeControl == 0 then if not next(noModeControl) then
updatePOV(dt) updatePOV(dt)
updateVanity(dt) updateVanity(dt)
end end
@ -206,7 +206,7 @@ local function onFrame(dt)
end end
applyControllerZoom(dt) applyControllerZoom(dt)
third_person.update(dt, smoothedSpeed) third_person.update(dt, smoothedSpeed)
if noHeadBobbing == 0 then head_bobbing.update(dt, smoothedSpeed) end if not next(noHeadBobbing) then head_bobbing.update(dt, smoothedSpeed) end
if slowViewChange then if slowViewChange then
local maxIncrease = dt * (100 + third_person.baseDistance) local maxIncrease = dt * (100 + third_person.baseDistance)
camera.setPreferredThirdPersonDistance( camera.setPreferredThirdPersonDistance(
@ -221,54 +221,92 @@ return {
-- @module Camera -- @module Camera
-- @usage require('openmw.interfaces').Camera -- @usage require('openmw.interfaces').Camera
interface = { interface = {
--- Interface version --- Interface version is 1
-- @field [parent=#Camera] #number version -- @field [parent=#Camera] #number version
version = 0, version = 1,
--- Return primary mode (MODE.FirstPerson or MODE.ThirdPerson). --- Return primary mode (MODE.FirstPerson or MODE.ThirdPerson).
-- @function [parent=#Camera] getPrimaryMode -- @function [parent=#Camera] getPrimaryMode
-- @return #number @{openmw.camera#MODE}
getPrimaryMode = function() return primaryMode end, getPrimaryMode = function() return primaryMode end,
--- @function [parent=#Camera] getBaseThirdPersonDistance
--- Get base third person distance (without applying angle and speed modifiers).
-- @function [parent=#Camera] getBaseThirdPersonDistance
-- @return #number
getBaseThirdPersonDistance = function() return third_person.baseDistance end, getBaseThirdPersonDistance = function() return third_person.baseDistance end,
--- @function [parent=#Camera] setBaseThirdPersonDistance --- Set base third person distance
-- @function [parent=#Camera] setBaseThirdPersonDistance
-- @param #number value
setBaseThirdPersonDistance = function(v) third_person.baseDistance = v end, setBaseThirdPersonDistance = function(v) third_person.baseDistance = v end,
--- @function [parent=#Camera] getTargetThirdPersonDistance --- Get the desired third person distance if there would be no obstacles (with angle and speed modifiers)
-- @function [parent=#Camera] getTargetThirdPersonDistance
-- @return #number
getTargetThirdPersonDistance = function() return third_person.preferredDistance end, getTargetThirdPersonDistance = function() return third_person.preferredDistance end,
--- @function [parent=#Camera] isModeControlEnabled --- Whether the built-in mode control logic is enabled.
isModeControlEnabled = function() return noModeControl == 0 end, -- @function [parent=#Camera] isModeControlEnabled
--- @function [parent=#Camera] disableModeControl -- @return #boolean
disableModeControl = function() noModeControl = noModeControl + 1 end, isModeControlEnabled = function() return not next(noModeControl) end,
--- @function [parent=#Camera] enableModeControl --- Disable with (optional) tag until the corresponding enable function is called with the same tag.
enableModeControl = function() noModeControl = math.max(0, noModeControl - 1) end, -- @function [parent=#Camera] disableModeControl
-- @param #string tag (optional, empty string by default) Will be disabled until the enabling function is called with the same tag
disableModeControl = function(tag) noModeControl[tag or ''] = true end,
--- Undo disableModeControl
-- @function [parent=#Camera] enableModeControl
-- @param #string tag (optional, empty string by default)
enableModeControl = function(tag) noModeControl[tag or ''] = nil end,
--- @function [parent=#Camera] isStandingPreviewEnabled --- Whether the built-in standing preview logic is enabled.
isStandingPreviewEnabled = function() return previewIfStandStill and noStandingPreview == 0 end, -- @function [parent=#Camera] isStandingPreviewEnabled
--- @function [parent=#Camera] disableStandingPreview -- @return #boolean
disableStandingPreview = function() noStandingPreview = noStandingPreview + 1 end, isStandingPreviewEnabled = function() return previewIfStandStill and not next(noStandingPreview) end,
--- @function [parent=#Camera] enableStandingPreview --- Disable with (optional) tag until the corresponding enable function is called with the same tag.
enableStandingPreview = function() noStandingPreview = math.max(0, noStandingPreview - 1) end, -- @function [parent=#Camera] disableStandingPreview
-- @param #string tag (optional, empty string by default) Will be disabled until the enabling function is called with the same tag
disableStandingPreview = function(tag) noStandingPreview[tag or ''] = true end,
--- Undo disableStandingPreview
-- @function [parent=#Camera] enableStandingPreview
-- @param #string tag (optional, empty string by default)
enableStandingPreview = function(tag) noStandingPreview[tag or ''] = nil end,
--- @function [parent=#Camera] isHeadBobbingEnabled --- Whether head bobbing is enabled.
isHeadBobbingEnabled = function() return head_bobbing.enabled and noHeadBobbing == 0 end, -- @function [parent=#Camera] isHeadBobbingEnabled
--- @function [parent=#Camera] disableHeadBobbing -- @return #boolean
disableHeadBobbing = function() noHeadBobbing = noHeadBobbing + 1 end, isHeadBobbingEnabled = function() return head_bobbing.enabled and not next(noHeadBobbing) end,
--- @function [parent=#Camera] enableHeadBobbing --- Disable with (optional) tag until the corresponding enable function is called with the same tag.
enableHeadBobbing = function() noHeadBobbing = math.max(0, noHeadBobbing - 1) end, -- @function [parent=#Camera] disableHeadBobbing
-- @param #string tag (optional, empty string by default) Will be disabled until the enabling function is called with the same tag
disableHeadBobbing = function(tag) noHeadBobbing[tag or ''] = true end,
--- Undo disableHeadBobbing
-- @function [parent=#Camera] enableHeadBobbing
-- @param #string tag (optional, empty string by default)
enableHeadBobbing = function(tag) noHeadBobbing[tag or ''] = nil end,
--- @function [parent=#Camera] isZoomEnabled --- Whether the built-in zooming is enabled.
isZoomEnabled = function() return noZoom == 0 end, -- @function [parent=#Camera] isZoomEnabled
--- @function [parent=#Camera] disableZoom -- @return #boolean
disableZoom = function() noZoom = noZoom + 1 end, isZoomEnabled = function() return not next(noZoom) end,
--- @function [parent=#Camera] enableZoom --- Disable with (optional) tag until the corresponding enable function is called with the same tag.
enableZoom = function() noZoom = math.max(0, noZoom - 1) end, -- @function [parent=#Camera] disableZoom
-- @param #string tag (optional, empty string by default) Will be disabled until the enabling function is called with the same tag
disableZoom = function(tag) noZoom[tag or ''] = true end,
--- Undo disableZoom
-- @function [parent=#Camera] enableZoom
-- @param #string tag (optional, empty string by default)
enableZoom = function(tag) noZoom[tag or ''] = nil end,
--- @function [parent=#Camera] isThirdPersonOffsetControlEnabled --- Whether the the third person offset can be changed by the built-in camera script.
isThirdPersonOffsetControlEnabled = function() return third_person.noOffsetControl == 0 end, -- @function [parent=#Camera] isThirdPersonOffsetControlEnabled
--- @function [parent=#Camera] disableThirdPersonOffsetControl -- @return #boolean
disableThirdPersonOffsetControl = function() third_person.noOffsetControl = third_person.noOffsetControl + 1 end, isThirdPersonOffsetControlEnabled = function() return not next(third_person.noOffsetControl) end,
--- @function [parent=#Camera] enableThirdPersonOffsetControl --- Disable with (optional) tag until the corresponding enable function is called with the same tag.
enableThirdPersonOffsetControl = function() third_person.noOffsetControl = math.max(0, third_person.noOffsetControl - 1) end, -- @function [parent=#Camera] disableThirdPersonOffsetControl
-- @param #string tag (optional, empty string by default) Will be disabled until the enabling function is called with the same tag
disableThirdPersonOffsetControl = function(tag) third_person.noOffsetControl[tag or ''] = true end,
--- Undo disableThirdPersonOffsetControl
-- @function [parent=#Camera] enableThirdPersonOffsetControl
-- @param #string tag (optional, empty string by default)
enableThirdPersonOffsetControl = function(tag) third_person.noOffsetControl[tag or ''] = nil end,
}, },
engineHandlers = { engineHandlers = {
onUpdate = onUpdate, onUpdate = onUpdate,

View File

@ -15,7 +15,7 @@ local M = {
baseDistance = 192, baseDistance = 192,
preferredDistance = 0, preferredDistance = 0,
standingPreview = false, standingPreview = false,
noOffsetControl = 0, noOffsetControl = {},
} }
local viewOverShoulder, autoSwitchShoulder local viewOverShoulder, autoSwitchShoulder
@ -142,7 +142,7 @@ function M.update(dt, smoothedSpeed)
return return
end end
if M.noOffsetControl == 0 then if not next(M.noOffsetControl) then
updateState() updateState()
else else
state = nil state = nil

View File

@ -109,12 +109,12 @@
--- ---
-- Pause the game starting from the next frame. -- Pause the game starting from the next frame.
-- @function [parent=#world] pause -- @function [parent=#world] pause
-- @param #string tag (optional) The game will be paused until `unpause` is called with the same tag. -- @param #string tag (optional, empty string by default) The game will be paused until `unpause` is called with the same tag.
--- ---
-- Remove given tag from the list of pause tags. Resume the game starting from the next frame if the list became empty. -- Remove given tag from the list of pause tags. Resume the game starting from the next frame if the list became empty.
-- @function [parent=#world] unpause -- @function [parent=#world] unpause
-- @param #string tag (optional) Needed to undo `pause` called with this tag. -- @param #string tag (optional, empty string by default) Needed to undo `pause` called with this tag.
--- ---
-- The tags that are currently pausing the game. -- The tags that are currently pausing the game.