-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdrawinterface.hpp
More file actions
175 lines (147 loc) · 4.79 KB
/
drawinterface.hpp
File metadata and controls
175 lines (147 loc) · 4.79 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
//
// author: Kovacs Marton
// email: tetra666@gmail.com
// license: whatever. note my name
//
// drawinterface.hpp
//
// common stuff, and the function declarations needed by the drawing logic
//
#ifndef WIZ_DRAW_H_
#define WIZ_DRAW_H_
const int FramePerSecond = 25;
const int FontHeight = 12;
#include <vector>
#include <string>
//
// interface file for drawing layer functions
//
typedef unsigned char uchar;
//simple RGB structure, [0 - 255] range
struct Color
{
explicit Color(uchar red, uchar green, uchar blue): red(red), green(green), blue(blue)
{}
uchar red;
uchar green;
uchar blue;
};
namespace Colors
{
const Color black(0, 0, 0);
const Color white(255, 255, 255);
const Color red(255, 0, 0);
const Color green(0, 255, 0);
const Color blue(0, 0, 255);
const Color teal(0, 255, 255);
const Color yellow(255, 255, 0);
const Color pink(255, 0, 255);
const Color purple(0x80, 0, 0x80);
const Color orange(255, 0xA5, 0);
const Color gold(0xFD, 0xD0, 0x17);
const Color lime(0x41, 0xA3, 0x17);
const Color gray(0xC0, 0xC0, 0xC0);
const Color grey(gray);
}
//simple class containing the x, y coordinates
struct Coordinate
{
typedef double CoordType;
explicit Coordinate(CoordType x = CoordType(), CoordType y = CoordType()): x(x), y(y)
{}
CoordType x;
CoordType y;
Coordinate& operator+=(const Coordinate& rhs);
Coordinate& operator*=(const Coordinate::CoordType& rhs);
Coordinate& operator/=(const Coordinate::CoordType& rhs);
};
Coordinate operator-(const Coordinate& op);
Coordinate operator+(const Coordinate& lhs, const Coordinate& rhs);
Coordinate operator-(const Coordinate& lhs, const Coordinate& rhs);
Coordinate operator*(const Coordinate& lhs, const Coordinate::CoordType& rhs);
Coordinate operator*(const Coordinate::CoordType& lhs, const Coordinate& rhs);
Coordinate operator/(const Coordinate& lhs, const Coordinate::CoordType& rhs);
Coordinate::CoordType Length(const Coordinate& vektor);
Coordinate::CoordType LengthSqr(const Coordinate& vektor);
Coordinate::CoordType Distance(const Coordinate& lhs, const Coordinate& rhs);
Coordinate::CoordType DistanceSqr(const Coordinate& lhs, const Coordinate& rhs);
Coordinate Normalize(const Coordinate& vektor, Coordinate::CoordType length);
Coordinate Rotate90Cw(const Coordinate& vektor);
Coordinate Rotate90Ccw(const Coordinate& vektor);
Coordinate::CoordType Dot(const Coordinate& lhs, const Coordinate& rhs);
template <class T>
inline T Sqr(T x)
{
return x*x;
}
typedef Coordinate Size;
//
// time in seconds
//
struct Options
{
Options(): size(0, 0), fontName("-adobe-helvetica-medium-r-normal--12-120-75-75-p-67-iso8859-1"), time(-1), score(-1)
{}
Size size;
std::vector<int> teams;
std::vector<std::string> names;
std::string logFile;
std::string fontName;
int time;
int score;
};
bool ParseCommandline(int argc, char* argv[], Options& options);
//
// implementation.cpp's interface
//
namespace DrawWrapper
{
void DrawCircle(Coordinate center, int size, Color col, bool fill = false);
void DrawLine(Coordinate begin, Coordinate end, Color col);
void DrawShape(Coordinate* begin, Coordinate* end, Color color, bool fill = false);
int Random(int sup);
Size GetSize();
int DrawTextCentered(const std::string& text, Coordinate center, Color color, int correction = -1);
void DrawText(const std::string& text, Coordinate botleft, Color color);
}
namespace RemoteProtocol
{
const std::string BEGIN = "begin";
const std::string COMMAND_SPEED = "speed";
const std::string COMMAND_SHOOT = "shoot";
const std::string QUERY = "get";
const std::string QUERY_SPEED = "speed";
const std::string QUERY_POSITION = "coords";
const std::string QUERY_TEAM = "team";
const std::string QUERY_ENEMIES = "enemies";
const std::string QUERY_FRIENDS = "friends";
const std::string QUERY_BULLETS = "bullets";
const std::string QUERY_CONTEXT = "context";
const std::string RESPONSE_SPEED = QUERY_SPEED;
const std::string RESPONSE_POSITION = QUERY_POSITION;
const std::string RESPONSE_TEAM = QUERY_TEAM;
const std::string RESPONSE_ENEMIES = QUERY_ENEMIES;
const std::string RESPONSE_FRIENDS = QUERY_FRIENDS;
const std::string RESPONSE_BULLETS = QUERY_BULLETS;
const std::string RESPONSE_CONTEXT = QUERY_CONTEXT;
const std::string ACK = "ack";
const std::string DEAD = "dead";
const std::string END = "end";
}
class IpcImplementation;
class Ipc
{
public:
Ipc(const std::string& name);
~Ipc();
Ipc(const Ipc&) = default;
Ipc& operator=(const Ipc&) = default;
//
// msg should NOT include \n
//
void Send(const std::string& msg);
std::string Receive();
private:
IpcImplementation* m_impl;
};
#endif