AGS: Split GameState::want_speech into two variables for easier handling

From upstream 2f6e7362f742c59020fc6a70fdf67c5a87ff2e69
This commit is contained in:
Paul Gilbert 2022-03-27 15:42:57 -07:00
parent 6ab3c326b3
commit 8e310c5d98
10 changed files with 42 additions and 47 deletions

View File

@ -390,7 +390,7 @@ bool try_auto_play_speech(const char *text, const char *&replace_text, int chari
replace_text = src; // skip voice tag
if (play_voice_speech(charid, sndid)) {
// if Voice Only, then blank out the text
if (_GP(play).want_speech == 2)
if (_GP(play).speech_mode == kSpeech_VoiceOnly)
replace_text = " ";
return true;
}

View File

@ -393,7 +393,7 @@ bool GameState::IsNonBlockingVoiceSpeech() const {
bool GameState::ShouldPlayVoiceSpeech() const {
return !_GP(play).fast_forward &&
(_GP(play).want_speech >= 1) && (!_GP(ResPaths).SpeechPak.Name.IsEmpty());
(_GP(play).speech_mode != kSpeech_TextOnly) && (!_GP(ResPaths).SpeechPak.Name.IsEmpty());
}
void GameState::ReadFromSavegame(Shared::Stream *in, GameStateSvgVersion svg_ver, RestoredData &r_data) {
@ -522,7 +522,7 @@ void GameState::ReadFromSavegame(Shared::Stream *in, GameStateSvgVersion svg_ver
entered_at_x = in->ReadInt32();
entered_at_y = in->ReadInt32();
entered_edge = in->ReadInt32();
want_speech = in->ReadInt32();
speech_mode = (SpeechMode)in->ReadInt32();
cant_skip_speech = in->ReadInt32();
in->ReadArrayOfInt32(script_timers, MAX_TIMERS);
sound_volume = in->ReadInt32();
@ -531,7 +531,7 @@ void GameState::ReadFromSavegame(Shared::Stream *in, GameStateSvgVersion svg_ver
speech_font = in->ReadInt32();
key_skip_wait = in->ReadInt8();
swap_portrait_lastchar = in->ReadInt32();
separate_music_lib = in->ReadInt32();
separate_music_lib = in->ReadInt32() != 0;
in_conversation = in->ReadInt32();
screen_tint = in->ReadInt32();
num_parsed_words = in->ReadInt32();
@ -726,7 +726,7 @@ void GameState::WriteForSavegame(Shared::Stream *out) const {
out->WriteInt32(entered_at_x);
out->WriteInt32(entered_at_y);
out->WriteInt32(entered_edge);
out->WriteInt32(want_speech);
out->WriteInt32(speech_mode);
out->WriteInt32(cant_skip_speech);
out->WriteArrayOfInt32(script_timers, MAX_TIMERS);
out->WriteInt32(sound_volume);
@ -735,7 +735,7 @@ void GameState::WriteForSavegame(Shared::Stream *out) const {
out->WriteInt32(speech_font);
out->WriteInt8(key_skip_wait);
out->WriteInt32(swap_portrait_lastchar);
out->WriteInt32(separate_music_lib);
out->WriteInt32(separate_music_lib ? 1 : 0);
out->WriteInt32(in_conversation);
out->WriteInt32(screen_tint);
out->WriteInt32(num_parsed_words);

View File

@ -26,13 +26,14 @@
#include "ags/lib/std/vector.h"
#include "ags/shared/ac/character_info.h"
#include "ags/engine/ac/runtime_defines.h"
#include "ags/engine/ac/speech.h"
#include "ags/engine/ac/timer.h"
#include "ags/shared/game/room_struct.h"
#include "ags/engine/game/viewport.h"
#include "ags/engine/media/audio/queued_audio_item.h"
#include "ags/shared/util/geometry.h"
#include "ags/shared/util/string_types.h"
#include "ags/shared/util/string.h"
#include "ags/engine/ac/timer.h"
namespace AGS3 {
@ -169,7 +170,8 @@ struct GameState {
char walkable_areas_on[MAX_WALK_AREAS + 1];
short screen_flipped = 0;
int entered_at_x = 0, entered_at_y = 0, entered_edge = 0;
int want_speech = 0;
bool voice_avail; // whether voice-over is available
SpeechMode speech_mode; // speech mode (text, voice, or both)
int cant_skip_speech = 0;
int32_t script_timers[MAX_TIMERS];
int sound_volume = 0, speech_volume = 0;
@ -177,7 +179,7 @@ struct GameState {
int8 key_skip_wait = 0;
int swap_portrait_lastchar = 0;
int swap_portrait_lastlastchar = 0;
int separate_music_lib = 0;
bool separate_music_lib = false;
int in_conversation = 0;
int screen_tint = 0;
int num_parsed_words = 0;

View File

@ -448,36 +448,24 @@ void SetSpeechVolume(int newvol) {
_GP(play).speech_volume = newvol;
}
// 0 = text only
// 1 = voice & text
// 2 = voice only
void SetVoiceMode(int newmod) {
if ((newmod < 0) | (newmod > 2))
quit("!SetVoiceMode: invalid mode number (must be 0,1,2)");
// If speech is turned off, store the mode anyway in case the
// user adds the VOX file later
if (_GP(play).want_speech < 0)
_GP(play).want_speech = (-newmod) - 1;
else
_GP(play).want_speech = newmod;
if ((newmod < kSpeech_First) | (newmod > kSpeech_Last))
quitprintf("!SetVoiceMode: invalid mode number %d", newmod);
_GP(play).speech_mode = (SpeechMode)newmod;
}
int GetVoiceMode() {
return _GP(play).want_speech >= 0 ? _GP(play).want_speech : -(_GP(play).want_speech + 1);
return (int)_GP(play).speech_mode;
}
int IsVoxAvailable() {
if (_GP(play).want_speech < 0)
return 0;
return 1;
return _GP(play).voice_avail ? 1 : 0;
}
int IsMusicVoxAvailable() {
return _GP(play).separate_music_lib;
return _GP(play).separate_music_lib ? 1 : 0;
}
ScriptAudioChannel *PlayVoiceClip(CharacterInfo *ch, int sndid, bool as_speech) {
if (!play_voice_nonblocking(ch->index_id, sndid, as_speech))
return nullptr;

View File

@ -22,6 +22,8 @@
#ifndef AGS_ENGINE_AC_GLOBAL_AUDIO_H
#define AGS_ENGINE_AC_GLOBAL_AUDIO_H
#include "ags/engine/ac/speech.h"
namespace AGS3 {
void StopAmbientSound(int channel);

View File

@ -68,7 +68,7 @@ String GetRuntimeInfo() {
_GP(spriteset).GetCacheSize() / 1024, _GP(spriteset).GetMaxCacheSize() / 1024, _GP(spriteset).GetLockedSize() / 1024);
if (_GP(play).separate_music_lib)
runtimeInfo.Append("[AUDIO.VOX enabled");
if (_GP(play).want_speech >= 1)
if (_GP(play).voice_avail)
runtimeInfo.Append("[SPEECH.VOX enabled");
if (get_translation_tree().size() > 0) {
runtimeInfo.Append("[Using translation ");

View File

@ -38,6 +38,15 @@ enum SkipSpeechStyle {
kSkipSpeechLast = kSkipSpeechMouse
};
enum SpeechMode {
kSpeech_TextOnly = 0,
kSpeech_VoiceText = 1,
kSpeech_VoiceOnly = 2,
kSpeech_First = kSpeech_TextOnly,
kSpeech_Last = kSpeech_VoiceOnly
};
int user_to_internal_skip_speech(SkipSpeechStyle userval);
SkipSpeechStyle internal_skip_speech_to_user(int internal_val);

View File

@ -325,7 +325,7 @@ HSaveError OpenSavegame(const String &filename, SavegameDescription &desc, Saveg
// Prepares engine for actual save restore (stops processes, cleans up memory)
void DoBeforeRestore(PreservedParams &pp) {
pp.SpeechVOX = _GP(play).want_speech;
pp.SpeechVOX = _GP(play).voice_avail;
pp.MusicVOX = _GP(play).separate_music_lib;
unload_old_room();
@ -431,13 +431,8 @@ HSaveError DoAfterRestore(const PreservedParams &pp, const RestoredData &r_data)
_GP(play).dialog_options_highlight_color = DIALOG_OPTIONS_HIGHLIGHT_COLOR_DEFAULT;
// Preserve whether the music vox is available
_GP(play).voice_avail = pp.SpeechVOX;
_GP(play).separate_music_lib = pp.MusicVOX;
// If they had the vox when they saved it, but they don't now
if ((pp.SpeechVOX < 0) && (_GP(play).want_speech >= 0))
_GP(play).want_speech = (-_GP(play).want_speech) - 1;
// If they didn't have the vox before, but now they do
else if ((pp.SpeechVOX >= 0) && (_GP(play).want_speech < 0))
_GP(play).want_speech = (-_GP(play).want_speech) - 1;
// Restore debug flags
if (_G(debug_flags) & DBG_DEBUGMODE)

View File

@ -43,8 +43,8 @@ typedef std::shared_ptr<Bitmap> PBitmap;
// loading save data
struct PreservedParams {
// Whether speech and audio packages available
int SpeechVOX;
int MusicVOX;
bool SpeechVOX;
bool MusicVOX;
// Script global data sizes
int GlScDataSize;
std::vector<int> ScMdDataSize;

View File

@ -267,7 +267,7 @@ void engine_init_mouse() {
}
void engine_locate_speech_pak() {
_GP(play).want_speech = -2;
_GP(play).voice_avail = false;
if (!_GP(usetup).no_speech_pack) {
String speech_file = "speech.vox";
@ -278,13 +278,12 @@ void engine_locate_speech_pak() {
_G(platform)->DisplayAlert("Unable to read voice pack, file could be corrupted or of unknown format.\nSpeech voice-over will be disabled.");
return;
}
Debug::Printf(kDbgMsg_Info, "Voice pack found and initialized.");
_GP(play).want_speech = 1;
_GP(play).voice_avail = true;
} else if (Path::ComparePaths(_GP(ResPaths).DataDir, _GP(ResPaths).VoiceDir2) != 0) {
// If we have custom voice directory set, we will enable voice-over even if speech.vox does not exist
Debug::Printf(kDbgMsg_Info, "Voice pack was not found, but explicit voice directory is defined: enabling voice-over.");
_GP(play).want_speech = 1;
_GP(play).voice_avail = true;
}
_GP(ResPaths).SpeechPak.Name = speech_file;
_GP(ResPaths).SpeechPak.Path = speech_filepath;
@ -292,18 +291,18 @@ void engine_locate_speech_pak() {
}
void engine_locate_audio_pak() {
_GP(play).separate_music_lib = 0;
_GP(play).separate_music_lib = false;
String music_file = _GP(game).GetAudioVOXName();
String music_filepath = find_assetlib(music_file);
if (!music_filepath.IsEmpty()) {
if (_GP(AssetMgr)->AddLibrary(music_filepath) == kAssetNoError) {
Debug::Printf(kDbgMsg_Info, "%s found and initialized.", music_file.GetCStr());
_GP(play).separate_music_lib = 1;
_GP(play).separate_music_lib = true;
_GP(ResPaths).AudioPak.Name = music_file;
_GP(ResPaths).AudioPak.Path = music_filepath;
} else {
_G(platform)->DisplayAlert("Unable to initialize digital audio pack '%s', file could be corrupt or of unsupported format.",
music_file.GetCStr());
music_file.GetCStr());
}
} else if (Path::ComparePaths(_GP(ResPaths).DataDir, _GP(ResPaths).AudioDir2) != 0) {
Debug::Printf(kDbgMsg_Info, "Audio pack was not found, but explicit audio directory is defined.");
@ -356,9 +355,8 @@ void engine_init_audio() {
if (_GP(usetup).audio_backend == 0) {
// all audio is disabled
// and the voice mode should not go to Voice Only
_GP(play).want_speech = -2;
_GP(play).separate_music_lib = 0;
_GP(play).voice_avail = false;
_GP(play).separate_music_lib = false;
}
}
@ -706,6 +704,7 @@ void engine_init_game_settings() {
_GP(play).music_master_volume = 100 + LegacyMusicMasterVolumeAdjustment;
_GP(play).digital_master_volume = 100;
_GP(play).screen_flipped = 0;
_GP(play).speech_mode = kSpeech_VoiceText;
_GP(play).cant_skip_speech = user_to_internal_skip_speech((SkipSpeechStyle)_GP(game).options[OPT_NOSKIPTEXT]);
_GP(play).sound_volume = 255;
_GP(play).speech_volume = 255;