Skip to content

Commit

Permalink
Engine: toggle game console logging along with play.debug_mode variable
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-mogilko committed Sep 4, 2017
1 parent b7cf302 commit 014cec4
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 6 deletions.
8 changes: 7 additions & 1 deletion Engine/ac/game.cpp
Expand Up @@ -316,6 +316,12 @@ int Game_GetDialogCount()
return game.numdialog;
}

void set_debug_mode(bool on)
{
play.debug_mode = on ? 1 : 0;
debug_set_console(on);
}

void set_game_speed(int fps) {
frames_per_second = fps;
time_between_timers = 1000 / fps;
Expand Down Expand Up @@ -2882,7 +2888,7 @@ void RegisterGameAPI()

void RegisterStaticObjects()
{
ccAddExternalStaticObject("game",&play, &GlobalStaticManager);
ccAddExternalStaticObject("game",&play, &GameStaticManager);
ccAddExternalStaticObject("gs_globals",&play.globalvars[0], &GlobalStaticManager);
ccAddExternalStaticObject("mouse",&scmouse, &GlobalStaticManager);
ccAddExternalStaticObject("palette",&palette[0], &GlobalStaticManager);
Expand Down
1 change: 1 addition & 0 deletions Engine/ac/game.h
Expand Up @@ -117,6 +117,7 @@ int Game_ChangeTranslation(const char *newFilename);

//=============================================================================

void set_debug_mode(bool on);
void set_game_speed(int fps);
void setup_for_dialog();
void restore_after_dialog();
Expand Down
14 changes: 14 additions & 0 deletions Engine/ac/statobj/agsstaticobject.cpp
@@ -1,8 +1,10 @@

#include <string.h>
#include "ac/statobj/agsstaticobject.h"
#include "ac/game.h"

AGSStaticObject GlobalStaticManager;
StaticGame GameStaticManager;

void AGSStaticObject::Read(const char *address, intptr_t offset, void *dest, int size)
{
Expand Down Expand Up @@ -53,3 +55,15 @@ void AGSStaticObject::WriteFloat(const char *address, intptr_t offset, float val
{
*(float*)(address + offset) = val;
}

void StaticGame::WriteInt32(const char *address, intptr_t offset, int32_t val)
{
if (offset == 4 * sizeof(int32_t))
{ // game.debug_mode
set_debug_mode(val != 0);
}
else
{
*(int32_t*)(address + offset) = val;
}
}
6 changes: 6 additions & 0 deletions Engine/ac/statobj/agsstaticobject.h
Expand Up @@ -36,6 +36,12 @@ struct AGSStaticObject : public ICCStaticObject {
virtual void WriteFloat(const char *address, intptr_t offset, float val);
};

// Wrapper around script's "Game" struct, managing access to its variables
struct StaticGame : public AGSStaticObject {
virtual void WriteInt32(const char *address, intptr_t offset, int32_t val);
};

extern AGSStaticObject GlobalStaticManager;
extern StaticGame GameStaticManager;

#endif // __AGS_EE_STATOBJ__AGSSTATICOBJECT_H
24 changes: 19 additions & 5 deletions Engine/debug/debug.cpp
Expand Up @@ -135,11 +135,7 @@ void apply_debug_config(const ConfigTree &cfg)
if (game.options[OPT_DEBUGMODE] != 0)
{
// Game console
DebugConsole.reset(new ConsoleOutputTarget());
PDebugOutput gmcs_out = DbgMgr.RegisterOutput(OutputGameConsoleID, DebugConsole.get(), kDbgMsgSet_Errors);
gmcs_out->SetGroupFilter(kDbgGroup_Main, kDbgMsgSet_All);
gmcs_out->SetGroupFilter(kDbgGroup_Script, kDbgMsgSet_All);
DebugMsgBuff->Send(OutputGameConsoleID);
debug_set_console(true);

// "Warnings.log" for printing script warnings in debug mode
DebugWarningsFile.reset(new LogFile());
Expand Down Expand Up @@ -168,6 +164,24 @@ void shutdown_debug()
DebugConsole.reset();
}

void debug_set_console(bool enable)
{
if (enable && DebugConsole.get() == NULL)
{
DebugConsole.reset(new ConsoleOutputTarget());
PDebugOutput gmcs_out = DbgMgr.RegisterOutput(OutputGameConsoleID, DebugConsole.get(), kDbgMsgSet_Errors);
gmcs_out->SetGroupFilter(kDbgGroup_Main, kDbgMsgSet_All);
gmcs_out->SetGroupFilter(kDbgGroup_Script, kDbgMsgSet_All);
if (DebugMsgBuff.get())
DebugMsgBuff->Send(OutputGameConsoleID);
}
else if (!enable && DebugConsole.get() != NULL)
{
DbgMgr.UnregisterOutput(OutputGameConsoleID);
DebugConsole.reset();
}
}

// Prepends message text with current room number and running script info, then logs result
void debug_script_print(const String &msg, MessageType mt)
{
Expand Down
2 changes: 2 additions & 0 deletions Engine/debug/debug_log.h
Expand Up @@ -25,6 +25,8 @@ void init_debug();
void apply_debug_config(const AGS::Common::ConfigTree &cfg);
void shutdown_debug();

void debug_set_console(bool enable);

// debug_script_log prints debug warnings tagged with kDbgGroup_Script,
// prepending it with current room number and script position identification
void debug_script_warn(const char *texx, ...);
Expand Down

0 comments on commit 014cec4

Please sign in to comment.