Browse Source

LoaderTR2 loads most parts of the Rooms

Thomas Buck 10 years ago
parent
commit
8e2118188c
9 changed files with 217 additions and 79 deletions
  1. 3
    0
      ChangeLog.md
  2. 5
    6
      include/Room.h
  3. 1
    8
      include/RoomData.h
  4. 3
    0
      src/Game.cpp
  5. 32
    31
      src/Room.cpp
  6. 10
    6
      src/RoomData.cpp
  7. 4
    2
      src/SkeletalModel.cpp
  8. 4
    2
      src/StaticMesh.cpp
  9. 155
    24
      src/loader/LoaderTR2.cpp

+ 3
- 0
ChangeLog.md View File

2
 
2
 
3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
4
 
4
 
5
+    [ 20141207 ]
6
+    * LoaderTR2 now also loads all important parts of the Room structures
7
+
5
     [ 20141206 ]
8
     [ 20141206 ]
6
     * LoaderTR2 now tries to load Moveables and Entities
9
     * LoaderTR2 now tries to load Moveables and Entities
7
     * Added Meshes to World, taking role of StaticMeshes
10
     * Added Meshes to World, taking role of StaticMeshes

+ 5
- 6
include/Room.h View File

22
   public:
22
   public:
23
     Room(TombRaider& tr, unsigned int index);
23
     Room(TombRaider& tr, unsigned int index);
24
 
24
 
25
-    Room();
25
+    Room(float p[3] = nullptr, unsigned int f = 0, unsigned int x = 0, unsigned int z = 0);
26
     ~Room();
26
     ~Room();
27
 
27
 
28
     BoundingBox& getBoundingBox();
28
     BoundingBox& getBoundingBox();
41
     unsigned int getNumZSectors();
41
     unsigned int getNumZSectors();
42
     void getPos(float p[3]);
42
     void getPos(float p[3]);
43
 
43
 
44
+    void setNumXSectors(unsigned int n);
45
+    void setNumZSectors(unsigned int n);
46
+    void setPos(float p[3]);
47
+
44
     void setFlags(unsigned int f);
48
     void setFlags(unsigned int f);
45
     unsigned int getFlags();
49
     unsigned int getFlags();
46
 
50
 
56
     Sector& getSector(unsigned long index);
60
     Sector& getSector(unsigned long index);
57
     void addSector(Sector* s);
61
     void addSector(Sector* s);
58
 
62
 
59
-    unsigned long sizeBox();
60
-    Box& getBox(unsigned long index);
61
-    void addBox(Box* b);
62
-
63
     unsigned long sizeModels();
63
     unsigned long sizeModels();
64
     StaticModel& getModel(unsigned long index);
64
     StaticModel& getModel(unsigned long index);
65
     void addModel(StaticModel* s);
65
     void addModel(StaticModel* s);
87
     std::vector<Sprite*> sprites;
87
     std::vector<Sprite*> sprites;
88
     std::vector<StaticModel*> models;
88
     std::vector<StaticModel*> models;
89
     std::vector<Portal*> portals;
89
     std::vector<Portal*> portals;
90
-    std::vector<Box*> boxes;
91
     std::vector<Sector*> sectors;
90
     std::vector<Sector*> sectors;
92
     std::vector<Light*> lights;
91
     std::vector<Light*> lights;
93
 
92
 

+ 1
- 8
include/RoomData.h View File

87
     int adjoiningRoom;
87
     int adjoiningRoom;
88
 };
88
 };
89
 
89
 
90
-class Box {
91
-  public:
92
-    Box(TombRaider& tr, unsigned int room, unsigned int index);
93
-
94
-  private:
95
-    float a[3], b[3], c[3], d[3];
96
-};
97
-
98
 class Sector {
90
 class Sector {
99
   public:
91
   public:
92
+    Sector(float f, float c, bool w) : floor(f), ceiling(c), wall(w) { }
100
     Sector(TombRaider& tr, unsigned int room, unsigned int index);
93
     Sector(TombRaider& tr, unsigned int room, unsigned int index);
101
     float getFloor();
94
     float getFloor();
102
     float getCeiling();
95
     float getCeiling();

+ 3
- 0
src/Game.cpp View File

20
 #include "StaticMesh.h"
20
 #include "StaticMesh.h"
21
 #include "system/Sound.h"
21
 #include "system/Sound.h"
22
 #include "TextureManager.h"
22
 #include "TextureManager.h"
23
+#include "UI.h"
23
 #include "World.h"
24
 #include "World.h"
24
 #include "utils/strings.h"
25
 #include "utils/strings.h"
25
 
26
 
89
                 mLoaded = true;
90
                 mLoaded = true;
90
                 //getRender().setMode(Render::modeVertexLight);
91
                 //getRender().setMode(Render::modeVertexLight);
91
             }
92
             }
