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