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

AndywinXp noreply at scummvm.org
Wed Sep 27 20:03:25 UTC 2023


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

Summary:
b6efe60385 SWORD1: DEMO: Implement accurate text rendering


Commit: b6efe6038522f6ce3b4053974c8eab77b7312665
    https://github.com/scummvm/scummvm/commit/b6efe6038522f6ce3b4053974c8eab77b7312665
Author: AndywinXp (andywinxp at gmail.com)
Date: 2023-09-27T22:03:20+02:00

Commit Message:
SWORD1: DEMO: Implement accurate text rendering

The differences have been discovered in a disasm of the
UK demo executable.

Changed paths:
    engines/sword1/control.cpp
    engines/sword1/logic.cpp
    engines/sword1/text.cpp


diff --git a/engines/sword1/control.cpp b/engines/sword1/control.cpp
index 8ea5d039140..ed0fdc48b8d 100644
--- a/engines/sword1/control.cpp
+++ b/engines/sword1/control.cpp
@@ -697,7 +697,10 @@ void Control::renderText(const uint8 *str, int32 x, int32 y, bool useSpeechFont)
 		}
 
 		l += _resMan->getUint16(f->width);
-		l -= useSpeechFont ? SP_OVERLAP : OVERLAP;
+
+		if (!SwordEngine::_systemVars.isDemo)
+			l -= useSpeechFont ? SP_OVERLAP : OVERLAP;
+
 		i += 1;
 	}
 }
@@ -737,7 +740,11 @@ void Control::renderRedText(const uint8 *str, int32 x, int32 y) {
 			}
 		}
 
-		l += (_resMan->getUint16(f->width) - OVERLAP);
+		l += _resMan->getUint16(f->width);
+
+		if (!SwordEngine::_systemVars.isDemo)
+			l -= OVERLAP;
+
 		i += 1;
 	}
 }
