@quake2ts/cgame 0.0.739 → 0.0.741

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs DELETED
@@ -1,1353 +0,0 @@
1
- 'use strict';
2
-
3
- var shared = require('@quake2ts/shared');
4
-
5
- var __defProp = Object.defineProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
-
11
- // src/hud/crosshair.ts
12
- var crosshairPic = null;
13
- var crosshairColor = [1, 1, 1, 1];
14
- var CROSSHAIR_NAMES = ["ch1", "ch2", "ch3"];
15
- var crosshairPics = [null, null, null];
16
- var Init_Crosshair = (cgi3) => {
17
- for (let i = 0; i < CROSSHAIR_NAMES.length; i++) {
18
- const name = CROSSHAIR_NAMES[i];
19
- try {
20
- crosshairPics[i] = cgi3.Draw_RegisterPic(`pics/${name}.pcx`);
21
- } catch (e) {
22
- if (i === 0) {
23
- try {
24
- crosshairPics[i] = cgi3.Draw_RegisterPic("pics/crosshair.pcx");
25
- } catch (e2) {
26
- cgi3.Com_Print("Failed to load crosshair image\n");
27
- }
28
- }
29
- }
30
- }
31
- crosshairPic = crosshairPics[0];
32
- };
33
- var Draw_Crosshair = (cgi3, width, height) => {
34
- if (crosshairPic) {
35
- const size = cgi3.Draw_GetPicSize(crosshairPic);
36
- const x = (width - size.width) / 2;
37
- const y = (height - size.height) / 2;
38
- cgi3.SCR_DrawColorPic(x, y, crosshairPic, { x: crosshairColor[0], y: crosshairColor[1], z: crosshairColor[2] }, crosshairColor[3]);
39
- }
40
- };
41
-
42
- // src/hud/icons.ts
43
- var iconPics = /* @__PURE__ */ new Map();
44
- var ICON_NAMES = [
45
- // Weapons
46
- "w_blaster",
47
- "w_shotgun",
48
- "w_sshotgun",
49
- "w_machinegun",
50
- "w_chaingun",
51
- "w_glauncher",
52
- "w_rlauncher",
53
- "w_hyperblaster",
54
- "w_railgun",
55
- "w_bfg",
56
- "w_grapple",
57
- // Ammo
58
- "a_grenades",
59
- "a_bullets",
60
- "a_cells",
61
- "a_rockets",
62
- "a_shells",
63
- "a_slugs",
64
- // Powerups
65
- "p_quad",
66
- "p_invulnerability",
67
- "p_silencer",
68
- "p_rebreather",
69
- "p_envirosuit",
70
- "p_adrenaline",
71
- "p_megahealth",
72
- // Armor
73
- "i_jacketarmor",
74
- "i_combatarmor",
75
- "i_bodyarmor",
76
- "i_powerscreen",
77
- "i_powershield",
78
- // Keys
79
- "k_datacd",
80
- "k_powercube",
81
- "k_pyramid",
82
- "k_dataspin",
83
- "k_security",
84
- "k_bluekey",
85
- "k_redkey"
86
- ];
87
- var Init_Icons = (cgi3) => {
88
- for (const name of ICON_NAMES) {
89
- try {
90
- const pic = cgi3.Draw_RegisterPic(`pics/${name}.pcx`);
91
- iconPics.set(name, pic);
92
- } catch (e) {
93
- cgi3.Com_Print(`Failed to load HUD image: pics/${name}.pcx
94
- `);
95
- }
96
- }
97
- };
98
- var damagePics = /* @__PURE__ */ new Map();
99
- var DAMAGE_INDICATOR_NAMES = [
100
- "d_left",
101
- "d_right",
102
- "d_up",
103
- "d_down"
104
- ];
105
- var Init_Damage = (cgi3) => {
106
- for (const name of DAMAGE_INDICATOR_NAMES) {
107
- try {
108
- const pic = cgi3.Draw_RegisterPic(`pics/${name}.pcx`);
109
- damagePics.set(name, pic);
110
- } catch (e) {
111
- cgi3.Com_Print(`Failed to load HUD image: pics/${name}.pcx
112
- `);
113
- }
114
- }
115
- };
116
- var WHITE = { x: 1, y: 1, z: 1 };
117
- var Draw_Damage = (cgi3, ps, width, height) => {
118
- if ((!ps.damageAlpha || ps.damageAlpha <= 0) && (!ps.damageIndicators || ps.damageIndicators.length === 0)) {
119
- return;
120
- }
121
- if (!ps.damageIndicators || ps.damageIndicators.length === 0) {
122
- return;
123
- }
124
- const cx = width * 0.5;
125
- const cy = height * 0.5;
126
- const { forward, right } = shared.angleVectors(ps.viewAngles);
127
- const radius = Math.min(width, height) * 0.25;
128
- for (const indicator of ps.damageIndicators) {
129
- const localRight = shared.dotVec3(indicator.direction, right);
130
- const localForward = shared.dotVec3(indicator.direction, forward);
131
- const angle2 = Math.atan2(localForward, localRight) * (180 / Math.PI);
132
- let picName = "";
133
- let xOff = 0;
134
- let yOff = 0;
135
- if (angle2 >= 45 && angle2 < 135) {
136
- picName = "d_up";
137
- yOff = -radius;
138
- } else if (angle2 >= -45 && angle2 < 45) {
139
- picName = "d_right";
140
- xOff = radius;
141
- } else if (angle2 >= -135 && angle2 < -45) {
142
- picName = "d_down";
143
- yOff = radius;
144
- } else {
145
- picName = "d_left";
146
- xOff = -radius;
147
- }
148
- const pic = damagePics.get(picName);
149
- if (pic) {
150
- const size = cgi3.Draw_GetPicSize(pic);
151
- const x = cx + xOff - size.width * 0.5;
152
- const y = cy + yOff - size.height * 0.5;
153
- const alpha = Math.max(0, Math.min(1, indicator.strength));
154
- cgi3.SCR_DrawColorPic(x, y, pic, WHITE, alpha);
155
- }
156
- }
157
- };
158
-
159
- // src/hud/messages.ts
160
- var CENTER_PRINT_DURATION = 3e3;
161
- var NOTIFY_DURATION = 5e3;
162
- var MAX_NOTIFY_MESSAGES = 4;
163
- var MessageSystem = class {
164
- constructor() {
165
- this.centerPrintMsg = null;
166
- this.notifyMessages = [];
167
- }
168
- addCenterPrint(text, now) {
169
- this.centerPrintMsg = {
170
- text,
171
- startTime: now,
172
- duration: CENTER_PRINT_DURATION
173
- };
174
- }
175
- addNotify(text, now) {
176
- this.notifyMessages.push({
177
- text,
178
- startTime: now,
179
- duration: NOTIFY_DURATION
180
- });
181
- if (this.notifyMessages.length > MAX_NOTIFY_MESSAGES) {
182
- this.notifyMessages.shift();
183
- }
184
- }
185
- // Additional methods for cgame API
186
- setCenterPrint(text, now) {
187
- this.centerPrintMsg = {
188
- text,
189
- startTime: now,
190
- duration: CENTER_PRINT_DURATION
191
- };
192
- }
193
- addNotification(text, is_chat, now) {
194
- this.notifyMessages.push({
195
- text,
196
- startTime: now,
197
- duration: NOTIFY_DURATION
198
- });
199
- if (this.notifyMessages.length > MAX_NOTIFY_MESSAGES) {
200
- this.notifyMessages.shift();
201
- }
202
- }
203
- clearNotifications() {
204
- this.notifyMessages = [];
205
- }
206
- clearCenterPrint() {
207
- this.centerPrintMsg = null;
208
- }
209
- drawCenterPrint(cgi3, now, layout) {
210
- if (!this.centerPrintMsg) return;
211
- if (now > this.centerPrintMsg.startTime + this.centerPrintMsg.duration) {
212
- this.centerPrintMsg = null;
213
- return;
214
- }
215
- const y = layout.CENTER_PRINT_Y;
216
- cgi3.SCR_DrawCenterString(y, this.centerPrintMsg.text);
217
- }
218
- drawNotifications(cgi3, now) {
219
- while (this.notifyMessages.length > 0 && now > this.notifyMessages[0].startTime + this.notifyMessages[0].duration) {
220
- this.notifyMessages.shift();
221
- }
222
- let y = 10;
223
- for (const msg of this.notifyMessages) {
224
- cgi3.SCR_DrawFontString(10, y, msg.text);
225
- y += cgi3.SCR_FontLineHeight();
226
- }
227
- }
228
- };
229
-
230
- // src/hud/subtitles.ts
231
- var SUBTITLE_DURATION = 3e3;
232
- var SubtitleSystem = class {
233
- constructor() {
234
- this.subtitle = null;
235
- }
236
- addSubtitle(text, now) {
237
- this.subtitle = {
238
- text,
239
- startTime: now,
240
- duration: SUBTITLE_DURATION
241
- };
242
- }
243
- drawSubtitles(cgi3, now) {
244
- if (!this.subtitle) {
245
- return;
246
- }
247
- if (now > this.subtitle.startTime + this.subtitle.duration) {
248
- this.subtitle = null;
249
- return;
250
- }
251
- const y = 200;
252
- cgi3.SCR_DrawCenterString(y, this.subtitle.text);
253
- }
254
- };
255
-
256
- // src/hud/blends.ts
257
- var Draw_Blends = (cgi3, ps, width, height) => {
258
- if (!ps.blend) return;
259
- const [r, g, b, a] = ps.blend;
260
- };
261
-
262
- // src/hud/pickup.ts
263
- var Draw_Pickup = (cgi3, ps, width, height) => {
264
- if (!ps.pickupIcon) return;
265
- const icon = iconPics.get(ps.pickupIcon);
266
- if (icon) {
267
- const size = cgi3.Draw_GetPicSize(icon);
268
- const x = width - size.width - 10;
269
- const y = height - size.height - 10;
270
- cgi3.SCR_DrawPic(x, y, icon);
271
- }
272
- };
273
-
274
- // src/hud/numbers.ts
275
- var Draw_Number = (cgi3, x, y, value, pics, width, color) => {
276
- const s = Math.abs(value).toString();
277
- for (let i = 0; i < s.length; i++) {
278
- const digit = parseInt(s[i]);
279
- const pic = pics[digit];
280
- if (pic) {
281
- if (color) {
282
- cgi3.SCR_DrawColorPic(x + i * width, y, pic, { x: color[0], y: color[1], z: color[2] }, color[3]);
283
- } else {
284
- cgi3.SCR_DrawPic(x + i * width, y, pic);
285
- }
286
- }
287
- }
288
- };
289
- var Draw_StatusBar = (cgi3, ps, hudNumberPics2, numberWidth2, timeMs, layout) => {
290
- const health = ps.stats[shared.PlayerStat.STAT_HEALTH] || 0;
291
- const armor = ps.stats[shared.PlayerStat.STAT_ARMOR] || 0;
292
- const ammo = ps.stats[shared.PlayerStat.STAT_AMMO] || 0;
293
- const armorIconIdx = ps.stats[shared.PlayerStat.STAT_ARMOR_ICON] || 0;
294
- let healthColor = void 0;
295
- if (health <= 25) {
296
- {
297
- healthColor = [1, 0, 0, 1];
298
- }
299
- }
300
- if (hudNumberPics2.length > 0) {
301
- Draw_Number(cgi3, layout.HEALTH_X, layout.HEALTH_Y, health, hudNumberPics2, numberWidth2, healthColor);
302
- Draw_Number(cgi3, layout.ARMOR_X, layout.ARMOR_Y, armor, hudNumberPics2, numberWidth2);
303
- Draw_Number(cgi3, layout.AMMO_X, layout.AMMO_Y, ammo, hudNumberPics2, numberWidth2);
304
- }
305
- if (armorIconIdx > 0) {
306
- const iconName = cgi3.get_configstring(shared.ConfigStringIndex.Images + armorIconIdx);
307
- if (iconName) {
308
- const icon = cgi3.Draw_RegisterPic(iconName);
309
- if (icon) {
310
- cgi3.SCR_DrawPic(layout.ARMOR_X - 24, layout.ARMOR_Y - 2, icon);
311
- }
312
- }
313
- }
314
- if (ps.pickupIcon) {
315
- const icon = cgi3.Draw_RegisterPic(ps.pickupIcon);
316
- if (icon) {
317
- cgi3.SCR_DrawPic(layout.WEAPON_ICON_X, layout.WEAPON_ICON_Y, icon);
318
- }
319
- } else {
320
- const selectedIconIdx = ps.stats[shared.PlayerStat.STAT_SELECTED_ICON] || 0;
321
- if (selectedIconIdx > 0) {
322
- const iconName = cgi3.get_configstring(shared.ConfigStringIndex.Images + selectedIconIdx);
323
- if (iconName) {
324
- const icon = cgi3.Draw_RegisterPic(iconName);
325
- if (icon) {
326
- cgi3.SCR_DrawPic(layout.WEAPON_ICON_X, layout.WEAPON_ICON_Y, icon);
327
- }
328
- }
329
- }
330
- }
331
- };
332
-
333
- // src/hud/layout.ts
334
- var REFERENCE_WIDTH = 640;
335
- var REFERENCE_HEIGHT = 480;
336
- var getHudLayout = (width, height) => {
337
- const scaleX = width / REFERENCE_WIDTH;
338
- const scaleY = height / REFERENCE_HEIGHT;
339
- const scale2 = Math.min(scaleX, scaleY);
340
- return {
341
- // Status bar numbers - Anchored Bottom-Left / Center / Right
342
- HEALTH_X: 100 * scale2,
343
- HEALTH_Y: height - (REFERENCE_HEIGHT - 450) * scale2,
344
- ARMOR_X: 200 * scale2,
345
- ARMOR_Y: height - (REFERENCE_HEIGHT - 450) * scale2,
346
- AMMO_X: width - (REFERENCE_WIDTH - 540) * scale2,
347
- // Anchor right? 540 is near right (640)
348
- AMMO_Y: height - (REFERENCE_HEIGHT - 450) * scale2,
349
- // Center print messages - Center
350
- CENTER_PRINT_X: width / 2,
351
- CENTER_PRINT_Y: 100 * scale2,
352
- // Top anchor
353
- // Weapon and powerup icons
354
- WEAPON_ICON_X: 10 * scale2,
355
- WEAPON_ICON_Y: height - (REFERENCE_HEIGHT - 450) * scale2,
356
- POWERUP_X: width - (REFERENCE_WIDTH - 610) * scale2,
357
- POWERUP_Y: height - (REFERENCE_HEIGHT - 450) * scale2,
358
- scale: scale2
359
- };
360
- };
361
-
362
- // src/screen.ts
363
- var cgi = null;
364
- var hudNumberPics = [];
365
- var numberWidth = 0;
366
- var messageSystem = new MessageSystem();
367
- var subtitleSystem = new SubtitleSystem();
368
- function CG_InitScreen(imports) {
369
- cgi = imports;
370
- }
371
- function CG_TouchPics() {
372
- if (!cgi) return;
373
- hudNumberPics.length = 0;
374
- for (let i = 0; i < 10; i++) {
375
- try {
376
- const pic = cgi.Draw_RegisterPic(`pics/hud/num_${i}.pcx`);
377
- hudNumberPics.push(pic);
378
- if (i === 0) {
379
- const size = cgi.Draw_GetPicSize(pic);
380
- numberWidth = size.width;
381
- }
382
- } catch (e) {
383
- cgi.Com_Print(`Warning: Failed to load HUD image: pics/hud/num_${i}.pcx
384
- `);
385
- }
386
- }
387
- Init_Crosshair(cgi);
388
- Init_Icons(cgi);
389
- Init_Damage(cgi);
390
- }
391
- function CG_DrawHUD(isplit, data, hud_vrect, hud_safe, scale2, playernum, ps) {
392
- if (!cgi) {
393
- console.error("CG_DrawHUD: cgame imports not initialized");
394
- return;
395
- }
396
- const timeMs = cgi.CL_ClientTime();
397
- const layout = getHudLayout(hud_vrect.width, hud_vrect.height);
398
- Draw_Blends(cgi, ps, hud_vrect.width, hud_vrect.height);
399
- Draw_StatusBar(cgi, ps, hudNumberPics, numberWidth, timeMs, layout);
400
- Draw_Pickup(cgi, ps, hud_vrect.width, hud_vrect.height);
401
- Draw_Damage(cgi, ps, hud_vrect.width, hud_vrect.height);
402
- if (ps.centerPrint) {
403
- const lines = ps.centerPrint.split("\n");
404
- let y = hud_vrect.height / 2 - lines.length * 10;
405
- for (const line of lines) {
406
- cgi.SCR_DrawCenterString(y, line);
407
- y += 16;
408
- }
409
- }
410
- messageSystem.drawCenterPrint(cgi, timeMs, layout);
411
- messageSystem.drawNotifications(cgi, timeMs);
412
- subtitleSystem.drawSubtitles(cgi, timeMs);
413
- Draw_Crosshair(cgi, hud_vrect.width, hud_vrect.height);
414
- }
415
- function CG_GetMessageSystem() {
416
- return messageSystem;
417
- }
418
- function CG_GetSubtitleSystem() {
419
- return subtitleSystem;
420
- }
421
- function CG_ParseConfigString(cgi3, i, s) {
422
- if (i >= shared.ConfigStringIndex.Models && i < shared.ConfigStringIndex.Models + shared.MAX_MODELS) {
423
- cgi3.RegisterModel(s);
424
- } else if (i >= shared.ConfigStringIndex.Sounds && i < shared.ConfigStringIndex.Sounds + shared.MAX_SOUNDS) {
425
- cgi3.RegisterSound(s);
426
- } else if (i >= shared.ConfigStringIndex.Images && i < shared.ConfigStringIndex.Images + shared.MAX_IMAGES) {
427
- cgi3.Draw_RegisterPic(s);
428
- }
429
- }
430
-
431
- // ../../node_modules/.pnpm/gl-matrix@3.4.4/node_modules/gl-matrix/esm/common.js
432
- var EPSILON = 1e-6;
433
- var ARRAY_TYPE = typeof Float32Array !== "undefined" ? Float32Array : Array;
434
- var RANDOM = Math.random;
435
- function round(a) {
436
- if (a >= 0) return Math.round(a);
437
- return a % 0.5 === 0 ? Math.floor(a) : Math.round(a);
438
- }
439
-
440
- // ../../node_modules/.pnpm/gl-matrix@3.4.4/node_modules/gl-matrix/esm/vec3.js
441
- var vec3_exports = {};
442
- __export(vec3_exports, {
443
- add: () => add,
444
- angle: () => angle,
445
- bezier: () => bezier,
446
- ceil: () => ceil,
447
- clone: () => clone,
448
- copy: () => copy,
449
- create: () => create,
450
- cross: () => cross,
451
- dist: () => dist,
452
- distance: () => distance,
453
- div: () => div,
454
- divide: () => divide,
455
- dot: () => dot,
456
- equals: () => equals,
457
- exactEquals: () => exactEquals,
458
- floor: () => floor,
459
- forEach: () => forEach,
460
- fromValues: () => fromValues,
461
- hermite: () => hermite,
462
- inverse: () => inverse,
463
- len: () => len,
464
- length: () => length,
465
- lerp: () => lerp,
466
- max: () => max,
467
- min: () => min,
468
- mul: () => mul,
469
- multiply: () => multiply,
470
- negate: () => negate,
471
- normalize: () => normalize,
472
- random: () => random,
473
- rotateX: () => rotateX,
474
- rotateY: () => rotateY,
475
- rotateZ: () => rotateZ,
476
- round: () => round2,
477
- scale: () => scale,
478
- scaleAndAdd: () => scaleAndAdd,
479
- set: () => set,
480
- slerp: () => slerp,
481
- sqrDist: () => sqrDist,
482
- sqrLen: () => sqrLen,
483
- squaredDistance: () => squaredDistance,
484
- squaredLength: () => squaredLength,
485
- str: () => str,
486
- sub: () => sub,
487
- subtract: () => subtract,
488
- transformMat3: () => transformMat3,
489
- transformMat4: () => transformMat4,
490
- transformQuat: () => transformQuat,
491
- zero: () => zero
492
- });
493
- function create() {
494
- var out = new ARRAY_TYPE(3);
495
- if (ARRAY_TYPE != Float32Array) {
496
- out[0] = 0;
497
- out[1] = 0;
498
- out[2] = 0;
499
- }
500
- return out;
501
- }
502
- function clone(a) {
503
- var out = new ARRAY_TYPE(3);
504
- out[0] = a[0];
505
- out[1] = a[1];
506
- out[2] = a[2];
507
- return out;
508
- }
509
- function length(a) {
510
- var x = a[0];
511
- var y = a[1];
512
- var z = a[2];
513
- return Math.sqrt(x * x + y * y + z * z);
514
- }
515
- function fromValues(x, y, z) {
516
- var out = new ARRAY_TYPE(3);
517
- out[0] = x;
518
- out[1] = y;
519
- out[2] = z;
520
- return out;
521
- }
522
- function copy(out, a) {
523
- out[0] = a[0];
524
- out[1] = a[1];
525
- out[2] = a[2];
526
- return out;
527
- }
528
- function set(out, x, y, z) {
529
- out[0] = x;
530
- out[1] = y;
531
- out[2] = z;
532
- return out;
533
- }
534
- function add(out, a, b) {
535
- out[0] = a[0] + b[0];
536
- out[1] = a[1] + b[1];
537
- out[2] = a[2] + b[2];
538
- return out;
539
- }
540
- function subtract(out, a, b) {
541
- out[0] = a[0] - b[0];
542
- out[1] = a[1] - b[1];
543
- out[2] = a[2] - b[2];
544
- return out;
545
- }
546
- function multiply(out, a, b) {
547
- out[0] = a[0] * b[0];
548
- out[1] = a[1] * b[1];
549
- out[2] = a[2] * b[2];
550
- return out;
551
- }
552
- function divide(out, a, b) {
553
- out[0] = a[0] / b[0];
554
- out[1] = a[1] / b[1];
555
- out[2] = a[2] / b[2];
556
- return out;
557
- }
558
- function ceil(out, a) {
559
- out[0] = Math.ceil(a[0]);
560
- out[1] = Math.ceil(a[1]);
561
- out[2] = Math.ceil(a[2]);
562
- return out;
563
- }
564
- function floor(out, a) {
565
- out[0] = Math.floor(a[0]);
566
- out[1] = Math.floor(a[1]);
567
- out[2] = Math.floor(a[2]);
568
- return out;
569
- }
570
- function min(out, a, b) {
571
- out[0] = Math.min(a[0], b[0]);
572
- out[1] = Math.min(a[1], b[1]);
573
- out[2] = Math.min(a[2], b[2]);
574
- return out;
575
- }
576
- function max(out, a, b) {
577
- out[0] = Math.max(a[0], b[0]);
578
- out[1] = Math.max(a[1], b[1]);
579
- out[2] = Math.max(a[2], b[2]);
580
- return out;
581
- }
582
- function round2(out, a) {
583
- out[0] = round(a[0]);
584
- out[1] = round(a[1]);
585
- out[2] = round(a[2]);
586
- return out;
587
- }
588
- function scale(out, a, b) {
589
- out[0] = a[0] * b;
590
- out[1] = a[1] * b;
591
- out[2] = a[2] * b;
592
- return out;
593
- }
594
- function scaleAndAdd(out, a, b, scale2) {
595
- out[0] = a[0] + b[0] * scale2;
596
- out[1] = a[1] + b[1] * scale2;
597
- out[2] = a[2] + b[2] * scale2;
598
- return out;
599
- }
600
- function distance(a, b) {
601
- var x = b[0] - a[0];
602
- var y = b[1] - a[1];
603
- var z = b[2] - a[2];
604
- return Math.sqrt(x * x + y * y + z * z);
605
- }
606
- function squaredDistance(a, b) {
607
- var x = b[0] - a[0];
608
- var y = b[1] - a[1];
609
- var z = b[2] - a[2];
610
- return x * x + y * y + z * z;
611
- }
612
- function squaredLength(a) {
613
- var x = a[0];
614
- var y = a[1];
615
- var z = a[2];
616
- return x * x + y * y + z * z;
617
- }
618
- function negate(out, a) {
619
- out[0] = -a[0];
620
- out[1] = -a[1];
621
- out[2] = -a[2];
622
- return out;
623
- }
624
- function inverse(out, a) {
625
- out[0] = 1 / a[0];
626
- out[1] = 1 / a[1];
627
- out[2] = 1 / a[2];
628
- return out;
629
- }
630
- function normalize(out, a) {
631
- var x = a[0];
632
- var y = a[1];
633
- var z = a[2];
634
- var len2 = x * x + y * y + z * z;
635
- if (len2 > 0) {
636
- len2 = 1 / Math.sqrt(len2);
637
- }
638
- out[0] = a[0] * len2;
639
- out[1] = a[1] * len2;
640
- out[2] = a[2] * len2;
641
- return out;
642
- }
643
- function dot(a, b) {
644
- return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
645
- }
646
- function cross(out, a, b) {
647
- var ax = a[0], ay = a[1], az = a[2];
648
- var bx = b[0], by = b[1], bz = b[2];
649
- out[0] = ay * bz - az * by;
650
- out[1] = az * bx - ax * bz;
651
- out[2] = ax * by - ay * bx;
652
- return out;
653
- }
654
- function lerp(out, a, b, t) {
655
- var ax = a[0];
656
- var ay = a[1];
657
- var az = a[2];
658
- out[0] = ax + t * (b[0] - ax);
659
- out[1] = ay + t * (b[1] - ay);
660
- out[2] = az + t * (b[2] - az);
661
- return out;
662
- }
663
- function slerp(out, a, b, t) {
664
- var angle2 = Math.acos(Math.min(Math.max(dot(a, b), -1), 1));
665
- var sinTotal = Math.sin(angle2);
666
- var ratioA = Math.sin((1 - t) * angle2) / sinTotal;
667
- var ratioB = Math.sin(t * angle2) / sinTotal;
668
- out[0] = ratioA * a[0] + ratioB * b[0];
669
- out[1] = ratioA * a[1] + ratioB * b[1];
670
- out[2] = ratioA * a[2] + ratioB * b[2];
671
- return out;
672
- }
673
- function hermite(out, a, b, c, d, t) {
674
- var factorTimes2 = t * t;
675
- var factor1 = factorTimes2 * (2 * t - 3) + 1;
676
- var factor2 = factorTimes2 * (t - 2) + t;
677
- var factor3 = factorTimes2 * (t - 1);
678
- var factor4 = factorTimes2 * (3 - 2 * t);
679
- out[0] = a[0] * factor1 + b[0] * factor2 + c[0] * factor3 + d[0] * factor4;
680
- out[1] = a[1] * factor1 + b[1] * factor2 + c[1] * factor3 + d[1] * factor4;
681
- out[2] = a[2] * factor1 + b[2] * factor2 + c[2] * factor3 + d[2] * factor4;
682
- return out;
683
- }
684
- function bezier(out, a, b, c, d, t) {
685
- var inverseFactor = 1 - t;
686
- var inverseFactorTimesTwo = inverseFactor * inverseFactor;
687
- var factorTimes2 = t * t;
688
- var factor1 = inverseFactorTimesTwo * inverseFactor;
689
- var factor2 = 3 * t * inverseFactorTimesTwo;
690
- var factor3 = 3 * factorTimes2 * inverseFactor;
691
- var factor4 = factorTimes2 * t;
692
- out[0] = a[0] * factor1 + b[0] * factor2 + c[0] * factor3 + d[0] * factor4;
693
- out[1] = a[1] * factor1 + b[1] * factor2 + c[1] * factor3 + d[1] * factor4;
694
- out[2] = a[2] * factor1 + b[2] * factor2 + c[2] * factor3 + d[2] * factor4;
695
- return out;
696
- }
697
- function random(out, scale2) {
698
- scale2 = scale2 === void 0 ? 1 : scale2;
699
- var r = RANDOM() * 2 * Math.PI;
700
- var z = RANDOM() * 2 - 1;
701
- var zScale = Math.sqrt(1 - z * z) * scale2;
702
- out[0] = Math.cos(r) * zScale;
703
- out[1] = Math.sin(r) * zScale;
704
- out[2] = z * scale2;
705
- return out;
706
- }
707
- function transformMat4(out, a, m) {
708
- var x = a[0], y = a[1], z = a[2];
709
- var w = m[3] * x + m[7] * y + m[11] * z + m[15];
710
- w = w || 1;
711
- out[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) / w;
712
- out[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) / w;
713
- out[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) / w;
714
- return out;
715
- }
716
- function transformMat3(out, a, m) {
717
- var x = a[0], y = a[1], z = a[2];
718
- out[0] = x * m[0] + y * m[3] + z * m[6];
719
- out[1] = x * m[1] + y * m[4] + z * m[7];
720
- out[2] = x * m[2] + y * m[5] + z * m[8];
721
- return out;
722
- }
723
- function transformQuat(out, a, q) {
724
- var qx = q[0], qy = q[1], qz = q[2], qw = q[3];
725
- var vx = a[0], vy = a[1], vz = a[2];
726
- var tx = qy * vz - qz * vy;
727
- var ty = qz * vx - qx * vz;
728
- var tz = qx * vy - qy * vx;
729
- tx = tx + tx;
730
- ty = ty + ty;
731
- tz = tz + tz;
732
- out[0] = vx + qw * tx + qy * tz - qz * ty;
733
- out[1] = vy + qw * ty + qz * tx - qx * tz;
734
- out[2] = vz + qw * tz + qx * ty - qy * tx;
735
- return out;
736
- }
737
- function rotateX(out, a, b, rad) {
738
- var p = [], r = [];
739
- p[0] = a[0] - b[0];
740
- p[1] = a[1] - b[1];
741
- p[2] = a[2] - b[2];
742
- r[0] = p[0];
743
- r[1] = p[1] * Math.cos(rad) - p[2] * Math.sin(rad);
744
- r[2] = p[1] * Math.sin(rad) + p[2] * Math.cos(rad);
745
- out[0] = r[0] + b[0];
746
- out[1] = r[1] + b[1];
747
- out[2] = r[2] + b[2];
748
- return out;
749
- }
750
- function rotateY(out, a, b, rad) {
751
- var p = [], r = [];
752
- p[0] = a[0] - b[0];
753
- p[1] = a[1] - b[1];
754
- p[2] = a[2] - b[2];
755
- r[0] = p[2] * Math.sin(rad) + p[0] * Math.cos(rad);
756
- r[1] = p[1];
757
- r[2] = p[2] * Math.cos(rad) - p[0] * Math.sin(rad);
758
- out[0] = r[0] + b[0];
759
- out[1] = r[1] + b[1];
760
- out[2] = r[2] + b[2];
761
- return out;
762
- }
763
- function rotateZ(out, a, b, rad) {
764
- var p = [], r = [];
765
- p[0] = a[0] - b[0];
766
- p[1] = a[1] - b[1];
767
- p[2] = a[2] - b[2];
768
- r[0] = p[0] * Math.cos(rad) - p[1] * Math.sin(rad);
769
- r[1] = p[0] * Math.sin(rad) + p[1] * Math.cos(rad);
770
- r[2] = p[2];
771
- out[0] = r[0] + b[0];
772
- out[1] = r[1] + b[1];
773
- out[2] = r[2] + b[2];
774
- return out;
775
- }
776
- function angle(a, b) {
777
- var ax = a[0], ay = a[1], az = a[2], bx = b[0], by = b[1], bz = b[2], mag = Math.sqrt((ax * ax + ay * ay + az * az) * (bx * bx + by * by + bz * bz)), cosine = mag && dot(a, b) / mag;
778
- return Math.acos(Math.min(Math.max(cosine, -1), 1));
779
- }
780
- function zero(out) {
781
- out[0] = 0;
782
- out[1] = 0;
783
- out[2] = 0;
784
- return out;
785
- }
786
- function str(a) {
787
- return "vec3(" + a[0] + ", " + a[1] + ", " + a[2] + ")";
788
- }
789
- function exactEquals(a, b) {
790
- return a[0] === b[0] && a[1] === b[1] && a[2] === b[2];
791
- }
792
- function equals(a, b) {
793
- var a0 = a[0], a1 = a[1], a2 = a[2];
794
- var b0 = b[0], b1 = b[1], b2 = b[2];
795
- return Math.abs(a0 - b0) <= EPSILON * Math.max(1, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= EPSILON * Math.max(1, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= EPSILON * Math.max(1, Math.abs(a2), Math.abs(b2));
796
- }
797
- var sub = subtract;
798
- var mul = multiply;
799
- var div = divide;
800
- var dist = distance;
801
- var sqrDist = squaredDistance;
802
- var len = length;
803
- var sqrLen = squaredLength;
804
- var forEach = (function() {
805
- var vec = create();
806
- return function(a, stride, offset, count, fn, arg) {
807
- var i, l;
808
- if (!stride) {
809
- stride = 3;
810
- }
811
- if (!offset) {
812
- offset = 0;
813
- }
814
- if (count) {
815
- l = Math.min(count * stride + offset, a.length);
816
- } else {
817
- l = a.length;
818
- }
819
- for (i = offset; i < l; i += stride) {
820
- vec[0] = a[i];
821
- vec[1] = a[i + 1];
822
- vec[2] = a[i + 2];
823
- fn(vec, vec, arg);
824
- a[i] = vec[0];
825
- a[i + 1] = vec[1];
826
- a[i + 2] = vec[2];
827
- }
828
- return a;
829
- };
830
- })();
831
-
832
- // src/view/camera.ts
833
- var toGlMatrixVec3 = (v) => {
834
- return vec3_exports.fromValues(v.x, v.y, v.z);
835
- };
836
- var updateCamera = (camera, viewSample) => {
837
- camera.bobAngles = toGlMatrixVec3(viewSample.angles);
838
- camera.bobOffset = toGlMatrixVec3(viewSample.offset);
839
- };
840
- var DEFAULT_SETTINGS = {
841
- runPitch: 2e-3,
842
- runRoll: 0.01,
843
- bobUp: 5e-3,
844
- bobPitch: 2e-3,
845
- bobRoll: 2e-3,
846
- maxBobHeight: 6,
847
- maxBobAngle: 1.2
848
- };
849
- function clampViewOffset(offset) {
850
- return {
851
- x: Math.max(-14, Math.min(14, offset.x)),
852
- y: Math.max(-14, Math.min(14, offset.y)),
853
- z: Math.max(-22, Math.min(30, offset.z))
854
- };
855
- }
856
- function computeBobMove(xyspeed, onGround, frameTimeMs) {
857
- if (!onGround) return 0;
858
- if (xyspeed > 210) return frameTimeMs / 400;
859
- if (xyspeed > 100) return frameTimeMs / 800;
860
- return frameTimeMs / 1600;
861
- }
862
- function computeBobValues(previousBobTime, xyspeed, pmFlags, onGround, frameTimeMs) {
863
- if (xyspeed < 5) {
864
- return { bobTime: 0, bobCycle: 0, bobCycleRun: 0, bobFracSin: 0 };
865
- }
866
- const bobMove = computeBobMove(xyspeed, onGround, frameTimeMs);
867
- const bobTimeRun = previousBobTime + bobMove;
868
- const crouched = shared.hasPmFlag(pmFlags, shared.PmFlag.Ducked) && onGround;
869
- const bobTime = crouched ? bobTimeRun * 4 : bobTimeRun;
870
- return {
871
- bobTime: bobTimeRun,
872
- bobCycle: Math.floor(bobTime),
873
- bobCycleRun: Math.floor(bobTimeRun),
874
- bobFracSin: Math.abs(Math.sin(bobTime * Math.PI))
875
- };
876
- }
877
- var ViewEffects = class {
878
- constructor(settings = {}) {
879
- this.bobTime = 0;
880
- this.bobCycle = 0;
881
- this.bobCycleRun = 0;
882
- this.bobFracSin = 0;
883
- this.settings = { ...DEFAULT_SETTINGS, ...settings };
884
- }
885
- addKick(kick) {
886
- if (kick.durationMs <= 0) return;
887
- this.kick = { ...kick, remainingMs: kick.durationMs };
888
- }
889
- get last() {
890
- return this.lastSample;
891
- }
892
- sample(state, frameTimeMs) {
893
- const { forward, right } = shared.angleVectors(
894
- shared.clampViewAngles({ pmFlags: state.pmFlags, cmdAngles: state.viewAngles, deltaAngles: state.deltaAngles ?? shared.ZERO_VEC3 }).viewangles
895
- );
896
- const xyspeed = Math.sqrt(state.velocity.x * state.velocity.x + state.velocity.y * state.velocity.y);
897
- const onGround = shared.hasPmFlag(state.pmFlags, shared.PmFlag.OnGround);
898
- const bobValues = computeBobValues(this.bobTime, xyspeed, state.pmFlags, onGround, frameTimeMs);
899
- this.bobTime = bobValues.bobTime;
900
- this.bobCycle = bobValues.bobCycle;
901
- this.bobCycleRun = bobValues.bobCycleRun;
902
- this.bobFracSin = bobValues.bobFracSin;
903
- let pitchTilt = shared.dotVec3(state.velocity, forward) * this.settings.runPitch;
904
- const side = shared.dotVec3(state.velocity, right);
905
- const sign = side < 0 ? -1 : 1;
906
- const absSide = Math.abs(side);
907
- let rollTilt = absSide * this.settings.runRoll;
908
- if (rollTilt > 2) {
909
- rollTilt = 2;
910
- }
911
- rollTilt *= sign;
912
- let pitchDelta = this.bobFracSin * this.settings.bobPitch * xyspeed;
913
- let rollDelta = this.bobFracSin * this.settings.bobRoll * xyspeed;
914
- if (shared.hasPmFlag(state.pmFlags, shared.PmFlag.Ducked) && onGround) {
915
- pitchDelta *= 6;
916
- rollDelta *= 6;
917
- }
918
- pitchTilt += Math.min(pitchDelta, this.settings.maxBobAngle);
919
- rollDelta = Math.min(rollDelta, this.settings.maxBobAngle);
920
- if (this.bobCycle & 1) rollDelta = -rollDelta;
921
- rollTilt += rollDelta;
922
- const bobHeight = Math.min(this.bobFracSin * xyspeed * this.settings.bobUp, this.settings.maxBobHeight);
923
- let kickPitch = 0;
924
- let kickRoll = 0;
925
- let kickX = 0;
926
- let kickY = 0;
927
- let kickZ = 0;
928
- if (this.kick && this.kick.remainingMs > 0) {
929
- const ratio = Math.max(0, Math.min(1, this.kick.remainingMs / this.kick.durationMs));
930
- kickPitch += ratio * this.kick.pitch;
931
- kickRoll += ratio * this.kick.roll;
932
- if (this.kick.origin) {
933
- kickX += ratio * this.kick.origin.x;
934
- kickY += ratio * this.kick.origin.y;
935
- kickZ += ratio * this.kick.origin.z;
936
- }
937
- this.kick.remainingMs = Math.max(0, this.kick.remainingMs - frameTimeMs);
938
- if (this.kick.remainingMs === 0) this.kick = void 0;
939
- }
940
- const angles = { x: pitchTilt + kickPitch, y: 0, z: rollTilt + kickRoll };
941
- const offset = { x: kickX, y: kickY, z: bobHeight + kickZ };
942
- const sample = {
943
- angles,
944
- offset: clampViewOffset(offset),
945
- bobCycle: this.bobCycle,
946
- bobCycleRun: this.bobCycleRun,
947
- bobFracSin: this.bobFracSin,
948
- xyspeed
949
- };
950
- this.lastSample = sample;
951
- return sample;
952
- }
953
- };
954
- var DEFAULTS = {
955
- pmFriction: 6,
956
- pmStopSpeed: 100,
957
- pmAccelerate: 10,
958
- pmAirAccelerate: 1,
959
- pmWaterAccelerate: 4,
960
- pmWaterFriction: 1,
961
- pmMaxSpeed: 300,
962
- pmDuckSpeed: 100,
963
- pmWaterSpeed: 400,
964
- groundIsSlick: false,
965
- errorTolerance: 0.1,
966
- errorSnapThreshold: 10
967
- };
968
- var DEFAULT_GRAVITY = 800;
969
- var ZERO_VEC32 = { x: 0, y: 0, z: 0 };
970
- var CMD_BACKUP = 64;
971
- function defaultPredictionState() {
972
- return {
973
- origin: ZERO_VEC32,
974
- velocity: ZERO_VEC32,
975
- viewAngles: ZERO_VEC32,
976
- onGround: false,
977
- // Physics fields
978
- pmFlags: shared.PmFlag.OnGround,
979
- pmType: shared.PmType.Normal,
980
- waterLevel: shared.WaterLevel.None,
981
- watertype: 0,
982
- gravity: DEFAULT_GRAVITY,
983
- deltaAngles: ZERO_VEC32,
984
- // Bounds
985
- mins: { x: -16, y: -16, z: -24 },
986
- maxs: { x: 16, y: 16, z: 32 },
987
- // Visual/Game fields
988
- damageAlpha: 0,
989
- damageIndicators: [],
990
- blend: [0, 0, 0, 0],
991
- stats: [],
992
- kick_angles: ZERO_VEC32,
993
- kick_origin: ZERO_VEC32,
994
- gunoffset: ZERO_VEC32,
995
- gunangles: ZERO_VEC32,
996
- gunindex: 0,
997
- // New fields
998
- pm_time: 0,
999
- pm_type: shared.PmType.Normal,
1000
- pm_flags: shared.PmFlag.OnGround,
1001
- gun_frame: 0,
1002
- rdflags: 0,
1003
- fov: 90,
1004
- renderfx: 0,
1005
- // Optional fields
1006
- pickupIcon: void 0,
1007
- centerPrint: void 0,
1008
- notify: void 0,
1009
- client: void 0,
1010
- health: 0,
1011
- armor: 0,
1012
- ammo: 0
1013
- };
1014
- }
1015
- function normalizeState(state) {
1016
- if (!state) return defaultPredictionState();
1017
- return {
1018
- ...defaultPredictionState(),
1019
- ...state,
1020
- origin: { ...state.origin },
1021
- velocity: { ...state.velocity },
1022
- viewAngles: { ...state.viewAngles },
1023
- deltaAngles: state.deltaAngles ? { ...state.deltaAngles } : ZERO_VEC32,
1024
- blend: state.blend ? [...state.blend] : [0, 0, 0, 0],
1025
- damageIndicators: state.damageIndicators ? [...state.damageIndicators] : [],
1026
- stats: state.stats ? [...state.stats] : []
1027
- };
1028
- }
1029
- function lerp2(a, b, t) {
1030
- return a + (b - a) * t;
1031
- }
1032
- function lerpAngle(a, b, t) {
1033
- let delta = shared.angleMod(b - a);
1034
- if (delta > 180) {
1035
- delta -= 360;
1036
- }
1037
- return shared.angleMod(a + delta * t);
1038
- }
1039
- function interpolatePredictionState(previous, latest, alpha) {
1040
- const clamped = Math.max(0, Math.min(alpha, 1));
1041
- return {
1042
- ...latest,
1043
- // Default to latest for discrete fields
1044
- origin: {
1045
- x: lerp2(previous.origin.x, latest.origin.x, clamped),
1046
- y: lerp2(previous.origin.y, latest.origin.y, clamped),
1047
- z: lerp2(previous.origin.z, latest.origin.z, clamped)
1048
- },
1049
- velocity: {
1050
- x: lerp2(previous.velocity.x, latest.velocity.x, clamped),
1051
- y: lerp2(previous.velocity.y, latest.velocity.y, clamped),
1052
- z: lerp2(previous.velocity.z, latest.velocity.z, clamped)
1053
- },
1054
- viewAngles: {
1055
- x: lerpAngle(previous.viewAngles.x, latest.viewAngles.x, clamped),
1056
- y: lerpAngle(previous.viewAngles.y, latest.viewAngles.y, clamped),
1057
- z: lerpAngle(previous.viewAngles.z, latest.viewAngles.z, clamped)
1058
- },
1059
- damageAlpha: lerp2(previous.damageAlpha, latest.damageAlpha, clamped),
1060
- blend: [
1061
- lerp2(previous.blend[0], latest.blend[0], clamped),
1062
- lerp2(previous.blend[1], latest.blend[1], clamped),
1063
- lerp2(previous.blend[2], latest.blend[2], clamped),
1064
- lerp2(previous.blend[3], latest.blend[3], clamped)
1065
- ],
1066
- // Interpolate health/armor for smooth HUD? Usually step.
1067
- health: lerp2(previous.health || 0, latest.health || 0, clamped),
1068
- armor: lerp2(previous.armor || 0, latest.armor || 0, clamped),
1069
- ammo: lerp2(previous.ammo || 0, latest.ammo || 0, clamped)
1070
- };
1071
- }
1072
- function simulateCommand(state, cmd, settings, trace, pointContents) {
1073
- const pmoveCmd = {
1074
- forwardmove: cmd.forwardmove,
1075
- sidemove: cmd.sidemove,
1076
- upmove: cmd.upmove,
1077
- buttons: cmd.buttons,
1078
- angles: cmd.angles
1079
- // Added missing property
1080
- };
1081
- const newState = shared.applyPmove(state, pmoveCmd, trace, pointContents);
1082
- const { viewangles } = shared.clampViewAngles({
1083
- pmFlags: state.pmFlags,
1084
- cmdAngles: cmd.angles,
1085
- deltaAngles: state.deltaAngles ?? ZERO_VEC32
1086
- });
1087
- return {
1088
- ...newState,
1089
- viewAngles: viewangles
1090
- };
1091
- }
1092
- var ClientPrediction = class {
1093
- constructor(physics, settings = {}) {
1094
- this.enabled = true;
1095
- this.baseFrame = {
1096
- frame: 0,
1097
- timeMs: 0,
1098
- state: defaultPredictionState()
1099
- };
1100
- this.commands = [];
1101
- this.predicted = defaultPredictionState();
1102
- this.predictionError = ZERO_VEC32;
1103
- this.settings = { ...DEFAULTS, ...settings };
1104
- this.physics = physics;
1105
- this.predicted = this.baseFrame.state ?? defaultPredictionState();
1106
- }
1107
- setPredictionEnabled(enabled) {
1108
- this.enabled = enabled;
1109
- }
1110
- setAuthoritative(frame) {
1111
- const normalized = normalizeState(frame.state);
1112
- if (frame.frame <= this.baseFrame.frame) {
1113
- return this.predicted;
1114
- }
1115
- if (this.enabled) {
1116
- let predictedAtFrame;
1117
- const relevantCommands = this.commands.filter((c) => c.sequence <= frame.frame && c.sequence > this.baseFrame.frame);
1118
- if (relevantCommands.length > 0 || this.baseFrame.frame === frame.frame) {
1119
- let tempState = normalizeState(this.baseFrame.state);
1120
- for (const cmd of relevantCommands) {
1121
- tempState = simulateCommand(tempState, cmd, this.settings, this.physics.trace, this.physics.pointContents);
1122
- }
1123
- predictedAtFrame = tempState;
1124
- }
1125
- if (predictedAtFrame) {
1126
- const error = shared.subtractVec3(predictedAtFrame.origin, normalized.origin);
1127
- const errorLen = shared.lengthVec3(error);
1128
- if (errorLen > this.settings.errorSnapThreshold) {
1129
- this.predictionError = ZERO_VEC32;
1130
- } else if (errorLen > this.settings.errorTolerance) {
1131
- this.predictionError = error;
1132
- } else {
1133
- this.predictionError = ZERO_VEC32;
1134
- }
1135
- } else {
1136
- this.predictionError = ZERO_VEC32;
1137
- }
1138
- } else {
1139
- this.predictionError = ZERO_VEC32;
1140
- }
1141
- this.baseFrame = { ...frame, state: normalized };
1142
- this.commands = this.commands.filter((cmd) => cmd.sequence > frame.frame);
1143
- return this.recompute();
1144
- }
1145
- getPredictionError() {
1146
- return this.predictionError;
1147
- }
1148
- // Decay error over time - usually called once per client frame
1149
- decayError(frametime) {
1150
- const len2 = shared.lengthVec3(this.predictionError);
1151
- if (len2 > 0) {
1152
- const decay = len2 * 10 * frametime;
1153
- const scale2 = Math.max(0, len2 - decay) / len2;
1154
- this.predictionError = shared.scaleVec3(this.predictionError, scale2);
1155
- }
1156
- }
1157
- enqueueCommand(cmd) {
1158
- this.commands.push(cmd);
1159
- if (this.commands.length > CMD_BACKUP) {
1160
- this.commands.shift();
1161
- }
1162
- return this.recompute();
1163
- }
1164
- getCommand(sequence) {
1165
- return this.commands.find((c) => c.sequence === sequence);
1166
- }
1167
- getPredictedState() {
1168
- return this.predicted;
1169
- }
1170
- recompute() {
1171
- let state = normalizeState(this.baseFrame.state);
1172
- if (this.enabled) {
1173
- for (const cmd of this.commands) {
1174
- state = simulateCommand(state, cmd, this.settings, this.physics.trace, this.physics.pointContents);
1175
- }
1176
- }
1177
- this.predicted = state;
1178
- return state;
1179
- }
1180
- };
1181
-
1182
- // src/index.ts
1183
- var cgi2 = null;
1184
- var cg_predict = null;
1185
- function Init() {
1186
- if (!cgi2) {
1187
- console.error("CGame Init: cgame imports not set");
1188
- return;
1189
- }
1190
- cgi2.Com_Print("===== CGame Initialization =====\n");
1191
- CG_InitScreen(cgi2);
1192
- cg_predict = cgi2.Cvar_Get("cg_predict", "1", 0);
1193
- cgi2.Cvar_Get("cg_showmiss", "0", 0);
1194
- cgi2.Com_Print("CGame initialized\n");
1195
- }
1196
- function Shutdown() {
1197
- if (cgi2) {
1198
- cgi2.Com_Print("CGame shutdown\n");
1199
- }
1200
- cgi2 = null;
1201
- }
1202
- function DrawHUD(isplit, data, hud_vrect, hud_safe, scale2, playernum, ps) {
1203
- CG_DrawHUD(isplit, data, hud_vrect, hud_safe, scale2, playernum, ps);
1204
- }
1205
- function TouchPics() {
1206
- CG_TouchPics();
1207
- }
1208
- function GetLayoutFlags(ps) {
1209
- return 0;
1210
- }
1211
- function GetActiveWeaponWheelWeapon(ps) {
1212
- return ps.stats[shared.PlayerStat.STAT_ACTIVE_WHEEL_WEAPON] ?? 0;
1213
- }
1214
- function GetOwnedWeaponWheelWeapons(ps) {
1215
- const owned = [];
1216
- const bits1 = ps.stats[shared.PlayerStat.STAT_WEAPONS_OWNED_1] || 0;
1217
- const bits2 = ps.stats[shared.PlayerStat.STAT_WEAPONS_OWNED_2] || 0;
1218
- const fullBits = bits1 | bits2 << 16;
1219
- for (let i = 0; i < shared.WEAPON_WHEEL_ORDER.length; i++) {
1220
- if (fullBits & 1 << i) {
1221
- owned.push(i);
1222
- }
1223
- }
1224
- return owned;
1225
- }
1226
- function GetWeaponWheelAmmoCount(ps, weapon) {
1227
- if (weapon < 0 || weapon >= shared.WEAPON_WHEEL_ORDER.length) {
1228
- return 0;
1229
- }
1230
- const weaponId = shared.WEAPON_WHEEL_ORDER[weapon];
1231
- const ammoType = shared.WEAPON_AMMO_MAP[weaponId];
1232
- if (ammoType === null) {
1233
- return -1;
1234
- }
1235
- return shared.G_GetAmmoStat(ps.stats, ammoType);
1236
- }
1237
- function GetPowerupWheelCount(ps) {
1238
- let count = 0;
1239
- const powerups = Object.values(shared.PowerupId);
1240
- for (const id of powerups) {
1241
- if (shared.G_GetPowerupStat(ps.stats, id) > 0) {
1242
- count++;
1243
- }
1244
- }
1245
- return count;
1246
- }
1247
- function GetHitMarkerDamage(ps) {
1248
- return ps.stats[shared.PlayerStat.STAT_HIT_MARKER] ?? 0;
1249
- }
1250
- function Pmove(pmove) {
1251
- const pm = pmove;
1252
- if (!pm || !pm.s || !pm.cmd || !cgi2) {
1253
- return;
1254
- }
1255
- if (cg_predict && cg_predict.value === 0) {
1256
- return;
1257
- }
1258
- const traceAdapter = (start, end, mins, maxs) => {
1259
- const zero2 = { x: 0, y: 0, z: 0 };
1260
- return cgi2.PM_Trace(
1261
- start,
1262
- end,
1263
- mins || zero2,
1264
- maxs || zero2
1265
- );
1266
- };
1267
- const pointContentsAdapter = (point) => {
1268
- const zero2 = { x: 0, y: 0, z: 0 };
1269
- const tr = cgi2.PM_Trace(point, point, zero2, zero2);
1270
- return tr.contents || 0;
1271
- };
1272
- const newState = shared.applyPmove(pm.s, pm.cmd, traceAdapter, pointContentsAdapter);
1273
- pm.s.origin = newState.origin;
1274
- pm.s.velocity = newState.velocity;
1275
- pm.s.onGround = newState.onGround;
1276
- pm.s.waterLevel = newState.waterLevel;
1277
- }
1278
- function ParseConfigString(i, s) {
1279
- if (!cgi2) return;
1280
- CG_ParseConfigString(cgi2, i, s);
1281
- }
1282
- function ParseCenterPrint(str2, isplit, instant) {
1283
- if (!cgi2) return;
1284
- const messageSystem2 = CG_GetMessageSystem();
1285
- messageSystem2.setCenterPrint(str2, cgi2.CL_ClientTime());
1286
- }
1287
- function NotifyMessage(isplit, msg, is_chat) {
1288
- if (!cgi2) return;
1289
- const messageSystem2 = CG_GetMessageSystem();
1290
- messageSystem2.addNotification(msg, is_chat, cgi2.CL_ClientTime());
1291
- }
1292
- function ClearNotify(isplit) {
1293
- const messageSystem2 = CG_GetMessageSystem();
1294
- messageSystem2.clearNotifications();
1295
- }
1296
- function ClearCenterprint(isplit) {
1297
- const messageSystem2 = CG_GetMessageSystem();
1298
- messageSystem2.clearCenterPrint();
1299
- }
1300
- function ShowSubtitle(text, soundName) {
1301
- if (!cgi2) return;
1302
- const subtitleSystem2 = CG_GetSubtitleSystem();
1303
- subtitleSystem2.addSubtitle(text, cgi2.CL_ClientTime());
1304
- }
1305
- function GetMonsterFlashOffset(id) {
1306
- return { x: 0, y: 0, z: 0 };
1307
- }
1308
- function GetExtension(name) {
1309
- return null;
1310
- }
1311
- function GetCGameAPI(imports) {
1312
- cgi2 = imports;
1313
- return {
1314
- // Lifecycle
1315
- Init,
1316
- Shutdown,
1317
- // Rendering
1318
- DrawHUD,
1319
- TouchPics,
1320
- // Layout
1321
- LayoutFlags: GetLayoutFlags,
1322
- // Weapon wheel
1323
- GetActiveWeaponWheelWeapon,
1324
- GetOwnedWeaponWheelWeapons,
1325
- GetWeaponWheelAmmoCount,
1326
- GetPowerupWheelCount,
1327
- // Hit markers
1328
- GetHitMarkerDamage,
1329
- // Prediction
1330
- Pmove,
1331
- // Parsing
1332
- ParseConfigString,
1333
- ParseCenterPrint,
1334
- NotifyMessage,
1335
- ShowSubtitle,
1336
- // State management
1337
- ClearNotify,
1338
- ClearCenterprint,
1339
- // Effects
1340
- GetMonsterFlashOffset,
1341
- // Extension
1342
- GetExtension
1343
- };
1344
- }
1345
-
1346
- exports.ClientPrediction = ClientPrediction;
1347
- exports.GetCGameAPI = GetCGameAPI;
1348
- exports.ViewEffects = ViewEffects;
1349
- exports.defaultPredictionState = defaultPredictionState;
1350
- exports.interpolatePredictionState = interpolatePredictionState;
1351
- exports.updateCamera = updateCamera;
1352
- //# sourceMappingURL=index.cjs.map
1353
- //# sourceMappingURL=index.cjs.map