Permalink
Browse files

Try to be more consistent with gameTime usage.

When updating the game state, we now determine what happened in the interval
[gameTime - deltaGameTime + 1; gameTime]. The time gameTime - deltaGameTime is now
considered to be in the past, so the game state may be modified at time
gameTime - deltaGameTime + 1, at the earliest.

During GAME_* message processing, deltaGameTime is 0, however it is still considered
valid to change the game state at gameTime - deltaGameTime + 1, since that will lie
within the following update interval.

Refs ticket:3175.
  • Loading branch information...
1 parent e5e0f72 commit f6dce9d6322f8d2309922dc58a31ce21c4bdaafe @Cyp Cyp committed Feb 24, 2012
Showing with 32 additions and 31 deletions.
  1. +1 −1 lib/gamelib/animobj.cpp
  2. +3 −3 src/combat.cpp
  3. +4 −4 src/component.cpp
  4. +6 −6 src/droid.cpp
  5. +1 −1 src/feature.cpp
  6. +1 −1 src/move.cpp
  7. +1 −1 src/multibot.cpp
  8. +1 −1 src/multiplay.cpp
  9. +1 −1 src/multistruct.cpp
  10. +2 −2 src/objmem.cpp
  11. +2 −1 src/projectile.cpp
  12. +1 −1 src/projectiledef.h
  13. +8 −8 src/structure.cpp
