drain object queues after each object

This commit is contained in:
2026-07-10 01:20:26 -05:00
parent 386967e936
commit 325d2c27dd
13 changed files with 259 additions and 106 deletions
+7 -6
View File
@@ -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 });
}
}
}