[Scummvm-git-logs] scummvm master -> 880d8261a78429abecbe0b53645747a365bcc444

mgerhardy martin.gerhardy at gmail.com
Sun Nov 29 22:51:05 UTC 2020


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

Summary:
55f558a110 TWINE: renamed variables and simplified code
b03fd3cba0 TWINE: replaced magic numbers
d992f58cdc TWINE: unified code
3427af227f TWINE: added assert to polygon handling
ae97d0bbbe TWINE: refactored polygon rendering code
0c2064ede2 TWINE: refactored polygon rendering code
ad8d15d807 TWINE: disabled unused code
3e7ba63b83 TWINE: fixed segfault in give_key debug command
fa1808b1c0 TWINE: refactored line rendering
938b438b0e TWINE: use size of struct for raw buffer arithmetic,...
1926f690fc TWINE: refactored rendering code
f5a13ed5a5 TWINE: inlined one of the renderPolygons methods
a75a08cd0e TWINE: cleanup and refactored rendering code
a71b3a3ac0 TWINE: reduced code duplication
91dc794937 TWINE: split render command buffer handling into several methods
1d08ac4ea6 TWINE: renamed structs
eb2f00a74a TWINE: group render command structs
f0fb127429 TWINE: renamed struct
78ec56e0c3 TWINE: removed dead code
df77fff8e8 TWINE: convert member to local var
c7a09011e7 TWINE: replaced magic numbers
880d8261a7 TWINE: refactored matrices


Commit: 55f558a1109c15c1a18b81eb75f672d4bfeff8ef
    https://github.com/scummvm/scummvm/commit/55f558a1109c15c1a18b81eb75f672d4bfeff8ef
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-11-29T23:50:28+01:00

Commit Message:
TWINE: renamed variables and simplified code

Changed paths:
    engines/twine/renderer.cpp
    engines/twine/renderer.h


diff --git a/engines/twine/renderer.cpp b/engines/twine/renderer.cpp
index 0dd94afc7e..1907e17cb5 100644
--- a/engines/twine/renderer.cpp
+++ b/engines/twine/renderer.cpp
@@ -1026,7 +1026,7 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 	Common::MemoryReadStream stream(ptr, 100000);
 	int16 numPolygons = stream.readSint16LE();
 
-	uint8 *edi = renderTab7;           // renderTab7 coordinates buffer
+	uint8 *renderBufferPtr = renderCoordinatesBuffer;
 
 	uint8 *afterPolyHeaderPtr = nullptr; // RECHECK THIS
 
@@ -1034,27 +1034,24 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 		int16 primitiveCounter = numPolygons; // the number of primitives = the number of polygons
 
 		do { // loop that load all the polygons
-			uint8 *render23 = edi;
 			polyHeader currentPolyHeader;
 			currentPolyHeader.renderType = stream.readByte();
 			currentPolyHeader.numOfVertex = stream.readByte();
 			currentPolyHeader.colorIndex = stream.readSint16LE();
-			int16 polyRenderType = currentPolyHeader.renderType;
 			int32 bestDepth = -32000;
+			polyHeader *destinationHeader = (polyHeader *)renderBufferPtr;
 
 			// TODO: RECHECK coordinates axis
-			if (polyRenderType >= 9) {
-				polyHeader *destinationHeader = (polyHeader *)edi;
-
+			if (currentPolyHeader.renderType >= 9) {
 				destinationHeader->renderType = currentPolyHeader.renderType - 2;
 				destinationHeader->numOfVertex = currentPolyHeader.numOfVertex;
 				destinationHeader->colorIndex = currentPolyHeader.colorIndex;
 
-				edi += 4;
+				renderBufferPtr += 4;
 
 				int16 counter = destinationHeader->numOfVertex;
 
-				afterPolyHeaderPtr = edi;
+				afterPolyHeaderPtr = renderBufferPtr;
 
 				do {
 					polyVertexHeader currentPolyVertex;
@@ -1063,7 +1060,7 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 
 					int16 shadeValue = currentPolyHeader.colorIndex + shadeTable[currentPolyVertex.shadeEntry];
 
-					computedVertex *currentComputedVertex = (computedVertex *)edi;
+					computedVertex *currentComputedVertex = (computedVertex *)renderBufferPtr;
 
 					currentComputedVertex->shadeValue = shadeValue;
 
@@ -1072,24 +1069,22 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 					currentComputedVertex->x = currentVertex->x;
 					currentComputedVertex->y = currentVertex->y;
 
-					edi += 6;
+					renderBufferPtr += 6;
 
 					int32 currentDepth = currentVertex->z;
 					if (currentDepth > bestDepth) {
 						bestDepth = currentDepth;
 					}
 				} while (--counter > 0);
-			} else if (polyRenderType >= POLYGONTYPE_GOURAUD) { // only 1 shade value is used
-				polyHeader *destinationHeader = (polyHeader *)edi;
-
-				destinationHeader->renderType = currentPolyHeader.renderType - 7;
+			} else if (currentPolyHeader.renderType >= POLYGONTYPE_GOURAUD) { // only 1 shade value is used
+				destinationHeader->renderType = currentPolyHeader.renderType - POLYGONTYPE_GOURAUD;
 				destinationHeader->numOfVertex = currentPolyHeader.numOfVertex;
 				const int16 shadeEntry = stream.readSint16LE();
 				const int16 shadeValue = currentPolyHeader.colorIndex + shadeTable[shadeEntry];
 				destinationHeader->colorIndex = shadeValue;
 
-				edi += 4;
-				afterPolyHeaderPtr = edi;
+				renderBufferPtr += 4;
+				afterPolyHeaderPtr = renderBufferPtr;
 				int16 counter = destinationHeader->numOfVertex;
 
 				do {
@@ -1097,12 +1092,12 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 
 					pointTab *currentVertex = &flattenPoints[eax / sizeof(pointTab)];
 
-					computedVertex *currentComputedVertex = (computedVertex *)edi;
+					computedVertex *currentComputedVertex = (computedVertex *)renderBufferPtr;
 					//currentComputedVertex->shadeValue = 0;
 					currentComputedVertex->x = currentVertex->x;
 					currentComputedVertex->y = currentVertex->y;
 
-					edi += 6;
+					renderBufferPtr += 6;
 
 					int32 currentDepth = currentVertex->z;
 					if (currentDepth > bestDepth) {
@@ -1110,29 +1105,26 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 					}
 				} while (--counter > 0);
 			} else { // no shade is used
-				polyHeader *destinationHeader = (polyHeader *)edi;
-
 				destinationHeader->renderType = currentPolyHeader.renderType;
 				destinationHeader->numOfVertex = currentPolyHeader.numOfVertex;
 				destinationHeader->colorIndex = currentPolyHeader.colorIndex;
 
-				edi += 4;
+				renderBufferPtr += 4;
 
-				afterPolyHeaderPtr = edi;
-				int32 eax = 0;
+				afterPolyHeaderPtr = renderBufferPtr;
 				int16 counter = currentPolyHeader.numOfVertex;
 
 				do {
-					eax = stream.readSint16LE();
+					int32 eax = stream.readSint16LE();
 
 					pointTab *currentVertex = &flattenPoints[eax / sizeof(pointTab)];
 
-					computedVertex *currentComputedVertex = (computedVertex *)edi;
+					computedVertex *currentComputedVertex = (computedVertex *)renderBufferPtr;
 					//currentComputedVertex->shadeValue = 0;
 					currentComputedVertex->x = currentVertex->x;
 					currentComputedVertex->y = currentVertex->y;
 
-					edi += 6;
+					renderBufferPtr += 6;
 
 					int32 currentDepth = currentVertex->z;
 					if (currentDepth > bestDepth) {
@@ -1164,7 +1156,7 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 
 			(*renderTabEntryPtr)->depth = bestDepth;
 			(*renderTabEntryPtr)->renderType = 1;
-			(*renderTabEntryPtr)->dataPtr = render23;
+			(*renderTabEntryPtr)->dataPtr = (uint8*)destinationHeader;
 			(*renderTabEntryPtr)++;
 		} while (--primitiveCounter);
 	}
@@ -1180,7 +1172,7 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 			stream.skip(3);
 			line.p1 = stream.readSint16LE();
 			line.p2 = stream.readSint16LE();
-			lineCoordinates *lineCoordinatesPtr = (lineCoordinates *)edi;
+			lineCoordinates *lineCoordinatesPtr = (lineCoordinates *)renderBufferPtr;
 
 			if (line.p1 % 6 != 0 || line.p2 % 6 != 0) {
 				error("RENDER ERROR: lineDataPtr reference is malformed!");
@@ -1202,10 +1194,10 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 
 			(*renderTabEntryPtr)->depth = bestDepth;
 			(*renderTabEntryPtr)->renderType = 0;
-			(*renderTabEntryPtr)->dataPtr = edi;
+			(*renderTabEntryPtr)->dataPtr = renderBufferPtr;
 			(*renderTabEntryPtr)++;
 
-			edi += 12;
+			renderBufferPtr += 12;
 		} while (--temp);
 	}
 
@@ -1220,17 +1212,17 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 			int16 size = stream.readUint16LE();
 			int16 center = stream.readUint16LE();
 
-			*(uint8 *)edi = color2;
-			*((int16 *)(edi + 1)) = flattenPoints[center / sizeof(pointTab)].x;
-			*((int16 *)(edi + 3)) = flattenPoints[center / sizeof(pointTab)].y;
-			*((int16 *)(edi + 5)) = size;
+			*(uint8 *)renderBufferPtr = color2;
+			*((int16 *)(renderBufferPtr + 1)) = flattenPoints[center / sizeof(pointTab)].x;
+			*((int16 *)(renderBufferPtr + 3)) = flattenPoints[center / sizeof(pointTab)].y;
+			*((int16 *)(renderBufferPtr + 5)) = size;
 
 			(*renderTabEntryPtr)->depth = flattenPoints[center / sizeof(pointTab)].z;
 			(*renderTabEntryPtr)->renderType = 2;
-			(*renderTabEntryPtr)->dataPtr = edi;
+			(*renderTabEntryPtr)->dataPtr = renderBufferPtr;
 			(*renderTabEntryPtr)++;
 
-			edi += 7;
+			renderBufferPtr += 7;
 		} while (--temp);
 	}
 
diff --git a/engines/twine/renderer.h b/engines/twine/renderer.h
index 5db653c14c..92279964d3 100644
--- a/engines/twine/renderer.h
+++ b/engines/twine/renderer.h
@@ -196,7 +196,7 @@ private:
 
 	renderTabEntry renderTab[1000];
 	renderTabEntry renderTabSorted[1000];
-	uint8 renderTab7[10000] {0};
+	uint8 renderCoordinatesBuffer[10000] {0};
 
 	int16 polyTab[960] {0};
 	int16 polyTab2[960] {0};


Commit: b03fd3cba0fd4e077409ff81460294d3dd5caa77
    https://github.com/scummvm/scummvm/commit/b03fd3cba0fd4e077409ff81460294d3dd5caa77
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-11-29T23:50:28+01:00

Commit Message:
TWINE: replaced magic numbers

Changed paths:
    engines/twine/renderer.cpp


diff --git a/engines/twine/renderer.cpp b/engines/twine/renderer.cpp
index 1907e17cb5..4e62aecf5b 100644
--- a/engines/twine/renderer.cpp
+++ b/engines/twine/renderer.cpp
@@ -1155,7 +1155,7 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 			numOfPrimitives++;
 
 			(*renderTabEntryPtr)->depth = bestDepth;
-			(*renderTabEntryPtr)->renderType = 1;
+			(*renderTabEntryPtr)->renderType = RENDERTYPE_DRAWPOLYGON;
 			(*renderTabEntryPtr)->dataPtr = (uint8*)destinationHeader;
 			(*renderTabEntryPtr)++;
 		} while (--primitiveCounter);
@@ -1193,7 +1193,7 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 			}
 
 			(*renderTabEntryPtr)->depth = bestDepth;
-			(*renderTabEntryPtr)->renderType = 0;
+			(*renderTabEntryPtr)->renderType = RENDERTYPE_DRAWLINE;
 			(*renderTabEntryPtr)->dataPtr = renderBufferPtr;
 			(*renderTabEntryPtr)++;
 
@@ -1218,7 +1218,7 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 			*((int16 *)(renderBufferPtr + 5)) = size;
 
 			(*renderTabEntryPtr)->depth = flattenPoints[center / sizeof(pointTab)].z;
-			(*renderTabEntryPtr)->renderType = 2;
+			(*renderTabEntryPtr)->renderType = RENDERTYPE_DRAWSPHERE;
 			(*renderTabEntryPtr)->dataPtr = renderBufferPtr;
 			(*renderTabEntryPtr)++;
 


Commit: d992f58cdc5c36e20b856661682ae0317c417197
    https://github.com/scummvm/scummvm/commit/d992f58cdc5c36e20b856661682ae0317c417197
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-11-29T23:50:28+01:00

Commit Message:
TWINE: unified code

Changed paths:
    engines/twine/renderer.cpp


diff --git a/engines/twine/renderer.cpp b/engines/twine/renderer.cpp
index 4e62aecf5b..2bcbb81e3d 100644
--- a/engines/twine/renderer.cpp
+++ b/engines/twine/renderer.cpp
@@ -1054,18 +1054,15 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 				afterPolyHeaderPtr = renderBufferPtr;
 
 				do {
-					polyVertexHeader currentPolyVertex;
-					currentPolyVertex.shadeEntry = stream.readSint16LE();
-					currentPolyVertex.dataOffset = stream.readSint16LE();
+					const int16 shadeEntry = stream.readSint16LE();
+					const int16 shadeValue = currentPolyHeader.colorIndex + shadeTable[shadeEntry];
 
-					int16 shadeValue = currentPolyHeader.colorIndex + shadeTable[currentPolyVertex.shadeEntry];
+					const int16 vertexOffset = stream.readSint16LE();
+					const int16 vertexIndex = vertexOffset / sizeof(pointTab);
+					const pointTab *currentVertex = &flattenPoints[vertexIndex];
 
 					computedVertex *currentComputedVertex = (computedVertex *)renderBufferPtr;
-
 					currentComputedVertex->shadeValue = shadeValue;
-
-					pointTab *currentVertex = &flattenPoints[currentPolyVertex.dataOffset / sizeof(pointTab)];
-
 					currentComputedVertex->x = currentVertex->x;
 					currentComputedVertex->y = currentVertex->y;
 
@@ -1088,9 +1085,9 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 				int16 counter = destinationHeader->numOfVertex;
 
 				do {
-					int32 eax = stream.readSint16LE();
-
-					pointTab *currentVertex = &flattenPoints[eax / sizeof(pointTab)];
+					const int16 vertexOffset = stream.readSint16LE();
+					const int16 vertexIndex = vertexOffset / sizeof(pointTab);
+					pointTab *currentVertex = &flattenPoints[vertexIndex];
 
 					computedVertex *currentComputedVertex = (computedVertex *)renderBufferPtr;
 					//currentComputedVertex->shadeValue = 0;
@@ -1115,9 +1112,9 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 				int16 counter = currentPolyHeader.numOfVertex;
 
 				do {
-					int32 eax = stream.readSint16LE();
-
-					pointTab *currentVertex = &flattenPoints[eax / sizeof(pointTab)];
+					const int16 vertexOffset = stream.readSint16LE();
+					const int16 vertexIndex = vertexOffset / sizeof(pointTab);
+					pointTab *currentVertex = &flattenPoints[vertexIndex];
 
 					computedVertex *currentComputedVertex = (computedVertex *)renderBufferPtr;
 					//currentComputedVertex->shadeValue = 0;


Commit: 3427af227f7ea35fc6745b5e4f41a41b8e25ea96
    https://github.com/scummvm/scummvm/commit/3427af227f7ea35fc6745b5e4f41a41b8e25ea96
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-11-29T23:50:28+01:00

Commit Message:
TWINE: added assert to polygon handling

Changed paths:
    engines/twine/renderer.cpp


diff --git a/engines/twine/renderer.cpp b/engines/twine/renderer.cpp
index 2bcbb81e3d..b48f0eb5bd 100644
--- a/engines/twine/renderer.cpp
+++ b/engines/twine/renderer.cpp
@@ -1037,6 +1037,7 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 			polyHeader currentPolyHeader;
 			currentPolyHeader.renderType = stream.readByte();
 			currentPolyHeader.numOfVertex = stream.readByte();
+			assert(currentPolyHeader.numOfVertex <= 16);
 			currentPolyHeader.colorIndex = stream.readSint16LE();
 			int32 bestDepth = -32000;
 			polyHeader *destinationHeader = (polyHeader *)renderBufferPtr;


Commit: ae97d0bbbe17fd9f6688a65f8d7253b91d0a2acd
    https://github.com/scummvm/scummvm/commit/ae97d0bbbe17fd9f6688a65f8d7253b91d0a2acd
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-11-29T23:50:28+01:00

Commit Message:
TWINE: refactored polygon rendering code

Changed paths:
    engines/twine/renderer.cpp


diff --git a/engines/twine/renderer.cpp b/engines/twine/renderer.cpp
index b48f0eb5bd..07dcce7a60 100644
--- a/engines/twine/renderer.cpp
+++ b/engines/twine/renderer.cpp
@@ -1028,8 +1028,6 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 
 	uint8 *renderBufferPtr = renderCoordinatesBuffer;
 
-	uint8 *afterPolyHeaderPtr = nullptr; // RECHECK THIS
-
 	if (numPolygons > 0) {
 		int16 primitiveCounter = numPolygons; // the number of primitives = the number of polygons
 
@@ -1041,6 +1039,7 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 			currentPolyHeader.colorIndex = stream.readSint16LE();
 			int32 bestDepth = -32000;
 			polyHeader *destinationHeader = (polyHeader *)renderBufferPtr;
+			computedVertex * const vertices = (computedVertex *)(renderBufferPtr + 4);
 
 			// TODO: RECHECK coordinates axis
 			if (currentPolyHeader.renderType >= 9) {
@@ -1052,8 +1051,7 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 
 				int16 counter = destinationHeader->numOfVertex;
 
-				afterPolyHeaderPtr = renderBufferPtr;
-
+				computedVertex *currentComputedVertex = vertices;
 				do {
 					const int16 shadeEntry = stream.readSint16LE();
 					const int16 shadeValue = currentPolyHeader.colorIndex + shadeTable[shadeEntry];
@@ -1062,7 +1060,6 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 					const int16 vertexIndex = vertexOffset / sizeof(pointTab);
 					const pointTab *currentVertex = &flattenPoints[vertexIndex];
 
-					computedVertex *currentComputedVertex = (computedVertex *)renderBufferPtr;
 					currentComputedVertex->shadeValue = shadeValue;
 					currentComputedVertex->x = currentVertex->x;
 					currentComputedVertex->y = currentVertex->y;
@@ -1073,6 +1070,7 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 					if (currentDepth > bestDepth) {
 						bestDepth = currentDepth;
 					}
+					++currentComputedVertex;
 				} while (--counter > 0);
 			} else if (currentPolyHeader.renderType >= POLYGONTYPE_GOURAUD) { // only 1 shade value is used
 				destinationHeader->renderType = currentPolyHeader.renderType - POLYGONTYPE_GOURAUD;
@@ -1082,7 +1080,7 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 				destinationHeader->colorIndex = shadeValue;
 
 				renderBufferPtr += 4;
-				afterPolyHeaderPtr = renderBufferPtr;
+				computedVertex *currentComputedVertex = vertices;
 				int16 counter = destinationHeader->numOfVertex;
 
 				do {
@@ -1090,7 +1088,6 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 					const int16 vertexIndex = vertexOffset / sizeof(pointTab);
 					pointTab *currentVertex = &flattenPoints[vertexIndex];
 
-					computedVertex *currentComputedVertex = (computedVertex *)renderBufferPtr;
 					//currentComputedVertex->shadeValue = 0;
 					currentComputedVertex->x = currentVertex->x;
 					currentComputedVertex->y = currentVertex->y;
@@ -1101,6 +1098,7 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 					if (currentDepth > bestDepth) {
 						bestDepth = currentDepth;
 					}
+					++currentComputedVertex;
 				} while (--counter > 0);
 			} else { // no shade is used
 				destinationHeader->renderType = currentPolyHeader.renderType;
@@ -1109,7 +1107,7 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 
 				renderBufferPtr += 4;
 
-				afterPolyHeaderPtr = renderBufferPtr;
+				computedVertex *currentComputedVertex = vertices;
 				int16 counter = currentPolyHeader.numOfVertex;
 
 				do {
@@ -1117,7 +1115,6 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 					const int16 vertexIndex = vertexOffset / sizeof(pointTab);
 					pointTab *currentVertex = &flattenPoints[vertexIndex];
 
-					computedVertex *currentComputedVertex = (computedVertex *)renderBufferPtr;
 					//currentComputedVertex->shadeValue = 0;
 					currentComputedVertex->x = currentVertex->x;
 					currentComputedVertex->y = currentVertex->y;
@@ -1128,24 +1125,25 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 					if (currentDepth > bestDepth) {
 						bestDepth = currentDepth;
 					}
+					++currentComputedVertex;
 				} while (--counter > 0);
 			}
 
-			int16 ax = *((const int16 *)(afterPolyHeaderPtr + 4));
-			int16 bx = *((const int16 *)(afterPolyHeaderPtr + 8));
+			int16 ax = vertices[0].y;
+			int16 bx = vertices[1].x;
 
-			ax -= *((const int16 *)(afterPolyHeaderPtr + 16));
-			bx -= *((const int16 *)(afterPolyHeaderPtr + 2));
+			ax -= vertices[2].y;
+			bx -= vertices[0].x;
 
 			ax *= bx;
 
 			int32 bestDepth2 = ax;
 
-			ax = *((const int16 *)(afterPolyHeaderPtr + 2));
-			int16 cx = *((const int16 *)(afterPolyHeaderPtr + 10));
+			ax = vertices[0].x;
+			int16 cx = vertices[1].y;
 
-			ax -= *((const int16 *)(afterPolyHeaderPtr + 14));
-			cx -= *((const int16 *)(afterPolyHeaderPtr + 4));
+			ax -= vertices[2].x;
+			cx -= vertices[0].y;
 
 			ax *= cx;
 			ax -= bestDepth2;
@@ -1257,7 +1255,7 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 	}
 
 	int16 primitiveCounter = numOfPrimitives;
-	afterPolyHeaderPtr = ptr + stream.pos();
+	uint8* afterPolyHeaderPtr = ptr + stream.pos();
 
 	do {
 		int16 type = renderTabEntryPtr2->renderType;


Commit: 0c2064ede28e9c4dce1e9441793db73b82352bc8
    https://github.com/scummvm/scummvm/commit/0c2064ede28e9c4dce1e9441793db73b82352bc8
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-11-29T23:50:28+01:00

Commit Message:
TWINE: refactored polygon rendering code

Changed paths:
    engines/twine/renderer.cpp


diff --git a/engines/twine/renderer.cpp b/engines/twine/renderer.cpp
index 07dcce7a60..a5394b1955 100644
--- a/engines/twine/renderer.cpp
+++ b/engines/twine/renderer.cpp
@@ -1129,24 +1129,14 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 				} while (--counter > 0);
 			}
 
-			int16 ax = vertices[0].y;
-			int16 bx = vertices[1].x;
-
-			ax -= vertices[2].y;
-			bx -= vertices[0].x;
-
+			const int16 bx = vertices[1].x - vertices[0].x;
+			int16 ax = vertices[0].y - vertices[2].y;
 			ax *= bx;
 
-			int32 bestDepth2 = ax;
-
-			ax = vertices[0].x;
-			int16 cx = vertices[1].y;
-
-			ax -= vertices[2].x;
-			cx -= vertices[0].y;
-
-			ax *= cx;
-			ax -= bestDepth2;
+			const int16 cx = vertices[1].y - vertices[0].y;
+			int16 dx = vertices[0].x - vertices[2].x;
+			dx *= cx;
+			dx -= ax;
 
 			numOfPrimitives++;
 


Commit: ad8d15d807fd4f8ddbf0346a5f6df458f8be8020
    https://github.com/scummvm/scummvm/commit/ad8d15d807fd4f8ddbf0346a5f6df458f8be8020
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-11-29T23:50:28+01:00

Commit Message:
TWINE: disabled unused code

Changed paths:
    engines/twine/renderer.cpp


diff --git a/engines/twine/renderer.cpp b/engines/twine/renderer.cpp
index a5394b1955..97edd0db56 100644
--- a/engines/twine/renderer.cpp
+++ b/engines/twine/renderer.cpp
@@ -1129,15 +1129,13 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 				} while (--counter > 0);
 			}
 
