]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/csqcmodel/sv_model.qc
Merge remote-tracking branch 'origin/divVerent/csqcmodel'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / 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
23 // generic CSQC model code
24
25 float CSQCModel_Send(entity to, float sf)
26 {
27         // some nice flags for CSQCMODEL_IF
28         float isplayer = (self.flags & FL_CLIENT);
29         float islocalplayer = (self == to);
30         float isnolocalplayer = (isplayer && (self != to));
31
32         WriteByte(MSG_ENTITY, ENT_CLIENT_MODEL);
33         WriteShort(MSG_ENTITY, sf);
34
35 #define CSQCMODEL_IF(cond) if(cond) {
36 #define CSQCMODEL_ENDIF }
37 #define CSQCMODEL_PROPERTY(flag,t,r,w,f) \
38         if(sf & flag) \
39         { \
40                 w(MSG_ENTITY, self.csqcmodel_##f); \
41         }
42 #define CSQCMODEL_PROPERTY_SCALED(flag,t,r,w,f,s,mi,ma) CSQCMODEL_PROPERTY(flag,t,r,w,f)
43         ALLPROPERTIES
44 #undef CSQCMODEL_PROPERTY_SCALED
45 #undef CSQCMODEL_PROPERTY
46 #undef CSQCMODEL_ENDIF
47 #undef CSQCMODEL_IF
48
49         return TRUE;
50 }
51
52 void CSQCModel_CheckUpdate()
53 {
54         // some nice flags for CSQCMODEL_IF
55         float isplayer = (self.flags & FL_CLIENT);
56         float islocalplayer = isplayer; // we set BOTH to 1 here as we need the sendflags
57         float isnolocalplayer = isplayer; // we set BOTH to 1 here as we need the sendflags
58
59         if(self.effects & EF_RESTARTANIM_BIT)
60         {
61                 self.SendFlags |= CSQCMODEL_PROPERTY_FRAME | CSQCMODEL_PROPERTY_FRAME2; // full anim resend please
62                 self.effects &~= EF_RESTARTANIM_BIT;
63         }
64
65         if(self.effects & EF_TELEPORT_BIT)
66         {
67                 self.SendFlags |= CSQCMODEL_PROPERTY_TELEPORTED; // no interpolation please
68                 self.effects &~= EF_TELEPORT_BIT;
69         }
70
71 #define CSQCMODEL_IF(cond) if(cond) {
72 #define CSQCMODEL_ENDIF }
73 #define CSQCMODEL_PROPERTY(flag,t,r,w,f) \
74         { \
75                 t tmp = self.f; \
76                 if(tmp != self.csqcmodel_##f) \
77                 { \
78                         self.csqcmodel_##f = tmp; \
79                         self.SendFlags |= flag; \
80                 } \
81         }
82 #define CSQCMODEL_PROPERTY_SCALED(flag,t,r,w,f,s,mi,ma) \
83         { \
84                 t tmp = bound(mi, s * self.f, ma); \
85                 if(tmp != self.csqcmodel_##f) \
86                 { \
87                         self.csqcmodel_##f = tmp; \
88                         self.SendFlags |= flag; \
89                 } \
90         }
91         ALLPROPERTIES
92 #undef CSQCMODEL_PROPERTY_SCALED
93 #undef CSQCMODEL_PROPERTY
94 #undef CSQCMODEL_ENDIF
95 #undef CSQCMODEL_IF
96 }
97
98 void CSQCModel_LinkEntity()
99 {
100         self.SendEntity = CSQCModel_Send;
101         self.SendFlags = 0xFFFFFF;
102 }
103
104 void CSQCModel_UnlinkEntity()
105 {
106         self.SendEntity = func_null;
107 }