2022-09-18 16:02:13 +00:00
|
|
|
use crate::defines::LevelInt;
|
|
|
|
use crate::ffi::{ExternPointer, OwnedPtr};
|
|
|
|
use crate::static_data::{GrowthRate, LookupGrowthRate};
|
|
|
|
use std::ptr::drop_in_place;
|
|
|
|
|
|
|
|
#[no_mangle]
|
2022-09-20 16:04:19 +00:00
|
|
|
unsafe extern "C" fn growth_rate_lookup_new(array: *const u32, length: usize) -> OwnedPtr<Box<dyn GrowthRate>> {
|
2022-09-18 16:02:13 +00:00
|
|
|
let array = std::slice::from_raw_parts(array, length);
|
2022-09-20 16:04:19 +00:00
|
|
|
Box::into_raw(Box::new(Box::new(LookupGrowthRate::new(array.to_vec()))))
|
2022-09-18 16:02:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2022-09-20 16:04:19 +00:00
|
|
|
unsafe extern "C" fn growth_rate_lookup_drop(ptr: OwnedPtr<Box<dyn GrowthRate>>) {
|
2022-09-18 16:02:13 +00:00
|
|
|
drop_in_place(ptr)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2022-09-20 16:04:19 +00:00
|
|
|
extern "C" fn growth_rate_calculate_level(ptr: ExternPointer<Box<dyn GrowthRate>>, experience: u32) -> LevelInt {
|
2022-09-18 16:02:13 +00:00
|
|
|
ptr.as_ref().calculate_level(experience)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2022-09-20 16:04:19 +00:00
|
|
|
extern "C" fn growth_rate_calculate_experience(ptr: ExternPointer<Box<dyn GrowthRate>>, level: LevelInt) -> u32 {
|
2022-09-18 16:02:13 +00:00
|
|
|
ptr.as_ref().calculate_experience(level)
|
|
|
|
}
|