|
@@ -23,24 +23,15 @@
|
23
|
23
|
#include <GL/glu.h>
|
24
|
24
|
#endif
|
25
|
25
|
|
26
|
|
-#if defined(linux) || defined(__APPLE__)
|
27
|
|
-#include <time.h>
|
28
|
|
-#include <sys/time.h>
|
29
|
|
-#endif
|
30
|
|
-
|
31
|
26
|
#include "utils/math.h"
|
|
27
|
+#include "utils/time.h"
|
32
|
28
|
#include "System.h"
|
33
|
29
|
|
34
|
|
-////////////////////////////////////////////////////////////
|
35
|
|
-// Constructors
|
36
|
|
-////////////////////////////////////////////////////////////
|
37
|
|
-
|
38
|
|
-System::System()
|
39
|
|
-{
|
|
30
|
+System::System() {
|
40
|
31
|
m_width = 800;
|
41
|
32
|
m_height = 600;
|
42
|
33
|
|
43
|
|
- m_driver = 0x0;
|
|
34
|
+ m_driver = NULL;
|
44
|
35
|
|
45
|
36
|
m_clipFar = 4000.0f;
|
46
|
37
|
m_clipNear = 4.0f;
|
|
@@ -63,25 +54,18 @@ System::System()
|
63
|
54
|
#endif
|
64
|
55
|
}
|
65
|
56
|
|
66
|
|
-
|
67
|
|
-System::~System()
|
68
|
|
-{
|
|
57
|
+System::~System() {
|
69
|
58
|
}
|
70
|
59
|
|
71
|
|
-
|
72
|
|
-////////////////////////////////////////////////////////////
|
73
|
|
-// Public Accessors
|
74
|
|
-////////////////////////////////////////////////////////////
|
75
|
|
-
|
76
|
|
-
|
77
|
|
-unsigned int System::getTicks()
|
78
|
|
-{
|
79
|
|
- return system_timer(1);
|
|
60
|
+unsigned int System::getTicks() {
|
|
61
|
+ return system_timer();
|
80
|
62
|
}
|
81
|
63
|
|
|
64
|
+void System::resetTicks() {
|
|
65
|
+ system_timer_reset();
|
|
66
|
+}
|
82
|
67
|
|
83
|
|
-int System::createDir(char *path)
|
84
|
|
-{
|
|
68
|
+int System::createDir(char *path) {
|
85
|
69
|
#ifdef WIN32
|
86
|
70
|
return _mkdir(path);
|
87
|
71
|
#else
|
|
@@ -89,80 +73,57 @@ int System::createDir(char *path)
|
89
|
73
|
#endif
|
90
|
74
|
}
|
91
|
75
|
|
92
|
|
-
|
93
|
|
-////////////////////////////////////////////////////////////
|
94
|
|
-// Public Mutators
|
95
|
|
-////////////////////////////////////////////////////////////
|
96
|
|
-
|
97
|
|
-unsigned int System::addCommandMode(const char *command)
|
98
|
|
-{
|
99
|
|
- if (command && command[0] == '[')
|
100
|
|
- {
|
|
76
|
+unsigned int System::addCommandMode(const char *command) {
|
|
77
|
+ if (command && command[0] == '[') {
|
101
|
78
|
mCmdModes.pushBack(command);
|
102
|
79
|
return (mCmdModes.size() - 1);
|
103
|
|
- }
|
104
|
|
- else
|
105
|
|
- {
|
|
80
|
+ } else {
|
106
|
81
|
return 0;
|
107
|
82
|
}
|
108
|
83
|
}
|
109
|
84
|
|
110
|
85
|
//! \fixme Modifer support later
|
111
|
|
-void System::bindKeyCommand(const char *cmd, unsigned int key, int event)
|
112
|
|
-{
|
|
86
|
+void System::bindKeyCommand(const char *cmd, unsigned int key, int event) {
|
113
|
87
|
printf("Bound command '%s' -> event %i (0x%x key)\n", cmd, event, key);
|
114
|
88
|
mKeyEvents[key] = event;
|
115
|
89
|
}
|
116
|
90
|
|
117
|
|
-
|
118
|
|
-void System::command(const char *cmd)
|
119
|
|
-{
|
|
91
|
+void System::command(const char *cmd) {
|
120
|
92
|
bool modeFound = false;
|
121
|
93
|
char *cmdbuf;
|
122
|
94
|
|
123
|
|
-
|
124
|
95
|
if (!cmd || !cmd[0]) // Null command string
|
125
|
96
|
return;
|
126
|
97
|
|
127
|
|
- if (cmd[0] == '[') // Set a mode, eg "[Engine.OpenGL.Driver]"
|
128
|
|
- {
|
129
|
|
- for (mCmdModes.start(); mCmdModes.forward(); mCmdModes.next())
|
130
|
|
- {
|
131
|
|
- if (strcmp(cmd, mCmdModes.current()) == 0)
|
132
|
|
- {
|
|
98
|
+ if (cmd[0] == '[') { // Set a mode, eg "[Engine.OpenGL.Driver]"
|
|
99
|
+ for (mCmdModes.start(); mCmdModes.forward(); mCmdModes.next()) {
|
|
100
|
+ if (strcmp(cmd, mCmdModes.current()) == 0) {
|
133
|
101
|
mCommandMode = mCmdModes.getCurrentIndex();
|
134
|
102
|
modeFound = true;
|
135
|
103
|
}
|
136
|
104
|
}
|
137
|
105
|
|
138
|
|
- if (!modeFound)
|
139
|
|
- {
|
|
106
|
+ if (!modeFound) {
|
140
|
107
|
// mCommandMode = 0;
|
141
|
108
|
printf("Command> Unknown mode '%s'\n", cmd);
|
142
|
109
|
}
|
143
|
|
- }
|
144
|
|
- else // Execute a command in current mode, eg "stat fps"
|
145
|
|
- {
|
|
110
|
+ } else { // Execute a command in current mode, eg "stat fps"
|
146
|
111
|
cmdbuf = new char[strlen(cmd) + 1];
|
147
|
112
|
strncpy(cmdbuf, cmd, strlen(cmd) + 1);
|
148
|
113
|
handleCommand(cmdbuf, mCommandMode);
|
149
|
114
|
}
|
150
|
115
|
}
|
151
|
116
|
|
152
|
|
-
|
153
|
|
-int System::loadResourceFile(const char *filename)
|
154
|
|
-{
|
|
117
|
+int System::loadResourceFile(const char *filename) {
|
155
|
118
|
char buffer[256];
|
156
|
119
|
bool line_comment = false;
|
157
|
120
|
FILE *f;
|
158
|
121
|
char c;
|
159
|
122
|
int i, j;
|
160
|
123
|
|
161
|
|
-
|
162
|
124
|
f = fopen(filename, "r");
|
163
|
125
|
|
164
|
|
- if (!f)
|
165
|
|
- {
|
|
126
|
+ if (!f) {
|
166
|
127
|
perror(filename);
|
167
|
128
|
return -1;
|
168
|
129
|
}
|
|
@@ -173,19 +134,16 @@ int System::loadResourceFile(const char *filename)
|
173
|
134
|
buffer[0] = 0;
|
174
|
135
|
|
175
|
136
|
// Strip out whitespace and comments
|
176
|
|
- while (fscanf(f, "%c", &c) != EOF)
|
177
|
|
- {
|
|
137
|
+ while (fscanf(f, "%c", &c) != EOF) {
|
178
|
138
|
if (line_comment && c != '\n')
|
179
|
139
|
continue;
|
180
|
140
|
|
181
|
|
- if (i > 254)
|
182
|
|
- {
|
|
141
|
+ if (i > 254) {
|
183
|
142
|
printf("loadResourceFile> Overflow handled\n");
|
184
|
143
|
i = 254;
|
185
|
144
|
}
|
186
|
145
|
|
187
|
|
- switch (c)
|
188
|
|
- {
|
|
146
|
+ switch (c) {
|
189
|
147
|
case '\v':
|
190
|
148
|
case '\t':
|
191
|
149
|
break;
|
|
@@ -195,12 +153,9 @@ int System::loadResourceFile(const char *filename)
|
195
|
153
|
break;
|
196
|
154
|
case '\n':
|
197
|
155
|
if (line_comment)
|
198
|
|
- {
|
199
|
156
|
line_comment = false;
|
200
|
|
- }
|
201
|
157
|
|
202
|
|
- if (buffer[0] == 0)
|
203
|
|
- {
|
|
158
|
+ if (buffer[0] == 0) {
|
204
|
159
|
i = 0;
|
205
|
160
|
continue;
|
206
|
161
|
}
|
|
@@ -209,12 +164,9 @@ int System::loadResourceFile(const char *filename)
|
209
|
164
|
//printf("'%s'\n", buffer);
|
210
|
165
|
|
211
|
166
|
// 'Preprocessor' commands
|
212
|
|
- if (buffer[0] == '@')
|
213
|
|
- {
|
214
|
|
- if (strncmp(buffer, "@include ", 9) == 0)
|
215
|
|
- {
|
216
|
|
- for (j = 9; j < i; ++j)
|
217
|
|
- {
|
|
167
|
+ if (buffer[0] == '@') {
|
|
168
|
+ if (strncmp((buffer + 1), "include ", 8) == 0) {
|
|
169
|
+ for (j = 9; j < i; ++j) {
|
218
|
170
|
buffer[j-9] = buffer[j];
|
219
|
171
|
buffer[j-8] = 0;
|
220
|
172
|
}
|
|
@@ -223,9 +175,7 @@ int System::loadResourceFile(const char *filename)
|
223
|
175
|
|
224
|
176
|
loadResourceFile(fullPath(buffer, 0));
|
225
|
177
|
}
|
226
|
|
- }
|
227
|
|
- else
|
228
|
|
- {
|
|
178
|
+ } else {
|
229
|
179
|
command(buffer);
|
230
|
180
|
}
|
231
|
181
|
|
|
@@ -242,19 +192,13 @@ int System::loadResourceFile(const char *filename)
|
242
|
192
|
return 0;
|
243
|
193
|
}
|
244
|
194
|
|
245
|
|
-
|
246
|
|
-void System::setDriverGL(const char *driver)
|
247
|
|
-{
|
|
195
|
+void System::setDriverGL(const char *driver) {
|
248
|
196
|
unsigned int len;
|
249
|
197
|
|
250
|
|
-
|
251
|
198
|
if (m_driver)
|
252
|
|
- {
|
253
|
199
|
delete [] m_driver;
|
254
|
|
- }
|
255
|
200
|
|
256
|
|
- if (driver && driver[0])
|
257
|
|
- {
|
|
201
|
+ if (driver && driver[0]) {
|
258
|
202
|
len = strlen(driver);
|
259
|
203
|
m_driver = new char[len+1];
|
260
|
204
|
strncpy(m_driver, driver, len);
|
|
@@ -262,17 +206,8 @@ void System::setDriverGL(const char *driver)
|
262
|
206
|
}
|
263
|
207
|
}
|
264
|
208
|
|
265
|
|
-
|
266
|
|
-void System::resetTicks()
|
267
|
|
-{
|
268
|
|
- system_timer(0);
|
269
|
|
-}
|
270
|
|
-
|
271
|
|
-
|
272
|
|
-void System::resizeGL(unsigned int w, unsigned int h)
|
273
|
|
-{
|
274
|
|
- if (!w || !h)
|
275
|
|
- {
|
|
209
|
+void System::resizeGL(unsigned int w, unsigned int h) {
|
|
210
|
+ if (!w || !h) {
|
276
|
211
|
printf("resizeGL> ERROR assertions 'w > 0', 'h > 0' failed\n");
|
277
|
212
|
return;
|
278
|
213
|
}
|
|
@@ -290,51 +225,6 @@ void System::resizeGL(unsigned int w, unsigned int h)
|
290
|
225
|
glFrustum(-fW, fW, -fH, fH, m_clipNear, m_clipFar);
|
291
|
226
|
|
292
|
227
|
glMatrixMode(GL_MODELVIEW);
|
293
|
|
-}
|
294
|
|
-
|
295
|
|
-////////////////////////////////////////////////////////////
|
296
|
|
-// Private Accessors
|
297
|
|
-////////////////////////////////////////////////////////////
|
298
|
|
-
|
299
|
|
-
|
300
|
|
-////////////////////////////////////////////////////////////
|
301
|
|
-// Private Mutators
|
302
|
|
-////////////////////////////////////////////////////////////
|
303
|
|
-
|
304
|
|
-
|
305
|
|
-
|
306
|
|
-////////////////////////////////////////////////////////////
|
307
|
|
-// Gobal helper functions
|
308
|
|
-////////////////////////////////////////////////////////////
|
309
|
|
-
|
310
|
|
-
|
311
|
|
-unsigned int system_timer(int state)
|
312
|
|
-{
|
313
|
|
- static struct timeval start;
|
314
|
|
- static struct timeval stop;
|
315
|
|
- static struct timezone tz;
|
316
|
|
-
|
317
|
|
-
|
318
|
|
- switch (state)
|
319
|
|
- {
|
320
|
|
- case 0:
|
321
|
|
- gettimeofday(&start, &tz);
|
322
|
|
- break;
|
323
|
|
- case 1:
|
324
|
|
- gettimeofday(&stop, &tz);
|
325
|
|
-
|
326
|
|
- if (start.tv_usec > stop.tv_usec)
|
327
|
|
- {
|
328
|
|
- stop.tv_usec += 1000000;
|
329
|
|
- stop.tv_sec--;
|
330
|
|
- }
|
331
|
|
-
|
332
|
|
- stop.tv_usec -= start.tv_usec;
|
333
|
|
- stop.tv_sec -= start.tv_sec;
|
334
|
|
-
|
335
|
|
- return ((stop.tv_sec - start.tv_sec) * 1000) + ((stop.tv_usec - start.tv_usec) / 1000);
|
336
|
|
- }
|
337
|
|
-
|
338
|
|
- return 0;
|
|
228
|
+ glLoadIdentity();
|
339
|
229
|
}
|
340
|
230
|
|