aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/debugger.cpp49
-rw-r--r--common/debugger.h4
-rw-r--r--common/util.cpp77
-rw-r--r--common/util.h67
4 files changed, 195 insertions, 2 deletions
diff --git a/common/debugger.cpp b/common/debugger.cpp
index 0ed4c4eeb6..0771e65720 100644
--- a/common/debugger.cpp
+++ b/common/debugger.cpp
@@ -43,6 +43,10 @@ Debugger<T>::Debugger() {
_debuggerDialog = new GUI::ConsoleDialog(1.0, 0.67F);
_debuggerDialog->setInputCallback(debuggerInputCallback, this);
_debuggerDialog->setCompletionCallback(debuggerCompletionCallback, this);
+
+ DCmd_Register("debugflag_list", &Debugger<T>::Cmd_DebugFlagsList);
+ DCmd_Register("debugflag_enable", &Debugger<T>::Cmd_DebugFlagEnable);
+ DCmd_Register("debugflag_disable", &Debugger<T>::Cmd_DebugFlagDisable);
}
template <class T>
@@ -340,6 +344,51 @@ void Debugger<T>::DCmd_Register(const char *cmdname, DebugProc pointer) {
_dcmd_count++;
}
+template <class T>
+bool Debugger<T>::Cmd_DebugFlagsList(int argc, const char **argv) {
+ const Common::Array<Common::EngineDebugLevel> &debugLevels = Common::listSpecialDebugLevels();
+
+ DebugPrintf("Engine debug levels:\n");
+ DebugPrintf("--------------------\n");
+ if (!debugLevels.size()) {
+ DebugPrintf("No engine debug levels\n");
+ return true;
+ }
+ for (uint i = 0; i < debugLevels.size(); ++i) {
+ DebugPrintf("'%s' - Description: %s\n", debugLevels[i].option.c_str(), debugLevels[i].description.c_str());
+ }
+ DebugPrintf("\n");
+ return true;
+}
+
+template <class T>
+bool Debugger<T>::Cmd_DebugFlagEnable(int argc, const char **argv) {
+ if (argc < 2) {
+ DebugPrintf("debugflag_enable <flag>\n");
+ } else {
+ if (Common::enableSpecialDebugLevel(argv[1])) {
+ DebugPrintf("Enabled debug flag '%s'\n", argv[1]);
+ } else {
+ DebugPrintf("Failed to enable debug flag '%s'\n", argv[1]);
+ }
+ }
+ return true;
+}
+
+template <class T>
+bool Debugger<T>::Cmd_DebugFlagDisable(int argc, const char **argv) {
+ if (argc < 2) {
+ DebugPrintf("debugflag_disable <flag>\n");
+ } else {
+ if (Common::disableSpecialDebugLevel(argv[1])) {
+ DebugPrintf("Disabled debug flag '%s'\n", argv[1]);
+ } else {
+ DebugPrintf("Failed to disable debug flag '%s'\n", argv[1]);
+ }
+ }
+ return true;
+}
+
// Console handler
#if USE_CONSOLE
template <class T>
diff --git a/common/debugger.h b/common/debugger.h
index b850ec3c21..25ddff8ac2 100644
--- a/common/debugger.h
+++ b/common/debugger.h
@@ -95,6 +95,10 @@ protected:
void DVar_Register(const char *varname, void *pointer, int type, int optional);
void DCmd_Register(const char *cmdname, DebugProc pointer);
+ bool Cmd_DebugFlagsList(int argc, const char **argv);
+ bool Cmd_DebugFlagEnable(int argc, const char **argv);
+ bool Cmd_DebugFlagDisable(int argc, const char **argv);
+
#if USE_CONSOLE
static bool debuggerInputCallback(GUI::ConsoleDialog *console, const char *input, void *refCon);
static bool debuggerCompletionCallback(GUI::ConsoleDialog *console, const char *input, char*& completion, void *refCon);
diff --git a/common/util.cpp b/common/util.cpp
index d98d8eb275..0502b562f2 100644
--- a/common/util.cpp
+++ b/common/util.cpp
@@ -275,5 +275,82 @@ const char *getRenderModeDescription(RenderMode id) {
return 0;
}
+#pragma mark -
+
+Array<EngineDebugLevel> gDebugLevels;
+uint32 gDebugLevelsEnabled = 0;
+
+bool addSpecialDebugLevel(uint32 level, const String &option, const String &description) {
+ for (uint i = 0; i < gDebugLevels.size(); ++i) {
+ if (!scumm_stricmp(option.c_str(), gDebugLevels[i].option.c_str())) {
+ warning("Declared engine debug level '%s' again", option.c_str());
+ gDebugLevels[i] = EngineDebugLevel(level, option, description);
+ return true;
+ }
+ }
+ gDebugLevels.push_back(EngineDebugLevel(level, option, description));
+ return true;
+}
+
+void clearAllSpecialDebugLevels() {
+ gDebugLevelsEnabled = 0;
+ gDebugLevels.clear();
+}
+
+bool enableSpecialDebugLevel(const String &option) {
+ for (uint i = 0; i < gDebugLevels.size(); ++i) {
+ if (!scumm_stricmp(option.c_str(), gDebugLevels[i].option.c_str())) {
+ gDebugLevelsEnabled |= gDebugLevels[i].level;
+ gDebugLevels[i].enabled = true;
+ return true;
+ }
+ }
+ return false;
+}
+
+void enableSpecialDebugLevelList(const String &option) {
+ uint start = 0;
+ uint end = 0;
+
+ const char *str = option.c_str();
+ for (end = start + 1; end <= option.size(); ++end) {
+ if (str[end] == ',' || end == option.size()) {
+ if (!enableSpecialDebugLevel(Common::String(&str[start], end-start))) {
+ warning("Engine does not support debug level '%s'", Common::String(&str[start], end-start).c_str());
+ }
+ start = end + 1;
+ }
+ }
+}
+
+bool disableSpecialDebugLevel(const String &option) {
+ for (uint i = 0; i < gDebugLevels.size(); ++i) {
+ if (!scumm_stricmp(option.c_str(), gDebugLevels[i].option.c_str())) {
+ gDebugLevelsEnabled &= ~gDebugLevels[i].level;
+ gDebugLevels[i].enabled = false;
+ return true;
+ }
+ }
+ return false;
+}
+
+const Array<EngineDebugLevel> &listSpecialDebugLevels() {
+ return gDebugLevels;
+}
} // End of namespace Common
+
+void CDECL debugC(int level, uint32 engine_level, const char *s, ...) {
+ char buf[STRINGBUFLEN];
+ va_list va;
+
+ if (level > gDebugLevel || !(Common::gDebugLevelsEnabled & engine_level))
+ return;
+
+ va_start(va, s);
+ vsnprintf(buf, STRINGBUFLEN, s, va);
+ va_end(va);
+
+ // pass it to debug for now
+ debug(level, buf);
+}
diff --git a/common/util.h b/common/util.h
index bed27ecf77..3aa202c088 100644
--- a/common/util.h
+++ b/common/util.h
@@ -23,6 +23,8 @@
#define COMMON_UTIL_H
#include "common/scummsys.h"
+#include "common/str.h"
+#include "common/array.h"
#if defined (__INNOTEK_LIBC__)
#undef MIN
@@ -46,8 +48,6 @@ template<typename T> inline void SWAP(T &a, T &b) { T tmp = a; a = b; b = tmp; }
namespace Common {
-class String;
-
/**
* Print a hexdump of the data passed in. The number of bytes per line is
* customizable.
@@ -196,6 +196,67 @@ extern RenderMode parseRenderMode(const String &str);
extern const char *getRenderModeCode(RenderMode id);
extern const char *getRenderModeDescription(RenderMode id);
+
+struct EngineDebugLevel {
+ EngineDebugLevel() : option(""), description(""), level(0), enabled(false) {}
+ EngineDebugLevel(uint32 l, const String &o, const String &d)
+ : option(o), description(d), level(l), enabled(false) {}
+ EngineDebugLevel(const EngineDebugLevel &copy)
+ : option(copy.option), description(copy.description), level(copy.level), enabled(copy.enabled) {}
+
+ EngineDebugLevel &operator =(const EngineDebugLevel &copy) {
+ option = copy.option;
+ description = copy.description;
+ level = copy.level;
+ enabled = copy.enabled;
+ return *this;
+ }
+
+ String option;
+ String description;
+
+ uint32 level;
+ bool enabled;
+};
+
+/**
+ * Adds a engine debug level.
+ * @param level the level flag (should be OR-able i.e. first one should be 1 than 2,4,...)
+ * @param option the option name which is used in the debugger/on the command line to enable
+ * this special debug level, the option will be compared case !insentiv! later
+ * @param descripton the description which shows up in the debugger
+ * @return true on success false on failure
+ */
+bool addSpecialDebugLevel(uint32 level, const String &option, const String &description);
+
+/**
+ * Resets all engine debug levels
+ */
+void clearAllSpecialDebugLevels();
+
+/**
+ * Enables a engine debug level
+ * @param option the option which should be enabled
+ * @return true on success false on failure
+ */
+bool enableSpecialDebugLevel(const String &option);
+
+// only used for parsing the levels from the commandline
+void enableSpecialDebugLevelList(const String &option);
+
+/**
+ * Disables a engine debug level
+ * @param option the option to disable
+ * @return true on success false on failure
+ */
+bool disableSpecialDebugLevel(const String &option);
+
+/**
+ * Lists all debug levels
+ * @return returns a arry with all debug levels
+ */
+const Array<EngineDebugLevel> &listSpecialDebugLevels();
+
} // End of namespace Common
@@ -213,6 +274,8 @@ void CDECL debug(const char *s, ...);
void CDECL debugN(int level, const char *s, ...);
void checkHeap();
+void CDECL debugC(int level, uint32 engine_level, const char *s, ...);
+
extern int gDebugLevel;