2022-10-08 11:15:04 +00:00
|
|
|
use crate::ffi::{ExternPointer, IdentifiablePointer, OwnedPtr};
|
2022-09-18 16:02:13 +00:00
|
|
|
use crate::static_data::{StaticStatisticSet, Statistic, StatisticSet};
|
|
|
|
use std::ptr::drop_in_place;
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// Basic foreign function interface for a statistic set.
|
2022-09-18 16:02:13 +00:00
|
|
|
macro_rules! statistic_set {
|
|
|
|
($num_type:ident) => {
|
|
|
|
paste::paste!{
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn [<statistic_set_ $num_type _new>](
|
|
|
|
hp: $num_type,
|
|
|
|
attack: $num_type,
|
|
|
|
defense: $num_type,
|
|
|
|
special_attack: $num_type,
|
|
|
|
special_defense: $num_type,
|
|
|
|
speed: $num_type,
|
2022-10-08 11:15:04 +00:00
|
|
|
) -> IdentifiablePointer<StatisticSet<$num_type>> {
|
|
|
|
Box::new(StatisticSet::new(
|
2022-09-18 16:02:13 +00:00
|
|
|
hp,
|
|
|
|
attack,
|
|
|
|
defense,
|
|
|
|
special_attack,
|
|
|
|
special_defense,
|
|
|
|
speed,
|
2022-10-08 11:15:04 +00:00
|
|
|
)).into()
|
2022-09-18 16:02:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
unsafe extern "C" fn [<statistic_set_ $num_type _drop>](ptr: OwnedPtr<StatisticSet<$num_type>>) {
|
|
|
|
drop_in_place(ptr)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn [<statistic_set_ $num_type _get_stat>](ptr: ExternPointer<StatisticSet<$num_type>>, stat: Statistic) -> $num_type {
|
|
|
|
ptr.as_ref().get_stat(stat)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn [<statistic_set_ $num_type _set_stat>](ptr: ExternPointer<StatisticSet<$num_type>>, stat: Statistic, value: $num_type) {
|
|
|
|
ptr.as_ref().set_stat(stat, value)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn [<statistic_set_ $num_type _increase_stat>](ptr: ExternPointer<StatisticSet<$num_type>>, stat: Statistic, value: $num_type) {
|
|
|
|
ptr.as_ref().increase_stat(stat, value)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn [<statistic_set_ $num_type _decrease_stat>](ptr: ExternPointer<StatisticSet<$num_type>>, stat: Statistic, value: $num_type) {
|
|
|
|
ptr.as_ref().decrease_stat(stat, value)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
statistic_set!(u8);
|
|
|
|
statistic_set!(u16);
|
|
|
|
statistic_set!(u32);
|
|
|
|
statistic_set!(i8);
|
|
|
|
statistic_set!(i16);
|
|
|
|
statistic_set!(i32);
|
|
|
|
|
2022-10-14 14:53:30 +00:00
|
|
|
/// Basic foreign function interface for a static statistic set.
|
2022-09-18 16:02:13 +00:00
|
|
|
macro_rules! static_statistic_set {
|
|
|
|
($num_type:ident) => {
|
|
|
|
paste::paste!{
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn [<static_statistic_set_ $num_type _new>](
|
|
|
|
hp: $num_type,
|
|
|
|
attack: $num_type,
|
|
|
|
defense: $num_type,
|
|
|
|
special_attack: $num_type,
|
|
|
|
special_defense: $num_type,
|
|
|
|
speed: $num_type,
|
2022-10-08 11:15:04 +00:00
|
|
|
) -> IdentifiablePointer<StaticStatisticSet<$num_type>> {
|
|
|
|
Box::new(StaticStatisticSet::new(
|
2022-09-18 16:02:13 +00:00
|
|
|
hp,
|
|
|
|
attack,
|
|
|
|
defense,
|
|
|
|
special_attack,
|
|
|
|
special_defense,
|
|
|
|
speed,
|
2022-10-08 11:15:04 +00:00
|
|
|
)).into()
|
2022-09-18 16:02:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
unsafe extern "C" fn [<static_statistic_set_ $num_type _drop>](ptr: OwnedPtr<StaticStatisticSet<$num_type>>) {
|
|
|
|
drop_in_place(ptr)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn [<static_statistic_set_ $num_type _get_stat>](ptr: ExternPointer<StaticStatisticSet<$num_type>>, stat: Statistic) -> $num_type {
|
|
|
|
ptr.as_ref().get_stat(stat)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
static_statistic_set!(u8);
|
|
|
|
static_statistic_set!(u16);
|
|
|
|
static_statistic_set!(u32);
|
|
|
|
static_statistic_set!(i8);
|
|
|
|
static_statistic_set!(i16);
|
|
|
|
static_statistic_set!(i32);
|