[Scummvm-git-logs] scummvm master -> 96c860c5bdc8c3b406ad100db5fd0558365b364d

dreammaster paulfgilbert at gmail.com
Sat Aug 29 21:35:27 UTC 2020


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:
ac7b1e326d GLK: HUGO: Properly fix display images
96c860c5bd GLK: HUGO: Fix hang closing ScummVM window


Commit: ac7b1e326dd066d41498e960aead5ffc3c8202e2
    https://github.com/scummvm/scummvm/commit/ac7b1e326dd066d41498e960aead5ffc3c8202e2
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2020-08-29T13:59:52-07:00

Commit Message:
GLK: HUGO: Properly fix display images

The resource file format Hugo uses has named entries.
Because of this, the original Glk code added to Hugo
does a whole mess of reading in a picture, then copying
it to a dummy pic file with a dummy number, just so a
call to glk_image_draw could detect it.

Since this isn't the first time I've had to deal with
named resources, it ended up being cleaner to add a new
variation of glk_image_draw and glk_image_draw_scaled
that can take in a string image parameter. That way, I
was able to set up an archive class to represent the
resource file, and pass the resource name directly
without worrying about dummy picture numbers & files

Changed paths:
  A engines/glk/hugo/resource_archive.cpp
  A engines/glk/hugo/resource_archive.h
    engines/glk/glk_api.cpp
    engines/glk/glk_api.h
    engines/glk/hugo/hemedia.cpp
    engines/glk/hugo/heres.cpp
    engines/glk/hugo/hugo.cpp
    engines/glk/hugo/hugo.h
    engines/glk/module.mk
    engines/glk/picture.cpp
    engines/glk/picture.h
    engines/glk/window_graphics.cpp
    engines/glk/window_graphics.h
    engines/glk/window_text_buffer.cpp
    engines/glk/window_text_buffer.h
    engines/glk/windows.cpp
    engines/glk/windows.h


