Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
cl_model.qc File Reference
#include "cl_model.qh"
#include "cl_player.qh"
#include "common.qh"
#include "interpolate.qh"
#include <common/csqcmodel_settings.qh>
Include dependency graph for cl_model.qc:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define CSQCMODEL_ENDIF   }
#define CSQCMODEL_IF(cond)
#define CSQCMODEL_PROPERTY(flag, t, r, w, f)
#define CSQCMODEL_PROPERTY_SCALED(flag, t, r, w, f, s, mi, ma)

Functions

void CSQCModel_Draw (entity this)
void CSQCModel_InterpolateAnimation_1To2_Do (entity this)
void CSQCModel_InterpolateAnimation_1To2_Note (entity this, int sf, bool set_times)
void CSQCModel_InterpolateAnimation_1To2_PreNote (entity this, int sf)
void CSQCModel_InterpolateAnimation_2To4_Do (entity this)
void CSQCModel_InterpolateAnimation_2To4_Note (entity this, int sf, bool set_times)
void CSQCModel_InterpolateAnimation_2To4_PreNote (entity this, int sf)
void CSQCModel_InterpolateAnimation_Do (entity this)
void CSQCModel_InterpolateAnimation_Note (entity this, int sf)
void CSQCModel_InterpolateAnimation_PreNote (entity this, int sf)
void CSQCModel_remove (entity this)
entity CSQCModel_server2csqc (int i)
 NET_HANDLE (ENT_CLIENT_MODEL, bool isnew)

Variables

float autocvar_cl_lerpanim_maxdelta_framegroups = 0.1
float autocvar_cl_nolerp = 0
float csqcmodel_lerpfrac
float csqcmodel_lerpfrac2
float csqcmodel_lerpfrac2time
float csqcmodel_lerpfractime
entity CSQCModel_players [255]

Macro Definition Documentation

◆ CSQCMODEL_ENDIF

#define CSQCMODEL_ENDIF   }

◆ CSQCMODEL_IF

#define CSQCMODEL_IF ( cond)
Value:
if(cond) {

◆ CSQCMODEL_PROPERTY

#define CSQCMODEL_PROPERTY ( flag,
t,
r,
w,
f )
Value:
if(sf & flag) \
this.f = r();

◆ CSQCMODEL_PROPERTY_SCALED

#define CSQCMODEL_PROPERTY_SCALED ( flag,
t,
r,
w,
f,
s,
mi,
ma )
Value:
if(sf & flag) \
this.f = (r() + mi) / s;

Function Documentation

◆ CSQCModel_Draw()

void CSQCModel_Draw ( entity this)

Definition at line 179 of file cl_model.qc.

180{
181 // some nice flags for CSQCMODEL_IF and the hooks
182 bool isplayer = (this.isplayermodel & ISPLAYER_CLIENT);
183 noref bool islocalplayer = (this.entnum == player_localnum + 1);
184 noref bool isnolocalplayer = (isplayer && (this.entnum != player_localnum + 1));
185
186 // we don't do this for the local player as that one is already handled
187 // by CSQCPlayer_SetCamera()
189
191
192 CSQCModel_Hook_PreDraw(this, isplayer);
193
194 if(isplayer)
195 {
196 if(this.entnum == player_localentnum)
198 else
200 }
201
202 // inherit draw flags easily
203 entity root = this;
204 while(root.tag_entity)
205 root = root.tag_entity;
206 if(this != root)
207 {
209 this.renderflags |= (root.renderflags & (RF_EXTERNALMODEL | RF_VIEWMODEL));
210 }
211
212 // we're drawn, now teleporting is over
213 this.csqcmodel_teleported = 0;
214}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
void CSQCModel_InterpolateAnimation_Do(entity this)
Definition cl_model.qc:170
float csqcmodel_teleported
Definition cl_model.qh:39
bool CSQCPlayer_IsLocalPlayer(entity this)
Definition cl_player.qc:210
float renderflags
Definition main.qh:111
float player_localnum
const float RF_VIEWMODEL
float player_localentnum
float entnum
const float RF_EXTERNALMODEL
void CSQCModel_Hook_PreDraw(entity this, bool isplayer)
int isplayermodel
void InterpolateOrigin_Do(entity this)
set origin based on iorigin1 (old pos), iorigin2 (desired pos), and time
const int ISPLAYER_CLIENT
Definition common.qh:57

References CSQCModel_Hook_PreDraw(), CSQCModel_InterpolateAnimation_Do(), csqcmodel_teleported, CSQCPlayer_IsLocalPlayer(), entity(), entnum, InterpolateOrigin_Do(), ISPLAYER_CLIENT, isplayermodel, player_localentnum, player_localnum, renderflags, RF_EXTERNALMODEL, and RF_VIEWMODEL.

