[Scummvm-cvs-logs] SF.net SVN: scummvm:[36139] scummvm/trunk

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Fri Jan 30 05:42:30 CET 2009


Revision: 36139
          http://scummvm.svn.sourceforge.net/scummvm/?rev=36139&view=rev
Author:   fingolfin
Date:     2009-01-30 04:42:30 +0000 (Fri, 30 Jan 2009)

Log Message:
-----------
Some work on the 'special debug levels' aka 'engine debug levels' code

Modified Paths:
--------------
    scummvm/trunk/common/debug.cpp
    scummvm/trunk/common/debug.h
    scummvm/trunk/engines/groovie/script.cpp
    scummvm/trunk/engines/groovie/vdx.cpp
    scummvm/trunk/engines/scumm/debugger.cpp
    scummvm/trunk/gui/debugger.cpp

Modified: scummvm/trunk/common/debug.cpp
===================================================================
--- scummvm/trunk/common/debug.cpp	2009-01-30 04:41:57 UTC (rev 36138)
+++ scummvm/trunk/common/debug.cpp	2009-01-30 04:42:30 UTC (rev 36139)
@@ -57,35 +57,35 @@
 
 namespace {
 
-DebugLevelContainer gDebugLevels;
+SpecialDebugLevelList gDebugLevels;
 uint32 gDebugLevelsEnabled = 0;
 
 struct DebugLevelSort {
-	bool operator()(const EngineDebugLevel &l, const EngineDebugLevel &r) {
-		return (l.option.compareToIgnoreCase(r.option) < 0);
+	bool operator()(const SpecialDebugLevel &l, const SpecialDebugLevel &r) {
+		return (l.name.compareToIgnoreCase(r.name) < 0);
 	}
 };
 
 struct DebugLevelSearch {
-	const String &_option;
+	const String &_name;
 
-	DebugLevelSearch(const String &option) : _option(option) {}
+	DebugLevelSearch(const String &name) : _name(name) {}
 
-	bool operator()(const EngineDebugLevel &l) {
-		return _option.equalsIgnoreCase(l.option);
+	bool operator()(const SpecialDebugLevel &l) {
+		return _name.equalsIgnoreCase(l.name);
 	}
 };
 
 }
 
-bool addSpecialDebugLevel(uint32 level, const String &option, const String &description) {
-	DebugLevelContainer::iterator i = find_if(gDebugLevels.begin(), gDebugLevels.end(), DebugLevelSearch(option));
+bool addSpecialDebugLevel(uint32 level, const String &name, const String &description) {
+	SpecialDebugLevelList::iterator i = find_if(gDebugLevels.begin(), gDebugLevels.end(), DebugLevelSearch(name));
 
 	if (i != gDebugLevels.end()) {
-		warning("Declared engine debug level '%s' again", option.c_str());
-		*i = EngineDebugLevel(level, option, description);
+		warning("Declared engine debug level '%s' again", name.c_str());
+		*i = SpecialDebugLevel(level, name, description);
 	} else {
-		gDebugLevels.push_back(EngineDebugLevel(level, option, description));
+		gDebugLevels.push_back(SpecialDebugLevel(level, name, description));
 		sort(gDebugLevels.begin(), gDebugLevels.end(), DebugLevelSort());
 	}
 
@@ -97,8 +97,8 @@
 	gDebugLevels.clear();
 }
 
-bool enableSpecialDebugLevel(const String &option) {
-	DebugLevelContainer::iterator i = find_if(gDebugLevels.begin(), gDebugLevels.end(), DebugLevelSearch(option));
+bool enableSpecialDebugLevel(const String &name) {
+	SpecialDebugLevelList::iterator i = find_if(gDebugLevels.begin(), gDebugLevels.end(), DebugLevelSearch(name));
 
 	if (i != gDebugLevels.end()) {
 		gDebugLevelsEnabled |= i->level;
@@ -110,8 +110,8 @@
 	}
 }
 
-void enableSpecialDebugLevelList(const String &option) {
-	StringTokenizer tokenizer(option, " ,");
+void enableSpecialDebugLevelList(const String &names) {
+	StringTokenizer tokenizer(names, " ,");
 	String token;
 
 	while (!tokenizer.empty()) {
@@ -122,7 +122,7 @@
 }
 
 bool disableSpecialDebugLevel(const String &option) {
-	DebugLevelContainer::iterator i = find_if(gDebugLevels.begin(), gDebugLevels.end(), DebugLevelSearch(option));
+	SpecialDebugLevelList::iterator i = find_if(gDebugLevels.begin(), gDebugLevels.end(), DebugLevelSearch(option));
 
 	if (i != gDebugLevels.end()) {
 		gDebugLevelsEnabled &= ~i->level;
@@ -134,7 +134,7 @@
 	}
 }
 
-const DebugLevelContainer &listSpecialDebugLevels() {
+const SpecialDebugLevelList &listSpecialDebugLevels() {
 	return gDebugLevels;
 }
 
@@ -142,6 +142,27 @@
 	return gDebugLevelsEnabled;
 }
 
+bool isSpecialDebugLevelEnabled(uint32 level) {
+	// FIXME: Seems gDebugLevel 11 has a special meaning? Document that!
+	if (gDebugLevel == 11)
+		return true;
+//	return gDebugLevelsEnabled & (1 << level);
+	return gDebugLevelsEnabled & level;
+}
+
+bool isSpecialDebugLevelEnabled(const String &name) {
+	// FIXME: Seems gDebugLevel 11 has a special meaning? Document that!
+	if (gDebugLevel == 11)
+		return true;
+
+	// Search for the debug level with the given name and check if it is enabled
+	SpecialDebugLevelList::iterator i = find_if(gDebugLevels.begin(), gDebugLevels.end(), DebugLevelSearch(name));
+	if (i != gDebugLevels.end())
+		return gDebugLevelsEnabled & i->level;
+	return false;
+}
+
+
 }	// End of namespace Common
 
 
@@ -217,6 +238,7 @@
 void debugC(int level, uint32 engine_level, const char *s, ...) {
 	va_list va;
 
+	// FIXME: Seems gDebugLevel 11 has a special meaning? Document that!
 	if (gDebugLevel != 11)
 		if (level > gDebugLevel || !(Common::gDebugLevelsEnabled & engine_level))
 			return;

Modified: scummvm/trunk/common/debug.h
===================================================================
--- scummvm/trunk/common/debug.h	2009-01-30 04:41:57 UTC (rev 36138)
+++ scummvm/trunk/common/debug.h	2009-01-30 04:42:30 UTC (rev 36139)
@@ -33,12 +33,12 @@
 namespace Common {
 
 
-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) {}
+struct SpecialDebugLevel {
+	SpecialDebugLevel() : level(0), enabled(false) {}
+	SpecialDebugLevel(uint32 l, const String &n, const String &d)
+		: name(n), description(d), level(l), enabled(false) {}
 
-	String option;
+	String name;
 	String description;
 
 	uint32 level;
@@ -48,42 +48,46 @@
 /**
  * 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
+ * @param name 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 description 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);
+bool addSpecialDebugLevel(uint32 level, const String &name, const String &description);
 
 /**
- * Resets all engine debug levels
+ * 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
+ * Enables an engine debug level.
+ * @param name the name of the debug level to enable
+ * @return true on success, false on failure
  */
-bool enableSpecialDebugLevel(const String &option);
+bool enableSpecialDebugLevel(const String &name);
 
-// only used for parsing the levels from the commandline
-void enableSpecialDebugLevelList(const String &option);
+/**
+ * Enables a list of engine debug levels, given as a comma-separated list
+ * of level names.
+ * @param name the list of names of debug levels to enable
+ */
+void enableSpecialDebugLevelList(const String &names);
 
 /**
- * Disables a engine debug level
- * @param option the option to disable
- * @return true on success false on failure
+ * Disables an engine debug level
+ * @param name the name of the debug level to disable
+ * @return true on success, false on failure
  */
-bool disableSpecialDebugLevel(const String &option);
+bool disableSpecialDebugLevel(const String &name);
 
-typedef List<EngineDebugLevel> DebugLevelContainer;
+typedef List<SpecialDebugLevel> SpecialDebugLevelList;
 
 /**
  * Lists all debug levels
  * @return returns a arry with all debug levels
  */
-const DebugLevelContainer &listSpecialDebugLevels();
+const SpecialDebugLevelList &listSpecialDebugLevels();
 
 /**
  * Return the active debug flag mask (i.e. all active debug flags ORed
@@ -92,6 +96,17 @@
 uint32 getEnabledSpecialDebugLevels();
 
 
+/**
+ * Test whether the given debug level is enabled.
+ */
+bool isSpecialDebugLevelEnabled(uint32 level);
+
+/**
+ * Test whether the given debug level is enabled.
+ */
+bool isSpecialDebugLevelEnabled(const String &name);
+
+
 }	// End of namespace Common
 
 

Modified: scummvm/trunk/engines/groovie/script.cpp
===================================================================
--- scummvm/trunk/engines/groovie/script.cpp	2009-01-30 04:41:57 UTC (rev 36138)
+++ scummvm/trunk/engines/groovie/script.cpp	2009-01-30 04:42:30 UTC (rev 36139)
@@ -42,12 +42,9 @@
 	char buf[STRINGBUFLEN];
 	va_list va;
 
-	uint32 engine_level = kGroovieDebugScript | kGroovieDebugAll;
+	if (!Common::isSpecialDebugLevelEnabled(kGroovieDebugScript | kGroovieDebugAll))
+		return;
 
-	if (gDebugLevel != 11)
-		if (!(Common::getEnabledSpecialDebugLevels() & engine_level))
-			return;
-
 	va_start(va, s);
 	vsnprintf(buf, STRINGBUFLEN, s, va);
 	va_end(va);

Modified: scummvm/trunk/engines/groovie/vdx.cpp
===================================================================
--- scummvm/trunk/engines/groovie/vdx.cpp	2009-01-30 04:41:57 UTC (rev 36138)
+++ scummvm/trunk/engines/groovie/vdx.cpp	2009-01-30 04:42:30 UTC (rev 36139)
@@ -49,8 +49,7 @@
 }
 
 uint16 VDXPlayer::loadInternal() {
-	uint32 engine_level = kGroovieDebugVideo | kGroovieDebugAll;
-	if ((gDebugLevel == 11) || (Common::getEnabledSpecialDebugLevels() & engine_level)) {
+	if (Common::isSpecialDebugLevelEnabled(kGroovieDebugVideo | kGroovieDebugAll)) {
 		int8 i;
 		debugN(1, "Groovie::VDX: New VDX: bitflags are ");
 		for (i = 15; i >= 0; i--) {

Modified: scummvm/trunk/engines/scumm/debugger.cpp
===================================================================
--- scummvm/trunk/engines/scumm/debugger.cpp	2009-01-30 04:41:57 UTC (rev 36138)
+++ scummvm/trunk/engines/scumm/debugger.cpp	2009-01-30 04:42:30 UTC (rev 36139)
@@ -498,59 +498,35 @@
 }
 
 bool ScummDebugger::Cmd_Debug(int argc, const char **argv) {
-	const Common::DebugLevelContainer &lvls = Common::listSpecialDebugLevels();
+	const Common::SpecialDebugLevelList &lvls = Common::listSpecialDebugLevels();
 
-	bool setFlag = false;	// Remove or add debug channel?
-
-	if ((argc == 1) && (Common::getEnabledSpecialDebugLevels() == 0)) {
-		DebugPrintf("No debug flags are enabled\n");
-		DebugPrintf("Available Channels: ");
-		for (Common::DebugLevelContainer::iterator i = lvls.begin(); i != lvls.end(); ++i) {
-			DebugPrintf("%s, ", i->option.c_str());
+	// No parameters given: Print out a list of all channels and their status
+	if (argc <= 1) {
+		DebugPrintf("Available debug channels: ");
+		for (Common::SpecialDebugLevelList::iterator i = lvls.begin(); i != lvls.end(); ++i) {
+			DebugPrintf("%c%s - %s (%s)\n", i->enabled ? '+' : ' ',
+					i->name.c_str(), i->description.c_str(),
+					i->enabled ? "enabled" : "disabled");
 		}
-		DebugPrintf("\n");
 		return true;
 	}
 
-	if ((argc == 1) && (Common::getEnabledSpecialDebugLevels() > 0)) {
-		for (Common::DebugLevelContainer::iterator i = lvls.begin(); i != lvls.end(); ++i) {
-			if (i->enabled)
-				DebugPrintf("%s - %s\n", i->option.c_str(), i->description.c_str());
-		}
-		return true;
-	}
-
 	// Enable or disable channel?
+	bool result = false;
 	if (argv[1][0] == '+') {
-		setFlag = true;
+		result = Common::enableSpecialDebugLevel(argv[1] + 1);
 	} else if (argv[1][0] == '-') {
-		setFlag = false;
+		result = Common::disableSpecialDebugLevel(argv[1] + 1);
+	}
+	
+	if (result) {
+		DebugPrintf("%s %s\n", (argv[1][0] == '+') ? "Enabled" : "Disabled", argv[1] + 1);
 	} else {
-		DebugPrintf("Syntax: Debug +CHANNEL, or Debug -CHANNEL\n");
-		DebugPrintf("Available Channels: ");
-		for (Common::DebugLevelContainer::iterator i = lvls.begin(); i != lvls.end(); ++i) {
-			DebugPrintf("%s\n", i->option.c_str());
-		}
+		DebugPrintf("Usage: debug [+CHANNEL|-CHANNEL]\n");
+		DebugPrintf("Enables or disables the given debug channel.\n");
+		DebugPrintf("When used without parameters, lists all avaiable debug channels and their status.\n");
 	}
 
-	// Identify flag
-	const char *realFlag = argv[1] + 1;
-	for (Common::DebugLevelContainer::iterator i = lvls.begin(); i != lvls.end(); ++i) {
-		if (i->option.equalsIgnoreCase(realFlag)) {
-			if (setFlag) {
-				enableSpecialDebugLevel(i->option);
-				DebugPrintf("Enable ");
-			} else {
-				disableSpecialDebugLevel(i->option);
-				DebugPrintf("Disable ");
-			}
-
-			DebugPrintf("%s\n", i->description.c_str());
-			return true;
-		}
-	}
-
-	DebugPrintf("Unknown flag. Type 'Debug ?' for syntax\n");
 	return true;
 }
 

Modified: scummvm/trunk/gui/debugger.cpp
===================================================================
--- scummvm/trunk/gui/debugger.cpp	2009-01-30 04:41:57 UTC (rev 36138)
+++ scummvm/trunk/gui/debugger.cpp	2009-01-30 04:42:30 UTC (rev 36139)
@@ -406,7 +406,7 @@
 }
 
 bool Debugger::Cmd_DebugFlagsList(int argc, const char **argv) {
-	const Common::DebugLevelContainer &debugLevels = Common::listSpecialDebugLevels();
+	const Common::SpecialDebugLevelList &debugLevels = Common::listSpecialDebugLevels();
 
 	DebugPrintf("Engine debug levels:\n");
 	DebugPrintf("--------------------\n");
@@ -414,8 +414,10 @@
 		DebugPrintf("No engine debug levels\n");
 		return true;
 	}
-	for (Common::DebugLevelContainer::const_iterator i = debugLevels.begin(); i != debugLevels.end(); ++i) {
-		DebugPrintf("'%s' - Description: %s\n", i->option.c_str(), i->description.c_str());
+	for (Common::SpecialDebugLevelList::const_iterator i = debugLevels.begin(); i != debugLevels.end(); ++i) {
+		DebugPrintf("%c%s - %s (%s)\n", i->enabled ? '+' : ' ',
+				i->name.c_str(), i->description.c_str(),
+				i->enabled ? "enabled" : "disabled");
 	}
 	DebugPrintf("\n");
 	return true;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list