/
scene.cpp
1352 lines (1103 loc) · 39.8 KB
/
scene.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "sherlock/scene.h"
#include "sherlock/sherlock.h"
#include "sherlock/screen.h"
#include "sherlock/scalpel/scalpel.h"
#include "sherlock/scalpel/scalpel_people.h"
#include "sherlock/scalpel/scalpel_scene.h"
#include "sherlock/tattoo/tattoo.h"
#include "sherlock/tattoo/tattoo_scene.h"
#include "sherlock/tattoo/tattoo_user_interface.h"
namespace Sherlock {
static const int FS_TRANS[8] = {
Scalpel::STOP_UP, Scalpel::STOP_UPRIGHT, Scalpel::STOP_RIGHT, Scalpel::STOP_DOWNRIGHT,
Scalpel::STOP_DOWN, Scalpel::STOP_DOWNLEFT, Scalpel::STOP_LEFT, Scalpel::STOP_UPLEFT
};
/*----------------------------------------------------------------*/
BgFileHeader::BgFileHeader() {
_numStructs = -1;
_numImages = -1;
_numcAnimations = -1;
_descSize = -1;
_seqSize = -1;
// Serrated Scalpel
_fill = -1;
// Rose Tattoo
_scrollSize = -1;
_bytesWritten = -1;
_fadeStyle = -1;
Common::fill(&_palette[0], &_palette[PALETTE_SIZE], 0);
}
void BgFileHeader::load(Common::SeekableReadStream &s, bool isRoseTattoo) {
_numStructs = s.readUint16LE();
_numImages = s.readUint16LE();
_numcAnimations = s.readUint16LE();
_descSize = s.readUint16LE();
_seqSize = s.readUint16LE();
if (isRoseTattoo) {
_scrollSize = s.readUint16LE();
_bytesWritten = s.readUint32LE();
_fadeStyle = s.readByte();
} else {
_fill = s.readUint16LE();
}
}
/*----------------------------------------------------------------*/
void BgFileHeaderInfo::load(Common::SeekableReadStream &s) {
_filesize = s.readUint32LE();
_maxFrames = s.readByte();
char buffer[9];
s.read(buffer, 9);
_filename = Common::String(buffer);
}
void BgFileHeaderInfo::load3DO(Common::SeekableReadStream &s) {
_filesize = s.readUint32BE();
_maxFrames = s.readByte();
char buffer[9];
s.read(buffer, 9);
_filename = Common::String(buffer);
s.skip(2); // only on 3DO!
}
/*----------------------------------------------------------------*/
void Exit::load(Common::SeekableReadStream &s, bool isRoseTattoo) {
if (isRoseTattoo) {
char buffer[41];
s.read(buffer, 41);
_dest = Common::String(buffer);
}
left = s.readSint16LE();
top = s.readSint16LE();
setWidth(s.readUint16LE());
setHeight(s.readUint16LE());
_image = isRoseTattoo ? s.readByte() : 0;
_scene = s.readSint16LE();
if (!isRoseTattoo)
_allow = s.readSint16LE();
_newPosition.x = s.readSint16LE();
_newPosition.y = s.readSint16LE();
_newFacing = s.readUint16LE();
if (isRoseTattoo)
_allow = s.readSint16LE();
}
void Exit::load3DO(Common::SeekableReadStream &s) {
left = s.readSint16BE();
top = s.readSint16BE();
setWidth(s.readUint16BE());
setHeight(s.readUint16BE());
_image = 0;
_scene = s.readSint16BE();
_allow = s.readSint16BE();
_newPosition.x = s.readSint16BE();
_newPosition.y = s.readSint16BE();
_newFacing = s.readUint16BE();
s.skip(2); // Filler
}
/*----------------------------------------------------------------*/
void SceneEntry::load(Common::SeekableReadStream &s) {
_startPosition.x = s.readSint16LE();
_startPosition.y = s.readSint16LE();
_startDir = s.readByte();
_allow = s.readByte();
}
void SceneEntry::load3DO(Common::SeekableReadStream &s) {
_startPosition.x = s.readSint16BE();
_startPosition.y = s.readSint16BE();
_startDir = s.readByte();
_allow = s.readByte();
}
void SceneSound::load(Common::SeekableReadStream &s) {
char buffer[9];
s.read(buffer, 8);
buffer[8] = '\0';
_name = Common::String(buffer);
_priority = s.readByte();
}
void SceneSound::load3DO(Common::SeekableReadStream &s) {
load(s);
}
/*----------------------------------------------------------------*/
int ObjectArray::indexOf(const Object &obj) const {
for (uint idx = 0; idx < size(); ++idx) {
if (&(*this)[idx] == &obj)
return idx;
}
return -1;
}
/*----------------------------------------------------------------*/
void ScaleZone::load(Common::SeekableReadStream &s) {
left = s.readSint16LE();
top = s.readSint16LE();
setWidth(s.readUint16LE());
setHeight(s.readUint16LE());
_topNumber = s.readByte();
_bottomNumber = s.readByte();
}
/*----------------------------------------------------------------*/
void WalkArray::load(Common::SeekableReadStream &s, bool isRoseTattoo) {
_pointsCount = (int8)s.readByte();
for (int idx = 0; idx < _pointsCount; ++idx) {
int x = s.readSint16LE();
int y = isRoseTattoo ? s.readSint16LE() : s.readByte();
push_back(Common::Point(x, y));
}
}
/*----------------------------------------------------------------*/
Scene *Scene::init(SherlockEngine *vm) {
if (vm->getGameID() == GType_SerratedScalpel)
return new Scalpel::ScalpelScene(vm);
else
return new Tattoo::TattooScene(vm);
}
Scene::Scene(SherlockEngine *vm): _vm(vm) {
_sceneStats = new bool *[SCENES_COUNT];
_sceneStats[0] = new bool[SCENES_COUNT * 65];
Common::fill(&_sceneStats[0][0], &_sceneStats[0][SCENES_COUNT * 65], false);
for (int idx = 1; idx < SCENES_COUNT; ++idx) {
_sceneStats[idx] = _sceneStats[idx - 1] + 65;
}
_currentScene = -1;
_goToScene = -1;
_loadingSavedGame = false;
_walkedInScene = false;
_version = 0;
_lzwMode = false;
_invGraphicItems = 0;
_cAnimFramePause = 0;
_restoreFlag = false;
_animating = 0;
_doBgAnimDone = true;
_tempFadeStyle = 0;
_exitZone = -1;
}
Scene::~Scene() {
freeScene();
delete[] _sceneStats[0];
delete[] _sceneStats;
}
void Scene::selectScene() {
Events &events = *_vm->_events;
People &people = *_vm->_people;
Screen &screen = *_vm->_screen;
Talk &talk = *_vm->_talk;
UserInterface &ui = *_vm->_ui;
// Reset fields
ui._windowOpen = ui._infoFlag = false;
ui._menuMode = STD_MODE;
// Free any previous scene
freeScene();
// Load the scene
Common::String sceneFile = Common::String::format("res%02d", _goToScene);
// _rrmName gets set during loadScene()
// _rrmName is for ScalpelScene::startCAnim
_currentScene = _goToScene;
_goToScene = -1;
loadScene(sceneFile);
// If the fade style was changed from running a movie, then reset it
if (_tempFadeStyle) {
screen._fadeStyle = _tempFadeStyle;
_tempFadeStyle = 0;
}
people._walkDest = Common::Point(people[HOLMES]._position.x / FIXED_INT_MULTIPLIER,
people[HOLMES]._position.y / FIXED_INT_MULTIPLIER);
_restoreFlag = true;
events.clearEvents();
// If there were any scripts waiting to be run, but were interrupt by a running
// canimation (probably the last scene's exit canim), clear the _scriptMoreFlag
if (talk._scriptMoreFlag == 3)
talk._scriptMoreFlag = 0;
}
void Scene::freeScene() {
if (_currentScene == -1)
return;
_vm->_talk->freeTalkVars();
_vm->_inventory->freeInv();
_vm->_music->freeSong();
_vm->_sound->freeLoadedSounds();
if (!_loadingSavedGame)
saveSceneStatus();
else
_loadingSavedGame = false;
_sequenceBuffer.clear();
_descText.clear();
_walkPoints.clear();
_cAnim.clear();
_bgShapes.clear();
_zones.clear();
_canimShapes.clear();
for (uint idx = 0; idx < _images.size(); ++idx)
delete _images[idx]._images;
_images.clear();
_currentScene = -1;
}
bool Scene::loadScene(const Common::String &filename) {
Events &events = *_vm->_events;
Music &music = *_vm->_music;
People &people = *_vm->_people;
Resources &res = *_vm->_res;
SaveManager &saves = *_vm->_saves;
Screen &screen = *_vm->_screen;
UserInterface &ui = *_vm->_ui;
bool flag;
_walkedInScene = false;
// Reset the list of walkable areas
_zones.clear();
_zones.push_back(Common::Rect(0, 0, SHERLOCK_SCREEN_WIDTH, SHERLOCK_SCREEN_HEIGHT));
_descText.clear();
_comments = "";
_bgShapes.clear();
_cAnim.clear();
_sequenceBuffer.clear();
//
// Load the room resource file for the scene
//
if (_vm->getPlatform() != Common::kPlatform3DO) {
// PC version
Common::String roomFilename = filename + ".rrm";
_roomFilename = roomFilename;
flag = _vm->_res->exists(roomFilename);
if (flag) {
Common::SeekableReadStream *rrmStream = _vm->_res->load(roomFilename);
rrmStream->seek(39);
if (IS_SERRATED_SCALPEL) {
_version = rrmStream->readByte();
_lzwMode = _version == 10;
} else {
_lzwMode = rrmStream->readByte() > 0;
}
// Go to header and read it in
rrmStream->seek(rrmStream->readUint32LE());
BgFileHeader bgHeader;
bgHeader.load(*rrmStream, IS_ROSE_TATTOO);
_invGraphicItems = bgHeader._numImages + 1;
if (IS_ROSE_TATTOO) {
screen.initPaletteFade(bgHeader._bytesWritten);
rrmStream->read(screen._cMap, PALETTE_SIZE);
screen.translatePalette(screen._cMap);
paletteLoaded();
// Read in background
if (_lzwMode) {
res.decompress(*rrmStream, (byte *)screen._backBuffer1.getPixels(), SHERLOCK_SCREEN_WIDTH * SHERLOCK_SCREEN_HEIGHT);
} else {
rrmStream->read(screen._backBuffer1.getPixels(), SHERLOCK_SCREEN_WIDTH * SHERLOCK_SCREEN_HEIGHT);
}
}
// Read in the shapes header info
Common::Array<BgFileHeaderInfo> bgInfo;
bgInfo.resize(bgHeader._numStructs);
for (uint idx = 0; idx < bgInfo.size(); ++idx)
bgInfo[idx].load(*rrmStream);
// Read information
if (IS_ROSE_TATTOO) {
// Load shapes
Common::SeekableReadStream *infoStream = !_lzwMode ? rrmStream : res.decompress(*rrmStream, bgHeader._numStructs * 625);
_bgShapes.resize(bgHeader._numStructs);
for (int idx = 0; idx < bgHeader._numStructs; ++idx)
_bgShapes[idx].load(*infoStream, _vm->getGameID() == GType_RoseTattoo);
if (_lzwMode)
delete infoStream;
// Load description text
_descText.resize(bgHeader._descSize);
if (_lzwMode)
res.decompress(*rrmStream, (byte *)&_descText[0], bgHeader._descSize);
else
rrmStream->read(&_descText[0], bgHeader._descSize);
// Load sequences
_sequenceBuffer.resize(bgHeader._seqSize);
if (_lzwMode)
res.decompress(*rrmStream, &_sequenceBuffer[0], bgHeader._seqSize);
else
rrmStream->read(&_sequenceBuffer[0], bgHeader._seqSize);
} else if (!_lzwMode) {
// Serrated Scalpel uncompressed info
_bgShapes.resize(bgHeader._numStructs);
for (int idx = 0; idx < bgHeader._numStructs; ++idx)
_bgShapes[idx].load(*rrmStream, false);
if (bgHeader._descSize) {
_descText.resize(bgHeader._descSize);
rrmStream->read(&_descText[0], bgHeader._descSize);
}
if (bgHeader._seqSize) {
_sequenceBuffer.resize(bgHeader._seqSize);
rrmStream->read(&_sequenceBuffer[0], bgHeader._seqSize);
}
} else {
// Serrated Scalpel compressed info
Common::SeekableReadStream *infoStream;
// Read shapes
infoStream = Resources::decompressLZ(*rrmStream, bgHeader._numStructs * 569);
_bgShapes.resize(bgHeader._numStructs);
for (int idx = 0; idx < bgHeader._numStructs; ++idx)
_bgShapes[idx].load(*infoStream, false);
delete infoStream;
// Read description texts
if (bgHeader._descSize) {
infoStream = Resources::decompressLZ(*rrmStream, bgHeader._descSize);
_descText.resize(bgHeader._descSize);
infoStream->read(&_descText[0], bgHeader._descSize);
delete infoStream;
}
// Read sequences
if (bgHeader._seqSize) {
infoStream = Resources::decompressLZ(*rrmStream, bgHeader._seqSize);
_sequenceBuffer.resize(bgHeader._seqSize);
infoStream->read(&_sequenceBuffer[0], bgHeader._seqSize);
delete infoStream;
}
}
// Set up the list of images used by the scene
_images.resize(bgHeader._numImages + 1);
for (int idx = 0; idx < bgHeader._numImages; ++idx) {
_images[idx + 1]._filesize = bgInfo[idx]._filesize;
_images[idx + 1]._maxFrames = bgInfo[idx]._maxFrames;
// Read in the image data
Common::SeekableReadStream *imageStream = _lzwMode ?
res.decompress(*rrmStream, bgInfo[idx]._filesize) :
rrmStream->readStream(bgInfo[idx]._filesize);
_images[idx + 1]._images = new ImageFile(*imageStream);
delete imageStream;
}
// Set up the bgShapes
for (int idx = 0; idx < bgHeader._numStructs; ++idx) {
_bgShapes[idx]._images = _images[_bgShapes[idx]._misc]._images;
_bgShapes[idx]._imageFrame = !_bgShapes[idx]._images ? (ImageFrame *)nullptr :
&(*_bgShapes[idx]._images)[0];
_bgShapes[idx]._examine = Common::String(&_descText[_bgShapes[idx]._descOffset]);
_bgShapes[idx]._sequences = &_sequenceBuffer[_bgShapes[idx]._sequenceOffset];
_bgShapes[idx]._misc = 0;
_bgShapes[idx]._seqCounter = 0;
_bgShapes[idx]._seqCounter2 = 0;
_bgShapes[idx]._seqStack = 0;
_bgShapes[idx]._frameNumber = -1;
_bgShapes[idx]._oldPosition = Common::Point(0, 0);
_bgShapes[idx]._oldSize = Common::Point(1, 1);
}
// Load in cAnim list
_cAnim.clear();
if (bgHeader._numcAnimations) {
int animSize = IS_SERRATED_SCALPEL ? 65 : 47;
Common::SeekableReadStream *cAnimStream = _lzwMode ?
res.decompress(*rrmStream, animSize * bgHeader._numcAnimations) :
rrmStream->readStream(animSize * bgHeader._numcAnimations);
// Load cAnim offset table as well
uint32 *cAnimOffsetTablePtr = new uint32[bgHeader._numcAnimations];
uint32 *cAnimOffsetPtr = cAnimOffsetTablePtr;
memset(cAnimOffsetTablePtr, 0, bgHeader._numcAnimations);
if (IS_SERRATED_SCALPEL) {
// Save current stream offset
int32 curOffset = rrmStream->pos();
rrmStream->seek(44); // Seek to cAnim-Offset-Table
for (uint16 curCAnim = 0; curCAnim < bgHeader._numcAnimations; curCAnim++) {
*cAnimOffsetPtr = rrmStream->readUint32LE();
cAnimOffsetPtr++;
}
// Seek back to original stream offset
rrmStream->seek(curOffset);
}
// TODO: load offset table for Rose Tattoo as well
// Go to the start of the cAnimOffsetTable
cAnimOffsetPtr = cAnimOffsetTablePtr;
_cAnim.resize(bgHeader._numcAnimations);
for (uint idx = 0; idx < _cAnim.size(); ++idx) {
_cAnim[idx].load(*cAnimStream, IS_ROSE_TATTOO, *cAnimOffsetPtr);
cAnimOffsetPtr++;
}
delete cAnimStream;
delete[] cAnimOffsetTablePtr;
}
// Read in the room bounding areas
int size = rrmStream->readUint16LE();
Common::SeekableReadStream *boundsStream = !_lzwMode ? rrmStream :
res.decompress(*rrmStream, size);
_zones.resize(size / 10);
for (uint idx = 0; idx < _zones.size(); ++idx) {
_zones[idx].left = boundsStream->readSint16LE();
_zones[idx].top = boundsStream->readSint16LE();
_zones[idx].setWidth(boundsStream->readSint16LE() + 1);
_zones[idx].setHeight(boundsStream->readSint16LE() + 1);
boundsStream->skip(2); // Skip unused scene number field
}
if (_lzwMode)
delete boundsStream;
// Ensure we've reached the path version byte
if (rrmStream->readByte() != (IS_SERRATED_SCALPEL ? 254 : 251))
error("Invalid scene path data");
// Load the walk directory and walk data
assert(_zones.size() < MAX_ZONES);
for (uint idx1 = 0; idx1 < _zones.size(); ++idx1) {
Common::fill(&_walkDirectory[idx1][0], &_walkDirectory[idx1][MAX_ZONES], 0);
for (uint idx2 = 0; idx2 < _zones.size(); ++idx2)
_walkDirectory[idx1][idx2] = rrmStream->readSint16LE();
}
// Read in the walk data
size = rrmStream->readUint16LE();
Common::SeekableReadStream *walkStream = !_lzwMode ? rrmStream :
res.decompress(*rrmStream, size);
int startPos = walkStream->pos();
while ((walkStream->pos() - startPos) < size) {
_walkPoints.push_back(WalkArray());
_walkPoints[_walkPoints.size() - 1]._fileOffset = walkStream->pos() - startPos;
_walkPoints[_walkPoints.size() - 1].load(*walkStream, IS_ROSE_TATTOO);
}
if (_lzwMode)
delete walkStream;
// Translate the file offsets of the walk directory to indexes in the loaded walk data
for (uint idx1 = 0; idx1 < _zones.size(); ++idx1) {
for (uint idx2 = 0; idx2 < _zones.size(); ++idx2) {
int fileOffset = _walkDirectory[idx1][idx2];
if (fileOffset == -1)
continue;
uint dataIndex = 0;
while (dataIndex < _walkPoints.size() && _walkPoints[dataIndex]._fileOffset != fileOffset)
++dataIndex;
assert(dataIndex < _walkPoints.size());
_walkDirectory[idx1][idx2] = dataIndex;
}
}
if (IS_ROSE_TATTOO) {
// Read in the entrance
_entrance.load(*rrmStream);
// Load scale zones
_scaleZones.resize(rrmStream->readByte());
for (uint idx = 0; idx < _scaleZones.size(); ++idx)
_scaleZones[idx].load(*rrmStream);
}
// Read in the exits
_exitZone = -1;
int numExits = rrmStream->readByte();
_exits.resize(numExits);
for (int idx = 0; idx < numExits; ++idx)
_exits[idx].load(*rrmStream, IS_ROSE_TATTOO);
if (IS_SERRATED_SCALPEL)
// Read in the entrance
_entrance.load(*rrmStream);
// Initialize sound list
int numSounds = rrmStream->readByte();
_sounds.resize(numSounds);
for (int idx = 0; idx < numSounds; ++idx)
_sounds[idx].load(*rrmStream);
loadSceneSounds();
if (IS_ROSE_TATTOO) {
// Load the object sound list
char buffer[27];
_objSoundList.resize(rrmStream->readUint16LE());
for (uint idx = 0; idx < _objSoundList.size(); ++idx) {
rrmStream->read(buffer, 27);
_objSoundList[idx] = Common::String(buffer);
}
} else {
// Read in palette
rrmStream->read(screen._cMap, PALETTE_SIZE);
screen.translatePalette(screen._cMap);
Common::copy(screen._cMap, screen._cMap + PALETTE_SIZE, screen._sMap);
// Read in the background
Common::SeekableReadStream *bgStream = !_lzwMode ? rrmStream :
res.decompress(*rrmStream, SHERLOCK_SCREEN_WIDTH * SHERLOCK_SCENE_HEIGHT);
bgStream->read(screen._backBuffer1.getPixels(), SHERLOCK_SCREEN_WIDTH * SHERLOCK_SCENE_HEIGHT);
if (_lzwMode)
delete bgStream;
}
// Backup the image and set the palette
screen._backBuffer2.blitFrom(screen._backBuffer1);
screen.setPalette(screen._cMap);
delete rrmStream;
}
} else {
// === 3DO version ===
_roomFilename = "rooms/" + filename + ".rrm";
flag = _vm->_res->exists(_roomFilename);
if (!flag)
error("loadScene: 3DO room data file not found");
Common::SeekableReadStream *roomStream = _vm->_res->load(_roomFilename);
// Read 3DO header
roomStream->skip(4); // UINT32: offset graphic data?
uint16 header3DO_numStructs = roomStream->readUint16BE();
uint16 header3DO_numImages = roomStream->readUint16BE();
uint16 header3DO_numAnimations = roomStream->readUint16BE();
roomStream->skip(6);
uint32 header3DO_bgInfo_offset = roomStream->readUint32BE() + 0x80;
uint32 header3DO_bgInfo_size = roomStream->readUint32BE();
uint32 header3DO_bgShapes_offset = roomStream->readUint32BE() + 0x80;
uint32 header3DO_bgShapes_size = roomStream->readUint32BE();
uint32 header3DO_descriptions_offset = roomStream->readUint32BE() + 0x80;
uint32 header3DO_descriptions_size = roomStream->readUint32BE();
uint32 header3DO_sequence_offset = roomStream->readUint32BE() + 0x80;
uint32 header3DO_sequence_size = roomStream->readUint32BE();
uint32 header3DO_cAnim_offset = roomStream->readUint32BE() + 0x80;
uint32 header3DO_cAnim_size = roomStream->readUint32BE();
uint32 header3DO_roomBounding_offset = roomStream->readUint32BE() + 0x80;
uint32 header3DO_roomBounding_size = roomStream->readUint32BE();
uint32 header3DO_walkDirectory_offset = roomStream->readUint32BE() + 0x80;
uint32 header3DO_walkDirectory_size = roomStream->readUint32BE();
uint32 header3DO_walkData_offset = roomStream->readUint32BE() + 0x80;
uint32 header3DO_walkData_size = roomStream->readUint32BE();
uint32 header3DO_exits_offset = roomStream->readUint32BE() + 0x80;
uint32 header3DO_exits_size = roomStream->readUint32BE();
uint32 header3DO_entranceData_offset = roomStream->readUint32BE() + 0x80;
uint32 header3DO_entranceData_size = roomStream->readUint32BE();
uint32 header3DO_soundList_offset = roomStream->readUint32BE() + 0x80;
uint32 header3DO_soundList_size = roomStream->readUint32BE();
uint32 header3DO_unknown_offset = roomStream->readUint32BE() + 0x80;
uint32 header3DO_unknown_size = roomStream->readUint32BE();
uint32 header3DO_bgGraphicData_offset = roomStream->readUint32BE() + 0x80;
uint32 header3DO_bgGraphicData_size = roomStream->readUint32BE();
int32 header3DO_soundList_count = header3DO_soundList_size / 9;
_invGraphicItems = header3DO_numImages + 1;
// === BGINFO === read in the shapes header info
Common::Array<BgFileHeaderInfo> bgInfo;
roomStream->seek(header3DO_bgInfo_offset);
bgInfo.resize(header3DO_numStructs);
for (uint idx = 0; idx < bgInfo.size(); ++idx)
bgInfo[idx].load3DO(*roomStream);
// === BGSHAPES === read in the shapes info
roomStream->seek(header3DO_bgShapes_offset);
_bgShapes.resize(header3DO_numStructs);
for (int idx = 0; idx < header3DO_numStructs; ++idx)
_bgShapes[idx].load3DO(*roomStream);
// === DESCRIPTION === read description text
if (header3DO_descriptions_size) {
roomStream->seek(header3DO_descriptions_offset);
_descText.resize(header3DO_descriptions_size);
roomStream->read(&_descText[0], header3DO_descriptions_size);
}
// === SEQUENCE === read sequence buffer
if (header3DO_sequence_size) {
roomStream->seek(header3DO_sequence_offset);
_sequenceBuffer.resize(header3DO_sequence_size);
roomStream->read(&_sequenceBuffer[0], header3DO_sequence_size);
}
// === IMAGES === set up the list of images used by the scene
roomStream->seek(header3DO_bgGraphicData_offset);
_images.resize(header3DO_numImages + 1);
for (int idx = 0; idx < header3DO_numImages; ++idx) {
_images[idx + 1]._filesize = bgInfo[idx]._filesize;
_images[idx + 1]._maxFrames = bgInfo[idx]._maxFrames;
// Read image data into memory
Common::SeekableReadStream *imageStream = roomStream->readStream(bgInfo[idx]._filesize);
// Load image data into an ImageFile array as room file data
// which is basically a fixed header, followed by a raw cel header, followed by regular cel data
_images[idx + 1]._images = new ImageFile3DO(*imageStream, true);
delete imageStream;
}
// === BGSHAPES === Set up the bgShapes
for (int idx = 0; idx < header3DO_numStructs; ++idx) {
_bgShapes[idx]._images = _images[_bgShapes[idx]._misc]._images;
_bgShapes[idx]._imageFrame = !_bgShapes[idx]._images ? (ImageFrame *)nullptr :
&(*_bgShapes[idx]._images)[0];
_bgShapes[idx]._examine = Common::String(&_descText[_bgShapes[idx]._descOffset]);
_bgShapes[idx]._sequences = &_sequenceBuffer[_bgShapes[idx]._sequenceOffset];
_bgShapes[idx]._misc = 0;
_bgShapes[idx]._seqCounter = 0;
_bgShapes[idx]._seqCounter2 = 0;
_bgShapes[idx]._seqStack = 0;
_bgShapes[idx]._frameNumber = -1;
_bgShapes[idx]._oldPosition = Common::Point(0, 0);
_bgShapes[idx]._oldSize = Common::Point(1, 1);
}
// === CANIM === read cAnim list
_cAnim.clear();
if (header3DO_numAnimations) {
roomStream->seek(header3DO_cAnim_offset);
Common::SeekableReadStream *cAnimStream = roomStream->readStream(header3DO_cAnim_size);
uint32 *cAnimOffsetTablePtr = new uint32[header3DO_numAnimations];
uint32 *cAnimOffsetPtr = cAnimOffsetTablePtr;
memset(cAnimOffsetTablePtr, 0, header3DO_numAnimations);
// Seek to end of graphics data and load cAnim offset table from there
roomStream->seek(header3DO_bgGraphicData_offset + header3DO_bgGraphicData_size);
for (uint16 curCAnim = 0; curCAnim < header3DO_numAnimations; curCAnim++) {
*cAnimOffsetPtr = roomStream->readUint32BE();
cAnimOffsetPtr++;
}
// Go to the start of the cAnimOffsetTable
cAnimOffsetPtr = cAnimOffsetTablePtr;
_cAnim.resize(header3DO_numAnimations);
for (uint idx = 0; idx < _cAnim.size(); ++idx) {
_cAnim[idx].load3DO(*cAnimStream, *cAnimOffsetPtr);
cAnimOffsetPtr++;
}
delete cAnimStream;
delete[] cAnimOffsetTablePtr;
}
// === BOUNDING AREAS === Read in the room bounding areas
int roomBoundingCount = header3DO_roomBounding_size / 12;
roomStream->seek(header3DO_roomBounding_offset);
_zones.resize(roomBoundingCount);
for (uint idx = 0; idx < _zones.size(); ++idx) {
_zones[idx].left = roomStream->readSint16BE();
_zones[idx].top = roomStream->readSint16BE();
_zones[idx].setWidth(roomStream->readSint16BE() + 1);
_zones[idx].setHeight(roomStream->readSint16BE() + 1);
roomStream->skip(4); // skip UINT32
}
// === WALK DIRECTORY === Load the walk directory
roomStream->seek(header3DO_walkDirectory_offset);
assert(_zones.size() < MAX_ZONES);
for (uint idx1 = 0; idx1 < _zones.size(); ++idx1) {
for (uint idx2 = 0; idx2 < _zones.size(); ++idx2)
_walkDirectory[idx1][idx2] = roomStream->readSint16BE();
}
// === WALK DATA === Read in the walk data
roomStream->seek(header3DO_walkData_offset);
int startPos = roomStream->pos();
while ((roomStream->pos() - startPos) < header3DO_walkData_size) {
_walkPoints.push_back(WalkArray());
_walkPoints[_walkPoints.size() - 1]._fileOffset = roomStream->pos() - startPos;
_walkPoints[_walkPoints.size() - 1].load(*roomStream, false);
}
// Translate the file offsets of the walk directory to indexes in the loaded walk data
for (uint idx1 = 0; idx1 < _zones.size(); ++idx1) {
for (uint idx2 = 0; idx2 < _zones.size(); ++idx2) {
int fileOffset = _walkDirectory[idx1][idx2];
if (fileOffset == -1)
continue;
uint dataIndex = 0;
while (dataIndex < _walkPoints.size() && _walkPoints[dataIndex]._fileOffset != fileOffset)
++dataIndex;
assert(dataIndex < _walkPoints.size());
_walkDirectory[idx1][idx2] = dataIndex;
}
}
// === EXITS === Read in the exits
roomStream->seek(header3DO_exits_offset);
int exitsCount = header3DO_exits_size / 20;
_exitZone = -1;
_exits.resize(exitsCount);
for (int idx = 0; idx < exitsCount; ++idx)
_exits[idx].load3DO(*roomStream);
// === ENTRANCE === Read in the entrance
roomStream->seek(header3DO_entranceData_offset);
_entrance.load3DO(*roomStream);
// === SOUND LIST === Initialize sound list
roomStream->seek(header3DO_soundList_offset);
_sounds.resize(header3DO_soundList_count);
for (int idx = 0; idx < header3DO_soundList_count; ++idx)
_sounds[idx].load3DO(*roomStream);
delete roomStream;
// === BACKGROUND PICTURE ===
// load from file rooms\[filename].bg
// it's uncompressed 15-bit RGB555 data
Common::String roomBackgroundFilename = "rooms/" + filename + ".bg";
flag = _vm->_res->exists(roomBackgroundFilename);
if (!flag)
error("loadScene: 3DO room background file not found (%s)", roomBackgroundFilename.c_str());
Common::File roomBackgroundStream;
if (!roomBackgroundStream.open(roomBackgroundFilename))
error("Could not load file - %s", roomBackgroundFilename.c_str());
int totalPixelCount = SHERLOCK_SCREEN_WIDTH * SHERLOCK_SCENE_HEIGHT;
uint16 *roomBackgroundDataPtr = NULL;
uint16 *pixelSourcePtr = NULL;
uint16 *pixelDestPtr = (uint16 *)screen._backBuffer1.getPixels();
uint16 curPixel = 0;
roomBackgroundDataPtr = new uint16[totalPixelCount];
roomBackgroundStream.read(roomBackgroundDataPtr, totalPixelCount * 2);
roomBackgroundStream.close();
// Convert data from RGB555 to RGB565
pixelSourcePtr = roomBackgroundDataPtr;
for (int pixels = 0; pixels < totalPixelCount; pixels++) {
curPixel = READ_BE_UINT16(pixelSourcePtr++);
byte curPixelRed = (curPixel >> 10) & 0x1F;
byte curPixelGreen = (curPixel >> 5) & 0x1F;
byte curPixelBlue = curPixel & 0x1F;
*pixelDestPtr = ((curPixelRed << 11) | (curPixelGreen << 6) | (curPixelBlue));
pixelDestPtr++;
}
delete[] roomBackgroundDataPtr;
#if 0
// code to show the background
screen.blitFrom(screen._backBuffer1);
_vm->_events->wait(10000);
#endif
// Backup the image
screen._backBuffer2.blitFrom(screen._backBuffer1);
}
// Handle drawing any on-screen interface
ui.drawInterface();
checkSceneStatus();
if (!saves._justLoaded) {
for (uint idx = 0; idx < _bgShapes.size(); ++idx) {
if (_bgShapes[idx]._type == HIDDEN && _bgShapes[idx]._aType == TALK_EVERY)
_bgShapes[idx].toggleHidden();
}
// Check for TURNON objects
for (uint idx = 0; idx < _bgShapes.size(); ++idx) {
if (_bgShapes[idx]._type == HIDDEN && (_bgShapes[idx]._flags & TURNON_OBJ))
_bgShapes[idx].toggleHidden();
}
// Check for TURNOFF objects
for (uint idx = 0; idx < _bgShapes.size(); ++idx) {
if (_bgShapes[idx]._type != HIDDEN && (_bgShapes[idx]._flags & TURNOFF_OBJ) &&
_bgShapes[idx]._type != INVALID)
_bgShapes[idx].toggleHidden();
if (_bgShapes[idx]._type == HIDE_SHAPE)
// Hiding isn't needed, since objects aren't drawn yet
_bgShapes[idx]._type = HIDDEN;
}
}
checkSceneFlags(false);
checkInventory();
// Handle starting any music for the scene
if (IS_SERRATED_SCALPEL && music._musicOn && music.loadSong(_currentScene))
music.startSong();
// Load walking images if not already loaded
people.loadWalk();
// Transition to the scene and setup entrance co-ordinates and animations
transitionToScene();
// Player has not yet walked in this scene
_walkedInScene = false;
saves._justLoaded = false;
events.clearEvents();
return flag;
}
void Scene::loadSceneSounds() {
Sound &sound = *_vm->_sound;
for (uint idx = 0; idx < _sounds.size(); ++idx)
sound.loadSound(_sounds[idx]._name, _sounds[idx]._priority);
}
void Scene::checkSceneStatus() {
if (_sceneStats[_currentScene][64]) {
for (uint idx = 0; idx < 64; ++idx) {
bool flag = _sceneStats[_currentScene][idx];
if (idx < _bgShapes.size()) {
Object &obj = _bgShapes[idx];
if (flag) {
// No shape to erase, so flag as hidden
obj._type = HIDDEN;
} else if (obj._images == nullptr || obj._images->size() == 0) {
// No shape
obj._type = NO_SHAPE;
} else {
obj._type = ACTIVE_BG_SHAPE;
}
} else {
// Finished checks
return;
}
}
}
}
void Scene::saveSceneStatus() {
// Flag any objects for the scene that have been altered
int count = MIN((int)_bgShapes.size(), 64);
for (int idx = 0; idx < count; ++idx) {
Object &obj = _bgShapes[idx];
_sceneStats[_currentScene][idx] = obj._type == HIDDEN || obj._type == REMOVE
|| obj._type == HIDE_SHAPE || obj._type == INVALID;
}
// Flag scene as having been visited