93
+
94
+            UI::setVisible(true);
92
         }
95
         }
93
     }
96
     }
94
 
97
 

+ 32
- 31
src/Room.cpp View File

19
 extern std::map<int, int> gMapTex2Bump;
19
 extern std::map<int, int> gMapTex2Bump;
20
 #endif
20
 #endif
21
 
21
 
22
-Room::Room(TombRaider& tr, unsigned int index) {
23
-    float box[2][3];
24
-    Matrix transform;
22
+Room::Room(float p[3], unsigned int f, unsigned int x, unsigned int z)
23
+    : flags(f), numXSectors(x), numZSectors(z) {
24
+    if (p == nullptr) {
25
+        pos[0] = 0.0f;
26
+        pos[1] = 0.0f;
27
+        pos[2] = 0.0f;
28
+    } else {
29
+        pos[0] = p[0];
30
+        pos[1] = p[0];
31
+        pos[2] = p[0];
32
+    }
33
+}
34
+
35
+void Room::setNumXSectors(unsigned int n) {
36
+    numXSectors = n;
37
+}
25
 
38
 
39
+void Room::setNumZSectors(unsigned int n) {
40
+    numZSectors = n;
41
+}
42
+
43
+void Room::setPos(float p[3]) {
44
+    for (int i = 0; i < 3; i++)
45
+        pos[i] = p[i];
46
+}
47
+
48
+Room::Room(TombRaider& tr, unsigned int index) {
26
     if (!tr.isRoomValid(index)) {
49
     if (!tr.isRoomValid(index)) {
27
         getLog() << "WARNING: Handling invalid vertex array in room" << Log::endl;
50
         getLog() << "WARNING: Handling invalid vertex array in room" << Log::endl;
28
         return;
51
         return;
30
 
53
 
31
     flags = 0;
54
     flags = 0;
32
     unsigned int trFlags = 0;
55
     unsigned int trFlags = 0;
56
+    float box[2][3];
33
     tr.getRoomInfo(index, &trFlags, pos, box[0], box[1]);
57
     tr.getRoomInfo(index, &trFlags, pos, box[0], box[1]);
34
 
58
 
35
     if (trFlags & tombraiderRoom_underWater)
59
     if (trFlags & tombraiderRoom_underWater)
44
     bbox.setBoundingBox(box[0], box[1]);
68
     bbox.setBoundingBox(box[0], box[1]);
45
 
69
 
46
     // Mongoose 2002.04.03, Setup 3D transform
70
     // Mongoose 2002.04.03, Setup 3D transform
71
+    Matrix transform;
47
     transform.setIdentity();
72
     transform.setIdentity();
48
     transform.translate(pos);
73
     transform.translate(pos);
49
 
74
 
57
         adjacentRooms.push_back(portals.back()->getAdjoiningRoom());
82
         adjacentRooms.push_back(portals.back()->getAdjoiningRoom());
58
     }
83
     }
59
 
84
 
60
-    //! \fixme Use more of sector structure, boxes, and floordata
61
-
62
     // List of sectors in this room
85
     // List of sectors in this room
63
     count = tr.getRoomSectorCount(index, &numZSectors, &numXSectors);
86
     count = tr.getRoomSectorCount(index, &numZSectors, &numXSectors);
64
     for (unsigned int i = 0; i < count; i++)
87
     for (unsigned int i = 0; i < count; i++)
65
         sectors.push_back(new Sector(tr, index, i));
88
         sectors.push_back(new Sector(tr, index, i));
66
 
89
 
67
-    // Setup collision boxes
68
-    //! fixme Should use sectors, but this is a test
69
-    count = tr.getRoomBoxCount(index);
70
-    for (unsigned int i = 0; i < count; i++)
71
-        boxes.push_back(new Box(tr, index, i));
72
-
73
     // Setup room lights
90
     // Setup room lights
74
     count = tr.getRoomLightCount(index);
91
     count = tr.getRoomLightCount(index);
75
     for (unsigned int i = 0; i < count; i++)
92
     for (unsigned int i = 0; i < count; i++)
391
 #endif
408
 #endif
392
 }
409
 }
