Skip to content

Commit

Permalink
TITANIC: Figured out sound durations for speeches & SFX
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed Sep 3, 2016
1 parent a4d577b commit 6e5072e
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 42 deletions.
4 changes: 2 additions & 2 deletions engines/titanic/messages/messages.h
Expand Up @@ -254,7 +254,7 @@ MESSAGE0(CMusicHasStoppedMsg);
MESSAGE0(CMusicSettingChangedMsg);
MESSAGE2(CNPCPlayAnimationMsg, const char *const *, names, nullptr, int, maxDuration, 0);
MESSAGE1(CNPCPlayIdleAnimationMsg, const char *const *, names, 0);
MESSAGE3(CNPCPlayTalkingAnimationMsg, int, value1, 0, int, value2, 0, const char *const *, names, nullptr);
MESSAGE3(CNPCPlayTalkingAnimationMsg, uint, speechDuration, 0, int, value2, 0, const char *const *, names, nullptr);
MESSAGE0(CNPCQueueIdleAnimMsg);
MESSAGE1(CNutPuzzleMsg, CString, value, "");
MESSAGE1(COnSummonBotMsg, int, value, 0);
Expand Down Expand Up @@ -328,7 +328,7 @@ MESSAGE4(CTrueTalkGetAnimSetMsg, int, value1, 0, uint, index, 0, uint, startFram
MESSAGE2(CTrueTalkGetAssetDetailsMsg, CString, filename, "", int, numValue, 0);
MESSAGE2(CTrueTalkGetStateValueMsg, int, stateNum, 0, int, stateVal, -1000);
MESSAGE2(CTrueTalkNotifySpeechEndedMsg, int, value1, 0, int, dialogueId, 0);
MESSAGE3(CTrueTalkNotifySpeechStartedMsg, uint, soundId, 0, uint, dialogueId, 0, int, value, 0);
MESSAGE3(CTrueTalkNotifySpeechStartedMsg, uint, speechDuration, 0, uint, dialogueId, 0, int, value, 0);
MESSAGE1(CTrueTalkQueueUpAnimSetMsg, int, value, 0);
MESSAGE0(CTrueTalkSelfQueueAnimSetMsg);
MESSAGE3(CTrueTalkTriggerActionMsg, int, action, 0, int, param1, 0, int, param2, 0);
Expand Down
26 changes: 13 additions & 13 deletions engines/titanic/npcs/true_talk_npc.cpp
Expand Up @@ -40,7 +40,7 @@ BEGIN_MESSAGE_MAP(CTrueTalkNPC, CCharacter)
END_MESSAGE_MAP()

CTrueTalkNPC::CTrueTalkNPC() : _assetName("z451.dlg"),
_assetNumber(0x11170), _fieldE4(0), _npcFlags(0), _soundId(0), _fieldF0(0),
_assetNumber(0x11170), _fieldE4(0), _npcFlags(0), _speechDuration(0), _startTicks(0),
_fieldF4(0), _fieldF8(0), _speechTimerId(0), _field100(0), _field104(0) {
}

Expand All @@ -50,8 +50,8 @@ void CTrueTalkNPC::save(SimpleFile *file, int indent) {
file->writeQuotedLine(_assetName, indent);
file->writeNumberLine(_fieldE4, indent);
file->writeNumberLine(_npcFlags, indent);
file->writeNumberLine(_soundId, indent);
file->writeNumberLine(_fieldF0, indent);
file->writeNumberLine(_speechDuration, indent);
file->writeNumberLine(_startTicks, indent);
file->writeNumberLine(_fieldF4, indent);
file->writeNumberLine(_fieldF8, indent);
file->writeNumberLine(_speechTimerId, indent);
Expand All @@ -67,8 +67,8 @@ void CTrueTalkNPC::load(SimpleFile *file) {
_assetName = file->readString();
_fieldE4 = file->readNumber();
_npcFlags = file->readNumber();
_soundId = file->readNumber();
_fieldF0 = file->readNumber();
_speechDuration = file->readNumber();
_startTicks = file->readNumber();
_fieldF4 = file->readNumber();
_fieldF8 = file->readNumber();
_speechTimerId = file->readNumber();
Expand Down Expand Up @@ -102,18 +102,18 @@ bool CTrueTalkNPC::TrueTalkNotifySpeechStartedMsg(CTrueTalkNotifySpeechStartedMs
if (_speechTimerId)
stopTimer(_speechTimerId);

_soundId = msg->_soundId;
_fieldF0 = getTicksCount();
_speechDuration = msg->_speechDuration;
_startTicks = getTicksCount();

if (hasActiveMovie() || (_npcFlags & NPCFLAG_2)) {
_npcFlags &= ~NPCFLAG_2;
stopMovie();

CNPCPlayTalkingAnimationMsg msg1(_soundId, 0, 0);
CNPCPlayTalkingAnimationMsg msg1(_speechDuration, 0, 0);
msg1.execute(this);

if (msg1._names) {
CNPCPlayAnimationMsg msg2(msg1._names, msg1._value1);
CNPCPlayAnimationMsg msg2(msg1._names, msg1._speechDuration);
msg2.execute(this);
}
}
Expand All @@ -125,7 +125,7 @@ bool CTrueTalkNPC::TrueTalkNotifySpeechStartedMsg(CTrueTalkNotifySpeechStartedMs
bool CTrueTalkNPC::TrueTalkNotifySpeechEndedMsg(CTrueTalkNotifySpeechEndedMsg *msg) {
_npcFlags &= ~NPCFLAG_SPEAKING;
--_field100;
_soundId = 0;
_speechDuration = 0;

if (!(_npcFlags & NPCFLAG_8)) {
CNPCPlayTalkingAnimationMsg msg1(0, 2, 0);
Expand All @@ -147,13 +147,13 @@ bool CTrueTalkNPC::MovieEndMsg(CMovieEndMsg *msg) {
return false;
}

int diff = getTicksCount() - _fieldF0;
int ticks = MAX((int)_soundId - diff, 0);
int diff = getTicksCount() - _startTicks;
int ticks = MAX((int)_speechDuration - diff, 0);
CNPCPlayTalkingAnimationMsg msg1(ticks, ticks > 1000 ? 2 : 1, 0);
msg1.execute(this);

if (msg1._names) {
CNPCPlayAnimationMsg msg2(msg1._names, msg1._value1);
CNPCPlayAnimationMsg msg2(msg1._names, ticks);
msg2.execute(this);
}

Expand Down
4 changes: 2 additions & 2 deletions engines/titanic/npcs/true_talk_npc.h
Expand Up @@ -57,8 +57,8 @@ class CTrueTalkNPC : public CCharacter {
CString _assetName;
int _fieldE4;
uint _npcFlags;
uint _soundId;
int _fieldF0;
uint _speechDuration;
uint _startTicks;
int _fieldF4;
int _fieldF8;
int _speechTimerId;
Expand Down
2 changes: 1 addition & 1 deletion engines/titanic/sound/proximity.cpp
Expand Up @@ -31,7 +31,7 @@ CProximity::CProximity() : _field4(0), _channelVolume(100), _fieldC(0),
_range(0.5), _elevation(0), _posX(0.0), _posY(0.0), _posZ(0.0),
_hasVelocity(false), _velocityX(0), _velocityY(0), _velocityZ(0),
_field54(0), _field58(0), _field5C(0), _freeSoundFlag(false), _endTalkerFn(nullptr),
_talker(nullptr), _field6C(0), _soundType(Audio::Mixer::kPlainSoundType) {
_talker(nullptr), _soundDuration(0), _soundType(Audio::Mixer::kPlainSoundType) {
}

} // End of namespace Titanic
2 changes: 1 addition & 1 deletion engines/titanic/sound/proximity.h
Expand Up @@ -62,7 +62,7 @@ class CProximity {
bool _freeSoundFlag;
CEndTalkerFn _endTalkerFn;
TTtalker *_talker;
int _field6C;
uint _soundDuration;
Audio::Mixer::SoundType _soundType;
public:
CProximity();
Expand Down
4 changes: 2 additions & 2 deletions engines/titanic/sound/sound.cpp
Expand Up @@ -158,7 +158,7 @@ int CSound::playSound(const CString &name, CProximity &prox) {
if (!waveFile)
return -1;

prox._field6C = waveFile->fn1();
prox._soundDuration = waveFile->getDuration();
if (prox._soundType != Audio::Mixer::kPlainSoundType)
waveFile->_soundType = prox._soundType;

Expand Down Expand Up @@ -208,7 +208,7 @@ int CSound::playSpeech(CDialogueFile *dialogueFile, int speechId, CProximity &pr
if (!waveFile)
return -1;

prox._field6C = waveFile->fn1();
prox._soundDuration = waveFile->getDuration();
activateSound(waveFile, prox._freeSoundFlag);

return _soundManager.playSound(*waveFile, prox);
Expand Down
5 changes: 2 additions & 3 deletions engines/titanic/sound/wave_file.cpp
Expand Up @@ -43,9 +43,8 @@ CWaveFile::~CWaveFile() {
}
}

int CWaveFile::fn1() {
// TODO
return 0;
uint CWaveFile::getDuration() const {
return _stream ? _stream->getLength().secs() : 0;
}

bool CWaveFile::loadSound(const CString &name) {
Expand Down
5 changes: 4 additions & 1 deletion engines/titanic/sound/wave_file.h
Expand Up @@ -45,7 +45,10 @@ class CWaveFile {
CWaveFile(QSoundManager *owner);
~CWaveFile();

int fn1();
/**
* Returns the duration of the wave file in seconds
*/
uint getDuration() const;

/**
* Return the size of the wave file
Expand Down
22 changes: 11 additions & 11 deletions engines/titanic/true_talk/true_talk_manager.cpp
Expand Up @@ -347,14 +347,14 @@ void CTrueTalkManager::setDialogue(CTrueTalkNPC *npc, TTroomScript *roomScript,
if (dialogueStr.empty())
return;

int soundId = readDialogSound();
uint speechDuration = readDialogueSpeech();
TTtalker *talker = new TTtalker(this, npc);
_talkers.push_back(talker);

bool isParrot = npc->getName().contains("parrot");
triggerNPC(npc);
playSpeech(talker, roomScript, view, isParrot);
talker->speechStarted(dialogueStr, _titleEngine._indexes[0], soundId);
talker->speechStarted(dialogueStr, _titleEngine._indexes[0], speechDuration);
}

#define STRING_BUFFER_SIZE 2048
Expand Down Expand Up @@ -400,30 +400,30 @@ CString CTrueTalkManager::readDialogueString() {
return result;
}

int CTrueTalkManager::readDialogSound() {
_field18 = 0;
uint CTrueTalkManager::readDialogueSpeech() {
_speechDuration = 0;

for (uint idx = 0; idx < _titleEngine._indexes.size(); ++idx) {
CWaveFile *waveFile = _gameManager->_sound.getTrueTalkSound(
_dialogueFile, _titleEngine._indexes[idx] - _dialogueId);
if (waveFile) {
_field18 = waveFile->fn1();
_speechDuration += waveFile->getDuration();
}
}

return _field18;
return _speechDuration;
}

void CTrueTalkManager::triggerNPC(CTrueTalkNPC *npc) {
CTrueTalkSelfQueueAnimSetMsg queueSetMsg;
if (queueSetMsg.execute(npc)) {
if (_field18 > 300) {
CTrueTalkQueueUpAnimSetMsg upMsg(_field18);
if (_speechDuration > 300) {
CTrueTalkQueueUpAnimSetMsg upMsg(_speechDuration);
upMsg.execute(npc);
}
} else {
CTrueTalkGetAnimSetMsg getAnimMsg;
if (_field18 > 300) {
if (_speechDuration > 300) {
do {
getAnimMsg.execute(npc);
if (!getAnimMsg._endFrame)
Expand All @@ -435,10 +435,10 @@ void CTrueTalkManager::triggerNPC(CTrueTalkNPC *npc) {
uint numFrames = getAnimMsg._endFrame - getAnimMsg._startFrame;
int64 val = (numFrames * 1000) * 0x88888889;
uint diff = (val >> (32 + 5)) - 500;
_field18 += diff;
_speechDuration += diff;

getAnimMsg._index++;
} while (_field18 > 0);
} while (_speechDuration > 0);
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions engines/titanic/true_talk/true_talk_manager.h
Expand Up @@ -50,7 +50,7 @@ class CTrueTalkManager {
int _currentCharId;
CDialogueFile *_dialogueFile;
int _dialogueId;
int _field18;
uint _speechDuration;
TTtalkerList _talkers;
private:
/**
Expand Down Expand Up @@ -96,9 +96,10 @@ class CTrueTalkManager {
CString readDialogueString();

/**
* Read in the sound from the dialogue file
* Read in the speech from the dialogue file
* @returns Duration of the speech in seconds
*/
int readDialogSound();
uint readDialogueSpeech();

/**
* Triggers animation for the NPC
Expand Down
4 changes: 2 additions & 2 deletions engines/titanic/true_talk/tt_talker.cpp
Expand Up @@ -26,10 +26,10 @@

namespace Titanic {

void TTtalker::speechStarted(const CString &dialogueStr, uint dialogueId, uint soundId) {
void TTtalker::speechStarted(const CString &dialogueStr, uint dialogueId, uint speechHandle) {
_dialogueId = dialogueId;

CTrueTalkNotifySpeechStartedMsg msg(soundId, dialogueId, 0);
CTrueTalkNotifySpeechStartedMsg msg(speechHandle, dialogueId, 0);
msg.execute(_npc, nullptr, MSGFLAG_BREAK_IF_HANDLED);
}

Expand Down
2 changes: 1 addition & 1 deletion engines/titanic/true_talk/tt_talker.h
Expand Up @@ -49,7 +49,7 @@ class TTtalker : public ListItem {
/**
* Start a new speech
*/
void speechStarted(const CString &dialogueStr, uint dialogueId, uint soundId);
void speechStarted(const CString &dialogueStr, uint dialogueId, uint speechHandle);

/**
* End the speech
Expand Down

0 comments on commit 6e5072e

Please sign in to comment.