Skip to content

Commit 9a000b8

Browse files
authored
Make editor default to 1x speed (#485)
* Make editor default to 1x speed
1 parent b822bca commit 9a000b8

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

libs/db/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,8 @@ pub struct State {
351351

352352
impl DB {
353353
pub fn create(path: PathBuf) -> Result<Self, Error> {
354-
Self::with_time_step(path, Duration::from_secs_f64(1.0 / 120.0))
354+
// Default to 1/60 s which gives 1x real-time at 60 Hz playback frequency.
355+
Self::with_time_step(path, Duration::from_secs_f64(1.0 / 60.0))
355356
}
356357

357358
pub fn with_time_step(path: PathBuf, time_step: Duration) -> Result<Self, Error> {

libs/impeller2/bevy/src/lib.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ pub use tcp::*;
5252
/// Increased from 64MB to 256MB to handle large Arrow IPC responses from SQL queries.
5353
pub const QUEUE_LEN: usize = 256 * 1024 * 1024;
5454

55+
/// The playback frequency used by the editor (frames per second).
56+
const PLAYBACK_FREQUENCY: f64 = 60.0;
57+
58+
/// The stream time-step that corresponds to 1x real-time playback at
59+
/// [`PLAYBACK_FREQUENCY`] Hz. `time_step * frequency == 1 second` of
60+
/// sim-time per second of wall-clock time.
61+
const REAL_TIME_STREAM_TIME_STEP: Duration =
62+
Duration::from_nanos((1_000_000_000.0 / PLAYBACK_FREQUENCY) as u64);
63+
5564
#[derive(Resource)]
5665
pub struct PacketRx(AsyncArcQueueRx);
5766

@@ -184,7 +193,10 @@ fn sink_inner(
184193
.insert(metadata.component_id, metadata);
185194
}
186195
*world_sink.db_config = metadata.db_config.clone();
187-
pending_stream_time_step = Some(metadata.db_config.default_stream_time_step);
196+
// Always start playback at 1x real-time speed regardless of
197+
// what the DB has stored. Playback speed is the requester's
198+
// concern; the DB should not dictate it.
199+
pending_stream_time_step = Some(REAL_TIME_STREAM_TIME_STEP);
188200
world_sink.commands.write_message(DbMessage::UpdateConfig);
189201
}
190202
OwnedPacket::Msg(m) if m.id == LastUpdated::ID => {
@@ -725,8 +737,8 @@ pub fn new_connection_packets(stream_id: StreamId) -> impl Iterator<Item = LenPa
725737
Stream {
726738
behavior: StreamBehavior::FixedRate(FixedRateBehavior {
727739
initial_timestamp: impeller2_wkt::InitialTimestamp::Earliest,
728-
timestep: Duration::from_secs_f64(1.0 / 60.0).as_nanos() as u64,
729-
frequency: 60,
740+
timestep: REAL_TIME_STREAM_TIME_STEP.as_nanos() as u64,
741+
frequency: PLAYBACK_FREQUENCY as u64,
730742
}),
731743
id: stream_id,
732744
}

libs/nox-ecs/src/impeller2_server.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,18 +151,17 @@ pub fn init_db(
151151
Ok::<_, elodin_db::Error>(())
152152
})?;
153153

154-
// The editor subscribes with a fixed playback frequency of 60 Hz.
155-
// For 1x real-time playback, time_step must equal 1/frequency so that
156-
// time_step * frequency = 1 second of sim-time per second of wall-clock.
157-
// default_playback_speed scales this linearly (2.0 = 2x real-time, etc.).
154+
// Playback speed is the requester's (editor's) concern, not the DB's.
155+
// Always store the 1x real-time time-step (1/60 s at 60 Hz playback).
156+
// The editor will use its own constant on connect and let the user
157+
// change speed via the command palette.
158158
const PLAYBACK_FREQUENCY: f64 = 60.0;
159159
let default_stream_time_step =
160160
Duration::from_secs_f64(world.metadata.default_playback_speed / PLAYBACK_FREQUENCY);
161161
db.default_stream_time_step.store(
162162
default_stream_time_step.as_nanos() as u64,
163163
atomic::Ordering::SeqCst,
164164
);
165-
// Also persist the computed value in db_config so it survives save/load
166165
db.with_state_mut(|state| {
167166
state.db_config.default_stream_time_step = default_stream_time_step;
168167
});

0 commit comments

Comments
 (0)