]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/csqcmodel.qc
add a simple generic CSQC model wrapper
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / csqcmodel.qc
1 // generic CSQC model code
2
3 #define ALLPROPERTIES \
4         PROPERTY(1, ReadCoord, WriteCoord, origin_x) \
5         PROPERTY(1, ReadCoord, WriteCoord, origin_y) \
6         PROPERTY(1, ReadCoord, WriteCoord, origin_z) \
7         PROPERTY(2, ReadAngle, WriteAngle, angles_x) \
8         PROPERTY(2, ReadAngle, WriteAngle, angles_y) \
9         PROPERTY(2, ReadAngle, WriteAngle, angles_z) \
10         PROPERTY(4, ReadShort, WriteShort, modelindex) \
11         PROPERTY(8, ReadByte, WriteByte, frame) \
12         PROPERTY(16, ReadByte, WriteByte, skin) \
13         PROPERTY(32, ReadInt24_t, WriteInt24_t, effects) \
14         PROPERTY_SCALED(64, ReadByte, WriteByte, alpha, 255, 0, 255) \
15         /* no attachment support */ \
16         /* no rtlight support */ \
17         /* no glow support */ \
18         /* no colormod support */ \
19         PROPERTY_SCALED(128, ReadByte, WriteByte, glowmod_x, 32, 0, 255) \
20         PROPERTY_SCALED(128, ReadByte, WriteByte, glowmod_y, 32, 0, 255) \
21         PROPERTY_SCALED(128, ReadByte, WriteByte, glowmod_z, 32, 0, 255)
22
23 #ifdef SVQC
24
25 #define PROPERTY(flag,r,w,f) \
26         .float csqcmodel_##f;
27 #define PROPERTY_SCALED(flag,r,w,f,s,mi,ma) PROPERTY(flag,r,w,f)
28         ALLPROPERTIES
29 #undef PROPERTY_SCALED
30 #undef PROPERTY
31
32 float CSQCModel_Send(entity to, float sf)
33 {
34         WriteByte(MSG_ENTITY, ENT_CS_CSQCMODEL);
35         WriteShort(MSG_ENTITY, sf);
36
37 #define PROPERTY(flag,r,w,f) \
38         if(sf & flag) \
39         { \
40                 w(MSG_ENTITY, self.csqcmodel_##f); \
41         }
42 #define PROPERTY_SCALED(flag,r,w,f,s,mi,ma) PROPERTY(flag,r,w,f)
43         ALLPROPERTIES
44 #undef PROPERTY_SCALED
45 #undef PROPERTY
46
47         return TRUE;
48 }
49
50 void CSQCModel_CheckUpdate()
51 {
52         float tmp;
53 #define PROPERTY(flag,r,w,f) \
54         tmp = self.f; \
55         if(tmp != self.csqcmodel_##f) \
56         { \
57                 self.csqcmodel_##f = tmp; \
58                 self.SendFlags |= flag; \
59         }
60 #define PROPERTY_SCALED(flag,r,w,f,s,mi,ma) \
61         tmp = bound(mi, s * self.f, ma); \
62         if(tmp != self.csqcmodel_##f) \
63         { \
64                 self.csqcmodel_##f = tmp; \
65                 self.SendFlags |= flag; \
66         }
67         ALLPROPERTIES
68 #undef PROPERTY_SCALED
69 #undef PROPERTY
70 }
71
72 void CSQCModel_LinkEntity()
73 {
74         Net_LinkEntity(self, TRUE, 0, CSQCModel_Send);
75 }
76
77 #endif
78
79 #ifdef CSQC
80
81 void CSQCModel_Read()
82 {
83         float sf;
84         sf = ReadShort();
85
86 #define PROPERTY(flag,r,w,f) \
87         if(sf & flag) \
88                 self.f = r();
89 #define PROPERTY_SCALED(flag,r,w,f,s,mi,ma) \
90         if(sf & flag) \
91                 self.f = r() / s;
92         ALLPROPERTIES
93 #undef PROPERTY_SCALED
94 #undef PROPERTY
95         
96         // interpolation
97         // draw it
98 }
99
100 #endif