aboutsummaryrefslogtreecommitdiffstats
path: root/code/qcommon
diff options
context:
space:
mode:
authortma <tma@edf5b092-35ff-0310-97b2-ce42778d08ea>2006-06-17 19:19:34 +0000
committertma <tma@edf5b092-35ff-0310-97b2-ce42778d08ea>2006-06-17 19:19:34 +0000
commit4a9519ad8553e47a44d3e68a26a147d8b53f7ff2 (patch)
treef5801f8578346498d59bf1d656c243f51c367bfb /code/qcommon
parent3a98677978bd7549f0cb8e8e4d500ee344305c41 (diff)
downloadioquake3-aero-4a9519ad8553e47a44d3e68a26a147d8b53f7ff2.tar.gz
ioquake3-aero-4a9519ad8553e47a44d3e68a26a147d8b53f7ff2.zip
* sv_minRate (from R1CH)
* [cl|sv]_packetdelay (from tjw) git-svn-id: svn://svn.icculus.org/quake3/trunk@808 edf5b092-35ff-0310-97b2-ce42778d08ea
Diffstat (limited to 'code/qcommon')
-rw-r--r--code/qcommon/common.c5
-rw-r--r--code/qcommon/net_chan.c66
-rw-r--r--code/qcommon/qcommon.h5
3 files changed, 74 insertions, 2 deletions
diff --git a/code/qcommon/common.c b/code/qcommon/common.c
index 1980edc..d1d40a9 100644
--- a/code/qcommon/common.c
+++ b/code/qcommon/common.c
@@ -77,6 +77,8 @@ cvar_t *com_buildScript; // for automated data building scripts
cvar_t *com_introPlayed;
cvar_t *cl_paused;
cvar_t *sv_paused;
+cvar_t *cl_packetdelay;
+cvar_t *sv_packetdelay;
cvar_t *com_cameraMode;
#if defined(_WIN32) && defined(_DEBUG)
cvar_t *com_noErrorInterrupt;
@@ -2085,6 +2087,7 @@ int Com_EventLoop( void ) {
MSG_Init( &buf, bufData, sizeof( bufData ) );
while ( 1 ) {
+ NET_FlushPacketQueue();
ev = Com_GetEvent();
// if no more events are available
@@ -2477,6 +2480,8 @@ void Com_Init( char *commandLine ) {
cl_paused = Cvar_Get ("cl_paused", "0", CVAR_ROM);
sv_paused = Cvar_Get ("sv_paused", "0", CVAR_ROM);
+ cl_packetdelay = Cvar_Get ("cl_packetdelay", "0", CVAR_CHEAT);
+ sv_packetdelay = Cvar_Get ("sv_packetdelay", "0", CVAR_CHEAT);
com_sv_running = Cvar_Get ("sv_running", "0", CVAR_ROM);
com_cl_running = Cvar_Get ("cl_running", "0", CVAR_ROM);
com_buildScript = Cvar_Get( "com_buildScript", "0", 0 );
diff --git a/code/qcommon/net_chan.c b/code/qcommon/net_chan.c
index 2ca1bfd..5c92c5d 100644
--- a/code/qcommon/net_chan.c
+++ b/code/qcommon/net_chan.c
@@ -615,6 +615,62 @@ void NET_SendLoopPacket (netsrc_t sock, int length, const void *data, netadr_t t
//=============================================================================
+typedef struct packetQueue_s {
+ struct packetQueue_s *next;
+ int length;
+ byte *data;
+ netadr_t to;
+ int release;
+} packetQueue_t;
+
+packetQueue_t *packetQueue = NULL;
+
+static void NET_QueuePacket( int length, const void *data, netadr_t to,
+ int offset )
+{
+ packetQueue_t *new, *next = packetQueue;
+
+ if(offset > 999)
+ offset = 999;
+
+ new = S_Malloc(sizeof(packetQueue_t));
+ new->data = S_Malloc(length);
+ Com_Memcpy(new->data, data, length);
+ new->length = length;
+ new->to = to;
+ new->release = Sys_Milliseconds() + offset;
+ new->next = NULL;
+
+ if(!packetQueue) {
+ packetQueue = new;
+ return;
+ }
+ while(next) {
+ if(!next->next) {
+ next->next = new;
+ return;
+ }
+ next = next->next;
+ }
+}
+
+void NET_FlushPacketQueue(void)
+{
+ packetQueue_t *last;
+ int now;
+
+ while(packetQueue) {
+ now = Sys_Milliseconds();
+ if(packetQueue->release >= now)
+ break;
+ Sys_SendPacket(packetQueue->length, packetQueue->data,
+ packetQueue->to);
+ last = packetQueue;
+ packetQueue = packetQueue->next;
+ Z_Free(last->data);
+ Z_Free(last);
+ }
+}
void NET_SendPacket( netsrc_t sock, int length, const void *data, netadr_t to ) {
@@ -634,7 +690,15 @@ void NET_SendPacket( netsrc_t sock, int length, const void *data, netadr_t to )
return;
}
- Sys_SendPacket( length, data, to );
+ if ( sock == NS_CLIENT && cl_packetdelay->integer > 0 ) {
+ NET_QueuePacket( length, data, to, cl_packetdelay->integer );
+ }
+ else if ( sock == NS_SERVER && sv_packetdelay->integer > 0 ) {
+ NET_QueuePacket( length, data, to, sv_packetdelay->integer );
+ }
+ else {
+ Sys_SendPacket( length, data, to );
+ }
}
/*
diff --git a/code/qcommon/qcommon.h b/code/qcommon/qcommon.h
index ada4fe0..202775f 100644
--- a/code/qcommon/qcommon.h
+++ b/code/qcommon/qcommon.h
@@ -159,7 +159,7 @@ void NET_Init( void );
void NET_Shutdown( void );
void NET_Restart( void );
void NET_Config( qboolean enableNetworking );
-
+void NET_FlushPacketQueue(void);
void NET_SendPacket (netsrc_t sock, int length, const void *data, netadr_t to);
void QDECL NET_OutOfBandPrint( netsrc_t net_socket, netadr_t adr, const char *format, ...);
void QDECL NET_OutOfBandData( netsrc_t sock, netadr_t adr, byte *format, int len );
@@ -758,6 +758,9 @@ extern cvar_t *com_altivec;
extern cvar_t *cl_paused;
extern cvar_t *sv_paused;
+extern cvar_t *cl_packetdelay;
+extern cvar_t *sv_packetdelay;
+
// com_speeds times
extern int time_game;
extern int time_frontend;