TTS: Fix crash when TextToSpeechManager is unavailable, clean up formatting

This commit is contained in:
Cameron Cawley 2020-05-25 18:29:41 +01:00 committed by Eugene Sandulenko
parent 30c00656e1
commit cc5abf5ebb
10 changed files with 70 additions and 54 deletions

View File

@ -553,13 +553,17 @@ extern "C" int scummvm_main(int argc, const char * const argv[]) {
#endif
#ifdef USE_TTS
Common::TextToSpeechManager *ttsMan = g_system->getTextToSpeechManager();
ttsMan->pushState();
if (ttsMan != nullptr) {
ttsMan->pushState();
}
#endif
// Try to run the game
Common::Error result = runGame(plugin, system, specialDebug);
#ifdef USE_TTS
ttsMan->popState();
if (ttsMan != nullptr) {
ttsMan->popState();
}
#endif
#ifdef ENABLE_EVENTRECORDER

View File

@ -564,8 +564,10 @@ void Engine::openMainMenuDialog() {
_mainMenuDialog = new MainMenuDialog(this);
#ifdef USE_TTS
Common::TextToSpeechManager *ttsMan = g_system->getTextToSpeechManager();
ttsMan->pushState();
g_gui.initTextToSpeech();
if (ttsMan != nullptr) {
ttsMan->pushState();
g_gui.initTextToSpeech();
}
#endif
setGameToLoadSlot(-1);
@ -590,7 +592,8 @@ void Engine::openMainMenuDialog() {
applyGameSettings();
syncSoundSettings();
#ifdef USE_TTS
ttsMan->popState();
if (ttsMan != nullptr)
ttsMan->popState();
#endif
}

View File

@ -93,11 +93,11 @@ static const LureGameDescription gameDescriptions[] = {
Common::EN_ANY,
Common::kPlatformDOS,
ADGF_NO_FLAGS,
#ifdef USE_TTS
GUIO1(GAMEOPTION_TTS_NARRATOR)
#else
GUIO0()
#endif
#ifdef USE_TTS
GUIO1(GAMEOPTION_TTS_NARRATOR)
#else
GUIO0()
#endif
},
GF_FLOPPY,
},
@ -110,12 +110,11 @@ static const LureGameDescription gameDescriptions[] = {
Common::EN_ANY,
Common::kPlatformDOS,
ADGF_NO_FLAGS,
#ifdef USE_TTS
GUIO1(GAMEOPTION_TTS_NARRATOR)
#else
GUIO0()
#endif
#ifdef USE_TTS
GUIO1(GAMEOPTION_TTS_NARRATOR)
#else
GUIO0()
#endif
},
GF_FLOPPY | GF_EGA,
},
@ -235,9 +234,9 @@ static const LureGameDescription gameDescriptions[] = {
class LureMetaEngine : public AdvancedMetaEngine {
public:
LureMetaEngine() : AdvancedMetaEngine(Lure::gameDescriptions, sizeof(Lure::LureGameDescription), lureGames
#ifdef USE_TTS
#ifdef USE_TTS
, optionsList
#endif
#endif
) {
_md5Bytes = 1024;

View File

@ -472,27 +472,29 @@ Surface *Surface::newDialog(uint16 width, uint8 numLines, const char **lines, bo
Surface *s = new Surface(width, size.y);
s->createDialog();
#ifdef USE_TTS
#ifdef USE_TTS
Common::String text;
#endif
#endif
uint16 yP = Surface::textY();
for (uint8 ctr = 0; ctr < numLines; ++ctr) {
#ifdef USE_TTS
#ifdef USE_TTS
text += lines[ctr];
#endif
#endif
s->writeString(Surface::textX(), yP, lines[ctr], true, color, varLength);
yP += squashedLines ? FONT_HEIGHT - 1 : FONT_HEIGHT;
}
#ifdef USE_TTS
#ifdef USE_TTS
if (ConfMan.getBool("tts_narrator")) {
Common::TextToSpeechManager *_ttsMan = g_system->getTextToSpeechManager();
_ttsMan->stop();
_ttsMan->say(text.c_str());
Common::TextToSpeechManager *ttsMan = g_system->getTextToSpeechManager();
if (ttsMan != nullptr) {
ttsMan->stop();
ttsMan->say(text.c_str());
}
}
#endif
#endif
return s;
}

View File

@ -138,7 +138,7 @@ static const ADExtraGuiOptionsMap optionsList[] = {
}
},*/
#ifdef USE_TTS
#ifdef USE_TTS
{
GAMEOPTION_TTS_NARRATOR,
{
@ -148,7 +148,7 @@ static const ADExtraGuiOptionsMap optionsList[] = {
false
}
},
#endif
#endif
AD_EXTRA_GUI_OPTIONS_TERMINATOR
};

View File

@ -56,11 +56,11 @@ static const MADSGameDescription gameDescriptions[] = {
Common::EN_ANY,
Common::kPlatformDOS,
ADGF_NO_FLAGS,
#ifdef USE_TTS
#ifdef USE_TTS
GUIO6(GUIO_NOSPEECH, GAMEOPTION_EASY_MOUSE, GAMEOPTION_ANIMATED_INVENTORY, GAMEOPTION_ANIMATED_INTERFACE, GAMEOPTION_NAUGHTY_MODE, GAMEOPTION_TTS_NARRATOR)
#else
#else
GUIO5(GUIO_NOSPEECH, GAMEOPTION_EASY_MOUSE, GAMEOPTION_ANIMATED_INVENTORY, GAMEOPTION_ANIMATED_INTERFACE, GAMEOPTION_NAUGHTY_MODE)
#endif
#endif
},
GType_RexNebular,
0

View File

@ -201,8 +201,9 @@ int TextDialog::estimatePieces(int maxLen) {
TextDialog::~TextDialog() {
#ifdef USE_TTS
if (ConfMan.getBool("tts_narrator")) {
Common::TextToSpeechManager* _ttsMan = g_system->getTextToSpeechManager();
_ttsMan->stop();
Common::TextToSpeechManager* ttsMan = g_system->getTextToSpeechManager();
if (ttsMan != nullptr)
ttsMan->stop();
}
#endif
@ -350,9 +351,9 @@ void TextDialog::draw() {
// Draw the text lines
int lineYp = _position.y + 5;
#ifdef USE_TTS
#ifdef USE_TTS
Common::String text;
#endif
#endif
for (int lineNum = 0; lineNum <= _numLines; ++lineNum) {
if (_lineXp[lineNum] == -1) {
// Draw a line across the entire dialog
@ -387,13 +388,15 @@ void TextDialog::draw() {
lineYp += _font->getHeight() + 1;
}
#ifdef USE_TTS
#ifdef USE_TTS
if (ConfMan.getBool("tts_narrator")) {
Common::TextToSpeechManager *_ttsMan = g_system->getTextToSpeechManager();
_ttsMan->stop();
_ttsMan->say(text.c_str());
Common::TextToSpeechManager *ttsMan = g_system->getTextToSpeechManager();
if (ttsMan != nullptr) {
ttsMan->stop();
ttsMan->say(text.c_str());
}
}
#endif
#endif
}
void TextDialog::calculateBounds() {

View File

@ -2064,13 +2064,15 @@ void ScalpelUserInterface::printObjectDesc(const Common::String &str, bool first
SHERLOCK_SCREEN_HEIGHT));
}
#ifdef USE_TTS
#ifdef USE_TTS
if (ConfMan.getBool("tts_narrator")) {
Common::TextToSpeechManager *_ttsMan = g_system->getTextToSpeechManager();
_ttsMan->stop();
_ttsMan->say(str.c_str());
Common::TextToSpeechManager *ttsMan = g_system->getTextToSpeechManager();
if (ttsMan != nullptr) {
ttsMan->stop();
ttsMan->say(str.c_str());
}
}
#endif
#endif
}
void ScalpelUserInterface::printObjectDesc() {

View File

@ -356,14 +356,16 @@ void Talk::talkTo(const Common::String filename) {
// Make a copy of the statement (in case the script frees the statement list), and then execute it
Statement statement = _statements[select];
#ifdef USE_TTS
#ifdef USE_TTS
if (_talkTo == -1 && ConfMan.getBool("tts_narrator")) {
Common::TextToSpeechManager *_ttsMan = g_system->getTextToSpeechManager();
_ttsMan->stop();
_ttsMan->say(_statements[select]._reply.c_str());
}
#endif
Common::TextToSpeechManager *ttsMan = g_system->getTextToSpeechManager();
if (ttsMan != nullptr) {
ttsMan->stop();
ttsMan->say(_statements[select]._reply.c_str());
}
}
#endif
doScript(_statements[select]._reply);

View File

@ -200,7 +200,8 @@ void PopUpDialog::read(Common::String str) {
if (ConfMan.hasKey("tts_enabled", "scummvm") &&
ConfMan.getBool("tts_enabled", "scummvm")) {
Common::TextToSpeechManager *ttsMan = g_system->getTextToSpeechManager();
ttsMan->say(str);
if (ttsMan != nullptr)
ttsMan->say(str);
}
#endif
}