/
gameinput.h
315 lines (278 loc) · 6.16 KB
/
gameinput.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
#pragma once
#include "m_fixed.h"
#include "binaryangle.h"
#include "gamecvars.h"
#include "packet.h"
int getincangle(int a, int na);
double getincanglef(double a, double na);
fixed_t getincangleq16(fixed_t a, fixed_t na);
lookangle getincanglebam(binangle a, binangle na);
struct PlayerHorizon
{
fixedhoriz horiz, ohoriz, horizoff, ohorizoff, target;
double adjustment;
void backup()
{
ohoriz = horiz;
ohorizoff = horizoff;
}
void restore()
{
horiz = ohoriz;
horizoff = ohorizoff;
}
void addadjustment(double value)
{
if (!SyncInput())
{
adjustment += value * FRACUNIT;
}
else
{
horiz += q16horiz(FloatToFixed(value));
}
}
void resetadjustment()
{
adjustment = 0;
}
void settarget(int value, bool backup = false)
{
if (!SyncInput() && !backup)
{
target = buildhoriz(value);
if (!target.asq16()) target = q16horiz(1);
}
else
{
horiz = buildhoriz(value);
if (backup) ohoriz = horiz;
}
}
void settarget(double value, bool backup = false)
{
if (!SyncInput() && !backup)
{
target = buildfhoriz(value);
if (!target.asq16()) target = q16horiz(1);
}
else
{
horiz = buildfhoriz(value);
if (backup) ohoriz = horiz;
}
}
void settarget(fixedhoriz value, bool backup = false)
{
if (!SyncInput() && !backup)
{
target = value;
if (!target.asq16()) target = q16horiz(1);
}
else
{
horiz = value;
if (backup) ohoriz = horiz;
}
}
void processhelpers(double const scaleAdjust)
{
if (target.asq16())
{
auto delta = (target - horiz).asq16();
if (abs(delta) > FRACUNIT)
{
horiz += q16horiz(xs_CRoundToInt(scaleAdjust * delta));
}
else
{
horiz = target;
target = q16horiz(0);
}
}
else if (adjustment)
{
horiz += q16horiz(xs_CRoundToInt(scaleAdjust * adjustment));
}
}
fixedhoriz osum()
{
return ohoriz + ohorizoff;
}
fixedhoriz sum()
{
return horiz + horizoff;
}
fixedhoriz interpolatedsum(double const smoothratio)
{
double const ratio = smoothratio * (1. / FRACUNIT);
fixed_t const prev = osum().asq16();
fixed_t const curr = sum().asq16();
return q16horiz(prev + xs_CRoundToInt(ratio * (curr - prev)));
}
};
struct PlayerAngle
{
binangle ang, oang, target;
lookangle look_ang, olook_ang, rotscrnang, orotscrnang, spin;
double adjustment;
void backup()
{
oang = ang;
olook_ang = look_ang;
orotscrnang = rotscrnang;
}
void restore()
{
ang = oang;
look_ang = olook_ang;
rotscrnang = orotscrnang;
}
void addadjustment(int value)
{
if (!SyncInput())
{
adjustment += BAngToBAM(value);
}
else
{
ang += buildang(value);
}
}
void addadjustment(double value)
{
if (!SyncInput())
{
adjustment += value * BAMUNIT;
}
else
{
ang += bamang(xs_CRoundToUInt(value * BAMUNIT));
}
}
void addadjustment(lookangle value)
{
if (!SyncInput())
{
adjustment += value.asbam();
}
else
{
ang += bamang(value.asbam());
}
}
void addadjustment(binangle value)
{
if (!SyncInput())
{
adjustment += value.asbam();
}
else
{
ang += value;
}
}
void resetadjustment()
{
adjustment = 0;
}
void settarget(int value, bool backup = false)
{
if (!SyncInput() && !backup)
{
target = buildang(value & 2047);
if (!target.asbam()) target = bamang(1);
}
else
{
ang = buildang(value & 2047);
if (backup) oang = ang;
}
}
void settarget(double value, bool backup = false)
{
if (!SyncInput() && !backup)
{
target = buildfang(fmod(value, 2048));
if (!target.asbam()) target = bamang(1);
}
else
{
ang = buildfang(fmod(value, 2048));
if (backup) oang = ang;
}
}
void settarget(binangle value, bool backup = false)
{
if (!SyncInput() && !backup)
{
target = value;
if (!target.asbam()) target = bamang(1);
}
else
{
ang = value;
if (backup) oang = ang;
}
}
void processhelpers(double const scaleAdjust)
{
if (target.asbam())
{
auto delta = getincanglebam(ang, target).asbam();
if (delta > BAMUNIT)
{
ang += bamang(xs_CRoundToUInt(scaleAdjust * delta));
}
else
{
ang = target;
target = bamang(0);
}
}
else if (adjustment)
{
ang += bamang(xs_CRoundToUInt(scaleAdjust * adjustment));
}
}
binangle osum()
{
return oang + olook_ang;
}
binangle sum()
{
return ang + look_ang;
}
binangle interpolatedsum(double const smoothratio)
{
double const ratio = smoothratio * (1. / FRACUNIT);
uint32_t const dang = UINT32_MAX >> 1;
int64_t const prev = osum().asbam();
int64_t const curr = sum().asbam();
return bamang(prev + xs_CRoundToUInt(ratio * (((curr + dang - prev) & 0xFFFFFFFF) - dang)));
}
lookangle interpolatedlookang(double const smoothratio)
{
double const ratio = smoothratio * (1. / FRACUNIT);
return bamlook(olook_ang.asbam() + xs_CRoundToInt(ratio * (look_ang - olook_ang).asbam()));
}
lookangle interpolatedrotscrn(double const smoothratio)
{
double const ratio = smoothratio * (1. / FRACUNIT);
return bamlook(orotscrnang.asbam() + xs_CRoundToInt(ratio * (rotscrnang - orotscrnang).asbam()));
}
double look_anghalf(double const smoothratio)
{
return (!SyncInput() ? look_ang : interpolatedlookang(smoothratio)).asbam() * (0.5 / BAMUNIT); // Used within draw code for weapon and crosshair when looking left/right.
}
};
class FSerializer;
FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngle& w, PlayerAngle* def);
FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerHorizon& w, PlayerHorizon* def);
void updateTurnHeldAmt(double const scaleAdjust);
bool const isTurboTurnTime();
void resetTurnHeldAmt();
void processMovement(InputPacket* currInput, InputPacket* inputBuffer, ControlInfo* const hidInput, double const scaleAdjust, int const drink_amt = 0, bool const allowstrafe = true, double const turnscale = 1);
void sethorizon(fixedhoriz* horiz, float const horz, ESyncBits* actions, double const scaleAdjust = 1);
void applylook(PlayerAngle* angle, float const avel, ESyncBits* actions, double const scaleAdjust = 1);
void calcviewpitch(vec2_t const pos, fixedhoriz* horizoff, binangle const ang, bool const aimmode, bool const canslopetilt, int const cursectnum, double const scaleAdjust = 1, bool const climbing = false);