newnet: Make GAME_DROIDDEST synchronised, improve synch recovery.

master
Cyp 2010-02-22 14:21:01 +01:00
parent af28145369
commit 8077c761e4
6 changed files with 25 additions and 13 deletions

View File

@ -617,6 +617,8 @@ void NETPACKAGED_CHECK(PACKAGED_CHECK *v)
queueAuto(v->body);
queueAuto(v->direction);
queueAuto(v->experience);
queueAuto(v->posX);
queueAuto(v->posY);
queueAuto(v->sMoveX);
queueAuto(v->sMoveY);
if (v->order == DORDER_ATTACK)

View File

@ -142,6 +142,8 @@ typedef struct PackagedCheck
uint32_t body;
float direction;
float experience;
uint16_t posX;
uint16_t posY;
float sMoveX;
float sMoveY;
uint32_t targetID; ///< Defined iff order == DORDER_ATTACK.

View File

@ -410,6 +410,7 @@ void removeDroidBase(DROID *psDel)
{
ASSERT_OR_RETURN( , droidOnMap(psDel), "Asking other players to destroy droid driving off the map");
SendDestroyDroid(psDel);
return;
}

View File

@ -1111,7 +1111,7 @@ BOOL SendDestroyDroid(const DROID* psDroid)
{
return true;
}
NETbeginEncode(NETgameQueue(selectedPlayer), GAME_DROIDDEST);
{
uint32_t id = psDroid->id;

View File

@ -588,7 +588,7 @@ BOOL recvMessage(void)
// TODO Remove all these cases.
//case GAME_DROID: //24 down, 18 to go.
//case GAME_DROIDINFO: // 2 down, 41 to go.
case GAME_DROIDDEST:
//case GAME_DROIDDEST: //25 down, 17 to go.
//case GAME_DROIDMOVE: // 1 down, 42 to go.
//case GAME_GROUPORDER: // 3 down, 40 to go.
//case GAME_CHECK_DROID: // 4 down, 39 to go.

View File

@ -273,6 +273,8 @@ static PACKAGED_CHECK packageCheck(const DROID *pD)
pc.body = pD->body;
pc.direction = pD->direction;
pc.experience = pD->experience;
pc.posX = pD->pos.x;
pc.posY = pD->pos.y;
pc.sMoveX = pD->sMove.fx;
pc.sMoveY = pD->sMove.fy;
if (pD->order == DORDER_ATTACK)
@ -332,19 +334,19 @@ BOOL recvDroidCheck(NETQUEUE queue)
continue; // Can't synch, since we didn't save data to be able to calculate a delta.
}
#define MERGECOPY(x, y, z1, z2) if (pc.y != pc2.y) { debug(LOG_SYNC, "Droid %u out of synch, changing "#x" from %"z1" to %"z2".", pc.droidID, x, pc.y); x = pc.y; }
#define MERGEDELTA(x, y, z1, z2) if (pc.y != pc2.y) { debug(LOG_SYNC, "Droid %u out of synch, changing "#x" from %"z1" to %"z2".", pc.droidID, x, x + pc.y - pc2.y); x += pc.y - pc2.y; }
#define MERGECOPY(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...
MERGEDELTA(pD->pos.x, sMoveX, "d", "f");
MERGEDELTA(pD->pos.y, sMoveY, "d", "f"); // Apparently the old off-screen update set both pos.[xy] and sMove.f[xy] to the received sMove.f[xy], so doing the same.
MERGEDELTA(pD->sMove.fx, sMoveX, "f", "f");
MERGEDELTA(pD->sMove.fy, sMoveY, "f", "f");
MERGEDELTA(pD->direction, direction, "f", "f");
MERGEDELTA(pD->pos.x, posX, "d");
MERGEDELTA(pD->pos.y, posY, "d");
MERGEDELTA(pD->sMove.fx, sMoveX, "f");
MERGEDELTA(pD->sMove.fy, sMoveY, "f");
MERGEDELTA(pD->direction, direction, "f");
pD->direction += pD->direction < 0 ? 360 : pD->direction >= 360 ? -360 : 0;
MERGEDELTA(pD->body, body, "u", "u");
MERGEDELTA(pD->experience, experience, "f", "f");
MERGEDELTA(pD->body, body, "u");
MERGEDELTA(pD->experience, experience, "f");
if (pc.sMoveX != pc2.sMoveX || pc.sMoveY != pc2.sMoveY)
if (pc.posX != pc2.posX || pc.posY != pc2.posY)
{
// snap droid(if on ground) to terrain level at x,y.
if ((asPropulsionStats + pD->asBits[COMP_PROPULSION].nStat)->propulsionType != PROPULSION_TYPE_LIFT) // if not airborne.
@ -380,9 +382,14 @@ BOOL recvDroidCheck(NETQUEUE queue)
case DORDER_GUARD:
if (pc.order != pc2.order)
{
DROID_ORDER_DATA sOrder;
memset(&sOrder, 0, sizeof(DROID_ORDER_DATA));
sOrder.order = pc.order;
debug(LOG_SYNC, "Droid %u out of synch, changing order from %s to %s.", pc.droidID, getDroidOrderName(pc2.order), getDroidOrderName(pc.order));
turnOffMultiMsg(true);
moveStopDroid(pD);
orderDroidBase(pD, &sOrder);
turnOffMultiMsg(false);
}
break;
@ -390,7 +397,7 @@ BOOL recvDroidCheck(NETQUEUE queue)
break; // Don't know what to do, but at least won't be actively breaking anything.
}
MERGECOPY(pD->secondaryOrder, secondaryOrder, "u", "u"); // The old code set this after changing orders, so doing that in case.
MERGECOPY(pD->secondaryOrder, secondaryOrder, "u"); // The old code set this after changing orders, so doing that in case.
#undef MERGECOPY
#undef MERGEDELTA