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