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

bluegr bluegr at gmail.com
Tue Jun 8 23:16:12 UTC 2021


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:
ae859a44ea TRECISION: Move the texture surface inside GraphicsManager


Commit: ae859a44eaa95e067c87860def912c94145fde62
    https://github.com/scummvm/scummvm/commit/ae859a44eaa95e067c87860def912c94145fde62
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2021-06-09T02:16:00+03:00

Commit Message:
TRECISION: Move the texture surface inside GraphicsManager

This removes the last code that had direct access to the screen buffer

Changed paths:
    engines/trecision/3d.cpp
    engines/trecision/actor.cpp
    engines/trecision/actor.h
    engines/trecision/graphics.cpp
    engines/trecision/graphics.h


diff --git a/engines/trecision/3d.cpp b/engines/trecision/3d.cpp
index 83cb76ffca..ad696f7d05 100644
--- a/engines/trecision/3d.cpp
+++ b/engines/trecision/3d.cpp
@@ -187,11 +187,9 @@ void Renderer3D::textureTriangle(int32 x1, int32 y1, int32 z1, int32 c1, int32 t
 			int32 mtx = ((int32)(_rTextX[y] - (olx = _lTextX[y])) << 16) / dx;
 			// slope dty/_dx
 			int32 mty = ((int32)(_rTextY[y] - (oly = _lTextY[y])) << 16) / dx;
-			// screen offset
-			int32 sl = el + MAXX * y;
 			// pointer to zbuffer
 			int16 *z = _zBuffer + (y - _zBufStartY) * _zBufWid + (el - _zBufStartX);
-			uint16 *screenPtr = _vm->_graphicsMgr->getScreenBufferPtr() + sl;
+			uint16 x = el;
 
 			zl <<= 16;
 			cl <<= 8;
@@ -199,12 +197,14 @@ void Renderer3D::textureTriangle(int32 x1, int32 y1, int32 z1, int32 c1, int32 t
 			oly <<= 16;
 			// loop through every pixel in horizontal scanline
 			while (dx) {
-				sl = zl >> 16;
-				if (*z > sl) {
-					*screenPtr = (uint16)_vm->_actor->_textureMat.getPixel(cl >> 9, texture[(olx >> 16) + t->_dx * (oly >> 16)]);
-					*z = (int16)sl;
+				const int32 screenOffset = zl >> 16;
+				if (*z > screenOffset) {
+					const uint16 textureX = (uint16)(cl >> 9);
+					const uint16 textureY = texture[(olx >> 16) + t->_dx * (oly >> 16)];
+					_vm->_graphicsMgr->drawTexturePixel(textureX, textureY, x, y);
+					*z = (int16)screenOffset;
 				}
-				++screenPtr; // increase screen x
+				++x;         // increase screen x
 				++z;         // increase zbuffer
 				zl += mz;    // increase the zbuffer by _dz/_dx
 				cl += mc;    // increase the color by dc/_dx
diff --git a/engines/trecision/actor.cpp b/engines/trecision/actor.cpp
index 6de09ab7ce..7bde30f35b 100644
--- a/engines/trecision/actor.cpp
+++ b/engines/trecision/actor.cpp
@@ -80,7 +80,6 @@ Actor::~Actor() {
 	delete[] _characterArea;
 	delete[] _face;
 	delete[] _textureData;
-	_textureMat.free();
 }
 
 void Actor::initTextures() {
@@ -329,7 +328,7 @@ void Actor::readModel(const char *filename) {
 	if (ff == nullptr)
 		error("readModel - Error opening file mat.tex");
 
-	_vm->_graphicsMgr->readSurface(ff, &_textureMat, 91, 256);
+	_vm->_graphicsMgr->readTexture(ff);
 
 	for (uint16 i = 0; i < MAXFACE; ++i) {
 		for (uint16 j = 0; j < 3; ++j) {
diff --git a/engines/trecision/actor.h b/engines/trecision/actor.h
index ea3041dbe3..8d0167f110 100644
--- a/engines/trecision/actor.h
+++ b/engines/trecision/actor.h
@@ -57,7 +57,6 @@ public:
 	SCamera *_camera;
 	STexture *_textures;
 
-	Graphics::Surface _textureMat;
 	int16  _textureCoord[MAXFACE][3][2];
 
 	uint32 _vertexNum;
diff --git a/engines/trecision/graphics.cpp b/engines/trecision/graphics.cpp
index 72dcd4fda8..c074e4d7d1 100644
--- a/engines/trecision/graphics.cpp
+++ b/engines/trecision/graphics.cpp
@@ -57,6 +57,8 @@ GraphicsManager::~GraphicsManager() {
 	_rightInventoryArrow.free();
 	_inventoryIcons.free();
 	_saveSlotThumbnails.free();
+	_textureMat.free();
+
 	delete[] _font;
 }
 
@@ -236,10 +238,6 @@ void GraphicsManager::copyToScreen(int x, int y, int w, int h) {
 	);
 }
 
-uint16 *GraphicsManager::getScreenBufferPtr() {
-	return (uint16 *)_screenBuffer.getPixels();
-}
-
 void GraphicsManager::readSurface(Common::SeekableReadStream *stream, Graphics::Surface *surface, uint16 width, uint16 height, uint16 count) {
 	surface->create(width * count, height, kImageFormat);
 
@@ -253,6 +251,15 @@ void GraphicsManager::readSurface(Common::SeekableReadStream *stream, Graphics::
 	surface->convertToInPlace(_screenFormat);
 }
 
+void GraphicsManager::readTexture(Common::SeekableReadStream *stream) {
+	readSurface(stream, &_textureMat, 91, 256);
+}
+
+void GraphicsManager::drawTexturePixel(uint16 textureX, uint16 textureY, uint16 screenX, uint16 screenY) {
+	const uint16 texturePixel = (uint16)_textureMat.getPixel(textureX, textureY);
+	_screenBuffer.setPixel(screenX, screenY, texturePixel);
+}
+
 void GraphicsManager::loadBackground(Common::SeekableReadStream *stream, uint16 width, uint16 height) {
 	readSurface(stream, &_background, width, height);
 	_smkBackground.copyFrom(_background);
diff --git a/engines/trecision/graphics.h b/engines/trecision/graphics.h
index e3cfc22892..ce773d8467 100644
--- a/engines/trecision/graphics.h
+++ b/engines/trecision/graphics.h
@@ -45,6 +45,7 @@ class GraphicsManager {
 	Graphics::Surface _rightInventoryArrow;
 	Graphics::Surface _inventoryIcons;
 	Graphics::Surface _saveSlotThumbnails;
+	Graphics::Surface _textureMat;
 
 	Graphics::PixelFormat _screenFormat;
 	uint16 _bitMask[3];
@@ -76,7 +77,6 @@ public:
 	void copyToScreen(int x, int y, int w, int h);
 	void copyToScreenBuffer(const Graphics::Surface *surface, int x, int y, const byte *palette);
 	void blitToScreenBuffer(const Graphics::Surface *surface, int x, int y, const byte *palette, bool useSmkBg);
-	uint16 *getScreenBufferPtr();
 	void paintScreen(bool flag);
 	void loadBackground(Common::SeekableReadStream *stream, uint16 width, uint16 height);
 	void clearScreenBuffer();
@@ -89,6 +89,8 @@ public:
 	void drawSaveSlotThumbnail(byte iconIndex, byte iconSlot, byte startLine);
 	void setSaveSlotThumbnail(byte iconSlot, const Graphics::Surface *thumbnail);
 	void readSurface(Common::SeekableReadStream *stream, Graphics::Surface *surface, uint16 width, uint16 height, uint16 count = 1);
+	void readTexture(Common::SeekableReadStream *stream);
+	void drawTexturePixel(uint16 textureX, uint16 textureY, uint16 screenX, uint16 screenY);
 
 	uint16 convertToScreenFormat(uint16 color) const;
 




More information about the Scummvm-git-logs mailing list