|
@@ -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
|
+
|