0.1.0-0-pre.4
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
30
crates/engines/engine-v1-common/unit_tests/game_loop.rs
Normal file
30
crates/engines/engine-v1-common/unit_tests/game_loop.rs
Normal 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));
|
||||
});
|
||||
}
|
||||
12
crates/engines/engine-v1-common/unit_tests/input.rs
Normal file
12
crates/engines/engine-v1-common/unit_tests/input.rs
Normal 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));
|
||||
});
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
# file: crates/engines/engine-v1-platform-api/Cargo.toml
|
||||
# version: 1
|
||||
# version: 2
|
||||
|
||||
[package]
|
||||
name = "engine-v1-platform-api"
|
||||
@@ -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
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// file: crates/engines/engine-v1-platform-api/src/service.rs
|
||||
// version: 2
|
||||
// version: 3
|
||||
|
||||
/// Platform capabilities that may have different implementations per target.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
@@ -61,11 +61,5 @@ impl MonetizationCapabilities {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod unit_tests {
|
||||
#[test]
|
||||
fn disabled_monetization_disables_both_services() {
|
||||
let capabilities = crate::MonetizationCapabilities::disabled();
|
||||
assert_eq!(capabilities.advertising(), crate::PlatformServiceAvailability::Disabled);
|
||||
assert_eq!(capabilities.billing(), crate::PlatformServiceAvailability::Disabled);
|
||||
}
|
||||
}
|
||||
#[path = "../unit_tests/service.rs"]
|
||||
mod tests;
|
||||
|
||||
11
crates/engines/engine-v1-platform-api/unit_tests/service.rs
Normal file
11
crates/engines/engine-v1-platform-api/unit_tests/service.rs
Normal file
@@ -0,0 +1,11 @@
|
||||
// file: crates/engines/engine-v1-platform-api/unit_tests/service.rs
|
||||
// version: 1
|
||||
|
||||
#[test]
|
||||
fn disabled_monetization_disables_both_services() {
|
||||
game_logging_lib::with_test_tracing("disabled_monetization_disables_both_services", || {
|
||||
let capabilities = crate::MonetizationCapabilities::disabled();
|
||||
assert_eq!(capabilities.advertising(), crate::PlatformServiceAvailability::Disabled);
|
||||
assert_eq!(capabilities.billing(), crate::PlatformServiceAvailability::Disabled);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user