-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathexample1.c
82 lines (64 loc) · 1.91 KB
/
example1.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "bt.h"
#include <stdio.h>
void *node_list[2] = { 0 };
void example_enter(void *node, void *object, struct node_operations *ops)
{
int *ctx = (int *)object;
*ctx = *ctx + 1;
printf("example_enter %p %d\n", node, *ctx);
}
void example_exit(void *node, void *object, struct node_operations *ops)
{
int *ctx = (int *)object;
*ctx = *ctx + 1;
printf("example_exit %p %d\n", node, *ctx);
}
void example_tick(void *node, void *object, struct node_operations *ops)
{
int *ctx = (int *)object;
*ctx = *ctx + 1;
printf("example_tick %p %d\n", node, *ctx);
if (node == node_list[0])
{
ops->fail(node_control(node));
return;
}
if (*ctx < 10) ops->running(node_control(node));
else ops->success(node_control(node));
}
int main(int argc, char *argv[])
{
behaviourtree_init();
struct node_callbacks example_cbs = {
.enter = example_enter,
.tick = example_tick,
.exit = example_exit
};
int begin_type = BRANCH_TYPE_BEGIN;
int end_type = BRANCH_TYPE_COUNT;
int running_type = begin_type;
for (; running_type < end_type; ++running_type)
{
int i = 0;
for (i = 0; i < 2; ++i)
{
node_list[i] = node_create(&example_cbs, 0);
printf(">>> node_create %d %p\n", i, node_list[i]);
}
printf("\n");
void *branch = branch_create(running_type, 2, node_list);
void *tree = behaviourtree_create(branch);
static const char *BRANCH_NAME[3] = { "SEQUENCE", "PRIORITY", "RANDOM" };
printf(">>> branch_type %s\n", BRANCH_NAME[running_type]);
int ctx = 1;
int tick = 0;
for (tick = 0; tick < 10; ++tick)
{
printf(">>> behaviourtree_tick %d\n", tick);
behaviourtree_tick(tree, (void *)&ctx);
}
printf("\n");
behaviourtree_release(tree);
}
return 0;
}