From ec40f6e3acc7874b82709ab81b254c741529fdff Mon Sep 17 00:00:00 2001 From: Mica White Date: Mon, 26 Oct 2026 10:52:04 -0400 Subject: Finish engine --- platforms/tortuise-script-wasm/src/scene.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 platforms/tortuise-script-wasm/src/scene.rs (limited to 'platforms/tortuise-script-wasm/src/scene.rs') diff --git a/platforms/tortuise-script-wasm/src/scene.rs b/platforms/tortuise-script-wasm/src/scene.rs new file mode 100644 index 0000000..93889a7 --- /dev/null +++ b/platforms/tortuise-script-wasm/src/scene.rs @@ -0,0 +1,22 @@ +use crate::ScriptContext; + +mod tortuise { + #[link(wasm_import_module = "tortuise")] + unsafe extern "C" { + pub unsafe fn scene_id_by_name(context: u64, name: *const u8, length: usize) -> usize; + pub safe fn switch_scene(context: u64, id: usize); + } +} + +impl ScriptContext<'_> { + pub fn scene_id(&self, name: &str) -> Option { + let id = unsafe { tortuise::scene_id_by_name(self.0, name.as_ptr(), name.len()) }; + (id < usize::MAX).then_some(id) + } + + pub fn switch_scene(&mut self, name: &str) -> Option<()> { + let id = self.scene_id(name)?; + tortuise::switch_scene(self.0, id); + Some(()) + } +} -- cgit v1.3.1