Clippy fixes, additional WASM registration work
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -3,7 +3,6 @@ use std::sync::atomic::{AtomicBool, AtomicPtr, AtomicUsize};
|
||||
use std::sync::{Arc, Weak};
|
||||
|
||||
use hashbrown::HashSet;
|
||||
use wasmer::NativeFunc;
|
||||
|
||||
use crate::dynamic_data::{DynamicLibrary, Script, TurnChoice};
|
||||
use crate::script_implementations::wasm::extern_ref::{ExternRef, VecExternRef};
|
||||
@@ -67,6 +66,28 @@ impl Script for WebAssemblyScript {
|
||||
&self.suppressed_count
|
||||
}
|
||||
|
||||
fn stack(&self) {
|
||||
if !self.capabilities.contains(&WebAssemblyScriptCapabilities::OnStack) {
|
||||
return;
|
||||
}
|
||||
let env = self.environment.upgrade().unwrap();
|
||||
let func = env.script_function_cache().stack(&env);
|
||||
if let Some(func) = func {
|
||||
func.call(self.self_ptr).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
fn on_remove(&self) {
|
||||
if !self.capabilities.contains(&WebAssemblyScriptCapabilities::OnRemove) {
|
||||
return;
|
||||
}
|
||||
let env = self.environment.upgrade().unwrap();
|
||||
let func = env.script_function_cache().on_remove(&env);
|
||||
if let Some(func) = func {
|
||||
func.call(self.self_ptr).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
fn on_initialize(&self, library: &DynamicLibrary, pars: &[EffectParameter]) {
|
||||
if !self.capabilities.contains(&WebAssemblyScriptCapabilities::Initialize) {
|
||||
return;
|
||||
@@ -101,15 +122,30 @@ impl Script for WebAssemblyScript {
|
||||
}
|
||||
|
||||
let env = self.environment.upgrade().unwrap();
|
||||
let exported = env.exported_functions();
|
||||
if let Some(f) = exported.get::<StringKey>(&"script_change_speed".into()) {
|
||||
let func: NativeFunc<(u32, ExternRef<TurnChoice>, u32), ()> = f.native().unwrap();
|
||||
let ptr = env.temp_allocate_mem_typed::<u32>();
|
||||
let func = env.script_function_cache().change_speed(&env);
|
||||
if let Some(func) = func {
|
||||
let ptr = env.temp_allocate_mem_typed::<u32>(*speed);
|
||||
func.call(self.self_ptr, ExternRef::new(env.as_ref(), choice), ptr.wasm_pointer)
|
||||
.unwrap();
|
||||
unsafe {
|
||||
*speed = *ptr.ptr;
|
||||
}
|
||||
*speed = *ptr.value();
|
||||
}
|
||||
}
|
||||
|
||||
fn change_priority(&self, choice: &TurnChoice, priority: &mut i8) {
|
||||
if !self
|
||||
.capabilities
|
||||
.contains(&WebAssemblyScriptCapabilities::ChangePriority)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
let env = self.environment.upgrade().unwrap();
|
||||
let func = env.script_function_cache().change_priority(&env);
|
||||
if let Some(func) = func {
|
||||
let ptr = env.temp_allocate_mem_typed::<i8>(*priority);
|
||||
func.call(self.self_ptr, ExternRef::new(env.as_ref(), choice), ptr.wasm_pointer)
|
||||
.unwrap();
|
||||
*priority = *ptr.value();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user