]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/csqcmodellib/interpolate.qc
#includes: cleanup
[xonotic/xonotic-data.pk3dir.git] / qcsrc / csqcmodellib / interpolate.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 #if defined(CSQC)
23         #include "../client/defs.qh"
24         #include "../warpzonelib/anglestransform.qh"
25         #include "../client/autocvars.qh"
26         #include "interpolate.qh"
27         #include "cl_model.qh"
28 #elif defined(MENUQC)
29 #elif defined(SVQC)
30 #endif
31
32 .vector iorigin1, iorigin2;
33 .vector ivelocity1, ivelocity2;
34 .vector iforward1, iforward2;
35 .vector iup1, iup2;
36 .vector ivforward1, ivforward2;
37 .vector ivup1, ivup2;
38 .float itime1, itime2;
39 void InterpolateOrigin_Reset()
40 {SELFPARAM();
41         self.iflags &= ~IFLAG_INTERNALMASK;
42         self.itime1 = self.itime2 = 0;
43 }
44 void InterpolateOrigin_Note()
45 {SELFPARAM();
46         float dt;
47         int f0;
48
49         dt = time - self.itime2;
50
51         f0 = self.iflags;
52         if(self.iflags & IFLAG_PREVALID)
53                 self.iflags |= IFLAG_VALID;
54         else
55                 self.iflags |= IFLAG_PREVALID;
56
57         if(self.iflags & IFLAG_ORIGIN)
58         {
59                 self.iorigin1 = self.iorigin2;
60                 self.iorigin2 = self.origin;
61         }
62
63         if(self.iflags & IFLAG_AUTOANGLES)
64                 if(self.iorigin2 != self.iorigin1)
65                         self.angles = vectoangles(self.iorigin2 - self.iorigin1);
66
67         if(self.iflags & IFLAG_AUTOVELOCITY)
68                 if(self.itime2 != self.itime1)
69                         self.velocity = (self.iorigin2 - self.iorigin1) * (1.0 / (self.itime2 - self.itime1));
70
71         if(self.iflags & IFLAG_ANGLES)
72         {
73                 fixedmakevectors(self.angles);
74                 if(f0 & IFLAG_VALID)
75                 {
76                         self.iforward1 = self.iforward2;
77                         self.iup1 = self.iup2;
78                 }
79                 else
80                 {
81                         self.iforward1 = v_forward;
82                         self.iup1 = v_up;
83                 }
84                 self.iforward2 = v_forward;
85                 self.iup2 = v_up;
86         }
87
88         if(self.iflags & IFLAG_V_ANGLE)
89         {
90                 fixedmakevectors(self.v_angle);
91                 if(f0 & IFLAG_VALID)
92                 {
93                         self.ivforward1 = self.ivforward2;
94                         self.ivup1 = self.ivup2;
95                 }
96                 else
97                 {
98                         self.ivforward1 = v_forward;
99                         self.ivup1 = v_up;
100                 }
101                 self.ivforward2 = v_forward;
102                 self.ivup2 = v_up;
103         }
104         else if(self.iflags & IFLAG_V_ANGLE_X)
105         {
106                 self.ivforward1_x = self.ivforward2_x;
107                 self.ivforward2_x = self.v_angle.x;
108         }
109
110         if(self.iflags & IFLAG_VELOCITY)
111         {
112                 self.ivelocity1 = self.ivelocity2;
113                 self.ivelocity2 = self.velocity;
114         }
115
116         if(self.iflags & IFLAG_TELEPORTED)
117         {
118                 self.iflags &= ~IFLAG_TELEPORTED;
119                 self.itime1 = self.itime2 = time; // don't lerp
120         }
121         else if(vlen(self.iorigin2 - self.iorigin1) > 1000)
122         {
123                 self.itime1 = self.itime2 = time; // don't lerp
124         }
125         else if((self.iflags & IFLAG_VELOCITY) && (vlen(self.ivelocity2 - self.ivelocity1) > 1000))
126         {
127                 self.itime1 = self.itime2 = time; // don't lerp
128         }
129         else if(dt >= 0.2)
130         {
131                 self.itime1 = self.itime2 = time;
132         }
133         else
134         {
135                 self.itime1 = serverprevtime;
136                 self.itime2 = time;
137         }
138 }
139 void InterpolateOrigin_Do()
140 {SELFPARAM();
141         vector forward, up;
142         if(self.itime1 && self.itime2 && self.itime1 != self.itime2)
143         {
144                 float f;
145                 f = bound(0, (time - self.itime1) / (self.itime2 - self.itime1), 1 + autocvar_cl_lerpexcess);
146                 if(self.iflags & IFLAG_ORIGIN)
147                         setorigin(self, (1 - f) * self.iorigin1 + f * self.iorigin2);
148                 if(self.iflags & IFLAG_ANGLES)
149                 {
150                         forward = (1 - f) * self.iforward1 + f * self.iforward2;
151                         up = (1 - f) * self.iup1 + f * self.iup2;
152                         self.angles = fixedvectoangles2(forward, up);
153                 }
154                 if(self.iflags & IFLAG_V_ANGLE)
155                 {
156                         forward = (1 - f) * self.ivforward1 + f * self.ivforward2;
157                         up = (1 - f) * self.ivup1 + f * self.ivup2;
158                         self.v_angle = fixedvectoangles2(forward, up);
159                 }
160                 else if(self.iflags & IFLAG_V_ANGLE_X)
161                         self.v_angle_x = (1 - f) * self.ivforward1_x + f * self.ivforward2_x;
162                 if(self.iflags & IFLAG_VELOCITY)
163                         self.velocity = (1 - f) * self.ivelocity1 + f * self.ivelocity2;
164         }
165 }
166 void InterpolateOrigin_Undo()
167 {SELFPARAM();
168         if(self.iflags & IFLAG_ORIGIN)
169                 setorigin(self, self.iorigin2);
170         if(self.iflags & IFLAG_ANGLES)
171                 self.angles = fixedvectoangles2(self.iforward2, self.iup2);
172         if(self.iflags & IFLAG_V_ANGLE)
173                 self.v_angle = fixedvectoangles2(self.ivforward2, self.ivup2);
174         else if(self.iflags & IFLAG_V_ANGLE_X)
175                 self.v_angle_x = self.ivforward2_x;
176         if(self.iflags & IFLAG_VELOCITY)
177                 self.velocity = self.ivelocity2;
178 }
179