Skip to content

Commit

Permalink
Add setting to use intervals instead of speed gain
Browse files Browse the repository at this point in the history
  • Loading branch information
veger committed May 23, 2024
1 parent ab3be84 commit f6fdfd8
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 44 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Version: 1.5.2

Minor Features:
- Try to fix missing player data in order to be more flexible to unexpected situations.
- Add (per player) setting to use intervals (milliseconds) between frames instead of speed gain (factor).
Bugfixes:
- Fix optional dependency on StatsGui.

Expand Down
8 changes: 7 additions & 1 deletion locale/en/locale.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ label-entity-info=Show entity info
label-show-gui=Show GUI
label-always-day=Always daytime
label-framerate=Frame rate:
label-interval=Interval:
label-name=Name:
label-position=Position:
label-resolution=Resolution:
Expand All @@ -46,6 +47,7 @@ label-cityblock-currentblock=Current:
label-cityblock-blockScale=Scale:
label-cityblock-centerOnPlayer=Select block:
label-transition-speedgain=Transition speed gain:
label-transition-interval=Transition interval:
item-add-tracker=<Add Tracker>
item-new-tracker=<New Tracker>
tab-cameras=Cameras
Expand All @@ -61,10 +63,12 @@ camera-entity-info=Show entity information (recipes) in the screenshots.
camera-show-gui=Show the GUI in the screenshots (make sure camera resolution and game/screen resolution match).
camera-always-day=Render in daylight, regardless of the time of day.
camera-framerate=Number of frames per second that your movie is going to be (often/default 25 fps).
camera-interval=Interval (elapsed game time) between frames in milliseconds. (actual interval might be slightly off due to rounding to game ticks)
camera-speedgain=Amount (factor) that the timelapse movie should speed up compared to actual time.
camera-refresh=Recalculate the camera settings. (due to rounding issues the actual values might differ a little).
camera-transitionperiod=Amount of the time takes to transition the camera to its new position.
camera-transition-speedgain=Amount (factor) that the timelapse movie should speed up compared to actual time during transitions.\n\nSet to 0 for stop-motion transitions (only possible with sequential numbering active). Note that depending on transition period, and your hardware, it might take a few game ticks (so not 100% stop-motion transition).
camera-transition-interval=Interval (elapsed game time) between frames in millisecond during transitions.\n\nSet to 0 for stop-motion transitions (only possible with sequential numbering active). Note that depending on transition period, and your hardware, it might take a few game ticks (so not 100% stop-motion transition).
pause-on-open=Pause game when this window is open.
tracker-cannot-delete-inuse=Cannot delete tracker because it is in use.
tracker-cannot-enable=This tracker cannot be enabled/disabled, this is managed by a specific event/trigger.
Expand All @@ -84,7 +88,7 @@ tracker-cityblock-currentblock=The city block to focus on, counting in whole blo
tracker-cityblock-currentblock-x=The position of the current city block, counting blocks rightwards.
tracker-cityblock-currentblock-y=The position of the current city block, counting blocks downwards.
tracker-cityblock-blockScale=How many city blocks to zoom out, centered on the current block.
tracker-cityblock-blockScale-value=A zoom of 3 will capture the current block and all of the neighbours. <enter> to set.
tracker-cityblock-blockScale-value=A zoom of 3 will capture the current block and all of the neighbors. <enter> to set.
tracker-cityblock-player=Use player coordinates to select the current city block.

[controls]
Expand All @@ -96,11 +100,13 @@ tlbe-take-screenshot=Take a screenshot
tlbe-save-folder=Save location
tlbe-sequential-names=Sequential names
tlbe-show-stats=Show camera status
tlbe-use-interval=Use interval as speed setting

[mod-setting-description]
tlbe-save-folder=Relative from 'User Data Directory'
tlbe-sequential-names=Use sequential numbering per camera for the screenshot numbers. When disabled, game ticks are used for screenshot numbering.
tlbe-show-stats=This requires the Stats GUI mod to be loaded.
tlbe-use-interval=Use intervals (between frames) instead of speed gain in the camera settings. When this setting is changed, reopen camera settings to update the UI.

