0.1.0-0-pre.4
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// file: crates/engines/engine-v1-common/src/game_loop.rs
|
||||
// version: 1
|
||||
// version: 2
|
||||
|
||||
/// Minimal update contract implemented by a game state consumed by engine V1.
|
||||
pub trait EngineGame {
|
||||
@@ -54,30 +54,5 @@ impl FixedStepRunner {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod unit_tests {
|
||||
#[derive(Default)]
|
||||
struct CountingGame {
|
||||
updates: u64,
|
||||
last_frame: Option<crate::EngineFrame>,
|
||||
}
|
||||
|
||||
impl crate::EngineGame for CountingGame {
|
||||
fn update(&mut self, frame: crate::EngineFrame, _input: crate::InputState) {
|
||||
self.updates = self.updates.saturating_add(1);
|
||||
self.last_frame = Some(frame);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fixed_step_runner_advances_index_and_elapsed_time() {
|
||||
let mut game = CountingGame::default();
|
||||
let mut runner = crate::FixedStepRunner::new(std::time::Duration::from_millis(16));
|
||||
runner.tick(&mut game, crate::InputState::none());
|
||||
runner.tick(&mut game, crate::InputState::none());
|
||||
assert_eq!(game.updates, 2);
|
||||
assert_eq!(runner.next_frame_index(), 2);
|
||||
assert_eq!(runner.elapsed(), std::time::Duration::from_millis(32));
|
||||
assert_eq!(game.last_frame.map(crate::EngineFrame::index), Some(1));
|
||||
}
|
||||
}
|
||||
#[path = "../unit_tests/game_loop.rs"]
|
||||
mod tests;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// file: crates/engines/engine-v1-common/src/input.rs
|
||||
// version: 1
|
||||
// version: 2
|
||||
|
||||
/// Platform-independent snapshot of logical input actions for one update.
|
||||
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
|
||||
@@ -51,11 +51,5 @@ impl InputState {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod unit_tests {
|
||||
#[test]
|
||||
fn action_state_is_independent() {
|
||||
let state = crate::InputState::none().with_action(crate::GameAction::Primary, true);
|
||||
assert!(state.is_active(crate::GameAction::Primary));
|
||||
assert!(!state.is_active(crate::GameAction::Secondary));
|
||||
}
|
||||
}
|
||||
#[path = "../unit_tests/input.rs"]
|
||||
mod tests;
|
||||
|
||||
Reference in New Issue
Block a user