quake2ts 0.0.202 → 0.0.203
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/package.json +1 -1
- package/packages/server/dist/index.cjs +131 -2
- package/packages/server/dist/index.js +131 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "quake2ts",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.203",
|
|
4
4
|
"description": "Quake II re-release port to TypeScript with WebGL renderer - A complete game engine with physics, networking, and BSP rendering",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"packageManager": "pnpm@8.15.7",
|
|
@@ -445,6 +445,110 @@ function writeDeltaEntity(from, to, writer, force, newEntity) {
|
|
|
445
445
|
if (bits & U_SOLID) writer.writeShort(to.solid);
|
|
446
446
|
}
|
|
447
447
|
|
|
448
|
+
// src/protocol/player.ts
|
|
449
|
+
var PS_M_TYPE = 1 << 0;
|
|
450
|
+
var PS_M_ORIGIN = 1 << 1;
|
|
451
|
+
var PS_M_VELOCITY = 1 << 2;
|
|
452
|
+
var PS_M_TIME = 1 << 3;
|
|
453
|
+
var PS_M_FLAGS = 1 << 4;
|
|
454
|
+
var PS_M_GRAVITY = 1 << 5;
|
|
455
|
+
var PS_M_DELTA_ANGLES = 1 << 6;
|
|
456
|
+
var PS_VIEWOFFSET = 1 << 7;
|
|
457
|
+
var PS_VIEWANGLES = 1 << 8;
|
|
458
|
+
var PS_KICKANGLES = 1 << 9;
|
|
459
|
+
var PS_BLEND = 1 << 10;
|
|
460
|
+
var PS_FOV = 1 << 11;
|
|
461
|
+
var PS_WEAPONINDEX = 1 << 12;
|
|
462
|
+
var PS_WEAPONFRAME = 1 << 13;
|
|
463
|
+
var PS_RDFLAGS = 1 << 14;
|
|
464
|
+
function writePlayerState(writer, ps) {
|
|
465
|
+
let mask = 0;
|
|
466
|
+
if (ps.pm_type !== 0) mask |= PS_M_TYPE;
|
|
467
|
+
if (ps.origin.x !== 0 || ps.origin.y !== 0 || ps.origin.z !== 0) mask |= PS_M_ORIGIN;
|
|
468
|
+
if (ps.velocity.x !== 0 || ps.velocity.y !== 0 || ps.velocity.z !== 0) mask |= PS_M_VELOCITY;
|
|
469
|
+
if (ps.pm_time !== 0) mask |= PS_M_TIME;
|
|
470
|
+
if (ps.pm_flags !== 0) mask |= PS_M_FLAGS;
|
|
471
|
+
if (ps.gravity !== 0) mask |= PS_M_GRAVITY;
|
|
472
|
+
if (ps.delta_angles.x !== 0 || ps.delta_angles.y !== 0 || ps.delta_angles.z !== 0) mask |= PS_M_DELTA_ANGLES;
|
|
473
|
+
if (ps.viewoffset.x !== 0 || ps.viewoffset.y !== 0 || ps.viewoffset.z !== 0) mask |= PS_VIEWOFFSET;
|
|
474
|
+
if (ps.viewangles.x !== 0 || ps.viewangles.y !== 0 || ps.viewangles.z !== 0) mask |= PS_VIEWANGLES;
|
|
475
|
+
if (ps.kick_angles.x !== 0 || ps.kick_angles.y !== 0 || ps.kick_angles.z !== 0) mask |= PS_KICKANGLES;
|
|
476
|
+
if (ps.gun_index !== 0) mask |= PS_WEAPONINDEX;
|
|
477
|
+
if (ps.gun_frame !== 0 || ps.gun_offset.x !== 0 || ps.gun_offset.y !== 0 || ps.gun_offset.z !== 0 || ps.gun_angles.x !== 0 || ps.gun_angles.y !== 0 || ps.gun_angles.z !== 0) {
|
|
478
|
+
mask |= PS_WEAPONFRAME;
|
|
479
|
+
}
|
|
480
|
+
if (ps.blend && (ps.blend[0] !== 0 || ps.blend[1] !== 0 || ps.blend[2] !== 0 || ps.blend[3] !== 0)) {
|
|
481
|
+
mask |= PS_BLEND;
|
|
482
|
+
}
|
|
483
|
+
if (ps.fov !== 0) mask |= PS_FOV;
|
|
484
|
+
if (ps.rdflags !== 0) mask |= PS_RDFLAGS;
|
|
485
|
+
let statsMask = 0;
|
|
486
|
+
for (let i = 0; i < 32; i++) {
|
|
487
|
+
if (ps.stats[i] && ps.stats[i] !== 0) {
|
|
488
|
+
statsMask |= 1 << i;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
writer.writeShort(mask);
|
|
492
|
+
if (mask & PS_M_TYPE) writer.writeByte(ps.pm_type);
|
|
493
|
+
if (mask & PS_M_ORIGIN) {
|
|
494
|
+
writer.writeShort(Math.round(ps.origin.x * 8));
|
|
495
|
+
writer.writeShort(Math.round(ps.origin.y * 8));
|
|
496
|
+
writer.writeShort(Math.round(ps.origin.z * 8));
|
|
497
|
+
}
|
|
498
|
+
if (mask & PS_M_VELOCITY) {
|
|
499
|
+
writer.writeShort(Math.round(ps.velocity.x * 8));
|
|
500
|
+
writer.writeShort(Math.round(ps.velocity.y * 8));
|
|
501
|
+
writer.writeShort(Math.round(ps.velocity.z * 8));
|
|
502
|
+
}
|
|
503
|
+
if (mask & PS_M_TIME) writer.writeByte(ps.pm_time);
|
|
504
|
+
if (mask & PS_M_FLAGS) writer.writeByte(ps.pm_flags);
|
|
505
|
+
if (mask & PS_M_GRAVITY) writer.writeShort(ps.gravity);
|
|
506
|
+
if (mask & PS_M_DELTA_ANGLES) {
|
|
507
|
+
writer.writeShort(Math.round(ps.delta_angles.x * (32768 / 180)));
|
|
508
|
+
writer.writeShort(Math.round(ps.delta_angles.y * (32768 / 180)));
|
|
509
|
+
writer.writeShort(Math.round(ps.delta_angles.z * (32768 / 180)));
|
|
510
|
+
}
|
|
511
|
+
if (mask & PS_VIEWOFFSET) {
|
|
512
|
+
writer.writeChar(Math.round(ps.viewoffset.x * 4));
|
|
513
|
+
writer.writeChar(Math.round(ps.viewoffset.y * 4));
|
|
514
|
+
writer.writeChar(Math.round(ps.viewoffset.z * 4));
|
|
515
|
+
}
|
|
516
|
+
if (mask & PS_VIEWANGLES) {
|
|
517
|
+
writer.writeAngle16(ps.viewangles.x);
|
|
518
|
+
writer.writeAngle16(ps.viewangles.y);
|
|
519
|
+
writer.writeAngle16(ps.viewangles.z);
|
|
520
|
+
}
|
|
521
|
+
if (mask & PS_KICKANGLES) {
|
|
522
|
+
writer.writeChar(Math.round(ps.kick_angles.x * 4));
|
|
523
|
+
writer.writeChar(Math.round(ps.kick_angles.y * 4));
|
|
524
|
+
writer.writeChar(Math.round(ps.kick_angles.z * 4));
|
|
525
|
+
}
|
|
526
|
+
if (mask & PS_WEAPONINDEX) writer.writeByte(ps.gun_index);
|
|
527
|
+
if (mask & PS_WEAPONFRAME) {
|
|
528
|
+
writer.writeByte(ps.gun_frame);
|
|
529
|
+
writer.writeChar(Math.round(ps.gun_offset.x * 4));
|
|
530
|
+
writer.writeChar(Math.round(ps.gun_offset.y * 4));
|
|
531
|
+
writer.writeChar(Math.round(ps.gun_offset.z * 4));
|
|
532
|
+
writer.writeChar(Math.round(ps.gun_angles.x * 4));
|
|
533
|
+
writer.writeChar(Math.round(ps.gun_angles.y * 4));
|
|
534
|
+
writer.writeChar(Math.round(ps.gun_angles.z * 4));
|
|
535
|
+
}
|
|
536
|
+
if (mask & PS_BLEND) {
|
|
537
|
+
writer.writeByte(Math.round(ps.blend[0]));
|
|
538
|
+
writer.writeByte(Math.round(ps.blend[1]));
|
|
539
|
+
writer.writeByte(Math.round(ps.blend[2]));
|
|
540
|
+
writer.writeByte(Math.round(ps.blend[3]));
|
|
541
|
+
}
|
|
542
|
+
if (mask & PS_FOV) writer.writeByte(ps.fov);
|
|
543
|
+
if (mask & PS_RDFLAGS) writer.writeByte(ps.rdflags);
|
|
544
|
+
writer.writeLong(statsMask);
|
|
545
|
+
for (let i = 0; i < 32; i++) {
|
|
546
|
+
if (statsMask & 1 << i) {
|
|
547
|
+
writer.writeShort(ps.stats[i]);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
|
|
448
552
|
// src/dedicated.ts
|
|
449
553
|
var MAX_CLIENTS = 16;
|
|
450
554
|
var FRAME_RATE = 10;
|
|
@@ -717,8 +821,33 @@ var DedicatedServer = class {
|
|
|
717
821
|
writer.writeByte(0);
|
|
718
822
|
writer.writeByte(0);
|
|
719
823
|
writer.writeByte(import_shared3.ServerCommand.playerinfo);
|
|
720
|
-
|
|
721
|
-
|
|
824
|
+
const ps = {
|
|
825
|
+
pm_type: snapshot.pmType,
|
|
826
|
+
origin: snapshot.origin,
|
|
827
|
+
velocity: snapshot.velocity,
|
|
828
|
+
pm_time: 0,
|
|
829
|
+
// Not explicitly in snapshot yet
|
|
830
|
+
pm_flags: snapshot.pmFlags,
|
|
831
|
+
gravity: Math.abs(snapshot.gravity.z),
|
|
832
|
+
// Usually only Z is relevant for gravity value
|
|
833
|
+
delta_angles: snapshot.deltaAngles,
|
|
834
|
+
viewoffset: { x: 0, y: 0, z: 22 },
|
|
835
|
+
// Default view offset if not in snapshot
|
|
836
|
+
viewangles: snapshot.viewangles,
|
|
837
|
+
kick_angles: snapshot.kick_angles,
|
|
838
|
+
gun_index: snapshot.gunindex,
|
|
839
|
+
gun_frame: 0,
|
|
840
|
+
// snapshot doesn't track gun frame yet?
|
|
841
|
+
gun_offset: snapshot.gunoffset,
|
|
842
|
+
gun_angles: snapshot.gunangles,
|
|
843
|
+
blend: snapshot.blend,
|
|
844
|
+
fov: 90,
|
|
845
|
+
// Default FOV
|
|
846
|
+
rdflags: 0,
|
|
847
|
+
// Not tracked
|
|
848
|
+
stats: snapshot.stats
|
|
849
|
+
};
|
|
850
|
+
writePlayerState(writer, ps);
|
|
722
851
|
writer.writeByte(import_shared3.ServerCommand.packetentities);
|
|
723
852
|
const entities = snapshot.packetEntities || [];
|
|
724
853
|
for (const entity of entities) {
|
|
@@ -405,6 +405,110 @@ function writeDeltaEntity(from, to, writer, force, newEntity) {
|
|
|
405
405
|
if (bits & U_SOLID) writer.writeShort(to.solid);
|
|
406
406
|
}
|
|
407
407
|
|
|
408
|
+
// src/protocol/player.ts
|
|
409
|
+
var PS_M_TYPE = 1 << 0;
|
|
410
|
+
var PS_M_ORIGIN = 1 << 1;
|
|
411
|
+
var PS_M_VELOCITY = 1 << 2;
|
|
412
|
+
var PS_M_TIME = 1 << 3;
|
|
413
|
+
var PS_M_FLAGS = 1 << 4;
|
|
414
|
+
var PS_M_GRAVITY = 1 << 5;
|
|
415
|
+
var PS_M_DELTA_ANGLES = 1 << 6;
|
|
416
|
+
var PS_VIEWOFFSET = 1 << 7;
|
|
417
|
+
var PS_VIEWANGLES = 1 << 8;
|
|
418
|
+
var PS_KICKANGLES = 1 << 9;
|
|
419
|
+
var PS_BLEND = 1 << 10;
|
|
420
|
+
var PS_FOV = 1 << 11;
|
|
421
|
+
var PS_WEAPONINDEX = 1 << 12;
|
|
422
|
+
var PS_WEAPONFRAME = 1 << 13;
|
|
423
|
+
var PS_RDFLAGS = 1 << 14;
|
|
424
|
+
function writePlayerState(writer, ps) {
|
|
425
|
+
let mask = 0;
|
|
426
|
+
if (ps.pm_type !== 0) mask |= PS_M_TYPE;
|
|
427
|
+
if (ps.origin.x !== 0 || ps.origin.y !== 0 || ps.origin.z !== 0) mask |= PS_M_ORIGIN;
|
|
428
|
+
if (ps.velocity.x !== 0 || ps.velocity.y !== 0 || ps.velocity.z !== 0) mask |= PS_M_VELOCITY;
|
|
429
|
+
if (ps.pm_time !== 0) mask |= PS_M_TIME;
|
|
430
|
+
if (ps.pm_flags !== 0) mask |= PS_M_FLAGS;
|
|
431
|
+
if (ps.gravity !== 0) mask |= PS_M_GRAVITY;
|
|
432
|
+
if (ps.delta_angles.x !== 0 || ps.delta_angles.y !== 0 || ps.delta_angles.z !== 0) mask |= PS_M_DELTA_ANGLES;
|
|
433
|
+
if (ps.viewoffset.x !== 0 || ps.viewoffset.y !== 0 || ps.viewoffset.z !== 0) mask |= PS_VIEWOFFSET;
|
|
434
|
+
if (ps.viewangles.x !== 0 || ps.viewangles.y !== 0 || ps.viewangles.z !== 0) mask |= PS_VIEWANGLES;
|
|
435
|
+
if (ps.kick_angles.x !== 0 || ps.kick_angles.y !== 0 || ps.kick_angles.z !== 0) mask |= PS_KICKANGLES;
|
|
436
|
+
if (ps.gun_index !== 0) mask |= PS_WEAPONINDEX;
|
|
437
|
+
if (ps.gun_frame !== 0 || ps.gun_offset.x !== 0 || ps.gun_offset.y !== 0 || ps.gun_offset.z !== 0 || ps.gun_angles.x !== 0 || ps.gun_angles.y !== 0 || ps.gun_angles.z !== 0) {
|
|
438
|
+
mask |= PS_WEAPONFRAME;
|
|
439
|
+
}
|
|
440
|
+
if (ps.blend && (ps.blend[0] !== 0 || ps.blend[1] !== 0 || ps.blend[2] !== 0 || ps.blend[3] !== 0)) {
|
|
441
|
+
mask |= PS_BLEND;
|
|
442
|
+
}
|
|
443
|
+
if (ps.fov !== 0) mask |= PS_FOV;
|
|
444
|
+
if (ps.rdflags !== 0) mask |= PS_RDFLAGS;
|
|
445
|
+
let statsMask = 0;
|
|
446
|
+
for (let i = 0; i < 32; i++) {
|
|
447
|
+
if (ps.stats[i] && ps.stats[i] !== 0) {
|
|
448
|
+
statsMask |= 1 << i;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
writer.writeShort(mask);
|
|
452
|
+
if (mask & PS_M_TYPE) writer.writeByte(ps.pm_type);
|
|
453
|
+
if (mask & PS_M_ORIGIN) {
|
|
454
|
+
writer.writeShort(Math.round(ps.origin.x * 8));
|
|
455
|
+
writer.writeShort(Math.round(ps.origin.y * 8));
|
|
456
|
+
writer.writeShort(Math.round(ps.origin.z * 8));
|
|
457
|
+
}
|
|
458
|
+
if (mask & PS_M_VELOCITY) {
|
|
459
|
+
writer.writeShort(Math.round(ps.velocity.x * 8));
|
|
460
|
+
writer.writeShort(Math.round(ps.velocity.y * 8));
|
|
461
|
+
writer.writeShort(Math.round(ps.velocity.z * 8));
|
|
462
|
+
}
|
|
463
|
+
if (mask & PS_M_TIME) writer.writeByte(ps.pm_time);
|
|
464
|
+
if (mask & PS_M_FLAGS) writer.writeByte(ps.pm_flags);
|
|
465
|
+
if (mask & PS_M_GRAVITY) writer.writeShort(ps.gravity);
|
|
466
|
+
if (mask & PS_M_DELTA_ANGLES) {
|
|
467
|
+
writer.writeShort(Math.round(ps.delta_angles.x * (32768 / 180)));
|
|
468
|
+
writer.writeShort(Math.round(ps.delta_angles.y * (32768 / 180)));
|
|
469
|
+
writer.writeShort(Math.round(ps.delta_angles.z * (32768 / 180)));
|
|
470
|
+
}
|
|
471
|
+
if (mask & PS_VIEWOFFSET) {
|
|
472
|
+
writer.writeChar(Math.round(ps.viewoffset.x * 4));
|
|
473
|
+
writer.writeChar(Math.round(ps.viewoffset.y * 4));
|
|
474
|
+
writer.writeChar(Math.round(ps.viewoffset.z * 4));
|
|
475
|
+
}
|
|
476
|
+
if (mask & PS_VIEWANGLES) {
|
|
477
|
+
writer.writeAngle16(ps.viewangles.x);
|
|
478
|
+
writer.writeAngle16(ps.viewangles.y);
|
|
479
|
+
writer.writeAngle16(ps.viewangles.z);
|
|
480
|
+
}
|
|
481
|
+
if (mask & PS_KICKANGLES) {
|
|
482
|
+
writer.writeChar(Math.round(ps.kick_angles.x * 4));
|
|
483
|
+
writer.writeChar(Math.round(ps.kick_angles.y * 4));
|
|
484
|
+
writer.writeChar(Math.round(ps.kick_angles.z * 4));
|
|
485
|
+
}
|
|
486
|
+
if (mask & PS_WEAPONINDEX) writer.writeByte(ps.gun_index);
|
|
487
|
+
if (mask & PS_WEAPONFRAME) {
|
|
488
|
+
writer.writeByte(ps.gun_frame);
|
|
489
|
+
writer.writeChar(Math.round(ps.gun_offset.x * 4));
|
|
490
|
+
writer.writeChar(Math.round(ps.gun_offset.y * 4));
|
|
491
|
+
writer.writeChar(Math.round(ps.gun_offset.z * 4));
|
|
492
|
+
writer.writeChar(Math.round(ps.gun_angles.x * 4));
|
|
493
|
+
writer.writeChar(Math.round(ps.gun_angles.y * 4));
|
|
494
|
+
writer.writeChar(Math.round(ps.gun_angles.z * 4));
|
|
495
|
+
}
|
|
496
|
+
if (mask & PS_BLEND) {
|
|
497
|
+
writer.writeByte(Math.round(ps.blend[0]));
|
|
498
|
+
writer.writeByte(Math.round(ps.blend[1]));
|
|
499
|
+
writer.writeByte(Math.round(ps.blend[2]));
|
|
500
|
+
writer.writeByte(Math.round(ps.blend[3]));
|
|
501
|
+
}
|
|
502
|
+
if (mask & PS_FOV) writer.writeByte(ps.fov);
|
|
503
|
+
if (mask & PS_RDFLAGS) writer.writeByte(ps.rdflags);
|
|
504
|
+
writer.writeLong(statsMask);
|
|
505
|
+
for (let i = 0; i < 32; i++) {
|
|
506
|
+
if (statsMask & 1 << i) {
|
|
507
|
+
writer.writeShort(ps.stats[i]);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
|
|
408
512
|
// src/dedicated.ts
|
|
409
513
|
var MAX_CLIENTS = 16;
|
|
410
514
|
var FRAME_RATE = 10;
|
|
@@ -677,8 +781,33 @@ var DedicatedServer = class {
|
|
|
677
781
|
writer.writeByte(0);
|
|
678
782
|
writer.writeByte(0);
|
|
679
783
|
writer.writeByte(ServerCommand.playerinfo);
|
|
680
|
-
|
|
681
|
-
|
|
784
|
+
const ps = {
|
|
785
|
+
pm_type: snapshot.pmType,
|
|
786
|
+
origin: snapshot.origin,
|
|
787
|
+
velocity: snapshot.velocity,
|
|
788
|
+
pm_time: 0,
|
|
789
|
+
// Not explicitly in snapshot yet
|
|
790
|
+
pm_flags: snapshot.pmFlags,
|
|
791
|
+
gravity: Math.abs(snapshot.gravity.z),
|
|
792
|
+
// Usually only Z is relevant for gravity value
|
|
793
|
+
delta_angles: snapshot.deltaAngles,
|
|
794
|
+
viewoffset: { x: 0, y: 0, z: 22 },
|
|
795
|
+
// Default view offset if not in snapshot
|
|
796
|
+
viewangles: snapshot.viewangles,
|
|
797
|
+
kick_angles: snapshot.kick_angles,
|
|
798
|
+
gun_index: snapshot.gunindex,
|
|
799
|
+
gun_frame: 0,
|
|
800
|
+
// snapshot doesn't track gun frame yet?
|
|
801
|
+
gun_offset: snapshot.gunoffset,
|
|
802
|
+
gun_angles: snapshot.gunangles,
|
|
803
|
+
blend: snapshot.blend,
|
|
804
|
+
fov: 90,
|
|
805
|
+
// Default FOV
|
|
806
|
+
rdflags: 0,
|
|
807
|
+
// Not tracked
|
|
808
|
+
stats: snapshot.stats
|
|
809
|
+
};
|
|
810
|
+
writePlayerState(writer, ps);
|
|
682
811
|
writer.writeByte(ServerCommand.packetentities);
|
|
683
812
|
const entities = snapshot.packetEntities || [];
|
|
684
813
|
for (const entity of entities) {
|