393
 
410
 
394
-Room::Room() : flags(0), numXSectors(0), numZSectors(0) {
395
-    pos[0] = 0;
396
-    pos[1] = 0;
397
-    pos[2] = 0;
398
-}
399
-
400
 #define EMPTY_VECTOR(x)     \
411
 #define EMPTY_VECTOR(x)     \
401
 while (!x.empty()) {        \
412
 while (!x.empty()) {        \
402
     delete x[x.size() - 1]; \
413
     delete x[x.size() - 1]; \
407
     EMPTY_VECTOR(sprites);
418
     EMPTY_VECTOR(sprites);
408
     EMPTY_VECTOR(models);
419
     EMPTY_VECTOR(models);
409
     EMPTY_VECTOR(portals);
420
     EMPTY_VECTOR(portals);
410
-    EMPTY_VECTOR(boxes);
411
     EMPTY_VECTOR(sectors);
421
     EMPTY_VECTOR(sectors);
412
     EMPTY_VECTOR(lights);
422
     EMPTY_VECTOR(lights);
413
 }
423
 }
533
     return -1;
543
     return -1;
534
 }
544
 }
535
 
545
 
546
+void Room::setFlags(unsigned int f) {
547
+    flags = f;
548
+}
549
+
536
 unsigned int Room::getFlags() {
550
 unsigned int Room::getFlags() {
537
     return flags;
551
     return flags;
538
 }
552
 }
589
     sectors.push_back(s);
603
     sectors.push_back(s);
590
 }
604
 }
591
 
605
 
592
-unsigned long Room::sizeBox() {
593
-    return boxes.size();
594
-}
595
-
596
-Box& Room::getBox(unsigned long index) {
597
-    assert(index < boxes.size());
598
-    return *boxes.at(index);
599
-}
600
-
601
-void Room::addBox(Box* b) {
602
-    boxes.push_back(b);
603
-}
604
-
605
 unsigned long Room::sizeModels() {
606
 unsigned long Room::sizeModels() {
606
     return models.size();
607
     return models.size();
607
 }
608
 }

+ 10
- 6
src/RoomData.cpp View File

219
 }
219
 }
220
 
220
 
221
 Portal::Portal(float vert[4][3], float norm[3], int adj) {
221
 Portal::Portal(float vert[4][3], float norm[3], int adj) {
222
+    for (unsigned int i = 0; i < 4; i++) {
223
+        for (unsigned int j = 0; j < 3; j++) {
224
+            vertices[i][j] = vert[i][j];
225
+        }
226
+
227
+        if (i < 3) {
228
+            normal[i] = norm[i];
229
+        }
230
+    }
222
 
231
 
232
+    adjoiningRoom = adj;
223
 }
233
 }
224
 
234
 
