Don't store the TurnChoices as 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 09:49:17 +02:00
parent 94403e2ca1
commit 09c2533bf5
6 changed files with 33 additions and 46 deletions

View File

@@ -1,26 +1,24 @@
use crate::dynamic_data::choices::TurnChoice;
use crate::dynamic_data::models::pokemon::Pokemon;
use parking_lot::RwLock;
use std::sync::Arc;
#[derive(Debug)]
pub struct ChoiceQueue<'battle, 'library> {
queue: Vec<Arc<RwLock<TurnChoice<'battle, 'library>>>>,
queue: Vec<TurnChoice<'battle, 'library>>,
current: usize,
}
impl<'battle, 'library> ChoiceQueue<'battle, 'library> {
pub fn new(queue: Vec<Arc<RwLock<TurnChoice<'battle, 'library>>>>) -> Self {
pub fn new(queue: Vec<TurnChoice<'battle, 'library>>) -> Self {
Self { queue, current: 0 }
}
pub fn dequeue<'b>(&'b mut self) -> &'b Arc<RwLock<TurnChoice<'battle, 'library>>> {
pub fn dequeue<'b>(&'b mut self) -> &'b TurnChoice<'battle, 'library> {
let c = &self.queue[self.current];
self.current += 1;
c
}
pub fn peek(&mut self) -> &'battle Arc<RwLock<TurnChoice>> {
pub fn peek(&mut self) -> &'battle TurnChoice {
&self.queue[self.current]
}
@@ -32,7 +30,7 @@ impl<'battle, 'library> ChoiceQueue<'battle, 'library> {
todo!()
}
pub(crate) fn get_queue(&self) -> &Vec<Arc<RwLock<TurnChoice<'battle, 'library>>>> {
pub(crate) fn get_queue(&self) -> &Vec<TurnChoice<'battle, 'library>> {
&self.queue
}
}