diff --git a/engine/tests/btree_test.c b/engine/tests/btree_test.c index 6c32f99..c2a89bc 100644 --- a/engine/tests/btree_test.c +++ b/engine/tests/btree_test.c @@ -47,7 +47,7 @@ void deinit(int *game) { bzObjectPoolDestroy(nodeStatePool); } -void igRenderBTNode(const BzAIBTNode *node, const BzAIBTNodeState *state, i32 depth) { +void igRenderBTNode(const BzAIBTNode *node, const BzAIBTNodeState *state, bool sameLine, i32 depth) { const BzAIBTNode *child = bzAIBTNodeChild(node); BzAIBTNodeType type = bzAIBTGetNodeType(node); char extraInfo[128]; @@ -58,24 +58,24 @@ void igRenderBTNode(const BzAIBTNode *node, const BzAIBTNodeState *state, i32 de switch (type) { case BZ_AIBT_DECOR_REPEAT: if (hasState) { - snprintf(extraInfo, sizeof(extraInfo), "(%d < %d)", + snprintf(extraInfo, sizeof(extraInfo), " (%d < %d)", bzAIBTRepeatStateGetIter(state), bzAIBTDecorGetRepeat(node)); } else { - snprintf(extraInfo, sizeof(extraInfo), "(%d)", bzAIBTDecorGetRepeat(node)); + snprintf(extraInfo, sizeof(extraInfo), " (%d)", bzAIBTDecorGetRepeat(node)); } break; case BZ_AIBT_DECOR_DELAY: if (hasState) { - snprintf(extraInfo, sizeof(extraInfo), "(%.2f < %.2fms)", + snprintf(extraInfo, sizeof(extraInfo), " (%.2f < %.2fms)", bzAIBTDelayStateGetElapsed(state), bzAIBTDecorGetDelay(node)); } else { - snprintf(extraInfo, sizeof(extraInfo), "(%.2fms)", bzAIBTDecorGetDelay(node)); + snprintf(extraInfo, sizeof(extraInfo), " (%.2fms)", bzAIBTDecorGetDelay(node)); } break; case BZ_AIBT_ACTION: - snprintf(extraInfo, sizeof(extraInfo), "(%s:%p)", + snprintf(extraInfo, sizeof(extraInfo), " (%s:%p)", bzAIBTActionGetName(node), bzAIBTActionGetFn(node)); break; @@ -89,10 +89,26 @@ void igRenderBTNode(const BzAIBTNode *node, const BzAIBTNodeState *state, i32 de if (hasState) color = (ImVec4) {1.0f, 1.0f, 0.5f, 1.0f}; - igTextColored(color, "%*s%s %s", depth * 2, "", - bzAIBTNodeTypeToStr(type), extraInfo); + bool hasSingleChild = false; + if (child && bzAIBTNodeNext(child) == NULL) hasSingleChild = true; + + const char *suffix = hasSingleChild ? " > " : ": "; + + if (sameLine) { + igTextColored(color, "%s%s%s", bzAIBTNodeTypeToStr(type), + extraInfo, suffix); + } else { + igTextColored(color, "%*s%s %s", + depth * 2, "", + bzAIBTNodeTypeToStr(type), extraInfo, suffix); + depth++; + } + + + while (child) { - igRenderBTNode(child, state, depth + 1); + if (hasSingleChild) igSameLine(0, 0); + igRenderBTNode(child, state, hasSingleChild, depth); child = bzAIBTNodeNext(child); } } @@ -100,7 +116,7 @@ void igRenderBTNode(const BzAIBTNode *node, const BzAIBTNodeState *state, i32 de void igRenderBT(BzAIBTState *state) { const BzAIBTNode *root = state->root; if (igBegin("BehaviourTree", NULL, 0)) { - igRenderBTNode(root, state->first, 0); + igRenderBTNode(root, state->first, false, 0); } igEnd(); }