225
 void Portal::getVertices(float vert[4][3]) {
235
 void Portal::getVertices(float vert[4][3]) {
236
 
246
 
237
 // ----------------------------------------------------------------------------
247
 // ----------------------------------------------------------------------------
238
 
248
 
239
-Box::Box(TombRaider& tr, unsigned int room, unsigned int index) {
240
-    tr.getRoomBox(room, index, a, b, c, d);
241
-}
242
-
243
-// ----------------------------------------------------------------------------
244
-
245
 Sector::Sector(TombRaider& tr, unsigned int room, unsigned int index) {
249
 Sector::Sector(TombRaider& tr, unsigned int room, unsigned int index) {
246
     unsigned int sectorFlags;
250
     unsigned int sectorFlags;
247
     int floorDataIndex, boxIndex, roomBelow, roomAbove;
251
     int floorDataIndex, boxIndex, roomBelow, roomAbove;

+ 4
- 2
src/SkeletalModel.cpp View File

59
 }
59
 }
60
 
60
 
61
 void BoneTag::display() {
61
 void BoneTag::display() {
62
-    getWorld().getStaticMesh(mesh).display();
63
-    //getWorld().getMesh(mesh).drawSolid(); // TODO ?
62
+    if (getWorld().sizeMesh() > 0)
63
+        getWorld().getMesh(mesh).drawSolid(); // TODO ?
64
+    else
65
+        getWorld().getStaticMesh(mesh).display();
64
 }
66
 }
65
 
67
 
66
 void BoneTag::getOffset(float o[3]) {
68
 void BoneTag::getOffset(float o[3]) {

+ 4
- 2
src/StaticMesh.cpp View File

94
 
94
 
95
 // ----------------------------------------------------------------------------
95
 // ----------------------------------------------------------------------------
96
 
96
 
97
-StaticMesh::StaticMesh(int i, int m) : id(i), mesh(m) { }
97
+StaticMesh::StaticMesh(int i, int m) : id(i), mesh(m) {
98
+    vertices = colors = normals = nullptr;
99
+}
98
 
100
 
99
 #ifdef EXPERIMENTAL
101
 #ifdef EXPERIMENTAL
100
 
102
 
263
 }
265
 }
264
 
266
 
265
 float StaticMesh::getRadius() {
267
 float StaticMesh::getRadius() {
266
-    assert((id != -1) && (mesh != -1));
268
+    assert((id == -1) && (mesh == -1));
267
     return radius;
269
     return radius;
268
 }
270
 }
269
 
271
 

+ 155
- 24
src/loader/LoaderTR2.cpp View File

17
 #include "SoundManager.h"
17
 #include "SoundManager.h"
18
 #include "TextureManager.h"
18
 #include "TextureManager.h"
19
 #include "World.h"
19
 #include "World.h"
20
+#include "math/Matrix.h"
20
 #include "math/Vec3.h"
21
 #include "math/Vec3.h"
21
 #include "system/Sound.h"
22
 #include "system/Sound.h"
22
 #include "utils/pixel.h"
23
 #include "utils/pixel.h"
172
 
173
 
173
     if ((numAnimatedTextures > 0) || (numWords > 0))
174
     if ((numAnimatedTextures > 0) || (numWords > 0))
174
         getLog() << "LoaderTR2: Found " << numAnimatedTextures << " Animated Textures!" << Log::endl;
175
         getLog() << "LoaderTR2: Found " << numAnimatedTextures << " Animated Textures!" << Log::endl;
176
+    else
177
+        getLog() << "LoaderTR2: No Animated Textures in this level?!" << Log::endl;
175
 
178
 
176
     if (pos != numWords)
179
     if (pos != numWords)
177
         getLog() << "LoaderTR2: Extra bytes at end of AnimatedTextures?!" << Log::endl;
180
         getLog() << "LoaderTR2: Extra bytes at end of AnimatedTextures?!" << Log::endl;
181
 
184
 
182
 void LoaderTR2::loadRooms() {
185
 void LoaderTR2::loadRooms() {
183
     uint16_t numRooms = file.readU16();
186
     uint16_t numRooms = file.readU16();
184
-
185
     for (unsigned int i = 0; i < numRooms; i++) {
187
     for (unsigned int i = 0; i < numRooms; i++) {
186
         // Room Header
188
         // Room Header
187
         int32_t xOffset = file.read32();
189
         int32_t xOffset = file.read32();
194
 
196
 
195
         uint16_t numVertices = file.readU16();
197
         uint16_t numVertices = file.readU16();
196
         std::vector<Vec3> vertices;
198
         std::vector<Vec3> vertices;
199
+        float bbox[2][3] = {
200
+            { 0.0f, 0.0f, 0.0f },
201
+            { 0.0f, 0.0f, 0.0f }
202
+        };
197
         for (unsigned int v = 0; v < numVertices; v++) {
203
         for (unsigned int v = 0; v < numVertices; v++) {
198
             // Vertex coordinates, relative to x/zOffset
204
             // Vertex coordinates, relative to x/zOffset
199
             int16_t x = file.read16();
205
             int16_t x = file.read16();
212
             int16_t light2 = file.read16(); // Almost always equal to light1
218
             int16_t light2 = file.read16(); // Almost always equal to light1
213
 
219
 
214
             vertices.emplace_back(x, y, z);
220
             vertices.emplace_back(x, y, z);
221
+
222
+            if (v == 0) {
223
+                for (int i = 0; i < 2; i++) {
224
+                    bbox[i][0] = x;
225
+                    bbox[i][1] = y;
226
+                    bbox[i][2] = z;
227
+                }
228
+            } else {
229
+                if (x < bbox[0][0])
230
+                    bbox[0][0] = x;
231
+                if (x > bbox[1][0])
232
+                    bbox[1][0] = x;
233
+
234
+                if (y < bbox[0][1])
235
+                    bbox[0][1] = y;
236
+                if (y > bbox[1][1])
237
+                    bbox[1][1] = y;
238
+
239
+                if (z < bbox[0][2])
240
+                    bbox[0][2] = z;
241
+                if (z > bbox[1][2])
242
+                    bbox[1][2] = z;
243
+            }
215
         }
244
         }
216
 
245
 
217
-        Room* room = new Room();
246
+        float pos[3] {
247
+            static_cast<float>(xOffset),
248
+            0.0f,
249
+            static_cast<float>(zOffset)
250
+        };
251
+        Room* room = new Room(pos);
252
+
253
+        bbox[0][0] += pos[0];
254
+        bbox[1][0] += pos[0];
255
+        bbox[0][2] += pos[2];
256
+        bbox[1][2] += pos[2];
257
+        room->getBoundingBox().setBoundingBox(bbox[0], bbox[1]);
218
 
258
 
219
         uint16_t numRectangles = file.readU16();
259
         uint16_t numRectangles = file.readU16();
220
         for (unsigned int r = 0; r < numRectangles; r++) {
260
         for (unsigned int r = 0; r < numRectangles; r++) {
254
             // TODO store sprites somewhere
294
             // TODO store sprites somewhere
255
         }
295
         }
256
 
296
 
297
+        Matrix transform;
298
+        transform.setIdentity();
299
+        transform.translate(pos);
300
+        room->addAdjacentRoom(i); // Always set room itself as first
301
+
257
         uint16_t numPortals = file.readU16();
302
         uint16_t numPortals = file.readU16();
258
         for (unsigned int p = 0; p < numPortals; p++) {
303
         for (unsigned int p = 0; p < numPortals; p++) {
259
             // Which room this portal leads to
304
             // Which room this portal leads to
281
             int16_t yCorner4 = file.read16();
326
             int16_t yCorner4 = file.read16();
282
             int16_t zCorner4 = file.read16();
327
             int16_t zCorner4 = file.read16();
283
 
328
 
284
-            // TODO store portals somewhere
329
+            float vertices[4][3] = {
330
+                {
331
+                    static_cast<float>(xCorner1),
332
+                    static_cast<float>(yCorner1),
333
+                    static_cast<float>(zCorner1)
334
+                }, {
335
+                    static_cast<float>(xCorner2),
336
+                    static_cast<float>(yCorner2),
337
+                    static_cast<float>(zCorner2)
338
+                }, {
339
+                    static_cast<float>(xCorner3),
340
+                    static_cast<float>(yCorner3),
341
+                    static_cast<float>(zCorner3)
342
+                }, {
343
+                    static_cast<float>(xCorner4),
344
+                    static_cast<float>(yCorner4),
345
+                    static_cast<float>(zCorner4)
346
+                }
347
+            };
348
+
349
+            // Portals have relative coordinates
350
+            transform.multiply3v(vertices[0], vertices[0]);
351
+            transform.multiply3v(vertices[1], vertices[1]);
352
+            transform.multiply3v(vertices[2], vertices[2]);
353
+            transform.multiply3v(vertices[3], vertices[3]);
354
+
355
+            float normals[3] = {
356
+                static_cast<float>(xNormal),
357
+                static_cast<float>(yNormal),
358
+                static_cast<float>(zNormal)
359
+            };
360
+
361
+            room->addPortal(new Portal(vertices, normals, adjoiningRoom));
362
+            room->addAdjacentRoom(adjoiningRoom);
285
         }
363
         }
286
 
364
 
287
         uint16_t numZSectors = file.readU16();
365
         uint16_t numZSectors = file.readU16();
288
         uint16_t numXSectors = file.readU16();
366
         uint16_t numXSectors = file.readU16();
367
+        room->setNumXSectors(numXSectors);
368
+        room->setNumZSectors(numZSectors);
289
         for (unsigned int s = 0; s < (numZSectors * numXSectors); s++) {
369
         for (unsigned int s = 0; s < (numZSectors * numXSectors); s++) {
290
             // Sectors are 1024*1024 world coordinates. Floor and Ceiling are
370
             // Sectors are 1024*1024 world coordinates. Floor and Ceiling are
291
             // signed numbers of 256 units of height.
371
             // signed numbers of 256 units of height.
303
             uint8_t roomAbove = file.readU8(); // 0xFF if none
383
             uint8_t roomAbove = file.readU8(); // 0xFF if none
304
             int8_t ceiling = file.read8(); // Absolute height of ceiling (/ 256)
384
             int8_t ceiling = file.read8(); // Absolute height of ceiling (/ 256)
305
 
385
 
306
-            // TODO store sectors somewhere
386
+            bool wall = false;
387
+            if ((((uint8_t)floor) == 0x81) || (((uint8_t)ceiling) == 0x81)) {
388
+                wall = true;
389
+            }
390
+
391
+            room->addSector(new Sector(floor * 256.0f, ceiling * 256.0f, wall));
307
         }
392
         }
308
 
393
 
309
         int16_t intensity1 = file.read16();
394
         int16_t intensity1 = file.read16();
347
             // TODO store static meshes somewhere
432
             // TODO store static meshes somewhere
348
         }
433
         }
349
 
434
 
350
-        int16_t alternateRoom = file.read16();
435
+        int16_t alternateRoom = file.read16(); // TODO
351
 
436
 
352
         uint16_t flags = file.readU16();
437
         uint16_t flags = file.readU16();
438
+        int roomFlags = 0;
439
+        if (flags & 0x0001) {
440
+            roomFlags |= RoomFlagUnderWater;
441
+        }
442
+        room->setFlags(room->getFlags() | roomFlags);
353
 
443
 
354
         getWorld().addRoom(room);
444
         getWorld().addRoom(room);
445
+
446
+        if ((numPortals == 0) || (numVertices == 0)
447
+            || ((numRectangles == 0) && (numTriangles == 0)))
448
+            getLog() << "LoaderTR2: Room " << i << " seems invalid: " << numPortals << "p "
449
+                     << numRectangles << "r " << numTriangles << "t " << numVertices
450
+                     << "v" << Log::endl;
355
     }
451
     }
356
 
452
 
357
     if (numRooms > 0)
453
     if (numRooms > 0)
370
 
466
 
371
     if (numFloorData > 0)
467
     if (numFloorData > 0)
372
         getLog() << "LoaderTR2: Found " << numFloorData << " words FloorData, unimplemented!" << Log::endl;
468
         getLog() << "LoaderTR2: Found " << numFloorData << " words FloorData, unimplemented!" << Log::endl;
469
+    else
470
+        getLog() << "LoaderTR2: No FloorData in this level?!" << Log::endl;
373
 }
471
 }