Referenced by NET_HANDLE().

◆ CSQCModel_InterpolateAnimation_1To2_Do()

void CSQCModel_InterpolateAnimation_1To2_Do ( entity this)

Definition at line 156 of file cl_model.qc.

157{
159 {
160 this.lerpfrac = 0;
161 }
162 else
163 {
164 if(this.frame2time == 0) // if frame2 was not previously displayed, only frame1 can make sense
165 this.lerpfrac = 0;
166 else
168 }
169}
float frame1time
start time of framegroup animation
Definition anim.qh:22
float frame2time
start time of framegroup animation
Definition anim.qh:24
float lerpfrac
strength of framegroup blend
Definition anim.qh:15
float autocvar_cl_nolerp
Definition cl_model.qc:30
float autocvar_cl_lerpanim_maxdelta_framegroups
Definition cl_model.qc:29
float time
float bound(float min, float value, float max)

References autocvar_cl_lerpanim_maxdelta_framegroups, autocvar_cl_nolerp, bound(), entity(), frame1time, frame2time, lerpfrac, and time.

Referenced by CSQCModel_InterpolateAnimation_Do().

◆ CSQCModel_InterpolateAnimation_1To2_Note()

void CSQCModel_InterpolateAnimation_1To2_Note ( entity this,
int sf,
bool set_times )

Definition at line 92 of file cl_model.qc.

93{
95 {
96 if(set_times)
97 this.frame1time = time;
98 }
99}
const int CSQCMODEL_PROPERTY_FRAME
Definition common.qh:61

References CSQCMODEL_PROPERTY_FRAME, entity(), frame1time, and time.

Referenced by CSQCModel_InterpolateAnimation_Note().

◆ CSQCModel_InterpolateAnimation_1To2_PreNote()

void CSQCModel_InterpolateAnimation_1To2_PreNote ( entity this,
int sf )

Definition at line 56 of file cl_model.qc.

57{
59 {
60 this.frame2 = this.frame;
61 this.frame2time = this.frame1time;
62 }
63}
float frame2
secondary framegroup animation (strength = lerpfrac)
Definition anim.qh:8
float frame
primary framegroup animation (strength = 1 - lerpfrac - lerpfrac3 - lerpfrac4)
Definition anim.qh:6

References CSQCMODEL_PROPERTY_FRAME, entity(), frame, frame1time, frame2, and frame2time.

Referenced by CSQCModel_InterpolateAnimation_PreNote().

◆ CSQCModel_InterpolateAnimation_2To4_Do()

void CSQCModel_InterpolateAnimation_2To4_Do ( entity this)

Definition at line 109 of file cl_model.qc.

110{
112 {
113 this.lerpfrac = this.csqcmodel_lerpfrac;
114 this.lerpfrac3 = 0;
115 this.lerpfrac4 = 0;
116 }
117 else
118 {
119 float l13, l24, llf;
120 float l24_13;
121
122 if(this.frame3time == 0) // if frame1/3 were not previously displayed, only frame1 can make sense
123 l13 = 1;
124 else
126
127 if(this.frame4time == 0) // if frame2/4 were not previously displayed, only frame2 can make sense
128 l24 = 1;
129 else
131
132 if(this.csqcmodel_lerpfrac2time == 0) // if there is no old lerpfrac (newly displayed model), only lerpfrac makes sense
133 llf = 1;
134 else
136
137 l24_13 = this.csqcmodel_lerpfrac * llf + this.csqcmodel_lerpfrac2 * (1 - llf);
138
139 this.lerpfrac = l24 * l24_13;
140 this.lerpfrac4 = (1 - l24) * l24_13;
141 this.lerpfrac3 = (1 - l13) * (1 - l24_13);
142
143 if(l24_13 == 0) // if frames 2/4 are not displayed, clear their frametime
144 {
145 this.frame2time = 0;
146 this.frame4time = 0;
147 }
148
149 if(l24_13 == 1) // if frames 1/3 are not displayed, clear their frametime
150 {
151 this.frame1time = 0;
152 this.frame3time = 0;
153 }
154 }
155}
float frame3time
start time of framegroup animation
Definition anim.qh:26
float lerpfrac4
strength of framegroup blend
Definition anim.qh:19
float frame4time
start time of framegroup animation
Definition anim.qh:28
float lerpfrac3
strength of framegroup blend
Definition anim.qh:17
float csqcmodel_lerpfrac
Definition cl_model.qc:32
float csqcmodel_lerpfractime
Definition cl_model.qc:34
float csqcmodel_lerpfrac2time
Definition cl_model.qc:35
float csqcmodel_lerpfrac2
Definition cl_model.qc:33

