Преглед на файлове

Started using Strings and Streams.

Many commands no longer included.
Thomas Buck преди 10 години
родител
ревизия
7e59ba5f3f
променени са 6 файла, в които са добавени 614 реда и са изтрити 646 реда
  1. 4
    0
      ChangeLog.md
  2. 1
    1
      data/OpenRaider.ini
  3. 6
    13
      include/OpenRaider.h
  4. 592
    258
      src/Command.cpp
  5. 11
    7
      src/Game.cpp
  6. 0
    367
      src/OpenRaider.cpp

+ 4
- 0
ChangeLog.md Целия файл

@@ -2,6 +2,10 @@
2 2
 
3 3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
4 4
 
5
+    [ 20140601 ]
6
+    * Started removing C-style I/O, now using Strings and Streams
7
+    * set size now takes two ints instead of a string
8
+
5 9
     [ 20140520 ]
6 10
     * cmake script checks for presence of functions needed for
7 11
       recursive folder traversal

+ 1
- 1
data/OpenRaider.ini Целия файл

@@ -11,7 +11,7 @@ set font       "$(datadir)/test.ttf"
11 11
 set gldriver   "/usr/lib/libGL.so.1"
12 12
 
13 13
 # Windowing
14
-set size       "1280x720"
14
+set size       1280 720
15 15
 set fullscreen false
16 16
 
17 17
 # Audio

+ 6
- 13
include/OpenRaider.h Целия файл

@@ -8,6 +8,8 @@
8 8
 #ifndef _OPENRAIDER_H_
9 9
 #define _OPENRAIDER_H_
10 10
 
11
+#include <sstream>
12
+#include <string>
11 13
 #include <vector>
12 14
 
13 15
 #include "Console.h"
@@ -40,20 +42,16 @@ public:
40 42
      */
41 43
     int loadConfig(const char *config);
42 44
 
45
+    int command(std::string &command);
43 46
     int command(const char *command);
44 47
 
45 48
     void run();
46
-
47 49
     void frame();
48 50
 
49 51
     void handleKeyboard(KeyboardButton key, bool pressed);
50
-
51 52
     void handleText(char *text, bool notFinished);
52
-
53 53
     void handleMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released);
54
-
55 54
     void handleMouseMotion(int xrel, int yrel);
56
-
57 55
     void handleMouseScroll(int xrel, int yrel);
58 56
 
59 57
     //! \fixme should be private
@@ -64,16 +62,11 @@ public:
64 62
 
65 63
 private:
66 64
 
67
-    int command(const char *command, std::vector<char *> *args);
68
-
65
+    int command(std::stringstream &command);
69 66
     char *expandDirectoryNames(const char *s);
70
-
71
-    int help(const char *cmd);
72
-
73
-    int set(const char *var, const char *value);
74
-
67
+    int help(std::string &cmd);
68
+    int set(std::stringstream &command);
75 69
     int bind(const char *action, const char *key);
76
-
77 70
     int bind(ActionEvents action, const char *key);
78 71
 
79 72
     bool mRunning;

+ 592
- 258
src/Command.cpp
Файловите разлики са ограничени, защото са твърде много
Целия файл


+ 11
- 7
src/Game.cpp Целия файл

@@ -358,25 +358,29 @@ void Game::processMoveables()
358 358
 // index moveable, i item, sometimes both moveable
359 359
 // object_id of item or moveable