374
 
472
 
375
 void LoaderTR2::loadSprites() {
473
 void LoaderTR2::loadSprites() {
430
 
528
 
431
     uint32_t numMeshPointers = file.readU32();
529
     uint32_t numMeshPointers = file.readU32();
432
 
530
 
433
-    if ((numMeshData == 0) || (numMeshPointers == 0)) {
434
-        getLog() << "LoaderTR2: No mesh data found!" << Log::endl;
435
-        return;
436
-    }
437
-
438
     for (unsigned int i = 0; i < numMeshPointers; i++) {
531
     for (unsigned int i = 0; i < numMeshPointers; i++) {
439
         uint32_t meshPointer = file.readU32();
532
         uint32_t meshPointer = file.readU32();
440
 
533
 
534
+        if (numMeshData < (meshPointer / 2)) {
535
+            getLog() << "LoaderTR2: Invalid Mesh: "
536
+                     << (meshPointer / 2) << " > " << numMeshData << Log::endl;
537
+            continue;
538
+        }
539
+
441
         char* tmpPtr = reinterpret_cast<char*>(&buffer[meshPointer / 2]);
540
         char* tmpPtr = reinterpret_cast<char*>(&buffer[meshPointer / 2]);
442
         BinaryMemory mem(tmpPtr, (numMeshData * 2) - meshPointer);
541
         BinaryMemory mem(tmpPtr, (numMeshData * 2) - meshPointer);
443
 
542
 
536
     }
635
     }
537
 
636
 
538
     if (numMeshPointers > 0)
637
     if (numMeshPointers > 0)
539
-        getLog() << "LoaderTR2: Found " << numMeshPointers << " Meshes, unimplemented!" << Log::endl;
638
+        getLog() << "LoaderTR2: Found " << numMeshPointers << " Meshes!" << Log::endl;
639
+    else
640
+        getLog() << "LoaderTR2: No Meshes in this level?!" << Log::endl;
540
 }
641
 }
