fix(simulation): address PR #2 review findings
- Fix Cargo.toml edition 2024 → 2021 (Hoshe #1) - Switch test runner to cargo-nextest in Makefile (Hoshe #2, D-030) - Add debug_assert tick ordering enforcement in InputQueue::push (Hoshe #4) - Add DayPhase Serialize/Deserialize derives (Tyre #6) - Add day phase boundary comments clarifying half-open ranges (Hoshe #3) - Add phase duration adjustability comment (Tyre #5) - Document ObserverSnapshot planned fields as TODO (Tyre #1) - Document entity_id as wire-format ID, not ECS Entity (Tyre #2) - Change Relationship.target_name to target_id: u64 (Tyre #3) - Clarify single app.update() is intentional boilerplate (Hoshe #8, Tyre #7) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -13,8 +13,16 @@ pub struct InputQueue {
|
||||
}
|
||||
|
||||
impl InputQueue {
|
||||
/// Add a new input to the queue
|
||||
/// Add a new input to the queue.
|
||||
/// Inputs must be pushed in tick order for deterministic processing.
|
||||
/// Panics in debug builds if tick ordering is violated.
|
||||
pub fn push(&mut self, input: PlayerInput) {
|
||||
debug_assert!(
|
||||
self.queue.back().is_none_or(|last| last.tick <= input.tick),
|
||||
"InputQueue: tick ordering violated (last={}, new={})",
|
||||
self.queue.back().map_or(0, |last| last.tick),
|
||||
input.tick,
|
||||
);
|
||||
self.queue.push_back(input);
|
||||
}
|
||||
|
||||
@@ -74,4 +82,18 @@ mod tests {
|
||||
let inputs = queue.drain_for_tick(10);
|
||||
assert!(inputs.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "tick ordering violated")]
|
||||
fn push_rejects_out_of_order_in_debug() {
|
||||
let mut queue = InputQueue::default();
|
||||
queue.push(PlayerInput {
|
||||
tick: 5,
|
||||
action: PlayerAction::MoveNorth,
|
||||
});
|
||||
queue.push(PlayerInput {
|
||||
tick: 2,
|
||||
action: PlayerAction::MoveSouth,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user