Skip to content

Commit a60fdc4

Browse files
committed
Start frame time at zero in --lockstep
This allows physics systems to be run deterministically.
1 parent 6dda1d7 commit a60fdc4

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

docs/language.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ The engine-supplied global values are:
7575
- `quantum` - the beats per quantum (usually 4)
7676
- `delta` - the difference between the current value of `beat` and the value
7777
at the last display frame
78-
- `time` - the current frame time (derived from Python's `perf_counter()`
79-
usually, though increasing by exactly `1/fps` per frame in non-realtime
78+
- `time` - the time that the current frame began execution (either the value
79+
of the high-resolution Python `perf_counter()` timer or a counter beginning
80+
at `0` and incrementing by exactly `1/fps` on each frame in non-realtime
8081
mode)
8182
- `clock` - the current UTC time as a seconds-since-UNIX-epoch value
8283
- `frame` - the current frame number, counting from 0 and increasing by one

docs/physics.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ The internal simulation clock can be read from the state and used to track the
108108
actual amount of simulation time that has passed (see [State
109109
interaction](#state-interaction) below).
110110

111+
A physics system is entirely deterministic *iff* it uses fixed starting
112+
conditions *and* **Flitter** is run in non-realtime mode. When run in realtime
113+
mode, small numerical differences in how time advances will introduce tiny
114+
variations that compound quickly in any non-trivial system to produce chaotic
115+
results.
116+
111117
### `!particle`
112118

113119
A `!particle` node specifies a point/spherical object to be simulated. At each

src/flitter/engine/control.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def switch_to_page(self, page_number):
102102
self.counter.reset(tempo, int(quantum), start)
103103
logger.info("Restore counter at beat {:.1f}, tempo {:.1f}, quantum {}", self.counter.beat, self.counter.tempo, self.counter.quantum)
104104
else:
105-
self.counter.reset()
105+
self.counter.reset(start=system_clock() if self.realtime else 0)
106106
setproctitle(f'flitter [{self.current_path}]')
107107

108108
def has_next_page(self):
@@ -169,7 +169,7 @@ async def run(self):
169169
try:
170170
frame_count = 0
171171
frames = []
172-
start_time = frame_time = system_clock() if self.realtime else self.counter.start
172+
start_time = frame_time = system_clock() if self.realtime else 0
173173
last = self.counter.beat_at_time(frame_time)
174174
save_state_time = system_clock() + self.STATE_SAVE_PERIOD
175175
execution = render = housekeeping = 0

0 commit comments

Comments
 (0)