54 lines
1.7 KiB
Rust
54 lines
1.7 KiB
Rust
// 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;
|
|
},
|
|
}
|
|
}
|