Don't store the TurnChoices as Arc<RwLock>>, to prevent locking issues.
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:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user