Floor layer

This commit is contained in:
2026-06-06 18:49:45 -05:00
parent a5f60e22e1
commit 374a69f0ca
8 changed files with 699 additions and 33 deletions
+44 -20
View File
@@ -212,16 +212,16 @@ impl ScriptHost {
}
Err(err) => {
failed.insert(name.clone());
errors
.borrow_mut()
.push(LogLine::raw(format!("script '{name}' failed to compile: {err}")));
errors.borrow_mut().push(LogLine::raw(format!(
"script '{name}' failed to compile: {err}"
)));
}
},
None => {
failed.insert(name.clone());
errors
.borrow_mut()
.push(LogLine::raw(format!("object references unknown script '{name}'")));
errors.borrow_mut().push(LogLine::raw(format!(
"object references unknown script '{name}'"
)));
}
}
}
@@ -294,12 +294,17 @@ impl ScriptHost {
return;
}
let options = CallFnOptions::default().with_tag(object_index as i64);
if let Err(err) =
engine.call_fn_with_options::<()>(options, &mut obj.scope, &compiled.ast, "bump", (bumper,))
{
errors
.borrow_mut()
.push(LogLine::raw(format!("script '{}' bump error: {err}", obj.script_name)));
if let Err(err) = engine.call_fn_with_options::<()>(
options,
&mut obj.scope,
&compiled.ast,
"bump",
(bumper,),
) {
errors.borrow_mut().push(LogLine::raw(format!(
"script '{}' bump error: {err}",
obj.script_name
)));
}
}
@@ -347,7 +352,10 @@ impl ScriptHost {
if cost > 0.0 {
self.objects[i].ready_timer = cost;
}
self.board_queue.borrow_mut().push(BoardAction { source: oid, action });
self.board_queue.borrow_mut().push(BoardAction {
source: oid,
action,
});
// A timed action ends the pump; zero-cost ones keep draining.
if cost > 0.0 {
break;
@@ -360,7 +368,12 @@ impl ScriptHost {
/// source), then pump that object so backlogged actions drain and later objects'
/// `blocked` checks can see earlier movers. Runtime errors are captured rather than
/// aborting the batch.
fn run<A: FuncArgs + Copy>(&mut self, hook: &str, defined: fn(&CompiledScript) -> bool, args: A) {
fn run<A: FuncArgs + Copy>(
&mut self,
hook: &str,
defined: fn(&CompiledScript) -> bool,
args: A,
) {
for i in 0..self.objects.len() {
// Scope the split borrow so it ends before the `pump` reborrow below.
{
@@ -377,9 +390,13 @@ impl ScriptHost {
{
// The tag carries this object's index to the host functions.
let options = CallFnOptions::default().with_tag(obj.object_index as i64);
if let Err(err) =
engine.call_fn_with_options::<()>(options, &mut obj.scope, &compiled.ast, hook, args)
{
if let Err(err) = engine.call_fn_with_options::<()>(
options,
&mut obj.scope,
&compiled.ast,
hook,
args,
) {
errors.borrow_mut().push(LogLine::raw(format!(
"script '{}' {hook} error: {err}",
obj.script_name
@@ -461,9 +478,16 @@ fn register_write_api(engine: &mut Engine, queues: &QueueMap) {
});
let q = queues.clone();
engine.register_fn("log", move |ctx: NativeCallContext, msg: ImmutableString| {
emit(&q, source_of(&ctx), Action::Log(LogLine::raw(msg.to_string())));
});
engine.register_fn(
"log",
move |ctx: NativeCallContext, msg: ImmutableString| {
emit(
&q,
source_of(&ctx),
Action::Log(LogLine::raw(msg.to_string())),
);
},
);
}
/// Registers the `Queue` object: a handle to an object's output queue with `length()`