ref: 84468fd0509e77afdc9030dd4ec9a397b79e22fa
parent: 1be6c4c341fc6b42c76b9848b624e94f7f4451e4
author: Simon Howard <[email protected]>
date: Fri Apr 14 11:25:42 EDT 2006
Add ability to play using the Vanilla player sync code Subversion-branch: /trunk/chocolate-doom Subversion-revision: 470
--- a/src/d_net.c
+++ b/src/d_net.c
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: d_net.c 455 2006-03-30 19:08:37Z fraggle $
+// $Id: d_net.c 470 2006-04-14 15:25:42Z fraggle $
//
// Copyright(C) 1993-1996 Id Software, Inc.
// Copyright(C) 2005 Simon Howard
@@ -117,7 +117,7 @@
//-----------------------------------------------------------------------------
-static const char rcsid[] = "$Id: d_net.c 455 2006-03-30 19:08:37Z fraggle $";
+static const char rcsid[] = "$Id: d_net.c 470 2006-04-14 15:25:42Z fraggle $";
#include "doomfeatures.h"
@@ -157,6 +157,7 @@
int maketic;
int lastnettic;
+int skiptics;
int ticdup;
int extratics;
fixed_t offsetms;
@@ -173,8 +174,16 @@
{
int time_ms;
- time_ms = I_GetTimeMS() + (offsetms / FRACUNIT);
+ time_ms = I_GetTimeMS();
+ if (net_cl_new_sync)
+ {
+ // Use the adjustments from net_client.c only if we are
+ // using the new sync mode.
+
+ time_ms += (offsetms / FRACUNIT);
+ }
+
return (time_ms * FPS) / 1000;
}
@@ -187,10 +196,10 @@
void NetUpdate (void)
{
- int nowtime;
- int newtics;
- int i;
- int gameticdiv;
+ int nowtime;
+ int newtics;
+ int i;
+ int gameticdiv;
// If we are running with singletics (timing a demo), this
// is all done separately.
@@ -208,12 +217,20 @@
#endif
// check time
- nowtime = GetAdjustedTime()/ticdup;
+ nowtime = GetAdjustedTime() / ticdup;
newtics = nowtime - lasttime;
lasttime = nowtime;
- if (newtics <= 0) // nothing new to update
- return;
+ if (skiptics <= newtics)
+ {
+ newtics -= skiptics;
+ skiptics = 0;
+ }
+ else
+ {
+ skiptics -= newtics;
+ newtics = 0;
+ }
// build new ticcmds for console player
gameticdiv = gametic/ticdup;
@@ -229,16 +246,24 @@
M_Ticker ();
- // If playing single player, do not allow tics to buffer
- // up very far
+ if (net_cl_new_sync)
+ {
+ // If playing single player, do not allow tics to buffer
+ // up very far
- if ((!netgame || demoplayback) && maketic - gameticdiv > 2)
- break;
+ if ((!netgame || demoplayback) && maketic - gameticdiv > 2)
+ break;
- // Never go more than ~200ms ahead
+ // Never go more than ~200ms ahead
- if (maketic - gameticdiv > 8)
- break;
+ if (maketic - gameticdiv > 8)
+ break;
+ }
+ else
+ {
+ if (maketic - gameticdiv >= 5)
+ break;
+ }
//printf ("mk:%i ",maketic);
G_BuildTiccmd(&cmd);
@@ -408,19 +433,27 @@
// TryRunTics
//
int oldnettics;
+int frametics[4];
+int frameon;
+int frameskip[4];
+int oldnettics;
extern boolean advancedemo;
void TryRunTics (void)
{
- int i;
- int lowtic;
- int entertic;
- int availabletics;
- int counts;
+ int i;
+ int lowtic;
+ int entertic;
+ static int oldentertics;
+ int realtics;
+ int availabletics;
+ int counts;
// get real tics
- entertic = I_GetTime ()/ticdup;
+ entertic = I_GetTime() / ticdup;
+ realtics = entertic - oldentertics;
+ oldentertics = entertic;
// get available tics
NetUpdate ();
@@ -431,8 +464,72 @@
// decide how many tics to run
- counts = availabletics;
+ if (net_cl_new_sync)
+ {
+ counts = availabletics;
+ }
+ else
+ {
+ // decide how many tics to run
+ if (realtics < availabletics-1)
+ counts = realtics+1;
+ else if (realtics < availabletics)
+ counts = realtics;
+ else
+ counts = availabletics;
+
+ if (counts < 1)
+ counts = 1;
+
+ frameon++;
+ if (!demoplayback)
+ {
+ int keyplayer = -1;
+
+ // ideally maketic should be 1 - 3 tics above lowtic
+ // if we are consistantly slower, speed up time
+
+ for (i=0 ; i<MAXPLAYERS ; i++)
+ {
+ if (playeringame[i])
+ {
+ keyplayer = i;
+ break;
+ }
+ }
+
+ if (keyplayer < 0)
+ {
+ // If there are no players, we can never advance anyway
+
+ return;
+ }
+
+ if (consoleplayer == keyplayer)
+ {
+ // the key player does not adapt
+ }
+ else
+ {
+ if (maketic <= nettics[keyplayer])
+ {
+ lasttime--;
+ // printf ("-");
+ }
+
+ frameskip[frameon & 3] = (oldnettics > nettics[keyplayer]);
+ oldnettics = maketic;
+
+ if (frameskip[0] && frameskip[1] && frameskip[2] && frameskip[3])
+ {
+ skiptics = 1;
+ // printf ("+");
+ }
+ }
+ }
+ }
+
if (counts < 1)
counts = 1;
@@ -449,7 +546,7 @@
// Don't stay in this loop forever. The menu is still running,
// so return to update the screen
- if (I_GetTime ()/ticdup - entertic > 0)
+ if (I_GetTime() / ticdup - entertic > 0)
{
return;
}
--- a/src/net_client.c
+++ b/src/net_client.c
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: net_client.c 462 2006-04-06 19:31:45Z fraggle $
+// $Id: net_client.c 470 2006-04-14 15:25:42Z fraggle $
//
// Copyright(C) 2005 Simon Howard
//
@@ -269,6 +269,11 @@
static fixed_t average_latency;
+// Use new-style ticcmd sync (fixes indigo lag)
+
+boolean net_cl_new_sync = true;
+
+
#define NET_CL_ExpandTicNum(b) NET_ExpandTicNum(recvwindow_start, (b))
// Called when a player leaves the game
@@ -466,6 +471,11 @@
settings.gameversion = gameversion;
settings.nomonsters = nomonsters;
+ if (M_CheckParm("-oldsync") > 0)
+ settings.new_sync = 0;
+ else
+ settings.new_sync = 1;
+
i = M_CheckParm("-extratics");
if (i > 0)
@@ -663,6 +673,12 @@
startskill = settings.skill;
lowres_turn = settings.lowres_turn;
nomonsters = settings.nomonsters;
+ net_cl_new_sync = settings.new_sync != 0;
+
+ if (net_cl_new_sync == false)
+ {
+ printf("Syncing netgames like Vanilla Doom.\n");
+ }
memset(recvwindow, 0, sizeof(recvwindow));
recvwindow_start = 0;
--- a/src/net_client.h
+++ b/src/net_client.h
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: net_client.h 405 2006-03-02 00:57:25Z fraggle $
+// $Id: net_client.h 470 2006-04-14 15:25:42Z fraggle $
//
// Copyright(C) 2005 Simon Howard
//
@@ -90,6 +90,7 @@
extern char net_player_addresses[MAXPLAYERS][MAXPLAYERNAME];
extern int net_player_number;
extern char *net_player_name;
+extern boolean net_cl_new_sync;
#endif /* #ifndef NET_CLIENT_H */
--- a/src/net_defs.h
+++ b/src/net_defs.h
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: net_defs.h 464 2006-04-06 20:48:35Z fraggle $
+// $Id: net_defs.h 470 2006-04-14 15:25:42Z fraggle $
//
// Copyright(C) 2005 Simon Howard
//
@@ -178,6 +178,7 @@
int skill;
int gameversion;
int lowres_turn;
+ int new_sync;
} net_gamesettings_t;
#define NET_TICDIFF_FORWARD (1 << 0)
--- a/src/net_structrw.c
+++ b/src/net_structrw.c
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: net_structrw.c 404 2006-03-02 00:10:23Z fraggle $
+// $Id: net_structrw.c 470 2006-04-14 15:25:42Z fraggle $
//
// Copyright(C) 2005 Simon Howard
//
@@ -79,6 +79,7 @@
NET_WriteInt8(packet, settings->skill);
NET_WriteInt8(packet, settings->gameversion);
NET_WriteInt8(packet, settings->lowres_turn);
+ NET_WriteInt8(packet, settings->new_sync);
}
boolean NET_ReadSettings(net_packet_t *packet, net_gamesettings_t *settings)
@@ -91,7 +92,8 @@
&& NET_ReadInt8(packet, (unsigned int *) &settings->map)
&& NET_ReadInt8(packet, (unsigned int *) &settings->skill)
&& NET_ReadInt8(packet, (unsigned int *) &settings->gameversion)
- && NET_ReadInt8(packet, (unsigned int *) &settings->lowres_turn);
+ && NET_ReadInt8(packet, (unsigned int *) &settings->lowres_turn)
+ && NET_ReadInt8(packet, (unsigned int *) &settings->new_sync);
}
void NET_WriteTiccmdDiff(net_packet_t *packet, net_ticdiff_t *diff,