Skip to content

Commit 4e8a8f7

Browse files
committed
feat(ffi): add processing_poll_events for external event loop integration
Exposes a C FFI function that ticks Bevy's app one frame, allowing embedders that manage their own window and event loop (e.g. a native C++ host using GLFW) to advance libprocessing's internal state each frame without using the built-in GLFW runner. The pattern is: processing_init(); processing_surface_create(...); processing_graphics_create(...); while (running) { running = processing_poll_events(); processing_begin_draw(gfx); // draw calls processing_end_draw(gfx); } Adds processing_core as a direct dependency of processing_ffi since app_mut is not re-exported through processing::prelude.
1 parent b398b97 commit 4e8a8f7

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

crates/processing_ffi/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ cuda = ["processing/cuda"]
1919

2020
[dependencies]
2121
processing = { workspace = true }
22+
processing_core = { workspace = true }
2223
bevy = { workspace = true }
2324
half = "2.7"
2425

crates/processing_ffi/src/lib.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4437,21 +4437,25 @@ fn key_code_to_u32(kc: KeyCode) -> u32 {
44374437
}
44384438
}
44394439

4440-
/// Tick the Bevy app one frame and poll GLFW events.
4440+
/// Tick the Bevy app one frame.
44414441
/// Call this once per frame from your external event loop, before begin_draw.
44424442
/// Returns true if the app should continue running, false if it should exit.
44434443
///
4444+
/// This is intended for embedders that drive their own window and event loop
4445+
/// (e.g. a native C++ host) and need to advance libprocessing's internal state
4446+
/// each frame without using the built-in GLFW runner.
4447+
///
44444448
/// SAFETY:
4445-
/// - processing_init has been called.
4446-
/// - This is called from the same thread as init.
4449+
/// - `processing_init` has been called.
4450+
/// - This is called from the same thread as `init`.
4451+
/// - This must not be called after `processing_exit`.
44474452
#[unsafe(no_mangle)]
44484453
pub extern "C" fn processing_poll_events() -> bool {
44494454
error::clear_error();
4450-
let result = processing_core::app_mut(|app| {
4455+
match processing_core::app_mut(|app| {
44514456
app.update();
44524457
Ok(())
4453-
});
4454-
match result {
4458+
}) {
44554459
Ok(_) => true,
44564460
Err(_) => false,
44574461
}

0 commit comments

Comments
 (0)