@@ -791,7 +798,10 @@ int32 Control::getTextLength(const uint8 *str, bool useSpeechFont) {
 	while (str[i] != 0) {
 		f = (FrameHeader *)((uint8 *)srFont +  _resMan->getUint32(srFont->spriteOffset[str[i] - 32]));
 		l += _resMan->getUint16(f->width);
-		l -= useSpeechFont ? SP_OVERLAP : OVERLAP;
+
+		if (!SwordEngine::_systemVars.isDemo)
+			l -= useSpeechFont ? SP_OVERLAP : OVERLAP;
+
 		i += 1;
 	}
 
diff --git a/engines/sword1/logic.cpp b/engines/sword1/logic.cpp
index 4abaa6750b4..7131676caa7 100644
--- a/engines/sword1/logic.cpp
+++ b/engines/sword1/logic.cpp
@@ -1205,8 +1205,8 @@ int Logic::fnISpeak(Object *cpt, int32 id, int32 cdt, int32 textNo, int32 spr, i
 
 		// now set text coords, above the player, usually
 
-#define TEXT_MARGIN 3 // distance kept from edges of screen
-#define ABOVE_HEAD 20 // distance kept above talking sprite
+		int textMargin = SwordEngine::_systemVars.isDemo ? 5 : 3; // distance kept from edges of screen
+		int aboveHead = SwordEngine::_systemVars.isDemo ? 10 : 20; // distance kept above talking sprite
 		uint16 textX, textY;
 		if (((id == GEORGE) || ((id == NICO) && (_scriptVars[SCREEN] == 10))) && (!cpt->o_anim_resource)) {
 			// if George is doing Voice-Over text (centered at the bottom of the screen)
@@ -1218,14 +1218,14 @@ int Logic::fnISpeak(Object *cpt, int32 id, int32 cdt, int32 textNo, int32 spr, i
 			else
 				textX = (cpt->o_mouse_x1 + cpt->o_mouse_x2) / 2 - textSpriteWidth / 2;
 
-			textY = cpt->o_mouse_y1 - textSpriteHeight - ABOVE_HEAD;
+			textY = cpt->o_mouse_y1 - textSpriteHeight - aboveHead;
 		}
 		// now ensure text is within visible screen
 		uint16 textLeftMargin, textRightMargin, textTopMargin, textBottomMargin;
-		textLeftMargin   = SCREEN_LEFT_EDGE   + TEXT_MARGIN + _scriptVars[SCROLL_OFFSET_X];
-		textRightMargin  = SCREEN_RIGHT_EDGE  - TEXT_MARGIN + _scriptVars[SCROLL_OFFSET_X] - textSpriteWidth;
-		textTopMargin    = SCREEN_TOP_EDGE    + TEXT_MARGIN + _scriptVars[SCROLL_OFFSET_Y];
-		textBottomMargin = SCREEN_BOTTOM_EDGE - TEXT_MARGIN + _scriptVars[SCROLL_OFFSET_Y] - textSpriteHeight;
+		textLeftMargin   = SCREEN_LEFT_EDGE   + textMargin + _scriptVars[SCROLL_OFFSET_X];
+		textRightMargin  = SCREEN_RIGHT_EDGE  - textMargin + _scriptVars[SCROLL_OFFSET_X] - textSpriteWidth;
+		textTopMargin    = SCREEN_TOP_EDGE    + textMargin + _scriptVars[SCROLL_OFFSET_Y];
+		textBottomMargin = SCREEN_BOTTOM_EDGE - textMargin + _scriptVars[SCROLL_OFFSET_Y] - textSpriteHeight;
 
 		textCpt->o_anim_x = textCpt->o_xcoord = CLIP<uint16>(textX, textLeftMargin, textRightMargin);
 		textCpt->o_anim_y = textCpt->o_ycoord = CLIP<uint16>(textY, textTopMargin, textBottomMargin);
diff --git a/engines/sword1/text.cpp b/engines/sword1/text.cpp
index 89b01d6336b..84b87b7307b 100644
--- a/engines/sword1/text.cpp
+++ b/engines/sword1/text.cpp
@@ -35,10 +35,11 @@
 
 namespace Sword1 {
 
-#define OVERLAP 3
+#define OVERLAP       3
+#define DEMO_OVERLAP  1
 #define DEBUG_OVERLAP 2
-#define SPACE ' '
-#define MAX_LINES       30
+#define SPACE         ' '
+#define MAX_LINES     30
 
 
 Text::Text(SwordEngine *vm, Logic *pLogic, ObjectMan *pObjMan, ResMan *pResMan, Screen *pScreen, bool czechVersion) {
@@ -51,7 +52,14 @@ Text::Text(SwordEngine *vm, Logic *pLogic, ObjectMan *pObjMan, ResMan *pResMan,
 	_fontId = (czechVersion) ? CZECH_GAME_FONT : GAME_FONT;
 	_font = (uint8 *)_resMan->openFetchRes(_fontId);
 
-	_joinWidth = charWidth(SPACE) - 2 * OVERLAP;
+	_joinWidth = charWidth(SPACE);
+
+	if (!SwordEngine::_systemVars.isDemo) {
+		_joinWidth -= 2 * OVERLAP;
+	} else {
+		_joinWidth -= 2 * DEMO_OVERLAP;
+	}
+
 	_charHeight = _resMan->getUint16(_resMan->fetchFrame(_font, 0)->height); // all chars have the same height
 	for (int i = 0; i < MAX_TEXT_OBS; i++)
 		_textBlocks[i] = NULL;
@@ -112,8 +120,16 @@ void Text::makeTextSprite(uint8 slot, const uint8 *text, uint16 maxWidth, uint8
 			textString = Common::convertBiDiString(textLogical, Common::kWindows1255);
 			curTextLine = (const uint8 *)textString.c_str();
 		}
-		for (uint16 pos = 0; pos < lines[lineCnt].length; pos++)
-			sprPtr += copyChar(*curTextLine++, sprPtr, sprWidth, pen) - OVERLAP;
+		for (uint16 pos = 0; pos < lines[lineCnt].length; pos++) {
+			sprPtr += copyChar(*curTextLine++, sprPtr, sprWidth, pen);
+
+			if (!SwordEngine::_systemVars.isDemo) {
+				sprPtr -= OVERLAP;
+			} else {
+				sprPtr -= DEMO_OVERLAP;
+			}
+		}
+
 		curTextLine++; // skip space at the end of the line
 		text += lines[lineCnt].length + 1;
 
@@ -139,14 +155,28 @@ uint16 Text::analyzeSentence(const uint8 *text, uint16 maxWidth, LineInfo *line)
 		uint16 wordLength = 0;
 
 		while ((*text != SPACE) && *text) {
-			wordWidth += charWidth(*text) - OVERLAP;
+			wordWidth += charWidth(*text);
+
+			if (!SwordEngine::_systemVars.isDemo) {
+				wordWidth -= OVERLAP;
+			} else {
+				wordWidth -= DEMO_OVERLAP;
+			}
+
 			wordLength++;
 			text++;
 		}
+
 		if (*text == SPACE)
 			text++;
 
-		wordWidth += OVERLAP; // no overlap on final letter of word!
+		// no overlap on final letter of word!
+		if (!SwordEngine::_systemVars.isDemo) {
+			wordWidth += OVERLAP;
+		} else {
+			wordWidth += DEMO_OVERLAP;
+		}
+
 		if (firstWord)  { // first word on first line, so no separating SPACE needed
 			line[0].width = wordWidth;
 			line[0].length = wordLength;




More information about the Scummvm-git-logs mailing list