View
@@ -221,7 +221,7 @@ animObj_Add( void *pParentObj, int iAnimID,
/* init object */
psObj->uwID = (UWORD) iAnimID;
psObj->psAnim = (ANIM3D *) psAnim;
- psObj->udwStartTime = gameTime - deltaGameTime; // Start animation at beginning of update period.
+ psObj->udwStartTime = gameTime - deltaGameTime + 1; // Start animation at beginning of update period.
psObj->udwStartDelay = udwStartDelay;
psObj->uwCycles = uwCycles;
psObj->bVisible = true;
View
@@ -72,13 +72,13 @@ bool combFire(WEAPON *psWeap, BASE_OBJECT *psAttacker, BASE_OBJECT *psTarget, in
return false;
}
- unsigned fireTime = gameTime - deltaGameTime; // Can fire earliest at the start of the tick.
+ unsigned fireTime = gameTime - deltaGameTime + 1; // Can fire earliest at the start of the tick.
/*see if reload-able weapon and out of ammo*/
if (psStats->reloadTime && !psWeap->ammo)
{
fireTime = std::max(fireTime, psWeap->lastFired + weaponReloadTime(psStats, psAttacker->player));
- if (gameTime <= fireTime)
+ if (gameTime < fireTime)
{
return false;
}
@@ -91,7 +91,7 @@ bool combFire(WEAPON *psWeap, BASE_OBJECT *psAttacker, BASE_OBJECT *psTarget, in
firePause = std::max(firePause, 1u); // Don't shoot infinitely many shots at once.
fireTime = std::max(fireTime, psWeap->lastFired + firePause);
- if (gameTime <= fireTime)
+ if (gameTime < fireTime)
{
/* Too soon to fire again */
return false;
View
@@ -1156,10 +1156,10 @@ void compPersonToBits(DROID *psDroid)
/* Tell about player colour */
col = getPlayerColour(psDroid->player);
- addEffect(&position, EFFECT_GRAVITON, GRAVITON_TYPE_GIBLET, true, headImd, col, gameTime - deltaGameTime);
- addEffect(&position, EFFECT_GRAVITON, GRAVITON_TYPE_GIBLET, true, legsImd, col, gameTime - deltaGameTime);
- addEffect(&position, EFFECT_GRAVITON, GRAVITON_TYPE_GIBLET, true, armImd, col, gameTime - deltaGameTime);
- addEffect(&position, EFFECT_GRAVITON, GRAVITON_TYPE_GIBLET, true, bodyImd, col, gameTime - deltaGameTime);
+ addEffect(&position, EFFECT_GRAVITON, GRAVITON_TYPE_GIBLET, true, headImd, col, gameTime - deltaGameTime + 1);
+ addEffect(&position, EFFECT_GRAVITON, GRAVITON_TYPE_GIBLET, true, legsImd, col, gameTime - deltaGameTime + 1);
+ addEffect(&position, EFFECT_GRAVITON, GRAVITON_TYPE_GIBLET, true, armImd, col, gameTime - deltaGameTime + 1);
+ addEffect(&position, EFFECT_GRAVITON, GRAVITON_TYPE_GIBLET, true, bodyImd, col, gameTime - deltaGameTime + 1);
}
View
@@ -389,7 +389,7 @@ void recycleDroid(DROID *psDroid)
vanishDroid(psDroid);
- addEffect(&position, EFFECT_EXPLOSION, EXPLOSION_TYPE_DISCOVERY, false, NULL, false, gameTime - deltaGameTime);
+ addEffect(&position, EFFECT_EXPLOSION, EXPLOSION_TYPE_DISCOVERY, false, NULL, false, gameTime - deltaGameTime + 1);
CHECK_DROID(psDroid);
}
@@ -794,8 +794,8 @@ void droidUpdate(DROID *psDroid)
emissionInterval = CALC_DROID_SMOKE_INTERVAL(percentDamage);
- int effectTime = std::max(gameTime - deltaGameTime, psDroid->lastEmission + emissionInterval);
- if (gameTime > effectTime)
+ int effectTime = std::max(gameTime - deltaGameTime + 1, psDroid->lastEmission + emissionInterval);
+ if (gameTime >= effectTime)
{
dv.x = psDroid->pos.x + DROID_DAMAGE_SPREAD;
dv.z = psDroid->pos.y + DROID_DAMAGE_SPREAD;
@@ -836,7 +836,7 @@ void droidUpdate(DROID *psDroid)
else
{
// do burn damage
- droidDamage(psDroid, BURN_DAMAGE, WC_HEAT, WSC_FLAME, gameTime - deltaGameTime/2, true);
+ droidDamage(psDroid, BURN_DAMAGE, WC_HEAT, WSC_FLAME, gameTime - deltaGameTime/2 + 1, true);
}
}
@@ -1383,7 +1383,7 @@ bool droidUpdateDroidRepair(DROID *psRepairDroid)
iVecEffect.y = psDroidToRepair->pos.z + rand()%8;;
iVecEffect.z = psDroidToRepair->pos.y + DROID_REPAIR_SPREAD;
effectGiveAuxVar(90+rand()%20);
- addEffect(&iVecEffect, EFFECT_EXPLOSION, EXPLOSION_TYPE_LASER, false, NULL, 0, gameTime - deltaGameTime + rand()%deltaGameTime);
+ addEffect(&iVecEffect, EFFECT_EXPLOSION, EXPLOSION_TYPE_LASER, false, NULL, 0, gameTime - deltaGameTime + 1 + rand()%deltaGameTime);
droidAddWeldSound( iVecEffect );
}
@@ -2009,7 +2009,7 @@ void droidSetBits(DROID_TEMPLATE *pTemplate,DROID *psDroid)
psDroid->body = calcTemplateBody(pTemplate, psDroid->player);
psDroid->originalBody = psDroid->body;
psDroid->expectedDamage = 0; // Begin life optimistically.
- psDroid->time = gameTime - deltaGameTime; // Start at beginning of tick.
+ psDroid->time = gameTime - deltaGameTime + 1; // Start at beginning of tick.
psDroid->prevSpacetime.time = psDroid->time - 1; // -1 for interpolation.
//create the droids weapons
View
@@ -402,7 +402,7 @@ bool removeFeature(FEATURE *psDel)
pos.x = psDel->pos.x;
pos.z = psDel->pos.y;
pos.y = map_Height(pos.x, pos.z) + 30;
- addEffect(&pos, EFFECT_EXPLOSION, EXPLOSION_TYPE_DISCOVERY, false, NULL, 0, gameTime - deltaGameTime);
+ addEffect(&pos, EFFECT_EXPLOSION, EXPLOSION_TYPE_DISCOVERY, false, NULL, 0, gameTime - deltaGameTime + 1);
if (psDel->psStats->subType == FEAT_GEN_ARTE)
{
scoreUpdateVar(WD_ARTEFACTS_FOUND);
View
@@ -2648,7 +2648,7 @@ void moveUpdateDroid(DROID *psDroid)
pos.x = psDroid->pos.x + (18-rand()%36);
pos.z = psDroid->pos.y + (18-rand()%36);
pos.y = psDroid->pos.z + (psDroid->sDisplay.imd->max.y / 3);
- addEffect(&pos, EFFECT_EXPLOSION, EXPLOSION_TYPE_SMALL, false, NULL, 0, gameTime - deltaGameTime);
+ addEffect(&pos, EFFECT_EXPLOSION, EXPLOSION_TYPE_SMALL, false, NULL, 0, gameTime - deltaGameTime + 1);
}
movePlayAudio( psDroid, bStarted, bStopped, moveSpeed );
View
@@ -734,7 +734,7 @@ bool recvDestroyDroid(NETQUEUE queue)
{
turnOffMultiMsg(true);
debug(LOG_DEATH, "Killing droid %d on request from player %d - huh?", psDroid->id, queue.index);
- destroyDroid(psDroid, gameTime);
+ destroyDroid(psDroid, gameTime - deltaGameTime + 1); // deltaGameTime is actually 0 here, since we're between updates. However, the value of gameTime - deltaGameTime + 1 will not change when we start the next tick.
turnOffMultiMsg(false);
}
else
View
@@ -1548,7 +1548,7 @@ bool recvDestroyFeature(NETQUEUE queue)
debug(LOG_FEATURE, "p%d feature id %d destroyed (%s)", pF->player, pF->id, pF->psStats->pName);
// Remove the feature locally
turnOffMultiMsg(true);
- removeFeature(pF);
+ destroyFeature(pF, gameTime - deltaGameTime + 1); // deltaGameTime is actually 0 here, since we're between updates. However, the value of gameTime - deltaGameTime + 1 will not change when we start the next tick.
turnOffMultiMsg(false);
return true;
View
@@ -196,7 +196,7 @@ bool recvDestroyStructure(NETQUEUE queue)
{
turnOffMultiMsg(true);
// Remove the struct from remote players machine
- destroyStruct(psStruct, gameTime);
+ destroyStruct(psStruct, gameTime - deltaGameTime + 1); // deltaGameTime is actually 0 here, since we're between updates. However, the value of gameTime - deltaGameTime + 1 will not change when we start the next tick.
turnOffMultiMsg(false);
// NOTE: I do not think this should be here!
technologyGiveAway(psStruct);
View
@@ -143,7 +143,7 @@ void objmemUpdate(void)
were destroyed before this turn */
/* First remove the objects from the start of the list */
- while (psDestroyedObj != NULL && psDestroyedObj->died < gameTime - deltaGameTime)
+ while (psDestroyedObj != NULL && psDestroyedObj->died <= gameTime - deltaGameTime)
{
psNext = psDestroyedObj->psNext;
objmemDestroy(psDestroyedObj);
@@ -155,7 +155,7 @@ void objmemUpdate(void)
for(psCurr = psPrev = psDestroyedObj; psCurr != NULL; psCurr = psNext)
{
psNext = psCurr->psNext;
- if (psCurr->died < gameTime - deltaGameTime)
+ if (psCurr->died <= gameTime - deltaGameTime)
{
objmemDestroy(psCurr);
View
@@ -896,6 +896,7 @@ static void proj_InFlightFunc(PROJECTILE *psProj)
{
// We hit!
setSpacetime(psProj, closestCollisionSpacetime);
+ psProj->time = std::max(psProj->time, gameTime - deltaGameTime + 1); // Make sure .died gets set in the interval [gameTime - deltaGameTime + 1; gameTime].
if(psProj->time == psProj->prevSpacetime.time)
{
--psProj->prevSpacetime.time;
@@ -1401,7 +1402,7 @@ static void proj_checkBurnDamage(PROJECTILE *psProj)
unsigned damageRate = weaponIncenDamage(psStats,psProj->player);
debug(LOG_NEVER, "Burn damage of %d per second to object %d, player %d\n", damageRate, psCurr->id, psCurr->player);
- int relativeDamage = objectDamage(psCurr, damageRate, psStats->weaponClass, psStats->weaponSubClass, gameTime - deltaGameTime/2, true);
+ int relativeDamage = objectDamage(psCurr, damageRate, psStats->weaponClass, psStats->weaponSubClass, gameTime - deltaGameTime/2 + 1, true);
proj_UpdateKills(psProj, relativeDamage);
}
}
View
@@ -43,7 +43,7 @@ struct PROJECTILE : public SIMPLE_OBJECT
PROJECTILE(uint32_t id, unsigned player) : SIMPLE_OBJECT(OBJ_PROJECTILE, id, player) {}
void update();
- bool deleteIfDead() { if (died == 0 || died > gameTime - deltaGameTime) return false; delete this; return true; }
+ bool deleteIfDead() { if (died == 0 || died >= gameTime - deltaGameTime) return false; delete this; return true; }
UBYTE state; ///< current projectile state
View
@@ -2352,16 +2352,16 @@ static bool structPlaceDroid(STRUCTURE *psStructure, DROID_TEMPLATE *psTempl,
iVecEffect.x = psNewDroid->pos.x;
iVecEffect.y = map_Height( psNewDroid->pos.x, psNewDroid->pos.y ) + DROID_CONSTRUCTION_SMOKE_HEIGHT;
iVecEffect.z = psNewDroid->pos.y;
- addEffect(&iVecEffect, EFFECT_CONSTRUCTION, CONSTRUCTION_TYPE_DRIFTING, false, NULL, 0, gameTime - deltaGameTime);
+ addEffect(&iVecEffect, EFFECT_CONSTRUCTION, CONSTRUCTION_TYPE_DRIFTING, false, NULL, 0, gameTime - deltaGameTime + 1);
iVecEffect.x = psNewDroid->pos.x - DROID_CONSTRUCTION_SMOKE_OFFSET;
iVecEffect.z = psNewDroid->pos.y - DROID_CONSTRUCTION_SMOKE_OFFSET;
- addEffect(&iVecEffect, EFFECT_CONSTRUCTION, CONSTRUCTION_TYPE_DRIFTING, false, NULL, 0, gameTime - deltaGameTime);
+ addEffect(&iVecEffect, EFFECT_CONSTRUCTION, CONSTRUCTION_TYPE_DRIFTING, false, NULL, 0, gameTime - deltaGameTime + 1);
iVecEffect.z = psNewDroid->pos.y + DROID_CONSTRUCTION_SMOKE_OFFSET;
- addEffect(&iVecEffect, EFFECT_CONSTRUCTION, CONSTRUCTION_TYPE_DRIFTING, false, NULL, 0, gameTime - deltaGameTime);
+ addEffect(&iVecEffect, EFFECT_CONSTRUCTION, CONSTRUCTION_TYPE_DRIFTING, false, NULL, 0, gameTime - deltaGameTime + 1);
iVecEffect.x = psNewDroid->pos.x + DROID_CONSTRUCTION_SMOKE_OFFSET;
- addEffect(&iVecEffect, EFFECT_CONSTRUCTION, CONSTRUCTION_TYPE_DRIFTING, false, NULL, 0, gameTime - deltaGameTime);
+ addEffect(&iVecEffect, EFFECT_CONSTRUCTION, CONSTRUCTION_TYPE_DRIFTING, false, NULL, 0, gameTime - deltaGameTime + 1);
iVecEffect.z = psNewDroid->pos.y - DROID_CONSTRUCTION_SMOKE_OFFSET;
- addEffect(&iVecEffect, EFFECT_CONSTRUCTION, CONSTRUCTION_TYPE_DRIFTING, false, NULL, 0, gameTime - deltaGameTime);
+ addEffect(&iVecEffect, EFFECT_CONSTRUCTION, CONSTRUCTION_TYPE_DRIFTING, false, NULL, 0, gameTime - deltaGameTime + 1);
}
/* add the droid to the list */
addDroid(psNewDroid, apsDroidLists);
@@ -3354,7 +3354,7 @@ static void aiUpdateStructure(STRUCTURE *psStructure, bool isMission)
iVecEffect.y = psDroid->pos.z + (10-rand()%20);
iVecEffect.z = psDroid->pos.y + (10-rand()%20);
effectSetSize(100);
- addEffect(&iVecEffect, EFFECT_EXPLOSION, EXPLOSION_TYPE_SPECIFIED, true, getImdFromIndex(MI_FLAME), 0, gameTime - deltaGameTime);
+ addEffect(&iVecEffect, EFFECT_EXPLOSION, EXPLOSION_TYPE_SPECIFIED, true, getImdFromIndex(MI_FLAME), 0, gameTime - deltaGameTime + 1);
}
}
}
@@ -3658,8 +3658,8 @@ void structureUpdate(STRUCTURE *psBuilding, bool mission)
if (damage > 0.)
{
emissionInterval = CalcStructureSmokeInterval(damage/65536.f);
- unsigned effectTime = std::max(gameTime - deltaGameTime, psBuilding->lastEmission + emissionInterval);
- if (gameTime > effectTime)
+ unsigned effectTime = std::max(gameTime - deltaGameTime + 1, psBuilding->lastEmission + emissionInterval);
+ if (gameTime >= effectTime)
{
widthScatter = getStructureWidth(psBuilding) * TILE_UNITS/2/3;
breadthScatter = getStructureBreadth(psBuilding) * TILE_UNITS/2/3;

0 comments on commit f6dce9d

Please sign in to comment.