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
28bool CSQCModel_Send(entity this, entity to, int sf)
29{
30 // some nice flags for CSQCMODEL_IF
31 noref bool isplayer = IS_CLIENT(this);
32 noref bool islocalplayer = (this == to);
33 noref bool isnolocalplayer = (isplayer && (this != to));
34
35 int psf = 0;
36 psf = BITSET(psf, ISPLAYER_CLIENT, isplayer);
37 psf = BITSET(psf, ISPLAYER_LOCAL, islocalplayer);
38 psf = BITSET(psf, ISPLAYER_PLAYER, IS_PLAYER(this));
39
40 WriteHeader(MSG_ENTITY, ENT_CLIENT_MODEL);
41 WriteInt24_t(MSG_ENTITY, sf);
43
44#define CSQCMODEL_IF(cond) if(cond) {
45#define CSQCMODEL_ENDIF }
46#define CSQCMODEL_PROPERTY(flag,t,r,w,f) \
47 if(sf & flag) \
48 { \
49 w(MSG_ENTITY, this.csqcmodel_##f); \
50 }
51#define CSQCMODEL_PROPERTY_SCALED(flag,t,r,w,f,s,mi,ma) \
52 if(sf & flag) \
53 { \
54 w(MSG_ENTITY, this.csqcmodel_##f); \
55 }
57#undef CSQCMODEL_PROPERTY_SCALED
58#undef CSQCMODEL_PROPERTY
59#undef CSQCMODEL_ENDIF
60#undef CSQCMODEL_IF
61
62 return true;
63}
64
65#if CSQCPLAYER_FORCE_UPDATES
66.float csqcmodel_nextforcedupdate;
67#endif
69{
70 // some nice flags for CSQCMODEL_IF
71 noref float isplayer = IS_CLIENT(e);
72 noref float islocalplayer = isplayer; // we set BOTH to 1 here as we need the sendflags
73 noref float isnolocalplayer = isplayer; // we set BOTH to 1 here as we need the sendflags
74
75#if CSQCPLAYER_FORCE_UPDATES
76 if(isplayer && time > e.csqcmodel_nextforcedupdate)
77 {
78 e.SendFlags |= CSQCMODEL_PROPERTY_ORIGIN;
79 e.csqcmodel_nextforcedupdate = time + (1 / (CSQCPLAYER_FORCE_UPDATES)) * (0.5 + random()); // ensure about 4 origin sends per sec
80 }
81#endif
82
83 if(e.effects & EF_RESTARTANIM_BIT)
84 {
85 e.SendFlags |= CSQCMODEL_PROPERTY_FRAME | CSQCMODEL_PROPERTY_FRAME2; // full anim resend please
86 e.effects &= ~EF_RESTARTANIM_BIT;
87 }
88
89 if(e.effects & EF_TELEPORT_BIT)
90 {
91 e.SendFlags |= CSQCMODEL_PROPERTY_TELEPORTED; // no interpolation please
92 e.effects &= ~EF_TELEPORT_BIT;
93 }
94
95#define CSQCMODEL_IF(cond) if(cond) {
96#define CSQCMODEL_ENDIF }
97#define CSQCMODEL_PROPERTY(flag,t,r,w,f) \
98 { \
99 t tmp = e.f; \
100 if(tmp != e.csqcmodel_##f) \
101 { \
102 e.csqcmodel_##f = tmp; \
103 e.SendFlags |= flag; \
104 } \
105 }
106#define CSQCMODEL_PROPERTY_SCALED(flag,t,r,w,f,s,mi,ma) \
107 { \
108 t tmp = rint(bound(mi, s * e.f, ma) - mi); \
109 if(tmp != e.csqcmodel_##f) \
110 { \
111 e.csqcmodel_##f = tmp; \
112 e.SendFlags |= flag; \
113 } \
114 }
116#undef CSQCMODEL_PROPERTY_SCALED
117#undef CSQCMODEL_PROPERTY
118#undef CSQCMODEL_ENDIF
119#undef CSQCMODEL_IF
120}
121
123{
125 e.SendFlags = 0xFFFFFF;
127}
128
#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:242
#define IS_PLAYER(s)
Definition player.qh:243
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
const int MSG_ENTITY
Definition net.qh:115
#define WriteHeader(to, id)
Definition net.qh:221
float random(void)
void WriteByte(float data, float dest, float desto)
var void func_null()
#define setSendEntity(e, f)
void CSQCModel_LinkEntity(entity e)
Definition sv_model.qc:122
void CSQCModel_CheckUpdate(entity e)
Definition sv_model.qc:68
void CSQCModel_UnlinkEntity(entity e)
Definition sv_model.qc:129
bool CSQCModel_Send(entity this, entity to, int sf)
Definition sv_model.qc:28