Initial work on DynamicLibrary up to and including the Pokemon model.

This commit is contained in:
Deukhoofd 2023-01-03 16:53:58 +01:00
parent 62a3ffb2bf
commit 7511f56b1a
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
6 changed files with 42 additions and 7 deletions

View File

@ -1,5 +1,6 @@
use crate::dynamic_data::{BattleStatCalculator, Gen7BattleStatCalculator};
use crate::ffi::IdentifiablePointer;
use crate::ffi::{IdentifiablePointer, OwnedPtr};
use std::ptr::drop_in_place;
/// Creates a new Gen 7 battle stat calculator
#[no_mangle]
@ -9,3 +10,9 @@ extern "C" fn gen_7_battle_stat_calculator_new() -> IdentifiablePointer<Box<dyn
let ptr = Box::into_raw(Box::new(v));
IdentifiablePointer::new(ptr, id)
}
/// Drops a battle stat calculator.
#[no_mangle]
extern "C" fn battle_stat_calculator_drop(ptr: OwnedPtr<Box<dyn BattleStatCalculator>>) {
unsafe { drop_in_place(ptr) };
}

View File

@ -1,5 +1,6 @@
use crate::dynamic_data::{DamageLibrary, Gen7DamageLibrary};
use crate::ffi::IdentifiablePointer;
use crate::ffi::{IdentifiablePointer, OwnedPtr};
use std::ptr::drop_in_place;
/// Creates a new generation 7 damage library. `has_randomness` defines whether a random damage
/// modifier (0.85x - 1.00x) is applied to the calculated damage.
@ -10,3 +11,9 @@ extern "C" fn gen_7_damage_library_new(randomness: u8) -> IdentifiablePointer<Bo
let ptr = Box::into_raw(Box::new(v));
IdentifiablePointer::new(ptr, id)
}
/// Drops a DamageLibrary.
#[no_mangle]
extern "C" fn damage_library_drop(ptr: OwnedPtr<Box<dyn DamageLibrary>>) {
unsafe { drop_in_place(ptr) };
}

View File

@ -3,6 +3,7 @@ use crate::dynamic_data::{
};
use crate::ffi::{IdentifiablePointer, OwnedPtr};
use crate::static_data::StaticData;
use std::ptr::drop_in_place;
use std::sync::Arc;
/// Instantiates a new DynamicLibrary with given parameters.
@ -25,3 +26,9 @@ extern "C" fn dynamic_library_new(
a.into()
}
}
/// Drops a dynamic library.
#[no_mangle]
extern "C" fn dynamic_library_drop(ptr: OwnedPtr<Arc<dyn StaticData>>) {
unsafe { drop_in_place(ptr) };
}

View File

@ -1,5 +1,6 @@
use crate::dynamic_data::{Gen7MiscLibrary, MiscLibrary};
use crate::ffi::IdentifiablePointer;
use crate::ffi::{IdentifiablePointer, OwnedPtr};
use std::ptr::drop_in_place;
/// Instantiates a new MiscLibrary.
#[no_mangle]
@ -9,3 +10,9 @@ extern "C" fn gen_7_misc_library_new() -> IdentifiablePointer<Box<dyn MiscLibrar
let ptr = Box::into_raw(Box::new(v));
IdentifiablePointer::new(ptr, id)
}
/// Drops a MiscLibrary.
#[no_mangle]
extern "C" fn misc_library_drop(ptr: OwnedPtr<Box<dyn MiscLibrary>>) {
unsafe { drop_in_place(ptr) };
}

View File

@ -1,5 +1,6 @@
use crate::dynamic_data::{EmptyScriptResolver, ScriptResolver};
use crate::ffi::IdentifiablePointer;
use crate::ffi::{IdentifiablePointer, OwnedPtr};
use std::ptr::drop_in_place;
/// Instantiates a basic empty script resolver, that always returns None.
#[no_mangle]
@ -12,6 +13,12 @@ extern "C" fn empty_script_resolver_new() -> IdentifiablePointer<Box<dyn ScriptR
IdentifiablePointer::new(ptr, id)
}
/// Drops a script resolver.
#[no_mangle]
extern "C" fn script_resolver_drop(ptr: OwnedPtr<Box<dyn ScriptResolver>>) {
unsafe { drop_in_place(ptr) };
}
/// Foreign function interfaces for the Webassembly script resolver.
#[cfg(feature = "wasm")]
mod web_assembly_script_resolver {

View File

@ -14,7 +14,7 @@ extern "C" fn pokemon_new(
library: ExternPointer<Arc<dyn DynamicLibrary>>,
species: ExternPointer<Arc<dyn Species>>,
form: ExternPointer<Arc<dyn Form>>,
hidden_ability: bool,
hidden_ability: u8,
ability_index: u8,
level: LevelInt,
unique_identifier: u32,
@ -28,7 +28,7 @@ extern "C" fn pokemon_new(
species.as_ref().clone(),
form.as_ref(),
AbilityIndex {
hidden: hidden_ability,
hidden: hidden_ability == 1,
index: ability_index,
},
level,
@ -246,7 +246,7 @@ extern "C" fn pokemon_get_battle_side_index(ptr: ExternPointer<Arc<Pokemon>>) ->
}
/// Get the index of the slot on the side of the battle the Pokemon is in. If the Pokemon
// is not on the battlefield, this always returns 0.
/// is not on the battlefield, this always returns 0.
#[no_mangle]
extern "C" fn pokemon_get_battle_index(ptr: ExternPointer<Arc<Pokemon>>) -> u8 {
ptr.as_ref().get_battle_index().unwrap_or_default()