[Scummvm-git-logs] scummvm master -> 565b4d5755417d2b2500aeb95fc1de2cb619676d
mgerhardy
martin.gerhardy at gmail.com
Tue Mar 16 18:26:58 UTC 2021
This automated email contains information about 7 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
2e70497df9 TWINE: fixed magic point script subtraction and reduced code duplication
7e5808da5d AGS: added achievement for astroloco steam
0a54429a7e TWINE: reuse the cached AnimData
46d7373671 TWINE: use AnimData for updating animations
9ba86d91de TWINE: removed raw anim data buffers
777ceef714 TWINE: cleanup in model animation code
565b4d5755 TWINE: cleanup in handling the bone states of the model animation
Commit: 2e70497df973b043a06a73ef37aa651ef9937e98
https://github.com/scummvm/scummvm/commit/2e70497df973b043a06a73ef37aa651ef9937e98
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2021-03-16T19:26:47+01:00
Commit Message:
TWINE: fixed magic point script subtraction and reduced code duplication
Changed paths:
engines/twine/debugger/console.cpp
engines/twine/scene/gamestate.cpp
engines/twine/scene/gamestate.h
engines/twine/script/script_life_v1.cpp
engines/twine/twine.cpp
diff --git a/engines/twine/debugger/console.cpp b/engines/twine/debugger/console.cpp
index 7eb5bb52b3..b34dc792ca 100644
--- a/engines/twine/debugger/console.cpp
+++ b/engines/twine/debugger/console.cpp
@@ -119,7 +119,7 @@ bool TwinEConsole::doAddMagicPoints(int argc, const char **argv) {
}
const int16 magicPoints = atoi(argv[1]);
_engine->_gameState->magicLevelIdx = CLIP<int16>(magicPoints, 0, 4);
- _engine->_gameState->inventoryMagicPoints = _engine->_gameState->magicLevelIdx * 20;
+ _engine->_gameState->setMaxMagicPoints();
return true;
}
diff --git a/engines/twine/scene/gamestate.cpp b/engines/twine/scene/gamestate.cpp
index 641d2ae57f..2db9ac2af7 100644
--- a/engines/twine/scene/gamestate.cpp
+++ b/engines/twine/scene/gamestate.cpp
@@ -588,10 +588,17 @@ int16 GameState::setMagicPoints(int16 val) {
inventoryMagicPoints = val;
if (inventoryMagicPoints > magicLevelIdx * 20) {
inventoryMagicPoints = magicLevelIdx * 20;
+ } else if (inventoryMagicPoints < 0) {
+ inventoryMagicPoints = 0;
}
return inventoryMagicPoints;
}
+int16 GameState::setMaxMagicPoints() {
+ inventoryMagicPoints = magicLevelIdx * 20;
+ return inventoryMagicPoints;
+}
+
void GameState::addMagicPoints(int16 val) {
setMagicPoints(inventoryMagicPoints + val);
}
diff --git a/engines/twine/scene/gamestate.h b/engines/twine/scene/gamestate.h
index b7f9fc5641..193abc9835 100644
--- a/engines/twine/scene/gamestate.h
+++ b/engines/twine/scene/gamestate.h
@@ -190,6 +190,7 @@ public:
int16 setLeafs(int16 value);
int16 setKashes(int16 value);
int16 setMagicPoints(int16 val);
+ int16 setMaxMagicPoints();
int16 setLeafBoxes(int16 val);
void addGas(int16 value);
diff --git a/engines/twine/script/script_life_v1.cpp b/engines/twine/script/script_life_v1.cpp
index f6b41b1b41..516c19beec 100644
--- a/engines/twine/script/script_life_v1.cpp
+++ b/engines/twine/script/script_life_v1.cpp
@@ -1133,7 +1133,7 @@ static int32 lPOS_POINT(TwinEEngine *engine, LifeScriptContext &ctx) {
*/
static int32 lSET_MAGIC_LEVEL(TwinEEngine *engine, LifeScriptContext &ctx) {
engine->_gameState->magicLevelIdx = ctx.stream.readByte();
- engine->_gameState->inventoryMagicPoints = engine->_gameState->magicLevelIdx * 20;
+ engine->_gameState->setMaxMagicPoints();
return 0;
}
@@ -1142,10 +1142,7 @@ static int32 lSET_MAGIC_LEVEL(TwinEEngine *engine, LifeScriptContext &ctx) {
* @note Opcode @c 0x3C
*/
static int32 lSUB_MAGIC_POINT(TwinEEngine *engine, LifeScriptContext &ctx) {
- engine->_gameState->inventoryMagicPoints = ctx.stream.readByte();
- if (engine->_gameState->inventoryMagicPoints < 0) {
- engine->_gameState->inventoryMagicPoints = 0;
- }
+ engine->_gameState->addMagicPoints(-ctx.stream.readByte());
return 0;
}
@@ -1398,7 +1395,7 @@ static int32 lSAY_MESSAGE_OBJ(TwinEEngine *engine, LifeScriptContext &ctx) {
*/
static int32 lFULL_POINT(TwinEEngine *engine, LifeScriptContext &ctx) {
engine->_scene->sceneHero->setLife(kActorMaxLife);
- engine->_gameState->inventoryMagicPoints = engine->_gameState->magicLevelIdx * 20;
+ engine->_gameState->setMaxMagicPoints();
return 0;
}
diff --git a/engines/twine/twine.cpp b/engines/twine/twine.cpp
index 1d3b25203c..b1225a6c8b 100644
--- a/engines/twine/twine.cpp
+++ b/engines/twine/twine.cpp
@@ -939,7 +939,7 @@ int32 TwinEEngine::runGameEngine() { // mainLoopInteration
_scene->sceneHero->pos = _scene->newHeroPos;
_scene->needChangeScene = _scene->currentSceneIdx;
- _gameState->inventoryMagicPoints = _gameState->magicLevelIdx * 20;
+ _gameState->setMaxMagicPoints();
_grid->centerOnActor(_scene->sceneHero);
@@ -953,7 +953,7 @@ int32 TwinEEngine::runGameEngine() { // mainLoopInteration
} else { // game over
_gameState->setLeafBoxes(2);
_gameState->setLeafs(1);
- _gameState->setMagicPoints(_gameState->magicLevelIdx * 20);
+ _gameState->setMaxMagicPoints();
_actor->heroBehaviour = _actor->previousHeroBehaviour;
actor->angle = _actor->previousHeroAngle;
actor->setLife(kActorMaxLife);
Commit: 7e5808da5ded6189c6624083c366c89e8221c451
https://github.com/scummvm/scummvm/commit/7e5808da5ded6189c6624083c366c89e8221c451
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2021-03-16T19:26:47+01:00
Commit Message:
AGS: added achievement for astroloco steam
Changed paths:
engines/ags/achievements_tables.h
diff --git a/engines/ags/achievements_tables.h b/engines/ags/achievements_tables.h
index 9857a3a276..f368bf8f8c 100644
--- a/engines/ags/achievements_tables.h
+++ b/engines/ags/achievements_tables.h
@@ -111,6 +111,35 @@ static const AchievementDescriptionList achievementDescriptionList[] = {
}
},
+ {
+ "astroloco",
+ Common::STEAM_ACHIEVEMENTS,
+ "357490",
+ {
+ ACHIEVEMENT_SIMPLE_ENTRY("NEW_GAME", "New Game", "It's all downhill from here."),
+ ACHIEVEMENT_SIMPLE_ENTRY("TECH_WHIZZ", "Tech-Whizz", "Get Gary back on his feet within two attempts."),
+ ACHIEVEMENT_SIMPLE_ENTRY("DONT_GET_COCKY", "Don't Get Cocky", "Defeat the marauding pirates."),
+ ACHIEVEMENT_SIMPLE_ENTRY("BROKEN_PIPE_DREAMS", "Broken Pipe Dreams", "Discover the pipe of your dreams."),
+ ACHIEVEMENT_SIMPLE_ENTRY("SUBATOMIC_FAMILY", "subAtomic Family", "Find the family from a previous game."),
+ ACHIEVEMENT_SIMPLE_ENTRY("THOROUGH_INVESTIGATION", "Thorough Investigation", "Diligently examine the contents of a locked cupboard."),
+ ACHIEVEMENT_SIMPLE_ENTRY("THE_KING_IN_THE_NORTH", "The King in the North", "Find an old friend within the Request-O-Matic."),
+ ACHIEVEMENT_SIMPLE_ENTRY("MONKEYING_AROUND", "Monkeying Around", "Find a sweet poster for a previous game."),
+ ACHIEVEMENT_SIMPLE_ENTRY("WIRETAP", "Wiretap", "Remotely remind a criminal that he's being watched."),
+ ACHIEVEMENT_SIMPLE_ENTRY("NO_MORE_HICCUPS", "No More Hiccups", "You're getting really good at holding your breath!"),
+ ACHIEVEMENT_SIMPLE_ENTRY("UNWANTED_GUEST", "Unwanted Guest", "Create your own 'Knock-Knock' joke."),
+ ACHIEVEMENT_SIMPLE_ENTRY("RECURRING_NIGHTMARE", "Recurring Nightmare", "This guy always bounces back!"),
+ ACHIEVEMENT_SIMPLE_ENTRY("BEHIND_THE_SCENES", "Behind the Scenes", "Our game has commentary! Are we cool yet?"),
+ ACHIEVEMENT_SIMPLE_ENTRY("ANTISOCIAL", "Antisocial", "That's no way to greet someone new!"),
+ ACHIEVEMENT_SIMPLE_ENTRY("THE_OTHER_SIDE", "The Other Side", "See things from someone else's point of view."),
+ ACHIEVEMENT_SIMPLE_ENTRY("INDECISIVE", "Indecisive", "You're in two minds on the matter."),
+ ACHIEVEMENT_SIMPLE_ENTRY("VIOLENT_TENDENCIES", "Violent Tendencies", "See the violence inherent in the system!"),
+ ACHIEVEMENT_SIMPLE_ENTRY("FOLLOW_THE_MONEY", "Follow the Money", "Find and follow the trail of gold."),
+ ACHIEVEMENT_SIMPLE_ENTRY("TUNNEL_VISION", "Tunnel Vision", "Find all five hidden trains."),
+ ACHIEVEMENT_SIMPLE_ENTRY("CRACK_SHOT", "Crack Shot", "Find all five hidden targets."),
+ ACHIEVEMENTS_LISTEND
+ }
+ },
+
{
"atotkdeluxe",
Common::STEAM_ACHIEVEMENTS,
Commit: 0a54429a7ee7eb09e908e959d828a16dd15800af
https://github.com/scummvm/scummvm/commit/0a54429a7ee7eb09e908e959d828a16dd15800af
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2021-03-16T19:26:47+01:00
Commit Message:
TWINE: reuse the cached AnimData
Changed paths:
engines/twine/menu/menu.cpp
engines/twine/scene/animations.cpp
engines/twine/scene/animations.h
diff --git a/engines/twine/menu/menu.cpp b/engines/twine/menu/menu.cpp
index 8d66c06181..949d24a632 100644
--- a/engines/twine/menu/menu.cpp
+++ b/engines/twine/menu/menu.cpp
@@ -976,7 +976,8 @@ void Menu::drawBehaviour(int32 left, int32 top, HeroBehaviourType behaviour, int
}
void Menu::prepareAndDrawBehaviour(int32 left, int32 top, int32 angle, HeroBehaviourType behaviour, Common::Rect &dirtyRect) {
- _engine->_animations->setAnimAtKeyframe(behaviourAnimState[(byte)behaviour], _engine->_resources->animTable[_engine->_actor->heroAnimIdx[(byte)behaviour]], behaviourEntity, &behaviourAnimData[(byte)behaviour]);
+ const int animIdx = _engine->_actor->heroAnimIdx[(byte)behaviour];
+ _engine->_animations->setAnimAtKeyframe(behaviourAnimState[(byte)behaviour], _engine->_resources->animData[animIdx], _engine->_resources->animTable[animIdx], behaviourEntity, &behaviourAnimData[(byte)behaviour]);
drawBehaviour(left, top, behaviour, angle, false, dirtyRect);
}
@@ -1033,7 +1034,8 @@ void Menu::processBehaviourMenu() {
HeroBehaviourType tmpHeroBehaviour = _engine->_actor->heroBehaviour;
- _engine->_animations->setAnimAtKeyframe(behaviourAnimState[(byte)_engine->_actor->heroBehaviour], _engine->_resources->animTable[_engine->_actor->heroAnimIdx[(byte)_engine->_actor->heroBehaviour]], behaviourEntity, &behaviourAnimData[(byte)_engine->_actor->heroBehaviour]);
+ const int animIdx = _engine->_actor->heroAnimIdx[(byte)_engine->_actor->heroBehaviour];
+ _engine->_animations->setAnimAtKeyframe(behaviourAnimState[(byte)_engine->_actor->heroBehaviour], _engine->_resources->animData[animIdx], _engine->_resources->animTable[animIdx], behaviourEntity, &behaviourAnimData[(byte)_engine->_actor->heroBehaviour]);
int32 tmpTime = _engine->lbaTime;
@@ -1078,7 +1080,8 @@ void Menu::processBehaviourMenu() {
drawBehaviour(left, top, tmpHeroBehaviour, _engine->_scene->sceneHero->angle, true, dirtyRect);
tmpHeroBehaviour = _engine->_actor->heroBehaviour;
_engine->_movements->setActorAngleSafe(_engine->_scene->sceneHero->angle, _engine->_scene->sceneHero->angle - ANGLE_90, ANGLE_17, &moveMenu);
- _engine->_animations->setAnimAtKeyframe(behaviourAnimState[(byte)_engine->_actor->heroBehaviour], _engine->_resources->animTable[_engine->_actor->heroAnimIdx[(byte)_engine->_actor->heroBehaviour]], behaviourEntity, &behaviourAnimData[(byte)_engine->_actor->heroBehaviour]);
+ const int tmpAnimIdx = _engine->_actor->heroAnimIdx[(byte)_engine->_actor->heroBehaviour];
+ _engine->_animations->setAnimAtKeyframe(behaviourAnimState[(byte)_engine->_actor->heroBehaviour], _engine->_resources->animData[tmpAnimIdx], _engine->_resources->animTable[tmpAnimIdx], behaviourEntity, &behaviourAnimData[(byte)_engine->_actor->heroBehaviour]);
}
drawBehaviour(left, top, _engine->_actor->heroBehaviour, -1, true, dirtyRect);
diff --git a/engines/twine/scene/animations.cpp b/engines/twine/scene/animations.cpp
index 96aaa2bd1a..0e2328d3ff 100644
--- a/engines/twine/scene/animations.cpp
+++ b/engines/twine/scene/animations.cpp
@@ -202,13 +202,11 @@ bool Animations::setModelAnimation(int32 keyframeIdx, const AnimData &animData,
return false;
}
-void Animations::setAnimAtKeyframe(int32 keyframeIdx, const uint8 *animPtr, uint8 *const bodyPtr, AnimTimerDataStruct *animTimerDataPtr) {
+void Animations::setAnimAtKeyframe(int32 keyframeIdx, const AnimData &animData, const uint8 *animPtr, uint8 *const bodyPtr, AnimTimerDataStruct *animTimerDataPtr) {
if (!Model::isAnimated(bodyPtr)) {
return;
}
- AnimData animData;
- animData.loadFromBuffer(animPtr, 100000);
const int32 numOfKeyframeInAnim = animData.getKeyframes().size();
if (keyframeIdx < 0 || keyframeIdx >= numOfKeyframeInAnim) {
return;
@@ -473,7 +471,7 @@ bool Animations::initAnim(AnimationTypes newAnim, int16 animType, AnimationTypes
if (actor->previousAnimIdx == -1) {
// if no previous animation
- setAnimAtKeyframe(0, _engine->_resources->animTable[animIndex], _engine->_actor->bodyTable[actor->entity], &actor->animTimerData);
+ setAnimAtKeyframe(0, _engine->_resources->animData[animIndex], _engine->_resources->animTable[animIndex], _engine->_actor->bodyTable[actor->entity], &actor->animTimerData);
} else {
// interpolation between animations
stockAnimation(_engine->_actor->bodyTable[actor->entity], &actor->animTimerData);
diff --git a/engines/twine/scene/animations.h b/engines/twine/scene/animations.h
index c9ac54d624..d62508cd6b 100644
--- a/engines/twine/scene/animations.h
+++ b/engines/twine/scene/animations.h
@@ -78,7 +78,7 @@ public:
* @param bodyPtr Body model poitner
* @param animTimerDataPtr Animation time data
*/
- void setAnimAtKeyframe(int32 keyframeIdx, const uint8 *animPtr, uint8 *const bodyPtr, AnimTimerDataStruct *animTimerDataPtr);
+ void setAnimAtKeyframe(int32 keyframeIdx, const AnimData &animData, const uint8 *animPtr, uint8 *const bodyPtr, AnimTimerDataStruct *animTimerDataPtr);
const uint8 *getKeyFrameData(int32 frameIdx, const uint8 *animPtr);
Commit: 46d7373671b4730e05950df752b5360bc55e939f
https://github.com/scummvm/scummvm/commit/46d7373671b4730e05950df752b5360bc55e939f
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2021-03-16T19:26:47+01:00
Commit Message:
TWINE: use AnimData for updating animations
Changed paths:
engines/twine/scene/actor.h
engines/twine/scene/animations.cpp
engines/twine/scene/animations.h
diff --git a/engines/twine/scene/actor.h b/engines/twine/scene/actor.h
index c9775833d5..cfa320d754 100644
--- a/engines/twine/scene/actor.h
+++ b/engines/twine/scene/actor.h
@@ -24,6 +24,7 @@
#define TWINE_ACTOR_H
#include "common/scummsys.h"
+#include "twine/parser/anim.h"
#include "twine/parser/body.h"
#include "twine/parser/entity.h"
#include "twine/shared.h"
@@ -72,7 +73,7 @@ struct ZVBox {
/** Actors animation timer structure */
struct AnimTimerDataStruct {
- const uint8 *ptr = nullptr;
+ const KeyFrame *ptr = nullptr;
int32 time = 0;
};
diff --git a/engines/twine/scene/animations.cpp b/engines/twine/scene/animations.cpp
index 0e2328d3ff..512858b67e 100644
--- a/engines/twine/scene/animations.cpp
+++ b/engines/twine/scene/animations.cpp
@@ -51,12 +51,10 @@ static const int32 magicLevelStrengthOfHit[] = {
MagicballStrengthType::kFireBallStrength,
0};
-Animations::Animations(TwinEEngine *engine) : _engine(engine), animBuffer((uint8 *)malloc(5000 * sizeof(uint8))) {
- animBufferPos = animBuffer;
+Animations::Animations(TwinEEngine *engine) : _engine(engine) {
}
Animations::~Animations() {
- free(animBuffer);
}
int32 Animations::getBodyAnimIndex(AnimationTypes animIdx, int32 actorIdx) {
@@ -75,9 +73,9 @@ const uint8 *Animations::getKeyFrameData(int32 frameIdx, const uint8 *animPtr) {
return (const uint8 *)((numOfBonesInAnim * 8 + 8) * frameIdx + animPtr + 8);
}
-void Animations::applyAnimStepRotation(uint8 *ptr, int32 deltaTime, int32 keyFrameLength, const uint8 *keyFramePtr, const uint8 *lastKeyFramePtr) {
- const int16 lastAngle = ClampAngle(READ_LE_INT16(lastKeyFramePtr));
- const int16 newAngle = ClampAngle(READ_LE_INT16(keyFramePtr));
+void Animations::applyAnimStepRotation(uint8 *ptr, int32 deltaTime, int32 keyFrameLength, int16 newAngle1, int16 lastAngle1) {
+ const int16 lastAngle = ClampAngle(lastAngle1);
+ const int16 newAngle = ClampAngle(newAngle1);
int16 angleDiff = newAngle - lastAngle;
@@ -97,10 +95,7 @@ void Animations::applyAnimStepRotation(uint8 *ptr, int32 deltaTime, int32 keyFra
*(int16 *)ptr = ClampAngle(computedAngle);
}
-void Animations::applyAnimStepTranslation(uint8 *ptr, int32 deltaTime, int32 keyFrameLength, const uint8 *keyFramePtr, const uint8 *lastKeyFramePtr) {
- int16 lastPos = READ_LE_INT16(lastKeyFramePtr);
- int16 newPos = READ_LE_INT16(keyFramePtr);
-
+void Animations::applyAnimStepTranslation(uint8 *ptr, int32 deltaTime, int32 keyFrameLength, int16 newPos, int16 lastPos) {
int16 distance = newPos - lastPos;
int16 computedPos;
@@ -113,8 +108,7 @@ void Animations::applyAnimStepTranslation(uint8 *ptr, int32 deltaTime, int32 key
*(int16 *)ptr = computedPos;
}
-int32 Animations::getAnimMode(uint8 *ptr, const uint8 *keyFramePtr) {
- const int16 opcode = READ_LE_INT16(keyFramePtr);
+int32 Animations::getAnimMode(uint8 *ptr, uint16 opcode) {
*(int16 *)ptr = opcode;
return opcode;
}
@@ -140,11 +134,10 @@ bool Animations::setModelAnimation(int32 keyframeIdx, const AnimData &animData,
}
const int32 keyFrameLength = keyFrame->length;
- const uint8 *keyFramePtr = getKeyFrameData(keyframeIdx, animPtr);
- const uint8 *lastKeyFramePtr = animTimerDataPtr->ptr;
+ const KeyFrame *lastKeyFramePtr = animTimerDataPtr->ptr;
int32 remainingFrameTime = animTimerDataPtr->time;
if (lastKeyFramePtr == nullptr) {
- lastKeyFramePtr = keyFramePtr;
+ lastKeyFramePtr = keyFrame;
remainingFrameTime = keyFrameLength;
}
const int32 deltaTime = _engine->lbaTime - remainingFrameTime;
@@ -158,44 +151,43 @@ bool Animations::setModelAnimation(int32 keyframeIdx, const AnimData &animData,
WRITE_LE_INT16(bonesPtr + 6, boneframe.z);
}
- animTimerDataPtr->ptr = keyFramePtr;
+ animTimerDataPtr->ptr = keyFrame;
animTimerDataPtr->time = _engine->lbaTime;
return true;
}
processLastRotationAngle = (processLastRotationAngle * deltaTime) / keyFrameLength;
- lastKeyFramePtr += 16;
- keyFramePtr += 16;
if (numOfBonesInAnim <= 1) {
return false;
}
+ int16 boneIdx = 1;
int16 tmpNumOfPoints = numOfBonesInAnim - 1;
- int boneIdx = 1;
do {
uint8 *const bonesPtr = Model::getBonesStateData(bodyPtr, boneIdx);
- const int16 animOpcode = getAnimMode(bonesPtr + 0, keyFramePtr + 0);
+ const BoneFrame &boneFrame = keyFrame->boneframes[boneIdx];
+ const BoneFrame &lastBoneFrame = lastKeyFramePtr->boneframes[boneIdx];
+
+ const int16 animOpcode = getAnimMode(bonesPtr + 0, boneFrame.type);
switch (animOpcode) {
case 0: // allow global rotate
- applyAnimStepRotation(bonesPtr + 2, deltaTime, keyFrameLength, keyFramePtr + 2, lastKeyFramePtr + 2);
- applyAnimStepRotation(bonesPtr + 4, deltaTime, keyFrameLength, keyFramePtr + 4, lastKeyFramePtr + 4);
- applyAnimStepRotation(bonesPtr + 6, deltaTime, keyFrameLength, keyFramePtr + 6, lastKeyFramePtr + 6);
+ applyAnimStepRotation(bonesPtr + 2, deltaTime, keyFrameLength, boneFrame.x, lastBoneFrame.x);
+ applyAnimStepRotation(bonesPtr + 4, deltaTime, keyFrameLength, boneFrame.y, lastBoneFrame.y);
+ applyAnimStepRotation(bonesPtr + 6, deltaTime, keyFrameLength, boneFrame.z, lastBoneFrame.z);
break;
case 1: // disallow global rotate
case 2: // disallow global rotate + hide
- applyAnimStepTranslation(bonesPtr + 2, deltaTime, keyFrameLength, keyFramePtr + 2, lastKeyFramePtr + 2);
- applyAnimStepTranslation(bonesPtr + 4, deltaTime, keyFrameLength, keyFramePtr + 4, lastKeyFramePtr + 4);
- applyAnimStepTranslation(bonesPtr + 6, deltaTime, keyFrameLength, keyFramePtr + 6, lastKeyFramePtr + 6);
+ applyAnimStepTranslation(bonesPtr + 2, deltaTime, keyFrameLength, boneFrame.x, lastBoneFrame.x);
+ applyAnimStepTranslation(bonesPtr + 4, deltaTime, keyFrameLength, boneFrame.y, lastBoneFrame.y);
+ applyAnimStepTranslation(bonesPtr + 6, deltaTime, keyFrameLength, boneFrame.z, lastBoneFrame.z);
break;
default:
error("Unsupported animation rotation mode %d", animOpcode);
}
- lastKeyFramePtr += 8;
- keyFramePtr += 8;
++boneIdx;
} while (--tmpNumOfPoints);
@@ -221,7 +213,7 @@ void Animations::setAnimAtKeyframe(int32 keyframeIdx, const AnimData &animData,
processRotationByAnim = keyFrame->boneframes[0].type;
processLastRotationAngle = ToAngle(keyFrame->boneframes[0].y);
- animTimerDataPtr->ptr = getKeyFrameData(keyframeIdx, animPtr);
+ animTimerDataPtr->ptr = animData.getKeyframe(keyframeIdx);
animTimerDataPtr->time = _engine->lbaTime;
const int16 numBones = Model::getNumBones(bodyPtr);
@@ -248,26 +240,26 @@ void Animations::stockAnimation(const uint8 *bodyPtr, AnimTimerDataStruct *animT
return;
}
+ if (animKeyframeBufIdx >= ARRAYSIZE(animKeyframeBuf)) {
+ animKeyframeBufIdx = 0;
+ }
animTimerDataPtr->time = _engine->lbaTime;
- animTimerDataPtr->ptr = animBufferPos;
+ KeyFrame *keyframe = &animKeyframeBuf[animKeyframeBufIdx++];
+ keyframe->boneframes.clear();
+ animTimerDataPtr->ptr = keyframe;
const int32 numBones = Model::getNumBones(bodyPtr);
-
- uint8 *bonesPtr = animBufferPos + 8;
+ keyframe->boneframes.reserve(numBones);
for (int32 i = 0; i < numBones; ++i) {
- const uint8 *ptrToData = Model::getBonesStateData(bodyPtr, i);
+ const uint16 *ptrToData = (const uint16*)Model::getBonesStateData(bodyPtr, i);
// these are 4 int16 values, type, x, y and z
- for (int32 j = 0; j < 8; j++) {
- *bonesPtr++ = *ptrToData++;
- }
- }
-
- // 8 = 4xint16 - firstpoint, numpoints, basepoint, baseelement - see elementEntry
- animBufferPos += (numBones * 8) + 8;
-
- if (animBuffer + (560 * 8) + 8 < animBufferPos) {
- animBufferPos = animBuffer;
+ BoneFrame boneFrame;
+ boneFrame.type = ptrToData[0];
+ boneFrame.x = ptrToData[1];
+ boneFrame.y = ptrToData[2];
+ boneFrame.z = ptrToData[3];
+ keyframe->boneframes.push_back(boneFrame);
}
}
@@ -291,7 +283,7 @@ bool Animations::verifyAnimAtKeyframe(int32 keyframeIdx, const AnimData &animDat
processLastRotationAngle = ToAngle(boneFrame.y);
if (deltaTime >= keyFrameLength) {
- animTimerDataPtr->ptr = getKeyFrameData(keyframeIdx, animPtr);
+ animTimerDataPtr->ptr = animData.getKeyframe(keyframeIdx);
animTimerDataPtr->time = _engine->lbaTime;
return true;
}
diff --git a/engines/twine/scene/animations.h b/engines/twine/scene/animations.h
index d62508cd6b..05b69d034f 100644
--- a/engines/twine/scene/animations.h
+++ b/engines/twine/scene/animations.h
@@ -34,9 +34,9 @@ class TwinEEngine;
class Animations {
private:
TwinEEngine *_engine;
- void applyAnimStepRotation(uint8 *ptr, int32 deltaTime, int32 keyFrameLength, const uint8 *keyFramePtr, const uint8 *lastKeyFramePtr);
- void applyAnimStepTranslation(uint8 *ptr, int32 deltaTime, int32 keyFrameLength, const uint8 *keyFramePtr, const uint8 *lastKeyFramePtr);
- int32 getAnimMode(uint8 *ptr, const uint8 *keyFramePtr);
+ void applyAnimStepRotation(uint8 *ptr, int32 deltaTime, int32 keyFrameLength, int16 newAngle1, int16 lastAngle1);
+ void applyAnimStepTranslation(uint8 *ptr, int32 deltaTime, int32 keyFrameLength, int16 newPos, int16 lastPos);
+ int32 getAnimMode(uint8 *ptr, uint16 opcode);
/**
* Verify animation at keyframe
@@ -47,8 +47,8 @@ private:
*/
bool verifyAnimAtKeyframe(int32 keyframeIdx, const AnimData &animData, const uint8 *animPtr, AnimTimerDataStruct *animTimerDataPtr);
- uint8 *const animBuffer;
- uint8 *animBufferPos = nullptr;
+ int animKeyframeBufIdx = 0;
+ KeyFrame animKeyframeBuf[32];
/** Rotation by anim and not by engine */
int16 processRotationByAnim = 0; // processActorVar5
@@ -78,7 +78,7 @@ public:
* @param bodyPtr Body model poitner
* @param animTimerDataPtr Animation time data
*/
- void setAnimAtKeyframe(int32 keyframeIdx, const AnimData &animData, const uint8 *animPtr, uint8 *const bodyPtr, AnimTimerDataStruct *animTimerDataPtr);
+ void setAnimAtKeyframe(int32 keyframeIdx, const AnimData &animData,const uint8 *animPtr, uint8 *const bodyPtr, AnimTimerDataStruct *animTimerDataPtr);
const uint8 *getKeyFrameData(int32 frameIdx, const uint8 *animPtr);
Commit: 9ba86d91def044d6104047a33b35da5a9fb87753
https://github.com/scummvm/scummvm/commit/9ba86d91def044d6104047a33b35da5a9fb87753
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2021-03-16T19:26:47+01:00
Commit Message:
TWINE: removed raw anim data buffers
Changed paths:
engines/twine/holomap.cpp
engines/twine/menu/menu.cpp
engines/twine/renderer/redraw.cpp
engines/twine/resources/resources.cpp
engines/twine/resources/resources.h
engines/twine/scene/animations.cpp
engines/twine/scene/animations.h
engines/twine/scene/gamestate.cpp
diff --git a/engines/twine/holomap.cpp b/engines/twine/holomap.cpp
index e68e54f1a4..3d89ea5eaa 100644
--- a/engines/twine/holomap.cpp
+++ b/engines/twine/holomap.cpp
@@ -320,10 +320,8 @@ void Holomap::drawHolomapTrajectory(int32 trajectoryIndex) {
_engine->flip();
ActorMoveStruct move;
AnimTimerDataStruct animTimerData;
- uint8 *animPtr = nullptr;
- const int32 animSize = HQR::getAllocEntry(&animPtr, Resources::HQR_RESS_FILE, data.getAnimation());
AnimData animData;
- animData.loadFromBuffer(animPtr, animSize);
+ animData.loadFromHQR(Resources::HQR_RESS_FILE, data.getAnimation());
uint8 *modelPtr = nullptr;
HQR::getAllocEntry(&modelPtr, Resources::HQR_RESS_FILE, data.getModel());
Renderer::prepareIsoModel(modelPtr);
@@ -358,7 +356,7 @@ void Holomap::drawHolomapTrajectory(int32 trajectoryIndex) {
_engine->_movements->setActorAngleSafe(ANGLE_0, -ANGLE_90, 500, &move);
}
- if (_engine->_animations->setModelAnimation(frameNumber, animData, animPtr, modelPtr, &animTimerData)) {
+ if (_engine->_animations->setModelAnimation(frameNumber, animData, modelPtr, &animTimerData)) {
frameNumber++;
if (frameNumber >= animData.getNumKeyframes()) {
frameNumber = animData.getLoopFrame();
@@ -406,7 +404,6 @@ void Holomap::drawHolomapTrajectory(int32 trajectoryIndex) {
_engine->_text->initSceneTextBank();
_engine->_input->enableKeyMap(mainKeyMapId);
- free(animPtr);
free(modelPtr);
}
diff --git a/engines/twine/menu/menu.cpp b/engines/twine/menu/menu.cpp
index 949d24a632..c94906afa4 100644
--- a/engines/twine/menu/menu.cpp
+++ b/engines/twine/menu/menu.cpp
@@ -914,12 +914,11 @@ void Menu::drawBehaviour(int32 left, int32 top, HeroBehaviourType behaviour, int
const Common::Rect &boxRect = calcBehaviourRect(left, top, behaviour);
const int animIdx = _engine->_actor->heroAnimIdx[(byte)behaviour];
- const uint8 *currentAnim = _engine->_resources->animTable[animIdx];
const AnimData ¤tAnimData = _engine->_resources->animData[animIdx];
uint currentAnimState = behaviourAnimState[(byte)behaviour];
- if (_engine->_animations->setModelAnimation(currentAnimState, currentAnimData, currentAnim, behaviourEntity, &behaviourAnimData[(byte)behaviour])) {
+ if (_engine->_animations->setModelAnimation(currentAnimState, currentAnimData, behaviourEntity, &behaviourAnimData[(byte)behaviour])) {
currentAnimState++; // keyframe
if (currentAnimState >= currentAnimData.getNumKeyframes()) {
currentAnimState = currentAnimData.getLoopFrame();
@@ -977,7 +976,7 @@ void Menu::drawBehaviour(int32 left, int32 top, HeroBehaviourType behaviour, int
void Menu::prepareAndDrawBehaviour(int32 left, int32 top, int32 angle, HeroBehaviourType behaviour, Common::Rect &dirtyRect) {
const int animIdx = _engine->_actor->heroAnimIdx[(byte)behaviour];
- _engine->_animations->setAnimAtKeyframe(behaviourAnimState[(byte)behaviour], _engine->_resources->animData[animIdx], _engine->_resources->animTable[animIdx], behaviourEntity, &behaviourAnimData[(byte)behaviour]);
+ _engine->_animations->setAnimAtKeyframe(behaviourAnimState[(byte)behaviour], _engine->_resources->animData[animIdx], behaviourEntity, &behaviourAnimData[(byte)behaviour]);
drawBehaviour(left, top, behaviour, angle, false, dirtyRect);
}
@@ -1035,7 +1034,7 @@ void Menu::processBehaviourMenu() {
HeroBehaviourType tmpHeroBehaviour = _engine->_actor->heroBehaviour;
const int animIdx = _engine->_actor->heroAnimIdx[(byte)_engine->_actor->heroBehaviour];
- _engine->_animations->setAnimAtKeyframe(behaviourAnimState[(byte)_engine->_actor->heroBehaviour], _engine->_resources->animData[animIdx], _engine->_resources->animTable[animIdx], behaviourEntity, &behaviourAnimData[(byte)_engine->_actor->heroBehaviour]);
+ _engine->_animations->setAnimAtKeyframe(behaviourAnimState[(byte)_engine->_actor->heroBehaviour], _engine->_resources->animData[animIdx], behaviourEntity, &behaviourAnimData[(byte)_engine->_actor->heroBehaviour]);
int32 tmpTime = _engine->lbaTime;
@@ -1081,7 +1080,7 @@ void Menu::processBehaviourMenu() {
tmpHeroBehaviour = _engine->_actor->heroBehaviour;
_engine->_movements->setActorAngleSafe(_engine->_scene->sceneHero->angle, _engine->_scene->sceneHero->angle - ANGLE_90, ANGLE_17, &moveMenu);
const int tmpAnimIdx = _engine->_actor->heroAnimIdx[(byte)_engine->_actor->heroBehaviour];
- _engine->_animations->setAnimAtKeyframe(behaviourAnimState[(byte)_engine->_actor->heroBehaviour], _engine->_resources->animData[tmpAnimIdx], _engine->_resources->animTable[tmpAnimIdx], behaviourEntity, &behaviourAnimData[(byte)_engine->_actor->heroBehaviour]);
+ _engine->_animations->setAnimAtKeyframe(behaviourAnimState[(byte)_engine->_actor->heroBehaviour], _engine->_resources->animData[tmpAnimIdx], behaviourEntity, &behaviourAnimData[(byte)_engine->_actor->heroBehaviour]);
}
drawBehaviour(left, top, _engine->_actor->heroBehaviour, -1, true, dirtyRect);
diff --git a/engines/twine/renderer/redraw.cpp b/engines/twine/renderer/redraw.cpp
index 3fba8ebec8..93d8f0c4ec 100644
--- a/engines/twine/renderer/redraw.cpp
+++ b/engines/twine/renderer/redraw.cpp
@@ -342,9 +342,8 @@ void Redraw::processDrawListActors(const DrawListStruct &drawCmd, bool bgRedraw)
const int32 actorIdx = drawCmd.actorIdx;
ActorStruct *actor = _engine->_scene->getActor(actorIdx);
if (actor->previousAnimIdx >= 0) {
- const uint8 *animPtr = _engine->_resources->animTable[actor->previousAnimIdx];
const AnimData &animData = _engine->_resources->animData[actor->previousAnimIdx];
- _engine->_animations->setModelAnimation(actor->animPosition, animData, animPtr, _engine->_actor->bodyTable[actor->entity], &actor->animTimerData);
+ _engine->_animations->setModelAnimation(actor->animPosition, animData, _engine->_actor->bodyTable[actor->entity], &actor->animTimerData);
}
const int32 x = actor->pos.x - _engine->_grid->camera.x;
diff --git a/engines/twine/resources/resources.cpp b/engines/twine/resources/resources.cpp
index b4b9ea9090..5d5e6fece0 100644
--- a/engines/twine/resources/resources.cpp
+++ b/engines/twine/resources/resources.cpp
@@ -40,9 +40,6 @@ Resources::~Resources() {
for (size_t i = 0; i < ARRAYSIZE(spriteTable); ++i) {
free(spriteTable[i]);
}
- for (size_t i = 0; i < ARRAYSIZE(animTable); ++i) {
- free(animTable[i]);
- }
for (size_t i = 0; i < ARRAYSIZE(samplesTable); ++i) {
free(samplesTable[i]);
}
@@ -93,8 +90,7 @@ void Resources::preloadAnimations() {
}
debug("preload %i animations", numEntries);
for (int32 i = 0; i < numEntries; i++) {
- animSizeTable[i] = HQR::getAllocEntry(&animTable[i], Resources::HQR_ANIM_FILE, i);
- animData[i].loadFromBuffer(animTable[i], animSizeTable[i]);
+ animData[i].loadFromHQR(Resources::HQR_ANIM_FILE, i);
}
}
diff --git a/engines/twine/resources/resources.h b/engines/twine/resources/resources.h
index d152470b0f..27a7237aba 100644
--- a/engines/twine/resources/resources.h
+++ b/engines/twine/resources/resources.h
@@ -167,10 +167,6 @@ public:
uint32 spriteSizeTable[NUM_SPRITES] {0};
SpriteData spriteData[NUM_SPRITES];
- /** Table with all loaded animations */
- uint8 *animTable[NUM_ANIMS]{nullptr};
- /** Table with all loaded animations sizes */
- uint32 animSizeTable[NUM_ANIMS]{0};
AnimData animData[NUM_ANIMS];
/** Table with all loaded samples */
diff --git a/engines/twine/scene/animations.cpp b/engines/twine/scene/animations.cpp
index 512858b67e..36cc58401f 100644
--- a/engines/twine/scene/animations.cpp
+++ b/engines/twine/scene/animations.cpp
@@ -54,9 +54,6 @@ static const int32 magicLevelStrengthOfHit[] = {
Animations::Animations(TwinEEngine *engine) : _engine(engine) {
}
-Animations::~Animations() {
-}
-
int32 Animations::getBodyAnimIndex(AnimationTypes animIdx, int32 actorIdx) {
ActorStruct *actor = _engine->_scene->getActor(actorIdx);
EntityData entityData;
@@ -68,11 +65,6 @@ int32 Animations::getBodyAnimIndex(AnimationTypes animIdx, int32 actorIdx) {
return bodyAnimIndex;
}
-const uint8 *Animations::getKeyFrameData(int32 frameIdx, const uint8 *animPtr) {
- const int16 numOfBonesInAnim = READ_LE_INT16(animPtr + 2);
- return (const uint8 *)((numOfBonesInAnim * 8 + 8) * frameIdx + animPtr + 8);
-}
-
void Animations::applyAnimStepRotation(uint8 *ptr, int32 deltaTime, int32 keyFrameLength, int16 newAngle1, int16 lastAngle1) {
const int16 lastAngle = ClampAngle(lastAngle1);
const int16 newAngle = ClampAngle(newAngle1);
@@ -113,7 +105,7 @@ int32 Animations::getAnimMode(uint8 *ptr, uint16 opcode) {
return opcode;
}
-bool Animations::setModelAnimation(int32 keyframeIdx, const AnimData &animData, const uint8 *animPtr, uint8 *const bodyPtr, AnimTimerDataStruct *animTimerDataPtr) {
+bool Animations::setModelAnimation(int32 keyframeIdx, const AnimData &animData, uint8 *const bodyPtr, AnimTimerDataStruct *animTimerDataPtr) {
if (!Model::isAnimated(bodyPtr)) {
return false;
}
@@ -194,7 +186,7 @@ bool Animations::setModelAnimation(int32 keyframeIdx, const AnimData &animData,
return false;
}
-void Animations::setAnimAtKeyframe(int32 keyframeIdx, const AnimData &animData, const uint8 *animPtr, uint8 *const bodyPtr, AnimTimerDataStruct *animTimerDataPtr) {
+void Animations::setAnimAtKeyframe(int32 keyframeIdx, const AnimData &animData, uint8 *const bodyPtr, AnimTimerDataStruct *animTimerDataPtr) {
if (!Model::isAnimated(bodyPtr)) {
return;
}
@@ -263,7 +255,7 @@ void Animations::stockAnimation(const uint8 *bodyPtr, AnimTimerDataStruct *animT
}
}
-bool Animations::verifyAnimAtKeyframe(int32 keyframeIdx, const AnimData &animData, const uint8 *animPtr, AnimTimerDataStruct *animTimerDataPtr) {
+bool Animations::verifyAnimAtKeyframe(int32 keyframeIdx, const AnimData &animData, AnimTimerDataStruct *animTimerDataPtr) {
const KeyFrame *keyFrame = animData.getKeyframe(keyframeIdx);
const int32 keyFrameLength = keyFrame->length;
@@ -463,7 +455,7 @@ bool Animations::initAnim(AnimationTypes newAnim, int16 animType, AnimationTypes
if (actor->previousAnimIdx == -1) {
// if no previous animation
- setAnimAtKeyframe(0, _engine->_resources->animData[animIndex], _engine->_resources->animTable[animIndex], _engine->_actor->bodyTable[actor->entity], &actor->animTimerData);
+ setAnimAtKeyframe(0, _engine->_resources->animData[animIndex], _engine->_actor->bodyTable[actor->entity], &actor->animTimerData);
} else {
// interpolation between animations
stockAnimation(_engine->_actor->bodyTable[actor->entity], &actor->animTimerData);
@@ -593,11 +585,10 @@ void Animations::processActorAnimations(int32 actorIdx) { // DoAnim
} else { // 3D actor
if (actor->previousAnimIdx != -1) {
const AnimData &animData = _engine->_resources->animData[actor->previousAnimIdx];
- const uint8 *animPtr = _engine->_resources->animTable[actor->previousAnimIdx];
bool keyFramePassed = false;
if (Model::isAnimated(_engine->_actor->bodyTable[actor->entity])) {
- keyFramePassed = verifyAnimAtKeyframe(actor->animPosition, animData, animPtr, &actor->animTimerData);
+ keyFramePassed = verifyAnimAtKeyframe(actor->animPosition, animData, &actor->animTimerData);
}
if (processRotationByAnim) {
diff --git a/engines/twine/scene/animations.h b/engines/twine/scene/animations.h
index 05b69d034f..552e0d419f 100644
--- a/engines/twine/scene/animations.h
+++ b/engines/twine/scene/animations.h
@@ -42,10 +42,9 @@ private:
* Verify animation at keyframe
* @param keyframeIdx Animation key frame index
* @param animData Animation data
- * @param animPtr Animation pointer
* @param animTimerDataPtr Animation time data
*/
- bool verifyAnimAtKeyframe(int32 keyframeIdx, const AnimData &animData, const uint8 *animPtr, AnimTimerDataStruct *animTimerDataPtr);
+ bool verifyAnimAtKeyframe(int32 keyframeIdx, const AnimData &animData, AnimTimerDataStruct *animTimerDataPtr);
int animKeyframeBufIdx = 0;
KeyFrame animKeyframeBuf[32];
@@ -64,7 +63,6 @@ private:
public:
Animations(TwinEEngine *engine);
- ~Animations();
/** Current process actor index */
int16 currentlyProcessedActorIdx = 0;
@@ -74,22 +72,20 @@ public:
/**
* Set animation keyframe
* @param keyframIdx Animation keyframe index
- * @param animPtr Pointer to animation
+ * @param animData Animation data
* @param bodyPtr Body model poitner
* @param animTimerDataPtr Animation time data
*/
- void setAnimAtKeyframe(int32 keyframeIdx, const AnimData &animData,const uint8 *animPtr, uint8 *const bodyPtr, AnimTimerDataStruct *animTimerDataPtr);
-
- const uint8 *getKeyFrameData(int32 frameIdx, const uint8 *animPtr);
+ void setAnimAtKeyframe(int32 keyframeIdx, const AnimData &animData, uint8 *const bodyPtr, AnimTimerDataStruct *animTimerDataPtr);
/**
* Set new body animation
* @param keyframeIdx Animation key frame index
- * @param animPtr Animation pointer
+ * @param animData Animation data
* @param bodyPtr Body model poitner
* @param animTimerDataPtr Animation time data
*/
- bool setModelAnimation(int32 keyframeIdx, const AnimData &animData, const uint8 *animPtr, uint8 *const bodyPtr, AnimTimerDataStruct *animTimerDataPtr);
+ bool setModelAnimation(int32 keyframeIdx, const AnimData &animData, uint8 *const bodyPtr, AnimTimerDataStruct *animTimerDataPtr);
/**
* Get entity anim index (This is taken from File3D entities)
diff --git a/engines/twine/scene/gamestate.cpp b/engines/twine/scene/gamestate.cpp
index 2db9ac2af7..70c0db437c 100644
--- a/engines/twine/scene/gamestate.cpp
+++ b/engines/twine/scene/gamestate.cpp
@@ -361,7 +361,6 @@ void GameState::processFoundItem(int32 item) {
_engine->_text->initVoxToPlay(item);
const int32 bodyAnimIdx = _engine->_animations->getBodyAnimIndex(AnimationTypes::kFoundItem);
- const uint8 *currentAnim = _engine->_resources->animTable[bodyAnimIdx];
const AnimData ¤tAnimData = _engine->_resources->animData[bodyAnimIdx];
AnimTimerDataStruct tmpAnimTimer = _engine->_scene->sceneHero->animTimerData;
@@ -392,7 +391,7 @@ void GameState::processFoundItem(int32 item) {
_engine->_interface->resetClip();
initEngineProjections();
- if (_engine->_animations->setModelAnimation(currentAnimState, currentAnimData, currentAnim, bodyPtr, &_engine->_scene->sceneHero->animTimerData)) {
+ if (_engine->_animations->setModelAnimation(currentAnimState, currentAnimData, bodyPtr, &_engine->_scene->sceneHero->animTimerData)) {
currentAnimState++; // keyframe
if (currentAnimState >= currentAnimData.getNumKeyframes()) {
currentAnimState = currentAnimData.getLoopFrame();
Commit: 777ceef714721d829ceeb5ae4b2ed38d7e33308d
https://github.com/scummvm/scummvm/commit/777ceef714721d829ceeb5ae4b2ed38d7e33308d
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2021-03-16T19:26:47+01:00
Commit Message:
TWINE: cleanup in model animation code
Changed paths:
engines/twine/scene/animations.cpp
engines/twine/scene/animations.h
diff --git a/engines/twine/scene/animations.cpp b/engines/twine/scene/animations.cpp
index 36cc58401f..e033dd7974 100644
--- a/engines/twine/scene/animations.cpp
+++ b/engines/twine/scene/animations.cpp
@@ -65,7 +65,7 @@ int32 Animations::getBodyAnimIndex(AnimationTypes animIdx, int32 actorIdx) {
return bodyAnimIndex;
}
-void Animations::applyAnimStepRotation(uint8 *ptr, int32 deltaTime, int32 keyFrameLength, int16 newAngle1, int16 lastAngle1) {
+int16 Animations::applyAnimStepRotation(int32 deltaTime, int32 keyFrameLength, int16 newAngle1, int16 lastAngle1) const {
const int16 lastAngle = ClampAngle(lastAngle1);
const int16 newAngle = ClampAngle(newAngle1);
@@ -84,10 +84,10 @@ void Animations::applyAnimStepRotation(uint8 *ptr, int32 deltaTime, int32 keyFra
computedAngle = lastAngle;
}
- *(int16 *)ptr = ClampAngle(computedAngle);
+ return ClampAngle(computedAngle);
}
-void Animations::applyAnimStepTranslation(uint8 *ptr, int32 deltaTime, int32 keyFrameLength, int16 newPos, int16 lastPos) {
+int16 Animations::applyAnimStepTranslation(int32 deltaTime, int32 keyFrameLength, int16 newPos, int16 lastPos) const {
int16 distance = newPos - lastPos;
int16 computedPos;
@@ -97,12 +97,7 @@ void Animations::applyAnimStepTranslation(uint8 *ptr, int32 deltaTime, int32 key
computedPos = lastPos;
}
- *(int16 *)ptr = computedPos;
-}
-
-int32 Animations::getAnimMode(uint8 *ptr, uint16 opcode) {
- *(int16 *)ptr = opcode;
- return opcode;
+ return computedPos;
}
bool Animations::setModelAnimation(int32 keyframeIdx, const AnimData &animData, uint8 *const bodyPtr, AnimTimerDataStruct *animTimerDataPtr) {
@@ -158,26 +153,25 @@ bool Animations::setModelAnimation(int32 keyframeIdx, const AnimData &animData,
int16 boneIdx = 1;
int16 tmpNumOfPoints = numOfBonesInAnim - 1;
do {
- uint8 *const bonesPtr = Model::getBonesStateData(bodyPtr, boneIdx);
+ BoneFrame *modelStateBoneFrame = (BoneFrame *)Model::getBonesStateData(bodyPtr, boneIdx);
const BoneFrame &boneFrame = keyFrame->boneframes[boneIdx];
const BoneFrame &lastBoneFrame = lastKeyFramePtr->boneframes[boneIdx];
- const int16 animOpcode = getAnimMode(bonesPtr + 0, boneFrame.type);
-
- switch (animOpcode) {
+ modelStateBoneFrame->type = boneFrame.type;
+ switch (boneFrame.type) {
case 0: // allow global rotate
- applyAnimStepRotation(bonesPtr + 2, deltaTime, keyFrameLength, boneFrame.x, lastBoneFrame.x);
- applyAnimStepRotation(bonesPtr + 4, deltaTime, keyFrameLength, boneFrame.y, lastBoneFrame.y);
- applyAnimStepRotation(bonesPtr + 6, deltaTime, keyFrameLength, boneFrame.z, lastBoneFrame.z);
+ modelStateBoneFrame->x = applyAnimStepRotation(deltaTime, keyFrameLength, boneFrame.x, lastBoneFrame.x);
+ modelStateBoneFrame->y = applyAnimStepRotation(deltaTime, keyFrameLength, boneFrame.y, lastBoneFrame.y);
+ modelStateBoneFrame->z = applyAnimStepRotation(deltaTime, keyFrameLength, boneFrame.z, lastBoneFrame.z);
break;
case 1: // disallow global rotate
case 2: // disallow global rotate + hide
- applyAnimStepTranslation(bonesPtr + 2, deltaTime, keyFrameLength, boneFrame.x, lastBoneFrame.x);
- applyAnimStepTranslation(bonesPtr + 4, deltaTime, keyFrameLength, boneFrame.y, lastBoneFrame.y);
- applyAnimStepTranslation(bonesPtr + 6, deltaTime, keyFrameLength, boneFrame.z, lastBoneFrame.z);
+ modelStateBoneFrame->x = applyAnimStepTranslation(deltaTime, keyFrameLength, boneFrame.x, lastBoneFrame.x);
+ modelStateBoneFrame->y = applyAnimStepTranslation(deltaTime, keyFrameLength, boneFrame.y, lastBoneFrame.y);
+ modelStateBoneFrame->z = applyAnimStepTranslation(deltaTime, keyFrameLength, boneFrame.z, lastBoneFrame.z);
break;
default:
- error("Unsupported animation rotation mode %d", animOpcode);
+ error("Unsupported animation rotation mode %d", boneFrame.type);
}
++boneIdx;
diff --git a/engines/twine/scene/animations.h b/engines/twine/scene/animations.h
index 552e0d419f..33c9bd7c1b 100644
--- a/engines/twine/scene/animations.h
+++ b/engines/twine/scene/animations.h
@@ -34,9 +34,8 @@ class TwinEEngine;
class Animations {
private:
TwinEEngine *_engine;
- void applyAnimStepRotation(uint8 *ptr, int32 deltaTime, int32 keyFrameLength, int16 newAngle1, int16 lastAngle1);
- void applyAnimStepTranslation(uint8 *ptr, int32 deltaTime, int32 keyFrameLength, int16 newPos, int16 lastPos);
- int32 getAnimMode(uint8 *ptr, uint16 opcode);
+ int16 applyAnimStepRotation(int32 deltaTime, int32 keyFrameLength, int16 newAngle1, int16 lastAngle1) const;
+ int16 applyAnimStepTranslation(int32 deltaTime, int32 keyFrameLength, int16 newPos, int16 lastPos) const;
/**
* Verify animation at keyframe
Commit: 565b4d5755417d2b2500aeb95fc1de2cb619676d
https://github.com/scummvm/scummvm/commit/565b4d5755417d2b2500aeb95fc1de2cb619676d
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2021-03-16T19:26:47+01:00
Commit Message:
TWINE: cleanup in handling the bone states of the model animation
Changed paths:
engines/twine/renderer/renderer.h
engines/twine/scene/animations.cpp
diff --git a/engines/twine/renderer/renderer.h b/engines/twine/renderer/renderer.h
index d64d40efda..5bae463f7f 100644
--- a/engines/twine/renderer/renderer.h
+++ b/engines/twine/renderer/renderer.h
@@ -146,12 +146,12 @@ struct Model {
return verticesBase + 2 + numVertices * 6;
}
- static const uint8 *getBonesStateData(const uint8 *bodyPtr, int boneIdx) {
- return getBonesBaseData(bodyPtr) + 8 + (boneIdx * 38);
+ static const BoneFrame *getBonesStateData(const uint8 *bodyPtr, int boneIdx) {
+ return (const BoneFrame*)(getBonesBaseData(bodyPtr) + 8 + (boneIdx * 38));
}
- static uint8 *getBonesStateData(uint8 *bodyPtr, int boneIdx) {
- return getBonesBaseData(bodyPtr) + 8 + (boneIdx * 38);
+ static BoneFrame *getBonesStateData(uint8 *bodyPtr, int boneIdx) {
+ return (BoneFrame*)(getBonesBaseData(bodyPtr) + 8 + (boneIdx * 38));
}
static BoneFrame *getBonesStateData(BodyData &bodyPtr, int boneIdx) {
diff --git a/engines/twine/scene/animations.cpp b/engines/twine/scene/animations.cpp
index e033dd7974..e5d01829c8 100644
--- a/engines/twine/scene/animations.cpp
+++ b/engines/twine/scene/animations.cpp
@@ -130,12 +130,8 @@ bool Animations::setModelAnimation(int32 keyframeIdx, const AnimData &animData,
const int32 deltaTime = _engine->lbaTime - remainingFrameTime;
if (deltaTime >= keyFrameLength) {
for (int32 i = 0; i < numOfBonesInAnim; ++i) {
- const BoneFrame &boneframe = keyFrame->boneframes[i];
- uint8 *bonesPtr = Model::getBonesStateData(bodyPtr, i);
- WRITE_LE_UINT16(bonesPtr + 0, boneframe.type);
- WRITE_LE_INT16(bonesPtr + 2, boneframe.x);
- WRITE_LE_INT16(bonesPtr + 4, boneframe.y);
- WRITE_LE_INT16(bonesPtr + 6, boneframe.z);
+ BoneFrame *boneState = Model::getBonesStateData(bodyPtr, i);
+ *boneState = keyFrame->boneframes[i];
}
animTimerDataPtr->ptr = keyFrame;
@@ -210,12 +206,8 @@ void Animations::setAnimAtKeyframe(int32 keyframeIdx, const AnimData &animData,
}
for (int32 i = 0; i < numOfBonesInAnim; ++i) {
- const BoneFrame &boneframe = keyFrame->boneframes[i];
- uint8 *bonesPtr = Model::getBonesStateData(bodyPtr, i);
- WRITE_LE_UINT16(bonesPtr + 0, boneframe.type);
- WRITE_LE_INT16(bonesPtr + 2, boneframe.x);
- WRITE_LE_INT16(bonesPtr + 4, boneframe.y);
- WRITE_LE_INT16(bonesPtr + 6, boneframe.z);
+ BoneFrame *boneState = Model::getBonesStateData(bodyPtr, i);
+ *boneState = keyFrame->boneframes[i];
}
return;
@@ -238,14 +230,7 @@ void Animations::stockAnimation(const uint8 *bodyPtr, AnimTimerDataStruct *animT
keyframe->boneframes.reserve(numBones);
for (int32 i = 0; i < numBones; ++i) {
- const uint16 *ptrToData = (const uint16*)Model::getBonesStateData(bodyPtr, i);
- // these are 4 int16 values, type, x, y and z
- BoneFrame boneFrame;
- boneFrame.type = ptrToData[0];
- boneFrame.x = ptrToData[1];
- boneFrame.y = ptrToData[2];
- boneFrame.z = ptrToData[3];
- keyframe->boneframes.push_back(boneFrame);
+ keyframe->boneframes.push_back(*Model::getBonesStateData(bodyPtr, i));
}
}
More information about the Scummvm-git-logs
mailing list