Browse Source

Added SoundManager

Thomas Buck 9 years ago
parent
commit
bd24c36a7f
9 changed files with 351 additions and 215 deletions
  1. 2
    0
      ChangeLog.md
  2. 48
    0
      include/SoundManager.h
  3. 2
    0
      include/TextureManager.h
  4. 1
    0
      src/CMakeLists.txt
  5. 3
    0
      src/Game.cpp
  6. 67
    0
      src/SoundManager.cpp
  7. 7
    0
      src/TextureManager.cpp
  8. 214
    215
      src/loader/LoaderTR2.cpp
  9. 7
    0
      src/main.cpp

+ 2
- 0
ChangeLog.md View File

@@ -4,6 +4,8 @@
4 4
 
5 5
     [ 20141129 ]
6 6
     * LoaderTR2 now supports loading animated textiles
7
+    * Clearing textures and textiles before loading a new level
8
+    * Added SoundManager
7 9
 
8 10
     [ 20141128 ]
9 11
     * Added FPS Histogram Debug UI

+ 48
- 0
include/SoundManager.h View File

@@ -0,0 +1,48 @@
1
+/*!
2
+ * \file include/SoundManager.h
3
+ * \brief This is the audio manager Header
4
+ *
5
+ * \author xythobuz
6
+ */
7
+
8
+#ifndef _SOUNDMANAGER_H_
9
+#define _SOUNDMANAGER_H_
10
+
11
+#include <vector>
12
+
13
+struct SoundSource {
14
+    float x, y, z;
15
+    int id, flags;
16
+
17
+    SoundSource(float _x, float _y, float _z, int i, int f)
18
+        : x(_x), y(_y), z(_z), id(i), flags(f) { }
19
+};
20
+
21
+struct SoundDetail {
22
+    int sample;
23
+    float volume;
24
+
25
+    SoundDetail(int s, float v) : sample(s), volume(v) { }
26
+};
27
+
28
+class SoundManager {
29
+  public:
30
+    void clear();
31
+    void addSoundSource(float x, float y, float z, int id, int flags);
32
+    void addSoundMapEntry(int id);
33
+    void addSoundDetail(int sample, float volume);
34
+    void addSampleIndex(int index);
35
+
36
+    int playSound(int index);
37
+
38
+  private:
39
+    std::vector<SoundSource> soundSources;
40
+    std::vector<int> soundMap;
41
+    std::vector<SoundDetail> soundDetails;
42
+    std::vector<int> sampleIndices;
43
+};
44
+
45
+SoundManager& getSoundManager();
46
+
47
+#endif
48
+

+ 2
- 0
include/TextureManager.h View File

