From a34997239a05e9d2a67cf654b98e1b8bbf479e96 Mon Sep 17 00:00:00 2001 From: Per Inge Mathisen Date: Sat, 14 Aug 2010 12:06:14 +0000 Subject: [PATCH] Fixes for game elements improperly being dependent on logical fps. Camera animation. Water animation. Weather animations. Replaced all usages of the generic timeAdjustedIncrement with proper gameTimeAdjustedIncrement or graphicsTimeAdjustedIncrement as appropriate. See ticket:2083 for more info. Patch reviewed by Cyp. git-svn-id: https://warzone2100.svn.sourceforge.net/svnroot/warzone2100/trunk@11457 4a71c877-e1ca-e34f-864e-861f7616d084 --- lib/gamelib/gtime.h | 12 ------------ src/advvis.c | 2 +- src/atmos.c | 6 +++--- src/design.c | 4 ++-- src/intdisplay.c | 9 ++++----- src/keybind.c | 34 ++++++---------------------------- src/lighting.c | 2 +- src/move.c | 4 ++-- src/terrain.c | 2 +- src/visibility.c | 4 ++-- src/warcam.c | 24 ++++++++++++------------ 11 files changed, 34 insertions(+), 69 deletions(-) diff --git a/lib/gamelib/gtime.h b/lib/gamelib/gtime.h index d3bfe3996..2fd48a03a 100644 --- a/lib/gamelib/gtime.h +++ b/lib/gamelib/gtime.h @@ -156,18 +156,6 @@ static inline float realTimeAdjustedIncrement(float value) return value * realTimeFraction; } -/** - * Returns value times deltaGameTime (pauseTime = true) or deltaRealTime (pauseTime = false), converted to seconds. - * @param value Amount to change something in a second. - * @param pauseTime If true, adjust also for pause of game time. Generally use true in-game, false for GUI. - * @return Amount to change this frame. - * TODO Replace all calls to this function with gameTimeAdjustedIncrement or realTimeAdjustedIncrement, and delete this function. - */ -static inline float timeAdjustedIncrement(float value, BOOL pauseTime) -{ - return (pauseTime ? gameTimeAdjustedIncrement : realTimeAdjustedIncrement)(value); -} - #ifdef __cplusplus } #endif //__cplusplus diff --git a/src/advvis.c b/src/advvis.c index 001d42f87..248a8b918 100644 --- a/src/advvis.c +++ b/src/advvis.c @@ -41,7 +41,7 @@ void avUpdateTiles( void ) const int len = mapHeight * mapWidth; const int playermask = 1 << selectedPlayer; UDWORD i = 0; - float maxLevel, increment = timeAdjustedIncrement(FADE_IN_TIME, true); // call once per frame + float maxLevel, increment = graphicsTimeAdjustedIncrement(FADE_IN_TIME); // call once per frame MAPTILE *psTile; /* Go through the tiles */ diff --git a/src/atmos.c b/src/atmos.c index 357668125..7df557143 100644 --- a/src/atmos.c +++ b/src/atmos.c @@ -124,9 +124,9 @@ static void processParticle(ATPART *psPart) if(!gamePaused()) { /* Move the particle - frame rate controlled */ - psPart->position.x += timeAdjustedIncrement(psPart->velocity.x, true); - psPart->position.y += timeAdjustedIncrement(psPart->velocity.y, true); - psPart->position.z += timeAdjustedIncrement(psPart->velocity.z, true); + psPart->position.x += graphicsTimeAdjustedIncrement(psPart->velocity.x); + psPart->position.y += graphicsTimeAdjustedIncrement(psPart->velocity.y); + psPart->position.z += graphicsTimeAdjustedIncrement(psPart->velocity.z); /* Wrap it around if it's gone off grid... */ testParticleWrap(psPart); diff --git a/src/design.c b/src/design.c index f536d71af..7619f4fa4 100644 --- a/src/design.c +++ b/src/design.c @@ -4478,7 +4478,7 @@ static void intDisplayStatForm(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, /* inc rotation if highlighted */ if ( Form->state & WCLICK_HILITE ) { - iRY += timeAdjustedIncrement(BUTTONOBJ_ROTSPEED, false); + iRY += graphicsTimeAdjustedIncrement(BUTTONOBJ_ROTSPEED); iRY %= 360; } @@ -4514,7 +4514,7 @@ static void intDisplayViewForm(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, Rotation.z = 0; /* inc rotation */ - iRY += timeAdjustedIncrement(BUTTONOBJ_ROTSPEED, false); + iRY += graphicsTimeAdjustedIncrement(BUTTONOBJ_ROTSPEED); iRY %= 360; //fixed depth scale the pie diff --git a/src/intdisplay.c b/src/intdisplay.c index 712c4bd7d..138a37e73 100644 --- a/src/intdisplay.c +++ b/src/intdisplay.c @@ -707,7 +707,7 @@ void intDisplayStatusButton(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, WZ Hilight = Form->state & WCLICK_HILITE; if(Hilight) { - Buffer->ImdRotation += timeAdjustedIncrement(BUTTONOBJ_ROTSPEED, false); + Buffer->ImdRotation += graphicsTimeAdjustedIncrement(BUTTONOBJ_ROTSPEED); } Hilight = formIsHilite(Form); // Hilited or flashing. @@ -916,7 +916,7 @@ void intDisplayObjectButton(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, WZ Hilight = Form->state & WCLICK_HILITE; if(Hilight) { - Buffer->ImdRotation += timeAdjustedIncrement(BUTTONOBJ_ROTSPEED, false); + Buffer->ImdRotation += graphicsTimeAdjustedIncrement(BUTTONOBJ_ROTSPEED); } Hilight = formIsHilite(Form); // Hilited or flashing. @@ -994,11 +994,10 @@ void intDisplayStatsButton(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, WZ_ Down = Form->state & (WCLICK_DOWN | WCLICK_LOCKED | WCLICK_CLICKLOCK); { - Hilight = Form->state & WCLICK_HILITE; if(Hilight) { - Buffer->ImdRotation += timeAdjustedIncrement(BUTTONOBJ_ROTSPEED, false); + Buffer->ImdRotation += graphicsTimeAdjustedIncrement(BUTTONOBJ_ROTSPEED); } Hilight = formIsHilite(Form); @@ -3007,7 +3006,7 @@ void intDisplayTransportButton(WIDGET *psWidget, UDWORD xOffset, if(Hilight) { - Buffer->ImdRotation += timeAdjustedIncrement(BUTTONOBJ_ROTSPEED, false); + Buffer->ImdRotation += graphicsTimeAdjustedIncrement(BUTTONOBJ_ROTSPEED); } Hilight = formIsHilite(Form); diff --git a/src/keybind.c b/src/keybind.c index b25e52f74..7f852bd3e 100644 --- a/src/keybind.c +++ b/src/keybind.c @@ -831,7 +831,7 @@ void kf_SystemClose( void ) /* Zooms out from display */ void kf_ZoomOut( void ) { - float zoomInterval = timeAdjustedIncrement(MAP_ZOOM_RATE, false); + float zoomInterval = graphicsTimeAdjustedIncrement(MAP_ZOOM_RATE); distance += zoomInterval; if(distance > MAXDISTANCE) @@ -870,7 +870,7 @@ void kf_RadarZoomOut( void ) /* Zooms in the map */ void kf_ZoomIn( void ) { - float zoomInterval = timeAdjustedIncrement(MAP_ZOOM_RATE, false); + float zoomInterval = graphicsTimeAdjustedIncrement(MAP_ZOOM_RATE); distance -= zoomInterval; if (distance < MINDISTANCE) @@ -929,7 +929,7 @@ void kf_ExpandScreen( void ) /* Spins the world round left */ void kf_RotateLeft( void ) { - float rotAmount = timeAdjustedIncrement(MAP_SPIN_RATE, false); + float rotAmount = graphicsTimeAdjustedIncrement(MAP_SPIN_RATE); player.r.y += rotAmount; } @@ -938,7 +938,7 @@ void kf_RotateLeft( void ) /* Spins the world right */ void kf_RotateRight( void ) { - float rotAmount = timeAdjustedIncrement(MAP_SPIN_RATE, false); + float rotAmount = graphicsTimeAdjustedIncrement(MAP_SPIN_RATE); player.r.y -= rotAmount; if (player.r.y < 0) @@ -951,36 +951,14 @@ void kf_RotateRight( void ) /* Pitches camera back */ void kf_PitchBack( void ) { -//#ifdef ALEXM -//SDWORD pitch; -//SDWORD angConcern; -//#endif - - float pitchAmount = timeAdjustedIncrement(MAP_PITCH_RATE, false); - -//#ifdef ALEXM -// pitch = getSuggestedPitch(); -// angConcern = DEG(360-pitch); -// -// if(player.r.x < angConcern) -// { -//#endif + float pitchAmount = graphicsTimeAdjustedIncrement(MAP_PITCH_RATE); player.r.x += pitchAmount; -//#ifdef ALEXM -// } -//#endif -//#ifdef ALEXM -// if(getDebugMappingStatus() == false) -//#endif - -// { if(player.r.x>DEG(360+MAX_PLAYER_X_ANGLE)) { player.r.x = DEG(360+MAX_PLAYER_X_ANGLE); } -// } setDesiredPitch(player.r.x/DEG_1); } @@ -988,7 +966,7 @@ void kf_PitchBack( void ) /* Pitches camera foward */ void kf_PitchForward( void ) { - float pitchAmount = timeAdjustedIncrement(MAP_PITCH_RATE, false); + float pitchAmount = graphicsTimeAdjustedIncrement(MAP_PITCH_RATE); player.r.x -= pitchAmount; if (player.r.x < DEG(360 + MIN_PLAYER_X_ANGLE)) diff --git a/src/lighting.c b/src/lighting.c index 2e5dbcc68..f001f799a 100644 --- a/src/lighting.c +++ b/src/lighting.c @@ -541,7 +541,7 @@ UDWORD retVal; if(lightVal>255) lightVal = 255; presVal = psDroid->illumination; adjust = (float)lightVal - (float)presVal; - adjust *= timeAdjustedIncrement(DROID_SEEK_LIGHT_SPEED, true); + adjust *= graphicsTimeAdjustedIncrement(DROID_SEEK_LIGHT_SPEED); retVal = presVal + adjust; if(retVal > 255) retVal = 255; psDroid->illumination = (UBYTE)retVal; diff --git a/src/move.c b/src/move.c index 7ed699411..cc9c13fb5 100644 --- a/src/move.c +++ b/src/move.c @@ -2117,7 +2117,7 @@ static void moveUpdateVtolModel(DROID *psDroid, SDWORD speed, uint16_t direction /* do vertical movement */ iMapZ = map_Height(psDroid->pos.x, psDroid->pos.y); - psDroid->pos.z = MAX(iMapZ, psDroid->pos.z + timeAdjustedIncrement(psDroid->sMove.iVertSpeed, true)); + psDroid->pos.z = MAX(iMapZ, psDroid->pos.z + gameTimeAdjustedIncrement(psDroid->sMove.iVertSpeed)); moveAdjustVtolHeight(psDroid, iMapZ); } @@ -2207,7 +2207,7 @@ static void moveUpdateCyborgModel(DROID *psDroid, SDWORD moveSpeed, uint16_t mov /* do vertical movement */ if ( psPropStats->propulsionType == PROPULSION_TYPE_JUMP ) { - iDz = timeAdjustedIncrement(psDroid->sMove.iVertSpeed, true); + iDz = gameTimeAdjustedIncrement(psDroid->sMove.iVertSpeed); iDroidZ = (SDWORD) psDroid->pos.z; if ( iDroidZ+iDz < (SDWORD) iMapZ ) diff --git a/src/terrain.c b/src/terrain.c index bb10915dc..b329b1a14 100644 --- a/src/terrain.c +++ b/src/terrain.c @@ -1464,7 +1464,7 @@ void drawWater(void) // move the water if(!gamePaused()) { - waterOffset += timeAdjustedIncrement(0.1f, true); + waterOffset += graphicsTimeAdjustedIncrement(0.1f); } // disable second texture diff --git a/src/visibility.c b/src/visibility.c index 5f5be68f2..1a0d92a0c 100644 --- a/src/visibility.c +++ b/src/visibility.c @@ -93,10 +93,10 @@ BOOL visInitialise(void) // update the visibility change levels void visUpdateLevel(void) { - visLevelIncAcc += timeAdjustedIncrement(VIS_LEVEL_INC, true); + visLevelIncAcc += gameTimeAdjustedIncrement(VIS_LEVEL_INC); visLevelInc = visLevelIncAcc; visLevelIncAcc -= visLevelInc; - visLevelDecAcc += timeAdjustedIncrement(VIS_LEVEL_DEC, true); + visLevelDecAcc += gameTimeAdjustedIncrement(VIS_LEVEL_DEC); visLevelDec = visLevelDecAcc; visLevelDecAcc -= visLevelDec; } diff --git a/src/warcam.c b/src/warcam.c index 3502e4c40..f60c699c4 100644 --- a/src/warcam.c +++ b/src/warcam.c @@ -732,17 +732,17 @@ static void updateCameraVelocity(UBYTE update) { if(update & X_UPDATE) { - trackingCamera.velocity.x += timeAdjustedIncrement(trackingCamera.acceleration.x, false); + trackingCamera.velocity.x += realTimeAdjustedIncrement(trackingCamera.acceleration.x); } if(update & Y_UPDATE) { - trackingCamera.velocity.y += timeAdjustedIncrement(trackingCamera.acceleration.y, false); + trackingCamera.velocity.y += realTimeAdjustedIncrement(trackingCamera.acceleration.y); } if(update & Z_UPDATE) { - trackingCamera.velocity.z += timeAdjustedIncrement(trackingCamera.acceleration.z, false); + trackingCamera.velocity.z += realTimeAdjustedIncrement(trackingCamera.acceleration.z); } } @@ -768,19 +768,19 @@ PROPULSION_STATS *psPropStats; if(update & X_UPDATE) { /* Need to update position along x axis */ - trackingCamera.position.x += timeAdjustedIncrement(trackingCamera.velocity.x, false); + trackingCamera.position.x += realTimeAdjustedIncrement(trackingCamera.velocity.x); } if(update & Y_UPDATE) { /* Need to update position along y axis */ - trackingCamera.position.y += timeAdjustedIncrement(trackingCamera.velocity.y, false); + trackingCamera.position.y += realTimeAdjustedIncrement(trackingCamera.velocity.y); } if(update & Z_UPDATE) { /* Need to update position along z axis */ - trackingCamera.position.z += timeAdjustedIncrement(trackingCamera.velocity.z, false); + trackingCamera.position.z += realTimeAdjustedIncrement(trackingCamera.velocity.z); } } @@ -920,15 +920,15 @@ static void updateCameraRotationVelocity( UBYTE update ) { if(update & Y_UPDATE) { - trackingCamera.rotVel.y += timeAdjustedIncrement(trackingCamera.rotAccel.y, false); + trackingCamera.rotVel.y += realTimeAdjustedIncrement(trackingCamera.rotAccel.y); } if(update & X_UPDATE) { - trackingCamera.rotVel.x += timeAdjustedIncrement(trackingCamera.rotAccel.x, false); + trackingCamera.rotVel.x += realTimeAdjustedIncrement(trackingCamera.rotAccel.x); } if(update & Z_UPDATE) { - trackingCamera.rotVel.z += timeAdjustedIncrement(trackingCamera.rotAccel.z, false); + trackingCamera.rotVel.z += realTimeAdjustedIncrement(trackingCamera.rotAccel.z); } } @@ -939,15 +939,15 @@ static void updateCameraRotationPosition( UBYTE update ) { if (update & Y_UPDATE) { - trackingCamera.rotation.y += timeAdjustedIncrement(trackingCamera.rotVel.y, false); + trackingCamera.rotation.y += realTimeAdjustedIncrement(trackingCamera.rotVel.y); } if (update & X_UPDATE) { - trackingCamera.rotation.x += timeAdjustedIncrement(trackingCamera.rotVel.x, false); + trackingCamera.rotation.x += realTimeAdjustedIncrement(trackingCamera.rotVel.x); } if (update & Z_UPDATE) { - trackingCamera.rotation.z += timeAdjustedIncrement(trackingCamera.rotVel.z, false); + trackingCamera.rotation.z += realTimeAdjustedIncrement(trackingCamera.rotVel.z); } }