Procházet zdrojové kódy

Fixed TR3 level loader

Thomas Buck před 9 roky
rodič
revize
4cb2078e24

+ 1
- 0
ChangeLog.md Zobrazit soubor

@@ -8,6 +8,7 @@
8 8
     * Removed color definitions in global.h
9 9
     * Font interface now using glm::vec4 float colors
10 10
     * Hard-coded controller mapping now supports all available ActionEvents
11
+    * Fixed TR3 level loading. Only some levels with invalid SoundSources still crash.
11 12
 
12 13
     [ 20140305 ]
13 14
     * SoundAL now has more useful error message output.

+ 3
- 0
include/loader/LoaderTR2.h Zobrazit soubor

@@ -26,6 +26,9 @@ class LoaderTR2 : public Loader {
26 26
     virtual void loadRoomStaticMeshes(std::vector<StaticModel*>& staticModels);
27 27
     virtual void loadRoomDataEnd(int16_t& alternateRoom, unsigned int& roomFlags);
28 28
     virtual void loadRoomVertex(RoomVertexTR2& vert);
29
+    virtual void loadRoomMesh(std::vector<IndexedRectangle>& rectangles,
30
+                              std::vector<IndexedRectangle>& triangles,
31
+                              uint16_t& numRectangles, uint16_t& numTriangles);
29 32
     virtual void loadRooms();
30 33
     virtual void loadFloorData();
31 34
     virtual void loadMeshes();

+ 3
- 0
include/loader/LoaderTR3.h Zobrazit soubor

@@ -17,6 +17,9 @@ class LoaderTR3 : public LoaderTR2 {
17 17
   protected:
18 18
     virtual void loadRoomLights();
19 19
     virtual void loadRoomDataEnd(int16_t& alternateRoom, unsigned int& roomFlags);
20
+    virtual void loadRoomMesh(std::vector<IndexedRectangle>& rectangles,
21
+                              std::vector<IndexedRectangle>& triangles,
22
+                              uint16_t& numRectangles, uint16_t& numTriangles);
20 23
 };
21 24
 
22 25
 #endif

+ 33
- 26
src/loader/LoaderTR2.cpp Zobrazit soubor

@@ -255,6 +255,37 @@ void LoaderTR2::loadRoomVertex(RoomVertexTR2& vert) {
255 255
     vert.light2 = file.read16();
256 256
 }
257 257
 
258
+void LoaderTR2::loadRoomMesh(std::vector<IndexedRectangle>& rectangles,
259
+                             std::vector<IndexedRectangle>& triangles,
260
+                             uint16_t& numRectangles, uint16_t& numTriangles) {
261
+    numRectangles = file.readU16();
262
+    for (unsigned int r = 0; r < numRectangles; r++) {
263
+        // Indices into the vertex list read just before
264
+        uint16_t vertex1 = file.readU16();
265
+        uint16_t vertex2 = file.readU16();
266
+        uint16_t vertex3 = file.readU16();
267
+        uint16_t vertex4 = file.readU16();
268
+
269
+        // Index into the object-texture list
270
+        uint16_t texture = file.readU16();
271
+
272
+        rectangles.emplace_back(texture, vertex1, vertex2, vertex3, vertex4);
273
+    }
274
+
275
+    numTriangles = file.readU16();
276
+    for (unsigned int t = 0; t < numTriangles; t++) {
277
+        // Indices into the room vertex list
278
+        uint16_t vertex1 = file.readU16();
279
+        uint16_t vertex2 = file.readU16();
280
+        uint16_t vertex3 = file.readU16();
281
+
282
+        // Index into the object-texture list
283
+        uint16_t texture = file.readU16();
284
+
285
+        triangles.emplace_back(texture, vertex1, vertex2, vertex3);
286
+    }
287
+}
288
+
258 289
 void LoaderTR2::loadRooms() {
259 290
     uint16_t numRooms = file.readU16();
260 291
     for (unsigned int i = 0; i < numRooms; i++) {
@@ -307,34 +338,10 @@ void LoaderTR2::loadRooms() {
307 338
         bbox[0] += pos;
308 339
         bbox[1] += pos;
309 340
 
310
-        uint16_t numRectangles = file.readU16();
311 341
         std::vector<IndexedRectangle> rectangles;
312
-        for (unsigned int r = 0; r < numRectangles; r++) {
313
-            // Indices into the vertex list read just before
314
-            uint16_t vertex1 = file.readU16();
315
-            uint16_t vertex2 = file.readU16();
316
-            uint16_t vertex3 = file.readU16();
317
-            uint16_t vertex4 = file.readU16();
318
-
319
-            // Index into the object-texture list
320
-            uint16_t texture = file.readU16();
321
-
322
-            rectangles.emplace_back(texture, vertex1, vertex2, vertex3, vertex4);
323
-        }
324
-
325
-        uint16_t numTriangles = file.readU16();
326 342
         std::vector<IndexedRectangle> triangles;
327
-        for (unsigned int t = 0; t < numTriangles; t++) {
328
-            // Indices into the room vertex list
329
-            uint16_t vertex1 = file.readU16();
330
-            uint16_t vertex2 = file.readU16();
331
-            uint16_t vertex3 = file.readU16();
332
-
333
-            // Index into the object-texture list
334
-            uint16_t texture = file.readU16();
335
-
336
-            triangles.emplace_back(texture, vertex1, vertex2, vertex3);
337
-        }
343
+        uint16_t numRectangles, numTriangles;
344
+        loadRoomMesh(rectangles, triangles, numRectangles, numTriangles);
338 345
 
339 346
         uint16_t numSprites = file.readU16();
340 347
         std::vector<RoomSprite*> roomSprites;

+ 31
- 0
src/loader/LoaderTR3.cpp Zobrazit soubor

@@ -83,3 +83,34 @@ void LoaderTR3::loadRoomDataEnd(int16_t& alternateRoom, unsigned int& roomFlags)
83 83
     // TODO store room-light color (?) somewhere
84 84
 }
85 85
 
86
+void LoaderTR3::loadRoomMesh(std::vector<IndexedRectangle>& rectangles,
87
+                             std::vector<IndexedRectangle>& triangles,
88
+                             uint16_t& numRectangles, uint16_t& numTriangles) {
89
+    numRectangles = file.readU16();
90
+    for (unsigned int r = 0; r < numRectangles; r++) {
91
+        // Indices into the vertex list read just before
92
+        uint16_t vertex1 = file.readU16();
93
+        uint16_t vertex2 = file.readU16();
94
+        uint16_t vertex3 = file.readU16();
95
+        uint16_t vertex4 = file.readU16();
96
+
97
+        // Index into the object-texture list
98
+        uint16_t texture = file.readU16() & 0x7FFF;
99
+
100
+        rectangles.emplace_back(texture, vertex1, vertex2, vertex3, vertex4);
101
+    }
102
+
103
+    numTriangles = file.readU16();
104
+    for (unsigned int t = 0; t < numTriangles; t++) {
105
+        // Indices into the room vertex list
106
+        uint16_t vertex1 = file.readU16();
107
+        uint16_t vertex2 = file.readU16();
108
+        uint16_t vertex3 = file.readU16();
109
+
110
+        // Index into the object-texture list
111
+        uint16_t texture = file.readU16() & 0x7FFF;
112
+
113
+        triangles.emplace_back(texture, vertex1, vertex2, vertex3);
114
+    }
115
+}
116
+

+ 2
- 2
utils/tombraider.bfft Zobrazit soubor

@@ -22,7 +22,7 @@ struct face4_t {
22 22
      */
23 23
     unsigned 16 little texture;
24 24
 
25
-    summary vertices[0], " - ", vertices[1], " - ", vertices[2], " - ", vertices[3];
25
+    summary texture, ": ", vertices[0], " - ", vertices[1], " - ", vertices[2], " - ", vertices[3];
26 26
 }
27 27
 
28 28
 // Triangular faces
@@ -53,7 +53,7 @@ struct room_vertex_t {
53 53
     vertex_t vertex;
54 54
 
55 55
     /*
56
-     * Room lighting is internal vertex lighting, except for except
56
+     * Room lighting is internal vertex lighting, except
57 57
      * for necessarily external sources like flares.
58 58
      * Room ambient lights and point sources are ignored.
59 59
      */

Loading…
Zrušit
Uložit