Browse Source

No longer crashes on exit

Thomas Buck 10 years ago
parent
commit
c29af0dda0
9 changed files with 44 additions and 68 deletions
  1. 1
    0
      ChangeLog.md
  2. 0
    1
      include/Sprite.h
  3. 0
    10
      include/Texture.h
  4. 8
    13
      src/Game.cpp
  5. 1
    1
      src/Menu.cpp
  6. 2
    2
      src/OpenRaider.cpp
  7. 30
    1
      src/Render.cpp
  8. 2
    6
      src/Sprite.cpp
  9. 0
    34
      src/Texture.cpp

+ 1
- 0
ChangeLog.md View File

@@ -8,6 +8,7 @@
8 8
       in the header of the service they provide, making main.h useless
9 9
     * Also some more work on the way to making OR compilable under Windows
10 10
     * Not using glu.h anywhere anymore
11
+    * No longer segfaults on exit
11 12
 
12 13
     [ 20140516 ]
13 14
     * Finished moving the Entity/SkeletalModel logic into classes

+ 0
- 1
include/Sprite.h View File

@@ -30,7 +30,6 @@ public:
30 30
     SpriteSequence(TombRaider &tr, unsigned int item, unsigned int sequence);
31 31
     ~SpriteSequence();
32 32
 
33
-    void add(Sprite &s);
34 33
     unsigned int size();
35 34
     Sprite &get(unsigned int index);
36 35
 

+ 0
- 10
include/Texture.h View File

@@ -57,16 +57,6 @@ public:
57 57
     int getTextureCount();
58 58
 
