Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
sv_model.qc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 Rudolf Polzer
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to
6 * deal in the Software without restriction, including without limitation the
7 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8 * sell copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 * IN THE SOFTWARE.
21 */
22#include "sv_model.qh"
23
24#include "common.qh"
25
26// generic CSQC model code
27
28#if CSQCPLAYER_FORCE_UPDATES
29.float csqcmodel_originupdatetime;
30#endif
31bool CSQCModel_Send(entity this, entity to, int sf)
32{
33 // some nice flags for CSQCMODEL_IF
34 noref bool isplayer = IS_CLIENT(this);
35 noref bool islocalplayer = (this == to);
36 noref bool isnolocalplayer = (isplayer && (this != to));
37
38 int psf = 0;
39 psf = BITSET(psf, ISPLAYER_CLIENT, isplayer);
40 psf = BITSET(psf, ISPLAYER_LOCAL, islocalplayer);
41 psf = BITSET(psf, ISPLAYER_PLAYER, IS_PLAYER(this));
42
43 WriteHeader(MSG_ENTITY, ENT_CLIENT_MODEL);
44 WriteInt24_t(MSG_ENTITY, sf);
46
47#define CSQCMODEL_IF(cond) if(cond) {
48#define CSQCMODEL_ENDIF }
49#define CSQCMODEL_PROPERTY(flag,t,r,w,f) \
50 if(sf & flag) \
51 { \
52 w(MSG_ENTITY, this.csqcmodel_##f); \
53 }
54#define CSQCMODEL_PROPERTY_SCALED(flag,t,r,w,f,s,mi,ma) \
55 if(sf & flag) \
56 { \
57 w(MSG_ENTITY, this.csqcmodel_##f); \
58 }
60#undef CSQCMODEL_PROPERTY_SCALED
61#undef CSQCMODEL_PROPERTY
62#undef CSQCMODEL_ENDIF
63#undef CSQCMODEL_IF
64
65#if CSQCPLAYER_FORCE_UPDATES
66 if (isplayer && (sf & CSQCMODEL_PROPERTY_ORIGIN))
67 this.csqcmodel_originupdatetime = time;
68#endif
69
70 return true;
71}
72
74{
75 // some nice flags for CSQCMODEL_IF
76 noref float isplayer = IS_CLIENT(e);
77 noref float islocalplayer = isplayer; // we set BOTH to 1 here as we need the sendflags
78 noref float isnolocalplayer = isplayer; // we set BOTH to 1 here as we need the sendflags
79
80#if CSQCPLAYER_FORCE_UPDATES
81 if (isplayer)
82 {
83 // Ensure at least CSQCPLAYER_FORCE_UPDATES origin sends per sec,
84 float interval = 1 / CSQCPLAYER_FORCE_UPDATES;
85 // reducing the interval as needed to keep e's client well within the limits of its replay buffers.
86 if (e.ping && CS(e).pm_frametime)
87 interval = min(interval, 0.75*CL_MAX_USERCMDS * CS(e).pm_frametime - e.ping*0.001);
88 if (time >= e.csqcmodel_originupdatetime + interval)
89 e.SendFlags |= CSQCMODEL_PROPERTY_ORIGIN;
90 }
91#endif
92
93 if(e.effects & EF_RESTARTANIM_BIT)
94 {
95 e.SendFlags |= CSQCMODEL_PROPERTY_FRAME | CSQCMODEL_PROPERTY_FRAME2; // full anim resend please
96 e.effects &= ~EF_RESTARTANIM_BIT;
97 }
98
99 if(e.effects & EF_TELEPORT_BIT)
100 {
101 e.SendFlags |= CSQCMODEL_PROPERTY_TELEPORTED; // no interpolation please
102 e.effects &= ~EF_TELEPORT_BIT;
103 }
104
105#define CSQCMODEL_IF(cond) if(cond) {
106#define CSQCMODEL_ENDIF }
107#define CSQCMODEL_PROPERTY(flag,t,r,w,f) \
108 { \
109 t tmp = e.f; \
110 if(tmp != e.csqcmodel_##f) \
111 { \
112 e.csqcmodel_##f = tmp; \
113 e.SendFlags |= flag; \
114 } \
115 }
116#define CSQCMODEL_PROPERTY_SCALED(flag,t,r,w,f,s,mi,ma) \
117 { \
118 t tmp = rint(bound(mi, s * e.f, ma) - mi); \
119 if(tmp != e.csqcmodel_##f) \
120 { \
121 e.csqcmodel_##f = tmp; \
122 e.SendFlags |= flag; \
123 } \
124 }
126#undef CSQCMODEL_PROPERTY_SCALED
127#undef CSQCMODEL_PROPERTY
128#undef CSQCMODEL_ENDIF
129#undef CSQCMODEL_IF
130}
131
133{
135 e.SendFlags = 0xFFFFFF;
137}
138
#define BITSET(var, mask, flag)
Definition bits.qh:11
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
#define IS_CLIENT(s)
Definition player.qh:241
#define IS_PLAYER(s)
Definition player.qh:242
float time
const int EF_TELEPORT_BIT
const int EF_RESTARTANIM_BIT
#define CSQCPLAYER_FORCE_UPDATES
const int ISPLAYER_PLAYER
Definition common.qh:59
const int CSQCMODEL_PROPERTY_FRAME2
Definition common.qh:67
const int ISPLAYER_LOCAL
Definition common.qh:58
const int CSQCMODEL_PROPERTY_FRAME
Definition common.qh:61
const int ISPLAYER_CLIENT
Definition common.qh:57
#define ALLPROPERTIES
Definition common.qh:93
const int CSQCMODEL_PROPERTY_ORIGIN
Definition common.qh:64
const int CSQCMODEL_PROPERTY_TELEPORTED
Definition common.qh:62
#define CL_MAX_USERCMDS
Definition common.qh:96
const int MSG_ENTITY
Definition net.qh:156
#define WriteHeader(to, id)
Definition net.qh:265
float min(float f,...)
void WriteByte(float data, float dest, float desto)
var void func_null()
#define setSendEntity(e, f)
ClientState CS(Client this)
Definition state.qh:47
void CSQCModel_LinkEntity(entity e)
Definition sv_model.qc:132
void CSQCModel_CheckUpdate(entity e)
Definition sv_model.qc:73
void CSQCModel_UnlinkEntity(entity e)
Definition sv_model.qc:139
bool CSQCModel_Send(entity this, entity to, int sf)
Definition sv_model.qc:31