Skip to content

Commit f6fdfd8

Browse files
committed
Add setting to use intervals instead of speed gain
1 parent ab3be84 commit f6fdfd8

File tree

6 files changed

+196
-44
lines changed

6 files changed

+196
-44
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Version: 1.5.2
33

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

locale/en/locale.cfg

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ label-entity-info=Show entity info
2727
label-show-gui=Show GUI
2828
label-always-day=Always daytime
2929
label-framerate=Frame rate:
30+
label-interval=Interval:
3031
label-name=Name:
3132
label-position=Position:
3233
label-resolution=Resolution:
@@ -46,6 +47,7 @@ label-cityblock-currentblock=Current:
4647
label-cityblock-blockScale=Scale:
4748
label-cityblock-centerOnPlayer=Select block:
4849
label-transition-speedgain=Transition speed gain:
50+
label-transition-interval=Transition interval:
4951
item-add-tracker=<Add Tracker>
5052
item-new-tracker=<New Tracker>
5153
tab-cameras=Cameras
@@ -61,10 +63,12 @@ camera-entity-info=Show entity information (recipes) in the screenshots.
6163
camera-show-gui=Show the GUI in the screenshots (make sure camera resolution and game/screen resolution match).
6264
camera-always-day=Render in daylight, regardless of the time of day.
6365
camera-framerate=Number of frames per second that your movie is going to be (often/default 25 fps).
66+
camera-interval=Interval (elapsed game time) between frames in milliseconds. (actual interval might be slightly off due to rounding to game ticks)
6467
camera-speedgain=Amount (factor) that the timelapse movie should speed up compared to actual time.
6568
camera-refresh=Recalculate the camera settings. (due to rounding issues the actual values might differ a little).
6669
camera-transitionperiod=Amount of the time takes to transition the camera to its new position.
6770
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).
71+
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).
6872
pause-on-open=Pause game when this window is open.
6973
tracker-cannot-delete-inuse=Cannot delete tracker because it is in use.
7074
tracker-cannot-enable=This tracker cannot be enabled/disabled, this is managed by a specific event/trigger.
@@ -84,7 +88,7 @@ tracker-cityblock-currentblock=The city block to focus on, counting in whole blo
8488
tracker-cityblock-currentblock-x=The position of the current city block, counting blocks rightwards.
8589
tracker-cityblock-currentblock-y=The position of the current city block, counting blocks downwards.
8690
tracker-cityblock-blockScale=How many city blocks to zoom out, centered on the current block.
87-
tracker-cityblock-blockScale-value=A zoom of 3 will capture the current block and all of the neighbours. <enter> to set.
91+
tracker-cityblock-blockScale-value=A zoom of 3 will capture the current block and all of the neighbors. <enter> to set.
8892
tracker-cityblock-player=Use player coordinates to select the current city block.
8993

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

100105
[mod-setting-description]
101106
tlbe-save-folder=Relative from 'User Data Directory'
102107
tlbe-sequential-names=Use sequential numbering per camera for the screenshot numbers. When disabled, game ticks are used for screenshot numbering.
103108
tlbe-show-stats=This requires the Stats GUI mod to be loaded.
109+
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.
104110

105111
[shortcut]
106112
tlbe=Time Lapse Base Edition

scripts/camera.lua

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ local Camera = {}
3131
--- @field saveFolder string
3232
--- @field saveName string
3333
--- @field screenshotNumber integer Number for the next screenshot (when sequentialNames is set in player settings)
34-
--- @field screenshotInterval number Interval (game ticks) between two screenshots (calculated from speedGain and frameRate)
34+
--- @field screenshotInterval number Interval (game ticks) between two screenshots (calculated from speedGain and frameRate)
3535
--- @field screenshotIntervalRealtime number Interval (game ticks) between two screenshots for realtime transitions (calculated from frameRate)
3636
--- @field screenshotIntervalTransition number Interval (game ticks) between two screenshots during transitions (calculated from frameRate)
37-
--- @field speedGain number Amount (factor) that the timelapse movie should speed up.
37+
--- @field speedGain number Amount (factor) that the timelapse movie should speed up compared to the game.
3838
--- @field surfaceName string
3939
--- @field trackers Tracker.tracker[]
4040
--- @field chartTags table Chart tags used to render viewfinder boxes on the map
@@ -57,6 +57,7 @@ Camera.CameraTransition = {}
5757
local maxZoom = 1
5858
local minZoom = 0.031250
5959
local ticks_per_second = 60
60+
local ms_per_tick = 1000 / ticks_per_second
6061
local tileSize = 32
6162

