Complete refactor of the FFI to use handles instead of pointers.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -26,13 +26,11 @@ use crate::static_data::TypeIdentifier;
|
||||
use crate::static_data::{Ability, Statistic};
|
||||
use crate::static_data::{ClampedStatisticSet, StatisticSet};
|
||||
use crate::utils::Random;
|
||||
use crate::{script_hook, PkmnError, StringKey, ValueIdentifiable, ValueIdentifier, VecExt};
|
||||
use crate::{script_hook, PkmnError, StringKey, VecExt};
|
||||
use anyhow::{anyhow, bail, Result};
|
||||
|
||||
/// The data of a Pokemon.
|
||||
struct PokemonData {
|
||||
/// A unique identifier so we know what value this is.
|
||||
identifier: ValueIdentifier,
|
||||
/// The library data of the Pokemon.
|
||||
library: Arc<dyn DynamicLibrary>,
|
||||
/// The species of the Pokemon.
|
||||
@@ -165,7 +163,6 @@ impl Pokemon {
|
||||
.get_nature(nature)
|
||||
.ok_or(PkmnError::InvalidNatureName { nature: nature.clone() })?;
|
||||
let pokemon_data = PokemonData {
|
||||
identifier: Default::default(),
|
||||
library,
|
||||
species: RwLock::new(species),
|
||||
form: RwLock::new(form.clone()),
|
||||
@@ -546,7 +543,7 @@ impl Pokemon {
|
||||
|
||||
/// Change the form of the Pokemon.
|
||||
pub fn change_form(&self, form: &Arc<dyn Form>) -> Result<()> {
|
||||
if self.form().value_identifier() == form.value_identifier() {
|
||||
if Arc::ptr_eq(&self.form(), form) {
|
||||
return Ok(());
|
||||
}
|
||||
*self.data.form.write() = form.clone();
|
||||
@@ -818,6 +815,10 @@ impl Pokemon {
|
||||
data: Arc::downgrade(&self.data),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_ptr(&self) -> *const c_void {
|
||||
Arc::as_ptr(&self.data) as *const c_void
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for Pokemon {
|
||||
@@ -938,12 +939,6 @@ impl VolatileScriptsOwner for Pokemon {
|
||||
}
|
||||
}
|
||||
|
||||
impl ValueIdentifiable for Pokemon {
|
||||
fn value_identifier(&self) -> ValueIdentifier {
|
||||
self.data.identifier
|
||||
}
|
||||
}
|
||||
|
||||
/// A source of damage. This should be as unique as possible.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
#[repr(u8)]
|
||||
|
||||
Reference in New Issue
Block a user