A bunch of multiplayer improvements

git-svn-id: https://svn.eduke32.com/eduke32@1567 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2009-12-14 05:23:29 +00:00
parent 410c1187d1
commit b46bd5fa19
10 changed files with 342 additions and 352 deletions

View file

@ -7,13 +7,30 @@
extern "C" { extern "C" {
#endif #endif
extern uint32_t crc32table[256];
void initcrc32table(void); void initcrc32table(void);
uint32_t crc32once(uint8_t *blk, uint32_t len); uint32_t crc32once(uint8_t *blk, uint32_t len);
void crc32init(uint32_t *crcvar); static inline void crc32init(uint32_t *crcvar)
void crc32block(uint32_t *crcvar, uint8_t *blk, uint32_t len); {
uint32_t crc32finish(uint32_t *crcvar); if (!crcvar) return;
*crcvar = 0xffffffffl;
}
static inline void crc32block(uint32_t *crcvar, uint8_t *blk, uint32_t len)
{
uint32_t crc = *crcvar;
while (len--) crc = crc32table[(crc ^ *(blk++)) & 0xffl] ^(crc >> 8);
*crcvar = crc;
}
static inline uint32_t crc32finish(uint32_t *crcvar)
{
*crcvar = *crcvar ^ 0xffffffffl;
return *crcvar;
}
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -1,64 +1,6 @@
#include "crc32.h" #include "crc32.h"
/* uint32_t crc32table[256];
// this table of numbers is borrowed from the InfoZip source.
static uint32_t crc32table[256] = {
0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,
0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,
0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,
0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,
0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL,
0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L,
0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L,
0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL,
0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL,
0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL,
0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L,
0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L,
0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,
0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L,
0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L,
0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L,
0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L,
0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L,
0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L,
0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL,
0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL,
0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,
0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL,
0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL,
0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL,
0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L,
0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,
0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL,
0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L,
0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L,
0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,
0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L,
0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L,
0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,
0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,
0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
0x2d02ef8dL
};
*/
static uint32_t crc32table[256];
void initcrc32table(void) void initcrc32table(void)
{ {
@ -74,7 +16,6 @@ void initcrc32table(void)
} }
} }
uint32_t crc32once(uint8_t *blk, uint32_t len) uint32_t crc32once(uint8_t *blk, uint32_t len)
{ {
uint32_t crc; uint32_t crc;
@ -83,23 +24,3 @@ uint32_t crc32once(uint8_t *blk, uint32_t len)
crc32block(&crc, blk, len); crc32block(&crc, blk, len);
return crc32finish(&crc); return crc32finish(&crc);
} }
void crc32init(uint32_t *crcvar)
{
if (!crcvar) return;
*crcvar = 0xffffffffl;
}
void crc32block(uint32_t *crcvar, uint8_t *blk, uint32_t len)
{
uint32_t crc = *crcvar;
while (len--) crc = crc32table[(crc ^ *(blk++)) & 0xffl] ^(crc >> 8);
*crcvar = crc;
}
uint32_t crc32finish(uint32_t *crcvar)
{
*crcvar = *crcvar ^ 0xffffffffl;
return *crcvar;
}

View file

@ -1100,6 +1100,7 @@ enum DukePacket_t
PACKET_PLAYER_INDEX, PACKET_PLAYER_INDEX,
PACKET_PLAYER_DISCONNECTED, PACKET_PLAYER_DISCONNECTED,
PACKET_PLAYER_SPAWN, PACKET_PLAYER_SPAWN,
PACKET_FRAG,
PACKET_REQUEST_GAMESTATE, PACKET_REQUEST_GAMESTATE,
PACKET_NEW_GAME, PACKET_NEW_GAME,
PACKET_LOAD_GAME, PACKET_LOAD_GAME,

View file

@ -185,6 +185,7 @@ extern void A_MoveCyclers(void);
extern void A_MoveDummyPlayers(void); extern void A_MoveDummyPlayers(void);
extern void P_ResetStatus(int32_t snum); extern void P_ResetStatus(int32_t snum);
extern void P_ResetPlayer(int32_t snum); extern void P_ResetPlayer(int32_t snum);
extern void P_FragPlayer(int32_t snum);
// game.c // game.c
extern inline void G_SetStatusBarScale(int32_t sc); extern inline void G_SetStatusBarScale(int32_t sc);
@ -248,6 +249,8 @@ extern void Net_SendQuit(void);
extern void G_AddUserQuote(const char *daquote); extern void G_AddUserQuote(const char *daquote);
extern void Net_NewGame(int32_t volume, int32_t level); extern void Net_NewGame(int32_t volume, int32_t level);
extern void Net_Disconnect(void);
extern void Net_Connect(const char * srvaddr);
extern int32_t SpriteFlags[MAXTILES]; extern int32_t SpriteFlags[MAXTILES];

View file

