Skip to content

Commit

Permalink
synch: Don't desynch on destroying droids with animations.
Browse files Browse the repository at this point in the history
Since droidUpdate is a synchronised function, it must not access graphicsTime which
is unsynchronised.

This partially reverts 1ce7e09.
  • Loading branch information
Cyp committed Jun 12, 2017
1 parent 77f9e5c commit 123ded5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/display3d.cpp
Expand Up @@ -332,8 +332,11 @@ void drawShape(BASE_OBJECT *psObj, iIMDShape *strImd, int colour, PIELIGHT build
if (strImd->objanimframes)
{
const int elapsed = graphicsTime - psObj->timeAnimationStarted;
if (elapsed < 0)
{
return; // Animation hasn't started yet.
}
const int frame = (elapsed / strImd->objanimtime) % strImd->objanimframes;
ASSERT(frame < strImd->objanimframes, "Bad index %d >= %d", frame, strImd->objanimframes);
const ANIMFRAME &state = strImd->objanimdata.at(frame);
if (state.scale.x == -1.0f) // disabled frame, for implementing key frame animation
{
Expand Down
4 changes: 2 additions & 2 deletions src/droid.cpp
Expand Up @@ -272,7 +272,7 @@ int32_t droidDamage(DROID *psDroid, unsigned damage, WEAPON_CLASS weaponClass, W
if (psDroid->sDisplay.imd->objanimpie[ANIM_EVENT_DYING] && psDroid->animationEvent != ANIM_EVENT_DYING)
{
debug(LOG_DEATH, "%s droid %d (%p) is starting death animation", objInfo(psDroid), (int)psDroid->id, psDroid);
psDroid->timeAnimationStarted = graphicsTime;
psDroid->timeAnimationStarted = gameTime;
psDroid->animationEvent = ANIM_EVENT_DYING;
if (psDroid->droidType == DROID_PERSON)
{
Expand Down Expand Up @@ -720,7 +720,7 @@ void droidUpdate(DROID *psDroid)
if (psDroid->animationEvent != ANIM_EVENT_NONE)
{
iIMDShape *imd = psDroid->sDisplay.imd->objanimpie[psDroid->animationEvent];
if (imd && imd->objanimcycles > 0 && graphicsTime > psDroid->timeAnimationStarted + imd->objanimtime * imd->objanimcycles)
if (imd && imd->objanimcycles > 0 && gameTime > psDroid->timeAnimationStarted + imd->objanimtime * imd->objanimcycles)
{
// Done animating (animation is defined by body - other components should follow suit)
if (psDroid->animationEvent == ANIM_EVENT_DYING)
Expand Down
6 changes: 3 additions & 3 deletions src/move.cpp
Expand Up @@ -1615,7 +1615,7 @@ static void moveUpdatePersonModel(DROID *psDroid, SDWORD speed, uint16_t directi
psDroid->action == DACTION_ROTATETOATTACK)
&& psDroid->animationEvent == ANIM_EVENT_NONE)
{
psDroid->timeAnimationStarted = graphicsTime;
psDroid->timeAnimationStarted = gameTime;
psDroid->animationEvent = ANIM_EVENT_FIRING;
}
else if (psDroid->animationEvent == ANIM_EVENT_ACTIVE)
Expand Down Expand Up @@ -1650,7 +1650,7 @@ static void moveUpdatePersonModel(DROID *psDroid, SDWORD speed, uint16_t directi
/* update anim if moving and not shooting */
if (psDroid->droidType == DROID_PERSON && speed != 0 && psDroid->animationEvent == ANIM_EVENT_NONE)
{
psDroid->timeAnimationStarted = graphicsTime;
psDroid->timeAnimationStarted = gameTime;
psDroid->animationEvent = ANIM_EVENT_ACTIVE;
}

Expand Down Expand Up @@ -1782,7 +1782,7 @@ static void moveUpdateCyborgModel(DROID *psDroid, SDWORD moveSpeed, uint16_t mov

if (psDroid->animationEvent == ANIM_EVENT_NONE)
{
psDroid->timeAnimationStarted = graphicsTime;
psDroid->timeAnimationStarted = gameTime;
psDroid->animationEvent = ANIM_EVENT_ACTIVE;
}

Expand Down
2 changes: 1 addition & 1 deletion src/structure.cpp
Expand Up @@ -3594,7 +3594,7 @@ void structureUpdate(STRUCTURE *psBuilding, bool mission)
else if (psBuilding->pFunctionality->resourceExtractor.psPowerGen
&& psBuilding->animationEvent == ANIM_EVENT_NONE) // we have a power generator, but no animation
{
psBuilding->timeAnimationStarted = graphicsTime; // so start animation
psBuilding->timeAnimationStarted = gameTime; // so start animation
psBuilding->animationEvent = ANIM_EVENT_ACTIVE;
}
}
Expand Down

0 comments on commit 123ded5

Please sign in to comment.