[shortcut]
tlbe=Time Lapse Base Edition
Expand Down
85 changes: 83 additions & 2 deletions scripts/camera.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ local Camera = {}
--- @field saveFolder string
--- @field saveName string
--- @field screenshotNumber integer Number for the next screenshot (when sequentialNames is set in player settings)
--- @field screenshotInterval number Interval (game ticks) between two screenshots (calculated from speedGain and frameRate)
--- @field screenshotInterval number Interval (game ticks) between two screenshots (calculated from speedGain and frameRate)
--- @field screenshotIntervalRealtime number Interval (game ticks) between two screenshots for realtime transitions (calculated from frameRate)
--- @field screenshotIntervalTransition number Interval (game ticks) between two screenshots during transitions (calculated from frameRate)
--- @field speedGain number Amount (factor) that the timelapse movie should speed up.
--- @field speedGain number Amount (factor) that the timelapse movie should speed up compared to the game.
--- @field surfaceName string
--- @field trackers Tracker.tracker[]
--- @field chartTags table Chart tags used to render viewfinder boxes on the map
Expand All @@ -57,6 +57,7 @@ Camera.CameraTransition = {}
local maxZoom = 1
local minZoom = 0.031250
local ticks_per_second = 60
local ms_per_tick = 1000 / ticks_per_second
local tileSize = 32

--- @return Camera.camera
Expand Down Expand Up @@ -319,6 +320,44 @@ function Camera.setSpeedGain(camera, speedGain)
Camera.updateConfig(camera)
end

---@param camera Camera.camera
---@param interval any
function Camera.setFrameInterval(camera, interval)
interval = tonumber(interval)

if interval == nil or interval < ms_per_tick then
-- keep minimum interval
interval = ms_per_tick
end

local speedGain = (interval * camera.frameRate) / 1000
if speedGain < 1 then
-- keep minimum speed gain
speedGain = 1
end

camera.speedGain = speedGain
Camera.updateConfig(camera)
end

---@param camera Camera.camera
---@return number|nil interval Camera interval
function Camera.calculateFrameInterval(camera)
if camera.speedGain == nil or camera.frameRate == nil then
return nil
end


local interval = ((1000 * camera.speedGain) / camera.frameRate)

if interval < ms_per_tick then
-- keep minimum interval
interval = ms_per_tick
end

return interval
end

---@param camera Camera.camera
---@param speedGain any
---@param allowStopMotion boolean
Expand All @@ -336,6 +375,48 @@ function Camera.setTransitionSpeedGain(camera, speedGain, allowStopMotion)
Camera.updateConfig(camera)
end

---@param camera Camera.camera
---@param interval any
---@param allowStopMotion boolean
function Camera.setTransitionFrameInterval(camera, interval, allowStopMotion)
interval = tonumber(interval)

if interval == nil then
-- keep minimum interval
interval = ms_per_tick
end
if not allowStopMotion and interval == 0 then
interval = ms_per_tick
end

local speedGain = (interval * camera.frameRate) / 1000
if not allowStopMotion and speedGain < 1 then
-- keep minimum speed gain
speedGain = 1
end

camera.transitionSpeedGain = speedGain
Camera.updateConfig(camera)
end

---@param camera Camera.camera
---@return number|nil interval Camera interval
function Camera.calculateTransitionFrameInterval(camera)
if camera.transitionSpeedGain == nil or camera.frameRate == nil then
return nil
end


local interval = ((1000 * camera.transitionSpeedGain) / camera.frameRate)

if interval < ms_per_tick then
-- keep minimum interval
interval = ms_per_tick
end

return interval
end

--- @param camera Camera.camera
--- @param transitionPeriod any
function Camera.setTransitionPeriod(camera, transitionPeriod)
Expand Down
6 changes: 4 additions & 2 deletions scripts/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ local Tracker = require("scripts.tracker")
--- @field cameras Camera.camera[]
--- @field trackers Tracker.tracker[]
--- @field pauseCameras boolean When true, pause all player cameras
--- @field pauseOnOpen boolean When true, pause cameras when the GUI is opened
--- @field showCameraStatus boolean When true, the Stats GUI is used to show status of each camera
--- @field saveFolder string
--- @field sequentialNames boolean
--- @field useInterval boolean When true, use interval (between frames) instead of speed gain
--- @field noticeMaxZoom boolean When true the warning about the max zoom is already raised
--- @field gui table Contains all (volatile) GUI elements
--- @field guiPersist persistedGUISettings Contains all persisted (between saves) GUI details
Expand Down Expand Up @@ -37,10 +39,10 @@ function Config.reload(event)

---@diagnostic disable: assign-type-mismatch
playerSettings.saveFolder = guiSettings["tlbe-save-folder"].value
---@diagnostic disable: assign-type-mismatch
playerSettings.sequentialNames = guiSettings["tlbe-sequential-names"].value
---@diagnostic disable: assign-type-mismatch
playerSettings.showCameraStatus = guiSettings["tlbe-show-stats"].value
playerSettings.useInterval = guiSettings["tlbe-use-interval"].value
---@diagnostic enable: assign-type-mismatch
end

--- @return playerSettings
Expand Down
Loading

0 comments on commit f6fdfd8

Please sign in to comment.