Don't store the ChoiceQueue as an Arc<RwLock> to prevent locking issues.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-06-18 10:41:42 +02:00
parent 09c2533bf5
commit 59d7344729
3 changed files with 19 additions and 16 deletions

View File

@@ -27,7 +27,7 @@ pub struct Battle<'own, 'library> {
pokemon_per_side: u8,
sides: Vec<BattleSide<'own, 'library>>,
random: BattleRandom,
current_turn_queue: Option<Arc<RwLock<ChoiceQueue<'own, 'library>>>>,
current_turn_queue: Option<ChoiceQueue<'own, 'library>>,
has_ended: bool,
result: BattleResult,
event_hook: EventHook,
@@ -128,9 +128,12 @@ impl<'own, 'library> Battle<'own, 'library> {
pub fn last_turn_time(&self) -> chrono::Duration {
self.last_turn_time
}
pub fn current_turn_queue(&self) -> &Option<Arc<RwLock<ChoiceQueue<'own, 'library>>>> {
pub fn current_turn_queue(&self) -> &Option<ChoiceQueue<'own, 'library>> {
&self.current_turn_queue
}
pub fn current_turn_queue_mut(&mut self) -> &mut Option<ChoiceQueue<'own, 'library>> {
&mut self.current_turn_queue
}
pub fn get_pokemon(&self, side: u8, index: u8) -> &Option<Arc<RwLock<Pokemon<'own, 'library>>>> {
let side = self.sides.get(side as usize);
@@ -259,14 +262,14 @@ impl<'own, 'library> Battle<'own, 'library> {
*choice.speed_mut() = speed;
choice.set_random_value(self.random.get() as u32);
choices.push(choice_opt.take().unwrap());
choices.push(choice_opt.take());
}
side.reset_choices();
}
self.current_turn += 1;
choices.sort_unstable_by(|a, b| b.cmp(a));
self.current_turn_queue = Some(Arc::new(RwLock::new(ChoiceQueue::new(choices))));
self.current_turn_queue = Some(ChoiceQueue::new(choices));
{
self.run_turn()?;