]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/csqcmodel/cl_model.qc
restructured it a lot
[xonotic/xonotic-data.pk3dir.git] / qcsrc / csqcmodel / cl_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 var float autocvar_cl_lerpanim_maxdelta_framegroups = 0.1;
26 var float autocvar_cl_nolerp = 0;
27
28 .float csqcmodel_lerpfrac;
29 .float csqcmodel_lerpfrac2;
30 .float csqcmodel_lerpfractime;
31
32 void CSQCModel_InterpolateAnimation_PreNote(float sf)
33 {
34 #ifdef CSQCMODELS_HAVE_TWO_FRAMES
35         if(sf & PROPERTY_FRAME)
36         {
37                 self.frame3 = self.frame;
38                 self.frame3time = self.frame1time;
39         }
40         if(sf & PROPERTY_FRAME2)
41         {
42                 self.frame4 = self.frame2;
43                 self.frame4time = self.frame2time;
44         }
45         if(sf & PROPERTY_LERPFRAC)
46         {
47                 self.csqcmodel_lerpfrac2 = self.csqcmodel_lerpfrac;
48                 self.lerpfrac = self.csqcmodel_lerpfrac;
49         }
50 #else
51         if(sf & PROPERTY_FRAME)
52         {
53                 self.frame2 = self.frame;
54                 self.frame2time = self.frame1time;
55                 self.frame1time = time;
56         }
57 #endif
58 }
59
60 void CSQCModel_InterpolateAnimation_Note(float sf)
61 {
62 #ifdef CSQCMODELS_HAVE_TWO_FRAMES
63         if(sf & PROPERTY_FRAME)
64         {
65                 self.frame1time = time;
66         }
67         if(sf & PROPERTY_FRAME2)
68         {
69                 self.frame2time = time;
70         }
71         if(sf & PROPERTY_LERPFRAC)
72         {
73                 self.csqcmodel_lerpfrac = self.lerpfrac;
74                 self.csqcmodel_lerpfractime = time;
75         }
76 #else
77         if(sf & PROPERTY_FRAME)
78         {
79                 self.frame2 = self.frame;
80                 self.frame2time = self.frame1time;
81                 self.frame1time = time;
82         }
83 #endif
84 }
85
86 void CSQCModel_InterpolateAnimation_Do()
87 {
88 #ifdef CSQCMODELS_HAVE_TWO_FRAMES
89         if(autocvar_cl_nolerp || (autocvar_cl_lerpanim_maxdelta_framegroups == 0))
90         {
91                 self.lerpfrac = self.csqcmodel_lerpfrac;
92                 self.lerpfrac3 = 0;
93                 self.lerpfrac4 = 0;
94         }
95         else
96         {
97                 float l13, l24, llf;
98                 float l24_13;
99                 l13 = bound(0, (time - self.frame1time) / autocvar_cl_lerpanim_maxdelta_framegroups, 1);
100                 l24 = bound(0, (time - self.frame2time) / autocvar_cl_lerpanim_maxdelta_framegroups, 1);
101                 llf = bound(0, (time - self.csqcmodel_lerpfractime) / autocvar_cl_lerpanim_maxdelta_framegroups, 1);
102                 l24_13 = self.csqcmodel_lerpfrac * llf + self.csqcmodel_lerpfrac2 * (1 - llf);
103
104                 self.lerpfrac  = l24 * l24_13;
105                 self.lerpfrac4 = (1 - l24) * l24_13;
106                 self.lerpfrac3 = (1 - l13) * (1 - l24_13);
107         }
108 #else
109         if(autocvar_cl_nolerp || (autocvar_cl_lerpanim_maxdelta_framegroups == 0))
110         {
111                 self.lerpfrac = 0;
112         }
113         else
114         {
115                 self.lerpfrac = 1 - bound(0, (time - self.frame1time) / autocvar_cl_lerpanim_maxdelta_framegroups, 1);
116         }
117 #endif
118 }
119
120 void CSQCModel_Draw()
121 {
122         InterpolateOrigin_Do();
123         CSQCModel_InterpolateAnimation_Do();
124 }
125
126 void CSQCModel_Read()
127 {
128         float sf;
129         sf = ReadShort();
130
131         self.iflags |= IFLAG_ANGLES; // interpolate angles too
132
133         CSQCPlayer_PreUpdate();
134         InterpolateOrigin_Undo();
135         CSQCModel_InterpolateAnimation_PreNote(sf);
136
137 #define PROPERTY(flag,r,w,f) \
138         if(sf & flag) \
139                 self.f = r();
140 #define PROPERTY_SCALED(flag,r,w,f,s,mi,ma) \
141         if(sf & flag) \
142                 self.f = r() / s;
143         ALLPROPERTIES
144 #undef PROPERTY_SCALED
145 #undef PROPERTY
146         
147         CSQCModel_InterpolateAnimation_Note(sf);
148         InterpolateOrigin_Note();
149         CSQCPlayer_PostUpdate();
150
151 #ifdef CSQCMODELS_SUPPORT_GETTAGINFO_BEFORE_DRAW
152         InterpolateOrigin_Do();
153         CSQCModel_InterpolateAnimation_Do();
154 #endif
155
156         // draw it
157         self.drawmask = MASK_NORMAL;
158         self.predraw = CSQCModel_Draw;
159 }