59 59
     /*!
60
-     * \brief Dumps a screenshot to disk.
61
-     *
62
-     * Avoids overwriting files with same base name.
63
-     * \param base base filename
64
-     * \param width viewport width
65
-     * \param height viewport height
66
-     */
67
-    void glScreenShot(char *base, unsigned int width, unsigned int height);
68
-
69
-    /*!
70 60
      * \brief Sets up multitexture rendering with passed ids
71 61
      * \param texture0 first texture for multitexture
72 62
      * \param texture1 second texture for multitexture

+ 8
- 13
src/Game.cpp View File

@@ -77,12 +77,10 @@ int Game::loadLevel(const char *level) {
77 77
 
78 78
     mName = bufferString("%s", level);
79 79
 
80
-    // Load the level pak into TombRaider
81 80
     getConsole().print("Loading %s", mName);
82 81
     int error = mTombRaider.Load(mName);
83
-    if (error != 0) {
82
+    if (error != 0)
84 83
         return error;
85
-    }
86 84
 
87 85
     // If required, load the external sound effect file MAIN.SFX into TombRaider
88 86
     if ((mTombRaider.getEngine() == TR_VERSION_2) || (mTombRaider.getEngine() == TR_VERSION_3)) {
@@ -98,9 +96,8 @@ int Game::loadLevel(const char *level) {
98 96
         strcpy(tmp + dir, "MAIN.SFX"); // overwrite the name itself with MAIN.SFX
99 97
         tmp[dir + 8] = '\0';
100 98
         error = mTombRaider.loadSFX(tmp);
101
-        if (error != 0) {
99
+        if (error != 0)
102 100
             getConsole().print("Could not load %s", tmp);
103
-        }
104 101
         delete [] tmp;
105 102
     }
106 103
 
@@ -112,23 +109,21 @@ int Game::loadLevel(const char *level) {
112 109
     processMoveables();
113 110
     processPakSounds();
114 111
 
115
-    // Free pak file
116 112
     mTombRaider.reset();
117 113
 
118
-    // Check if the level contains Lara
119 114
     if (mLara == -1) {
120 115
         getConsole().print("Can't find Lara entity in level pak!");
116
+        destroy();
121 117
         return -1;
118
+    } else {
119
+        mLoaded = true;
120
+        getRender().setMode(Render::modeVertexLight);
121
+        return 0;
122 122
     }
123
-
124
-    mLoaded = true;
125
-    getRender().setMode(Render::modeVertexLight);
126
-
127
-    return 0;
128 123
 }
129 124
 
130 125
 void Game::handleAction(ActionEvents action, bool isFinished) {
131
-    if (mLoaded) {
126
+    if (mLoaded && (!isFinished)) {
132 127
         if (action == forwardAction) {
133 128
             getLara().move('f');
134 129
         } else if (action == backwardAction) {

+ 1
- 1
src/Menu.cpp View File

@@ -281,7 +281,7 @@ void Menu::handleKeyboard(KeyboardButton key, bool pressed) {
281 281
 void Menu::handleMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released) {
282 282
     int items = (getWindow().mHeight - 110) / 25;
283 283
 
284
-    if ((!released) || (button != leftmouseKey))
284
+    if (released || (button != leftmouseKey))
285 285
         return;
286 286
 
287 287
     if ((y >= 100) && (y <= (unsigned int)(100 + (25 * items)))) {

+ 2
- 2
src/OpenRaider.cpp View File

@@ -523,7 +523,7 @@ void OpenRaider::handleKeyboard(KeyboardButton key, bool pressed) {
523 523
         } else if (!getConsole().isVisible()) {
524 524
             for (int i = forwardAction; i < ActionEventCount; i++) {
525 525
                 if (keyBindings[i] == key) {
526
-                    getGame().handleAction((ActionEvents)i, pressed);
526
+                    getGame().handleAction((ActionEvents)i, !pressed);
527 527
                 }
528 528
             }
529 529
         } else {
@@ -555,7 +555,7 @@ void OpenRaider::handleMouseClick(unsigned int x, unsigned int y, KeyboardButton
555 555
     } else if (!getConsole().isVisible()) {
556 556
         for (int i = forwardAction; i < ActionEventCount; i++) {
557 557
             if (keyBindings[i] == button) {
558
-                getGame().handleAction((ActionEvents)i, !released);
558
+                getGame().handleAction((ActionEvents)i, released);
559 559
             }
560 560
         }
561 561
     }

+ 30
- 1
src/Render.cpp View File

@@ -17,6 +17,7 @@
17 17
 #include "OpenRaider.h"
18 18
 #include "Render.h"
19 19
 #include "utils/strings.h"
20
+#include "utils/tga.h"
20 21
 
21 22
 Render::Render() {
22 23
     mSkyMesh = -1;
@@ -36,7 +37,35 @@ Render::~Render() {
36 37
 
37 38
 void Render::screenShot(char *filenameBase)
38 39
 {
39
-    mTexture.glScreenShot(filenameBase, getWindow().mWidth, getWindow().mHeight);
40
+    FILE *f;
41
+    int sz = getWindow().mWidth * getWindow().mHeight;
42
+    unsigned char *image = new unsigned char[sz * 3];
43
+    char *filename = NULL;
44
+    static int count = 0;
45
+    bool done = false;
46
+
47
+    assert(filenameBase != NULL);
48
+
49
+    // Don't overwrite files
50
+    while (!done) {
51
+        filename = bufferString("%s-%04i.tga", filenameBase, count++);
52
+
53
+        f = fopen(filename, "rb");
54
+
55
+        if (f)
56
+            fclose(f);
57
+        else
58
+            done = true;
59
+    }
60
+
61
+    // Capture frame buffer
62
+    glReadPixels(0, 0, getWindow().mWidth, getWindow().mHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, image);
63
+
64
+    tgaSaveFilename(image, getWindow().mWidth, getWindow().mHeight, 0, "%s", filename);
65
+    printf("Took screenshot '%s'.\n", filename);
66
+
67
+    delete [] filename;
68
+    delete [] image;
40 69
 }
41 70
 
42 71
 unsigned int Render::getFlags() {

+ 2
- 6
src/Sprite.cpp View File

@@ -13,16 +13,12 @@
13 13
 
14 14
 SpriteSequence::SpriteSequence(TombRaider &tr, unsigned int item, unsigned int sequence) {
15 15
     for (int i = 0; i < (-tr.SpriteSequence()[sequence].negative_length); i++)
16
-        add(*new Sprite(tr, item, sequence, i));
16
+        sprites.push_back(new Sprite(tr, item, sequence, i));
17 17
 }
18 18
 
19 19
 SpriteSequence::~SpriteSequence() {
20 20
     for (unsigned int i = 0; i < sprites.size(); i++)
21
-        delete &sprites.at(i);
22
-}
23
-
24
-void SpriteSequence::add(Sprite &s) {
25
-    sprites.push_back(&s);
21
+        delete sprites.at(i);
26 22
 }
27 23
 
28 24
 unsigned int SpriteSequence::size() {

+ 0
- 34
src/Texture.cpp View File

@@ -278,40 +278,6 @@ void Texture::bindTextureId(unsigned int n) {
278 278
     glBindTexture(GL_TEXTURE_2D, mTextureIds[n]);
279 279
 }
280 280
 
281
-void Texture::glScreenShot(char *base, unsigned int width, unsigned int height) {
282
-    FILE *f;
283
-    int sz = width * height;
284
-    unsigned char *image = new unsigned char[sz * 3];
285
-    char *filename = NULL;
286
-    static int count = 0;
287
-    bool done = false;
288
-
289
-    assert(base != NULL);
290
-    assert(width > 0);
291
-    assert(height > 0);
292
-
293
-    // Don't overwrite files
294
-    while (!done) {
295
-        filename = bufferString("%s-%04i.tga", base, count++);
296
-
297
-        f = fopen(filename, "rb");
298
-
299
-        if (f)
300
-            fclose(f);
301
-        else
302
-            done = true;
303
-    }
304
-
305
-    // Capture frame buffer
306
-    glReadPixels(0, 0, width, height, GL_BGR_EXT, GL_UNSIGNED_BYTE, image);
307
-
308
-    tgaSaveFilename(image, width, height, 0, "%s", filename);
309
-    printf("Took screenshot '%s'.\n", filename);
310
-
311
-    delete [] filename;
312
-    delete [] image;
313
-}
314
-
315 281
 int Texture::loadTGA(const char *filename) {
316 282
     FILE *f;
317 283
     unsigned char *image = NULL;

Loading…
Cancel
Save