Add/Get name for nodes in behaviour tree

This commit is contained in:
2024-01-10 07:45:26 +01:00
parent 113ac72181
commit 3b77d5cdcf
3 changed files with 16 additions and 14 deletions

View File

@@ -15,6 +15,7 @@ struct BzBTNode {
BzBTNode *next;
BzBTNodeType type;
const char *name;
union {
struct {
i32 n;
@@ -24,10 +25,8 @@ struct BzBTNode {
} delay;
struct {
BzBTActionFn fn;
const char *name;
} action;
} as;
};
struct BzBTNodeState {
@@ -167,14 +166,19 @@ BzBTNode *bzBTDecorDelay(BzObjectPool *nodePool, BzBTNode *parent, f32 ms) {
return node;
}
BzBTNode *bzBTAction(BzObjectPool *nodePool, BzBTNode *parent, BzBTActionFn fn,
const char *name) {
BzBTNode *bzBTAction(BzObjectPool *nodePool, BzBTNode *parent, BzBTActionFn fn) {
BzBTNode *node = bzBTNodeMake(nodePool, parent, BZ_BT_ACTION);
node->as.action.fn = fn;
node->as.action.name = name;
return node;
}
void bzBTNodeSetName(BzBTNode *node, const char *name) {
node->name = name;
}
const char *bzBTNodeGetName(const BzBTNode *node) {
return node->name;
}
i32 bzBTDecorGetRepeat(const BzBTNode *node) {
BZ_ASSERT(node->type == BZ_BT_DECOR_REPEAT);
return node->as.repeat.n;
@@ -188,10 +192,6 @@ BzBTActionFn bzBTActionGetFn(const BzBTNode *node) {
BZ_ASSERT(node->type == BZ_BT_ACTION);
return node->as.action.fn;
}
const char *bzBTActionGetName(const BzBTNode *node) {
BZ_ASSERT(node->type == BZ_BT_ACTION);
return node->as.action.name;
}
BzBTNodeType bzBTGetNodeType(const BzBTNode *node) {
return node->type;

View File

@@ -72,16 +72,17 @@ BzBTNode *bzBTDecorUntilFail(BzObjectPool *nodePool, BzBTNode *parent);
BzBTNode *bzBTDecorRepeat(BzObjectPool *nodePool, BzBTNode *parent, i32 n);
BzBTNode *bzBTDecorDelay(BzObjectPool *nodePool, BzBTNode *parent, f32 ms);
BzBTNode *bzBTAction(BzObjectPool *nodePool, BzBTNode *parent, BzBTActionFn fn,
const char *name);
BzBTNode *bzBTAction(BzObjectPool *nodePool, BzBTNode *parent, BzBTActionFn fn);
// Reflection data
void bzBTNodeSetName(BzBTNode *node, const char *name);
const char *bzBTNodeGetName(const BzBTNode *node);
i32 bzBTDecorGetRepeat(const BzBTNode *node);
f32 bzBTDecorGetDelay(const BzBTNode *node);
BzBTActionFn bzBTActionGetFn(const BzBTNode *node);
const char *bzBTActionGetName(const BzBTNode *node);
BzBTNodeType bzBTGetNodeType(const BzBTNode *node);
BzBTNode *bzBTNodeChild(const BzBTNode *node);

View File

@@ -31,7 +31,8 @@ bool init(int *game) {
BzBTNode *seq = bzBTCompSequence(nodePool, node, false);
bzBTDecorDelay(nodePool, seq, 1.0f);
bzBTAction(nodePool, seq, printAction, "printAction");
node = bzBTAction(nodePool, seq, printAction);
bzBTNodeSetName(node,"printAction");
agentState = bzBTCreateState(&(BzBTStateDesc) {
.root = printBT,
@@ -76,7 +77,7 @@ void igRenderBTNode(const BzBTNode *node, const BzBTNodeState *state, bool sameL
break;
case BZ_BT_ACTION:
snprintf(extraInfo, sizeof(extraInfo), " (%s:%p)",
bzBTActionGetName(node),
bzBTNodeGetName(node) ? bzBTNodeGetName(node) : "?",
bzBTActionGetFn(node));
break;
default: