102 lines
3.2 KiB
C
102 lines
3.2 KiB
C
#ifndef BREEZE_BEHAVIOUR_TREE_H
|
|
#define BREEZE_BEHAVIOUR_TREE_H
|
|
|
|
#include "../defines.h"
|
|
|
|
typedef struct BzAIBTNode BzAIBTNode;
|
|
|
|
typedef enum BzAIBTStatus {
|
|
BZ_AIBT_RUNNING,
|
|
BZ_AIBT_SUCCESS,
|
|
BZ_AIBT_FAIL,
|
|
BZ_AIBT_ERROR,
|
|
} BzAIBTStatus;
|
|
|
|
typedef BzAIBTStatus(*BzAIBTActionFn)(void *data);
|
|
|
|
typedef enum BzAIBTNodeType {
|
|
// Composite
|
|
BZ_AIBT_COMP_SELECTOR,
|
|
BZ_AIBT_COMP_SEQUENCE,
|
|
BZ_AIBT_COMP_PARALLEL_SELECTOR,
|
|
BZ_AIBT_COMP_PARALLEL_SEQUENCE,
|
|
// Decorator
|
|
BZ_AIBT_DECOR_DUMMY,
|
|
BZ_AIBT_DECOR_SUCCESS,
|
|
BZ_AIBT_DECOR_FAIL,
|
|
BZ_AIBT_DECOR_INVERT,
|
|
BZ_AIBT_DECOR_UNTIL_SUCCESS,
|
|
BZ_AIBT_DECOR_UNTIL_FAIL,
|
|
BZ_AIBT_DECOR_REPEAT,
|
|
BZ_AIBT_DECOR_DELAY,
|
|
// Action/Task
|
|
BZ_AIBT_ACTION,
|
|
} BzAIBTNodeType;
|
|
|
|
typedef struct BzObjectPool BzObjectPool;
|
|
typedef struct BzAIBTNodeState BzAIBTNodeState;
|
|
|
|
typedef struct BzAIBTState {
|
|
const BzAIBTNode *root;
|
|
BzAIBTNodeState *first;
|
|
BzAIBTNodeState *last;
|
|
|
|
BzObjectPool *nodeStatePool;
|
|
void *userData;
|
|
} BzAIBTState;
|
|
|
|
typedef struct BzAIBTStateDesc {
|
|
const BzAIBTNode *root;
|
|
|
|
BzObjectPool *pool;
|
|
void *userData;
|
|
} BzAIBTStateDesc;
|
|
|
|
size_t bzAIBTGetNodeSize();
|
|
size_t bzAIBTGetNodeStateSize();
|
|
|
|
const char *bzAIBTNodeTypeToStr(BzAIBTNodeType type);
|
|
|
|
BzAIBTNode *bzAIBTMakeRoot(BzObjectPool *nodePool);
|
|
void bzAIBTDestroyRoot(BzObjectPool *nodePool, BzAIBTNode *node);
|
|
|
|
BzAIBTNode *bzAIBTCompSelector(BzObjectPool *nodePool, BzAIBTNode *parent, bool parallel);
|
|
BzAIBTNode *bzAIBTCompSequence(BzObjectPool *nodePool, BzAIBTNode *parent, bool parallel);
|
|
|
|
BzAIBTNode *bzAIBTDecorDummy(BzObjectPool *nodePool, BzAIBTNode *parent);
|
|
BzAIBTNode *bzAIBTDecorSuccess(BzObjectPool *nodePool, BzAIBTNode *parent);
|
|
BzAIBTNode *bzAIBTDecorFail(BzObjectPool *nodePool, BzAIBTNode *parent);
|
|
BzAIBTNode *bzAIBTDecorInvert(BzObjectPool *nodePool, BzAIBTNode *parent);
|
|
BzAIBTNode *bzAIBTDecorUntilSuccess(BzObjectPool *nodePool, BzAIBTNode *parent);
|
|
BzAIBTNode *bzAIBTDecorUntilFail(BzObjectPool *nodePool, BzAIBTNode *parent);
|
|
BzAIBTNode *bzAIBTDecorRepeat(BzObjectPool *nodePool, BzAIBTNode *parent, i32 n);
|
|
BzAIBTNode *bzAIBTDecorDelay(BzObjectPool *nodePool, BzAIBTNode *parent, f32 ms);
|
|
|
|
BzAIBTNode *bzAIBTAction(BzObjectPool *nodePool, BzAIBTNode *parent, BzAIBTActionFn fn,
|
|
const char *name);
|
|
|
|
// Reflection data
|
|
|
|
i32 bzAIBTDecorGetRepeat(const BzAIBTNode *node);
|
|
f32 bzAIBTDecorGetDelay(const BzAIBTNode *node);
|
|
|
|
BzAIBTActionFn bzAIBTActionGetFn(const BzAIBTNode *node);
|
|
const char *bzAIBTActionGetName(const BzAIBTNode *node);
|
|
|
|
BzAIBTNodeType bzAIBTGetNodeType(const BzAIBTNode *node);
|
|
BzAIBTNode *bzAIBTNodeChild(const BzAIBTNode *node);
|
|
BzAIBTNode *bzAIBTNodeNext(const BzAIBTNode *node);
|
|
|
|
const BzAIBTNodeState *bzAIBTNodeStateNext(const BzAIBTNodeState *state);
|
|
bool bzAIBTNodeMatchesState(const BzAIBTNode *node, const BzAIBTNodeState *state);
|
|
|
|
i32 bzAIBTRepeatStateGetIter(const BzAIBTNodeState *state);
|
|
f32 bzAIBTDelayStateGetElapsed(const BzAIBTNodeState *state);
|
|
|
|
BzAIBTState bzAIBTCreateState(const BzAIBTStateDesc *desc);
|
|
void bzAIBTDestroyState(BzAIBTState *state);
|
|
|
|
BzAIBTStatus bzAIBTExecute(BzAIBTState *state, f32 dt);
|
|
|
|
#endif //BREEZE_BEHAVIOUR_TREE_H
|