Initial commit
This commit is contained in:
238
engines/ags/shared/debugging/debug_manager.cpp
Normal file
238
engines/ags/shared/debugging/debug_manager.cpp
Normal file
@@ -0,0 +1,238 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "ags/shared/debugging/debug_manager.h"
|
||||
#include "ags/shared/util/string_types.h"
|
||||
#include "ags/globals.h"
|
||||
|
||||
namespace AGS3 {
|
||||
namespace AGS {
|
||||
namespace Shared {
|
||||
|
||||
DebugOutput::DebugOutput(const String &id, IOutputHandler *handler, MessageType def_verbosity, bool enabled)
|
||||
: _id(id)
|
||||
, _handler(handler)
|
||||
, _enabled(enabled)
|
||||
, _defaultVerbosity(def_verbosity) {
|
||||
_groupFilter.resize(_GP(DbgMgr)._lastGroupID + 1, _defaultVerbosity);
|
||||
}
|
||||
|
||||
String DebugOutput::GetID() const {
|
||||
return _id;
|
||||
}
|
||||
|
||||
IOutputHandler *DebugOutput::GetHandler() const {
|
||||
return _handler;
|
||||
}
|
||||
|
||||
bool DebugOutput::IsEnabled() const {
|
||||
return _enabled;
|
||||
}
|
||||
|
||||
void DebugOutput::SetEnabled(bool enable) {
|
||||
_enabled = enable;
|
||||
}
|
||||
|
||||
void DebugOutput::SetGroupFilter(DebugGroupID id, MessageType verbosity) {
|
||||
uint32_t key = _GP(DbgMgr).GetGroup(id).UID.ID;
|
||||
if (key != kDbgGroup_None)
|
||||
_groupFilter[key] = verbosity;
|
||||
else
|
||||
_unresolvedGroups.insert(std::make_pair(id.SID, verbosity));
|
||||
}
|
||||
|
||||
void DebugOutput::SetAllGroupFilters(MessageType verbosity) {
|
||||
for (auto &group : _groupFilter)
|
||||
group = verbosity;
|
||||
for (auto &group : _unresolvedGroups)
|
||||
group._value = verbosity;
|
||||
}
|
||||
|
||||
void DebugOutput::ClearGroupFilters() {
|
||||
for (auto &gf : _groupFilter)
|
||||
gf = kDbgMsg_None;
|
||||
_unresolvedGroups.clear();
|
||||
}
|
||||
|
||||
void DebugOutput::ResolveGroupID(DebugGroupID id) {
|
||||
if (!id.IsValid())
|
||||
return;
|
||||
|
||||
DebugGroupID real_id = _GP(DbgMgr).GetGroup(id).UID;
|
||||
if (real_id.IsValid()) {
|
||||
if (_groupFilter.size() <= id.ID)
|
||||
_groupFilter.resize(id.ID + 1, _defaultVerbosity);
|
||||
GroupNameToMTMap::const_iterator it = _unresolvedGroups.find(real_id.SID);
|
||||
if (it != _unresolvedGroups.end()) {
|
||||
_groupFilter[real_id.ID] = it->_value;
|
||||
_unresolvedGroups.erase(it);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool DebugOutput::TestGroup(DebugGroupID id, MessageType mt) const {
|
||||
DebugGroupID real_id = _GP(DbgMgr).GetGroup(id).UID;
|
||||
if (real_id.ID == (uint32_t)kDbgGroup_None || real_id.ID >= _groupFilter.size())
|
||||
return false;
|
||||
return (_groupFilter[real_id.ID] >= mt) != 0;
|
||||
}
|
||||
|
||||
DebugManager::DebugManager() {
|
||||
// Add hardcoded groups
|
||||
RegisterGroup(DebugGroup(DebugGroupID(kDbgGroup_Main, "main"), ""));
|
||||
RegisterGroup(DebugGroup(DebugGroupID(kDbgGroup_Game, "game"), "Game"));
|
||||
RegisterGroup(DebugGroup(DebugGroupID(kDbgGroup_Script, "script"), "Script"));
|
||||
RegisterGroup(DebugGroup(DebugGroupID(kDbgGroup_SprCache, "sprcache"), "Sprite cache"));
|
||||
RegisterGroup(DebugGroup(DebugGroupID(kDbgGroup_ManObj, "manobj"), "Managed obj"));
|
||||
_firstFreeGroupID = _groups.size();
|
||||
_lastGroupID = _firstFreeGroupID;
|
||||
}
|
||||
|
||||
DebugGroup DebugManager::GetGroup(DebugGroupID id) {
|
||||
if (id.ID != (uint32_t)kDbgGroup_None) {
|
||||
return id.ID < _groups.size() ? _groups[id.ID] : DebugGroup();
|
||||
} else if (!id.SID.IsEmpty()) {
|
||||
GroupByStringMap::const_iterator it = _groupByStrLookup.find(id.SID);
|
||||
return it != _groupByStrLookup.end() ? _groups[it->_value.ID] : DebugGroup();
|
||||
}
|
||||
return DebugGroup();
|
||||
}
|
||||
|
||||
PDebugOutput DebugManager::GetOutput(const String &id) {
|
||||
OutMap::const_iterator it = _outputs.find(id);
|
||||
return it != _outputs.end() ? it->_value.Target : PDebugOutput();
|
||||
}
|
||||
|
||||
DebugGroup DebugManager::RegisterGroup(const String &id, const String &out_name) {
|
||||
DebugGroup group = GetGroup(id);
|
||||
if (group.UID.IsValid())
|
||||
return group;
|
||||
group = DebugGroup(DebugGroupID(++_GP(DbgMgr)._lastGroupID, id), out_name);
|
||||
_groups.push_back(group);
|
||||
_groupByStrLookup[group.UID.SID] = group.UID;
|
||||
|
||||
// Resolve group reference on every output target
|
||||
for (OutMap::const_iterator it = _outputs.begin(); it != _outputs.end(); ++it) {
|
||||
it->_value.Target->ResolveGroupID(group.UID);
|
||||
}
|
||||
return group;
|
||||
}
|
||||
|
||||
void DebugManager::RegisterGroup(const DebugGroup &group) {
|
||||
if (_groups.size() <= group.UID.ID)
|
||||
_groups.resize(group.UID.ID + 1);
|
||||
_groups[group.UID.ID] = group; _groupByStrLookup[group.UID.SID] = group.UID;
|
||||
}
|
||||
|
||||
PDebugOutput DebugManager::RegisterOutput(const String &id, IOutputHandler *handler, MessageType def_verbosity, bool enabled) {
|
||||
_outputs[id].Target = PDebugOutput(new DebugOutput(id, handler, def_verbosity, enabled));
|
||||
_outputs[id].Suppressed = false;
|
||||
return _outputs[id].Target;
|
||||
}
|
||||
|
||||
void DebugManager::UnregisterAll() {
|
||||
_lastGroupID = _firstFreeGroupID;
|
||||
_groups.clear();
|
||||
_groupByStrLookup.clear();
|
||||
_outputs.clear();
|
||||
}
|
||||
|
||||
void DebugManager::UnregisterGroup(DebugGroupID id) {
|
||||
DebugGroup group = GetGroup(id);
|
||||
if (!group.UID.IsValid())
|
||||
return;
|
||||
_groups[group.UID.ID] = DebugGroup();
|
||||
_groupByStrLookup.erase(group.UID.SID);
|
||||
}
|
||||
|
||||
void DebugManager::UnregisterOutput(const String &id) {
|
||||
_outputs.erase(id);
|
||||
}
|
||||
|
||||
void DebugManager::Print(DebugGroupID group_id, MessageType mt, const String &text) {
|
||||
const DebugGroup &group = GetGroup(group_id);
|
||||
DebugMessage msg(text, group.UID.ID, group.OutputName, mt);
|
||||
|
||||
for (OutMap::iterator it = _outputs.begin(); it != _outputs.end(); ++it) {
|
||||
SendMessage(it->_value, msg);
|
||||
}
|
||||
}
|
||||
|
||||
void DebugManager::SendMessage(const String &out_id, const DebugMessage &msg) {
|
||||
OutMap::iterator it = _outputs.find(out_id);
|
||||
if (it != _outputs.end())
|
||||
SendMessage(it->_value, msg);
|
||||
}
|
||||
|
||||
void DebugManager::SendMessage(OutputSlot &out, const DebugMessage &msg) {
|
||||
IOutputHandler *handler = out.Target->GetHandler();
|
||||
if (!handler || !out.Target->IsEnabled() || out.Suppressed)
|
||||
return;
|
||||
if (!out.Target->TestGroup(msg.GroupID, msg.MT))
|
||||
return;
|
||||
// We suppress current target before the call so that if it makes
|
||||
// a call to output system itself, message would not print to the
|
||||
// same target
|
||||
out.Suppressed = true;
|
||||
handler->PrintMessage(msg);
|
||||
out.Suppressed = false;
|
||||
}
|
||||
|
||||
namespace Debug {
|
||||
|
||||
void Printf(const String &text) {
|
||||
_GP(DbgMgr).Print(kDbgGroup_Main, kDbgMsg_Default, text);
|
||||
}
|
||||
|
||||
void Printf(MessageType mt, const String &text) {
|
||||
_GP(DbgMgr).Print(kDbgGroup_Main, mt, text);
|
||||
}
|
||||
|
||||
void Printf(DebugGroupID group, MessageType mt, const String &text) {
|
||||
_GP(DbgMgr).Print(group, mt, text);
|
||||
}
|
||||
|
||||
void Printf(const char *fmt, ...) {
|
||||
va_list argptr;
|
||||
va_start(argptr, fmt);
|
||||
_GP(DbgMgr).Print(kDbgGroup_Main, kDbgMsg_Default, String::FromFormatV(fmt, argptr));
|
||||
va_end(argptr);
|
||||
}
|
||||
|
||||
void Printf(MessageType mt, const char *fmt, ...) {
|
||||
va_list argptr;
|
||||
va_start(argptr, fmt);
|
||||
_GP(DbgMgr).Print(kDbgGroup_Main, mt, String::FromFormatV(fmt, argptr));
|
||||
va_end(argptr);
|
||||
}
|
||||
|
||||
void Printf(DebugGroupID group, MessageType mt, const char *fmt, ...) {
|
||||
va_list argptr;
|
||||
va_start(argptr, fmt);
|
||||
_GP(DbgMgr).Print(group, mt, String::FromFormatV(fmt, argptr));
|
||||
va_end(argptr);
|
||||
}
|
||||
|
||||
} // namespace Debug
|
||||
|
||||
} // namespace Shared
|
||||
} // namespace AGS
|
||||
} // namespace AGS3
|
||||
168
engines/ags/shared/debugging/debug_manager.h
Normal file
168
engines/ags/shared/debugging/debug_manager.h
Normal file
@@ -0,0 +1,168 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// AGS logging system is built with idea that the engine components should not
|
||||
// be bothered with specifying particular output method. Instead they use
|
||||
// generic logging interface, and the actual message printing is done by one
|
||||
// or more registered handlers.
|
||||
// Firstly this makes logging functions independent of running platform or
|
||||
// back-end, secondly it grants end-users ability to configure output according
|
||||
// to their preference.
|
||||
//
|
||||
// To make the logging work we need to register two sets of "entities":
|
||||
// debug groups and output targets.
|
||||
// Debug group is an arbitrary object with a name that describes message
|
||||
// sender.
|
||||
// Output target defines printing handler and a set of verbosity rules
|
||||
// one per each known group.
|
||||
//
|
||||
// When the message is sent, it is tagged with one of the existing group IDs
|
||||
// and a message type (debug info, warning, error). This message is sent onto
|
||||
// each of the registered output targets, which do checks to find out whether
|
||||
// the message is permitted to be sent further to the printing handler, or not.
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#ifndef AGS_SHARED_DEBUGGING_DEBUG_MANAGER_H
|
||||
#define AGS_SHARED_DEBUGGING_DEBUG_MANAGER_H
|
||||
|
||||
#include "common/std/memory.h"
|
||||
#include "common/std/map.h"
|
||||
#include "ags/shared/debugging/out.h"
|
||||
#include "ags/shared/debugging/output_handler.h"
|
||||
#include "ags/shared/util/string.h"
|
||||
#include "ags/shared/util/string_types.h"
|
||||
|
||||
namespace AGS3 {
|
||||
namespace AGS {
|
||||
namespace Shared {
|
||||
|
||||
// DebugGroup is a message sender definition, identified by DebugGroupID
|
||||
// and providing OutputName that could be used when printing its messages.
|
||||
// OutputName may or may not be same as DebugGroupID.SID.
|
||||
struct DebugGroup {
|
||||
DebugGroupID UID;
|
||||
String OutputName;
|
||||
|
||||
DebugGroup() {
|
||||
}
|
||||
DebugGroup(DebugGroupID id, String out_name) : UID(id), OutputName(out_name) {
|
||||
}
|
||||
};
|
||||
|
||||
// DebugOutput is a slot for IOutputHandler with its own group filter
|
||||
class DebugOutput {
|
||||
public:
|
||||
DebugOutput(const String &id, IOutputHandler *handler, MessageType def_verbosity = kDbgMsg_All, bool enabled = true);
|
||||
|
||||
String GetID() const;
|
||||
IOutputHandler *GetHandler() const;
|
||||
|
||||
bool IsEnabled() const;
|
||||
void SetEnabled(bool enable);
|
||||
// Setup group filter: either allow or disallow a group with the given ID
|
||||
void SetGroupFilter(DebugGroupID id, MessageType verbosity);
|
||||
// Assign same verbosity level to all known groups
|
||||
void SetAllGroupFilters(MessageType verbosity);
|
||||
// Clear all group filters; this efficiently disables everything
|
||||
void ClearGroupFilters();
|
||||
// Try to resolve group filter unknown IDs
|
||||
void ResolveGroupID(DebugGroupID id);
|
||||
// Test if given group id is permitted
|
||||
bool TestGroup(DebugGroupID id, MessageType mt) const;
|
||||
|
||||
private:
|
||||
String _id;
|
||||
IOutputHandler *_handler;
|
||||
bool _enabled;
|
||||
MessageType _defaultVerbosity;
|
||||
// Set of permitted groups' numeric IDs
|
||||
std::vector<MessageType> _groupFilter;
|
||||
// Set of unresolved groups, which numeric IDs are not yet known
|
||||
typedef std::unordered_map<String, MessageType, IgnoreCase_Hash, IgnoreCase_EqualTo> GroupNameToMTMap;
|
||||
GroupNameToMTMap _unresolvedGroups;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<DebugOutput> PDebugOutput;
|
||||
|
||||
|
||||
class DebugManager {
|
||||
friend class DebugOutput;
|
||||
|
||||
public:
|
||||
DebugManager();
|
||||
|
||||
// Gets full group ID for any partial one; if the group is not registered returns unset ID
|
||||
DebugGroup GetGroup(DebugGroupID id);
|
||||
// Gets output control interface for the given ID
|
||||
PDebugOutput GetOutput(const String &id);
|
||||
// Registers debugging group with the given string ID; numeric ID
|
||||
// will be assigned internally. Returns full ID pair.
|
||||
// If the group with such string id already exists, returns existing ID.
|
||||
DebugGroup RegisterGroup(const String &id, const String &out_name);
|
||||
// Registers output delegate for passing debug messages to;
|
||||
// if the output with such id already exists, replaces the old one
|
||||
PDebugOutput RegisterOutput(const String &id, IOutputHandler *handler, MessageType def_verbosity = kDbgMsg_All, bool enabled = true);
|
||||
// Unregisters all groups and all targets
|
||||
void UnregisterAll();
|
||||
// Unregisters debugging group with the given ID
|
||||
void UnregisterGroup(DebugGroupID id);
|
||||
// Unregisters output delegate with the given ID
|
||||
void UnregisterOutput(const String &id);
|
||||
|
||||
// Output message of given group and message type
|
||||
void Print(DebugGroupID group_id, MessageType mt, const String &text);
|
||||
// Send message directly to the output with given id; the message
|
||||
// must pass the output's message filter though
|
||||
void SendMessage(const String &out_id, const DebugMessage &msg);
|
||||
|
||||
private:
|
||||
// OutputSlot struct wraps over output target and adds a flag which indicates
|
||||
// that this target is temporarily disabled (for internal use only)
|
||||
struct OutputSlot {
|
||||
PDebugOutput Target;
|
||||
bool Suppressed;
|
||||
|
||||
OutputSlot() : Suppressed(false) {
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::vector<DebugGroup> GroupVector;
|
||||
typedef std::unordered_map<String, DebugGroupID, IgnoreCase_Hash, IgnoreCase_EqualTo> GroupByStringMap;
|
||||
typedef std::unordered_map<String, OutputSlot, IgnoreCase_Hash, IgnoreCase_EqualTo> OutMap;
|
||||
|
||||
void RegisterGroup(const DebugGroup &id);
|
||||
void SendMessage(OutputSlot &out, const DebugMessage &msg);
|
||||
|
||||
uint32_t _firstFreeGroupID;
|
||||
uint32_t _lastGroupID;
|
||||
GroupVector _groups;
|
||||
GroupByStringMap _groupByStrLookup;
|
||||
OutMap _outputs;
|
||||
};
|
||||
|
||||
} // namespace Shared
|
||||
} // namespace AGS
|
||||
} // namespace AGS3
|
||||
|
||||
#endif
|
||||
173
engines/ags/shared/debugging/out.h
Normal file
173
engines/ags/shared/debugging/out.h
Normal file
@@ -0,0 +1,173 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// Debug output interface provides functions which send a formatted message
|
||||
// tagged with group ID and message type to the registered output handlers.
|
||||
//
|
||||
// Depending on configuration this message may be printed by any of those
|
||||
// handlers, or none of them. The calling unit should not worry about where the
|
||||
// message goes.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// On using message types.
|
||||
//
|
||||
// Please keep in mind, that there are different levels of errors. AGS logging
|
||||
// system allows to classify debug message by two parameters: debug group and
|
||||
// message type. Sometimes message type alone is not enough. Debug groups can
|
||||
// also be used to distinct messages that has less (or higher) importance.
|
||||
//
|
||||
// For example, there are engine errors and user (game-dev) mistakes. Script
|
||||
// commands that cannot be executed under given circumstances are user
|
||||
// mistakes, and usually are not as severe as internal engine errors. This is
|
||||
// why it is advised to use a separate debug group for mistakes like that to
|
||||
// distinct them from reports on the internal engine's problems and make
|
||||
// verbosity configuration flexible.
|
||||
//
|
||||
// kDbgMsg_Debug - is the most mundane type of message (if the printing function
|
||||
// argument list does not specify message type, it is probably kDbgMsg_Debug).
|
||||
// You can use it for almost anything, from noting some process steps to
|
||||
// displaying current object state. If certain messages are meant to be printed
|
||||
// very often, consider using another distinct debug group so that it may be
|
||||
// disabled to reduce log verbosity.
|
||||
//
|
||||
// kDbgMsg_Info - is a type for important notifications, such as initialization
|
||||
// and stopping of engine components.
|
||||
//
|
||||
// kDbgMsg_Warn - this is suggested for more significant cases, when you find
|
||||
// out that something is not right, but is not immediately affecting engine
|
||||
// processing. For example: certain object was constructed in a way that
|
||||
// would make them behave unexpectedly, or certain common files are missing but
|
||||
// it is not clear yet whether the game will be accessing them.
|
||||
// In other words: use kDbgMsg_Warn when there is no problem right away, but
|
||||
// you are *anticipating* that one may happen under certain circumstances.
|
||||
//
|
||||
// kDbgMsg_Error - use this kind of message is for actual serious problems.
|
||||
// If certain operation assumes both positive and negative results are
|
||||
// acceptable, it is preferred to report such negative result with simple
|
||||
// kDbgMsg_Debug message. kDbgMsg_Error is for negative results that are not
|
||||
// considered acceptable for normal run.
|
||||
//
|
||||
// kDbgMsg_Fatal - is the message type to be reported when the program or
|
||||
// component abortion is imminent.
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#ifndef AGS_SHARED_CORE_DEBUGGING_OUT_H
|
||||
#define AGS_SHARED_CORE_DEBUGGING_OUT_H
|
||||
|
||||
#include "ags/shared/util/string.h"
|
||||
|
||||
namespace AGS3 {
|
||||
namespace AGS {
|
||||
namespace Shared {
|
||||
|
||||
// Message types provide distinction for debug messages by their intent.
|
||||
enum MessageType {
|
||||
kDbgMsg_None = 0,
|
||||
// Alerts may be informative messages with topmost level of importance,
|
||||
// such as reporting engine startup and shutdown.
|
||||
kDbgMsg_Alert,
|
||||
// Fatal errors are ones that make program abort immediately.
|
||||
kDbgMsg_Fatal,
|
||||
// Error messages are about engine not being able to perform requested
|
||||
// operation in a situation when that will affect game playability and
|
||||
// further execution.
|
||||
kDbgMsg_Error,
|
||||
// Warnings are made when unexpected or non-standart behavior
|
||||
// is detected in program, which is not immediately critical,
|
||||
// but may be a symptom of a bigger problem.
|
||||
kDbgMsg_Warn,
|
||||
// General information messages.
|
||||
kDbgMsg_Info,
|
||||
// Debug reason is for arbitrary information about events and current
|
||||
// game state.
|
||||
kDbgMsg_Debug,
|
||||
|
||||
|
||||
// Convenient aliases
|
||||
kDbgMsg_Default = kDbgMsg_Debug,
|
||||
kDbgMsg_All = kDbgMsg_Debug
|
||||
};
|
||||
|
||||
// This enumeration is a list of common hard-coded groups, but more could
|
||||
// be added via debugging configuration interface (see 'debug/debug.h').
|
||||
enum CommonDebugGroup : uint32 {
|
||||
kDbgGroup_None = UINT32_MAX,
|
||||
// Main debug group is for reporting general engine status and issues
|
||||
kDbgGroup_Main = 0,
|
||||
// Game group is for logging game logic state and issues
|
||||
kDbgGroup_Game,
|
||||
// Log from the game script
|
||||
kDbgGroup_Script,
|
||||
// Sprite cache logging
|
||||
kDbgGroup_SprCache,
|
||||
// Group for debugging managed object state (can slow engine down!)
|
||||
kDbgGroup_ManObj
|
||||
};
|
||||
|
||||
// Debug group identifier defining either numeric or string id, or both
|
||||
struct DebugGroupID {
|
||||
uint32_t ID;
|
||||
String SID;
|
||||
|
||||
DebugGroupID() : ID((uint32_t)kDbgGroup_None) {
|
||||
}
|
||||
DebugGroupID(uint32_t id, const String &sid = "") : ID(id), SID(sid) {
|
||||
}
|
||||
DebugGroupID(const String &sid) : ID((uint32_t)kDbgGroup_None), SID(sid) {
|
||||
}
|
||||
// Tells if any of the id components is valid
|
||||
bool IsValid() const {
|
||||
return ID != (uint32_t)kDbgGroup_None || !SID.IsEmpty();
|
||||
}
|
||||
// Tells if both id components are properly set
|
||||
bool IsComplete() const {
|
||||
return ID != (uint32_t)kDbgGroup_None && !SID.IsEmpty();
|
||||
}
|
||||
};
|
||||
|
||||
namespace Debug {
|
||||
//
|
||||
// Debug output
|
||||
//
|
||||
// Output a plain message of default group and default type
|
||||
void Printf(const String &text);
|
||||
// Output a plain message of default group and given type
|
||||
void Printf(MessageType mt, const String &text);
|
||||
// Output a plain message of given group and type
|
||||
void Printf(DebugGroupID group_id, MessageType mt, const String &text);
|
||||
// Output formatted message of default group and default type
|
||||
void Printf(const char *fmt, ...);
|
||||
// Output formatted message of default group and given type
|
||||
void Printf(MessageType mt, const char *fmt, ...);
|
||||
// Output formatted message of given group and type
|
||||
void Printf(DebugGroupID group_id, MessageType mt, const char *fmt, ...);
|
||||
|
||||
} // namespace Debug
|
||||
|
||||
} // namespace Shared
|
||||
} // namespace AGS
|
||||
} // namespace AGS3
|
||||
|
||||
#endif
|
||||
68
engines/ags/shared/debugging/output_handler.h
Normal file
68
engines/ags/shared/debugging/output_handler.h
Normal file
@@ -0,0 +1,68 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// IOutputHandler is a debug printing interface. Its implementations can be
|
||||
// registered as potential output for the debug log.
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#ifndef AGS_SHARED_CORE_DEBUGGING_OUTPUT_HANDLER_H
|
||||
#define AGS_SHARED_CORE_DEBUGGING_OUTPUT_HANDLER_H
|
||||
|
||||
#include "ags/shared/debugging/out.h"
|
||||
#include "ags/shared/util/string.h"
|
||||
|
||||
namespace AGS3 {
|
||||
namespace AGS {
|
||||
namespace Shared {
|
||||
|
||||
struct DebugMessage {
|
||||
String Text;
|
||||
uint32_t GroupID;
|
||||
String GroupName;
|
||||
MessageType MT;
|
||||
|
||||
DebugMessage() : GroupID((uint32_t)kDbgGroup_None), MT(kDbgMsg_None) {
|
||||
}
|
||||
DebugMessage(const String &text, uint32_t group_id, const String &group_name, MessageType mt)
|
||||
: Text(text)
|
||||
, GroupID(group_id)
|
||||
, GroupName(group_name)
|
||||
, MT(mt) {
|
||||
}
|
||||
};
|
||||
|
||||
class IOutputHandler {
|
||||
public:
|
||||
virtual ~IOutputHandler() {}
|
||||
|
||||
// Print the given text sent from the debug group.
|
||||
// Implementations are free to decide which message components are to be printed, and how.
|
||||
virtual void PrintMessage(const DebugMessage &msg) = 0;
|
||||
};
|
||||
|
||||
} // namespace Shared
|
||||
} // namespace AGS
|
||||
} // namespace AGS3
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user