sync player state with other players on spawn

git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@2615 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
Lee Salzman
2008-09-15 05:54:01 +00:00
parent 9507058d56
commit feb4cbd82e
2 changed files with 31 additions and 9 deletions
+9 -6
View File
@@ -297,13 +297,16 @@ void parsemessages(int cn, playerent *d, ucharbuf &p)
case SV_SPAWN:
{
int ls = getint(p), gunselect = getint(p);
if(!d) break;
d->respawn();
d->spawnstate(gamemode);
d->lifesequence = ls;
playerent *s = d;
if(!s) { static playerent dummy; s = &dummy; }
s->respawn();
s->lifesequence = getint(p);
s->health = getint(p);
s->armour = getint(p);
s->selectweapon(getint(p));
loopi(NUMGUNS) s->ammo[i] = getint(p);
loopi(NUMGUNS) s->mag[i] = getint(p);
d->state = CS_SPAWNING;
d->selectweapon(gunselect);
break;
}
+22 -3
View File
@@ -2360,8 +2360,18 @@ void process(ENetPacket *packet, int sender, int chan) // sender may be -1
if(packet->flags&ENET_PACKET_FLAG_RELIABLE) reliablemessages = true;
#define QUEUE_MSG { if(cl->type==ST_TCPIP) while(curmsg<p.length()) cl->messages.add(p.buf[curmsg++]); }
#define QUEUE_INT(n) { if(cl->type==ST_TCPIP) { curmsg = p.length(); ucharbuf buf = cl->messages.reserve(5); putint(buf, n); cl->messages.addbuf(buf); } }
#define QUEUE_STR(text) { if(cl->type==ST_TCPIP) { curmsg = p.length(); ucharbuf buf = cl->messages.reserve(2*(int)strlen(text)+1); sendstring(text, buf); cl->messages.addbuf(buf); } }
#define QUEUE_BUF(size, body) { \
if(cl->type==ST_TCPIP) \
{ \
curmsg = p.length(); \
ucharbuf buf = cl->messages.reserve(size); \
{ body; } \
cl->messages.addbuf(buf); \
} \
}
#define QUEUE_INT(n) QUEUE_BUF(5, putint(buf, n))
#define QUEUE_UINT(n) QUEUE_BUF(4, putuint(buf, n))
#define QUEUE_STR(text) QUEUE_BUF(2*strlen(text)+1, sendstring(text, buf))
#define MSG_PACKET(packet) \
ENetPacket *packet = enet_packet_create(NULL, 16 + p.length() - curmsg, ENET_PACKET_FLAG_RELIABLE); \
ucharbuf buf(packet->data, packet->dataLength); \
@@ -2506,7 +2516,16 @@ void process(ENetPacket *packet, int sender, int chan) // sender may be -1
cl->state.lastspawn = -1;
cl->state.state = CS_ALIVE;
cl->state.gunselect = gunselect;
QUEUE_MSG;
QUEUE_BUF(5*(5 + 2*NUMGUNS),
{
putint(buf, SV_SPAWN);
putint(buf, cl->state.lifesequence);
putint(buf, cl->state.health);
putint(buf, cl->state.armour);
putint(buf, cl->state.gunselect);
loopi(NUMGUNS) putint(buf, cl->state.ammo[i]);
loopi(NUMGUNS) putint(buf, cl->state.mag[i]);
});
break;
}