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

mgerhardy martin.gerhardy at gmail.com
Sun Aug 15 10:30:34 UTC 2021


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

Summary:
97ae393b0a TWINE: reduced usage of the global _destPos
b04ea7b6ae TWINE: moved distance math functions out of the movement class
319beeecee TWINE: fixed penguin position handling
4e9d709853 TWINE: fixed typo
518bfac418 TWINE: fixed holomap script function
632bb99460 TWINE: const
b4813d1b65 TWINE: prepare to remove the _destPos member
e39b381819 TWINE: removed _destPos member from Renderer class
5456346d78 TWINE: new debug command to place the actor at the center of the camera
a1c1a74833 TWINE: fixed rendering artifacts for OverlayType::koInventoryItem


Commit: 97ae393b0a7255c87b207814eee82fe42dfb5ade
    https://github.com/scummvm/scummvm/commit/97ae393b0a7255c87b207814eee82fe42dfb5ade
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2021-08-15T12:30:09+02:00

Commit Message:
TWINE: reduced usage of the global _destPos

also identified a few potential issues and marked them with a TODO

Changed paths:
    engines/twine/renderer/renderer.cpp
    engines/twine/renderer/renderer.h
    engines/twine/scene/animations.cpp
    engines/twine/scene/collision.cpp
    engines/twine/scene/extra.cpp
    engines/twine/scene/movements.cpp
    engines/twine/scene/movements.h
    engines/twine/scene/scene.cpp
    engines/twine/script/script_life_v1.cpp
    engines/twine/script/script_move_v1.cpp
    engines/twine/twine.cpp


diff --git a/engines/twine/renderer/renderer.cpp b/engines/twine/renderer/renderer.cpp
index f2a3378312..46b5d19ed3 100644
--- a/engines/twine/renderer/renderer.cpp
+++ b/engines/twine/renderer/renderer.cpp
@@ -174,9 +174,8 @@ const IVec3 &Renderer::setBaseRotation(int32 x, int32 y, int32 z, bool transpose
 	if (transpose) {
 		baseMatrixTranspose();
 	}
-	getBaseRotationPosition(_baseTransPos.x, _baseTransPos.y, _baseTransPos.z);
+	_baseRotPos = getBaseRotationPosition(_baseTransPos.x, _baseTransPos.y, _baseTransPos.z);
 
-	_baseRotPos = _destPos;
 	return _baseRotPos;
 }
 
@@ -318,12 +317,12 @@ void Renderer::applyRotation(IMatrix3x3 *targetMatrix, const IMatrix3x3 *current
 	}
 }
 
