Let a called behavior share the caller's local state machines
A local state machine started over in every Run behavior call, so a state set in a sub-behavior was gone by the next call. A character controller split into sub-behaviors could therefore never remember that it was attacking. Scene or global scope would keep the state, but then every character shares it. - A call now runs on the states of the instance that runs it, however deep. A state one call sets is still set in the next one, and the call begins in the start state like the instance does. - A move made inside a call is reported like one the caller made. The caller's On state entered and On state exited hear it, the event nodes of the called graph stay silent as before. - Two objects running the same behavior still hold a state each. - This reverses the rule from #229 that local machines of a called behavior are not kept. Keep stays a switch for variables only. Tests: - Two unit tests that pinned the old rule now expect the shared state. - New world test: a sub-behavior closes a door per object, the caller's events hear it, and the next call finds it closed. - Counter-check: with the old call context the 3 tests fail. - Gate on melektaus-atx: 239 files, 3600 tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d80d5cce26
commit
ed7872c893
3 files changed
+53
-19
No files matched your search
@@ -240,17 +240,10 @@ export class GraphInterpreter {
|
||||
this.callStack.push(call.behaviorId);
|
||||
this.callSites.push(site);
|
||||
this.calledBehaviors.add(call.behaviorId);
|
||||
// Fresh states every call, and nothing of the caller's variables or states. What it does to a
|
||||
// local machine therefore dies with the call and is not reported; a `global` machine is the
|
||||
// run's, so moving that one is a move like any other.
|
||||
const inner: NodeContext = {
|
||||
...ctx,
|
||||
variables,
|
||||
states: {},
|
||||
stateChanged: (machineId, from, to) => {
|
||||
if (machineId in ctx.shared.states) ctx.stateChanged(machineId, from, to);
|
||||
},
|
||||
};
|
||||
// Nothing of the caller's variables, but its local machines: a local machine belongs to the
|
||||
// running instance however deep the call, so what a call sets is still set on the next one,
|
||||
// and the move is heard like one the caller made itself.
|
||||
const inner: NodeContext = { ...ctx, variables };
|
||||
try {
|
||||
for (const entry of entries) {
|
||||
this.trace?.onNode(entry.id);
|
||||
|
||||
Reference in new issue
Block a user