AGS: Move debug globals to Globals

This commit is contained in:
Paul Gilbert 2021-03-06 07:59:45 -08:00
parent e81f87769d
commit fd5c11f382
16 changed files with 108 additions and 96 deletions

View file

@ -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");

View file

@ -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);
}

View file

@ -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);
}
}

View file

@ -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);

View file

@ -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) {

View file

@ -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)) {

View file

@ -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) {

View file

@ -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

View file

@ -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"
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);
}

View file

@ -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

View file

@ -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

View file

@ -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;

View file

@ -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) {

View file

@ -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)) {

View file

@ -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;

View file

@ -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;
/**@}*/
/**