Browse Source

Fixed TR1 level loading (sound samples and colors)

Thomas Buck 9 years ago
parent
commit
7386eef8ae
6 changed files with 77 additions and 44 deletions
  1. 6
    0
      ChangeLog.md
  2. 1
    1
      include/loader/LoaderTR2.h
  3. 20
    19
      src/loader/LoaderTR1.cpp
  4. 14
    9
      src/loader/LoaderTR2.cpp
  5. 30
    9
      src/system/SoundAL.cpp
  6. 6
    6
      utils/tombraider.bfft

+ 6
- 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
+    [ 20140305 ]
6
+    * SoundAL now has more useful error message output.
7
+    * Fixed TR1 color map parsing, now textures have the proper color values.
8
+    * Fixed TR1 sound sample parsing. Can now load all TR1 levels without crashing.
9
+    * Improved parsing and summaries in binspector level reading script.
10
+
5
     [ 20140304 ]
11
     [ 20140304 ]
6
     * Added (more or less working) support for loading TR1 levels
12
     * Added (more or less working) support for loading TR1 levels
7
     * Updated imgui
13
     * Updated imgui

+ 1
- 1
include/loader/LoaderTR2.h View File

45
     virtual void loadSampleIndices();
45
     virtual void loadSampleIndices();
46
 
46
 
47
     virtual void loadExternalSoundFile(std::string f);
47
     virtual void loadExternalSoundFile(std::string f);
48
-    virtual void loadSoundFiles(BinaryReader& sfx);
48
+    virtual int loadSoundFiles(BinaryReader& sfx, unsigned int count = 0);
49
 
49
 
50
     virtual int getPaletteIndex(uint16_t index);
50
     virtual int getPaletteIndex(uint16_t index);
51
 };
51
 };

+ 20
- 19
src/loader/LoaderTR1.cpp View File

47
     loadSoundMap();
47
     loadSoundMap();
48
     loadSoundDetails();
48
     loadSoundDetails();
49
     loadSoundSamples();
49
     loadSoundSamples();
50
-    loadSampleIndices();
51
 
50
 
52
     return 0;
51
     return 0;
53
 }
52
 }
59
         uint8_t g = file.readU8();
58
         uint8_t g = file.readU8();
60
         uint8_t b = file.readU8();
59
         uint8_t b = file.readU8();
61
 
60
 
62
-        //! \fixme Hack to make everything brighter
63
-        static const uint8_t lightHackFactor = 3;
64
-        r *= lightHackFactor;
65
-        if (r > 255)
66
-            r = 255;
67
-        g *= lightHackFactor;
68
-        if (g > 255)
69
-            g = 255;
70
-        b *= lightHackFactor;
71
-        if (b > 255)
72
-            b = 255;
61
+        // Color values range from 0 to 63, so multiply by 4
62
+        static const uint8_t lightFactor = 4;
63
+        r *= lightFactor;
64
+        g *= lightFactor;
65
+        b *= lightFactor;
73
 
66
 
74
         glm::vec4 c(r / 255.0f, g / 255.0f, b / 255.0f, 1.0f);
67
         glm::vec4 c(r / 255.0f, g / 255.0f, b / 255.0f, 1.0f);
75
         TextureManager::setPalette(i, c);
68
         TextureManager::setPalette(i, c);
253
 
246
 
