0.1.0-0-pre.4

This commit is contained in:
2026-09-16 01:01:09 +02:00
parent 2c79a05dd6
commit dc22011997
38 changed files with 540 additions and 131 deletions

View File

@@ -1,5 +1,5 @@
# file: crates/engines/engine-v1-common/Cargo.toml
# version: 1
# version: 2
[package]
name = "engine-v1-common"
@@ -10,5 +10,8 @@ repository.workspace = true
authors.workspace = true
publish.workspace = true
[dev-dependencies]
game-logging-lib = { path = "../../common/game-logging-lib" }
[lints]
workspace = true

View File

@@ -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;

View File

@@ -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;

View File

@@ -0,0 +1,30 @@
// file: crates/engines/engine-v1-common/unit_tests/game_loop.rs
// version: 1
#[derive(Default)]
struct CountingGame {
updates: u64,
last_frame: std::option::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 = std::option::Option::Some(frame);
return;
}
}
#[test]
fn fixed_step_runner_advances_index_and_elapsed_time() {
game_logging_lib::with_test_tracing("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), std::option::Option::Some(1));
});
}

View File

@@ -0,0 +1,12 @@
// file: crates/engines/engine-v1-common/unit_tests/input.rs
// version: 1
#[test]
fn action_state_is_independent() {
game_logging_lib::with_test_tracing("action_state_is_independent", || {
let input = crate::InputState::none().with_action(crate::GameAction::Primary, true);
assert!(input.is_active(crate::GameAction::Primary));
assert!(!input.is_active(crate::GameAction::Secondary));
assert!(!input.is_active(crate::GameAction::Left));
});
}