From 3e38572869c3d6010f331a1bec20d7b175dc4810 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Wed, 16 Oct 2024 20:59:39 -0700 Subject: [PATCH] update roblox emulator: thread scheduler --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- src/main.rs | 11 +++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 73379bf..d6b4609 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -588,9 +588,9 @@ dependencies = [ [[package]] name = "roblox_emulator" -version = "0.4.5" +version = "0.4.6" source = "sparse+https://git.itzana.me/api/packages/strafesnet/cargo/" -checksum = "e571815fbe60c55af562c4c3f24754a6d207c09f9e4ae4e52231a712b5b943dc" +checksum = "03e2535327bd9069b20caa9df0a5cac87fa886cd2418c7f174016502d584a488" dependencies = [ "glam", "mlua", diff --git a/Cargo.toml b/Cargo.toml index 567df7d..361ecd4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ authors = ["Rhys Lloyd "] [dependencies] anyhow = "1.0.89" clap = { version = "4.5.18", features = ["derive"] } -roblox_emulator = { version = "0.4.5", registry = "strafesnet" } +roblox_emulator = { version = "0.4.6", registry = "strafesnet" } rbx_binary = { version = "0.7.4", registry = "strafesnet" } rbx_dom_weak = { version = "2.9.0", registry = "strafesnet" } rbx_xml = { version = "0.13.3", registry = "strafesnet" } diff --git a/src/main.rs b/src/main.rs index 5119c20..cafac1b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -42,6 +42,14 @@ fn main()->anyhow::Result<()>{ } } +fn run_runnable_to_completion(runnable:&roblox_emulator::runner::Runnable)->anyhow::Result<()>{ + while runnable.has_scheduled_threads()?{ + runnable.game_tick()?; + std::thread::sleep(std::time::Duration::from_nanos(1_000_000_000/60)); + } + Ok(()) +} + fn run_script(input_file:PathBuf)->anyhow::Result<()>{ let source={ let mut source=String::new(); @@ -52,6 +60,7 @@ fn run_script(input_file:PathBuf)->anyhow::Result<()>{ let runner=roblox_emulator::runner::Runner::new()?; let runnable=runner.runnable_context_with_services(&mut context,&services)?; runnable.run_script(script)?; + run_runnable_to_completion(&runnable)?; Ok(()) } @@ -90,6 +99,7 @@ fn run_model(input_file:PathBuf)->anyhow::Result<()>{ for script in scripts{ runnable.run_script(script)?; } + run_runnable_to_completion(&runnable)?; Ok(()) } @@ -103,5 +113,6 @@ fn run_place(input_file:PathBuf)->anyhow::Result<()>{ for script in scripts{ runnable.run_script(script)?; } + run_runnable_to_completion(&runnable)?; Ok(()) }