|
@@ -1,28 +1,12 @@
|
1
|
|
-/* -*- Mode: C++; tab-width: 3; indent-tabs-mode: t; c-basic-offset: 3 -*- */
|
2
|
|
-/*================================================================
|
|
1
|
+/*!
|
|
2
|
+ * \file System.h
|
|
3
|
+ * \brief Mostly defines the interface of System implementations.
|
3
|
4
|
*
|
4
|
|
- * Project : UnRaider, OpenRaider, RaiderUnification 2003
|
5
|
|
- * Author : Terry 'Mongoose' Hendrix II
|
6
|
|
- * Website : http://www.westga.edu/~stu7440/
|
7
|
|
- * Email : stu7440@westga.edu
|
8
|
|
- * Object : System
|
9
|
|
- * License : No use w/o permission (C) 2002 Mongoose
|
10
|
|
- * Comments:
|
|
5
|
+ * Currently only SDL is used, but there was a GLUT implementation.
|
11
|
6
|
*
|
12
|
|
- *
|
13
|
|
- * This file was generated using Mongoose's C++
|
14
|
|
- * template generator script. <stu7440@westga.edu>
|
15
|
|
- *
|
16
|
|
- *-- Test Defines -----------------------------------------------
|
17
|
|
- *
|
18
|
|
- * UNIT_TEST_SYSTEM - Builds System class as a console unit test
|
19
|
|
- *
|
20
|
|
- *-- History ------------------------------------------------
|
21
|
|
- *
|
22
|
|
- * 2002.08.09:
|
23
|
|
- * Mongoose - Created
|
24
|
|
- ================================================================*/
|
25
|
|
-
|
|
7
|
+ * \author Mongoose
|
|
8
|
+ * \author xythobuz
|
|
9
|
+ */
|
26
|
10
|
|
27
|
11
|
#ifndef GUARD__UNRAIDER_MONGOOSE_SYSTEM_H_
|
28
|
12
|
#define GUARD__UNRAIDER_MONGOOSE_SYSTEM_H_
|
|
@@ -30,7 +14,7 @@
|
30
|
14
|
#include "mstl/Map.h"
|
31
|
15
|
#include "mstl/Vector.h"
|
32
|
16
|
|
33
|
|
-// TODO: Replace with unicode compatible key codes
|
|
17
|
+//! \todo Replace with unicode compatible key codes
|
34
|
18
|
#define SYS_MOUSE_LEFT 6000
|
35
|
19
|
#define SYS_MOUSE_RIGHT 6001
|
36
|
20
|
#define SYS_MOUSE_MIDDLE 6002
|
|
@@ -55,18 +39,15 @@
|
55
|
39
|
#define SYS_KEY_F11 1010
|
56
|
40
|
#define SYS_KEY_F12 1011
|
57
|
41
|
|
58
|
|
-typedef enum
|
59
|
|
-{
|
60
|
|
- SYS_MOD_KEY_LSHIFT = 1,
|
61
|
|
- SYS_MOD_KEY_RSHIFT = 2,
|
62
|
|
- SYS_MOD_KEY_LCTRL = 4,
|
63
|
|
- SYS_MOD_KEY_RCTRL = 8,
|
64
|
|
- SYS_MOD_KEY_LALT = 16,
|
65
|
|
- SYS_MOD_KEY_RALT = 32,
|
66
|
|
-
|
67
|
|
- SYS_MOD_KEY_LMETA = 64,
|
68
|
|
- SYS_MOD_KEY_RMETA = 128,
|
69
|
|
-
|
|
42
|
+typedef enum {
|
|
43
|
+ SYS_MOD_KEY_LSHIFT = 1,
|
|
44
|
+ SYS_MOD_KEY_RSHIFT = 2,
|
|
45
|
+ SYS_MOD_KEY_LCTRL = 4,
|
|
46
|
+ SYS_MOD_KEY_RCTRL = 8,
|
|
47
|
+ SYS_MOD_KEY_LALT = 16,
|
|
48
|
+ SYS_MOD_KEY_RALT = 32,
|
|
49
|
+ SYS_MOD_KEY_LMETA = 64,
|
|
50
|
+ SYS_MOD_KEY_RMETA = 128,
|
70
|
51
|
} sdl_sys_mod_key_t;
|
71
|
52
|
|
72
|
53
|
|
|
@@ -74,485 +55,243 @@ class System
|
74
|
55
|
{
|
75
|
56
|
public:
|
76
|
57
|
|
77
|
|
- ////////////////////////////////////////////////////////////
|
78
|
|
- // Constructors
|
79
|
|
- ////////////////////////////////////////////////////////////
|
80
|
|
-
|
81
|
|
- System();
|
82
|
|
- /*------------------------------------------------------
|
83
|
|
- * Pre :
|
84
|
|
- * Post : Constructs an object of System
|
85
|
|
- *
|
86
|
|
- *-- History ------------------------------------------
|
87
|
|
- *
|
88
|
|
- * 2002.08.09:
|
89
|
|
- * Mongoose - Created
|
90
|
|
- ------------------------------------------------------*/
|
91
|
|
-
|
92
|
|
- virtual ~System();
|
93
|
|
- /*------------------------------------------------------
|
94
|
|
- * Pre : System object is allocated
|
95
|
|
- * Post : Deconstructs an object of System
|
96
|
|
- *
|
97
|
|
- *-- History ------------------------------------------
|
98
|
|
- *
|
99
|
|
- * 2002.08.09:
|
100
|
|
- * Mongoose - Created
|
101
|
|
- ------------------------------------------------------*/
|
102
|
|
-
|
103
|
|
-
|
104
|
|
- ////////////////////////////////////////////////////////////
|
105
|
|
- // Public Accessors
|
106
|
|
- ////////////////////////////////////////////////////////////
|
107
|
|
-
|
108
|
|
- static char *bufferString(const char *string, ...);
|
109
|
|
- /*------------------------------------------------------
|
110
|
|
- * Pre : <String> is a valid string with valid args
|
111
|
|
- *
|
112
|
|
- * Post : Generates a buufered string for the printf
|
113
|
|
- * call
|
114
|
|
- *
|
115
|
|
- *-- History ------------------------------------------
|
116
|
|
- *
|
117
|
|
- * 2003.06.03:
|
118
|
|
- * Mongoose - Made into a printf string caching system
|
119
|
|
- *
|
120
|
|
- * 2001.12.31:
|
121
|
|
- * Mongoose - Created, was GLString::glPrintf
|
122
|
|
- ------------------------------------------------------*/
|
123
|
|
-
|
124
|
|
- static char *fullPath(const char *path, char end);
|
125
|
|
- /*------------------------------------------------------
|
126
|
|
- * Pre :
|
127
|
|
- * Post : Returns allocated string of path, with
|
128
|
|
- * expansion of unix home enviroment char and
|
129
|
|
- * makes sure string ends in "end" char
|
130
|
|
- *
|
131
|
|
- * end = 0 appends no addional char
|
132
|
|
- *
|
133
|
|
- *-- History ------------------------------------------
|
134
|
|
- *
|
135
|
|
- * 2002.08.17:
|
136
|
|
- * Mongoose - Created
|
137
|
|
- ------------------------------------------------------*/
|
138
|
|
-
|
139
|
|
- static char *getFileFromFullPath(char *filename);
|
140
|
|
- /*------------------------------------------------------
|
141
|
|
- * Pre :
|
142
|
|
- * Post :
|
143
|
|
- *
|
144
|
|
- *-- History ------------------------------------------
|
145
|
|
- *
|
146
|
|
- * 2003.07.05:
|
147
|
|
- * Mongoose - Created
|
148
|
|
- ------------------------------------------------------*/
|
149
|
|
-
|
150
|
|
- virtual unsigned int getTicks();
|
151
|
|
- /*------------------------------------------------------
|
152
|
|
- * Pre :
|
153
|
|
- * Post : Returns number of milliseconds since start of
|
154
|
|
- * program
|
155
|
|
- *
|
156
|
|
- *-- History ------------------------------------------
|
157
|
|
- *
|
158
|
|
- * 2002.06.06:
|
159
|
|
- * Mongoose - Created
|
160
|
|
- ------------------------------------------------------*/
|
161
|
|
-
|
162
|
|
- static int downloadToBuffer(char *urlString,
|
163
|
|
- unsigned char **buffer, unsigned int *size);
|
164
|
|
- /*------------------------------------------------------
|
165
|
|
- * Pre :
|
166
|
|
- * Post : Downloads something into passed buffer,
|
167
|
|
- * Returns < 0 on error, 0 on sucess
|
168
|
|
- *
|
169
|
|
- *-- History ------------------------------------------
|
170
|
|
- *
|
171
|
|
- * 2003.07.12:
|
172
|
|
- * Mongoose - Created
|
173
|
|
- ------------------------------------------------------*/
|
174
|
|
-
|
175
|
|
- static int downloadToFile(char *urlString, char *filename);
|
176
|
|
- /*------------------------------------------------------
|
177
|
|
- * Pre :
|
178
|
|
- * Post : Downloads something into a disk file,
|
179
|
|
- * Returns < 0 on error, 0 on sucess
|
180
|
|
- *
|
181
|
|
- *-- History ------------------------------------------
|
182
|
|
- *
|
183
|
|
- * 2003.07.12:
|
184
|
|
- * Mongoose - Created
|
185
|
|
- ------------------------------------------------------*/
|
186
|
|
-
|
187
|
|
- static int createDir(char *path);
|
188
|
|
- /*------------------------------------------------------
|
189
|
|
- * Pre : Creates directory
|
190
|
|
- * Post : Returns -1 on error
|
191
|
|
- *
|
192
|
|
- *-- History ------------------------------------------
|
193
|
|
- *
|
194
|
|
- * 2003.07.12:
|
195
|
|
- * Mongoose - Created
|
196
|
|
- ------------------------------------------------------*/
|
197
|
|
-
|
198
|
|
-
|
199
|
|
- ////////////////////////////////////////////////////////////
|
200
|
|
- // Public Mutators
|
201
|
|
- ////////////////////////////////////////////////////////////
|
202
|
|
-
|
203
|
|
- virtual unsigned int addCommandMode(const char *command);
|
204
|
|
- /*------------------------------------------------------
|
205
|
|
- * Pre : <Command> is valid command mode for the
|
206
|
|
- * resource file, eg "[Engine.OpenGL.Driver]"
|
207
|
|
- *
|
208
|
|
- * Post : Returns Id given to mode
|
209
|
|
- *
|
210
|
|
- *-- History ------------------------------------------
|
211
|
|
- *
|
212
|
|
- * 2002.03.23:
|
213
|
|
- * Mongoose - Created
|
214
|
|
- ------------------------------------------------------*/
|
215
|
|
-
|
216
|
|
- virtual void bindKeyCommand(const char *cmd, unsigned int key, int event);
|
217
|
|
- /*------------------------------------------------------
|
218
|
|
- * Pre : <Cmd> is a valid command string
|
219
|
|
- * <Key> is a valid keyboard code
|
220
|
|
- * <Event> is a valid game event Id
|
221
|
|
- *
|
222
|
|
- * Post : Sets <Event> binding <Cmd> to <Key> press
|
223
|
|
- *
|
224
|
|
- *-- History ------------------------------------------
|
225
|
|
- *
|
226
|
|
- * 2003.06.03:
|
227
|
|
- * Mongoose - Created
|
228
|
|
- ------------------------------------------------------*/
|
229
|
|
-
|
230
|
|
- virtual void command(const char *cmd);
|
231
|
|
- /*------------------------------------------------------
|
232
|
|
- * Pre : cmd is a valid command string
|
233
|
|
- * Post : cmd sets it's var
|
234
|
|
- *
|
235
|
|
- *-- History ------------------------------------------
|
236
|
|
- *
|
237
|
|
- * 2001.05.27:
|
238
|
|
- * Mongoose - Created
|
239
|
|
- ------------------------------------------------------*/
|
240
|
|
-
|
241
|
|
- virtual void gameFrame() = 0;
|
242
|
|
- /*------------------------------------------------------
|
243
|
|
- * Pre :
|
244
|
|
- * Post :
|
245
|
|
- *
|
246
|
|
- *-- History ------------------------------------------
|
247
|
|
- *
|
248
|
|
- * 2002.08.09?:
|
249
|
|
- * Mongoose - Created
|
250
|
|
- ------------------------------------------------------*/
|
251
|
|
-
|
252
|
|
- virtual void handleMouseMotionEvent(float x, float y) = 0;
|
253
|
|
- /*------------------------------------------------------
|
254
|
|
- * Pre :
|
255
|
|
- * Post :
|
256
|
|
- *
|
257
|
|
- *-- History ------------------------------------------
|
258
|
|
- *
|
259
|
|
- * 2002.08.09?:
|
260
|
|
- * Mongoose - Created
|
261
|
|
- ------------------------------------------------------*/
|
262
|
|
-
|
263
|
|
- virtual void handleBoundKeyPressEvent(unsigned int key) = 0;
|
264
|
|
- /*------------------------------------------------------
|
265
|
|
- * Pre : <Key> is a valid keyboard code
|
266
|
|
- *
|
267
|
|
- * Post : Recieves <Event> bound to <Cmd> from <Key> press
|
268
|
|
- *
|
269
|
|
- *-- History ------------------------------------------
|
270
|
|
- *
|
271
|
|
- * 2003.06.03:
|
272
|
|
- * Mongoose - Created
|
273
|
|
- ------------------------------------------------------*/
|
274
|
|
-
|
275
|
|
- virtual void handleBoundKeyReleaseEvent(unsigned int key) = 0;
|
276
|
|
- /*------------------------------------------------------
|
277
|
|
- * Pre : <Key> is a valid keyboard code
|
278
|
|
- *
|
279
|
|
- * Post : Recieves <Event> bound to <Cmd> from <Key> release
|
280
|
|
- *
|
281
|
|
- *-- History ------------------------------------------
|
282
|
|
- *
|
283
|
|
- * 2003.06.03:
|
284
|
|
- * Mongoose - Created
|
285
|
|
- ------------------------------------------------------*/
|
286
|
|
-
|
287
|
|
- virtual void handleCommand(char *command, unsigned int mode) = 0;
|
288
|
|
- /*------------------------------------------------------
|
289
|
|
- * Pre : <Command> is valid keyword optionally followed
|
290
|
|
- * by ' ' (space) seperated and argument(s)
|
291
|
|
- *
|
292
|
|
- * <Mode> is the current type or resource mode
|
293
|
|
- *
|
294
|
|
- * Post : Executes valid command based on keyword
|
295
|
|
- *
|
296
|
|
- *-- History ------------------------------------------
|
297
|
|
- *
|
298
|
|
- * 2002.03.23:
|
299
|
|
- * Mongoose - Created
|
300
|
|
- ------------------------------------------------------*/
|
301
|
|
-
|
302
|
|
- virtual void handleConsoleKeyPressEvent(unsigned int key,
|
303
|
|
- unsigned int mod) = 0;
|
304
|
|
- /*------------------------------------------------------
|
305
|
|
- * Pre : <Key> is a valid keyboard code
|
306
|
|
- *
|
307
|
|
- * Post : Recieves <Key> code from text input in console mode
|
308
|
|
- *
|
309
|
|
- *-- History ------------------------------------------
|
310
|
|
- *
|
311
|
|
- * 2003.06.03:
|
312
|
|
- * Mongoose - Created
|
313
|
|
- ------------------------------------------------------*/
|
314
|
|
-
|
315
|
|
- virtual void handleKeyPressEvent(unsigned int key, unsigned int mod) = 0;
|
316
|
|
- /*------------------------------------------------------
|
317
|
|
- * Pre :
|
318
|
|
- * Post :
|
319
|
|
- *
|
320
|
|
- *-- History ------------------------------------------
|
321
|
|
- *
|
322
|
|
- * 2002.08.09?:
|
323
|
|
- * Mongoose - Created
|
324
|
|
- ------------------------------------------------------*/
|
325
|
|
-
|
326
|
|
- virtual void handleKeyReleaseEvent(unsigned int key, unsigned int mod) = 0;
|
327
|
|
- /*------------------------------------------------------
|
328
|
|
- * Pre :
|
329
|
|
- * Post :
|
330
|
|
- *
|
331
|
|
- *-- History ------------------------------------------
|
332
|
|
- *
|
333
|
|
- * 2002.08.09?:
|
334
|
|
- * Mongoose - Created
|
335
|
|
- ------------------------------------------------------*/
|
336
|
|
-
|
337
|
|
- virtual void initGL();
|
338
|
|
- /*------------------------------------------------------
|
339
|
|
- * Pre :
|
340
|
|
- * Post :
|
341
|
|
- *
|
342
|
|
- *-- History ------------------------------------------
|
343
|
|
- *
|
344
|
|
- * 2002.08.09?:
|
345
|
|
- * Mongoose - Created
|
346
|
|
- ------------------------------------------------------*/
|
347
|
|
-
|
348
|
|
- virtual void initVideo(unsigned int width, unsigned int height,
|
349
|
|
- bool fullscreen) = 0;
|
350
|
|
- /*------------------------------------------------------
|
351
|
|
- * Pre :
|
352
|
|
- * Post :
|
353
|
|
- *
|
354
|
|
- *-- History ------------------------------------------
|
355
|
|
- *
|
356
|
|
- * 2002.08.09?:
|
357
|
|
- * Mongoose - Created
|
358
|
|
- ------------------------------------------------------*/
|
359
|
|
-
|
360
|
|
- virtual int loadResourceFile(const char *filename);
|
361
|
|
- /*------------------------------------------------------
|
362
|
|
- * Pre :
|
363
|
|
- * Post : Init the resource vars
|
364
|
|
- *
|
365
|
|
- * Returns less than zero value on error
|
366
|
|
- *
|
367
|
|
- *-- History ------------------------------------------
|
368
|
|
- *
|
369
|
|
- * 2001.05.27:
|
370
|
|
- * Mongoose - Created
|
371
|
|
- ------------------------------------------------------*/
|
372
|
|
-
|
373
|
|
- static void resetTicks();
|
374
|
|
- /*------------------------------------------------------
|
375
|
|
- * Pre :
|
376
|
|
- * Post :
|
377
|
|
- *
|
378
|
|
- *-- History ------------------------------------------
|
379
|
|
- *
|
380
|
|
- * 2002.08.09?:
|
381
|
|
- * Mongoose - Created
|
382
|
|
- ------------------------------------------------------*/
|
383
|
|
-
|
384
|
|
- virtual void resizeGL(unsigned int width, unsigned int height);
|
385
|
|
- /*------------------------------------------------------
|
386
|
|
- * Pre :
|
387
|
|
- * Post :
|
388
|
|
- *
|
389
|
|
- *-- History ------------------------------------------
|
390
|
|
- *
|
391
|
|
- * 2002.08.09?:
|
392
|
|
- * Mongoose - Created
|
393
|
|
- ------------------------------------------------------*/
|
394
|
|
-
|
395
|
|
- virtual void runGame() = 0;
|
396
|
|
- /*------------------------------------------------------
|
397
|
|
- * Pre :
|
398
|
|
- * Post :
|
399
|
|
- *
|
400
|
|
- *-- History ------------------------------------------
|
401
|
|
- *
|
402
|
|
- * 2002.08.09?:
|
403
|
|
- * Mongoose - Created
|
404
|
|
- ------------------------------------------------------*/
|
405
|
|
-
|
406
|
|
- void setConsoleMode(bool on);
|
407
|
|
- /*------------------------------------------------------
|
408
|
|
- * Pre :
|
409
|
|
- * Post : Turns console key events on/off,
|
410
|
|
- * mostly for allowing text entry vs key
|
411
|
|
- * impluse commands
|
412
|
|
- *
|
413
|
|
- *-- History ------------------------------------------
|
414
|
|
- *
|
415
|
|
- * 2003.06.03:
|
416
|
|
- * Mongoose - Created
|
417
|
|
- ------------------------------------------------------*/
|
418
|
|
-
|
419
|
|
- void setDriverGL(const char *driver);
|
420
|
|
- /*------------------------------------------------------
|
421
|
|
- * Pre :
|
422
|
|
- * Post :
|
423
|
|
- *
|
424
|
|
- *-- History ------------------------------------------
|
425
|
|
- *
|
426
|
|
- * 2002.08.09?:
|
427
|
|
- * Mongoose - Created
|
428
|
|
- ------------------------------------------------------*/
|
429
|
|
-
|
430
|
|
- void setFastCardPerformance(bool isFast);
|
431
|
|
- /*------------------------------------------------------
|
432
|
|
- * Pre :
|
433
|
|
- * Post :
|
434
|
|
- *
|
435
|
|
- *-- History ------------------------------------------
|
436
|
|
- *
|
437
|
|
- * 2002.08.09?:
|
438
|
|
- * Mongoose - Created
|
439
|
|
- ------------------------------------------------------*/
|
440
|
|
-
|
441
|
|
- virtual void shutdown(int code) = 0;
|
442
|
|
- /*------------------------------------------------------
|
443
|
|
- * Pre :
|
444
|
|
- * Post :
|
445
|
|
- *
|
446
|
|
- *-- History ------------------------------------------
|
447
|
|
- *
|
448
|
|
- * 2002.08.09?:
|
449
|
|
- * Mongoose - Created
|
450
|
|
- ------------------------------------------------------*/
|
451
|
|
-
|
452
|
|
- virtual void swapBuffersGL() = 0;
|
453
|
|
- /*------------------------------------------------------
|
454
|
|
- * Pre :
|
455
|
|
- * Post :
|
456
|
|
- *
|
457
|
|
- *-- History ------------------------------------------
|
458
|
|
- *
|
459
|
|
- * 2002.08.09?:
|
460
|
|
- * Mongoose - Created
|
461
|
|
- ------------------------------------------------------*/
|
462
|
|
-
|
463
|
|
- virtual void toggleFullscreen() = 0;
|
464
|
|
- /*------------------------------------------------------
|
465
|
|
- * Pre :
|
466
|
|
- * Post :
|
467
|
|
- *
|
468
|
|
- *-- History ------------------------------------------
|
469
|
|
- *
|
470
|
|
- * 2002.08.09?:
|
471
|
|
- * Mongoose - Created
|
472
|
|
- ------------------------------------------------------*/
|
473
|
|
-
|
474
|
|
- protected:
|
475
|
|
-
|
476
|
|
- unsigned int m_width; /* Width of the viewport */
|
477
|
|
-
|
478
|
|
- unsigned int m_height; /* Height of the viewport */
|
479
|
|
-
|
480
|
|
- bool m_fastCard; /* Assume expensive calls are fine if true */
|
481
|
|
-
|
482
|
|
- char *m_driver; /* String for dynamic use of GL library */
|
483
|
|
-
|
484
|
|
- float m_clipNear; /* Clip near distance */
|
485
|
|
-
|
486
|
|
- float m_clipFar; /* Clip far distance */
|
487
|
|
-
|
488
|
|
- float m_fovY; /* Field of vision */
|
489
|
|
-
|
490
|
|
- Map<unsigned int, int> mKeyEvents; /* Single key press event mappings */
|
491
|
|
-
|
492
|
|
- bool mConsoleMode; /* Using text (console) event handler? */
|
493
|
|
-
|
494
|
|
- Vector<const char *> mCmdModes; /* Dynamic resource command collection */
|
495
|
|
-
|
496
|
|
- unsigned int mCommandMode; /* Current resource command mode */
|
497
|
|
-
|
498
|
|
- unsigned int mConsoleKey; /* Console toggle event now handled lower */
|
499
|
|
-
|
500
|
|
- bool mFullscreen;
|
501
|
|
-
|
502
|
|
- private:
|
503
|
|
-
|
504
|
|
- ////////////////////////////////////////////////////////////
|
505
|
|
- // Private Accessors
|
506
|
|
- ////////////////////////////////////////////////////////////
|
507
|
|
-
|
508
|
|
-
|
509
|
|
- ////////////////////////////////////////////////////////////
|
510
|
|
- // Private Mutators
|
511
|
|
- ////////////////////////////////////////////////////////////
|
|
58
|
+ ////////////////////////////////////////////////////////////
|
|
59
|
+ // Constructors
|
|
60
|
+ ////////////////////////////////////////////////////////////
|
|
61
|
+
|
|
62
|
+ /*!
|
|
63
|
+ * \brief Constructs an object of System
|
|
64
|
+ */
|
|
65
|
+ System();
|
|
66
|
+
|
|
67
|
+ /*!
|
|
68
|
+ * \brief Deconstructs an object of System
|
|
69
|
+ */
|
|
70
|
+ virtual ~System();
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+ ////////////////////////////////////////////////////////////
|
|
74
|
+ // Public Accessors
|
|
75
|
+ ////////////////////////////////////////////////////////////
|
|
76
|
+
|
|
77
|
+ /*!
|
|
78
|
+ * \brief Generates a buufered string for the printf call
|
|
79
|
+ * \param string Format string like for printf
|
|
80
|
+ * \returns string in a buffer
|
|
81
|
+ */
|
|
82
|
+ static char *bufferString(const char *string, ...);
|
|
83
|
+
|
|
84
|
+ /*!
|
|
85
|
+ * \brief Expansion of unix home enviroment char.
|
|
86
|
+ * Also makes sure string ends in "end" char.
|
|
87
|
+ * \param path path string
|
|
88
|
+ * \param end end character. 0 appends no additional char
|
|
89
|
+ * \returns allocated string of path with expansions
|
|
90
|
+ */
|
|
91
|
+ static char *fullPath(const char *path, char end);
|
|
92
|
+
|
|
93
|
+ /*!
|
|
94
|
+ * \brief Only returns last part of a path string.
|
|
95
|
+ * \param filename Path to a file
|
|
96
|
+ * \returns Name of the file in filename, without path in front
|
|
97
|
+ */
|
|
98
|
+ static char *getFileFromFullPath(char *filename);
|
|
99
|
+
|
|
100
|
+ /*!
|
|
101
|
+ * \brief Gets the game tick
|
|
102
|
+ * \returns number of milliseconds since start of program
|
|
103
|
+ */
|
|
104
|
+ virtual unsigned int getTicks();
|
|
105
|
+
|
|
106
|
+ /*!
|
|
107
|
+ * \brief Downloads something into passed buffer
|
|
108
|
+ * \todo Not yet implemented!
|
|
109
|
+ * \param urlString URL of thing to download
|
|
110
|
+ * \param buffer array of strings as target
|
|
111
|
+ * \param size size of buffer
|
|
112
|
+ * \returns < 0 on error, 0 on success
|
|
113
|
+ */
|
|
114
|
+ static int downloadToBuffer(char *urlString,
|
|
115
|
+ unsigned char **buffer, unsigned int *size);
|
|
116
|
+
|
|
117
|
+ /*!
|
|
118
|
+ * \brief Downloads something into a disk file.
|
|
119
|
+ * Supports HTTP and FTP.
|
|
120
|
+ * \param urlString URL of thing to download
|
|
121
|
+ * \param filename file that should be created/filled
|
|
122
|
+ * \returns < 0 on error, 0 on success. -1000 if libferit not linked
|
|
123
|
+ */
|
|
124
|
+ static int downloadToFile(char *urlString, char *filename);
|
|
125
|
+
|
|
126
|
+ /*!
|
|
127
|
+ * \brief Created a directory
|
|
128
|
+ * \param path Directory to create
|
|
129
|
+ * \returns -1 on error
|
|
130
|
+ */
|
|
131
|
+ static int createDir(char *path);
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+ ////////////////////////////////////////////////////////////
|
|
135
|
+ // Public Mutators
|
|
136
|
+ ////////////////////////////////////////////////////////////
|
|
137
|
+
|
|
138
|
+ /*!
|
|
139
|
+ * \brief Created a new Command Mode.
|
|
140
|
+ * \param command valid command mode for the resource file, eg "[Engine.OpenGL.Driver]"
|
|
141
|
+ * \returns id given to mode
|
|
142
|
+ */
|
|
143
|
+ virtual unsigned int addCommandMode(const char *command);
|
|
144
|
+
|
|
145
|
+ /*!
|
|
146
|
+ * \brief Binds a key to a command
|
|
147
|
+ * \param cmd valid command string for event
|
|
148
|
+ * \param key valid keyboard code
|
|
149
|
+ * \param event valid game event id
|
|
150
|
+ */
|
|
151
|
+ virtual void bindKeyCommand(const char *cmd, unsigned int key, int event);
|
|
152
|
+
|
|
153
|
+ /*!
|
|
154
|
+ * \brief Executes a command string
|
|
155
|
+ * \param cmd valid command string, cmd sets its var
|
|
156
|
+ */
|
|
157
|
+ virtual void command(const char *cmd);
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+ virtual void gameFrame() = 0;
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+ virtual void handleMouseMotionEvent(float x, float y) = 0;
|
|
164
|
+
|
|
165
|
+ /*!
|
|
166
|
+ * \brief Receives the event bound to the command from the key press
|
|
167
|
+ * \param key key pressed
|
|
168
|
+ */
|
|
169
|
+ virtual void handleBoundKeyPressEvent(unsigned int key) = 0;
|
|
170
|
+
|
|
171
|
+ /*!
|
|
172
|
+ * \brief Receives the event bound to the command from the key release
|
|
173
|
+ * \param key key released
|
|
174
|
+ */
|
|
175
|
+ virtual void handleBoundKeyReleaseEvent(unsigned int key) = 0;
|
|
176
|
+
|
|
177
|
+ /*!
|
|
178
|
+ * \brief Executes valid command based on keyword
|
|
179
|
+ * \param command valid keyword, optionally followed by space separated arguments
|
|
180
|
+ * \param mode current type or resource mode
|
|
181
|
+ */
|
|
182
|
+ virtual void handleCommand(char *command, unsigned int mode) = 0;
|
|
183
|
+
|
|
184
|
+ /*!
|
|
185
|
+ * \brief Receives key code from text input in console mode
|
|
186
|
+ * \param key is a valid keyboard code
|
|
187
|
+ * \param mod modifier key
|
|
188
|
+ */
|
|
189
|
+ virtual void handleConsoleKeyPressEvent(unsigned int key,
|
|
190
|
+ unsigned int mod) = 0;
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+ virtual void handleKeyPressEvent(unsigned int key, unsigned int mod) = 0;
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+ virtual void handleKeyReleaseEvent(unsigned int key, unsigned int mod) = 0;
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+ virtual void initGL();
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+ virtual void initVideo(unsigned int width, unsigned int height,
|
|
203
|
+ bool fullscreen) = 0;
|
|
204
|
+
|
|
205
|
+ /*!
|
|
206
|
+ * \brief Init the resource vars
|
|
207
|
+ * \param filename resource file
|
|
208
|
+ * \returns < 0 on error
|
|
209
|
+ */
|
|
210
|
+ virtual int loadResourceFile(const char *filename);
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+ static void resetTicks();
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+ virtual void resizeGL(unsigned int width, unsigned int height);
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+ virtual void runGame() = 0;
|
|
220
|
+
|
|
221
|
+ /*!
|
|
222
|
+ * \brief Turns console key events on/off
|
|
223
|
+ * Mostly for allowing text entry vs key impulse commands
|
|
224
|
+ * \param on new state
|
|
225
|
+ */
|
|
226
|
+ void setConsoleMode(bool on);
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+ void setDriverGL(const char *driver);
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+ void setFastCardPerformance(bool isFast);
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+ virtual void shutdown(int code) = 0;
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+ virtual void swapBuffersGL() = 0;
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+ virtual void toggleFullscreen() = 0;
|
|
242
|
+
|
|
243
|
+protected:
|
|
244
|
+
|
|
245
|
+ unsigned int m_width; //!< Width of the viewport
|
|
246
|
+ unsigned int m_height; //!< Height of the viewport
|
|
247
|
+ bool m_fastCard; //!< Assume expensive calls are fine if true
|
|
248
|
+ char *m_driver; //!< String for dynamic use of GL library
|
|
249
|
+ float m_clipNear; //!< Clip near distance
|
|
250
|
+ float m_clipFar; //!< Clip far distance
|
|
251
|
+ float m_fovY; //!< Field of vision
|
|
252
|
+ Map<unsigned int, int> mKeyEvents; //!< Single key press event mappings
|
|
253
|
+ bool mConsoleMode; //!< Using text (console) event handler?
|
|
254
|
+ Vector<const char *> mCmdModes; //!< Dynamic resource command collection
|
|
255
|
+ unsigned int mCommandMode; //!< Current resource command mode
|
|
256
|
+ unsigned int mConsoleKey; //!< Console toggle event now handled lower
|
|
257
|
+
|
|
258
|
+private:
|
|
259
|
+
|
|
260
|
+ ////////////////////////////////////////////////////////////
|
|
261
|
+ // Private Accessors
|
|
262
|
+ ////////////////////////////////////////////////////////////
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+ ////////////////////////////////////////////////////////////
|
|
266
|
+ // Private Mutators
|
|
267
|
+ ////////////////////////////////////////////////////////////
|
512
|
268
|
};
|
513
|
269
|
|
514
|
270
|
|
515
|
|
-// Could make these static methods later, depends on API evolution
|
516
|
|
-
|
517
|
|
- bool rc_command(const char *symbol, char *command);
|
518
|
|
- /*------------------------------------------------------
|
519
|
|
- * Pre :
|
520
|
|
- * Post : Returns true if <Command> matches <Symbol>
|
521
|
|
- * command string
|
522
|
|
- *
|
523
|
|
- * Returns the rest of the argument list back in
|
524
|
|
- * <Command> buffer, if any
|
525
|
|
- *
|
526
|
|
- *-- History ------------------------------------------
|
527
|
|
- *
|
528
|
|
- * 2002.03.23:
|
529
|
|
- * Mongoose - Created
|
530
|
|
- ------------------------------------------------------*/
|
531
|
|
-
|
532
|
|
- int rc_get_bool(char *buffer, bool *val);
|
533
|
|
- /*------------------------------------------------------
|
534
|
|
- * Pre : Buffer is "true" or "false"
|
535
|
|
- *
|
536
|
|
- * Post : Returns 0 if <Buffer> is "true" or "false"
|
537
|
|
- * and sets <Val> accordingly
|
538
|
|
- *
|
539
|
|
- * Returns -1 for null string
|
540
|
|
- * Returns -2 if string isn't "true" or "false"
|
541
|
|
- *
|
542
|
|
- *-- History ------------------------------------------
|
543
|
|
- *
|
544
|
|
- * 2002.03.23:
|
545
|
|
- * Mongoose - Created
|
546
|
|
- ------------------------------------------------------*/
|
547
|
|
-
|
548
|
|
- unsigned int system_timer(int state);
|
549
|
|
- /*------------------------------------------------------
|
550
|
|
- * Pre : 0 - reset, 1 - get number of ticks
|
551
|
|
- * Post : Sets timer state and returns number of ticks
|
552
|
|
- *
|
553
|
|
- *-- History ------------------------------------------
|
554
|
|
- *
|
555
|
|
- * 2002.06.06:
|
556
|
|
- * Mongoose - Created
|
557
|
|
- ------------------------------------------------------*/
|
|
271
|
+//! \todo Could make these static methods later, depends on API evolution
|
|
272
|
+
|
|
273
|
+ /*!
|
|
274
|
+ * \brief Checks if Command matches Symbol.
|
|
275
|
+ * Returns the rest of the argument list back in command buffer, if any
|
|
276
|
+ * \param symbol command string
|
|
277
|
+ * \param command with arguments
|
|
278
|
+ * \returns true if command matches symbol
|
|
279
|
+ */
|
|
280
|
+ bool rc_command(const char *symbol, char *command);
|
|
281
|
+
|
|
282
|
+ /*!
|
|
283
|
+ * \brief Interpret a string as a bool
|
|
284
|
+ * \param buffer "true" or "false"
|
|
285
|
+ * \param val is set to boolean interpretation of buffer
|
|
286
|
+ * \returns -1 for null string, -2 if string is not "true" or "false"
|
|
287
|
+ */
|
|
288
|
+ int rc_get_bool(char *buffer, bool *val);
|
|
289
|
+
|
|
290
|
+ /*!
|
|
291
|
+ * \brief Sets timer state and returns number of ticks
|
|
292
|
+ * \param state 0 - reset, 1 - get number of ticks
|
|
293
|
+ * \returns number of ticks
|
|
294
|
+ */
|
|
295
|
+ unsigned int system_timer(int state);
|
|
296
|
+
|
558
|
297
|
#endif
|