0.1.0-0-pre.7
This commit is contained in:
50
crates/apps/game-android-entrypoint/Cargo.toml
Normal file
50
crates/apps/game-android-entrypoint/Cargo.toml
Normal file
@@ -0,0 +1,50 @@
|
||||
# file: crates/apps/game-android-entrypoint/Cargo.toml
|
||||
# version: 1
|
||||
|
||||
[package]
|
||||
name = "game-android-entrypoint"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
repository.workspace = true
|
||||
authors.workspace = true
|
||||
publish.workspace = true
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[features]
|
||||
default = []
|
||||
reflex = ["dep:game-reflex-poc"]
|
||||
snake = ["dep:game-snake-poc"]
|
||||
|
||||
[dependencies]
|
||||
engine-v1-common = { path = "../../engines/engine-v1-common" }
|
||||
engine-v1-sdl = { path = "../../engines/engine-v1-sdl" }
|
||||
game-reflex-poc = { path = "../../games/game-reflex-poc", optional = true }
|
||||
game-snake-poc = { path = "../../games/game-snake-poc", optional = true }
|
||||
|
||||
[lints.rust]
|
||||
missing_docs = "warn"
|
||||
unreachable_pub = "deny"
|
||||
unsafe_code = "allow"
|
||||
|
||||
[lints.clippy]
|
||||
unwrap_used = "deny"
|
||||
expect_used = "deny"
|
||||
implicit_return = "deny"
|
||||
needless_return = "allow"
|
||||
useless_vec = "deny"
|
||||
question_mark = "deny"
|
||||
question_mark_used = "deny"
|
||||
needless_match = "allow"
|
||||
manual_ok_err = "allow"
|
||||
manual_unwrap_or = "allow"
|
||||
manual_map = "allow"
|
||||
match_like_matches_macro = "allow"
|
||||
single_match = "allow"
|
||||
manual_unwrap_or_default = "allow"
|
||||
manual_find = "allow"
|
||||
explicit_counter_loop = "allow"
|
||||
get_first = "allow"
|
||||
implicit_saturating_sub = "allow"
|
||||
53
crates/apps/game-android-entrypoint/src/lib.rs
Normal file
53
crates/apps/game-android-entrypoint/src/lib.rs
Normal file
@@ -0,0 +1,53 @@
|
||||
// file: crates/apps/game-android-entrypoint/src/lib.rs
|
||||
// version: 1
|
||||
|
||||
#![warn(missing_docs)]
|
||||
#![deny(unreachable_pub)]
|
||||
#![allow(unsafe_code)]
|
||||
|
||||
//! Minimal SDL3 Android entry point.
|
||||
//!
|
||||
//! This crate is the only normalized Rust FFI export exception in the current workspace.
|
||||
//! It uses one unsafe export attribute to expose `SDL_main` to `SDLActivity`; it contains no unsafe block and no unsafe function.
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "../unit_tests/selection.rs"]
|
||||
mod tests;
|
||||
|
||||
#[unsafe(export_name = "SDL_main")]
|
||||
extern "C" fn sdl_main(_argc: core::ffi::c_int, _argv: *mut *mut core::ffi::c_char) -> core::ffi::c_int {
|
||||
return run_selected_game();
|
||||
}
|
||||
|
||||
#[cfg(feature = "reflex")]
|
||||
fn run_selected_game() -> core::ffi::c_int {
|
||||
let runtime = engine_v1_sdl::SdlRuntime::new("Reflex POC", 405, 720, std::time::Duration::from_millis(16));
|
||||
let mut game = game_reflex_poc::ReflexState::new();
|
||||
return run_game(&runtime, &mut game);
|
||||
}
|
||||
|
||||
#[cfg(all(not(feature = "reflex"), feature = "snake"))]
|
||||
fn run_selected_game() -> core::ffi::c_int {
|
||||
let runtime = engine_v1_sdl::SdlRuntime::new("Snake POC", 405, 720, std::time::Duration::from_millis(16));
|
||||
let mut game = game_snake_poc::SnakeState::new();
|
||||
return run_game(&runtime, &mut game);
|
||||
}
|
||||
|
||||
#[cfg(not(any(feature = "reflex", feature = "snake")))]
|
||||
fn run_selected_game() -> core::ffi::c_int {
|
||||
return 2;
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "reflex", feature = "snake"))]
|
||||
fn run_game<G>(runtime: &engine_v1_sdl::SdlRuntime, game: &mut G) -> core::ffi::c_int
|
||||
where
|
||||
G: engine_v1_common::EngineGame,
|
||||
{
|
||||
match runtime.run(game) {
|
||||
std::result::Result::Ok(()) => return 0,
|
||||
std::result::Result::Err(error) => {
|
||||
eprintln!("Android SDL3 runtime error: {error}");
|
||||
return 1;
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// file: crates/apps/game-android-entrypoint/unit_tests/selection.rs
|
||||
// version: 1
|
||||
|
||||
#[test]
|
||||
fn no_feature_entrypoint_has_failure_status() {
|
||||
#[cfg(not(any(feature = "reflex", feature = "snake")))]
|
||||
assert_eq!(crate::run_selected_game(), 2);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
# file: crates/engines/engine-v1-sdl/Cargo.toml
|
||||
# version: 4
|
||||
# version: 5
|
||||
|
||||
[package]
|
||||
name = "engine-v1-sdl"
|
||||
@@ -12,9 +12,14 @@ publish.workspace = true
|
||||
|
||||
[dependencies]
|
||||
engine-v1-common = { path = "../engine-v1-common" }
|
||||
sdl3 = { workspace = true, features = ["use-pkg-config"] }
|
||||
tracing.workspace = true
|
||||
|
||||
[target.'cfg(target_os = "android")'.dependencies]
|
||||
sdl3.workspace = true
|
||||
|
||||
[target.'cfg(not(target_os = "android"))'.dependencies]
|
||||
sdl3 = { workspace = true, features = ["use-pkg-config"] }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
|
||||
Reference in New Issue
Block a user