46 lines
1.3 KiB
Rust
46 lines
1.3 KiB
Rust
|
use crate::defines::LevelInt;
|
||
|
use crate::ffi::{BorrowedPtr, ExternPointer, OwnedPtr};
|
||
|
use crate::static_data::{GrowthRate, GrowthRateLibrary};
|
||
|
use std::ffi::{c_char, CStr};
|
||
|
use std::ptr::drop_in_place;
|
||
|
|
||
|
#[no_mangle]
|
||
|
extern "C" fn growth_rate_library_new(capacity: usize) -> OwnedPtr<GrowthRateLibrary> {
|
||
|
Box::into_raw(Box::new(GrowthRateLibrary::new(capacity)))
|
||
|
}
|
||
|
|
||
|
#[no_mangle]
|
||
|
unsafe extern "C" fn growth_rate_library_drop(ptr: OwnedPtr<GrowthRateLibrary>) {
|
||
|
drop_in_place(ptr)
|
||
|
}
|
||
|
|
||
|
#[no_mangle]
|
||
|
unsafe extern "C" fn growth_rate_library_calculate_level(
|
||
|
ptr: ExternPointer<GrowthRateLibrary>,
|
||
|
growth_rate: BorrowedPtr<c_char>,
|
||
|
experience: u32,
|
||
|
) -> LevelInt {
|
||
|
ptr.as_ref()
|
||
|
.calculate_level(&CStr::from_ptr(growth_rate).into(), experience)
|
||
|
}
|
||
|
|
||
|
#[no_mangle]
|
||
|
unsafe extern "C" fn growth_rate_library_calculate_experience(
|
||
|
ptr: ExternPointer<GrowthRateLibrary>,
|
||
|
growth_rate: BorrowedPtr<c_char>,
|
||
|
level: LevelInt,
|
||
|
) -> u32 {
|
||
|
ptr.as_ref()
|
||
|
.calculate_experience(&CStr::from_ptr(growth_rate).into(), level)
|
||
|
}
|
||
|
|
||
|
#[no_mangle]
|
||
|
unsafe extern "C" fn growth_rate_library_add_growth_rate(
|
||
|
ptr: ExternPointer<GrowthRateLibrary>,
|
||
|
name: BorrowedPtr<c_char>,
|
||
|
growth_rate: OwnedPtr<Box<dyn GrowthRate>>,
|
||
|
) {
|
||
|
ptr.as_mut()
|
||
|
.add_growth_rate(&CStr::from_ptr(name).into(), *Box::from_raw(growth_rate));
|
||
|
}
|