]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/csqcmodel.qc
c03d0f5e9ed9bd5b9ca7e5700079da6c9133815b
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / csqcmodel.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 .vector glowmod;
26 .vector view_ofs;
27
28 #define ALLPROPERTIES \
29         PROPERTY(1, ReadCoord, WriteCoord, origin_x) \
30         PROPERTY(1, ReadCoord, WriteCoord, origin_y) \
31         PROPERTY(1, ReadCoord, WriteCoord, origin_z) \
32         PROPERTY(2, ReadAngle, WriteAngle, angles_x) \
33         PROPERTY(2, ReadAngle, WriteAngle, angles_y) \
34         PROPERTY(2, ReadAngle, WriteAngle, angles_z) \
35         PROPERTY(4, ReadShort, WriteShort, modelindex) \
36         PROPERTY(8, ReadByte, WriteByte, frame) \
37         PROPERTY(16, ReadByte, WriteByte, skin) \
38         PROPERTY(32, ReadInt24_t, WriteInt24_t, effects) \
39         PROPERTY_SCALED(64, ReadByte, WriteByte, alpha, 255, 0, 255) \
40         PROPERTY_SCALED(128, ReadByte, WriteByte, glowmod_x, 32, 0, 255) \
41         PROPERTY_SCALED(128, ReadByte, WriteByte, glowmod_y, 32, 0, 255) \
42         PROPERTY_SCALED(128, ReadByte, WriteByte, glowmod_z, 32, 0, 255) \
43         PROPERTY(256, ReadChar, WriteChar, view_ofs_z) \
44         PROPERTY(512, ReadShort, WriteShort, colormap)
45
46 #ifdef SVQC
47
48 #define PROPERTY(flag,r,w,f) \
49         .float csqcmodel_##f;
50 #define PROPERTY_SCALED(flag,r,w,f,s,mi,ma) PROPERTY(flag,r,w,f)
51         ALLPROPERTIES
52 #undef PROPERTY_SCALED
53 #undef PROPERTY
54
55 float CSQCModel_Send(entity to, float sf)
56 {
57         WriteByte(MSG_ENTITY, ENT_CLIENT_MODEL);
58         WriteShort(MSG_ENTITY, sf);
59
60 #define PROPERTY(flag,r,w,f) \
61         if(sf & flag) \
62         { \
63                 w(MSG_ENTITY, self.csqcmodel_##f); \
64         }
65 #define PROPERTY_SCALED(flag,r,w,f,s,mi,ma) PROPERTY(flag,r,w,f)
66         ALLPROPERTIES
67 #undef PROPERTY_SCALED
68 #undef PROPERTY
69
70         return TRUE;
71 }
72
73 void CSQCModel_CheckUpdate()
74 {
75         float tmp;
76 #define PROPERTY(flag,r,w,f) \
77         tmp = self.f; \
78         if(tmp != self.csqcmodel_##f) \
79         { \
80                 self.csqcmodel_##f = tmp; \
81                 self.SendFlags |= flag; \
82         }
83 #define PROPERTY_SCALED(flag,r,w,f,s,mi,ma) \
84         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         ALLPROPERTIES
91 #undef PROPERTY_SCALED
92 #undef PROPERTY
93 }
94
95 void CSQCModel_LinkEntity()
96 {
97         Net_LinkEntity(self, TRUE, 0, CSQCModel_Send);
98 }
99
100 #endif
101
102 #ifdef CSQC
103
104 void CSQCModel_Draw()
105 {
106         InterpolateOrigin_Do();
107 }
108
109 void CSQCModel_Read()
110 {
111         float sf;
112         sf = ReadShort();
113
114         CSQCPlayer_PreUpdate();
115         InterpolateOrigin_Undo();
116
117 #define PROPERTY(flag,r,w,f) \
118         if(sf & flag) \
119                 self.f = r();
120 #define PROPERTY_SCALED(flag,r,w,f,s,mi,ma) \
121         if(sf & flag) \
122                 self.f = r() / s;
123         ALLPROPERTIES
124 #undef PROPERTY_SCALED
125 #undef PROPERTY
126         
127         InterpolateOrigin_Note();
128         CSQCPlayer_PostUpdate();
129
130         // draw it
131         self.drawmask = MASK_NORMAL;
132         self.predraw = CSQCModel_Draw;
133 }
134
135 #endif