0.1.0-0-pre.11

This commit is contained in:
2026-09-16 11:32:07 +02:00
parent fa098943bf
commit ab9403384f
14 changed files with 465 additions and 44 deletions

View File

@@ -1,5 +1,5 @@
// file: crates/engines/engine-v1-sdl/src/runtime.rs
// version: 7
// version: 8
/// Minimal SDL3 runtime used by Desktop and Android POC runners.
pub struct SdlRuntime {
@@ -47,9 +47,22 @@ impl SdlRuntime {
match event {
sdl3::event::Event::Quit { .. } => break 'running,
sdl3::event::Event::KeyDown { keycode: Some(sdl3::keyboard::Keycode::Escape), .. } => break 'running,
sdl3::event::Event::KeyDown { keycode: Some(sdl3::keyboard::Keycode::Left), repeat: false, .. } => {
input = input.with_action(engine_v1_common::GameAction::Left, true);
},
sdl3::event::Event::KeyDown { keycode: Some(sdl3::keyboard::Keycode::Right), repeat: false, .. } => {
input = input.with_action(engine_v1_common::GameAction::Right, true);
},
sdl3::event::Event::KeyDown { keycode: Some(sdl3::keyboard::Keycode::Up), repeat: false, .. } => {
input = input.with_action(engine_v1_common::GameAction::Up, true);
},
sdl3::event::Event::KeyDown { keycode: Some(sdl3::keyboard::Keycode::Down), repeat: false, .. } => {
input = input.with_action(engine_v1_common::GameAction::Down, true);
},
sdl3::event::Event::MouseButtonDown { mouse_btn: sdl3::mouse::MouseButton::Left, x, y, .. } => {
pointer = normalize_mouse_pointer(&canvas, true, x, y);
input = input.with_pointer(pointer).with_action(engine_v1_common::GameAction::Primary, true);
input = apply_pointer_direction(input, pointer);
},
sdl3::event::Event::MouseButtonUp { mouse_btn: sdl3::mouse::MouseButton::Left, x, y, .. } => {
pointer = normalize_mouse_pointer(&canvas, false, x, y);
@@ -62,6 +75,7 @@ impl SdlRuntime {
sdl3::event::Event::FingerDown { x, y, .. } => {
pointer = engine_v1_common::PointerState::normalized(true, x, y);
input = input.with_pointer(pointer).with_action(engine_v1_common::GameAction::Primary, true);
input = apply_pointer_direction(input, pointer);
},
sdl3::event::Event::FingerMotion { x, y, .. } => {
pointer = engine_v1_common::PointerState::normalized(true, x, y);
@@ -119,3 +133,20 @@ fn render_scene(canvas: &mut sdl3::render::WindowCanvas, scene: engine_v1_common
canvas.present();
return std::result::Result::Ok(());
}
fn apply_pointer_direction(mut input: engine_v1_common::InputState, pointer: engine_v1_common::PointerState) -> engine_v1_common::InputState {
let horizontal = pointer.x() - 0.5;
let vertical = pointer.y() - 0.5;
if horizontal.abs() >= vertical.abs() {
if horizontal < 0.0 {
input = input.with_action(engine_v1_common::GameAction::Left, true);
} else {
input = input.with_action(engine_v1_common::GameAction::Right, true);
}
} else if vertical < 0.0 {
input = input.with_action(engine_v1_common::GameAction::Up, true);
} else {
input = input.with_action(engine_v1_common::GameAction::Down, true);
}
return input;
}