GameApi
28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
Interpreter.hh
Go to the documentation of this file.
1
2
char
cmda
[] =
"ca"
;
3
char
cmdb
[] = { 1,2,3,4,5,0 };
4
char
cmdc
[] = { 1,2,3,4,5,0 };
5
char
*
cmds
[] = { &
cmda
, &
cmdb
, &
cmdc
};
6
7
class
PointCollectionInterpret
:
public
PointCollection2d
8
{
9
public
:
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
}
81
private
:
82
char
**
cmds
;
83
std::vector<Point2d> vec;
84
Point2d
current_point;
85
Vector2d
current_vector;
86
};
87
88
int
main
()
89
{
90
PointCollectionInterpret
d
(
cmds
);
91
d
.execute(0);
92
}
cmds
char * cmds[]
Definition
Interpreter.hh:5
cmdc
char cmdc[]
Definition
Interpreter.hh:4
cmdb
char cmdb[]
Definition
Interpreter.hh:3
main
int main()
Definition
Interpreter.hh:88
cmda
char cmda[]
Definition
Interpreter.hh:2
PointCollection2d
Definition
Effect.hh:2663
PointCollectionInterpret
Definition
Interpreter.hh:8
PointCollectionInterpret::Index
Point2d Index(int i) const
Definition
Interpreter.hh:12
PointCollectionInterpret::PointCollectionInterpret
PointCollectionInterpret(char **cmds)
Definition
Interpreter.hh:10
PointCollectionInterpret::Size
int Size() const
Definition
Interpreter.hh:11
PointCollectionInterpret::execute
void execute(char cmd)
Definition
Interpreter.hh:17
d
d
Definition
meshpage.php:3895
Point2d
Definition
VectorTools.hh:910
Vector2d
Definition
VectorTools.hh:972
Vector2d::dy
float dy
Definition
VectorTools.hh:973
Vector2d::dx
float dx
Definition
VectorTools.hh:973
Interpreter.hh
Generated by
1.15.0