References autocvar_cl_lerpanim_maxdelta_framegroups, autocvar_cl_nolerp, bound(), csqcmodel_lerpfrac, csqcmodel_lerpfrac2, csqcmodel_lerpfrac2time, csqcmodel_lerpfractime, entity(), frame1time, frame2time, frame3time, frame4time, lerpfrac, lerpfrac3, lerpfrac4, and time.

Referenced by CSQCModel_Hook_PreDraw(), and CSQCModel_InterpolateAnimation_Do().

◆ CSQCModel_InterpolateAnimation_2To4_Note()

void CSQCModel_InterpolateAnimation_2To4_Note ( entity this,
int sf,
bool set_times )

Definition at line 73 of file cl_model.qc.

74{
76 {
77 if(set_times)
78 this.frame1time = time;
79 }
81 {
82 if(set_times)
83 this.frame2time = time;
84 }
86 {
87 this.csqcmodel_lerpfrac = this.lerpfrac;
88 if(set_times)
90 }
91}
const int CSQCMODEL_PROPERTY_FRAME2
Definition common.qh:67
const int CSQCMODEL_PROPERTY_LERPFRAC
Definition common.qh:68

References csqcmodel_lerpfrac, csqcmodel_lerpfractime, CSQCMODEL_PROPERTY_FRAME, CSQCMODEL_PROPERTY_FRAME2, CSQCMODEL_PROPERTY_LERPFRAC, entity(), frame1time, frame2time, lerpfrac, and time.

Referenced by CSQCModel_Hook_PreDraw(), and CSQCModel_InterpolateAnimation_Note().

◆ CSQCModel_InterpolateAnimation_2To4_PreNote()

void CSQCModel_InterpolateAnimation_2To4_PreNote ( entity this,
int sf )

Definition at line 37 of file cl_model.qc.

38{
40 {
41 this.frame3 = this.frame;
42 this.frame3time = this.frame1time;
43 }
45 {
46 this.frame4 = this.frame2;
47 this.frame4time = this.frame2time;
48 }
50 {
53 this.lerpfrac = this.csqcmodel_lerpfrac;
54 }
55}
float frame3
tertiary framegroup animation (strength = lerpfrac3)
Definition anim.qh:10
float frame4
quaternary framegroup animation (strength = lerpfrac4)
Definition anim.qh:12

References csqcmodel_lerpfrac, csqcmodel_lerpfrac2, csqcmodel_lerpfrac2time, csqcmodel_lerpfractime, CSQCMODEL_PROPERTY_FRAME, CSQCMODEL_PROPERTY_FRAME2, CSQCMODEL_PROPERTY_LERPFRAC, entity(), frame, frame1time, frame2, frame2time, frame3, frame3time, frame4, frame4time, and lerpfrac.

Referenced by CSQCModel_Hook_PreDraw(), and CSQCModel_InterpolateAnimation_PreNote().

◆ CSQCModel_InterpolateAnimation_Do()

void CSQCModel_InterpolateAnimation_Do ( entity this)

Definition at line 170 of file cl_model.qc.

171{
172#ifdef CSQCMODEL_HAVE_TWO_FRAMES
174#else
176#endif
177}
void CSQCModel_InterpolateAnimation_1To2_Do(entity this)
Definition cl_model.qc:156
void CSQCModel_InterpolateAnimation_2To4_Do(entity this)
Definition cl_model.qc:109

References CSQCModel_InterpolateAnimation_1To2_Do(), CSQCModel_InterpolateAnimation_2To4_Do(), and entity().

Referenced by CSQCModel_Draw(), and NET_HANDLE().

◆ CSQCModel_InterpolateAnimation_Note()

void CSQCModel_InterpolateAnimation_Note ( entity this,
int sf )

Definition at line 100 of file cl_model.qc.

101{
102#ifdef CSQCMODEL_HAVE_TWO_FRAMES
104#else
106#endif
107}
void CSQCModel_InterpolateAnimation_1To2_Note(entity this, int sf, bool set_times)
Definition cl_model.qc:92
void CSQCModel_InterpolateAnimation_2To4_Note(entity this, int sf, bool set_times)
Definition cl_model.qc:73

References CSQCModel_InterpolateAnimation_1To2_Note(), CSQCModel_InterpolateAnimation_2To4_Note(), and entity().

Referenced by NET_HANDLE().

◆ CSQCModel_InterpolateAnimation_PreNote()

void CSQCModel_InterpolateAnimation_PreNote ( entity this,
int sf )