254
 void LoaderTR1::loadSoundSamples() {
247
 void LoaderTR1::loadSoundSamples() {
255
     uint32_t soundSampleSize = file.readU32();
248
     uint32_t soundSampleSize = file.readU32();
256
-    if (soundSampleSize <= 0) {
257
-        return;
258
-    }
259
-
260
     std::vector<uint8_t> buffer;
249
     std::vector<uint8_t> buffer;
261
     for (int i = 0; i < soundSampleSize; i++) {
250
     for (int i = 0; i < soundSampleSize; i++) {
262
         buffer.push_back(file.readU8());
251
         buffer.push_back(file.readU8());
263
     }
252
     }
264
 
253
 
265
-    char* tmpPtr = reinterpret_cast<char*>(&buffer[0]);
266
-    BinaryMemory sfx(tmpPtr, soundSampleSize);
267
-    loadSoundFiles(sfx);
254
+    uint32_t numSampleIndices = file.readU32();
255
+    for (unsigned int i = 0; i < numSampleIndices; i++) {
256
+        SoundManager::addSampleIndex(i);
257
+        uint32_t sampleOffset = file.readU32();
258
+        assertLessThan(sampleOffset, soundSampleSize);
259
+        char* tmpPtr = reinterpret_cast<char*>(&buffer[sampleOffset]);
260
+        BinaryMemory sample(tmpPtr, soundSampleSize - sampleOffset);
261
+        int ret = loadSoundFiles(sample, 1);
262
+        assertEqual(ret, 1);
263
+    }
264
+
265
+    if (numSampleIndices > 0)
266
+        Log::get(LOG_INFO) << "LoaderTR1: Found " << numSampleIndices << " SoundSamples" << Log::endl;
267
+    else
268
+        Log::get(LOG_INFO) << "LoaderTR1: No SoundSamples in this level?!" << Log::endl;
268
 }
269
 }
269
 
270
 
270
 int LoaderTR1::getPaletteIndex(uint16_t index) {
271
 int LoaderTR1::getPaletteIndex(uint16_t index) {

+ 14
- 9
src/loader/LoaderTR2.cpp View File

1113
         return;
1113
         return;
1114
     }
1114
     }
1115
 
1115
 
1116
-    loadSoundFiles(sfx);
1116
+    int riffCount = loadSoundFiles(sfx);
1117
+    if (riffCount > 0)
1118
+        Log::get(LOG_INFO) << "LoaderTR2: Loaded " << riffCount << " SoundSamples" << Log::endl;
1119
+    else if (riffCount == 0)
1120
+        Log::get(LOG_INFO) << "LoaderTR2: No SoundSamples found!" << Log::endl;
1121
+    else
1122
+        Log::get(LOG_ERROR) << "LoaderTR2: Error loading SoundSamples!" << Log::endl;
1117
 }
1123
 }
1118
 
1124
 
1119
-void LoaderTR2::loadSoundFiles(BinaryReader& sfx) {
1125
+int LoaderTR2::loadSoundFiles(BinaryReader& sfx, unsigned int count) {
1120
     int riffCount = 0;
1126
     int riffCount = 0;
1121
     while (!sfx.eof()) {
1127
     while (!sfx.eof()) {
1128
+        if ((count > 0) && (riffCount >= count))
1129
+            break;
1130
+
1122
         char test[5];
1131
         char test[5];
1123
         test[4] = '\0';
1132
         test[4] = '\0';
1124
         for (int i = 0; i < 4; i++)
1133
         for (int i = 0; i < 4; i++)
1125
             test[i] = sfx.read8();
1134
             test[i] = sfx.read8();
1126
 
1135
 
1127
         if (std::string("RIFF") != std::string(test)) {
1136
         if (std::string("RIFF") != std::string(test)) {
1128
-            Log::get(LOG_DEBUG) << "LoaderTR2: External SFX invalid! (" << riffCount
1137
+            Log::get(LOG_DEBUG) << "LoaderTR2: SoundSamples invalid! (" << riffCount
1129
                                 << ", \"" << test << "\" != \"RIFF\")" << Log::endl;
1138
                                 << ", \"" << test << "\" != \"RIFF\")" << Log::endl;
1130
-            return;
1139
+            return -1;
1131
         }
1140
         }
1132
 
1141
 
1133
         // riffSize is (fileLength - 8)
1142
         // riffSize is (fileLength - 8)
1144
 
1153
 
1145
         riffCount++;
1154
         riffCount++;
1146
     }
1155
     }
1147
-
1148
-    if (riffCount > 0)
1149
-        Log::get(LOG_INFO) << "LoaderTR2: Loaded " << riffCount << " SoundSamples" << Log::endl;
1150
-    else
1151
-        Log::get(LOG_INFO) << "LoaderTR2: No SoundSamples found!" << Log::endl;
1156
+    return riffCount;
1152
 }
1157
 }
