diff --git a/Cargo.lock b/Cargo.lock index 350f0e5a..6c4dc6d1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6167,6 +6167,7 @@ dependencies = [ "cbindgen", "half", "processing", + "processing_core", ] [[package]] diff --git a/crates/processing_ffi/Cargo.toml b/crates/processing_ffi/Cargo.toml index 16d41364..286fedb4 100644 --- a/crates/processing_ffi/Cargo.toml +++ b/crates/processing_ffi/Cargo.toml @@ -19,6 +19,7 @@ cuda = ["processing/cuda"] [dependencies] processing = { workspace = true } +processing_core = { workspace = true } bevy = { workspace = true } half = "2.7" diff --git a/crates/processing_ffi/src/lib.rs b/crates/processing_ffi/src/lib.rs index 297202a3..3f2bff64 100644 --- a/crates/processing_ffi/src/lib.rs +++ b/crates/processing_ffi/src/lib.rs @@ -4453,3 +4453,27 @@ fn key_code_to_u32(kc: KeyCode) -> u32 { _ => 0, } } + +/// Tick the Bevy app one frame. +/// Call this once per frame from your external event loop, before begin_draw. +/// Returns true if the app should continue running, false if it should exit. +/// +/// This is intended for embedders that drive their own window and event loop +/// (e.g. a native C++ host) and need to advance libprocessing's internal state +/// each frame without using the built-in GLFW runner. +/// +/// SAFETY: +/// - `processing_init` has been called. +/// - This is called from the same thread as `init`. +/// - This must not be called after `processing_exit`. +#[unsafe(no_mangle)] +pub extern "C" fn processing_poll_events() -> bool { + error::clear_error(); + match processing_core::app_mut(|app| { + app.update(); + Ok(()) + }) { + Ok(_) => true, + Err(_) => false, + } +}