[Scummvm-git-logs] scummvm master -> eb47ab4a5ba313ff901e94e79b2211fa5829f8fd

criezy criezy at scummvm.org
Mon Mar 15 00:57:22 UTC 2021


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

Summary:
8de62d8182 AGS: Add custom debug console commands
aaa1bb151a IMAGE: Allow writing PNG from 8 bit surfaces
eb47ab4a5b AGS: Add debug commands to get sprite info and dump sprite


Commit: 8de62d8182da0fdce85bed470a816ca378ada992
    https://github.com/scummvm/scummvm/commit/8de62d8182da0fdce85bed470a816ca378ada992
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2021-03-15T00:56:01Z

Commit Message:
AGS: Add custom debug console commands

Currently two commands are supported, one to list the AGS
DebugManager group verbosity levels, and one to change
those. This allows to enable and disable debug output.

Changed paths:
  A engines/ags/console.cpp
  A engines/ags/console.h
    engines/ags/ags.cpp
    engines/ags/module.mk


diff --git a/engines/ags/ags.cpp b/engines/ags/ags.cpp
index ff5f313301..4c24caaaec 100644
--- a/engines/ags/ags.cpp
+++ b/engines/ags/ags.cpp
@@ -25,6 +25,7 @@
 #include "ags/events.h"
 #include "ags/game_scanner.h"
 #include "ags/music.h"
+#include "ags/console.h"
 #include "common/scummsys.h"
 #include "common/config-manager.h"
 #include "common/debug-channels.h"
