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

mgerhardy martin.gerhardy at gmail.com
Tue Dec 8 19:21:04 UTC 2020


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

Summary:
e51c0bcff0 TWINE: removed unused code
208904c53c TWINE: removed stub in holomap code
ba9bc506e5 TWINE: extended EntityData class
3b00761f78 TWINE: debug logging
d2f7c935d8 TWINE: format the code
f6f245ab65 TWINE: removed redundant null pointer check
42929ae8dc TWINE: reset body table index in a method
e68d08b8d1 TWINE: ensure that the proper entity data buffer size is set
b26514e55b TWINE: started to use the entity data


Commit: e51c0bcff0ebe1dd176457f44c65476cd323aa73
    https://github.com/scummvm/scummvm/commit/e51c0bcff0ebe1dd176457f44c65476cd323aa73
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-12-08T20:03:23+01:00

Commit Message:
TWINE: removed unused code

currentIndex and localActor->entity are the same values - so the call to copyActorInternAnim was a NOP

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


diff --git a/engines/twine/actor.cpp b/engines/twine/actor.cpp
index 2360859e28..47fbe8643c 100644
--- a/engines/twine/actor.cpp
+++ b/engines/twine/actor.cpp
@@ -283,7 +283,6 @@ void Actor::initModelActor(int32 bodyIdx, int16 actorIdx) {
 
 	localActor->entity = entityIdx;
 	localActor->body = bodyIdx;
-	int currentIndex = localActor->entity;
 
 	if (actorBoundingBox.hasBoundingBox) {
 		ZVBox &bbox = localActor->boudingBox;
@@ -325,16 +324,6 @@ void Actor::initModelActor(int32 bodyIdx, int16 actorIdx) {
 		bbox.z.bottomLeft = -result;
 		bbox.z.topRight = result;
 	}
-
-	if (currentIndex == -1) {
-		return;
-	}
-
-	if (localActor->previousAnimIdx == -1) {
-		return;
-	}
-
-	_engine->_renderer->copyActorInternAnim(bodyTable[currentIndex], bodyTable[localActor->entity]);
 }
 
 void Actor::initActor(int16 actorIdx) {
diff --git a/engines/twine/renderer.cpp b/engines/twine/renderer.cpp
index b56ccd8e61..030e8c75f6 100644
--- a/engines/twine/renderer.cpp
+++ b/engines/twine/renderer.cpp
@@ -1526,54 +1526,6 @@ int32 Renderer::renderIsoModel(int32 x, int32 y, int32 z, int32 angleX, int32 an
 	return 0;
 }
 
-void Renderer::copyActorInternAnim(const uint8 *bodyPtrSrc, uint8 *bodyPtrDest) {
-	// check if both characters allow animation
-
-	const Model *srcBodyHeader = (const Model *)bodyPtrSrc;
-	if (!srcBodyHeader->bodyFlag.animated) {
-		return;
-	}
-
-	Model *destBodyHeader = (Model *)bodyPtrDest;
-	if (!destBodyHeader->bodyFlag.animated) {
-		return;
-	}
-
-	// skip header
-	bodyPtrSrc += 16;
-	bodyPtrDest += 16;
-
-	*(uint32 *)(bodyPtrDest + 0) = *(const uint32 *)(bodyPtrSrc + 0);
-	*(uint32 *)(bodyPtrDest + 4) = *(const uint32 *)(bodyPtrSrc + 4);
-
-	bodyPtrSrc += srcBodyHeader->offsetToData;
-	const int32 srcNumPoints = *(const int16 *)bodyPtrSrc;
-	// skip vertices
-	bodyPtrSrc += srcNumPoints * sizeof(pointTab) + 2;
-	int16 cx = *(const int16 *)bodyPtrSrc;
-
-	bodyPtrDest += destBodyHeader->offsetToData;
-	const int32 destNumPoints = *(const int16 *)bodyPtrDest;
-	// skip vertices
-	bodyPtrDest += destNumPoints * sizeof(pointTab) + 2;
-	const int16 ax = *(const int16 *)bodyPtrDest;
-
-	if (cx > ax) {
-		cx = ax;
-	}
-
-	bodyPtrSrc += 10;
-	bodyPtrDest += 10;
-
-	for (int32 i = 0; i < cx; i++) {
-		*(uint32 *)(bodyPtrDest + 0) = *(const uint32 *)(bodyPtrSrc + 0);
-		*(uint32 *)(bodyPtrDest + 4) = *(const uint32 *)(bodyPtrSrc + 4);
-
-		bodyPtrDest += 30;
-		bodyPtrSrc += 30;
-	}
-}
-
 void Renderer::renderBehaviourModel(const Common::Rect &rect, int32 y, int32 angle, uint8 *entityPtr) {
 	renderBehaviourModel(rect.left, rect.top, rect.right, rect.bottom, y, angle, entityPtr);
 }
diff --git a/engines/twine/renderer.h b/engines/twine/renderer.h
index 6a67c2c929..ea565ce1b2 100644
--- a/engines/twine/renderer.h
+++ b/engines/twine/renderer.h
@@ -284,8 +284,6 @@ public:
 
 	int32 renderIsoModel(int32 x, int32 y, int32 z, int32 angleX, int32 angleY, int32 angleZ, uint8 *bodyPtr);
 
-	void copyActorInternAnim(const uint8 *bodyPtrSrc, uint8 *bodyPtrDest);
-
 	void renderBehaviourModel(int32 boxLeft, int32 boxTop, int32 boxRight, int32 boxBottom, int32 y, int32 angle, uint8 *entityPtr);
 	void renderBehaviourModel(const Common::Rect &rect, int32 y, int32 angle, uint8 *entityPtr);
 


Commit: 208904c53cb290571fcc8ff8f70ee1b170878369
    https://github.com/scummvm/scummvm/commit/208904c53cb290571fcc8ff8f70ee1b170878369
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-12-08T20:03:23+01:00

Commit Message:
TWINE: removed stub in holomap code

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


diff --git a/engines/twine/holomap.cpp b/engines/twine/holomap.cpp
index 646d87d81a..cc83b007f6 100644
--- a/engines/twine/holomap.cpp
+++ b/engines/twine/holomap.cpp
@@ -73,10 +73,6 @@ void Holomap::clearHolomapPosition(int32 locationIdx) {
 	_engine->_gameState->holomapFlags[locationIdx] |= 0x40;
 }
 
-void Holomap::loadGfxSub(uint8 *modelPtr) {
-	// TODO is this prepareIsoModel?
-}
-
 void Holomap::loadGfxSub1() {
 	// TODO
 }
@@ -97,11 +93,10 @@ void Holomap::loadHolomapGFX() {
 	uint8 *videoPtr7 = videoPtr6 + HQR::getEntry(videoPtr6, Resources::HQR_RESS_FILE, RESSHQR_HOLOARROWMDL);
 	uint8 *videoPtr8 = videoPtr7 + HQR::getEntry(videoPtr7, Resources::HQR_RESS_FILE, RESSHQR_HOLOTWINARROWMDL);
 
-	loadGfxSub(videoPtr5);
-	loadGfxSub(videoPtr6);
-	loadGfxSub(videoPtr7);
-
-	loadGfxSub(videoPtr8);
+	_engine->_renderer->prepareIsoModel(videoPtr5);
+	_engine->_renderer->prepareIsoModel(videoPtr6);
+	_engine->_renderer->prepareIsoModel(videoPtr7);
+	_engine->_renderer->prepareIsoModel(videoPtr8);
 
 	// TODO:
 	// uint8 *videoPtr1 = (uint8 *)_engine->workVideoBuffer.getPixels();
diff --git a/engines/twine/holomap.h b/engines/twine/holomap.h
index 60bdfd0776..7ebcad74c6 100644
--- a/engines/twine/holomap.h
+++ b/engines/twine/holomap.h
@@ -77,7 +77,6 @@ public:
 	/** Draw Holomap Trajectory */
 	void drawHolomapTrajectory(int32 trajectoryIndex);
 
-	void loadGfxSub(uint8 *modelPtr);
 	void loadGfxSub1();
 	void loadGfxSub2();
 


Commit: ba9bc506e503cf481613bd0d62c1f1e85b892c79
    https://github.com/scummvm/scummvm/commit/ba9bc506e503cf481613bd0d62c1f1e85b892c79
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-12-08T20:03:23+01:00

Commit Message:
TWINE: extended EntityData class

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


diff --git a/engines/twine/entity.cpp b/engines/twine/entity.cpp
index dbcb3c6e66..af5beab502 100644
--- a/engines/twine/entity.cpp
+++ b/engines/twine/entity.cpp
@@ -167,12 +167,24 @@ bool EntityData::loadFromStream(Common::SeekableReadStream &stream) {
 
 bool EntityData::loadFromBuffer(const uint8* buf, uint32 size) {
 	if (size == 0) {
-		error("Failed to load entity data");
+		return false;
 	}
 	Common::MemoryReadStream stream(buf, size);
 	return loadFromStream(stream);
 }
 
+const Common::Array<EntityAnim::Action>* EntityData::getActions(AnimationTypes animation) const {
+	for (const EntityAnim& anim : _animations) {
+		if (anim.animation == animation) {
+			if (anim._actions.empty()) {
+				return nullptr;
+			}
+			return &anim._actions;
+		}
+	}
+	return nullptr;
+}
+
 const EntityBody* EntityData::getBody(const int index) const {
 	for (const EntityBody& body : _bodies) {
 		if (body.index == index) {
diff --git a/engines/twine/entity.h b/engines/twine/entity.h
index 38bb8c71eb..210928966a 100644
--- a/engines/twine/entity.h
+++ b/engines/twine/entity.h
@@ -31,9 +31,9 @@
 namespace TwinE {
 
 struct EntityBody {
-	int index;
+	int index;		/**< index in file3d.hqr */
 	ActorBoundingBox actorBoundingBox;
-	int bodyIndex;
+	int bodyIndex;	/**< index in body.hqr */
 };
 
 struct EntityAnim {
@@ -74,9 +74,10 @@ private:
 public:
 	bool loadFromStream(Common::SeekableReadStream &stream);
 
-	bool loadFromBuffer(const uint8* buf, uint32 size);
+	bool loadFromBuffer(const uint8 *buf, uint32 size);
 
-	const EntityBody* getBody(const int index) const;
+	const Common::Array<EntityAnim::Action> *getActions(AnimationTypes animation) const;
+	const EntityBody *getBody(const int index) const;
 	int32 getAnimIndex(AnimationTypes animation) const;
 };
 


Commit: 3b00761f78f5c0e9aec42eb0b87ac3ec9feabc2b
    https://github.com/scummvm/scummvm/commit/3b00761f78f5c0e9aec42eb0b87ac3ec9feabc2b
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-12-08T20:03:23+01:00

Commit Message:
TWINE: debug logging

Changed paths:
    engines/twine/actor.cpp


diff --git a/engines/twine/actor.cpp b/engines/twine/actor.cpp
index 47fbe8643c..8560717543 100644
--- a/engines/twine/actor.cpp
+++ b/engines/twine/actor.cpp
@@ -257,6 +257,8 @@ void Actor::initModelActor(int32 bodyIdx, int16 actorIdx) {
 		return;
 	}
 
+	debug("Load body %i for actor %i", bodyIdx, actorIdx);
+
 	if (IS_HERO(actorIdx) && heroBehaviour == HeroBehaviourType::kProtoPack && localActor->armor != 0 && localActor->armor != 1) {
 		setBehaviour(HeroBehaviourType::kNormal);
 	}
@@ -274,6 +276,7 @@ void Actor::initModelActor(int32 bodyIdx, int16 actorIdx) {
 		bbox.y.topRight = 0;
 		bbox.z.bottomLeft = 0;
 		bbox.z.topRight = 0;
+		debug("Failed to initialize body %i for actor %i", bodyIdx, actorIdx);
 		return;
 	}
 
@@ -348,6 +351,7 @@ void Actor::initActor(int16 actorIdx) {
 	} else {
 		actor->entity = -1;
 
+		debug("Init actor %i with model %i", actorIdx, actor->body);
 		initModelActor(actor->body, actorIdx);
 
 		actor->previousAnimIdx = -1;
@@ -499,6 +503,7 @@ ActorStruct::~ActorStruct() {
 void ActorStruct::loadModel(int32 modelIndex) {
 	entity = modelIndex;
 	if (!staticFlags.bIsSpriteActor) {
+		debug("Init actor with model %i", modelIndex);
 		entityDataSize = HQR::getAllocEntry(&entityDataPtr, Resources::HQR_FILE3D_FILE, modelIndex);
 	} else {
 		entityDataSize = 0;


Commit: d2f7c935d89b73980c9052c06835d0b14e2938e3
    https://github.com/scummvm/scummvm/commit/d2f7c935d89b73980c9052c06835d0b14e2938e3
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-12-08T20:03:23+01:00

Commit Message:
TWINE: format the code

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


diff --git a/engines/twine/actor.h b/engines/twine/actor.h
index 1c7241eb3d..502e7cbb44 100644
--- a/engines/twine/actor.h
+++ b/engines/twine/actor.h
@@ -158,7 +158,7 @@ public:
 	inline bool brickCausesDamage() { return _brickCausesDamage; }
 	void loadModel(int32 modelIndex);
 
-	int32 entity = 0; // costumeIndex
+	int32 entity = 0; // costumeIndex - index into bodyTable
 	/**
 	 * 0: tunic + medallion
 	 * 1: tunic
diff --git a/engines/twine/animations.cpp b/engines/twine/animations.cpp
index 3d11b8edfb..f12fb7aa59 100644
--- a/engines/twine/animations.cpp
+++ b/engines/twine/animations.cpp
@@ -40,13 +40,12 @@
 namespace TwinE {
 
 static const int32 magicLevelStrengthOfHit[] = {
-	MagicballStrengthType::kNoBallStrength,
-	MagicballStrengthType::kYellowBallStrength,
-	MagicballStrengthType::kGreenBallStrength,
-	MagicballStrengthType::kRedBallStrength,
-	MagicballStrengthType::kFireBallStrength,
-	0
-};
+    MagicballStrengthType::kNoBallStrength,
+    MagicballStrengthType::kYellowBallStrength,
+    MagicballStrengthType::kGreenBallStrength,
+    MagicballStrengthType::kRedBallStrength,
+    MagicballStrengthType::kFireBallStrength,
+    0};
 
 Animations::Animations(TwinEEngine *engine) : _engine(engine), animBuffer((uint8 *)malloc(5000 * sizeof(uint8))) {
 	animBufferPos = animBuffer;
@@ -68,6 +67,8 @@ int32 Animations::setAnimAtKeyframe(int32 keyframeIdx, const uint8 *animPtr, uin
 
 	int16 numOfBonesInAnim = READ_LE_INT16(animPtr + 2);
 
+	// A bones is 8 bytes - length uint16, x, y and z as sint16
+	// additional 8 bytes for the animation header numkeyframes, numboneframes, loopframe and unkown uint16 fields
 	const uint8 *ptrToData = (const uint8 *)((numOfBonesInAnim * 8 + 8) * keyframeIdx + animPtr + 8);
 
 	animTimerDataPtr->ptr = ptrToData;
@@ -183,7 +184,7 @@ bool Animations::setModelAnimation(int32 animState, const uint8 *animPtr, uint8
 		return false;
 	}
 	int32 numOfPointInAnim = READ_LE_INT16(animPtr + 2);
-	const uint8* keyFramePtr = ((numOfPointInAnim * 8 + 8) * animState) + animPtr + 8;
+	const uint8 *keyFramePtr = ((numOfPointInAnim * 8 + 8) * animState) + animPtr + 8;
 	const int32 keyFrameLength = READ_LE_INT16(keyFramePtr);
 
 	const uint8 *lastKeyFramePtr = animTimerDataPtr->ptr;
@@ -198,7 +199,7 @@ bool Animations::setModelAnimation(int32 animState, const uint8 *animPtr, uint8
 
 	const int16 numVertices = READ_LE_INT16(verticesBase);
 	verticesBase += 2;
-	uint8* bonesBase = verticesBase + numVertices * 6;
+	uint8 *bonesBase = verticesBase + numVertices * 6;
 
 	const int32 numBones = READ_LE_INT16(bonesBase);
 	bonesBase += 2;
@@ -209,7 +210,7 @@ bool Animations::setModelAnimation(int32 animState, const uint8 *animPtr, uint8
 
 	const int32 deltaTime = _engine->lbaTime - remainingFrameTime;
 
-	uint8* edi = bonesBase + 8;
+	uint8 *edi = bonesBase + 8;
 	if (deltaTime >= keyFrameLength) {
 		const int32 *sourcePtr = (const int32 *)(keyFramePtr + 8);
 		int32 *destPtr = (int32 *)edi; // keyframe
@@ -252,13 +253,13 @@ bool Animations::setModelAnimation(int32 animState, const uint8 *animPtr, uint8
 			const int16 animOpcode = getAnimMode(&edi, &keyFramePtr, &lastKeyFramePtr);
 
 			switch (animOpcode) {
-			case 0:  // allow global rotate
+			case 0: // allow global rotate
 				applyAnimStepRotation(&edi, deltaTime, keyFrameLength, &keyFramePtr, &lastKeyFramePtr);
 				applyAnimStepRotation(&edi, deltaTime, keyFrameLength, &keyFramePtr, &lastKeyFramePtr);
 				applyAnimStepRotation(&edi, deltaTime, keyFrameLength, &keyFramePtr, &lastKeyFramePtr);
 				break;
-			case 1:  // dissallow global rotate
-			case 2:  // dissallow global rotate + hide
+			case 1: // dissallow global rotate
+			case 2: // dissallow global rotate + hide
 				applyAnimStep(&edi, deltaTime, keyFrameLength, &keyFramePtr, &lastKeyFramePtr);
 				applyAnimStep(&edi, deltaTime, keyFrameLength, &keyFramePtr, &lastKeyFramePtr);
 				applyAnimStep(&edi, deltaTime, keyFrameLength, &keyFramePtr, &lastKeyFramePtr);
@@ -803,7 +804,7 @@ void Animations::processActorAnimations(int32 actorIdx) { // DoAnim
 
 			bool keyFramePassed = false;
 			if (Model::isAnimated(_engine->_actor->bodyTable[actor->entity])) {
-				keyFramePassed = verifyAnimAtKeyframe(actor->animPosition, animPtr, &actor->animTimerData);;
+				keyFramePassed = verifyAnimAtKeyframe(actor->animPosition, animPtr, &actor->animTimerData);
 			}
 
 			if (processRotationByAnim) {


Commit: f6f245ab6554f577e3a36df5cd7cce21a4acb149
    https://github.com/scummvm/scummvm/commit/f6f245ab6554f577e3a36df5cd7cce21a4acb149
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-12-08T20:03:23+01:00

Commit Message:
TWINE: removed redundant null pointer check

Changed paths:
    engines/twine/animations.cpp


diff --git a/engines/twine/animations.cpp b/engines/twine/animations.cpp
index f12fb7aa59..4f489487f7 100644
--- a/engines/twine/animations.cpp
+++ b/engines/twine/animations.cpp
@@ -677,9 +677,7 @@ bool Animations::initAnim(AnimationTypes newAnim, int16 animType, AnimationTypes
 	actor->dynamicFlags.bAnimEnded = 0;
 	actor->dynamicFlags.bAnimFrameReached = 1;
 
-	if (actor->animExtraPtr) {
-		processAnimActions(actorIdx);
-	}
+	processAnimActions(actorIdx);
 
 	actor->lastRotationAngle = 0;
 	actor->lastX = 0;
@@ -836,9 +834,7 @@ void Animations::processActorAnimations(int32 actorIdx) { // DoAnim
 				actor->animPosition++;
 
 				// if actor have animation actions to process
-				if (actor->animExtraPtr) {
-					processAnimActions(actorIdx);
-				}
+				processAnimActions(actorIdx);
 
 				int16 numKeyframe = actor->animPosition;
 				if (numKeyframe == getNumKeyframes(animPtr)) {
@@ -862,9 +858,7 @@ void Animations::processActorAnimations(int32 actorIdx) { // DoAnim
 						actor->strengthOfHit = 0;
 					}
 
-					if (actor->animExtraPtr) {
-						processAnimActions(actorIdx);
-					}
+					processAnimActions(actorIdx);
 
 					actor->dynamicFlags.bAnimEnded = 1;
 				}


Commit: 42929ae8dcf43e6a171e94a6bc9e44fbb8503728
    https://github.com/scummvm/scummvm/commit/42929ae8dcf43e6a171e94a6bc9e44fbb8503728
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-12-08T20:03:24+01:00

Commit Message:
TWINE: reset body table index in a method

Changed paths:
    engines/twine/actor.cpp
    engines/twine/actor.h
    engines/twine/gamestate.cpp
    engines/twine/scene.cpp


diff --git a/engines/twine/actor.cpp b/engines/twine/actor.cpp
index 8560717543..f2db5e322a 100644
--- a/engines/twine/actor.cpp
+++ b/engines/twine/actor.cpp
@@ -496,6 +496,10 @@ void Actor::processActorExtraBonus(int32 actorIdx) { // GiveExtraBonus
 	}
 }
 
+void Actor::clearBodyTable() {
+	currentPositionInBodyPtrTab = 0;
+}
+
 ActorStruct::~ActorStruct() {
 	free(entityDataPtr);
 }
diff --git a/engines/twine/actor.h b/engines/twine/actor.h
index 502e7cbb44..7db132aca0 100644
--- a/engines/twine/actor.h
+++ b/engines/twine/actor.h
@@ -309,6 +309,7 @@ public:
 
 	/** Current position in body table */
 	int32 currentPositionInBodyPtrTab;
+	void clearBodyTable();
 
 	/** Restart hero variables while opening new scenes */
 	void restartHeroScene();
diff --git a/engines/twine/gamestate.cpp b/engines/twine/gamestate.cpp
index 03567b0357..4f4e93bee7 100644
--- a/engines/twine/gamestate.cpp
+++ b/engines/twine/gamestate.cpp
@@ -91,7 +91,7 @@ void GameState::initGameStateVars() {
 		holomapFlags[i] = 0;
 	}
 
-	_engine->_actor->currentPositionInBodyPtrTab = 0;
+	_engine->_actor->clearBodyTable();
 }
 
 void GameState::initHeroVars() {
diff --git a/engines/twine/scene.cpp b/engines/twine/scene.cpp
index c2970ffc5f..fee71c2fa8 100644
--- a/engines/twine/scene.cpp
+++ b/engines/twine/scene.cpp
@@ -284,7 +284,7 @@ void Scene::resetScene() {
 		_engine->_redraw->overlayList[i].info0 = -1;
 	}
 
-	_engine->_actor->currentPositionInBodyPtrTab = 0;
+	_engine->_actor->clearBodyTable();
 	_engine->_screens->useAlternatePalette = false;
 }
 


Commit: e68d08b8d1b520e906c50dd55fe71edcfb07e769
    https://github.com/scummvm/scummvm/commit/e68d08b8d1b520e906c50dd55fe71edcfb07e769
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-12-08T20:03:24+01:00

Commit Message:
TWINE: ensure that the proper entity data buffer size is set

Changed paths:
    engines/twine/actor.cpp


diff --git a/engines/twine/actor.cpp b/engines/twine/actor.cpp
index f2db5e322a..a8149bd257 100644
--- a/engines/twine/actor.cpp
+++ b/engines/twine/actor.cpp
@@ -87,28 +87,44 @@ void Actor::loadHeroEntities() {
 		error("Failed to load actor athletic 3d data");
 	}
 	sceneHero->entityDataPtr = heroEntityATHLETIC;
+	sceneHero->entityDataSize = heroEntityATHLETICSize;
 	heroAnimIdxATHLETIC = _engine->_animations->getBodyAnimIndex(AnimationTypes::kStanding);
+	if (heroAnimIdxATHLETIC == -1) {
+		error("Could not find athletic animation data");
+	}
 
 	heroEntityAGGRESSIVESize = HQR::getAllocEntry(&heroEntityAGGRESSIVE, Resources::HQR_FILE3D_FILE, FILE3DHQR_HEROAGGRESSIVE);
 	if (heroEntityAGGRESSIVESize == 0) {
 		error("Failed to load actor aggressive 3d data");
 	}
 	sceneHero->entityDataPtr = heroEntityAGGRESSIVE;
+	sceneHero->entityDataSize = heroEntityAGGRESSIVESize;
 	heroAnimIdxAGGRESSIVE = _engine->_animations->getBodyAnimIndex(AnimationTypes::kStanding);
+	if (heroAnimIdxAGGRESSIVE == -1) {
+		error("Could not find aggressive animation data");
+	}
 
 	heroEntityDISCRETESize = HQR::getAllocEntry(&heroEntityDISCRETE, Resources::HQR_FILE3D_FILE, FILE3DHQR_HERODISCRETE);
 	if (heroEntityDISCRETESize == 0) {
 		error("Failed to load actor discrete 3d data");
 	}
 	sceneHero->entityDataPtr = heroEntityDISCRETE;
+	sceneHero->entityDataSize = heroEntityDISCRETESize;
 	heroAnimIdxDISCRETE = _engine->_animations->getBodyAnimIndex(AnimationTypes::kStanding);
+	if (heroAnimIdxDISCRETE == -1) {
+		error("Could not find discrete animation data");
+	}
 
 	heroEntityPROTOPACKSize = HQR::getAllocEntry(&heroEntityPROTOPACK, Resources::HQR_FILE3D_FILE, FILE3DHQR_HEROPROTOPACK);
 	if (heroEntityPROTOPACKSize == 0) {
 		error("Failed to load actor protopack 3d data");
 	}
 	sceneHero->entityDataPtr = heroEntityPROTOPACK;
+	sceneHero->entityDataSize = heroEntityPROTOPACKSize;
 	heroAnimIdxPROTOPACK = _engine->_animations->getBodyAnimIndex(AnimationTypes::kStanding);
+	if (heroAnimIdxPROTOPACK == -1) {
+		error("Could not find protopack animation data");
+	}
 
 	heroEntityNORMALSize = HQR::getAllocEntry(&heroEntityNORMAL, Resources::HQR_FILE3D_FILE, FILE3DHQR_HERONORMAL);
 	if (heroEntityNORMALSize == 0) {
@@ -117,6 +133,9 @@ void Actor::loadHeroEntities() {
 	sceneHero->entityDataPtr = heroEntityNORMAL;
 	sceneHero->entityDataSize = heroEntityNORMALSize;
 	heroAnimIdxNORMAL = _engine->_animations->getBodyAnimIndex(AnimationTypes::kStanding);
+	if (heroAnimIdxNORMAL == -1) {
+		error("Could not find normal animation data");
+	}
 
 	sceneHero->animExtraPtr = _engine->_animations->currentActorAnimExtraPtr;
 }


Commit: b26514e55b2d11013d0c0434fec1a496629acefa
    https://github.com/scummvm/scummvm/commit/b26514e55b2d11013d0c0434fec1a496629acefa
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-12-08T20:03:24+01:00

Commit Message:
TWINE: started to use the entity data

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


diff --git a/engines/twine/actor.cpp b/engines/twine/actor.cpp
index a8149bd257..6613e06ad5 100644
--- a/engines/twine/actor.cpp
+++ b/engines/twine/actor.cpp
@@ -25,6 +25,7 @@
 #include "common/system.h"
 #include "common/textconsole.h"
 #include "twine/animations.h"
+#include "twine/entity.h"
 #include "twine/extra.h"
 #include "twine/gamestate.h"
 #include "twine/grid.h"
diff --git a/engines/twine/actor.h b/engines/twine/actor.h
index 7db132aca0..583b1e0bb4 100644
--- a/engines/twine/actor.h
+++ b/engines/twine/actor.h
@@ -171,7 +171,7 @@ public:
 	int32 body = 0;
 	AnimationTypes anim = AnimationTypes::kAnimNone;
 	AnimationTypes animExtra = AnimationTypes::kStanding;  //field_2
-	const uint8 *animExtraPtr = nullptr;
+	AnimationTypes animExtraPtr = AnimationTypes::kAnimNone;
 	int32 sprite = 0; // field_8
 	uint8 *entityDataPtr = nullptr;
 	int32 entityDataSize = 0;
diff --git a/engines/twine/animations.cpp b/engines/twine/animations.cpp
index 4f489487f7..c8ddabe3cb 100644
--- a/engines/twine/animations.cpp
+++ b/engines/twine/animations.cpp
@@ -28,12 +28,14 @@
 #include "common/util.h"
 #include "twine/actor.h"
 #include "twine/collision.h"
+#include "twine/entity.h"
 #include "twine/gamestate.h"
 #include "twine/grid.h"
 #include "twine/movements.h"
 #include "twine/renderer.h"
 #include "twine/resources.h"
 #include "twine/scene.h"
+#include "twine/shared.h"
 #include "twine/sound.h"
 #include "twine/twine.h"
 
@@ -279,40 +281,15 @@ bool Animations::setModelAnimation(int32 animState, const uint8 *animPtr, uint8
 	return false;
 }
 
-// see Actor::initBody
 int32 Animations::getBodyAnimIndex(AnimationTypes animIdx, int32 actorIdx) {
 	ActorStruct *actor = _engine->_scene->getActor(actorIdx);
-	const uint8 *entityDataPtr = actor->entityDataPtr;
-
-	do {
-		const uint8 type = *entityDataPtr++;
-		if (type == 0xFF) {
-			currentActorAnimExtraPtr = nullptr;
-			return -1;
-		}
-
-		const uint8 *ptr = (entityDataPtr + 1);
-
-		if (type == 3) {
-			if (animIdx == (AnimationTypes)*entityDataPtr) {
-				ptr++;
-				uint16 realAnimIdx = READ_LE_INT16(ptr);
-				ptr += 2;
-				const uint8 *ptr2 = ptr;
-				ptr++;
-				const uint8 *costumePtr = nullptr;
-				if (*ptr2 != 0) {
-					costumePtr = ptr - 1;
-				}
-				currentActorAnimExtraPtr = costumePtr;
-				return realAnimIdx;
-			}
-		}
-
-		entityDataPtr = *ptr + ptr;
-	} while (1);
-
-	return 0;
+	EntityData entityData;
+	entityData.loadFromBuffer(actor->entityDataPtr, actor->entityDataSize);
+	const int32 bodyAnimIndex = entityData.getAnimIndex(animIdx);
+	if (bodyAnimIndex != -1) {
+		currentActorAnimExtraPtr = animIdx;
+	}
+	return bodyAnimIndex;
 }
 
 int32 Animations::stockAnimation(const uint8 *bodyPtr, AnimTimerDataStruct *animTimerDataPtr) {
@@ -403,209 +380,106 @@ bool Animations::verifyAnimAtKeyframe(int32 animIdx, const uint8 *animPtr, AnimT
 
 void Animations::processAnimActions(int32 actorIdx) {
 	ActorStruct *actor = _engine->_scene->getActor(actorIdx);
-	if (actor->animExtraPtr == nullptr) {
+	if (actor->entityDataPtr == nullptr || actor->animExtraPtr == AnimationTypes::kAnimNone) {
 		return;
 	}
 
-	// TODO: fix size
-	Common::MemoryReadStream stream(actor->animExtraPtr, 1000000);
-
-	int32 index = 0;
-	const int32 endAnimEntityIdx = stream.readByte();
-	while (index++ < endAnimEntityIdx) {
-		const int32 actionType = stream.readByte();
-		if (actionType >= ActionType::ACTION_LAST) {
-			return;
-		}
-
-		switch (actionType) {
-		case ActionType::ACTION_HITTING: {
-			const int32 animFrame = stream.readByte() - 1;
-			const int32 strength = stream.readByte();
-
-			if (animFrame == actor->animPosition) {
-				actor->strengthOfHit = strength;
+	EntityData entityData;
+	entityData.loadFromBuffer(actor->entityDataPtr, actor->entityDataSize);
+	const Common::Array<EntityAnim::Action> *actions = entityData.getActions(actor->animExtraPtr);
+	if (actions == nullptr) {
+		return;
+	}
+	for (const EntityAnim::Action &action : *actions) {
+		switch (action.type) {
+		case ActionType::ACTION_HITTING:
+			if (action.animFrame - 1 == actor->animPosition) {
+				actor->strengthOfHit = action.strength;
 				actor->dynamicFlags.bIsHitting = 1;
 			}
 			break;
-		}
-		case ActionType::ACTION_SAMPLE: {
-			const int32 animFrame = stream.readByte();
-			const int16 sampleIdx = stream.readSint16LE();
-
-			if (animFrame == actor->animPosition) {
-				_engine->_sound->playSample(sampleIdx, 1, actor->x, actor->y, actor->z, actorIdx);
-			}
-			break;
-		}
-		case ActionType::ACTION_SAMPLE_FREQ: {
-			const int32 animFrame = stream.readByte();
-			const int16 sampleIdx = stream.readSint16LE();
-			/*int16 frequency = */stream.readSint16LE();
-
-			if (animFrame == actor->animPosition) {
-				_engine->_sound->playSample(sampleIdx, 1, actor->x, actor->y, actor->z, actorIdx);
+		case ActionType::ACTION_SAMPLE:
+		case ActionType::ACTION_SAMPLE_FREQ:
+			if (action.animFrame == actor->animPosition) {
+				_engine->_sound->playSample(action.sampleIndex, 1, actor->x, actor->y, actor->z, actorIdx);
 			}
 			break;
-		}
-		case ActionType::ACTION_THROW_EXTRA_BONUS: {
-			const int32 animFrame = stream.readByte();
-			const int32 yHeight = stream.readSint16LE();
-			const int32 sprite = stream.readByte();
-			const int32 xAngle = ToAngle(stream.readSint16LE());
-			const int32 yAngle = actor->angle + ToAngle(stream.readSint16LE());
-			const int32 xRotPoint = stream.readSint16LE();
-			const int32 extraAngle = ToAngle(stream.readByte());
-			const int32 strengthOfHit = stream.readByte();
-
-			if (animFrame == actor->animPosition) {
-				_engine->_extra->addExtraThrow(actorIdx, actor->x, actor->y + yHeight, actor->z, sprite, xAngle, yAngle, xRotPoint, extraAngle, strengthOfHit);
+		case ActionType::ACTION_THROW_EXTRA_BONUS:
+			if (action.animFrame == actor->animPosition) {
+				_engine->_extra->addExtraThrow(actorIdx, actor->x, actor->y + action.yHeight, actor->z, action.spriteIndex, action.xAngle, action.yAngle, action.xRotPoint, action.extraAngle, action.strength);
 			}
 			break;
-		}
-		case ActionType::ACTION_THROW_MAGIC_BALL: {
-			const int32 animFrame = stream.readByte();
-			const int32 yOffset = stream.readSint16LE();
-			const int32 xAngle = ToAngle(stream.readSint16LE());
-			const int32 xRotPoint = stream.readSint16LE();
-			const int32 extraAngle = stream.readByte();
-
-			if (_engine->_gameState->magicBallIdx == -1 && animFrame == actor->animPosition) {
-				_engine->_extra->addExtraThrowMagicball(actor->x, actor->y + yOffset, actor->z, xAngle, actor->angle, xRotPoint, extraAngle);
+		case ActionType::ACTION_THROW_MAGIC_BALL:
+			if (_engine->_gameState->magicBallIdx == -1 && action.animFrame == actor->animPosition) {
+				_engine->_extra->addExtraThrowMagicball(actor->x, actor->y + action.yHeight, actor->z, action.xAngle, actor->angle + action.yAngle, action.xRotPoint, action.extraAngle);
 			}
 			break;
-		}
-		case ActionType::ACTION_SAMPLE_REPEAT: {
-			const int32 animFrame = stream.readByte();
-			const int16 sampleIdx = stream.readSint16LE();
-			const int16 repeat = stream.readSint16LE();
-
-			if (animFrame == actor->animPosition) {
-				_engine->_sound->playSample(sampleIdx, repeat, actor->x, actor->y, actor->z, actorIdx);
+		case ActionType::ACTION_SAMPLE_REPEAT:
+			if (action.animFrame == actor->animPosition) {
+				_engine->_sound->playSample(action.sampleIndex, action.repeat, actor->x, actor->y, actor->z, actorIdx);
 			}
 			break;
-		}
-		case ActionType::ACTION_THROW_SEARCH: {
-			const int32 animFrame = stream.readByte();
-			const int32 yOffset = stream.readSint16LE();
-			const int32 spriteIdx = stream.readByte();
-			const int32 targetActorIdx = stream.readByte();
-			const int32 finalAngle = stream.readSint16LE();
-			const int32 strengthOfHit = stream.readByte();
-			if (animFrame == actor->animPosition) {
-				_engine->_extra->addExtraAiming(actorIdx, actor->x, actor->y + yOffset, actor->z, spriteIdx, targetActorIdx, finalAngle, strengthOfHit);
+		case ActionType::ACTION_THROW_SEARCH:
+			if (action.animFrame == actor->animPosition) {
+				_engine->_extra->addExtraAiming(actorIdx, actor->x, actor->y + action.yHeight, actor->z, action.spriteIndex, action.targetActor, action.finalAngle, action.strength);
 			}
 			break;
-		}
-		case ActionType::ACTION_THROW_ALPHA: {
-			const int32 animFrame = stream.readByte();
-			const int32 yHeight = stream.readSint16LE();
-			const int32 spriteIdx = stream.readByte();
-			const int32 xAngle = ToAngle(stream.readSint16LE());
-			const int32 yAngle = actor->angle + ToAngle(stream.readSint16LE());
-			const int32 xRotPoint = stream.readSint16LE();
-			const int32 extraAngle = ToAngle(stream.readByte());
-			const int32 strengthOfHit = stream.readByte();
-
-			if (animFrame == actor->animPosition) {
-				_engine->_extra->addExtraThrow(actorIdx, actor->x, actor->y + yHeight, actor->z, spriteIdx, xAngle, yAngle, xRotPoint, extraAngle, strengthOfHit);
+		case ActionType::ACTION_THROW_ALPHA:
+			if (action.animFrame == actor->animPosition) {
+				_engine->_extra->addExtraThrow(actorIdx, actor->x, actor->y + action.yHeight, actor->z, action.spriteIndex, action.xAngle, actor->angle + action.yAngle, action.xRotPoint, action.extraAngle, action.strength);
 			}
 			break;
-		}
-		case ActionType::ACTION_SAMPLE_STOP: {
-			const int32 animFrame = stream.readByte();
-			const int32 sampleIdx = stream.readByte(); //why is it reading a byte but saving it in a 32bit variable?
-			stream.skip(1);               // TODO what is the meaning of this extra byte?
-
-			if (animFrame == actor->animPosition) {
-				_engine->_sound->stopSample(sampleIdx);
+		case ActionType::ACTION_SAMPLE_STOP:
+			if (action.animFrame == actor->animPosition) {
+				_engine->_sound->stopSample(action.sampleIndex);
 			}
 			break;
-		}
 		case ActionType::ACTION_LEFT_STEP:
-		case ActionType::ACTION_RIGHT_STEP: {
-			const int32 animFrame = stream.readByte();
-			if (animFrame == actor->animPosition && (actor->brickSound & 0x0F0) != 0x0F0) {
+		case ActionType::ACTION_RIGHT_STEP:
+			if (action.animFrame == actor->animPosition && (actor->brickSound & 0x0F0) != 0x0F0) {
 				const int16 sampleIdx = (actor->brickSound & 0x0F) + Samples::WalkFloorBegin;
 				_engine->_sound->playSample(sampleIdx, 1, actor->x, actor->y, actor->z, actorIdx);
 			}
 			break;
-		}
-		case ActionType::ACTION_HERO_HITTING: {
-			const int32 animFrame = stream.readByte() - 1;
-			if (animFrame == actor->animPosition) {
+		case ActionType::ACTION_HERO_HITTING:
+			if (action.animFrame - 1 == actor->animPosition) {
 				actor->strengthOfHit = magicLevelStrengthOfHit[_engine->_gameState->magicLevelIdx];
 				actor->dynamicFlags.bIsHitting = 1;
 			}
 			break;
-		}
-		case ActionType::ACTION_THROW_3D: {
-			const int32 animFrame = stream.readByte();
-			const int32 distanceX = stream.readSint16LE();
-			const int32 distanceY = stream.readSint16LE();
-			const int32 distanceZ = stream.readSint16LE();
-			const int32 spriteIdx = stream.readByte();
-			const int32 xAngle = ToAngle(stream.readSint16LE());
-			const int32 yAngle = ToAngle(stream.readSint16LE());
-			const int32 xRotPoint = stream.readSint16LE();
-			const int32 extraAngle = ToAngle(stream.readByte());
-			const int32 strength = stream.readByte();
-
-			if (animFrame == actor->animPosition) {
-				_engine->_movements->rotateActor(distanceX, distanceZ, actor->angle);
+		case ActionType::ACTION_THROW_3D:
+			if (action.animFrame == actor->animPosition) {
+				_engine->_movements->rotateActor(action.distanceX, action.distanceZ, actor->angle);
 
 				const int32 throwX = _engine->_renderer->destX + actor->x;
-				const int32 throwY = distanceY + actor->y;
+				const int32 throwY = action.distanceY + actor->y;
 				const int32 throwZ = _engine->_renderer->destZ + actor->z;
 
-				_engine->_extra->addExtraThrow(actorIdx, throwX, throwY, throwZ, spriteIdx,
-				                               xAngle, yAngle + actor->angle, xRotPoint, extraAngle, strength);
+				_engine->_extra->addExtraThrow(actorIdx, throwX, throwY, throwZ, action.spriteIndex,
+				                               action.xAngle, action.yAngle + actor->angle, action.xRotPoint, action.extraAngle, action.strength);
 			}
 			break;
-		}
-		case ActionType::ACTION_THROW_3D_ALPHA: {
-			const int32 animFrame = stream.readByte();
-			const int32 distanceX = stream.readSint16LE();
-			const int32 distanceY = stream.readSint16LE();
-			const int32 distanceZ = stream.readSint16LE();
-			const int32 spriteIdx = stream.readByte();
-			const int32 xAngle = ToAngle(stream.readSint16LE());
-			const int32 yAngle = ToAngle(stream.readSint16LE());
-			const int32 xRotPoint = stream.readSint16LE();
-			const int32 extraAngle = ToAngle(stream.readByte());
-			const int32 strength = stream.readByte();
-
-			if (animFrame == actor->animPosition) {
+		case ActionType::ACTION_THROW_3D_ALPHA:
+			if (action.animFrame == actor->animPosition) {
 				const int32 newAngle = _engine->_movements->getAngleAndSetTargetActorDistance(actor->y, 0, _engine->_scene->sceneHero->y, _engine->_movements->getDistance2D(actor->x, actor->z, _engine->_scene->sceneHero->x, _engine->_scene->sceneHero->z));
 
-				_engine->_movements->rotateActor(distanceX, distanceZ, actor->angle);
+				_engine->_movements->rotateActor(action.distanceX, action.distanceZ, actor->angle);
 
 				const int32 throwX = _engine->_renderer->destX + actor->x;
-				const int32 throwY = distanceY + actor->y;
+				const int32 throwY = action.distanceY + actor->y;
 				const int32 throwZ = _engine->_renderer->destZ + actor->z;
 
-				_engine->_extra->addExtraThrow(actorIdx, throwX, throwY, throwZ, spriteIdx,
-				                               xAngle + newAngle, yAngle + actor->angle, xRotPoint, extraAngle, strength);
+				_engine->_extra->addExtraThrow(actorIdx, throwX, throwY, throwZ, action.spriteIndex,
+				                               action.xAngle + newAngle, action.yAngle + actor->angle, action.xRotPoint, action.extraAngle, action.strength);
 			}
 			break;
-		}
-		case ActionType::ACTION_THROW_3D_SEARCH: {
-			const int32 animFrame = stream.readByte();
-			const int32 distanceX = stream.readSint16LE();
-			const int32 distanceY = stream.readSint16LE();
-			const int32 distanceZ = stream.readSint16LE();
-			const int32 spriteIdx = stream.readByte();
-			const int32 targetActor = stream.readByte();
-			const int32 finalAngle = ToAngle(stream.readSint16LE());
-			const int32 strengthOfHit = stream.readByte();
-
-			if (animFrame == actor->animPosition) {
-				_engine->_movements->rotateActor(distanceX, distanceZ, actor->angle);
-				_engine->_extra->addExtraAiming(actorIdx, actor->x + _engine->_renderer->destX, actor->y + distanceY, actor->z + distanceZ, spriteIdx,
-				                                targetActor, finalAngle, strengthOfHit);
+		case ActionType::ACTION_THROW_3D_SEARCH:
+			if (action.animFrame == actor->animPosition) {
+				_engine->_movements->rotateActor(action.distanceX, action.distanceZ, actor->angle);
+				_engine->_extra->addExtraAiming(actorIdx, actor->x + _engine->_renderer->destX, actor->y + action.distanceY, actor->z + action.distanceZ, action.spriteIndex,
+				                                action.targetActor, action.finalAngle, action.strength);
 			}
 			break;
-		}
 		case ActionType::ACTION_ZV:
 		default:
 			break;
diff --git a/engines/twine/animations.h b/engines/twine/animations.h
index 4e03b7c159..26d600cb98 100644
--- a/engines/twine/animations.h
+++ b/engines/twine/animations.h
@@ -68,7 +68,7 @@ public:
 	/** Current process actor index */
 	int16 currentlyProcessedActorIdx = 0;
 	/** Current actor anim extra pointer */
-	const uint8 *currentActorAnimExtraPtr = nullptr;
+	AnimationTypes currentActorAnimExtraPtr = AnimationTypes::kAnimNone;
 
 	/**
 	 * Set animation keyframe




More information about the Scummvm-git-logs mailing list