2 * Copyright (c) 2011 Rudolf Polzer
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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
23 // generic CSQC model code
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)
48 #define PROPERTY(flag,r,w,f) \
50 #define PROPERTY_SCALED(flag,r,w,f,s,mi,ma) PROPERTY(flag,r,w,f)
52 #undef PROPERTY_SCALED
55 float CSQCModel_Send(entity to, float sf)
57 WriteByte(MSG_ENTITY, ENT_CLIENT_MODEL);
58 WriteShort(MSG_ENTITY, sf);
60 #define PROPERTY(flag,r,w,f) \
63 w(MSG_ENTITY, self.csqcmodel_##f); \
65 #define PROPERTY_SCALED(flag,r,w,f,s,mi,ma) PROPERTY(flag,r,w,f)
67 #undef PROPERTY_SCALED
73 void CSQCModel_CheckUpdate()
76 #define PROPERTY(flag,r,w,f) \
78 if(tmp != self.csqcmodel_##f) \
80 self.csqcmodel_##f = tmp; \
81 self.SendFlags |= flag; \
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) \
87 self.csqcmodel_##f = tmp; \
88 self.SendFlags |= flag; \
91 #undef PROPERTY_SCALED
95 void CSQCModel_LinkEntity()
97 Net_LinkEntity(self, TRUE, 0, CSQCModel_Send);
104 void CSQCModel_Draw()
106 InterpolateOrigin_Do();
109 void CSQCModel_Read()
114 CSQCPlayer_PreUpdate();
115 InterpolateOrigin_Undo();
117 #define PROPERTY(flag,r,w,f) \
120 #define PROPERTY_SCALED(flag,r,w,f,s,mi,ma) \
124 #undef PROPERTY_SCALED
127 InterpolateOrigin_Note();
128 CSQCPlayer_PostUpdate();
131 self.drawmask = MASK_NORMAL;
132 self.predraw = CSQCModel_Draw;