1153
 
1158
 
1154
 // ---- Stuff ----
1159
 // ---- Stuff ----

+ 30
- 9
src/system/SoundAL.cpp View File

27
 glm::vec3 SoundAL::lastPosition(0.0f, 0.0f, 0.0f);
27
 glm::vec3 SoundAL::lastPosition(0.0f, 0.0f, 0.0f);
28
 
28
 
29
 int SoundAL::initialize() {
29
 int SoundAL::initialize() {
30
-    if (init)
30
+    if (init) {
31
+        Log::get(LOG_WARNING) << "SoundAL Warning: Already initialized..." << Log::endl;
31
         return 0;
32
         return 0;
33
+    }
32
 
34
 
33
     ALCdevice* device = alcOpenDevice(nullptr);
35
     ALCdevice* device = alcOpenDevice(nullptr);
34
     ALCcontext* context = alcCreateContext(device, nullptr);
36
     ALCcontext* context = alcCreateContext(device, nullptr);
51
 }
53
 }
52
 
54
 
53
 void SoundAL::shutdown() {
55
 void SoundAL::shutdown() {
54
-    if (!init)
56
+    if (!init) {
57
+        Log::get(LOG_ERROR) << "SoundAL Error: Shutdown but not initialized!" << Log::endl;
55
         return;
58
         return;
59
+    }
56
 
60
 
57
     clear();
61
     clear();
62
+    init = false;
63
+
58
     if (alutExit() == AL_FALSE)
64
     if (alutExit() == AL_FALSE)
59
         Log::get(LOG_ERROR) << "SoundAL Error: " << alutGetErrorString(alutGetError()) << Log::endl;
65
         Log::get(LOG_ERROR) << "SoundAL Error: " << alutGetErrorString(alutGetError()) << Log::endl;
60
-    init = false;
61
 }
66
 }
62
 
67
 
63
 void SoundAL::clear() {
68
 void SoundAL::clear() {
64
-    if (!init)
69
+    if (!init) {
70
+        Log::get(LOG_ERROR) << "SoundAL Error: Clear but not initialized!" << Log::endl;
65
         return;
71
         return;
72
+    }
66
 
73
 
67
     stopAll();
74
     stopAll();
68
 
75
 
98
 }
105
 }
99
 
106
 
100
 int SoundAL::loadBuffer(unsigned char* buffer, unsigned int length) {
107
 int SoundAL::loadBuffer(unsigned char* buffer, unsigned int length) {
101
-    if (!init)
108
+    if (!init) {
109
+        Log::get(LOG_ERROR) << "SoundAL Error: Buffer load, but not initialized!" << Log::endl;
102
         return -1;
110
         return -1;
111
+    }
103
 
112
 
104
     alGetError();
113
     alGetError();
105
     unsigned int r = alutCreateBufferFromFileImage(buffer, length);
114
     unsigned int r = alutCreateBufferFromFileImage(buffer, length);
119
 }
128
 }
120
 
129
 
121
 int SoundAL::addSource(int buffer, float volume, bool atListener, bool loop) {
130
 int SoundAL::addSource(int buffer, float volume, bool atListener, bool loop) {
122
-    if ((!init) || (buffer < 0) || (buffer >= buffers.size()))
131
+    if (!init) {
132
+        Log::get(LOG_ERROR) << "SoundAL Error: Adding source, but not initialized!" << Log::endl;
123
         return -1;
133
         return -1;
134
+    }
135
+
136
+    if ((buffer < 0) || (buffer >= buffers.size())) {
137
+        Log::get(LOG_ERROR) << "SoundAL Error: Adding source, but '" << buffer
138
+                            << "' invalid (max '" << buffers.size() << "')!" << Log::endl;
139
+        return -2;
140
+    }
124
 
141
 
125
     unsigned int id;
142
     unsigned int id;
126
 
143
 
128
     alGenSources(1, &id);
145
     alGenSources(1, &id);
129
     if (alGetError() != AL_NO_ERROR) {
146
     if (alGetError() != AL_NO_ERROR) {
130
         Log::get(LOG_ERROR) << "SoundAL Error: Could not create source!" << Log::endl;
147
         Log::get(LOG_ERROR) << "SoundAL Error: Could not create source!" << Log::endl;
131
-        return -2;
148
+        return -3;
132
     }
149
     }
133
 
150
 
134
     alSourcei(id, AL_BUFFER, buffers.at(buffer));
151
     alSourcei(id, AL_BUFFER, buffers.at(buffer));
148
 }
165
 }
