11 Oct 2010

This commit is contained in:
g-cont 2010-10-11 00:00:00 +04:00 committed by Alibek Omarov
parent 3fe6b9a8b6
commit d8a292491d
20 changed files with 143 additions and 94 deletions

View File

@ -6,7 +6,6 @@
#include "common.h"
#include "client.h"
#include "byteorder.h"
#include "protocol.h"
#include "net_encode.h"
/*

View File

@ -5,7 +5,6 @@
#include "common.h"
#include "client.h"
#include "protocol.h"
#include "net_encode.h"
#include "entity_types.h"
#include "input.h"

View File

@ -8,7 +8,6 @@
#include "byteorder.h"
#include "matrix_lib.h"
#include "const.h"
#include "protocol.h"
#include "triangle_api.h"
#include "r_efx.h"
#include "event_flags.h"

View File

@ -6,7 +6,6 @@
#include "common.h"
#include "client.h"
#include "byteorder.h"
#include "protocol.h"
#include "net_encode.h"
#include "input.h"

View File

@ -5,7 +5,6 @@
#include "common.h"
#include "client.h"
#include "protocol.h"
#include "net_encode.h"
#include "event_flags.h"

View File

@ -6,7 +6,6 @@
#include "common.h"
#include "client.h"
#include "const.h"
#include "protocol.h"
#include "pm_local.h"
void CL_ClearPhysEnts( void )

View File

@ -8,7 +8,6 @@
#include "matrix_lib.h"
#include "const.h"
#include "pm_local.h"
#include "protocol.h"
#include "net_encode.h"
#define MAX_FORWARD 6

View File

@ -7,7 +7,6 @@
#include "netchan.h"
#include "mathlib.h"
#include "byteorder.h"
#include "protocol.h"
#include "net_encode.h"
#define MAKE_FRAGID( id, count ) ((( id & 0xffff ) << 16 ) | ( count & 0xffff ))
@ -1397,7 +1396,7 @@ void Netchan_TransmitBits( netchan_t *chan, int length, byte *data )
for( i = BF_GetNumBytesWritten( &send ); i < 16; i++ )
{
// NOTE: that the server can parse svc_nop, too.
BF_WriteByte( &send, svc_nop );
BF_WriteByte( &send, 1 );
}
}

View File

@ -7,7 +7,6 @@
#include "netchan.h"
#include "byteorder.h"
#include "mathlib.h"
#include "protocol.h"
#include "net_encode.h"
#include "event_api.h"
#include "usercmd.h"
@ -15,6 +14,7 @@
#include "entity_state.h"
#include "weaponinfo.h"
#include "entity_types.h"
#include "protocol.h"
#define DELTA_PATH "delta.lst"
static bool delta_init = false;

View File

@ -48,8 +48,6 @@
// bytes will be stripped by the networking channel layer
#define NET_MAX_MESSAGE PAD_NUMBER(( NET_MAX_PAYLOAD + HEADER_BYTES ), 16 )
#define PORT_MASTER 27900
#define PORT_CLIENT 27901
#define PORT_SERVER 27910

View File

@ -9,7 +9,7 @@
// server to client
#define svc_bad 0 // immediately crash client when received
#define svc_nop 1 // end of user messages
#define svc_nop 1 // does nothing
#define svc_disconnect 2 // kick client from server
#define svc_changing 3 // changelevel by server request
#define svc_configstring 4 // [short] [string]
@ -64,4 +64,18 @@
#define MAX_CLIENT_BITS 5
#define MAX_CLIENTS (1<<MAX_CLIENT_BITS)
/*
==============================================================
DELTA-PACKET ENTITIES
==============================================================
*/
typedef struct
{
int num_entities;
entity_state_t *entities;
} packet_entities_t;
#endif//PROTOCOL_H

View File

