drain object queues after each object
This commit is contained in:
@@ -25,8 +25,9 @@ use rhai::{Dynamic, Engine};
|
||||
use crate::api::board::BoardRef;
|
||||
use crate::api::queue::ObjQueue;
|
||||
use crate::Direction;
|
||||
use crate::action::BoardAction;
|
||||
use crate::object_def::ObjectDef;
|
||||
use crate::script::{BoardQueue, Registerable};
|
||||
use crate::script::Registerable;
|
||||
use crate::utils::{ErrorSink, ObjectId};
|
||||
|
||||
/// A snapshot of one board object, returned by `Board.tagged`, `Board.named`,
|
||||
@@ -69,7 +70,7 @@ impl ObjectInfo {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn drain(&mut self, target: BoardQueue, dt: f64) {
|
||||
pub fn drain(&mut self, target: &mut Vec<BoardAction>, dt: f64) {
|
||||
let mut b = self.board.borrow_mut();
|
||||
if let Some(def) = b.objects.get_mut(&self.id) {
|
||||
def.queue.drain(self.id, target, dt)
|
||||
|
||||
@@ -7,7 +7,7 @@ use std::collections::VecDeque;
|
||||
use std::rc::Rc;
|
||||
use rhai::{Dynamic, Engine};
|
||||
use crate::action::{Action, BoardAction};
|
||||
use crate::script::{BoardQueue, Registerable};
|
||||
use crate::script::Registerable;
|
||||
use crate::utils::{ErrorSink, ObjectId};
|
||||
|
||||
/// A single object's output queue.
|
||||
@@ -44,10 +44,11 @@ impl ObjQueue {
|
||||
}
|
||||
}
|
||||
|
||||
/// Drains object `i`'s output queue onto a target queue: first advances
|
||||
/// leading `Delay` actions by dt, then drains actions into the target
|
||||
/// queue until we run out (or hit another delay)
|
||||
pub fn drain(&mut self, source: ObjectId, target: BoardQueue, mut dt: f64) {
|
||||
/// Drains object `i`'s output queue into `target`: first advances leading
|
||||
/// `Delay` actions by dt, then moves the run of ready actions into `target`
|
||||
/// until we run out (or hit another delay). Each ready action is tagged with
|
||||
/// `source` so [`GameState`](crate::game::GameState) knows who issued it.
|
||||
pub fn drain(&mut self, source: ObjectId, target: &mut Vec<BoardAction>, mut dt: f64) {
|
||||
let mut queue = self.0.borrow_mut();
|
||||
loop {
|
||||
match queue.front_mut() {
|
||||
@@ -63,7 +64,7 @@ impl ObjQueue {
|
||||
}
|
||||
Some(_) => {
|
||||
let action = queue.pop_front().unwrap();
|
||||
target.borrow_mut().push(BoardAction { source, action });
|
||||
target.push(BoardAction { source, action });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user