Remove AI prefix from behaviour_tree
This commit is contained in:
@@ -4,39 +4,39 @@
|
||||
BzObjectPool *nodePool = NULL;
|
||||
BzObjectPool *nodeStatePool = NULL;
|
||||
|
||||
BzAIBTNode *printBT = NULL;
|
||||
BzAIBTState agentState;
|
||||
BzBTNode *printBT = NULL;
|
||||
BzBTState agentState;
|
||||
|
||||
BzAIBTStatus printAction(void *data) {
|
||||
BzBTStatus printAction(void *data) {
|
||||
bzLogInfo("Hello, world!");
|
||||
return BZ_AIBT_SUCCESS;
|
||||
return BZ_BT_SUCCESS;
|
||||
}
|
||||
|
||||
bool init(int *game) {
|
||||
rlImGuiSetup(true);
|
||||
nodePool = bzObjectPoolCreate(&(BzObjectPoolDesc) {
|
||||
.objectSize = bzAIBTGetNodeSize(),
|
||||
.objectSize = bzBTGetNodeSize(),
|
||||
});
|
||||
nodeStatePool = bzObjectPoolCreate(&(BzObjectPoolDesc) {
|
||||
.objectSize = bzAIBTGetNodeStateSize()
|
||||
.objectSize = bzBTGetNodeStateSize()
|
||||
});
|
||||
|
||||
// for 1..5:
|
||||
// seq
|
||||
// delay 1s
|
||||
// print "Hello, world!"
|
||||
printBT = bzAIBTMakeRoot(nodePool);
|
||||
BzAIBTNode *node = bzAIBTDecorRepeat(nodePool, printBT, 5);
|
||||
printBT = bzBTMakeRoot(nodePool);
|
||||
BzBTNode *node = bzBTDecorRepeat(nodePool, printBT, 5);
|
||||
|
||||
BzAIBTNode *seq = bzAIBTCompSequence(nodePool, node, false);
|
||||
BzBTNode *seq = bzBTCompSequence(nodePool, node, false);
|
||||
|
||||
bzAIBTDecorDelay(nodePool, seq, 1.0f);
|
||||
bzAIBTAction(nodePool, seq, printAction, "printAction");
|
||||
bzBTDecorDelay(nodePool, seq, 1.0f);
|
||||
bzBTAction(nodePool, seq, printAction, "printAction");
|
||||
|
||||
agentState = bzAIBTCreateState(&(BzAIBTStateDesc) {
|
||||
.root = printBT,
|
||||
.pool = nodeStatePool,
|
||||
.userData = NULL
|
||||
agentState = bzBTCreateState(&(BzBTStateDesc) {
|
||||
.root = printBT,
|
||||
.pool = nodeStatePool,
|
||||
.userData = NULL
|
||||
});
|
||||
|
||||
return true;
|
||||
@@ -47,60 +47,60 @@ void deinit(int *game) {
|
||||
bzObjectPoolDestroy(nodeStatePool);
|
||||
}
|
||||
|
||||
void igRenderBTNode(const BzAIBTNode *node, const BzAIBTNodeState *state, bool sameLine, i32 depth) {
|
||||
const BzAIBTNode *child = bzAIBTNodeChild(node);
|
||||
BzAIBTNodeType type = bzAIBTGetNodeType(node);
|
||||
void igRenderBTNode(const BzBTNode *node, const BzBTNodeState *state, bool sameLine, i32 depth) {
|
||||
const BzBTNode *child = bzBTNodeChild(node);
|
||||
BzBTNodeType type = bzBTGetNodeType(node);
|
||||
char extraInfo[128];
|
||||
extraInfo[0] = '\0';
|
||||
|
||||
bool hasState = bzAIBTNodeMatchesState(node, state);
|
||||
bool hasState = bzBTNodeMatchesState(node, state);
|
||||
|
||||
switch (type) {
|
||||
case BZ_AIBT_DECOR_REPEAT:
|
||||
case BZ_BT_DECOR_REPEAT:
|
||||
if (hasState) {
|
||||
snprintf(extraInfo, sizeof(extraInfo), " (%d < %d)",
|
||||
bzAIBTRepeatStateGetIter(state),
|
||||
bzAIBTDecorGetRepeat(node));
|
||||
bzBTRepeatStateGetIter(state),
|
||||
bzBTDecorGetRepeat(node));
|
||||
} else {
|
||||
snprintf(extraInfo, sizeof(extraInfo), " (%d)", bzAIBTDecorGetRepeat(node));
|
||||
snprintf(extraInfo, sizeof(extraInfo), " (%d)", bzBTDecorGetRepeat(node));
|
||||
}
|
||||
break;
|
||||
case BZ_AIBT_DECOR_DELAY:
|
||||
case BZ_BT_DECOR_DELAY:
|
||||
if (hasState) {
|
||||
snprintf(extraInfo, sizeof(extraInfo), " (%.2f < %.2fms)",
|
||||
bzAIBTDelayStateGetElapsed(state),
|
||||
bzAIBTDecorGetDelay(node));
|
||||
bzBTDelayStateGetElapsed(state),
|
||||
bzBTDecorGetDelay(node));
|
||||
} else {
|
||||
snprintf(extraInfo, sizeof(extraInfo), " (%.2fms)", bzAIBTDecorGetDelay(node));
|
||||
snprintf(extraInfo, sizeof(extraInfo), " (%.2fms)", bzBTDecorGetDelay(node));
|
||||
}
|
||||
break;
|
||||
case BZ_AIBT_ACTION:
|
||||
case BZ_BT_ACTION:
|
||||
snprintf(extraInfo, sizeof(extraInfo), " (%s:%p)",
|
||||
bzAIBTActionGetName(node),
|
||||
bzAIBTActionGetFn(node));
|
||||
bzBTActionGetName(node),
|
||||
bzBTActionGetFn(node));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (hasState)
|
||||
state = bzAIBTNodeStateNext(state);
|
||||
state = bzBTNodeStateNext(state);
|
||||
|
||||
ImVec4 color = {1.0f, 1.0f, 1.0f, 1.0f};
|
||||
if (hasState)
|
||||
color = (ImVec4) {1.0f, 1.0f, 0.5f, 1.0f};
|
||||
|
||||
bool hasSingleChild = false;
|
||||
if (child && bzAIBTNodeNext(child) == NULL) hasSingleChild = true;
|
||||
if (child && bzBTNodeNext(child) == NULL) hasSingleChild = true;
|
||||
|
||||
const char *suffix = hasSingleChild ? " > " : ": ";
|
||||
|
||||
if (sameLine) {
|
||||
igTextColored(color, "%s%s%s", bzAIBTNodeTypeToStr(type),
|
||||
igTextColored(color, "%s%s%s", bzBTNodeTypeToStr(type),
|
||||
extraInfo, suffix);
|
||||
} else {
|
||||
igTextColored(color, "%*s%s %s",
|
||||
depth * 2, "",
|
||||
bzAIBTNodeTypeToStr(type), extraInfo, suffix);
|
||||
bzBTNodeTypeToStr(type), extraInfo, suffix);
|
||||
depth++;
|
||||
}
|
||||
|
||||
@@ -109,12 +109,12 @@ void igRenderBTNode(const BzAIBTNode *node, const BzAIBTNodeState *state, bool s
|
||||
while (child) {
|
||||
if (hasSingleChild) igSameLine(0, 0);
|
||||
igRenderBTNode(child, state, hasSingleChild, depth);
|
||||
child = bzAIBTNodeNext(child);
|
||||
child = bzBTNodeNext(child);
|
||||
}
|
||||
}
|
||||
|
||||
void igRenderBT(BzAIBTState *state) {
|
||||
const BzAIBTNode *root = state->root;
|
||||
void igRenderBT(BzBTState *state) {
|
||||
const BzBTNode *root = state->root;
|
||||
if (igBegin("BehaviourTree", NULL, 0)) {
|
||||
igRenderBTNode(root, state->first, false, 0);
|
||||
}
|
||||
@@ -124,7 +124,7 @@ void igRenderBT(BzAIBTState *state) {
|
||||
void render(float dt, int *game) {
|
||||
ClearBackground(WHITE);
|
||||
|
||||
BzAIBTStatus status = bzAIBTExecute(&agentState, dt);
|
||||
BzBTStatus status = bzBTExecute(&agentState, dt);
|
||||
|
||||
rlImGuiBegin();
|
||||
igRenderBT(&agentState);
|
||||
|
||||
Reference in New Issue
Block a user