360 360
 void Game::processMoveable(int index, int i, int object_id) {
361
+    // Check if the SkeletalModel is already cached
361 362
     bool cached = false;
362
-    unsigned int mod = 0;
363
-    for (; mod < getWorld().sizeSkeletalModel(); mod++) {
364
-        if (getWorld().getSkeletalModel(mod).getId() == object_id) {
363
+    unsigned int model;
364
+    for (model = 0; model < getWorld().sizeSkeletalModel(); model++) {
365
+        if (getWorld().getSkeletalModel(model).getId() == object_id) {
365 366
             cached = true;
366 367
             break;
367 368
         }
368 369
     }
369 370
 
370
-    if (!cached) {
371
+    // Create a new SkeletalModel, if needed
372
+    if (!cached)
371 373
         getWorld().addSkeletalModel(*new SkeletalModel(mTombRaider, index, object_id));
372
-    }
373 374
 
374
-    getWorld().addEntity(*new Entity(mTombRaider, index, i, mod));
375
+    // Create a new Entity, using the cached or the new SkeletalModel
376
+    Entity &entity = *new Entity(mTombRaider, index, i, model);
377
+    getWorld().addEntity(entity);
375 378
 
376 379
     // Store reference to Lara
377
-    if (getWorld().getEntity(getWorld().sizeEntity() - 1).getObjectId() == 0)
380
+    if (entity.getObjectId() == 0)
378 381
         mLara = getWorld().sizeEntity() - 1;
379 382
 
383
+    // Store reference to the SkyMesh
380 384
     if (i == mTombRaider.getSkyModelId())
381 385
         getRender().setSkyMesh(i, //moveable[i].starting_mesh,
382 386
                 (mTombRaider.Engine() == TR_VERSION_2));

+ 0
- 367
src/OpenRaider.cpp Целия файл

@@ -89,373 +89,6 @@ int OpenRaider::initialize() {
89 89
     return 0;
90 90
 }
91 91
 
92
-int OpenRaider::loadConfig(const char *config) {
93
-    assert(config != NULL);
94
-    assert(config[0] != '\0');
95
-
96
-    char *configFile = fullPath(config, 0);
97
-    getConsole().print("Loading config from \"%s\"...", configFile);
98
-
99
-    FILE *f = fopen(configFile, "r");
100
-    if (f == NULL) {
101
-        getConsole().print("Could not open file!");
102
-        return -1;
103
-    }
104
-
105
-    char buffer[256];
106
-    while (fgets(buffer, 256, f) != NULL) {
107
-        int error = command(buffer);
108
-        if (error != 0) {
109
-            getConsole().print("Error Code: %d", error);
110
-        }
111
-    }
112
-
113
-    fclose(f);
114
-
115
-    return 0;
116
-}
117
-
118
-int OpenRaider::command(const char *command) {
119
-    assert(command != NULL);
120
-    assert(command[0] != '\0');
121
-
122
-    int returnValue = 0;
123
-    char *cmd = bufferString("%s", command);
124
-    size_t length = strlen(cmd);
125
-
126
-    // Command ends at '\n' or # when a comment begins
127
-    for (size_t i = 0; i < length; i++) {
128
-        if (cmd[i] == '\n' || cmd[i] == '#') {
129
-            cmd[i] = '\0';
130
-            break;
131
-        }
132
-    }
133
-
134
-    char *token = strtok(cmd, " \t");
135
-    if (token != NULL) {
136
-        // token is the command to execute
137
-        // get arguments
138
-        std::vector<char *> args;
139
-        char *next;
140
-        while ((next = strtok(NULL, " \t")) != NULL) {
141
-            args.push_back(next);
142
-        }
143
-
144
-        // Execute
145
-        returnValue = this->command(token, &args);
146
-    }
147
-
148
-    delete [] cmd;
149
-    return returnValue;
150
-}
151
-
152
-char *OpenRaider::expandDirectoryNames(const char *s) {
153
-    assert(s != NULL);
154
-    assert(s[0] != '\0');
155
-
156
-    if (mBaseDir != NULL) {
157
-        const char *base = "$(basedir)";
158
-        if (strstr(s, base) != NULL) {
159
-            return stringReplace(s, base, mBaseDir);
160
-        }
161
-    }
162
-
163
-    if (mPakDir != NULL) {
164
-        const char *pak = "$(pakdir)";
165
-        if (strstr(s, pak) != NULL) {
166
-            return stringReplace(s, pak, mPakDir);
167
-        }
168
-    }
169
-
170
-    if (mAudioDir != NULL) {
171
-        const char *audio = "$(audiodir)";
172
-        if (strstr(s, audio) != NULL) {
173
-            return stringReplace(s, audio, mAudioDir);
174
-        }
175
-    }
176
-
177
-    if (mDataDir != NULL) {
178
-        const char *data = "$(datadir)";
179
-        if (strstr(s, data) != NULL) {
180
-            return stringReplace(s, data, mDataDir);
181
-        }
182
-    }
183
-
184
-    return NULL;
185
-}
186
-
187
-#define CHANGE_DIR_WITH_EXPANSION(a) do {     \
188
-    char *quotes = stringRemoveQuotes(value); \
189
-    char *tmp = expandDirectoryNames(quotes); \
190
-    if (tmp == NULL) {                        \
191
-        a = fullPath(quotes, 0);              \
192
-    } else {                                  \
193
-        a = fullPath(tmp, 0);                 \
194
-        delete [] tmp;                        \
195
-    }                                         \
196
-    delete [] quotes;                         \
197
-} while(false)
198
-
199
-int OpenRaider::set(const char *var, const char *value) {
200
-    assert(var != NULL);
201
-    assert(var[0] != '\0');
202
-    assert(value != NULL);
203
-    assert(value[0] != '\0');
204
-
205
-    if (strcmp(var, "size") == 0) {
206
-        // value has format like "\"1024x768\""
207
-        unsigned int w = DEFAULT_WIDTH, h = DEFAULT_HEIGHT;
208
-        if (sscanf(value, "\"%5ux%5u\"", &w, &h) != 2) {
209
-            getConsole().print("set-size-Error: Invalid value (%s)", value);
210
-            return -2;
211
-        }
212
-        getWindow().setSize(w, h);
213
-    } else if (strcmp(var, "fullscreen") == 0) {
214
-        bool fullscreen = false;
215
-        if (readBool(value, &fullscreen) != 0) {
216
-            getConsole().print("set-fullscreen-Error: Invalid value (%s)", value);
217
-            return -3;
218
-        }
219
-        getWindow().setFullscreen(fullscreen);
220
-    } else if (strcmp(var, "gldriver") == 0) {
221
-        getWindow().setDriver(value);
222
-    } else if (strcmp(var, "audio") == 0) {
223
-        bool audio = false;
224
-        if (readBool(value, &audio) != 0) {
225
-            getConsole().print("set-audio-Error: Invalid value (%s)", value);
226
-            return -4;
227
-        }
228
-        getSound().setEnabled(audio);
229
-    } else if (strcmp(var, "volume") == 0) {
230
-        float vol = 1.0f;
231
-        if (sscanf(value, "%5f", &vol) != 1) {
232
-            getConsole().print("set-volume-Error: Invalid value (%s)", value);
233
-            return -5;
234
-        }
235
-        getSound().setVolume(vol);
236
-    } else if (strcmp(var, "mouse_x") == 0) {
237
-        float sense = 1.0f;
238
-        if (sscanf(value, "%5f", &sense) != 1) {
239
-            getConsole().print("set-mouse_x-Error: Invalid value (%s)", value);
240
-            return -6;
241
-        }
242
-        getCamera().setSensitivityX(OR_DEG_TO_RAD(sense));
243
-    } else if (strcmp(var, "mouse_y") == 0) {
244
-        float sense = 1.0f;
245
-        if (sscanf(value, "%5f", &sense) != 1) {
246
-            getConsole().print("set-mouse_y-Error: Invalid value (%s)", value);
247
-            return -7;
248
-        }
249
-        getCamera().setSensitivityY(OR_DEG_TO_RAD(sense));
250
-    } else if (strcmp(var, "fps") == 0) {
251
-        bool fps = false;
252
-        if (readBool(value, &fps) != 0) {
253
-            getConsole().print("set-fps-Error: Invalid value (%s)", value);
254
-            return -8;
255
-        }
256
-        mFPS = fps;
257
-    } else if (strcmp(var, "basedir") == 0) {
258
-        CHANGE_DIR_WITH_EXPANSION(mBaseDir);
259
-    } else if (strcmp(var, "pakdir") == 0) {
260
-        CHANGE_DIR_WITH_EXPANSION(mPakDir);
261
-    } else if (strcmp(var, "audiodir") == 0) {
262
-        CHANGE_DIR_WITH_EXPANSION(mAudioDir);
263
-    } else if (strcmp(var, "datadir") == 0) {
264
-        CHANGE_DIR_WITH_EXPANSION(mDataDir);
265
-    } else if (strcmp(var, "font") == 0) {
266
-        char *quotes = stringReplace(value, "\"", "");
267
-        char *tmp = expandDirectoryNames(quotes);
268
-        if (tmp == NULL) {
269
-            getWindow().setFont(quotes);
270
-        } else {
271
-            getWindow().setFont(tmp);
272
-            delete [] tmp;
273
-        }
274
-        delete [] quotes;
275
-    } else {
276
-        getConsole().print("set-Error: Unknown variable (%s = %s)", var, value);
277
-        return -1;
278
-    }
279
-
280
-    return 0;
281
-}
282
-
283
-int OpenRaider::bind(const char *action, const char *key) {
284
-    assert(action != NULL);
285
-    assert(action[0] != '\0');
286
-    assert(key != NULL);
287
-    assert(key[0] != '\0');
288
-
289
-    const char *tmp = action;
290
-    if (action[0] == '+')
291
-        tmp++;
292
-
293
-    if (strcmp(tmp, "menu") == 0) {
294
-        return bind(menuAction, key);
295
-    } else if (strcmp(tmp, "console") == 0) {
296
-        return bind(consoleAction, key);
297
-    } else if (strcmp(tmp, "forward") == 0) {
298
-        return bind(forwardAction, key);
299
-    } else if (strcmp(tmp, "backward") == 0) {
300
-        return bind(backwardAction, key);
301
-    } else if (strcmp(tmp, "left") == 0) {
302
-        return bind(leftAction, key);
303
-    } else if (strcmp(tmp, "right") == 0) {
304
-        return bind(rightAction, key);
305
-    } else if (strcmp(tmp, "jump") == 0) {
306
-        return bind(jumpAction, key);
307
-    } else if (strcmp(tmp, "crouch") == 0) {
308
-        return bind(crouchAction, key);
309
-    } else if (strcmp(tmp, "use") == 0) {
310
-        return bind(useAction, key);
311
-    } else if (strcmp(tmp, "holster") == 0) {
312
-        return bind(holsterAction, key);
313
-    } else if (strcmp(tmp, "walk") == 0) {
314
-        return bind(walkAction, key);
315
-    } else {
316
-        getConsole().print("bind-Error: Unknown action (%s --> %s)", key, action);
317
-        return -1;
318
-    }
319
-}
320
-
321
-int OpenRaider::bind(ActionEvents action, const char *key) {
322
-    assert(action < ActionEventCount);
323
-    assert(key != NULL);
324
-    assert(key[0] != '\0');
325
-
326
-    size_t length = strlen(key);
327
-    if ((key[0] == '\'') && (key[length - 1] == '\'') && (length == 3)) {
328
-        // Literal character like w, a, s, d, 0, 1...
329
-        char c = key[1];
330
-        if (((c >= '0') && (c <= '9'))
331
-            || ((c >= 'a') && (c <= 'z'))) {
332
-            keyBindings[action] = (KeyboardButton)c;
333
-        } else {
334
-            getConsole().print("bind-\'\'-Error: Unknown key (%s)", key);
335
-            return -1;
336
-        }
337
-    } else if ((key[0] == '\"') && (key[length - 1] == '\"')) {
338
-        // Special characters like tilde, esc, quote...
339
-        char *tmp = stringRemoveQuotes(key);
340
-        if (strcmp(tmp, "quote") == 0) {
341
-            keyBindings[action] = quoteKey;
342
-        } else if (strcmp(tmp, "backslash") == 0) {
343
-            keyBindings[action] = backslashKey;
344
-        } else if (strcmp(tmp, "backspace") == 0) {
345
-            keyBindings[action] = backspaceKey;
346
-        } else if (strcmp(tmp, "capslock") == 0) {
347
-            keyBindings[action] = capslockKey;
348
-        } else if (strcmp(tmp, "comma") == 0) {
349
-            keyBindings[action] = commaKey;
350
-        } else if (strcmp(tmp, "del") == 0) {
351
-            keyBindings[action] = delKey;
352
-        } else if (strcmp(tmp, "up") == 0) {
353
-            keyBindings[action] = upKey;
354
-        } else if (strcmp(tmp, "down") == 0) {
355
-            keyBindings[action] = downKey;
356
-        } else if (strcmp(tmp, "left") == 0) {
357
-            keyBindings[action] = leftKey;
358
-        } else if (strcmp(tmp, "right") == 0) {
359
-            keyBindings[action] = rightKey;
360
-        } else if (strcmp(tmp, "end") == 0) {
361
-            keyBindings[action] = endKey;
362
-        } else if (strcmp(tmp, "equals") == 0) {
363
-            keyBindings[action] = equalsKey;
364
-        } else if (strcmp(tmp, "escape") == 0) {
365
-            keyBindings[action] = escapeKey;
366
-        } else if (strcmp(tmp, "f1") == 0) {
367
-            keyBindings[action] = f1Key;
368
-        } else if (strcmp(tmp, "f2") == 0) {
369
-            keyBindings[action] = f2Key;
370
-        } else if (strcmp(tmp, "f3") == 0) {
371
-            keyBindings[action] = f3Key;
372
-        } else if (strcmp(tmp, "f4") == 0) {
373
-            keyBindings[action] = f4Key;
374
-        } else if (strcmp(tmp, "f5") == 0) {
375
-            keyBindings[action] = f5Key;
376
-        } else if (strcmp(tmp, "f6") == 0) {
377
-            keyBindings[action] = f6Key;
378
-        } else if (strcmp(tmp, "f7") == 0) {
379
-            keyBindings[action] = f7Key;
380
-        } else if (strcmp(tmp, "f8") == 0) {
381
-            keyBindings[action] = f8Key;
382
-        } else if (strcmp(tmp, "f9") == 0) {
383
-            keyBindings[action] = f9Key;
384
-        } else if (strcmp(tmp, "f10") == 0) {
385
-            keyBindings[action] = f10Key;
386
-        } else if (strcmp(tmp, "f11") == 0) {
387
-            keyBindings[action] = f11Key;
388
-        } else if (strcmp(tmp, "f12") == 0) {
389
-            keyBindings[action] = f12Key;
390
-        } else if (strcmp(tmp, "backquote") == 0) {
391
-            keyBindings[action] = backquoteKey;
392
-        } else if (strcmp(tmp, "home") == 0) {
393
-            keyBindings[action] = homeKey;
394
-        } else if (strcmp(tmp, "insert") == 0) {
395
-            keyBindings[action] = insertKey;
396
-        } else if (strcmp(tmp, "leftalt") == 0) {
397
-            keyBindings[action] = leftaltKey;
398
-        } else if (strcmp(tmp, "leftctrl") == 0) {
399
-            keyBindings[action] = leftctrlKey;
400
-        } else if (strcmp(tmp, "leftbracket") == 0) {
401
-            keyBindings[action] = leftbracketKey;
402
-        } else if (strcmp(tmp, "leftgui") == 0) {
403
-            keyBindings[action] = leftguiKey;
404
-        } else if (strcmp(tmp, "leftshift") == 0) {
405
-            keyBindings[action] = leftshiftKey;
406
-        } else if (strcmp(tmp, "minus") == 0) {
407
-            keyBindings[action] = minusKey;
408
-        } else if (strcmp(tmp, "numlock") == 0) {
409
-            keyBindings[action] = numlockKey;
410
-        } else if (strcmp(tmp, "pagedown") == 0) {
411
-            keyBindings[action] = pagedownKey;
412
-        } else if (strcmp(tmp, "pageup") == 0) {
413
-            keyBindings[action] = pageupKey;
414
-        } else if (strcmp(tmp, "pause") == 0) {
415
-            keyBindings[action] = pauseKey;
416
-        } else if (strcmp(tmp, "dot") == 0) {
417
-            keyBindings[action] = dotKey;
418
-        } else if (strcmp(tmp, "rightalt") == 0) {
419
-            keyBindings[action] = rightaltKey;
420
-        } else if (strcmp(tmp, "rightctrl") == 0) {
421
-            keyBindings[action] = rightctrlKey;
422
-        } else if (strcmp(tmp, "enter") == 0) {
423
-            keyBindings[action] = enterKey;
424
-        } else if (strcmp(tmp, "rightgui") == 0) {
425
-            keyBindings[action] = rightguiKey;
426
-        } else if (strcmp(tmp, "rightbracket") == 0) {
427
-            keyBindings[action] = rightbracketKey;
428
-        } else if (strcmp(tmp, "rightshift") == 0) {
429
-            keyBindings[action] = rightshiftKey;
430
-        } else if (strcmp(tmp, "scrolllock") == 0) {
431
-            keyBindings[action] = scrolllockKey;
432
-        } else if (strcmp(tmp, "semicolon") == 0) {
433
-            keyBindings[action] = semicolonKey;
434
-        } else if (strcmp(tmp, "slash") == 0) {
435
-            keyBindings[action] = slashKey;
436
-        } else if (strcmp(tmp, "space") == 0) {
437
-            keyBindings[action] = spaceKey;
438
-        } else if (strcmp(tmp, "tab") == 0) {
439
-            keyBindings[action] = tabKey;
440
-        } else if (strcmp(tmp, "leftmouse") == 0) {
441
-            keyBindings[action] = leftmouseKey;
442
-        } else if (strcmp(tmp, "middlemouse") == 0) {
443
-            keyBindings[action] = middlemouseKey;
444
-        } else if (strcmp(tmp, "rightmouse") == 0) {
445
-            keyBindings[action] = rightmouseKey;
446
-        } else {
447
-            getConsole().print("bind-\"\"-Error: Unknown key (%s)", key);
448
-            delete [] tmp;
449
-            return -2;
450
-        }
451
-        delete [] tmp;
452
-    } else {
453
-        getConsole().print("bind-Error: Unknown key (%s)", key);
454
-        return -3;
455
-    }
456
-    return 0;
457
-}
458
-
459 92
 void OpenRaider::run() {
460 93
     assert(mRunning == false);
461 94
     mRunning = true;

Loading…
Отказ
Запис