Просмотр исходного кода

Fixed TR1 level loading (sound samples and colors)

Thomas Buck 9 лет назад
Родитель
Сommit
7386eef8ae
6 измененных файлов: 77 добавлений и 44 удалений
  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 Просмотреть файл

@@ -2,6 +2,12 @@
2 2
 
3 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 11
     [ 20140304 ]
6 12
     * Added (more or less working) support for loading TR1 levels
7 13
     * Updated imgui

+ 1
- 1
include/loader/LoaderTR2.h Просмотреть файл

@@ -45,7 +45,7 @@ class LoaderTR2 : public Loader {
45 45
     virtual void loadSampleIndices();
46 46
 
47 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 50
     virtual int getPaletteIndex(uint16_t index);
51 51
 };

+ 20
- 19
src/loader/LoaderTR1.cpp Просмотреть файл

@@ -47,7 +47,6 @@ int LoaderTR1::load(std::string f) {
47 47
     loadSoundMap();
48 48
     loadSoundDetails();
49 49
     loadSoundSamples();
50
-    loadSampleIndices();
51 50
 
52 51
     return 0;
53 52
 }
@@ -59,17 +58,11 @@ void LoaderTR1::loadPalette() {
59 58
         uint8_t g = file.readU8();
60 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 67
         glm::vec4 c(r / 255.0f, g / 255.0f, b / 255.0f, 1.0f);
75 68
         TextureManager::setPalette(i, c);
@@ -253,18 +246,26 @@ void LoaderTR1::loadSoundMap() {
253 246
 
254 247
 void LoaderTR1::loadSoundSamples() {
255 248
     uint32_t soundSampleSize = file.readU32();
256
-    if (soundSampleSize <= 0) {
257
-        return;
258
-    }
259
-
260 249
     std::vector<uint8_t> buffer;
261 250
     for (int i = 0; i < soundSampleSize; i++) {
262 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 271
 int LoaderTR1::getPaletteIndex(uint16_t index) {

+ 14
- 9
src/loader/LoaderTR2.cpp Просмотреть файл

@@ -1113,21 +1113,30 @@ void LoaderTR2::loadExternalSoundFile(std::string f) {
1113 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 1126
     int riffCount = 0;
1121 1127
     while (!sfx.eof()) {
1128
+        if ((count > 0) && (riffCount >= count))
1129
+            break;
1130
+
1122 1131
         char test[5];
1123 1132
         test[4] = '\0';
1124 1133
         for (int i = 0; i < 4; i++)
1125 1134
             test[i] = sfx.read8();
1126 1135
 
1127 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 1138
                                 << ", \"" << test << "\" != \"RIFF\")" << Log::endl;
1130
-            return;
1139
+            return -1;
1131 1140
         }
1132 1141
 
1133 1142
         // riffSize is (fileLength - 8)
@@ -1144,11 +1153,7 @@ void LoaderTR2::loadSoundFiles(BinaryReader& sfx) {
1144 1153
 
1145 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 1159
 // ---- Stuff ----

+ 30
- 9
src/system/SoundAL.cpp Просмотреть файл

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

+ 6
- 6
utils/tombraider.bfft Просмотреть файл

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

Загрузка…
Отмена
Сохранить