Simlify and improve BT visualization
This commit is contained in:
@@ -227,8 +227,7 @@ static const BzBTNodeState *findNodeState(const BzBTNode *node, const BzBTNodeSt
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
void igVisualizeBTState(const BzBTNode *node, const BzBTNodeState *state,
|
||||
bool isActive, bool sameLine, i32 depth) {
|
||||
static void visualizeBTState(const BzBTNode *node, const BzBTNodeState *state, bool sameLine, bool isActive, i32 depth) {
|
||||
const BzBTNode *child = bzBTNodeChild(node);
|
||||
BzBTNodeType type = bzBTGetNodeType(node);
|
||||
char extraInfo[128];
|
||||
@@ -236,7 +235,7 @@ void igVisualizeBTState(const BzBTNode *node, const BzBTNodeState *state,
|
||||
|
||||
const BzBTNodeState *nodeState = findNodeState(node, state);
|
||||
bool hasState = nodeState != NULL;
|
||||
isActive |= hasState;
|
||||
isActive |= nodeState != NULL;
|
||||
|
||||
switch (type) {
|
||||
case BZ_BT_DECOR_REPEAT:
|
||||
@@ -249,7 +248,7 @@ void igVisualizeBTState(const BzBTNode *node, const BzBTNodeState *state,
|
||||
}
|
||||
break;
|
||||
case BZ_BT_DECOR_DELAY:
|
||||
if (hasState) {
|
||||
if (isActive) {
|
||||
snprintf(extraInfo, sizeof(extraInfo), " (%.2f < %.2fms)",
|
||||
bzBTDelayStateGetElapsed(nodeState),
|
||||
bzBTDecorGetDelay(node));
|
||||
@@ -271,35 +270,43 @@ void igVisualizeBTState(const BzBTNode *node, const BzBTNodeState *state,
|
||||
if (isActive)
|
||||
color = (ImVec4) {1.0f, 1.0f, 0.5f, 1.0f};
|
||||
|
||||
bool hasSingleChild = true;
|
||||
if (child && bzBTNodeNext(child)) hasSingleChild = false;
|
||||
bool hasSingleChild = child && bzBTNodeNext(child) == NULL;
|
||||
|
||||
const char *suffix = hasSingleChild ? " > " : ": ";
|
||||
|
||||
if (sameLine) {
|
||||
igTextColored(color, "%s%s%s", bzBTNodeTypeToStr(type),
|
||||
extraInfo, suffix);
|
||||
} else {
|
||||
igTextColored(color, "%*s%s %s",
|
||||
depth * 2, "",
|
||||
bzBTNodeTypeToStr(type), extraInfo, suffix);
|
||||
depth++;
|
||||
}
|
||||
i32 offset = depth * 2;
|
||||
if (sameLine) offset = 0;
|
||||
const char *prefix = sameLine ? " > " : "";
|
||||
const char *postfix = child != NULL && !hasSingleChild ? ":" : "";
|
||||
igTextColored(color, "%s%*s%s%s%s", prefix, offset, "", bzBTNodeTypeToStr(type), extraInfo, postfix);
|
||||
|
||||
bool isComposite = type == BZ_BT_COMP_SELECTOR ||
|
||||
type == BZ_BT_COMP_P_SELECTOR ||
|
||||
type == BZ_BT_COMP_SEQUENCE ||
|
||||
type == BZ_BT_COMP_P_SEQUENCE;
|
||||
|
||||
depth++;
|
||||
while (child) {
|
||||
if (hasSingleChild) igSameLine(0, 0);
|
||||
bool childActive = isActive && hasSingleChild;
|
||||
if (hasState && isComposite && !childActive)
|
||||
childActive = bzBTCompStateGetRunningChild(state) == child;
|
||||
igVisualizeBTState(child, state, childActive, hasSingleChild, depth);
|
||||
bool childHasState = hasState && isComposite && bzBTCompStateGetRunningChild(nodeState) == child;
|
||||
visualizeBTState(child, state, hasSingleChild, childHasState, depth);
|
||||
child = bzBTNodeNext(child);
|
||||
}
|
||||
}
|
||||
void igVisualizeBTState(const BzBTNode *node, const BzBTNodeState *state) {
|
||||
igSeparatorText("Tree State");
|
||||
visualizeBTState(node, state, false, true, 0);
|
||||
|
||||
igSeparatorText("State stack");
|
||||
size_t stateSize = 0;
|
||||
const BzBTNodeState *pState = state;
|
||||
while (pState) {
|
||||
const BzBTNode *pNode = bzBTNodeStateGetNode(pState);
|
||||
stateSize += bzBTGetNodeStateSize();
|
||||
BzBTNodeType type = bzBTGetNodeType(pNode);
|
||||
igText("%s", bzBTNodeTypeToStr(type));
|
||||
pState = bzBTNodeStateNext(pState);
|
||||
}
|
||||
igNewLine();
|
||||
igText("Total stack state size: %ld bytes.", stateSize);
|
||||
}
|
||||
void igBzBTState(ecs_world_t *ecs,
|
||||
ecs_entity_t entity, ecs_entity_t comp) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user