Fixes for growth rate FFI
This commit is contained in:
parent
726e294f11
commit
1070753be7
|
@ -4,24 +4,22 @@ use crate::static_data::{GrowthRate, LookupGrowthRate};
|
||||||
use std::ptr::drop_in_place;
|
use std::ptr::drop_in_place;
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
unsafe extern "C" fn growth_rate_lookup_new(array: *const u32, length: usize) -> OwnedPtr<LookupGrowthRate> {
|
unsafe extern "C" fn growth_rate_lookup_new(array: *const u32, length: usize) -> OwnedPtr<Box<dyn GrowthRate>> {
|
||||||
let array = std::slice::from_raw_parts(array, length);
|
let array = std::slice::from_raw_parts(array, length);
|
||||||
Box::into_raw(Box::new(LookupGrowthRate::new(array.to_vec())))
|
Box::into_raw(Box::new(Box::new(LookupGrowthRate::new(array.to_vec()))))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
unsafe extern "C" fn growth_rate_lookup_drop(ptr: OwnedPtr<LookupGrowthRate>) {
|
unsafe extern "C" fn growth_rate_lookup_drop(ptr: OwnedPtr<Box<dyn GrowthRate>>) {
|
||||||
drop_in_place(ptr)
|
drop_in_place(ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
#[allow(improper_ctypes_definitions)]
|
extern "C" fn growth_rate_calculate_level(ptr: ExternPointer<Box<dyn GrowthRate>>, experience: u32) -> LevelInt {
|
||||||
extern "C" fn growth_rate_calculate_level(ptr: ExternPointer<dyn GrowthRate>, experience: u32) -> LevelInt {
|
|
||||||
ptr.as_ref().calculate_level(experience)
|
ptr.as_ref().calculate_level(experience)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
#[allow(improper_ctypes_definitions)]
|
extern "C" fn growth_rate_calculate_experience(ptr: ExternPointer<Box<dyn GrowthRate>>, level: LevelInt) -> u32 {
|
||||||
extern "C" fn growth_rate_calculate_experience(ptr: ExternPointer<dyn GrowthRate>, level: LevelInt) -> u32 {
|
|
||||||
ptr.as_ref().calculate_experience(level)
|
ptr.as_ref().calculate_experience(level)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue