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

@@ -14,8 +14,7 @@ use std::sync::Arc;
impl<'own, 'library> Battle<'own, 'library> {
pub(crate) fn run_turn(&mut self) -> PkmnResult<()> {
let cq = self.current_turn_queue();
let mut choice_queue = cq.as_ref().unwrap().write();
let mut choice_queue = self.current_turn_queue().as_ref().unwrap();
// We are now at the very beginning of a turn. We have assigned speeds and priorities to all
// choices, and put them in the correct order.
@@ -24,7 +23,7 @@ impl<'own, 'library> Battle<'own, 'library> {
// is primarily intended to be used to reset variables on a script (for example scripts that need
// to check whether a pokemon was hit this turn. By resetting here, and setting a variable to true
// they can then know this later on.)
for choice in choice_queue.get_queue() {
for choice in choice_queue.get_queue().iter().flatten() {
script_hook!(on_before_turn, choice, choice);
}
@@ -32,8 +31,9 @@ impl<'own, 'library> Battle<'own, 'library> {
// One by one dequeue the turns, and run them. If the battle has ended we do not want to
// continue running however.
while choice_queue.has_next() && !self.has_ended() {
let choice = choice_queue.dequeue();
let choice = self.current_turn_queue_mut().as_mut().unwrap().dequeue();
self.execute_choice(&choice)?;
choice_queue = self.current_turn_queue().as_ref().unwrap();
}
// If the battle is not ended, we have arrived at the normal end of a turn. and thus want