Browse Source

Fixed TR3 level loader

Thomas Buck 9 years ago
parent
commit
4cb2078e24

+ 1
- 0
ChangeLog.md View File

8
     * Removed color definitions in global.h
8
     * Removed color definitions in global.h
9
     * Font interface now using glm::vec4 float colors
9
     * Font interface now using glm::vec4 float colors
10
     * Hard-coded controller mapping now supports all available ActionEvents
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
     [ 20140305 ]
13
     [ 20140305 ]
13
     * SoundAL now has more useful error message output.
14
     * SoundAL now has more useful error message output.

+ 3
- 0
include/loader/LoaderTR2.h View File

26
     virtual void loadRoomStaticMeshes(std::vector<StaticModel*>& staticModels);
26
     virtual void loadRoomStaticMeshes(std::vector<StaticModel*>& staticModels);
27
     virtual void loadRoomDataEnd(int16_t& alternateRoom, unsigned int& roomFlags);
27
     virtual void loadRoomDataEnd(int16_t& alternateRoom, unsigned int& roomFlags);
28
     virtual void loadRoomVertex(RoomVertexTR2& vert);
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
     virtual void loadRooms();
32
     virtual void loadRooms();
30
     virtual void loadFloorData();
33
     virtual void loadFloorData();
31
     virtual void loadMeshes();
34
     virtual void loadMeshes();

+ 3
- 0
include/loader/LoaderTR3.h View File

17
   protected:
17
   protected:
18
     virtual void loadRoomLights();
18
     virtual void loadRoomLights();
19
     virtual void loadRoomDataEnd(int16_t& alternateRoom, unsigned int& roomFlags);
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
 #endif
25
 #endif

+ 33
- 26
src/loader/LoaderTR2.cpp View File

255
     vert.light2 = file.read16();
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
 void LoaderTR2::loadRooms() {
289
 void LoaderTR2::loadRooms() {
259
     uint16_t numRooms = file.readU16();
290
     uint16_t numRooms = file.readU16();
260
     for (unsigned int i = 0; i < numRooms; i++) {
291
     for (unsigned int i = 0; i < numRooms; i++) {
307
         bbox[0] += pos;
338
         bbox[0] += pos;
308
         bbox[1] += pos;
339
         bbox[1] += pos;
309
 
340
 
310
-        uint16_t numRectangles = file.readU16();
311
         std::vector<IndexedRectangle> rectangles;
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
         std::vector<IndexedRectangle> triangles;
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
         uint16_t numSprites = file.readU16();
346
         uint16_t numSprites = file.readU16();
340
         std::vector<RoomSprite*> roomSprites;
347
         std::vector<RoomSprite*> roomSprites;

+ 31
- 0
src/loader/LoaderTR3.cpp View File

83
     // TODO store room-light color (?) somewhere
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 View File

22
      */
22
      */
23
     unsigned 16 little texture;
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
 // Triangular faces
28
 // Triangular faces
53
     vertex_t vertex;
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
      * for necessarily external sources like flares.
57
      * for necessarily external sources like flares.
58
      * Room ambient lights and point sources are ignored.
58
      * Room ambient lights and point sources are ignored.
59
      */
59
      */

Loading…
Cancel
Save