Definition at line 64 of file cl_model.qc.

65{
66#ifdef CSQCMODEL_HAVE_TWO_FRAMES
68#else
70#endif
71}
void CSQCModel_InterpolateAnimation_2To4_PreNote(entity this, int sf)
Definition cl_model.qc:37
void CSQCModel_InterpolateAnimation_1To2_PreNote(entity this, int sf)
Definition cl_model.qc:56

References CSQCModel_InterpolateAnimation_1To2_PreNote(), CSQCModel_InterpolateAnimation_2To4_PreNote(), and entity().

Referenced by NET_HANDLE().

◆ CSQCModel_remove()

void CSQCModel_remove ( entity this)

Definition at line 218 of file cl_model.qc.

219{
220 CSQCModel_players[this.entnum - 1] = NULL;
221}
entity CSQCModel_players[255]
Definition cl_model.qc:216
#define NULL
Definition post.qh:14

References CSQCModel_players, entity(), entnum, and NULL.

Referenced by NET_HANDLE().

◆ CSQCModel_server2csqc()

entity CSQCModel_server2csqc ( int i)
Parameters
izero indexed player

Definition at line 314 of file cl_model.qc.

315{
316 if (i < maxclients) return CSQCModel_players[i];
317 ++i;
318 LOG_DEBUGF("player out of bounds: %d", i);
319 return findfloat(NULL, entnum, i);
320}
float maxclients
#define LOG_DEBUGF(...)
Definition log.qh:81
entity findfloat(entity start,.float field, float match)

References CSQCModel_players, entity(), entnum, findfloat(), LOG_DEBUGF, maxclients, and NULL.

Referenced by CSQC_UpdateView(), CSQCPlayer_SetCamera(), entcs_GetAlpha(), entcs_GetColor(), entcs_IsDead(), Hud_Dynamic_Frame(), Scoreboard_WouldDraw(), StrafeHUD_GetStrafeplayer(), viewloc_SetViewLocation(), viewmodel_animate(), and viewmodel_draw().

◆ NET_HANDLE()

NET_HANDLE ( ENT_CLIENT_MODEL ,
bool isnew )

Definition at line 223 of file cl_model.qc.