@ -13,6 +13,7 @@
#include "pm_defs.h"
#include "pm_movevars.h"
#include "entity_state.h"
#include "protocol.h"
#include "netchan.h"
#include "world.h"
@ -103,11 +104,14 @@ typedef struct server_s
typedef struct
{
int num_entities;
int first_entity; // into the circular sv_packet_entities[]
double senttime; // time the message was transmitted
double senttime;
float ping_time;
clientdata_t clientdata;
weapon_data_t weapondata[32];
packet_entities_t entities;
// legacy (needs to be removed)
float latency;
clientdata_t cd; // clientdata
} client_frame_t;
typedef struct sv_client_s
@ -119,6 +123,10 @@ typedef struct sv_client_s
bool send_message;
bool skip_message;
netchan_t netchan;
int chokecount; // number of messages rate supressed
int delta_sequence; // -1 = no compression.
double next_messagetime; // time when we should send next world state update
double next_messageinterval; // default time to wait for next message
@ -164,8 +172,6 @@ typedef struct sv_client_s
int challenge; // challenge of this user, randomly generated
int userid; // identifying number on server
netchan_t netchan;
} sv_client_t;
/*
@ -394,6 +400,7 @@ void SV_Newgame_f( void );
//
void SV_WriteFrameToClient( sv_client_t *client, sizebuf_t *msg );
void SV_BuildClientFrame( sv_client_t *client );
void SV_ClearFrames( client_frame_t **frames );
void SV_InactivateClients( void );
void SV_SendMessagesToAll( void );

View File

@ -6,7 +6,6 @@
#include "common.h"
#include "const.h"
#include "server.h"
#include "protocol.h"
#include "net_encode.h"
#include "entity_types.h"
@ -180,6 +179,8 @@ gotnewcl:
sv_client = newcl;
edictnum = (newcl - svs.clients) + 1;
SV_ClearFrames( &newcl->frames );
ent = EDICT_NUM( edictnum );
newcl->edict = ent;
newcl->challenge = challenge; // save challenge for checksumming
@ -264,6 +265,8 @@ edict_t *SV_FakeConnect( const char *netname )
sv_client = newcl;
edictnum = (newcl - svs.clients) + 1;
SV_ClearFrames( &newcl->frames ); // fakeclients doesn't have frames
ent = EDICT_NUM( edictnum );
newcl->edict = ent;
newcl->challenge = -1; // fake challenge
@ -362,6 +365,8 @@ void SV_DropClient( sv_client_t *drop )
drop->state = cs_zombie; // become free in a few seconds
drop->name[0] = 0;
SV_ClearFrames( &drop->frames );
// Throw away any residual garbage in the channel.
Netchan_Clear( &drop->netchan );

View File

@ -5,7 +5,6 @@
#include "common.h"
#include "server.h"
#include "protocol.h"
#include "byteorder.h"
sv_client_t *sv_client; // current client

View File

@ -6,7 +6,6 @@
#include "common.h"
#include "server.h"
#include "const.h"
#include "protocol.h"
#include "net_encode.h"
#include "entity_types.h"
@ -43,6 +42,79 @@ static int SV_EntityNumbers( const void *a, const void *b )
return 1;
}
/*
=======================
SV_ClearPacketEntities
=======================
*/
void SV_ClearPacketEntities( client_frame_t *frame )
{
packet_entities_t *packet;
ASSERT( frame != NULL );
packet = &frame->entities;
if( packet )
{
if( packet->entities != NULL )
Mem_Free( packet->entities );
packet->num_entities = 0;
packet->entities = NULL;
}
}
/*
=======================
SV_AllocPacketEntities
=======================
*/
void SV_AllocPacketEntities( client_frame_t *frame, int count )
{
packet_entities_t *packet;
ASSERT( frame != NULL );
packet = &frame->entities;
if( packet->entities != NULL )
{
SV_ClearPacketEntities( frame );
}
if( count < 1 ) count = 1;
packet->entities = Mem_Alloc( svgame.mempool, sizeof( entity_state_t ) * count );
packet->num_entities = count;
}
/*
================
SV_ClearFrames
free client frames memory
================
*/
void SV_ClearFrames( client_frame_t **frames )
{
client_frame_t *frame;
int i;
if( *frames == NULL )
return;
for( i = 0, frame = *frames; i < SV_UPDATE_BACKUP; i++, frames++ )
{
SV_ClearPacketEntities( frame );
frame->senttime = 0.0f;
frame->ping_time = -1;
}
Mem_Free( *frames );
*frames = NULL;
}
/*
=============================================================================
@ -57,51 +129,31 @@ SV_EmitPacketEntities
Writes a delta update of an entity_state_t list to the message->
=============
*/
void SV_EmitPacketEntities( client_frame_t *from, client_frame_t *to, sizebuf_t *msg )
void SV_EmitPacketEntities( packet_entities_t *from, packet_entities_t *to, sizebuf_t *msg )
{
entity_state_t *oldent, *newent;
int oldindex, newindex;
int oldnum, newnum;
int from_num_entities;
int oldindex, newindex;
int oldnum, newnum;
int oldmax;
BF_WriteByte( msg, svc_packetentities );
if( !from ) from_num_entities = 0;
else from_num_entities = from->num_entities;
if( !from ) oldmax = 0;
else oldmax = from->num_entities;
newent = NULL;
oldent = NULL;
newindex = 0;
oldindex = 0;
while( newindex < to->num_entities || oldindex < from_num_entities )
while( newindex < to->num_entities || oldindex < oldmax )
{
if( newindex >= to->num_entities )
{
newnum = MAX_ENTNUMBER;
}
else
{
newent = &svs.client_entities[(to->first_entity+newindex)%svs.num_client_entities];
newnum = newent->number;
}
if( oldindex >= from_num_entities )
{
oldnum = MAX_ENTNUMBER;
}
else
{
oldent = &svs.client_entities[(from->first_entity+oldindex)%svs.num_client_entities];
oldnum = oldent->number;
}
newnum = newindex >= to->num_entities ? MAX_ENTNUMBER : to->entities[newindex].number;
oldnum = oldindex >= oldmax ? MAX_ENTNUMBER : from->entities[oldindex].number;
if( newnum == oldnum )
{
// delta update from old position
// because the force parm is false, this will not result
// in any bytes being emited if the entity has not changed at all
MSG_WriteDeltaEntity( oldent, newent, msg, false, sv_time( ));
MSG_WriteDeltaEntity( &from->entities[oldindex], &to->entities[newindex], msg, false, sv_time( ));
oldindex++;
newindex++;
continue;
@ -110,7 +162,7 @@ void SV_EmitPacketEntities( client_frame_t *from, client_frame_t *to, sizebuf_t
if( newnum < oldnum )
{
// this is a new entity, send it from the baseline
MSG_WriteDeltaEntity( &svs.baselines[newnum], newent, msg, true, sv_time( ));
MSG_WriteDeltaEntity( &svs.baselines[newnum], &to->entities[newindex], msg, true, sv_time( ));
newindex++;
continue;
}
@ -119,12 +171,12 @@ void SV_EmitPacketEntities( client_frame_t *from, client_frame_t *to, sizebuf_t
{
bool force;
if( EDICT_NUM( oldent->number )->free )
if( EDICT_NUM( from->entities[oldindex].number )->free )
force = true; // entity completely removed from server
else force = false; // just removed from delta-message
// remove from message
MSG_WriteDeltaEntity( oldent, NULL, msg, force, sv_time( ));
MSG_WriteDeltaEntity( &from->entities[oldindex], NULL, msg, force, sv_time( ));
oldindex++;
continue;
}
@ -272,14 +324,14 @@ void SV_WriteClientData( client_frame_t *from, client_frame_t *to, sizebuf_t *ms
clientdata_t *cd, *ocd;
clientdata_t dummy;
cd = &to->cd;
cd = &to->clientdata;
if( !from )
{
Mem_Set( &dummy, 0, sizeof( dummy ));
ocd = &dummy;
}
else ocd = &from->cd;
else ocd = &from->clientdata;
BF_WriteByte( msg, svc_clientdata );
MSG_WriteClientData( msg, ocd, cd, sv.time );
@ -293,35 +345,32 @@ SV_WriteFrameToClient
void SV_WriteFrameToClient( sv_client_t *cl, sizebuf_t *msg )
{
client_frame_t *frame, *oldframe;
packet_entities_t *from, *to;
int lastframe;
// this is the frame we are creating
frame = &cl->frames[sv.framenum & SV_UPDATE_MASK];
to = &frame->entities;
if( cl->lastframe <= 0 )
{
// client is asking for a retransmit
oldframe = NULL;
lastframe = -1;
from = NULL;
}
else if( sv.framenum - cl->lastframe >= (SV_UPDATE_BACKUP - 3))
{
// client hasn't gotten a good message through in a long time
oldframe = NULL;
lastframe = -1;
from = NULL;
}
else
{ // we have a valid message to delta from
oldframe = &cl->frames[cl->lastframe & SV_UPDATE_MASK];
lastframe = cl->lastframe;
// the snapshot's entities may still have rolled off the buffer, though
if( oldframe->first_entity <= svs.next_client_entities - svs.num_client_entities )
{
MsgDev( D_WARN, "%s: ^7delta request from out of date entities.\n", cl->name );
oldframe = NULL;
lastframe = 0;
}
from = &oldframe->entities;
}
// delta encode the events
@ -338,7 +387,7 @@ void SV_WriteFrameToClient( sv_client_t *cl, sizebuf_t *msg )
SV_WriteClientData( oldframe, frame, msg );
// delta encode the entities
SV_EmitPacketEntities( oldframe, frame, msg );
SV_EmitPacketEntities( from, to, msg );
}
@ -362,9 +411,8 @@ void SV_BuildClientFrame( sv_client_t *cl )
edict_t *clent;
edict_t *viewent; // may be NULL
client_frame_t *frame;
entity_state_t *state;
packet_entities_t *packet;
static sv_ents_t frame_ents;
int i;
clent = cl->edict;
viewent = cl->pViewEntity;
@ -393,13 +441,14 @@ void SV_BuildClientFrame( sv_client_t *cl )
// this is the frame we are creating
frame = &cl->frames[sv.framenum & SV_UPDATE_MASK];
frame->senttime = host.realtime; // save it for ping calc later
packet = &frame->entities;
// clear everything in this snapshot
frame_ents.num_entities = c_fullsend = 0;
if( !SV_ClientFromEdict( clent, true )) return; // not in game yet
// update clientdata_t
svgame.dllFuncs.pfnUpdateClientData( clent, false, &frame->cd );
svgame.dllFuncs.pfnUpdateClientData( clent, false, &frame->clientdata );
// add all the entities directly visible to the eye, which
// may include portal entities that merge other viewpoints
@ -412,22 +461,9 @@ void SV_BuildClientFrame( sv_client_t *cl )
// of an entity being included twice.
qsort( frame_ents.entities, frame_ents.num_entities, sizeof( frame_ents.entities[0] ), SV_EntityNumbers );
// copy the entity states out
frame->num_entities = 0;
frame->first_entity = svs.next_client_entities;
for( i = 0; i < frame_ents.num_entities; i++ )
{
// add it to the circular client_entities array
state = &svs.client_entities[svs.next_client_entities % svs.num_client_entities];
*state = frame_ents.entities[i];
svs.next_client_entities++;
// this should never hit, map should always be restarted first in SV_Frame
if( svs.next_client_entities >= 0x7FFFFFFE )
Host_Error( "svs.next_client_entities wrapped\n" );
frame->num_entities++;
}
// copy the entity states to client frame
SV_AllocPacketEntities( frame, frame_ents.num_entities );
Mem_Copy( packet->entities, frame_ents.entities, sizeof( entity_state_t ) * frame_ents.num_entities );
}
/*

View File

@ -5,7 +5,6 @@
#include "common.h"
#include "server.h"
#include "protocol.h"
#include "net_encode.h"
#include "byteorder.h"
#include "matrix_lib.h"

View File

@ -5,7 +5,6 @@
#include "common.h"
#include "server.h"
#include "protocol.h"
int SV_UPDATE_BACKUP = SINGLEPLAYER_BACKUP;
@ -305,6 +304,9 @@ bool SV_SpawnServer( const char *mapname, const char *startspot )
if( svs.clients[i].state > cs_connected )
svs.clients[i].state = cs_connected;
svs.clients[i].lastframe = -1;
// release frames
SV_ClearFrames( &svs.clients[i].frames );
}
// make cvars consistant
@ -422,8 +424,6 @@ void SV_InitGame( void )
svs.spawncount = Com_RandomLong( 0, 65535 );
svs.clients = Z_Malloc( sizeof( sv_client_t ) * sv_maxclients->integer );
svs.num_client_entities = sv_maxclients->integer * SV_UPDATE_BACKUP * 64; // g-cont: what a mem waster ???
svs.client_entities = Z_Malloc( sizeof( entity_state_t ) * svs.num_client_entities );
svs.baselines = Z_Malloc( sizeof( entity_state_t ) * GI->max_edicts );
// client frames will be allocated in SV_DirectConnect
@ -448,6 +448,8 @@ void SV_InitGame( void )
ent = EDICT_NUM( i + 1 );
SV_InitEdict( ent );
SV_ClearFrames( &svs.clients[i].frames );
// make crosslinks
svs.clients[i].edict = ent;
Mem_Set( &svs.clients[i].lastcmd, 0, sizeof( svs.clients[i].lastcmd ));

View File

@ -5,7 +5,6 @@
#include "common.h"
#include "server.h"
#include "protocol.h"
#include "net_encode.h"
#define HEARTBEAT_SECONDS 300.0 // 300 seconds
@ -653,6 +652,6 @@ void SV_Shutdown( bool reconnect )
// free server static data
if( svs.clients ) Z_Free( svs.clients );
if( svs.baselines ) Z_Free( svs.baselines );
if( svs.client_entities ) Z_Free( svs.client_entities );
Mem_Set( &svs, 0, sizeof( svs ));
}

View File

@ -6,7 +6,6 @@
#include "common.h"
#include "mathlib.h"
#include "matrix_lib.h"
#include "protocol.h"
#include "server.h"
#include "const.h"
#include "pm_defs.h"

View File

@ -6,7 +6,6 @@
#include "common.h"
#include "server.h"
#include "const.h"
#include "protocol.h"
#include "pm_local.h"
bool SV_CopyEdictToPhysEnt( physent_t *pe, edict_t *ed, bool player_trace )