OpenRaider  0.1.4-dev
Open Source Tomb Raider Game Engine implementation
LoaderTR3.cpp
Go to the documentation of this file.
1 
8 #include "global.h"
9 #include "loader/LoaderTR3.h"
10 
11 int LoaderTR3::load(std::string f) {
12  if (file.open(f) != 0) {
13  return 1; // Could not open file
14  }
15 
16  uint32_t version = file.readU32();
17  if ((version != 0xFF080038) && (version != 0xFF180038)) {
18  return 2; // Not a TR3 level?!
19  }
20 
21  loadPalette();
22  loadTextures();
23 
24  file.seek(file.tell() + 4); // Unused value?
25 
26  loadRooms();
27  loadFloorData();
28  loadMeshes();
29  loadMoveables();
31  loadSprites();
32  loadCameras();
36  loadTextiles();
37  loadItems();
38 
39  file.seek(file.tell() + 8192); // Skip Light map, only for 8bit coloring
40 
42  loadDemoData();
43  loadSoundMap();
46 
48 
49  // TODO load TR3 PC version CDAUDIO.WAD file
50  // TODO load TR3 Mac version CDAudio.db and WAV files
51 
52  return 0;
53 }
54 
56  int16_t intensity1 = file.read16();
57  int16_t intensity2 = file.read16();
58 
59  uint16_t numLights = file.readU16();
60  for (unsigned int l = 0; l < numLights; l++) {
61  // Position of light, in world coordinates
62  int32_t x = file.read32();
63  int32_t y = file.read32();
64  int32_t z = file.read32();
65 
66  uint16_t intensity1 = file.readU16();
67  uint16_t intensity2 = file.readU16(); // Almost always equal to intensity1
68 
69  uint32_t fade1 = file.readU32(); // Falloff value?
70  uint32_t fade2 = file.readU32(); // Falloff value?
71 
72  // TODO store light somewhere
73  }
74 }
75 
76 void LoaderTR3::loadRoomDataEnd(int16_t& alternateRoom, unsigned int& roomFlags) {
77  LoaderTR2::loadRoomDataEnd(alternateRoom, roomFlags);
78 
79  uint8_t r = file.readU8();
80  uint8_t g = file.readU8();
81  uint8_t b = file.readU8();
82 
83  // TODO store room-light color (?) somewhere
84 }
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 
virtual void loadPalette()
Definition: LoaderTR2.cpp:66
virtual void loadAnimatedTextures()
Definition: LoaderTR2.cpp:155
BinaryFile file
Definition: Loader.h:34
virtual uint8_t readU8()
Definition: binary.cpp:14
virtual void loadSoundSources()
Definition: LoaderTR2.cpp:1084
virtual void loadSoundMap()
Definition: LoaderTR2.cpp:1107
virtual long long tell()
Definition: binary.cpp:123
TR3 level file loader.
virtual void loadRoomMesh(std::vector< IndexedRectangle > &rectangles, std::vector< IndexedRectangle > &triangles, uint16_t &numRectangles, uint16_t &numTriangles)
Definition: LoaderTR3.cpp:86
Included everywhere.
virtual void loadCinematicFrames()
Definition: LoaderTR2.cpp:1226
virtual void seek(long long pos=0)
Definition: binary.cpp:128
virtual int load(std::string f)
Definition: LoaderTR3.cpp:11
virtual void loadSampleIndices()
Definition: LoaderTR2.cpp:1136
virtual void loadTextiles()
Definition: LoaderTR2.cpp:108
virtual void loadRoomDataEnd(int16_t &alternateRoom, unsigned int &roomFlags)
Definition: LoaderTR3.cpp:76
virtual void loadMeshes()
Definition: LoaderTR2.cpp:527
virtual int16_t read16()
Definition: binary.cpp:77
virtual void loadItems()
Definition: LoaderTR2.cpp:976
virtual void loadStaticMeshes()
Definition: LoaderTR2.cpp:648
virtual void loadSprites()
Definition: LoaderTR2.cpp:480
virtual void loadCameras()
Definition: LoaderTR2.cpp:1209
virtual uint16_t readU16()
Definition: binary.cpp:21
virtual void loadRoomDataEnd(int16_t &alternateRoom, unsigned int &roomFlags)
Definition: LoaderTR2.cpp:239
virtual void loadTextures()
Definition: LoaderTR2.cpp:81
virtual void loadMoveables()
Definition: LoaderTR2.cpp:785
virtual void loadSoundDetails()
Definition: LoaderTR2.cpp:1113
virtual void loadRooms()
Definition: LoaderTR2.cpp:289
virtual uint32_t readU32()
Definition: binary.cpp:27
virtual void loadDemoData()
Definition: LoaderTR2.cpp:1246
virtual int32_t read32()
Definition: binary.cpp:85
virtual void loadRoomLights()
Definition: LoaderTR3.cpp:55
virtual void loadBoxesOverlapsZones()
Definition: LoaderTR2.cpp:1021
virtual void loadFloorData()
Definition: LoaderTR2.cpp:465
virtual void loadExternalSoundFile(std::string f)
Definition: LoaderTR2.cpp:1148
int open(std::string f="")
Definition: binary.cpp:112