Browse Source

Moved methods from World into Room.

Also changed some strange old delete-guards.
Thomas Buck 10 years ago
parent
commit
afad81a858
19 changed files with 258 additions and 428 deletions
  1. 4
    0
      ChangeLog.md
  2. 0
    15
      include/Render.h
  3. 7
    0
      include/Room.h
  4. 0
    1
      include/TombRaider.h
  5. 0
    46
      include/World.h
  6. 0
    1
      include/WorldData.h
  7. 8
    12
      src/Console.cpp
  8. 6
    7
      src/Entity.cpp
  9. 2
    2
      src/Font.cpp
  10. 2
    2
      src/FontSDL.cpp
  11. 12
    2
      src/Game.cpp
  12. 1
    0
      src/Menu.cpp
  13. 32
    67
      src/Mesh.cpp
  14. 8
    8
      src/OpenRaider.cpp
  15. 19
    31
      src/Render.cpp
  16. 56
    0
      src/Room.cpp
  17. 2
    1
      src/RoomData.cpp
  18. 98
    148
      src/TombRaider.cpp
  19. 1
    85
      src/World.cpp

+ 4
- 0
ChangeLog.md View File

@@ -2,6 +2,10 @@
2 2
 
3 3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
4 4
 
5
+    [ 20140613 ]
6
+    * Changed strange delete-guards
7
+    * Moved some methods from World into the proper classes
8
+
5 9
     [ 20140605 ]
6 10
     * Split Font/Text-Rendering Subsystem from Windowing System
7 11
     * Slight improvements on Window Interface/Implementation differences

+ 0
- 15
include/Render.h View File

@@ -171,13 +171,6 @@ private:
171 171
     void buildRoomRenderList(Room &room);
172 172
 
173 173
     /*!
174
-     * \brief Renders visible world object.
175
-     *
176
-     * Texture must be initialized.
177
-     */
178
-    void drawObjects();
179
-
180
-    /*!
181 174
      * \brief Renders Sky domes/boxes/etc by scaling factor.
182 175
      *
183 176
      * Texture must be initialized.
@@ -186,14 +179,6 @@ private:
186 179
     void drawSkyMesh(float scale);
187 180
 
188 181
     /*!
189
-     * \brief Renders a skeletal model.
190
-     *
191
-     * Texture must be initialized!
192
-     * \param model model to render
193
-     */
194
-    void drawModel(SkeletalModel *model);
195
-
196
-    /*!
197 182
      * \brief Updates View Volume. Call once per render frame.
198 183
      */
199 184
     void updateViewVolume();

+ 7
- 0
include/Room.h View File

@@ -28,6 +28,13 @@ public:
28 28
     Mesh &getMesh();
29 29
     void display(bool alpha);
30 30
 
31
+    bool isWall(unsigned int sector);
32
+    int getSector(float x, float z, float *floor, float *ceiling);
33
+    int getSector(float x, float z);
34
+    void getHeightAtPosition(float x, float *y, float z);
35
+    int getAdjoiningRoom(float x, float y, float z,
36
+        float x2, float y2, float z2);
37
+
31 38
     unsigned int getNumXSectors();
32 39
     unsigned int getNumZSectors();
33 40
     void getPos(vec3_t p);

+ 0
- 1
include/TombRaider.h View File

@@ -670,7 +670,6 @@ private:
670 670
 
671 671
     void printDebug(const char *methodName, const char *s, ...) __attribute__((format(printf, 3, 4)));
672 672
 
673
-    bool mReset;                           //!< Guard multiple calls to reset()
674 673
     bool mDebug;                           //!< Debug output toggle
675 674
     unsigned int mPakVersion;              //!< TombRaider pak file header version
676 675
     tr2_version_type mEngineVersion;       //!< TombRaider engine version

+ 0
- 46
include/World.h View File

@@ -82,52 +82,6 @@ public:
82 82
      */
83 83
     int getRoomByLocation(float x, float y, float z);
84 84
 
85
-    /*!
86
-     * \brief Looks for portal crossings from xyz to xyz2 segment
87
-     * from room[index]
88
-     * \param index valid room index
89
-     * \param x X coordinate of first point
90
-     * \param y Y coordinate of first point
91
-     * \param z Z coordinate of first point
92
-     * \param x2 X coordinate of second point
93
-     * \param y2 Y coordinate of second point
94
-     * \param z2 Z coordinate of second point
95
-     * \returns index of adjoined room or -1
96
-     */
97
-    int getAdjoiningRoom(int index,
98
-                            float x, float y, float z,
99
-                            float x2, float y2, float z2);
100
-
101
-    /*!
102
-     * \brief Gets the sector index of the position in room
103
-     * \param room valid room index
104
-     * \param x X coordinate in room
105
-     * \param z Z coordinate in room
106
-     * \returns sector index of position in room
107
-     */
108
-    int getSector(int room, float x, float z);
109
-
110
-    int getSector(int room, float x, float z, float *floor, float *ceiling);
111
-
112
-    unsigned int getRoomInfo(int room);
113
-
114
-    /*!
115
-     * \brief Check if sector is a wall
116
-     * \param room valid room index
117
-     * \param sector valid sector index
118
-     * \returns true if this sector is a wall
119
-     */
120
-    bool isWall(int room, int sector);
121
-
122
-    /*!
123
-     * \brief Get the world height at a position
124
-     * \param index valid room index
125
-     * \param x X coordinate
126
-     * \param y will be set to world height in that room
127
-     * \param z Z coordinate
128
-     */
129
-    void getHeightAtPosition(int index, float x, float *y, float z);
130
-
131 85
 private:
132 86
 
133 87
     // Old World

+ 0
- 1
include/WorldData.h View File

@@ -10,7 +10,6 @@
10 10
 #define _WORLDDATA_H_
11 11
 
12 12
 #include "math/math.h"
13
-#include "SkeletalModel.h"
14 13
 
15 14
 /*! \fixme For now shaders are textures on tex objects
16 15
  * and materials on color objects. If -1

+ 8
- 12
src/Console.cpp View File

@@ -29,26 +29,22 @@ Console::Console() {
29 29
 }
30 30
 
31 31
 Console::~Console() {
32
-    if (mInputBuffer)
33
-        delete [] mInputBuffer;
32
+    delete [] mInputBuffer;
33
+    mInputBuffer = NULL;
34 34
 
35
-    if (mPartialInput)
36
-        delete [] mPartialInput;
35
+    delete [] mPartialInput;
36
+    mPartialInput = NULL;
37 37
 
38
-    if (mUnfinishedInput)
39
-        delete [] mUnfinishedInput;
38
+    delete [] mUnfinishedInput;
39
+    mUnfinishedInput = NULL;
40 40
 
41 41
     while (mHistory.size() > 0) {
42
-        char *tmp = mHistory.back();
43
-        if (tmp != NULL)
44
-            delete [] tmp;
42
+        delete [] mHistory.back();
45 43
         mHistory.pop_back();
46 44
     }
47 45
 
48 46
     while (mCommandHistory.size() > 0) {
49
-        char *tmp = mCommandHistory.back();
50
-        if (tmp != NULL)
51
-            delete [] tmp;
47
+        delete [] mCommandHistory.back();
52 48
         mCommandHistory.pop_back();
53 49
     }
54 50
 }

+ 6
- 7
src/Entity.cpp View File

@@ -109,8 +109,7 @@ void Entity::move(char movement) {
109 109
     roomNew = getWorld().getRoomByLocation(room, x, y, z);
110 110
 
111 111
     if (roomNew == -1) { // Will we hit a portal?
112
-        roomNew = getWorld().getAdjoiningRoom(room,
113
-                pos[0],  pos[1], pos[2],
112
+        roomNew = getWorld().getRoom(room).getAdjoiningRoom(pos[0], pos[1], pos[2],
114 113
                 x, y, z);
115 114
 
116 115
         if (roomNew > -1)
@@ -120,9 +119,9 @@ void Entity::move(char movement) {
120 119
             return;
121 120
     }
122 121
 
123
-    roomFlags = getWorld().getRoomInfo(roomNew);
124
-    sector = getWorld().getSector(roomNew, x, z, &floor, &ceiling);
125
-    wall = getWorld().isWall(roomNew, sector);
122
+    roomFlags = getWorld().getRoom(roomNew).getFlags();
123
+    sector = getWorld().getRoom(roomNew).getSector(x, z, &floor, &ceiling);
124
+    wall = getWorld().getRoom(roomNew).isWall(sector);
126 125
 
127 126
     // If you're underwater you may want to swim  =)
128 127
     // ...if you're worldMoveType_walkNoSwim, you better hope it's shallow
@@ -167,7 +166,7 @@ void Entity::move(char movement) {
167 166
          */
168 167
 
169 168
         h = y;
170
-        getWorld().getHeightAtPosition(room, x, &h, z);
169
+        getWorld().getRoom(room).getHeightAtPosition(x, &h, z);
171 170
 
