Skip to content
Browse files

Remove DROID::sMove.ebit[XY], use gameTimeAdjustedAverage instead.

  • Loading branch information...
1 parent 17e4e8f commit 7e3c8e4f4eecb8b2648e06f0a549b22dcc1fecc2 @Cyp Cyp committed
Showing with 18 additions and 39 deletions.
  1. +5 −0 lib/gamelib/gtime.h
  2. +2 −4 src/droid.cpp
  3. +7 −4 src/move.cpp
  4. +0 −18 src/move.h
  5. +0 −6 src/movedef.h
  6. +4 −7 src/multisync.cpp
View
5 lib/gamelib/gtime.h
@@ -167,6 +167,11 @@ static inline int32_t gameTimeAdjustedAverage(int value)
{
return quantiseFraction(value, GAME_TICKS_PER_SEC, gameTime + deltaGameTime, gameTime);
}
+/// Returns the numerator/denominator times deltaGameTime, converted to seconds. The return value is rounded up or down, such that it is exactly right on average.
+static inline int32_t gameTimeAdjustedAverage(int numerator, int denominator)
+{
+ return quantiseFraction(numerator, GAME_TICKS_PER_SEC*denominator, gameTime + deltaGameTime, gameTime);
+}
void sendPlayerGameTime(void); ///< Sends a GAME_GAME_TIME message with gameTime plus latency to our game queues.
void recvPlayerGameTime(NETQUEUE queue); ///< Processes a GAME_GAME_TIME message.
View
6 src/droid.cpp
@@ -722,11 +722,11 @@ void _syncDebugDroid(const char *function, DROID const *psDroid, char ch)
actTarLen += sprintf(actTar + actTarLen, "_%u", psDroid->psActionTarget[i]? psDroid->psActionTarget[i]->id : 0);
}
- _syncDebug(function, "%c droid%d = p%d;pos(%d.%d,%d.%d,%d),rot(%d,%d,%d),ord%d(%d,%d)^%d,act%d%s,so%X,bp%d,sMove(st%d,spd%d,mdir%d,path%d/%d,src(%d,%d),tar(%d,%d),dst(%d,%d),bump(%d,%d,%d,%d,(%d,%d),%d)),exp%u, power = %"PRId64"", ch,
+ _syncDebug(function, "%c droid%d = p%d;pos(%d,%d,%d),rot(%d,%d,%d),ord%d(%d,%d)^%d,act%d%s,so%X,bp%d,sMove(st%d,spd%d,mdir%d,path%d/%d,src(%d,%d),tar(%d,%d),dst(%d,%d),bump(%d,%d,%d,%d,(%d,%d),%d)),exp%u, power = %"PRId64"", ch,
psDroid->id,
psDroid->player,
- psDroid->pos.x, psDroid->sMove.eBitX, psDroid->pos.y, psDroid->sMove.eBitY, psDroid->pos.z,
+ psDroid->pos.x, psDroid->pos.y, psDroid->pos.z,
psDroid->rot.direction, psDroid->rot.pitch, psDroid->rot.roll,
psDroid->order, psDroid->orderX, psDroid->orderY, psDroid->listSize,
psDroid->action, actTar,
@@ -2179,8 +2179,6 @@ DROID *reallyBuildDroid(DROID_TEMPLATE *pTemplate, Position pos, UDWORD player,
psDroid->droidType = droidTemplateType(pTemplate); // Is set again later to the same thing, in droidSetBits.
psDroid->pos = pos;
psDroid->rot = rot;
- psDroid->sMove.eBitX = 0;
- psDroid->sMove.eBitY = 0;
//don't worry if not on homebase cos not being drawn yet
if (!onMission)
View
11 src/move.cpp
@@ -172,6 +172,11 @@
// How fast vtols 'skid'
#define VTOL_SKID_DECEL 600
+/// Extra precision added to movement calculations.
+#define EXTRA_BITS 8
+#define EXTRA_PRECISION (1 << EXTRA_BITS)
+
+
static uint32_t oilTimer = 0;
static unsigned drumCount = 0;
@@ -1614,10 +1619,8 @@ static void moveUpdateDroidPos(DROID *psDroid, int32_t dx, int32_t dy)
return;
}
- newPos = droidGetPrecisePosition(psDroid);
- newPos.x += dx;
- newPos.y += dy;
- droidSetPrecisePosition(psDroid, newPos);
+ psDroid->pos.x += gameTimeAdjustedAverage(dx*GAME_UPDATES_PER_SEC, EXTRA_PRECISION);
+ psDroid->pos.y += gameTimeAdjustedAverage(dy*GAME_UPDATES_PER_SEC, EXTRA_PRECISION);
/* impact if about to go off map else update coordinates */
if ( worldOnMap( psDroid->pos.x, psDroid->pos.y ) == false )
View
18 src/move.h
@@ -66,24 +66,6 @@ extern bool moveCheckDroidMovingAndVisible( void *psObj );
// set a vtol to be hovering in the air
void moveMakeVtolHover( DROID *psDroid );
-/// Get high precision droid position
-static inline Position droidGetPrecisePosition(const DROID *psDroid)
-{
- return Position(psDroid->pos.x * EXTRA_PRECISION + psDroid->sMove.eBitX, psDroid->pos.y * EXTRA_PRECISION + psDroid->sMove.eBitY, 0);
-}
-
-/// Set high precision droid position
-static inline void droidSetPrecisePosition(DROID *psDroid, Position newPos)
-{
- // Store extra bits of precision
- psDroid->sMove.eBitX = newPos.x & EXTRA_MASK;
- psDroid->sMove.eBitY = newPos.y & EXTRA_MASK;
-
- // Drop extra bits of precision. The &~EXTRA_MASK is needed in the case of negative coordinates. Note that signed right-shift of negative numbers is implementation defined, although at least GCC says it does an arithmetic right-shift, which is what's needed.
- psDroid->pos.x = (newPos.x & ~EXTRA_MASK) / EXTRA_PRECISION;
- psDroid->pos.y = (newPos.y & ~EXTRA_MASK) / EXTRA_PRECISION;
-}
-
const char *moveDescription(MOVE_STATUS status);
#endif // __INCLUDED_SRC_MOVE_H__
View
6 src/movedef.h
@@ -43,11 +43,6 @@ enum MOVE_STATUS
MOVESHUFFLE,
};
-/// Extra precision added to movement calculations, stored in ebitX, ebitY.
-#define EXTRA_BITS 8
-#define EXTRA_PRECISION (1 << EXTRA_BITS)
-#define EXTRA_MASK (EXTRA_PRECISION - 1)
-
struct MOVE_CONTROL
{
MOVE_STATUS Status; // Inactive, Navigating or moving point to point status
@@ -58,7 +53,6 @@ struct MOVE_CONTROL
Vector2i destination; // World coordinates of movement destination
Vector2i src, target;
int speed; // Speed of motion
- uint8_t eBitX, eBitY; // extra bits stored in a temporary bit bucket
uint16_t moveDir; // direction of motion (not the direction the droid is facing)
uint16_t bumpDir; // direction at last bump
View
11 src/multisync.cpp
@@ -301,7 +301,7 @@ static PACKAGED_CHECK packageCheck(const DROID *pD)
ASSERT(false, "Droid %u body is too high before synch, is %u, which is more than %u.", pc.droidID, pD->body, pD->originalBody);
}
pc.experience = pD->experience;
- pc.pos = droidGetPrecisePosition(pD);
+ pc.pos = pD->pos;
pc.rot = pD->rot;
if (pD->order == DORDER_ATTACK)
{
@@ -334,7 +334,6 @@ bool recvDroidCheck(NETQUEUE queue)
{
DROID * pD;
PACKAGED_CHECK pc;
- Position precPos;
NETauto(&pc);
@@ -367,11 +366,9 @@ bool recvDroidCheck(NETQUEUE queue)
#define MERGECOPYSYNC(x, y, z) if (pc.y != pc2.y) { debug(LOG_SYNC, "Droid %u out of synch, changing "#x" from %"z" to %"z".", pc.droidID, x, pc.y); x = pc.y; }
#define MERGEDELTA(x, y, z) if (pc.y != pc2.y) { debug(LOG_SYNC, "Droid %u out of synch, changing "#x" from %"z" to %"z".", pc.droidID, x, x + pc.y - pc2.y); x += pc.y - pc2.y; }
// player not synched here...
- precPos = droidGetPrecisePosition(pD);
- MERGEDELTA(precPos.x, pos.x, "d");
- MERGEDELTA(precPos.y, pos.y, "d");
- MERGEDELTA(precPos.z, pos.z, "d");
- droidSetPrecisePosition(pD, precPos);
+ MERGEDELTA(pD->pos.x, pos.x, "d");
+ MERGEDELTA(pD->pos.y, pos.y, "d");
+ MERGEDELTA(pD->pos.z, pos.z, "d");
MERGEDELTA(pD->rot.direction, rot.direction, "d");
MERGEDELTA(pD->rot.pitch, rot.pitch, "d");
MERGEDELTA(pD->rot.roll, rot.roll, "d");

0 comments on commit 7e3c8e4

Please sign in to comment.
Something went wrong with that request. Please try again.