Переглянути джерело

No longer crashes on exit

Thomas Buck 11 роки тому
джерело
коміт
c29af0dda0
9 змінених файлів з 44 додано та 68 видалено
  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 Переглянути файл

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

+ 0
- 1
include/Sprite.h Переглянути файл

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

+ 0
- 10
include/Texture.h Переглянути файл

57
     int getTextureCount();
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
      * \brief Sets up multitexture rendering with passed ids
60
      * \brief Sets up multitexture rendering with passed ids
71
      * \param texture0 first texture for multitexture
61
      * \param texture0 first texture for multitexture
72
      * \param texture1 second texture for multitexture
62
      * \param texture1 second texture for multitexture

+ 8
- 13
src/Game.cpp Переглянути файл

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

+ 1
- 1
src/Menu.cpp Переглянути файл

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

+ 2
- 2
src/OpenRaider.cpp Переглянути файл

523
         } else if (!getConsole().isVisible()) {
523
         } else if (!getConsole().isVisible()) {
524
             for (int i = forwardAction; i < ActionEventCount; i++) {
524
             for (int i = forwardAction; i < ActionEventCount; i++) {
525
                 if (keyBindings[i] == key) {
525
                 if (keyBindings[i] == key) {
526
-                    getGame().handleAction((ActionEvents)i, pressed);
526
+                    getGame().handleAction((ActionEvents)i, !pressed);
527
                 }
527
                 }
528
             }
528
             }
529
         } else {
529
         } else {
555
     } else if (!getConsole().isVisible()) {
555
     } else if (!getConsole().isVisible()) {
556
         for (int i = forwardAction; i < ActionEventCount; i++) {
556
         for (int i = forwardAction; i < ActionEventCount; i++) {
557
             if (keyBindings[i] == button) {
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 Переглянути файл

17
 #include "OpenRaider.h"
17
 #include "OpenRaider.h"
18
 #include "Render.h"
18
 #include "Render.h"
19
 #include "utils/strings.h"
19
 #include "utils/strings.h"
20
+#include "utils/tga.h"
20
 
21
 
21
 Render::Render() {
22
 Render::Render() {
22
     mSkyMesh = -1;
23
     mSkyMesh = -1;
36
 
37
 
37
 void Render::screenShot(char *filenameBase)
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
 unsigned int Render::getFlags() {
71
 unsigned int Render::getFlags() {

+ 2
- 6
src/Sprite.cpp Переглянути файл

13
 
13
 
14
 SpriteSequence::SpriteSequence(TombRaider &tr, unsigned int item, unsigned int sequence) {
14
 SpriteSequence::SpriteSequence(TombRaider &tr, unsigned int item, unsigned int sequence) {
15
     for (int i = 0; i < (-tr.SpriteSequence()[sequence].negative_length); i++)
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
 SpriteSequence::~SpriteSequence() {
19
 SpriteSequence::~SpriteSequence() {
20
     for (unsigned int i = 0; i < sprites.size(); i++)
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
 unsigned int SpriteSequence::size() {
24
 unsigned int SpriteSequence::size() {

+ 0
- 34
src/Texture.cpp Переглянути файл

278
     glBindTexture(GL_TEXTURE_2D, mTextureIds[n]);
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
 int Texture::loadTGA(const char *filename) {
281
 int Texture::loadTGA(const char *filename) {
316
     FILE *f;
282
     FILE *f;
317
     unsigned char *image = NULL;
283
     unsigned char *image = NULL;

Завантаження…
Відмінити
Зберегти