GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
Interpreter.hh
Go to the documentation of this file.
1
2char cmda[] = "ca";
3char cmdb[] = { 1,2,3,4,5,0 };
4char cmdc[] = { 1,2,3,4,5,0 };
5char *cmds[] = { &cmda, &cmdb, &cmdc };
6
8{
9public:
10 PointCollectionInterpret(char** cmds) : cmds(cmds) { current_point.x = 0.0; current_point.y = 0.0; current_vector.dx = 0.0; current_vector.dy = -1.0; }
11 int Size() const { return vec.size(); }
12 Point2d Index(int i) const
13 {
14 return vec[i];
15 }
16
17 void execute(char cmd)
18 {
19 char *cmdptr = cmds[cmd];
20 while(1)
21 {
22 switch(*cmdptr++)
23 {
24 case '\0': return;
25 case 'c': // funccall: (1, cmdnum)
26 {
27 char cmdtoexecute = *cmdptr++ - 'a';
28 execute(cmdtoexecute);
29 }
30 break;
31 case 'p': // Point
32 {
33 vec.push_back(current_point);
34 }
35 break;
36 case 'f': // Forward
37 {
38 current_point += current_vector;
39 break;
40 }
41 break;
42 case 'b': // Backward
43 {
44 current_point += current_vector;
45 break;
46 }
47 break;
48 case 'l': // rotate left
49 {
50 Vector2d v;
51 v.dx = current_vector.dx * cos(45.0/2.0*2.0*3.14159/360.0)
52 - current_vector.dy * sin(45/2.0*2.0*3.14159/360.0);
53 v.dy = current_vector.dx * sin(45.0/2.0*2.0*3.14159/360.0)
54 + current_vector.dy * cos(45.0/2.0*2.0*3.14159/360.0);
55 current_vector = v;
56 }
57 break;
58 case 'r': // rotate right
59 {
60 Vector2d v;
61 v.dx = current_vector.dx * cos(-45.0/2.0*2.0*3.14159/360.0)
62 - current_vector.dy * sin(-45/2.0*2.0*3.14159/360.0);
63 v.dy = current_vector.dx * sin(-45.0/2.0*2.0*3.14159/360.0)
64 + current_vector.dy * cos(-45.0/2.0*2.0*3.14159/360.0);
65 current_vector = v;
66 }
67 break;
68 case 's': // scale down *2
69 {
70 current_vector /= 2.0;
71 break;
72 }
73 case 'S': // scale up *2
74 {
75 current_vector *= 2.0;
76 break;
77 }
78 };
79 }
80 }
81private:
82 char **cmds;
83 std::vector<Point2d> vec;
84 Point2d current_point;
85 Vector2d current_vector;
86};
87
88int main()
89{
91 d.execute(0);
92}
char * cmds[]
Definition Interpreter.hh:5
char cmdc[]
Definition Interpreter.hh:4
char cmdb[]
Definition Interpreter.hh:3
int main()
Definition Interpreter.hh:88
char cmda[]
Definition Interpreter.hh:2
Definition Effect.hh:2663
Definition Interpreter.hh:8
Point2d Index(int i) const
Definition Interpreter.hh:12
PointCollectionInterpret(char **cmds)
Definition Interpreter.hh:10
int Size() const
Definition Interpreter.hh:11
void execute(char cmd)
Definition Interpreter.hh:17
d
Definition meshpage.php:3895
Definition VectorTools.hh:910
Definition VectorTools.hh:972
float dy
Definition VectorTools.hh:973
float dx
Definition VectorTools.hh:973