Skip to content

Commit

Permalink
add a wider variety of jitter
Browse files Browse the repository at this point in the history
  • Loading branch information
myk002 committed Jun 28, 2024
1 parent bd8550f commit 5f457d2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
10 changes: 8 additions & 2 deletions docs/timestream.rst
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,17 @@ of their advantage.
Limitations
-----------

Right now, not all aspects of the game are perfectly adjusted. For example,
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.

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
changes that ``timestream`` is making to the calendar.

Here is a (likely incomplete) list of game elements that are not adjusted by
Here is a (possibly incomplete) list of game elements that are not adjusted by
``timestream`` and will appear "slow" in-game:

- Army movement across the world map (including raids sent out from the fort)
Expand Down
16 changes: 12 additions & 4 deletions timestream.lua
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,19 @@ local function on_tick()
local timeskip = math.floor(clamp_timeskip(desired_timeskip))

-- add some jitter so we don't fall into a constant pattern
-- to reduce the risk of repeatedly missing an unknown threshold
timeskip = math.random(timeskip - 1, timeskip)
-- this reduces the risk of repeatedly missing an unknown threshold
-- also keeps the game from looking robotic at lower frame rates
local jitter_category = math.random(1, 10)
if jitter_category <= 1 then
timeskip = math.random(0, timeskip)
elseif jitter_category <= 3 then
timeskip = math.random(math.max(0, timeskip-2), timeskip)
elseif jitter_category <= 5 then
timeskip = math.random(math.max(0, timeskip-4), timeskip)
end

-- no need to let our deficit grow beyond the maximum single-step jump
timeskip_deficit = math.min(desired_timeskip - timeskip, 9.0)
-- no need to let our deficit grow unbounded
timeskip_deficit = math.min(desired_timeskip - timeskip, 100.0)

if timeskip <= 0 then return end

Expand Down

0 comments on commit 5f457d2

Please sign in to comment.