Properly clear state

This commit is contained in:
2024-01-12 21:19:57 +01:00
parent 25a3229bb2
commit 4dd9b366e7
2 changed files with 9 additions and 4 deletions

View File

@@ -470,8 +470,13 @@ static inline BzBTExecReturn bzBTExecuteComposite(const BzBTNode *node, f32 dt,
bzBTClearNodeState(pChild, state, statePool); bzBTClearNodeState(pChild, state, statePool);
pChild = pChild->next; pChild = pChild->next;
} }
// For finished parallel composites clean up all children
if (finished && isParallel) {
execStateClear(&execReturn.state, statePool);
}
if (finished) { if (finished) {
// Finished composites mustn't have state
BZ_ASSERT(execReturn.state.first == NULL); BZ_ASSERT(execReturn.state.first == NULL);
if (nodeState) releaseNodeState(nodeState, statePool); if (nodeState) releaseNodeState(nodeState, statePool);
return execReturn; return execReturn;
@@ -501,12 +506,11 @@ static inline BzBTExecReturn bzBTExecuteDecorator(const BzBTNode *node, f32 dt,
case BZ_BT_DECOR_DELAY: case BZ_BT_DECOR_DELAY:
nodeState = ensureValidNodeState(node, nodeState, statePool); nodeState = ensureValidNodeState(node, nodeState, statePool);
nodeState->as.delay.elapsed += dt; nodeState->as.delay.elapsed += dt;
execStatePushBack(&execReturn.state, nodeState);
if (nodeState->as.delay.elapsed < node->as.delay.ms) { if (nodeState->as.delay.elapsed < node->as.delay.ms) {
execStatePushBack(&execReturn.state, nodeState);
execReturn.status = BZ_BT_RUNNING; execReturn.status = BZ_BT_RUNNING;
return execReturn; return execReturn;
} }
BZ_ASSERT(nodeState == execStatePopFront(&execReturn.state));
releaseNodeState(nodeState, statePool); releaseNodeState(nodeState, statePool);
break; break;
default: default:

View File

@@ -27,9 +27,10 @@ bool init(int *game) {
// print "Hello, world!" // print "Hello, world!"
printBT = bzBTMakeRoot(nodePool); printBT = bzBTMakeRoot(nodePool);
BzBTNode *pseq = bzBTCompPSelector(nodePool, printBT); BzBTNode *pseq = bzBTCompPSelector(nodePool, printBT);
bzBTDecorDelay(nodePool, pseq, 2.0f); BzBTNode *node = bzBTDecorFail(nodePool, pseq);
bzBTDecorDelay(nodePool, node, 2.0f);
BzBTNode *node = bzBTDecorRepeat(nodePool, pseq, 5); node = bzBTDecorRepeat(nodePool, pseq, 5);
BzBTNode *seq = bzBTCompSequence(nodePool, node); BzBTNode *seq = bzBTCompSequence(nodePool, node);