[Scummvm-cvs-logs] scummvm master -> e734bb5078055521e04508ce19c5766b36817300

eriktorbjorn eriktorbjorn at telia.com
Sat Aug 29 18:12:14 CEST 2015


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
7f4268dc3d DEBUGGER: Add function for printing a StringArray in columns
e734bb5078 SHERLOCK: Rework the "song" debugger command


Commit: 7f4268dc3dcf2cc6a34c605a7ddbd69d8740526e
    https://github.com/scummvm/scummvm/commit/7f4268dc3dcf2cc6a34c605a7ddbd69d8740526e
Author: Torbjörn Andersson (eriktorbjorn at users.sourceforge.net)
Date: 2015-08-29T18:08:52+02:00

Commit Message:
DEBUGGER: Add function for printing a StringArray in columns

Changed paths:
    gui/debugger.cpp
    gui/debugger.h



diff --git a/gui/debugger.cpp b/gui/debugger.cpp
index 466681e..209a787 100644
--- a/gui/debugger.cpp
+++ b/gui/debugger.cpp
@@ -87,6 +87,19 @@ Debugger::~Debugger() {
 
 
 // Initialisation Functions
+int Debugger::getCharsPerLine() {
+#ifndef USE_TEXT_CONSOLE_FOR_DEBUGGER
+	const int charsPerLine = _debuggerDialog->getCharsPerLine();
+#elif defined(USE_READLINE)
+	int charsPerLine, rows;
+	rl_get_screen_size(&rows, &charsPerLine);
+#else
+	// Can we do better?
+	const int charsPerLine = 80;
+#endif
+	return charsPerLine;
+}
+
 int Debugger::debugPrintf(const char *format, ...) {
 	va_list	argptr;
 
@@ -101,6 +114,36 @@ int Debugger::debugPrintf(const char *format, ...) {
 	return count;
 }
 
+void Debugger::debugPrintColumns(const Common::StringArray &list) {
+	uint maxLength = 0;
+	uint i, j;
+
+	for (i = 0; i < list.size(); i++) {
+		if (list[i].size() > maxLength)
+			maxLength = list[i].size();
+	}
+
+	uint charsPerLine = getCharsPerLine();
+	uint columnWidth = maxLength + 2;
+	uint columns = charsPerLine / columnWidth;
+
+	uint lines = list.size() / columns;
+
+	if (list.size() % columns)
+		lines++;
+
+
+	for (i = 0; i < lines; i++) {
+		for (j = 0; j < columns; j++) {
+			uint pos = i + j * lines;
+			if (pos < list.size()) {
+				debugPrintf("%*s", -columnWidth, list[pos].c_str());
+			}
+		}
+		debugPrintf("\n");
+	}
+}
+
 void Debugger::preEnter() {
 	g_engine->pauseEngine(true);
 }
@@ -447,15 +490,7 @@ bool Debugger::cmdExit(int argc, const char **argv) {
 // Print a list of all registered commands (and variables, if any),
 // nicely word-wrapped.
 bool Debugger::cmdHelp(int argc, const char **argv) {
-#ifndef USE_TEXT_CONSOLE_FOR_DEBUGGER
-	const int charsPerLine = _debuggerDialog->getCharsPerLine();
-#elif defined(USE_READLINE)
-	int charsPerLine, rows;
-	rl_get_screen_size(&rows, &charsPerLine);
-#else
-	// Can we do better?
-	const int charsPerLine = 80;
-#endif
+	const int charsPerLine = getCharsPerLine();
 	int width, size;
 	uint i;
 
diff --git a/gui/debugger.h b/gui/debugger.h
index ef6f900..bc9306c 100644
--- a/gui/debugger.h
+++ b/gui/debugger.h
@@ -28,6 +28,7 @@
 #include "common/hashmap.h"
 #include "common/hash-str.h"
 #include "common/array.h"
+#include "common/str-array.h"
 
 namespace GUI {
 
@@ -40,8 +41,12 @@ public:
 	Debugger();
 	virtual ~Debugger();
 
+	int getCharsPerLine();
+
 	int debugPrintf(const char *format, ...) GCC_PRINTF(2, 3);
 
+	void debugPrintColumns(const Common::StringArray &list);
+
 	/**
 	 * The onFrame() method should be invoked by the engine at regular
 	 * intervals (usually once per main loop iteration) whenever the


Commit: e734bb5078055521e04508ce19c5766b36817300
    https://github.com/scummvm/scummvm/commit/e734bb5078055521e04508ce19c5766b36817300
Author: Torbjörn Andersson (eriktorbjorn at users.sourceforge.net)
Date: 2015-08-29T18:09:54+02:00

Commit Message:
SHERLOCK: Rework the "song" debugger command

Instead of taking a room number (which didn't work in Rose Tattoo),
it now takes a song name. To see which songs are available, use the
"songs" command.

Note that this is still only works for Serrated Scalpel, since I
haven't implemented getting a list of available songs for Rose
Tattoo. I need to study the resource manager a bit first...

Changed paths:
    engines/sherlock/debugger.cpp
    engines/sherlock/debugger.h
    engines/sherlock/music.cpp
    engines/sherlock/music.h



diff --git a/engines/sherlock/debugger.cpp b/engines/sherlock/debugger.cpp
index 2813a7e..b3c64e8 100644
--- a/engines/sherlock/debugger.cpp
+++ b/engines/sherlock/debugger.cpp
@@ -29,6 +29,7 @@
 #include "audio/mixer.h"
 #include "audio/decoders/aiff.h"
 #include "audio/decoders/wave.h"
+#include "common/str-array.h"
 
 namespace Sherlock {
 
@@ -45,8 +46,9 @@ Debugger::Debugger(SherlockEngine *vm) : GUI::Debugger(), _vm(vm) {
 	registerCmd("continue",	     WRAP_METHOD(Debugger, cmdExit));
 	registerCmd("scene",         WRAP_METHOD(Debugger, cmdScene));
 	registerCmd("song",          WRAP_METHOD(Debugger, cmdSong));
+	registerCmd("songs",         WRAP_METHOD(Debugger, cmdListSongs));
 	registerCmd("dumpfile",      WRAP_METHOD(Debugger, cmdDumpFile));
-	registerCmd("locations",	 WRAP_METHOD(Debugger, cmdLocations));
+	registerCmd("locations",     WRAP_METHOD(Debugger, cmdLocations));
 }
 
 void Debugger::postEnter() {
@@ -87,15 +89,29 @@ bool Debugger::cmdScene(int argc, const char **argv) {
 
 bool Debugger::cmdSong(int argc, const char **argv) {
 	if (argc != 2) {
-		debugPrintf("Format: song <room>\n");
+		debugPrintf("Format: song <name>\n");
 		return true;
 	}
 
-	if (!_vm->_music->loadSong(strToInt(argv[1]))) {
-		debugPrintf("Invalid song number.\n");
-		return true;
+	Common::StringArray songs;
+	_vm->_music->getSongNames(songs);
+
+	for (uint i = 0; i < songs.size(); i++) {
+		if (songs[i].equalsIgnoreCase(argv[1])) {
+			_vm->_music->loadSong(songs[i]);
+			return false;
+		}
 	}
-	return false;
+
+	debugPrintf("Invalid song. Use the 'songs' command to see which ones are available.\n");
+	return true;
+}
+
+bool Debugger::cmdListSongs(int argc, const char **argv) {
+	Common::StringArray songs;
+	_vm->_music->getSongNames(songs);
+	debugPrintColumns(songs);
+	return true;
 }
 
 bool Debugger::cmdDumpFile(int argc, const char **argv) {
diff --git a/engines/sherlock/debugger.h b/engines/sherlock/debugger.h
index abc8ef0..622098c 100644
--- a/engines/sherlock/debugger.h
+++ b/engines/sherlock/debugger.h
@@ -50,6 +50,11 @@ private:
 	bool cmdSong(int argc, const char **argv);
 
 	/**
+	 * Lists all available songs
+	 */
+	bool cmdListSongs(int argc, const char **argv);
+
+	/**
 	 * Dumps a file to disk
 	 */
 	bool cmdDumpFile(int argc, const char **argv);
diff --git a/engines/sherlock/music.cpp b/engines/sherlock/music.cpp
index 99f7b45..10796e4 100644
--- a/engines/sherlock/music.cpp
+++ b/engines/sherlock/music.cpp
@@ -20,6 +20,7 @@
  *
  */
 
+#include "common/algorithm.h"
 #include "common/config-manager.h"
 #include "common/mutex.h"
 #include "sherlock/sherlock.h"
@@ -579,4 +580,14 @@ void Music::setMusicVolume(int volume) {
 	_vm->_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, volume);
 }
 
+void Music::getSongNames(Common::StringArray &songs) {
+	songs.clear();
+	if (IS_SERRATED_SCALPEL) {
+		for (int i = 0; i < ARRAYSIZE(SONG_NAMES); i++) {
+			songs.push_back(SONG_NAMES[i]);
+		}
+	}
+	Common::sort(songs.begin(), songs.end());
+}
+
 } // End of namespace Sherlock
diff --git a/engines/sherlock/music.h b/engines/sherlock/music.h
index ca203da..afd3a42 100644
--- a/engines/sherlock/music.h
+++ b/engines/sherlock/music.h
@@ -31,6 +31,7 @@
 #include "audio/audiostream.h"
 #include "audio/mixer.h"
 #include "common/mutex.h"
+#include "common/str-array.h"
 
 namespace Sherlock {
 
@@ -121,9 +122,13 @@ public:
 	 * Sets the volume of the MIDI music with a value ranging from 0 to 127
 	 */
 	void setMusicVolume(int volume);
+
+	/**
+	 * Gets the names of all the songs in the game. Used by the debugger.
+	 */
+	void getSongNames(Common::StringArray &songs);
 };
 
 } // End of namespace Sherlock
 
 #endif
-






More information about the Scummvm-git-logs mailing list