[Scummvm-git-logs] scummvm master -> 720459c55ac2dbce8637273ce220856b9f7b95d2

athrxx noreply at scummvm.org
Fri Jul 17 19:25:55 UTC 2026


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

Summary:
720459c55a KYRA: (EOB) - minor performance boost


Commit: 720459c55ac2dbce8637273ce220856b9f7b95d2
    https://github.com/scummvm/scummvm/commit/720459c55ac2dbce8637273ce220856b9f7b95d2
Author: athrxx (athrxx at scummvm.org)
Date: 2026-07-17T21:25:25+02:00

Commit Message:
KYRA: (EOB) - minor performance boost

Changed paths:
    engines/kyra/engine/eobcommon.cpp
    engines/kyra/engine/kyra_rpg.cpp
    engines/kyra/engine/kyra_rpg.h
    engines/kyra/engine/scene_rpg.cpp
    engines/kyra/graphics/screen.cpp
    engines/kyra/graphics/screen.h
    engines/kyra/graphics/screen_eob.cpp
    engines/kyra/graphics/screen_eob.h


diff --git a/engines/kyra/engine/eobcommon.cpp b/engines/kyra/engine/eobcommon.cpp
index cff470ec13f..7668eca4373 100644
--- a/engines/kyra/engine/eobcommon.cpp
+++ b/engines/kyra/engine/eobcommon.cpp
@@ -524,7 +524,7 @@ Common::Error EoBCoreEngine::init() {
 
 	_wllVcnOffset = (_flags.platform == Common::kPlatformFMTowns) ? 0 : 16;
 	int bpp = _screen->bytesPerPixel();
-	setVcnFormat(bpp);
+	setVcnFormat(bpp, _configRenderMode);
 
 	_greenFadingTable = new uint8[256 * bpp]();
 	_blueFadingTable = new uint8[256 * bpp]();
diff --git a/engines/kyra/engine/kyra_rpg.cpp b/engines/kyra/engine/kyra_rpg.cpp
index 7d2f5ea4d02..688047a95b7 100644
--- a/engines/kyra/engine/kyra_rpg.cpp
+++ b/engines/kyra/engine/kyra_rpg.cpp
@@ -203,7 +203,7 @@ Common::Error KyraRpgEngine::init() {
 	for (int i = 0; i < 128; i++)
 		_vcnColTable[i] = i & 0x0F;
 
-	setVcnFormat(1);
+	setVcnFormat(1, Common::kRenderDefault);
 
 	_doorShapes = new uint8*[6]();
 
diff --git a/engines/kyra/engine/kyra_rpg.h b/engines/kyra/engine/kyra_rpg.h
index b049dd6383e..9a54b471dfd 100644
--- a/engines/kyra/engine/kyra_rpg.h
+++ b/engines/kyra/engine/kyra_rpg.h
@@ -315,12 +315,12 @@ protected:
 	bool checkSceneUpdateNeed(int block);
 	uint16 calcNewBlockPosition(uint16 curBlock, uint16 direction);
 
-	void setVcnFormat(int outputBPP);
+	void setVcnFormat(int outputBPP, Common::RenderMode renderMode);
 	void drawVcnBlocks();
 	void vcnDraw_fw_4bit(uint8 *&dst, const uint8 *&src);
 	void vcnDraw_bw_4bit(uint8 *&dst, const uint8 *&src);
-	void vcnDraw_fw_trans_4bit(uint8 *&dst, const uint8 *&src);
-	void vcnDraw_bw_trans_4bit(uint8 *&dst, const uint8 *&src);
+	template<bool cga> void vcnDraw_fw_trans_4bit(uint8 *&dst, const uint8 *&src);
+	template<bool cga> void vcnDraw_bw_trans_4bit(uint8 *&dst, const uint8 *&src);
 	template<typename T> void vcnDraw_fw_hiCol(uint8 *&dst, const uint8 *&src);
 	template<typename T> void vcnDraw_bw_hiCol(uint8 *&dst, const uint8 *&src);
 	template<typename T> void vcnDraw_fw_trans_hiCol(uint8 *&dst, const uint8 *&src);
diff --git a/engines/kyra/engine/scene_rpg.cpp b/engines/kyra/engine/scene_rpg.cpp
index 58437e132eb..ccee439213b 100644
--- a/engines/kyra/engine/scene_rpg.cpp
+++ b/engines/kyra/engine/scene_rpg.cpp
@@ -344,7 +344,7 @@ uint16 KyraRpgEngine::calcNewBlockPosition(uint16 curBlock, uint16 direction) {
 	return (curBlock + blockPosTable[direction]) & 0x3FF;
 }
 
-void KyraRpgEngine::setVcnFormat(int outputBPP) {
+void KyraRpgEngine::setVcnFormat(int outputBPP, Common::RenderMode renderMode) {
 	_vcnBpp = outputBPP;
 
 	delete[] _sceneWindowBuffer;
@@ -361,9 +361,12 @@ void KyraRpgEngine::setVcnFormat(int outputBPP) {
 	else if (_flags.platform == Common::kPlatformAmiga || (_flags.gameID == GI_EOB1 && _flags.use16ColorMode))
 		_vcnDrawLine = new VcnLineDrawingMethods(new VcnDrawProc(this, &KyraRpgEngine::vcnDraw_fw_planar), new VcnDrawProc(this, &KyraRpgEngine::vcnDraw_bw_planar),
 			new VcnDrawProc(this, &KyraRpgEngine::vcnDraw_fw_trans_planar), new VcnDrawProc(this, &KyraRpgEngine::vcnDraw_bw_trans_planar));
+	else if (renderMode == Common::kRenderCGA)
+		_vcnDrawLine = new VcnLineDrawingMethods(new VcnDrawProc(this, &KyraRpgEngine::vcnDraw_fw_4bit), new VcnDrawProc(this, &KyraRpgEngine::vcnDraw_bw_4bit),
+			new VcnDrawProc(this, &KyraRpgEngine::vcnDraw_fw_trans_4bit<true>), new VcnDrawProc(this, &KyraRpgEngine::vcnDraw_bw_trans_4bit<true>));
 	else
 		_vcnDrawLine = new VcnLineDrawingMethods(new VcnDrawProc(this, &KyraRpgEngine::vcnDraw_fw_4bit), new VcnDrawProc(this, &KyraRpgEngine::vcnDraw_bw_4bit),
-			new VcnDrawProc(this, &KyraRpgEngine::vcnDraw_fw_trans_4bit), new VcnDrawProc(this, &KyraRpgEngine::vcnDraw_bw_trans_4bit));
+			new VcnDrawProc(this, &KyraRpgEngine::vcnDraw_fw_trans_4bit<false>), new VcnDrawProc(this, &KyraRpgEngine::vcnDraw_bw_trans_4bit<false>));
 }
 
 void KyraRpgEngine::drawVcnBlocks() {
@@ -463,20 +466,20 @@ void KyraRpgEngine::vcnDraw_bw_4bit(uint8 *&dst, const uint8 *&src) {
 	src += 5;
 }
 
-void KyraRpgEngine::vcnDraw_fw_trans_4bit(uint8 *&dst, const uint8 *&src) {
+template<bool cga> void KyraRpgEngine::vcnDraw_fw_trans_4bit(uint8 *&dst, const uint8 *&src) {
 	for (int blockX = 0; blockX < 4; blockX++) {
 		uint8 bl = *src++;
-		uint8 mask = _vcnTransitionMask ? *_vcnMaskTbl++ : 0;
+		uint8 mask = cga ? *_vcnMaskTbl++ : 0;
 		uint8 h = _vcnColTable[((bl >> 4) + _wllVcnRmdOffset) | _vcnShiftVal];
 		uint8 l = _vcnColTable[((bl & 0x0F) + _wllVcnRmdOffset) | _vcnShiftVal];
 
-		if (_vcnTransitionMask)
+		if (cga)
 			*dst = (*dst & (mask >> 4)) | h;
 		else if (h)
 			*dst = h;
 		dst++;
 
-		if (_vcnTransitionMask)
+		if (cga)
 			*dst = (*dst & (mask & 0x0F)) | l;
 		else if (l)
 			*dst = l;
@@ -484,31 +487,38 @@ void KyraRpgEngine::vcnDraw_fw_trans_4bit(uint8 *&dst, const uint8 *&src) {
 	}
 }
 
-void KyraRpgEngine::vcnDraw_bw_trans_4bit(uint8 *&dst, const uint8 *&src) {
+template<bool cga> void KyraRpgEngine::vcnDraw_bw_trans_4bit(uint8 *&dst, const uint8 *&src) {
 	src += 3;
-	_vcnMaskTbl += 3;
+	if (cga)
+		_vcnMaskTbl += 3;
 	for (int blockX = 0; blockX < 4; blockX++) {
 		uint8 bl = *src--;
-		uint8 mask = _vcnTransitionMask ? *_vcnMaskTbl-- : 0;
+		uint8 mask = cga ? *_vcnMaskTbl-- : 0;
 		uint8 h = _vcnColTable[((bl & 0x0F) + _wllVcnRmdOffset) | _vcnShiftVal];
 		uint8 l = _vcnColTable[((bl >> 4) + _wllVcnRmdOffset) | _vcnShiftVal];
 
-		if (_vcnTransitionMask)
+		if (cga)
 			*dst = (*dst & (mask & 0x0F)) | h;
 		else if (h)
 			*dst = h;
 		dst++;
 
-		if (_vcnTransitionMask)
+		if (cga)
 			*dst = (*dst & (mask >> 4)) | l;
 		else if (l)
 			*dst = l;
 		dst++;
 	}
 	src += 5;
-	_vcnMaskTbl += 5;
+	if (cga)
+		_vcnMaskTbl += 5;
 }
 
+template void KyraRpgEngine::vcnDraw_fw_trans_4bit<true>(uint8 *&dst, const uint8 *&src);
+template void KyraRpgEngine::vcnDraw_bw_trans_4bit<true>(uint8 *&dst, const uint8 *&src);
+template void KyraRpgEngine::vcnDraw_fw_trans_4bit<false>(uint8 *&dst, const uint8 *&src);
+template void KyraRpgEngine::vcnDraw_bw_trans_4bit<false>(uint8 *&dst, const uint8 *&src);
+
 template<typename T> void KyraRpgEngine::vcnDraw_fw_hiCol(uint8 *&dst, const uint8 *&src) {
 	const T *hiColorPal = reinterpret_cast<const T*>(screen()->getHiColorPalette());
 	T *d = reinterpret_cast<T*>(dst);
diff --git a/engines/kyra/graphics/screen.cpp b/engines/kyra/graphics/screen.cpp
index fcc1315c813..2ec438c65b5 100644
--- a/engines/kyra/graphics/screen.cpp
+++ b/engines/kyra/graphics/screen.cpp
@@ -80,7 +80,6 @@ Screen::Screen(KyraEngine_v1 *vm, OSystem *system, const ScreenDim *dimTable, co
 	_textRenderBufferSize = 0;
 
 	_outputPixelFormat = Graphics::PixelFormat::createFormatCLUT8();
-	_useShapeShading = true;
 	_screenPageSize = SCREEN_PAGE_SIZE;
 	_hiColorNativePalettes = nullptr;
 	_hiColorConversionPalette = nullptr;
diff --git a/engines/kyra/graphics/screen.h b/engines/kyra/graphics/screen.h
index 27b0f12cca7..92605cdaab3 100644
--- a/engines/kyra/graphics/screen.h
+++ b/engines/kyra/graphics/screen.h
@@ -891,7 +891,6 @@ protected:
 
 	// colors/palette specific
 	bool _use16ColorMode;
-	bool _useShapeShading;
 	bool _4bitPixelPacking;
 	bool _useHiResEGADithering;
 	Graphics::PixelFormat _outputPixelFormat;
diff --git a/engines/kyra/graphics/screen_eob.cpp b/engines/kyra/graphics/screen_eob.cpp
index 3dcb2814e0d..63ef1af881a 100644
--- a/engines/kyra/graphics/screen_eob.cpp
+++ b/engines/kyra/graphics/screen_eob.cpp
@@ -107,6 +107,7 @@ Screen_EoB::Screen_EoB(EoBCoreEngine *vm, OSystem *system) : Screen(vm, system,
 	_defaultRenderBuffer = 0;
 	_defaultRenderBufferSize = 0;
 	_specialColorReplace = false;
+	_drawShapeSetPixel = nullptr;
 	memset(_segaCurPalette, 0, sizeof(_segaCurPalette));
 }
 
@@ -127,6 +128,11 @@ Screen_EoB::~Screen_EoB() {
 	delete _segaAnimator;
 }
 
+template void Screen_EoB::drawShapeSetPixel<uint8, false>(uint8 *dst, uint8 col);
+template void Screen_EoB::drawShapeSetPixel<uint16, false>(uint8 *dst, uint8 col);
+template void Screen_EoB::drawShapeSetPixel<uint32, false>(uint8 *dst, uint8 col);
+template void Screen_EoB::drawShapeSetPixel<uint8, true>(uint8 *dst, uint8 col);
+
 bool Screen_EoB::init() {
 	if (Screen::init()) {
 		int temp;
@@ -172,7 +178,18 @@ bool Screen_EoB::init() {
 			sega_setTextBuffer(0, 0);
 		}
 
-		_useShapeShading = (_internalBytesPerPixel == 1 && !_isAmiga && !_isSegaCD && !_use16ColorMode && _renderMode != Common::kRenderCGA && _renderMode != Common::kRenderEGA) || _useHiResEGADithering;
+		static const DrawShapePlotFunc drawShapePlotFuncs[4] = {
+			&Screen_EoB::drawShapeSetPixel<uint8, false>,
+			&Screen_EoB::drawShapeSetPixel<uint16, false>,
+			&Screen_EoB::drawShapeSetPixel<uint32, false>,
+			&Screen_EoB::drawShapeSetPixel<uint8, true>
+		};
+
+		int index = (_internalBytesPerPixel >> 1);
+		if ((_internalBytesPerPixel == 1 && !_isAmiga && !_isSegaCD && !_use16ColorMode && _renderMode != Common::kRenderCGA && _renderMode != Common::kRenderEGA) || _useHiResEGADithering)
+			index += 3;
+		_drawShapeSetPixel = drawShapePlotFuncs[index];
+		assert(_drawShapeSetPixel);
 
 		static const char *cpsExt[] = { "CPS", "EGA", "SHP", "BIN" };
 		int ci = 0;
@@ -846,7 +863,7 @@ void Screen_EoB::drawT1Shape(uint8 pageNum, const byte *t1data, int x, int y, in
 
 		for (int i = 0; i < rW; i++, src2++, dst += _internalBytesPerPixel)
 			if (*src2)
-				drawShapeSetPixel(dst, *src2);
+				(this->*_drawShapeSetPixel)(dst, *src2);
 
 		dstL += SCREEN_W * _internalBytesPerPixel;
 		src += width;
@@ -1006,7 +1023,7 @@ void Screen_EoB::drawShape(uint8 pageNum, const uint8 *shapeData, int x, int y,
 				src += pixelStep;
 
 				if (m) {
-					drawShapeSetPixel(dst, c);
+					(this->*_drawShapeSetPixel)(dst, c);
 					dst += _internalBytesPerPixel;
 					xpos--;
 				} else if (pixelsPerByte) {
@@ -1161,7 +1178,7 @@ void Screen_EoB::drawShape(uint8 pageNum, const uint8 *shapeData, int x, int y,
 				}
 				uint8 col = (pixelsPerByte == 2) ? pal[(in >> shift) & pixelPackingMask] : (*dst & ((trans >> shift) & (pixelPackingMask))) | pal[(in >> shift) & pixelPackingMask];
 				if (col || pixelsPerByte == 4)
-					drawShapeSetPixel(dst, col);
+					(this->*_drawShapeSetPixel)(dst, col);
 				dst += _internalBytesPerPixel;
 				shift = ((shift - (pixelStep * pixelPacking)) & 7);
 			}
@@ -1199,6 +1216,9 @@ const uint8 *Screen_EoB::scaleShapeStep(const uint8 *shp) {
 	shp += 3;
 	d += 3;
 
+	_dsDiv = w2 / 3;
+	_dsRem = w2 % 3;
+
 	if (pixelsPerByte == 2) {
 		int i = 0;
 		while (i < 16) {
@@ -1217,25 +1237,26 @@ const uint8 *Screen_EoB::scaleShapeStep(const uint8 *shp) {
 		_dsScaleTrans = (i << 4) | (i & 0x0F);
 		for (int ii = 0; ii < 16; ii++)
 			*d++ = *shp++;
-	}
-
-	_dsDiv = w2 / 3;
-	_dsRem = w2 % 3;
 
-	while (--h) {
-		if (pixelsPerByte == 2)
+		while (--h) {
 			scaleShapeProcessLine4Bit(d, shp);
-		else
-			scaleShapeProcessLine2Bit(d, shp, transOffsetDst, transOffsetSrc);
-		if (!--h)
-			break;
-		if (pixelsPerByte == 2)
+			if (!--h)
+				break;
 			scaleShapeProcessLine4Bit(d, shp);
-		else
+			if (!--h)
+				break;
+			shp += w2;
+		}
+	} else {
+		while (--h) {
 			scaleShapeProcessLine2Bit(d, shp, transOffsetDst, transOffsetSrc);
-		if (!--h)
-			break;
-		shp += w2;
+			if (!--h)
+				break;
+			scaleShapeProcessLine2Bit(d, shp, transOffsetDst, transOffsetSrc);
+			if (!--h)
+				break;
+			shp += w2;
+		}
 	}
 
 	return (const uint8 *)dst;
@@ -1860,32 +1881,29 @@ void Screen_EoB::ditherRect(const uint8 *src, uint8 *dst, int dstPitch, int srcW
 	}
 }
 
-void Screen_EoB::drawShapeSetPixel(uint8 *dst, uint8 col) {
-	if (_internalBytesPerPixel == 4) {
-		*reinterpret_cast<uint32*>(dst) = reinterpret_cast<const uint32*>(_hiColorNativePalettes)[(_dsShapeFadingLevel << 8) + col];
-		return;
-	} else if (_internalBytesPerPixel == 2) {
-		*reinterpret_cast<uint16*>(dst) = reinterpret_cast<const uint16*>(_hiColorNativePalettes)[(_dsShapeFadingLevel << 8) + col];
-		return;
-	} else if (_useShapeShading) {
-		if (_dsBackgroundFading) {
-			if (_dsShapeFadingLevel) {
-				col = *dst;
-			} else {
-				_dsBackgroundFadingXOffs &= 7;
-				col = *(dst + _dsBackgroundFadingXOffs++);
+template<typename pixelType, bool shapeFading> void Screen_EoB::drawShapeSetPixel(uint8 *dst, uint8 col) {
+	if (sizeof(pixelType) > 1) {
+		*reinterpret_cast<pixelType*>(dst) = reinterpret_cast<const pixelType*>(_hiColorNativePalettes)[(_dsShapeFadingLevel << 8) + col];
+	} else {
+		if (shapeFading) {
+			if (_dsBackgroundFading) {
+				if (_dsShapeFadingLevel) {
+					col = *dst;
+				} else {
+					_dsBackgroundFadingXOffs &= 7;
+					col = *(dst + _dsBackgroundFadingXOffs++);
+				}
 			}
-		}
 
-		if (_dsShapeFadingLevel) {
-			assert(_dsShapeFadingTable);
-			uint8 cnt = _dsShapeFadingLevel;
-			while (cnt--)
-				col = _dsShapeFadingTable[col];
+			if (_dsShapeFadingLevel) {
+				assert(_dsShapeFadingTable);
+				uint8 cnt = _dsShapeFadingLevel;
+				while (cnt--)
+					col = _dsShapeFadingTable[col];
+			}
 		}
+		*dst = col;
 	}
-
-	*dst = col;
 }
 
 void Screen_EoB::scaleShapeProcessLine2Bit(uint8 *&shpDst, const uint8 *&shpSrc, uint32 transOffsetDst, uint32 transOffsetSrc) {
diff --git a/engines/kyra/graphics/screen_eob.h b/engines/kyra/graphics/screen_eob.h
index 5bd95090a7e..02529345142 100644
--- a/engines/kyra/graphics/screen_eob.h
+++ b/engines/kyra/graphics/screen_eob.h
@@ -166,7 +166,7 @@ private:
 	void updateDirtyRects() override;
 	void ditherRect(const uint8 *src, uint8 *dst, int dstPitch, int srcW, int srcH, int colorKey = -1);
 
-	void drawShapeSetPixel(uint8 *dst, uint8 col);
+	template<typename pixelType	, bool shapeFading>	void drawShapeSetPixel(uint8 *dst, uint8 col);
 	void scaleShapeProcessLine2Bit(uint8 *&shpDst, const uint8 *&shpSrc, uint32 transOffsetDst, uint32 transOffsetSrc);
 	void scaleShapeProcessLine4Bit(uint8 *&dst, const uint8 *&src);
 	bool posWithinRect(int posX, int posY, int x1, int y1, int x2, int y2);
@@ -176,6 +176,9 @@ private:
 	void generateEGADitheringTable(const Palette &pal);
 	void generateCGADitheringTables(const uint8 *mappingData);
 
+	typedef void (Screen_EoB::*DrawShapePlotFunc)(uint8*, uint8);
+	DrawShapePlotFunc _drawShapeSetPixel;
+
 	int _dsDiv, _dsRem, _dsScaleTrans;
 	uint8 *_cgaScaleTable;
 	int16 _gfxX, _gfxY;




More information about the Scummvm-git-logs mailing list