Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
kayhhh committed Oct 13, 2024
1 parent 5c3eb3b commit 62d4dcd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
19 changes: 19 additions & 0 deletions crates/unavi-scripting/src/api/wired/input/input_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,25 @@ impl HostInputHandler for ScriptData {
}

fn drop(&mut self, rep: Resource<InputHandlerRes>) -> 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::<InputHandlerRes>::new_own(res.rep());

HostInputHandler::drop(&mut data, res).unwrap();
assert!(data.table.get(&res_weak).is_err());
}
}
5 changes: 1 addition & 4 deletions crates/unavi-scripting/src/api/wired/player/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
5 changes: 1 addition & 4 deletions crates/unavi-scripting/tests/scripts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Fixed>::from_duration(step));

for i in 0..10 {
Expand All @@ -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::<Fixed>::from_duration(step));

for i in 0..NUM_UPDATES {
debug!("Updating... ({})", i);
tokio::time::sleep(step).await;
Expand Down

0 comments on commit 62d4dcd

Please sign in to comment.