541
 
642
 
542
 void LoaderTR2::loadStaticMeshes() {
643
 void LoaderTR2::loadStaticMeshes() {
571
     }
672
     }
572
 
673
 
573
     if (numStaticMeshes > 0)
674
     if (numStaticMeshes > 0)
574
-        getLog() << "LoaderTR2: Found " << numStaticMeshes << " StaticMeshes, unimplemented!" << Log::endl;
675
+        getLog() << "LoaderTR2: Found " << numStaticMeshes << " StaticMeshes!" << Log::endl;
575
     else
676
     else
576
         getLog() << "LoaderTR2: No StaticMeshes in this level?!" << Log::endl;
677
         getLog() << "LoaderTR2: No StaticMeshes in this level?!" << Log::endl;
577
 }
678
 }
834
         int32_t y = file.read32();
935
         int32_t y = file.read32();
835
         int32_t z = file.read32();
936
         int32_t z = file.read32();
836
 
937
 
837
-        int16_t angle = file.read16(); // (0xC000 >> 14) * 90deg
938
+        uint16_t angle = file.readU16(); // (0xC000 >> 14) * 90deg
838
         int16_t intensity1 = file.read16(); // Constant lighting; -1 means mesh lighting
939
         int16_t intensity1 = file.read16(); // Constant lighting; -1 means mesh lighting