@ -580,6 +580,50 @@ void G_HandleSpecialKeys(void)
} }
} }
void Net_Connect(const char * srvaddr)
{
ENetAddress address;
ENetEvent event;
char * addrstr = NULL;
Net_Disconnect();
net_client = enet_host_create (NULL, 1, 0, 0);
if (net_client == NULL)
{
initprintf ("An error occurred while trying to create an ENet client host.\n");
return;
}
addrstr = strtok((char *)srvaddr,":");
enet_address_set_host (&address, addrstr);
address.port = atoi((addrstr = strtok(NULL,":")) == NULL ? "23513" : addrstr);
// use 2 channels for easy packet sorting at a lower level than the game later
net_peer = enet_host_connect (net_client, &address, 2);
if (net_peer == NULL)
{
initprintf ("No available peers for initiating an ENet connection.\n");
return;
}
/* Wait up to 5 seconds for the connection attempt to succeed. */
if (enet_host_service (net_client, & event, 5000) > 0 &&
event.type == ENET_EVENT_TYPE_CONNECT)
initprintf("Connection to %s:%d succeeded.\n",(char *)srvaddr,address.port);
else
{
/* Either the 5 seconds are up or a disconnect event was */
/* received. Reset the peer in the event the 5 seconds */
/* had run out without any significant event. */
enet_peer_reset (net_peer);
Net_Disconnect();
initprintf("Connection to %s:%d failed.\n",(char *)srvaddr,address.port);
}
}
void Net_Disconnect(void) void Net_Disconnect(void)
{ {
if (net_client) if (net_client)
@ -596,11 +640,14 @@ void Net_Disconnect(void)
case ENET_EVENT_TYPE_CONNECT: case ENET_EVENT_TYPE_CONNECT:
case ENET_EVENT_TYPE_NONE: case ENET_EVENT_TYPE_NONE:
case ENET_EVENT_TYPE_RECEIVE: case ENET_EVENT_TYPE_RECEIVE:
if (event.packet)
enet_packet_destroy (event.packet); enet_packet_destroy (event.packet);
break; break;
case ENET_EVENT_TYPE_DISCONNECT: case ENET_EVENT_TYPE_DISCONNECT:
G_GameExit(" "); numplayers = playerswhenstarted = ud.multimode = 1;
myconnectindex = screenpeek = 0;
G_BackToMenu();
break; break;
} }
} }
@ -685,15 +732,14 @@ static void Net_SendVersion(void)
if (numplayers < 2) return; if (numplayers < 2) return;
buf[0] = PACKET_VERSION; buf[0] = PACKET_VERSION;
buf[1] = myconnectindex; buf[1] = (uint8_t)atoi(s_buildDate);
buf[2] = (uint8_t)atoi(s_buildDate); buf[2] = BYTEVERSION;
buf[3] = BYTEVERSION; buf[3] = myconnectindex;
buf[4] = myconnectindex;
if (net_client) if (net_client)
enet_peer_send(net_peer, 0, enet_packet_create(&buf[0], 5, ENET_PACKET_FLAG_RELIABLE)); enet_peer_send(net_peer, 0, enet_packet_create(&buf[0], 4, ENET_PACKET_FLAG_RELIABLE));
else if (net_server) else if (net_server)
enet_host_broadcast(net_server, 0, enet_packet_create(&buf[0], 5, ENET_PACKET_FLAG_RELIABLE)); enet_host_broadcast(net_server, 0, enet_packet_create(&buf[0], 4, ENET_PACKET_FLAG_RELIABLE));
} }
static void Net_SendPlayerOptions(void) static void Net_SendPlayerOptions(void)
@ -804,7 +850,7 @@ void Net_ParsePacket(ENetEvent * event)
{ {
uint8_t * packbuf = event->packet->data; uint8_t * packbuf = event->packet->data;
int32_t packbufleng = event->packet->dataLength; int32_t packbufleng = event->packet->dataLength;
int32_t i, j, l; int16_t i, j, l;
int32_t other = packbuf[--packbufleng]; int32_t other = packbuf[--packbufleng];
input_t *nsyn; input_t *nsyn;
@ -825,6 +871,7 @@ void Net_ParsePacket(ENetEvent * event)
Bmemcpy(&ticrandomseed, &packbuf[j], sizeof(ticrandomseed)); Bmemcpy(&ticrandomseed, &packbuf[j], sizeof(ticrandomseed));
j += sizeof(ticrandomseed); j += sizeof(ticrandomseed);
ud.pause_on = packbuf[j++];
TRAVERSE_CONNECT(i) TRAVERSE_CONNECT(i)
{ {
@ -885,6 +932,8 @@ process:
j += sizeof(int16_t); j += sizeof(int16_t);
Bmemcpy(&g_player[i].ps->last_extra, &packbuf[j], sizeof(int16_t)); Bmemcpy(&g_player[i].ps->last_extra, &packbuf[j], sizeof(int16_t));
j += sizeof(int16_t); j += sizeof(int16_t);
Bmemcpy(g_player[i].frags, &packbuf[j], sizeof(g_player[i].frags));
j += sizeof(g_player[i].frags);
l = i; l = i;
@ -933,6 +982,7 @@ process:
} }
{ {
/*
int16_t ahead, zhead, phead; int16_t ahead, zhead, phead;
Bmemcpy(&ahead, &packbuf[j], sizeof(int16_t)); Bmemcpy(&ahead, &packbuf[j], sizeof(int16_t));
@ -948,10 +998,11 @@ process:
deletesprite(ahead); deletesprite(ahead);
if (zhead != -1 && sprite[zhead].statnum != STAT_ACTOR && sprite[zhead].statnum != STAT_ZOMBIEACTOR) if (zhead != -1 && sprite[zhead].statnum != STAT_ACTOR && sprite[zhead].statnum != STAT_ZOMBIEACTOR)
deletesprite(ahead); deletesprite(zhead);
if (phead != -1 && sprite[phead].statnum != STAT_PROJECTILE) if (phead != -1 && sprite[phead].statnum != STAT_PROJECTILE)
deletesprite(ahead); deletesprite(phead);
*/
// sprite updates tacked on to the end of the packet // sprite updates tacked on to the end of the packet
@ -972,33 +1023,46 @@ process:
opicnum = sprite[i].picnum; opicnum = sprite[i].picnum;
Bmemcpy(&sprite[i], &packbuf[j], sizeof(spritetype)); Bmemcpy(&sprite[i], &packbuf[j], sizeof(spritetype));
j += sizeof(spritetype);
if (sprite[i].picnum != opicnum)
{
sect = sprite[i].sectnum; sect = sprite[i].sectnum;
statnum = sprite[i].statnum; statnum = sprite[i].statnum;
sprite[i].sectnum = osect; sprite[i].sectnum = osect;
sprite[i].statnum = ostatnum; sprite[i].statnum = ostatnum;
deletesprite(i); // doesn't exist on the client yet
insertsprite(sect, statnum); if (ostatnum == MAXSTATUS || osect == MAXSECTORS)
{
int16_t sprs[MAXSPRITES], j = 0;
while ((sprs[j++] = insertsprite(sect, statnum)) != i);
if (j != 1)
{
j--;
while (--j) deletesprite(sprs[j]);
deletesprite(sprs[0]);
}
} }
else else
{ {
sect = sprite[i].sectnum;
statnum = sprite[i].statnum;
sprite[i].sectnum = osect;
sprite[i].statnum = ostatnum;
if (sect != osect) changespritesect(i, sect); if (sect != osect) changespritesect(i, sect);
if (statnum != ostatnum) changespritestat(i, statnum); if (statnum != ostatnum) changespritestat(i, statnum);
}
#ifdef POLYMER #ifdef POLYMER
if (sprite[i].picnum == opicnum)
{
mylight = ActorExtra[i].lightptr; mylight = ActorExtra[i].lightptr;
lightid = ActorExtra[i].lightId; lightid = ActorExtra[i].lightId;
#endif
} }
else if (getrendermode() == 4 && ActorExtra[i].lightptr != NULL)
{
polymer_deletelight(ActorExtra[i].lightId);
ActorExtra[i].lightId = -1;
ActorExtra[i].lightptr = NULL;
}
#endif
j += sizeof(spritetype); /*initprintf("updating sprite %d (%d)\n",i,sprite[i].picnum);*/
jj = j++; jj = j++;
@ -1160,14 +1224,14 @@ process:
break; break;
case PACKET_VERSION: case PACKET_VERSION:
if (packbuf[2] != (uint8_t)atoi(s_buildDate)) if (packbuf[1] != (uint8_t)atoi(s_buildDate))
{ {
initprintf("Player %d has version %d, expecting %d\n",packbuf[2],(uint8_t)atoi(s_buildDate)); initprintf("Player %d has version %d, expecting %d\n",other,packbuf[1],(uint8_t)atoi(s_buildDate));
G_GameExit("You cannot play with different versions of EDuke32!"); G_GameExit("You cannot play with different versions of EDuke32!");
} }
if (packbuf[3] != BYTEVERSION) if (packbuf[2] != BYTEVERSION)
{ {
initprintf("Player %d has version %d, expecting %d\n",packbuf[3],BYTEVERSION); initprintf("Player %d has version %d, expecting %d\n",other,packbuf[2],BYTEVERSION);
G_GameExit("You cannot play Duke with different versions!"); G_GameExit("You cannot play Duke with different versions!");
} }
break; break;
@ -1177,21 +1241,24 @@ process:
playerswhenstarted = packbuf[2]; playerswhenstarted = packbuf[2];
ud.multimode = packbuf[3]; ud.multimode = packbuf[3];
if (packbuf[4]) // ID of new player if (packbuf[4]) // ID of new player
{
clearbufbyte(&g_player[packbuf[4]].playerquitflag,1,0x01010101); clearbufbyte(&g_player[packbuf[4]].playerquitflag,1,0x01010101);
for (i=1; i<playerswhenstarted; i++) if (!g_player[packbuf[4]].ps) g_player[packbuf[4]].ps = (DukePlayer_t *) Bcalloc(1,sizeof(DukePlayer_t));
{ if (!g_player[packbuf[4]].sync) g_player[packbuf[4]].sync = (input_t *) Bcalloc(1,sizeof(input_t));
if (!g_player[i].ps) g_player[i].ps = (DukePlayer_t *) Bcalloc(1,sizeof(DukePlayer_t));
if (!g_player[i].sync) g_player[i].sync = (input_t *) Bcalloc(1,sizeof(input_t));
} }
for (i=0; i<playerswhenstarted-1; i++) connectpoint2[i] = i+1; for (i=0; i<playerswhenstarted-1; i++) connectpoint2[i] = i+1;
connectpoint2[playerswhenstarted-1] = -1; connectpoint2[playerswhenstarted-1] = -1;
// myconnectindex is 0 until we get PACKET_PLAYER_INDEX
if (net_client && myconnectindex != 0)
{
Net_SendVersion(); Net_SendVersion();
Net_SendPlayerName(); Net_SendPlayerName();
Net_SendPlayerOptions(); Net_SendPlayerOptions();
Net_SendWeaponChoice(); Net_SendWeaponChoice();
}
break; break;
@ -1218,6 +1285,12 @@ process:
P_ResetPlayer(packbuf[1]); P_ResetPlayer(packbuf[1]);
break; break;
case PACKET_FRAG:
g_player[packbuf[1]].ps->frag_ps = packbuf[2];
ActorExtra[g_player[packbuf[1]].ps->i].picnum = packbuf[3];
P_FragPlayer(packbuf[1]);
break;
case PACKET_PLAYER_OPTIONS: case PACKET_PLAYER_OPTIONS:
other = packbuf[1]; other = packbuf[1];
i = 2; i = 2;
@ -1527,12 +1600,12 @@ void Net_GetPackets(void)
switch (event.type) switch (event.type)
{ {
case ENET_EVENT_TYPE_RECEIVE: case ENET_EVENT_TYPE_RECEIVE:
/*
initprintf ("A packet of length %u was received from player %d on channel %u.\n", initprintf ("A packet of length %u was received from player %d on channel %u.\n",
event.packet -> dataLength, event.packet -> dataLength,
event.peer -> data, event.peer -> data,
event.channelID); event.channelID);
*/
// channelID 1 is the map state transfer from the server // channelID 1 is the map state transfer from the server
if (event.channelID == 1) if (event.channelID == 1)
{ {
@ -1708,6 +1781,7 @@ void faketimerhandler(void)
ticrandomseed = randomseed; ticrandomseed = randomseed;
Bmemcpy(&packbuf[j], &ticrandomseed, sizeof(ticrandomseed)); Bmemcpy(&packbuf[j], &ticrandomseed, sizeof(ticrandomseed));
j += sizeof(ticrandomseed); j += sizeof(ticrandomseed);
packbuf[j++] = ud.pause_on;
nsyn = (input_t *)&inputfifo[0][0]; nsyn = (input_t *)&inputfifo[0][0];
@ -1753,6 +1827,8 @@ void faketimerhandler(void)
j += sizeof(int16_t); j += sizeof(int16_t);
Bmemcpy(&packbuf[j], &g_player[i].ps->last_extra, sizeof(int16_t)); Bmemcpy(&packbuf[j], &g_player[i].ps->last_extra, sizeof(int16_t));
j += sizeof(int16_t); j += sizeof(int16_t);
Bmemcpy(&packbuf[j], g_player[i].frags, sizeof(g_player[i].frags));
j += sizeof(g_player[i].frags);
l = i; l = i;
@ -1832,6 +1908,7 @@ void faketimerhandler(void)
} }
} }
/*
Bmemcpy(&packbuf[j], &headspritestat[STAT_ACTOR], sizeof(int16_t)); Bmemcpy(&packbuf[j], &headspritestat[STAT_ACTOR], sizeof(int16_t));
j += sizeof(int16_t); j += sizeof(int16_t);
@ -1840,14 +1917,15 @@ void faketimerhandler(void)
Bmemcpy(&packbuf[j], &headspritestat[STAT_PROJECTILE], sizeof(int16_t)); Bmemcpy(&packbuf[j], &headspritestat[STAT_PROJECTILE], sizeof(int16_t));
j += sizeof(int16_t); j += sizeof(int16_t);
*/
k = 0; k = 0;
{ {
int32_t lists[] = { STAT_STANDABLE, STAT_EFFECTOR, STAT_ACTOR, STAT_ZOMBIEACTOR, STAT_PROJECTILE }, zz; int32_t lists[] = { STAT_PROJECTILE, STAT_STANDABLE, STAT_ACTIVATOR, STAT_TRANSPORT, STAT_EFFECTOR, STAT_ACTOR, STAT_ZOMBIEACTOR };
int32_t zj = j++; int32_t zz, zj;
packbuf[zj] = 0; packbuf[(zj = j++)] = 0;
for (zz = 0; (unsigned)zz < (sizeof(lists)/sizeof(lists[0])); zz++) for (zz = 0; (unsigned)zz < (sizeof(lists)/sizeof(lists[0])); zz++)
TRAVERSE_SPRITE_STAT(headspritestat[lists[zz]], i, nexti) TRAVERSE_SPRITE_STAT(headspritestat[lists[zz]], i, nexti)
@ -1856,10 +1934,11 @@ void faketimerhandler(void)
{ {
l = crc32once((uint8_t *)&sprite[i], sizeof(spritetype)); l = crc32once((uint8_t *)&sprite[i], sizeof(spritetype));
if (spritecrc[i] != l) if (!lastupdate[i] || spritecrc[i] != l)
{ {
int32_t jj = 0; int32_t jj = 0;
/*initprintf("updating sprite %d (%d)\n",i,sprite[i].picnum);*/
spritecrc[i] = l; spritecrc[i] = l;
lastupdate[i] = totalclock; lastupdate[i] = totalclock;
Bmemcpy(&packbuf[j], &i, sizeof(int16_t)); Bmemcpy(&packbuf[j], &i, sizeof(int16_t));
@ -1969,7 +2048,7 @@ void faketimerhandler(void)
if (k > 6) break; if (k > 6) break;
} }
packbuf[zj] = k; packbuf[zj] = k;
j++;
} }
{ {
@ -5189,6 +5268,8 @@ int32_t A_InsertSprite(int32_t whatsect,int32_t s_x,int32_t s_y,int32_t s_z,int3
A_ResetVars(i); A_ResetVars(i);
lastupdate[i] = 0;
if (apScriptGameEvent[EVENT_EGS]) if (apScriptGameEvent[EVENT_EGS])
{ {
extern int32_t block_deletesprite; extern int32_t block_deletesprite;
@ -9922,49 +10003,7 @@ static void G_CheckCommandLine(int32_t argc, const char **argv)
{ {
if (argc > i+1) if (argc > i+1)
{ {
ENetAddress address; Net_Connect((char *)argv[i+1]);
ENetEvent event;
char * addrstr = NULL;
Net_Disconnect();
net_client = enet_host_create (NULL, 1, 0, 0);
if (net_client == NULL)
{
initprintf ("An error occurred while trying to create an ENet client host.\n");
i += 2;
continue;
}
addrstr = strtok((char *)argv[i+1],":");
enet_address_set_host (&address, addrstr);
address.port = atoi((addrstr = strtok(NULL,":")) == NULL ? "23513" : addrstr);
// use 2 channels for easy packet sorting at a lower level than the game later
net_peer = enet_host_connect (net_client, &address, 2);
if (net_peer == NULL)
{
initprintf ("No available peers for initiating an ENet connection.\n");
i += 2;
continue;
}
/* Wait up to 5 seconds for the connection attempt to succeed. */
if (enet_host_service (net_client, & event, 5000) > 0 &&
event.type == ENET_EVENT_TYPE_CONNECT)
initprintf("Connection to %s:%d succeeded.\n",(char *)argv[i+1],address.port);
else
{
/* Either the 5 seconds are up or a disconnect event was */
/* received. Reset the peer in the event the 5 seconds */
/* had run out without any significant event. */
enet_peer_reset (net_peer);
Net_Disconnect();
initprintf("Connection to %s:%d failed.\n",(char *)argv[i+1],address.port);
}
i++; i++;
} }
i++; i++;
@ -10878,6 +10917,7 @@ void app_main(int32_t argc,const char **argv)
int32_t i = 0, j; int32_t i = 0, j;
char cwd[BMAX_PATH]; char cwd[BMAX_PATH];
// extern char datetimestring[]; // extern char datetimestring[];
ENetCallbacks callbacks = { Bmalloc, Bfree, NULL };
#ifdef RENDERTYPEWIN #ifdef RENDERTYPEWIN
if (argc > 1) if (argc > 1)
@ -10896,7 +10936,7 @@ void app_main(int32_t argc,const char **argv)
} }
#endif #endif
if (enet_initialize () != 0) if (enet_initialize_with_callbacks(ENET_VERSION, &callbacks) != 0)
initprintf("An error occurred while initializing ENet.\n"); initprintf("An error occurred while initializing ENet.\n");
else atexit (enet_deinitialize); else atexit (enet_deinitialize);

View file

@ -23,7 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
#include "duke3d.h" #include "duke3d.h"
const char *s_buildDate = "20091106"; const char *s_buildDate = "20091212";
char *MusicPtr = NULL; char *MusicPtr = NULL;
int32_t g_musicSize; int32_t g_musicSize;

View file

@ -1147,6 +1147,23 @@ static int32_t osdcmd_inittimer(const osdfuncparm_t *parm)
return OSDCMD_OK; return OSDCMD_OK;
} }
static int32_t osdcmd_disconnect(const osdfuncparm_t *parm)
{
UNREFERENCED_PARAMETER(parm);
Net_Disconnect();
return OSDCMD_OK;
}
static int32_t osdcmd_connect(const osdfuncparm_t *parm)
{
if (parm->numparms != 1)
return OSDCMD_SHOWHELP;
Net_Connect(parm->parms[0]);
G_BackToMenu();
return OSDCMD_OK;
}
static int32_t osdcmd_cvar_set_multi(const osdfuncparm_t *parm) static int32_t osdcmd_cvar_set_multi(const osdfuncparm_t *parm)
{ {
int32_t r = osdcmd_cvar_set(parm); int32_t r = osdcmd_cvar_set(parm);
@ -1326,6 +1343,9 @@ int32_t registerosdcommands(void)
OSD_RegisterFunction("cmenu","cmenu <#>: jumps to menu", osdcmd_cmenu); OSD_RegisterFunction("cmenu","cmenu <#>: jumps to menu", osdcmd_cmenu);
OSD_RegisterFunction("crosshaircolor","crosshaircolor: changes the crosshair color", osdcmd_crosshaircolor); OSD_RegisterFunction("crosshaircolor","crosshaircolor: changes the crosshair color", osdcmd_crosshaircolor);
OSD_RegisterFunction("connect","connect: connects to a multiplayer game", osdcmd_connect);
OSD_RegisterFunction("disconnect","disconnect: disconnects from the local multiplayer game", osdcmd_disconnect);
OSD_RegisterFunction("echo","echo [text]: echoes text to the console", osdcmd_echo); OSD_RegisterFunction("echo","echo [text]: echoes text to the console", osdcmd_echo);
OSD_RegisterFunction("fileinfo","fileinfo <file>: gets a file's information", osdcmd_fileinfo); OSD_RegisterFunction("fileinfo","fileinfo <file>: gets a file's information", osdcmd_fileinfo);

View file

@ -27,6 +27,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "duke3d.h" #include "duke3d.h"
#include "osd.h" #include "osd.h"
#include "gamedef.h" #include "gamedef.h"
#include "enet/enet.h"
int32_t g_currentweapon; int32_t g_currentweapon;
int32_t g_gun_pos; int32_t g_gun_pos;
@ -40,7 +41,7 @@ int32_t g_weapon_xoffset;
int32_t turnheldtime; //MED int32_t turnheldtime; //MED
int32_t lastcontroltime; //MED int32_t lastcontroltime; //MED
extern int32_t g_levelTextTime; extern int32_t g_levelTextTime, ticrandomseed;
int32_t g_numObituaries = 0; int32_t g_numObituaries = 0;
int32_t g_numSelfObituaries = 0; int32_t g_numSelfObituaries = 0;
@ -1048,6 +1049,8 @@ DOSKIPBULLETHOLE:
l = j; l = j;
else l = -1; else l = -1;
if (numplayers > 1 && net_client) return -1;
/* j = A_InsertSprite(sect, /* j = A_InsertSprite(sect,
sx+(sintable[(348+sa+512)&2047]/448), sx+(sintable[(348+sa+512)&2047]/448),
sy+(sintable[(sa+348)&2047]/448), sy+(sintable[(sa+348)&2047]/448),
@ -1695,6 +1698,9 @@ SKIPBULLETHOLE:
if (p >= 0 && j >= 0) if (p >= 0 && j >= 0)
l = j; l = j;
else l = -1; else l = -1;
if (numplayers > 1 && net_client) return -1;
if (ActorExtra[i].shootzvel) zvel = ActorExtra[i].shootzvel; if (ActorExtra[i].shootzvel) zvel = ActorExtra[i].shootzvel;
j = A_InsertSprite(sect, j = A_InsertSprite(sect,
srcvect.x+(sintable[(348+sa+512)&2047]/448), srcvect.x+(sintable[(348+sa+512)&2047]/448),
@ -3813,6 +3819,115 @@ int32_t P_FindOtherPlayer(int32_t p,int32_t *d)
return closest_player; return closest_player;
} }
void P_FragPlayer(int32_t snum)
{
DukePlayer_t *p = g_player[snum].ps;
spritetype *s = &sprite[p->i];
randomseed = ticrandomseed;
if (net_server)
{
packbuf[0] = PACKET_FRAG;
packbuf[1] = snum;
packbuf[2] = p->frag_ps;
packbuf[3] = ActorExtra[p->i].picnum;
packbuf[4] = myconnectindex;
enet_host_broadcast(net_server, 0, enet_packet_create(packbuf, 5, ENET_PACKET_FLAG_RELIABLE));
}
if (s->pal != 1)
{
p->pals[0] = 63;
p->pals[1] = 0;
p->pals[2] = 0;
p->pals_time = 63;
p->posz -= (16<<8);
s->z -= (16<<8);
}
if (ud.recstat == 1 && ud.multimode < 2)
G_CloseDemoWrite();
if (s->pal != 1)
{
p->dead_flag = (512-((krand()&1)<<10)+(krand()&255)-512)&2047;
if (p->dead_flag == 0)
p->dead_flag++;
}
p->jetpack_on = 0;
p->holoduke_on = -1;
S_StopEnvSound(DUKE_JETPACK_IDLE,p->i);
if (p->scream_voice >= FX_Ok)
{
FX_StopSound(p->scream_voice);
// S_TestSoundCallback(DUKE_SCREAM);
p->scream_voice = -1;
}
if (s->pal != 1 && (s->cstat&32768) == 0) s->cstat = 0;
if (ud.multimode > 1 && (s->pal != 1 || (s->cstat&32768)))
{
if (p->frag_ps != snum)
{
if (GTFLAGS(GAMETYPE_TDM) && g_player[p->frag_ps].ps->team == g_player[snum].ps->team)
g_player[p->frag_ps].ps->fraggedself++;
else
{
g_player[p->frag_ps].ps->frag++;
g_player[p->frag_ps].frags[snum]++;
}
if (snum == screenpeek)
{
Bsprintf(ScriptQuotes[115],"KILLED BY %s",&g_player[p->frag_ps].user_name[0]);
P_DoQuote(115,p);
}
else
{
Bsprintf(ScriptQuotes[116],"KILLED %s",&g_player[snum].user_name[0]);
P_DoQuote(116,g_player[p->frag_ps].ps);
}
if (ud.obituaries)
{
Bsprintf(tempbuf,ScriptQuotes[FIRST_OBITUARY_QUOTE+(krand()%g_numObituaries)],
&g_player[p->frag_ps].user_name[0],
&g_player[snum].user_name[0]);
G_AddUserQuote(tempbuf);
}
else krand();
}
else
{
if (ActorExtra[p->i].picnum != APLAYERTOP)
{
p->fraggedself++;
if (A_CheckEnemyTile(sprite[p->wackedbyactor].picnum))
Bsprintf(tempbuf,ScriptQuotes[FIRST_OBITUARY_QUOTE+(krand()%g_numObituaries)],"A monster",&g_player[snum].user_name[0]);
else if (ActorExtra[p->i].picnum == NUKEBUTTON)
Bsprintf(tempbuf,"^02%s^02 tried to leave",&g_player[snum].user_name[0]);
else
{
// random suicide death string
Bsprintf(tempbuf,ScriptQuotes[FIRST_SUICIDE_QUOTE+(krand()%g_numSelfObituaries)],&g_player[snum].user_name[0]);
}
}
else Bsprintf(tempbuf,"^02%s^02 switched to team %d",&g_player[snum].user_name[0],p->team+1);
if (ud.obituaries)
G_AddUserQuote(tempbuf);
}
p->frag_ps = snum;
pus = NUMPAGES;
}
}
void P_ProcessInput(int32_t snum) void P_ProcessInput(int32_t snum)
{ {
int32_t j, i, k, doubvel, fz, cz, hz, lz, truefdist, x, y, shrunk; int32_t j, i, k, doubvel, fz, cz, hz, lz, truefdist, x, y, shrunk;
@ -4014,27 +4129,6 @@ void P_ProcessInput(int32_t snum)
return; return;
} }
} }
/*
if(p->select_dir)
{
if(psectlotag != 15 || (sb_snum&(1<<31)) )
p->select_dir = 0;
else
{
if(g_player[snum].sync->fvel > 127)
{
p->select_dir = 0;
G_ActivateWarpElevators(pi,-1);
}
else if(g_player[snum].sync->fvel <= -127)
{
p->select_dir = 0;
G_ActivateWarpElevators(pi,1);
}
return;
}
}
*/
if (p->pals_time >= 0) if (p->pals_time >= 0)
p->pals_time--; p->pals_time--;
@ -4055,99 +4149,8 @@ void P_ProcessInput(int32_t snum)
if (s->extra <= 0) if (s->extra <= 0)
{ {
if (p->dead_flag == 0) if ((numplayers < 2 || net_server) && p->dead_flag == 0)
{ P_FragPlayer(snum);
if (s->pal != 1)
{
p->pals[0] = 63;
p->pals[1] = 0;
p->pals[2] = 0;
p->pals_time = 63;
p->posz -= (16<<8);
s->z -= (16<<8);
}
if (ud.recstat == 1 && ud.multimode < 2)
G_CloseDemoWrite();
if (s->pal != 1)
{
p->dead_flag = (512-((krand()&1)<<10)+(krand()&255)-512)&2047;
if (p->dead_flag == 0)
p->dead_flag++;
}
p->jetpack_on = 0;
p->holoduke_on = -1;
S_StopEnvSound(DUKE_JETPACK_IDLE,p->i);
if (p->scream_voice >= FX_Ok)
{
FX_StopSound(p->scream_voice);
// S_TestSoundCallback(DUKE_SCREAM);
p->scream_voice = -1;
}
if (s->pal != 1 && (s->cstat&32768) == 0) s->cstat = 0;
if (ud.multimode > 1 && (s->pal != 1 || (s->cstat&32768)))
{
if (p->frag_ps != snum)
{
if (GTFLAGS(GAMETYPE_TDM) && g_player[p->frag_ps].ps->team == g_player[snum].ps->team)
g_player[p->frag_ps].ps->fraggedself++;
else
{
g_player[p->frag_ps].ps->frag++;
g_player[p->frag_ps].frags[snum]++;
}
if (snum == screenpeek)
{
Bsprintf(ScriptQuotes[115],"KILLED BY %s",&g_player[p->frag_ps].user_name[0]);
P_DoQuote(115,p);
}
else
{
Bsprintf(ScriptQuotes[116],"KILLED %s",&g_player[snum].user_name[0]);
P_DoQuote(116,g_player[p->frag_ps].ps);
}
if (ud.obituaries)
{
Bsprintf(tempbuf,ScriptQuotes[FIRST_OBITUARY_QUOTE+(krand()%g_numObituaries)],
&g_player[p->frag_ps].user_name[0],
&g_player[snum].user_name[0]);
G_AddUserQuote(tempbuf);
}
else krand();
}
else
{
if (ActorExtra[p->i].picnum != APLAYERTOP)
{
p->fraggedself++;
if (A_CheckEnemyTile(sprite[p->wackedbyactor].picnum))
Bsprintf(tempbuf,ScriptQuotes[FIRST_OBITUARY_QUOTE+(krand()%g_numObituaries)],"A monster",&g_player[snum].user_name[0]);
else if (ActorExtra[p->i].picnum == NUKEBUTTON)
Bsprintf(tempbuf,"^02%s^02 tried to leave",&g_player[snum].user_name[0]);
else
{
// random suicide death string
Bsprintf(tempbuf,ScriptQuotes[FIRST_SUICIDE_QUOTE+(krand()%g_numSelfObituaries)],&g_player[snum].user_name[0]);
}
}
else Bsprintf(tempbuf,"^02%s^02 switched to team %d",&g_player[snum].user_name[0],p->team+1);
if (ud.obituaries)
{
G_AddUserQuote(tempbuf);
}
}
p->frag_ps = snum;
pus = NUMPAGES;
}
}
if (psectlotag == 2) if (psectlotag == 2)
{ {
@ -4251,15 +4254,6 @@ void P_ProcessInput(int32_t snum)
goto HORIZONLY; goto HORIZONLY;
j = ksgn(g_player[snum].sync->avel); j = ksgn(g_player[snum].sync->avel);
/*
if( j && ud.screen_tilting == 2)
{
k = 4;
if(sb_snum&(1<<5)) k <<= 2;
p->rotscrnang -= k*j;
p->look_ang += k*j;
}
*/
if (s->xvel < 32 || p->on_ground == 0 || p->bobcounter == 1024) if (s->xvel < 32 || p->on_ground == 0 || p->bobcounter == 1024)
{ {
@ -5435,6 +5429,8 @@ SHOOTINCODE:
p->ammo_amount[p->curr_weapon]--; p->ammo_amount[p->curr_weapon]--;
if (numplayers < 2 || net_server)
{
if (p->on_ground && TEST_SYNC_KEY(sb_snum, SK_CROUCH)) if (p->on_ground && TEST_SYNC_KEY(sb_snum, SK_CROUCH))
{ {
k = 15; k = 15;
@ -5479,6 +5475,7 @@ SHOOTINCODE:
sprite[j].zvel /= 3; sprite[j].zvel /= 3;
sprite[j].xvel /= 3; sprite[j].xvel /= 3;
} }
}
p->hbomb_on = 1; p->hbomb_on = 1;
} }
else if ((*kb) < aplWeaponHoldDelay[p->curr_weapon][snum] && TEST_SYNC_KEY(sb_snum, SK_FIRE)) else if ((*kb) < aplWeaponHoldDelay[p->curr_weapon][snum] && TEST_SYNC_KEY(sb_snum, SK_FIRE))

View file

@ -121,17 +121,19 @@ int32_t MUSIC_Init(int32_t SoundCard, int32_t Address)
else else
{ {
char *s[] = { "/etc/timidity.cfg", "/etc/timidity/timidity.cfg", "/etc/timidity/freepats.cfg" }; char *s[] = { "/etc/timidity.cfg", "/etc/timidity/timidity.cfg", "/etc/timidity/freepats.cfg" };
FILE *fp; FILE *fp = NULL;
uint32_t i; int32_t i;
for (i = 0; i < sizeof(s)/sizeof(s[0]); i++) for (i = (sizeof(s)/sizeof(s[0]))-1; i>=0; i--)
{ {
fp = fopen(s[i], "r"); fp = Bfopen(s[i], "r");
if (fp == NULL) if (fp == NULL)
{ {
if (i == sizeof(s)/sizeof(s[0])) if (i == 0)
{ {
initprintf("Error opening %s, %s or %s\n",s[0],s[1],s[2]); initprintf("Error: couldn't open any of the following files:\n");
for (i = (sizeof(s)/sizeof(s[0]))-1; i>=0; i--)
initprintf("%s\n",s[i]);
return(MUSIC_Error); return(MUSIC_Error);
} }
continue; continue;

View file

@ -145,18 +145,7 @@ void S_MusicStartup(void)
MUSIC_SetVolume(ud.config.MusicVolume); MUSIC_SetVolume(ud.config.MusicVolume);
} }
initprintf("Couldn't find selected sound card, or, error w/ sound card itself.\n"); initprintf("S_MusicStartup(): failed initializing\n");
/*
S_SoundShutdown();
uninittimer();
uninitengine();
CONTROL_Shutdown();
CONFIG_WriteSetup();
KB_Shutdown();
uninitgroupfile();
//unlink("duke3d.tmp");
exit(-1);
*/
} }
} }