Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[timestream] remove independent calendar speed settings #1256

Merged
merged 1 commit into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 9 additions & 26 deletions docs/timestream.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,10 @@ your fully developed fort appear as energetic as the dwarves in a newly created
fort, and mature forts are much more fun to play.

Note that whereas your dwarves zip around like you're running at 100 FPS, the
onscreen FPS counter, if enabled, will still show a lower number. See the
`Technical details`_ section below if you're interested in what's going on
vanilla onscreen FPS counter, if enabled, will still show a lower number. See
the `Technical details`_ section below if you're interested in what's going on
under the hood.

You can also use this tool to change the in-game calendar speed. Your dwarves
will be able to get less/more done per season (depending on whether you speed
up or slow down the calendar).

Usage
-----

Expand All @@ -46,12 +42,7 @@ Examples
which is usually 100).

``timestream set fps 50``
Tweak the simulation so dwarves move at an apparent 50 frames per second.

``timestream set calendar-rate 0.5``
Make the days twice as long and allow dwarves to accomplish twice as much
per day (requires that your target FPS is set at least 2x higher than the
FPS the game is actually running at).
Tweak the simulation so it runs at an apparent 50 frames per second.

``timestream reset``
Reset settings to defaults: the vanilla FPS cap with no calendar speed
Expand All @@ -66,15 +57,6 @@ Settings
to set the vanilla FPS cap for that. Set a target FPS of -1 to make no
adjustment at all to the apparent FPS of the game.

:calendar-rate: Set the calendar rate in relation to the target FPS. A calendar
rate factor of 1 means time flows "normally" for the units in the game.
Values between 0 and 1 slow the calendar relative to the world, allowing
units to get more done per day, and values above 1 speed the calendar
relative to the world, causing the days to pass quicker and preventing
units from getting as much done per day. The actual fps must be below the
configured target ``fps`` setting for the ``calendar-rate`` setting to take
effect.

Technical details
-----------------

Expand Down Expand Up @@ -113,11 +95,12 @@ of their advantage.
Limitations
-----------

DF does critial game tasks every 10 ticks that must not be skipped, so
`timestream` cannot advance more than 9 ticks at a time. This means that, with
the default target of 100 FPS, the game will start showing signs of slowdown if
the real FPS drops below about 15. The interface will also become less
responsive to mouse gestures as the real FPS drops.
DF does critial game tasks every 10 calendar ticks that must not be skipped, so
`timestream` cannot advance more than 9 ticks at a time. This puts an upper
limit on how much `timestream` can help. With the default target of 100 FPS,
the game will start showing signs of slowdown if the real FPS drops below about
15. The interface will also become less responsive to mouse gestures as the
real FPS drops.

Finally, not all aspects of the game are perfectly adjusted. For example,
armies on world map will move at the same (real-time) rate regardless of
Expand Down
24 changes: 5 additions & 19 deletions timestream.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,6 @@ local SETTINGS = {
end,
default=function() return df.global.init.fps_cap end,
},
{
name='calendar-rate',
internal_name='calendar_rate',
validate=function(arg)
local val = tonumber(arg)
if not val or val <= 0 then qerror('calendar-rate must be larger than 0') end
return val
end,
default=1.0,
},
}

local function get_default_state()
Expand Down Expand Up @@ -74,7 +64,7 @@ local TICK_TRIGGERS = {
}

-- "owed" ticks we would like to skip at the next opportunity
local timeskip_deficit, calendar_timeskip_deficit = 0.0, 0.0
local timeskip_deficit = 0.0

local function get_desired_timeskip(real_fps, desired_fps)
-- minus 1 to account for the current frame
Expand Down Expand Up @@ -265,7 +255,7 @@ end
local function on_tick()
local real_fps = math.max(1, dfhack.internal.getUnpausedFps())
if real_fps >= state.settings.fps then
timeskip_deficit, calendar_timeskip_deficit = 0.0, 0.0
timeskip_deficit = 0.0
return
end

Expand All @@ -292,12 +282,8 @@ local function on_tick()
end
if timeskip <= 0 then return end

local desired_calendar_timeskip = (timeskip * state.settings.calendar_rate) + calendar_timeskip_deficit
local calendar_timeskip = math.max(1, math.floor(desired_calendar_timeskip))
calendar_timeskip_deficit = math.max(0, desired_calendar_timeskip - calendar_timeskip)

df.global.cur_year_tick = df.global.cur_year_tick + calendar_timeskip
df.global.cur_year_tick_advmode = df.global.cur_year_tick_advmode + calendar_timeskip*144
df.global.cur_year_tick = df.global.cur_year_tick + timeskip
df.global.cur_year_tick_advmode = df.global.cur_year_tick_advmode + timeskip*144

adjust_units(timeskip)
adjust_activities(timeskip)
Expand All @@ -307,7 +293,7 @@ end
-- hook management

local function do_enable()
timeskip_deficit, calendar_timeskip_deficit = 0.0, 0.0
timeskip_deficit = 0.0
state.enabled = true
repeatutil.scheduleEvery(GLOBAL_KEY, 1, 'ticks', on_tick)
end
Expand Down