@@ -57,6 +57,8 @@ class TextureManager {
57 57
 
58 58
     int initialize();
59 59
 
60
+    void clear();
61
+
60 62
     int numTextures(TextureStorage s = TextureStorage::GAME);
61 63
 
62 64
     /*!

+ 1
- 0
src/CMakeLists.txt View File

@@ -78,6 +78,7 @@ set (SRCS ${SRCS} "RunTime.cpp")
78 78
 set (SRCS ${SRCS} "Script.cpp")
79 79
 set (SRCS ${SRCS} "SkeletalModel.cpp")
80 80
 set (SRCS ${SRCS} "Sound.cpp")
81
+set (SRCS ${SRCS} "SoundManager.cpp")
81 82
 set (SRCS ${SRCS} "Sprite.cpp")
82 83
 set (SRCS ${SRCS} "StaticMesh.cpp")
83 84
 set (SRCS ${SRCS} "TextureManager.cpp")

+ 3
- 0
src/Game.cpp View File

@@ -17,6 +17,7 @@
17 17
 #include "Log.h"
18 18
 #include "Render.h"
19 19
 #include "Sound.h"
20
+#include "SoundManager.h"
20 21
 #include "StaticMesh.h"
21 22
 #include "TextureManager.h"
22 23
 #include "World.h"
@@ -55,6 +56,8 @@ void Game::destroy() {
55 56
     getWorld().destroy();
56 57
     getRender().ClearWorld();
57 58
     getSound().clear(); // Remove all previously loaded sounds
59
+    getSoundManager().clear();
60
+    getTextureManager().clear();
58 61
 }
59 62
 
60 63
 bool Game::isLoaded() {

+ 67
- 0
src/SoundManager.cpp View File

@@ -0,0 +1,67 @@
1
+/*!
2
+ * \file src/SoundManager.cpp
3
+ * \brief This is the audio manager Implementation
4
+ *
5
+ * \author xythobuz
6
+ */
7
+
8
+#include "global.h"
9
+#include "Sound.h"
10
+#include "SoundManager.h"
11
+
12
+void SoundManager::clear() {
13
+    soundSources.clear();
14
+    soundMap.clear();
15
+    soundDetails.clear();
16
+    sampleIndices.clear();
17
+}
18
+
19
+void SoundManager::addSoundSource(float x, float y, float z, int id, int flags) {
20
+    soundSources.emplace_back(x, y, z, id, flags);
21
+}
22
+
23
+void SoundManager::addSoundMapEntry(int id) {
24
+    soundMap.push_back(id);
25
+}
26
+
27
+void SoundManager::addSoundDetail(int sample, float volume) {
28
+    soundDetails.emplace_back(sample, volume);
29
+}
30
+
31
+void SoundManager::addSampleIndex(int index) {
32
+    sampleIndices.push_back(index);
33
+}
34
+
35
+int SoundManager::playSound(int index) {
36
+    if (index >= soundMap.size())
37
+        return -1; // SoundMap not big enough
38
+
39
+    index = soundMap.at(index);
40
+
41
+    if (index == -1)
42
+        return -2; // SoundMap has no entry here (-1)
43
+
44
+    if (index >= soundDetails.size())
45
+        return -3; // SoundMap entry is bigger than SoundDetails
46
+
47
+    SoundDetail s = soundDetails.at(index);
48
+
49
+    if (s.sample == -1)
50
+        return -4; // SoundDetail has no entry here (-1)
51
+
52
+    if (s.sample >= sampleIndices.size())
53
+        return -5; // SoundDetail entry is bigger than SampleIndices
54
+
55
+    index = sampleIndices.at(s.sample);
56
+
57
+    if (index == -1)
58
+        return -6; // SampleIndices has no entry here (-1)
59
+
60
+    if (index >= getSound().registeredSources())
61
+        return -7; // SampleIndices entry is bigger than number of sounds loaded
62
+
63
+    // TODO play sound _index_ with matching volume
64
+
65
+    return 0;
66
+}
67
+

+ 7
- 0
src/TextureManager.cpp View File

@@ -138,6 +138,10 @@ TextureManager::~TextureManager() {
138 138
         mTextureIdsSystem.pop_back();
139 139
     }
140 140
 
141
+    clear();
142
+}
143
+
144
+void TextureManager::clear() {
141 145
     while (mTextureIdsGame.size() > 0) {
142 146
         unsigned int id = mTextureIdsGame.at(mTextureIdsGame.size() - 1);
143 147
         glDeleteTextures(1, &id);
@@ -148,6 +152,9 @@ TextureManager::~TextureManager() {
148 152
         delete tiles.at(tiles.size() - 1);
149 153
         tiles.pop_back();
150 154
     }
155
+
156
+    while (!animations.empty())
157
+        animations.pop_back();
151 158
 }
152 159
 
153 160
 void TextureManager::addTile(TextureTile* t) {

+ 214
- 215
src/loader/LoaderTR2.cpp View File

@@ -14,6 +14,7 @@
14 14
 #include "Mesh.h"
15 15
 #include "Room.h"
16 16
 #include "Sound.h"
17
+#include "SoundManager.h"
17 18
 #include "TextureManager.h"
18 19
 #include "utils/pixel.h"
19 20
 #include "loader/LoaderTR2.h"
@@ -63,6 +64,8 @@ int LoaderTR2::load(std::string f) {
63 64
     return 0; // TODO Not finished with implementation!
64 65
 }
65 66
 
67
+// ---- Textures ----
68
+
66 69
 void LoaderTR2::loadPaletteTextiles() {
67 70
     file.seek(file.tell() + 768); // Skip 8bit palette, 256 * 3 bytes
68 71
 
@@ -93,6 +96,73 @@ void LoaderTR2::loadPaletteTextiles() {
93 96
     }
94 97
 }
95 98
 
99
+void LoaderTR2::loadTextures() {
100
+    uint32_t numObjectTextures = file.readU32();
101
+    for (unsigned int o = 0; o < numObjectTextures; o++) {
102
+        // 0 means that a texture is all-opaque, and that transparency
103
+        // information is ignored.
104
+        // 1 means that transparency information is used. In 8-bit color,
105
+        // index 0 is the transparent color, while in 16-bit color, the
106
+        // top bit (0x8000) is the alpha channel (1 = opaque, 0 = transparent)
107
+        uint16_t attribute = file.readU16();
108
+
109
+        // Index into the textile list
110
+        uint16_t tile = file.readU16();
111
+
112
+        TextureTile* t = new TextureTile(attribute, tile);
113
+
114
+        // The four corner vertices of the texture
115
+        // The Pixel values are the actual coordinates of the vertexs pixel
116
+        // The Coordinate values depend on where the other vertices are in
117
+        // the object texture. And if the object texture is used to specify
118
+        // a triangle, then the fourth vertexs values will all be zero
119
+        // Coordinate is 1 if Pixel is the low val, 255 if high val in object texture
120
+        for (int i = 0; i < 4; i++) {
121
+            uint8_t xCoordinate = file.readU8();
122
+            uint8_t xPixel = file.readU8();
123
+            uint8_t yCoordinate = file.readU8();
124
+            uint8_t yPixel = file.readU8();
125
+
126
+            assert((xCoordinate != 1) || (xCoordinate != 255));
127
+            assert((yCoordinate != 1) || (yCoordinate != 255));
128
+
129
+            t->add(new TextureTileVertex(xCoordinate, xPixel, yCoordinate, yPixel));
130
+        }
131
+
132
+        getTextureManager().addTile(t);
133
+    }
134
+}
135
+
136
+void LoaderTR2::loadAnimatedTextures() {
137
+    uint32_t numWords = file.readU32() - 1;
138
+    uint16_t numAnimatedTextures = file.readU16();
139
+    std::vector<uint16_t> animatedTextures;
140
+    for (unsigned int a = 0; a < numWords; a++) {
141
+        animatedTextures.push_back(file.readU16());
142
+    }
143
+
144
+    int pos = 0;
145
+    for (unsigned int a = 0; a < numAnimatedTextures; a++) {
146
+        int count = animatedTextures.at(pos) + 1;
147
+        if ((pos + count) >= numWords) {
148
+            getLog() << "LoaderTR2: Invalid AnimatedTextures ("
149
+                << pos + count << " >= " << numWords << ")!" << Log::endl;
150
+            return;
151
+        }
152
+
153
+        for (int i = 0; i < count; i++) {
154
+            getTextureManager().addAnimatedTile(a, animatedTextures.at(pos + i + 1));
155
+        }
156
+
157
+        pos += count + 1;
158
+    }
159
+
160
+    if (pos != numWords)
161
+        getLog() << "LoaderTR2: Extra bytes at end of AnimatedTextures?" << Log::endl;
162
+}
163
+
164
+// ---- Rooms ----
165
+
96 166
 void LoaderTR2::loadRooms() {
97 167
     uint16_t numRooms = file.readU16();
98 168
 
@@ -281,6 +351,34 @@ void LoaderTR2::loadFloorData() {
281 351
         getLog() << "LoaderTR2: Found " << numFloorData << " words FloorData, unimplemented!" << Log::endl;
282 352
 }
283 353
 
354
+void LoaderTR2::loadSprites() {
355
+    uint32_t numSpriteTextures = file.readU32();
356
+    for (unsigned int s = 0; s < numSpriteTextures; s++) {
357
+        uint16_t tile = file.readU16();
358
+        uint8_t x = file.readU8();
359
+        uint8_t y = file.readU8();
360
+        uint16_t width = file.readU16(); // Actually (width * 256) + 255
361
+        uint16_t height = file.readU16(); // Actually (height * 256) + 255
362
+        int16_t leftSide = file.read16();
363
+        int16_t topSide = file.read16();
364
+        int16_t rightSide = file.read16();
365
+        int16_t bottomSide = file.read16();
366
+
367
+        // TODO store sprite textures somewhere
368
+    }
369
+
370
+    uint32_t numSpriteSequences = file.readU32();
371
+    for (unsigned int s = 0; s < numSpriteSequences; s++) {
372
+        int32_t objectID = file.read32(); // Item identifier, matched in Items[]
373
+        int16_t negativeLength = file.read16(); // Negative sprite count
374
+        int16_t offset = file.read16(); // Where sequence starts in sprite texture list
375
+
376
+        // TODO store sprite sequences somewhere
377
+    }
378
+}
379
+
380
+// ---- Meshes ----
381
+
284 382
 void LoaderTR2::loadMeshes() {
285 383
     // Number of bitu16s of mesh data to follow
286 384
     // Read all the mesh data into a buffer, because
@@ -308,6 +406,43 @@ void LoaderTR2::loadMeshes() {
308 406
     }
309 407
 }
310 408
 
409
+void LoaderTR2::loadStaticMeshes() {
410
+    uint32_t numStaticMeshes = file.readU32();
411
+    for (unsigned int s = 0; s < numStaticMeshes; s++) {
412
+        uint32_t objectID = file.readU32(); // Matched in Items[]
413
+        uint16_t mesh = file.readU16(); // Offset into MeshPointers[]
414
+
415
+        // tr2_vertex BoundingBox[2][2];
416
+        // First index is which one, second index is opposite corners
417
+        int16_t x11 = file.read16();
418
+        int16_t y11 = file.read16();
419
+        int16_t z11 = file.read16();
420
+
421
+        int16_t x12 = file.read16();
422
+        int16_t y12 = file.read16();
423
+        int16_t z12 = file.read16();
424
+
425
+        int16_t x21 = file.read16();
426
+        int16_t y21 = file.read16();
427
+        int16_t z21 = file.read16();
428
+
429
+        int16_t x22 = file.read16();
430
+        int16_t y22 = file.read16();
431
+        int16_t z22 = file.read16();
432
+
433
+        // Meaning uncertain. Usually 2, and 3 for objects Lara can
434
+        // travel through, like TR2s skeletons and underwater plants
435
+        uint16_t flags = file.readU16();
436
+
437
+        // TODO store static meshes somewhere
438
+    }
439
+
440
+    if (numStaticMeshes > 0)
441
+        getLog() << "LoaderTR2: Found " << numStaticMeshes << " StaticMeshes, unimplemented!" << Log::endl;
442
+}
443
+
444
+// ---- Moveables ----
445
+
311 446
 void LoaderTR2::loadMoveables() {
312 447
     uint32_t numAnimations = file.readU32();
313 448
     for (unsigned int a = 0; a < numAnimations; a++) {
@@ -410,140 +545,30 @@ void LoaderTR2::loadMoveables() {
410 545
     // TODO combine all this into moveables with their animations
411 546
 }
412 547
 
413
-void LoaderTR2::loadStaticMeshes() {
414
-    uint32_t numStaticMeshes = file.readU32();
415
-    for (unsigned int s = 0; s < numStaticMeshes; s++) {
416
-        uint32_t objectID = file.readU32(); // Matched in Items[]
417
-        uint16_t mesh = file.readU16(); // Offset into MeshPointers[]
418
-
419
-        // tr2_vertex BoundingBox[2][2];
420
-        // First index is which one, second index is opposite corners
421
-        int16_t x11 = file.read16();
422
-        int16_t y11 = file.read16();
423
-        int16_t z11 = file.read16();
424
-
425
-        int16_t x12 = file.read16();
426
-        int16_t y12 = file.read16();
427
-        int16_t z12 = file.read16();
428
-
429
-        int16_t x21 = file.read16();
430
-        int16_t y21 = file.read16();
431
-        int16_t z21 = file.read16();
432
-
433
-        int16_t x22 = file.read16();
434
-        int16_t y22 = file.read16();
435
-        int16_t z22 = file.read16();
436
-
437
-        // Meaning uncertain. Usually 2, and 3 for objects Lara can
438
-        // travel through, like TR2s skeletons and underwater plants
439
-        uint16_t flags = file.readU16();
440
-
441
-        // TODO store static meshes somewhere
442
-    }
443
-
444
-    if (numStaticMeshes > 0)
445
-        getLog() << "LoaderTR2: Found " << numStaticMeshes << " StaticMeshes, unimplemented!" << Log::endl;
446
-}
447
-
448
-void LoaderTR2::loadTextures() {
449
-    uint32_t numObjectTextures = file.readU32();
450
-    for (unsigned int o = 0; o < numObjectTextures; o++) {
451
-        // 0 means that a texture is all-opaque, and that transparency
452
-        // information is ignored.
453
-        // 1 means that transparency information is used. In 8-bit color,
454
-        // index 0 is the transparent color, while in 16-bit color, the
455
-        // top bit (0x8000) is the alpha channel (1 = opaque, 0 = transparent)
456
-        uint16_t attribute = file.readU16();
457
-
458
-        // Index into the textile list
459
-        uint16_t tile = file.readU16();
460
-
461
-        TextureTile* t = new TextureTile(attribute, tile);
462
-
463
-        // The four corner vertices of the texture
464
-        // The Pixel values are the actual coordinates of the vertexs pixel
465
-        // The Coordinate values depend on where the other vertices are in
466
-        // the object texture. And if the object texture is used to specify
467
-        // a triangle, then the fourth vertexs values will all be zero
468
-        // Coordinate is 1 if Pixel is the low val, 255 if high val in object texture
469
-        for (int i = 0; i < 4; i++) {
470
-            uint8_t xCoordinate = file.readU8();
471
-            uint8_t xPixel = file.readU8();
472
-            uint8_t yCoordinate = file.readU8();
473
-            uint8_t yPixel = file.readU8();
474
-
475
-            assert((xCoordinate != 1) || (xCoordinate != 255));
476
-            assert((yCoordinate != 1) || (yCoordinate != 255));
477
-
478
-            t->add(new TextureTileVertex(xCoordinate, xPixel, yCoordinate, yPixel));
479
-        }
480
-
481
-        getTextureManager().addTile(t);
482
-    }
483
-}
484
-
485
-void LoaderTR2::loadSprites() {
486
-    uint32_t numSpriteTextures = file.readU32();
487
-    for (unsigned int s = 0; s < numSpriteTextures; s++) {
488
-        uint16_t tile = file.readU16();
489
-        uint8_t x = file.readU8();
490
-        uint8_t y = file.readU8();
491
-        uint16_t width = file.readU16(); // Actually (width * 256) + 255
492
-        uint16_t height = file.readU16(); // Actually (height * 256) + 255
493
-        int16_t leftSide = file.read16();
494
-        int16_t topSide = file.read16();
495
-        int16_t rightSide = file.read16();
496
-        int16_t bottomSide = file.read16();
497
-
498
-        // TODO store sprite textures somewhere
499
-    }
500
-
501
-    uint32_t numSpriteSequences = file.readU32();
502
-    for (unsigned int s = 0; s < numSpriteSequences; s++) {
503
-        int32_t objectID = file.read32(); // Item identifier, matched in Items[]
504
-        int16_t negativeLength = file.read16(); // Negative sprite count
505
-        int16_t offset = file.read16(); // Where sequence starts in sprite texture list
506
-
507
-        // TODO store sprite sequences somewhere
508
-    }
509
-}
510
-
511
-void LoaderTR2::loadCameras() {
512
-    uint32_t numCameras = file.readU32();
513
-    for (unsigned int c = 0; c < numCameras; c++) {
514
-        int32_t x = file.read32();
515
-        int32_t y = file.read32();
516
-        int32_t z = file.read32();
548
+void LoaderTR2::loadItems() {
549
+    uint32_t numItems = file.readU32();
550
+    for (unsigned int i = 0; i < numItems; i++) {
551
+        int16_t objectID = file.read16();
517 552
         int16_t room = file.read16();
518 553
 
519
-        file.seek(file.tell() + 2); // Unknown, correlates to Boxes? Zones?
520
-
521
-        // TODO store cameras somewhere
522
-    }
523
-
524
-    if (numCameras > 0)
525
-        getLog() << "LoaderTR2: Found " << numCameras << " Cameras, unimplemented!" << Log::endl;
526
-}
527
-
528
-void LoaderTR2::loadSoundSources() {
529
-    uint32_t numSoundSources = file.readU32();
530
-    for (unsigned int s = 0; s < numSoundSources; s++) {
531
-        // Absolute world coordinate positions of sound source
554
+        // Item position in world coordinates
532 555
         int32_t x = file.read32();
533 556
         int32_t y = file.read32();
534 557
         int32_t z = file.read32();
535 558
 
536
-        // Internal sound index
537
-        uint16_t soundID = file.readU16();
559
+        int16_t angle = file.read16(); // (0xC000 >> 14) * 90deg
560
+        int16_t intensity1 = file.read16(); // Constant lighting; -1 means mesh lighting
561
+        int16_t intensity2 = file.read16(); // Almost always like intensity1
538 562
 
539
-        // Unknown, 0x40, 0x80 or 0xC0
563
+        // 0x0100 - Initially visible
564
+        // 0x3E00 - Activation mask, open, can be XORed with related FloorData list fields.
540 565
         uint16_t flags = file.readU16();
541 566
 
542
-        // TODO store sound sources somewhere
567
+        // TODO store items somewhere
543 568
     }
544 569
 
545
-    if (numSoundSources > 0)
546
-        getLog() << "LoaderTR2: Found " << numSoundSources << " SoundSources, unimplemented!" << Log::endl;
570
+    if (numItems > 0)
571
+        getLog() << "LoaderTR2: Found " << numItems << " Items, unimplemented!" << Log::endl;
547 572
 }
548 573
 
549 574
 void LoaderTR2::loadBoxesOverlapsZones() {
@@ -585,130 +610,55 @@ void LoaderTR2::loadBoxesOverlapsZones() {
585 610
         getLog() << "LoaderTR2: Found NPC NavigationHints, not yet implemented!" << Log::endl;
586 611
 }
587 612
 
588
-void LoaderTR2::loadAnimatedTextures() {
589
-    uint32_t numWords = file.readU32() - 1;
590
-    uint16_t numAnimatedTextures = file.readU16();
591
-    std::vector<uint16_t> animatedTextures;
592
-    for (unsigned int a = 0; a < numWords; a++) {
593
-        animatedTextures.push_back(file.readU16());
594
-    }
595
-
596
-    int pos = 0;
597
-    for (unsigned int a = 0; a < numAnimatedTextures; a++) {
598
-        int count = animatedTextures.at(pos) + 1;
599
-        if ((pos + count) >= numWords) {
600
-            getLog() << "LoaderTR2: Invalid AnimatedTextures ("
601
-                << pos + count << " >= " << numWords << ")!" << Log::endl;
602
-            return;
603
-        }
604
-
605
-        for (int i = 0; i < count; i++) {
606
-            getTextureManager().addAnimatedTile(a, animatedTextures.at(pos + i + 1));
607
-        }
608
-
609
-        pos += count + 1;
610
-    }
611
-
612
-    if (pos != numWords)
613
-        getLog() << "LoaderTR2: Extra bytes at end of AnimatedTextures?" << Log::endl;
614
-}
615
-
616
-void LoaderTR2::loadItems() {
617
-    uint32_t numItems = file.readU32();
618
-    for (unsigned int i = 0; i < numItems; i++) {
619
-        int16_t objectID = file.read16();
620
-        int16_t room = file.read16();
613
+// ---- Sound ----
621 614
 
622
-        // Item position in world coordinates
615
+void LoaderTR2::loadSoundSources() {
616
+    uint32_t numSoundSources = file.readU32();
617
+    for (unsigned int s = 0; s < numSoundSources; s++) {
618
+        // Absolute world coordinate positions of sound source
623 619
         int32_t x = file.read32();
624 620
         int32_t y = file.read32();
625 621
         int32_t z = file.read32();
626 622
 
627
-        int16_t angle = file.read16(); // (0xC000 >> 14) * 90deg
628
-        int16_t intensity1 = file.read16(); // Constant lighting; -1 means mesh lighting
629
-        int16_t intensity2 = file.read16(); // Almost always like intensity1
623
+        // Internal sound index
624
+        uint16_t soundID = file.readU16();
630 625
 
631
-        // 0x0100 - Initially visible
632
-        // 0x3E00 - Activation mask, open, can be XORed with related FloorData list fields.
626
+        // Unknown, 0x40, 0x80 or 0xC0
633 627
         uint16_t flags = file.readU16();
634 628
 
635
-        // TODO store items somewhere
629
+        getSoundManager().addSoundSource(x, y, z, soundID, flags);
636 630
     }
637
-
638
-    if (numItems > 0)
639
-        getLog() << "LoaderTR2: Found " << numItems << " Items, unimplemented!" << Log::endl;
640
-}
641
-
642
-void LoaderTR2::loadCinematicFrames() {
643
-    uint16_t numCinematicFrames = file.readU16();
644
-    for (unsigned int c = 0; c < numCinematicFrames; c++) {
645
-        int16_t rotY = file.read16(); // Y rotation, +-32767 = +-180deg
646
-        int16_t rotZ = file.read16(); // Z rotation, like rotY
647
-        int16_t rotZ2 = file.read16(); // Like rotZ?
648
-        int16_t posZ = file.read16(); // Camera pos relative to what?
649
-        int16_t posY = file.read16();
650
-        int16_t posX = file.read16();
651
-        int16_t unknown = file.read16(); // Changing this can cause runtime error
652
-        int16_t rotX = file.read16(); // X rotation, like rotY
653
-
654
-        // TODO store cinematic frames somewhere
655
-    }
656
-
657
-    if (numCinematicFrames > 0)
658
-        getLog() << "LoaderTR2: Found " << numCinematicFrames
659
-            << " CinematicFrames, not yet implemented!" << Log::endl;
660
-}
661
-
662
-void LoaderTR2::loadDemoData() {
663
-    uint16_t numDemoData = file.readU16();
664
-    for (unsigned int d = 0; d < numDemoData; d++)
665
-        file.readU8();
666
-
667
-    // TODO store demo data somewhere, find out meaning
668
-    if (numDemoData > 0)
669
-        getLog() << "LoaderTR2: Found " << numDemoData << " bytes DemoData, not yet implemented!" << Log::endl;
670 631
 }
671 632
 
672 633
 void LoaderTR2::loadSoundMap() {
673
-    std::array<int16_t, 370> soundMap;
674
-    for (auto& x : soundMap) {
675
-        x = file.read16();
634
+    for (int i = 0; i < 370; i++) {
635
+        getSoundManager().addSoundMapEntry(file.read16());
676 636
     }
677
-
678
-    // TODO store sound map somewhere
679 637
 }
680 638
 
681 639
 void LoaderTR2::loadSoundDetails() {
682 640
     uint32_t numSoundDetails = file.readU32();
683 641
     for (unsigned int s = 0; s < numSoundDetails; s++) {
684
-        int16_t sample = file.read16(); // Index into SampleIndices[]
685
-        int16_t volume = file.read16();
642
+        uint16_t sample = file.readU16(); // Index into SampleIndices[]
643
+        uint16_t volume = file.readU16();
686 644
 
687 645
         // sound range? distance at which this sound can be heard?
688
-        int16_t unknown1 = file.read16();
646
+        uint16_t unknown1 = file.readU16();
689 647
 
690 648
         // Bits 8-15: priority?
691 649
         // Bits 2-7: number of samples in this group
692 650
         // Bits 0-1: channel number?
693
-        int16_t unknown2 = file.read16();
651
+        uint16_t unknown2 = file.readU16();
694 652
 
695
-        // TODO store sound details somewhere
653
+        getSoundManager().addSoundDetail(sample, ((float)volume) / 32767.0f);
696 654
     }
697
-
698
-    if (numSoundDetails > 0)
699
-        getLog() << "LoaderTR2: Found " << numSoundDetails << " SoundDetails, unimplemented!" << Log::endl;
700 655
 }
701 656
 
702 657
 void LoaderTR2::loadSampleIndices() {
703 658
     uint32_t numSampleIndices = file.readU32();
704
-    std::vector<uint32_t> sampleIndices;
705 659
     for (unsigned int i = 0; i < numSampleIndices; i++) {
706
-        sampleIndices.push_back(file.readU32());
660
+        getSoundManager().addSampleIndex(file.readU32());
707 661
     }
708
-
709
-    // TODO store sample indices somewhere
710
-    if (numSampleIndices > 0)
711
-        getLog() << "LoaderTR2: Found " << numSampleIndices << " SampleIndices, unimplemented!" << Log::endl;
712 662
 }
713 663
 
714 664
 void LoaderTR2::loadExternalSoundFile(std::string f) {
@@ -757,3 +707,52 @@ void LoaderTR2::loadExternalSoundFile(std::string f) {
757 707
         getLog() << "LoaderTR2: Found " << riffCount << " SoundSamples" << Log::endl;
758 708
 }
759 709
 
710
+// ---- Stuff ----
711
+
712
+void LoaderTR2::loadCameras() {
713
+    uint32_t numCameras = file.readU32();
714
+    for (unsigned int c = 0; c < numCameras; c++) {
715
+        int32_t x = file.read32();
716
+        int32_t y = file.read32();
717
+        int32_t z = file.read32();
718
+        int16_t room = file.read16();
719
+
720
+        file.seek(file.tell() + 2); // Unknown, correlates to Boxes? Zones?
721
+
722
+        // TODO store cameras somewhere
723
+    }
724
+
725
+    if (numCameras > 0)
726
+        getLog() << "LoaderTR2: Found " << numCameras << " Cameras, unimplemented!" << Log::endl;
727
+}
728
+
729
+void LoaderTR2::loadCinematicFrames() {
730
+    uint16_t numCinematicFrames = file.readU16();
731
+    for (unsigned int c = 0; c < numCinematicFrames; c++) {
732
+        int16_t rotY = file.read16(); // Y rotation, +-32767 = +-180deg
733
+        int16_t rotZ = file.read16(); // Z rotation, like rotY
734
+        int16_t rotZ2 = file.read16(); // Like rotZ?
735
+        int16_t posZ = file.read16(); // Camera pos relative to what?
736
+        int16_t posY = file.read16();
737
+        int16_t posX = file.read16();
738
+        int16_t unknown = file.read16(); // Changing this can cause runtime error
739
+        int16_t rotX = file.read16(); // X rotation, like rotY
740
+
741
+        // TODO store cinematic frames somewhere
742
+    }
743
+
744
+    if (numCinematicFrames > 0)
745
+        getLog() << "LoaderTR2: Found " << numCinematicFrames
746
+            << " CinematicFrames, not yet implemented!" << Log::endl;
747
+}
748
+
749
+void LoaderTR2::loadDemoData() {
750
+    uint16_t numDemoData = file.readU16();
751
+    for (unsigned int d = 0; d < numDemoData; d++)
752
+        file.readU8();
753
+
754
+    // TODO store demo data somewhere, find out meaning
755
+    if (numDemoData > 0)
756
+        getLog() << "LoaderTR2: Found " << numDemoData << " bytes DemoData, not yet implemented!" << Log::endl;
757
+}
758
+

+ 7
- 0
src/main.cpp View File

@@ -24,6 +24,7 @@
24 24
 #include "MenuFolder.h"
25 25
 #include "Render.h"
26 26
 #include "RunTime.h"
27
+#include "SoundManager.h"
27 28
 #include "TextureManager.h"
28 29
 #include "UI.h"
29 30
 #include "Window.h"
@@ -52,6 +53,7 @@ static std::shared_ptr<MenuFolder> gMenu;
52 53
 static std::shared_ptr<Render> gRender;
53 54
 static std::shared_ptr<RunTime> gRunTime;
54 55
 static std::shared_ptr<Sound> gSound;
56
+static std::shared_ptr<SoundManager> gSoundManager;
55 57
 static std::shared_ptr<TextureManager> gTextureManager;
56 58
 static std::shared_ptr<Window> gWindow;
57 59
 static std::shared_ptr<World> gWorld;
@@ -84,6 +86,10 @@ Sound& getSound() {
84 86
     return *gSound;
85 87
 }
86 88
 
89
+SoundManager& getSoundManager() {
90
+    return *gSoundManager;
91
+}
92
+
87 93
 TextureManager& getTextureManager() {
88 94
     return *gTextureManager;
89 95
 }
@@ -114,6 +120,7 @@ int main(int argc, char* argv[]) {
114 120
     gLog.reset(new Log());
115 121
     gMenu.reset(new MenuFolder());
116 122
     gRender.reset(new Render());
123
+    gSoundManager.reset(new SoundManager());
117 124
     gTextureManager.reset(new TextureManager());
118 125
     gWorld.reset(new World());
119 126
 

Loading…
Cancel
Save