[Scummvm-git-logs] scummvm master -> 4c069b89d6dbaddc2f190c8672bd26f1b7661963

mgerhardy martin.gerhardy at gmail.com
Thu Dec 3 19:53:56 UTC 2020


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

Summary:
38e27acc9e TWINE: type safety for points array
a7636bbccc TWINE: cleanup in renderAnimatedModel
4f00ad0c03 TWINE: removed unused member
ee481364d2 TWINE: extract to local vars
7092d170fb TWINE: refactored bodyHeaderStruct usage
4c069b89d6 TWINE: (hopefully) fixed manual mode for agressive behaviour doesn't work as expected


Commit: 38e27acc9e0894d4a1000ecfca545f6200553f88
    https://github.com/scummvm/scummvm/commit/38e27acc9e0894d4a1000ecfca545f6200553f88
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-12-03T12:51:44+01:00

Commit Message:
TWINE: type safety for points array

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


diff --git a/engines/twine/renderer.cpp b/engines/twine/renderer.cpp
index df8542a9bc..b0c2dc3b26 100644
--- a/engines/twine/renderer.cpp
+++ b/engines/twine/renderer.cpp
@@ -237,7 +237,7 @@ void Renderer::applyPointsRotation(const pointTab *pointsPtr, int32 numPoints, p
 	} while (--numOfPoints2);
 }
 
-void Renderer::processRotatedElement(Matrix *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 pointTab *pointsPtr, int32 rotZ, int32 rotY, int32 rotX, const elementEntry *elemPtr, ModelData *modelData) {
 	int32 firstPoint = elemPtr->firstPoint;
 	int32 numOfPoints2 = elemPtr->numOfPoints;
 
@@ -275,7 +275,7 @@ void Renderer::processRotatedElement(Matrix *targetMatrix, const uint8 *pointsPt
 		warning("RENDER WARNING: No points in this model!");
 	}
 
-	applyPointsRotation((const pointTab *)(pointsPtr + firstPoint), numOfPoints2, &modelData->computedPoints[firstPoint / sizeof(pointTab)], targetMatrix);
+	applyPointsRotation(&pointsPtr[firstPoint / sizeof(pointTab)], numOfPoints2, &modelData->computedPoints[firstPoint / sizeof(pointTab)], targetMatrix);
 }
 
 void Renderer::applyPointsTranslation(const pointTab *pointsPtr, int32 numPoints, pointTab *destPoints, const Matrix *translationMatrix) {
@@ -295,7 +295,7 @@ void Renderer::applyPointsTranslation(const pointTab *pointsPtr, int32 numPoints
 	} while (--numOfPoints2);
 }
 
