More removal of RwLocks and replace it with Atomics, to prevent locks.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-06-18 14:17:29 +02:00
parent 59d7344729
commit c45c7538bf
15 changed files with 293 additions and 192 deletions

View File

@@ -1,13 +1,14 @@
use crate::dynamic_data::models::pokemon::Pokemon;
use crate::static_data::statistic_set::StatisticSet;
use crate::static_data::statistics::Statistic;
use std::sync::atomic::AtomicU32;
#[derive(Debug)]
pub struct BattleStatCalculator {}
impl BattleStatCalculator {
pub fn calculate_flat_stats(&self, pokemon: &Pokemon) -> StatisticSet<u32> {
StatisticSet::<u32>::new(
pub fn calculate_flat_stats(&self, pokemon: &Pokemon) -> StatisticSet<AtomicU32> {
StatisticSet::<AtomicU32>::new(
self.calculate_health_stat(pokemon),
self.calculate_other_stat(pokemon, Statistic::Attack),
self.calculate_other_stat(pokemon, Statistic::Defense),
@@ -25,8 +26,8 @@ impl BattleStatCalculator {
}
}
pub fn calculate_boosted_stats(&self, pokemon: &Pokemon) -> StatisticSet<u32> {
StatisticSet::<u32>::new(
pub fn calculate_boosted_stats(&self, pokemon: &Pokemon) -> StatisticSet<AtomicU32> {
StatisticSet::<AtomicU32>::new(
self.calculate_boosted_stat(pokemon, Statistic::HP),
self.calculate_boosted_stat(pokemon, Statistic::Attack),
self.calculate_boosted_stat(pokemon, Statistic::Defense),

View File

@@ -39,7 +39,7 @@ impl<'library> Debug for dyn MiscLibrary<'library> {
#[derive(Debug)]
pub struct Gen7MiscLibrary<'library> {
struggle_data: *const MoveData,
struggle_learned_move: Arc<RwLock<LearnedMove<'library>>>,
struggle_learned_move: Arc<LearnedMove<'library>>,
}
impl<'library> Gen7MiscLibrary<'library> {
@@ -50,17 +50,14 @@ impl<'library> Gen7MiscLibrary<'library> {
MoveCategory::Physical,
50,
255,
10,
255,
MoveTarget::Any,
0,
SecondaryEffect::new(-1.0, StringKey::new("struggle"), vec![]),
HashSet::new(),
));
let struggle_ptr = Box::into_raw(struggle_data);
let struggle_learned_move = Arc::new(RwLock::new(LearnedMove::new(
unsafe { &*struggle_ptr },
MoveLearnMethod::Unknown,
)));
let struggle_learned_move = Arc::new(LearnedMove::new(unsafe { &*struggle_ptr }, MoveLearnMethod::Unknown));
Self {
struggle_data: struggle_ptr,
struggle_learned_move,