From 8950bcbf020c1b78738e6cb809352fdce49ac1d2 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Wed, 16 Oct 2024 19:50:40 -0700 Subject: [PATCH] game ticks api --- src/runner/runner.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/runner/runner.rs b/src/runner/runner.rs index 80efe97..04611e6 100644 --- a/src/runner/runner.rs +++ b/src/runner/runner.rs @@ -90,4 +90,23 @@ impl Runnable<'_>{ .set_name(name) .exec().map_err(|error|Error::Lua{source,error}) } + pub fn has_scheduled_threads(&self)->Result{ + scheduler_mut(&self.lua,|scheduler| + Ok(scheduler.has_scheduled_threads()) + ) + } + pub fn game_tick(&self)->Result<(),mlua::Error>{ + if let Some(threads)=scheduler_mut(&self.lua,|scheduler|Ok(scheduler.tick_threads()))?{ + for thread in threads{ + //TODO: return dt and total run time + let result=thread.resume::((1.0/30.0,0.0)) + .map_err(|error|Error::Lua{source:"source unavailable".to_owned(),error}); + match result{ + Ok(_)=>(), + Err(e)=>println!("game_tick Error: {e}"), + } + } + } + Ok(()) + } }