-void Renderer::processTranslatedElement(Matrix *targetMatrix, const uint8 *pointsPtr, int32 rotX, int32 rotY, int32 rotZ, const elementEntry *elemPtr, ModelData *modelData) {
+void Renderer::processTranslatedElement(Matrix *targetMatrix, const pointTab *pointsPtr, int32 rotX, int32 rotY, int32 rotZ, const elementEntry *elemPtr, ModelData *modelData) {
 	renderAngleX = rotX;
 	renderAngleY = rotY;
 	renderAngleZ = rotZ;
@@ -318,7 +318,7 @@ void Renderer::processTranslatedElement(Matrix *targetMatrix, const uint8 *point
 		*targetMatrix = matricesTable[matrixIndex];
 	}
 
-	applyPointsTranslation((const pointTab *)(pointsPtr + elemPtr->firstPoint), elemPtr->numOfPoints, &modelData->computedPoints[elemPtr->firstPoint / sizeof(pointTab)], targetMatrix);
+	applyPointsTranslation(&pointsPtr[elemPtr->firstPoint / sizeof(pointTab)], elemPtr->numOfPoints, &modelData->computedPoints[elemPtr->firstPoint / sizeof(pointTab)], targetMatrix);
 }
 
 void Renderer::translateGroup(int16 ax, int16 bx, int16 cx) {
@@ -1259,7 +1259,7 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, RenderCom
 int32 Renderer::renderAnimatedModel(ModelData *modelData, uint8 *bodyPtr, RenderCommand *renderCmds) {
 	int32 numOfPoints = *((const uint16 *)bodyPtr);
 	bodyPtr += 2;
-	const uint8 *pointsPtr = bodyPtr;
+	const pointTab *pointsPtr = (const pointTab *)bodyPtr;
 
 	bodyPtr += numOfPoints * sizeof(pointTab);
 
@@ -1301,8 +1301,8 @@ int32 Renderer::renderAnimatedModel(ModelData *modelData, uint8 *bodyPtr, Render
 	numOfPrimitives = numOfPoints;
 
 	// 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;
+	const pointTab *pointPtr = &modelData->computedPoints[0];
+	pointTab *pointPtrDest = &modelData->flattenPoints[0];
 
 	if (isUsingOrhoProjection) { // use standard projection
 		do {
diff --git a/engines/twine/renderer.h b/engines/twine/renderer.h
index 9f6acbd5c5..9fd7a720c1 100644
--- a/engines/twine/renderer.h
+++ b/engines/twine/renderer.h
@@ -162,9 +162,9 @@ private:
 	void getCameraAnglePositions(int32 x, int32 y, int32 z);
 	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 processRotatedElement(Matrix *targetMatrix, const pointTab *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 processTranslatedElement(Matrix *targetMatrix, const pointTab *pointsPtr, int32 rotX, int32 rotY, int32 rotZ, const elementEntry *elemPtr, ModelData *modelData);
 	void translateGroup(int16 ax, int16 bx, int16 cx);
 
 	// ---- variables ----


Commit: a7636bbccc55403390252f8f88cbafb69998eb22
    https://github.com/scummvm/scummvm/commit/a7636bbccc55403390252f8f88cbafb69998eb22
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-12-03T12:51:45+01:00

Commit Message:
TWINE: cleanup in renderAnimatedModel

Changed paths:
    engines/twine/renderer.cpp


diff --git a/engines/twine/renderer.cpp b/engines/twine/renderer.cpp
index b0c2dc3b26..057678dfeb 100644
--- a/engines/twine/renderer.cpp
+++ b/engines/twine/renderer.cpp
@@ -1257,25 +1257,21 @@ int32 Renderer::renderModelElements(int32 numOfPrimitives, uint8 *ptr, RenderCom
 }
 
 int32 Renderer::renderAnimatedModel(ModelData *modelData, uint8 *bodyPtr, RenderCommand *renderCmds) {
-	int32 numOfPoints = *((const uint16 *)bodyPtr);
+	const int32 numOfPoints = *((const uint16 *)bodyPtr);
 	bodyPtr += 2;
 	const pointTab *pointsPtr = (const pointTab *)bodyPtr;
 
 	bodyPtr += numOfPoints * sizeof(pointTab);
 
-	int32 numOfElements = *((const uint16 *)bodyPtr);
+	const int32 numOfElements = *((const uint16 *)bodyPtr);
 	bodyPtr += 2;
-
-	uint8 *elementsPtr = bodyPtr;
-	const uint8 *elementsPtr2 = elementsPtr;
+	const elementEntry *elemEntryPtr = (const elementEntry *)bodyPtr;
 
 	Matrix *modelMatrix = &matricesTable[0];
 
-	processRotatedElement(modelMatrix, pointsPtr, renderAngleX, renderAngleY, renderAngleZ, (const elementEntry *)elementsPtr, modelData);
-
-	elementsPtr += sizeof(elementEntry);
+	processRotatedElement(modelMatrix, pointsPtr, renderAngleX, renderAngleY, renderAngleZ, elemEntryPtr, modelData);
 
-	const elementEntry *elemEntryPtr = (const elementEntry *)elementsPtr;
+	++elemEntryPtr;
 
 	int32 numOfPrimitives = 0;
 
@@ -1287,14 +1283,13 @@ int32 Renderer::renderAnimatedModel(ModelData *modelData, uint8 *bodyPtr, Render
 			int16 boneType = elemEntryPtr->flag;
 
 			if (boneType == 0) {
-				processRotatedElement(modelMatrix, pointsPtr, elemEntryPtr->rotateX, elemEntryPtr->rotateY, elemEntryPtr->rotateZ, elemEntryPtr, modelData); // rotation
+				processRotatedElement(modelMatrix, pointsPtr, elemEntryPtr->rotateX, elemEntryPtr->rotateY, elemEntryPtr->rotateZ, elemEntryPtr, modelData);
 			} else if (boneType == 1) {
-				processTranslatedElement(modelMatrix, pointsPtr, elemEntryPtr->rotateX, elemEntryPtr->rotateY, elemEntryPtr->rotateZ, elemEntryPtr, modelData); // translation
+				processTranslatedElement(modelMatrix, pointsPtr, elemEntryPtr->rotateX, elemEntryPtr->rotateY, elemEntryPtr->rotateZ, elemEntryPtr, modelData);
 			}
 
 			++modelMatrix;
-			elementsPtr += sizeof(elementEntry);
-			elemEntryPtr = (elementEntry *)elementsPtr;
+			++elemEntryPtr;
 		} while (--numOfPrimitives);
 	}
 
@@ -1393,7 +1388,7 @@ int32 Renderer::renderAnimatedModel(ModelData *modelData, uint8 *bodyPtr, Render
 		} while (--numOfPrimitives);
 	}
 
-	int32 *shadePtr = (int32 *)elementsPtr;
+	int32 *shadePtr = (int32 *)(bodyPtr + numOfElements * sizeof(elementEntry));
 
 	int32 numOfShades = *((const uint16 *)shadePtr);
 
@@ -1402,11 +1397,11 @@ int32 Renderer::renderAnimatedModel(ModelData *modelData, uint8 *bodyPtr, Render
 	if (numOfShades) { // process normal data
 		uint8 *currentShadeDestination = (uint8 *)modelData->shadeTable;
 		Matrix *lightMatrix = &matricesTable[0];
-		const uint8 *pri2Ptr3;
 
 		numOfPrimitives = numOfElements;
 
-		const uint8 *tmpElemPtr = pri2Ptr3 = elementsPtr2 + 18;
+		const uint8 *tmpElemPtr = bodyPtr + 18;
+		const uint8 *pri2Ptr3 = tmpElemPtr;
 
 		do { // for each element
 			numOfShades = *((const uint16 *)tmpElemPtr);


Commit: 4f00ad0c035940a97875993ff7661b942992469b
    https://github.com/scummvm/scummvm/commit/4f00ad0c035940a97875993ff7661b942992469b
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-12-03T12:51:45+01:00

Commit Message:
TWINE: removed unused member

Changed paths:
    engines/twine/grid.cpp
    engines/twine/renderer.cpp
    engines/twine/scene.cpp
    engines/twine/scene.h
    engines/twine/script_life_v1.cpp


diff --git a/engines/twine/grid.cpp b/engines/twine/grid.cpp
index 5b35358aba..6b93bde112 100644
--- a/engines/twine/grid.cpp
+++ b/engines/twine/grid.cpp
@@ -638,7 +638,7 @@ void Grid::redrawGrid() {
 
 	memset(brickInfoBuffer, 0, sizeof(brickInfoBuffer));
 
-	if (_engine->_scene->changeRoomVar10 == 0) {
+	if (!_engine->_scene->changeRoomVar10) {
 		return;
 	}
 
diff --git a/engines/twine/renderer.cpp b/engines/twine/renderer.cpp
index 057678dfeb..f4d968e9ad 100644
--- a/engines/twine/renderer.cpp
+++ b/engines/twine/renderer.cpp
@@ -1295,7 +1295,6 @@ int32 Renderer::renderAnimatedModel(ModelData *modelData, uint8 *bodyPtr, Render
 
 	numOfPrimitives = numOfPoints;
 
-	// TODO: stack var will maybe exceed max stack size on some platforms - 27300 bytes
 	const pointTab *pointPtr = &modelData->computedPoints[0];
 	pointTab *pointPtrDest = &modelData->flattenPoints[0];
 
diff --git a/engines/twine/scene.cpp b/engines/twine/scene.cpp
index 79981db7d3..43d53ac19e 100644
--- a/engines/twine/scene.cpp
+++ b/engines/twine/scene.cpp
@@ -367,8 +367,7 @@ void Scene::changeScene() {
 	_engine->_screens->lockPalette = false;
 
 	needChangeScene = -1;
-	changeRoomVar10 = 1;
-	changeRoomVar11 = 14;
+	changeRoomVar10 = true;
 
 	_engine->_renderer->setLightVector(alphaLight, betaLight, 0);
 
diff --git a/engines/twine/scene.h b/engines/twine/scene.h
index 30b4a9a0f3..e3c237723f 100644
--- a/engines/twine/scene.h
+++ b/engines/twine/scene.h
@@ -346,8 +346,7 @@ public:
 	ScenePoint sceneTracks[NUM_MAX_TRACKS];
 
 	// TODO: check what is this
-	int16 changeRoomVar10 = 0;
-	int16 changeRoomVar11 = 0;
+	bool changeRoomVar10 = false;
 
 	uint8 sceneFlags[NUM_SCENES_FLAGS] {0}; // cubeFlags
 
diff --git a/engines/twine/script_life_v1.cpp b/engines/twine/script_life_v1.cpp
index c665bf20b1..693ebd7774 100644
--- a/engines/twine/script_life_v1.cpp
+++ b/engines/twine/script_life_v1.cpp
@@ -1719,11 +1719,11 @@ static int32 lPROJ_ISO(TwinEEngine *engine, LifeScriptContext &ctx) {
 static int32 lPROJ_3D(TwinEEngine *engine, LifeScriptContext &ctx) {
 	engine->_screens->copyScreen(engine->frontVideoBuffer, engine->workVideoBuffer);
 	engine->flip();
-	engine->_scene->changeRoomVar10 = 0;
+	engine->_scene->changeRoomVar10 = false;
 
 	engine->_renderer->setCameraPosition(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, 128, 1024, 1024);
 	engine->_renderer->setCameraAngle(0, 1500, 0, 25, -128, 0, 13000);
-	engine->_renderer->setLightVector(896, 950, 0);
+	engine->_renderer->setLightVector(896, 950, ANGLE_0);
 
 	engine->_text->initTextBank(TextBankId::Credits);
 


Commit: ee481364d2447c9322e8206ded6b71aa4cd440a4
    https://github.com/scummvm/scummvm/commit/ee481364d2447c9322e8206ded6b71aa4cd440a4
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-12-03T12:51:45+01:00

Commit Message:
TWINE: extract to local vars

Changed paths:
    engines/twine/actor.cpp
    engines/twine/animations.cpp
    engines/twine/scene.cpp


diff --git a/engines/twine/actor.cpp b/engines/twine/actor.cpp
index 601facf7e5..e6e4439dea 100644
--- a/engines/twine/actor.cpp
+++ b/engines/twine/actor.cpp
@@ -56,107 +56,110 @@ Actor::~Actor() {
 }
 
 void Actor::restartHeroScene() {
-	_engine->_scene->sceneHero->controlMode = ControlMode::kManual;
-	memset(&_engine->_scene->sceneHero->dynamicFlags, 0, sizeof(_engine->_scene->sceneHero->dynamicFlags));
-	memset(&_engine->_scene->sceneHero->staticFlags, 0, sizeof(_engine->_scene->sceneHero->staticFlags));
-
-	_engine->_scene->sceneHero->staticFlags.bComputeCollisionWithObj = 1;
-	_engine->_scene->sceneHero->staticFlags.bComputeCollisionWithBricks = 1;
-	_engine->_scene->sceneHero->staticFlags.bIsZonable = 1;
-	_engine->_scene->sceneHero->staticFlags.bCanDrown = 1;
-	_engine->_scene->sceneHero->staticFlags.bCanFall = 1;
-
-	_engine->_scene->sceneHero->armor = 1;
-	_engine->_scene->sceneHero->positionInMoveScript = -1;
-	_engine->_scene->sceneHero->labelIdx = -1;
-	_engine->_scene->sceneHero->positionInLifeScript = 0;
-	_engine->_scene->sceneHero->zone = -1;
-	_engine->_scene->sceneHero->angle = previousHeroAngle;
-
-	_engine->_movements->setActorAngleSafe(_engine->_scene->sceneHero->angle, _engine->_scene->sceneHero->angle, 0, &_engine->_scene->sceneHero->move);
+	ActorStruct *sceneHero = _engine->_scene->sceneHero;
+	sceneHero->controlMode = ControlMode::kManual;
+	memset(&sceneHero->dynamicFlags, 0, sizeof(sceneHero->dynamicFlags));
+	memset(&sceneHero->staticFlags, 0, sizeof(sceneHero->staticFlags));
+
+	sceneHero->staticFlags.bComputeCollisionWithObj = 1;
+	sceneHero->staticFlags.bComputeCollisionWithBricks = 1;
+	sceneHero->staticFlags.bIsZonable = 1;
+	sceneHero->staticFlags.bCanDrown = 1;
+	sceneHero->staticFlags.bCanFall = 1;
+
+	sceneHero->armor = 1;
+	sceneHero->positionInMoveScript = -1;
+	sceneHero->labelIdx = -1;
+	sceneHero->positionInLifeScript = 0;
+	sceneHero->zone = -1;
+	sceneHero->angle = previousHeroAngle;
+
+	_engine->_movements->setActorAngleSafe(sceneHero->angle, sceneHero->angle, 0, &sceneHero->move);
 	setBehaviour(previousHeroBehaviour);
 
 	cropBottomScreen = 0;
 }
 
 void Actor::loadHeroEntities() {
+	ActorStruct *sceneHero = _engine->_scene->sceneHero;
 	heroEntityATHLETICSize = HQR::getAllocEntry(&heroEntityATHLETIC, Resources::HQR_FILE3D_FILE, FILE3DHQR_HEROATHLETIC);
 	if (heroEntityATHLETICSize == 0) {
 		error("Failed to load actor athletic 3d data");
 	}
-	_engine->_scene->sceneHero->entityDataPtr = heroEntityATHLETIC;
+	sceneHero->entityDataPtr = heroEntityATHLETIC;
 	heroAnimIdxATHLETIC = _engine->_animations->getBodyAnimIndex(AnimationTypes::kStanding);
 
 	heroEntityAGGRESSIVESize = HQR::getAllocEntry(&heroEntityAGGRESSIVE, Resources::HQR_FILE3D_FILE, FILE3DHQR_HEROAGGRESSIVE);
 	if (heroEntityAGGRESSIVESize == 0) {
 		error("Failed to load actor aggressive 3d data");
 	}
-	_engine->_scene->sceneHero->entityDataPtr = heroEntityAGGRESSIVE;
+	sceneHero->entityDataPtr = heroEntityAGGRESSIVE;
 	heroAnimIdxAGGRESSIVE = _engine->_animations->getBodyAnimIndex(AnimationTypes::kStanding);
 
 	heroEntityDISCRETESize = HQR::getAllocEntry(&heroEntityDISCRETE, Resources::HQR_FILE3D_FILE, FILE3DHQR_HERODISCRETE);
 	if (heroEntityDISCRETESize == 0) {
 		error("Failed to load actor discrete 3d data");
 	}
-	_engine->_scene->sceneHero->entityDataPtr = heroEntityDISCRETE;
+	sceneHero->entityDataPtr = heroEntityDISCRETE;
 	heroAnimIdxDISCRETE = _engine->_animations->getBodyAnimIndex(AnimationTypes::kStanding);
 
 	heroEntityPROTOPACKSize = HQR::getAllocEntry(&heroEntityPROTOPACK, Resources::HQR_FILE3D_FILE, FILE3DHQR_HEROPROTOPACK);
 	if (heroEntityPROTOPACKSize == 0) {
 		error("Failed to load actor protopack 3d data");
 	}
-	_engine->_scene->sceneHero->entityDataPtr = heroEntityPROTOPACK;
+	sceneHero->entityDataPtr = heroEntityPROTOPACK;
 	heroAnimIdxPROTOPACK = _engine->_animations->getBodyAnimIndex(AnimationTypes::kStanding);
 
 	heroEntityNORMALSize = HQR::getAllocEntry(&heroEntityNORMAL, Resources::HQR_FILE3D_FILE, FILE3DHQR_HERONORMAL);
 	if (heroEntityNORMALSize == 0) {
 		error("Failed to load actor normal 3d data");
 	}
-	_engine->_scene->sceneHero->entityDataPtr = heroEntityNORMAL;
-	_engine->_scene->sceneHero->entityDataSize = heroEntityNORMALSize;
+	sceneHero->entityDataPtr = heroEntityNORMAL;
+	sceneHero->entityDataSize = heroEntityNORMALSize;
 	heroAnimIdxNORMAL = _engine->_animations->getBodyAnimIndex(AnimationTypes::kStanding);
 
-	_engine->_scene->sceneHero->animExtraPtr = _engine->_animations->currentActorAnimExtraPtr;
+	sceneHero->animExtraPtr = _engine->_animations->currentActorAnimExtraPtr;
 }
 
 void Actor::setBehaviour(HeroBehaviourType behaviour) {
+	ActorStruct *sceneHero = _engine->_scene->sceneHero;
 	switch (behaviour) {
 	case HeroBehaviourType::kNormal:
 		heroBehaviour = behaviour;
-		_engine->_scene->sceneHero->entityDataPtr = heroEntityNORMAL;
-		_engine->_scene->sceneHero->entityDataSize = heroEntityNORMALSize;
+		sceneHero->entityDataPtr = heroEntityNORMAL;
+		sceneHero->entityDataSize = heroEntityNORMALSize;
 		break;
 	case HeroBehaviourType::kAthletic:
 		heroBehaviour = behaviour;
-		_engine->_scene->sceneHero->entityDataPtr = heroEntityATHLETIC;
-		_engine->_scene->sceneHero->entityDataSize = heroEntityATHLETICSize;
+		sceneHero->entityDataPtr = heroEntityATHLETIC;
+		sceneHero->entityDataSize = heroEntityATHLETICSize;
 		break;
 	case HeroBehaviourType::kAggressive:
 		heroBehaviour = behaviour;
-		_engine->_scene->sceneHero->entityDataPtr = heroEntityAGGRESSIVE;
-		_engine->_scene->sceneHero->entityDataSize = heroEntityAGGRESSIVESize;
+		sceneHero->entityDataPtr = heroEntityAGGRESSIVE;
+		sceneHero->entityDataSize = heroEntityAGGRESSIVESize;
 		break;
 	case HeroBehaviourType::kDiscrete:
 		heroBehaviour = behaviour;
-		_engine->_scene->sceneHero->entityDataPtr = heroEntityDISCRETE;
-		_engine->_scene->sceneHero->entityDataSize = heroEntityDISCRETESize;
+		sceneHero->entityDataPtr = heroEntityDISCRETE;
+		sceneHero->entityDataSize = heroEntityDISCRETESize;
 		break;
 	case HeroBehaviourType::kProtoPack:
 		heroBehaviour = behaviour;
-		_engine->_scene->sceneHero->entityDataPtr = heroEntityPROTOPACK;
-		_engine->_scene->sceneHero->entityDataSize = heroEntityPROTOPACKSize;
+		sceneHero->entityDataPtr = heroEntityPROTOPACK;
+		sceneHero->entityDataSize = heroEntityPROTOPACKSize;
 		break;
 	};
 
-	const int32 bodyIdx = _engine->_scene->sceneHero->body;
+	const int32 bodyIdx = sceneHero->body;
 
-	_engine->_scene->sceneHero->entity = -1;
-	_engine->_scene->sceneHero->body = -1;
+	sceneHero->entity = -1;
+	sceneHero->body = -1;
 
 	initModelActor(bodyIdx, 0);
 
-	_engine->_scene->sceneHero->anim = AnimationTypes::kAnimNone;
-	_engine->_scene->sceneHero->animType = 0;
+	sceneHero->anim = AnimationTypes::kAnimNone;
+	sceneHero->animType = 0;
 
 	_engine->_animations->initAnim(AnimationTypes::kStanding, 0, AnimationTypes::kAnimInvalid, 0);
 }
@@ -170,12 +173,13 @@ void Actor::initSpriteActor(int32 actorIdx) {
 		stream.skip(4);
 
 		localActor->entity = localActor->sprite;
-		localActor->boudingBox.x.bottomLeft = stream.readSint16LE();
-		localActor->boudingBox.x.topRight = stream.readSint16LE();
-		localActor->boudingBox.y.bottomLeft = stream.readSint16LE();
-		localActor->boudingBox.y.topRight = stream.readSint16LE();
-		localActor->boudingBox.z.bottomLeft = stream.readSint16LE();
-		localActor->boudingBox.z.topRight = stream.readSint16LE();
+		ZVBox &bbox = localActor->boudingBox;
+		bbox.x.bottomLeft = stream.readSint16LE();
+		bbox.x.topRight = stream.readSint16LE();
+		bbox.y.bottomLeft = stream.readSint16LE();
+		bbox.y.topRight = stream.readSint16LE();
+		bbox.z.bottomLeft = stream.readSint16LE();
+		bbox.z.topRight = stream.readSint16LE();
 	}
 }
 
@@ -262,12 +266,13 @@ void Actor::initModelActor(int32 bodyIdx, int16 actorIdx) {
 		localActor->body = -1;
 		localActor->entity = -1;
 
-		localActor->boudingBox.x.bottomLeft = 0;
-		localActor->boudingBox.x.topRight = 0;
-		localActor->boudingBox.y.bottomLeft = 0;
-		localActor->boudingBox.y.topRight = 0;
-		localActor->boudingBox.z.bottomLeft = 0;
-		localActor->boudingBox.z.topRight = 0;
+		ZVBox &bbox = localActor->boudingBox;
+		bbox.x.bottomLeft = 0;
+		bbox.x.topRight = 0;
+		bbox.y.bottomLeft = 0;
+		bbox.y.topRight = 0;
+		bbox.z.bottomLeft = 0;
+		bbox.z.topRight = 0;
 		return;
 	}
 
@@ -280,19 +285,21 @@ void Actor::initModelActor(int32 bodyIdx, int16 actorIdx) {
 	int currentIndex = localActor->entity;
 
 	if (actorBoundingBox.hasBoundingBox) {
-		localActor->boudingBox.x.bottomLeft = actorBoundingBox.bottomLeftX;
-		localActor->boudingBox.x.topRight = actorBoundingBox.topRightX;
-		localActor->boudingBox.y.bottomLeft = actorBoundingBox.bottomLeftY;
-		localActor->boudingBox.y.topRight = actorBoundingBox.topRightY;
-		localActor->boudingBox.z.bottomLeft = actorBoundingBox.bottomLeftZ;
-		localActor->boudingBox.z.topRight = actorBoundingBox.topRightZ;
+		ZVBox &bbox = localActor->boudingBox;
+		bbox.x.bottomLeft = actorBoundingBox.bottomLeftX;
+		bbox.x.topRight = actorBoundingBox.topRightX;
+		bbox.y.bottomLeft = actorBoundingBox.bottomLeftY;
+		bbox.y.topRight = actorBoundingBox.topRightY;
+		bbox.z.bottomLeft = actorBoundingBox.bottomLeftZ;
+		bbox.z.topRight = actorBoundingBox.topRightZ;
 	} else {
+		ZVBox &bbox = localActor->boudingBox;
 		Common::MemoryReadStream stream(bodyTable[localActor->entity], bodyTableSize[localActor->entity]);
 		stream.skip(2);
 		const int16 var1 = stream.readSint16LE();
 		const int16 var2 = stream.readSint16LE();
-		localActor->boudingBox.y.bottomLeft = stream.readSint16LE();
-		localActor->boudingBox.y.topRight = stream.readSint16LE();
+		bbox.y.bottomLeft = stream.readSint16LE();
+		bbox.y.topRight = stream.readSint16LE();
 		const int16 var3 = stream.readSint16LE();
 		const int16 var4 = stream.readSint16LE();
 
@@ -312,10 +319,10 @@ void Actor::initModelActor(int32 bodyIdx, int16 actorIdx) {
 			result >>= 2;
 		}
 
-		localActor->boudingBox.x.bottomLeft = -result;
-		localActor->boudingBox.x.topRight = result;
-		localActor->boudingBox.z.bottomLeft = -result;
-		localActor->boudingBox.z.topRight = result;
+		bbox.x.bottomLeft = -result;
+		bbox.x.topRight = result;
+		bbox.z.bottomLeft = -result;
+		bbox.z.topRight = result;
 	}
 
 	if (currentIndex == -1) {
@@ -377,12 +384,13 @@ void Actor::resetActor(int16 actorIdx) {
 	actor->y = -1;
 	actor->z = 0;
 
-	actor->boudingBox.x.bottomLeft = 0;
-	actor->boudingBox.x.topRight = 0;
-	actor->boudingBox.y.bottomLeft = 0;
-	actor->boudingBox.y.topRight = 0;
-	actor->boudingBox.z.bottomLeft = 0;
-	actor->boudingBox.z.topRight = 0;
+	ZVBox &bbox = actor->boudingBox;
+	bbox.x.bottomLeft = 0;
+	bbox.x.topRight = 0;
+	bbox.y.bottomLeft = 0;
+	bbox.y.topRight = 0;
+	bbox.z.bottomLeft = 0;
+	bbox.z.topRight = 0;
 
 	actor->angle = 0;
 	actor->speed = 40;
@@ -485,12 +493,11 @@ void Actor::processActorExtraBonus(int32 actorIdx) { // GiveExtraBonus
 	}
 	if (actor->dynamicFlags.bIsDead) {
 		_engine->_extra->addExtraBonus(actor->x, actor->y, actor->z, ANGLE_90, 0, bonusSprite, actor->bonusAmount);
-		// FIXME add constant for sample index
 		_engine->_sound->playSample(Samples::ItemPopup, 1, actor->x, actor->y, actor->z, actorIdx);
 	} else {
-		const int32 angle = _engine->_movements->getAngleAndSetTargetActorDistance(actor->x, actor->z, _engine->_scene->sceneHero->x, _engine->_scene->sceneHero->z);
+		ActorStruct *sceneHero = _engine->_scene->sceneHero;
+		const int32 angle = _engine->_movements->getAngleAndSetTargetActorDistance(actor->x, actor->z, sceneHero->x, sceneHero->z);
 		_engine->_extra->addExtraBonus(actor->x, actor->y + actor->boudingBox.y.topRight, actor->z, 200, angle, bonusSprite, actor->bonusAmount);
-		// FIXME add constant for sample index
 		_engine->_sound->playSample(Samples::ItemPopup, 1, actor->x, actor->y + actor->boudingBox.y.topRight, actor->z, actorIdx);
 	}
 }
diff --git a/engines/twine/animations.cpp b/engines/twine/animations.cpp
index da12906e49..b763d78c84 100644
--- a/engines/twine/animations.cpp
+++ b/engines/twine/animations.cpp
@@ -446,9 +446,10 @@ int32 Animations::verifyAnimAtKeyframe(int32 animIdx, uint8 *animPtr, uint8 *bod
 void Animations::processAnimActions(int32 actorIdx) {
 	ActorStruct *actor = _engine->_scene->getActor(actorIdx);
 	if (actor->animExtraPtr == nullptr) {
-		return; // avoid null pointers
+		return;
 	}
 
+	// TODO: fix size
 	Common::MemoryReadStream stream(actor->animExtraPtr, 1000000);
 
 	int32 index = 0;
diff --git a/engines/twine/scene.cpp b/engines/twine/scene.cpp
index 43d53ac19e..99cec049ee 100644
--- a/engines/twine/scene.cpp
+++ b/engines/twine/scene.cpp
@@ -355,9 +355,10 @@ void Scene::changeScene() {
 	heroPositionType = ScenePositionType::kNoPosition;
 	_sampleAmbienceTime = 0;
 
-	_engine->_grid->newCameraX = _sceneActors[currentlyFollowedActor].x >> 9;
-	_engine->_grid->newCameraY = _sceneActors[currentlyFollowedActor].y >> 8;
-	_engine->_grid->newCameraZ = _sceneActors[currentlyFollowedActor].z >> 9;
+	ActorStruct *followedActor = getActor(currentlyFollowedActor);
+	_engine->_grid->newCameraX = followedActor->x >> 9;
+	_engine->_grid->newCameraY = followedActor->y >> 8;
+	_engine->_grid->newCameraZ = followedActor->z >> 9;
 
 	_engine->_gameState->magicBallIdx = -1;
 	_engine->_movements->heroMoved = true;


Commit: 7092d170fb29290a804ab5ceb44d182de30ef826
    https://github.com/scummvm/scummvm/commit/7092d170fb29290a804ab5ceb44d182de30ef826
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-12-03T12:51:45+01:00

Commit Message:
TWINE: refactored bodyHeaderStruct usage

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


diff --git a/engines/twine/animations.cpp b/engines/twine/animations.cpp
index b763d78c84..d3fbd6323f 100644
--- a/engines/twine/animations.cpp
+++ b/engines/twine/animations.cpp
@@ -209,9 +209,8 @@ bool Animations::setModelAnimation(int32 animState, const uint8 *animPtr, uint8
 
 	int32 keyFrameLength = READ_LE_INT16(keyFramePtr);
 
-	int16 bodyHeader = READ_LE_INT16(bodyPtr);
-
-	if (!(bodyHeader & 2)) {
+	const Model *bodyHeader = (Model *)bodyPtr;
+	if (!bodyHeader->bodyFlag.animated) {
 		return false;
 	}
 
@@ -227,10 +226,9 @@ bool Animations::setModelAnimation(int32 animState, const uint8 *animPtr, uint8
 
 	const uint8* lastKeyFramePtr = ebx;
 
-	int32 eax = READ_LE_INT16(edi - 2);
-	edi += eax;
+	edi += bodyHeader->offsetToData;
 
-	eax = READ_LE_INT16(edi);
+	int16 eax = READ_LE_INT16(edi);
 	eax = eax + eax * 2;
 	edi = edi + eax * 2 + 12;
 
@@ -350,9 +348,9 @@ int32 Animations::getBodyAnimIndex(AnimationTypes animIdx, int32 actorIdx) {
 
 int32 Animations::stockAnimation(uint8 *bodyPtr, AnimTimerDataStruct *animTimerDataPtr) {
 	uint8 *animPtr = animBuffer2;
-	int32 playAnim = READ_LE_INT16(bodyPtr);
+	int32 bodyHeader = READ_LE_INT16(bodyPtr);
 
-	if (!(playAnim & 2)) {
+	if (!(bodyHeader & 2)) {
 		return 0;
 	}
 	const uint8 *ptr = (bodyPtr + 0x10);
diff --git a/engines/twine/renderer.cpp b/engines/twine/renderer.cpp
index f4d968e9ad..b56ccd8e61 100644
--- a/engines/twine/renderer.cpp
+++ b/engines/twine/renderer.cpp
@@ -1457,20 +1457,20 @@ int32 Renderer::renderAnimatedModel(ModelData *modelData, uint8 *bodyPtr, Render
 }
 
 void Renderer::prepareIsoModel(uint8 *bodyPtr) { // loadGfxSub
-	bodyHeaderStruct *bodyHeader;
 	int32 bp = 36;
 	int32 bx = sizeof(elementEntry);
 
-	bodyHeader = (bodyHeaderStruct *)bodyPtr;
+	Model *bodyHeader = (Model *)bodyPtr;
 
 	// This function should only be called ONCE, otherwise it corrupts the model data.
 	// The following code implements an unused flag to indicate that a model was already processed.
-	if ((bodyHeader->bodyFlag & 0x80)) {
+	if (bodyHeader->bodyFlag.alreadyPrepared) {
 		return;
 	}
-	bodyHeader->bodyFlag |= 0x80;
+	bodyHeader->bodyFlag.alreadyPrepared = 1;
 
-	if (!(bodyHeader->bodyFlag & 2)) { // no animation applicable
+	// no animation applicable
+	if (!bodyHeader->bodyFlag.animated) {
 		return;
 	}
 
@@ -1514,12 +1514,10 @@ int32 Renderer::renderIsoModel(int32 x, int32 y, int32 z, int32 angleX, int32 an
 		renderZ = destZ - baseRotPosZ;
 	}
 
-	int16 bodyHeader = *((const uint16 *)bodyPtr);
-
-	// jump after the header
-	uint8 *ptr = bodyPtr + 16 + *((const uint16 *)(bodyPtr + 14));
-
-	if (bodyHeader & 2) { // if animated
+	Model *bodyHeader = (Model *)bodyPtr;
+	if (bodyHeader->bodyFlag.animated) {
+		// jump after the header
+		uint8 *ptr = bodyPtr + 16 + *((const uint16 *)(bodyPtr + 14));
 		// the mostly used renderer code
 		// restart at the beginning of the renderTable
 		return renderAnimatedModel(&_modelData, ptr, _renderCmds);
@@ -1530,11 +1528,14 @@ int32 Renderer::renderIsoModel(int32 x, int32 y, int32 z, int32 angleX, int32 an
 
 void Renderer::copyActorInternAnim(const uint8 *bodyPtrSrc, uint8 *bodyPtrDest) {
 	// check if both characters allow animation
-	if (!(*((const int16 *)bodyPtrSrc) & 2)) {
+
+	const Model *srcBodyHeader = (const Model *)bodyPtrSrc;
+	if (!srcBodyHeader->bodyFlag.animated) {
 		return;
 	}
 
-	if (!(*((const int16 *)bodyPtrDest) & 2)) {
+	Model *destBodyHeader = (Model *)bodyPtrDest;
+	if (!destBodyHeader->bodyFlag.animated) {
 		return;
 	}
 
@@ -1542,20 +1543,20 @@ void Renderer::copyActorInternAnim(const uint8 *bodyPtrSrc, uint8 *bodyPtrDest)
 	bodyPtrSrc += 16;
 	bodyPtrDest += 16;
 
-	*((uint32 *)bodyPtrDest) = *((const uint32 *)bodyPtrSrc);
-	*((uint32 *)(bodyPtrDest + 4)) = *((const uint32 *)(bodyPtrSrc + 4));
+	*(uint32 *)(bodyPtrDest + 0) = *(const uint32 *)(bodyPtrSrc + 0);
+	*(uint32 *)(bodyPtrDest + 4) = *(const uint32 *)(bodyPtrSrc + 4);
 
-	bodyPtrSrc = bodyPtrSrc + *((const int16 *)(bodyPtrSrc - 2));
-	const int32 srcNumPoints = *((const int16 *)bodyPtrSrc);
+	bodyPtrSrc += srcBodyHeader->offsetToData;
+	const int32 srcNumPoints = *(const int16 *)bodyPtrSrc;
 	// skip vertices
-	bodyPtrSrc = bodyPtrSrc + srcNumPoints * sizeof(pointTab) + 2;
-	int16 cx = *((const int16 *)bodyPtrSrc);
+	bodyPtrSrc += srcNumPoints * sizeof(pointTab) + 2;
+	int16 cx = *(const int16 *)bodyPtrSrc;
 
-	bodyPtrDest = bodyPtrDest + *((const int16 *)(bodyPtrDest - 2));
-	const int32 destNumPoints = *((const int16 *)bodyPtrDest);
+	bodyPtrDest += destBodyHeader->offsetToData;
+	const int32 destNumPoints = *(const int16 *)bodyPtrDest;
 	// skip vertices
-	bodyPtrDest = bodyPtrDest + destNumPoints * sizeof(pointTab) + 2;
-	int16 ax = *((const int16 *)bodyPtrDest);
+	bodyPtrDest += destNumPoints * sizeof(pointTab) + 2;
+	const int16 ax = *(const int16 *)bodyPtrDest;
 
 	if (cx > ax) {
 		cx = ax;
@@ -1565,8 +1566,8 @@ void Renderer::copyActorInternAnim(const uint8 *bodyPtrSrc, uint8 *bodyPtrDest)
 	bodyPtrDest += 10;
 
 	for (int32 i = 0; i < cx; i++) {
-		*((uint32 *)bodyPtrDest) = *((const uint32 *)bodyPtrSrc);
-		*((uint32 *)(bodyPtrDest + 4)) = *((const uint32 *)(bodyPtrSrc + 4));
+		*(uint32 *)(bodyPtrDest + 0) = *(const uint32 *)(bodyPtrSrc + 0);
+		*(uint32 *)(bodyPtrDest + 4) = *(const uint32 *)(bodyPtrSrc + 4);
 
 		bodyPtrDest += 30;
 		bodyPtrSrc += 30;
diff --git a/engines/twine/renderer.h b/engines/twine/renderer.h
index 9fd7a720c1..07f7d6558c 100644
--- a/engines/twine/renderer.h
+++ b/engines/twine/renderer.h
@@ -63,6 +63,34 @@ struct Matrix {
 	int32 row3[3] {0, 0, 0};
 };
 
+struct Model {
+	struct BodyFlags {
+		uint16 unk1 : 1;
+		uint16 animated : 1;
+		uint16 unk3 : 1;
+		uint16 unk4 : 1;
+		uint16 unk5 : 1;
+		uint16 unk6 : 1;
+		uint16 unk7 : 1;
+		uint16 alreadyPrepared : 1;
+		uint16 unk9 : 1;
+		uint16 unk10 : 1;
+		uint16 unk11 : 1;
+		uint16 unk12 : 1;
+		uint16 unk13 : 1;
+		uint16 unk14 : 1;
+		uint16 unk15 : 1;
+		uint16 unk16 : 1;
+	} bodyFlag;
+	int16 minsx = 0;
+	int16 maxsx = 0;
+	int16 minsy = 0;
+	int16 maxsy = 0;
+	int16 minsz = 0;
+	int16 maxsz = 0;
+	int16 offsetToData = 0;
+};
+
 class Renderer {
 private:
 	TwinEEngine *_engine;
@@ -134,19 +162,6 @@ private:
 		int16 dataOffset = 0;
 	};
 
-	struct bodyHeaderStruct {
-		int16 bodyFlag = 0;
-		int16 minsx = 0;
-		int16 maxsx = 0;
-		int16 minsy = 0;
-		int16 maxsy = 0;
-		int16 minsz = 0;
-		int16 maxsz = 0;
-		int16 offsetToData = 0;
-		int8 *ptrToKeyFrame = nullptr;
-		int32 keyFrameTime = 0;
-	};
-
 	struct ModelData {
 		pointTab computedPoints[800];
 		pointTab flattenPoints[800];


Commit: 4c069b89d6dbaddc2f190c8672bd26f1b7661963
    https://github.com/scummvm/scummvm/commit/4c069b89d6dbaddc2f190c8672bd26f1b7661963
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-12-03T20:53:25+01:00

Commit Message:
TWINE: (hopefully) fixed manual mode for agressive behaviour doesn't work as expected

https://bugs.scummvm.org/ticket/11981

Changed paths:
    engines/twine/movements.cpp


diff --git a/engines/twine/movements.cpp b/engines/twine/movements.cpp
index 58f49b206a..93115e8eb8 100644
--- a/engines/twine/movements.cpp
+++ b/engines/twine/movements.cpp
@@ -248,13 +248,11 @@ bool Movements::processBehaviourExecution(int actorIdx) {
 				}
 			}
 		} else {
-			if (_engine->_input->isActionActive(TwinEActionType::TurnLeft)) {
+			if (_engine->_input->toggleActionIfActive(TwinEActionType::TurnLeft)) {
 				_engine->_animations->initAnim(AnimationTypes::kLeftPunch, 1, AnimationTypes::kStanding, actorIdx);
-			} else if (_engine->_input->isActionActive(TwinEActionType::TurnRight)) {
+			} else if (_engine->_input->toggleActionIfActive(TwinEActionType::TurnRight)) {
 				_engine->_animations->initAnim(AnimationTypes::kRightPunch, 1, AnimationTypes::kStanding, actorIdx);
-			}
-
-			if (_engine->_input->isActionActive(TwinEActionType::MoveForward)) {
+			} else if (_engine->_input->toggleActionIfActive(TwinEActionType::MoveForward)) {
 				_engine->_animations->initAnim(AnimationTypes::kKick, 1, AnimationTypes::kStanding, actorIdx);
 			}
 		}




More information about the Scummvm-git-logs mailing list