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

fracturehill noreply at scummvm.org
Tue Jan 30 22:13:30 UTC 2024


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

Summary:
a6e9cd3424 NANCY: Fix resource leak when shutting engine down
b43b66dcc6 NANCY: Change the font height calculation in nancy6
9a549a88b2 NANCY: Implement Autotext images
f3fee34f42 NANCY: Indent Autotext when wrapping


Commit: a6e9cd3424d074ec1a2c3f3f0eb824e17a2e7c59
    https://github.com/scummvm/scummvm/commit/a6e9cd3424d074ec1a2c3f3f0eb824e17a2e7c59
Author: Kaloyan Chehlarski (strahy at outlook.com)
Date: 2024-01-30T23:13:12+01:00

Commit Message:
NANCY: Fix resource leak when shutting engine down

ActionRecords weren't being deleted, which resulted in
memory leaks and files being kept open.

Changed paths:
    engines/nancy/action/actionmanager.cpp
    engines/nancy/action/actionmanager.h


diff --git a/engines/nancy/action/actionmanager.cpp b/engines/nancy/action/actionmanager.cpp
index 7e4db14e873..3ef59039dac 100644
--- a/engines/nancy/action/actionmanager.cpp
+++ b/engines/nancy/action/actionmanager.cpp
@@ -40,6 +40,10 @@
 namespace Nancy {
 namespace Action {
 
+ActionManager::~ActionManager() {
+	clearActionRecords();
+}
+
 void ActionManager::handleInput(NancyInput &input) {
 	bool setHoverCursor = false;
 	for (auto &rec : _records) {
diff --git a/engines/nancy/action/actionmanager.h b/engines/nancy/action/actionmanager.h
index 7224fe1ce99..20c8018928c 100644
--- a/engines/nancy/action/actionmanager.h
+++ b/engines/nancy/action/actionmanager.h
@@ -55,7 +55,7 @@ public:
 	static const byte kCursStandard				= 254;
 
 	ActionManager() {}
-	virtual ~ActionManager() {}
+	virtual ~ActionManager();
 
 	void handleInput(NancyInput &input);
 


Commit: b43b66dcc6c3ddc86cf35e44f16e1cc74999b990
    https://github.com/scummvm/scummvm/commit/b43b66dcc6c3ddc86cf35e44f16e1cc74999b990
Author: Kaloyan Chehlarski (strahy at outlook.com)
Date: 2024-01-30T23:13:12+01:00

Commit Message:
NANCY: Change the font height calculation in nancy6

This ensures the text can be (nearly) pixel-perfect.

Changed paths:
    engines/nancy/font.cpp


diff --git a/engines/nancy/font.cpp b/engines/nancy/font.cpp
index f6116580006..bd3e3e2912e 100644
--- a/engines/nancy/font.cpp
+++ b/engines/nancy/font.cpp
@@ -130,6 +130,10 @@ void Font::read(Common::SeekableReadStream &stream) {
 		_fontHeight = MAX<int>(cur.height(), _fontHeight);
 	}
 
+	if (g_nancy->getGameType() >= kGameTypeNancy6) {
+		_fontHeight = getCharWidth('o') * 2 - 1;
+	}
+
 	_textboxData = GetEngineData(TBOX);
 	assert(_textboxData);
 }


Commit: 9a549a88b2d04ae75c4c22382c121ff6c2706ca3
    https://github.com/scummvm/scummvm/commit/9a549a88b2d04ae75c4c22382c121ff6c2706ca3
Author: Kaloyan Chehlarski (strahy at outlook.com)
Date: 2024-01-30T23:13:12+01:00

Commit Message:
NANCY: Implement Autotext images

Added support for images inside Autotext. Used extensively
in nancy7.

Changed paths:
    engines/nancy/action/autotext.cpp
    engines/nancy/action/autotext.h
    engines/nancy/misc/hypertext.cpp
    engines/nancy/misc/hypertext.h


diff --git a/engines/nancy/action/autotext.cpp b/engines/nancy/action/autotext.cpp
index 86670ded214..e5509145816 100644
--- a/engines/nancy/action/autotext.cpp
+++ b/engines/nancy/action/autotext.cpp
@@ -40,15 +40,19 @@ void Autotext::readData(Common::SeekableReadStream &stream) {
 	_surfWidth = stream.readUint16LE();
 	_surfHeight = stream.readUint16LE();
 
-	readFilename(stream, _imageName);
+	Common::Path imageName;
+	readFilename(stream, imageName);
 
 	uint16 numImages = stream.readUint16LE();
+	if (numImages) {
+		for (uint i = 0; i < numImages; ++i) {
+			uint16 line = stream.readUint16LE();
+			Common::Rect src;
+			readRect(stream, src);
+			addImage(line, src);
+		}
 
-	_imageLineIDs.resize(numImages);
-	_imageSrcs.resize(numImages);
-	for (uint i = 0; i < numImages; ++i) {
-		_imageLineIDs[i] = stream.readUint16LE();
-		readRect(stream, _imageSrcs[i]);
+		setImageName(imageName);
 	}
 
 	stream.skip((5 - numImages) * (2 + 16));
@@ -139,6 +143,14 @@ void Autotext::execute() {
 		Common::Rect textBounds = surf.getBounds();
 		textBounds.left += _offset.x;
 		textBounds.top += _offset.y;
+
+		const Font *font = g_nancy->_graphicsManager->getFont(_fontID);
+		assert(font);
+		uint d = (font->getFontHeight() + 1) / 2 + 1;
+
+		textBounds.top += d + 1;
+		textBounds.left += d;
+
 		drawAllText(textBounds, _fontID, _fontID);
 	}
 
diff --git a/engines/nancy/action/autotext.h b/engines/nancy/action/autotext.h
index 6ae633b12d4..95684d4d5c0 100644
--- a/engines/nancy/action/autotext.h
+++ b/engines/nancy/action/autotext.h
@@ -52,12 +52,6 @@ protected:
 	uint16 _surfWidth = 0;
 	uint16 _surfHeight = 0;
 
-	// Data for displaying images inside text; not supported yet
-	Common::Path _imageName;
-
-	Common::Array<uint16> _imageLineIDs;
-	Common::Array<Common::Rect> _imageSrcs;
-
 	bool _useAutotextChunk = false;
 
 	// Only one of these is valid
diff --git a/engines/nancy/misc/hypertext.cpp b/engines/nancy/misc/hypertext.cpp
index 3a5bf08b4ba..c732d745935 100644
--- a/engines/nancy/misc/hypertext.cpp
+++ b/engines/nancy/misc/hypertext.cpp
@@ -22,6 +22,7 @@
 
 #include "engines/nancy/nancy.h"
 #include "engines/nancy/graphics.h"
+#include "engines/nancy/resource.h"
 
 #include "engines/nancy/misc/hypertext.h"
 
@@ -48,19 +49,35 @@ void HypertextParser::addTextLine(const Common::String &text) {
 	_needsTextRedraw = true;
 }
 
+void HypertextParser::addImage(uint16 lineID, const Common::Rect &src) {
+	_imageLineIDs.push_back(lineID);
+	_imageSrcs.push_back(src);
+}
+
+void HypertextParser::setImageName(const Common::Path &name) {
+	_imageName = name;
+}
+
 void HypertextParser::drawAllText(const Common::Rect &textBounds, uint fontID, uint highlightFontID) {
 	using namespace Common;
 
 	const Font *font = nullptr;
 	const Font *highlightFont = nullptr;
+	Graphics::ManagedSurface image;
 
 	_numDrawnLines = 0;
 
+	if (!_imageName.empty()) {
+		g_nancy->_resource->loadImage(_imageName, image);
+	}
+
 	for (uint lineID = 0; lineID < _textLines.size(); ++lineID) {
 		Common::String currentLine;
 		bool hasHotspot = false;
 		Rect hotspot;
 		Common::Queue<ColorFontChange> colorTextChanges;
+		Common::Queue<uint16> newlineTokens;
+		newlineTokens.push(0);
 		int curFontID = fontID;
 		uint numNonSpaceChars = 0;
 
@@ -107,6 +124,7 @@ void HypertextParser::drawAllText(const Common::Rect &textBounds, uint fontID, u
 					}
 
 					currentLine += '\n';
+					newlineTokens.push(numNonSpaceChars);
 					continue;
 				case 't' :
 					// Tab
@@ -158,6 +176,7 @@ void HypertextParser::drawAllText(const Common::Rect &textBounds, uint fontID, u
 		
 		font = g_nancy->_graphicsManager->getFont(curFontID);
 		highlightFont = g_nancy->_graphicsManager->getFont(highlightFontID);
+		assert(font && highlightFont);
 
 		// Do word wrapping on the text, sans tokens. This assumes
 		// all text uses fonts of the same width
@@ -176,8 +195,41 @@ void HypertextParser::drawAllText(const Common::Rect &textBounds, uint fontID, u
 		// respect color tokens
 		uint totalCharsDrawn = 0;
 		byte colorID = _defaultTextColor;
-		for (Common::String &line : wrappedLines) {
-			uint horizontalOffset = 0;
+		uint numNewlineTokens = 0;
+		uint horizontalOffset = 0;
+		for (uint lineNumber = 0; lineNumber < wrappedLines.size(); ++lineNumber) {
+			Common::String &line = wrappedLines[lineNumber];
+			horizontalOffset = 0;
+			// Draw images
+			if (newlineTokens.front() <= totalCharsDrawn) {
+				newlineTokens.pop();
+
+				for (uint i = 0; i < _imageLineIDs.size(); ++i) {
+					if (numNewlineTokens == _imageLineIDs[i]) {
+						// A lot of magic numbers that make sure we draw pixel-perfect. This is a mess for three reasons:
+						// - The original engine draws strings with a bottom-left anchor, while ScummVM uses top-left
+						// - The original engine uses inclusive rects, while ScummVM uses non-includive
+						// - The original engine does some stupid stuff with spacing
+						// This works correctly in nancy7, but might fail with different games/fonts
+						if (lineNumber != 0) {
+							_imageVerticalOffset += (font->getFontHeight() + 1) / 2 + 1;
+						}
+
+						_fullSurface.blitFrom(image, _imageSrcs[i],
+							Common::Point(	textBounds.left + horizontalOffset + 1,
+											textBounds.top + _numDrawnLines * highlightFont->getFontHeight() + _imageVerticalOffset));
+						_imageVerticalOffset += _imageSrcs[i].height() - 1;
+
+						if (lineNumber == 0) {
+							_imageVerticalOffset += font->getFontHeight() / 2 - 1;
+						} else {
+							_imageVerticalOffset += (font->getFontHeight() + 1) / 2 + 3;
+						}
+					}
+				}
+
+				++numNewlineTokens;
+			}
 
 			// Trim whitespaces (only) at beginning and end of wrapped lines
 			while (line.lastChar() == ' ') {
@@ -220,7 +272,7 @@ void HypertextParser::drawAllText(const Common::Rect &textBounds, uint fontID, u
 				font->drawString(				&_fullSurface,
 												stringToDraw,
 												textBounds.left + horizontalOffset,
-												textBounds.top + _numDrawnLines * font->getFontHeight(),
+												textBounds.top + _numDrawnLines * font->getFontHeight() + _imageVerticalOffset,
 												textBounds.width(),
 												colorID);
 
@@ -229,7 +281,7 @@ void HypertextParser::drawAllText(const Common::Rect &textBounds, uint fontID, u
 					highlightFont->drawString(	&_textHighlightSurface,
 												stringToDraw,
 												textBounds.left + horizontalOffset,
-												textBounds.top + _numDrawnLines * highlightFont->getFontHeight(),
+												textBounds.top + _numDrawnLines * highlightFont->getFontHeight() + _imageVerticalOffset,
 												textBounds.width(),
 												colorID);
 				}
@@ -252,7 +304,25 @@ void HypertextParser::drawAllText(const Common::Rect &textBounds, uint fontID, u
 			++_numDrawnLines;
 
 			// Record the height of the text currently drawn. Used for textbox scrolling
-			_drawnTextHeight = (_numDrawnLines - 1) * font->getFontHeight();
+			_drawnTextHeight = (_numDrawnLines - 1) * font->getFontHeight() + _imageVerticalOffset;
+		}
+
+		// Draw the footer image(s)
+		for (uint i = 0; i < _imageLineIDs.size(); ++i) {
+			if (numNewlineTokens <= _imageLineIDs[i]) {
+				_imageVerticalOffset += (font->getFontHeight() + 1) / 2 + 1;
+
+				_fullSurface.blitFrom(image, _imageSrcs[i],
+					Common::Point(	textBounds.left + horizontalOffset + 1,
+									textBounds.top + _numDrawnLines * highlightFont->getFontHeight() + _imageVerticalOffset));
+				_imageVerticalOffset += _imageSrcs[i].height() - 1;
+
+				if (i < _imageLineIDs.size() - 1) {
+					_imageVerticalOffset += (font->getFontHeight() + 1) / 2 + 3;
+				}
+
+				_drawnTextHeight = (_numDrawnLines - 1) * font->getFontHeight() + _imageVerticalOffset;
+			}
 		}
 
 		// Add the hotspot to the list
diff --git a/engines/nancy/misc/hypertext.h b/engines/nancy/misc/hypertext.h
index a94138cc0bc..177f9dd51bd 100644
--- a/engines/nancy/misc/hypertext.h
+++ b/engines/nancy/misc/hypertext.h
@@ -37,13 +37,16 @@ public:
 		_numDrawnLines(0),
 		_drawnTextHeight(0),
 		_needsTextRedraw(false),
-		_defaultTextColor(0) {}
+		_defaultTextColor(0),
+		_imageVerticalOffset(0) {}
 	virtual ~HypertextParser() {};
 
 protected:
 	void initSurfaces(uint width, uint height, const struct Graphics::PixelFormat &format, uint32 backgroundColor, uint32 highlightBackgroundColor);
 
 	void addTextLine(const Common::String &text);
+	void addImage(uint16 lineID, const Common::Rect &src);
+	void setImageName(const Common::Path &name);
 
 	void drawAllText(const Common::Rect &textBounds, uint fontID, uint highlightFontID);
 	virtual void clear();
@@ -54,10 +57,16 @@ protected:
 	uint32 _backgroundColor;
 	uint32 _highlightBackgroundColor;
 	uint _defaultTextColor;
+	uint _imageVerticalOffset;
 
 	Common::Array<Common::String> _textLines;
 	Common::Array<Common::Rect> _hotspots;
 
+	// Data for displaying images inside text; used in Hypertext
+	Common::Path _imageName;
+	Common::Array<uint16> _imageLineIDs;
+	Common::Array<Common::Rect> _imageSrcs;
+
 	uint16 _numDrawnLines;
 	uint16 _drawnTextHeight;
 	bool _needsTextRedraw;


Commit: f3fee34f42ed2cf0081ccd15f60b894427fc8a68
    https://github.com/scummvm/scummvm/commit/f3fee34f42ed2cf0081ccd15f60b894427fc8a68
Author: Kaloyan Chehlarski (strahy at outlook.com)
Date: 2024-01-30T23:13:12+01:00

Commit Message:
NANCY: Indent Autotext when wrapping

Replicating a bug in the original engine, where a value
from TBOX is used in all rendering, resulting in all wrapped
textlines appearing slightly indented inwards.

Changed paths:
    engines/nancy/action/autotext.cpp
    engines/nancy/misc/hypertext.cpp
    engines/nancy/misc/hypertext.h
    engines/nancy/ui/textbox.cpp


diff --git a/engines/nancy/action/autotext.cpp b/engines/nancy/action/autotext.cpp
index e5509145816..40b276a6f72 100644
--- a/engines/nancy/action/autotext.cpp
+++ b/engines/nancy/action/autotext.cpp
@@ -151,7 +151,11 @@ void Autotext::execute() {
 		textBounds.top += d + 1;
 		textBounds.left += d;
 
-		drawAllText(textBounds, _fontID, _fontID);
+		// Original engine uses a particular value in the TBOX chunk in all
+		// text rendering, including Autotext
+		auto *tbox = GetEngineData(TBOX);
+
+		drawAllText(textBounds, tbox->leftOffset - textBounds.left, _fontID, _fontID);
 	}
 
 	_isDone = true;
diff --git a/engines/nancy/misc/hypertext.cpp b/engines/nancy/misc/hypertext.cpp
index c732d745935..b80d4653681 100644
--- a/engines/nancy/misc/hypertext.cpp
+++ b/engines/nancy/misc/hypertext.cpp
@@ -58,7 +58,7 @@ void HypertextParser::setImageName(const Common::Path &name) {
 	_imageName = name;
 }
 
-void HypertextParser::drawAllText(const Common::Rect &textBounds, uint fontID, uint highlightFontID) {
+void HypertextParser::drawAllText(const Common::Rect &textBounds, uint leftOffsetNonNewline, uint fontID, uint highlightFontID) {
 	using namespace Common;
 
 	const Font *font = nullptr;
@@ -197,12 +197,15 @@ void HypertextParser::drawAllText(const Common::Rect &textBounds, uint fontID, u
 		byte colorID = _defaultTextColor;
 		uint numNewlineTokens = 0;
 		uint horizontalOffset = 0;
+		bool newLineStart = false;
 		for (uint lineNumber = 0; lineNumber < wrappedLines.size(); ++lineNumber) {
 			Common::String &line = wrappedLines[lineNumber];
 			horizontalOffset = 0;
+			newLineStart = false;
 			// Draw images
 			if (newlineTokens.front() <= totalCharsDrawn) {
 				newlineTokens.pop();
+				newLineStart = true;
 
 				for (uint i = 0; i < _imageLineIDs.size(); ++i) {
 					if (numNewlineTokens == _imageLineIDs[i]) {
@@ -271,7 +274,7 @@ void HypertextParser::drawAllText(const Common::Rect &textBounds, uint fontID, u
 				// Draw the normal text
 				font->drawString(				&_fullSurface,
 												stringToDraw,
-												textBounds.left + horizontalOffset,
+												textBounds.left + horizontalOffset + (newLineStart ? 0 : leftOffsetNonNewline),
 												textBounds.top + _numDrawnLines * font->getFontHeight() + _imageVerticalOffset,
 												textBounds.width(),
 												colorID);
@@ -280,7 +283,7 @@ void HypertextParser::drawAllText(const Common::Rect &textBounds, uint fontID, u
 				if (hasHotspot) {
 					highlightFont->drawString(	&_textHighlightSurface,
 												stringToDraw,
-												textBounds.left + horizontalOffset,
+												textBounds.left + horizontalOffset + (newLineStart ? leftOffsetNonNewline : 0),
 												textBounds.top + _numDrawnLines * highlightFont->getFontHeight() + _imageVerticalOffset,
 												textBounds.width(),
 												colorID);
diff --git a/engines/nancy/misc/hypertext.h b/engines/nancy/misc/hypertext.h
index 177f9dd51bd..795c2f76773 100644
--- a/engines/nancy/misc/hypertext.h
+++ b/engines/nancy/misc/hypertext.h
@@ -48,7 +48,7 @@ protected:
 	void addImage(uint16 lineID, const Common::Rect &src);
 	void setImageName(const Common::Path &name);
 
-	void drawAllText(const Common::Rect &textBounds, uint fontID, uint highlightFontID);
+	void drawAllText(const Common::Rect &textBounds, uint leftOffsetNonNewline, uint fontID, uint highlightFontID);
 	virtual void clear();
 
 	Graphics::ManagedSurface _fullSurface; 			// Contains all rendered text (may be cropped)
diff --git a/engines/nancy/ui/textbox.cpp b/engines/nancy/ui/textbox.cpp
index 83abe3b56f9..092214b8de4 100644
--- a/engines/nancy/ui/textbox.cpp
+++ b/engines/nancy/ui/textbox.cpp
@@ -147,9 +147,9 @@ void Textbox::drawTextbox() {
 	const Font *font = g_nancy->_graphicsManager->getFont(_fontIDOverride != -1 ? _fontIDOverride : tbox->defaultFontID);
 	textBounds.top -= font->getFontHeight();
 
-	HypertextParser::drawAllText(	textBounds,															// bounds of text within full surface
+	HypertextParser::drawAllText(	textBounds,	0,													// bounds of text within full surface
 									_fontIDOverride != -1 ? _fontIDOverride : tbox->defaultFontID,	// font for basic text
-									tbox->highlightConversationFontID);									// font for highlight text
+									tbox->highlightConversationFontID);								// font for highlight text
 
 	setVisible(true);
 }




More information about the Scummvm-git-logs mailing list