224{
225 int sf = ReadInt24_t();
226 int psf = ReadByte();
227
228 // some nice flags for CSQCMODEL_IF and the hooks
229 bool isplayer = (psf & ISPLAYER_CLIENT) || (this.entnum >= 1 && this.entnum <= maxclients);
230 if (isnew && isplayer)
231 {
232 CSQCModel_players[this.entnum - 1] = this;
233 this.entremove = CSQCModel_remove;
234 }
235 bool islocalplayer = (this.entnum == player_localnum + 1);
236 noref bool isnolocalplayer = (isplayer && !islocalplayer);
237
238 this.isplayermodel = BITSET(this.isplayermodel, ISPLAYER_CLIENT, isplayer);
239 this.isplayermodel = BITSET(this.isplayermodel, ISPLAYER_LOCAL, islocalplayer);
241
242 this.iflags |= IFLAG_ORIGIN; // interpolate origin too
243 this.iflags |= IFLAG_ANGLES; // interpolate angles too
244 this.iflags |= IFLAG_VELOCITY | IFLAG_AUTOVELOCITY; // let's calculate velocity automatically
245
246 CSQCModel_Hook_PreUpdate(this, isnew, isplayer, islocalplayer);
247
251
252#define CSQCMODEL_IF(cond) if(cond) {
253#define CSQCMODEL_ENDIF }
254#define CSQCMODEL_PROPERTY(flag,t,r,w,f) \
255 if(sf & flag) \
256 this.f = r();
257#define CSQCMODEL_PROPERTY_SCALED(flag,t,r,w,f,s,mi,ma) \
258 if(sf & flag) \
259 this.f = (r() + mi) / s;
261#undef CSQCMODEL_PROPERTY_SCALED
262#undef CSQCMODEL_PROPERTY
263#undef CSQCMODEL_ENDIF
264#undef CSQCMODEL_IF
265
267 {
268 vector pmin = this.mins, pmax = this.maxs;
269 setmodelindex(this, this.modelindex); // this retrieves the .model key and sets mins/maxs/absmin/absmax
270 setsize(this, pmin, pmax);
271 }
272
274 {
275 this.iflags |= IFLAG_TELEPORTED;
276 this.csqcmodel_teleported = 1;
277 }
278
279 if(sf & BIT(3))
280 this.alpha = this.m_alpha;
281
282 if(sf & BIT(11))
283 viewloc_SetTags(this);
284
288
289 CSQCModel_Hook_PostUpdate(this, isnew, isplayer, islocalplayer);
290
291#ifdef CSQCMODEL_SUPPORT_GETTAGINFO_BEFORE_DRAW
294#endif
295
296 // relink
297 setorigin(this, this.origin);
298
299 // set obvious render flags
300 if(this.entnum == player_localentnum)
302 else
304
305 // draw it
306 this.drawmask = MASK_NORMAL;
308 return true;
309}
#define BIT(n)
Only ever assign into the first 24 bits in QC (so max is BIT(23)).
Definition bits.qh:8
#define BITSET(var, mask, flag)
Definition bits.qh:11
void CSQCModel_remove(entity this)
Definition cl_model.qc:218
void CSQCModel_InterpolateAnimation_Note(entity this, int sf)
Definition cl_model.qc:100
void CSQCModel_Draw(entity this)
Definition cl_model.qc:179
void CSQCModel_InterpolateAnimation_PreNote(entity this, int sf)
Definition cl_model.qc:64
bool CSQCPlayer_PreUpdate(entity this)
Definition cl_player.qc:673
bool CSQCPlayer_PostUpdate(entity this)
Definition cl_player.qc:680
float alpha
Definition items.qc:13
float drawmask
float modelindex
const float MASK_NORMAL
vector mins
vector maxs
vector origin
void CSQCModel_Hook_PostUpdate(entity this, bool isnew, bool isplayer, bool islocalplayer)
void CSQCModel_Hook_PreUpdate(entity this, bool isnew, bool isplayer, bool islocalplayer)
float m_alpha
void InterpolateOrigin_Undo(entity this)
snap origin to iorigin2 (actual origin)
void InterpolateOrigin_Note(entity this)
const int IFLAG_AUTOVELOCITY
const int IFLAG_VELOCITY
const int IFLAG_ANGLES
const int IFLAG_ORIGIN
const int IFLAG_TELEPORTED
int iflags
const int CSQCMODEL_PROPERTY_MODELINDEX
Definition common.qh:63
const int ISPLAYER_PLAYER
Definition common.qh:59
const int ISPLAYER_LOCAL
Definition common.qh:58
#define ALLPROPERTIES
Definition common.qh:93
const int CSQCMODEL_PROPERTY_TELEPORTED
Definition common.qh:62
int ReadInt24_t()
Definition net.qh:355
int ReadByte()
vector
Definition self.qh:92
#define setpredraw(e, f)
Definition self.qh:84
void viewloc_SetTags(entity this)
Definition viewloc.qc:74

References ALLPROPERTIES, alpha, BIT, BITSET, CSQCModel_Draw(), CSQCModel_Hook_PostUpdate(), CSQCModel_Hook_PreUpdate(), CSQCModel_InterpolateAnimation_Do(), CSQCModel_InterpolateAnimation_Note(), CSQCModel_InterpolateAnimation_PreNote(), CSQCModel_players, CSQCMODEL_PROPERTY_MODELINDEX, CSQCMODEL_PROPERTY_TELEPORTED, CSQCModel_remove(), csqcmodel_teleported, CSQCPlayer_PostUpdate(), CSQCPlayer_PreUpdate(), drawmask, entnum, IFLAG_ANGLES, IFLAG_AUTOVELOCITY, IFLAG_ORIGIN, IFLAG_TELEPORTED, IFLAG_VELOCITY, iflags, InterpolateOrigin_Do(), InterpolateOrigin_Note(), InterpolateOrigin_Undo(), ISPLAYER_CLIENT, ISPLAYER_LOCAL, ISPLAYER_PLAYER, isplayermodel, m_alpha, MASK_NORMAL, maxclients, maxs, mins, modelindex, origin, player_localentnum, player_localnum, ReadByte(), ReadInt24_t(), renderflags, RF_EXTERNALMODEL, setpredraw, vector, and viewloc_SetTags().

Variable Documentation

◆ autocvar_cl_lerpanim_maxdelta_framegroups

float autocvar_cl_lerpanim_maxdelta_framegroups = 0.1

◆ autocvar_cl_nolerp

float autocvar_cl_nolerp = 0

◆ csqcmodel_lerpfrac

◆ csqcmodel_lerpfrac2

float csqcmodel_lerpfrac2

◆ csqcmodel_lerpfrac2time

float csqcmodel_lerpfrac2time

◆ csqcmodel_lerpfractime

◆ CSQCModel_players

entity CSQCModel_players[255]

Definition at line 216 of file cl_model.qc.

Referenced by CSQCModel_remove(), CSQCModel_server2csqc(), and NET_HANDLE().