839
         int16_t intensity2 = file.read16(); // Almost always like intensity1
940
         int16_t intensity2 = file.read16(); // Almost always like intensity1
840
 
941
 
868
     }
969
     }
869
 
970
 
870
     if (numItems > 0)
971
     if (numItems > 0)
871
-        getLog() << "LoaderTR2: Found " << numItems << " Items, unimplemented!" << Log::endl;
972
+        getLog() << "LoaderTR2: Found " << numItems << " Items!" << Log::endl;
872
     else
973
     else
873
         getLog() << "LoaderTR2: No Items in this level?!" << Log::endl;
974
         getLog() << "LoaderTR2: No Items in this level?!" << Log::endl;
874
 }
975
 }
886
 
987
 
887
         // Index into overlaps[]. The high bit is sometimes set
988
         // Index into overlaps[]. The high bit is sometimes set
888
         // this occurs in front of swinging doors and the like
989
         // this occurs in front of swinging doors and the like
889
-        int16_t overlapIndex = file.read16();
990
+        uint16_t overlapIndex = file.readU16();
890
 
991
 
891
         // TODO store boxes somewhere
992
         // TODO store boxes somewhere
892
     }
993
     }
893
 
994
 
894
     uint32_t numOverlaps = file.readU32();
995
     uint32_t numOverlaps = file.readU32();
895
-    std::vector<uint16_t> overlaps;
996
+    std::vector<std::vector<uint16_t>> overlaps;
997
+    overlaps.emplace_back();
998
+    unsigned int list = 0;
896
     for (unsigned int o = 0; o < numOverlaps; o++) {
999
     for (unsigned int o = 0; o < numOverlaps; o++) {
897
-        overlaps.push_back(file.readU16());
1000
+        // Apparently used by NPCs to decide where to go next.
1001
+        // List of neighboring boxes for each box.
1002
+        // Each entry is a uint16, 0x8000 set marks end of list.
1003
+        uint16_t e = file.readU16();
1004
+        overlaps.at(list).push_back(e);
1005
+        if (e & 0x8000) {
1006
+            overlaps.emplace_back();
1007
+            list++;
1008
+        }
898
     }
1009
     }
899
 
1010
 
900
     // TODO store overlaps somewhere
1011
     // TODO store overlaps somewhere
901
 
1012
 