diff --git a/engines/glk/glk_api.cpp b/engines/glk/glk_api.cpp
index 51557db0a5..d7ea0e0f30 100644
--- a/engines/glk/glk_api.cpp
+++ b/engines/glk/glk_api.cpp
@@ -893,36 +893,14 @@ uint GlkAPI::glk_buffer_canon_normalize_uni(uint32 *buf, uint len, uint numchars
 }
 
 bool GlkAPI::glk_image_draw(winid_t win, uint image, int val1, int val2) {
-	if (!win) {
-		warning("image_draw: invalid ref");
-	} else if (g_conf->_graphics) {
-		TextBufferWindow *textWin = dynamic_cast<TextBufferWindow *>(win);
-		GraphicsWindow *gfxWin = dynamic_cast<GraphicsWindow *>(win);
-
-		if (textWin)
-			return textWin->drawPicture(image, val1, false, 0, 0);
-		else if (gfxWin)
-			return gfxWin->drawPicture(image, val1, val2, false, 0, 0);
-	}
-
-	return false;
+	return glk_image_draw(win, Common::String::format("%d", image),
+		val1, val2);
 }
 
 bool GlkAPI::glk_image_draw_scaled(winid_t win, uint image, int val1, int val2,
                                   uint width, uint height) {
-	if (!win) {
-		warning("image_draw_scaled: invalid ref");
-	} else if (g_conf->_graphics) {
-		TextBufferWindow *textWin = dynamic_cast<TextBufferWindow *>(win);
-		GraphicsWindow *gfxWin = dynamic_cast<GraphicsWindow *>(win);
-
-		if (textWin)
-			return textWin->drawPicture(image, val1, true, width, height);
-		else if (gfxWin)
-			return gfxWin->drawPicture(image, val1, val2, true, width, height);
-	}
-
-	return false;
+	return glk_image_draw_scaled(win, Common::String::format("%d", image),
+		val1, val2, width, height);
 }
 
 bool GlkAPI::glk_image_draw(winid_t win, const Graphics::Surface &image, uint transColor,
@@ -962,11 +940,49 @@ bool GlkAPI::glk_image_draw_scaled(winid_t win, const Graphics::Surface &image,
 	return true;
 }
 
+bool GlkAPI::glk_image_draw(winid_t win, const Common::String &image, int val1, int val2) {
+	if (!win) {
+		warning("image_draw: invalid ref");
+	} else if (g_conf->_graphics) {
+		TextBufferWindow *textWin = dynamic_cast<TextBufferWindow *>(win);
+		GraphicsWindow *gfxWin = dynamic_cast<GraphicsWindow *>(win);
+
+		if (textWin)
+			return textWin->drawPicture(image, val1, false, 0, 0);
+		else if (gfxWin)
+			return gfxWin->drawPicture(image, val1, val2, false, 0, 0);
+	}
+
+	return false;
+}
+
+bool GlkAPI::glk_image_draw_scaled(winid_t win, const Common::String &image,
+		int val1, int val2, uint width, uint height) {
+	if (!win) {
+		warning("image_draw_scaled: invalid ref");
+	} else if (g_conf->_graphics) {
+		TextBufferWindow *textWin = dynamic_cast<TextBufferWindow *>(win);
+		GraphicsWindow *gfxWin = dynamic_cast<GraphicsWindow *>(win);
+
+		if (textWin)
+			return textWin->drawPicture(image, val1, true, width, height);
+		else if (gfxWin)
+			return gfxWin->drawPicture(image, val1, val2, true, width, height);
+	}
+
+	return false;
+}
+
 bool GlkAPI::glk_image_get_info(uint image, uint *width, uint *height) {
+	return glk_image_get_info(Common::String::format("%u", image),
+		width, height);
+}
+
+bool GlkAPI::glk_image_get_info(const Common::String &name, uint *width, uint *height) {
 	if (!g_conf->_graphics)
 		return false;
 
-	Picture *pic = g_vm->_pictures->load(image);
+	Picture *pic = g_vm->_pictures->load(name);
 	if (!pic)
 		return false;
 
diff --git a/engines/glk/glk_api.h b/engines/glk/glk_api.h
index ddb575e4b3..e5881ea01c 100644
--- a/engines/glk/glk_api.h
+++ b/engines/glk/glk_api.h
@@ -203,8 +203,12 @@ public:
 		int xp = 0, int yp = 0);
 	bool glk_image_draw_scaled(winid_t win, const Graphics::Surface &image, uint transColor,
 		int xp, int yp, uint width, uint height);
+	bool glk_image_draw(winid_t win, const Common::String &image, int val1, int val2);
+	bool glk_image_draw_scaled(winid_t win, const Common::String &image,
+		int val1, int val2, uint width, uint height);
 
 	bool glk_image_get_info(uint image, uint *width, uint *height);
+	bool glk_image_get_info(const Common::String &name, uint *width, uint *height);
 
 	void glk_window_flow_break(winid_t win);
 
diff --git a/engines/glk/hugo/hemedia.cpp b/engines/glk/hugo/hemedia.cpp
index a7ddbf6d00..ba7fdb23ca 100644
--- a/engines/glk/hugo/hemedia.cpp
+++ b/engines/glk/hugo/hemedia.cpp
@@ -81,51 +81,6 @@ int Hugo::hugo_hasgraphics() {
 		&& glk_gestalt(gestalt_DrawImage, glk_window_get_type(mainwin));
 }
 
-int Hugo::hugo_displaypicture(HUGO_FILE infile, long reslen) {
-	int idVal;
-
-	/* Ignore the call if the current window is set elsewhere. */
-	if (currentwin != NULL && currentwin != mainwin)
-	{
-		hugo_fclose(infile);
-		return false;
-	}
-
-	idVal = loadres(infile, reslen, PIC);
-	if (idVal < 0)
-	{
-		hugo_fclose(infile);
-		return false;
-	}
-
-#if 0
-	/* Get picture width and height for scaling. */
-	glui32 width, height;
-	if (glk_image_get_info(idVal, &width, &height))
-	{
-		/* Scale large images. */
-		if (width > PIC_MAX_WIDTH)
-		{
-			height = height * PIC_MAX_WIDTH / width;
-			width = PIC_MAX_WIDTH;
-		}
-		if (height > PIC_MAX_HEIGHT)
-		{
-			width = width * PIC_MAX_HEIGHT / height;
-			height = PIC_MAX_HEIGHT;
-		}
-	}
-#endif
-
-	hugo_fclose(infile);
-
-	/* Draw, then move cursor down to the next line. */
-	glk_image_draw(mainwin, idVal, imagealign_InlineUp, 0);
-	glk_put_char('\n');
-
-	return true;
-}
-
 void Hugo::initsound() {
 	if (!glk_gestalt(gestalt_Sound, 0))
 		return;
diff --git a/engines/glk/hugo/heres.cpp b/engines/glk/hugo/heres.cpp
index 606f712f0c..7c49210bea 100644
--- a/engines/glk/hugo/heres.cpp
+++ b/engines/glk/hugo/heres.cpp
@@ -26,35 +26,22 @@ namespace Glk {
 namespace Hugo {
 
 void Hugo::DisplayPicture() {
-	char filename[MAX_RES_PATH], resname[MAX_RES_PATH];
-	long reslength;
-
-	GetResourceParameters(filename, resname, PICTURE_T);
-	
-	if (!hugo_hasgraphics())
-	{
+	if (!hugo_hasgraphics()) {
 		var[system_status] = STAT_UNAVAILABLE;
 		return;
 	}
 
-	/* If filename is empty, no resource file was specified and
-	   the line[] array simply holds the path of the file to be loaded
-	   as a resource
-	*/
-	if (!(reslength = FindResource(filename, resname)))
-		return;
-
-	/* Find out what type of image resource this is */
-	resource_type = (char)((hugo_fgetc(resource_file)==0xff) ? JPEG_R : UNKNOWN_R);
-	hugo_fseek(resource_file, -1, SEEK_CUR);
-
-	/* If FindResource() is successful, the resource file is already
-	   open and positioned; hugo_displaypicture() is responsible for
-	   closing resource_file before returning regardless of success
-	   or failure
-	*/
-	if (!hugo_displaypicture(resource_file, reslength))
+	char filename[MAX_RES_PATH], resname[MAX_RES_PATH];
+	g_vm->GetResourceParameters(filename, resname, PICTURE_T);
+	Common::String picName = Common::String::format("%s,%s",
+		filename, resname);
+
+	// Draw game's picture then move cursor down to the next line
+	if (glk_image_draw(mainwin, picName, imagealign_InlineUp, 0)) {
+		glk_put_char('\n');
+	} else {
 		var[system_status] = STAT_LOADERROR;
+	}
 }
 
 void Hugo::PlayMusic() {
@@ -253,7 +240,7 @@ Identified:
 #endif
 }
 
-long Hugo::FindResource(char *filename, char *resname) {
+long Hugo::FindResource(const char *filename, const char *resname) {
 	char resource_in_file[MAX_RES_PATH];
 	int i, len;
 	int rescount;
@@ -281,7 +268,7 @@ long Hugo::FindResource(char *filename, char *resname) {
 
 
 	/* Open the resourcefile */
-	strupr(filename);
+	//strupr(filename);
 
 #if !defined (GLK)
 	/* stdio implementation */
diff --git a/engines/glk/hugo/hugo.cpp b/engines/glk/hugo/hugo.cpp
index af98c8fbdc..4582d61cc4 100644
--- a/engines/glk/hugo/hugo.cpp
+++ b/engines/glk/hugo/hugo.cpp
@@ -21,11 +21,14 @@
  */
 
 #include "glk/hugo/hugo.h"
+#include "glk/hugo/resource_archive.h"
 #include "common/config-manager.h"
 
 namespace Glk {
 namespace Hugo {
 
+Hugo *g_vm;
+
 Hugo::Hugo(OSystem *syst, const GlkGameDescription &gameDesc) : GlkAPI(syst, gameDesc),
 		mainwin(nullptr), currentwin(nullptr), secondwin(nullptr), auxwin(nullptr), 
 		runtime_warnings(false), dbnest(0), address_scale(16),
@@ -79,6 +82,7 @@ Hugo::Hugo(OSystem *syst, const GlkGameDescription &gameDesc) : GlkAPI(syst, gam
 		active_screen(0), step_nest(0), history_last(0)
 #endif
 		{
+	g_vm = this;
 	strcpy(gamefile, "");
 
 	// heexpr
@@ -133,6 +137,10 @@ Hugo::Hugo(OSystem *syst, const GlkGameDescription &gameDesc) : GlkAPI(syst, gam
 #endif
 }
 
+Hugo::~Hugo() {
+	g_vm = nullptr;
+}
+
 void Hugo::runGame() {
 	hugo_init_screen();
 
@@ -141,6 +149,9 @@ void Hugo::runGame() {
 	strcpy(gamefile, getFilename().c_str());
 	strcpy(pbuffer, "");
 
+	ResourceArchive *res = new ResourceArchive();
+	SearchMan.add("Resouces", res);
+
 	gameseg = 0;
 
 	LoadGame();
diff --git a/engines/glk/hugo/hugo.h b/engines/glk/hugo/hugo.h
index c5864e1372..23a0ed39ab 100644
--- a/engines/glk/hugo/hugo.h
+++ b/engines/glk/hugo/hugo.h
@@ -36,10 +36,13 @@
 namespace Glk {
 namespace Hugo {
 
+class ResourceArchive;
+
 /**
  * Hugo game interpreter
  */
 class Hugo : public GlkAPI, public HTokens, public StringFunctions {
+	friend class ResourceArchive;
 private:
 	int _savegameSlot;
 	winid_t mainwin, currentwin;
@@ -639,8 +642,6 @@ private:
 
 	int hugo_hasgraphics();
 
-	int hugo_displaypicture(HUGO_FILE infile, long reslen);
-
 	void initsound();
 
 	void initmusic();
@@ -905,7 +906,7 @@ private:
 	 * and on-disk resources in (if not the given directory) "source" or "resource" (where these are the
 	 * environment variables "HUGO_...", not actual on-disk directories).
 	 */
-	long FindResource(char *filename, char *resname);
+	long FindResource(const char *filename, const char *resname);
 
 	/**
 	 * Processes resourcefile/filename (and resource, if applicable).
@@ -1182,6 +1183,11 @@ public:
 	 */
 	Hugo(OSystem *syst, const GlkGameDescription &gameDesc);
 
+	/**
+	 * Destructor
+	 */
+	~Hugo();
+
 	/**
 	 * Run the game
 	 */
@@ -1204,6 +1210,8 @@ public:
 	Common::Error writeGameData(Common::WriteStream *ws) override;
 };
 
+extern Hugo *g_vm;
+
 } // End of namespace Hugo
 } // End of namespace Glk
 
diff --git a/engines/glk/hugo/resource_archive.cpp b/engines/glk/hugo/resource_archive.cpp
new file mode 100644
index 0000000000..74f6a41f41
--- /dev/null
+++ b/engines/glk/hugo/resource_archive.cpp
@@ -0,0 +1,94 @@
+/* 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 "glk/hugo/resource_archive.h"
+#include "glk/hugo/hugo.h"
+#include "common/algorithm.h"
+#include "common/memstream.h"
+
+namespace Glk {
+namespace Hugo {
+
+bool ResourceArchive::splitName(const Common::String &name,
+		Common::String &filename, Common::String &resName) {
+	int commaIndex = name.findFirstOf(',');
+	if (commaIndex == Common::String::npos)
+		return false;
+
+	filename = Common::String(name.c_str(), commaIndex);
+	resName = Common::String(name.c_str() + commaIndex + 1);
+
+	if (resName.hasSuffixIgnoreCase(".jpg"))
+		resName = Common::String(resName.c_str(), resName.size() - 4);
+	else if (resName.hasSuffixIgnoreCase(".jpeg"))
+		resName = Common::String(resName.c_str(), resName.size() - 5);
+	else if (resName.contains("."))
+		return false;
+
+	return true;
+}
+
+
+bool ResourceArchive::hasFile(const Common::String &name) const {
+	Common::String filename, resName;
+
+	if (!splitName(name, filename, resName))
+		return false;
+	size_t resLength = g_vm->FindResource(filename.c_str(), resName.c_str());
+	g_vm->hugo_fclose(g_vm->resource_file);
+
+	return resLength != 0;
+}
+
+const Common::ArchiveMemberPtr ResourceArchive::getMember(const Common::String &name) const {
+	if (!hasFile(name))
+		return Common::ArchiveMemberPtr();
+
+	return Common::ArchiveMemberPtr(new Common::GenericArchiveMember(name, this));
+}
+
+Common::SeekableReadStream *ResourceArchive::createReadStreamForMember(const Common::String &name) const {
+	Common::String filename, resName;
+
+	// Split up the file and resource entry; return if it's not one
+	if (!splitName(name, filename, resName))
+		return nullptr;
+
+	// Try and get the entry details from the given file
+	size_t resLength = g_vm->FindResource(filename.c_str(), resName.c_str());
+
+	if (!resLength) {
+		g_vm->hugo_fclose(g_vm->resource_file);
+		return nullptr;
+	}
+
+	// Otherwise, load the specified resource
+	byte *buffer = (byte *)malloc(resLength);
+	g_vm->glk_get_buffer_stream(g_vm->resource_file, (char *)buffer, resLength);
+	g_vm->hugo_fclose(g_vm->resource_file);
+
+	// Return a stream to allow access to the data
+	return new Common::MemoryReadStream(buffer, resLength, DisposeAfterUse::YES);
+}
+
+} // End of namespace Hugo
+} // End of namespace Glk
diff --git a/engines/glk/hugo/resource_archive.h b/engines/glk/hugo/resource_archive.h
new file mode 100644
index 0000000000..f386b313fb
--- /dev/null
+++ b/engines/glk/hugo/resource_archive.h
@@ -0,0 +1,78 @@
+/* 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 GLK_HUGO_RESOURCE_ARCHIVE_H
+#define GLK_HUGO_RESOURCE_ARCHIVE_H
+
+#include "common/archive.h"
+
+namespace Glk {
+namespace Hugo {
+
+/**
+ * ScummVM archive that provides virtual access to the Hugo
+ * resource files
+ */
+class ResourceArchive : public Common::Archive {
+private:
+	/**
+	 * Splits a resource file and entry pair into individual names
+	 */
+	static bool splitName(const Common::String &name,
+		Common::String &filename, Common::String &resName);
+public:
+	~ResourceArchive() override {}
+
+	/**
+	 * Check if a member with the given name is present in the Archive.
+	 * Patterns are not allowed, as this is meant to be a quick File::exists()
+	 * replacement.
+	 */
+	bool hasFile(const Common::String &name) const override;
+
+	/**
+	 * Add all members of the Archive to list.
+	 * Must only append to list, and not remove elements from it.
+	 *
+	 * @return the number of names added to list
+	 */
+	int listMembers(Common::ArchiveMemberList &list) const override {
+		return 0;
+	}
+
+	/**
+	 * Returns a ArchiveMember representation of the given file.
+	 */
+	const Common::ArchiveMemberPtr getMember(const Common::String &name) const override;
+
+	/**
+	 * Create a stream bound to a member with the specified name in the
+	 * archive. If no member with this name exists, 0 is returned.
+	 * @return the newly created input stream
+	 */
+	Common::SeekableReadStream *createReadStreamForMember(const Common::String &name) const override;
+};
+
+} // End of namespace Hugo
+} // End of namespace Glk
+
+#endif
diff --git a/engines/glk/module.mk b/engines/glk/module.mk
index 27b826a938..d3b53007b7 100644
--- a/engines/glk/module.mk
+++ b/engines/glk/module.mk
@@ -209,6 +209,7 @@ MODULE_OBJS := \
 	hugo/heset.o \
 	hugo/htokens.o \
 	hugo/hugo.o \
+	hugo/resource_archive.o \
 	hugo/stringfn.o \
 	jacl/detection.o \
 	jacl/display.o \
diff --git a/engines/glk/picture.cpp b/engines/glk/picture.cpp
index 4c3f8454ed..c15ba59a93 100644
--- a/engines/glk/picture.cpp
+++ b/engines/glk/picture.cpp
@@ -34,7 +34,8 @@ Pictures::Pictures() : _refCount(0) {
 	Common::File f;
 	if (f.open("apal")) {
 		while (f.pos() < f.size())
-			_adaptivePics.push_back(f.readUint32BE());
+			_adaptivePics.push_back(
+				Common::String::format("%u", f.readUint32BE()));
 	}
 }
 
@@ -58,13 +59,13 @@ void Pictures::decrement() {
 		clear();
 }
 
-PictureEntry *Pictures::search(uint id) {
+PictureEntry *Pictures::search(const Common::String &name) {
 	Picture *pic;
 
 	for (uint idx = 0; idx < _store.size(); ++idx) {
 		pic = _store[idx]._picture;
 
-		if (pic && pic->_id == id)
+		if (pic && pic->_name.equalsIgnoreCase(name))
 			return &_store[idx];
 	}
 
@@ -79,7 +80,7 @@ void Pictures::storeOriginal(Picture *pic) {
 }
 
 void Pictures::storeScaled(Picture *pic) {
-	PictureEntry *entry = search(pic->_id);
+	PictureEntry *entry = search(pic->_name);
 	if (!entry)
 		return;
 
@@ -97,20 +98,20 @@ void Pictures::store(Picture *pic) {
 		storeScaled(pic);
 }
 
-Picture *Pictures::retrieve(uint id, bool scaled) {
+Picture *Pictures::retrieve(const Common::String &name, bool scaled) {
 	Picture *pic;
 
 	for (uint idx = 0; idx < _store.size(); ++idx) {
 		pic = scaled ? _store[idx]._scaled : _store[idx]._picture;
 
-		if (pic && pic->_id == id)
+		if (pic && pic->_name.equalsIgnoreCase(name))
 			return pic;
 	}
 
 	return nullptr;
 }
 
-Picture *Pictures::load(uint32 id) {
+Picture *Pictures::load(const Common::String &name) {
 	::Image::PNGDecoder png;
 	::Image::JPEGDecoder jpg;
 	Graphics::Surface rectImg;
@@ -122,29 +123,38 @@ Picture *Pictures::load(uint32 id) {
 	Picture *pic;
 
 	// Check if the picture is already in the store
-	pic = retrieve(id, false);
+	pic = retrieve(name, false);
 	if (pic)
 		return pic;
 
 	Common::File f;
-	if (f.open(Common::String::format("pic%u.png", id))) {
+	if ((name.hasSuffixIgnoreCase(".png") && f.open(name))
+		|| f.open(Common::String::format("pic%s.png", name.c_str()))
+		|| f.open(Common::String::format("%s.png", name.c_str()))
+	) {
 		png.setKeepTransparencyPaletted(true);
 		png.loadStream(f);
 		img = png.getSurface();
 		palette = png.getPalette();
 		palCount = png.getPaletteColorCount();
 		transColor = png.getTransparentColor();
-	} else if (f.open(Common::String::format("pic%u.jpg", id))) {
+	} else if (
+		((name.hasSuffixIgnoreCase(".jpg") || name.hasSuffixIgnoreCase(".jpeg")) && f.open(name))
+		|| f.open(Common::String::format("pic%s.jpg", name.c_str()))
+		|| f.open(Common::String::format("pic%s.jpeg", name.c_str()))
+		|| f.open(Common::String::format("%s.jpg", name.c_str()))
+	) {
 		jpg.setOutputPixelFormat(g_system->getScreenFormat());
 		jpg.loadStream(f);
 		img = jpg.getSurface();
-	} else if (f.open(Common::String::format("pic%u.raw", id))) {
+	} else if ((name.hasSuffixIgnoreCase(".raw") && f.open(name)) ||
+			f.open(Common::String::format("pic%s.raw", name.c_str()))) {
 		raw.loadStream(f);
 		img = raw.getSurface();
 		palette = raw.getPalette();
 		palCount = raw.getPaletteColorCount();
 		transColor = raw.getTransparentColor();
-	} else if (f.open(Common::String::format("pic%u.rect", id))) {
+	} else if (f.open(Common::String::format("pic%s.rect", name.c_str()))) {
 		rectImg.w = f.readUint32BE();
 		rectImg.h = f.readUint32BE();
 		img = &rectImg;
@@ -156,7 +166,7 @@ Picture *Pictures::load(uint32 id) {
 	// Also check if it's going to be an adaptive pic
 	bool isAdaptive = false;
 	for (uint idx = 0; idx < _adaptivePics.size() && !isAdaptive; ++idx)
-		isAdaptive = _adaptivePics[idx] == id;
+		isAdaptive = _adaptivePics[idx].equalsIgnoreCase(name);
 
 	if (isAdaptive) {
 		// It is, so used previously saved palette
@@ -172,7 +182,7 @@ Picture *Pictures::load(uint32 id) {
 	// Create new picture based on the image
 	pic = new Picture(img->w, img->h, g_system->getScreenFormat());
 	pic->_refCount = 1;
-    pic->_id = id;
+    pic->_name = name;
     pic->_scaled = false;
 	if (transColor != -1 || (!palette && img->format.aBits() > 0))
 		pic->clear(pic->getTransparentColor());
@@ -206,13 +216,13 @@ Picture *Pictures::load(uint32 id) {
 
 Picture *Pictures::scale(Picture *src, size_t sx, size_t sy) {
 	// Check for the presence of an already scaled version of that size
-	Picture *dst = retrieve(src->_id, true);
+	Picture *dst = retrieve(src->_name, true);
 	if (dst && dst->w == sx && dst->h == sy)
 		return dst;
 
 	// Create a new picture of the destination size and rescale the source picture
 	dst = new Picture(sx, sy, src->format);
-	dst->_id = src->_id;
+	dst->_name = src->_name;
 	dst->_scaled = true;
 	dst->transBlitFrom(*src, src->getBounds(), dst->getBounds(), (uint)0x8888);
 
@@ -223,7 +233,7 @@ Picture *Pictures::scale(Picture *src, size_t sx, size_t sy) {
 /*--------------------------------------------------------------------------*/
 
 Picture::Picture(int width, int height, const Graphics::PixelFormat &fmt) :
-		Graphics::ManagedSurface(width, height, fmt), _refCount(0), _id(0), _scaled(false) {
+		Graphics::ManagedSurface(width, height, fmt), _refCount(0), _scaled(false) {
 
 	// Default transparent color chosen at random
 	_transColor = format.RGBToColor(0x77, 0x77, 0x77);
diff --git a/engines/glk/picture.h b/engines/glk/picture.h
index a8b7e0a9b2..d28a2498a8 100644
--- a/engines/glk/picture.h
+++ b/engines/glk/picture.h
@@ -36,13 +36,13 @@ private:
 	int _transColor;
 public:
 	int _refCount;
-	uint _id;
+	Common::String _name;
 	bool _scaled;
 
 	/**
 	 * Constructor
 	 */
-	Picture() : Graphics::ManagedSurface(), _refCount(0), _id(0), _scaled(false), _transColor(0x7777) {}
+	Picture() : Graphics::ManagedSurface(), _refCount(0), _scaled(false), _transColor(0x7777) {}
 
 	/**
 	 * Constructor
@@ -90,7 +90,7 @@ class Pictures {
 private:
 	int _refCount;
 	Common::Array<PictureEntry> _store;
-	Common::Array<uint> _adaptivePics;
+	Common::Array<Common::String> _adaptivePics;
 	Common::Array<byte> _savedPalette;
 private:
 	/**
@@ -131,7 +131,7 @@ public:
 	/**
 	 * Searches for an existing picture entry
 	 */
-	PictureEntry *search(uint id);
+	PictureEntry *search(const Common::String &name);
 
 	/**
 	 * Stores a picture in the store
@@ -141,12 +141,12 @@ public:
 	/**
 	 * Retrieves a picture from the store
 	 */
-	Picture *retrieve(uint id, bool scaled);
+	Picture *retrieve(const Common::String &name, bool scaled);
 
 	/**
 	 * Load a given picture
 	 */
-	Picture *load(uint32 id);
+	Picture *load(const Common::String &name);
 
 	/**
 	 * Rescale the passed picture to a new picture of a given size
diff --git a/engines/glk/window_graphics.cpp b/engines/glk/window_graphics.cpp
index 2090165441..e39dd0a9e8 100644
--- a/engines/glk/window_graphics.cpp
+++ b/engines/glk/window_graphics.cpp
@@ -96,7 +96,7 @@ void GraphicsWindow::redraw() {
 	}
 }
 
-bool GraphicsWindow::drawPicture(uint image, int xpos, int ypos, bool scale,
+bool GraphicsWindow::drawPicture(const Common::String &image, int xpos, int ypos, bool scale,
                                    uint imagewidth, uint imageheight) {
 	Picture *pic = g_vm->_pictures->load(image);
 	uint hyperlink = _attr.hyper;
diff --git a/engines/glk/window_graphics.h b/engines/glk/window_graphics.h
index 7a3eb9bc48..b32bae79fc 100644
--- a/engines/glk/window_graphics.h
+++ b/engines/glk/window_graphics.h
@@ -52,7 +52,7 @@ public:
 	 */
 	~GraphicsWindow() override;
 
-	bool drawPicture(uint image, int xpos, int ypos, bool scale,
+	bool drawPicture(const Common::String &image, int xpos, int ypos, bool scale,
 	                   uint imagewidth, uint imageheight);
 	void drawPicture(const Graphics::Surface &image, uint transColor, int x0, int y0,
 		int width, int height, uint linkval = 0);
diff --git a/engines/glk/window_text_buffer.cpp b/engines/glk/window_text_buffer.cpp
index 5ceeadda5c..19cfbb5040 100644
--- a/engines/glk/window_text_buffer.cpp
+++ b/engines/glk/window_text_buffer.cpp
@@ -275,12 +275,12 @@ bool TextBufferWindow::putPicture(Picture *pic, uint align, uint linkval) {
 	return true;
 }
 
-uint TextBufferWindow::drawPicture(uint image, uint align, uint scaled, uint width, uint height) {
+uint TextBufferWindow::drawPicture(const Common::String &name, uint align, uint scaled, uint width, uint height) {
 	Picture *pic;
 	uint hyperlink;
 	int error;
 
-	pic = g_vm->_pictures->load(image);
+	pic = g_vm->_pictures->load(name);
 
 	if (!pic)
 		return false;
diff --git a/engines/glk/window_text_buffer.h b/engines/glk/window_text_buffer.h
index c1260a541d..3ecaa11ef1 100644
--- a/engines/glk/window_text_buffer.h
+++ b/engines/glk/window_text_buffer.h
@@ -150,7 +150,7 @@ public:
 
 	int acceptScroll(uint arg);
 
-	uint drawPicture(uint image, uint align, uint scaled, uint width, uint height);
+	uint drawPicture(const Common::String &image, uint align, uint scaled, uint width, uint height);
 
 	/**
 	 * Get the font info structure associated with the window
diff --git a/engines/glk/windows.cpp b/engines/glk/windows.cpp
index b418b56b4f..44defed166 100644
--- a/engines/glk/windows.cpp
+++ b/engines/glk/windows.cpp
@@ -708,6 +708,11 @@ bool Window::checkTerminators(uint32 ch) {
 }
 
 bool Window::imageDraw(uint image, uint align, int val1, int val2) {
+	return imageDraw(Common::String::format("%u", image),
+		align, val1, val2);
+}
+
+bool Window::imageDraw(const Common::String & image, uint align, int val1, int val2) {
 	if (!g_conf->_graphics)
 		return false;
 
diff --git a/engines/glk/windows.h b/engines/glk/windows.h
index ef9068f4b9..0192204075 100644
--- a/engines/glk/windows.h
+++ b/engines/glk/windows.h
@@ -542,6 +542,7 @@ public:
 	virtual void redraw();
 
 	bool imageDraw(uint image, uint align, int val1, int val2);
+	bool imageDraw(const Common::String &image, uint align, int val1, int val2);
 
 	int acceptScroll(uint arg);
 


Commit: 96c860c5bdc8c3b406ad100db5fd0558365b364d
    https://github.com/scummvm/scummvm/commit/96c860c5bdc8c3b406ad100db5fd0558365b364d
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2020-08-29T14:23:57-07:00

Commit Message:
GLK: HUGO: Fix hang closing ScummVM window

Changed paths:
    engines/glk/hugo/heglk.cpp
    engines/glk/hugo/herun.cpp


diff --git a/engines/glk/hugo/heglk.cpp b/engines/glk/hugo/heglk.cpp
index c4c3eec5e5..4eeacb6504 100644
--- a/engines/glk/hugo/heglk.cpp
+++ b/engines/glk/hugo/heglk.cpp
@@ -118,14 +118,15 @@ int Hugo::hugo_waitforkey() {
 		/* Grab an event */
 		glk_select(&ev);
 
-		switch (ev.type)
-		{
+		switch (ev.type) {
 		case evtype_CharInput:
 			/* (Will always be mainwin, but anyway) */
 			if (ev.window == currentwin) {
 				gotchar = true;
 			}
 			break;
+		case evtype_Quit:
+			return 0;
 		default:
 			break;
 		}
diff --git a/engines/glk/hugo/herun.cpp b/engines/glk/hugo/herun.cpp
index 56e27c55bf..7ca30e5fb1 100644
--- a/engines/glk/hugo/herun.cpp
+++ b/engines/glk/hugo/herun.cpp
@@ -192,6 +192,9 @@ Start:
 
 	do
 	{
+		if (shouldQuit())
+			return;
+
 		if (xverb==0)
 		{
 			undorecord = true;
@@ -1343,7 +1346,8 @@ ContinueRunning:
 
 	while (MEM(codeptr) != CLOSE_BRACE_T)   /* until "}" */
 	{
-
+		if (shouldQuit())
+			return;
 #if defined (DEBUGGER)
 		/* Check if we're stepping over, and if we've returned to
 		   the original level of nesting:




More information about the Scummvm-git-logs mailing list