vkQuake2 doxygen  1.0 dev
cl_pred.c
Go to the documentation of this file.
1 /*
2 Copyright (C) 1997-2001 Id Software, Inc.
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 
13 See the GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 
19 */
20 
21 #include "client.h"
22 
23 
24 /*
25 ===================
26 CL_CheckPredictionError
27 ===================
28 */
30 {
31  int frame;
32  int delta[3];
33  int i;
34  int len;
35 
37  return;
38 
39  // calculate the last usercmd_t we sent that the server has processed
41  frame &= (CMD_BACKUP-1);
42 
43  // compare what the server returned with what we had predicted it to be
45 
46  // save the prediction error for interpolation
47  len = abs(delta[0]) + abs(delta[1]) + abs(delta[2]);
48  if (len > 640) // 80 world units
49  { // a teleport or something
51  }
52  else
53  {
54  if (cl_showmiss->value && (delta[0] || delta[1] || delta[2]) )
55  Com_Printf ("prediction miss on %i: %i\n", cl.frame.serverframe,
56  delta[0] + delta[1] + delta[2]);
57 
59 
60  // save for error itnerpolation
61  for (i=0 ; i<3 ; i++)
62  cl.prediction_error[i] = delta[i]*0.125;
63  }
64 }
65 
66 
67 /*
68 ====================
69 CL_ClipMoveToEntities
70 
71 ====================
72 */
73 void CL_ClipMoveToEntities ( vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, trace_t *tr )
74 {
75  int i, x, zd, zu;
76  trace_t trace;
77  int headnode;
78  float *angles;
79  entity_state_t *ent;
80  int num;
81  cmodel_t *cmodel;
82  vec3_t bmins, bmaxs;
83 
84  for (i=0 ; i<cl.frame.num_entities ; i++)
85  {
87  ent = &cl_parse_entities[num];
88 
89  if (!ent->solid)
90  continue;
91 
92  if (ent->number == cl.playernum+1)
93  continue;
94 
95  if (ent->solid == 31)
96  { // special value for bmodel
97  cmodel = cl.model_clip[ent->modelindex];
98  if (!cmodel)
99  continue;
100  headnode = cmodel->headnode;
101  angles = ent->angles;
102  }
103  else
104  { // encoded bbox
105  x = 8*(ent->solid & 31);
106  zd = 8*((ent->solid>>5) & 31);
107  zu = 8*((ent->solid>>10) & 63) - 32;
108 
109  bmins[0] = bmins[1] = -x;
110  bmaxs[0] = bmaxs[1] = x;
111  bmins[2] = -zd;
112  bmaxs[2] = zu;
113 
114  headnode = CM_HeadnodeForBox (bmins, bmaxs);
115  angles = vec3_origin; // boxes don't rotate
116  }
117 
118  if (tr->allsolid)
119  return;
120 
121  trace = CM_TransformedBoxTrace (start, end,
122  mins, maxs, headnode, MASK_PLAYERSOLID,
123  ent->origin, angles);
124 
125  if (trace.allsolid || trace.startsolid ||
126  trace.fraction < tr->fraction)
127  {
128  trace.ent = (struct edict_s *)ent;
129  if (tr->startsolid)
130  {
131  *tr = trace;
132  tr->startsolid = true;
133  }
134  else
135  *tr = trace;
136  }
137  else if (trace.startsolid)
138  tr->startsolid = true;
139  }
140 }
141 
142 
143 /*
144 ================
145 CL_PMTrace
146 ================
147 */
149 {
150  trace_t t;
151 
152  // check against world
153  t = CM_BoxTrace (start, end, mins, maxs, 0, MASK_PLAYERSOLID);
154  if (t.fraction < 1.0)
155  t.ent = (struct edict_s *)1;
156 
157  // check all other solid models
158  CL_ClipMoveToEntities (start, mins, maxs, end, &t);
159 
160  return t;
161 }
162 
164 {
165  int i;
166  entity_state_t *ent;
167  int num;
168  cmodel_t *cmodel;
169  int contents;
170 
171  contents = CM_PointContents (point, 0);
172 
173  for (i=0 ; i<cl.frame.num_entities ; i++)
174  {
176  ent = &cl_parse_entities[num];
177 
178  if (ent->solid != 31) // special value for bmodel
179  continue;
180 
181  cmodel = cl.model_clip[ent->modelindex];
182  if (!cmodel)
183  continue;
184 
185  contents |= CM_TransformedPointContents (point, cmodel->headnode, ent->origin, ent->angles);
186  }
187 
188  return contents;
189 }
190 
191 
192 /*
193 =================
194 CL_PredictMovement
195 
196 Sets cl.predicted_origin and cl.predicted_angles
197 =================
198 */
200 {
201  int ack, current;
202  int frame;
203  int oldframe;
204  usercmd_t *cmd;
205  pmove_t pm;
206  int i;
207  int step;
208  int oldz;
209 
210  if (cls.state != ca_active)
211  return;
212 
213  if (cl_paused->value)
214  return;
215 
217  { // just set angles
218  for (i=0 ; i<3 ; i++)
219  {
221  }
222  return;
223  }
224 
227 
228  // if we are too far out of date, just freeze
229  if (current - ack >= CMD_BACKUP)
230  {
231  if (cl_showmiss->value)
232  Com_Printf ("exceeded CMD_BACKUP\n");
233  return;
234  }
235 
236  // copy current state to pmove
237  memset (&pm, 0, sizeof(pm));
238  pm.trace = CL_PMTrace;
240 
242 
244 
245 // SCR_DebugGraph (current - ack - 1, 0);
246 
247  frame = 0;
248 
249  // run frames
250  while (++ack < current)
251  {
252  frame = ack & (CMD_BACKUP-1);
253  cmd = &cl.cmds[frame];
254 
255  pm.cmd = *cmd;
256  Pmove (&pm);
257 
258  // save for debug checking
260  }
261 
262  oldframe = (ack-2) & (CMD_BACKUP-1);
263  oldz = cl.predicted_origins[oldframe][2];
264  step = pm.s.origin[2] - oldz;
265  if (step > 63 && step < 160 && (pm.s.pm_flags & PMF_ON_GROUND) )
266  {
267  cl.predicted_step = step * 0.125;
269  }
270 
271 
272  // copy results out for rendering
273  cl.predicted_origin[0] = pm.s.origin[0]*0.125;
274  cl.predicted_origin[1] = pm.s.origin[1]*0.125;
275  cl.predicted_origin[2] = pm.s.origin[2]*0.125;
276 
278 }
CM_BoxTrace
trace_t CM_BoxTrace(vec3_t start, vec3_t end, vec3_t mins, vec3_t maxs, int headnode, int brushmask)
Definition: cmodel.c:1350
cl_paused
cvar_t * cl_paused
Definition: cl_main.c:60
client_state_t::predicted_origin
vec3_t predicted_origin
Definition: client.h:112
entity_state_s::solid
int solid
Definition: q_shared.h:1158
pm
pmove_t * pm
Definition: pmove.c:48
netchan_t::incoming_acknowledged
int incoming_acknowledged
Definition: qcommon.h:598
trace_t::fraction
float fraction
Definition: q_shared.h:457
VectorSubtract
#define VectorSubtract(a, b, c)
Definition: q_shared.h:163
PMF_NO_PREDICTION
#define PMF_NO_PREDICTION
Definition: q_shared.h:487
entity_state_s
Definition: q_shared.h:1145
frame_t::parse_entities
int parse_entities
Definition: client.h:52
entity_state_s::origin
vec3_t origin
Definition: q_shared.h:1149
client_state_t::prediction_error
vec3_t prediction_error
Definition: client.h:114
client_state_t::predicted_angles
vec3_t predicted_angles
Definition: client.h:113
x
GLint GLenum GLint x
Definition: qgl_win.c:116
client_state_t::viewangles
vec3_t viewangles
Definition: client.h:125
trace_t
Definition: q_shared.h:453
VectorClear
#define VectorClear(a)
Definition: q_shared.h:166
i
int i
Definition: q_shared.c:305
client_state_t::model_clip
struct cmodel_s * model_clip[MAX_MODELS]
Definition: client.h:164
frame_t::num_entities
int num_entities
Definition: client.h:51
ca_active
@ ca_active
Definition: client.h:189
CM_TransformedPointContents
int CM_TransformedPointContents(vec3_t p, int headnode, vec3_t origin, vec3_t angles)
Definition: cmodel.c:937
CL_PredictMovement
void CL_PredictMovement(void)
Definition: cl_pred.c:199
edict_s::mins
vec3_t mins
Definition: g_local.h:990
cmodel_s::headnode
int headnode
Definition: q_shared.h:436
CM_PointContents
int CM_PointContents(vec3_t p, int headnode)
Definition: cmodel.c:917
trace_t::allsolid
qboolean allsolid
Definition: q_shared.h:455
CL_PMTrace
trace_t CL_PMTrace(vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end)
Definition: cl_pred.c:148
cl_showmiss
cvar_t * cl_showmiss
Definition: cl_main.c:57
pmove_t::trace
trace_t(* trace)(vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end)
Definition: q_shared.h:552
edict_s
Definition: g_local.h:968
player_state_t::pmove
pmove_state_t pmove
Definition: q_shared.h:1176
t
GLdouble t
Definition: qgl_win.c:328
cvar_s::value
float value
Definition: q_shared.h:331
client_state_t::cmds
usercmd_t cmds[CMD_BACKUP]
Definition: client.h:105
pmove_state_t::delta_angles
short delta_angles[3]
Definition: q_shared.h:503
frame_t::serverframe
int serverframe
Definition: client.h:46
entity_state_s::number
int number
Definition: q_shared.h:1147
client_state_t::frame
frame_t frame
Definition: client.h:116
CMD_BACKUP
#define CMD_BACKUP
Definition: client.h:85
client_state_t::playernum
int playernum
Definition: client.h:156
client_state_t::predicted_step
float predicted_step
Definition: client.h:109
cmodel_s
Definition: q_shared.h:432
current
static int current
Definition: cl_scrn.c:129
client_state_t::predicted_step_time
unsigned predicted_step_time
Definition: client.h:110
frame_t::playerstate
player_state_t playerstate
Definition: client.h:50
MAX_PARSE_ENTITIES
#define MAX_PARSE_ENTITIES
Definition: client.h:312
client_state_t::predicted_origins
short predicted_origins[CMD_BACKUP][3]
Definition: client.h:107
cl_parse_entities
entity_state_t cl_parse_entities[MAX_PARSE_ENTITIES]
Definition: cl_main.c:95
VectorCopy
#define VectorCopy(a, b)
Definition: q_shared.h:165
netchan_t::outgoing_sequence
int outgoing_sequence
Definition: qcommon.h:603
CL_CheckPredictionError
void CL_CheckPredictionError(void)
Definition: cl_pred.c:29
vec3_origin
vec3_t vec3_origin
Definition: q_shared.c:24
CM_HeadnodeForBox
int CM_HeadnodeForBox(vec3_t mins, vec3_t maxs)
Definition: cmodel.c:775
usercmd_s
Definition: q_shared.h:517
client_static_t::state
connstate_t state
Definition: client.h:204
SHORT2ANGLE
#define SHORT2ANGLE(x)
Definition: q_shared.h:1093
pm_airaccelerate
float pm_airaccelerate
Definition: pmove.c:57
pmove_t::s
pmove_state_t s
Definition: q_shared.h:532
client_static_t::frametime
float frametime
Definition: client.h:209
pmove_t::cmd
usercmd_t cmd
Definition: q_shared.h:535
PMF_ON_GROUND
#define PMF_ON_GROUND
Definition: q_shared.h:483
edict_s::maxs
vec3_t maxs
Definition: g_local.h:990
cl_predict
cvar_t * cl_predict
Definition: cl_main.c:46
trace_t::startsolid
qboolean startsolid
Definition: q_shared.h:456
entity_state_s::modelindex
int modelindex
Definition: q_shared.h:1152
client_state_t::configstrings
char configstrings[MAX_CONFIGSTRINGS][MAX_QPATH]
Definition: client.h:158
trace_t::ent
struct edict_s * ent
Definition: q_shared.h:462
Pmove
void Pmove(pmove_t *pmove)
Definition: pmove.c:1240
pmove_state_t::origin
short origin[3]
Definition: q_shared.h:498
Com_Printf
void Com_Printf(char *fmt,...)
Definition: common.c:104
pmove_t::viewangles
vec3_t viewangles
Definition: q_shared.h:542
cls
client_static_t cls
Definition: cl_main.c:90
CL_PMpointcontents
int CL_PMpointcontents(vec3_t point)
Definition: cl_pred.c:163
CM_TransformedBoxTrace
trace_t CM_TransformedBoxTrace(vec3_t start, vec3_t end, vec3_t mins, vec3_t maxs, int headnode, int brushmask, vec3_t origin, vec3_t angles)
Definition: cmodel.c:1451
MASK_PLAYERSOLID
#define MASK_PLAYERSOLID
Definition: q_shared.h:396
CS_AIRACCEL
#define CS_AIRACCEL
Definition: q_shared.h:1108
pmove_t::pointcontents
int(* pointcontents)(vec3_t point)
Definition: q_shared.h:553
entity_state_s::angles
vec3_t angles
Definition: q_shared.h:1150
cl
client_state_t cl
Definition: cl_main.c:91
pmove_state_t::pm_flags
byte pm_flags
Definition: q_shared.h:500
vec3_t
vec_t vec3_t[3]
Definition: q_shared.h:134
pmove_t
Definition: q_shared.h:529
client.h
CL_ClipMoveToEntities
void CL_ClipMoveToEntities(vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, trace_t *tr)
Definition: cl_pred.c:73
client_static_t::netchan
netchan_t netchan
Definition: client.h:224
client_static_t::realtime
int realtime
Definition: client.h:208