902
-    std::vector<int16_t> zones;
903
     for (unsigned int z = 0; z < numBoxes; z++) {
1013
     for (unsigned int z = 0; z < numBoxes; z++) {
904
-        for (unsigned int i = 0; i < 10; i++) {
905
-            zones.push_back(file.read16());
906
-        }
1014
+        // Normal room state
1015
+        int16_t ground1 = file.read16();
1016
+        int16_t ground2 = file.read16();
1017
+        int16_t ground3 = file.read16();
1018
+        int16_t ground4 = file.read16();
1019
+        int16_t fly = file.read16();
1020
+
1021
+        // Alternate room state
1022
+        int16_t ground1alt = file.read16();
1023
+        int16_t ground2alt = file.read16();
1024
+        int16_t ground3alt = file.read16();
1025
+        int16_t ground4alt = file.read16();
1026
+        int16_t flyAlt = file.read16();
1027
+
1028
+        // TODO store zones somewhere
907
     }
1029
     }
908
 
1030
 
909
-    // TODO store zones somewhere
910
-
911
     if ((numBoxes > 0) || (numOverlaps > 0))
1031
     if ((numBoxes > 0) || (numOverlaps > 0))
912
-        getLog() << "LoaderTR2: Found NPC NavigationHints, unimplemented!" << Log::endl;
1032
+        getLog() << "LoaderTR2: Found NPC NavigationHints (" << numBoxes
1033
+                 << ", " << numOverlaps << ", " << list << "), unimplemented!" << Log::endl;
1034
+    else
1035
+        getLog() << "LoaderTR2: No NPC NavigationHints in this level?!" << Log::endl;
913
 }
1036
 }
914
 
1037
 
915
 // ---- Sound ----
1038
 // ---- Sound ----
933
 
1056
 
934
     if (numSoundSources > 0)
1057
     if (numSoundSources > 0)
935
         getLog() << "LoaderTR2: Found " << numSoundSources << " SoundSources" << Log::endl;
1058
         getLog() << "LoaderTR2: Found " << numSoundSources << " SoundSources" << Log::endl;
1059
+    else
1060
+        getLog() << "LoaderTR2: No SoundSources in this level?!" << Log::endl;
936
 }
1061
 }
937
 
1062
 
938
 void LoaderTR2::loadSoundMap() {
1063
 void LoaderTR2::loadSoundMap() {
960
 
1085
 
961
     if (numSoundDetails > 0)
1086
     if (numSoundDetails > 0)
962
         getLog() << "LoaderTR2: Found " << numSoundDetails << " SoundDetails" << Log::endl;
1087
         getLog() << "LoaderTR2: Found " << numSoundDetails << " SoundDetails" << Log::endl;
1088
+    else
1089
+        getLog() << "LoaderTR2: No SoundDetails in this level?!" << Log::endl;
963
 }
1090
 }
964
 
1091
 
965
 void LoaderTR2::loadSampleIndices() {
1092
 void LoaderTR2::loadSampleIndices() {
970
 
1097
 
971
     if (numSampleIndices > 0)
1098
     if (numSampleIndices > 0)
972
         getLog() << "LoaderTR2: Found " << numSampleIndices << " SampleIndices" << Log::endl;
1099
         getLog() << "LoaderTR2: Found " << numSampleIndices << " SampleIndices" << Log::endl;
1100
+    else
1101
+        getLog() << "LoaderTR2: No SampleIndices in this level?!" << Log::endl;
973
 }
1102
 }
974
 
1103
 
975
 void LoaderTR2::loadExternalSoundFile(std::string f) {
1104
 void LoaderTR2::loadExternalSoundFile(std::string f) {
1016
 
1145
 
1017
     if (riffCount > 0)
1146
     if (riffCount > 0)
1018
         getLog() << "LoaderTR2: Found " << riffCount << " SoundSamples in SFX" << Log::endl;
1147
         getLog() << "LoaderTR2: Found " << riffCount << " SoundSamples in SFX" << Log::endl;
1148
+    else
1149
+        getLog() << "LoaderTR2: No SoundSamples in SFX?!" << Log::endl;
1019
 }
1150
 }
1020
 
1151
 
1021
 // ---- Stuff ----
1152
 // ---- Stuff ----

Loading…
Cancel
Save