[Scummvm-git-logs] scummvm master -> 49c8bc415b459c292db27d7ade36dcf594b3c528
dreammaster
dreammaster at scummvm.org
Sun Mar 7 00:30:43 UTC 2021
This automated email contains information about 7 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
e81f87769d AGS: Remove deprecated code from AGSLinux
fd5c11f382 AGS: Move debug globals to Globals
f07da658f1 AGS: Move engine.cpp globals to Globals
68e925ecd0 AGS: Move interactions.cpp globals to Globals
9b4f54cf77 AGS: Move file.cpp globals to Globals
21e9dde4ca AGS: Move cc_error.cpp globals to Globals
49c8bc415b AGS: Move global_dialog.cpp globals to Globals
Commit: e81f87769dcf677d3646be49c7d011ee091f821e
https://github.com/scummvm/scummvm/commit/e81f87769dcf677d3646be49c7d011ee091f821e
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-03-06T15:11:38-08:00
Commit Message:
AGS: Remove deprecated code from AGSLinux
Changed paths:
engines/ags/engine/platform/linux/acpllnx.cpp
diff --git a/engines/ags/engine/platform/linux/acpllnx.cpp b/engines/ags/engine/platform/linux/acpllnx.cpp
index f9a0706525..62c70f8f6a 100644
--- a/engines/ags/engine/platform/linux/acpllnx.cpp
+++ b/engines/ags/engine/platform/linux/acpllnx.cpp
@@ -43,14 +43,6 @@ namespace AGS3 {
using AGS::Shared::String;
-
-// Replace the default Allegro icon. The original defintion is in the
-// Allegro 4.4 source under "src/x/xwin.c".
-//include "ags/shared/icon.xpm"
-//void *allegro_icon = icon_xpm;
-String CommonDataDirectory;
-String UserDataDirectory;
-
struct AGSLinux : AGSPlatformDriver {
int CDPlayerCommand(int cmdd, int datt) override;
@@ -92,50 +84,12 @@ void AGSLinux::DisplayAlert(const char *text, ...) {
::AGS::g_vm->GUIError(msg);
}
-size_t BuildXDGPath(char *destPath, size_t destSize) {
-#ifdef TODO
- // Check to see if XDG_DATA_HOME is set in the enviroment
- const char *home_dir = getenv("XDG_DATA_HOME");
- size_t l = 0;
- if (home_dir) {
- l = snprintf(destPath, destSize, "%s", home_dir);
- } else {
- // No evironment variable, so we fall back to home dir in /etc/passwd
- struct passwd *p = getpwuid(getuid());
- l = snprintf(destPath, destSize, "%s/.local", p->pw_dir);
- if (mkdir(destPath, 0755) != 0 && errnum != AL_EEXIST)
- return 0;
- l += snprintf(destPath + l, destSize - l, "/share");
- if (mkdir(destPath, 0755) != 0 && errnum != AL_EEXIST)
- return 0;
- }
- return l;
-#endif
- return 0;
-}
-
-void DetermineDataDirectories() {
-#ifdef TODO
- if (!UserDataDirectory.IsEmpty())
- return;
- char xdg_path[256];
- if (BuildXDGPath(xdg_path, sizeof(xdg_path)) == 0)
- sprintf(xdg_path, "%s", "/tmp");
- UserDataDirectory.Format("%s/ags", xdg_path);
- mkdir(UserDataDirectory.GetCStr(), 0755);
- CommonDataDirectory.Format("%s/ags-common", xdg_path);
- mkdir(CommonDataDirectory.GetCStr(), 0755);
-#endif
-}
-
const char *AGSLinux::GetAllUsersDataDirectory() {
- DetermineDataDirectories();
- return CommonDataDirectory;
+ return "";
}
const char *AGSLinux::GetUserSavedgamesDirectory() {
- DetermineDataDirectories();
- return UserDataDirectory;
+ return "";
}
const char *AGSLinux::GetUserConfigDirectory() {
@@ -147,8 +101,7 @@ const char *AGSLinux::GetUserGlobalConfigDirectory() {
}
const char *AGSLinux::GetAppOutputDirectory() {
- DetermineDataDirectories();
- return UserDataDirectory;
+ return "";
}
unsigned long AGSLinux::GetDiskFreeSpaceMB() {
@@ -161,7 +114,7 @@ const char *AGSLinux::GetNoMouseErrorString() {
}
const char *AGSLinux::GetAllegroFailUserHint() {
- return "Make sure you have latest version of Allegro 4 libraries installed, and X server is running.";
+ return nullptr;
}
eScriptSystemOSID AGSLinux::GetSystemOSID() {
Commit: fd5c11f38279a1022e033c86250f40cac84beade
https://github.com/scummvm/scummvm/commit/fd5c11f38279a1022e033c86250f40cac84beade
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-03-06T15:11:38-08:00
Commit Message:
AGS: Move debug globals to Globals
Changed paths:
engines/ags/ags.cpp
engines/ags/engine/ac/draw.cpp
engines/ags/engine/ac/game.cpp
engines/ags/engine/ac/global_audio.cpp
engines/ags/engine/ac/global_debug.cpp
engines/ags/engine/ac/global_video.cpp
engines/ags/engine/ac/room.cpp
engines/ags/engine/debugging/consoleoutputtarget.cpp
engines/ags/engine/debugging/debug.cpp
engines/ags/engine/debugging/debug_log.h
engines/ags/engine/debugging/debugger.h
engines/ags/engine/main/engine.cpp
engines/ags/engine/main/game_run.cpp
engines/ags/engine/media/audio/audio.cpp
engines/ags/globals.cpp
engines/ags/globals.h
diff --git a/engines/ags/ags.cpp b/engines/ags/ags.cpp
index b366b7df65..97ee0819f6 100644
--- a/engines/ags/ags.cpp
+++ b/engines/ags/ags.cpp
@@ -135,7 +135,7 @@ static int main_process_cmdline(ConfigTree &cfg, int argc, const char *argv[]) {
_G(justDisplayVersion) = true;
return 0;
} else if (scumm_stricmp(arg, "-updatereg") == 0)
- debug_flags |= DBG_REGONLY;
+ _G(debug_flags) |= DBG_REGONLY;
#if AGS_PLATFORM_DEBUG
else if ((scumm_stricmp(arg, "--startr") == 0) && (ee < argc - 1)) {
_G(override_start_room) = atoi(argv[ee + 1]);
@@ -196,17 +196,17 @@ static int main_process_cmdline(ConfigTree &cfg, int argc, const char *argv[]) {
INIwritestring(cfg, "graphics", "game_scale_win", argv[++ee]);
else
INIwritestring(cfg, "graphics", "game_scale_win", "max_round");
- } else if (scumm_stricmp(arg, "--fps") == 0) display_fps = kFPS_Forced;
- else if (scumm_stricmp(arg, "--test") == 0) debug_flags |= DBG_DEBUGMODE;
- else if (scumm_stricmp(arg, "-noiface") == 0) debug_flags |= DBG_NOIFACE;
- else if (scumm_stricmp(arg, "-nosprdisp") == 0) debug_flags |= DBG_NODRAWSPRITES;
- else if (scumm_stricmp(arg, "-nospr") == 0) debug_flags |= DBG_NOOBJECTS;
- else if (scumm_stricmp(arg, "-noupdate") == 0) debug_flags |= DBG_NOUPDATE;
- else if (scumm_stricmp(arg, "-nosound") == 0) debug_flags |= DBG_NOSFX;
- else if (scumm_stricmp(arg, "-nomusic") == 0) debug_flags |= DBG_NOMUSIC;
- else if (scumm_stricmp(arg, "-noscript") == 0) debug_flags |= DBG_NOSCRIPT;
- else if (scumm_stricmp(arg, "-novideo") == 0) debug_flags |= DBG_NOVIDEO;
- else if (scumm_stricmp(arg, "-dbgscript") == 0) debug_flags |= DBG_DBGSCRIPT;
+ } else if (scumm_stricmp(arg, "--fps") == 0) _G(display_fps) = kFPS_Forced;
+ else if (scumm_stricmp(arg, "--test") == 0) _G(debug_flags) |= DBG_DEBUGMODE;
+ else if (scumm_stricmp(arg, "-noiface") == 0) _G(debug_flags) |= DBG_NOIFACE;
+ else if (scumm_stricmp(arg, "-nosprdisp") == 0) _G(debug_flags) |= DBG_NODRAWSPRITES;
+ else if (scumm_stricmp(arg, "-nospr") == 0) _G(debug_flags) |= DBG_NOOBJECTS;
+ else if (scumm_stricmp(arg, "-noupdate") == 0) _G(debug_flags) |= DBG_NOUPDATE;
+ else if (scumm_stricmp(arg, "-nosound") == 0) _G(debug_flags) |= DBG_NOSFX;
+ else if (scumm_stricmp(arg, "-nomusic") == 0) _G(debug_flags) |= DBG_NOMUSIC;
+ else if (scumm_stricmp(arg, "-noscript") == 0) _G(debug_flags) |= DBG_NOSCRIPT;
+ else if (scumm_stricmp(arg, "-novideo") == 0) _G(debug_flags) |= DBG_NOVIDEO;
+ else if (scumm_stricmp(arg, "-dbgscript") == 0) _G(debug_flags) |= DBG_DBGSCRIPT;
else if (scumm_stricmp(arg, "--log") == 0) INIwriteint(cfg, "misc", "log", 1);
else if (scumm_stricmp(arg, "--no-log") == 0) INIwriteint(cfg, "misc", "log", 0);
//
@@ -332,7 +332,7 @@ Common::Error AGSEngine::run() {
#if AGS_PLATFORM_OS_WINDOWS
setup_malloc_handling();
#endif
- AGS3::debug_flags = 0;
+ _G(debug_flags) = 0;
AGS3::ConfigTree startup_opts;
int res = AGS3::main_process_cmdline(startup_opts, ARGC, ARGV);
@@ -357,7 +357,7 @@ Common::Error AGSEngine::run() {
AGS3::main_set_gamedir(ARGC, ARGV);
// Update shell associations and exit
- if (AGS3::debug_flags & DBG_REGONLY)
+ if (_G(debug_flags) & DBG_REGONLY)
return Common::kNoError;
_G(loadSaveGameOnStartup) = ConfMan.getInt("save_slot");
diff --git a/engines/ags/engine/ac/draw.cpp b/engines/ags/engine/ac/draw.cpp
index 6cc9b3aa9a..cf6d7b3c61 100644
--- a/engines/ags/engine/ac/draw.cpp
+++ b/engines/ags/engine/ac/draw.cpp
@@ -1828,11 +1828,11 @@ void prepare_room_sprites() {
clear_sprite_list();
- if ((debug_flags & DBG_NOOBJECTS) == 0) {
+ if ((_G(debug_flags) & DBG_NOOBJECTS) == 0) {
prepare_objects_for_drawing();
prepare_characters_for_drawing();
- if ((debug_flags & DBG_NODRAWSPRITES) == 0) {
+ if ((_G(debug_flags) & DBG_NODRAWSPRITES) == 0) {
our_eip = 34;
draw_sprite_list();
}
@@ -1910,8 +1910,8 @@ void draw_fps(const Rect &viewport) {
char fps_buffer[60];
// Don't display fps if we don't have enough information (because loop count was just reset)
- if (!std::isUndefined(fps)) {
- snprintf(fps_buffer, sizeof(fps_buffer), "FPS: %2.1f / %s", fps, base_buffer);
+ if (!std::isUndefined(_G(fps))) {
+ snprintf(fps_buffer, sizeof(fps_buffer), "FPS: %2.1f / %s", _G(fps), base_buffer);
} else {
snprintf(fps_buffer, sizeof(fps_buffer), "FPS: --.- / %s", base_buffer);
}
@@ -1950,7 +1950,7 @@ void draw_gui_and_overlays() {
// Draw GUIs - they should always be on top of overlays like
// speech background text
our_eip = 35;
- if (((debug_flags & DBG_NOIFACE) == 0) && (displayed_room >= 0)) {
+ if (((_G(debug_flags) & DBG_NOIFACE) == 0) && (displayed_room >= 0)) {
int aa;
if (playerchar->activeinv >= MAX_INV) {
@@ -2235,7 +2235,7 @@ void construct_engine_overlay() {
gfxDriver->BeginSpriteBatch(viewport, SpriteTransform());
// draw the debug console, if appropriate
- if ((_GP(play).debug_mode > 0) && (display_console != 0)) {
+ if ((_GP(play).debug_mode > 0) && (_G(display_console) != 0)) {
const int font = FONT_NORMAL;
int ypp = 1;
int txtspacing = getfontspacing_outlined(font);
@@ -2249,8 +2249,8 @@ void construct_engine_overlay() {
color_t draw_color = debugConsoleBuffer->GetCompatibleColor(15);
debugConsoleBuffer->FillRect(Rect(0, 0, viewport.GetWidth() - 1, barheight), draw_color);
color_t text_color = debugConsoleBuffer->GetCompatibleColor(16);
- for (int jj = first_debug_line; jj != last_debug_line; jj = (jj + 1) % DEBUG_CONSOLE_NUMLINES) {
- wouttextxy(debugConsoleBuffer, 1, ypp, font, text_color, debug_line[jj]);
+ for (int jj = _G(first_debug_line); jj != _G(last_debug_line); jj = (jj + 1) % DEBUG_CONSOLE_NUMLINES) {
+ wouttextxy(debugConsoleBuffer, 1, ypp, font, text_color, _G(debug_line)[jj]);
ypp += txtspacing;
}
@@ -2263,7 +2263,7 @@ void construct_engine_overlay() {
invalidate_sprite(0, 0, debugConsole, false);
}
- if (display_fps != kFPS_Hide)
+ if (_G(display_fps) != kFPS_Hide)
draw_fps(viewport);
}
diff --git a/engines/ags/engine/ac/game.cpp b/engines/ags/engine/ac/game.cpp
index ae1b8dbabe..e2f0143e91 100644
--- a/engines/ags/engine/ac/game.cpp
+++ b/engines/ags/engine/ac/game.cpp
@@ -970,8 +970,8 @@ void create_savegame_screenshot(Bitmap *&screenShot) {
// that it supports it. But we want it all the time for ScummVM GMM
if (/*_GP(game).options[OPT_SAVESCREENSHOT] */true) {
// Render the view without any UI elements
- int old_flags = debug_flags;
- debug_flags |= DBG_NOIFACE;
+ int old_flags = _G(debug_flags);
+ _G(debug_flags) |= DBG_NOIFACE;
construct_game_scene(true);
int usewid = data_to_game_coord(_GP(play).screenshot_width);
@@ -988,7 +988,7 @@ void create_savegame_screenshot(Bitmap *&screenShot) {
screenShot = CopyScreenIntoBitmap(usewid, usehit);
// Restore original screen
- debug_flags = old_flags;
+ _G(debug_flags) = old_flags;
construct_game_scene(true);
}
}
diff --git a/engines/ags/engine/ac/global_audio.cpp b/engines/ags/engine/ac/global_audio.cpp
index f1f3fb76f1..576e133984 100644
--- a/engines/ags/engine/ac/global_audio.cpp
+++ b/engines/ags/engine/ac/global_audio.cpp
@@ -126,7 +126,7 @@ int IsSoundPlaying() {
// returns -1 on failure, channel number on success
int PlaySoundEx(int val1, int channel) {
- if (debug_flags & DBG_NOSFX)
+ if (_G(debug_flags) & DBG_NOSFX)
return -1;
ScriptAudioClip *aclip = GetAudioClipForOldStyleNumber(_GP(game), false, val1);
diff --git a/engines/ags/engine/ac/global_debug.cpp b/engines/ags/engine/ac/global_debug.cpp
index 5290658b6d..7e3dd4e6d0 100644
--- a/engines/ags/engine/ac/global_debug.cpp
+++ b/engines/ags/engine/ac/global_debug.cpp
@@ -138,8 +138,8 @@ void script_debug(int cmdd, int dataa) {
if (goToRoom >= 0)
NewRoom(goToRoom);
} else if (cmdd == 4) {
- if (display_fps != kFPS_Forced)
- display_fps = (FPSDisplayMode)dataa;
+ if (_G(display_fps) != kFPS_Forced)
+ _G(display_fps) = (FPSDisplayMode)dataa;
} else if (cmdd == 5) {
if (dataa == 0) dataa = _GP(game).playercharacter;
if (_GP(game).chars[dataa].walking < 1) {
diff --git a/engines/ags/engine/ac/global_video.cpp b/engines/ags/engine/ac/global_video.cpp
index d2faf689df..89489c2b98 100644
--- a/engines/ags/engine/ac/global_video.cpp
+++ b/engines/ags/engine/ac/global_video.cpp
@@ -42,7 +42,7 @@ void scrPlayVideo(const char *name, int skip, int flags) {
if (_GP(play).fast_forward)
return;
- if (debug_flags & DBG_NOVIDEO)
+ if (_G(debug_flags) & DBG_NOVIDEO)
return;
if ((flags < 10) && (_GP(usetup).audio_backend == 0)) {
diff --git a/engines/ags/engine/ac/room.cpp b/engines/ags/engine/ac/room.cpp
index 4fc0562152..73137912ba 100644
--- a/engines/ags/engine/ac/room.cpp
+++ b/engines/ags/engine/ac/room.cpp
@@ -713,7 +713,7 @@ void load_new_room(int newnum, CharacterInfo *forchar) {
update_polled_stuff_if_runtime();
_G(roominst) = nullptr;
- if (debug_flags & DBG_NOSCRIPT) ;
+ if (_G(debug_flags) & DBG_NOSCRIPT) ;
else if (_GP(thisroom).CompiledScript != nullptr) {
compile_room_script();
if (croom->tsdatasize > 0) {
diff --git a/engines/ags/engine/debugging/consoleoutputtarget.cpp b/engines/ags/engine/debugging/consoleoutputtarget.cpp
index ebff347358..c80e3e2a05 100644
--- a/engines/ags/engine/debugging/consoleoutputtarget.cpp
+++ b/engines/ags/engine/debugging/consoleoutputtarget.cpp
@@ -20,9 +20,9 @@
*
*/
-//include <string.h>
#include "ags/engine/debugging/consoleoutputtarget.h"
#include "ags/engine/debugging/debug_log.h"
+#include "ags/globals.h"
namespace AGS3 {
namespace AGS {
@@ -36,11 +36,11 @@ ConsoleOutputTarget::~ConsoleOutputTarget() {}
void ConsoleOutputTarget::PrintMessage(const DebugMessage &msg) {
// limit number of characters for console
// TODO: is there a way to find out how many characters can fit in?
- debug_line[last_debug_line] = msg.Text.Left(99);
+ _G(debug_line)[_G(last_debug_line)] = msg.Text.Left(99);
- last_debug_line = (last_debug_line + 1) % DEBUG_CONSOLE_NUMLINES;
- if (last_debug_line == first_debug_line)
- first_debug_line = (first_debug_line + 1) % DEBUG_CONSOLE_NUMLINES;
+ _G(last_debug_line) = (_G(last_debug_line) + 1) % DEBUG_CONSOLE_NUMLINES;
+ if (_G(last_debug_line) == _G(first_debug_line))
+ _G(first_debug_line) = (_G(first_debug_line) + 1) % DEBUG_CONSOLE_NUMLINES;
}
} // namespace Engine
diff --git a/engines/ags/engine/debugging/debug.cpp b/engines/ags/engine/debugging/debug.cpp
index 3a66e0c042..2a00e0a4db 100644
--- a/engines/ags/engine/debugging/debug.cpp
+++ b/engines/ags/engine/debugging/debug.cpp
@@ -48,7 +48,8 @@
#include "ags/events.h"
#if AGS_PLATFORM_OS_WINDOWS
-//include <winalleg.h>
+#include <winalleg.h>
+#include "ags/shared/platform/windows/debug/namedpipesagsdebugger.h"
#endif
namespace AGS3 {
@@ -58,14 +59,15 @@ using namespace AGS::Engine;
extern char check_dynamic_sprites_at_exit;
extern int displayed_room;
-
extern char pexbuf[STD_BUFFER_SIZE];
+const char *OutputMsgBufID = "buffer";
+const char *OutputFileID = "file";
+const char *OutputSystemID = "stdout";
+const char *OutputGameConsoleID = "console";
-#if AGS_PLATFORM_OS_WINDOWS
-
-#include "ags/shared/platform/windows/debug/namedpipesagsdebugger.h"
+#if AGS_PLATFORM_OS_WINDOWS
HWND editor_window_handle = 0;
IAGSEditorDebugger *GetEditorDebugger(const char *instanceToken) {
@@ -80,40 +82,21 @@ IAGSEditorDebugger *GetEditorDebugger(const char *instanceToken) {
#endif
-int debug_flags = 0;
-
-String debug_line[DEBUG_CONSOLE_NUMLINES];
-int first_debug_line = 0, last_debug_line = 0, display_console = 0;
-
-float fps = std::numeric_limits<float>::quiet_undefined();
-FPSDisplayMode display_fps = kFPS_Hide;
-
-std::unique_ptr<MessageBuffer> DebugMsgBuff;
-std::unique_ptr<LogFile> DebugLogFile;
-std::unique_ptr<ConsoleOutputTarget> DebugConsole;
-
-const String OutputMsgBufID = "buffer";
-const String OutputFileID = "file";
-const String OutputSystemID = "stdout";
-const String OutputGameConsoleID = "console";
-
-
-
PDebugOutput create_log_output(const String &name, const String &path = "", LogFile::OpenMode open_mode = LogFile::kLogFile_Overwrite) {
// Else create new one, if we know this ID
if (name.CompareNoCase(OutputSystemID) == 0) {
return _GP(DbgMgr).RegisterOutput(OutputSystemID, AGSPlatformDriver::GetDriver(), kDbgMsg_None);
} else if (name.CompareNoCase(OutputFileID) == 0) {
- DebugLogFile.reset(new LogFile());
+ _GP(DebugLogFile).reset(new LogFile());
String logfile_path = !path.IsEmpty() ? path : String::FromFormat("%s/ags.log", platform->GetAppOutputDirectory());
- if (!DebugLogFile->OpenFile(logfile_path, open_mode))
+ if (!_GP(DebugLogFile)->OpenFile(logfile_path, open_mode))
return nullptr;
platform->WriteStdOut("Logging to %s", logfile_path.GetCStr());
- auto dbgout = _GP(DbgMgr).RegisterOutput(OutputFileID, DebugLogFile.get(), kDbgMsg_None);
+ auto dbgout = _GP(DbgMgr).RegisterOutput(OutputFileID, _GP(DebugLogFile).get(), kDbgMsg_None);
return dbgout;
} else if (name.CompareNoCase(OutputGameConsoleID) == 0) {
- DebugConsole.reset(new ConsoleOutputTarget());
- return _GP(DbgMgr).RegisterOutput(OutputGameConsoleID, DebugConsole.get(), kDbgMsg_None);
+ _GP(DebugConsole).reset(new ConsoleOutputTarget());
+ return _GP(DbgMgr).RegisterOutput(OutputGameConsoleID, _GP(DebugConsole).get(), kDbgMsg_None);
}
return nullptr;
}
@@ -206,8 +189,8 @@ void apply_log_config(const ConfigTree &cfg, const String &log_id,
}
// Delegate buffered messages to this new output
- if (DebugMsgBuff && !was_created_earlier)
- DebugMsgBuff->Send(log_id);
+ if (_GP(DebugMsgBuff) && !was_created_earlier)
+ _GP(DebugMsgBuff)->Send(log_id);
}
void init_debug(const ConfigTree &cfg, bool stderr_only) {
@@ -219,8 +202,8 @@ void init_debug(const ConfigTree &cfg, bool stderr_only) {
return;
// Message buffer to save all messages in case we read different log settings from config file
- DebugMsgBuff.reset(new MessageBuffer());
- _GP(DbgMgr).RegisterOutput(OutputMsgBufID, DebugMsgBuff.get(), kDbgMsg_All);
+ _GP(DebugMsgBuff).reset(new MessageBuffer());
+ _GP(DbgMgr).RegisterOutput(OutputMsgBufID, _GP(DebugMsgBuff).get(), kDbgMsg_All);
}
void apply_debug_config(const ConfigTree &cfg) {
@@ -258,7 +241,7 @@ void apply_debug_config(const ConfigTree &cfg) {
// If the game was compiled in Debug mode *and* there's no regular file log,
// then open "warnings.log" for printing script warnings.
- if (_GP(game).options[OPT_DEBUGMODE] != 0 && !DebugLogFile) {
+ if (_GP(game).options[OPT_DEBUGMODE] != 0 && !_GP(DebugLogFile)) {
auto dbgout = create_log_output(OutputFileID, "warnings.log", LogFile::kLogFile_OverwriteAtFirstMessage);
if (dbgout) {
dbgout->SetGroupFilter(kDbgGroup_Game, kDbgMsg_Warn);
@@ -268,20 +251,20 @@ void apply_debug_config(const ConfigTree &cfg) {
// We don't need message buffer beyond this point
_GP(DbgMgr).UnregisterOutput(OutputMsgBufID);
- DebugMsgBuff.reset();
+ _GP(DebugMsgBuff).reset();
}
void shutdown_debug() {
// Shutdown output subsystem
_GP(DbgMgr).UnregisterAll();
- DebugMsgBuff.reset();
- DebugLogFile.reset();
- DebugConsole.reset();
+ _GP(DebugMsgBuff).reset();
+ _GP(DebugLogFile).reset();
+ _GP(DebugConsole).reset();
}
void debug_set_console(bool enable) {
- if (DebugConsole)
+ if (_GP(DebugConsole))
_GP(DbgMgr).GetOutput(OutputGameConsoleID)->SetEnabled(enable);
}
diff --git a/engines/ags/engine/debugging/debug_log.h b/engines/ags/engine/debugging/debug_log.h
index 9525086218..6d20839f25 100644
--- a/engines/ags/engine/debugging/debug_log.h
+++ b/engines/ags/engine/debugging/debug_log.h
@@ -49,10 +49,6 @@ bool init_editor_debugging();
// allow LShift to single-step, RShift to pause flow
void scriptDebugHook(ccInstance *ccinst, int linenum);
-extern AGS::Shared::String debug_line[DEBUG_CONSOLE_NUMLINES];
-extern int first_debug_line, last_debug_line, display_console;
-
-
extern AGSPlatformDriver *platform;
} // namespace AGS3
diff --git a/engines/ags/engine/debugging/debugger.h b/engines/ags/engine/debugging/debugger.h
index 7e4b070413..760e5df4bb 100644
--- a/engines/ags/engine/debugging/debugger.h
+++ b/engines/ags/engine/debugging/debugger.h
@@ -56,10 +56,6 @@ enum FPSDisplayMode {
kFPS_Forced = 2 // forced shown by the engine arg
};
-extern float fps;
-extern FPSDisplayMode display_fps;
-extern int debug_flags;
-
} // namespace AGS3
#endif
diff --git a/engines/ags/engine/main/engine.cpp b/engines/ags/engine/main/engine.cpp
index 0d047e9290..fdcefc6e09 100644
--- a/engines/ags/engine/main/engine.cpp
+++ b/engines/ags/engine/main/engine.cpp
@@ -408,13 +408,13 @@ void engine_init_audio() {
}
void engine_init_debug() {
- if ((debug_flags & (~DBG_DEBUGMODE)) > 0) {
+ if ((_G(debug_flags) & (~DBG_DEBUGMODE)) > 0) {
platform->DisplayAlert("Engine debugging enabled.\n"
"\nNOTE: You have selected to enable one or more engine debugging options.\n"
"These options cause many parts of the game to behave abnormally, and you\n"
"may not see the game as you are used to it. The point is to test whether\n"
"the engine passes a point where it is crashing on you normally.\n"
- "[Debug flags enabled: 0x%02X]", debug_flags);
+ "[Debug flags enabled: 0x%02X]", _G(debug_flags));
}
}
@@ -863,7 +863,7 @@ void engine_init_game_settings() {
for (ee = 0; ee < MAX_ROOM_BGFRAMES; ee++)
_GP(play).raw_modified[ee] = 0;
_GP(play).game_speed_modifier = 0;
- if (debug_flags & DBG_DEBUGMODE)
+ if (_G(debug_flags) & DBG_DEBUGMODE)
_GP(play).debug_mode = 1;
gui_disabled_style = convert_gui_disabled_style(_GP(game).options[OPT_DISABLEOFF]);
_GP(play).shake_screen_yoff = 0;
diff --git a/engines/ags/engine/main/game_run.cpp b/engines/ags/engine/main/game_run.cpp
index a664d60615..b83b433f84 100644
--- a/engines/ags/engine/main/game_run.cpp
+++ b/engines/ags/engine/main/game_run.cpp
@@ -383,7 +383,7 @@ static void check_keyboard_controls() {
// debug console
if ((kgn == '`') && (_GP(play).debug_mode > 0)) {
- display_console = !display_console;
+ _G(display_console) = !_G(display_console);
return;
}
@@ -409,7 +409,7 @@ static void check_keyboard_controls() {
return;
}
- if ((kgn == eAGSKeyCodeCtrlE) && (display_fps == kFPS_Forced)) {
+ if ((kgn == eAGSKeyCodeCtrlE) && (_G(display_fps) == kFPS_Forced)) {
// if --fps paramter is used, Ctrl+E will max out frame rate
setTimerFps(isTimerFpsMaxed() ? frames_per_second : 1000);
return;
@@ -599,7 +599,7 @@ static void game_loop_check_controls(bool checkControls) {
}
static void game_loop_do_update() {
- if (debug_flags & DBG_NOUPDATE);
+ if (_G(debug_flags) & DBG_NOUPDATE);
else if (game_paused == 0) update_stuff();
}
@@ -703,7 +703,7 @@ static void game_loop_update_fps() {
auto frames = loopcounter - lastcounter;
if (duration >= std::chrono::milliseconds(1000) && frames > 0) {
- fps = 1000.0f * frames / duration.count();
+ _G(fps) = 1000.0f * frames / duration.count();
t1 = t2;
lastcounter = loopcounter;
}
@@ -712,8 +712,8 @@ static void game_loop_update_fps() {
float get_current_fps() {
// if we have maxed out framerate then return the frame rate we're seeing instead
// fps must be greater that 0 or some timings will take forever.
- if (isTimerFpsMaxed() && fps > 0.0f) {
- return fps;
+ if (isTimerFpsMaxed() && _G(fps) > 0.0f) {
+ return _G(fps);
}
return frames_per_second;
}
@@ -722,7 +722,7 @@ void set_loop_counter(unsigned int new_counter) {
loopcounter = new_counter;
t1 = AGS_Clock::now();
lastcounter = loopcounter;
- fps = std::numeric_limits<float>::quiet_undefined();
+ _G(fps) = std::numeric_limits<float>::quiet_undefined();
}
void UpdateGameOnce(bool checkControls, IDriverDependantBitmap *extraBitmap, int extraX, int extraY) {
diff --git a/engines/ags/engine/media/audio/audio.cpp b/engines/ags/engine/media/audio/audio.cpp
index c915e16681..62d90ed8d9 100644
--- a/engines/ags/engine/media/audio/audio.cpp
+++ b/engines/ags/engine/media/audio/audio.cpp
@@ -1017,7 +1017,7 @@ SOUNDCLIP *load_music_from_disk(int mnum, bool doRepeat) {
}
static void play_new_music(int mnum, SOUNDCLIP *music) {
- if (debug_flags & DBG_NOMUSIC)
+ if (_G(debug_flags) & DBG_NOMUSIC)
return;
if ((_GP(play).cur_music_number == mnum) && (music == nullptr)) {
diff --git a/engines/ags/globals.cpp b/engines/ags/globals.cpp
index aaf4d836a2..35955e20a9 100644
--- a/engines/ags/globals.cpp
+++ b/engines/ags/globals.cpp
@@ -63,12 +63,17 @@
#include "ags/engine/ac/dynobj/scriptregion.h"
#include "ags/engine/ac/dynobj/scriptstring.h"
#include "ags/engine/ac/statobj/staticarray.h"
+#include "ags/engine/debugging/consoleoutputtarget.h"
+#include "ags/engine/debugging/debugger.h"
+#include "ags/engine/debugging/logfile.h"
+#include "ags/engine/debugging/messagebuffer.h"
#include "ags/engine/media/audio/ambientsound.h"
#include "ags/engine/media/audio/audiodefines.h"
#include "ags/engine/script/executingscript.h"
#include "ags/engine/script/nonblockingscriptfunction.h"
#include "ags/engine/script/script.h"
#include "ags/engine/script/systemimports.h"
+#include "ags/lib/std/limits.h"
namespace AGS3 {
@@ -84,6 +89,14 @@ Globals::Globals() {
// TODO: double check that ambient sounds array actually needs +1
_ambient = new std::array<AmbientSound>(MAX_SOUND_CHANNELS + 1);
+ // debug.cpp globals
+ _fps = std::numeric_limits<float>::quiet_undefined();
+ _display_fps = kFPS_Hide;
+ _debug_line = new String[DEBUG_CONSOLE_NUMLINES];
+ _DebugMsgBuff = new std::unique_ptr<AGS::Engine::MessageBuffer>();
+ _DebugLogFile = new std::unique_ptr<AGS::Engine::LogFile>();
+ _DebugConsole = new std::unique_ptr<AGS::Engine::ConsoleOutputTarget>();
+
// debugmanager.cpp globals
_DbgMgr = new AGS::Shared::DebugManager();
@@ -199,6 +212,12 @@ Globals::~Globals() {
delete _audioChannels;
delete _ambient;
+ // debug.cpp globals
+ delete[] _debug_line;
+ delete _DebugMsgBuff;
+ delete _DebugLogFile;
+ delete _DebugConsole;
+
// debugmanager.cpp globals
delete _DbgMgr;
diff --git a/engines/ags/globals.h b/engines/ags/globals.h
index 0caec08569..c8e3ef25bb 100644
--- a/engines/ags/globals.h
+++ b/engines/ags/globals.h
@@ -53,10 +53,19 @@ class GUITextBox;
class RoomStruct;
} // namespace Shared
+
+namespace Engine {
+
+class ConsoleOutputTarget;
+class LogFile;
+class MessageBuffer;
+
+} // namespace Engine
} // namespace AGS
class Navigation;
class SplitLines;
+class SpriteCache;
class TTFFontRenderer;
class WFNFontRenderer;
@@ -101,8 +110,6 @@ struct StaticArray;
struct SystemImports;
struct ViewStruct;
-class SpriteCache;
-
class Globals {
public:
/**
@@ -146,6 +153,17 @@ public:
std::vector<Breakpoint> _breakpoints;
int _numBreakpoints = 0;
+ int _debug_flags = 0;
+
+ String *_debug_line;
+ int _first_debug_line = 0, _last_debug_line = 0, _display_console = 0;
+
+ float _fps;
+ int _display_fps;
+ std::unique_ptr<AGS::Engine::MessageBuffer> *_DebugMsgBuff;
+ std::unique_ptr<AGS::Engine::LogFile> *_DebugLogFile;
+ std::unique_ptr<AGS::Engine::ConsoleOutputTarget> *_DebugConsole;
+
/**@}*/
/**
Commit: f07da658f14572782d9f7a3b207bfda802507859
https://github.com/scummvm/scummvm/commit/f07da658f14572782d9f7a3b207bfda802507859
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-03-06T15:11:38-08:00
Commit Message:
AGS: Move engine.cpp globals to Globals
Changed paths:
engines/ags/engine/ac/file.cpp
engines/ags/engine/ac/game.cpp
engines/ags/engine/ac/gamestate.cpp
engines/ags/engine/ac/global_game.cpp
engines/ags/engine/game/savegame.cpp
engines/ags/engine/main/engine.cpp
engines/ags/engine/main/engine.h
engines/ags/globals.cpp
engines/ags/globals.h
diff --git a/engines/ags/engine/ac/file.cpp b/engines/ags/engine/ac/file.cpp
index 9f4cdd3bda..7b5ab5c743 100644
--- a/engines/ags/engine/ac/file.cpp
+++ b/engines/ags/engine/ac/file.cpp
@@ -370,14 +370,14 @@ Stream *LocateAsset(const AssetPath &path, size_t &asset_size) {
// Change to the different library, if required
// TODO: teaching AssetManager to register multiple libraries simultaneously
// will let us skip this step, and also make this operation much faster.
- if (!assetlib.IsEmpty() && assetlib.CompareNoCase(ResPaths.GamePak.Name) != 0) {
+ if (!assetlib.IsEmpty() && assetlib.CompareNoCase(_GP(ResPaths).GamePak.Name) != 0) {
AssetManager::SetDataFile(get_known_assetlib(assetlib));
needsetback = true;
}
Stream *asset_stream = AssetManager::OpenAsset(assetname);
asset_size = AssetManager::GetLastAssetSize();
if (needsetback)
- AssetManager::SetDataFile(ResPaths.GamePak.Path);
+ AssetManager::SetDataFile(_GP(ResPaths).GamePak.Path);
return asset_stream;
}
@@ -463,13 +463,13 @@ bool DoesAssetExistInLib(const AssetPath &assetname) {
// Change to the different library, if required
// TODO: teaching AssetManager to register multiple libraries simultaneously
// will let us skip this step, and also make this operation much faster.
- if (!assetname.first.IsEmpty() && assetname.first.CompareNoCase(ResPaths.GamePak.Name) != 0) {
+ if (!assetname.first.IsEmpty() && assetname.first.CompareNoCase(_GP(ResPaths).GamePak.Name) != 0) {
AssetManager::SetDataFile(get_known_assetlib(assetname.first));
needsetback = true;
}
bool res = AssetManager::DoesAssetExist(assetname.second);
if (needsetback)
- AssetManager::SetDataFile(ResPaths.GamePak.Path);
+ AssetManager::SetDataFile(_GP(ResPaths).GamePak.Path);
return res;
}
@@ -505,10 +505,10 @@ void get_install_dir_path(char *buffer, const char *fileName) {
}
String find_assetlib(const String &filename) {
- String libname = cbuf_to_string_and_free(ci_find_file(ResPaths.DataDir, filename));
+ String libname = cbuf_to_string_and_free(ci_find_file(_GP(ResPaths).DataDir, filename));
if (AssetManager::IsDataFile(libname))
return libname;
- if (Path::ComparePaths(ResPaths.DataDir, installDirectory) != 0) {
+ if (Path::ComparePaths(_GP(ResPaths).DataDir, installDirectory) != 0) {
// Hack for running in Debugger
libname = cbuf_to_string_and_free(ci_find_file(installDirectory, filename));
if (AssetManager::IsDataFile(libname))
@@ -521,18 +521,18 @@ String find_assetlib(const String &filename) {
String get_known_assetlib(const String &filename) {
// TODO: write now there's only 3 regular PAKs, so we may do this quick
// string comparison, but if we support more maybe we could use a table.
- if (filename.CompareNoCase(ResPaths.GamePak.Name) == 0)
- return ResPaths.GamePak.Path;
- if (filename.CompareNoCase(ResPaths.AudioPak.Name) == 0)
- return ResPaths.AudioPak.Path;
- if (filename.CompareNoCase(ResPaths.SpeechPak.Name) == 0)
- return ResPaths.SpeechPak.Path;
+ if (filename.CompareNoCase(_GP(ResPaths).GamePak.Name) == 0)
+ return _GP(ResPaths).GamePak.Path;
+ if (filename.CompareNoCase(_GP(ResPaths).AudioPak.Name) == 0)
+ return _GP(ResPaths).AudioPak.Path;
+ if (filename.CompareNoCase(_GP(ResPaths).SpeechPak.Name) == 0)
+ return _GP(ResPaths).SpeechPak.Path;
return String();
}
Stream *find_open_asset(const String &filename) {
Stream *asset_s = Shared::AssetManager::OpenAsset(filename);
- if (!asset_s && Path::ComparePaths(ResPaths.DataDir, installDirectory) != 0) {
+ if (!asset_s && Path::ComparePaths(_GP(ResPaths).DataDir, installDirectory) != 0) {
// Just in case they're running in Debug, try standalone file in compiled folder
asset_s = ci_fopen(String::FromFormat("%s/%s", installDirectory.GetCStr(), filename.GetCStr()));
}
@@ -542,14 +542,14 @@ Stream *find_open_asset(const String &filename) {
AssetPath get_audio_clip_assetpath(int bundling_type, const String &filename) {
// Special case is explicitly defined audio directory, which should be
// tried first regardless of bundling type.
- if (Path::ComparePaths(ResPaths.DataDir, installAudioDirectory) != 0) {
+ if (Path::ComparePaths(_GP(ResPaths).DataDir, installAudioDirectory) != 0) {
String filepath = String::FromFormat("%s/%s", installAudioDirectory.GetCStr(), filename.GetCStr());
if (Path::IsFile(filepath))
return AssetPath("", filepath);
}
if (bundling_type == AUCL_BUNDLE_EXE)
- return AssetPath(ResPaths.GamePak.Name, filename);
+ return AssetPath(_GP(ResPaths).GamePak.Name, filename);
else if (bundling_type == AUCL_BUNDLE_VOX)
return AssetPath(_GP(game).GetAudioVOXName(), filename);
return AssetPath();
@@ -558,12 +558,12 @@ AssetPath get_audio_clip_assetpath(int bundling_type, const String &filename) {
AssetPath get_voice_over_assetpath(const String &filename) {
// Special case is explicitly defined voice-over directory, which should be
// tried first.
- if (Path::ComparePaths(ResPaths.DataDir, installVoiceDirectory) != 0) {
+ if (Path::ComparePaths(_GP(ResPaths).DataDir, installVoiceDirectory) != 0) {
String filepath = String::FromFormat("%s/%s", installVoiceDirectory.GetCStr(), filename.GetCStr());
if (Path::IsFile(filepath))
return AssetPath("", filepath);
}
- return AssetPath(ResPaths.SpeechPak.Name, filename);
+ return AssetPath(_GP(ResPaths).SpeechPak.Name, filename);
}
ScriptFileHandle valid_handles[MAX_OPEN_SCRIPT_FILES + 1];
diff --git a/engines/ags/engine/ac/game.cpp b/engines/ags/engine/ac/game.cpp
index e2f0143e91..f00becb6cb 100644
--- a/engines/ags/engine/ac/game.cpp
+++ b/engines/ags/engine/ac/game.cpp
@@ -722,7 +722,7 @@ void Game_SetIgnoreUserInputAfterTextTimeoutMs(int newValueMs) {
}
const char *Game_GetFileName() {
- return CreateNewScriptString(ResPaths.GamePak.Name);
+ return CreateNewScriptString(_GP(ResPaths).GamePak.Name);
}
const char *Game_GetName() {
@@ -1532,7 +1532,7 @@ HSaveError load_game(int slotNumber, bool &data_overwritten) {
return new SavegameError(kSvgErr_DifferentColorDepth, String::FromFormat("Running: %d-bit, saved in: %d-bit.", _GP(game).GetColorDepth(), desc.ColorDepth));
// saved with different game file
- if (Path::ComparePaths(desc.MainDataFilename, ResPaths.GamePak.Name)) {
+ if (Path::ComparePaths(desc.MainDataFilename, _GP(ResPaths).GamePak.Name)) {
// [IKM] 2012-11-26: this is a workaround, indeed.
// Try to find wanted game's executable; if it does not exist,
// continue loading savedgame in current game, and pray for the best
diff --git a/engines/ags/engine/ac/gamestate.cpp b/engines/ags/engine/ac/gamestate.cpp
index d61d476fb0..8b7c171908 100644
--- a/engines/ags/engine/ac/gamestate.cpp
+++ b/engines/ags/engine/ac/gamestate.cpp
@@ -383,7 +383,7 @@ bool GameState::IsNonBlockingVoiceSpeech() const {
bool GameState::ShouldPlayVoiceSpeech() const {
return !_GP(play).fast_forward &&
- (_GP(play).want_speech >= 1) && (!ResPaths.SpeechPak.Name.IsEmpty());
+ (_GP(play).want_speech >= 1) && (!_GP(ResPaths).SpeechPak.Name.IsEmpty());
}
void GameState::ReadFromSavegame(Shared::Stream *in, GameStateSvgVersion svg_ver, RestoredData &r_data) {
diff --git a/engines/ags/engine/ac/global_game.cpp b/engines/ags/engine/ac/global_game.cpp
index 79df31351e..61f8621cb2 100644
--- a/engines/ags/engine/ac/global_game.cpp
+++ b/engines/ags/engine/ac/global_game.cpp
@@ -246,8 +246,8 @@ int RunAGSGame(const char *newgame, unsigned int mode, int data) {
if ((mode & RAGMODE_LOADNOW) == 0) {
// need to copy, since the script gets destroyed
get_install_dir_path(gamefilenamebuf, newgame);
- ResPaths.GamePak.Path = gamefilenamebuf;
- ResPaths.GamePak.Name = Shared::Path::get_filename(gamefilenamebuf);
+ _GP(ResPaths).GamePak.Path = gamefilenamebuf;
+ _GP(ResPaths).GamePak.Name = Shared::Path::get_filename(gamefilenamebuf);
_GP(play).takeover_data = data;
load_new_game_restore = -1;
@@ -271,8 +271,8 @@ int RunAGSGame(const char *newgame, unsigned int mode, int data) {
// Adjust config (NOTE: normally, RunAGSGame would need a redesign to allow separate config etc per each game)
_GP(usetup).translation = ""; // reset to default, prevent from trying translation file of game A in game B
- if (Shared::AssetManager::SetDataFile(ResPaths.GamePak.Path) != Shared::kAssetNoError)
- quitprintf("!RunAGSGame: unable to load new game file '%s'", ResPaths.GamePak.Path.GetCStr());
+ if (Shared::AssetManager::SetDataFile(_GP(ResPaths).GamePak.Path) != Shared::kAssetNoError)
+ quitprintf("!RunAGSGame: unable to load new game file '%s'", _GP(ResPaths).GamePak.Path.GetCStr());
show_preload();
diff --git a/engines/ags/engine/game/savegame.cpp b/engines/ags/engine/game/savegame.cpp
index dbfb258ad7..aaebf5aca7 100644
--- a/engines/ags/engine/game/savegame.cpp
+++ b/engines/ags/engine/game/savegame.cpp
@@ -676,7 +676,7 @@ void WriteDescription(Stream *out, const String &user_text, const Bitmap *user_i
StrUtil::WriteString(_G(EngineVersion).LongString, out);
StrUtil::WriteString(_GP(game).guid, out);
StrUtil::WriteString(_GP(game).gamename, out);
- StrUtil::WriteString(ResPaths.GamePak.Name, out);
+ StrUtil::WriteString(_GP(ResPaths).GamePak.Name, out);
out->WriteInt32(loaded_game_file_version);
out->WriteInt32(_GP(game).GetColorDepth());
// User description
diff --git a/engines/ags/engine/main/engine.cpp b/engines/ags/engine/main/engine.cpp
index fdcefc6e09..02f97d8c86 100644
--- a/engines/ags/engine/main/engine.cpp
+++ b/engines/ags/engine/main/engine.cpp
@@ -102,10 +102,6 @@ extern CharacterInfo *playerchar;
extern Bitmap **guibg;
extern IDriverDependantBitmap **guibgbmp;
-ResourcePaths ResPaths;
-
-t_engine_pre_init_callback engine_pre_init_callback = nullptr;
-
#define ALLEGRO_KEYBOARD_HANDLER
bool engine_init_allegro() {
@@ -318,7 +314,7 @@ void engine_locate_speech_pak() {
Debug::Printf("Initializing speech vox");
if (AssetManager::SetDataFile(speech_filepath) != Shared::kAssetNoError) {
platform->DisplayAlert("Unable to read voice pack, file could be corrupted or of unknown format.\nSpeech voice-over will be disabled.");
- AssetManager::SetDataFile(ResPaths.GamePak.Path); // switch back to the main data pack
+ AssetManager::SetDataFile(_GP(ResPaths).GamePak.Path); // switch back to the main data pack
return;
}
// TODO: why is this read right here??? move this to InitGameState!
@@ -342,16 +338,16 @@ void engine_locate_speech_pak() {
}
delete speechsync;
}
- AssetManager::SetDataFile(ResPaths.GamePak.Path); // switch back to the main data pack
+ AssetManager::SetDataFile(_GP(ResPaths).GamePak.Path); // switch back to the main data pack
Debug::Printf(kDbgMsg_Info, "Voice pack found and initialized.");
_GP(play).want_speech = 1;
- } else if (Path::ComparePaths(ResPaths.DataDir, get_voice_install_dir()) != 0) {
+ } else if (Path::ComparePaths(_GP(ResPaths).DataDir, get_voice_install_dir()) != 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 voice installation directory is defined: enabling voice-over.");
_GP(play).want_speech = 1;
}
- ResPaths.SpeechPak.Name = speech_file;
- ResPaths.SpeechPak.Path = speech_filepath;
+ _GP(ResPaths).SpeechPak.Name = speech_file;
+ _GP(ResPaths).SpeechPak.Path = speech_filepath;
}
}
@@ -361,11 +357,11 @@ void engine_locate_audio_pak() {
String music_filepath = find_assetlib(music_file);
if (!music_filepath.IsEmpty()) {
if (AssetManager::SetDataFile(music_filepath) == kAssetNoError) {
- AssetManager::SetDataFile(ResPaths.GamePak.Path);
+ AssetManager::SetDataFile(_GP(ResPaths).GamePak.Path);
Debug::Printf(kDbgMsg_Info, "%s found and initialized.", music_file.GetCStr());
_GP(play).separate_music_lib = 1;
- ResPaths.AudioPak.Name = music_file;
- ResPaths.AudioPak.Path = music_filepath;
+ _GP(ResPaths).AudioPak.Name = music_file;
+ _GP(ResPaths).AudioPak.Path = music_filepath;
} else {
platform->DisplayAlert("Unable to initialize digital audio pack '%s', file could be corrupt or of unsupported format.",
music_file.GetCStr());
@@ -497,15 +493,15 @@ void engine_init_directories() {
if (!_GP(usetup).shared_data_dir.IsEmpty())
Debug::Printf(kDbgMsg_Info, "Shared data directory: %s", _GP(usetup).shared_data_dir.GetCStr());
- ResPaths.DataDir = _GP(usetup).data_files_dir;
- ResPaths.GamePak.Path = _GP(usetup).main_data_filepath;
- ResPaths.GamePak.Name = Shared::Path::get_filename(_GP(usetup).main_data_filepath);
+ _GP(ResPaths).DataDir = _GP(usetup).data_files_dir;
+ _GP(ResPaths).GamePak.Path = _GP(usetup).main_data_filepath;
+ _GP(ResPaths).GamePak.Name = Shared::Path::get_filename(_GP(usetup).main_data_filepath);
set_install_dir(_GP(usetup).install_dir, _GP(usetup).install_audio_dir, _GP(usetup).install_voice_dir);
if (!_GP(usetup).install_dir.IsEmpty()) {
// running in debugger: don't redirect to the game exe folder (_Debug)
// TODO: find out why we need to do this (and do we?)
- ResPaths.DataDir = ".";
+ _GP(ResPaths).DataDir = ".";
}
// if end-user specified custom save path, use it
@@ -1144,8 +1140,8 @@ static int al_find_resource(char *dest, const char *resource, int dest_size) {
// is mixed with game-related data adjustments. Divide it in parts, move game
// data init into either InitGameState() or other game method as appropriate.
int initialize_engine(const ConfigTree &startup_opts) {
- if (engine_pre_init_callback) {
- engine_pre_init_callback();
+ if (_G(engine_pre_init_callback)) {
+ _G(engine_pre_init_callback)();
}
//-----------------------------------------------------
@@ -1373,7 +1369,7 @@ const char *get_engine_version() {
}
void engine_set_pre_init_callback(t_engine_pre_init_callback callback) {
- engine_pre_init_callback = callback;
+ _G(engine_pre_init_callback) = callback;
}
} // namespace AGS3
diff --git a/engines/ags/engine/main/engine.h b/engines/ags/engine/main/engine.h
index f08af9fa99..d4b2d8d3a3 100644
--- a/engines/ags/engine/main/engine.h
+++ b/engines/ags/engine/main/engine.h
@@ -57,7 +57,6 @@ struct ResourcePaths {
PackLocation AudioPak; // audio package
PackLocation SpeechPak; // voice-over package
};
-extern ResourcePaths ResPaths;
// Register a callback that will be called before engine is initialised.
// Used for apps to register their own plugins and other configuration
diff --git a/engines/ags/globals.cpp b/engines/ags/globals.cpp
index 35955e20a9..03e229a1b9 100644
--- a/engines/ags/globals.cpp
+++ b/engines/ags/globals.cpp
@@ -110,6 +110,9 @@ Globals::Globals() {
_RoomCamRects = new std::vector<DirtyRects>();
_RoomCamPositions = new std::vector<std::pair<int, int> >();
+ // engine.cpp globals
+ _ResPaths = new ResourcePaths();
+
// fonts.cpp globals
_fonts = new std::vector<AGS::Shared::Font>();
_ttfRenderer = new TTFFontRenderer();
@@ -231,6 +234,9 @@ Globals::~Globals() {
delete _RoomCamRects;
delete _RoomCamPositions;
+ // engine.cpp globals
+ delete _ResPaths;
+
// fonts.cpp globals
delete _fonts;
delete _ttfRenderer;
diff --git a/engines/ags/globals.h b/engines/ags/globals.h
index c8e3ef25bb..856601ed1f 100644
--- a/engines/ags/globals.h
+++ b/engines/ags/globals.h
@@ -27,6 +27,7 @@
#include "ags/shared/util/version.h"
#include "ags/shared/gui/guimain.h"
#include "ags/shared/script/cc_script.h"
+#include "ags/engine/main/engine.h"
#include "ags/lib/std/array.h"
#include "ags/lib/std/set.h"
#include "ags/lib/allegro/fixed.h"
@@ -92,6 +93,7 @@ struct ManagedObjectPool;
struct MoveList;
struct NonBlockingScriptFunction;
struct ObjectCache;
+struct ResourcePaths;
struct RoomCameraDrawData;
struct RoomStatus;
struct RuntimeScriptValue;
@@ -214,6 +216,16 @@ public:
/**@}*/
+ /**
+ * \defgroup engine globals
+ * @{
+ */
+
+ ResourcePaths *_ResPaths;
+ t_engine_pre_init_callback _engine_pre_init_callback = nullptr;
+
+ /**@}*/
+
/**
* \defgroup fonts globals
* @{
Commit: 68e925ecd06d1da65c4a9a24f0d51cd6261de2df
https://github.com/scummvm/scummvm/commit/68e925ecd06d1da65c4a9a24f0d51cd6261de2df
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-03-06T15:11:39-08:00
Commit Message:
AGS: Move interactions.cpp globals to Globals
Changed paths:
engines/ags/engine/ac/game.cpp
engines/ags/engine/game/savegame_components.cpp
engines/ags/engine/script/script.cpp
engines/ags/globals.cpp
engines/ags/globals.h
engines/ags/shared/ac/gamesetupstruct.cpp
engines/ags/shared/game/interactions.cpp
engines/ags/shared/game/interactions.h
diff --git a/engines/ags/engine/ac/game.cpp b/engines/ags/engine/ac/game.cpp
index f00becb6cb..22535dd0c5 100644
--- a/engines/ags/engine/ac/game.cpp
+++ b/engines/ags/engine/ac/game.cpp
@@ -1306,12 +1306,12 @@ void restore_game_displayed_room_status(Stream *in, RestoredData &r_data) {
}
HSaveError restore_game_globalvars(Stream *in) {
- if (in->ReadInt32() != numGlobalVars) {
+ if (in->ReadInt32() != _G(numGlobalVars)) {
return new SavegameError(kSvgErr_GameContentAssertion, "Restore game error: mismatching number of Global Variables.");
}
- for (int i = 0; i < numGlobalVars; ++i) {
- globalvars[i].Read(in);
+ for (int i = 0; i < _G(numGlobalVars); ++i) {
+ _G(globalvars)[i].Read(in);
}
return HSaveError::None();
}
diff --git a/engines/ags/engine/game/savegame_components.cpp b/engines/ags/engine/game/savegame_components.cpp
index 41120f7a96..79ee0bec3f 100644
--- a/engines/ags/engine/game/savegame_components.cpp
+++ b/engines/ags/engine/game/savegame_components.cpp
@@ -205,9 +205,9 @@ HSaveError WriteGameState(PStream out) {
if (loaded_game_file_version <= kGameVersion_272) {
// Global variables
- out->WriteInt32(numGlobalVars);
- for (int i = 0; i < numGlobalVars; ++i)
- globalvars[i].Write(out.get());
+ out->WriteInt32(_G(numGlobalVars));
+ for (int i = 0; i < _G(numGlobalVars); ++i)
+ _G(globalvars)[i].Write(out.get());
}
// Game state
@@ -294,10 +294,10 @@ HSaveError ReadGameState(PStream in, int32_t cmp_ver, const PreservedParams &pp,
if (loaded_game_file_version <= kGameVersion_272) {
// Legacy interaction global variables
- if (!AssertGameContent(err, in->ReadInt32(), numGlobalVars, "Global Variables"))
+ if (!AssertGameContent(err, in->ReadInt32(), _G(numGlobalVars), "Global Variables"))
return err;
- for (int i = 0; i < numGlobalVars; ++i)
- globalvars[i].Read(in.get());
+ for (int i = 0; i < _G(numGlobalVars); ++i)
+ _G(globalvars)[i].Read(in.get());
}
// Game state
diff --git a/engines/ags/engine/script/script.cpp b/engines/ags/engine/script/script.cpp
index 86dba205f5..45fad9dddb 100644
--- a/engines/ags/engine/script/script.cpp
+++ b/engines/ags/engine/script/script.cpp
@@ -581,17 +581,17 @@ InteractionVariable *get_interaction_variable(int varindx) {
if ((varindx >= LOCAL_VARIABLE_OFFSET) && ((size_t)varindx < LOCAL_VARIABLE_OFFSET + _GP(thisroom).LocalVariables.size()))
return &_GP(thisroom).LocalVariables[varindx - LOCAL_VARIABLE_OFFSET];
- if ((varindx < 0) || (varindx >= numGlobalVars))
+ if ((varindx < 0) || (varindx >= _G(numGlobalVars)))
quit("!invalid interaction variable specified");
- return &globalvars[varindx];
+ return &_G(globalvars)[varindx];
}
InteractionVariable *FindGraphicalVariable(const char *varName) {
int ii;
- for (ii = 0; ii < numGlobalVars; ii++) {
- if (ags_stricmp(globalvars[ii].Name, varName) == 0)
- return &globalvars[ii];
+ for (ii = 0; ii < _G(numGlobalVars); ii++) {
+ if (ags_stricmp(_G(globalvars)[ii].Name, varName) == 0)
+ return &_G(globalvars)[ii];
}
for (size_t i = 0; i < _GP(thisroom).LocalVariables.size(); ++i) {
if (ags_stricmp(_GP(thisroom).LocalVariables[i].Name, varName) == 0)
diff --git a/engines/ags/globals.cpp b/engines/ags/globals.cpp
index 03e229a1b9..028a5d980d 100644
--- a/engines/ags/globals.cpp
+++ b/engines/ags/globals.cpp
@@ -27,6 +27,7 @@
#include "ags/shared/font/fonts.h"
#include "ags/shared/font/ttffontrenderer.h"
#include "ags/shared/font/wfnfontrenderer.h"
+#include "ags/shared/game/interactions.h"
#include "ags/shared/game/roomstruct.h"
#include "ags/shared/gui/guibutton.h"
#include "ags/shared/gui/guiinv.h"
@@ -172,6 +173,10 @@ Globals::Globals() {
// guitextbox.cpp globals
_guitext = new std::vector<AGS::Shared::GUITextBox>();
+ // interactions.cpp globals
+ _globalvars = new InteractionVariable[MAX_GLOBAL_VARIABLES];
+ _globalvars[0] = InteractionVariable("Global 1", 0, 0);
+
// managedobjectpool.cpp globals
_pool = new ManagedObjectPool();
@@ -294,6 +299,9 @@ Globals::~Globals() {
// guitextbox.cpp globals
delete _guitext;
+ // interactions.cpp globals
+ delete[] _globalvars;
+
// managedobjectpool.cpp globals
delete _pool;
diff --git a/engines/ags/globals.h b/engines/ags/globals.h
index 856601ed1f..c7ef82cf2b 100644
--- a/engines/ags/globals.h
+++ b/engines/ags/globals.h
@@ -51,6 +51,7 @@ class GUILabel;
class GUIListBox;
class GUISlider;
class GUITextBox;
+struct InteractionVariable;
class RoomStruct;
} // namespace Shared
@@ -359,6 +360,16 @@ public:
/**@}*/
+ /**
+ * \defgroup interactions globals
+ * @{
+ */
+
+ AGS::Shared::InteractionVariable *_globalvars;
+ int _numGlobalVars = 1;
+
+ /**@}*/
+
/**
* \defgroup main globals
* @{
diff --git a/engines/ags/shared/ac/gamesetupstruct.cpp b/engines/ags/shared/ac/gamesetupstruct.cpp
index 449fd2db00..0ad7042e24 100644
--- a/engines/ags/shared/ac/gamesetupstruct.cpp
+++ b/engines/ags/shared/ac/gamesetupstruct.cpp
@@ -172,7 +172,7 @@ HGameFileError GameSetupStruct::read_cursors(Shared::Stream *in, GameDataVersion
}
void GameSetupStruct::read_interaction_scripts(Shared::Stream *in, GameDataVersion data_ver) {
- numGlobalVars = 0;
+ _G(numGlobalVars) = 0;
if (data_ver > kGameVersion_272) { // 3.x
charScripts.resize(numcharacters);
@@ -189,9 +189,9 @@ void GameSetupStruct::read_interaction_scripts(Shared::Stream *in, GameDataVersi
for (size_t i = 0; i < (size_t)numinvitems; ++i)
intrInv[i].reset(Interaction::CreateFromStream(in));
- numGlobalVars = in->ReadInt32();
- for (size_t i = 0; i < (size_t)numGlobalVars; ++i)
- globalvars[i].Read(in);
+ _G(numGlobalVars) = in->ReadInt32();
+ for (size_t i = 0; i < (size_t)_G(numGlobalVars); ++i)
+ _G(globalvars)[i].Read(in);
}
}
diff --git a/engines/ags/shared/game/interactions.cpp b/engines/ags/shared/game/interactions.cpp
index 436b48f36d..f76071c5cb 100644
--- a/engines/ags/shared/game/interactions.cpp
+++ b/engines/ags/shared/game/interactions.cpp
@@ -30,9 +30,6 @@ namespace AGS3 {
using namespace AGS::Shared;
-InteractionVariable globalvars[MAX_GLOBAL_VARIABLES] = { InteractionVariable("Global 1", 0, 0) };
-int numGlobalVars = 1;
-
namespace AGS {
namespace Shared {
diff --git a/engines/ags/shared/game/interactions.h b/engines/ags/shared/game/interactions.h
index dba759886f..caa4893565 100644
--- a/engines/ags/shared/game/interactions.h
+++ b/engines/ags/shared/game/interactions.h
@@ -206,11 +206,6 @@ typedef std::shared_ptr<InteractionScripts> PInteractionScripts;
} // namespace Shared
} // namespace AGS
-
-// Legacy global variables
-extern AGS::Shared::InteractionVariable globalvars[MAX_GLOBAL_VARIABLES];
-extern int numGlobalVars;
-
} // namespace AGS3
#endif
Commit: 9b4f54cf771380867b71201c824bd229ab849971
https://github.com/scummvm/scummvm/commit/9b4f54cf771380867b71201c824bd229ab849971
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-03-06T15:11:39-08:00
Commit Message:
AGS: Move file.cpp globals to Globals
Changed paths:
engines/ags/engine/ac/file.cpp
engines/ags/globals.h
diff --git a/engines/ags/engine/ac/file.cpp b/engines/ags/engine/ac/file.cpp
index 7b5ab5c743..ecdcc0322c 100644
--- a/engines/ags/engine/ac/file.cpp
+++ b/engines/ags/engine/ac/file.cpp
@@ -58,16 +58,6 @@ using namespace AGS::Shared;
extern AGSPlatformDriver *platform;
extern int MAXSTRLEN;
-// TODO: the asset path configuration should certainly be revamped at some
-// point, with uniform method of configuring auxiliary paths and packages.
-
-// Installation directory, may contain absolute or relative path
-String installDirectory;
-// Installation directory, containing audio files
-String installAudioDirectory;
-// Installation directory, containing voice-over files
-String installVoiceDirectory;
-
// object-based File routines
int File_Exists(const char *fnmm) {
@@ -475,42 +465,42 @@ bool DoesAssetExistInLib(const AssetPath &assetname) {
void set_install_dir(const String &path, const String &audio_path, const String &voice_path) {
if (path.IsEmpty())
- installDirectory = ".";
+ _G(installDirectory) = ".";
else
- installDirectory = Path::MakePathNoSlash(path);
+ _G(installDirectory) = Path::MakePathNoSlash(path);
if (audio_path.IsEmpty())
- installAudioDirectory = ".";
+ _G(installAudioDirectory) = ".";
else
- installAudioDirectory = Path::MakePathNoSlash(audio_path);
+ _G(installAudioDirectory) = Path::MakePathNoSlash(audio_path);
if (voice_path.IsEmpty())
- installVoiceDirectory = ".";
+ _G(installVoiceDirectory) = ".";
else
- installVoiceDirectory = Path::MakePathNoSlash(voice_path);
+ _G(installVoiceDirectory) = Path::MakePathNoSlash(voice_path);
}
String get_install_dir() {
- return installDirectory;
+ return _G(installDirectory);
}
String get_audio_install_dir() {
- return installAudioDirectory;
+ return _G(installAudioDirectory);
}
String get_voice_install_dir() {
- return installVoiceDirectory;
+ return _G(installVoiceDirectory);
}
void get_install_dir_path(char *buffer, const char *fileName) {
- sprintf(buffer, "%s/%s", installDirectory.GetCStr(), fileName);
+ sprintf(buffer, "%s/%s", _G(installDirectory).GetCStr(), fileName);
}
String find_assetlib(const String &filename) {
String libname = cbuf_to_string_and_free(ci_find_file(_GP(ResPaths).DataDir, filename));
if (AssetManager::IsDataFile(libname))
return libname;
- if (Path::ComparePaths(_GP(ResPaths).DataDir, installDirectory) != 0) {
+ if (Path::ComparePaths(_GP(ResPaths).DataDir, _G(installDirectory)) != 0) {
// Hack for running in Debugger
- libname = cbuf_to_string_and_free(ci_find_file(installDirectory, filename));
+ libname = cbuf_to_string_and_free(ci_find_file(_G(installDirectory), filename));
if (AssetManager::IsDataFile(libname))
return libname;
}
@@ -532,9 +522,9 @@ String get_known_assetlib(const String &filename) {
Stream *find_open_asset(const String &filename) {
Stream *asset_s = Shared::AssetManager::OpenAsset(filename);
- if (!asset_s && Path::ComparePaths(_GP(ResPaths).DataDir, installDirectory) != 0) {
+ if (!asset_s && Path::ComparePaths(_GP(ResPaths).DataDir, _G(installDirectory)) != 0) {
// Just in case they're running in Debug, try standalone file in compiled folder
- asset_s = ci_fopen(String::FromFormat("%s/%s", installDirectory.GetCStr(), filename.GetCStr()));
+ asset_s = ci_fopen(String::FromFormat("%s/%s", _G(installDirectory).GetCStr(), filename.GetCStr()));
}
return asset_s;
}
@@ -542,8 +532,8 @@ Stream *find_open_asset(const String &filename) {
AssetPath get_audio_clip_assetpath(int bundling_type, const String &filename) {
// Special case is explicitly defined audio directory, which should be
// tried first regardless of bundling type.
- if (Path::ComparePaths(_GP(ResPaths).DataDir, installAudioDirectory) != 0) {
- String filepath = String::FromFormat("%s/%s", installAudioDirectory.GetCStr(), filename.GetCStr());
+ if (Path::ComparePaths(_GP(ResPaths).DataDir, _G(installAudioDirectory)) != 0) {
+ String filepath = String::FromFormat("%s/%s", _G(installAudioDirectory).GetCStr(), filename.GetCStr());
if (Path::IsFile(filepath))
return AssetPath("", filepath);
}
@@ -558,8 +548,8 @@ AssetPath get_audio_clip_assetpath(int bundling_type, const String &filename) {
AssetPath get_voice_over_assetpath(const String &filename) {
// Special case is explicitly defined voice-over directory, which should be
// tried first.
- if (Path::ComparePaths(_GP(ResPaths).DataDir, installVoiceDirectory) != 0) {
- String filepath = String::FromFormat("%s/%s", installVoiceDirectory.GetCStr(), filename.GetCStr());
+ if (Path::ComparePaths(_GP(ResPaths).DataDir, _G(installVoiceDirectory)) != 0) {
+ String filepath = String::FromFormat("%s/%s", _G(installVoiceDirectory).GetCStr(), filename.GetCStr());
if (Path::IsFile(filepath))
return AssetPath("", filepath);
}
diff --git a/engines/ags/globals.h b/engines/ags/globals.h
index c7ef82cf2b..0c525dc50d 100644
--- a/engines/ags/globals.h
+++ b/engines/ags/globals.h
@@ -227,6 +227,22 @@ public:
/**@}*/
+ /**
+ * \defgroup file globals
+ * @{
+ */
+
+ // TODO: the asset path configuration should certainly be revamped at some
+ // point, with uniform method of configuring auxiliary paths and packages.
+ // Installation directory, may contain absolute or relative path
+ String _installDirectory;
+ // Installation directory, containing audio files
+ String _installAudioDirectory;
+ // Installation directory, containing voice-over files
+ String _installVoiceDirectory;
+
+ /**@}*/
+
/**
* \defgroup fonts globals
* @{
Commit: 21e9dde4caa647c2883ec3bb496acb75335a488a
https://github.com/scummvm/scummvm/commit/21e9dde4caa647c2883ec3bb496acb75335a488a
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-03-06T15:11:39-08:00
Commit Message:
AGS: Move cc_error.cpp globals to Globals
Changed paths:
engines/ags/engine/ac/event.cpp
engines/ags/engine/ac/game.cpp
engines/ags/engine/ac/room.cpp
engines/ags/engine/debugging/debug.cpp
engines/ags/engine/game/game_init.cpp
engines/ags/engine/game/savegame.cpp
engines/ags/engine/game/savegame_components.cpp
engines/ags/engine/script/cc_instance.cpp
engines/ags/engine/script/script.cpp
engines/ags/globals.h
engines/ags/shared/game/main_game_file.cpp
engines/ags/shared/game/room_file.cpp
engines/ags/shared/script/cc_error.cpp
engines/ags/shared/script/cc_error.h
diff --git a/engines/ags/engine/ac/event.cpp b/engines/ags/engine/ac/event.cpp
index 7bc6e14449..23361b01c3 100644
--- a/engines/ags/engine/ac/event.cpp
+++ b/engines/ags/engine/ac/event.cpp
@@ -156,7 +156,7 @@ void force_event(int evtyp, int ev1, int ev2, int ev3) {
void process_event(EventHappened *evp) {
RuntimeScriptValue rval_null;
if (evp->type == EV_TEXTSCRIPT) {
- ccError = 0;
+ _G(ccError) = 0;
if (evp->data2 > -1000) {
QueueScriptFunction(kScInstGame, tsnames[evp->data1], 1, RuntimeScriptValue().SetInt32(evp->data2));
} else {
diff --git a/engines/ags/engine/ac/game.cpp b/engines/ags/engine/ac/game.cpp
index 22535dd0c5..f4c2995561 100644
--- a/engines/ags/engine/ac/game.cpp
+++ b/engines/ags/engine/ac/game.cpp
@@ -1470,7 +1470,7 @@ HSaveError restore_game_data(Stream *in, SavegameVersion svg_version, const Pres
if (ccUnserializeAllObjects(in, &ccUnserializer)) {
return new SavegameError(kSvgErr_GameObjectInitFailed,
- String::FromFormat("Managed pool deserialization failed: %s.", ccErrorString.GetCStr()));
+ String::FromFormat("Managed pool deserialization failed: %s.", _G(ccErrorString).GetCStr()));
}
// preserve legacy music type setting
diff --git a/engines/ags/engine/ac/room.cpp b/engines/ags/engine/ac/room.cpp
index 73137912ba..218ec4333f 100644
--- a/engines/ags/engine/ac/room.cpp
+++ b/engines/ags/engine/ac/room.cpp
@@ -993,17 +993,17 @@ void check_new_room() {
}
void compile_room_script() {
- ccError = 0;
+ _G(ccError) = 0;
_G(roominst) = ccInstance::CreateFromScript(_GP(thisroom).CompiledScript);
- if ((ccError != 0) || (_G(roominst) == nullptr)) {
- quitprintf("Unable to create local script: %s", ccErrorString.GetCStr());
+ if ((_G(ccError) != 0) || (_G(roominst) == nullptr)) {
+ quitprintf("Unable to create local script: %s", _G(ccErrorString).GetCStr());
}
_G(roominstFork) = _G(roominst)->Fork();
if (_G(roominstFork) == nullptr)
- quitprintf("Unable to create forked room instance: %s", ccErrorString.GetCStr());
+ quitprintf("Unable to create forked room instance: %s", _G(ccErrorString).GetCStr());
_GP(repExecAlways).roomHasFunction = true;
_GP(lateRepExecAlways).roomHasFunction = true;
diff --git a/engines/ags/engine/debugging/debug.cpp b/engines/ags/engine/debugging/debug.cpp
index 2a00e0a4db..9e12ac0779 100644
--- a/engines/ags/engine/debugging/debug.cpp
+++ b/engines/ags/engine/debugging/debug.cpp
@@ -311,7 +311,7 @@ String get_cur_script(int numberOfLinesOfCallStack) {
if (sci)
callstack = sci->GetCallStack(numberOfLinesOfCallStack);
if (callstack.IsEmpty())
- callstack = ccErrorCallStack;
+ callstack = _G(ccErrorCallStack);
return callstack;
}
diff --git a/engines/ags/engine/game/game_init.cpp b/engines/ags/engine/game/game_init.cpp
index 9178ead0e9..69337d950f 100644
--- a/engines/ags/engine/game/game_init.cpp
+++ b/engines/ags/engine/game/game_init.cpp
@@ -400,7 +400,7 @@ HGameInitError InitGameState(const LoadedGameEntities &ents, GameDataVersion dat
_GP(scriptModules) = ents.ScriptModules;
AllocScriptModules();
if (create_global_script())
- return new GameInitError(kGameInitErr_ScriptLinkFailed, ccErrorString);
+ return new GameInitError(kGameInitErr_ScriptLinkFailed, _G(ccErrorString));
return HGameInitError::None();
}
diff --git a/engines/ags/engine/game/savegame.cpp b/engines/ags/engine/game/savegame.cpp
index aaebf5aca7..6cfd918def 100644
--- a/engines/ags/engine/game/savegame.cpp
+++ b/engines/ags/engine/game/savegame.cpp
@@ -463,7 +463,7 @@ HSaveError DoAfterRestore(const PreservedParams &pp, const RestoredData &r_data)
if (create_global_script()) {
return new SavegameError(kSvgErr_GameObjectInitFailed,
- String::FromFormat("Unable to recreate global script: %s", ccErrorString.GetCStr()));
+ String::FromFormat("Unable to recreate global script: %s", _G(ccErrorString).GetCStr()));
}
// read the global data into the newly created script
diff --git a/engines/ags/engine/game/savegame_components.cpp b/engines/ags/engine/game/savegame_components.cpp
index 79ee0bec3f..0dae07d1ce 100644
--- a/engines/ags/engine/game/savegame_components.cpp
+++ b/engines/ags/engine/game/savegame_components.cpp
@@ -984,7 +984,7 @@ HSaveError WriteManagedPool(PStream out) {
HSaveError ReadManagedPool(PStream in, int32_t cmp_ver, const PreservedParams &pp, RestoredData &r_data) {
if (ccUnserializeAllObjects(in.get(), &ccUnserializer)) {
return new SavegameError(kSvgErr_GameObjectInitFailed,
- String::FromFormat("Managed pool deserialization failed: %s", ccErrorString.GetCStr()));
+ String::FromFormat("Managed pool deserialization failed: %s", _G(ccErrorString).GetCStr()));
}
return HSaveError::None();
}
diff --git a/engines/ags/engine/script/cc_instance.cpp b/engines/ags/engine/script/cc_instance.cpp
index f1650f97f3..0f8e94831b 100644
--- a/engines/ags/engine/script/cc_instance.cpp
+++ b/engines/ags/engine/script/cc_instance.cpp
@@ -276,7 +276,7 @@ void ccInstance::AbortAndDestroy() {
}
int ccInstance::CallScriptFunction(const char *funcname, int32_t numargs, const RuntimeScriptValue *params) {
- ccError = 0;
+ _G(ccError) = 0;
currentline = 0;
if (numargs > 0 && !params) {
@@ -346,7 +346,7 @@ int ccInstance::CallScriptFunction(const char *funcname, int32_t numargs, const
PushValueToStack(params[i]);
}
PushValueToStack(RuntimeScriptValue().SetInt32(0)); // return address on stack
- if (ccError) {
+ if (_G(ccError)) {
return -1;
}
runningInst = this;
@@ -381,7 +381,7 @@ int ccInstance::CallScriptFunction(const char *funcname, int32_t numargs, const
cc_error("stack pointer was not zero at completion of script");
return -5;
}
- return ccError;
+ return _G(ccError);
}
// Macros to maintain the call stack
@@ -546,7 +546,7 @@ int ccInstance::Run(int32_t curpc) {
registers[SREG_SP].RValue++;
} else {
PushDataToStack(arg2.IValue);
- if (ccError) {
+ if (_G(ccError)) {
return -1;
}
}
@@ -567,7 +567,7 @@ int ccInstance::Run(int32_t curpc) {
// This is practically LOADSPOFFS
reg1 = GetStackPtrOffsetRw(arg2.IValue);
}
- if (ccError) {
+ if (_G(ccError)) {
return -1;
}
} else {
@@ -629,7 +629,7 @@ int ccInstance::Run(int32_t curpc) {
break;
case SCMD_LOADSPOFFS:
registers[SREG_MAR] = GetStackPtrOffsetRw(arg1.IValue);
- if (ccError) {
+ if (_G(ccError)) {
return -1;
}
break;
@@ -708,7 +708,7 @@ int ccInstance::Run(int32_t curpc) {
ASSERT_STACK_SPACE_AVAILABLE(1);
PushValueToStack(RuntimeScriptValue().SetInt32(pc + codeOp.ArgCount + 1));
- if (ccError) {
+ if (_G(ccError)) {
return -1;
}
@@ -756,7 +756,7 @@ int ccInstance::Run(int32_t curpc) {
// Push reg[arg1] value to the stack
ASSERT_STACK_SPACE_AVAILABLE(1);
PushValueToStack(reg1);
- if (ccError) {
+ if (_G(ccError)) {
return -1;
}
break;
@@ -811,7 +811,7 @@ int ccInstance::Run(int32_t curpc) {
// 64 bit: Handles are always 32 bit values. They are not C pointer.
case SCMD_MEMREADPTR: {
- ccError = 0;
+ _G(ccError) = 0;
int32_t handle = registers[SREG_MAR].ReadInt32();
void *object;
@@ -824,7 +824,7 @@ int ccInstance::Run(int32_t curpc) {
}
// if error occurred, cc_error will have been set
- if (ccError)
+ if (_G(ccError))
return -1;
break;
}
@@ -940,7 +940,7 @@ int ccInstance::Run(int32_t curpc) {
// 0, so that the cc_run_code returns
RuntimeScriptValue oldstack = registers[SREG_SP];
PushValueToStack(RuntimeScriptValue().SetInt32(0));
- if (ccError) {
+ if (_G(ccError)) {
return -1;
}
@@ -1028,7 +1028,7 @@ int ccInstance::Run(int32_t curpc) {
cc_error("invalid pointer type for function call: %d", reg1.Type);
}
- if (ccError) {
+ if (_G(ccError)) {
return -1;
}
diff --git a/engines/ags/engine/script/script.cpp b/engines/ags/engine/script/script.cpp
index 45fad9dddb..296ff16715 100644
--- a/engines/ags/engine/script/script.cpp
+++ b/engines/ags/engine/script/script.cpp
@@ -294,23 +294,23 @@ bool DoRunScriptFuncCantBlock(ccInstance *sci, NonBlockingScriptFunction *funcTo
funcToRun->atLeastOneImplementationExists = true;
}
// this might be nested, so don't disrupt blocked scripts
- ccErrorString = "";
- ccError = 0;
+ _G(ccErrorString) = "";
+ _G(ccError) = 0;
_G(no_blocking_functions)--;
return (hasTheFunc);
}
char scfunctionname[MAX_FUNCTION_NAME_LEN + 1];
int PrepareTextScript(ccInstance *sci, const char **tsname) {
- ccError = 0;
+ _G(ccError) = 0;
// FIXME: try to make it so this function is not called with NULL sci
if (sci == nullptr) return -1;
if (sci->GetSymbolAddress(tsname[0]).IsNull()) {
- ccErrorString = "no such function in script";
+ _G(ccErrorString) = "no such function in script";
return -2;
}
if (sci->IsBeingRun()) {
- ccErrorString = "script is already in execution";
+ _G(ccErrorString) = "script is already in execution";
return -3;
}
_G(scripts)[_G(num_scripts)].init();
@@ -339,23 +339,23 @@ int PrepareTextScript(ccInstance *sci, const char **tsname) {
int RunScriptFunctionIfExists(ccInstance *sci, const char *tsname, int numParam, const RuntimeScriptValue *params) {
int oldRestoreCount = gameHasBeenRestored;
- // First, save the current ccError state
+ // First, save the current _G(ccError) state
// This is necessary because we might be attempting
// to run Script B, while Script A is still running in the
// background.
// If CallInstance here has an error, it would otherwise
- // also abort Script A because ccError is a global variable.
- int cachedCcError = ccError;
- ccError = 0;
+ // also abort Script A because _G(ccError) is a global variable.
+ int cachedCcError = _G(ccError);
+ _G(ccError) = 0;
int toret = PrepareTextScript(sci, &tsname);
if (toret) {
- ccError = cachedCcError;
+ _G(ccError) = cachedCcError;
return -18;
}
// Clear the error message
- ccErrorString = "";
+ _G(ccErrorString) = "";
if (numParam < 3) {
toret = _G(curscript)->inst->CallScriptFunction(tsname, numParam, params);
@@ -377,7 +377,7 @@ int RunScriptFunctionIfExists(ccInstance *sci, const char *tsname, int numParam,
_G(post_script_cleanup_stack)--;
// restore cached error state
- ccError = cachedCcError;
+ _G(ccError) = cachedCcError;
// if the game has been restored, ensure that any further scripts are not run
if ((oldRestoreCount != gameHasBeenRestored) && (eventClaimed == EVENT_INPROGRESS))
@@ -407,7 +407,7 @@ int RunTextScript(ccInstance *sci, const char *tsname) {
int toret = RunScriptFunctionIfExists(sci, tsname, 0, nullptr);
if ((toret == -18) && (sci == _G(roominst))) {
// functions in room script must exist
- quitprintf("prepare_script: error %d (%s) trying to run '%s' (Room %d)", toret, ccErrorString.GetCStr(), tsname, displayed_room);
+ quitprintf("prepare_script: error %d (%s) trying to run '%s' (Room %d)", toret, _G(ccErrorString).GetCStr(), tsname, displayed_room);
}
return toret;
}
@@ -472,7 +472,7 @@ char *make_ts_func_name(const char *base, int iii, int subd) {
void post_script_cleanup() {
// should do any post-script stuff here, like go to new room
- if (ccError) quit(ccErrorString);
+ if (_G(ccError)) quit(_G(ccErrorString));
ExecutingScript copyof = _G(scripts)[_G(num_scripts) - 1];
if (_G(scripts)[_G(num_scripts) - 1].forked)
delete _G(scripts)[_G(num_scripts) - 1].inst;
@@ -562,10 +562,10 @@ void quit_with_script_error(const char *functionName) {
// TODO: clean up the error reporting logic. Now engine will append call
// stack info in quit_check_for_error_state() but only in case of explicit
// script error ("!" type), and not in other case.
- if (ccErrorIsUserError)
- quitprintf("!Error running function '%s':\n%s", functionName, ccErrorString.GetCStr());
+ if (_G(ccErrorIsUserError))
+ quitprintf("!Error running function '%s':\n%s", functionName, _G(ccErrorString).GetCStr());
else
- quitprintf("Error running function '%s':\n%s\n\n%s", functionName, ccErrorString.GetCStr(), get_cur_script(5).GetCStr());
+ quitprintf("Error running function '%s':\n%s\n\n%s", functionName, _G(ccErrorString).GetCStr(), get_cur_script(5).GetCStr());
}
int get_nivalue(InteractionCommandList *nic, int idx, int parm) {
diff --git a/engines/ags/globals.h b/engines/ags/globals.h
index 0c525dc50d..69ec0e37c7 100644
--- a/engines/ags/globals.h
+++ b/engines/ags/globals.h
@@ -136,6 +136,20 @@ public:
/**@}*/
+ /**
+ * \defgroup cc_error globals
+ * @{
+ */
+
+ int _ccError = 0;
+ int _ccErrorLine = 0;
+ String _ccErrorString;
+ String _ccErrorCallStack;
+ bool _ccErrorIsUserError = false;
+ const char *_ccCurScriptName = "";
+
+ /**@}*/
+
/**
* \defgroup debug globals
* @{
diff --git a/engines/ags/shared/game/main_game_file.cpp b/engines/ags/shared/game/main_game_file.cpp
index 9a360d71dd..da582f485e 100644
--- a/engines/ags/shared/game/main_game_file.cpp
+++ b/engines/ags/shared/game/main_game_file.cpp
@@ -183,7 +183,7 @@ HGameFileError ReadDialogScript(PScript &dialog_script, Stream *in, GameDataVers
if (data_ver > kGameVersion_310) { // 3.1.1+ dialog script
dialog_script.reset(ccScript::CreateFromStream(in));
if (dialog_script == nullptr)
- return new MainGameFileError(kMGFErr_CreateDialogScriptFailed, ccErrorString);
+ return new MainGameFileError(kMGFErr_CreateDialogScriptFailed, _G(ccErrorString));
} else { // 2.x and < 3.1.1 dialog
dialog_script.reset();
}
@@ -197,7 +197,7 @@ HGameFileError ReadScriptModules(std::vector<PScript> &sc_mods, Stream *in, Game
for (int i = 0; i < count; ++i) {
sc_mods[i].reset(ccScript::CreateFromStream(in));
if (sc_mods[i] == nullptr)
- return new MainGameFileError(kMGFErr_CreateScriptModuleFailed, ccErrorString);
+ return new MainGameFileError(kMGFErr_CreateScriptModuleFailed, _G(ccErrorString));
}
} else {
sc_mods.resize(0);
@@ -672,7 +672,7 @@ HGameFileError ReadGameData(LoadedGameEntities &ents, Stream *in, GameDataVersio
return new MainGameFileError(kMGFErr_NoGlobalScript);
ents.GlobalScript.reset(ccScript::CreateFromStream(in));
if (!ents.GlobalScript)
- return new MainGameFileError(kMGFErr_CreateGlobalScriptFailed, ccErrorString);
+ return new MainGameFileError(kMGFErr_CreateGlobalScriptFailed, _G(ccErrorString));
err = ReadDialogScript(ents.DialogScript, in, data_ver);
if (!err)
return err;
diff --git a/engines/ags/shared/game/room_file.cpp b/engines/ags/shared/game/room_file.cpp
index 11f5baf9fe..916b7b9105 100644
--- a/engines/ags/shared/game/room_file.cpp
+++ b/engines/ags/shared/game/room_file.cpp
@@ -34,6 +34,7 @@
#include "ags/shared/script/cc_script.h"
#include "ags/shared/util/compress.h"
#include "ags/shared/util/string_utils.h"
+#include "ags/globals.h"
namespace AGS3 {
@@ -404,7 +405,7 @@ HRoomFileError ReadScriptBlock(char *&buf, Stream *in, RoomFileVersion data_ver)
HRoomFileError ReadCompSc3Block(RoomStruct *room, Stream *in, RoomFileVersion data_ver) {
room->CompiledScript.reset(ccScript::CreateFromStream(in));
if (room->CompiledScript == nullptr)
- return new RoomFileError(kRoomFileErr_ScriptLoadFailed, ccErrorString);
+ return new RoomFileError(kRoomFileErr_ScriptLoadFailed, _G(ccErrorString));
return HRoomFileError::None();
}
diff --git a/engines/ags/shared/script/cc_error.cpp b/engines/ags/shared/script/cc_error.cpp
index f404788f6c..4c3c9d527d 100644
--- a/engines/ags/shared/script/cc_error.cpp
+++ b/engines/ags/shared/script/cc_error.cpp
@@ -23,6 +23,7 @@
#include "ags/shared/script/script_common.h" // current_line
#include "ags/shared/util/string.h"
#include "ags/lib/std/utility.h"
+#include "ags/globals.h"
namespace AGS3 {
@@ -33,17 +34,10 @@ extern std::pair<String, String> cc_error_at_line(const char *error_msg);
// Returns script error message without location or callstack
extern String cc_error_without_line(const char *error_msg);
-int ccError = 0;
-int ccErrorLine = 0;
-String ccErrorString;
-String ccErrorCallStack;
-bool ccErrorIsUserError = false;
-const char *ccCurScriptName = "";
-
void cc_error(const char *descr, ...) {
- ccErrorIsUserError = false;
+ _G(ccErrorIsUserError) = false;
if (descr[0] == '!') {
- ccErrorIsUserError = true;
+ _G(ccErrorIsUserError) = true;
descr++;
}
@@ -55,15 +49,15 @@ void cc_error(const char *descr, ...) {
if (currentline > 0) {
// [IKM] Implementation is project-specific
std::pair<String, String> errinfo = cc_error_at_line(displbuf);
- ccErrorString = errinfo.first;
- ccErrorCallStack = errinfo.second;
+ _G(ccErrorString) = errinfo.first;
+ _G(ccErrorCallStack) = errinfo.second;
} else {
- ccErrorString = cc_error_without_line(displbuf);
- ccErrorCallStack = "";
+ _G(ccErrorString) = cc_error_without_line(displbuf);
+ _G(ccErrorCallStack) = "";
}
- ccError = 1;
- ccErrorLine = currentline;
+ _G(ccError) = 1;
+ _G(ccErrorLine) = currentline;
}
} // namespace AGS3
diff --git a/engines/ags/shared/script/cc_error.h b/engines/ags/shared/script/cc_error.h
index 35089ada23..de2db0457c 100644
--- a/engines/ags/shared/script/cc_error.h
+++ b/engines/ags/shared/script/cc_error.h
@@ -35,14 +35,6 @@ namespace AGS3 {
extern void cc_error(const char *, ...);
-// error reporting
-extern int ccError; // set to non-zero if error occurs
-extern int ccErrorLine; // line number of the error
-extern AGS::Shared::String ccErrorString; // description of the error
-extern AGS::Shared::String ccErrorCallStack; // callstack where error happened
-extern bool ccErrorIsUserError;
-extern const char *ccCurScriptName; // name of currently compiling script
-
} // namespace AGS3
#endif
Commit: 49c8bc415b459c292db27d7ade36dcf594b3c528
https://github.com/scummvm/scummvm/commit/49c8bc415b459c292db27d7ade36dcf594b3c528
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-03-06T15:11:39-08:00
Commit Message:
AGS: Move global_dialog.cpp globals to Globals
Changed paths:
engines/ags/engine/ac/global_dialog.cpp
engines/ags/engine/ac/global_room.cpp
engines/ags/globals.cpp
engines/ags/globals.h
diff --git a/engines/ags/engine/ac/global_dialog.cpp b/engines/ags/engine/ac/global_dialog.cpp
index a75f334b2d..7035af2108 100644
--- a/engines/ags/engine/ac/global_dialog.cpp
+++ b/engines/ags/engine/ac/global_dialog.cpp
@@ -36,10 +36,8 @@ namespace AGS3 {
using namespace AGS::Shared;
-
extern DialogTopic *dialog;
-ScriptPosition last_in_dialog_request_script_pos;
void RunDialog(int tum) {
if ((tum < 0) | (tum >= _GP(game).numdialog))
quit("!RunDialog: invalid topic number specified");
@@ -51,11 +49,11 @@ void RunDialog(int tum) {
_GP(play).stop_dialog_at_end = DIALOG_NEWTOPIC + tum;
else
quitprintf("!RunDialog: two NewRoom/RunDialog/StopDialog requests within dialog; last was called in \"%s\", line %d",
- last_in_dialog_request_script_pos.Section.GetCStr(), last_in_dialog_request_script_pos.Line);
+ _GP(last_in_dialog_request_script_pos).Section.GetCStr(), _GP(last_in_dialog_request_script_pos).Line);
return;
}
- get_script_position(last_in_dialog_request_script_pos);
+ get_script_position(_GP(last_in_dialog_request_script_pos));
if (_G(inside_script))
_G(curscript)->queue_action(ePSARunDialog, tum, "RunDialog");
@@ -70,7 +68,7 @@ void StopDialog() {
debug_script_log("StopDialog called but no dialog");
return;
}
- get_script_position(last_in_dialog_request_script_pos);
+ get_script_position(_GP(last_in_dialog_request_script_pos));
_GP(play).stop_dialog_at_end = DIALOG_STOP;
}
diff --git a/engines/ags/engine/ac/global_room.cpp b/engines/ags/engine/ac/global_room.cpp
index b1375f0e3d..3ffc01945d 100644
--- a/engines/ags/engine/ac/global_room.cpp
+++ b/engines/ags/engine/ac/global_room.cpp
@@ -81,7 +81,6 @@ void SetAmbientLightLevel(int light_level) {
_GP(play).rtint_light = light_level;
}
-extern ScriptPosition last_in_dialog_request_script_pos;
void NewRoom(int nrnum) {
if (nrnum < 0)
quitprintf("!NewRoom: room change requested to invalid room number %d.", nrnum);
@@ -103,12 +102,12 @@ void NewRoom(int nrnum) {
_GP(play).stop_dialog_at_end = DIALOG_NEWROOM + nrnum;
else {
quitprintf("!NewRoom: two NewRoom/RunDialog/StopDialog requests within dialog; last was called in \"%s\", line %d",
- last_in_dialog_request_script_pos.Section.GetCStr(), last_in_dialog_request_script_pos.Line);
+ _GP(last_in_dialog_request_script_pos).Section.GetCStr(), _GP(last_in_dialog_request_script_pos).Line);
}
return;
}
- get_script_position(last_in_dialog_request_script_pos);
+ get_script_position(_GP(last_in_dialog_request_script_pos));
if (in_leaves_screen >= 0) {
// NewRoom called from the Player Leaves Screen event -- just
diff --git a/engines/ags/globals.cpp b/engines/ags/globals.cpp
index 028a5d980d..bd88af5f74 100644
--- a/engines/ags/globals.cpp
+++ b/engines/ags/globals.cpp
@@ -70,6 +70,7 @@
#include "ags/engine/debugging/messagebuffer.h"
#include "ags/engine/media/audio/ambientsound.h"
#include "ags/engine/media/audio/audiodefines.h"
+#include "ags/engine/script/cc_instance.h"
#include "ags/engine/script/executingscript.h"
#include "ags/engine/script/nonblockingscriptfunction.h"
#include "ags/engine/script/script.h"
@@ -155,6 +156,9 @@ Globals::Globals() {
_StaticInventoryArray = new StaticArray();
_StaticDialogArray = new StaticArray();
+ // global_dialog.cpp globals
+ _last_in_dialog_request_script_pos = new ScriptPosition();
+
// guibutton.cpp globals
_guibuts = new std::vector<AGS::Shared::GUIButton>();
@@ -281,6 +285,9 @@ Globals::~Globals() {
delete _StaticInventoryArray;
delete _StaticDialogArray;
+ // global_dialog.cpp globals
+ delete _last_in_dialog_request_script_pos;
+
// guibutton.cpp globals
delete _guibuts;
diff --git a/engines/ags/globals.h b/engines/ags/globals.h
index 69ec0e37c7..c193302e54 100644
--- a/engines/ags/globals.h
+++ b/engines/ags/globals.h
@@ -104,6 +104,7 @@ struct ScriptGUI;
struct ScriptHotspot;
struct ScriptInvItem;
struct ScriptObject;
+struct ScriptPosition;
struct ScriptRegion;
struct ScriptString;
struct ScriptSystem;
@@ -330,6 +331,15 @@ public:
/**@}*/
+ /**
+ * \defgroup global_dialog globals
+ * @{
+ */
+
+ ScriptPosition *_last_in_dialog_request_script_pos;
+
+ /**@}*/
+
/**
* \defgroup guibutton globals
* @{
More information about the Scummvm-git-logs
mailing list