6263
--- @return Camera.camera
@@ -319,6 +320,44 @@ function Camera.setSpeedGain(camera, speedGain)
319320
Camera.updateConfig(camera)
320321
end
321322

323+
---@param camera Camera.camera
324+
---@param interval any
325+
function Camera.setFrameInterval(camera, interval)
326+
interval = tonumber(interval)
327+
328+
if interval == nil or interval < ms_per_tick then
329+
-- keep minimum interval
330+
interval = ms_per_tick
331+
end
332+
333+
local speedGain = (interval * camera.frameRate) / 1000
334+
if speedGain < 1 then
335+
-- keep minimum speed gain
336+
speedGain = 1
337+
end
338+
339+
camera.speedGain = speedGain
340+
Camera.updateConfig(camera)
341+
end
342+
343+
---@param camera Camera.camera
344+
---@return number|nil interval Camera interval
345+
function Camera.calculateFrameInterval(camera)
346+
if camera.speedGain == nil or camera.frameRate == nil then
347+
return nil
348+
end
349+
350+
351+
local interval = ((1000 * camera.speedGain) / camera.frameRate)
352+
353+
if interval < ms_per_tick then
354+
-- keep minimum interval
355+
interval = ms_per_tick
356+
end
357+
358+
return interval
359+
end
360+
322361
---@param camera Camera.camera
323362
---@param speedGain any
324363
---@param allowStopMotion boolean
@@ -336,6 +375,48 @@ function Camera.setTransitionSpeedGain(camera, speedGain, allowStopMotion)
336375
Camera.updateConfig(camera)
337376
end
338377

378+
---@param camera Camera.camera
379+
---@param interval any
380+
---@param allowStopMotion boolean
381+
function Camera.setTransitionFrameInterval(camera, interval, allowStopMotion)
382+
interval = tonumber(interval)
383+
384+
if interval == nil then
385+
-- keep minimum interval
386+
interval = ms_per_tick
387+
end
388+
if not allowStopMotion and interval == 0 then
389+
interval = ms_per_tick
390+
end
391+
392+
local speedGain = (interval * camera.frameRate) / 1000
393+
if not allowStopMotion and speedGain < 1 then
394+
-- keep minimum speed gain
395+
speedGain = 1
396+
end
397+
398+
camera.transitionSpeedGain = speedGain
399+
Camera.updateConfig(camera)
400+
end
401+
402+
---@param camera Camera.camera
403+
---@return number|nil interval Camera interval
404+
function Camera.calculateTransitionFrameInterval(camera)
405+
if camera.transitionSpeedGain == nil or camera.frameRate == nil then
406+
return nil
407+
end
408+
409+
410+
local interval = ((1000 * camera.transitionSpeedGain) / camera.frameRate)
411+
412+
if interval < ms_per_tick then
413+
-- keep minimum interval
414+
interval = ms_per_tick
415+
end
416+
417+
return interval
418+
end
419+
339420
--- @param camera Camera.camera
340421
--- @param transitionPeriod any
341422
function Camera.setTransitionPeriod(camera, transitionPeriod)

scripts/config.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ local Tracker = require("scripts.tracker")
77
--- @field cameras Camera.camera[]
88
--- @field trackers Tracker.tracker[]
99
--- @field pauseCameras boolean When true, pause all player cameras
10+
--- @field pauseOnOpen boolean When true, pause cameras when the GUI is opened
1011
--- @field showCameraStatus boolean When true, the Stats GUI is used to show status of each camera
1112
--- @field saveFolder string
1213
--- @field sequentialNames boolean
14+
--- @field useInterval boolean When true, use interval (between frames) instead of speed gain
1315
--- @field noticeMaxZoom boolean When true the warning about the max zoom is already raised
1416
--- @field gui table Contains all (volatile) GUI elements
1517
--- @field guiPersist persistedGUISettings Contains all persisted (between saves) GUI details
@@ -37,10 +39,10 @@ function Config.reload(event)
3739

3840
---@diagnostic disable: assign-type-mismatch
3941
playerSettings.saveFolder = guiSettings["tlbe-save-folder"].value
40-
---@diagnostic disable: assign-type-mismatch
4142
playerSettings.sequentialNames = guiSettings["tlbe-sequential-names"].value
42-
---@diagnostic disable: assign-type-mismatch
4343
playerSettings.showCameraStatus = guiSettings["tlbe-show-stats"].value
44+
playerSettings.useInterval = guiSettings["tlbe-use-interval"].value
45+
---@diagnostic enable: assign-type-mismatch
4446
end
4547

4648
--- @return playerSettings

0 commit comments

Comments
 (0)