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);
}
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];
@@ -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();
}