[Scummvm-git-logs] scummvm master -> 719ea5b72c315c7c460d3a85242882df4c2817a1
dreammaster
noreply at scummvm.org
Mon Mar 28 02:17:17 UTC 2022
This automated email contains information about 13 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
8e12d38366 AGS: Simplier implementation of --windowed/--fullscreen cmd arg
d291f1cd1c AGS: Fixed gfxmode "desktop" interpretation for the windowed mode
7799fab6ba AGS: Fixed comments for FontRenderParams
0acbe50dd3 AGS: Added a flag for AGS mode that selects a font by a nominal size
a8fc0f8ec9 AGS: Fixed a use of !(ALFONT_FLG_SELECT_NOMINAL_SZ)
5027f54a02 AGS: Added util methods for measuring preloaded TTF fonts
0e41656981 AGS: Fixed utility audio chans were missing a sync with audio core
bb01ccb213 AGS: Fixed AssetManager::RemoveLibrary()
e052c54fe2 AGS: Hotfixed FindFileRecursive::PopDir() resulting in unwanted "./"
6ab3c326b3 AGS: Don't quit if setting translation failed on start
8e310c5d98 AGS: Split GameState::want_speech into two variables for easier handling
70d620c07a AGS: Support freely switching voice-over pack at runtime
719ea5b72c AGS: Added Game.ChangeSpeechVox and SpeechVoxFilename
Commit: 8e12d38366ae1569a0ba9e2ce9b890985e01910b
https://github.com/scummvm/scummvm/commit/8e12d38366ae1569a0ba9e2ce9b890985e01910b
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-03-27T19:14:52-07:00
Commit Message:
AGS: Simplier implementation of --windowed/--fullscreen cmd arg
>From upstream 87d14d90579cbcf798ff7b6b72f125b54803c74e
Changed paths:
engines/ags/engine/main/engine.cpp
engines/ags/engine/main/main.cpp
engines/ags/globals.h
diff --git a/engines/ags/engine/main/engine.cpp b/engines/ags/engine/main/engine.cpp
index 32df5b34ff9..da1ed7d7539 100644
--- a/engines/ags/engine/main/engine.cpp
+++ b/engines/ags/engine/main/engine.cpp
@@ -175,16 +175,6 @@ bool engine_run_setup(const ConfigTree &cfg, int &app_res) {
return true;
}
-void engine_force_window() {
- // Force to run in a window, override the config file
- // TODO: actually overwrite config tree instead
- if (_G(force_window) == 1) {
- _GP(usetup).Screen.Windowed = true;
- } else if (_G(force_window) == 2) {
- _GP(usetup).Screen.Windowed = false;
- }
-}
-
// Scans given directory for the AGS game config. If such config exists
// and it contains data file name, then returns one.
// Otherwise returns empty string.
@@ -1120,7 +1110,6 @@ int initialize_engine(const ConfigTree &startup_opts) {
}
// Set up game options from user config
engine_set_config(cfg);
- engine_force_window();
if (_G(justTellInfo)) {
engine_print_info(_G(tellInfoKeys), &cfg);
return EXIT_NORMAL;
diff --git a/engines/ags/engine/main/main.cpp b/engines/ags/engine/main/main.cpp
index 79af9863c73..c4e19aade28 100644
--- a/engines/ags/engine/main/main.cpp
+++ b/engines/ags/engine/main/main.cpp
@@ -208,7 +208,6 @@ int main_process_cmdline(ConfigTree &cfg, int argc, const char *argv[]) {
} else if ((ags_stricmp(arg, "--enabledebugger") == 0) && (argc > ee + 1)) {
strcpy(_G(editor_debugger_instance_token), argv[ee + 1]);
_G(editor_debugging_enabled) = 1;
- _G(force_window) = 1;
ee++;
} else if (ags_stricmp(arg, "--conf") == 0 && (argc > ee + 1)) {
_GP(usetup).conf_path = argv[++ee];
@@ -243,9 +242,9 @@ int main_process_cmdline(ConfigTree &cfg, int argc, const char *argv[]) {
else if ((ags_stricmp(arg, "--shared-data-dir") == 0) && (argc > ee + 1))
cfg["misc"]["shared_data_dir"] = argv[++ee];
else if (ags_stricmp(arg, "--windowed") == 0)
- _G(force_window) = 1;
+ cfg["graphics"]["windowed"] = "1";
else if (ags_stricmp(arg, "--fullscreen") == 0)
- _G(force_window) = 2;
+ cfg["graphics"]["windowed"] = "0";
else if ((ags_stricmp(arg, "--gfxdriver") == 0) && (argc > ee + 1)) {
INIwritestring(cfg, "graphics", "driver", argv[++ee]);
} else if ((ags_stricmp(arg, "--gfxfilter") == 0) && (argc > ee + 1)) {
diff --git a/engines/ags/globals.h b/engines/ags/globals.h
index 2f8dcbe4ab0..064b9544988 100644
--- a/engines/ags/globals.h
+++ b/engines/ags/globals.h
@@ -1065,7 +1065,6 @@ public:
String _cmdGameDataPath;
// Startup flags, set from parameters to engine
- int _force_window = 0;
int _override_start_room = 0;
bool _justDisplayHelp = false;
bool _justDisplayVersion = false;
Commit: d291f1cd1c0c736dfd0ec3ba842f7a5d8e6492b6
https://github.com/scummvm/scummvm/commit/d291f1cd1c0c736dfd0ec3ba842f7a5d8e6492b6
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-03-27T19:14:52-07:00
Commit Message:
AGS: Fixed gfxmode "desktop" interpretation for the windowed mode
>From upstream e4cdd9010cf4e0fc6122942dd18a6a9a4560338a
Changed paths:
engines/ags/engine/main/config.cpp
diff --git a/engines/ags/engine/main/config.cpp b/engines/ags/engine/main/config.cpp
index 54c55d5b320..10a391bd294 100644
--- a/engines/ags/engine/main/config.cpp
+++ b/engines/ags/engine/main/config.cpp
@@ -94,15 +94,18 @@ void INIwritestring(ConfigTree &cfg, const String §n, const String &item, co
cfg[sectn][item] = value;
}
-static WindowSetup parse_window_mode(const String &option, bool as_windowed, WindowSetup def_value = WindowSetup()) {
+WindowSetup parse_window_mode(const String &option, bool as_windowed, WindowSetup def_value) {
// "full_window" option means pseudo fullscreen ("borderless fullscreen window")
if (!as_windowed && (option.CompareNoCase("full_window") == 0))
- return WindowSetup(as_windowed ? kWnd_Windowed : kWnd_FullDesktop);
+ return WindowSetup(kWnd_FullDesktop);
// Check supported options for explicit resolution or scale factor,
// in which case we'll use either a resizing window or a REAL fullscreen mode
const WindowMode exp_wmode = as_windowed ? kWnd_Windowed : kWnd_Fullscreen;
+ // Note that for "desktop" we return "default" for windowed, this will result
+ // in refering to the desktop size but resizing in accordance to the scaling style
if (option.CompareNoCase("desktop") == 0)
- return WindowSetup(get_desktop_size(), exp_wmode);
+ return as_windowed ? WindowSetup(exp_wmode) : WindowSetup(get_desktop_size(), exp_wmode);
+ // "Native" means using game resolution as a window size
if (option.CompareNoCase("native") == 0)
return WindowSetup(_GP(game).GetGameRes(), exp_wmode);
// Try parse an explicit resolution type or game scale factor --
@@ -110,7 +113,7 @@ static WindowSetup parse_window_mode(const String &option, bool as_windowed, Win
if (at == 0) { // try parse as a scale (xN)
int scale = StrUtil::StringToInt(option.Mid(1));
if (scale > 0) return WindowSetup(scale, exp_wmode);
- } else if (at != (size_t)(-1)) { // else try parse as a "width x height"
+ } else if (at != -1) { // else try parse as a "width x height"
Size sz = Size(StrUtil::StringToInt(option.Mid(0, at)),
StrUtil::StringToInt(option.Mid(at + 1)));
if (!sz.IsNull()) return WindowSetup(sz, exp_wmode);
Commit: 7799fab6ba70f9ce5bfe25abe5a26dbdf63a060e
https://github.com/scummvm/scummvm/commit/7799fab6ba70f9ce5bfe25abe5a26dbdf63a060e
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-03-27T19:14:53-07:00
Commit Message:
AGS: Fixed comments for FontRenderParams
>From upstream d0218d799c4367eafc9294972ceb97a069954caa
Changed paths:
engines/ags/shared/font/ags_font_renderer.h
diff --git a/engines/ags/shared/font/ags_font_renderer.h b/engines/ags/shared/font/ags_font_renderer.h
index e2479093762..42de9c296f4 100644
--- a/engines/ags/shared/font/ags_font_renderer.h
+++ b/engines/ags/shared/font/ags_font_renderer.h
@@ -42,13 +42,11 @@ protected:
~IAGSFontRenderer() {}
};
-// Font render params, mainly for dealing with various compatibility issues and
-// broken fonts. NOTE: currently left empty as a result of rewrite, but may be
-// used again in the future.
+// Font render params, mainly for dealing with various compatibility issues.
struct FontRenderParams {
// Font's render multiplier
int SizeMultiplier = 1;
- int LoadMode = 0;
+ int LoadMode = 0; // contains font flags from FFLG_LOADMODEMASK
};
// Describes loaded font's properties
Commit: 0acbe50dd3f72a2996d218bd5963c0787a2f475a
https://github.com/scummvm/scummvm/commit/0acbe50dd3f72a2996d218bd5963c0787a2f475a
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-03-27T19:14:53-07:00
Commit Message:
AGS: Added a flag for AGS mode that selects a font by a nominal size
>From upstream 48644d35bd912bcb06aebbae2e2a1c9dc24e48d0
Changed paths:
engines/ags/lib/alfont/alfont.cpp
engines/ags/lib/alfont/alfont.h
engines/ags/shared/font/ttf_font_renderer.cpp
diff --git a/engines/ags/lib/alfont/alfont.cpp b/engines/ags/lib/alfont/alfont.cpp
index de18a0c425a..8a8c10b0efd 100644
--- a/engines/ags/lib/alfont/alfont.cpp
+++ b/engines/ags/lib/alfont/alfont.cpp
@@ -431,7 +431,8 @@ int alfont_set_font_size_ex(ALFONT_FONT *f, int h, int flags) {
real_height = abs(f->face->size->metrics.ascender >> 6) + abs(f->face->size->metrics.descender >> 6);
// AGS COMPAT HACK: always choose the first result
- break;
+ if ((flags & ALFONT_FLG_SELECT_NOMINAL_SZ) != 0)
+ break;
if (real_height == h) {
/* we found the wanted height */
diff --git a/engines/ags/lib/alfont/alfont.h b/engines/ags/lib/alfont/alfont.h
index 07cf53ba1cd..3de23919ac2 100644
--- a/engines/ags/lib/alfont/alfont.h
+++ b/engines/ags/lib/alfont/alfont.h
@@ -46,6 +46,11 @@ namespace AGS3 {
#define ALFONT_FLG_FORCE_RESIZE 0x01
// Make ascender equal to formal font height
#define ALFONT_FLG_ASCENDER_EQ_HEIGHT 0x02
+// When resizing a font, select the first result even if the actual
+// pixel height is different from the requested size;
+// otherwise will search for the point size which results in pixel
+// height closest to the requested size.
+#define ALFONT_FLG_SELECT_NOMINAL_SZ 0x04
/* structs */
typedef struct ALFONT_FONT ALFONT_FONT;
diff --git a/engines/ags/shared/font/ttf_font_renderer.cpp b/engines/ags/shared/font/ttf_font_renderer.cpp
index 4285de26aab..9fc494d71e2 100644
--- a/engines/ags/shared/font/ttf_font_renderer.cpp
+++ b/engines/ags/shared/font/ttf_font_renderer.cpp
@@ -79,7 +79,7 @@ bool TTFFontRenderer::IsBitmapFont() {
}
static int GetAlfontFlags(int load_mode) {
- int flags = ALFONT_FLG_FORCE_RESIZE;
+ int flags = ALFONT_FLG_FORCE_RESIZE | ALFONT_FLG_SELECT_NOMINAL_SZ;
// Compatibility: font ascender is always adjusted to the formal font's height;
// EXCEPTION: not if it's a game made before AGS 3.4.1 with TTF anti-aliasing
// (the reason is uncertain, but this is to emulate old engine's behavior).
Commit: a8fc0f8ec93c6713879ab15e0effe7f3b207f1f2
https://github.com/scummvm/scummvm/commit/a8fc0f8ec93c6713879ab15e0effe7f3b207f1f2
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-03-27T19:14:53-07:00
Commit Message:
AGS: Fixed a use of !(ALFONT_FLG_SELECT_NOMINAL_SZ)
>From upstream a0d6a8f6dc7145ad4343110b8e0aefc3fabafbe2
Changed paths:
engines/ags/lib/alfont/alfont.cpp
diff --git a/engines/ags/lib/alfont/alfont.cpp b/engines/ags/lib/alfont/alfont.cpp
index 8a8c10b0efd..0346e3d03e1 100644
--- a/engines/ags/lib/alfont/alfont.cpp
+++ b/engines/ags/lib/alfont/alfont.cpp
@@ -472,14 +472,14 @@ int alfont_set_font_size_ex(ALFONT_FONT *f, int h, int flags) {
if (!error) {
_alfont_uncache_glyphs(f);
- f->face_h = h;
+ f->face_h = test_h;
f->real_face_h = real_height;
f->face_ascender = f->face->size->metrics.ascender >> 6;
// AGS COMPAT HACK: set ascender to the formal font height
if ((flags & ALFONT_FLG_ASCENDER_EQ_HEIGHT) != 0) {
- f->face_ascender = h;
- f->real_face_h = h + abs(f->face->size->metrics.descender >> 6);
+ f->face_ascender = test_h;
+ f->real_face_h = test_h + abs(f->face->size->metrics.descender >> 6);
}
return ALFONT_OK;
Commit: 5027f54a0222c8ada3d8097c9a38ad42ee3cd731
https://github.com/scummvm/scummvm/commit/5027f54a0222c8ada3d8097c9a38ad42ee3cd731
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-03-27T19:14:53-07:00
Commit Message:
AGS: Added util methods for measuring preloaded TTF fonts
>From upstream 89ae16e236073b6e3a06274e336ce853d906eed7
Changed paths:
engines/ags/shared/font/ttf_font_renderer.cpp
engines/ags/shared/font/ttf_font_renderer.h
diff --git a/engines/ags/shared/font/ttf_font_renderer.cpp b/engines/ags/shared/font/ttf_font_renderer.cpp
index 9fc494d71e2..dd5373a4973 100644
--- a/engines/ags/shared/font/ttf_font_renderer.cpp
+++ b/engines/ags/shared/font/ttf_font_renderer.cpp
@@ -89,40 +89,44 @@ static int GetAlfontFlags(int load_mode) {
return flags;
}
-bool TTFFontRenderer::LoadFromDiskEx(int fontNumber, int fontSize,
- const FontRenderParams *params, FontMetrics *metrics) {
- String file_name = String::FromFormat("agsfnt%d.ttf", fontNumber);
- Stream *reader = _GP(AssetMgr)->OpenAsset(file_name);
- char *membuffer;
-
- if (reader == nullptr)
- return false;
+// Loads a TTF font of a certain size, optionally fill the FontMetrics struct
+static ALFONT_FONT *LoadTTF(const String &filename, int fontSize,
+ int alfont_flags, FontMetrics *metrics) {
+ std::unique_ptr<Stream> reader(_GP(AssetMgr)->OpenAsset(filename));
+ if (!reader)
+ return nullptr;
const size_t lenof = reader->GetLength();
- membuffer = (char *)malloc(lenof);
- reader->ReadArray(membuffer, lenof, 1);
- delete reader;
-
- ALFONT_FONT *alfptr = alfont_load_font_from_mem(membuffer, lenof);
- free(membuffer);
-
- if (alfptr == nullptr)
- return false;
+ std::vector<char> buf; buf.resize(lenof);
+ reader->Read(&buf.front(), lenof);
+ reader.reset();
+
+ ALFONT_FONT *alfptr = alfont_load_font_from_mem(&buf.front(), lenof);
+ if (!alfptr)
+ return nullptr;
+ alfont_set_font_size_ex(alfptr, fontSize, alfont_flags);
+ if (metrics) {
+ metrics->Height = alfont_get_font_height(alfptr);
+ metrics->RealHeight = alfont_get_font_real_height(alfptr);
+ }
+ return alfptr;
+}
+bool TTFFontRenderer::LoadFromDiskEx(int fontNumber, int fontSize,
+ const FontRenderParams *params, FontMetrics *metrics) {
+ String filename = String::FromFormat("agsfnt%d.ttf", fontNumber);
if (fontSize <= 0)
fontSize = 8; // compatibility fix
if (params && params->SizeMultiplier > 1)
fontSize *= params->SizeMultiplier;
- alfont_set_font_size_ex(alfptr, fontSize, GetAlfontFlags(params->LoadMode));
+ ALFONT_FONT *alfptr = LoadTTF(filename, fontSize,
+ GetAlfontFlags(params->LoadMode), metrics);
+ if (!alfptr)
+ return false;
_fontData[fontNumber].AlFont = alfptr;
_fontData[fontNumber].Params = params ? *params : FontRenderParams();
-
- if (metrics) {
- metrics->Height = alfont_get_font_height(alfptr);
- metrics->RealHeight = alfont_get_font_real_height(alfptr);
- }
return true;
}
@@ -144,4 +148,20 @@ void TTFFontRenderer::FreeMemory(int fontNumber) {
_fontData.erase(fontNumber);
}
+bool TTFFontRenderer::MeasureFontOfPointSize(const String &filename, int size_pt, FontMetrics *metrics) {
+ ALFONT_FONT *alfptr = LoadTTF(filename, size_pt, ALFONT_FLG_FORCE_RESIZE | ALFONT_FLG_SELECT_NOMINAL_SZ, metrics);
+ if (!alfptr)
+ return false;
+ alfont_destroy_font(alfptr);
+ return true;
+}
+
+bool TTFFontRenderer::MeasureFontOfPixelHeight(const String &filename, int pixel_height, FontMetrics *metrics) {
+ ALFONT_FONT *alfptr = LoadTTF(filename, pixel_height, ALFONT_FLG_FORCE_RESIZE, metrics);
+ if (!alfptr)
+ return false;
+ alfont_destroy_font(alfptr);
+ return true;
+}
+
} // namespace AGS3
diff --git a/engines/ags/shared/font/ttf_font_renderer.h b/engines/ags/shared/font/ttf_font_renderer.h
index 1b2e7bedf51..592effeff80 100644
--- a/engines/ags/shared/font/ttf_font_renderer.h
+++ b/engines/ags/shared/font/ttf_font_renderer.h
@@ -24,6 +24,7 @@
#include "ags/lib/std/map.h"
#include "ags/shared/font/ags_font_renderer.h"
+#include "ags/shared/util/string.h"
namespace AGS3 {
@@ -52,6 +53,15 @@ public:
const char *GetName(int fontNumber) override;
void AdjustFontForAntiAlias(int fontNumber, bool aa_mode) override;
+ //
+ // Utility functions
+ //
+ // Try load the TTF font using provided point size, and report its metrics
+ static bool MeasureFontOfPointSize(const AGS::Shared::String &filename, int size_pt, FontMetrics *metrics);
+ // Try load the TTF font, find the point size which results in pixel height
+ // as close to the requested as possible; report its metrics
+ static bool MeasureFontOfPixelHeight(const AGS::Shared::String &filename, int pixel_height, FontMetrics *metrics);
+
private:
struct FontData {
ALFONT_FONT *AlFont;
Commit: 0e4165698198345bdd24dfaf6e5a39ead7f33a18
https://github.com/scummvm/scummvm/commit/0e4165698198345bdd24dfaf6e5a39ead7f33a18
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-03-27T19:14:54-07:00
Commit Message:
AGS: Fixed utility audio chans were missing a sync with audio core
>From upstream 6560bb43ee8723c160c8ccaa1fcff007b99f1aeb
Changed paths:
engines/ags/engine/media/audio/audio.cpp
diff --git a/engines/ags/engine/media/audio/audio.cpp b/engines/ags/engine/media/audio/audio.cpp
index 4ba7f22bed0..75fcf729696 100644
--- a/engines/ags/engine/media/audio/audio.cpp
+++ b/engines/ags/engine/media/audio/audio.cpp
@@ -801,7 +801,7 @@ void update_audio_system_on_game_loop() {
}
// Update and sync logical game channels with the audio backend
- for (int i = 0; i < _GP(game).numGameChannels; ++i) {
+ for (int i = 0; i < TOTAL_AUDIO_CHANNELS; ++i) {
auto *ch = AudioChans::GetChannel(i);
if (ch) { // update the playing channel, and if it's finished then dispose it
if (ch->is_ready() && !ch->update()) {
Commit: bb01ccb21390dec720242145e1231615eb1700db
https://github.com/scummvm/scummvm/commit/bb01ccb21390dec720242145e1231615eb1700db
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-03-27T19:14:54-07:00
Commit Message:
AGS: Fixed AssetManager::RemoveLibrary()
>From upstream b1355178a86a277ac12440eb6c0ec996c153137d
Changed paths:
engines/ags/lib/std/vector.h
engines/ags/shared/core/asset_manager.cpp
diff --git a/engines/ags/lib/std/vector.h b/engines/ags/lib/std/vector.h
index db7fd5daa31..9d7bff210b1 100644
--- a/engines/ags/lib/std/vector.h
+++ b/engines/ags/lib/std/vector.h
@@ -197,6 +197,18 @@ public:
this->insert_at(destIndex++, *first);
}
}
+
+ /**
+ * Remove an element
+ */
+ void remove(T element) {
+ for (uint i = 0; i < this->size(); ++i) {
+ if (this->operator[](i) == element) {
+ this->remove_at(i);
+ return;
+ }
+ }
+ }
};
} // namespace std
diff --git a/engines/ags/shared/core/asset_manager.cpp b/engines/ags/shared/core/asset_manager.cpp
index 9decbff00f9..edb3efdbbd5 100644
--- a/engines/ags/shared/core/asset_manager.cpp
+++ b/engines/ags/shared/core/asset_manager.cpp
@@ -124,14 +124,10 @@ AssetError AssetManager::AddLibrary(const String &path, const String &filters, c
void AssetManager::RemoveLibrary(const String &path) {
int idx = 0;
- for (auto it = _libs.cbegin(); it != _libs.cend(); ++it, ++idx) {
+ for (auto it = _libs.begin(); it != _libs.end(); ++it, ++idx) {
if (Path::ComparePaths((*it)->BasePath, path) == 0) {
-#ifdef TODO
- std::remove(_activeLibs.begin(), _activeLibs.end(), (*it).get());
- _libs.erase(it);
-#else
- error("TODO");
-#endif
+ _libs.remove_at(idx);
+ _activeLibs.remove(*it);
return;
}
}
Commit: e052c54fe2f045efc100a9cc49e976f12bfdb0e4
https://github.com/scummvm/scummvm/commit/e052c54fe2f045efc100a9cc49e976f12bfdb0e4
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-03-27T19:14:54-07:00
Commit Message:
AGS: Hotfixed FindFileRecursive::PopDir() resulting in unwanted "./"
>From upstream 53008728a5df2b586077abbbcb9bd81d45fcdbc5
Changed paths:
engines/ags/shared/util/directory.cpp
diff --git a/engines/ags/shared/util/directory.cpp b/engines/ags/shared/util/directory.cpp
index cfb8c395289..0d455885e45 100644
--- a/engines/ags/shared/util/directory.cpp
+++ b/engines/ags/shared/util/directory.cpp
@@ -217,6 +217,8 @@ bool FindFileRecursive::PopDir() {
_fdirs.pop();
_fullDir = Path::GetParent(_fullDir);
_curDir = Path::GetParent(_curDir);
+ if (_curDir.Compare(".") == 0)
+ _curDir = ""; // hotfix for GetParent returning "."
// advance dir iterator that we just recovered
_fdir.Next();
return true;
Commit: 6ab3c326b3a955916bae7a4632175a3d11300feb
https://github.com/scummvm/scummvm/commit/6ab3c326b3a955916bae7a4632175a3d11300feb
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-03-27T19:14:54-07:00
Commit Message:
AGS: Don't quit if setting translation failed on start
>From upstream ac5cb3be64a5c23e8d274099baed76b0b54cfb17
Changed paths:
engines/ags/engine/ac/game.cpp
engines/ags/engine/ac/translation.cpp
engines/ags/engine/ac/translation.h
engines/ags/engine/main/engine.cpp
diff --git a/engines/ags/engine/ac/game.cpp b/engines/ags/engine/ac/game.cpp
index 8f7c9516842..3605b71e027 100644
--- a/engines/ags/engine/ac/game.cpp
+++ b/engines/ags/engine/ac/game.cpp
@@ -702,18 +702,18 @@ const char *Game_GetTranslationFilename() {
}
int Game_ChangeTranslation(const char *newFilename) {
- if ((newFilename == nullptr) || (newFilename[0] == 0)) {
+ if ((newFilename == nullptr) || (newFilename[0] == 0)) { // switch back to default translation
close_translation();
_GP(usetup).translation = "";
return 1;
}
String oldTransFileName = get_translation_name();
- if (init_translation(newFilename, oldTransFileName, false)) {
- _GP(usetup).translation = newFilename;
- return 1;
- }
- return 0;
+ if (!init_translation(newFilename, oldTransFileName))
+ return 0; // failed, kept previous translation
+
+ _GP(usetup).translation = newFilename;
+ return 1;
}
ScriptAudioClip *Game_GetAudioClip(int index) {
diff --git a/engines/ags/engine/ac/translation.cpp b/engines/ags/engine/ac/translation.cpp
index 72bcbc192b8..41ba8978a5a 100644
--- a/engines/ags/engine/ac/translation.cpp
+++ b/engines/ags/engine/ac/translation.cpp
@@ -56,10 +56,10 @@ void close_translation() {
set_uformat(U_ASCII);
}
-bool init_translation(const String &lang, const String &fallback_lang, bool quit_on_error) {
-
+bool init_translation(const String &lang, const String &fallback_lang) {
if (lang.IsEmpty())
return false;
+ _G(trans_name) = lang;
_G(trans_filename) = String::FromFormat("%s.tra", lang.GetCStr());
std::unique_ptr<Stream> in(_GP(AssetMgr)->OpenAsset(_G(trans_filename)));
@@ -80,20 +80,15 @@ bool init_translation(const String &lang, const String &fallback_lang, bool quit
// Process errors
if (!err) {
- String err_msg = String::FromFormat("Failed to read translation file: %s:\n%s",
+ close_translation();
+ Debug::Printf(kDbgMsg_Error, "Failed to read translation file: %s:\n%s",
_G(trans_filename).GetCStr(),
err->FullMessage().GetCStr());
- close_translation();
- if (quit_on_error) {
- quitprintf("!%s", err_msg.GetCStr());
- } else {
- Debug::Printf(kDbgMsg_Error, err_msg);
- if (!fallback_lang.IsEmpty()) {
- Debug::Printf("Fallback to translation: %s", fallback_lang.GetCStr());
- init_translation(fallback_lang, "", false);
- }
- return false;
+ if (!fallback_lang.IsEmpty()) {
+ Debug::Printf("Fallback to translation: %s", fallback_lang.GetCStr());
+ init_translation(fallback_lang, "");
}
+ return false;
}
// Translation read successfully
diff --git a/engines/ags/engine/ac/translation.h b/engines/ags/engine/ac/translation.h
index f14acbd17c1..98a9112ef1a 100644
--- a/engines/ags/engine/ac/translation.h
+++ b/engines/ags/engine/ac/translation.h
@@ -31,7 +31,7 @@ using AGS::Shared::String;
using AGS::Shared::StringMap;
void close_translation();
-bool init_translation(const String &lang, const String &fallback_lang, bool quit_on_error);
+bool init_translation(const String &lang, const String &fallback_lang);
// Returns current translation name, or empty string if default translation is used
String get_translation_name();
// Returns fill path to the translation file, or empty string if default translation is used
diff --git a/engines/ags/engine/main/engine.cpp b/engines/ags/engine/main/engine.cpp
index da1ed7d7539..9d1b9651b4f 100644
--- a/engines/ags/engine/main/engine.cpp
+++ b/engines/ags/engine/main/engine.cpp
@@ -800,7 +800,7 @@ void engine_init_game_settings() {
_GP(play).globalstrings[ee][0] = 0;
if (!_GP(usetup).translation.IsEmpty())
- init_translation(_GP(usetup).translation, "", true);
+ Game_ChangeTranslation(_GP(usetup).translation.GetCStr());
update_invorder();
_G(displayed_room) = -10;
Commit: 8e310c5d98ae667cc8a16d2574450976ab45726c
https://github.com/scummvm/scummvm/commit/8e310c5d98ae667cc8a16d2574450976ab45726c
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-03-27T19:14:55-07:00
Commit Message:
AGS: Split GameState::want_speech into two variables for easier handling
>From upstream 2f6e7362f742c59020fc6a70fdf67c5a87ff2e69
Changed paths:
engines/ags/engine/ac/display.cpp
engines/ags/engine/ac/game_state.cpp
engines/ags/engine/ac/game_state.h
engines/ags/engine/ac/global_audio.cpp
engines/ags/engine/ac/global_audio.h
engines/ags/engine/ac/global_debug.cpp
engines/ags/engine/ac/speech.h
engines/ags/engine/game/savegame.cpp
engines/ags/engine/game/savegame_internal.h
engines/ags/engine/main/engine.cpp
diff --git a/engines/ags/engine/ac/display.cpp b/engines/ags/engine/ac/display.cpp
index f4982318498..5b371590c58 100644
--- a/engines/ags/engine/ac/display.cpp
+++ b/engines/ags/engine/ac/display.cpp
@@ -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;
}
diff --git a/engines/ags/engine/ac/game_state.cpp b/engines/ags/engine/ac/game_state.cpp
index d1377afd50c..a23e357188e 100644
--- a/engines/ags/engine/ac/game_state.cpp
+++ b/engines/ags/engine/ac/game_state.cpp
@@ -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);
diff --git a/engines/ags/engine/ac/game_state.h b/engines/ags/engine/ac/game_state.h
index 40bb4325524..0dfec5c0eba 100644
--- a/engines/ags/engine/ac/game_state.h
+++ b/engines/ags/engine/ac/game_state.h
@@ -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;
diff --git a/engines/ags/engine/ac/global_audio.cpp b/engines/ags/engine/ac/global_audio.cpp
index 25505046c1f..aacce811acf 100644
--- a/engines/ags/engine/ac/global_audio.cpp
+++ b/engines/ags/engine/ac/global_audio.cpp
@@ -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;
diff --git a/engines/ags/engine/ac/global_audio.h b/engines/ags/engine/ac/global_audio.h
index fa3ca2a32ed..fb398ddc6fd 100644
--- a/engines/ags/engine/ac/global_audio.h
+++ b/engines/ags/engine/ac/global_audio.h
@@ -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);
diff --git a/engines/ags/engine/ac/global_debug.cpp b/engines/ags/engine/ac/global_debug.cpp
index b825b911bd6..af8a2fa9477 100644
--- a/engines/ags/engine/ac/global_debug.cpp
+++ b/engines/ags/engine/ac/global_debug.cpp
@@ -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 ");
diff --git a/engines/ags/engine/ac/speech.h b/engines/ags/engine/ac/speech.h
index 68bfc0cd3ba..9e10e13d76d 100644
--- a/engines/ags/engine/ac/speech.h
+++ b/engines/ags/engine/ac/speech.h
@@ -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);
diff --git a/engines/ags/engine/game/savegame.cpp b/engines/ags/engine/game/savegame.cpp
index f84772f92ff..8a4819a5d0f 100644
--- a/engines/ags/engine/game/savegame.cpp
+++ b/engines/ags/engine/game/savegame.cpp
@@ -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)
diff --git a/engines/ags/engine/game/savegame_internal.h b/engines/ags/engine/game/savegame_internal.h
index 080a1317354..12430ba53fa 100644
--- a/engines/ags/engine/game/savegame_internal.h
+++ b/engines/ags/engine/game/savegame_internal.h
@@ -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;
diff --git a/engines/ags/engine/main/engine.cpp b/engines/ags/engine/main/engine.cpp
index 9d1b9651b4f..48c165e2af7 100644
--- a/engines/ags/engine/main/engine.cpp
+++ b/engines/ags/engine/main/engine.cpp
@@ -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;
Commit: 70d620c07a866e14c30ee97ef4bc521167fc8974
https://github.com/scummvm/scummvm/commit/70d620c07a866e14c30ee97ef4bc521167fc8974
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-03-27T19:14:55-07:00
Commit Message:
AGS: Support freely switching voice-over pack at runtime
>From upstream 40b6fff14ac404185b822245bc1a3ba4af928a12
Changed paths:
engines/ags/engine/ac/game_state.cpp
engines/ags/engine/ac/global_audio.cpp
engines/ags/engine/ac/speech.cpp
engines/ags/engine/ac/speech.h
engines/ags/engine/main/engine.cpp
engines/ags/engine/main/engine.h
engines/ags/globals.h
engines/ags/shared/core/asset_manager.h
diff --git a/engines/ags/engine/ac/game_state.cpp b/engines/ags/engine/ac/game_state.cpp
index a23e357188e..d934512398d 100644
--- a/engines/ags/engine/ac/game_state.cpp
+++ b/engines/ags/engine/ac/game_state.cpp
@@ -393,7 +393,7 @@ bool GameState::IsNonBlockingVoiceSpeech() const {
bool GameState::ShouldPlayVoiceSpeech() const {
return !_GP(play).fast_forward &&
- (_GP(play).speech_mode != kSpeech_TextOnly) && (!_GP(ResPaths).SpeechPak.Name.IsEmpty());
+ (_GP(play).speech_mode != kSpeech_TextOnly) && (_GP(play).voice_avail);
}
void GameState::ReadFromSavegame(Shared::Stream *in, GameStateSvgVersion svg_ver, RestoredData &r_data) {
diff --git a/engines/ags/engine/ac/global_audio.cpp b/engines/ags/engine/ac/global_audio.cpp
index aacce811acf..e1f1a18d661 100644
--- a/engines/ags/engine/ac/global_audio.cpp
+++ b/engines/ags/engine/ac/global_audio.cpp
@@ -474,6 +474,7 @@ ScriptAudioChannel *PlayVoiceClip(CharacterInfo *ch, int sndid, bool as_speech)
// Construct an asset name for the voice-over clip for the given character and cue id
String get_cue_filename(int charid, int sndid) {
+ String asset_path = get_voice_assetpath();
String script_name;
if (charid >= 0) {
// append the first 4 characters of the script name to the filename
@@ -484,7 +485,7 @@ String get_cue_filename(int charid, int sndid) {
} else {
script_name = "NARR";
}
- return String::FromFormat("%s%d", script_name.GetCStr(), sndid);
+ return String::FromFormat("%s%s%d", asset_path.GetCStr(), script_name.GetCStr(), sndid);
}
// Play voice-over clip on the common channel;
diff --git a/engines/ags/engine/ac/speech.cpp b/engines/ags/engine/ac/speech.cpp
index 14c87fb944c..9ac9527af0a 100644
--- a/engines/ags/engine/ac/speech.cpp
+++ b/engines/ags/engine/ac/speech.cpp
@@ -19,9 +19,10 @@
*
*/
+#include "ags/engine/ac/speech.h"
+#include "ags/engine/ac/asset_helper.h"
#include "ags/shared/ac/common.h"
#include "ags/engine/ac/runtime_defines.h"
-#include "ags/engine/ac/speech.h"
#include "ags/engine/debugging/debug_log.h"
#include "ags/shared/ac/game_setup_struct.h"
#include "ags/engine/ac/game_state.h"
@@ -31,10 +32,17 @@
#include "ags/engine/script/script_api.h"
#include "ags/engine/script/script_runtime.h"
#include "ags/engine/ac/dynobj/script_overlay.h"
+#include "ags/engine/ac/game_setup.h"
+#include "ags/engine/ac/game_state.h"
+#include "ags/shared/core/asset_manager.h"
+#include "ags/engine/main/engine.h"
+#include "ags/shared/util/path.h"
#include "ags/globals.h"
namespace AGS3 {
+using namespace AGS::Shared;
+
int user_to_internal_skip_speech(SkipSpeechStyle userval) {
switch (userval) {
case kSkipSpeechNone:
@@ -82,6 +90,52 @@ SkipSpeechStyle internal_skip_speech_to_user(int internal_val) {
return kSkipSpeechNone;
}
+bool init_voicepak(const String &name) {
+ if (_GP(usetup).no_speech_pack) return false; // voice-over disabled
+
+ _GP(play).voice_avail = false;
+ String speech_file = name.IsEmpty() ? "speech.vox" : String::FromFormat("sp_%s.vox", name.GetCStr());
+ if (_GP(ResPaths).SpeechPak.Name.CompareNoCase(speech_file) == 0)
+ return true; // same pak already assigned
+
+ // First remove existing voice packs
+ _GP(AssetMgr)->RemoveLibrary(_GP(ResPaths).SpeechPak.Path);
+ _GP(AssetMgr)->RemoveLibrary(_GP(ResPaths).VoiceDirSub);
+
+ // Now check for the new packs and add if they exist
+ String speech_filepath = find_assetlib(speech_file);
+ if (!speech_filepath.IsEmpty()) {
+ Debug::Printf(kDbgMsg_Info, "Voice pack found: %s", speech_file.GetCStr());
+ _GP(play).voice_avail = true;
+ } else {
+ Debug::Printf(kDbgMsg_Error, "Unable to init voice pack '%s', file not found or of unknown format.",
+ speech_file.GetCStr());
+ }
+
+ String speech_subdir = "";
+ if (!_GP(ResPaths).VoiceDir2.IsEmpty() && 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
+ speech_subdir = name.IsEmpty() ? _GP(ResPaths).VoiceDir2 : Path::ConcatPaths(_GP(ResPaths).VoiceDir2, name);
+ if (File::IsDirectory(speech_subdir)) {
+ Debug::Printf(kDbgMsg_Info, "Optional voice directory is defined: %s", speech_subdir.GetCStr());
+ _GP(play).voice_avail = true;
+ }
+ }
+
+ // Save new resource locations and register asset libraries
+ _G(VoiceAssetPath) = name.IsEmpty() ? "" : String::FromFormat("%s/", name.GetCStr());
+ _GP(ResPaths).SpeechPak.Name = speech_file;
+ _GP(ResPaths).SpeechPak.Path = speech_filepath;
+ _GP(ResPaths).VoiceDirSub = speech_subdir;
+ _GP(AssetMgr)->AddLibrary(_GP(ResPaths).VoiceDirSub, "voice");
+ _GP(AssetMgr)->AddLibrary(_GP(ResPaths).SpeechPak.Path, "voice");
+ return _GP(play).voice_avail;
+}
+
+String get_voice_assetpath() {
+ return _G(VoiceAssetPath);
+}
+
//=============================================================================
//
// Script API Functions
diff --git a/engines/ags/engine/ac/speech.h b/engines/ags/engine/ac/speech.h
index 9e10e13d76d..1f2ee51038e 100644
--- a/engines/ags/engine/ac/speech.h
+++ b/engines/ags/engine/ac/speech.h
@@ -22,6 +22,8 @@
#ifndef AGS_ENGINE_AC_SPEECH_H
#define AGS_ENGINE_AC_SPEECH_H
+#include "ags/shared/util/string.h"
+
namespace AGS3 {
enum SkipSpeechStyle {
@@ -49,6 +51,11 @@ enum SpeechMode {
int user_to_internal_skip_speech(SkipSpeechStyle userval);
SkipSpeechStyle internal_skip_speech_to_user(int internal_val);
+// Locates and initializes a voice pack of the given *name*, tells if successful;
+// pass empty string for default voice pack.
+bool init_voicepak(const AGS::Shared::String &name = "");
+// Gets an asset's parent path for voice-over clips and data files
+AGS::Shared::String get_voice_assetpath();
} // namespace AGS3
diff --git a/engines/ags/engine/main/engine.cpp b/engines/ags/engine/main/engine.cpp
index 48c165e2af7..39ac3eb7b41 100644
--- a/engines/ags/engine/main/engine.cpp
+++ b/engines/ags/engine/main/engine.cpp
@@ -267,27 +267,7 @@ void engine_init_mouse() {
}
void engine_locate_speech_pak() {
- _GP(play).voice_avail = false;
-
- if (!_GP(usetup).no_speech_pack) {
- String speech_file = "speech.vox";
- String speech_filepath = find_assetlib(speech_file);
- if (!speech_filepath.IsEmpty()) {
- Debug::Printf("Initializing speech vox");
- if (_GP(AssetMgr)->AddLibrary(speech_filepath) != Shared::kAssetNoError) {
- _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).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).voice_avail = true;
- }
- _GP(ResPaths).SpeechPak.Name = speech_file;
- _GP(ResPaths).SpeechPak.Path = speech_filepath;
- }
+ init_voicepak("");
}
void engine_locate_audio_pak() {
diff --git a/engines/ags/engine/main/engine.h b/engines/ags/engine/main/engine.h
index 01c2bf65958..62bec9fabbf 100644
--- a/engines/ags/engine/main/engine.h
+++ b/engines/ags/engine/main/engine.h
@@ -63,7 +63,8 @@ struct ResourcePaths {
// This is bit ugly, but remain so until more flexible configuration is designed
String DataDir2; // optional data directory
String AudioDir2; // optional audio directory
- String VoiceDir2; // optional voice-over directory
+ String VoiceDir2; // optional voice-over directory (base)
+ String VoiceDirSub;// full voice-over directory with optional sub-dir
};
// (Re-)Assign all known asset search paths to the AssetManager
diff --git a/engines/ags/globals.h b/engines/ags/globals.h
index 064b9544988..4cd059b663f 100644
--- a/engines/ags/globals.h
+++ b/engines/ags/globals.h
@@ -529,6 +529,7 @@ public:
ScriptDialogOptionsRendering *_ccDialogOptionsRendering;
ScriptDrawingSurface *_dialogOptionsRenderingSurface = nullptr;
+ String _VoiceAssetPath;
int _said_speech_line = 0; // used while in dialog to track whether screen needs updating
int _said_text = 0;
int _longestline = 0;
diff --git a/engines/ags/shared/core/asset_manager.h b/engines/ags/shared/core/asset_manager.h
index eb51c44e0cd..a61dd606c20 100644
--- a/engines/ags/shared/core/asset_manager.h
+++ b/engines/ags/shared/core/asset_manager.h
@@ -94,7 +94,8 @@ public:
// Add library location to the list of asset locations
AssetError AddLibrary(const String &path, const AssetLibInfo **lib = nullptr);
- // Add library location, specifying comma-separated list of filters
+ // Add library location, specifying comma-separated list of filters;
+ // if library was already added before, this method will overwrite the filters only
AssetError AddLibrary(const String &path, const String &filters, const AssetLibInfo **lib = nullptr);
// Remove library location from the list of asset locations
void RemoveLibrary(const String &path);
Commit: 719ea5b72c315c7c460d3a85242882df4c2817a1
https://github.com/scummvm/scummvm/commit/719ea5b72c315c7c460d3a85242882df4c2817a1
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-03-27T19:14:55-07:00
Commit Message:
AGS: Added Game.ChangeSpeechVox and SpeechVoxFilename
>From upstream ef3e9ae2df25fba24a3c1c091c81981431a72f36
Changed paths:
engines/ags/engine/ac/game.cpp
engines/ags/engine/ac/game.h
engines/ags/engine/ac/speech.cpp
engines/ags/engine/ac/speech.h
engines/ags/engine/script/script_api.h
engines/ags/globals.h
diff --git a/engines/ags/engine/ac/game.cpp b/engines/ags/engine/ac/game.cpp
index 3605b71e027..c603df1dc7f 100644
--- a/engines/ags/engine/ac/game.cpp
+++ b/engines/ags/engine/ac/game.cpp
@@ -716,6 +716,20 @@ int Game_ChangeTranslation(const char *newFilename) {
return 1;
}
+const char *Game_GetSpeechVoxFilename() {
+ return CreateNewScriptString(get_voicepak_name().GetCStr());
+}
+
+bool Game_ChangeSpeechVox(const char *newFilename) {
+ if (!init_voicepak(newFilename)) {
+ // if failed (and was not default)- fallback to default
+ if (strlen(newFilename) > 0)
+ init_voicepak();
+ return false;
+ }
+ return true;
+}
+
ScriptAudioClip *Game_GetAudioClip(int index) {
if (index < 0 || (size_t)index >= _GP(game).audioClips.size())
return nullptr;
@@ -1468,6 +1482,10 @@ RuntimeScriptValue Sc_Game_ChangeTranslation(const RuntimeScriptValue *params, i
API_SCALL_INT_POBJ(Game_ChangeTranslation, const char);
}
+RuntimeScriptValue Sc_Game_ChangeSpeechVox(const RuntimeScriptValue *params, int32_t param_count) {
+ API_SCALL_BOOL_POBJ(Game_ChangeSpeechVox, const char);
+}
+
// int (const char *token)
RuntimeScriptValue Sc_Game_DoOnceOnly(const RuntimeScriptValue *params, int32_t param_count) {
API_SCALL_INT_POBJ(Game_DoOnceOnly, const char);
@@ -1663,6 +1681,10 @@ RuntimeScriptValue Sc_Game_GetTranslationFilename(const RuntimeScriptValue *para
API_CONST_SCALL_OBJ(const char, _GP(myScriptStringImpl), Game_GetTranslationFilename);
}
+RuntimeScriptValue Sc_Game_GetSpeechVoxFilename(const RuntimeScriptValue *params, int32_t param_count) {
+ API_SCALL_OBJ(const char, _GP(myScriptStringImpl), Game_GetSpeechVoxFilename);
+}
+
// int ()
RuntimeScriptValue Sc_Game_GetUseNativeCoordinates(const RuntimeScriptValue *params, int32_t param_count) {
API_SCALL_INT(Game_GetUseNativeCoordinates);
@@ -1682,7 +1704,7 @@ RuntimeScriptValue Sc_Game_GetAudioClip(const RuntimeScriptValue *params, int32_
}
RuntimeScriptValue Sc_Game_IsPluginLoaded(const RuntimeScriptValue *params, int32_t param_count) {
- API_SCALL_BOOL_OBJ(pl_is_plugin_loaded, const char);
+ API_SCALL_BOOL_POBJ(pl_is_plugin_loaded, const char);
}
RuntimeScriptValue Sc_Game_PlayVoiceClip(const RuntimeScriptValue *params, int32_t param_count) {
@@ -1759,9 +1781,11 @@ void RegisterGameAPI() {
ccAddExternalStaticFunction("Game::get_AudioClipCount", Sc_Game_GetAudioClipCount);
ccAddExternalStaticFunction("Game::geti_AudioClips", Sc_Game_GetAudioClip);
ccAddExternalStaticFunction("Game::IsPluginLoaded", Sc_Game_IsPluginLoaded);
+ ccAddExternalStaticFunction("Game::ChangeSpeechVox", Sc_Game_ChangeSpeechVox);
ccAddExternalStaticFunction("Game::PlayVoiceClip", Sc_Game_PlayVoiceClip);
ccAddExternalStaticFunction("Game::SimulateKeyPress", Sc_Game_SimulateKeyPress);
ccAddExternalStaticFunction("Game::get_BlockingWaitSkipped", Sc_Game_BlockingWaitSkipped);
+ ccAddExternalStaticFunction("Game::get_SpeechVoxFilename", Sc_Game_GetSpeechVoxFilename);
ccAddExternalStaticFunction("Game::get_Camera", Sc_Game_GetCamera);
ccAddExternalStaticFunction("Game::get_CameraCount", Sc_Game_GetCameraCount);
diff --git a/engines/ags/engine/ac/game.h b/engines/ags/engine/ac/game.h
index 3b046b9d053..3fa76848152 100644
--- a/engines/ags/engine/ac/game.h
+++ b/engines/ags/engine/ac/game.h
@@ -140,6 +140,8 @@ int Game_GetNormalFont();
const char *Game_GetTranslationFilename();
int Game_ChangeTranslation(const char *newFilename);
+const char *Game_GetSpeechVoxFilename();
+bool Game_ChangeSpeechVox(const char *newFilename);
//=============================================================================
diff --git a/engines/ags/engine/ac/speech.cpp b/engines/ags/engine/ac/speech.cpp
index 9ac9527af0a..a83f4e2a38a 100644
--- a/engines/ags/engine/ac/speech.cpp
+++ b/engines/ags/engine/ac/speech.cpp
@@ -123,6 +123,7 @@ bool init_voicepak(const String &name) {
}
// Save new resource locations and register asset libraries
+ _G(VoicePakName) = name;
_G(VoiceAssetPath) = name.IsEmpty() ? "" : String::FromFormat("%s/", name.GetCStr());
_GP(ResPaths).SpeechPak.Name = speech_file;
_GP(ResPaths).SpeechPak.Path = speech_filepath;
@@ -132,6 +133,10 @@ bool init_voicepak(const String &name) {
return _GP(play).voice_avail;
}
+String get_voicepak_name() {
+ return _G(VoicePakName);
+}
+
String get_voice_assetpath() {
return _G(VoiceAssetPath);
}
diff --git a/engines/ags/engine/ac/speech.h b/engines/ags/engine/ac/speech.h
index 1f2ee51038e..6bfff0537a8 100644
--- a/engines/ags/engine/ac/speech.h
+++ b/engines/ags/engine/ac/speech.h
@@ -54,6 +54,8 @@ SkipSpeechStyle internal_skip_speech_to_user(int internal_val);
// Locates and initializes a voice pack of the given *name*, tells if successful;
// pass empty string for default voice pack.
bool init_voicepak(const AGS::Shared::String &name = "");
+// Gets voice pack's ID name, that is a filename without "sp_" prefix and no extension.
+AGS::Shared::String get_voicepak_name();
// Gets an asset's parent path for voice-over clips and data files
AGS::Shared::String get_voice_assetpath();
diff --git a/engines/ags/engine/script/script_api.h b/engines/ags/engine/script/script_api.h
index 0217ae6f643..8f4887e7f95 100644
--- a/engines/ags/engine/script/script_api.h
+++ b/engines/ags/engine/script/script_api.h
@@ -280,7 +280,7 @@ inline const char *ScriptVSprintf(char *buffer, size_t buf_length, const char *f
#define API_SCALL_BOOL(FUNCTION) \
return RuntimeScriptValue().SetInt32AsBool(FUNCTION())
-#define API_SCALL_BOOL_OBJ(FUNCTION, P1CLASS) \
+#define API_SCALL_BOOL_POBJ(FUNCTION, P1CLASS) \
ASSERT_PARAM_COUNT(FUNCTION, 1); \
return RuntimeScriptValue().SetInt32AsBool(FUNCTION((P1CLASS*)params[0].Ptr))
diff --git a/engines/ags/globals.h b/engines/ags/globals.h
index 4cd059b663f..d6418494d56 100644
--- a/engines/ags/globals.h
+++ b/engines/ags/globals.h
@@ -529,6 +529,9 @@ public:
ScriptDialogOptionsRendering *_ccDialogOptionsRendering;
ScriptDrawingSurface *_dialogOptionsRenderingSurface = nullptr;
+ // identifier (username) of the voice pak
+ String _VoicePakName;
+ // parent part to use when making voice asset names
String _VoiceAssetPath;
int _said_speech_line = 0; // used while in dialog to track whether screen needs updating
int _said_text = 0;
More information about the Scummvm-git-logs
mailing list