-void Renderer::applyPointsRotation(const Common::Array<BodyVertex> &vertices, int32 firstPoint, int32 numPoints, I16Vec3 *destPoints, const IMatrix3x3 *rotationMatrix) {
+void Renderer::applyPointsRotation(const Common::Array<BodyVertex> &vertices, int32 firstPoint, int32 numPoints, I16Vec3 *destPoints, const IMatrix3x3 *rotationMatrix, const IVec3 &destPos) {
 	for (int32 i = 0; i < numPoints; ++i) {
 		const BodyVertex &vertex = vertices[i + firstPoint];
-		destPoints->x = ((rotationMatrix->row1.x * vertex.x + rotationMatrix->row1.y * vertex.y + rotationMatrix->row1.z * vertex.z) / SCENE_SIZE_HALF) + _destPos.x;
-		destPoints->y = ((rotationMatrix->row2.x * vertex.x + rotationMatrix->row2.y * vertex.y + rotationMatrix->row2.z * vertex.z) / SCENE_SIZE_HALF) + _destPos.y;
-		destPoints->z = ((rotationMatrix->row3.x * vertex.x + rotationMatrix->row3.y * vertex.y + rotationMatrix->row3.z * vertex.z) / SCENE_SIZE_HALF) + _destPos.z;
+		destPoints->x = ((rotationMatrix->row1.x * vertex.x + rotationMatrix->row1.y * vertex.y + rotationMatrix->row1.z * vertex.z) / SCENE_SIZE_HALF) + destPos.x;
+		destPoints->y = ((rotationMatrix->row2.x * vertex.x + rotationMatrix->row2.y * vertex.y + rotationMatrix->row2.z * vertex.z) / SCENE_SIZE_HALF) + destPos.y;
+		destPoints->z = ((rotationMatrix->row3.x * vertex.x + rotationMatrix->row3.y * vertex.y + rotationMatrix->row3.z * vertex.z) / SCENE_SIZE_HALF) + destPos.z;
 
 		destPoints++;
 	}
@@ -335,20 +334,17 @@ void Renderer::processRotatedElement(IMatrix3x3 *targetMatrix, const Common::Arr
 	const IVec3 renderAngle(rotX, rotY, rotZ);
 
 	const IMatrix3x3 *currentMatrix;
+	IVec3 destPos;
 	// if its the first point
 	if (bone.isRoot()) {
 		currentMatrix = &_baseMatrix;
-
-		_destPos.x = 0;
-		_destPos.y = 0;
-		_destPos.z = 0;
 	} else {
 		const int32 pointIdx = bone.vertex;
 		const int32 matrixIndex = bone.parent;
 		assert(matrixIndex >= 0 && matrixIndex < ARRAYSIZE(_matricesTable));
 		currentMatrix = &_matricesTable[matrixIndex];
 
-		_destPos = modelData->computedPoints[pointIdx];
+		destPos = modelData->computedPoints[pointIdx];
 	}
 
 	applyRotation(targetMatrix, currentMatrix, renderAngle);
@@ -357,19 +353,19 @@ void Renderer::processRotatedElement(IMatrix3x3 *targetMatrix, const Common::Arr
 		warning("RENDER WARNING: No points in this model!");
 	}
 
-	applyPointsRotation(vertices, firstPoint, numOfPoints, &modelData->computedPoints[firstPoint], targetMatrix);
+	applyPointsRotation(vertices, firstPoint, numOfPoints, &modelData->computedPoints[firstPoint], targetMatrix, destPos);
 }
 
-void Renderer::applyPointsTranslation(const Common::Array<BodyVertex> &vertices, int32 firstPoint, int32 numPoints, I16Vec3 *destPoints, const IMatrix3x3 *translationMatrix, const IVec3 &angleVec) {
+void Renderer::applyPointsTranslation(const Common::Array<BodyVertex> &vertices, int32 firstPoint, int32 numPoints, I16Vec3 *destPoints, const IMatrix3x3 *translationMatrix, const IVec3 &angleVec, const IVec3 &destPos) {
 	for (int32 i = 0; i < numPoints; ++i) {
 		const BodyVertex &vertex = vertices[i + firstPoint];
 		const int32 tmpX = vertex.x + angleVec.z;
 		const int32 tmpY = vertex.y + angleVec.y;
 		const int32 tmpZ = vertex.z + angleVec.x;
 
-		destPoints->x = ((translationMatrix->row1.x * tmpX + translationMatrix->row1.y * tmpY + translationMatrix->row1.z * tmpZ) / SCENE_SIZE_HALF) + _destPos.x;
-		destPoints->y = ((translationMatrix->row2.x * tmpX + translationMatrix->row2.y * tmpY + translationMatrix->row2.z * tmpZ) / SCENE_SIZE_HALF) + _destPos.y;
-		destPoints->z = ((translationMatrix->row3.x * tmpX + translationMatrix->row3.y * tmpY + translationMatrix->row3.z * tmpZ) / SCENE_SIZE_HALF) + _destPos.z;
+		destPoints->x = ((translationMatrix->row1.x * tmpX + translationMatrix->row1.y * tmpY + translationMatrix->row1.z * tmpZ) / SCENE_SIZE_HALF) + destPos.x;
+		destPoints->y = ((translationMatrix->row2.x * tmpX + translationMatrix->row2.y * tmpY + translationMatrix->row2.z * tmpZ) / SCENE_SIZE_HALF) + destPos.y;
+		destPoints->z = ((translationMatrix->row3.x * tmpX + translationMatrix->row3.y * tmpY + translationMatrix->row3.z * tmpZ) / SCENE_SIZE_HALF) + destPos.z;
 
 		destPoints++;
 	}
@@ -381,22 +377,20 @@ void Renderer::processTranslatedElement(IMatrix3x3 *targetMatrix, const Common::
 	renderAngle.y = rotY;
 	renderAngle.z = rotZ;
 
-	if (bone.isRoot()) { // base point
-		_destPos.x = 0;
-		_destPos.y = 0;
-		_destPos.z = 0;
+	IVec3 destPos;
 
+	if (bone.isRoot()) { // base point
 		*targetMatrix = _baseMatrix;
 	} else { // dependent
 		const int32 pointsIdx = bone.vertex;
-		_destPos = modelData->computedPoints[pointsIdx];
+		destPos = modelData->computedPoints[pointsIdx];
 
 		const int32 matrixIndex = bone.parent;
 		assert(matrixIndex >= 0 && matrixIndex < ARRAYSIZE(_matricesTable));
 		*targetMatrix = _matricesTable[matrixIndex];
 	}
 
-	applyPointsTranslation(vertices, bone.firstVertex, bone.numVertices, &modelData->computedPoints[bone.firstVertex], targetMatrix, renderAngle);
+	applyPointsTranslation(vertices, bone.firstVertex, bone.numVertices, &modelData->computedPoints[bone.firstVertex], targetMatrix, renderAngle, destPos);
 }
 
 void Renderer::setLightVector(int32 angleX, int32 angleY, int32 angleZ) {
@@ -407,9 +401,7 @@ void Renderer::setLightVector(int32 angleX, int32 angleY, int32 angleZ) {
 
 	const IVec3 renderAngle(angleX, angleY, angleZ);
 	applyRotation(&_shadeMatrix, &_baseMatrix, renderAngle);
-	translateGroup(0, 0, 59);
-
-	_lightPos = _destPos;
+	_lightPos = translateGroup(0, 0, 59);
 }
 
 static FORCEINLINE int16 clamp(int16 x, int16 a, int16 b) {
diff --git a/engines/twine/renderer/renderer.h b/engines/twine/renderer/renderer.h
index e0f319d6bc..d12b37964e 100644
--- a/engines/twine/renderer/renderer.h
+++ b/engines/twine/renderer/renderer.h
@@ -143,9 +143,9 @@ private:
 		return getCameraAnglePositions(vec.x, vec.y, vec.z);
 	}
 	void applyRotation(IMatrix3x3 *targetMatrix, const IMatrix3x3 *currentMatrix, const IVec3 &angleVec);
-	void applyPointsRotation(const Common::Array<BodyVertex>& vertices, int32 firstPoint, int32 numPoints, I16Vec3 *destPoints, const IMatrix3x3 *rotationMatrix);
+	void applyPointsRotation(const Common::Array<BodyVertex>& vertices, int32 firstPoint, int32 numPoints, I16Vec3 *destPoints, const IMatrix3x3 *rotationMatrix, const IVec3 &destPos);
 	void processRotatedElement(IMatrix3x3 *targetMatrix, const Common::Array<BodyVertex>& vertices, int32 rotX, int32 rotY, int32 rotZ, const BodyBone &bone, ModelData *modelData);
-	void applyPointsTranslation(const Common::Array<BodyVertex>& vertices, int32 firstPoint, int32 numPoints, I16Vec3 *destPoints, const IMatrix3x3 *translationMatrix, const IVec3 &angleVec);
+	void applyPointsTranslation(const Common::Array<BodyVertex>& vertices, int32 firstPoint, int32 numPoints, I16Vec3 *destPoints, const IMatrix3x3 *translationMatrix, const IVec3 &angleVec, const IVec3 &destPos);
 	void processTranslatedElement(IMatrix3x3 *targetMatrix, const Common::Array<BodyVertex>& vertices, int32 rotX, int32 rotY, int32 rotZ, const BodyBone &bone, ModelData *modelData);
 	const IVec3 &translateGroup(int32 x, int32 y, int32 z);
 
diff --git a/engines/twine/scene/animations.cpp b/engines/twine/scene/animations.cpp
index b5e5e35f4c..7fd1399450 100644
--- a/engines/twine/scene/animations.cpp
+++ b/engines/twine/scene/animations.cpp
@@ -334,11 +334,11 @@ void Animations::processAnimActions(int32 actorIdx) {
 			break;
 		case ActionType::ACTION_THROW_3D:
 			if (action.animFrame == actor->_animPosition) {
-				_engine->_movements->rotateActor(action.distanceX, action.distanceZ, actor->_angle);
+				const IVec3 &destPos = _engine->_movements->rotateActor(action.distanceX, action.distanceZ, actor->_angle);
 
-				const int32 throwX = _engine->_renderer->_destPos.x + actor->_pos.x;
+				const int32 throwX = destPos.x + actor->_pos.x;
 				const int32 throwY = action.distanceY + actor->_pos.y;
-				const int32 throwZ = _engine->_renderer->_destPos.z + actor->_pos.z;
+				const int32 throwZ = destPos.z + actor->_pos.z;
 
 				_engine->_extra->addExtraThrow(actorIdx, throwX, throwY, throwZ, action.spriteIndex,
 				                               action.xAngle, action.yAngle + actor->_angle, action.xRotPoint, action.extraAngle, action.strength);
@@ -349,11 +349,11 @@ void Animations::processAnimActions(int32 actorIdx) {
 				const int32 distance = _engine->_movements->getDistance2D(actor->pos(), _engine->_scene->_sceneHero->pos());
 				const int32 newAngle = _engine->_movements->getAngleAndSetTargetActorDistance(actor->_pos.y, 0, _engine->_scene->_sceneHero->_pos.y, distance);
 
-				_engine->_movements->rotateActor(action.distanceX, action.distanceZ, actor->_angle);
+				const IVec3 &destPos = _engine->_movements->rotateActor(action.distanceX, action.distanceZ, actor->_angle);
 
-				const int32 throwX = _engine->_renderer->_destPos.x + actor->_pos.x;
+				const int32 throwX = destPos.x + actor->_pos.x;
 				const int32 throwY = action.distanceY + actor->_pos.y;
-				const int32 throwZ = _engine->_renderer->_destPos.z + actor->_pos.z;
+				const int32 throwZ = destPos.z + actor->_pos.z;
 
 				_engine->_extra->addExtraThrow(actorIdx, throwX, throwY, throwZ, action.spriteIndex,
 				                               action.xAngle + newAngle, action.yAngle + actor->_angle, action.xRotPoint, action.extraAngle, action.strength);
@@ -361,20 +361,20 @@ void Animations::processAnimActions(int32 actorIdx) {
 			break;
 		case ActionType::ACTION_THROW_3D_SEARCH:
 			if (action.animFrame == actor->_animPosition) {
-				_engine->_movements->rotateActor(action.distanceX, action.distanceZ, actor->_angle);
-				const int32 x = actor->_pos.x + _engine->_renderer->_destPos.x;
+				const IVec3 &destPos = _engine->_movements->rotateActor(action.distanceX, action.distanceZ, actor->_angle);
+				const int32 x = actor->_pos.x + destPos.x;
 				const int32 y = actor->_pos.y + action.distanceY;
-				const int32 z = actor->_pos.z + _engine->_renderer->_destPos.z;
+				const int32 z = actor->_pos.z + destPos.z;
 				_engine->_extra->addExtraAiming(actorIdx, x, y, z, action.spriteIndex,
 				                                action.targetActor, action.finalAngle, action.strength);
 			}
 			break;
 		case ActionType::ACTION_UNKNOWN_21:
 			if (_engine->_gameState->_magicBallIdx == -1 && action.animFrame == actor->_animPosition) {
-				_engine->_movements->rotateActor(action.distanceX, action.distanceZ, actor->_angle);
-				const int32 x = actor->_pos.x + _engine->_renderer->_destPos.x;
+				const IVec3 &destPos = _engine->_movements->rotateActor(action.distanceX, action.distanceZ, actor->_angle);
+				const int32 x = actor->_pos.x + destPos.x;
 				const int32 y = actor->_pos.y + action.distanceY;
-				const int32 z = actor->_pos.z + _engine->_renderer->_destPos.z;
+				const int32 z = actor->_pos.z + destPos.z;
 				_engine->_extra->addExtraThrowMagicball(x, y, z, action.xAngle, actor->_angle, action.yAngle, action.finalAngle);
 			}
 			break;
@@ -486,14 +486,14 @@ void Animations::processActorAnimations(int32 actorIdx) { // DoAnim
 					}
 				}
 
-				_engine->_movements->rotateActor(xAxisRotation, 0, actor->_spriteActorRotation);
+				IVec3 destPos = _engine->_movements->rotateActor(xAxisRotation, 0, actor->_spriteActorRotation);
 
-				processActor.y = actor->_pos.y - _engine->_renderer->_destPos.z;
+				processActor.y = actor->_pos.y - destPos.z;
 
-				_engine->_movements->rotateActor(0, _engine->_renderer->_destPos.x, actor->_angle);
+				destPos = _engine->_movements->rotateActor(0, destPos.x, actor->_angle);
 
-				processActor.x = actor->_pos.x + _engine->_renderer->_destPos.x;
-				processActor.z = actor->_pos.z + _engine->_renderer->_destPos.z;
+				processActor.x = actor->_pos.x + destPos.x;
+				processActor.z = actor->_pos.z + destPos.z;
 
 				_engine->_movements->setActorAngle(ANGLE_0, actor->_speed, ANGLE_17, &actor->_move);
 
@@ -552,9 +552,7 @@ void Animations::processActorAnimations(int32 actorIdx) { // DoAnim
 					processActor.z = ((processActor.z / 128) * 128);
 				}
 
-				actor->_lastPos.x = 0;
-				actor->_lastPos.y = 0;
-				actor->_lastPos.z = 0;
+				actor->_lastPos = IVec3();
 			}
 		}
 	} else { // 3D actor
@@ -575,10 +573,10 @@ void Animations::processActorAnimations(int32 actorIdx) { // DoAnim
 			actor->_angle = ClampAngle(actor->_angle + _processLastRotationAngle - actor->_lastRotationAngle);
 			actor->_lastRotationAngle = _processLastRotationAngle;
 
-			_engine->_movements->rotateActor(_currentStep.x, _currentStep.z, actor->_angle);
+			const IVec3 &destPos = _engine->_movements->rotateActor(_currentStep.x, _currentStep.z, actor->_angle);
 
-			_currentStep.x = _engine->_renderer->_destPos.x;
-			_currentStep.z = _engine->_renderer->_destPos.z;
+			_currentStep.x = destPos.x;
+			_currentStep.z = destPos.z;
 
 			processActor = actor->pos() + _currentStep - actor->_lastPos;
 
@@ -622,9 +620,7 @@ void Animations::processActorAnimations(int32 actorIdx) { // DoAnim
 
 				actor->_lastRotationAngle = ANGLE_0;
 
-				actor->_lastPos.x = 0;
-				actor->_lastPos.y = 0;
-				actor->_lastPos.z = 0;
+				actor->_lastPos = IVec3();
 			}
 		}
 	}
@@ -688,13 +684,13 @@ void Animations::processActorAnimations(int32 actorIdx) { // DoAnim
 
 		// process wall hit while running
 		if (_engine->_collision->_causeActorDamage && !actor->_dynamicFlags.bIsFalling && !_currentlyProcessedActorIdx && _engine->_actor->_heroBehaviour == HeroBehaviourType::kAthletic && actor->_anim == AnimationTypes::kForward) {
-			_engine->_movements->rotateActor(actor->_boudingBox.mins.x, actor->_boudingBox.mins.z, actor->_angle + ANGLE_360 + ANGLE_135);
+			IVec3 destPos = _engine->_movements->rotateActor(actor->_boudingBox.mins.x, actor->_boudingBox.mins.z, actor->_angle + ANGLE_360 + ANGLE_135);
 
-			_engine->_renderer->_destPos.x += processActor.x;
-			_engine->_renderer->_destPos.z += processActor.z;
+			destPos.x += processActor.x;
+			destPos.z += processActor.z;
 
-			if (_engine->_renderer->_destPos.x >= 0 && _engine->_renderer->_destPos.z >= 0 && _engine->_renderer->_destPos.x <= 0x7E00 && _engine->_renderer->_destPos.z <= 0x7E00) {
-				if (_engine->_grid->getBrickShape(_engine->_renderer->_destPos.x, processActor.y + BRICK_HEIGHT, _engine->_renderer->_destPos.z) != ShapeType::kNone && _engine->_cfgfile.WallCollision) { // avoid wall hit damage
+			if (destPos.x >= 0 && destPos.z >= 0 && destPos.x <= 0x7E00 && destPos.z <= 0x7E00) { // SCENE_SIZE_MAX
+				if (_engine->_grid->getBrickShape(destPos.x, processActor.y + BRICK_HEIGHT, destPos.z) != ShapeType::kNone && _engine->_cfgfile.WallCollision) { // avoid wall hit damage
 					_engine->_extra->addExtraSpecial(actor->_pos.x, actor->_pos.y + 1000, actor->_pos.z, ExtraSpecialType::kHitStars);
 					initAnim(AnimationTypes::kBigHit, AnimType::kAnimationType_2, AnimationTypes::kStanding, _currentlyProcessedActorIdx);
 
diff --git a/engines/twine/scene/collision.cpp b/engines/twine/scene/collision.cpp
index 4338765d35..24c00276ad 100644
--- a/engines/twine/scene/collision.cpp
+++ b/engines/twine/scene/collision.cpp
@@ -321,15 +321,15 @@ int32 Collision::checkCollisionWithActors(int32 actorIdx) {
 	}
 
 	if (actor->_dynamicFlags.bIsHitting) {
-		_engine->_movements->rotateActor(0, 200, actor->_angle);
+		const IVec3 &destPos = _engine->_movements->rotateActor(0, 200, actor->_angle);
 
-		mins.x = _engine->_renderer->_destPos.x + processActor.x + actor->_boudingBox.mins.x;
+		mins.x = destPos.x + processActor.x + actor->_boudingBox.mins.x;
 		mins.y = processActor.y + actor->_boudingBox.mins.y;
-		mins.z = _engine->_renderer->_destPos.z + processActor.z + actor->_boudingBox.mins.z;
+		mins.z = destPos.z + processActor.z + actor->_boudingBox.mins.z;
 
-		maxs.x = _engine->_renderer->_destPos.x + processActor.x + actor->_boudingBox.maxs.x;
+		maxs.x = destPos.x + processActor.x + actor->_boudingBox.maxs.x;
 		maxs.y = processActor.y + actor->_boudingBox.maxs.y;
-		maxs.z = _engine->_renderer->_destPos.z + processActor.z + actor->_boudingBox.maxs.z;
+		maxs.z = destPos.z + processActor.z + actor->_boudingBox.maxs.z;
 
 		for (int32 a = 0; a < _engine->_scene->_sceneNumActors; a++) {
 			const ActorStruct *actorTest = _engine->_scene->getActor(a);
diff --git a/engines/twine/scene/extra.cpp b/engines/twine/scene/extra.cpp
index be7e60d5f3..bd3e1fde4b 100644
--- a/engines/twine/scene/extra.cpp
+++ b/engines/twine/scene/extra.cpp
@@ -136,14 +136,14 @@ void Extra::throwExtra(ExtraListStruct *extra, int32 xAngle, int32 yAngle, int32
 
 	extra->lastPos = extra->pos;
 
-	_engine->_movements->rotateActor(x, 0, xAngle);
+	IVec3 destPos = _engine->_movements->rotateActor(x, 0, xAngle);
 
-	extra->destPos.y = -_engine->_renderer->_destPos.z;
+	extra->destPos.y = -destPos.z;
 
-	_engine->_movements->rotateActor(0, _engine->_renderer->_destPos.x, yAngle);
+	destPos = _engine->_movements->rotateActor(0, destPos.x, yAngle);
 
-	extra->destPos.x = _engine->_renderer->_destPos.x;
-	extra->destPos.z = _engine->_renderer->_destPos.z;
+	extra->destPos.x = destPos.x;
+	extra->destPos.z = destPos.z;
 
 	extra->angle = extraAngle;
 	extra->spawnTime = _engine->_lbaTime;
@@ -412,10 +412,10 @@ void Extra::drawSpecialShape(const ExtraShape &shapeTable, int32 x, int32 y, int
 	renderRect.top = 0x7D00;
 	renderRect.bottom = -0x7D00;
 
-	_engine->_movements->rotateActor(shapeX, shapeZ, angle);
+	IVec3 destPos = _engine->_movements->rotateActor(shapeX, shapeZ, angle);
 
-	const int32 computedX = _engine->_renderer->_destPos.x + x;
-	const int32 computedY = _engine->_renderer->_destPos.z + y;
+	const int32 computedX = destPos.x + x;
+	const int32 computedY = destPos.z + y;
 
 	if (computedX < renderRect.left) {
 		renderRect.left = computedX;
@@ -447,10 +447,10 @@ void Extra::drawSpecialShape(const ExtraShape &shapeTable, int32 x, int32 y, int
 		_engine->_renderer->_projPos.x = currentX;
 		_engine->_renderer->_projPos.y = currentY;
 
-		_engine->_movements->rotateActor(shapeX, shapeZ, angle);
+		destPos = _engine->_movements->rotateActor(shapeX, shapeZ, angle);
 
-		currentX = _engine->_renderer->_destPos.x + x;
-		currentY = _engine->_renderer->_destPos.z + y;
+		currentX = destPos.x + x;
+		currentY = destPos.z + y;
 
 		if (currentX < renderRect.left) {
 			renderRect.left = currentX;
@@ -631,12 +631,12 @@ void Extra::processExtras() {
 				pos = 1;
 			}
 
-			_engine->_movements->rotateActor(pos, 0, angle2);
-			extra->pos.y -= _engine->_renderer->_destPos.z;
+			IVec3 destPos = _engine->_movements->rotateActor(pos, 0, angle2);
+			extra->pos.y -= destPos.z;
 
-			_engine->_movements->rotateActor(0, _engine->_renderer->_destPos.x, tmpAngle);
-			extra->pos.x += _engine->_renderer->_destPos.x;
-			extra->pos.z += _engine->_renderer->_destPos.z;
+			destPos = _engine->_movements->rotateActor(0, destPos.x, tmpAngle);
+			extra->pos.x += destPos.x;
+			extra->pos.z += destPos.z;
 
 			_engine->_movements->setActorAngle(ANGLE_0, extra->destPos.z, ANGLE_17, &extra->trackActorMove);
 
@@ -682,12 +682,12 @@ void Extra::processExtras() {
 				pos = 1;
 			}
 
-			_engine->_movements->rotateActor(pos, 0, angle2);
-			extra->pos.y -= _engine->_renderer->_destPos.z;
+			IVec3 destPos = _engine->_movements->rotateActor(pos, 0, angle2);
+			extra->pos.y -= destPos.z;
 
-			_engine->_movements->rotateActor(0, _engine->_renderer->_destPos.x, tmpAngle);
-			extra->pos.x += _engine->_renderer->_destPos.x;
-			extra->pos.z += _engine->_renderer->_destPos.z;
+			destPos = _engine->_movements->rotateActor(0, destPos.x, tmpAngle);
+			extra->pos.x += destPos.x;
+			extra->pos.z += destPos.z;
 
 			_engine->_movements->setActorAngle(ANGLE_0, extra->destPos.z, ANGLE_17, &extra->trackActorMove);
 
diff --git a/engines/twine/scene/movements.cpp b/engines/twine/scene/movements.cpp
index 43bdc29e65..0db98dcddc 100644
--- a/engines/twine/scene/movements.cpp
+++ b/engines/twine/scene/movements.cpp
@@ -141,10 +141,11 @@ int32 Movements::getAngleAndSetTargetActorDistance(int32 x1, int32 z1, int32 x2,
 	return ClampAngle(finalAngle);
 }
 
-void Movements::rotateActor(int32 x, int32 z, int32 angle) {
+const IVec3 &Movements::rotateActor(int32 x, int32 z, int32 angle) {
 	const double radians = AngleToRadians(angle);
 	_engine->_renderer->_destPos.x = (int32)(x * cos(radians) + z * sin(radians));
 	_engine->_renderer->_destPos.z = (int32)(-x * sin(radians) + z * cos(radians));
+	return _engine->_renderer->_destPos;
 }
 
 int32 Movements::getDistance2D(int32 x1, int32 z1, int32 x2, int32 z2) const {
diff --git a/engines/twine/scene/movements.h b/engines/twine/scene/movements.h
index 5ba51bfada..0c54a39abc 100644
--- a/engines/twine/scene/movements.h
+++ b/engines/twine/scene/movements.h
@@ -183,7 +183,7 @@ public:
 	 * @param z Actor current Z coordinate
 	 * @param angle Actor angle to rotate
 	 */
-	void rotateActor(int32 x, int32 z, int32 angle);
+	const IVec3 &rotateActor(int32 x, int32 z, int32 angle);
 
 	/**
 	 * Get distance value in 2D
diff --git a/engines/twine/scene/scene.cpp b/engines/twine/scene/scene.cpp
index 9ce91d8876..76d956fa6a 100644
--- a/engines/twine/scene/scene.cpp
+++ b/engines/twine/scene/scene.cpp
@@ -733,12 +733,12 @@ void Scene::processActorZones(int32 actorIdx) {
 				break;
 			case ZoneType::kLadder:
 				if (IS_HERO(actorIdx) && _engine->_actor->_heroBehaviour != HeroBehaviourType::kProtoPack && (actor->_anim == AnimationTypes::kForward || actor->_anim == AnimationTypes::kTopLadder || actor->_anim == AnimationTypes::kClimbLadder)) {
-					_engine->_movements->rotateActor(actor->_boudingBox.mins.x, actor->_boudingBox.mins.z, actor->_angle + ANGLE_360 + ANGLE_135);
-					_engine->_renderer->_destPos.x += _engine->_movements->_processActor.x;
-					_engine->_renderer->_destPos.z += _engine->_movements->_processActor.z;
+					IVec3 destPos = _engine->_movements->rotateActor(actor->_boudingBox.mins.x, actor->_boudingBox.mins.z, actor->_angle + ANGLE_360 + ANGLE_135);
+					destPos.x += _engine->_movements->_processActor.x;
+					destPos.z += _engine->_movements->_processActor.z;
 
-					if (_engine->_renderer->_destPos.x >= 0 && _engine->_renderer->_destPos.z >= 0 && _engine->_renderer->_destPos.x <= 0x7E00 && _engine->_renderer->_destPos.z <= 0x7E00) {
-						if (_engine->_grid->getBrickShape(_engine->_renderer->_destPos.x, actor->_pos.y + ANGLE_90, _engine->_renderer->_destPos.z) != ShapeType::kNone) {
+					if (destPos.x >= 0 && destPos.z >= 0 && destPos.x <= 0x7E00 && destPos.z <= 0x7E00) {
+						if (_engine->_grid->getBrickShape(destPos.x, actor->_pos.y + ANGLE_90, destPos.z) != ShapeType::kNone) {
 							_currentActorInZone = true;
 							if (actor->_pos.y >= ABS(zone->mins.y + zone->maxs.y) / 2) {
 								_engine->_animations->initAnim(AnimationTypes::kTopLadder, AnimType::kAnimationType_2, AnimationTypes::kStanding, actorIdx); // reached end of ladder
diff --git a/engines/twine/script/script_life_v1.cpp b/engines/twine/script/script_life_v1.cpp
index 6e5f869f38..748f850117 100644
--- a/engines/twine/script/script_life_v1.cpp
+++ b/engines/twine/script/script_life_v1.cpp
@@ -1117,6 +1117,8 @@ static int32 lPOS_POINT(TwinEEngine *engine, LifeScriptContext &ctx) {
 	int32 trackIdx = ctx.stream.readByte();
 
 	const IVec3 &sp = engine->_scene->_sceneTracks[trackIdx];
+	// TODO: is this needed? Most likely not as the scene track positions are passed as parameters
+	// everywhere and the _destPos var is not used in this function.
 	engine->_renderer->_destPos = sp;
 	ctx.actor->_pos = sp;
 
diff --git a/engines/twine/script/script_move_v1.cpp b/engines/twine/script/script_move_v1.cpp
index 197f69b91e..58198e436a 100644
--- a/engines/twine/script/script_move_v1.cpp
+++ b/engines/twine/script/script_move_v1.cpp
@@ -117,9 +117,9 @@ static int32 mGOTO_POINT(TwinEEngine *engine, MoveScriptContext &ctx) {
 	engine->_scene->_currentScriptValue = ctx.stream.readByte();
 
 	const IVec3 &sp = engine->_scene->_sceneTracks[engine->_scene->_currentScriptValue];
-	engine->_renderer->_destPos.x = sp.x;
-	engine->_renderer->_destPos.y = sp.y;
-	engine->_renderer->_destPos.z = sp.z;
+	// TODO: is this needed? Most likely not as the scene track positions are passed as parameters
+	// everywhere and the _destPos var is not used in this function.
+	engine->_renderer->_destPos = sp;
 
 	const int32 newAngle = engine->_movements->getAngleAndSetTargetActorDistance(ctx.actor->_pos.x, ctx.actor->_pos.z, sp.x, sp.z);
 
@@ -189,9 +189,9 @@ static int32 mPOS_POINT(TwinEEngine *engine, MoveScriptContext &ctx) {
 	engine->_scene->_currentScriptValue = ctx.stream.readByte();
 
 	const IVec3 &sp = engine->_scene->_sceneTracks[engine->_scene->_currentScriptValue];
-	engine->_renderer->_destPos.x = sp.x;
-	engine->_renderer->_destPos.y = sp.y;
-	engine->_renderer->_destPos.z = sp.z;
+	// TODO: is this needed? Most likely not as the scene track positions are passed as parameters
+	// everywhere and the _destPos var is not used in this function.
+	engine->_renderer->_destPos = sp;
 
 	if (ctx.actor->_staticFlags.bIsSpriteActor) {
 		ctx.actor->_speed = 0;
@@ -247,6 +247,8 @@ static int32 mGOTO_SYM_POINT(TwinEEngine *engine, MoveScriptContext &ctx) {
 	engine->_scene->_currentScriptValue = ctx.stream.readByte();
 
 	const IVec3 &sp = engine->_scene->_sceneTracks[engine->_scene->_currentScriptValue];
+	// TODO: is this needed? Most likely not as the scene track positions are passed as parameters
+	// everywhere and the _destPos var is not used in this function.
 	engine->_renderer->_destPos = sp;
 
 	const int32 newAngle = ANGLE_180 + engine->_movements->getAngleAndSetTargetActorDistance(ctx.actor->_pos.x, ctx.actor->_pos.z, sp.x, sp.z);
@@ -318,9 +320,9 @@ static int32 mGOTO_POINT_3D(TwinEEngine *engine, MoveScriptContext &ctx) {
 	engine->_scene->_currentScriptValue = trackId;
 
 	const IVec3 &sp = engine->_scene->_sceneTracks[engine->_scene->_currentScriptValue];
-	engine->_renderer->_destPos.x = sp.x;
-	engine->_renderer->_destPos.y = sp.y;
-	engine->_renderer->_destPos.z = sp.z;
+	// TODO: is this needed? Most likely not as the scene track positions are passed as parameters
+	// everywhere and the _destPos var is not used in this function.
+	engine->_renderer->_destPos = sp;
 
 	ctx.actor->_angle = engine->_movements->getAngleAndSetTargetActorDistance(ctx.actor->_pos.x, ctx.actor->_pos.z, sp.x, sp.z);
 	ctx.actor->_spriteActorRotation = engine->_movements->getAngleAndSetTargetActorDistance(ctx.actor->_pos.y, 0, sp.y, engine->_movements->_targetActorDistance);
diff --git a/engines/twine/twine.cpp b/engines/twine/twine.cpp
index ed5bba3033..833750a915 100644
--- a/engines/twine/twine.cpp
+++ b/engines/twine/twine.cpp
@@ -647,6 +647,9 @@ void TwinEEngine::processInventoryAction() {
 	case kiPinguin: {
 		ActorStruct *pinguin = _scene->getActor(_scene->_mecaPinguinIdx);
 
+		// TODO: is this meant to happen before the rotateActor() call - the _destPos might be
+		// set to some random position. Also the _destPos that is set by the rotateActor call
+		// is not used anywhere in this switch/case - as far as I can see.
 		pinguin->_pos.x = _renderer->_destPos.x + _scene->_sceneHero->_pos.x;
 		pinguin->_pos.y = _scene->_sceneHero->_pos.y;
 		pinguin->_pos.z = _renderer->_destPos.z + _scene->_sceneHero->_pos.z;


Commit: b04ea7b6ae415a8adc5090db2b6f906fd747e54f
    https://github.com/scummvm/scummvm/commit/b04ea7b6ae415a8adc5090db2b6f906fd747e54f
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2021-08-15T12:30:09+02:00

Commit Message:
TWINE: moved distance math functions out of the movement class

Changed paths:
  A engines/twine/shared.cpp
    engines/twine/audio/sound.cpp
    engines/twine/module.mk
    engines/twine/scene/animations.cpp
    engines/twine/scene/movements.cpp
    engines/twine/scene/movements.h
    engines/twine/script/script_life_v1.cpp
    engines/twine/shared.h


diff --git a/engines/twine/audio/sound.cpp b/engines/twine/audio/sound.cpp
index 1cdef5258e..87af4466d5 100644
--- a/engines/twine/audio/sound.cpp
+++ b/engines/twine/audio/sound.cpp
@@ -54,7 +54,7 @@ void Sound::setSamplePosition(int32 channelIdx, int32 x, int32 y, int32 z) {
 	const int32 camX = _engine->_grid->_newCamera.x * BRICK_SIZE;
 	const int32 camY = _engine->_grid->_newCamera.y * BRICK_HEIGHT;
 	const int32 camZ = _engine->_grid->_newCamera.z * BRICK_SIZE;
-	int32 distance = _engine->_movements->getDistance3D(camX, camY, camZ, x, y, z);
+	int32 distance = getDistance3D(camX, camY, camZ, x, y, z);
 	distance = _engine->_collision->getAverageValue(0, distance, 10000, 255);
 	const byte targetVolume = CLIP<byte>(255 - distance, 0, 255);
 	_engine->_system->getMixer()->setChannelVolume(samplesPlaying[channelIdx], targetVolume);
diff --git a/engines/twine/module.mk b/engines/twine/module.mk
index 380d4053cd..c2f59a66d0 100644
--- a/engines/twine/module.mk
+++ b/engines/twine/module.mk
@@ -46,6 +46,7 @@ MODULE_OBJS := \
 	holomap.o \
 	input.o \
 	metaengine.o \
+	shared.o \
 	text.o \
 	twine.o
 
diff --git a/engines/twine/scene/animations.cpp b/engines/twine/scene/animations.cpp
index 7fd1399450..6fd7c20ee3 100644
--- a/engines/twine/scene/animations.cpp
+++ b/engines/twine/scene/animations.cpp
@@ -346,7 +346,7 @@ void Animations::processAnimActions(int32 actorIdx) {
 			break;
 		case ActionType::ACTION_THROW_3D_ALPHA:
 			if (action.animFrame == actor->_animPosition) {
-				const int32 distance = _engine->_movements->getDistance2D(actor->pos(), _engine->_scene->_sceneHero->pos());
+				const int32 distance = getDistance2D(actor->pos(), _engine->_scene->_sceneHero->pos());
 				const int32 newAngle = _engine->_movements->getAngleAndSetTargetActorDistance(actor->_pos.y, 0, _engine->_scene->_sceneHero->_pos.y, distance);
 
 				const IVec3 &destPos = _engine->_movements->rotateActor(action.distanceX, action.distanceZ, actor->_angle);
@@ -454,7 +454,7 @@ bool Animations::initAnim(AnimationTypes newAnim, AnimType animType, AnimationTy
 	return true;
 }
 
-void Animations::processActorAnimations(int32 actorIdx) { // DoAnim
+void Animations::processActorAnimations(int32 actorIdx) {
 	ActorStruct *actor = _engine->_scene->getActor(actorIdx);
 
 	_currentlyProcessedActorIdx = actorIdx;
@@ -499,7 +499,7 @@ void Animations::processActorAnimations(int32 actorIdx) { // DoAnim
 
 				if (actor->_dynamicFlags.bIsSpriteMoving) {
 					if (actor->_doorStatus) { // open door
-						if (_engine->_movements->getDistance2D(processActor.x, processActor.z, actor->_lastPos.x, actor->_lastPos.z) >= actor->_doorStatus) {
+						if (getDistance2D(processActor.x, processActor.z, actor->_lastPos.x, actor->_lastPos.z) >= actor->_doorStatus) {
 							if (actor->_angle == ANGLE_0) {
 								processActor.z = actor->_lastPos.z + actor->_doorStatus;
 							} else if (actor->_angle == ANGLE_90) {
diff --git a/engines/twine/scene/movements.cpp b/engines/twine/scene/movements.cpp
index 0db98dcddc..578b3ce1fc 100644
--- a/engines/twine/scene/movements.cpp
+++ b/engines/twine/scene/movements.cpp
@@ -148,22 +148,6 @@ const IVec3 &Movements::rotateActor(int32 x, int32 z, int32 angle) {
 	return _engine->_renderer->_destPos;
 }
 
-int32 Movements::getDistance2D(int32 x1, int32 z1, int32 x2, int32 z2) const {
-	return (int32)sqrt((float)((x2 - x1) * (x2 - x1) + (z2 - z1) * (z2 - z1)));
-}
-
-int32 Movements::getDistance2D(const IVec3 &v1, const IVec3 &v2) const {
-	return (int32)sqrt((float)((v2.x - v1.x) * (v2.x - v1.x) + (v2.z - v1.z) * (v2.z - v1.z)));
-}
-
-int32 Movements::getDistance3D(int32 x1, int32 y1, int32 z1, int32 x2, int32 y2, int32 z2) const {
-	return (int32)sqrt((float)((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) + (z2 - z1) * (z2 - z1)));
-}
-
-int32 Movements::getDistance3D(const IVec3 &v1, const IVec3 &v2) const {
-	return (int32)sqrt((float)((v2.x - v1.x) * (v2.x - v1.x) + (v2.y - v1.y) * (v2.y - v1.y) + (v2.z - v1.z) * (v2.z - v1.z)));
-}
-
 void Movements::moveActor(int32 angleFrom, int32 angleTo, int32 speed, ActorMoveStruct *movePtr) const { // ManualRealAngle
 	const int16 from = ClampAngle(angleFrom);
 	const int16 to = ClampAngle(angleTo);
diff --git a/engines/twine/scene/movements.h b/engines/twine/scene/movements.h
index 0c54a39abc..4cfe008aa8 100644
--- a/engines/twine/scene/movements.h
+++ b/engines/twine/scene/movements.h
@@ -185,28 +185,6 @@ public:
 	 */
 	const IVec3 &rotateActor(int32 x, int32 z, int32 angle);
 
-	/**
-	 * Get distance value in 2D
-	 * @param x1 Actor 1 X coordinate
-	 * @param z1 Actor 1 Z coordinate
-	 * @param x2 Actor 2 X coordinate
-	 * @param z2 Actor 2 Z coordinate
-	 */
-	int32 getDistance2D(int32 x1, int32 z1, int32 x2, int32 z2) const;
-	int32 getDistance2D(const IVec3 &v1, const IVec3 &v2) const;
-
-	/**
-	 * Get distance value in 3D
-	 * @param x1 Actor 1 X coordinate
-	 * @param y1 Actor 1 Y coordinate
-	 * @param z1 Actor 1 Z coordinate
-	 * @param x2 Actor 2 X coordinate
-	 * @param y2 Actor 2 Y coordinate
-	 * @param z2 Actor 2 Z coordinate
-	 */
-	int32 getDistance3D(int32 x1, int32 y1, int32 z1, int32 x2, int32 y2, int32 z2) const;
-	int32 getDistance3D(const IVec3 &v1, const IVec3 &v2) const;
-
 	/**
 	 * Move actor around the scene
 	 * @param angleFrom Current actor angle
diff --git a/engines/twine/script/script_life_v1.cpp b/engines/twine/script/script_life_v1.cpp
index 748f850117..f7259a5f8d 100644
--- a/engines/twine/script/script_life_v1.cpp
+++ b/engines/twine/script/script_life_v1.cpp
@@ -162,7 +162,7 @@ static int32 processLifeConditions(TwinEEngine *engine, LifeScriptContext &ctx)
 				engine->_scene->_currentScriptValue = MAX_TARGET_ACTOR_DISTANCE;
 			} else {
 				// Returns int32, so we check for integer overflow
-				int32 distance = engine->_movements->getDistance2D(ctx.actor->pos(), otherActor->pos());
+				int32 distance = getDistance2D(ctx.actor->pos(), otherActor->pos());
 				if (ABS(distance) > MAX_TARGET_ACTOR_DISTANCE) {
 					engine->_scene->_currentScriptValue = MAX_TARGET_ACTOR_DISTANCE;
 				} else {
@@ -307,7 +307,7 @@ static int32 processLifeConditions(TwinEEngine *engine, LifeScriptContext &ctx)
 
 		if (!targetActor->_dynamicFlags.bIsDead) {
 			// Returns int32, so we check for integer overflow
-			int32 distance = engine->_movements->getDistance3D(ctx.actor->pos(), targetActor->pos());
+			int32 distance = getDistance3D(ctx.actor->pos(), targetActor->pos());
 			if (ABS(distance) > MAX_TARGET_ACTOR_DISTANCE) {
 				engine->_scene->_currentScriptValue = MAX_TARGET_ACTOR_DISTANCE;
 			} else {
diff --git a/engines/twine/shared.cpp b/engines/twine/shared.cpp
new file mode 100644
index 0000000000..fa4cddb4e5
--- /dev/null
+++ b/engines/twine/shared.cpp
@@ -0,0 +1,43 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "twine/shared.h"
+
+namespace TwinE {
+
+int32 getDistance2D(int32 x1, int32 z1, int32 x2, int32 z2) {
+	return (int32)sqrt((float)((x2 - x1) * (x2 - x1) + (z2 - z1) * (z2 - z1)));
+}
+
+int32 getDistance2D(const IVec3 &v1, const IVec3 &v2) {
+	return (int32)sqrt((float)((v2.x - v1.x) * (v2.x - v1.x) + (v2.z - v1.z) * (v2.z - v1.z)));
+}
+
+int32 getDistance3D(int32 x1, int32 y1, int32 z1, int32 x2, int32 y2, int32 z2) {
+	return (int32)sqrt((float)((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) + (z2 - z1) * (z2 - z1)));
+}
+
+int32 getDistance3D(const IVec3 &v1, const IVec3 &v2) {
+	return (int32)sqrt((float)((v2.x - v1.x) * (v2.x - v1.x) + (v2.y - v1.y) * (v2.y - v1.y) + (v2.z - v1.z) * (v2.z - v1.z)));
+}
+
+}
diff --git a/engines/twine/shared.h b/engines/twine/shared.h
index 0f5a70e777..92ba92cc71 100644
--- a/engines/twine/shared.h
+++ b/engines/twine/shared.h
@@ -124,6 +124,28 @@ inline constexpr IVec3 operator-(const IVec3 &v) {
 	return IVec3{-v.x, -v.y, -v.z};
 }
 
+/**
+ * Get distance value in 2D
+ * @param x1 Actor 1 X coordinate
+ * @param z1 Actor 1 Z coordinate
+ * @param x2 Actor 2 X coordinate
+ * @param z2 Actor 2 Z coordinate
+ */
+int32 getDistance2D(int32 x1, int32 z1, int32 x2, int32 z2);
+int32 getDistance2D(const IVec3 &v1, const IVec3 &v2);
+
+/**
+ * Get distance value in 3D
+ * @param x1 Actor 1 X coordinate
+ * @param y1 Actor 1 Y coordinate
+ * @param z1 Actor 1 Z coordinate
+ * @param x2 Actor 2 X coordinate
+ * @param y2 Actor 2 Y coordinate
+ * @param z2 Actor 2 Z coordinate
+ */
+int32 getDistance3D(int32 x1, int32 y1, int32 z1, int32 x2, int32 y2, int32 z2);
+int32 getDistance3D(const IVec3 &v1, const IVec3 &v2);
+
 /**
  * @brief Axis aligned bounding box
  */


Commit: 319beeeceee34ee8e160d8d3de1e93ff7d8d9d34
    https://github.com/scummvm/scummvm/commit/319beeeceee34ee8e160d8d3de1e93ff7d8d9d34
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2021-08-15T12:30:09+02:00

Commit Message:
TWINE: fixed penguin position handling

checked against the disassembly

Changed paths:
    engines/twine/twine.cpp


diff --git a/engines/twine/twine.cpp b/engines/twine/twine.cpp
index 833750a915..f540cf0d82 100644
--- a/engines/twine/twine.cpp
+++ b/engines/twine/twine.cpp
@@ -647,15 +647,13 @@ void TwinEEngine::processInventoryAction() {
 	case kiPinguin: {
 		ActorStruct *pinguin = _scene->getActor(_scene->_mecaPinguinIdx);
 
-		// TODO: is this meant to happen before the rotateActor() call - the _destPos might be
-		// set to some random position. Also the _destPos that is set by the rotateActor call
-		// is not used anywhere in this switch/case - as far as I can see.
-		pinguin->_pos.x = _renderer->_destPos.x + _scene->_sceneHero->_pos.x;
-		pinguin->_pos.y = _scene->_sceneHero->_pos.y;
-		pinguin->_pos.z = _renderer->_destPos.z + _scene->_sceneHero->_pos.z;
-		pinguin->_angle = _scene->_sceneHero->_angle;
+		const IVec3 &destPos = _movements->rotateActor(0, 800, pinguin->_angle);
+
+		pinguin->_pos = _scene->_sceneHero->_pos;
+		pinguin->_pos.x += destPos.x;
+		pinguin->_pos.z += destPos.z;
 
-		_movements->rotateActor(0, 800, pinguin->_angle);
+		pinguin->_angle = _scene->_sceneHero->_angle;
 
 		if (!_collision->checkCollisionWithActors(_scene->_mecaPinguinIdx)) {
 			pinguin->setLife(kActorMaxLife);


Commit: 4e9d709853dbe3fd3a8541e0f1b1590ad7f77acf
    https://github.com/scummvm/scummvm/commit/4e9d709853dbe3fd3a8541e0f1b1590ad7f77acf
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2021-08-15T12:30:09+02:00

Commit Message:
TWINE: fixed typo

Changed paths:
    engines/twine/debugger/console.cpp
    engines/twine/scene/gamestate.cpp
    engines/twine/scene/scene.h
    engines/twine/script/script_life_v1.cpp
    engines/twine/shared.h
    engines/twine/twine.cpp


diff --git a/engines/twine/debugger/console.cpp b/engines/twine/debugger/console.cpp
index 40e3faf0a8..0bf0245b24 100644
--- a/engines/twine/debugger/console.cpp
+++ b/engines/twine/debugger/console.cpp
@@ -380,7 +380,7 @@ static const char *ItemNames[] = {
 	"MrMiesPass",
 	"ProtoPack",
 	"Snowboard",
-	"Pinguin",
+	"Penguin",
 	"GasItem",
 	"PirateFlag",
 	"MagicFlute",
diff --git a/engines/twine/scene/gamestate.cpp b/engines/twine/scene/gamestate.cpp
index d6eb7dc7c4..2b5e2ea169 100644
--- a/engines/twine/scene/gamestate.cpp
+++ b/engines/twine/scene/gamestate.cpp
@@ -118,7 +118,7 @@ void GameState::initEngineVars() {
 	_engine->_scene->_currentSceneIdx = SCENE_CEILING_GRID_FADE_1;
 	_engine->_scene->_needChangeScene = LBA1SceneId::Citadel_Island_Prison;
 	_engine->_quitGame = -1;
-	_engine->_scene->_mecaPinguinIdx = -1;
+	_engine->_scene->_mecaPenguinIdx = -1;
 	_engine->_menuOptions->canShowCredits = false;
 
 	_inventoryNumLeafs = 0;
diff --git a/engines/twine/scene/scene.h b/engines/twine/scene/scene.h
index 42c58c6b77..cd619687dc 100644
--- a/engines/twine/scene/scene.h
+++ b/engines/twine/scene/scene.h
@@ -191,15 +191,15 @@ public:
 	int32 _sceneNumActors = 0;
 	ActorStruct *_sceneHero = nullptr;
 
-	/** Meca pinguin actor index */
-	int16 _mecaPinguinIdx = 0; // currentPingouin
+	/** Meca penguin actor index */
+	int16 _mecaPenguinIdx = 0;
 
 	/** Current followed actor in scene */
 	int16 _currentlyFollowedActor = OWN_ACTOR_SCENE_INDEX;
 	/** Current actor in zone - climbing a ladder */
 	bool _currentActorInZone = false;
 	/** Current actor manipulated in scripts */
-	int16 _currentScriptValue = 0; // manipActorResult
+	int16 _currentScriptValue = 0;
 
 	int16 _talkingActor = 0;
 
@@ -209,7 +209,7 @@ public:
 
 	bool _enableGridTileRendering = true;
 
-	uint8 _sceneFlags[NUM_SCENES_FLAGS]{0}; // cubeFlags
+	uint8 _sceneFlags[NUM_SCENES_FLAGS]{0};
 
 	int32 _sceneNumZones = 0;
 	ZoneStruct _sceneZones[NUM_MAX_ZONES];
diff --git a/engines/twine/script/script_life_v1.cpp b/engines/twine/script/script_life_v1.cpp
index f7259a5f8d..dff2d25178 100644
--- a/engines/twine/script/script_life_v1.cpp
+++ b/engines/twine/script/script_life_v1.cpp
@@ -1296,12 +1296,12 @@ static int32 lBIG_MESSAGE(TwinEEngine *engine, LifeScriptContext &ctx) {
  * @note Opcode @c 0x47
  */
 static int32 lINIT_PINGOUIN(TwinEEngine *engine, LifeScriptContext &ctx) {
-	int32 pingouinActor = ctx.stream.readByte();
-	engine->_scene->_mecaPinguinIdx = pingouinActor;
-	ActorStruct *mecaPinguin = engine->_scene->getActor(pingouinActor);
-	mecaPinguin->_dynamicFlags.bIsDead = 1;
-	mecaPinguin->_entity = -1;
-	mecaPinguin->_zone = -1;
+	const int32 penguinActor = ctx.stream.readByte();
+	engine->_scene->_mecaPenguinIdx = penguinActor;
+	ActorStruct *penguin = engine->_scene->getActor(penguinActor);
+	penguin->_dynamicFlags.bIsDead = 1;
+	penguin->_entity = -1;
+	penguin->_zone = -1;
 	return 0;
 }
 
diff --git a/engines/twine/shared.h b/engines/twine/shared.h
index 92ba92cc71..dd36b584b5 100644
--- a/engines/twine/shared.h
+++ b/engines/twine/shared.h
@@ -528,7 +528,7 @@ enum InventoryItems {
 	kMrMiesPass = 11,
 	kiProtoPack = 12,
 	kSnowboard = 13,
-	kiPinguin = 14,
+	kiPenguin = 14,
 	kGasItem = 15,
 	kPirateFlag = 16,
 	kMagicFlute = 17,
diff --git a/engines/twine/twine.cpp b/engines/twine/twine.cpp
index f540cf0d82..2843265212 100644
--- a/engines/twine/twine.cpp
+++ b/engines/twine/twine.cpp
@@ -644,26 +644,26 @@ void TwinEEngine::processInventoryAction() {
 			_actor->setBehaviour(HeroBehaviourType::kProtoPack);
 		}
 		break;
-	case kiPinguin: {
-		ActorStruct *pinguin = _scene->getActor(_scene->_mecaPinguinIdx);
-
-		const IVec3 &destPos = _movements->rotateActor(0, 800, pinguin->_angle);
-
-		pinguin->_pos = _scene->_sceneHero->_pos;
-		pinguin->_pos.x += destPos.x;
-		pinguin->_pos.z += destPos.z;
-
-		pinguin->_angle = _scene->_sceneHero->_angle;
-
-		if (!_collision->checkCollisionWithActors(_scene->_mecaPinguinIdx)) {
-			pinguin->setLife(kActorMaxLife);
-			pinguin->_body = BodyType::btNone;
-			_actor->initModelActor(BodyType::btNormal, _scene->_mecaPinguinIdx);
-			pinguin->_dynamicFlags.bIsDead = 0;
-			pinguin->setBrickShape(ShapeType::kNone);
-			_movements->moveActor(pinguin->_angle, pinguin->_angle, pinguin->_speed, &pinguin->_move);
-			_gameState->removeItem(InventoryItems::kiPinguin);
-			pinguin->_delayInMillis = _lbaTime + 1500;
+	case kiPenguin: {
+		ActorStruct *penguin = _scene->getActor(_scene->_mecaPenguinIdx);
+
+		const IVec3 &destPos = _movements->rotateActor(0, 800, penguin->_angle);
+
+		penguin->_pos = _scene->_sceneHero->_pos;
+		penguin->_pos.x += destPos.x;
+		penguin->_pos.z += destPos.z;
+
+		penguin->_angle = _scene->_sceneHero->_angle;
+
+		if (!_collision->checkCollisionWithActors(_scene->_mecaPenguinIdx)) {
+			penguin->setLife(kActorMaxLife);
+			penguin->_body = BodyType::btNone;
+			_actor->initModelActor(BodyType::btNormal, _scene->_mecaPenguinIdx);
+			penguin->_dynamicFlags.bIsDead = 0;
+			penguin->setBrickShape(ShapeType::kNone);
+			_movements->moveActor(penguin->_angle, penguin->_angle, penguin->_speed, &penguin->_move);
+			_gameState->removeItem(InventoryItems::kiPenguin);
+			penguin->_delayInMillis = _lbaTime + 1500;
 		}
 		break;
 	}
@@ -869,7 +869,7 @@ int32 TwinEEngine::runGameEngine() { // mainLoopInteration
 			} else {
 				_sound->playSample(Samples::Explode, 1, actor->pos(), a);
 
-				if (a == _scene->_mecaPinguinIdx) {
+				if (a == _scene->_mecaPenguinIdx) {
 					_extra->addExtraExplode(actor->pos());
 				}
 			}


Commit: 518bfac418cbe3a91c831f8b65c074387f4afcbc
    https://github.com/scummvm/scummvm/commit/518bfac418cbe3a91c831f8b65c074387f4afcbc
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2021-08-15T12:30:09+02:00

Commit Message:
TWINE: fixed holomap script function

Changed paths:
    engines/twine/script/script_life_v1.cpp


diff --git a/engines/twine/script/script_life_v1.cpp b/engines/twine/script/script_life_v1.cpp
index dff2d25178..381ec84828 100644
--- a/engines/twine/script/script_life_v1.cpp
+++ b/engines/twine/script/script_life_v1.cpp
@@ -1310,7 +1310,7 @@ static int32 lINIT_PINGOUIN(TwinEEngine *engine, LifeScriptContext &ctx) {
  * @note Opcode @c 0x48
  */
 static int32 lSET_HOLO_POS(TwinEEngine *engine, LifeScriptContext &ctx) {
-	static int32 location = ctx.stream.readByte();
+	const int32 location = ctx.stream.readByte();
 	engine->_holomap->setHolomapPosition(location);
 	return 0;
 }
@@ -1320,7 +1320,7 @@ static int32 lSET_HOLO_POS(TwinEEngine *engine, LifeScriptContext &ctx) {
  * @note Opcode @c 0x49
  */
 static int32 lCLR_HOLO_POS(TwinEEngine *engine, LifeScriptContext &ctx) {
-	static int32 location = ctx.stream.readByte();
+	const int32 location = ctx.stream.readByte();
 	engine->_holomap->clearHolomapPosition(location);
 	return 0;
 }


Commit: 632bb99460edab3e5a69f6dda5e306c67c5d5215
    https://github.com/scummvm/scummvm/commit/632bb99460edab3e5a69f6dda5e306c67c5d5215
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2021-08-15T12:30:09+02:00

Commit Message:
TWINE: const

Changed paths:
    engines/twine/script/script_life_v1.cpp


diff --git a/engines/twine/script/script_life_v1.cpp b/engines/twine/script/script_life_v1.cpp
index 381ec84828..f84514ad2a 100644
--- a/engines/twine/script/script_life_v1.cpp
+++ b/engines/twine/script/script_life_v1.cpp
@@ -1215,7 +1215,7 @@ static int32 lPLAY_FLA(TwinEEngine *engine, LifeScriptContext &ctx) {
  * @note Opcode @c 0x41
  */
 static int32 lPLAY_MIDI(TwinEEngine *engine, LifeScriptContext &ctx) {
-	int32 midiIdx = ctx.stream.readByte();
+	const int32 midiIdx = ctx.stream.readByte();
 	engine->_music->playMidiMusic(midiIdx); // TODO: improve this
 	return 0;
 }
@@ -1234,7 +1234,7 @@ static int32 lINC_CLOVER_BOX(TwinEEngine *engine, LifeScriptContext &ctx) {
  * @note Opcode @c 0x43
  */
 static int32 lSET_USED_INVENTORY(TwinEEngine *engine, LifeScriptContext &ctx) {
-	int32 item = ctx.stream.readByte();
+	const int32 item = ctx.stream.readByte();
 	if (item < InventoryItems::kKeypad) { // TODO: this looks wrong - why only up to keypad?
 		engine->_gameState->_inventoryFlags[item] = 1;
 	}
@@ -1246,7 +1246,7 @@ static int32 lSET_USED_INVENTORY(TwinEEngine *engine, LifeScriptContext &ctx) {
  * @note Opcode @c 0x44
  */
 static int32 lADD_CHOICE(TwinEEngine *engine, LifeScriptContext &ctx) {
-	TextId choiceIdx = (TextId)ctx.stream.readSint16LE();
+	const TextId choiceIdx = (TextId)ctx.stream.readSint16LE();
 	engine->_gameState->_gameChoices[engine->_gameState->_numChoices++] = choiceIdx;
 	return 0;
 }
@@ -1256,7 +1256,7 @@ static int32 lADD_CHOICE(TwinEEngine *engine, LifeScriptContext &ctx) {
  * @note Opcode @c 0x45
  */
 static int32 lASK_CHOICE(TwinEEngine *engine, LifeScriptContext &ctx) {
-	TextId choiceIdx = (TextId)ctx.stream.readSint16LE();
+	const TextId choiceIdx = (TextId)ctx.stream.readSint16LE();
 
 	ScopedEngineFreeze scopedFreeze(engine);
 	if (engine->_text->_showDialogueBubble) {
@@ -1275,7 +1275,7 @@ static int32 lASK_CHOICE(TwinEEngine *engine, LifeScriptContext &ctx) {
  * @note Opcode @c 0x46
  */
 static int32 lBIG_MESSAGE(TwinEEngine *engine, LifeScriptContext &ctx) {
-	TextId textIdx = (TextId)ctx.stream.readSint16LE();
+	const TextId textIdx = (TextId)ctx.stream.readSint16LE();
 
 	ScopedEngineFreeze scopedFreeze(engine);
 	engine->_text->textClipFull();


Commit: b4813d1b651e06e25567aaff34f6035572fbb017
    https://github.com/scummvm/scummvm/commit/b4813d1b651e06e25567aaff34f6035572fbb017
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2021-08-15T12:30:09+02:00

Commit Message:
TWINE: prepare to remove the _destPos member

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


diff --git a/engines/twine/renderer/renderer.cpp b/engines/twine/renderer/renderer.cpp
index 46b5d19ed3..74fe275ef4 100644
--- a/engines/twine/renderer/renderer.cpp
+++ b/engines/twine/renderer/renderer.cpp
@@ -65,7 +65,7 @@ void Renderer::init(int32 w, int32 h) {
 	_holomap_polytab_1_3_ptr = _holomap_polytab_1_3;
 }
 
-const IVec3 &Renderer::projectXYPositionOnScreen(int32 x, int32 y, int32 z) {
+IVec3 Renderer::projectXYPositionOnScreen(int32 x, int32 y, int32 z) {
 	if (_isUsingOrthoProjection) {
 		_projPos.x = ((x - z) * 24) / BRICK_SIZE + _orthoProjPos.x;
 		_projPos.y = y;
@@ -148,7 +148,7 @@ void Renderer::baseMatrixTranspose() {
 	SWAP(_baseMatrix.row2.z, _baseMatrix.row3.y);
 }
 
-const IVec3 &Renderer::setBaseRotation(int32 x, int32 y, int32 z, bool transpose) {
+IVec3 Renderer::setBaseRotation(int32 x, int32 y, int32 z, bool transpose) {
 	const double Xradians = (double)((ANGLE_90 - x) % ANGLE_360) * 2 * M_PI / ANGLE_360;
 	const double Yradians = (double)((ANGLE_90 - y) % ANGLE_360) * 2 * M_PI / ANGLE_360;
 	const double Zradians = (double)((ANGLE_90 - z) % ANGLE_360) * 2 * M_PI / ANGLE_360;
@@ -179,25 +179,24 @@ const IVec3 &Renderer::setBaseRotation(int32 x, int32 y, int32 z, bool transpose
 	return _baseRotPos;
 }
 
-const IVec3 &Renderer::getBaseRotationPosition(int32 x, int32 y, int32 z) {
-	_destPos.x = (_baseMatrix.row1.x * x + _baseMatrix.row1.y * y + _baseMatrix.row1.z * z) / SCENE_SIZE_HALF;
-	_destPos.y = (_baseMatrix.row2.x * x + _baseMatrix.row2.y * y + _baseMatrix.row2.z * z) / SCENE_SIZE_HALF;
-	_destPos.z = (_baseMatrix.row3.x * x + _baseMatrix.row3.y * y + _baseMatrix.row3.z * z) / SCENE_SIZE_HALF;
-	return _destPos;
+IVec3 Renderer::getBaseRotationPosition(int32 x, int32 y, int32 z) {
+	const int32 vx = (_baseMatrix.row1.x * x + _baseMatrix.row1.y * y + _baseMatrix.row1.z * z) / SCENE_SIZE_HALF;
+	const int32 vy = (_baseMatrix.row2.x * x + _baseMatrix.row2.y * y + _baseMatrix.row2.z * z) / SCENE_SIZE_HALF;
+	const int32 vz = (_baseMatrix.row3.x * x + _baseMatrix.row3.y * y + _baseMatrix.row3.z * z) / SCENE_SIZE_HALF;
+	return IVec3(vx, vy, vz);
 }
 
-const IVec3 &Renderer::getCameraAnglePositions(int32 x, int32 y, int32 z) {
-	_destPos.x = (_baseMatrix.row1.x * x + _baseMatrix.row2.x * y + _baseMatrix.row3.x * z) / SCENE_SIZE_HALF;
-	_destPos.y = (_baseMatrix.row1.y * x + _baseMatrix.row2.y * y + _baseMatrix.row3.y * z) / SCENE_SIZE_HALF;
-	_destPos.z = (_baseMatrix.row1.z * x + _baseMatrix.row2.z * y + _baseMatrix.row3.z * z) / SCENE_SIZE_HALF;
-	return _destPos;
+IVec3 Renderer::getCameraAnglePositions(int32 x, int32 y, int32 z) {
+	const int32 vx = (_baseMatrix.row1.x * x + _baseMatrix.row2.x * y + _baseMatrix.row3.x * z) / SCENE_SIZE_HALF;
+	const int32 vy = (_baseMatrix.row1.y * x + _baseMatrix.row2.y * y + _baseMatrix.row3.y * z) / SCENE_SIZE_HALF;
+	const int32 vz = (_baseMatrix.row1.z * x + _baseMatrix.row2.z * y + _baseMatrix.row3.z * z) / SCENE_SIZE_HALF;
+	return IVec3(vx, vy, vz);
 }
 
-const IVec3 &Renderer::translateGroup(int32 x, int32 y, int32 z) {
-	_destPos.x = (_shadeMatrix.row1.x * x + _shadeMatrix.row1.y * y + _shadeMatrix.row1.z * z) / SCENE_SIZE_HALF;
-	_destPos.y = (_shadeMatrix.row2.x * x + _shadeMatrix.row2.y * y + _shadeMatrix.row2.z * z) / SCENE_SIZE_HALF;
-	_destPos.z = _destPos.y;
-	return _destPos;
+IVec3 Renderer::translateGroup(int32 x, int32 y, int32 z) {
+	const int32 vx = (_shadeMatrix.row1.x * x + _shadeMatrix.row1.y * y + _shadeMatrix.row1.z * z) / SCENE_SIZE_HALF;
+	const int32 vy = (_shadeMatrix.row2.x * x + _shadeMatrix.row2.y * y + _shadeMatrix.row2.z * z) / SCENE_SIZE_HALF;
+	return IVec3(vx, vy, vy);
 }
 
 void Renderer::setCameraAngle(int32 transPosX, int32 transPosY, int32 transPosZ, int32 rotPosX, int32 rotPosY, int32 rotPosZ, int32 param6) {
@@ -212,7 +211,7 @@ void Renderer::setCameraAngle(int32 transPosX, int32 transPosY, int32 transPosZ,
 	_baseTransPos = updateCameraAnglePositions();
 }
 
-const IVec3 &Renderer::updateCameraAnglePositions(int zShift) {
+IVec3 Renderer::updateCameraAnglePositions(int zShift) {
 	return getCameraAnglePositions(_baseRotPos.x, _baseRotPos.y, _baseRotPos.z + zShift);
 }
 
diff --git a/engines/twine/renderer/renderer.h b/engines/twine/renderer/renderer.h
index d12b37964e..6a806c9886 100644
--- a/engines/twine/renderer/renderer.h
+++ b/engines/twine/renderer/renderer.h
@@ -138,8 +138,8 @@ private:
 	bool renderAnimatedModel(ModelData *modelData, const BodyData &bodyData, RenderCommand *renderCmds, const IVec3 &angleVec, const IVec3 &renderPos, Common::Rect &modelRect);
 	void circleFill(int32 x, int32 y, int32 radius, uint8 color);
 	bool renderModelElements(int32 numOfPrimitives, const BodyData &bodyData, RenderCommand **renderCmds, ModelData *modelData, Common::Rect &modelRect);
-	const IVec3 &getCameraAnglePositions(int32 x, int32 y, int32 z);
-	inline const IVec3 &getCameraAnglePositions(const IVec3 &vec) {
+	IVec3 getCameraAnglePositions(int32 x, int32 y, int32 z);
+	inline IVec3 getCameraAnglePositions(const IVec3 &vec) {
 		return getCameraAnglePositions(vec.x, vec.y, vec.z);
 	}
 	void applyRotation(IMatrix3x3 *targetMatrix, const IMatrix3x3 *currentMatrix, const IVec3 &angleVec);
@@ -147,7 +147,7 @@ private:
 	void processRotatedElement(IMatrix3x3 *targetMatrix, const Common::Array<BodyVertex>& vertices, int32 rotX, int32 rotY, int32 rotZ, const BodyBone &bone, ModelData *modelData);
 	void applyPointsTranslation(const Common::Array<BodyVertex>& vertices, int32 firstPoint, int32 numPoints, I16Vec3 *destPoints, const IMatrix3x3 *translationMatrix, const IVec3 &angleVec, const IVec3 &destPos);
 	void processTranslatedElement(IMatrix3x3 *targetMatrix, const Common::Array<BodyVertex>& vertices, int32 rotX, int32 rotY, int32 rotZ, const BodyBone &bone, ModelData *modelData);
-	const IVec3 &translateGroup(int32 x, int32 y, int32 z);
+	IVec3 translateGroup(int32 x, int32 y, int32 z);
 
 	IVec3 _baseTransPos;
 	IVec3 _orthoProjPos;
@@ -219,9 +219,9 @@ public:
 	IVec3 getHolomapRotation(const int32 angleX, const int32 angleY, const int32 angleZ) const;
 
 	void setLightVector(int32 angleX, int32 angleY, int32 angleZ);
-	const IVec3 &getBaseRotationPosition(int32 x, int32 y, int32 z);
+	IVec3 getBaseRotationPosition(int32 x, int32 y, int32 z);
 
-	inline const IVec3 &getBaseRotationPosition(const IVec3& vec) {
+	inline IVec3 getBaseRotationPosition(const IVec3& vec) {
 		return getBaseRotationPosition(vec.x, vec.y, vec.z);
 	}
 
@@ -233,17 +233,17 @@ public:
 
 	IVec3 &projectPositionOnScreen(int32 cX, int32 cY, int32 cZ);
 
-	inline const IVec3 &projectXYPositionOnScreen(const IVec3& pos) {
+	inline IVec3 projectXYPositionOnScreen(const IVec3& pos) {
 		return projectXYPositionOnScreen(pos.x, pos.y, pos.z);
 	}
-	const IVec3 &projectXYPositionOnScreen(int32 x,int32 y,int32 z);
+	IVec3 projectXYPositionOnScreen(int32 x,int32 y,int32 z);
 	void setCameraPosition(int32 x, int32 y, int32 depthOffset, int32 scaleY, int32 scaleZ);
 	void setCameraAngle(int32 transPosX, int32 transPosY, int32 transPosZ, int32 rotPosX, int32 rotPosY, int32 rotPosZ, int32 param6);
-	const IVec3 &updateCameraAnglePositions(int zShift = 0);
+	IVec3 updateCameraAnglePositions(int zShift = 0);
 	void setBaseTranslation(int32 x, int32 y, int32 z);
-	const IVec3 &setBaseRotation(int32 x, int32 y, int32 z, bool transpose = false);
+	IVec3 setBaseRotation(int32 x, int32 y, int32 z, bool transpose = false);
 
-	inline const IVec3 &setBaseRotation(const IVec3 &rot, bool transpose = false) {
+	inline IVec3 setBaseRotation(const IVec3 &rot, bool transpose = false) {
 		return setBaseRotation(rot.x, rot.y, rot.z, transpose);
 	}
 


Commit: e39b3818196a84bc1ceee4a90a7497b5db9f9ecb
    https://github.com/scummvm/scummvm/commit/e39b3818196a84bc1ceee4a90a7497b5db9f9ecb
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2021-08-15T12:30:09+02:00

Commit Message:
TWINE: removed _destPos member from Renderer class

Changed paths:
    engines/twine/renderer/renderer.h
    engines/twine/scene/movements.cpp
    engines/twine/scene/movements.h
    engines/twine/script/script_life_v1.cpp
    engines/twine/script/script_move_v1.cpp


diff --git a/engines/twine/renderer/renderer.h b/engines/twine/renderer/renderer.h
index 6a806c9886..2bc00f7415 100644
--- a/engines/twine/renderer/renderer.h
+++ b/engines/twine/renderer/renderer.h
@@ -213,7 +213,6 @@ public:
 	void init(int32 w, int32 h);
 
 	IVec3 _projPos;
-	IVec3 _destPos;
 
 	void setBaseRotationPos(int32 x, int32 y, int32 z);
 	IVec3 getHolomapRotation(const int32 angleX, const int32 angleY, const int32 angleZ) const;
diff --git a/engines/twine/scene/movements.cpp b/engines/twine/scene/movements.cpp
index 578b3ce1fc..1f8739621c 100644
--- a/engines/twine/scene/movements.cpp
+++ b/engines/twine/scene/movements.cpp
@@ -141,11 +141,11 @@ int32 Movements::getAngleAndSetTargetActorDistance(int32 x1, int32 z1, int32 x2,
 	return ClampAngle(finalAngle);
 }
 
-const IVec3 &Movements::rotateActor(int32 x, int32 z, int32 angle) {
+IVec3 Movements::rotateActor(int32 x, int32 z, int32 angle) {
 	const double radians = AngleToRadians(angle);
-	_engine->_renderer->_destPos.x = (int32)(x * cos(radians) + z * sin(radians));
-	_engine->_renderer->_destPos.z = (int32)(-x * sin(radians) + z * cos(radians));
-	return _engine->_renderer->_destPos;
+	const int32 vx = (int32)(x * cos(radians) + z * sin(radians));
+	const int32 vz = (int32)(-x * sin(radians) + z * cos(radians));
+	return IVec3(vx, 0, vz);
 }
 
 void Movements::moveActor(int32 angleFrom, int32 angleTo, int32 speed, ActorMoveStruct *movePtr) const { // ManualRealAngle
diff --git a/engines/twine/scene/movements.h b/engines/twine/scene/movements.h
index 4cfe008aa8..0a664361a9 100644
--- a/engines/twine/scene/movements.h
+++ b/engines/twine/scene/movements.h
@@ -183,7 +183,7 @@ public:
 	 * @param z Actor current Z coordinate
 	 * @param angle Actor angle to rotate
 	 */
-	const IVec3 &rotateActor(int32 x, int32 z, int32 angle);
+	IVec3 rotateActor(int32 x, int32 z, int32 angle);
 
 	/**
 	 * Move actor around the scene
diff --git a/engines/twine/script/script_life_v1.cpp b/engines/twine/script/script_life_v1.cpp
index f84514ad2a..4be5156425 100644
--- a/engines/twine/script/script_life_v1.cpp
+++ b/engines/twine/script/script_life_v1.cpp
@@ -1114,14 +1114,8 @@ static int32 lZOOM(TwinEEngine *engine, LifeScriptContext &ctx) {
  * @note Opcode @c 0x3A
  */
 static int32 lPOS_POINT(TwinEEngine *engine, LifeScriptContext &ctx) {
-	int32 trackIdx = ctx.stream.readByte();
-
-	const IVec3 &sp = engine->_scene->_sceneTracks[trackIdx];
-	// TODO: is this needed? Most likely not as the scene track positions are passed as parameters
-	// everywhere and the _destPos var is not used in this function.
-	engine->_renderer->_destPos = sp;
-	ctx.actor->_pos = sp;
-
+	const int32 trackIdx = ctx.stream.readByte();
+	ctx.actor->_pos = engine->_scene->_sceneTracks[trackIdx];
 	return 0;
 }
 
diff --git a/engines/twine/script/script_move_v1.cpp b/engines/twine/script/script_move_v1.cpp
index 58198e436a..c3e540f09c 100644
--- a/engines/twine/script/script_move_v1.cpp
+++ b/engines/twine/script/script_move_v1.cpp
@@ -117,10 +117,6 @@ static int32 mGOTO_POINT(TwinEEngine *engine, MoveScriptContext &ctx) {
 	engine->_scene->_currentScriptValue = ctx.stream.readByte();
 
 	const IVec3 &sp = engine->_scene->_sceneTracks[engine->_scene->_currentScriptValue];
-	// TODO: is this needed? Most likely not as the scene track positions are passed as parameters
-	// everywhere and the _destPos var is not used in this function.
-	engine->_renderer->_destPos = sp;
-
 	const int32 newAngle = engine->_movements->getAngleAndSetTargetActorDistance(ctx.actor->_pos.x, ctx.actor->_pos.z, sp.x, sp.z);
 
 	if (ctx.actor->_staticFlags.bIsSpriteActor) {
@@ -189,10 +185,6 @@ static int32 mPOS_POINT(TwinEEngine *engine, MoveScriptContext &ctx) {
 	engine->_scene->_currentScriptValue = ctx.stream.readByte();
 
 	const IVec3 &sp = engine->_scene->_sceneTracks[engine->_scene->_currentScriptValue];
-	// TODO: is this needed? Most likely not as the scene track positions are passed as parameters
-	// everywhere and the _destPos var is not used in this function.
-	engine->_renderer->_destPos = sp;
-
 	if (ctx.actor->_staticFlags.bIsSpriteActor) {
 		ctx.actor->_speed = 0;
 	}
@@ -247,10 +239,6 @@ static int32 mGOTO_SYM_POINT(TwinEEngine *engine, MoveScriptContext &ctx) {
 	engine->_scene->_currentScriptValue = ctx.stream.readByte();
 
 	const IVec3 &sp = engine->_scene->_sceneTracks[engine->_scene->_currentScriptValue];
-	// TODO: is this needed? Most likely not as the scene track positions are passed as parameters
-	// everywhere and the _destPos var is not used in this function.
-	engine->_renderer->_destPos = sp;
-
 	const int32 newAngle = ANGLE_180 + engine->_movements->getAngleAndSetTargetActorDistance(ctx.actor->_pos.x, ctx.actor->_pos.z, sp.x, sp.z);
 
 	if (ctx.actor->_staticFlags.bIsSpriteActor) {
@@ -320,10 +308,6 @@ static int32 mGOTO_POINT_3D(TwinEEngine *engine, MoveScriptContext &ctx) {
 	engine->_scene->_currentScriptValue = trackId;
 
 	const IVec3 &sp = engine->_scene->_sceneTracks[engine->_scene->_currentScriptValue];
-	// TODO: is this needed? Most likely not as the scene track positions are passed as parameters
-	// everywhere and the _destPos var is not used in this function.
-	engine->_renderer->_destPos = sp;
-
 	ctx.actor->_angle = engine->_movements->getAngleAndSetTargetActorDistance(ctx.actor->_pos.x, ctx.actor->_pos.z, sp.x, sp.z);
 	ctx.actor->_spriteActorRotation = engine->_movements->getAngleAndSetTargetActorDistance(ctx.actor->_pos.y, 0, sp.y, engine->_movements->_targetActorDistance);
 


Commit: 5456346d7860411507cb24a341c77cd69f03e4ab
    https://github.com/scummvm/scummvm/commit/5456346d7860411507cb24a341c77cd69f03e4ab
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2021-08-15T12:30:09+02:00

Commit Message:
TWINE: new debug command to place the actor at the center of the camera

Changed paths:
    engines/twine/debugger/debug.cpp
    engines/twine/input.cpp
    engines/twine/input.h
    engines/twine/metaengine.cpp


diff --git a/engines/twine/debugger/debug.cpp b/engines/twine/debugger/debug.cpp
index 9fae6d761b..a4c0a06fa2 100644
--- a/engines/twine/debugger/debug.cpp
+++ b/engines/twine/debugger/debug.cpp
@@ -30,6 +30,7 @@
 #include "twine/renderer/redraw.h"
 #include "twine/renderer/screens.h"
 #include "twine/scene/scene.h"
+#include "twine/scene/grid.h"
 #include "twine/text.h"
 #include "twine/twine.h"
 
@@ -458,6 +459,14 @@ void Debug::processDebug() {
 	if (!_engine->_cfgfile.Debug) {
 		return;
 	}
+
+	Input *input = _engine->_input;
+	if (input->isActionActive(TwinEActionType::DebugPlaceActorAtCenterOfScreen)) {
+		ActorStruct *actor = _engine->_scene->getActor(OWN_ACTOR_SCENE_INDEX);
+		actor->_pos = _engine->_grid->_camera;
+		actor->_pos.y += 1000;
+	}
+
 	debugProcessWindow();
 
 	_engine->_debugGrid->changeGrid();
diff --git a/engines/twine/input.cpp b/engines/twine/input.cpp
index 86f97000ef..021e05a0dd 100644
--- a/engines/twine/input.cpp
+++ b/engines/twine/input.cpp
@@ -123,6 +123,7 @@ void Input::processCustomEngineEventStart(const Common::Event &event) {
 		case TwinEActionType::DebugGridCameraPressDown:
 		case TwinEActionType::DebugGridCameraPressLeft:
 		case TwinEActionType::DebugGridCameraPressRight:
+		case TwinEActionType::DebugPlaceActorAtCenterOfScreen:
 		case TwinEActionType::DebugMenu:
 		case TwinEActionType::DebugMenuActivate:
 		case TwinEActionType::NextRoom:
diff --git a/engines/twine/input.h b/engines/twine/input.h
index da33d606ee..25adfe8383 100644
--- a/engines/twine/input.h
+++ b/engines/twine/input.h
@@ -49,6 +49,7 @@ enum TwinEActionType {
 	DebugGridCameraPressDown,
 	DebugGridCameraPressLeft,
 	DebugGridCameraPressRight,
+	DebugPlaceActorAtCenterOfScreen,
 	DebugMenu,
 	DebugMenuActivate,
 	QuickBehaviourNormal,
diff --git a/engines/twine/metaengine.cpp b/engines/twine/metaengine.cpp
index f66de6c135..b87df8359a 100644
--- a/engines/twine/metaengine.cpp
+++ b/engines/twine/metaengine.cpp
@@ -141,6 +141,11 @@ Common::KeymapArray TwinEMetaEngine::initKeymaps(const char *target) const {
 		act->addDefaultInputMapping("c");
 		gameKeyMap->addAction(act);
 
+		act = new Action("DEBUGPLACEACTORATCENTEROFSCREEN", _("Place actor at center of screen"));
+		act->setCustomEngineActionEvent(TwinEActionType::DebugPlaceActorAtCenterOfScreen);
+		act->addDefaultInputMapping("v");
+		gameKeyMap->addAction(act);
+
 		act = new Action("DEBUGMENU", _("Debug Menu"));
 		act->setCustomEngineActionEvent(TwinEActionType::DebugMenu);
 		act->addDefaultInputMapping("MOUSE_RIGHT");


Commit: a1c1a74833806e8358edf9ae58dfccff6e85e1e5
    https://github.com/scummvm/scummvm/commit/a1c1a74833806e8358edf9ae58dfccff6e85e1e5
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2021-08-15T12:30:09+02:00

Commit Message:
TWINE: fixed rendering artifacts for OverlayType::koInventoryItem

... in combination with the holomap

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


diff --git a/engines/twine/renderer/redraw.cpp b/engines/twine/renderer/redraw.cpp
index 106c49fe69..1efa33dd29 100644
--- a/engines/twine/renderer/redraw.cpp
+++ b/engines/twine/renderer/redraw.cpp
@@ -600,7 +600,7 @@ void Redraw::renderOverlays() {
 			}
 			case OverlayType::koInventoryItem: {
 				const int32 item = overlay->info0;
-				const Common::Rect rect(10, 10, 69, 69);
+				const Common::Rect rect(10, 10, 79, 79);
 
 				_engine->_interface->drawFilledRect(rect, COLOR_BLACK);
 				_engine->_interface->setClip(rect);




More information about the Scummvm-git-logs mailing list