Print nodes with single child on the same line

This commit is contained in:
2024-01-09 22:18:17 +01:00
parent 47f2ccd87d
commit adcee0a94d

View File

@@ -47,7 +47,7 @@ void deinit(int *game) {
bzObjectPoolDestroy(nodeStatePool); 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); const BzAIBTNode *child = bzAIBTNodeChild(node);
BzAIBTNodeType type = bzAIBTGetNodeType(node); BzAIBTNodeType type = bzAIBTGetNodeType(node);
char extraInfo[128]; char extraInfo[128];
@@ -89,10 +89,26 @@ void igRenderBTNode(const BzAIBTNode *node, const BzAIBTNodeState *state, i32 de
if (hasState) if (hasState)
color = (ImVec4) {1.0f, 1.0f, 0.5f, 1.0f}; color = (ImVec4) {1.0f, 1.0f, 0.5f, 1.0f};
igTextColored(color, "%*s%s %s", depth * 2, "", bool hasSingleChild = false;
bzAIBTNodeTypeToStr(type), extraInfo); 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) { while (child) {
igRenderBTNode(child, state, depth + 1); if (hasSingleChild) igSameLine(0, 0);
igRenderBTNode(child, state, hasSingleChild, depth);
child = bzAIBTNodeNext(child); child = bzAIBTNodeNext(child);
} }
} }
@@ -100,7 +116,7 @@ void igRenderBTNode(const BzAIBTNode *node, const BzAIBTNodeState *state, i32 de
void igRenderBT(BzAIBTState *state) { void igRenderBT(BzAIBTState *state) {
const BzAIBTNode *root = state->root; const BzAIBTNode *root = state->root;
if (igBegin("BehaviourTree", NULL, 0)) { if (igBegin("BehaviourTree", NULL, 0)) {
igRenderBTNode(root, state->first, 0); igRenderBTNode(root, state->first, false, 0);
} }
igEnd(); igEnd();
} }