0.1.0-2-beta.1.fix.3

This commit is contained in:
2026-09-17 16:57:36 +02:00
parent a278eb7109
commit 977b193e00
21 changed files with 289 additions and 39 deletions

View File

@@ -1,5 +1,5 @@
// file: crates/engines/engine-v1-sdl/src/lib.rs
// version: 3
// version: 4
#![warn(missing_docs)]
#![deny(unreachable_pub)]
@@ -12,3 +12,5 @@ mod unit_tests;
/// Re-export of the minimal SDL3 runtime used by Desktop POC runners.
pub use self::runtime::SdlRuntime;
/// Re-export of the platform-native Back request bridge.
pub use self::runtime::request_platform_back;

View File

@@ -1,5 +1,5 @@
// file: crates/engines/engine-v1-sdl/src/runtime.rs
// version: 11
// version: 12
/// Minimal SDL3 runtime used by Desktop and Android POC runners.
pub struct SdlRuntime {
@@ -9,6 +9,17 @@ pub struct SdlRuntime {
frame_duration: std::time::Duration,
}
static PLATFORM_BACK_REQUESTED: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
/// Requests the active SDL runtime to evaluate a platform-native Back action.
///
/// Platform adapters use this signal when the host operating system does not expose Back
/// as a normal SDL keyboard event.
pub fn request_platform_back() {
PLATFORM_BACK_REQUESTED.store(true, std::sync::atomic::Ordering::Release);
return;
}
impl SdlRuntime {
/// Creates a minimal SDL3 runtime configuration.
#[must_use]
@@ -21,10 +32,6 @@ impl SdlRuntime {
where
G: engine_v1_common::EngineGame,
{
#[cfg(target_os = "android")]
{
let _ = sdl3::hint::set(sdl3::hint::names::ANDROID_TRAP_BACK_BUTTON, "1");
}
let sdl = match sdl3::init() {
std::result::Result::Ok(value) => value,
std::result::Result::Err(error) => return std::result::Result::Err(error.to_string()),
@@ -47,6 +54,12 @@ impl SdlRuntime {
let mut pointer = engine_v1_common::PointerState::inactive();
tracing::info!(title = %self.title, width = self.width, height = self.height, "SDL3 runtime started");
'running: loop {
if take_platform_back_request() {
tracing::info!(source = "platform_back", "SDL3 platform Back requested");
if quit_requested(game, engine_v1_common::QuitSource::PlatformBack) {
break 'running;
}
}
let mut input = engine_v1_common::InputState::none().with_pointer(pointer);
for event in events.poll_iter() {
match event {
@@ -166,6 +179,10 @@ fn render_scene(canvas: &mut sdl3::render::WindowCanvas, scene: engine_v1_common
const SWIPE_DIRECTION_THRESHOLD: f32 = 0.04;
fn take_platform_back_request() -> bool {
return PLATFORM_BACK_REQUESTED.swap(false, std::sync::atomic::Ordering::AcqRel);
}
fn quit_requested<G>(game: &mut G, source: engine_v1_common::QuitSource) -> bool
where
G: engine_v1_common::EngineGame,

View File

@@ -1,5 +1,5 @@
// file: crates/engines/engine-v1-sdl/unit_tests/swipe.rs
// version: 3
// version: 4
fn pointer(x: f32, y: f32) -> engine_v1_common::PointerState {
return engine_v1_common::PointerState::normalized(true, x, y);
@@ -48,3 +48,10 @@ fn runtime_respects_game_quit_decision() {
assert!(!super::quit_requested(&mut game, engine_v1_common::QuitSource::PlatformBack));
assert_eq!(game.requests, 1);
}
#[test]
fn platform_back_bridge_is_consumed_once() {
super::request_platform_back();
assert!(super::take_platform_back_request());
assert!(!super::take_platform_back_request());
}