-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStateMachineTreeUnitTest.hpp
More file actions
106 lines (89 loc) · 1.59 KB
/
StateMachineTreeUnitTest.hpp
File metadata and controls
106 lines (89 loc) · 1.59 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#pragma once
#include "StateMachineTree.h"
class AITest : public SNL::StateMachineTree
{
public:
AITest() { frame = 0; }
enum
{
Preparing=1,
Working,
Ending
};
void Tick()
{
frame++;
BGN_SMT
{
BGN_STATE(Preparing)
{
timer = 3;
SMT_PAUSE_IF(--timer)
report("wait 3 ticks to get here");
timer = 2;
SMT_CHECK_POINT
report("get first check point, wait 2 round");
if (--timer) break;
timer = 3;
SMT_CHECK_POINT
report("get second check point, wait 3 round");
if (--timer) break;
BGN_NEW_STATE
{
timer = 2;
BGN_STATE(1)
{
report("do task1-1 2 times in sub state");
if (--timer) break;
//go to the same level state
GotoState(2, -1);
}END_STATE
BGN_STATE(2)
{
report("do task1-2 10 times in sub state");
timer++;
if (timer > 10)
{
//goto the top level state
GotoState(Working, 0);
break;
}
}END_STATE
}END_STATE
}END_STATE
BGN_STATE(Working)
{
report("keep on doing task2");
if (frame > 90)
{
GotoState(3, 0);
}
}END_STATE
BGN_STATE(Ending)
{
report("doing task3");
}END_STATE
}
END_SMT
}
void report(const char * tex)
{
std::cout<< tex<< std::endl;
}
int timer;
int frame = 0;
};
void UnitTestSMT()
{
AITest ai;
for (int i = 0; i < 100; i++)
{
std::cout << std::endl << "FRAME : " << i << std::endl;
ai.Tick();
for (int i = 0; i <= ai.LastDebugStackDepth; i++)
{
std::cout << ai.DebugStateStack[i] << " <<<===";
}
std::cout << std::endl;
}
}