From 62d4dcd12031c1449c94bbc24389cb0f84addfeb Mon Sep 17 00:00:00 2001 From: Kayh Date: Sun, 13 Oct 2024 19:30:17 -0400 Subject: [PATCH] clean up --- .../src/api/wired/input/input_handler.rs | 19 +++++++++++++++++++ .../src/api/wired/player/player.rs | 5 +---- crates/unavi-scripting/tests/scripts.rs | 5 +---- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/crates/unavi-scripting/src/api/wired/input/input_handler.rs b/crates/unavi-scripting/src/api/wired/input/input_handler.rs index 67280749f..7b1e4e107 100644 --- a/crates/unavi-scripting/src/api/wired/input/input_handler.rs +++ b/crates/unavi-scripting/src/api/wired/input/input_handler.rs @@ -83,6 +83,25 @@ impl HostInputHandler for ScriptData { } fn drop(&mut self, rep: Resource) -> wasm_bridge::Result<()> { + self.table.delete(rep)?; Ok(()) } } + +#[cfg(test)] +mod tests { + use crate::api::tests::init_test_data; + + use super::*; + + #[test] + fn test_cleanup_resource() { + let (_, mut data) = init_test_data(); + + let res = HostInputHandler::new(&mut data).unwrap(); + let res_weak = Resource::::new_own(res.rep()); + + HostInputHandler::drop(&mut data, res).unwrap(); + assert!(data.table.get(&res_weak).is_err()); + } +} diff --git a/crates/unavi-scripting/src/api/wired/player/player.rs b/crates/unavi-scripting/src/api/wired/player/player.rs index 6cad9a80d..b654e75ca 100644 --- a/crates/unavi-scripting/src/api/wired/player/player.rs +++ b/crates/unavi-scripting/src/api/wired/player/player.rs @@ -3,10 +3,7 @@ use std::sync::{Arc, RwLock}; use wasm_bridge::component::Resource; use wasm_bridge_wasi::ResourceTable; -use crate::{ - api::wired::scene::{bindings::node::HostNode, nodes::base::NodeRes}, - data::ScriptData, -}; +use crate::{api::wired::scene::nodes::base::NodeRes, data::ScriptData}; use super::bindings::api::{HostPlayer, Node, Skeleton}; diff --git a/crates/unavi-scripting/tests/scripts.rs b/crates/unavi-scripting/tests/scripts.rs index 0ad7c3db3..7f2884ca3 100644 --- a/crates/unavi-scripting/tests/scripts.rs +++ b/crates/unavi-scripting/tests/scripts.rs @@ -39,7 +39,7 @@ pub async fn test_script(name: &str) { let mut did_load = false; - let step = Duration::from_secs_f32(0.5); + let step = Duration::from_secs_f32(0.25); app.insert_resource(Time::::from_duration(step)); for i in 0..10 { @@ -57,9 +57,6 @@ pub async fn test_script(name: &str) { assert!(did_load); - let step = Duration::from_secs_f32(0.1); - app.insert_resource(Time::::from_duration(step)); - for i in 0..NUM_UPDATES { debug!("Updating... ({})", i); tokio::time::sleep(step).await;