@@ -121,6 +122,8 @@ Common::Error AGSEngine::run() {
 	return Common::kNoError;
 #endif
 
+	setDebugger(new AGSConsole(this));
+
 	const char *filename = _gameDescription->desc.filesDescriptions[0].fileName;
 	const char *ARGV[] = { "scummvm.exe", filename };
 	const int ARGC = 2;
diff --git a/engines/ags/console.cpp b/engines/ags/console.cpp
new file mode 100644
index 0000000000..d4495c45c8
--- /dev/null
+++ b/engines/ags/console.cpp
@@ -0,0 +1,199 @@
+/* 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 2
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "ags/console.h"
+#include "ags/ags.h"
+#include "ags/globals.h"
+
+namespace AGS {
+
+AGSConsole::AGSConsole(AGSEngine *vm) : GUI::Debugger(), _vm(vm), _logOutputTarget(nullptr), _agsDebuggerOutput(nullptr) {
+	registerCmd("ags_debug_groups_list",   WRAP_METHOD(AGSConsole, Cmd_listDebugGroups));
+	registerCmd("ags_debug_groups_set",  WRAP_METHOD(AGSConsole, Cmd_setDebugGroupLevel));
+	
+	_logOutputTarget = new LogOutputTarget();
+	_agsDebuggerOutput = _GP(DbgMgr).RegisterOutput("ScummVMLog", _logOutputTarget, AGS3::AGS::Shared::kDbgMsg_None);
+}
+
+AGSConsole::~AGSConsole() {
+	delete _logOutputTarget;
+}
+
+struct LevelName {
+	const char *name;
+	AGS3::AGS::Shared::MessageType level;
+};
+
+static const LevelName levelNames[] = {
+	{"none", AGS3::AGS::Shared::kDbgMsg_None},
+	{"alerts", AGS3::AGS::Shared::kDbgMsg_Alert},
+	{"fatal", AGS3::AGS::Shared::kDbgMsg_Fatal},
+	{"errors", AGS3::AGS::Shared::kDbgMsg_Error},
+	{"warnings", AGS3::AGS::Shared::kDbgMsg_None},
+	{"info", AGS3::AGS::Shared::kDbgMsg_Info},
+	{"debug", AGS3::AGS::Shared::kDbgMsg_Debug},
+	{nullptr, AGS3::AGS::Shared::kDbgMsg_None}
+};
+
+struct GroupName{
+	const char* name;
+	uint32_t group;
+};
+
+static const GroupName groupNames[] = {
+	{"Main", AGS3::AGS::Shared::kDbgGroup_Main},
+	{"Game", AGS3::AGS::Shared::kDbgGroup_Game},
+	{"Script", AGS3::AGS::Shared::kDbgGroup_Script},
+	{"SpriteCache", AGS3::AGS::Shared::kDbgGroup_SprCache},
+	{"ManObj", AGS3::AGS::Shared::kDbgGroup_ManObj},
+	{nullptr, (uint32_t)-1}
+};
+
+bool AGSConsole::Cmd_listDebugGroups(int argc, const char **argv) {
+	if (argc != 1) {
+		debugPrintf("Usage: %s\n", argv[0]);
+		return true;
+	}
+
+	debugPrintf("%-16s %-16s\n", "Name", "Level");
+	for (int i = 0 ; groupNames[i].name != nullptr ; ++i)
+		debugPrintf("%-16s %-16s\n", groupNames[i].name, getVerbosityLevel(groupNames[i].group));
+	return true;
+}
+
+bool AGSConsole::Cmd_setDebugGroupLevel(int argc, const char **argv) {
+	if (argc != 3) {
+		debugPrintf("Usage: %s group level\n", argv[0]);
+		debugPrintf("   valid groups: ");
+		printGroupList();
+		debugPrintf("\n");
+		debugPrintf("   valid levels: ");
+		printLevelList();
+		debugPrintf("\n");
+		return true;
+	}
+
+	bool found = false;
+	uint32_t group = parseGroup(argv[1], found);
+	if (!found) {
+		debugPrintf("Unknown debug group '%s'\n", argv[1]);
+		debugPrintf("Valid groups are: ");
+		printGroupList();
+		debugPrintf("\n");
+		return true;
+	}
+
+	AGS3::AGS::Shared::MessageType level = parseLevel(argv[2], found);
+	if (!found) {
+		debugPrintf("Unknown level '%s'\n", argv[2]);
+		debugPrintf("Valid levels are: ");
+		printLevelList();
+		debugPrintf("\n");
+		return true;
+	}
+	
+	_agsDebuggerOutput->SetGroupFilter(group, level);
+	return true;
+}
+
+const char *AGSConsole::getVerbosityLevel(uint32_t groupID) const {
+	int i = 1;
+	while (levelNames[i].name != nullptr) {
+		if (!_agsDebuggerOutput->TestGroup(groupID, levelNames[i].level))
+			break;
+		++i;
+	}
+	return levelNames[i - 1].name;
+}
+
+uint32_t AGSConsole::parseGroup(const char *name, bool &found) const {
+	int i = 0;
+	while (groupNames[i].name != nullptr) {
+		if (scumm_stricmp(name, groupNames[i].name) == 0) {
+			found = true;
+			return groupNames[i].group;
+		}
+		++i;
+	}
+
+	found = false;
+	return (uint32_t)-1;
+}
+
+AGS3::AGS::Shared::MessageType AGSConsole::parseLevel(const char *name, bool &found) const {
+	int i = 0;
+	while (levelNames[i].name != nullptr) {
+		if (scumm_stricmp(name, levelNames[i].name) == 0) {
+			found = true;
+			return levelNames[i].level;
+		}
+		++i;
+	}
+
+	found = false;
+	return AGS3::AGS::Shared::kDbgMsg_None;
+}
+
+void AGSConsole::printGroupList() {
+	debugPrintf("%s", groupNames[0].name);
+	for (int i = 1 ; groupNames[i].name != nullptr ; ++i)
+		debugPrintf(", %s", groupNames[i].name);
+}
+
+void AGSConsole::printLevelList() {
+	debugPrintf("%s", levelNames[0].name);
+	for (int i = 1 ; levelNames[i].name != nullptr ; ++i)
+		debugPrintf(", %s", levelNames[i].name);
+}
+
+LogOutputTarget::LogOutputTarget() {
+}
+
+LogOutputTarget::~LogOutputTarget() {
+}
+
+void LogOutputTarget::PrintMessage(const AGS3::AGS::Shared::DebugMessage &msg) {
+	LogMessageType::Type msgType = LogMessageType::kInfo;
+	switch (msg.MT) {
+	case AGS3::AGS::Shared::kDbgMsg_None:
+		return;
+	case AGS3::AGS::Shared::kDbgMsg_Alert:
+	case AGS3::AGS::Shared::kDbgMsg_Fatal:
+	case AGS3::AGS::Shared::kDbgMsg_Error:
+		msgType = LogMessageType::kError;
+		break;
+	case AGS3::AGS::Shared::kDbgMsg_Warn:
+		msgType = LogMessageType::kWarning;
+		break;
+	case AGS3::AGS::Shared::kDbgMsg_Info:
+		msgType = LogMessageType::kInfo;
+		break;
+	case AGS3::AGS::Shared::kDbgMsg_Debug:
+		msgType = LogMessageType::kDebug;
+		break;
+	}
+	Common::String text = Common::String::format("%s\n", msg.Text.GetCStr());
+	g_system->logMessage(msgType, text.c_str());
+}
+
+
+} // End of namespace CGE
diff --git a/engines/ags/console.h b/engines/ags/console.h
new file mode 100644
index 0000000000..0ce70a9c55
--- /dev/null
+++ b/engines/ags/console.h
@@ -0,0 +1,66 @@
+
+/* 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 2
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef AGS_CONSOLE_H
+#define AGS_CONSOLE_H
+
+#include "gui/debugger.h"
+#include "ags/shared/debugging/debugmanager.h"
+#include "ags/shared/debugging/outputhandler.h"
+
+namespace AGS {
+
+class AGSEngine;
+class LogOutputTarget;
+
+class AGSConsole : public GUI::Debugger {
+public:
+	AGSConsole(AGSEngine *vm);
+	~AGSConsole() override;
+
+private:
+	AGSEngine *_vm;
+	LogOutputTarget *_logOutputTarget;
+	AGS3::AGS::Shared::PDebugOutput _agsDebuggerOutput;
+
+	bool Cmd_listDebugGroups(int argc, const char **argv);
+	bool Cmd_setDebugGroupLevel(int argc, const char **argv);
+	
+	const char *getVerbosityLevel(uint32_t groupID) const;
+	uint32_t parseGroup(const char *, bool &) const;
+	AGS3::AGS::Shared::MessageType parseLevel(const char *, bool &) const;
+	void printGroupList();
+	void printLevelList();
+};
+
+class LogOutputTarget : public AGS3::AGS::Shared::IOutputHandler {
+public:
+	LogOutputTarget();
+	virtual ~LogOutputTarget() override;
+
+	void PrintMessage(const AGS3::AGS::Shared::DebugMessage &msg) override;
+};
+
+} // End of namespace CGE
+
+#endif
diff --git a/engines/ags/module.mk b/engines/ags/module.mk
index b6375cb7cc..1f7f88cd2b 100644
--- a/engines/ags/module.mk
+++ b/engines/ags/module.mk
@@ -7,6 +7,7 @@ MODULE_OBJS = \
 	globals.o \
 	metaengine.o \
 	music.o \
+	console.o \
 	lib/aastr-0.1.1/aarot.o \
 	lib/aastr-0.1.1/aastr.o \
 	lib/aastr-0.1.1/aautil.o \


Commit: aaa1bb151a5e2348870749995af314b3a0514d8d
    https://github.com/scummvm/scummvm/commit/aaa1bb151a5e2348870749995af314b3a0514d8d
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2021-03-15T00:56:01Z

Commit Message:
IMAGE: Allow writing PNG from 8 bit surfaces

Changed paths:
    image/png.cpp
    image/png.h


diff --git a/image/png.cpp b/image/png.cpp
index 734f2b0be3..d389908d00 100644
--- a/image/png.cpp
+++ b/image/png.cpp
@@ -299,7 +299,7 @@ bool PNGDecoder::loadStream(Common::SeekableReadStream &stream) {
 #endif
 }
 
-bool writePNG(Common::WriteStream &out, const Graphics::Surface &input) {
+bool writePNG(Common::WriteStream &out, const Graphics::Surface &input, const byte *palette) {
 #ifdef USE_PNG
 #ifdef SCUMM_LITTLE_ENDIAN
 	const Graphics::PixelFormat requiredFormat_3byte(3, 8, 8, 8, 0, 0, 8, 16, 0);
@@ -320,7 +320,7 @@ bool writePNG(Common::WriteStream &out, const Graphics::Surface &input) {
 		if (input.format == requiredFormat_4byte) {
 			surface = &input;
 		} else {
-			surface = tmp = input.convertTo(requiredFormat_4byte);
+			surface = tmp = input.convertTo(requiredFormat_4byte, palette);
 		}
 		colorType = PNG_COLOR_TYPE_RGB_ALPHA;
 	}
diff --git a/image/png.h b/image/png.h
index 0ab4b99bdf..65ed9ece0a 100644
--- a/image/png.h
+++ b/image/png.h
@@ -84,8 +84,12 @@ private:
 
 /**
  * Outputs a compressed PNG stream of the given input surface.
+  *
+ *  @param out  Stream to which to write the PNG image.
+ *  @param input The surface to save as a PNG image..
+ *  @param palette    The palette (in RGB888), if the source format has a bpp of 1.
  */
-bool writePNG(Common::WriteStream &out, const Graphics::Surface &input);
+bool writePNG(Common::WriteStream &out, const Graphics::Surface &input, const byte *palette = nullptr);
 /** @} */
 } // End of namespace Image
 


