Behaviour tree decorator implementation
This commit is contained in:
@@ -2,6 +2,9 @@ project(BreezeTests)
|
||||
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
|
||||
add_executable(btree_test btree_test.c)
|
||||
target_link_libraries(btree_test LINK_PRIVATE Breeze)
|
||||
|
||||
add_executable(window_test window_test.c)
|
||||
target_link_libraries(window_test LINK_PRIVATE Breeze)
|
||||
|
||||
|
||||
63
engine/tests/btree_test.c
Normal file
63
engine/tests/btree_test.c
Normal file
@@ -0,0 +1,63 @@
|
||||
#define BZ_ENTRYPOINT
|
||||
#include <breeze.h>
|
||||
|
||||
BzObjectPool *nodePool = NULL;
|
||||
BzObjectPool *nodeStatePool = NULL;
|
||||
|
||||
BzAIBTNode *printBT = NULL;
|
||||
|
||||
BzAIBTStatus printAction(void *data) {
|
||||
bzLogInfo("Hello, world!");
|
||||
return BZ_AIBT_FAIL;
|
||||
}
|
||||
|
||||
bool init(int *game) {
|
||||
nodePool = bzObjectPoolCreate(&(BzObjectPoolDesc) {
|
||||
.objectSize = bzAIBTGetNodeSize(),
|
||||
});
|
||||
nodeStatePool = bzObjectPoolCreate(&(BzObjectPoolDesc) {
|
||||
.objectSize = bzAIBTGetNodeStateSize()
|
||||
});
|
||||
|
||||
// for 1..5:
|
||||
// delay 1s
|
||||
// print "Hello, world!"
|
||||
printBT = bzAIBTMakeRoot(nodePool);
|
||||
BzAIBTNode *node = bzAIBTDecorRepeat(nodePool, printBT, 5);
|
||||
node = bzAIBTDecorDelay(nodePool, node, 1.0f);
|
||||
bzAIBTAction(nodePool, node, printAction);
|
||||
|
||||
BzAIBTState state = bzAIBTCreateState(&(BzAIBTStateDesc) {
|
||||
.root = printBT,
|
||||
.pool = nodeStatePool,
|
||||
.userData = NULL
|
||||
});
|
||||
|
||||
BzAIBTStatus status = BZ_AIBT_RUNNING;
|
||||
|
||||
i32 count = 0;
|
||||
while (status == BZ_AIBT_RUNNING) {
|
||||
status = bzAIBTExecute(&state, 0.2f);
|
||||
count++;
|
||||
}
|
||||
bzLogInfo("Iter: %d", count);
|
||||
|
||||
bzObjectPoolDestroy(nodePool);
|
||||
bzObjectPoolDestroy(nodeStatePool);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void render(float dt, int *game) {
|
||||
ClearBackground(WHITE);
|
||||
|
||||
}
|
||||
|
||||
bool bzMain(BzAppDesc *appDesc, int argc, const char **argv) {
|
||||
appDesc->init = (BzAppInitFunc) init;
|
||||
appDesc->render = (BzAppRenderFunc) render;
|
||||
|
||||
init(NULL);
|
||||
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user