Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
interpolate.qc
Go to the documentation of this file.
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#include "interpolate.qh"
23
24// 1 = old, 2 = new
28.vector iup1, iup2;
30.vector ivup1, ivup2;
31.float itime1, itime2;
33{
35 this.itime1 = this.itime2 = 0;
36}
38{
39 float dt = time - this.itime2;
40
41 int f0 = this.iflags;
42 if (this.iflags & IFLAG_PREVALID) this.iflags |= IFLAG_VALID;
43 else this.iflags |= IFLAG_PREVALID;
44
45 if (this.iflags & IFLAG_ORIGIN)
46 {
47 this.iorigin1 = this.iorigin2;
48 this.iorigin2 = this.origin;
49 }
50
51 if ((this.iflags & IFLAG_AUTOANGLES) && this.iorigin2 != this.iorigin1)
52 this.angles = vectoangles(this.iorigin2 - this.iorigin1);
53
54 if ((this.iflags & IFLAG_AUTOVELOCITY) && this.itime2 != this.itime1)
55 this.velocity = (this.iorigin2 - this.iorigin1) * (1.0 / (this.itime2 - this.itime1));
56
57 if (this.iflags & IFLAG_ANGLES)
58 {
59 vector forward, right, up;
60 FIXED_MAKE_VECTORS(this.angles, forward, right, up);
61 if (f0 & IFLAG_VALID)
62 {
63 this.iforward1 = this.iforward2;
64 this.iup1 = this.iup2;
65 }
66 else
67 {
68 this.iforward1 = forward;
69 this.iup1 = up;
70 }
71 this.iforward2 = forward;
72 this.iup2 = up;
73 }
74
75 if (this.iflags & IFLAG_V_ANGLE)
76 {
77 vector forward, right, up;
78 FIXED_MAKE_VECTORS(this.v_angle, forward, right, up);
79 if (f0 & IFLAG_VALID)
80 {
81 this.ivforward1 = this.ivforward2;
82 this.ivup1 = this.ivup2;
83 }
84 else
85 {
86 this.ivforward1 = forward;
87 this.ivup1 = up;
88 }
89 this.ivforward2 = forward;
90 this.ivup2 = up;
91 }
92 else if (this.iflags & IFLAG_V_ANGLE_X)
93 {
94 this.ivforward1_x = this.ivforward2_x;
95 this.ivforward2_x = this.v_angle.x;
96 }
97
98 if (this.iflags & IFLAG_VELOCITY)
99 {
100 this.ivelocity1 = this.ivelocity2;
101 this.ivelocity2 = this.velocity;
102 }
103
104 if (this.iflags & IFLAG_TELEPORTED)
105 {
107 this.itime1 = this.itime2 = time; // don't lerp
108 }
109 else if (vdist(this.iorigin2 - this.iorigin1, >, 1000))
110 {
111 this.itime1 = this.itime2 = time; // don't lerp
112 }
113 else if ((this.iflags & IFLAG_VELOCITY) && vdist(this.ivelocity2 - this.ivelocity1, >, 1000))
114 {
115 this.itime1 = this.itime2 = time; // don't lerp
116 }
117 else if (dt >= 0.2)
118 {
119 this.itime1 = this.itime2 = time;
120 }
121 else
122 {
123 this.itime1 = serverprevtime;
124 this.itime2 = time;
125 }
126}
127
130{
131 if (this.itime1 && this.itime2 && this.itime1 != this.itime2)
132 {
133 float f = bound(0, (time - this.itime1) / (this.itime2 - this.itime1), 1 + autocvar_cl_lerpexcess);
134 float f_1 = 1 - f;
135 if (this.iflags & IFLAG_ORIGIN)
136 setorigin(this, f_1 * this.iorigin1 + f * this.iorigin2);
137 if (this.iflags & IFLAG_ANGLES)
138 {
139 vector forward = f_1 * this.iforward1 + f * this.iforward2;
140 vector up = f_1 * this.iup1 + f * this.iup2;
141 this.angles = fixedvectoangles2(forward, up);
142 }
143 if (this.iflags & IFLAG_V_ANGLE)
144 {
145 vector forward = f_1 * this.ivforward1 + f * this.ivforward2;
146 vector up = f_1 * this.ivup1 + f * this.ivup2;
147 this.v_angle = fixedvectoangles2(forward, up);
148 }
149 else if (this.iflags & IFLAG_V_ANGLE_X)
150 {
151 this.v_angle_x = f_1 * this.ivforward1.x + f * this.ivforward2.x;
152 }
153 if (this.iflags & IFLAG_VELOCITY)
154 this.velocity = f_1 * this.ivelocity1 + f * this.ivelocity2;
155 }
156}
157
160{
161 if (this.iflags & IFLAG_ORIGIN) setorigin(this, this.iorigin2);
162 if (this.iflags & IFLAG_ANGLES) this.angles = fixedvectoangles2(this.iforward2, this.iup2);
163 if (this.iflags & IFLAG_V_ANGLE) this.v_angle = fixedvectoangles2(this.ivforward2, this.ivup2);
164 else if (this.iflags & IFLAG_V_ANGLE_X) this.v_angle_x = this.ivforward2_x;
165 if (this.iflags & IFLAG_VELOCITY) this.velocity = this.ivelocity2;
166}
#define fixedvectoangles2
#define FIXED_MAKE_VECTORS(angles, forward, right, up)
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
float serverprevtime
Definition main.qh:207
vector v_angle
Definition player.qh:237
vector velocity
float time
vector origin
ent angles
Definition ent_cs.qc:121
vector iforward2
float itime1
vector ivup2
vector ivelocity2
vector ivforward1
vector iup2
vector iorigin1
void InterpolateOrigin_Undo(entity this)
snap origin to iorigin2 (actual origin)
void InterpolateOrigin_Reset(entity this)
vector ivup1
void InterpolateOrigin_Note(entity this)
vector ivelocity1
vector ivforward2
float itime2
void InterpolateOrigin_Do(entity this)
set origin based on iorigin1 (old pos), iorigin2 (desired pos), and time
vector iup1
vector iforward1
const int IFLAG_AUTOVELOCITY
const int IFLAG_PREVALID
const int IFLAG_V_ANGLE_X
const int IFLAG_V_ANGLE
const int IFLAG_VELOCITY
float autocvar_cl_lerpexcess
const int IFLAG_VALID
const int IFLAG_AUTOANGLES
const int IFLAG_INTERNALMASK
const int IFLAG_ANGLES
const int IFLAG_ORIGIN
const int IFLAG_TELEPORTED
int iflags
float bound(float min, float value, float max)
vector vectoangles(vector v)
iorigin2
Definition projectile.qh:10
vector
Definition self.qh:92
#define vdist(v, cmp, f)
Vector distance comparison, avoids sqrt()
Definition vector.qh:8