172 171
         switch (moveType) {
173 172
             case MoveTypeFly:
@@ -211,7 +210,7 @@ void Entity::move(char movement) {
211 210
 
212 211
 void Entity::print() {
213 212
     getConsole().print("Entity %d:", objectId);
214
-    getConsole().print("  Room %i (0x%X)", room, getWorld().getRoomInfo(room));
213
+    getConsole().print("  Room %i (0x%X)", room, getWorld().getRoom(room).getFlags());
215 214
     getConsole().print("  %.1fx %.1fy %.1fz", pos[0], pos[1], pos[2]);
216 215
     getConsole().print("  %.1f Yaw", OR_RAD_TO_DEG(angles[1]));
217 216
 }

+ 2
- 2
src/Font.cpp View File

@@ -10,8 +10,8 @@
10 10
 #include "Font.h"
11 11
 
12 12
 Font::~Font() {
13
-    if (mFontName)
14
-        delete [] mFontName;
13
+    delete [] mFontName;
14
+    mFontName = NULL;
15 15
 }
16 16
 
17 17
 void Font::setFont(const char *font) {

+ 2
- 2
src/FontSDL.cpp View File

@@ -31,8 +31,8 @@ FontSDL::~FontSDL() {
31 31
     if (mFontInit)
32 32
         TTF_Quit();
33 33
 
34
-    if (tempText.text)
35
-        delete [] tempText.text;
34
+    delete [] tempText.text;
35
+    tempText.text = NULL;
36 36
 }
37 37
 
38 38
 int FontSDL::initialize() {

+ 12
- 2
src/Game.cpp View File

@@ -55,9 +55,9 @@ int Game::initialize() {
55 55
 }
56 56
 
57 57
 void Game::destroy() {
58
-    if (mName)
59
-        delete [] mName;
58
+    delete [] mName;
60 59
     mName = NULL;
60
+
61 61
     mLoaded = false;
62 62
     mLara = -1;
63 63
     getRender().setMode(Render::modeDisabled);
@@ -132,6 +132,16 @@ void Game::handleAction(ActionEvents action, bool isFinished) {
132 132
             getLara().move('l');
133 133
         } else if (action == rightAction) {
134 134
             getLara().move('r');
135
+        } else if (action == jumpAction) {
136
+
137
+        } else if (action == crouchAction) {
138
+
139
+        } else if (action == useAction) {
140
+
141
+        } else if (action == holsterAction) {
142
+
143
+        } else if (action == walkAction) {
144
+
135 145
         }
136 146
     }
137 147
 }

+ 1
- 0
src/Menu.cpp View File

@@ -45,6 +45,7 @@ Menu::Menu() {
45 45
 
46 46
 Menu::~Menu() {
47 47
     delete [] mainText.text;
48
+    mainText.text = NULL;
48 49
 
49 50
     while (mMapList.size() > 0) {
50 51
         delete [] mMapList.back();

+ 32
- 67
src/Mesh.cpp View File

@@ -49,98 +49,63 @@ Mesh::Mesh()
49 49
 
50 50
 Mesh::~Mesh()
51 51
 {
52
-    unsigned int i;
52
+    delete [] mVertices;
53
+    mVertices = NULL;
53 54
 
55
+    delete [] mNormals;
56
+    mNormals = NULL;
54 57
 
55
-    if (mVertices)
56
-    {
57
-        delete [] mVertices;
58
-    }
59
-
60
-    if (mNormals)
61
-    {
62
-        delete [] mNormals;
63
-    }
64
-
65
-    if (mColors)
66
-    {
67
-        delete [] mColors;
68
-    }
58
+    delete [] mColors;
59
+    mColors = NULL;
69 60
 
70 61
     if (mTris)
71 62
     {
72
-        for (i = 0; i < mNumTris; ++i)
63
+        for (unsigned int i = 0; i < mNumTris; ++i)
73 64
         {
74
-            if (mTris[i].triangles)
75
-                delete [] mTris[i].triangles;
76
-
77
-            if (mTris[i].alpha_triangles)
78
-                delete [] mTris[i].alpha_triangles;
79
-
80
-            if (mTris[i].texcoors)
81
-                delete [] mTris[i].texcoors;
82
-
83
-            if (mTris[i].texcoors2)
84
-                delete [] mTris[i].texcoors2;
65
+            delete [] mTris[i].triangles;
66
+            delete [] mTris[i].alpha_triangles;
67
+            delete [] mTris[i].texcoors;
68
+            delete [] mTris[i].texcoors2;
85 69
         }
86 70
 
87 71
         delete [] mTris;
72
+        mTris = NULL;
88 73
     }
89 74
 
90 75
     if (mQuads)
91 76
     {
92
-        for (i = 0; i < mNumQuads; ++i)
77
+        for (unsigned int i = 0; i < mNumQuads; ++i)
93 78
         {
94
-            if (mQuads[i].quads)
95
-                delete [] mQuads[i].quads;
96
-
97
-            if (mQuads[i].alpha_quads)
98
-                delete [] mQuads[i].alpha_quads;
99
-
100
-            if (mQuads[i].texcoors)
101
-                delete [] mQuads[i].texcoors;
102
-
103
-            if (mQuads[i].texcoors2)
104
-                delete [] mQuads[i].texcoors2;
79
+            delete [] mQuads[i].quads;
80
+            delete [] mQuads[i].alpha_quads;
81
+            delete [] mQuads[i].texcoors;
82
+            delete [] mQuads[i].texcoors2;
105 83
         }
106 84
 
107 85
         delete [] mQuads;
86
+        mQuads = NULL;
108 87
     }
109 88
 
110
-    if (mVertexArray)
111
-    {
112
-        delete [] mVertexArray;
113
-    }
89
+    delete [] mVertexArray;
90
+    mVertexArray = NULL;
114 91
 
115
-    if (mNormalArray)
116
-    {
117
-        delete [] mNormalArray;
118
-    }
92
+    delete [] mNormalArray;
93
+    mNormalArray = NULL;
119 94
 
120
-    if (mColorArray)
121
-    {
122
-        delete [] mColorArray;
123
-    }
95
+    delete [] mColorArray;
96
+    mColorArray = NULL;
124 97
 
125
-    if (mTriangleTextures)
126
-    {
127
-        delete [] mTriangleTextures;
128
-    }
98
+    delete [] mTriangleTextures;
99
+    mTriangleTextures = NULL;
129 100
 
130
-    if (mTriangleIndices)
131
-    {
132
-        delete [] mTriangleIndices;
133
-    }
101
+    delete [] mTriangleIndices;
102
+    mTriangleIndices = NULL;
134 103
 
135
-    if (mTriangleFlags)
136
-    {
137
-        delete [] mTriangleFlags;
138
-    }
104
+    delete [] mTriangleFlags;
105
+    mTriangleFlags = NULL;
139 106
 
140
-    if (mTriangleTexCoordArray)
141
-    {
142
-        delete [] mTriangleTexCoordArray;
143
-    }
107
+    delete [] mTriangleTexCoordArray;
108
+    mTriangleTexCoordArray = NULL;
144 109
 }
145 110
 
146 111
 

+ 8
- 8
src/OpenRaider.cpp View File

@@ -33,17 +33,17 @@ OpenRaider::OpenRaider() {
33 33
 }
34 34
 
35 35
 OpenRaider::~OpenRaider() {
36
-    if (mBaseDir)
37
-        delete mBaseDir;
36
+    delete mBaseDir;
37
+    mBaseDir = NULL;
38 38
 
39
-    if (mPakDir)
40
-        delete mPakDir;
39
+    delete mPakDir;
40
+    mPakDir = NULL;
41 41
 
42
-    if (mAudioDir)
43
-        delete mAudioDir;
42
+    delete mAudioDir;
43
+    mAudioDir = NULL;
44 44
 
45
-    if (mDataDir)
46
-        delete mDataDir;
45
+    delete mDataDir;
46
+    mDataDir = NULL;
47 47
 }
48 48
 
49 49
 int OpenRaider::initialize() {

+ 19
- 31
src/Render.cpp View File

@@ -35,6 +35,10 @@ Render::~Render() {
35 35
     ClearWorld();
36 36
 }
37 37
 
38
+void Render::ClearWorld() {
39
+    mRoomRenderList.clear();
40
+}
41
+
38 42
 
39 43
 void Render::screenShot(char *filenameBase)
40 44
 {
@@ -119,11 +123,6 @@ int Render::initTextures(char *textureDir) {
119 123
 }
120 124
 
121 125
 
122
-void Render::ClearWorld() {
123
-    mRoomRenderList.clear();
124
-}
125
-
126
-
127 126
 // Texture must be set to WHITE solid color texture
128 127
 void renderTrace(int color, vec3_t start, vec3_t end)
129 128
 {
@@ -388,12 +387,12 @@ void Render::display()
388 387
     camPos[2] = curPos[2] - (1024.0f * cosf(yaw));
389 388
 
390 389
     int index = getGame().getLara().getRoom();
391
-    int sector = getWorld().getSector(index, camPos[0], camPos[2]);
390
+    int sector = getWorld().getRoom(index).getSector(camPos[0], camPos[2]);
392 391
 
393 392
     // Handle camera out of world
394 393
     if ((sector < 0) ||
395 394
             ((unsigned int)sector >= getWorld().getRoom(index).sizeSectors()) ||
396
-            getWorld().isWall(index, sector)) {
395
+            getWorld().getRoom(index).isWall(sector)) {
397 396
         camPos[0] = curPos[0] + (64.0f * sinf(yaw));
398 397
         camPos[1] -= 64.0f;
399 398
         camPos[2] = curPos[2] + (64.0f * cosf(yaw));
@@ -460,7 +459,18 @@ void Render::display()
460 459
 
461 460
         // Draw objects not tied to rooms
462 461
         glPushMatrix();
463
-        drawObjects();
462
+
463
+        // Draw lara or other player model ( move to entity rendering method )
464
+        if (mFlags & Render::fViewModel)
465
+            getGame().getLara().display();
466
+
467
+        // Draw sprites after player to handle alpha
468
+        for (unsigned int i = 0; i < getWorld().sizeSprite(); i++) {
469
+            SpriteSequence &sprite = getWorld().getSprite(i);
470
+            for (unsigned int j = 0; j < sprite.size(); j++)
471
+                sprite.get(j).display();
472
+        }
473
+
464 474
         glPopMatrix();
465 475
 
466 476
         // Depth sort entityRenderList with qsort
@@ -487,13 +497,7 @@ void Render::display()
487 497
 void Render::drawLoadScreen()
488 498
 {
489 499
     float x = 0.0f, y = 0.0f, z = -160.0f;
490
-    float w, h;
491
-
492
-    if (getWindow().getWidth() < getWindow().getHeight())
493
-        w = h = (float)getWindow().getWidth();
494
-    else
495
-        w = h = (float)getWindow().getHeight();
496
-
500
+    float w = getWindow().getWidth(), h = getWindow().getHeight();
497 501
 
498 502
     if (mTexture.getTextureCount() <= 0)
499 503
         return;
@@ -640,9 +644,7 @@ void Render::drawSkyMesh(float scale)
640 644
     glPushMatrix();
641 645
 
642 646
     if (mSkyMeshRotation)
643
-    {
644 647
         glRotated(90.0, 1, 0, 0);
645
-    }
646 648
 
647 649
     glTranslated(0.0, 1000.0, 0.0);
648 650
     glScaled(scale, scale, scale);
@@ -653,20 +655,6 @@ void Render::drawSkyMesh(float scale)
653 655
 }
654 656
 
655 657
 
656
-void Render::drawObjects() {
657
-    // Draw lara or other player model ( move to entity rendering method )
658
-    if (mFlags & Render::fViewModel)
659
-        getGame().getLara().display();
660
-
661
-    // Draw sprites after player to handle alpha
662
-    for (unsigned int i = 0; i < getWorld().sizeSprite(); i++) {
663
-        SpriteSequence &sprite = getWorld().getSprite(i);
664
-        for (unsigned int j = 0; j < sprite.size(); j++)
665
-            sprite.get(j).display();
666
-    }
667
-}
668
-
669
-
670 658
 void Render::tmpRenderModelMesh(model_mesh_t *r_mesh, texture_tri_t *ttri)
671 659
 {
672 660
     glBegin(GL_TRIANGLES);

+ 56
- 0
src/Room.cpp View File

@@ -517,6 +517,62 @@ void Room::display(bool alpha) {
517 517
     }
518 518
 }
519 519
 
520
+bool Room::isWall(unsigned int sector) {
521
+    assert(sector >= 0);
522
+    assert(sector < sectors.size());
523
+
524
+    //! \fixme is (sector > 0) correct??
525
+    return ((sector > 0) && sectors.at(sector)->isWall());
526
+}
527
+
528
+int Room::getSector(float x, float z, float *floor, float *ceiling) {
529
+    assert(floor != NULL);
530
+    assert(ceiling != NULL);
531
+
532
+    int sector = getSector(x, z);
533
+
534
+    if ((sector >= 0) && (sector < (int)sectors.size())) {
535
+        *floor = sectors.at(sector)->getFloor();
536
+        *ceiling = sectors.at(sector)->getCeiling();
537
+    }
538
+
539
+    return sector;
540
+}
541
+
542
+int Room::getSector(float x, float z) {
543
+    int sector = (((((int)x - (int)pos[0]) / 1024) *
544
+        numZSectors) + (((int)z - (int)pos[2]) / 1024));
545
+
546
+    if (sector < 0)
547
+        return -1;
548
+
549
+    return sector;
550
+}
551
+
552
+void Room::getHeightAtPosition(float x, float *y, float z) {
553
+    int sector = getSector(x, z);
554
+    if ((sector >= 0) && (sector < (int)sectors.size()))
555
+        *y = sectors.at(sector)->getFloor();
556
+}
557
+
558
+int Room::getAdjoiningRoom(float x, float y, float z,
559
+        float x2, float y2, float z2) {
560
+    vec3_t intersect, p1, p2;
561
+    vec3_t vertices[4];
562
+
563
+    p1[0] = x;  p1[1] = y;  p1[2] = z;
564
+    p2[0] = x2; p2[1] = y2; p2[2] = z2;
565
+
566
+    for (unsigned int i = 0; i < portals.size(); i++) {
567
+        portals.at(i)->getVertices(vertices);
568
+        if (intersectionLinePolygon(intersect, p1, p2, //4,
569
+                    vertices))
570
+            return portals.at(i)->getAdjoiningRoom();
571
+    }
572
+
573
+    return -1;
574
+}
575
+
520 576
 unsigned int Room::getFlags() {
521 577
     return flags;
522 578
 }

+ 2
- 1
src/RoomData.cpp View File

@@ -7,8 +7,9 @@
7 7
 
8 8
 #include "global.h"
9 9
 #include "Render.h"
10
-#include "RoomData.h"
10
+#include "SkeletalModel.h"
11 11
 #include "World.h"
12
+#include "RoomData.h"
12 13
 
13 14
 BoundingBox::BoundingBox() {
14 15
     a[0] = a[1] = a[2] = 0;

+ 98
- 148
src/TombRaider.cpp View File

@@ -68,7 +68,6 @@ TombRaider::TombRaider()
68 68
     flyByCamerasTR5 = 0x0;
69 69
 
70 70
     mNumTR4Samples = 0;
71
-    mReset = false;
72 71
     mDebug = false;
73 72
     mRiffAlternateLoaded = false;
74 73
     mRoomVertexLightingFactor = 50.0f;
@@ -421,8 +420,6 @@ int TombRaider::Load(char *filename)
421 420
     }
422 421
 
423 422
 
424
-    mReset = false;
425
-
426 423
     Fread(&mPakVersion, sizeof(mPakVersion), 1, f);
427 424
     //! \fixme endian
428 425
 
@@ -4107,109 +4104,93 @@ int TombRaider::loadSFX(char *filename)
4107 4104
 
4108 4105
 void TombRaider::reset()
4109 4106
 {
4110
-    unsigned int i;
4111
-
4112
-
4113
-    // Mongoose 2003.05.13, Don't let some jackass reset over and over
4114
-    if (mReset)
4115
-    {
4116
-        return;
4117
-    }
4118
-
4119
-    //! \fixme Palettes aren't the same size anymore
4120
-    //memset(_palette8, 0, 256);
4121
-    //memset(_palette16, 0, 256);
4122
-
4123
-    if (_anim_dispatches)
4124
-        delete [] _anim_dispatches;
4107
+    delete [] _anim_dispatches;
4108
+    _anim_dispatches = NULL;
4125 4109
 
4126
-    if (_anim_commands)
4127
-        delete [] _anim_commands;
4110
+    delete [] _anim_commands;
4111
+    _anim_commands = NULL;
4128 4112
 
4129
-    if (_mesh_trees)
4130
-        delete [] _mesh_trees;
4113
+    delete [] _mesh_trees;
4114
+    _mesh_trees = NULL;
4131 4115
 
4132
-    if (_frames)
4133
-        delete [] _frames;
4116
+    delete [] _frames;
4117
+    _frames = NULL;
4134 4118
 
4135
-    if (_moveables)
4136
-        delete [] _moveables;
4119
+    delete [] _moveables;
4120
+    _moveables = NULL;
4137 4121
 
4138
-    if (_static_meshes)
4139
-        delete [] _static_meshes;
4122
+    delete [] _static_meshes;
4123
+    _static_meshes = NULL;
4140 4124
 
4141
-    if (_object_textures)
4142
-        delete [] _object_textures;
4125
+    delete [] _object_textures;
4126
+    _object_textures = NULL;
4143 4127
 
4144
-    if (_sprite_textures)
4145
-        delete [] _sprite_textures;
4128
+    delete [] _sprite_textures;
4129
+    _sprite_textures = NULL;
4146 4130
 
4147
-    if (_sprite_sequences)
4148
-        delete [] _sprite_sequences;
4131
+    delete [] _sprite_sequences;
4132
+    _sprite_sequences = NULL;
4149 4133
 
4150
-    if (_cameras)
4151
-        delete [] _cameras;
4134
+    delete [] _cameras;
4135
+    _cameras = NULL;
4152 4136
 
4153
-    if (_sound_sources)
4154
-        delete [] _sound_sources;
4137
+    delete [] _sound_sources;
4138
+    _sound_sources = NULL;
4155 4139
 
4156
-    if (_boxes)
4157
-        delete [] _boxes;
4140
+    delete [] _boxes;
4141
+    _boxes = NULL;
4158 4142
 
4159
-    if (_overlaps)
4160
-        delete [] _overlaps;
4143
+    delete [] _overlaps;
4144
+    _overlaps = NULL;
4161 4145
 
4162
-    if (_zones)
4163
-        delete [] _zones;
4146
+    delete [] _zones;
4147
+    _zones = NULL;
4164 4148
 
4165
-    if (_animated_textures)
4166
-        delete [] _animated_textures;
4149
+    delete [] _animated_textures;
4150
+    _animated_textures = NULL;
4167 4151
 
4168
-    if (_items)
4169
-        delete [] _items;
4152
+    delete [] _items;
4153
+    _items = NULL;
4170 4154
 
4171
-    if (_light_map)
4172
-        delete [] _light_map;
4155
+    delete [] _light_map;
4156
+    _light_map = NULL;
4173 4157
 
4174
-    if (_cinematic_frames)
4175
-        delete [] _cinematic_frames;
4158
+    delete [] _cinematic_frames;
4159
+    _cinematic_frames = NULL;
4176 4160
 
4177
-    if (_demo_data)
4178
-        delete [] _demo_data;
4161
+    delete [] _demo_data;
4162
+    _demo_data = NULL;
4179 4163
 
4180
-    if (mRiffAlternateOffsets)
4181
-        delete [] mRiffAlternateOffsets;
4164
+    delete [] mRiffAlternateOffsets;
4165
+    mRiffAlternateOffsets = NULL;
4182 4166
 
4183
-    if (mSoundMap)
4184
-        delete [] mSoundMap;
4167
+    delete [] mSoundMap;
4168
+    mSoundMap = NULL;
4185 4169
 
4186
-    if (mSoundDetails)
4187
-        delete [] mSoundDetails;
4170
+    delete [] mSoundDetails;
4171
+    mSoundDetails = NULL;
4188 4172
 
4189
-    if (mSampleIndices)
4190
-        delete [] mSampleIndices;
4173
+    delete [] mSampleIndices;
4174
+    mSampleIndices = NULL;
4191 4175
 
4192
-    if (mRiffData)
4193
-        delete [] mRiffData;
4176
+    delete [] mRiffData;
4177
+    mRiffData = NULL;
4194 4178
 
4195
-    if (mTR4Samples)
4196
-    {
4197
-        for (i = 0; i < mNumTR4Samples; ++i)
4198
-        {
4199
-            if (mTR4SamplesSz[i])
4200
-                delete [] mTR4Samples[i];
4179
+    if (mTR4Samples) {
4180
+        for (unsigned int i = 0; i < mNumTR4Samples; ++i) {
4181
+            delete [] mTR4Samples[i];
4182
+            mTR4Samples[i] = NULL;
4201 4183
         }
4202 4184
 
4203 4185
         delete [] mTR4Samples;
4186
+        mTR4Samples = NULL;
4204 4187
     }
4205 4188
 
4206
-    if (mTR4SamplesSz)
4207
-        delete [] mTR4SamplesSz;
4189
+    delete [] mTR4SamplesSz;
4190
+    mTR4SamplesSz = NULL;
4208 4191
 
4209
-    if (_rooms)
4210
-    {
4211
-        for (i = 0; i < _num_rooms; ++i)
4212
-        {
4192
+    if (_rooms) {
4193
+        for (unsigned int i = 0; i < _num_rooms; ++i) {
4213 4194
             if (_rooms[i].room_data.num_vertices > 0)
4214 4195
                 delete [] _rooms[i].room_data.vertices;
4215 4196
 
@@ -4223,107 +4204,78 @@ void TombRaider::reset()
4223 4204
                 delete [] _rooms[i].room_data.sprites;
4224 4205
 
4225 4206
             if (_rooms[i].num_portals > 0)
4226
-                delete []_rooms[i].portals;
4227
-
4228
-            if (_rooms[i].sector_list)
4229
-                delete [] _rooms[i].sector_list;
4230
-
4231
-            if (_rooms[i].lights)
4232
-                delete [] _rooms[i].lights;
4207
+                delete [] _rooms[i].portals;
4233 4208
 
4234
-            if (_rooms[i].tr4Lights)
4235
-                delete [] _rooms[i].tr4Lights;
4236
-
4237
-            if (_rooms[i].static_meshes)
4238
-                delete [] _rooms[i].static_meshes;
4209
+            delete [] _rooms[i].sector_list;
4210
+            delete [] _rooms[i].lights;
4211
+            delete [] _rooms[i].tr4Lights;
4212
+            delete [] _rooms[i].static_meshes;
4239 4213
         }
4240 4214
 
4241 4215
         delete [] _rooms;
4216
+        _rooms = NULL;
4242 4217
     }
4243 4218
 
4244
-    if (_floor_data)
4245
-    {
4246
-        delete [] _floor_data;
4247
-    }
4248
-
4249
-    if (mMeshes)
4250
-    {
4251
-        for (i = 0; (int)i < mMeshCount; ++i)
4252
-        {
4253
-            if (mMeshes[i].vertices)
4254
-                delete [] mMeshes[i].vertices;
4255
-
4256
-            if (mMeshes[i].mesh_lights)
4257
-                delete [] mMeshes[i].mesh_lights;
4258
-
4259
-            if (mMeshes[i].normals)
4260
-                delete [] mMeshes[i].normals;
4261
-
4262
-            if (mMeshes[i].textured_rectangles)
4263
-                delete [] mMeshes[i].textured_rectangles;
4264
-
4265
-            if (mMeshes[i].textured_triangles)
4266
-                delete [] mMeshes[i].textured_triangles;
4267
-
4268
-            if (mMeshes[i].coloured_rectangles)
4269
-                delete [] mMeshes[i].coloured_rectangles;
4219
+    delete [] _floor_data;
4220
+    _floor_data = NULL;
4270 4221
 
4271
-            if (mMeshes[i].coloured_triangles)
4272
-                delete [] mMeshes[i].coloured_triangles;
4222
+    if (mMeshes) {
4223
+        for (unsigned int i = 0; (int)i < mMeshCount; ++i) {
4224
+            delete [] mMeshes[i].vertices;
4225
+            delete [] mMeshes[i].mesh_lights;
4226
+            delete [] mMeshes[i].normals;
4227
+            delete [] mMeshes[i].textured_rectangles;
4228
+            delete [] mMeshes[i].textured_triangles;
4229
+            delete [] mMeshes[i].coloured_rectangles;
4230
+            delete [] mMeshes[i].coloured_triangles;
4273 4231
         }
4274 4232
 
4275 4233
         delete [] mMeshes;
4234
+        mMeshes = NULL;
4276 4235
     }
4277 4236
 
4278
-    if (_animations)
4279
-        delete [] _animations;
4237
+    delete [] _animations;
4238
+    _animations = NULL;
4280 4239
 
4281
-    if (_state_changes)
4282
-        delete _state_changes;
4283
-    //delete [] _state_changes;
4240
+    delete [] _state_changes;
4241
+    _state_changes = NULL;
4284 4242
 
4285 4243
     numMoveablesTR5 = 0;
4286
-    if (moveablesTR5)
4287
-        delete [] moveablesTR5;
4244
+    delete [] moveablesTR5;
4245
+    moveablesTR5 = NULL;
4288 4246
 
4289 4247
     numAnimationsTR5 = 0;
4290
-    if (animationsTR5)
4291
-        delete [] animationsTR5;
4248
+    delete [] animationsTR5;
4249
+    animationsTR5 = NULL;
4292 4250
 
4293 4251
     numObjectTexturesTR5 = 0;
4294
-    if (objectTexturesTR5)
4295
-        delete [] objectTexturesTR5;
4252
+    delete [] objectTexturesTR5;
4253
+    objectTexturesTR5 = NULL;
4296 4254
 
4297 4255
     numCinematicFramesTR5 = 0;
4298
-    if (cinematicFramesTR5)
4299
-        delete [] cinematicFramesTR5;
4256
+    delete [] cinematicFramesTR5;
4257
+    cinematicFramesTR5 = NULL;
4300 4258
 
4301 4259
     numFlyByCamerasTR5 = 0;
4302
-    if (flyByCamerasTR5)
4303
-        delete [] flyByCamerasTR5;
4260
+    delete [] flyByCamerasTR5;
4261
+    flyByCamerasTR5 = NULL;
4304 4262
 
4305 4263
     // Texture use
4306
-    if (_tex_special)
4307
-        delete [] _tex_special;
4308
-
4309
-    if (_textile8)
4310
-        delete [] _textile8;
4311
-
4312
-    if (_textile16)
4313
-        delete [] _textile16;
4314
-
4315
-    if (_textile32)
4316
-        delete [] _textile32;
4317
-
4318
-    //! \fixme Damaged memory causes delete to not set pointer to NULL?
4264
+    delete [] _tex_special;
4319 4265
     _tex_special = NULL;
4266
+
4267
+    delete [] _textile8;
4320 4268
     _textile8 = NULL;
4269
+
4270
+    delete [] _textile16;
4321 4271
     _textile16 = NULL;
4272
+
4273
+    delete [] _textile32;
4322 4274
     _textile32 = NULL;
4323 4275
 
4324 4276
     // Compressed level use
4325
-    if (mCompressedLevelData)
4326
-        delete [] mCompressedLevelData;
4277
+    delete [] mCompressedLevelData;
4278
+    mCompressedLevelData = NULL;
4327 4279
 
4328 4280
     mCompressedLevelDataOffset  = 0;
4329 4281
     mCompressedLevelSize = 0;
@@ -4364,8 +4316,6 @@ void TombRaider::reset()
4364 4316
     _num_sprite_textures = 0;
4365 4317
     _num_sprite_sequences = 0;
4366 4318
     _num_overlaps = 0;
4367
-
4368
-    mReset = true;
4369 4319
 }
4370 4320
 
4371 4321
 

+ 1
- 85
src/World.cpp View File

@@ -27,6 +27,7 @@ void World::addMesh(model_mesh_t *mesh)
27 27
         mMeshes.push_back(mesh);
28 28
 }
29 29
 
30
+
30 31
 void World::addRoom(Room &room) {
31 32
     mRooms.push_back(&room);
32 33
 }
@@ -109,91 +110,6 @@ int World::getRoomByLocation(float x, float y, float z) {
109 110
 }
110 111
 
111 112
 
112
-int World::getAdjoiningRoom(int index,
113
-        float x, float y, float z,
114
-        float x2, float y2, float z2) {
115
-    assert(index >= 0);
116
-    assert(index < (int)mRooms.size());
117
-    Room &room = *mRooms.at(index);
118
-    vec3_t intersect, p1, p2;
119
-    vec3_t vertices[4];
120
-
121
-    p1[0] = x;  p1[1] = y;  p1[2] = z;
122
-    p2[0] = x2; p2[1] = y2; p2[2] = z2;
123
-
124
-    for (unsigned int i = 0; i < room.sizePortals(); i++) {
125
-        room.getPortal(i).getVertices(vertices);
126
-        if (intersectionLinePolygon(intersect, p1, p2, //4,
127
-                    vertices))
128
-            return room.getPortal(i).getAdjoiningRoom();
129
-    }
130
-
131
-    return -1;
132
-}
133
-
134
-
135
-int World::getSector(int room, float x, float z, float *floor, float *ceiling) {
136
-    assert(room >= 0);
137
-    assert(room < (int)mRooms.size());
138
-    assert(floor != NULL);
139
-    assert(ceiling != NULL);
140
-
141
-    int sector = getSector(room, x, z);
142
-
143
-    if ((sector >= 0) && (sector < (int)mRooms.at(room)->sizeSectors())) {
144
-        *floor = mRooms.at(room)->getSector(sector).getFloor();
145
-        *ceiling = mRooms.at(room)->getSector(sector).getCeiling();
146
-    }
147
-
148
-    return sector;
149
-}
150
-
151
-
152
-int World::getSector(int room, float x, float z) {
153
-    assert(room >= 0);
154
-    assert(room < (int)mRooms.size());
155
-
156
-    vec3_t pos;
157
-    mRooms.at(room)->getPos(pos);
158
-    int sector = (((((int)x - (int)pos[0]) / 1024) *
159
-        mRooms.at(room)->getNumZSectors()) + (((int)z - (int)pos[2]) / 1024));
160
-
161
-    if (sector < 0)
162
-        return -1;
163
-
164
-    return sector;
165
-}
166
-
167
-
168
-unsigned int World::getRoomInfo(int room) {
169
-    assert(room >= 0);
170
-    assert(room < (int)mRooms.size());
171
-
172
-    return mRooms.at(room)->getFlags();
173
-}
174
-
175
-
176
-bool World::isWall(int room, int sector) {
177
-    assert(room >= 0);
178
-    assert(room < (int)mRooms.size());
179
-    assert(sector >= 0);
180
-    assert(sector < (int)mRooms.at(room)->sizeSectors());
181
-
182
-    //! \fixme is (sector > 0) correct??
183
-    return ((sector > 0) && mRooms.at(room)->getSector(sector).isWall());
184
-}
185
-
186
-
187
-void World::getHeightAtPosition(int index, float x, float *y, float z) {
188
-    assert(index >= 0);
189
-    assert(index < (int)mRooms.size());
190
-
191
-    int sector = getSector(index, x, z);
192
-    if ((sector >= 0) && (sector < (int)mRooms.at(index)->sizeSectors()))
193
-        *y = mRooms.at(index)->getSector(sector).getFloor();
194
-}
195
-
196
-
197 113
 void World::destroy() {
198 114
     for (unsigned int i = 0; i != mRooms.size(); i++)
199 115
         delete mRooms[i];

Loading…
Cancel
Save