+#if 0
 			const int16 bx = vertices[1].x - vertices[0].x;
-			int16 ax = vertices[0].y - vertices[2].y;
-			ax *= bx;
+			const int16 ax = (vertices[0].y - vertices[2].y) * bx;
 
 			const int16 cx = vertices[1].y - vertices[0].y;
-			int16 dx = vertices[0].x - vertices[2].x;
-			dx *= cx;
-			dx -= ax;
-
+			const int16 dx = (vertices[0].x - vertices[2].x) * cx - ax;
+#endif
 			numOfPrimitives++;
 
 			(*renderTabEntryPtr)->depth = bestDepth;


Commit: 3e7ba63b831235c3b0af3b0033f18fab9e778a1c
    https://github.com/scummvm/scummvm/commit/3e7ba63b831235c3b0af3b0033f18fab9e778a1c
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-11-29T23:50:28+01:00

Commit Message:
TWINE: fixed segfault in give_key debug command

Changed paths:
    engines/twine/console.cpp


diff --git a/engines/twine/console.cpp b/engines/twine/console.cpp
index d6ffba3d23..363b8e46c6 100644
--- a/engines/twine/console.cpp
+++ b/engines/twine/console.cpp
@@ -117,7 +117,7 @@ bool TwinEConsole::doSetGameFlag(int argc, const char **argv) {
 
 bool TwinEConsole::doGiveKey(int argc, const char **argv) {
 	int amount = 1;
-	if (argc >= 1) {
+	if (argc >= 2) {
 		amount = atoi(argv[1]);
 	}
 	_engine->_gameState->inventoryNumKeys += amount;
@@ -168,7 +168,7 @@ bool TwinEConsole::doGiveAllItems(int argc, const char **argv) {
 	}
 	_engine->_gameState->gameFlags[GAMEFLAG_INVENTORY_DISABLED] = 0;
 	int amount = 10;
-	if (argc > 1) {
+	if (argc >= 2) {
 		amount = atoi(argv[1]);
 	}
 	_engine->_gameState->inventoryNumKeys += amount;


Commit: fa1808b1c0f137ad4c130e262deddc32feff2e1c
    https://github.com/scummvm/scummvm/commit/fa1808b1c0f137ad4c130e262deddc32feff2e1c
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-11-29T23:50:28+01:00

Commit Message:
TWINE: refactored line rendering

Changed paths:
    engines/twine/renderer.cpp
    engines/twine/renderer.h


diff --git a/engines/twine/renderer.cpp b/engines/twine/renderer.cpp
index 97edd0db56..768416a1ee 100644
--- a/engines/twine/renderer.cpp
+++ b/engines/twine/renderer.cpp
@@ -1154,34 +1154,27 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 			lineData line;
 			line.colorIndex = stream.readByte();
 			stream.skip(3);
-			line.p1 = stream.readSint16LE();
-			line.p2 = stream.readSint16LE();
+			line.firstPointOffset = stream.readSint16LE();
+			line.secondPointOffset = stream.readSint16LE();
 			lineCoordinates *lineCoordinatesPtr = (lineCoordinates *)renderBufferPtr;
 
-			if (line.p1 % 6 != 0 || line.p2 % 6 != 0) {
+			if (line.firstPointOffset % 6 != 0 || line.secondPointOffset % 6 != 0) {
 				error("RENDER ERROR: lineDataPtr reference is malformed!");
 			}
 
-			const int32 point1 = line.p1 / 6;
-			const int32 point2 = line.p2 / 6;
+			const int32 point1Index = line.firstPointOffset / 6;
+			const int32 point2Index = line.secondPointOffset / 6;
 			lineCoordinatesPtr->colorIndex = line.colorIndex;
-			lineCoordinatesPtr->x1 = flattenPoints[point1].x;
-			lineCoordinatesPtr->y1 = flattenPoints[point1].y;
-			lineCoordinatesPtr->x2 = flattenPoints[point2].x;
-			lineCoordinatesPtr->y2 = flattenPoints[point2].y;
-			int32 bestDepth = flattenPoints[point1].z;
-			int32 depth = flattenPoints[point2].z;
-
-			if (depth >= bestDepth) {
-				bestDepth = depth;
-			}
-
-			(*renderTabEntryPtr)->depth = bestDepth;
+			lineCoordinatesPtr->x1 = flattenPoints[point1Index].x;
+			lineCoordinatesPtr->y1 = flattenPoints[point1Index].y;
+			lineCoordinatesPtr->x2 = flattenPoints[point2Index].x;
+			lineCoordinatesPtr->y2 = flattenPoints[point2Index].y;
+			(*renderTabEntryPtr)->depth = MAX(flattenPoints[point1Index].z, flattenPoints[point2Index].z);
 			(*renderTabEntryPtr)->renderType = RENDERTYPE_DRAWLINE;
 			(*renderTabEntryPtr)->dataPtr = renderBufferPtr;
 			(*renderTabEntryPtr)++;
 
-			renderBufferPtr += 12;
+			renderBufferPtr += sizeof(lineCoordinates);
 		} while (--temp);
 	}
 
@@ -1190,23 +1183,22 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 	if (temp) {
 		numOfPrimitives += temp;
 		do {
+			sphereData *sphere = (sphereData *)renderBufferPtr;
 			stream.skip(1);
-			uint8 color2 = stream.readByte();
+			sphere->colorIndex = stream.readByte();
 			stream.skip(2);
-			int16 size = stream.readUint16LE();
-			int16 center = stream.readUint16LE();
-
-			*(uint8 *)renderBufferPtr = color2;
-			*((int16 *)(renderBufferPtr + 1)) = flattenPoints[center / sizeof(pointTab)].x;
-			*((int16 *)(renderBufferPtr + 3)) = flattenPoints[center / sizeof(pointTab)].y;
-			*((int16 *)(renderBufferPtr + 5)) = size;
+			sphere->radius = stream.readUint16LE();
+			const int16 centerOffset = stream.readUint16LE();
+			const int16 centerIndex = centerOffset / 6;
+			sphere->x = flattenPoints[centerIndex].x;
+			sphere->y = flattenPoints[centerIndex].y;
 
-			(*renderTabEntryPtr)->depth = flattenPoints[center / sizeof(pointTab)].z;
+			(*renderTabEntryPtr)->depth = flattenPoints[centerOffset / sizeof(pointTab)].z;
 			(*renderTabEntryPtr)->renderType = RENDERTYPE_DRAWSPHERE;
 			(*renderTabEntryPtr)->dataPtr = renderBufferPtr;
 			(*renderTabEntryPtr)++;
 
-			renderBufferPtr += 7;
+			renderBufferPtr += sizeof(sphereData);
 		} while (--temp);
 	}
 
diff --git a/engines/twine/renderer.h b/engines/twine/renderer.h
index 92279964d3..c912a1ba55 100644
--- a/engines/twine/renderer.h
+++ b/engines/twine/renderer.h
@@ -101,8 +101,8 @@ private:
 		uint8 unk1 = 0;
 		uint8 unk2 = 0;
 		uint8 unk3 = 0;
-		int16 p1 = 0;
-		int16 p2 = 0;
+		int16 firstPointOffset = 0;  /**< byte offsets */
+		int16 secondPointOffset = 0; /**< byte offsets */
 	};
 
 	struct polyVertexHeader {
@@ -116,6 +116,13 @@ private:
 		int16 y = 0;
 	};
 
+	struct sphereData {
+		int8 colorIndex = 0;
+		int16 x = 0;
+		int16 y = 0;
+		int16 radius = 0;
+	};
+
 	struct bodyHeaderStruct {
 		int16 bodyFlag = 0;
 		int16 minsx = 0;


Commit: 938b438b0e12d95de47ae0a46a09366afc1d1a95
    https://github.com/scummvm/scummvm/commit/938b438b0e12d95de47ae0a46a09366afc1d1a95
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-11-29T23:50:29+01:00

Commit Message:
TWINE: use size of struct for raw buffer arithmetic,...

but not for the reading of the stream data from hqr files - they are fixed, no matter how
the padding and alignment rules of the platform are

Changed paths:
    engines/twine/renderer.cpp


diff --git a/engines/twine/renderer.cpp b/engines/twine/renderer.cpp
index 768416a1ee..b0f662a98b 100644
--- a/engines/twine/renderer.cpp
+++ b/engines/twine/renderer.cpp
@@ -1039,7 +1039,7 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 			currentPolyHeader.colorIndex = stream.readSint16LE();
 			int32 bestDepth = -32000;
 			polyHeader *destinationHeader = (polyHeader *)renderBufferPtr;
-			computedVertex * const vertices = (computedVertex *)(renderBufferPtr + 4);
+			computedVertex * const vertices = (computedVertex *)(renderBufferPtr + sizeof(polyHeader));
 
 			// TODO: RECHECK coordinates axis
 			if (currentPolyHeader.renderType >= 9) {
@@ -1047,7 +1047,7 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 				destinationHeader->numOfVertex = currentPolyHeader.numOfVertex;
 				destinationHeader->colorIndex = currentPolyHeader.colorIndex;
 
-				renderBufferPtr += 4;
+				renderBufferPtr += sizeof(polyHeader);
 
 				int16 counter = destinationHeader->numOfVertex;
 
@@ -1057,14 +1057,14 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 					const int16 shadeValue = currentPolyHeader.colorIndex + shadeTable[shadeEntry];
 
 					const int16 vertexOffset = stream.readSint16LE();
-					const int16 vertexIndex = vertexOffset / sizeof(pointTab);
+					const int16 vertexIndex = vertexOffset / 6;
 					const pointTab *currentVertex = &flattenPoints[vertexIndex];
 
 					currentComputedVertex->shadeValue = shadeValue;
 					currentComputedVertex->x = currentVertex->x;
 					currentComputedVertex->y = currentVertex->y;
 
-					renderBufferPtr += 6;
+					renderBufferPtr += sizeof(pointTab);
 
 					int32 currentDepth = currentVertex->z;
 					if (currentDepth > bestDepth) {
@@ -1079,20 +1079,20 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 				const int16 shadeValue = currentPolyHeader.colorIndex + shadeTable[shadeEntry];
 				destinationHeader->colorIndex = shadeValue;
 
-				renderBufferPtr += 4;
+				renderBufferPtr += sizeof(polyHeader);
 				computedVertex *currentComputedVertex = vertices;
 				int16 counter = destinationHeader->numOfVertex;
 
 				do {
 					const int16 vertexOffset = stream.readSint16LE();
-					const int16 vertexIndex = vertexOffset / sizeof(pointTab);
+					const int16 vertexIndex = vertexOffset / 6;
 					pointTab *currentVertex = &flattenPoints[vertexIndex];
 
 					//currentComputedVertex->shadeValue = 0;
 					currentComputedVertex->x = currentVertex->x;
 					currentComputedVertex->y = currentVertex->y;
 
-					renderBufferPtr += 6;
+					renderBufferPtr += sizeof(pointTab);
 
 					int32 currentDepth = currentVertex->z;
 					if (currentDepth > bestDepth) {
@@ -1105,21 +1105,21 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 				destinationHeader->numOfVertex = currentPolyHeader.numOfVertex;
 				destinationHeader->colorIndex = currentPolyHeader.colorIndex;
 
-				renderBufferPtr += 4;
+				renderBufferPtr += sizeof(polyHeader);
 
 				computedVertex *currentComputedVertex = vertices;
 				int16 counter = currentPolyHeader.numOfVertex;
 
 				do {
 					const int16 vertexOffset = stream.readSint16LE();
-					const int16 vertexIndex = vertexOffset / sizeof(pointTab);
+					const int16 vertexIndex = vertexOffset / 6;
 					pointTab *currentVertex = &flattenPoints[vertexIndex];
 
 					//currentComputedVertex->shadeValue = 0;
 					currentComputedVertex->x = currentVertex->x;
 					currentComputedVertex->y = currentVertex->y;
 
-					renderBufferPtr += 6;
+					renderBufferPtr += sizeof(pointTab);
 
 					int32 currentDepth = currentVertex->z;
 					if (currentDepth > bestDepth) {


Commit: 1926f690fc52fb79f7d89e81424106d2c0fb877f
    https://github.com/scummvm/scummvm/commit/1926f690fc52fb79f7d89e81424106d2c0fb877f
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-11-29T23:50:29+01:00

Commit Message:
TWINE: refactored rendering code

Changed paths:
    engines/twine/renderer.cpp
    engines/twine/renderer.h
    engines/twine/text.cpp


diff --git a/engines/twine/renderer.cpp b/engines/twine/renderer.cpp
index b0f662a98b..92d87fd0f6 100644
--- a/engines/twine/renderer.cpp
+++ b/engines/twine/renderer.cpp
@@ -392,7 +392,7 @@ FORCEINLINE int16 clamp(int16 x, int16 a, int16 b) {
 	return x < a ? a : (x > b ? b : x);
 }
 
-void Renderer::computePolygons(int16 polyRenderType, vertexData *vertices, int32 numVertices, int &vleft, int &vright, int &vtop, int &vbottom) {
+void Renderer::computePolygons(int16 polyRenderType, Vertex *vertices, int32 numVertices, int &vleft, int &vright, int &vtop, int &vbottom) {
 	vleft = vtop = 32767;
 	vright = vbottom = -32768;
 
@@ -417,7 +417,7 @@ void Renderer::computePolygons(int16 polyRenderType, vertexData *vertices, int32
 		}
 	}
 
-	uint8 vertexParam1 = vertices[numVertices - 1].param;
+	uint8 vertexParam1 = vertices[numVertices - 1].colorIndex;
 	uint8 vertexParam2 = vertexParam1;
 	int16 currentVertexX = vertices[numVertices - 1].x;
 	int16 currentVertexY = vertices[numVertices - 1].y;
@@ -427,7 +427,7 @@ void Renderer::computePolygons(int16 polyRenderType, vertexData *vertices, int32
 		int16 oldVertexX = currentVertexX;
 		uint8 oldVertexParam = vertexParam1;
 
-		vertexParam1 = vertexParam2 = vertices[nVertex].param;
+		vertexParam1 = vertexParam2 = vertices[nVertex].colorIndex;
 		currentVertexX = vertices[nVertex].x;
 		currentVertexY = vertices[nVertex].y;
 
@@ -995,14 +995,13 @@ void Renderer::renderPolygons(int32 renderType, int32 color, int vleft, int vrig
 	}
 }
 
-void Renderer::renderPolygons(const polyHeader &polyHeader) {
+void Renderer::renderPolygons(const Polygon &polygon, Vertex *vertices) {
 	int vleft = 0;
 	int vright = 0;
 	int vtop = 0;
 	int vbottom = 0;
-	vertexData *vertices = (vertexData *)vertexCoordinates;
-	computePolygons(polyHeader.renderType, vertices, polyHeader.numOfVertex, vleft, vright, vtop, vbottom);
-	renderPolygons(polyHeader.renderType, polyHeader.colorIndex, vleft, vright, vtop, vbottom);
+	computePolygons(polygon.renderType, vertices, polygon.numVertices, vleft, vright, vtop, vbottom);
+	renderPolygons(polygon.renderType, polygon.colorIndex, vleft, vright, vtop, vbottom);
 }
 
 void Renderer::circleFill(int32 x, int32 y, int32 radius, uint8 color) {
@@ -1032,39 +1031,39 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 		int16 primitiveCounter = numPolygons; // the number of primitives = the number of polygons
 
 		do { // loop that load all the polygons
-			polyHeader currentPolyHeader;
-			currentPolyHeader.renderType = stream.readByte();
-			currentPolyHeader.numOfVertex = stream.readByte();
-			assert(currentPolyHeader.numOfVertex <= 16);
-			currentPolyHeader.colorIndex = stream.readSint16LE();
+			Polygon currentPolygon;
+			currentPolygon.renderType = stream.readByte();
+			currentPolygon.numVertices = stream.readByte();
+			assert(currentPolygon.numVertices <= 16);
+			currentPolygon.colorIndex = stream.readSint16LE();
 			int32 bestDepth = -32000;
-			polyHeader *destinationHeader = (polyHeader *)renderBufferPtr;
-			computedVertex * const vertices = (computedVertex *)(renderBufferPtr + sizeof(polyHeader));
+			Polygon *destinationPolygon = (Polygon *)renderBufferPtr;
+			Vertex * const vertices = (Vertex *)(renderBufferPtr + sizeof(Polygon));
 
 			// TODO: RECHECK coordinates axis
-			if (currentPolyHeader.renderType >= 9) {
-				destinationHeader->renderType = currentPolyHeader.renderType - 2;
-				destinationHeader->numOfVertex = currentPolyHeader.numOfVertex;
-				destinationHeader->colorIndex = currentPolyHeader.colorIndex;
+			if (currentPolygon.renderType >= 9) {
+				destinationPolygon->renderType = currentPolygon.renderType - 2;
+				destinationPolygon->numVertices = currentPolygon.numVertices;
+				destinationPolygon->colorIndex = currentPolygon.colorIndex;
 
-				renderBufferPtr += sizeof(polyHeader);
+				renderBufferPtr += sizeof(Polygon);
 
-				int16 counter = destinationHeader->numOfVertex;
+				int16 counter = destinationPolygon->numVertices;
 
-				computedVertex *currentComputedVertex = vertices;
+				Vertex *currentComputedVertex = vertices;
 				do {
 					const int16 shadeEntry = stream.readSint16LE();
-					const int16 shadeValue = currentPolyHeader.colorIndex + shadeTable[shadeEntry];
+					const int16 shadeValue = currentPolygon.colorIndex + shadeTable[shadeEntry];
 
 					const int16 vertexOffset = stream.readSint16LE();
 					const int16 vertexIndex = vertexOffset / 6;
 					const pointTab *currentVertex = &flattenPoints[vertexIndex];
 
-					currentComputedVertex->shadeValue = shadeValue;
+					currentComputedVertex->colorIndex = shadeValue;
 					currentComputedVertex->x = currentVertex->x;
 					currentComputedVertex->y = currentVertex->y;
 
-					renderBufferPtr += sizeof(pointTab);
+					renderBufferPtr += sizeof(Vertex);
 
 					int32 currentDepth = currentVertex->z;
 					if (currentDepth > bestDepth) {
@@ -1072,27 +1071,27 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 					}
 					++currentComputedVertex;
 				} while (--counter > 0);
-			} else if (currentPolyHeader.renderType >= POLYGONTYPE_GOURAUD) { // only 1 shade value is used
-				destinationHeader->renderType = currentPolyHeader.renderType - POLYGONTYPE_GOURAUD;
-				destinationHeader->numOfVertex = currentPolyHeader.numOfVertex;
+			} else if (currentPolygon.renderType >= POLYGONTYPE_GOURAUD) { // only 1 shade value is used
+				destinationPolygon->renderType = currentPolygon.renderType - POLYGONTYPE_GOURAUD;
+				destinationPolygon->numVertices = currentPolygon.numVertices;
 				const int16 shadeEntry = stream.readSint16LE();
-				const int16 shadeValue = currentPolyHeader.colorIndex + shadeTable[shadeEntry];
-				destinationHeader->colorIndex = shadeValue;
+				const int16 shadeValue = currentPolygon.colorIndex + shadeTable[shadeEntry];
+				destinationPolygon->colorIndex = shadeValue;
 
-				renderBufferPtr += sizeof(polyHeader);
-				computedVertex *currentComputedVertex = vertices;
-				int16 counter = destinationHeader->numOfVertex;
+				renderBufferPtr += sizeof(Polygon);
+				Vertex *currentComputedVertex = vertices;
+				int16 counter = destinationPolygon->numVertices;
 
 				do {
 					const int16 vertexOffset = stream.readSint16LE();
 					const int16 vertexIndex = vertexOffset / 6;
-					pointTab *currentVertex = &flattenPoints[vertexIndex];
+					const pointTab *currentVertex = &flattenPoints[vertexIndex];
 
-					//currentComputedVertex->shadeValue = 0;
+					//currentVertex->shadeValue = 0;
 					currentComputedVertex->x = currentVertex->x;
 					currentComputedVertex->y = currentVertex->y;
 
-					renderBufferPtr += sizeof(pointTab);
+					renderBufferPtr += sizeof(Vertex);
 
 					int32 currentDepth = currentVertex->z;
 					if (currentDepth > bestDepth) {
@@ -1101,25 +1100,25 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 					++currentComputedVertex;
 				} while (--counter > 0);
 			} else { // no shade is used
-				destinationHeader->renderType = currentPolyHeader.renderType;
-				destinationHeader->numOfVertex = currentPolyHeader.numOfVertex;
-				destinationHeader->colorIndex = currentPolyHeader.colorIndex;
+				destinationPolygon->renderType = currentPolygon.renderType;
+				destinationPolygon->numVertices = currentPolygon.numVertices;
+				destinationPolygon->colorIndex = currentPolygon.colorIndex;
 
-				renderBufferPtr += sizeof(polyHeader);
+				renderBufferPtr += sizeof(Polygon);
 
-				computedVertex *currentComputedVertex = vertices;
-				int16 counter = currentPolyHeader.numOfVertex;
+				Vertex *currentComputedVertex = vertices;
+				int16 counter = currentPolygon.numVertices;
 
 				do {
 					const int16 vertexOffset = stream.readSint16LE();
 					const int16 vertexIndex = vertexOffset / 6;
-					pointTab *currentVertex = &flattenPoints[vertexIndex];
+					const pointTab *currentVertex = &flattenPoints[vertexIndex];
 
-					//currentComputedVertex->shadeValue = 0;
+					//currentVertex->shadeValue = 0;
 					currentComputedVertex->x = currentVertex->x;
 					currentComputedVertex->y = currentVertex->y;
 
-					renderBufferPtr += sizeof(pointTab);
+					renderBufferPtr += sizeof(Vertex);
 
 					int32 currentDepth = currentVertex->z;
 					if (currentDepth > bestDepth) {
@@ -1140,7 +1139,7 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 
 			(*renderTabEntryPtr)->depth = bestDepth;
 			(*renderTabEntryPtr)->renderType = RENDERTYPE_DRAWPOLYGON;
-			(*renderTabEntryPtr)->dataPtr = (uint8*)destinationHeader;
+			(*renderTabEntryPtr)->dataPtr = (uint8*)destinationPolygon;
 			(*renderTabEntryPtr)++;
 		} while (--primitiveCounter);
 	}
@@ -1244,73 +1243,51 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 
 		switch (type) {
 		case RENDERTYPE_DRAWLINE: { // draw a line
-			Common::MemoryReadStream typeStream(pointer, 12);
-			lineCoordinates lineCoords;
-			lineCoords.colorIndex = typeStream.readByte();
-			typeStream.skip(3);
-			lineCoords.x1 = typeStream.readSint16LE();
-			lineCoords.y1 = typeStream.readSint16LE();
-			lineCoords.x2 = typeStream.readSint16LE();
-			lineCoords.y2 = typeStream.readSint16LE();
-			const int32 x1 = lineCoords.x1;
-			const int32 y1 = lineCoords.y1;
-			const int32 x2 = lineCoords.x2;
-			const int32 y2 = lineCoords.y2;
-			_engine->_interface->drawLine(x1, y1, x2, y2, lineCoords.colorIndex);
+			const lineCoordinates *lineCoords = (const lineCoordinates*)pointer;
+			const int32 x1 = lineCoords->x1;
+			const int32 y1 = lineCoords->y1;
+			const int32 x2 = lineCoords->x2;
+			const int32 y2 = lineCoords->y2;
+			_engine->_interface->drawLine(x1, y1, x2, y2, lineCoords->colorIndex);
 			break;
 		}
 		case RENDERTYPE_DRAWPOLYGON: { // draw a polygon
-			// TODO: size
-			Common::MemoryReadStream typeStream(pointer, 10000);
-			polyHeader polyHeader;
-			polyHeader.renderType = typeStream.readByte();
-			polyHeader.numOfVertex = typeStream.readByte();
-			polyHeader.colorIndex = typeStream.readByte();
-			typeStream.skip(1);
-
-			uint8 *destPtr = (uint8 *)vertexCoordinates;
-			const int32 triangleCount = polyHeader.numOfVertex * 3;
-			for (int32 i = 0; i < triangleCount; i++) {
-				*((int16 *)destPtr) = typeStream.readSint16LE();
-				destPtr += 2;
-			}
-
-			renderPolygons(polyHeader);
+			const Polygon* header = (const Polygon*)pointer;
+			Vertex* vertices = (Vertex*)(pointer + sizeof(Polygon));
+			renderPolygons(*header, vertices);
 			break;
 		}
 		case RENDERTYPE_DRAWSPHERE: { // draw a sphere
-			const int32 circleParam1 = *(const uint8 *)pointer;
-			const int32 circleParam4 = *((const int16 *)(pointer + 1));
-			const int32 circleParam5 = *((const int16 *)(pointer + 3));
-			int32 circleParam3 = *((const int16 *)(pointer + 5));
+			sphereData* sphere = (sphereData*)pointer;
+			int32 radius =  sphere->radius;
 
 			if (!isUsingOrhoProjection) {
-				circleParam3 = (circleParam3 * cameraPosY) / (cameraPosX + *(const int16 *)pointer);
+				radius = (radius * cameraPosY) / (cameraPosX + *(const int16 *)pointer); // TODO: this does not make sense.
 			} else {
-				circleParam3 = (circleParam3 * 34) >> 9;
+				radius = (radius * 34) >> 9;
 			}
 
-			circleParam3 += 3;
+			radius += 3;
 
-			if (circleParam4 + circleParam3 > _engine->_redraw->renderRect.right) {
-				_engine->_redraw->renderRect.right = circleParam4 + circleParam3;
+			if (sphere->x + radius > _engine->_redraw->renderRect.right) {
+				_engine->_redraw->renderRect.right = sphere->x + radius;
 			}
 
-			if (circleParam4 - circleParam3 < _engine->_redraw->renderRect.left) {
-				_engine->_redraw->renderRect.left = circleParam4 - circleParam3;
+			if (sphere->x - radius < _engine->_redraw->renderRect.left) {
+				_engine->_redraw->renderRect.left = sphere->x - radius;
 			}
 
-			if (circleParam5 + circleParam3 > _engine->_redraw->renderRect.bottom) {
-				_engine->_redraw->renderRect.bottom = circleParam5 + circleParam3;
+			if (sphere->y + radius > _engine->_redraw->renderRect.bottom) {
+				_engine->_redraw->renderRect.bottom = sphere->y + radius;
 			}
 
-			if (circleParam5 - circleParam3 < _engine->_redraw->renderRect.top) {
-				_engine->_redraw->renderRect.top = circleParam5 - circleParam3;
+			if (sphere->y - radius < _engine->_redraw->renderRect.top) {
+				_engine->_redraw->renderRect.top = sphere->y - radius;
 			}
 
-			circleParam3 -= 3;
+			radius -= 3;
 
-			circleFill(circleParam4, circleParam5, circleParam3, circleParam1);
+			circleFill(sphere->x, sphere->y, radius, sphere->colorIndex);
 			break;
 		}
 		default:
diff --git a/engines/twine/renderer.h b/engines/twine/renderer.h
index c912a1ba55..e60b635ebc 100644
--- a/engines/twine/renderer.h
+++ b/engines/twine/renderer.h
@@ -40,10 +40,17 @@ namespace TwinE {
 
 class TwinEEngine;
 
-struct polyHeader {
-	uint8 renderType = 0; //FillVertic_AType
-	uint8 numOfVertex = 0;
+struct Vertex {
 	int16 colorIndex = 0;
+	int16 x = 0;
+	int16 y = 0;
+};
+
+struct Polygon {
+	uint8 renderType = 0;
+	uint8 numVertices = 0;
+	int16 colorIndex = 0;
+	// followed by Vertex array
 };
 
 class Renderer {
@@ -110,12 +117,6 @@ private:
 		int16 dataOffset = 0;
 	};
 
-	struct computedVertex {
-		int16 shadeValue = 0;
-		int16 x = 0;
-		int16 y = 0;
-	};
-
 	struct sphereData {
 		int8 colorIndex = 0;
 		int16 x = 0;
@@ -136,12 +137,6 @@ private:
 		int32 keyFrameTime = 0;
 	};
 
-	struct vertexData {
-		uint8 param = 0;
-		int16 x = 0;
-		int16 y = 0;
-	};
-
 	union packed16 {
 		struct {
 			uint8 al = 0;
@@ -221,7 +216,7 @@ private:
 	void renderPolygonsDither(uint8 *out, int vtop, int32 vsize, int32 color) const;
 	void renderPolygonsMarble(uint8 *out, int vtop, int32 vsize, int32 color) const;
 
-	void computePolygons(int16 polyRenderType, vertexData *vertices, int32 numVertices, int &vleft, int &vright, int &vtop, int &vbottom);
+	void computePolygons(int16 polyRenderType, Vertex *vertices, int32 numVertices, int &vleft, int &vright, int &vtop, int &vbottom);
 	void renderPolygons(int32 renderType, int32 color, int vleft, int vright, int vtop, int vbottom);
 
 public:
@@ -249,7 +244,7 @@ public:
 	void setLightVector(int32 angleX, int32 angleY, int32 angleZ);
 
 	void prepareIsoModel(uint8 *bodyPtr); // loadGfxSub
-	void renderPolygons(const polyHeader &polyHeader);
+	void renderPolygons(const Polygon &polygon, Vertex *vertices);
 
 	int32 projectPositionOnScreen(int32 cX, int32 cY, int32 cZ);
 	void setCameraPosition(int32 x, int32 y, int32 cX, int32 cY, int32 cZ);
diff --git a/engines/twine/text.cpp b/engines/twine/text.cpp
index 54b6e3b2f9..755b5d230d 100644
--- a/engines/twine/text.cpp
+++ b/engines/twine/text.cpp
@@ -456,23 +456,25 @@ void Text::renderContinueReadingTriangle() {
 	const int32 top = _dialTextBox.bottom - 24;
 	const int32 bottom = _dialTextBox.bottom - 3;
 
-	_engine->_renderer->vertexCoordinates[0] = _dialTextStopColor;
-	_engine->_renderer->vertexCoordinates[1] = right;
-	_engine->_renderer->vertexCoordinates[2] = top;
-
-	_engine->_renderer->vertexCoordinates[3] = _dialTextStopColor;
-	_engine->_renderer->vertexCoordinates[4] = left;
-	_engine->_renderer->vertexCoordinates[5] = bottom;
-
-	_engine->_renderer->vertexCoordinates[6] = _dialTextStartColor;
-	_engine->_renderer->vertexCoordinates[7] = _engine->_renderer->vertexCoordinates[1];
-	_engine->_renderer->vertexCoordinates[8] = _engine->_renderer->vertexCoordinates[5];
-
-	polyHeader polyHdr;
-	polyHdr.numOfVertex = 3;
-	polyHdr.colorIndex = _dialTextStopColor;
-	polyHdr.renderType = POLYGONTYPE_FLAT;
-	_engine->_renderer->renderPolygons(polyHdr);
+	Vertex vertices[3];
+
+	vertices[0].colorIndex = _dialTextStopColor;
+	vertices[0].x = right;
+	vertices[0].y = top;
+
+	vertices[1].colorIndex = _dialTextStopColor;
+	vertices[1].x = left;
+	vertices[1].y = bottom;
+
+	vertices[2].colorIndex = _dialTextStartColor;
+	vertices[2].x = _engine->_renderer->vertexCoordinates[1];
+	vertices[2].y = _engine->_renderer->vertexCoordinates[5];
+
+	Polygon polygon;
+	polygon.numVertices = 3;
+	polygon.colorIndex = _dialTextStopColor;
+	polygon.renderType = POLYGONTYPE_FLAT;
+	_engine->_renderer->renderPolygons(polygon, vertices);
 
 	_engine->copyBlockPhys(Common::Rect(left, top, right, bottom));
 }


Commit: f5a13ed5a5463ef9f16f415f089ea4d7d0da0e6d
    https://github.com/scummvm/scummvm/commit/f5a13ed5a5463ef9f16f415f089ea4d7d0da0e6d
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-11-29T23:50:29+01:00

Commit Message:
TWINE: inlined one of the renderPolygons methods

Changed paths:
    engines/twine/renderer.cpp
    engines/twine/renderer.h


diff --git a/engines/twine/renderer.cpp b/engines/twine/renderer.cpp
index 92d87fd0f6..d8670d9b10 100644
--- a/engines/twine/renderer.cpp
+++ b/engines/twine/renderer.cpp
@@ -957,53 +957,50 @@ void Renderer::renderPolygonsDither(uint8 *out, int vtop, int32 vsize, int32 col
 void Renderer::renderPolygonsMarble(uint8 *out, int vtop, int32 vsize, int32 color) const {
 }
 
-void Renderer::renderPolygons(int32 renderType, int32 color, int vleft, int vright, int vtop, int vbottom) {
+void Renderer::renderPolygons(const Polygon &polygon, Vertex *vertices) {
+	int vleft = 0;
+	int vright = 0;
+	int vtop = 0;
+	int vbottom = 0;
+	computePolygons(polygon.renderType, vertices, polygon.numVertices, vleft, vright, vtop, vbottom);
+
 	uint8 *out = (uint8*)_engine->frontVideoBuffer.getBasePtr(0, vtop);
 	const int32 vsize = vbottom - vtop + 1;
 
-	switch (renderType) {
+	switch (polygon.renderType) {
 	case POLYGONTYPE_FLAT:
-		renderPolygonsFlat(out, vtop, vsize, color);
+		renderPolygonsFlat(out, vtop, vsize, polygon.colorIndex);
 		break;
 	case POLYGONTYPE_COPPER:
-		renderPolygonsCopper(out, vtop, vsize, color);
+		renderPolygonsCopper(out, vtop, vsize, polygon.colorIndex);
 		break;
 	case POLYGONTYPE_BOPPER:
-		renderPolygonsBopper(out, vtop, vsize, color);
+		renderPolygonsBopper(out, vtop, vsize, polygon.colorIndex);
 		break;
 	case POLYGONTYPE_TELE:
-		renderPolygonsTele(out, vtop, vsize, color);
+		renderPolygonsTele(out, vtop, vsize, polygon.colorIndex);
 		break;
 	case POLYGONTYPE_TRAS:
-		renderPolygonsTras(out, vtop, vsize, color);
+		renderPolygonsTras(out, vtop, vsize, polygon.colorIndex);
 		break;
 	case POLYGONTYPE_TRAME:
-		renderPolygonTrame(out, vtop, vsize, color);
+		renderPolygonTrame(out, vtop, vsize, polygon.colorIndex);
 		break;
 	case POLYGONTYPE_GOURAUD:
-		renderPolygonsGouraud(out, vtop, vsize, color);
+		renderPolygonsGouraud(out, vtop, vsize, polygon.colorIndex);
 		break;
 	case POLYGONTYPE_DITHER:
-		renderPolygonsDither(out, vtop, vsize, color);
+		renderPolygonsDither(out, vtop, vsize, polygon.colorIndex);
 		break;
 	case POLYGONTYPE_MARBLE:
-		renderPolygonsMarble(out, vtop, vsize, color);
+		renderPolygonsMarble(out, vtop, vsize, polygon.colorIndex);
 		break;
 	default:
-		warning("RENDER WARNING: Unsuported render type %d", renderType);
+		warning("RENDER WARNING: Unsuported render type %d", polygon.renderType);
 		break;
 	}
 }
 
-void Renderer::renderPolygons(const Polygon &polygon, Vertex *vertices) {
-	int vleft = 0;
-	int vright = 0;
-	int vtop = 0;
-	int vbottom = 0;
-	computePolygons(polygon.renderType, vertices, polygon.numVertices, vleft, vright, vtop, vbottom);
-	renderPolygons(polygon.renderType, polygon.colorIndex, vleft, vright, vtop, vbottom);
-}
-
 void Renderer::circleFill(int32 x, int32 y, int32 radius, uint8 color) {
 	radius += 1;
 
diff --git a/engines/twine/renderer.h b/engines/twine/renderer.h
index e60b635ebc..f4eb3f3d83 100644
--- a/engines/twine/renderer.h
+++ b/engines/twine/renderer.h
@@ -217,7 +217,6 @@ private:
 	void renderPolygonsMarble(uint8 *out, int vtop, int32 vsize, int32 color) const;
 
 	void computePolygons(int16 polyRenderType, Vertex *vertices, int32 numVertices, int &vleft, int &vright, int &vtop, int &vbottom);
-	void renderPolygons(int32 renderType, int32 color, int vleft, int vright, int vtop, int vbottom);
 
 public:
 	Renderer(TwinEEngine *engine) : _engine(engine) {}


Commit: a75a08cd0e5c6ef262f282f966d8927625992e1a
    https://github.com/scummvm/scummvm/commit/a75a08cd0e5c6ef262f282f966d8927625992e1a
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-11-29T23:50:29+01:00

Commit Message:
TWINE: cleanup and refactored rendering code

Changed paths:
    engines/twine/renderer.cpp


diff --git a/engines/twine/renderer.cpp b/engines/twine/renderer.cpp
index d8670d9b10..3837f193af 100644
--- a/engines/twine/renderer.cpp
+++ b/engines/twine/renderer.cpp
@@ -1033,95 +1033,74 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 			currentPolygon.numVertices = stream.readByte();
 			assert(currentPolygon.numVertices <= 16);
 			currentPolygon.colorIndex = stream.readSint16LE();
-			int32 bestDepth = -32000;
+
+			int16 bestDepth = -32000;
+
 			Polygon *destinationPolygon = (Polygon *)renderBufferPtr;
-			Vertex * const vertices = (Vertex *)(renderBufferPtr + sizeof(Polygon));
+			destinationPolygon->numVertices = currentPolygon.numVertices;
+
+			renderBufferPtr += sizeof(Polygon);
+
+			Vertex * const vertices = (Vertex *)renderBufferPtr;
+			renderBufferPtr += destinationPolygon->numVertices * sizeof(Vertex);
+
+			Vertex *vertex = vertices;
+			int16 counter = destinationPolygon->numVertices;
 
 			// TODO: RECHECK coordinates axis
 			if (currentPolygon.renderType >= 9) {
 				destinationPolygon->renderType = currentPolygon.renderType - 2;
-				destinationPolygon->numVertices = currentPolygon.numVertices;
 				destinationPolygon->colorIndex = currentPolygon.colorIndex;
 
-				renderBufferPtr += sizeof(Polygon);
-
-				int16 counter = destinationPolygon->numVertices;
-
-				Vertex *currentComputedVertex = vertices;
 				do {
 					const int16 shadeEntry = stream.readSint16LE();
 					const int16 shadeValue = currentPolygon.colorIndex + shadeTable[shadeEntry];
 
 					const int16 vertexOffset = stream.readSint16LE();
 					const int16 vertexIndex = vertexOffset / 6;
-					const pointTab *currentVertex = &flattenPoints[vertexIndex];
-
-					currentComputedVertex->colorIndex = shadeValue;
-					currentComputedVertex->x = currentVertex->x;
-					currentComputedVertex->y = currentVertex->y;
+					const pointTab *point = &flattenPoints[vertexIndex];
 
-					renderBufferPtr += sizeof(Vertex);
-
-					int32 currentDepth = currentVertex->z;
-					if (currentDepth > bestDepth) {
-						bestDepth = currentDepth;
-					}
-					++currentComputedVertex;
+					vertex->colorIndex = shadeValue;
+					vertex->x = point->x;
+					vertex->y = point->y;
+					bestDepth = MAX(bestDepth, point->z);
+					++vertex;
 				} while (--counter > 0);
-			} else if (currentPolygon.renderType >= POLYGONTYPE_GOURAUD) { // only 1 shade value is used
+			} else if (currentPolygon.renderType >= POLYGONTYPE_GOURAUD) {
+				// only 1 shade value is used
 				destinationPolygon->renderType = currentPolygon.renderType - POLYGONTYPE_GOURAUD;
 				destinationPolygon->numVertices = currentPolygon.numVertices;
 				const int16 shadeEntry = stream.readSint16LE();
 				const int16 shadeValue = currentPolygon.colorIndex + shadeTable[shadeEntry];
 				destinationPolygon->colorIndex = shadeValue;
 
-				renderBufferPtr += sizeof(Polygon);
-				Vertex *currentComputedVertex = vertices;
-				int16 counter = destinationPolygon->numVertices;
-
 				do {
 					const int16 vertexOffset = stream.readSint16LE();
 					const int16 vertexIndex = vertexOffset / 6;
-					const pointTab *currentVertex = &flattenPoints[vertexIndex];
-
-					//currentVertex->shadeValue = 0;
-					currentComputedVertex->x = currentVertex->x;
-					currentComputedVertex->y = currentVertex->y;
-
-					renderBufferPtr += sizeof(Vertex);
+					const pointTab *point = &flattenPoints[vertexIndex];
 
-					int32 currentDepth = currentVertex->z;
-					if (currentDepth > bestDepth) {
-						bestDepth = currentDepth;
-					}
-					++currentComputedVertex;
+					vertex->colorIndex = 0;
+					vertex->x = point->x;
+					vertex->y = point->y;
+					bestDepth = MAX(bestDepth, point->z);
+					++vertex;
 				} while (--counter > 0);
-			} else { // no shade is used
+			} else {
+				// no shade is used
 				destinationPolygon->renderType = currentPolygon.renderType;
 				destinationPolygon->numVertices = currentPolygon.numVertices;
 				destinationPolygon->colorIndex = currentPolygon.colorIndex;
 
-				renderBufferPtr += sizeof(Polygon);
-
-				Vertex *currentComputedVertex = vertices;
-				int16 counter = currentPolygon.numVertices;
-
 				do {
 					const int16 vertexOffset = stream.readSint16LE();
 					const int16 vertexIndex = vertexOffset / 6;
-					const pointTab *currentVertex = &flattenPoints[vertexIndex];
-
-					//currentVertex->shadeValue = 0;
-					currentComputedVertex->x = currentVertex->x;
-					currentComputedVertex->y = currentVertex->y;
+					const pointTab *point = &flattenPoints[vertexIndex];
 
-					renderBufferPtr += sizeof(Vertex);
-
-					int32 currentDepth = currentVertex->z;
-					if (currentDepth > bestDepth) {
-						bestDepth = currentDepth;
-					}
-					++currentComputedVertex;
+					vertex->colorIndex = 0;
+					vertex->x = point->x;
+					vertex->y = point->y;
+					bestDepth = MAX(bestDepth, point->z);
+					++vertex;
 				} while (--counter > 0);
 			}
 


Commit: a71b3a3ac00e997cffcbdde47d22121f48a0f05e
    https://github.com/scummvm/scummvm/commit/a71b3a3ac00e997cffcbdde47d22121f48a0f05e
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-11-29T23:50:29+01:00

Commit Message:
TWINE: reduced code duplication

Changed paths:
    engines/twine/renderer.cpp


diff --git a/engines/twine/renderer.cpp b/engines/twine/renderer.cpp
index 3837f193af..78f51c8844 100644
--- a/engines/twine/renderer.cpp
+++ b/engines/twine/renderer.cpp
@@ -1028,16 +1028,15 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 		int16 primitiveCounter = numPolygons; // the number of primitives = the number of polygons
 
 		do { // loop that load all the polygons
-			Polygon currentPolygon;
-			currentPolygon.renderType = stream.readByte();
-			currentPolygon.numVertices = stream.readByte();
-			assert(currentPolygon.numVertices <= 16);
-			currentPolygon.colorIndex = stream.readSint16LE();
+			const uint8 renderType = stream.readByte();
+			const uint8 numVertices = stream.readByte();
+			assert(numVertices <= 16);
+			const int16 colorIndex = stream.readSint16LE();
 
 			int16 bestDepth = -32000;
 
 			Polygon *destinationPolygon = (Polygon *)renderBufferPtr;
-			destinationPolygon->numVertices = currentPolygon.numVertices;
+			destinationPolygon->numVertices = numVertices;
 
 			renderBufferPtr += sizeof(Polygon);
 
@@ -1048,13 +1047,13 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 			int16 counter = destinationPolygon->numVertices;
 
 			// TODO: RECHECK coordinates axis
-			if (currentPolygon.renderType >= 9) {
-				destinationPolygon->renderType = currentPolygon.renderType - 2;
-				destinationPolygon->colorIndex = currentPolygon.colorIndex;
+			if (renderType >= 9) {
+				destinationPolygon->renderType = renderType - 2;
+				destinationPolygon->colorIndex = colorIndex;
 
 				do {
 					const int16 shadeEntry = stream.readSint16LE();
-					const int16 shadeValue = currentPolygon.colorIndex + shadeTable[shadeEntry];
+					const int16 shadeValue = colorIndex + shadeTable[shadeEntry];
 
 					const int16 vertexOffset = stream.readSint16LE();
 					const int16 vertexIndex = vertexOffset / 6;
@@ -1066,30 +1065,18 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 					bestDepth = MAX(bestDepth, point->z);
 					++vertex;
 				} while (--counter > 0);
-			} else if (currentPolygon.renderType >= POLYGONTYPE_GOURAUD) {
-				// only 1 shade value is used
-				destinationPolygon->renderType = currentPolygon.renderType - POLYGONTYPE_GOURAUD;
-				destinationPolygon->numVertices = currentPolygon.numVertices;
-				const int16 shadeEntry = stream.readSint16LE();
-				const int16 shadeValue = currentPolygon.colorIndex + shadeTable[shadeEntry];
-				destinationPolygon->colorIndex = shadeValue;
-
-				do {
-					const int16 vertexOffset = stream.readSint16LE();
-					const int16 vertexIndex = vertexOffset / 6;
-					const pointTab *point = &flattenPoints[vertexIndex];
-
-					vertex->colorIndex = 0;
-					vertex->x = point->x;
-					vertex->y = point->y;
-					bestDepth = MAX(bestDepth, point->z);
-					++vertex;
-				} while (--counter > 0);
 			} else {
-				// no shade is used
-				destinationPolygon->renderType = currentPolygon.renderType;
-				destinationPolygon->numVertices = currentPolygon.numVertices;
-				destinationPolygon->colorIndex = currentPolygon.colorIndex;
+				if (renderType >= POLYGONTYPE_GOURAUD) {
+					// only 1 shade value is used
+					destinationPolygon->renderType = renderType - POLYGONTYPE_GOURAUD;
+					const int16 shadeEntry = stream.readSint16LE();
+					const int16 shadeValue = colorIndex + shadeTable[shadeEntry];
+					destinationPolygon->colorIndex = shadeValue;
+				} else {
+					// no shade is used
+					destinationPolygon->renderType = renderType;
+					destinationPolygon->colorIndex = colorIndex;
+				}
 
 				do {
 					const int16 vertexOffset = stream.readSint16LE();


Commit: 91dc794937da5581110c574da9861fb3d6c61640
    https://github.com/scummvm/scummvm/commit/91dc794937da5581110c574da9861fb3d6c61640
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-11-29T23:50:29+01:00

Commit Message:
TWINE: split render command buffer handling into several methods

Changed paths:
    engines/twine/renderer.cpp
    engines/twine/renderer.h


diff --git a/engines/twine/renderer.cpp b/engines/twine/renderer.cpp
index 78f51c8844..a4d95ca532 100644
--- a/engines/twine/renderer.cpp
+++ b/engines/twine/renderer.cpp
@@ -281,7 +281,7 @@ void Renderer::processRotatedElement(int32 *targetMatrix, const uint8 *pointsPtr
 		warning("RENDER WARNING: No points in this model!");
 	}
 
-	applyPointsRotation((const pointTab*)(pointsPtr + firstPoint), numOfPoints2, &computedPoints[firstPoint / sizeof(pointTab)], targetMatrix);
+	applyPointsRotation((const pointTab *)(pointsPtr + firstPoint), numOfPoints2, &computedPoints[firstPoint / sizeof(pointTab)], targetMatrix);
 }
 
 void Renderer::applyPointsTranslation(const pointTab *pointsPtr, int32 numPoints, pointTab *destPoints, const int32 *translationMatrix) {
@@ -330,7 +330,7 @@ void Renderer::processTranslatedElement(int32 *targetMatrix, const uint8 *points
 		}
 	}
 
-	applyPointsTranslation((const pointTab*)(pointsPtr + elemPtr->firstPoint), elemPtr->numOfPoints, &computedPoints[elemPtr->firstPoint / sizeof(pointTab)], targetMatrix);
+	applyPointsTranslation((const pointTab *)(pointsPtr + elemPtr->firstPoint), elemPtr->numOfPoints, &computedPoints[elemPtr->firstPoint / sizeof(pointTab)], targetMatrix);
 }
 
 void Renderer::translateGroup(int16 ax, int16 bx, int16 cx) {
@@ -464,7 +464,7 @@ void Renderer::computePolygons(int16 polyRenderType, Vertex *vertices, int32 num
 		float slope = (float)hsize / (float)vsize;
 		slope = up ? -slope : slope;
 
-		for (int32  i = 0; i < vsize + 2; i++) {
+		for (int32 i = 0; i < vsize + 2; i++) {
 			if (outPtr - polyTab < ARRAYSIZE(polyTab)) {
 				if (outPtr - polyTab > 0) {
 					*outPtr = xpos;
@@ -749,7 +749,7 @@ void Renderer::renderPolygonsGouraud(uint8 *out, int vtop, int32 vsize, int32 co
 			int16 colorSize = stopColor - startColor;
 
 			int16 stop = ptr1[SCREEN_HEIGHT]; // stop
-			int16 start = ptr1[0];  // start
+			int16 start = ptr1[0];            // start
 
 			ptr1++;
 			uint8 *out2 = start + out;
@@ -837,7 +837,7 @@ void Renderer::renderPolygonsDither(uint8 *out, int vtop, int32 vsize, int32 col
 	do {
 		if (currentLine >= 0 && currentLine < SCREEN_HEIGHT) {
 			int16 stop = ptr1[SCREEN_HEIGHT]; // stop
-			int16 start = ptr1[0];  // start
+			int16 start = ptr1[0];            // start
 			ptr1++;
 			int32 hsize = stop - start;
 
@@ -964,7 +964,7 @@ void Renderer::renderPolygons(const Polygon &polygon, Vertex *vertices) {
 	int vbottom = 0;
 	computePolygons(polygon.renderType, vertices, polygon.numVertices, vleft, vright, vtop, vbottom);
 
-	uint8 *out = (uint8*)_engine->frontVideoBuffer.getBasePtr(0, vtop);
+	uint8 *out = (uint8 *)_engine->frontVideoBuffer.getBasePtr(0, vtop);
 	const int32 vsize = vbottom - vtop + 1;
 
 	switch (polygon.renderType) {
@@ -1017,176 +1017,189 @@ void Renderer::circleFill(int32 x, int32 y, int32 radius, uint8 color) {
 	}
 }
 
-int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTabEntry **renderTabEntryPtr) {
-	// TODO: proper size
-	Common::MemoryReadStream stream(ptr, 100000);
-	int16 numPolygons = stream.readSint16LE();
+uint8 *Renderer::prepareSpheres(Common::MemoryReadStream &stream, int32 &numOfPrimitives, RenderCommand **renderCmds, uint8 *renderBufferPtr) {
+	int16 numSpheres = stream.readSint16LE();
+	if (numSpheres <= 0) {
+		return renderBufferPtr;
+	}
+	numOfPrimitives += numSpheres;
+	do {
+		sphereData *sphere = (sphereData *)renderBufferPtr;
+		stream.skip(1);
+		sphere->colorIndex = stream.readByte();
+		stream.skip(2);
+		sphere->radius = stream.readUint16LE();
+		const int16 centerOffset = stream.readUint16LE();
+		const int16 centerIndex = centerOffset / 6;
+		sphere->x = flattenPoints[centerIndex].x;
+		sphere->y = flattenPoints[centerIndex].y;
+
+		(*renderCmds)->depth = flattenPoints[centerIndex].z;
+		(*renderCmds)->renderType = RENDERTYPE_DRAWSPHERE;
+		(*renderCmds)->dataPtr = renderBufferPtr;
+		(*renderCmds)++;
+
+		renderBufferPtr += sizeof(sphereData);
+	} while (--numSpheres);
+
+	return renderBufferPtr;
+}
 
-	uint8 *renderBufferPtr = renderCoordinatesBuffer;
+uint8 *Renderer::prepareLines(Common::MemoryReadStream &stream, int32 &numOfPrimitives, RenderCommand **renderCmds, uint8 *renderBufferPtr) {
+	int16 numLines = stream.readSint16LE();
+	if (numLines <= 0) {
+		return renderBufferPtr;
+	}
+	numOfPrimitives += numLines;
 
-	if (numPolygons > 0) {
-		int16 primitiveCounter = numPolygons; // the number of primitives = the number of polygons
+	do {
+		lineData line;
+		line.colorIndex = stream.readByte();
+		stream.skip(3);
+		line.firstPointOffset = stream.readSint16LE();
+		line.secondPointOffset = stream.readSint16LE();
+		lineCoordinates *lineCoordinatesPtr = (lineCoordinates *)renderBufferPtr;
+
+		if (line.firstPointOffset % 6 != 0 || line.secondPointOffset % 6 != 0) {
+			error("RENDER ERROR: lineDataPtr reference is malformed!");
+		}
 
-		do { // loop that load all the polygons
-			const uint8 renderType = stream.readByte();
-			const uint8 numVertices = stream.readByte();
-			assert(numVertices <= 16);
-			const int16 colorIndex = stream.readSint16LE();
+		const int32 point1Index = line.firstPointOffset / 6;
+		const int32 point2Index = line.secondPointOffset / 6;
+		lineCoordinatesPtr->colorIndex = line.colorIndex;
+		lineCoordinatesPtr->x1 = flattenPoints[point1Index].x;
+		lineCoordinatesPtr->y1 = flattenPoints[point1Index].y;
+		lineCoordinatesPtr->x2 = flattenPoints[point2Index].x;
+		lineCoordinatesPtr->y2 = flattenPoints[point2Index].y;
+		(*renderCmds)->depth = MAX(flattenPoints[point1Index].z, flattenPoints[point2Index].z);
+		(*renderCmds)->renderType = RENDERTYPE_DRAWLINE;
+		(*renderCmds)->dataPtr = renderBufferPtr;
+		(*renderCmds)++;
+
+		renderBufferPtr += sizeof(lineCoordinates);
+	} while (--numLines);
+
+	return renderBufferPtr;
+}
 
-			int16 bestDepth = -32000;
+uint8 *Renderer::preparePolygons(Common::MemoryReadStream &stream, int32 &numOfPrimitives, RenderCommand **renderCmds, uint8 *renderBufferPtr) {
+	int16 numPolygons = stream.readSint16LE();
+	if (numPolygons <= 0) {
+		return renderBufferPtr;
+	}
+	int16 primitiveCounter = numPolygons; // the number of primitives = the number of polygons
 
-			Polygon *destinationPolygon = (Polygon *)renderBufferPtr;
-			destinationPolygon->numVertices = numVertices;
+	do { // loop that load all the polygons
+		const uint8 renderType = stream.readByte();
+		const uint8 numVertices = stream.readByte();
+		assert(numVertices <= 16);
+		const int16 colorIndex = stream.readSint16LE();
 
-			renderBufferPtr += sizeof(Polygon);
+		int16 bestDepth = -32000;
 
-			Vertex * const vertices = (Vertex *)renderBufferPtr;
-			renderBufferPtr += destinationPolygon->numVertices * sizeof(Vertex);
+		Polygon *destinationPolygon = (Polygon *)renderBufferPtr;
+		destinationPolygon->numVertices = numVertices;
 
-			Vertex *vertex = vertices;
-			int16 counter = destinationPolygon->numVertices;
+		renderBufferPtr += sizeof(Polygon);
 
-			// TODO: RECHECK coordinates axis
-			if (renderType >= 9) {
-				destinationPolygon->renderType = renderType - 2;
-				destinationPolygon->colorIndex = colorIndex;
+		Vertex *const vertices = (Vertex *)renderBufferPtr;
+		renderBufferPtr += destinationPolygon->numVertices * sizeof(Vertex);
 
-				do {
-					const int16 shadeEntry = stream.readSint16LE();
-					const int16 shadeValue = colorIndex + shadeTable[shadeEntry];
+		Vertex *vertex = vertices;
+		int16 counter = destinationPolygon->numVertices;
 
-					const int16 vertexOffset = stream.readSint16LE();
-					const int16 vertexIndex = vertexOffset / 6;
-					const pointTab *point = &flattenPoints[vertexIndex];
+		// TODO: RECHECK coordinates axis
+		if (renderType >= 9) {
+			destinationPolygon->renderType = renderType - 2;
+			destinationPolygon->colorIndex = colorIndex;
 
-					vertex->colorIndex = shadeValue;
-					vertex->x = point->x;
-					vertex->y = point->y;
-					bestDepth = MAX(bestDepth, point->z);
-					++vertex;
-				} while (--counter > 0);
-			} else {
-				if (renderType >= POLYGONTYPE_GOURAUD) {
-					// only 1 shade value is used
-					destinationPolygon->renderType = renderType - POLYGONTYPE_GOURAUD;
-					const int16 shadeEntry = stream.readSint16LE();
-					const int16 shadeValue = colorIndex + shadeTable[shadeEntry];
-					destinationPolygon->colorIndex = shadeValue;
-				} else {
-					// no shade is used
-					destinationPolygon->renderType = renderType;
-					destinationPolygon->colorIndex = colorIndex;
-				}
+			do {
+				const int16 shadeEntry = stream.readSint16LE();
+				const int16 shadeValue = colorIndex + shadeTable[shadeEntry];
+
+				const int16 vertexOffset = stream.readSint16LE();
+				const int16 vertexIndex = vertexOffset / 6;
+				const pointTab *point = &flattenPoints[vertexIndex];
 
-				do {
-					const int16 vertexOffset = stream.readSint16LE();
-					const int16 vertexIndex = vertexOffset / 6;
-					const pointTab *point = &flattenPoints[vertexIndex];
-
-					vertex->colorIndex = 0;
-					vertex->x = point->x;
-					vertex->y = point->y;
-					bestDepth = MAX(bestDepth, point->z);
-					++vertex;
-				} while (--counter > 0);
+				vertex->colorIndex = shadeValue;
+				vertex->x = point->x;
+				vertex->y = point->y;
+				bestDepth = MAX(bestDepth, point->z);
+				++vertex;
+			} while (--counter > 0);
+		} else {
+			if (renderType >= POLYGONTYPE_GOURAUD) {
+				// only 1 shade value is used
+				destinationPolygon->renderType = renderType - POLYGONTYPE_GOURAUD;
+				const int16 shadeEntry = stream.readSint16LE();
+				const int16 shadeValue = colorIndex + shadeTable[shadeEntry];
+				destinationPolygon->colorIndex = shadeValue;
+			} else {
+				// no shade is used
+				destinationPolygon->renderType = renderType;
+				destinationPolygon->colorIndex = colorIndex;
 			}
 
+			do {
+				const int16 vertexOffset = stream.readSint16LE();
+				const int16 vertexIndex = vertexOffset / 6;
+				const pointTab *point = &flattenPoints[vertexIndex];
+
+				vertex->colorIndex = destinationPolygon->colorIndex;
+				vertex->x = point->x;
+				vertex->y = point->y;
+				bestDepth = MAX(bestDepth, point->z);
+				++vertex;
+			} while (--counter > 0);
+		}
+
 #if 0
-			const int16 bx = vertices[1].x - vertices[0].x;
-			const int16 ax = (vertices[0].y - vertices[2].y) * bx;
+		const int16 bx = vertices[1].x - vertices[0].x;
+		const int16 ax = (vertices[0].y - vertices[2].y) * bx;
 
-			const int16 cx = vertices[1].y - vertices[0].y;
-			const int16 dx = (vertices[0].x - vertices[2].x) * cx - ax;
+		const int16 cx = vertices[1].y - vertices[0].y;
+		const int16 dx = (vertices[0].x - vertices[2].x) * cx - ax;
 #endif
-			numOfPrimitives++;
-
-			(*renderTabEntryPtr)->depth = bestDepth;
-			(*renderTabEntryPtr)->renderType = RENDERTYPE_DRAWPOLYGON;
-			(*renderTabEntryPtr)->dataPtr = (uint8*)destinationPolygon;
-			(*renderTabEntryPtr)++;
-		} while (--primitiveCounter);
-	}
-
-	// prepare lines
-
-	int16 temp = stream.readSint16LE();
-	if (temp) {
-		numOfPrimitives += temp;
-		do {
-			lineData line;
-			line.colorIndex = stream.readByte();
-			stream.skip(3);
-			line.firstPointOffset = stream.readSint16LE();
-			line.secondPointOffset = stream.readSint16LE();
-			lineCoordinates *lineCoordinatesPtr = (lineCoordinates *)renderBufferPtr;
-
-			if (line.firstPointOffset % 6 != 0 || line.secondPointOffset % 6 != 0) {
-				error("RENDER ERROR: lineDataPtr reference is malformed!");
-			}
-
-			const int32 point1Index = line.firstPointOffset / 6;
-			const int32 point2Index = line.secondPointOffset / 6;
-			lineCoordinatesPtr->colorIndex = line.colorIndex;
-			lineCoordinatesPtr->x1 = flattenPoints[point1Index].x;
-			lineCoordinatesPtr->y1 = flattenPoints[point1Index].y;
-			lineCoordinatesPtr->x2 = flattenPoints[point2Index].x;
-			lineCoordinatesPtr->y2 = flattenPoints[point2Index].y;
-			(*renderTabEntryPtr)->depth = MAX(flattenPoints[point1Index].z, flattenPoints[point2Index].z);
-			(*renderTabEntryPtr)->renderType = RENDERTYPE_DRAWLINE;
-			(*renderTabEntryPtr)->dataPtr = renderBufferPtr;
-			(*renderTabEntryPtr)++;
-
-			renderBufferPtr += sizeof(lineCoordinates);
-		} while (--temp);
-	}
+		numOfPrimitives++;
 
-	// prepare spheres
-	temp = stream.readSint16LE();
-	if (temp) {
-		numOfPrimitives += temp;
-		do {
-			sphereData *sphere = (sphereData *)renderBufferPtr;
-			stream.skip(1);
-			sphere->colorIndex = stream.readByte();
-			stream.skip(2);
-			sphere->radius = stream.readUint16LE();
-			const int16 centerOffset = stream.readUint16LE();
-			const int16 centerIndex = centerOffset / 6;
-			sphere->x = flattenPoints[centerIndex].x;
-			sphere->y = flattenPoints[centerIndex].y;
-
-			(*renderTabEntryPtr)->depth = flattenPoints[centerOffset / sizeof(pointTab)].z;
-			(*renderTabEntryPtr)->renderType = RENDERTYPE_DRAWSPHERE;
-			(*renderTabEntryPtr)->dataPtr = renderBufferPtr;
-			(*renderTabEntryPtr)++;
-
-			renderBufferPtr += sizeof(sphereData);
-		} while (--temp);
-	}
+		(*renderCmds)->depth = bestDepth;
+		(*renderCmds)->renderType = RENDERTYPE_DRAWPOLYGON;
+		(*renderCmds)->dataPtr = (uint8 *)destinationPolygon;
+		(*renderCmds)++;
+	} while (--primitiveCounter);
 
-	const renderTabEntry *renderTabEntryPtr2 = renderTab;
+	return renderBufferPtr;
+}
 
-	renderTabEntry *renderTabSortedPtr = renderTabSorted;
+const Renderer::RenderCommand *Renderer::depthSortRenderCommands(int32 numOfPrimitives) {
+	RenderCommand *sortedCmd = _renderCmdsSortedByDepth;
 	int32 bestPoly = 0;
 	for (int32 i = 0; i < numOfPrimitives; i++) { // then we sort the polygones | WARNING: very slow | TODO: improve this
-		renderTabEntryPtr2 = renderTab;
-		int16 bestZ = -0x7FFF;
+		const RenderCommand *cmd = _renderCmds;
+		int16 bestZ = -32767;
 		for (int32 j = 0; j < numOfPrimitives; j++) {
-			if (renderTabEntryPtr2->depth > bestZ) {
-				bestZ = renderTabEntryPtr2->depth;
+			if (cmd->depth > bestZ) {
+				bestZ = cmd->depth;
 				bestPoly = j;
 			}
-			renderTabEntryPtr2++;
+			cmd++;
 		}
-		renderTabSortedPtr->depth = renderTab[bestPoly].depth;
-		renderTabSortedPtr->renderType = renderTab[bestPoly].renderType;
-		renderTabSortedPtr->dataPtr = renderTab[bestPoly].dataPtr;
-		renderTabSortedPtr++;
-		renderTab[bestPoly].depth = -0x7FFF;
+		*sortedCmd = _renderCmds[bestPoly];
+		sortedCmd++;
+		_renderCmds[bestPoly].depth = -32767;
 	}
-	renderTabEntryPtr2 = renderTabSorted;
 
-	// prepare to render elements
+	return _renderCmdsSortedByDepth;
+}
+
+int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, RenderCommand **renderCmds) {
+	// TODO: proper size
+	Common::MemoryReadStream stream(ptr, 100000);
+
+	uint8 *renderBufferPtr = renderCoordinatesBuffer;
+	renderBufferPtr = preparePolygons(stream, numOfPrimitives, renderCmds, renderBufferPtr);
+	renderBufferPtr = prepareLines(stream, numOfPrimitives, renderCmds, renderBufferPtr);
+	renderBufferPtr = prepareSpheres(stream, numOfPrimitives, renderCmds, renderBufferPtr);
 
 	if (numOfPrimitives == 0) {
 		_engine->_redraw->renderRect.right = -1;
@@ -1195,18 +1208,17 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 		_engine->_redraw->renderRect.top = -1;
 		return -1;
 	}
+	const RenderCommand *cmds = depthSortRenderCommands(numOfPrimitives);
 
 	int16 primitiveCounter = numOfPrimitives;
-	uint8* afterPolyHeaderPtr = ptr + stream.pos();
 
 	do {
-		int16 type = renderTabEntryPtr2->renderType;
-		uint8 *pointer = renderTabEntryPtr2->dataPtr;
-		afterPolyHeaderPtr += 8;
+		int16 type = cmds->renderType;
+		uint8 *pointer = cmds->dataPtr;
 
 		switch (type) {
-		case RENDERTYPE_DRAWLINE: { // draw a line
-			const lineCoordinates *lineCoords = (const lineCoordinates*)pointer;
+		case RENDERTYPE_DRAWLINE: {
+			const lineCoordinates *lineCoords = (const lineCoordinates *)pointer;
 			const int32 x1 = lineCoords->x1;
 			const int32 y1 = lineCoords->y1;
 			const int32 x2 = lineCoords->x2;
@@ -1214,15 +1226,15 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 			_engine->_interface->drawLine(x1, y1, x2, y2, lineCoords->colorIndex);
 			break;
 		}
-		case RENDERTYPE_DRAWPOLYGON: { // draw a polygon
-			const Polygon* header = (const Polygon*)pointer;
-			Vertex* vertices = (Vertex*)(pointer + sizeof(Polygon));
+		case RENDERTYPE_DRAWPOLYGON: {
+			const Polygon *header = (const Polygon *)pointer;
+			Vertex *vertices = (Vertex *)(pointer + sizeof(Polygon));
 			renderPolygons(*header, vertices);
 			break;
 		}
-		case RENDERTYPE_DRAWSPHERE: { // draw a sphere
-			sphereData* sphere = (sphereData*)pointer;
-			int32 radius =  sphere->radius;
+		case RENDERTYPE_DRAWSPHERE: {
+			sphereData *sphere = (sphereData *)pointer;
+			int32 radius = sphere->radius;
 
 			if (!isUsingOrhoProjection) {
 				radius = (radius * cameraPosY) / (cameraPosX + *(const int16 *)pointer); // TODO: this does not make sense.
@@ -1257,12 +1269,12 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, renderTab
 			break;
 		}
 
-		renderTabEntryPtr2++;
+		cmds++;
 	} while (--primitiveCounter);
 	return 0;
 }
 
-int32 Renderer::renderAnimatedModel(uint8 *bodyPtr, renderTabEntry *renderTabEntryPtr) {
+int32 Renderer::renderAnimatedModel(uint8 *bodyPtr, RenderCommand *renderCmds) {
 	//	int32 *tmpLightMatrix;
 	int32 numOfPoints = *((const uint16 *)bodyPtr);
 	bodyPtr += 2;
@@ -1464,7 +1476,7 @@ int32 Renderer::renderAnimatedModel(uint8 *bodyPtr, renderTabEntry *renderTabEnt
 		} while (--numOfPrimitives);
 	}
 
-	return renderModelElements(numOfPrimitives, (uint8 *)shadePtr, &renderTabEntryPtr);
+	return renderModelElements(numOfPrimitives, (uint8 *)shadePtr, &renderCmds);
 }
 
 void Renderer::prepareIsoModel(uint8 *bodyPtr) { // loadGfxSub
@@ -1533,7 +1545,7 @@ int32 Renderer::renderIsoModel(int32 x, int32 y, int32 z, int32 angleX, int32 an
 	if (bodyHeader & 2) { // if animated
 		// the mostly used renderer code
 		// restart at the beginning of the renderTable
-		return renderAnimatedModel(ptr, renderTab);
+		return renderAnimatedModel(ptr, _renderCmds);
 	}
 	error("Unsupported unanimated model render!");
 	return 0;
diff --git a/engines/twine/renderer.h b/engines/twine/renderer.h
index f4eb3f3d83..50d9c3b1b9 100644
--- a/engines/twine/renderer.h
+++ b/engines/twine/renderer.h
@@ -36,6 +36,10 @@
 #define POLYGONTYPE_GOURAUD 7
 #define POLYGONTYPE_DITHER 8
 
+namespace Common {
+class MemoryReadStream;
+}
+
 namespace TwinE {
 
 class TwinEEngine;
@@ -57,7 +61,7 @@ class Renderer {
 private:
 	TwinEEngine *_engine;
 
-	struct renderTabEntry {
+	struct RenderCommand {
 		int16 depth = 0;
 		int16 renderType = 0;
 		uint8 *dataPtr = nullptr;
@@ -145,9 +149,9 @@ private:
 		uint16 temp = 0;
 	};
 
-	int32 renderAnimatedModel(uint8 *bodyPtr, renderTabEntry *renderTabEntryPtr);
+	int32 renderAnimatedModel(uint8 *bodyPtr, RenderCommand *renderCmds);
 	void circleFill(int32 x, int32 y, int32 radius, uint8 color);
-	int32 renderModelElements(int32 numOfPrimitives, uint8 *pointer, renderTabEntry** renderTabEntryPtr);
+	int32 renderModelElements(int32 numOfPrimitives, uint8 *pointer, RenderCommand** renderCmds);
 	void getBaseRotationPosition(int32 x, int32 y, int32 z);
 	void getCameraAnglePositions(int32 x, int32 y, int32 z);
 	void applyRotation(int32 *targetMatrix, const int32 *currentMatrix);
@@ -196,8 +200,8 @@ private:
 	pointTab flattenPoints[800];  // _flattenPointTable
 	int16 shadeTable[500] {0};
 
-	renderTabEntry renderTab[1000];
-	renderTabEntry renderTabSorted[1000];
+	RenderCommand _renderCmds[1000];
+	RenderCommand _renderCmdsSortedByDepth[1000];
 	uint8 renderCoordinatesBuffer[10000] {0};
 
 	int16 polyTab[960] {0};
@@ -218,6 +222,11 @@ private:
 
 	void computePolygons(int16 polyRenderType, Vertex *vertices, int32 numVertices, int &vleft, int &vright, int &vtop, int &vbottom);
 
+	const RenderCommand *depthSortRenderCommands(int32 numOfPrimitives);
+	uint8* preparePolygons(Common::MemoryReadStream &stream, int32 &numOfPrimitives, RenderCommand **renderCmds, uint8 *renderBufferPtr);
+	uint8* prepareSpheres(Common::MemoryReadStream &stream, int32 &numOfPrimitives, RenderCommand **renderCmds, uint8 *renderBufferPtr);
+	uint8* prepareLines(Common::MemoryReadStream &stream, int32 &numOfPrimitives, RenderCommand **renderCmds, uint8 *renderBufferPtr);
+
 public:
 	Renderer(TwinEEngine *engine) : _engine(engine) {}
 


Commit: 1d08ac4ea6476bc06ebe0b3a645d31fd0370488b
    https://github.com/scummvm/scummvm/commit/1d08ac4ea6476bc06ebe0b3a645d31fd0370488b
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-11-29T23:50:29+01:00

Commit Message:
TWINE: renamed structs

Changed paths:
    engines/twine/renderer.cpp
    engines/twine/renderer.h


diff --git a/engines/twine/renderer.cpp b/engines/twine/renderer.cpp
index a4d95ca532..993a02d385 100644
--- a/engines/twine/renderer.cpp
+++ b/engines/twine/renderer.cpp
@@ -1024,7 +1024,7 @@ uint8 *Renderer::prepareSpheres(Common::MemoryReadStream &stream, int32 &numOfPr
 	}
 	numOfPrimitives += numSpheres;
 	do {
-		sphereData *sphere = (sphereData *)renderBufferPtr;
+		CmdRenderSphere *sphere = (CmdRenderSphere *)renderBufferPtr;
 		stream.skip(1);
 		sphere->colorIndex = stream.readByte();
 		stream.skip(2);
@@ -1039,7 +1039,7 @@ uint8 *Renderer::prepareSpheres(Common::MemoryReadStream &stream, int32 &numOfPr
 		(*renderCmds)->dataPtr = renderBufferPtr;
 		(*renderCmds)++;
 
-		renderBufferPtr += sizeof(sphereData);
+		renderBufferPtr += sizeof(CmdRenderSphere);
 	} while (--numSpheres);
 
 	return renderBufferPtr;
@@ -1058,7 +1058,7 @@ uint8 *Renderer::prepareLines(Common::MemoryReadStream &stream, int32 &numOfPrim
 		stream.skip(3);
 		line.firstPointOffset = stream.readSint16LE();
 		line.secondPointOffset = stream.readSint16LE();
-		lineCoordinates *lineCoordinatesPtr = (lineCoordinates *)renderBufferPtr;
+		CmdRenderLine *lineCoordinatesPtr = (CmdRenderLine *)renderBufferPtr;
 
 		if (line.firstPointOffset % 6 != 0 || line.secondPointOffset % 6 != 0) {
 			error("RENDER ERROR: lineDataPtr reference is malformed!");
@@ -1076,7 +1076,7 @@ uint8 *Renderer::prepareLines(Common::MemoryReadStream &stream, int32 &numOfPrim
 		(*renderCmds)->dataPtr = renderBufferPtr;
 		(*renderCmds)++;
 
-		renderBufferPtr += sizeof(lineCoordinates);
+		renderBufferPtr += sizeof(CmdRenderLine);
 	} while (--numLines);
 
 	return renderBufferPtr;
@@ -1174,9 +1174,10 @@ uint8 *Renderer::preparePolygons(Common::MemoryReadStream &stream, int32 &numOfP
 const Renderer::RenderCommand *Renderer::depthSortRenderCommands(int32 numOfPrimitives) {
 	RenderCommand *sortedCmd = _renderCmdsSortedByDepth;
 	int32 bestPoly = 0;
+	const int16 minDepth = -32767;
 	for (int32 i = 0; i < numOfPrimitives; i++) { // then we sort the polygones | WARNING: very slow | TODO: improve this
 		const RenderCommand *cmd = _renderCmds;
-		int16 bestZ = -32767;
+		int16 bestZ = minDepth;
 		for (int32 j = 0; j < numOfPrimitives; j++) {
 			if (cmd->depth > bestZ) {
 				bestZ = cmd->depth;
@@ -1186,7 +1187,7 @@ const Renderer::RenderCommand *Renderer::depthSortRenderCommands(int32 numOfPrim
 		}
 		*sortedCmd = _renderCmds[bestPoly];
 		sortedCmd++;
-		_renderCmds[bestPoly].depth = -32767;
+		_renderCmds[bestPoly].depth = minDepth;
 	}
 
 	return _renderCmdsSortedByDepth;
@@ -1218,7 +1219,7 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, RenderCom
 
 		switch (type) {
 		case RENDERTYPE_DRAWLINE: {
-			const lineCoordinates *lineCoords = (const lineCoordinates *)pointer;
+			const CmdRenderLine *lineCoords = (const CmdRenderLine *)pointer;
 			const int32 x1 = lineCoords->x1;
 			const int32 y1 = lineCoords->y1;
 			const int32 x2 = lineCoords->x2;
@@ -1233,7 +1234,7 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, RenderCom
 			break;
 		}
 		case RENDERTYPE_DRAWSPHERE: {
-			sphereData *sphere = (sphereData *)pointer;
+			CmdRenderSphere *sphere = (CmdRenderSphere *)pointer;
 			int32 radius = sphere->radius;
 
 			if (!isUsingOrhoProjection) {
diff --git a/engines/twine/renderer.h b/engines/twine/renderer.h
index 50d9c3b1b9..809af3b500 100644
--- a/engines/twine/renderer.h
+++ b/engines/twine/renderer.h
@@ -96,7 +96,7 @@ private:
 	#include "common/pack-end.h"
 	static_assert(sizeof(elementEntry) == 38, "Unexpected elementEntry size");
 
-	struct lineCoordinates {
+	struct CmdRenderLine {
 		uint8 colorIndex = 0;
 		uint8 unk1 = 0;
 		uint8 unk2 = 0;
@@ -121,7 +121,7 @@ private:
 		int16 dataOffset = 0;
 	};
 
-	struct sphereData {
+	struct CmdRenderSphere {
 		int8 colorIndex = 0;
 		int16 x = 0;
 		int16 y = 0;


Commit: eb2f00a74a0f7f73c9dbeee21e852a8a7a759a0a
    https://github.com/scummvm/scummvm/commit/eb2f00a74a0f7f73c9dbeee21e852a8a7a759a0a
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-11-29T23:50:29+01:00

Commit Message:
TWINE: group render command structs

Changed paths:
    engines/twine/renderer.h


diff --git a/engines/twine/renderer.h b/engines/twine/renderer.h
index 809af3b500..16a83df555 100644
--- a/engines/twine/renderer.h
+++ b/engines/twine/renderer.h
@@ -67,6 +67,24 @@ private:
 		uint8 *dataPtr = nullptr;
 	};
 
+	struct CmdRenderLine {
+		uint8 colorIndex = 0;
+		uint8 unk1 = 0;
+		uint8 unk2 = 0;
+		uint8 unk3 = 0;
+		int16 x1 = 0;
+		int16 y1 = 0;
+		int16 x2 = 0;
+		int16 y2 = 0;
+	};
+
+	struct CmdRenderSphere {
+		int8 colorIndex = 0;
+		int16 x = 0;
+		int16 y = 0;
+		int16 radius = 0;
+	};
+
 	#include "common/pack-start.h"
 	struct pointTab {
 		int16 x = 0;
@@ -96,17 +114,6 @@ private:
 	#include "common/pack-end.h"
 	static_assert(sizeof(elementEntry) == 38, "Unexpected elementEntry size");
 
-	struct CmdRenderLine {
-		uint8 colorIndex = 0;
-		uint8 unk1 = 0;
-		uint8 unk2 = 0;
-		uint8 unk3 = 0;
-		int16 x1 = 0;
-		int16 y1 = 0;
-		int16 x2 = 0;
-		int16 y2 = 0;
-	};
-
 	struct lineData {
 		uint8 colorIndex = 0;
 		uint8 unk1 = 0;
@@ -121,13 +128,6 @@ private:
 		int16 dataOffset = 0;
 	};
 
-	struct CmdRenderSphere {
-		int8 colorIndex = 0;
-		int16 x = 0;
-		int16 y = 0;
-		int16 radius = 0;
-	};
-
 	struct bodyHeaderStruct {
 		int16 bodyFlag = 0;
 		int16 minsx = 0;
@@ -141,14 +141,6 @@ private:
 		int32 keyFrameTime = 0;
 	};
 
-	union packed16 {
-		struct {
-			uint8 al = 0;
-			uint8 ah = 0;
-		} bit;
-		uint16 temp = 0;
-	};
-
 	int32 renderAnimatedModel(uint8 *bodyPtr, RenderCommand *renderCmds);
 	void circleFill(int32 x, int32 y, int32 radius, uint8 color);
 	int32 renderModelElements(int32 numOfPrimitives, uint8 *pointer, RenderCommand** renderCmds);


Commit: f0fb127429c2742175dab56fee048f176d6d89ba
    https://github.com/scummvm/scummvm/commit/f0fb127429c2742175dab56fee048f176d6d89ba
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-11-29T23:50:29+01:00

Commit Message:
TWINE: renamed struct

Changed paths:
    engines/twine/holomap.cpp
    engines/twine/renderer.cpp
    engines/twine/renderer.h
    engines/twine/text.cpp


diff --git a/engines/twine/holomap.cpp b/engines/twine/holomap.cpp
index 4db487d2e9..646d87d81a 100644
--- a/engines/twine/holomap.cpp
+++ b/engines/twine/holomap.cpp
@@ -74,7 +74,7 @@ void Holomap::clearHolomapPosition(int32 locationIdx) {
 }
 
 void Holomap::loadGfxSub(uint8 *modelPtr) {
-	// TODO
+	// TODO is this prepareIsoModel?
 }
 
 void Holomap::loadGfxSub1() {
diff --git a/engines/twine/renderer.cpp b/engines/twine/renderer.cpp
index 993a02d385..d6e72f3340 100644
--- a/engines/twine/renderer.cpp
+++ b/engines/twine/renderer.cpp
@@ -957,7 +957,7 @@ void Renderer::renderPolygonsDither(uint8 *out, int vtop, int32 vsize, int32 col
 void Renderer::renderPolygonsMarble(uint8 *out, int vtop, int32 vsize, int32 color) const {
 }
 
-void Renderer::renderPolygons(const Polygon &polygon, Vertex *vertices) {
+void Renderer::renderPolygons(const CmdRenderPolygon &polygon, Vertex *vertices) {
 	int vleft = 0;
 	int vright = 0;
 	int vtop = 0;
@@ -1097,10 +1097,10 @@ uint8 *Renderer::preparePolygons(Common::MemoryReadStream &stream, int32 &numOfP
 
 		int16 bestDepth = -32000;
 
-		Polygon *destinationPolygon = (Polygon *)renderBufferPtr;
+		CmdRenderPolygon *destinationPolygon = (CmdRenderPolygon *)renderBufferPtr;
 		destinationPolygon->numVertices = numVertices;
 
-		renderBufferPtr += sizeof(Polygon);
+		renderBufferPtr += sizeof(CmdRenderPolygon);
 
 		Vertex *const vertices = (Vertex *)renderBufferPtr;
 		renderBufferPtr += destinationPolygon->numVertices * sizeof(Vertex);
@@ -1228,8 +1228,8 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, RenderCom
 			break;
 		}
 		case RENDERTYPE_DRAWPOLYGON: {
-			const Polygon *header = (const Polygon *)pointer;
-			Vertex *vertices = (Vertex *)(pointer + sizeof(Polygon));
+			const CmdRenderPolygon *header = (const CmdRenderPolygon *)pointer;
+			Vertex *vertices = (Vertex *)(pointer + sizeof(CmdRenderPolygon));
 			renderPolygons(*header, vertices);
 			break;
 		}
diff --git a/engines/twine/renderer.h b/engines/twine/renderer.h
index 16a83df555..e9a622553e 100644
--- a/engines/twine/renderer.h
+++ b/engines/twine/renderer.h
@@ -50,7 +50,7 @@ struct Vertex {
 	int16 y = 0;
 };
 
-struct Polygon {
+struct CmdRenderPolygon {
 	uint8 renderType = 0;
 	uint8 numVertices = 0;
 	int16 colorIndex = 0;
@@ -244,7 +244,7 @@ public:
 	void setLightVector(int32 angleX, int32 angleY, int32 angleZ);
 
 	void prepareIsoModel(uint8 *bodyPtr); // loadGfxSub
-	void renderPolygons(const Polygon &polygon, Vertex *vertices);
+	void renderPolygons(const CmdRenderPolygon &polygon, Vertex *vertices);
 
 	int32 projectPositionOnScreen(int32 cX, int32 cY, int32 cZ);
 	void setCameraPosition(int32 x, int32 y, int32 cX, int32 cY, int32 cZ);
diff --git a/engines/twine/text.cpp b/engines/twine/text.cpp
index 755b5d230d..ad131bce48 100644
--- a/engines/twine/text.cpp
+++ b/engines/twine/text.cpp
@@ -470,7 +470,7 @@ void Text::renderContinueReadingTriangle() {
 	vertices[2].x = _engine->_renderer->vertexCoordinates[1];
 	vertices[2].y = _engine->_renderer->vertexCoordinates[5];
 
-	Polygon polygon;
+	CmdRenderPolygon polygon;
 	polygon.numVertices = 3;
 	polygon.colorIndex = _dialTextStopColor;
 	polygon.renderType = POLYGONTYPE_FLAT;


Commit: 78ec56e0c385f81478a046dc53ab5b7e29c2e6bd
    https://github.com/scummvm/scummvm/commit/78ec56e0c385f81478a046dc53ab5b7e29c2e6bd
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-11-29T23:50:29+01:00

Commit Message:
TWINE: removed dead code

Changed paths:
    engines/twine/renderer.cpp


diff --git a/engines/twine/renderer.cpp b/engines/twine/renderer.cpp
index d6e72f3340..d18c190e58 100644
--- a/engines/twine/renderer.cpp
+++ b/engines/twine/renderer.cpp
@@ -1153,13 +1153,6 @@ uint8 *Renderer::preparePolygons(Common::MemoryReadStream &stream, int32 &numOfP
 			} while (--counter > 0);
 		}
 
-#if 0
-		const int16 bx = vertices[1].x - vertices[0].x;
-		const int16 ax = (vertices[0].y - vertices[2].y) * bx;
-
-		const int16 cx = vertices[1].y - vertices[0].y;
-		const int16 dx = (vertices[0].x - vertices[2].x) * cx - ax;
-#endif
 		numOfPrimitives++;
 
 		(*renderCmds)->depth = bestDepth;


Commit: df77fff8e8b4196f689ac78efc61673641e958e1
    https://github.com/scummvm/scummvm/commit/df77fff8e8b4196f689ac78efc61673641e958e1
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-11-29T23:50:29+01:00

Commit Message:
TWINE: convert member to local var

Changed paths:
    engines/twine/renderer.cpp
    engines/twine/renderer.h


diff --git a/engines/twine/renderer.cpp b/engines/twine/renderer.cpp
index d18c190e58..2ed266b158 100644
--- a/engines/twine/renderer.cpp
+++ b/engines/twine/renderer.cpp
@@ -243,7 +243,7 @@ void Renderer::applyPointsRotation(const pointTab *pointsPtr, int32 numPoints, p
 	} while (--numOfPoints2);
 }
 
-void Renderer::processRotatedElement(int32 *targetMatrix, const uint8 *pointsPtr, int32 rotZ, int32 rotY, int32 rotX, const elementEntry *elemPtr) { // unsigned char * elemPtr) // loadPart
+void Renderer::processRotatedElement(int32 *targetMatrix, const uint8 *pointsPtr, int32 rotZ, int32 rotY, int32 rotX, const elementEntry *elemPtr, ModelData *modelData) { // unsigned char * elemPtr) // loadPart
 	int32 firstPoint = elemPtr->firstPoint;
 	int32 numOfPoints2 = elemPtr->numOfPoints;
 
@@ -270,9 +270,9 @@ void Renderer::processRotatedElement(int32 *targetMatrix, const uint8 *pointsPtr
 		int32 pointIdx = (elemPtr->basePoint) / sizeof(pointTab);
 		currentMatrix = &matricesTable[baseElement / sizeof(int32)];
 
-		destX = computedPoints[pointIdx].x;
-		destY = computedPoints[pointIdx].y;
-		destZ = computedPoints[pointIdx].z;
+		destX = modelData->computedPoints[pointIdx].x;
+		destY = modelData->computedPoints[pointIdx].y;
+		destZ = modelData->computedPoints[pointIdx].z;
 	}
 
 	applyRotation(targetMatrix, currentMatrix);
@@ -281,7 +281,7 @@ void Renderer::processRotatedElement(int32 *targetMatrix, const uint8 *pointsPtr
 		warning("RENDER WARNING: No points in this model!");
 	}
 
-	applyPointsRotation((const pointTab *)(pointsPtr + firstPoint), numOfPoints2, &computedPoints[firstPoint / sizeof(pointTab)], targetMatrix);
+	applyPointsRotation((const pointTab *)(pointsPtr + firstPoint), numOfPoints2, &modelData->computedPoints[firstPoint / sizeof(pointTab)], targetMatrix);
 }
 
 void Renderer::applyPointsTranslation(const pointTab *pointsPtr, int32 numPoints, pointTab *destPoints, const int32 *translationMatrix) {
@@ -301,7 +301,7 @@ void Renderer::applyPointsTranslation(const pointTab *pointsPtr, int32 numPoints
 	} while (--numOfPoints2);
 }
 
-void Renderer::processTranslatedElement(int32 *targetMatrix, const uint8 *pointsPtr, int32 rotX, int32 rotY, int32 rotZ, const elementEntry *elemPtr) {
+void Renderer::processTranslatedElement(int32 *targetMatrix, const uint8 *pointsPtr, int32 rotX, int32 rotY, int32 rotZ, const elementEntry *elemPtr, ModelData *modelData) {
 	renderAngleX = rotX;
 	renderAngleY = rotY;
 	renderAngleZ = rotZ;
@@ -318,9 +318,9 @@ void Renderer::processTranslatedElement(int32 *targetMatrix, const uint8 *points
 		}
 	} else { // dependent
 		const int pointsIdx = elemPtr->basePoint / 6;
-		destX = computedPoints[pointsIdx].x;
-		destY = computedPoints[pointsIdx].y;
-		destZ = computedPoints[pointsIdx].z;
+		destX = modelData->computedPoints[pointsIdx].x;
+		destY = modelData->computedPoints[pointsIdx].y;
+		destZ = modelData->computedPoints[pointsIdx].z;
 
 		const int32 *source = &matricesTable[elemPtr->baseElement / sizeof(int32)];
 		int32 *dest = targetMatrix;
@@ -330,7 +330,7 @@ void Renderer::processTranslatedElement(int32 *targetMatrix, const uint8 *points
 		}
 	}
 
-	applyPointsTranslation((const pointTab *)(pointsPtr + elemPtr->firstPoint), elemPtr->numOfPoints, &computedPoints[elemPtr->firstPoint / sizeof(pointTab)], targetMatrix);
+	applyPointsTranslation((const pointTab *)(pointsPtr + elemPtr->firstPoint), elemPtr->numOfPoints, &modelData->computedPoints[elemPtr->firstPoint / sizeof(pointTab)], targetMatrix);
 }
 
 void Renderer::translateGroup(int16 ax, int16 bx, int16 cx) {
@@ -1017,7 +1017,7 @@ void Renderer::circleFill(int32 x, int32 y, int32 radius, uint8 color) {
 	}
 }
 
-uint8 *Renderer::prepareSpheres(Common::MemoryReadStream &stream, int32 &numOfPrimitives, RenderCommand **renderCmds, uint8 *renderBufferPtr) {
+uint8 *Renderer::prepareSpheres(Common::MemoryReadStream &stream, int32 &numOfPrimitives, RenderCommand **renderCmds, uint8 *renderBufferPtr, ModelData *modelData) {
 	int16 numSpheres = stream.readSint16LE();
 	if (numSpheres <= 0) {
 		return renderBufferPtr;
@@ -1031,10 +1031,10 @@ uint8 *Renderer::prepareSpheres(Common::MemoryReadStream &stream, int32 &numOfPr
 		sphere->radius = stream.readUint16LE();
 		const int16 centerOffset = stream.readUint16LE();
 		const int16 centerIndex = centerOffset / 6;
-		sphere->x = flattenPoints[centerIndex].x;
-		sphere->y = flattenPoints[centerIndex].y;
+		sphere->x = modelData->flattenPoints[centerIndex].x;
+		sphere->y = modelData->flattenPoints[centerIndex].y;
 
-		(*renderCmds)->depth = flattenPoints[centerIndex].z;
+		(*renderCmds)->depth = modelData->flattenPoints[centerIndex].z;
 		(*renderCmds)->renderType = RENDERTYPE_DRAWSPHERE;
 		(*renderCmds)->dataPtr = renderBufferPtr;
 		(*renderCmds)++;
@@ -1045,7 +1045,7 @@ uint8 *Renderer::prepareSpheres(Common::MemoryReadStream &stream, int32 &numOfPr
 	return renderBufferPtr;
 }
 
-uint8 *Renderer::prepareLines(Common::MemoryReadStream &stream, int32 &numOfPrimitives, RenderCommand **renderCmds, uint8 *renderBufferPtr) {
+uint8 *Renderer::prepareLines(Common::MemoryReadStream &stream, int32 &numOfPrimitives, RenderCommand **renderCmds, uint8 *renderBufferPtr, ModelData *modelData) {
 	int16 numLines = stream.readSint16LE();
 	if (numLines <= 0) {
 		return renderBufferPtr;
@@ -1067,11 +1067,11 @@ uint8 *Renderer::prepareLines(Common::MemoryReadStream &stream, int32 &numOfPrim
 		const int32 point1Index = line.firstPointOffset / 6;
 		const int32 point2Index = line.secondPointOffset / 6;
 		lineCoordinatesPtr->colorIndex = line.colorIndex;
-		lineCoordinatesPtr->x1 = flattenPoints[point1Index].x;
-		lineCoordinatesPtr->y1 = flattenPoints[point1Index].y;
-		lineCoordinatesPtr->x2 = flattenPoints[point2Index].x;
-		lineCoordinatesPtr->y2 = flattenPoints[point2Index].y;
-		(*renderCmds)->depth = MAX(flattenPoints[point1Index].z, flattenPoints[point2Index].z);
+		lineCoordinatesPtr->x1 = modelData->flattenPoints[point1Index].x;
+		lineCoordinatesPtr->y1 = modelData->flattenPoints[point1Index].y;
+		lineCoordinatesPtr->x2 = modelData->flattenPoints[point2Index].x;
+		lineCoordinatesPtr->y2 = modelData->flattenPoints[point2Index].y;
+		(*renderCmds)->depth = MAX(modelData->flattenPoints[point1Index].z, modelData->flattenPoints[point2Index].z);
 		(*renderCmds)->renderType = RENDERTYPE_DRAWLINE;
 		(*renderCmds)->dataPtr = renderBufferPtr;
 		(*renderCmds)++;
@@ -1082,7 +1082,7 @@ uint8 *Renderer::prepareLines(Common::MemoryReadStream &stream, int32 &numOfPrim
 	return renderBufferPtr;
 }
 
-uint8 *Renderer::preparePolygons(Common::MemoryReadStream &stream, int32 &numOfPrimitives, RenderCommand **renderCmds, uint8 *renderBufferPtr) {
+uint8 *Renderer::preparePolygons(Common::MemoryReadStream &stream, int32 &numOfPrimitives, RenderCommand **renderCmds, uint8 *renderBufferPtr, ModelData *modelData) {
 	int16 numPolygons = stream.readSint16LE();
 	if (numPolygons <= 0) {
 		return renderBufferPtr;
@@ -1115,11 +1115,11 @@ uint8 *Renderer::preparePolygons(Common::MemoryReadStream &stream, int32 &numOfP
 
 			do {
 				const int16 shadeEntry = stream.readSint16LE();
-				const int16 shadeValue = colorIndex + shadeTable[shadeEntry];
+				const int16 shadeValue = colorIndex + modelData->shadeTable[shadeEntry];
 
 				const int16 vertexOffset = stream.readSint16LE();
 				const int16 vertexIndex = vertexOffset / 6;
-				const pointTab *point = &flattenPoints[vertexIndex];
+				const pointTab *point = &modelData->flattenPoints[vertexIndex];
 
 				vertex->colorIndex = shadeValue;
 				vertex->x = point->x;
@@ -1132,7 +1132,7 @@ uint8 *Renderer::preparePolygons(Common::MemoryReadStream &stream, int32 &numOfP
 				// only 1 shade value is used
 				destinationPolygon->renderType = renderType - POLYGONTYPE_GOURAUD;
 				const int16 shadeEntry = stream.readSint16LE();
-				const int16 shadeValue = colorIndex + shadeTable[shadeEntry];
+				const int16 shadeValue = colorIndex + modelData->shadeTable[shadeEntry];
 				destinationPolygon->colorIndex = shadeValue;
 			} else {
 				// no shade is used
@@ -1143,7 +1143,7 @@ uint8 *Renderer::preparePolygons(Common::MemoryReadStream &stream, int32 &numOfP
 			do {
 				const int16 vertexOffset = stream.readSint16LE();
 				const int16 vertexIndex = vertexOffset / 6;
-				const pointTab *point = &flattenPoints[vertexIndex];
+				const pointTab *point = &modelData->flattenPoints[vertexIndex];
 
 				vertex->colorIndex = destinationPolygon->colorIndex;
 				vertex->x = point->x;
@@ -1186,14 +1186,14 @@ const Renderer::RenderCommand *Renderer::depthSortRenderCommands(int32 numOfPrim
 	return _renderCmdsSortedByDepth;
 }
 
-int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, RenderCommand **renderCmds) {
+int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, RenderCommand **renderCmds, ModelData *modelData) {
 	// TODO: proper size
 	Common::MemoryReadStream stream(ptr, 100000);
 
 	uint8 *renderBufferPtr = renderCoordinatesBuffer;
-	renderBufferPtr = preparePolygons(stream, numOfPrimitives, renderCmds, renderBufferPtr);
-	renderBufferPtr = prepareLines(stream, numOfPrimitives, renderCmds, renderBufferPtr);
-	renderBufferPtr = prepareSpheres(stream, numOfPrimitives, renderCmds, renderBufferPtr);
+	renderBufferPtr = preparePolygons(stream, numOfPrimitives, renderCmds, renderBufferPtr, modelData);
+	renderBufferPtr = prepareLines(stream, numOfPrimitives, renderCmds, renderBufferPtr, modelData);
+	renderBufferPtr = prepareSpheres(stream, numOfPrimitives, renderCmds, renderBufferPtr, modelData);
 
 	if (numOfPrimitives == 0) {
 		_engine->_redraw->renderRect.right = -1;
@@ -1268,8 +1268,7 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, RenderCom
 	return 0;
 }
 
-int32 Renderer::renderAnimatedModel(uint8 *bodyPtr, RenderCommand *renderCmds) {
-	//	int32 *tmpLightMatrix;
+int32 Renderer::renderAnimatedModel(ModelData *modelData, uint8 *bodyPtr, RenderCommand *renderCmds) {
 	int32 numOfPoints = *((const uint16 *)bodyPtr);
 	bodyPtr += 2;
 	const uint8 *pointsPtr = bodyPtr;
@@ -1284,7 +1283,7 @@ int32 Renderer::renderAnimatedModel(uint8 *bodyPtr, RenderCommand *renderCmds) {
 
 	int32 *modelMatrix = matricesTable;
 
-	processRotatedElement(modelMatrix, pointsPtr, renderAngleX, renderAngleY, renderAngleZ, (const elementEntry *)elementsPtr);
+	processRotatedElement(modelMatrix, pointsPtr, renderAngleX, renderAngleY, renderAngleZ, (const elementEntry *)elementsPtr, modelData);
 
 	elementsPtr += sizeof(elementEntry);
 
@@ -1300,9 +1299,9 @@ int32 Renderer::renderAnimatedModel(uint8 *bodyPtr, RenderCommand *renderCmds) {
 			int16 boneType = elemEntryPtr->flag;
 
 			if (boneType == 0) {
-				processRotatedElement(modelMatrix, pointsPtr, elemEntryPtr->rotateX, elemEntryPtr->rotateY, elemEntryPtr->rotateZ, elemEntryPtr); // rotation
+				processRotatedElement(modelMatrix, pointsPtr, elemEntryPtr->rotateX, elemEntryPtr->rotateY, elemEntryPtr->rotateZ, elemEntryPtr, modelData); // rotation
 			} else if (boneType == 1) {
-				processTranslatedElement(modelMatrix, pointsPtr, elemEntryPtr->rotateX, elemEntryPtr->rotateY, elemEntryPtr->rotateZ, elemEntryPtr); // translation
+				processTranslatedElement(modelMatrix, pointsPtr, elemEntryPtr->rotateX, elemEntryPtr->rotateY, elemEntryPtr->rotateZ, elemEntryPtr, modelData); // translation
 			}
 
 			modelMatrix += 9;
@@ -1313,8 +1312,9 @@ int32 Renderer::renderAnimatedModel(uint8 *bodyPtr, RenderCommand *renderCmds) {
 
 	numOfPrimitives = numOfPoints;
 
-	const pointTab *pointPtr = (pointTab *)computedPoints;
-	pointTab *pointPtrDest = (pointTab *)flattenPoints;
+	// TODO: stack var will maybe exceed max stack size on some platforms - 27300 bytes
+	const pointTab *pointPtr = (pointTab *)modelData->computedPoints;
+	pointTab *pointPtrDest = (pointTab *)modelData->flattenPoints;
 
 	if (isUsingOrhoProjection) { // use standard projection
 		do {
@@ -1412,7 +1412,7 @@ int32 Renderer::renderAnimatedModel(uint8 *bodyPtr, RenderCommand *renderCmds) {
 	shadePtr = (int32 *)(((uint8 *)shadePtr) + 2);
 
 	if (numOfShades) { // process normal data
-		uint8 *currentShadeDestination = (uint8 *)shadeTable;
+		uint8 *currentShadeDestination = (uint8 *)modelData->shadeTable;
 		int32 *lightMatrix = matricesTable;
 		const uint8 *pri2Ptr3;
 
@@ -1470,7 +1470,7 @@ int32 Renderer::renderAnimatedModel(uint8 *bodyPtr, RenderCommand *renderCmds) {
 		} while (--numOfPrimitives);
 	}
 
-	return renderModelElements(numOfPrimitives, (uint8 *)shadePtr, &renderCmds);
+	return renderModelElements(numOfPrimitives, (uint8 *)shadePtr, &renderCmds, modelData);
 }
 
 void Renderer::prepareIsoModel(uint8 *bodyPtr) { // loadGfxSub
@@ -1539,7 +1539,7 @@ int32 Renderer::renderIsoModel(int32 x, int32 y, int32 z, int32 angleX, int32 an
 	if (bodyHeader & 2) { // if animated
 		// the mostly used renderer code
 		// restart at the beginning of the renderTable
-		return renderAnimatedModel(ptr, _renderCmds);
+		return renderAnimatedModel(&_modelData, ptr, _renderCmds);
 	}
 	error("Unsupported unanimated model render!");
 	return 0;
diff --git a/engines/twine/renderer.h b/engines/twine/renderer.h
index e9a622553e..372c798b43 100644
--- a/engines/twine/renderer.h
+++ b/engines/twine/renderer.h
@@ -141,16 +141,24 @@ private:
 		int32 keyFrameTime = 0;
 	};
 
-	int32 renderAnimatedModel(uint8 *bodyPtr, RenderCommand *renderCmds);
+	struct ModelData {
+		pointTab computedPoints[800];
+		pointTab flattenPoints[800];
+		int16 shadeTable[500] {0};
+	};
+
+	ModelData _modelData;
+
+	int32 renderAnimatedModel(ModelData *modelData, uint8 *bodyPtr, RenderCommand *renderCmds);
 	void circleFill(int32 x, int32 y, int32 radius, uint8 color);
-	int32 renderModelElements(int32 numOfPrimitives, uint8 *pointer, RenderCommand** renderCmds);
+	int32 renderModelElements(int32 numOfPrimitives, uint8 *pointer, RenderCommand** renderCmds, ModelData *modelData);
 	void getBaseRotationPosition(int32 x, int32 y, int32 z);
 	void getCameraAnglePositions(int32 x, int32 y, int32 z);
 	void applyRotation(int32 *targetMatrix, const int32 *currentMatrix);
 	void applyPointsRotation(const pointTab *pointsPtr, int32 numPoints, pointTab *destPoints, const int32 *rotationMatrix);
-	void processRotatedElement(int32 *targetMatrix, const uint8 *pointsPtr, int32 rotZ, int32 rotY, int32 rotX, const elementEntry *elemPtr);
+	void processRotatedElement(int32 *targetMatrix, const uint8 *pointsPtr, int32 rotZ, int32 rotY, int32 rotX, const elementEntry *elemPtr, ModelData *modelData);
 	void applyPointsTranslation(const pointTab *pointsPtr, int32 numPoints, pointTab *destPoints, const int32 *translationMatrix);
-	void processTranslatedElement(int32 *targetMatrix, const uint8 *pointsPtr, int32 rotX, int32 rotY, int32 rotZ, const elementEntry *elemPtr);
+	void processTranslatedElement(int32 *targetMatrix, const uint8 *pointsPtr, int32 rotX, int32 rotY, int32 rotZ, const elementEntry *elemPtr, ModelData *modelData);
 	void translateGroup(int16 ax, int16 bx, int16 cx);
 
 	// ---- variables ----
@@ -188,10 +196,6 @@ private:
 	int32 lightY = 0;
 	int32 lightZ = 0;
 
-	pointTab computedPoints[800]; // _projectedPointTable
-	pointTab flattenPoints[800];  // _flattenPointTable
-	int16 shadeTable[500] {0};
-
 	RenderCommand _renderCmds[1000];
 	RenderCommand _renderCmdsSortedByDepth[1000];
 	uint8 renderCoordinatesBuffer[10000] {0};
@@ -215,9 +219,9 @@ private:
 	void computePolygons(int16 polyRenderType, Vertex *vertices, int32 numVertices, int &vleft, int &vright, int &vtop, int &vbottom);
 
 	const RenderCommand *depthSortRenderCommands(int32 numOfPrimitives);
-	uint8* preparePolygons(Common::MemoryReadStream &stream, int32 &numOfPrimitives, RenderCommand **renderCmds, uint8 *renderBufferPtr);
-	uint8* prepareSpheres(Common::MemoryReadStream &stream, int32 &numOfPrimitives, RenderCommand **renderCmds, uint8 *renderBufferPtr);
-	uint8* prepareLines(Common::MemoryReadStream &stream, int32 &numOfPrimitives, RenderCommand **renderCmds, uint8 *renderBufferPtr);
+	uint8* preparePolygons(Common::MemoryReadStream &stream, int32 &numOfPrimitives, RenderCommand **renderCmds, uint8 *renderBufferPtr, ModelData *modelData);
+	uint8* prepareSpheres(Common::MemoryReadStream &stream, int32 &numOfPrimitives, RenderCommand **renderCmds, uint8 *renderBufferPtr, ModelData *modelData);
+	uint8* prepareLines(Common::MemoryReadStream &stream, int32 &numOfPrimitives, RenderCommand **renderCmds, uint8 *renderBufferPtr, ModelData *modelData);
 
 public:
 	Renderer(TwinEEngine *engine) : _engine(engine) {}


Commit: c7a09011e750f1c787010929e6cc3b790a22ec3a
    https://github.com/scummvm/scummvm/commit/c7a09011e750f1c787010929e6cc3b790a22ec3a
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-11-29T23:50:29+01:00

Commit Message:
TWINE: replaced magic numbers

Changed paths:
    engines/twine/renderer.cpp


diff --git a/engines/twine/renderer.cpp b/engines/twine/renderer.cpp
index 2ed266b158..27d6803a87 100644
--- a/engines/twine/renderer.cpp
+++ b/engines/twine/renderer.cpp
@@ -103,9 +103,9 @@ void Renderer::getBaseRotationPosition(int32 x, int32 y, int32 z) {
 void Renderer::setBaseRotation(int32 x, int32 y, int32 z) {
 	shadeAngleTab3 = &shadeAngleTable[384];
 
-	double Xradians = (double)((256 - x) % 1024) * 2 * M_PI / 1024;
-	double Yradians = (double)((256 - y) % 1024) * 2 * M_PI / 1024;
-	double Zradians = (double)((256 - z) % 1024) * 2 * M_PI / 1024;
+	double Xradians = (double)((ANGLE_90 - x) % ANGLE_360) * 2 * M_PI / ANGLE_360;
+	double Yradians = (double)((ANGLE_90 - y) % ANGLE_360) * 2 * M_PI / ANGLE_360;
+	double Zradians = (double)((ANGLE_90 - z) % ANGLE_360) * 2 * M_PI / ANGLE_360;
 
 	baseMatrix[0] = (int32)(sin(Zradians) * sin(Yradians) * 16384);
 	baseMatrix[1] = (int32)(-cos(Zradians) * 16384);
@@ -161,7 +161,7 @@ void Renderer::applyRotation(int32 *targetMatrix, const int32 *currentMatrix) {
 	if (renderAngleX) {
 		int32 angle = renderAngleX;
 		int32 angleVar2 = shadeAngleTable[ClampAngle(angle)];
-		angle += 256;
+		angle += ANGLE_90;
 		int32 angleVar1 = shadeAngleTable[ClampAngle(angle)];
 
 		matrix1[0] = currentMatrix[0];
@@ -183,7 +183,7 @@ void Renderer::applyRotation(int32 *targetMatrix, const int32 *currentMatrix) {
 	if (renderAngleZ) {
 		int32 angle = renderAngleZ;
 		int32 angleVar2 = shadeAngleTable[ClampAngle(angle)];
-		angle += 256;
+		angle += ANGLE_90;
 		int32 angleVar1 = shadeAngleTable[ClampAngle(angle)];
 
 		matrix2[2] = matrix1[2];
@@ -205,7 +205,7 @@ void Renderer::applyRotation(int32 *targetMatrix, const int32 *currentMatrix) {
 	if (renderAngleY) {
 		int32 angle = renderAngleY;
 		int32 angleVar2 = shadeAngleTable[ClampAngle(angle)];
-		angle += 256;
+		angle += ANGLE_90;
 		int32 angleVar1 = shadeAngleTable[ClampAngle(angle)];
 
 		targetMatrix[1] = matrix2[1];


Commit: 880d8261a78429abecbe0b53645747a365bcc444
    https://github.com/scummvm/scummvm/commit/880d8261a78429abecbe0b53645747a365bcc444
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-11-29T23:50:29+01:00

Commit Message:
TWINE: refactored matrices

Changed paths:
    engines/twine/renderer.cpp
    engines/twine/renderer.h


diff --git a/engines/twine/renderer.cpp b/engines/twine/renderer.cpp
index 27d6803a87..df8542a9bc 100644
--- a/engines/twine/renderer.cpp
+++ b/engines/twine/renderer.cpp
@@ -95,9 +95,9 @@ void Renderer::setOrthoProjection(int32 x, int32 y, int32 z) {
 }
 
 void Renderer::getBaseRotationPosition(int32 x, int32 y, int32 z) {
-	destX = (baseMatrix[0] * x + baseMatrix[1] * y + baseMatrix[2] * z) >> 14;
-	destY = (baseMatrix[3] * x + baseMatrix[4] * y + baseMatrix[5] * z) >> 14;
-	destZ = (baseMatrix[6] * x + baseMatrix[7] * y + baseMatrix[8] * z) >> 14;
+	destX = (baseMatrix.row1[0] * x + baseMatrix.row1[1] * y + baseMatrix.row1[2] * z) >> 14;
+	destY = (baseMatrix.row2[0] * x + baseMatrix.row2[1] * y + baseMatrix.row2[2] * z) >> 14;
+	destZ = (baseMatrix.row3[0] * x + baseMatrix.row3[1] * y + baseMatrix.row3[2] * z) >> 14;
 }
 
 void Renderer::setBaseRotation(int32 x, int32 y, int32 z) {
@@ -107,23 +107,23 @@ void Renderer::setBaseRotation(int32 x, int32 y, int32 z) {
 	double Yradians = (double)((ANGLE_90 - y) % ANGLE_360) * 2 * M_PI / ANGLE_360;
 	double Zradians = (double)((ANGLE_90 - z) % ANGLE_360) * 2 * M_PI / ANGLE_360;
 
-	baseMatrix[0] = (int32)(sin(Zradians) * sin(Yradians) * 16384);
-	baseMatrix[1] = (int32)(-cos(Zradians) * 16384);
-	baseMatrix[2] = (int32)(sin(Zradians) * cos(Yradians) * 16384);
-	baseMatrix[3] = (int32)(cos(Zradians) * sin(Xradians) * 16384);
-	baseMatrix[4] = (int32)(sin(Zradians) * sin(Xradians) * 16384);
-	baseMatrix[6] = (int32)(cos(Zradians) * cos(Xradians) * 16384);
-	baseMatrix[7] = (int32)(sin(Zradians) * cos(Xradians) * 16384);
+	baseMatrix.row1[0] = (int32)(sin(Zradians) * sin(Yradians) * 16384);
+	baseMatrix.row1[1] = (int32)(-cos(Zradians) * 16384);
+	baseMatrix.row1[2] = (int32)(sin(Zradians) * cos(Yradians) * 16384);
+	baseMatrix.row2[0] = (int32)(cos(Zradians) * sin(Xradians) * 16384);
+	baseMatrix.row2[1] = (int32)(sin(Zradians) * sin(Xradians) * 16384);
+	baseMatrix.row3[0] = (int32)(cos(Zradians) * cos(Xradians) * 16384);
+	baseMatrix.row3[1] = (int32)(sin(Zradians) * cos(Xradians) * 16384);
 
-	int32 matrixElem = baseMatrix[3];
+	int32 matrixElem = baseMatrix.row2[0];
 
-	baseMatrix[3] = (int32)(sin(Yradians) * matrixElem + 16384 * cos(Yradians) * cos(Xradians));
-	baseMatrix[5] = (int32)(cos(Yradians) * matrixElem - 16384 * sin(Yradians) * cos(Xradians));
+	baseMatrix.row2[0] = (int32)(sin(Yradians) * matrixElem + 16384 * cos(Yradians) * cos(Xradians));
+	baseMatrix.row2[2] = (int32)(cos(Yradians) * matrixElem - 16384 * sin(Yradians) * cos(Xradians));
 
-	matrixElem = baseMatrix[6];
+	matrixElem = baseMatrix.row3[0];
 
-	baseMatrix[6] = (int32)(sin(Yradians) * matrixElem - 16384 * sin(Xradians) * cos(Yradians));
-	baseMatrix[8] = (int32)(cos(Yradians) * matrixElem + 16384 * sin(Xradians) * sin(Yradians));
+	baseMatrix.row3[0] = (int32)(sin(Yradians) * matrixElem - 16384 * sin(Xradians) * cos(Yradians));
+	baseMatrix.row3[2] = (int32)(cos(Yradians) * matrixElem + 16384 * sin(Xradians) * sin(Yradians));
 
 	getBaseRotationPosition(baseTransPosX, baseTransPosY, baseTransPosZ);
 
@@ -133,9 +133,9 @@ void Renderer::setBaseRotation(int32 x, int32 y, int32 z) {
 }
 
 void Renderer::getCameraAnglePositions(int32 x, int32 y, int32 z) {
-	destX = (baseMatrix[0] * x + baseMatrix[3] * y + baseMatrix[6] * z) >> 14;
-	destY = (baseMatrix[1] * x + baseMatrix[4] * y + baseMatrix[7] * z) >> 14;
-	destZ = (baseMatrix[2] * x + baseMatrix[5] * y + baseMatrix[8] * z) >> 14;
+	destX = (baseMatrix.row1[0] * x + baseMatrix.row2[0] * y + baseMatrix.row3[0] * z) >> 14;
+	destY = (baseMatrix.row1[1] * x + baseMatrix.row2[1] * y + baseMatrix.row3[1] * z) >> 14;
+	destZ = (baseMatrix.row1[2] * x + baseMatrix.row2[2] * y + baseMatrix.row3[2] * z) >> 14;
 }
 
 void Renderer::setCameraAngle(int32 transPosX, int32 transPosY, int32 transPosZ, int32 rotPosX, int32 rotPosY, int32 rotPosZ, int32 param6) {
@@ -154,9 +154,9 @@ void Renderer::setCameraAngle(int32 transPosX, int32 transPosY, int32 transPosZ,
 	baseTransPosZ = destZ;
 }
 
-void Renderer::applyRotation(int32 *targetMatrix, const int32 *currentMatrix) {
-	int32 matrix1[9];
-	int32 matrix2[9];
+void Renderer::applyRotation(Matrix *targetMatrix, const Matrix *currentMatrix) {
+	Matrix matrix1;
+	Matrix matrix2;
 
 	if (renderAngleX) {
 		int32 angle = renderAngleX;
@@ -164,20 +164,18 @@ void Renderer::applyRotation(int32 *targetMatrix, const int32 *currentMatrix) {
 		angle += ANGLE_90;
 		int32 angleVar1 = shadeAngleTable[ClampAngle(angle)];
 
-		matrix1[0] = currentMatrix[0];
-		matrix1[3] = currentMatrix[3];
-		matrix1[6] = currentMatrix[6];
+		matrix1.row1[0] = currentMatrix->row1[0];
+		matrix1.row2[0] = currentMatrix->row2[0];
+		matrix1.row3[0] = currentMatrix->row3[0];
 
-		matrix1[1] = (currentMatrix[2] * angleVar2 + currentMatrix[1] * angleVar1) >> 14;
-		matrix1[2] = (currentMatrix[2] * angleVar1 - currentMatrix[1] * angleVar2) >> 14;
-		matrix1[4] = (currentMatrix[5] * angleVar2 + currentMatrix[4] * angleVar1) >> 14;
-		matrix1[5] = (currentMatrix[5] * angleVar1 - currentMatrix[4] * angleVar2) >> 14;
-		matrix1[7] = (currentMatrix[8] * angleVar2 + currentMatrix[7] * angleVar1) >> 14;
-		matrix1[8] = (currentMatrix[8] * angleVar1 - currentMatrix[7] * angleVar2) >> 14;
+		matrix1.row1[1] = (currentMatrix->row1[2] * angleVar2 + currentMatrix->row1[1] * angleVar1) >> 14;
+		matrix1.row1[2] = (currentMatrix->row1[2] * angleVar1 - currentMatrix->row1[1] * angleVar2) >> 14;
+		matrix1.row2[1] = (currentMatrix->row2[2] * angleVar2 + currentMatrix->row2[1] * angleVar1) >> 14;
+		matrix1.row2[2] = (currentMatrix->row2[2] * angleVar1 - currentMatrix->row2[1] * angleVar2) >> 14;
+		matrix1.row3[1] = (currentMatrix->row3[2] * angleVar2 + currentMatrix->row3[1] * angleVar1) >> 14;
+		matrix1.row3[2] = (currentMatrix->row3[2] * angleVar1 - currentMatrix->row3[1] * angleVar2) >> 14;
 	} else {
-		for (int32 i = 0; i < 9; i++) {
-			matrix1[i] = currentMatrix[i];
-		}
+		matrix1 = *currentMatrix;
 	}
 
 	if (renderAngleZ) {
@@ -186,20 +184,18 @@ void Renderer::applyRotation(int32 *targetMatrix, const int32 *currentMatrix) {
 		angle += ANGLE_90;
 		int32 angleVar1 = shadeAngleTable[ClampAngle(angle)];
 
-		matrix2[2] = matrix1[2];
-		matrix2[5] = matrix1[5];
-		matrix2[8] = matrix1[8];
+		matrix2.row1[2] = matrix1.row1[2];
+		matrix2.row2[2] = matrix1.row2[2];
+		matrix2.row3[2] = matrix1.row3[2];
 
-		matrix2[0] = (matrix1[1] * angleVar2 + matrix1[0] * angleVar1) >> 14;
-		matrix2[1] = (matrix1[1] * angleVar1 - matrix1[0] * angleVar2) >> 14;
-		matrix2[3] = (matrix1[4] * angleVar2 + matrix1[3] * angleVar1) >> 14;
-		matrix2[4] = (matrix1[4] * angleVar1 - matrix1[3] * angleVar2) >> 14;
-		matrix2[6] = (matrix1[7] * angleVar2 + matrix1[6] * angleVar1) >> 14;
-		matrix2[7] = (matrix1[7] * angleVar1 - matrix1[6] * angleVar2) >> 14;
+		matrix2.row1[0] = (matrix1.row1[1] * angleVar2 + matrix1.row1[0] * angleVar1) >> 14;
+		matrix2.row1[1] = (matrix1.row1[1] * angleVar1 - matrix1.row1[0] * angleVar2) >> 14;
+		matrix2.row2[0] = (matrix1.row2[1] * angleVar2 + matrix1.row2[0] * angleVar1) >> 14;
+		matrix2.row2[1] = (matrix1.row2[1] * angleVar1 - matrix1.row2[0] * angleVar2) >> 14;
+		matrix2.row3[0] = (matrix1.row3[1] * angleVar2 + matrix1.row3[0] * angleVar1) >> 14;
+		matrix2.row3[1] = (matrix1.row3[1] * angleVar1 - matrix1.row3[0] * angleVar2) >> 14;
 	} else {
-		for (int32 i = 0; i < 9; i++) {
-			matrix2[i] = matrix1[i];
-		}
+		matrix2 = matrix1;
 	}
 
 	if (renderAngleY) {
@@ -208,25 +204,23 @@ void Renderer::applyRotation(int32 *targetMatrix, const int32 *currentMatrix) {
 		angle += ANGLE_90;
 		int32 angleVar1 = shadeAngleTable[ClampAngle(angle)];
 
-		targetMatrix[1] = matrix2[1];
-		targetMatrix[4] = matrix2[4];
-		targetMatrix[7] = matrix2[7];
+		targetMatrix->row1[1] = matrix2.row1[1];
+		targetMatrix->row2[1] = matrix2.row2[1];
+		targetMatrix->row3[1] = matrix2.row3[1];
 
-		targetMatrix[0] = (matrix2[0] * angleVar1 - matrix2[2] * angleVar2) >> 14;
-		targetMatrix[2] = (matrix2[0] * angleVar2 + matrix2[2] * angleVar1) >> 14;
-		targetMatrix[3] = (matrix2[3] * angleVar1 - matrix2[5] * angleVar2) >> 14;
-		targetMatrix[5] = (matrix2[3] * angleVar2 + matrix2[5] * angleVar1) >> 14;
+		targetMatrix->row1[0] = (matrix2.row1[0] * angleVar1 - matrix2.row1[2] * angleVar2) >> 14;
+		targetMatrix->row1[2] = (matrix2.row1[0] * angleVar2 + matrix2.row1[2] * angleVar1) >> 14;
+		targetMatrix->row2[0] = (matrix2.row2[0] * angleVar1 - matrix2.row2[2] * angleVar2) >> 14;
+		targetMatrix->row2[2] = (matrix2.row2[0] * angleVar2 + matrix2.row2[2] * angleVar1) >> 14;
 
-		targetMatrix[6] = (matrix2[6] * angleVar1 - matrix2[8] * angleVar2) >> 14;
-		targetMatrix[8] = (matrix2[6] * angleVar2 + matrix2[8] * angleVar1) >> 14;
+		targetMatrix->row3[0] = (matrix2.row3[0] * angleVar1 - matrix2.row3[2] * angleVar2) >> 14;
+		targetMatrix->row3[2] = (matrix2.row3[0] * angleVar2 + matrix2.row3[2] * angleVar1) >> 14;
 	} else {
-		for (int32 i = 0; i < 9; i++) {
-			targetMatrix[i] = matrix2[i];
-		}
+		*targetMatrix = matrix2;
 	}
 }
 
-void Renderer::applyPointsRotation(const pointTab *pointsPtr, int32 numPoints, pointTab *destPoints, const int32 *rotationMatrix) {
+void Renderer::applyPointsRotation(const pointTab *pointsPtr, int32 numPoints, pointTab *destPoints, const Matrix *rotationMatrix) {
 	int32 numOfPoints2 = numPoints;
 
 	do {
@@ -234,16 +228,16 @@ void Renderer::applyPointsRotation(const pointTab *pointsPtr, int32 numPoints, p
 		const int16 tmpY = pointsPtr->y;
 		const int16 tmpZ = pointsPtr->z;
 
-		destPoints->x = ((rotationMatrix[0] * tmpX + rotationMatrix[1] * tmpY + rotationMatrix[2] * tmpZ) >> 14) + destX;
-		destPoints->y = ((rotationMatrix[3] * tmpX + rotationMatrix[4] * tmpY + rotationMatrix[5] * tmpZ) >> 14) + destY;
-		destPoints->z = ((rotationMatrix[6] * tmpX + rotationMatrix[7] * tmpY + rotationMatrix[8] * tmpZ) >> 14) + destZ;
+		destPoints->x = ((rotationMatrix->row1[0] * tmpX + rotationMatrix->row1[1] * tmpY + rotationMatrix->row1[2] * tmpZ) >> 14) + destX;
+		destPoints->y = ((rotationMatrix->row2[0] * tmpX + rotationMatrix->row2[1] * tmpY + rotationMatrix->row2[2] * tmpZ) >> 14) + destY;
+		destPoints->z = ((rotationMatrix->row3[0] * tmpX + rotationMatrix->row3[1] * tmpY + rotationMatrix->row3[2] * tmpZ) >> 14) + destZ;
 
 		destPoints++;
 		pointsPtr++;
 	} while (--numOfPoints2);
 }
 
-void Renderer::processRotatedElement(int32 *targetMatrix, const uint8 *pointsPtr, int32 rotZ, int32 rotY, int32 rotX, const elementEntry *elemPtr, ModelData *modelData) { // unsigned char * elemPtr) // loadPart
+void Renderer::processRotatedElement(Matrix *targetMatrix, const uint8 *pointsPtr, int32 rotZ, int32 rotY, int32 rotX, const elementEntry *elemPtr, ModelData *modelData) { // unsigned char * elemPtr) // loadPart
 	int32 firstPoint = elemPtr->firstPoint;
 	int32 numOfPoints2 = elemPtr->numOfPoints;
 
@@ -255,20 +249,20 @@ void Renderer::processRotatedElement(int32 *targetMatrix, const uint8 *pointsPtr
 		error("RENDER ERROR: invalid firstPoint in process_rotated_element func");
 	}
 
-	//baseElement = *((unsigned short int*)elemPtr+6);
-	const int16 baseElement = elemPtr->baseElement;
-
-	const int32 *currentMatrix;
+	const Matrix *currentMatrix;
 	// if its the first point
-	if (baseElement == -1) {
-		currentMatrix = baseMatrix;
+	if (elemPtr->baseElement == -1) {
+		currentMatrix = &baseMatrix;
 
 		destX = 0;
 		destY = 0;
 		destZ = 0;
 	} else {
-		int32 pointIdx = (elemPtr->basePoint) / sizeof(pointTab);
-		currentMatrix = &matricesTable[baseElement / sizeof(int32)];
+		const int32 pointIdx = elemPtr->basePoint / sizeof(pointTab);
+		assert(elemPtr->baseElement % 36 == 0);
+		const int32 matrixIndex = elemPtr->baseElement / 36;
+		assert(matrixIndex >= 0 && matrixIndex < ARRAYSIZE(matricesTable));
+		currentMatrix = &matricesTable[matrixIndex];
 
 		destX = modelData->computedPoints[pointIdx].x;
 		destY = modelData->computedPoints[pointIdx].y;
@@ -284,7 +278,7 @@ void Renderer::processRotatedElement(int32 *targetMatrix, const uint8 *pointsPtr
 	applyPointsRotation((const pointTab *)(pointsPtr + firstPoint), numOfPoints2, &modelData->computedPoints[firstPoint / sizeof(pointTab)], targetMatrix);
 }
 
-void Renderer::applyPointsTranslation(const pointTab *pointsPtr, int32 numPoints, pointTab *destPoints, const int32 *translationMatrix) {
+void Renderer::applyPointsTranslation(const pointTab *pointsPtr, int32 numPoints, pointTab *destPoints, const Matrix *translationMatrix) {
 	int32 numOfPoints2 = numPoints;
 
 	do {
@@ -292,16 +286,16 @@ void Renderer::applyPointsTranslation(const pointTab *pointsPtr, int32 numPoints
 		const int16 tmpY = pointsPtr->y + renderAngleY;
 		const int16 tmpZ = pointsPtr->z + renderAngleX;
 
-		destPoints->x = ((translationMatrix[0] * tmpX + translationMatrix[1] * tmpY + translationMatrix[2] * tmpZ) >> 14) + destX;
-		destPoints->y = ((translationMatrix[3] * tmpX + translationMatrix[4] * tmpY + translationMatrix[5] * tmpZ) >> 14) + destY;
-		destPoints->z = ((translationMatrix[6] * tmpX + translationMatrix[7] * tmpY + translationMatrix[8] * tmpZ) >> 14) + destZ;
+		destPoints->x = ((translationMatrix->row1[0] * tmpX + translationMatrix->row1[1] * tmpY + translationMatrix->row1[2] * tmpZ) >> 14) + destX;
+		destPoints->y = ((translationMatrix->row2[0] * tmpX + translationMatrix->row2[1] * tmpY + translationMatrix->row2[2] * tmpZ) >> 14) + destY;
+		destPoints->z = ((translationMatrix->row3[0] * tmpX + translationMatrix->row3[1] * tmpY + translationMatrix->row3[2] * tmpZ) >> 14) + destZ;
 
 		destPoints++;
 		pointsPtr++;
 	} while (--numOfPoints2);
 }
 
-void Renderer::processTranslatedElement(int32 *targetMatrix, const uint8 *pointsPtr, int32 rotX, int32 rotY, int32 rotZ, const elementEntry *elemPtr, ModelData *modelData) {
+void Renderer::processTranslatedElement(Matrix *targetMatrix, const uint8 *pointsPtr, int32 rotX, int32 rotY, int32 rotZ, const elementEntry *elemPtr, ModelData *modelData) {
 	renderAngleX = rotX;
 	renderAngleY = rotY;
 	renderAngleZ = rotZ;
@@ -311,23 +305,17 @@ void Renderer::processTranslatedElement(int32 *targetMatrix, const uint8 *points
 		destY = 0;
 		destZ = 0;
 
-		int32 *dest = targetMatrix;
-
-		for (int32 i = 0; i < 9; i++) {
-			dest[i] = baseMatrix[i];
-		}
+		*targetMatrix = baseMatrix;
 	} else { // dependent
 		const int pointsIdx = elemPtr->basePoint / 6;
 		destX = modelData->computedPoints[pointsIdx].x;
 		destY = modelData->computedPoints[pointsIdx].y;
 		destZ = modelData->computedPoints[pointsIdx].z;
 
-		const int32 *source = &matricesTable[elemPtr->baseElement / sizeof(int32)];
-		int32 *dest = targetMatrix;
-
-		for (int32 i = 0; i < 9; i++) {
-			dest[i] = source[i];
-		}
+		assert(elemPtr->baseElement % 36 == 0);
+		const int32 matrixIndex = elemPtr->baseElement / 36;
+		assert(matrixIndex >= 0 && matrixIndex < ARRAYSIZE(matricesTable));
+		*targetMatrix = matricesTable[matrixIndex];
 	}
 
 	applyPointsTranslation((const pointTab *)(pointsPtr + elemPtr->firstPoint), elemPtr->numOfPoints, &modelData->computedPoints[elemPtr->firstPoint / sizeof(pointTab)], targetMatrix);
@@ -338,32 +326,32 @@ void Renderer::translateGroup(int16 ax, int16 bx, int16 cx) {
 	int32 ebx = bx;
 	int32 ecx = cx;
 
-	int32 edi = shadeMatrix[0];
-	int32 eax = shadeMatrix[1];
+	int32 edi = shadeMatrix.row1[0];
+	int32 eax = shadeMatrix.row1[1];
 	edi *= ebp;
 	eax *= ebx;
 	edi += eax;
-	eax = shadeMatrix[2];
+	eax = shadeMatrix.row1[2];
 	eax *= ecx;
 	eax += edi;
 	eax >>= 14;
 
 	destX = eax;
 
-	edi = shadeMatrix[3];
-	eax = shadeMatrix[4];
+	edi = shadeMatrix.row2[0];
+	eax = shadeMatrix.row2[1];
 	edi *= ebp;
 	eax *= ebx;
 	edi += eax;
-	eax = shadeMatrix[5];
+	eax = shadeMatrix.row2[2];
 	eax *= ecx;
 	eax += edi;
 	eax >>= 14;
 	destY = eax;
 
-	ebp *= shadeMatrix[6];
-	ebx *= shadeMatrix[7];
-	ecx *= shadeMatrix[8];
+	ebp *= shadeMatrix.row3[0];
+	ebx *= shadeMatrix.row3[1];
+	ecx *= shadeMatrix.row3[2];
 	ebx += ebp;
 	ebx += ecx;
 	ebx >>= 14;
@@ -380,7 +368,7 @@ void Renderer::setLightVector(int32 angleX, int32 angleY, int32 angleZ) {
 	renderAngleY = angleY;
 	renderAngleZ = angleZ;
 
-	applyRotation(shadeMatrix, baseMatrix);
+	applyRotation(&shadeMatrix, &baseMatrix);
 	translateGroup(0, 0, 59);
 
 	lightX = destX;
@@ -1281,7 +1269,7 @@ int32 Renderer::renderAnimatedModel(ModelData *modelData, uint8 *bodyPtr, Render
 	uint8 *elementsPtr = bodyPtr;
 	const uint8 *elementsPtr2 = elementsPtr;
 
-	int32 *modelMatrix = matricesTable;
+	Matrix *modelMatrix = &matricesTable[0];
 
 	processRotatedElement(modelMatrix, pointsPtr, renderAngleX, renderAngleY, renderAngleZ, (const elementEntry *)elementsPtr, modelData);
 
@@ -1293,7 +1281,7 @@ int32 Renderer::renderAnimatedModel(ModelData *modelData, uint8 *bodyPtr, Render
 
 	if (numOfElements - 1 != 0) {
 		numOfPrimitives = numOfElements - 1;
-		modelMatrix = &matricesTable[9];
+		modelMatrix = &matricesTable[1];
 
 		do {
 			int16 boneType = elemEntryPtr->flag;
@@ -1304,7 +1292,7 @@ int32 Renderer::renderAnimatedModel(ModelData *modelData, uint8 *bodyPtr, Render
 				processTranslatedElement(modelMatrix, pointsPtr, elemEntryPtr->rotateX, elemEntryPtr->rotateY, elemEntryPtr->rotateZ, elemEntryPtr, modelData); // translation
 			}
 
-			modelMatrix += 9;
+			++modelMatrix;
 			elementsPtr += sizeof(elementEntry);
 			elemEntryPtr = (elementEntry *)elementsPtr;
 		} while (--numOfPrimitives);
@@ -1413,7 +1401,7 @@ int32 Renderer::renderAnimatedModel(ModelData *modelData, uint8 *bodyPtr, Render
 
 	if (numOfShades) { // process normal data
 		uint8 *currentShadeDestination = (uint8 *)modelData->shadeTable;
-		int32 *lightMatrix = matricesTable;
+		Matrix *lightMatrix = &matricesTable[0];
 		const uint8 *pri2Ptr3;
 
 		numOfPrimitives = numOfElements;
@@ -1426,17 +1414,17 @@ int32 Renderer::renderAnimatedModel(ModelData *modelData, uint8 *bodyPtr, Render
 			if (numOfShades) {
 				int32 numShades = numOfShades;
 
-				shadeMatrix[0] = (*lightMatrix) * lightX;
-				shadeMatrix[1] = (*(lightMatrix + 1)) * lightX;
-				shadeMatrix[2] = (*(lightMatrix + 2)) * lightX;
+				shadeMatrix.row1[0] = lightMatrix->row1[0] * lightX;
+				shadeMatrix.row1[1] = lightMatrix->row1[1] * lightX;
+				shadeMatrix.row1[2] = lightMatrix->row1[2] * lightX;
 
-				shadeMatrix[3] = (*(lightMatrix + 3)) * lightY;
-				shadeMatrix[4] = (*(lightMatrix + 4)) * lightY;
-				shadeMatrix[5] = (*(lightMatrix + 5)) * lightY;
+				shadeMatrix.row2[0] = lightMatrix->row2[0] * lightY;
+				shadeMatrix.row2[1] = lightMatrix->row2[1] * lightY;
+				shadeMatrix.row2[2] = lightMatrix->row2[2] * lightY;
 
-				shadeMatrix[6] = (*(lightMatrix + 6)) * lightZ;
-				shadeMatrix[7] = (*(lightMatrix + 7)) * lightZ;
-				shadeMatrix[8] = (*(lightMatrix + 8)) * lightZ;
+				shadeMatrix.row3[0] = lightMatrix->row3[0] * lightZ;
+				shadeMatrix.row3[1] = lightMatrix->row3[1] * lightZ;
+				shadeMatrix.row3[2] = lightMatrix->row3[2] * lightZ;
 
 				do { // for each normal
 					const int16 *colPtr = (const int16 *)shadePtr;
@@ -1445,9 +1433,10 @@ int32 Renderer::renderAnimatedModel(ModelData *modelData, uint8 *bodyPtr, Render
 					int16 col2 = *((const int16 *)colPtr++);
 					int16 col3 = *((const int16 *)colPtr++);
 
-					int32 color = shadeMatrix[0] * col1 + shadeMatrix[1] * col2 + shadeMatrix[2] * col3;
-					color += shadeMatrix[3] * col1 + shadeMatrix[4] * col2 + shadeMatrix[5] * col3;
-					color += shadeMatrix[6] * col1 + shadeMatrix[7] * col2 + shadeMatrix[8] * col3;
+					int32 color = 0;
+					color += shadeMatrix.row1[0] * col1 + shadeMatrix.row1[1] * col2 + shadeMatrix.row1[2] * col3;
+					color += shadeMatrix.row2[0] * col1 + shadeMatrix.row2[1] * col2 + shadeMatrix.row2[2] * col3;
+					color += shadeMatrix.row3[0] * col1 + shadeMatrix.row3[1] * col2 + shadeMatrix.row3[2] * col3;
 
 					int32 shade = 0;
 
@@ -1466,7 +1455,7 @@ int32 Renderer::renderAnimatedModel(ModelData *modelData, uint8 *bodyPtr, Render
 
 			tmpElemPtr = pri2Ptr3 = pri2Ptr3 + sizeof(elementEntry); // next element
 
-			/*tmpLightMatrix =*/lightMatrix = lightMatrix + 9;
+			++lightMatrix;
 		} while (--numOfPrimitives);
 	}
 
@@ -1508,7 +1497,7 @@ void Renderer::prepareIsoModel(uint8 *bodyPtr) { // loadGfxSub
 	}
 }
 
-int32 Renderer::renderIsoModel(int32 x, int32 y, int32 z, int32 angleX, int32 angleY, int32 angleZ, uint8 *bodyPtr) { // AffObjetIso
+int32 Renderer::renderIsoModel(int32 x, int32 y, int32 z, int32 angleX, int32 angleY, int32 angleZ, uint8 *bodyPtr) {
 	renderAngleX = angleX;
 	renderAngleY = angleY;
 	renderAngleZ = angleZ;
diff --git a/engines/twine/renderer.h b/engines/twine/renderer.h
index 372c798b43..9f6acbd5c5 100644
--- a/engines/twine/renderer.h
+++ b/engines/twine/renderer.h
@@ -57,6 +57,12 @@ struct CmdRenderPolygon {
 	// followed by Vertex array
 };
 
+struct Matrix {
+	int32 row1[3] {0, 0, 0};
+	int32 row2[3] {0, 0, 0};
+	int32 row3[3] {0, 0, 0};
+};
+
 class Renderer {
 private:
 	TwinEEngine *_engine;
@@ -154,11 +160,11 @@ private:
 	int32 renderModelElements(int32 numOfPrimitives, uint8 *pointer, RenderCommand** renderCmds, ModelData *modelData);
 	void getBaseRotationPosition(int32 x, int32 y, int32 z);
 	void getCameraAnglePositions(int32 x, int32 y, int32 z);
-	void applyRotation(int32 *targetMatrix, const int32 *currentMatrix);
-	void applyPointsRotation(const pointTab *pointsPtr, int32 numPoints, pointTab *destPoints, const int32 *rotationMatrix);
-	void processRotatedElement(int32 *targetMatrix, const uint8 *pointsPtr, int32 rotZ, int32 rotY, int32 rotX, const elementEntry *elemPtr, ModelData *modelData);
-	void applyPointsTranslation(const pointTab *pointsPtr, int32 numPoints, pointTab *destPoints, const int32 *translationMatrix);
-	void processTranslatedElement(int32 *targetMatrix, const uint8 *pointsPtr, int32 rotX, int32 rotY, int32 rotZ, const elementEntry *elemPtr, ModelData *modelData);
+	void applyRotation(Matrix *targetMatrix, const Matrix *currentMatrix);
+	void applyPointsRotation(const pointTab *pointsPtr, int32 numPoints, pointTab *destPoints, const Matrix *rotationMatrix);
+	void processRotatedElement(Matrix *targetMatrix, const uint8 *pointsPtr, int32 rotZ, int32 rotY, int32 rotX, const elementEntry *elemPtr, ModelData *modelData);
+	void applyPointsTranslation(const pointTab *pointsPtr, int32 numPoints, pointTab *destPoints, const Matrix *translationMatrix);
+	void processTranslatedElement(Matrix *targetMatrix, const uint8 *pointsPtr, int32 rotX, int32 rotY, int32 rotZ, const elementEntry *elemPtr, ModelData *modelData);
 	void translateGroup(int16 ax, int16 bx, int16 cx);
 
 	// ---- variables ----
@@ -187,11 +193,9 @@ private:
 
 	// ---
 
-	int32 baseMatrix[3 * 3] {0};
-
-	int32 matricesTable[30 * 3 * 3 + 1] {0};
-
-	int32 shadeMatrix[3 * 3] {0};
+	Matrix baseMatrix;
+	Matrix matricesTable[30 + 1];
+	Matrix shadeMatrix;
 	int32 lightX = 0;
 	int32 lightY = 0;
 	int32 lightZ = 0;




More information about the Scummvm-git-logs mailing list