Skip to content

Commit ac42aa8

Browse files
TehRealSaltmadame-rachelle
authored andcommitted
cl_debugprediction console variable
Makes `gametic` run behind `ClientTic` by n ticks, and forces player prediction code to run. Only works if you are in a singleplayer session. This is intended to be useful for mod development, as you can quickly test prediction issues without creating a multiplayer server. It may also come in handy if any improvements are made to the prediction code in the future.
1 parent 154eea5 commit ac42aa8

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/d_net.cpp

+21-1
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,14 @@ CUSTOM_CVAR(Int, cl_showchat, CHAT_GLOBAL, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
162162
self = CHAT_GLOBAL;
163163
}
164164

165+
CUSTOM_CVAR(Int, cl_debugprediction, 0, CVAR_CHEAT)
166+
{
167+
if (self < 0)
168+
self = 0;
169+
else if (self > BACKUPTICS - 1)
170+
self = BACKUPTICS - 1;
171+
}
172+
165173
// Used to write out all network events that occured leading up to the next tick.
166174
static struct NetEventData
167175
{
@@ -1969,7 +1977,19 @@ void TryRunTics()
19691977
int runTics = min<int>(totalTics, availableTics);
19701978
if (totalTics > 0 && totalTics < availableTics - 1 && !singletics)
19711979
++runTics;
1972-
1980+
1981+
// Test player prediction code in singleplayer
1982+
// by running the gametic behind the ClientTic
1983+
if (!netgame && !demoplayback && cl_debugprediction > 0)
1984+
{
1985+
int debugTarget = ClientTic - cl_debugprediction;
1986+
int debugOffset = gametic - debugTarget;
1987+
if (debugOffset > 0)
1988+
{
1989+
runTics = max<int>(runTics - debugOffset, 0);
1990+
}
1991+
}
1992+
19731993
// If there are no tics to run, check for possible stall conditions and new
19741994
// commands to predict.
19751995
if (runTics <= 0)

src/playsim/p_user.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ CUSTOM_CVAR(Float, cl_rubberband_limit, 756.0f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG
133133
self = 0.0f;
134134
}
135135

136+
EXTERN_CVAR (Int, cl_debugprediction)
137+
136138
ColorSetList ColorSets;
137139
PainFlashList PainFlashes;
138140

@@ -1440,7 +1442,7 @@ void P_PredictPlayer (player_t *player)
14401442
player->mo == NULL ||
14411443
player != player->mo->Level->GetConsolePlayer() ||
14421444
player->playerstate != PST_LIVE ||
1443-
!netgame ||
1445+
(!netgame && cl_debugprediction == 0) ||
14441446
/*player->morphTics ||*/
14451447
(player->cheats & CF_PREDICTING))
14461448
{

0 commit comments

Comments
 (0)