Commit: eb47ab4a5ba313ff901e94e79b2211fa5829f8fd
    https://github.com/scummvm/scummvm/commit/eb47ab4a5ba313ff901e94e79b2211fa5829f8fd
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2021-03-15T00:56:01Z

Commit Message:
AGS: Add debug commands to get sprite info and dump sprite

Changed paths:
    engines/ags/console.cpp
    engines/ags/console.h


diff --git a/engines/ags/console.cpp b/engines/ags/console.cpp
index d4495c45c8..6943b2c928 100644
--- a/engines/ags/console.cpp
+++ b/engines/ags/console.cpp
@@ -23,13 +23,18 @@
 #include "ags/console.h"
 #include "ags/ags.h"
 #include "ags/globals.h"
+#include "ags/shared/ac/spritecache.h"
+#include "ags/shared/gfx/allegrobitmap.h"
+#include "image/png.h"
 
 namespace AGS {
 
 AGSConsole::AGSConsole(AGSEngine *vm) : GUI::Debugger(), _vm(vm), _logOutputTarget(nullptr), _agsDebuggerOutput(nullptr) {
 	registerCmd("ags_debug_groups_list",   WRAP_METHOD(AGSConsole, Cmd_listDebugGroups));
 	registerCmd("ags_debug_groups_set",  WRAP_METHOD(AGSConsole, Cmd_setDebugGroupLevel));
-	
+	registerCmd("ags_sprite_info",   WRAP_METHOD(AGSConsole, Cmd_getSptintInfo));
+	registerCmd("ags_sprite_dump",  WRAP_METHOD(AGSConsole, Cmd_dumpSrite));
+
 	_logOutputTarget = new LogOutputTarget();
 	_agsDebuggerOutput = _GP(DbgMgr).RegisterOutput("ScummVMLog", _logOutputTarget, AGS3::AGS::Shared::kDbgMsg_None);
 }
@@ -165,6 +170,66 @@ void AGSConsole::printLevelList() {
 		debugPrintf(", %s", levelNames[i].name);
 }
 
+bool AGSConsole::Cmd_getSptintInfo(int argc, const char **argv) {
+	if (argc != 2) {
+		debugPrintf("Usage: %s SpriteNumber\n", argv[0]);
+		return true;
+	}
+
+	int spriteId = atoi(argv[1]);
+	if (!_GP(spriteset).DoesSpriteExist(spriteId)) {
+		debugPrintf("Sprite %d does not exist\n", spriteId);
+		return true;
+	}
+
+	AGS3::Shared::Bitmap *sprite = _GP(spriteset)[spriteId];
+	if (!sprite) {
+		debugPrintf("Failed to get sprite %d\n", spriteId);
+		return true;
+	}
+
+	debugPrintf("Size: %dx%d\n", sprite->GetWidth(), sprite->GetHeight());
+	debugPrintf("Color depth: %d\n", sprite->GetColorDepth());
+	return true;
+}
+
+bool AGSConsole::Cmd_dumpSrite(int argc, const char **argv) {
+	if (argc != 2) {
+		debugPrintf("Usage: %s SpriteNumber\n", argv[0]);
+		return true;
+	}
+
+	int spriteId = atoi(argv[1]);
+	if (!_GP(spriteset).DoesSpriteExist(spriteId)) {
+		debugPrintf("Sprite %d does not exist\n", spriteId);
+		return true;
+	}
+
+	AGS3::Shared::Bitmap *sprite = _GP(spriteset)[spriteId];
+	if (!sprite) {
+		debugPrintf("Failed to get sprite %d\n", spriteId);
+		return true;
+	}
+
+	Common::String pngFile = Common::String::format("%s-sprite%03d.png", _vm->getGameId().c_str(), spriteId);
+	Common::DumpFile df;
+	if (df.open(pngFile)) {
+		byte *palette = nullptr;
+		if (sprite->GetColorDepth() == 8) {
+			palette = new byte[256 * 3];
+			for (int c = 0, i = 0 ; c < 256 ; ++c, i += 3) {
+				palette[i] = _G(current_palette)[c].r * 255 / 63;
+				palette[i + 1] = _G(current_palette)[c].g * 255 / 63;
+				palette[i + 2] = _G(current_palette)[c].b * 255 / 63;
+			}
+		}
+		Image::writePNG(df, sprite->GetAllegroBitmap()->getSurface().rawSurface(), palette);
+		delete [] palette;
+	}
+
+	return true;
+}
+
 LogOutputTarget::LogOutputTarget() {
 }
 
diff --git a/engines/ags/console.h b/engines/ags/console.h
index 0ce70a9c55..a6c30d296f 100644
--- a/engines/ags/console.h
+++ b/engines/ags/console.h
@@ -45,7 +45,10 @@ private:
 
 	bool Cmd_listDebugGroups(int argc, const char **argv);
 	bool Cmd_setDebugGroupLevel(int argc, const char **argv);
-	
+
+	bool Cmd_getSptintInfo(int argc, const char **argv);
+	bool Cmd_dumpSrite(int argc, const char **argv);
+
 	const char *getVerbosityLevel(uint32_t groupID) const;
 	uint32_t parseGroup(const char *, bool &) const;
 	AGS3::AGS::Shared::MessageType parseLevel(const char *, bool &) const;




More information about the Scummvm-git-logs mailing list