NANCY: Separate SoundDescription reading functions

This commit is contained in:
Kaloyan Chehlarski 2023-05-09 13:20:47 +03:00
parent 3a39e75388
commit 685eccf1c2
20 changed files with 141 additions and 69 deletions

View File

@ -64,17 +64,17 @@ void BombPuzzle::readData(Common::SeekableReadStream &stream) {
_solveOrder[i] = stream.readByte();
}
_snipSound.readData(stream, SoundDescription::kNormal);
_noToolSound.readData(stream, SoundDescription::kNormal);
_snipSound.readNormal(stream);
_noToolSound.readNormal(stream);
_toolID = stream.readUint16LE();
_solveSceneChange.readData(stream);
stream.skip(2);
_solveSound.readData(stream, SoundDescription::kNormal);
_solveSound.readNormal(stream);
_failSceneChange.readData(stream);
stream.skip(2);
_failSound.readData(stream, SoundDescription::kNormal);
_failSound.readNormal(stream);
switch (NancySceneState.getDifficulty()) {
case 0:

View File

@ -58,7 +58,7 @@ void ConversationSound::readData(Common::SeekableReadStream &stream) {
ser.setVersion(g_nancy->getGameType());
if (ser.getVersion() >= kGameTypeNancy2) {
_sound.readData(stream, SoundDescription::kNormal);
_sound.readNormal(stream);
}
char *rawText = new char[1500];
@ -67,10 +67,10 @@ void ConversationSound::readData(Common::SeekableReadStream &stream) {
delete[] rawText;
if (ser.getVersion() <= kGameTypeNancy1) {
_sound.readData(stream, SoundDescription::kNormal);
_sound.readNormal(stream);
}
_responseGenericSound.readData(stream, SoundDescription::kNormal);
_responseGenericSound.readNormal(stream);
ser.skip(1);
ser.syncAsByte(_conditionalResponseCharacterID);
ser.syncAsByte(_goodbyeResponseCharacterID);

View File

@ -79,11 +79,11 @@ void LeverPuzzle::readData(Common::SeekableReadStream &stream) {
_correctSequence.push_back(stream.readByte());
}
_moveSound.readData(stream, SoundDescription::kNormal);
_noMoveSound.readData(stream, SoundDescription::kNormal);
_moveSound.readNormal(stream);
_noMoveSound.readNormal(stream);
_solveExitScene.readData(stream);
_solveSoundDelay = stream.readUint16LE();
_solveSound.readData(stream, SoundDescription::kNormal);
_solveSound.readNormal(stream);
_exitScene.readData(stream);
readRect(stream, _exitHotspot);
}

View File

@ -101,12 +101,12 @@ void OrderingPuzzle::readData(Common::SeekableReadStream &stream) {
ser.skip(15 - _sequenceLength, kGameTypeNancy1);
if (ser.getVersion() != kGameTypeVampire) {
_clickSound.readData(stream, SoundDescription::kNormal);
_clickSound.readNormal(stream);
}
_solveExitScene.readData(stream, ser.getVersion() == kGameTypeVampire);
ser.syncAsUint16LE(_solveSoundDelay);
_solveSound.readData(stream, SoundDescription::kNormal);
_solveSound.readNormal(stream);
_exitScene.readData(stream, ser.getVersion() == kGameTypeVampire);
readRect(stream, _exitHotspot);
}

View File

@ -85,7 +85,7 @@ void Overlay::readData(Common::SeekableReadStream &stream) {
_sceneChange.readData(stream);
_flagsOnTrigger.readData(stream);
_sound.readData(stream, SoundDescription::kNormal);
_sound.readNormal(stream);
uint numViewportFrames = stream.readUint16LE();
if (_overlayType == kPlayOverlayAnimated) {

View File

@ -67,13 +67,13 @@ void OverrideLockPuzzle::readData(Common::SeekableReadStream &stream) {
readRectArray(stream, _lightDests, num);
stream.skip((10 - num) * 16);
_buttonSound.readData(stream, SoundDescription::kNormal);
_wrongSound.readData(stream, SoundDescription::kNormal);
_buttonSound.readNormal(stream);
_wrongSound.readNormal(stream);
_buttonPopTime = stream.readUint16LE();
_solveExitScene.readData(stream);
_solveSound.readData(stream, SoundDescription::kNormal);
_solveSound.readNormal(stream);
_exitScene.readData(stream);
readRect(stream, _exitHotspot);

View File

@ -56,9 +56,9 @@ void PasswordPuzzle::readData(Common::SeekableReadStream &stream) {
buf[19] = '\0';
_password = buf;
_solveExitScene.readData(stream);
_solveSound.readData(stream, SoundDescription::kNormal);
_solveSound.readNormal(stream);
_failExitScene.readData(stream);
_failSound.readData(stream, SoundDescription::kNormal);
_failSound.readNormal(stream);
_exitScene.readData(stream);
readRect(stream, _exitHotspot);
}

View File

@ -554,7 +554,7 @@ void ShowInventoryItem::execute() {
}
void PlayDigiSoundAndDie::readData(Common::SeekableReadStream &stream) {
_sound.readData(stream, SoundDescription::kDIGI);
_sound.readDIGI(stream);
_sceneChange.readData(stream, g_nancy->getGameType() == kGameTypeVampire);
_flagOnTrigger.label = stream.readSint16LE();
@ -589,7 +589,7 @@ void PlayDigiSoundAndDie::execute() {
}
void PlaySoundPanFrameAnchorAndDie::readData(Common::SeekableReadStream &stream) {
_sound.readData(stream, SoundDescription::kDIGI);
_sound.readDIGI(stream);
stream.skip(2);
}
@ -600,7 +600,7 @@ void PlaySoundPanFrameAnchorAndDie::execute() {
}
void PlaySoundMultiHS::readData(Common::SeekableReadStream &stream) {
_sound.readData(stream, SoundDescription::kNormal);
_sound.readNormal(stream);
if (g_nancy->getGameType() != kGameTypeVampire) {
_sceneChange.readData(stream);
@ -653,7 +653,7 @@ void PlaySoundMultiHS::execute() {
void HintSystem::readData(Common::SeekableReadStream &stream) {
_characterID = stream.readByte();
_genericSound.readData(stream, SoundDescription::kNormal);
_genericSound.readNormal(stream);
}
void HintSystem::execute() {

View File

@ -53,13 +53,13 @@ void RiddlePuzzle::readData(Common::SeekableReadStream &stream) {
_textboxTextFontID = stream.readUint16LE();
_cursorBlinkTime = stream.readUint16LE();
readRect(stream, _screenPosition);
_typeSound.readData(stream, SoundDescription::kNormal);
_eraseSound.readData(stream, SoundDescription::kNormal);
_enterSound.readData(stream, SoundDescription::kNormal);
_typeSound.readNormal(stream);
_eraseSound.readNormal(stream);
_enterSound.readNormal(stream);
_successSceneChange.readData(stream);
_successSound.readData(stream, SoundDescription::kNormal);
_successSound.readNormal(stream);
_exitSceneChange.readData(stream);
_exitSound.readData(stream, SoundDescription::kNormal);
_exitSound.readNormal(stream);
readRect(stream, _exitHotspot);
_riddles.resize(stream.readUint16LE()) ;
@ -72,7 +72,7 @@ void RiddlePuzzle::readData(Common::SeekableReadStream &stream) {
stream.read(buf, 128);
buf[127] = '\0';
riddle.text = buf;
riddle.sound.readData(stream, SoundDescription::kNormal);
riddle.sound.readNormal(stream);
for (uint j = 0; j < 8; ++j) {
stream.read(buf, 20);
@ -84,9 +84,9 @@ void RiddlePuzzle::readData(Common::SeekableReadStream &stream) {
}
riddle.sceneIncorrect.readData(stream);
riddle.soundIncorrect.readData(stream, SoundDescription::kNormal);
riddle.soundIncorrect.readNormal(stream);
riddle.sceneCorrect.readData(stream);
riddle.soundCorrect.readData(stream, SoundDescription::kNormal);
riddle.soundCorrect.readNormal(stream);
}
}

View File

@ -88,12 +88,12 @@ void RippedLetterPuzzle::readData(Common::SeekableReadStream &stream) {
_solveRotations[i] = stream.readByte();
}
_takeSound.readData(stream, SoundDescription::kNormal);
_dropSound.readData(stream, SoundDescription::kNormal);
_rotateSound.readData(stream, SoundDescription::kNormal);
_takeSound.readNormal(stream);
_dropSound.readNormal(stream);
_rotateSound.readNormal(stream);
_solveExitScene.readData(stream);
_solveSound.readData(stream, SoundDescription::kNormal);
_solveSound.readNormal(stream);
_exitScene.readData(stream);
readRect(stream, _exitHotspot);

View File

@ -92,10 +92,10 @@ void RotatingLockPuzzle::readData(Common::SeekableReadStream &stream) {
stream.skip(8 - numDials);
_clickSound.readData(stream, SoundDescription::kNormal);
_clickSound.readNormal(stream);
_solveExitScene.readData(stream);
_solveSoundDelay = stream.readUint16LE();
_solveSound.readData(stream, SoundDescription::kNormal);
_solveSound.readNormal(stream);
_exitScene.readData(stream);
readRect(stream, _exitHotspot);

View File

@ -74,7 +74,7 @@ void PlaySecondaryMovie::readData(Common::SeekableReadStream &stream) {
}
_triggerFlags.readData(stream);
_sound.readData(stream, SoundDescription::kNormal);
_sound.readNormal(stream);
_sceneChange.readData(stream, ser.getVersion() == kGameTypeVampire);
uint16 numVideoDescs;

View File

@ -104,9 +104,9 @@ void SliderPuzzle::readData(Common::SeekableReadStream &stream) {
stream.skip((6 - _height) * 6 * 2);
_clickSound.readData(stream, SoundDescription::kNormal);
_clickSound.readNormal(stream);
_solveExitScene.readData(stream);
_solveSound.readData(stream, SoundDescription::kNormal);
_solveSound.readNormal(stream);
_exitScene.readData(stream);
readRect(stream, _exitHotspot);
}

View File

@ -65,12 +65,12 @@ void Telephone::readData(Common::SeekableReadStream &stream) {
}
}
_genericDialogueSound.readData(stream, SoundDescription::kNormal);
_genericButtonSound.readData(stream, SoundDescription::kNormal);
_ringSound.readData(stream, SoundDescription::kNormal);
_dialToneSound.readData(stream, SoundDescription::kNormal);
_dialAgainSound.readData(stream, SoundDescription::kNormal);
_hangUpSound.readData(stream, SoundDescription::kNormal);
_genericDialogueSound.readNormal(stream);
_genericButtonSound.readNormal(stream);
_ringSound.readNormal(stream);
_dialToneSound.readNormal(stream);
_dialAgainSound.readNormal(stream);
_hangUpSound.readNormal(stream);
_buttonSoundNames.reserve(12);
for (uint i = 0; i < 12; ++i) {

View File

@ -81,12 +81,12 @@ void TowerPuzzle::readData(Common::SeekableReadStream &stream) {
}
}
_takeSound.readData(stream, SoundDescription::kNormal);
_dropSound.readData(stream, SoundDescription::kNormal);
_takeSound.readNormal(stream);
_dropSound.readNormal(stream);
_solveExitScene._sceneChange.readData(stream);
stream.skip(2);
_solveSound.readData(stream, SoundDescription::kNormal);
_solveSound.readNormal(stream);
_solveExitScene._flag.label = stream.readSint16LE();
_solveExitScene._flag.flag = stream.readByte();

View File

@ -86,19 +86,17 @@ void SecondaryVideoDescription::readData(Common::SeekableReadStream &stream) {
stream.skip(0x20);
}
void SoundDescription::readData(Common::SeekableReadStream &stream, Type type) {
void SoundDescription::readNormal(Common::SeekableReadStream &stream) {
Common::Serializer s(&stream, nullptr);
s.setVersion(type);
s.setVersion(g_nancy->getGameType());
readFilename(s, name);
s.skip(4, kScene, kScene);
s.syncAsUint16LE(channelID);
s.skip(2); // PLAY_SOUND_FROM_HD = 1, PLAY_SOUND_FROM_CDROM = 2
s.skip(2); // PLAY_SOUND_AS_DIGI = 1, PLAY_SOUND_AS_STREAM = 2
s.skip(4, kNormal, kNormal);
s.skip(2, kMenu, kMenu);
s.skip(4);
s.syncAsUint16LE(numLoops);
uint16 loopType;
@ -111,10 +109,83 @@ void SoundDescription::readData(Common::SeekableReadStream &stream, Type type) {
s.syncAsUint16LE(volume);
s.skip(2); // Second volume, always (?) same as the first
s.syncAsUint32LE(samplesPerSec, kNormal, kNormal);
s.syncAsUint16LE(panAnchorFrame, kDIGI, kDIGI);
s.skip(2, kDIGI, kDIGI);
s.skip(4, kMenu, kScene);
s.syncAsUint32LE(samplesPerSec);
}
void SoundDescription::readDIGI(Common::SeekableReadStream &stream) {
Common::Serializer s(&stream, nullptr);
s.setVersion(g_nancy->getGameType());
readFilename(s, name);
s.syncAsUint16LE(channelID);
s.skip(2); // PLAY_SOUND_FROM_HD = 1, PLAY_SOUND_FROM_CDROM = 2
s.skip(2); // PLAY_SOUND_AS_DIGI = 1, PLAY_SOUND_AS_STREAM = 2
s.syncAsUint16LE(numLoops);
uint16 loopType;
s.syncAsUint16LE(loopType);
if (loopType != 0) { // LOOP_ONCE = 1, LOOP_INFINITE = 0
numLoops = 0;
}
s.skip(2);
s.syncAsUint16LE(volume);
s.skip(2); // Second volume, always (?) same as the first
s.syncAsUint16LE(panAnchorFrame);
s.skip(2);
}
void SoundDescription::readMenu(Common::SeekableReadStream &stream) {
Common::Serializer s(&stream, nullptr);
s.setVersion(g_nancy->getGameType());
readFilename(s, name);
s.syncAsUint16LE(channelID);
s.skip(2); // PLAY_SOUND_FROM_HD = 1, PLAY_SOUND_FROM_CDROM = 2
s.skip(2); // PLAY_SOUND_AS_DIGI = 1, PLAY_SOUND_AS_STREAM = 2
s.skip(2);
s.syncAsUint16LE(numLoops);
uint16 loopType;
s.syncAsUint16LE(loopType);
if (loopType != 0) { // LOOP_ONCE = 1, LOOP_INFINITE = 0
numLoops = 0;
}
s.skip(2);
s.syncAsUint16LE(volume);
s.skip(2); // Second volume, always (?) same as the first
s.skip(4);
}
void SoundDescription::readScene(Common::SeekableReadStream &stream) {
Common::Serializer s(&stream, nullptr);
s.setVersion(g_nancy->getGameType());
readFilename(s, name);
s.skip(4);
s.syncAsUint16LE(channelID);
s.skip(2); // PLAY_SOUND_FROM_HD = 1, PLAY_SOUND_FROM_CDROM = 2
s.skip(2); // PLAY_SOUND_AS_DIGI = 1, PLAY_SOUND_AS_STREAM = 2
s.syncAsUint16LE(numLoops);
uint16 loopType;
s.syncAsUint16LE(loopType);
if (loopType != 0) { // LOOP_ONCE = 1, LOOP_INFINITE = 0
numLoops = 0;
}
s.skip(2);
s.syncAsUint16LE(volume);
s.skip(2); // Second volume, always (?) same as the first
s.skip(4);
}
void ConditionalDialogue::readData(Common::SeekableReadStream &stream) {

View File

@ -172,8 +172,6 @@ struct SecondaryVideoDescription {
// Descrbes a single sound. Combines four different structs found in the data in one
struct SoundDescription {
enum Type { kNormal = 0, kDIGI = 1, kMenu = 2, kScene = 3 };
Common::String name;
uint16 channelID = 0;
uint16 numLoops = 0;
@ -181,7 +179,10 @@ struct SoundDescription {
uint16 panAnchorFrame = 0;
uint32 samplesPerSec = 0;
void readData(Common::SeekableReadStream &stream, Type type);
void readNormal(Common::SeekableReadStream &stream);
void readDIGI(Common::SeekableReadStream &stream);
void readMenu(Common::SeekableReadStream &stream);
void readScene(Common::SeekableReadStream &stream);
};
// Structs inside nancy.dat, which contains all the data that was

View File

@ -124,7 +124,7 @@ INV::INV(Common::SeekableReadStream *chunkStream) {
byte textBuf[60];
if (s.getVersion() >= kGameTypeNancy2) {
cantSound.readData(*chunkStream, SoundDescription::kNormal);
cantSound.readNormal(*chunkStream);
s.syncBytes(textBuf, 60);
textBuf[59] = '\0';
cantText = (char *)textBuf;
@ -167,14 +167,14 @@ INV::INV(Common::SeekableReadStream *chunkStream) {
textBuf[59] = '\0';
item.generalCantText = (char *)textBuf;
item.specificCantSound.readData(*chunkStream, SoundDescription::kNormal);
item.generalCantSound.readData(*chunkStream, SoundDescription::kNormal);
item.specificCantSound.readNormal(*chunkStream);
item.generalCantSound.readNormal(*chunkStream);
} else if (s.getVersion() >= kGameTypeNancy3) {
s.syncBytes(textBuf, 60);
textBuf[59] = '\0';
item.specificCantText = (char *)textBuf;
item.specificCantSound.readData(*chunkStream, SoundDescription::kNormal);
item.specificCantSound.readNormal(*chunkStream);
}
}
@ -246,7 +246,7 @@ MAP::MAP(Common::SeekableReadStream *chunkStream) {
sounds.resize(numMaps);
for (uint i = 0; i < numMaps; ++i) {
sounds[i].readData(*chunkStream, SoundDescription::kMenu);
sounds[i].readMenu(*chunkStream);
}
s.skip(0x20);
@ -345,7 +345,7 @@ CRED::CRED(Common::SeekableReadStream *chunkStream) {
updateTime = chunkStream->readUint16LE();
pixelsToScroll = chunkStream->readUint16LE();
sound.readData(*chunkStream, SoundDescription::kMenu);
sound.readMenu(*chunkStream);
delete chunkStream;
}

View File

@ -264,7 +264,7 @@ void SoundManager::loadCommonSounds(IFF *boot) {
chunk = boot->getChunkStream(s);
if (chunk) {
SoundDescription &desc = _commonSounds.getOrCreateVal(s);
desc.readData(*chunk, SoundDescription::kNormal);
desc.readNormal(*chunk);
g_nancy->_sound->loadSound(desc);
_channels[desc.channelID].isPersistent = true;
@ -276,7 +276,7 @@ void SoundManager::loadCommonSounds(IFF *boot) {
chunk = boot->getChunkStream("MSND"); // channel 28
if (chunk) {
SoundDescription &desc = _commonSounds.getOrCreateVal("MSND");
desc.readData(*chunk, SoundDescription::kMenu);
desc.readMenu(*chunk);
g_nancy->_sound->loadSound(desc);
_channels[desc.channelID].isPersistent = true;

View File

@ -74,7 +74,7 @@ void Scene::SceneSummary::read(Common::SeekableReadStream &stream) {
readFilename(stream, palettes[2]);
}
sound.readData(stream, SoundDescription::kScene);
sound.readScene(stream);
ser.skip(6);
ser.syncAsUint16LE(panningType);