149
 
166
 
150
 int SoundAL::sourceAt(int source, glm::vec3 pos) {
167
 int SoundAL::sourceAt(int source, glm::vec3 pos) {
151
-    if (!init)
168
+    if (!init) {
169
+        Log::get(LOG_ERROR) << "SoundAL Error: Positioning source, but not initialized!" << Log::endl;
152
         return -1;
170
         return -1;
171
+    }
153
 
172
 
154
     if ((source < 0) || (source >= sources.size())) {
173
     if ((source < 0) || (source >= sources.size())) {
155
         Log::get(LOG_ERROR) << "SoundAL: Can't position non-existing source!" << Log::endl;
174
         Log::get(LOG_ERROR) << "SoundAL: Can't position non-existing source!" << Log::endl;
162
 }
181
 }
163
 
182
 
164
 void SoundAL::listenAt(glm::vec3 pos, glm::vec3 at, glm::vec3 up) {
183
 void SoundAL::listenAt(glm::vec3 pos, glm::vec3 at, glm::vec3 up) {
165
-    if (!init)
184
+    if (!init) {
185
+        Log::get(LOG_ERROR) << "SoundAL Error: Positioning listener, but not initialized!" << Log::endl;
166
         return;
186
         return;
187
+    }
167
 
188
 
168
     float orientation[6] = { at.x, at.y, at.z, up.x, up.y, up.z };
189
     float orientation[6] = { at.x, at.y, at.z, up.x, up.y, up.z };
169
     alListenerfv(AL_POSITION, &pos[0]);
190
     alListenerfv(AL_POSITION, &pos[0]);

+ 6
- 6
utils/tombraider.bfft View File

380
     signed 16 little unknown1;
380
     signed 16 little unknown1;
381
     signed 16 little unknown2;
381
     signed 16 little unknown2;
382
 
382
 
383
-    summary sample, " - ", volume;
383
+    summary "Sample: ", sample, ", Vol: ", volume * 100 / 32767, "%";
384
 }
384
 }
385
 
385
 
386
 // ########## Main file layout ##########
386
 // ########## Main file layout ##########
508
 
508
 
509
     // TR1s sound map has 256 entries, TR2 & TR3 have 370
509
     // TR1s sound map has 256 entries, TR2 & TR3 have 370
510
     if (TRversion > 1)
510
     if (TRversion > 1)
511
-        skip soundMap[370 * 2];
511
+        signed 16 little soundMap[370];
512
     else
512
     else
513
-        skip soundMap[256 * 2];
513
+        signed 16 little soundMap[256];
514
 
514
 
515
     unsigned 32 little numSoundDetails;
515
     unsigned 32 little numSoundDetails;
516
     sound_details_t soundDetails[numSoundDetails];
516
     sound_details_t soundDetails[numSoundDetails];
517
 
517
 
518
     // TR1 has the sample data embedded here (WAV files)
518
     // TR1 has the sample data embedded here (WAV files)
519
     if (TRversion == 1) {
519
     if (TRversion == 1) {
520
-        unsigned 32 little numSamples;
521
-        skip samples[numSamples];
520
+        unsigned 32 little numWAVSamples;
521
+        skip wavSamples[numWAVSamples];
522
     }
522
     }
523
 
523
 
524
     unsigned 32 little numSampleIndices;
524
     unsigned 32 little numSampleIndices;
525
-    skip sampleIndices[numSampleIndices * 4];
525
+    unsigned 32 little sampleIndices[numSampleIndices];
526
 }
526
 }
527
 
527
 

Loading…
Cancel
Save