Remove lifetime mess, replace a lot of code with Arc instead of borrows.
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This cleans up the codebase massively, and allows me to maintain some semblance of sanity.
This commit is contained in:
@@ -8,31 +8,31 @@ use crate::dynamic_data::Pokemon;
|
||||
/// helper functions to change the turn order while doing the execution. This is needed, as several
|
||||
/// moves in Pokemon actively mess with this order.
|
||||
#[derive(Debug)]
|
||||
pub struct ChoiceQueue<'battle, 'library> {
|
||||
pub struct ChoiceQueue {
|
||||
/// Our storage of turn choices. Starts out completely filled, then slowly empties as turns get
|
||||
/// executed.
|
||||
queue: Vec<Option<TurnChoice<'battle, 'library>>>,
|
||||
queue: Vec<Option<TurnChoice>>,
|
||||
/// The current index of the turn we need to execute next.
|
||||
current: usize,
|
||||
}
|
||||
|
||||
impl<'battle, 'library> ChoiceQueue<'battle, 'library> {
|
||||
impl ChoiceQueue {
|
||||
/// Initializes a ChoiceQueue. We expect the given queue to already be sorted here.
|
||||
pub(crate) fn new(queue: Vec<Option<TurnChoice<'battle, 'library>>>) -> Self {
|
||||
pub(crate) fn new(queue: Vec<Option<TurnChoice>>) -> Self {
|
||||
Self { queue, current: 0 }
|
||||
}
|
||||
|
||||
/// Dequeues the next turn choice to be executed. This gives ownership to the callee, and replaces
|
||||
/// our own reference to the turn choice with an empty spot. It also increments the current position
|
||||
/// by one.
|
||||
pub fn dequeue<'b>(&'b mut self) -> TurnChoice<'battle, 'library> {
|
||||
pub fn dequeue<'b>(&'b mut self) -> TurnChoice {
|
||||
let c = self.queue[self.current].take();
|
||||
self.current += 1;
|
||||
c.unwrap()
|
||||
}
|
||||
|
||||
/// This reads what the next choice to execute will be, without modifying state.
|
||||
pub fn peek(&self) -> &'battle TurnChoice {
|
||||
pub fn peek(&self) -> &TurnChoice {
|
||||
self.queue[self.current].as_ref().unwrap()
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ impl<'battle, 'library> ChoiceQueue<'battle, 'library> {
|
||||
}
|
||||
|
||||
/// Internal helper function to be easily able to iterate over the yet to be executed choices.
|
||||
pub(crate) fn get_queue(&self) -> &[Option<TurnChoice<'battle, 'library>>] {
|
||||
pub(crate) fn get_queue(&self) -> &[Option<TurnChoice>] {
|
||||
&self.queue[self.current..self.queue.len()]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user