quake2ts 0.0.7 → 0.0.39
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/README.md +425 -0
- package/apps/viewer/dist/browser/index.global.js +1 -1
- package/apps/viewer/dist/browser/index.global.js.map +1 -1
- package/apps/viewer/dist/cjs/index.cjs +2097 -295
- package/apps/viewer/dist/cjs/index.cjs.map +1 -1
- package/apps/viewer/dist/esm/index.js +2097 -295
- package/apps/viewer/dist/esm/index.js.map +1 -1
- package/apps/viewer/dist/tsconfig.tsbuildinfo +1 -1
- package/apps/viewer/dist/types/index.d.ts +1 -1
- package/package.json +1 -1
- package/packages/client/dist/browser/index.global.js +1 -1
- package/packages/client/dist/browser/index.global.js.map +1 -1
- package/packages/client/dist/cjs/index.cjs +1200 -13
- package/packages/client/dist/cjs/index.cjs.map +1 -1
- package/packages/client/dist/esm/index.js +1186 -12
- package/packages/client/dist/esm/index.js.map +1 -1
- package/packages/client/dist/tsconfig.tsbuildinfo +1 -1
- package/packages/client/dist/types/index.d.ts +14 -6
- package/packages/client/dist/types/index.d.ts.map +1 -1
- package/packages/client/dist/types/input/bindings.d.ts +18 -0
- package/packages/client/dist/types/input/bindings.d.ts.map +1 -0
- package/packages/client/dist/types/input/command-buffer.d.ts +15 -0
- package/packages/client/dist/types/input/command-buffer.d.ts.map +1 -0
- package/packages/client/dist/types/input/controller.d.ts +125 -0
- package/packages/client/dist/types/input/controller.d.ts.map +1 -0
- package/packages/client/dist/types/prediction.d.ts +38 -0
- package/packages/client/dist/types/prediction.d.ts.map +1 -0
- package/packages/client/dist/types/view-effects.d.ts +41 -0
- package/packages/client/dist/types/view-effects.d.ts.map +1 -0
- package/packages/engine/dist/browser/index.global.js +257 -1
- package/packages/engine/dist/browser/index.global.js.map +1 -1
- package/packages/engine/dist/cjs/index.cjs +2408 -2
- package/packages/engine/dist/cjs/index.cjs.map +1 -1
- package/packages/engine/dist/esm/index.js +2340 -2
- package/packages/engine/dist/esm/index.js.map +1 -1
- package/packages/engine/dist/tsconfig.tsbuildinfo +1 -1
- package/packages/engine/dist/types/assets/animation.d.ts +33 -0
- package/packages/engine/dist/types/assets/animation.d.ts.map +1 -0
- package/packages/engine/dist/types/assets/audio.d.ts +21 -0
- package/packages/engine/dist/types/assets/audio.d.ts.map +1 -0
- package/packages/engine/dist/types/assets/bsp.d.ts +1 -1
- package/packages/engine/dist/types/assets/bsp.d.ts.map +1 -1
- package/packages/engine/dist/types/assets/ingestion.d.ts +31 -0
- package/packages/engine/dist/types/assets/ingestion.d.ts.map +1 -1
- package/packages/engine/dist/types/assets/manager.d.ts +43 -0
- package/packages/engine/dist/types/assets/manager.d.ts.map +1 -0
- package/packages/engine/dist/types/assets/md3.d.ts +69 -0
- package/packages/engine/dist/types/assets/md3.d.ts.map +1 -0
- package/packages/engine/dist/types/assets/ogg.d.ts +12 -0
- package/packages/engine/dist/types/assets/ogg.d.ts.map +1 -0
- package/packages/engine/dist/types/assets/pakIndexStore.d.ts +19 -0
- package/packages/engine/dist/types/assets/pakIndexStore.d.ts.map +1 -0
- package/packages/engine/dist/types/assets/pakValidation.d.ts +28 -0
- package/packages/engine/dist/types/assets/pakValidation.d.ts.map +1 -0
- package/packages/engine/dist/types/assets/pcx.d.ts +13 -0
- package/packages/engine/dist/types/assets/pcx.d.ts.map +1 -0
- package/packages/engine/dist/types/assets/texture.d.ts +29 -0
- package/packages/engine/dist/types/assets/texture.d.ts.map +1 -0
- package/packages/engine/dist/types/assets/wal.d.ts +21 -0
- package/packages/engine/dist/types/assets/wal.d.ts.map +1 -0
- package/packages/engine/dist/types/assets/wav.d.ts +11 -0
- package/packages/engine/dist/types/assets/wav.d.ts.map +1 -0
- package/packages/engine/dist/types/audio/api.d.ts +29 -0
- package/packages/engine/dist/types/audio/api.d.ts.map +1 -0
- package/packages/engine/dist/types/audio/channels.d.ts +15 -0
- package/packages/engine/dist/types/audio/channels.d.ts.map +1 -0
- package/packages/engine/dist/types/audio/constants.d.ts +24 -0
- package/packages/engine/dist/types/audio/constants.d.ts.map +1 -0
- package/packages/engine/dist/types/audio/context.d.ts +67 -0
- package/packages/engine/dist/types/audio/context.d.ts.map +1 -0
- package/packages/engine/dist/types/audio/music.d.ts +42 -0
- package/packages/engine/dist/types/audio/music.d.ts.map +1 -0
- package/packages/engine/dist/types/audio/precache.d.ts +28 -0
- package/packages/engine/dist/types/audio/precache.d.ts.map +1 -0
- package/packages/engine/dist/types/audio/registry.d.ts +13 -0
- package/packages/engine/dist/types/audio/registry.d.ts.map +1 -0
- package/packages/engine/dist/types/audio/spatialization.d.ts +14 -0
- package/packages/engine/dist/types/audio/spatialization.d.ts.map +1 -0
- package/packages/engine/dist/types/audio/system.d.ts +101 -0
- package/packages/engine/dist/types/audio/system.d.ts.map +1 -0
- package/packages/engine/dist/types/configstrings.d.ts +1 -0
- package/packages/engine/dist/types/configstrings.d.ts.map +1 -1
- package/packages/engine/dist/types/index.d.ts +26 -1
- package/packages/engine/dist/types/index.d.ts.map +1 -1
- package/packages/engine/dist/types/render/bspPipeline.d.ts +42 -0
- package/packages/engine/dist/types/render/bspPipeline.d.ts.map +1 -0
- package/packages/engine/dist/types/render/bspTraversal.d.ts +11 -0
- package/packages/engine/dist/types/render/bspTraversal.d.ts.map +1 -0
- package/packages/engine/dist/types/render/culling.d.ts +8 -0
- package/packages/engine/dist/types/render/culling.d.ts.map +1 -0
- package/packages/engine/dist/types/render/md2Pipeline.d.ts +51 -0
- package/packages/engine/dist/types/render/md2Pipeline.d.ts.map +1 -0
- package/packages/engine/dist/types/render/resources.d.ts +10 -0
- package/packages/engine/dist/types/render/resources.d.ts.map +1 -1
- package/packages/engine/dist/types/render/skybox.d.ts +26 -0
- package/packages/engine/dist/types/render/skybox.d.ts.map +1 -0
- package/packages/game/dist/browser/index.global.js +1 -1
- package/packages/game/dist/browser/index.global.js.map +1 -1
- package/packages/game/dist/cjs/index.cjs +2926 -116
- package/packages/game/dist/cjs/index.cjs.map +1 -1
- package/packages/game/dist/esm/index.js +2863 -115
- package/packages/game/dist/esm/index.js.map +1 -1
- package/packages/game/dist/tsconfig.tsbuildinfo +1 -1
- package/packages/game/dist/types/ai/constants.d.ts +13 -0
- package/packages/game/dist/types/ai/constants.d.ts.map +1 -0
- package/packages/game/dist/types/ai/index.d.ts +4 -0
- package/packages/game/dist/types/ai/index.d.ts.map +1 -0
- package/packages/game/dist/types/ai/movement.d.ts +20 -0
- package/packages/game/dist/types/ai/movement.d.ts.map +1 -0
- package/packages/game/dist/types/ai/perception.d.ts +21 -0
- package/packages/game/dist/types/ai/perception.d.ts.map +1 -0
- package/packages/game/dist/types/checksum.d.ts +3 -0
- package/packages/game/dist/types/checksum.d.ts.map +1 -0
- package/packages/game/dist/types/combat/armor.d.ts +39 -0
- package/packages/game/dist/types/combat/armor.d.ts.map +1 -0
- package/packages/game/dist/types/combat/damage.d.ts +52 -0
- package/packages/game/dist/types/combat/damage.d.ts.map +1 -0
- package/packages/game/dist/types/combat/damageFlags.d.ts +15 -0
- package/packages/game/dist/types/combat/damageFlags.d.ts.map +1 -0
- package/packages/game/dist/types/combat/damageMods.d.ts +79 -0
- package/packages/game/dist/types/combat/damageMods.d.ts.map +1 -0
- package/packages/game/dist/types/combat/index.d.ts +6 -0
- package/packages/game/dist/types/combat/index.d.ts.map +1 -0
- package/packages/game/dist/types/combat/specialDamage.d.ts +88 -0
- package/packages/game/dist/types/combat/specialDamage.d.ts.map +1 -0
- package/packages/game/dist/types/entities/entity.d.ts +46 -2
- package/packages/game/dist/types/entities/entity.d.ts.map +1 -1
- package/packages/game/dist/types/entities/index.d.ts +6 -2
- package/packages/game/dist/types/entities/index.d.ts.map +1 -1
- package/packages/game/dist/types/entities/pool.d.ts +9 -0
- package/packages/game/dist/types/entities/pool.d.ts.map +1 -1
- package/packages/game/dist/types/entities/spawn.d.ts +27 -0
- package/packages/game/dist/types/entities/spawn.d.ts.map +1 -0
- package/packages/game/dist/types/entities/system.d.ts +32 -1
- package/packages/game/dist/types/entities/system.d.ts.map +1 -1
- package/packages/game/dist/types/entities/thinkScheduler.d.ts +6 -0
- package/packages/game/dist/types/entities/thinkScheduler.d.ts.map +1 -1
- package/packages/game/dist/types/entities/triggers.d.ts +3 -0
- package/packages/game/dist/types/entities/triggers.d.ts.map +1 -0
- package/packages/game/dist/types/entities/utils.d.ts +4 -0
- package/packages/game/dist/types/entities/utils.d.ts.map +1 -0
- package/packages/game/dist/types/index.d.ts +5 -0
- package/packages/game/dist/types/index.d.ts.map +1 -1
- package/packages/game/dist/types/inventory/ammo.d.ts +17 -0
- package/packages/game/dist/types/inventory/ammo.d.ts.map +1 -0
- package/packages/game/dist/types/inventory/index.d.ts +2 -0
- package/packages/game/dist/types/inventory/index.d.ts.map +1 -0
- package/packages/game/dist/types/level.d.ts +1 -0
- package/packages/game/dist/types/level.d.ts.map +1 -1
- package/packages/game/dist/types/save/index.d.ts +4 -0
- package/packages/game/dist/types/save/index.d.ts.map +1 -0
- package/packages/game/dist/types/save/rerelease.d.ts +25 -0
- package/packages/game/dist/types/save/rerelease.d.ts.map +1 -0
- package/packages/game/dist/types/save/save.d.ts +49 -0
- package/packages/game/dist/types/save/save.d.ts.map +1 -0
- package/packages/game/dist/types/save/storage.d.ts +37 -0
- package/packages/game/dist/types/save/storage.d.ts.map +1 -0
- package/packages/shared/dist/browser/index.global.js +1 -1
- package/packages/shared/dist/browser/index.global.js.map +1 -1
- package/packages/shared/dist/cjs/index.cjs +638 -9
- package/packages/shared/dist/cjs/index.cjs.map +1 -1
- package/packages/shared/dist/esm/index.js +616 -9
- package/packages/shared/dist/esm/index.js.map +1 -1
- package/packages/shared/dist/tsconfig.tsbuildinfo +1 -1
- package/packages/shared/dist/types/bsp/collision.d.ts +56 -0
- package/packages/shared/dist/types/bsp/collision.d.ts.map +1 -1
- package/packages/shared/dist/types/bsp/contents.d.ts +1 -0
- package/packages/shared/dist/types/bsp/contents.d.ts.map +1 -1
- package/packages/shared/dist/types/index.d.ts +2 -0
- package/packages/shared/dist/types/index.d.ts.map +1 -1
- package/packages/shared/dist/types/math/random.d.ts +11 -0
- package/packages/shared/dist/types/math/random.d.ts.map +1 -1
- package/packages/shared/dist/types/protocol/contracts.d.ts +17 -0
- package/packages/shared/dist/types/protocol/contracts.d.ts.map +1 -0
- package/packages/shared/dist/types/protocol/usercmd.d.ts +30 -0
- package/packages/shared/dist/types/protocol/usercmd.d.ts.map +1 -0
- package/packages/tools/dist/tsconfig.tsbuildinfo +1 -1
|
@@ -20,6 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
CGAME_EXPORT_KEYS: () => CGAME_EXPORT_KEYS,
|
|
24
|
+
CGAME_IMPORT_KEYS: () => CGAME_IMPORT_KEYS,
|
|
23
25
|
CONTENTS_AREAPORTAL: () => CONTENTS_AREAPORTAL,
|
|
24
26
|
CONTENTS_AUX: () => CONTENTS_AUX,
|
|
25
27
|
CONTENTS_CURRENT_0: () => CONTENTS_CURRENT_0,
|
|
@@ -45,13 +47,23 @@ __export(index_exports, {
|
|
|
45
47
|
CONTENTS_SLIME: () => CONTENTS_SLIME,
|
|
46
48
|
CONTENTS_SOLID: () => CONTENTS_SOLID,
|
|
47
49
|
CONTENTS_TRANSLUCENT: () => CONTENTS_TRANSLUCENT,
|
|
50
|
+
CONTENTS_TRIGGER: () => CONTENTS_TRIGGER,
|
|
48
51
|
CONTENTS_WATER: () => CONTENTS_WATER,
|
|
49
52
|
CONTENTS_WINDOW: () => CONTENTS_WINDOW,
|
|
50
53
|
CS_MAX_STRING_LENGTH: () => CS_MAX_STRING_LENGTH,
|
|
51
54
|
CS_MAX_STRING_LENGTH_OLD: () => CS_MAX_STRING_LENGTH_OLD,
|
|
55
|
+
CollisionEntityIndex: () => CollisionEntityIndex,
|
|
52
56
|
ConfigStringIndex: () => ConfigStringIndex,
|
|
53
57
|
CvarFlags: () => CvarFlags,
|
|
58
|
+
DEFAULT_FORWARD_SPEED: () => DEFAULT_FORWARD_SPEED,
|
|
59
|
+
DEFAULT_MOUSE_SENSITIVITY: () => DEFAULT_MOUSE_SENSITIVITY,
|
|
60
|
+
DEFAULT_PITCH_SPEED: () => DEFAULT_PITCH_SPEED,
|
|
61
|
+
DEFAULT_SIDE_SPEED: () => DEFAULT_SIDE_SPEED,
|
|
62
|
+
DEFAULT_UP_SPEED: () => DEFAULT_UP_SPEED,
|
|
63
|
+
DEFAULT_YAW_SPEED: () => DEFAULT_YAW_SPEED,
|
|
54
64
|
DIST_EPSILON: () => DIST_EPSILON,
|
|
65
|
+
GAME_EXPORT_KEYS: () => GAME_EXPORT_KEYS,
|
|
66
|
+
GAME_IMPORT_KEYS: () => GAME_IMPORT_KEYS,
|
|
55
67
|
LAST_VISIBLE_CONTENTS: () => LAST_VISIBLE_CONTENTS,
|
|
56
68
|
MASK_ALL: () => MASK_ALL,
|
|
57
69
|
MASK_BLOCK_SIGHT: () => MASK_BLOCK_SIGHT,
|
|
@@ -116,6 +128,7 @@ __export(index_exports, {
|
|
|
116
128
|
addPmFlag: () => addPmFlag,
|
|
117
129
|
addPointToBounds: () => addPointToBounds,
|
|
118
130
|
addVec3: () => addVec3,
|
|
131
|
+
addViewAngles: () => addViewAngles,
|
|
119
132
|
angleMod: () => angleMod,
|
|
120
133
|
angleVectors: () => angleVectors,
|
|
121
134
|
applyPmoveAccelerate: () => applyPmoveAccelerate,
|
|
@@ -125,6 +138,8 @@ __export(index_exports, {
|
|
|
125
138
|
applyPmoveFlyMove: () => applyPmoveFlyMove,
|
|
126
139
|
applyPmoveFriction: () => applyPmoveFriction,
|
|
127
140
|
applyPmoveWaterMove: () => applyPmoveWaterMove,
|
|
141
|
+
assertContract: () => assertContract,
|
|
142
|
+
boxContents: () => boxContents,
|
|
128
143
|
boxOnPlaneSide: () => boxOnPlaneSide,
|
|
129
144
|
boxesIntersect: () => boxesIntersect,
|
|
130
145
|
buildAirGroundWish: () => buildAirGroundWish,
|
|
@@ -160,18 +175,23 @@ __export(index_exports, {
|
|
|
160
175
|
hasAnyContents: () => hasAnyContents,
|
|
161
176
|
hasPmFlag: () => hasPmFlag,
|
|
162
177
|
hasSurfaceFlags: () => hasSurfaceFlags,
|
|
178
|
+
inPHS: () => inPHS,
|
|
179
|
+
inPVS: () => inPVS,
|
|
163
180
|
initialSnapPosition: () => initialSnapPosition,
|
|
164
181
|
isAtLeastWaistDeep: () => isAtLeastWaistDeep,
|
|
165
182
|
isUnderwater: () => isUnderwater,
|
|
166
183
|
lengthSquaredVec3: () => lengthSquaredVec3,
|
|
167
184
|
lengthVec3: () => lengthVec3,
|
|
168
185
|
lerpAngle: () => lerpAngle,
|
|
186
|
+
mouseDeltaToViewDelta: () => mouseDeltaToViewDelta,
|
|
169
187
|
multiplyVec3: () => multiplyVec3,
|
|
170
188
|
negateVec3: () => negateVec3,
|
|
171
189
|
normalizeVec3: () => normalizeVec3,
|
|
172
190
|
perpendicularVec3: () => perpendicularVec3,
|
|
173
191
|
planeDistanceToPoint: () => planeDistanceToPoint,
|
|
174
192
|
pmoveCmdScale: () => pmoveCmdScale,
|
|
193
|
+
pointContents: () => pointContents,
|
|
194
|
+
pointContentsMany: () => pointContentsMany,
|
|
175
195
|
pointInsideBrush: () => pointInsideBrush,
|
|
176
196
|
pointOnPlaneSide: () => pointOnPlaneSide,
|
|
177
197
|
projectPointOnPlane: () => projectPointOnPlane,
|
|
@@ -190,6 +210,8 @@ __export(index_exports, {
|
|
|
190
210
|
stepSlideMove: () => stepSlideMove,
|
|
191
211
|
subtractVec3: () => subtractVec3,
|
|
192
212
|
testBoxInBrush: () => testBoxInBrush,
|
|
213
|
+
traceBox: () => traceBox,
|
|
214
|
+
validateContract: () => validateContract,
|
|
193
215
|
vectorToAngles: () => vectorToAngles,
|
|
194
216
|
vectorToYaw: () => vectorToYaw,
|
|
195
217
|
waterCurrentVelocity: () => waterCurrentVelocity
|
|
@@ -607,6 +629,19 @@ var MersenneTwister19937 = class {
|
|
|
607
629
|
}
|
|
608
630
|
this.index = 0;
|
|
609
631
|
}
|
|
632
|
+
getState() {
|
|
633
|
+
return {
|
|
634
|
+
index: this.index,
|
|
635
|
+
state: Array.from(this.state)
|
|
636
|
+
};
|
|
637
|
+
}
|
|
638
|
+
setState(snapshot) {
|
|
639
|
+
if (snapshot.state.length !== STATE_SIZE) {
|
|
640
|
+
throw new Error(`Expected ${STATE_SIZE} MT state values, received ${snapshot.state.length}`);
|
|
641
|
+
}
|
|
642
|
+
this.index = snapshot.index;
|
|
643
|
+
this.state = Uint32Array.from(snapshot.state, (value) => value >>> 0);
|
|
644
|
+
}
|
|
610
645
|
};
|
|
611
646
|
var RandomGenerator = class {
|
|
612
647
|
constructor(options = {}) {
|
|
@@ -671,6 +706,12 @@ var RandomGenerator = class {
|
|
|
671
706
|
randomIndex(container) {
|
|
672
707
|
return this.irandom(container.length);
|
|
673
708
|
}
|
|
709
|
+
getState() {
|
|
710
|
+
return { mt: this.mt.getState() };
|
|
711
|
+
}
|
|
712
|
+
setState(snapshot) {
|
|
713
|
+
this.mt.setState(snapshot.mt);
|
|
714
|
+
}
|
|
674
715
|
};
|
|
675
716
|
function createRandomGenerator(options) {
|
|
676
717
|
return new RandomGenerator(options);
|
|
@@ -685,6 +726,7 @@ var CONTENTS_LAVA = 1 << 3;
|
|
|
685
726
|
var CONTENTS_SLIME = 1 << 4;
|
|
686
727
|
var CONTENTS_WATER = 1 << 5;
|
|
687
728
|
var CONTENTS_MIST = 1 << 6;
|
|
729
|
+
var CONTENTS_TRIGGER = 1073741824;
|
|
688
730
|
var CONTENTS_NO_WATERJUMP = 1 << 13;
|
|
689
731
|
var CONTENTS_PROJECTILECLIP = 1 << 14;
|
|
690
732
|
var CONTENTS_AREAPORTAL = 1 << 15;
|
|
@@ -764,6 +806,8 @@ var PlaneSide = /* @__PURE__ */ ((PlaneSide2) => {
|
|
|
764
806
|
return PlaneSide2;
|
|
765
807
|
})(PlaneSide || {});
|
|
766
808
|
var DIST_EPSILON = 0.03125;
|
|
809
|
+
var MAX_CHECKCOUNT = Number.MAX_SAFE_INTEGER - 1;
|
|
810
|
+
var globalBrushCheckCount = 1;
|
|
767
811
|
function buildCollisionModel(lumps) {
|
|
768
812
|
const planes = lumps.planes.map((plane) => ({
|
|
769
813
|
...plane,
|
|
@@ -803,7 +847,8 @@ function buildCollisionModel(lumps) {
|
|
|
803
847
|
leaves,
|
|
804
848
|
brushes,
|
|
805
849
|
leafBrushes: lumps.leafBrushes,
|
|
806
|
-
bmodels
|
|
850
|
+
bmodels,
|
|
851
|
+
visibility: lumps.visibility
|
|
807
852
|
};
|
|
808
853
|
}
|
|
809
854
|
function computePlaneSignBits(normal) {
|
|
@@ -950,6 +995,420 @@ function createDefaultTrace() {
|
|
|
950
995
|
allsolid: false
|
|
951
996
|
};
|
|
952
997
|
}
|
|
998
|
+
function findLeafIndex(point, model, headnode) {
|
|
999
|
+
let nodeIndex = headnode;
|
|
1000
|
+
while (nodeIndex >= 0) {
|
|
1001
|
+
const node = model.nodes[nodeIndex];
|
|
1002
|
+
const dist = planeDistanceToPoint(node.plane, point);
|
|
1003
|
+
nodeIndex = dist >= 0 ? node.children[0] : node.children[1];
|
|
1004
|
+
}
|
|
1005
|
+
return -1 - nodeIndex;
|
|
1006
|
+
}
|
|
1007
|
+
function computeLeafContents(model, leafIndex, point) {
|
|
1008
|
+
const leaf = model.leaves[leafIndex];
|
|
1009
|
+
let contents = leaf.contents;
|
|
1010
|
+
const brushCheckCount = nextBrushCheckCount();
|
|
1011
|
+
const start = leaf.firstLeafBrush;
|
|
1012
|
+
const end = start + leaf.numLeafBrushes;
|
|
1013
|
+
for (let i = start; i < end; i += 1) {
|
|
1014
|
+
const brushIndex = model.leafBrushes[i];
|
|
1015
|
+
const brush = model.brushes[brushIndex];
|
|
1016
|
+
if (brush.checkcount === brushCheckCount) continue;
|
|
1017
|
+
brush.checkcount = brushCheckCount;
|
|
1018
|
+
if (brush.sides.length === 0) continue;
|
|
1019
|
+
if (pointInsideBrush(point, brush)) {
|
|
1020
|
+
contents |= brush.contents;
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
return contents;
|
|
1024
|
+
}
|
|
1025
|
+
function nextBrushCheckCount() {
|
|
1026
|
+
const count = globalBrushCheckCount;
|
|
1027
|
+
globalBrushCheckCount += 1;
|
|
1028
|
+
if (globalBrushCheckCount >= MAX_CHECKCOUNT) {
|
|
1029
|
+
globalBrushCheckCount = 1;
|
|
1030
|
+
}
|
|
1031
|
+
return count;
|
|
1032
|
+
}
|
|
1033
|
+
function isPointBounds(mins, maxs) {
|
|
1034
|
+
return mins.x === 0 && mins.y === 0 && mins.z === 0 && maxs.x === 0 && maxs.y === 0 && maxs.z === 0;
|
|
1035
|
+
}
|
|
1036
|
+
function planeOffsetForBounds(plane, mins, maxs) {
|
|
1037
|
+
if (isPointBounds(mins, maxs)) return 0;
|
|
1038
|
+
const offset = plane.normal.x * (plane.normal.x < 0 ? maxs.x : mins.x) + plane.normal.y * (plane.normal.y < 0 ? maxs.y : mins.y) + plane.normal.z * (plane.normal.z < 0 ? maxs.z : mins.z);
|
|
1039
|
+
return offset;
|
|
1040
|
+
}
|
|
1041
|
+
function planeOffsetMagnitude(plane, mins, maxs) {
|
|
1042
|
+
return Math.abs(planeOffsetForBounds(plane, mins, maxs));
|
|
1043
|
+
}
|
|
1044
|
+
function lerpPoint(start, end, t) {
|
|
1045
|
+
return addVec3(start, scaleVec3(subtractVec3(end, start), t));
|
|
1046
|
+
}
|
|
1047
|
+
function finalizeTrace(trace, start, end) {
|
|
1048
|
+
const clampedFraction = trace.allsolid ? 0 : trace.fraction;
|
|
1049
|
+
const endpos = lerpPoint(start, end, clampedFraction);
|
|
1050
|
+
return {
|
|
1051
|
+
fraction: clampedFraction,
|
|
1052
|
+
endpos,
|
|
1053
|
+
plane: trace.plane,
|
|
1054
|
+
planeNormal: trace.startsolid ? void 0 : trace.plane?.normal,
|
|
1055
|
+
contents: trace.contents,
|
|
1056
|
+
surfaceFlags: trace.surfaceFlags,
|
|
1057
|
+
startsolid: trace.startsolid,
|
|
1058
|
+
allsolid: trace.allsolid
|
|
1059
|
+
};
|
|
1060
|
+
}
|
|
1061
|
+
function clusterForPoint(point, model, headnode) {
|
|
1062
|
+
const leafIndex = findLeafIndex(point, model, headnode);
|
|
1063
|
+
return model.leaves[leafIndex]?.cluster ?? -1;
|
|
1064
|
+
}
|
|
1065
|
+
function clusterVisible(visibility, from, to, usePhs) {
|
|
1066
|
+
if (!visibility || visibility.numClusters === 0) return true;
|
|
1067
|
+
if (from < 0 || to < 0) return false;
|
|
1068
|
+
if (from >= visibility.clusters.length || to >= visibility.numClusters) return false;
|
|
1069
|
+
const cluster = visibility.clusters[from];
|
|
1070
|
+
const set = usePhs ? cluster.phs : cluster.pvs;
|
|
1071
|
+
const byte = set[to >> 3];
|
|
1072
|
+
if (byte === void 0) return false;
|
|
1073
|
+
return (byte & 1 << (to & 7)) !== 0;
|
|
1074
|
+
}
|
|
1075
|
+
function recursiveHullCheck(params) {
|
|
1076
|
+
const {
|
|
1077
|
+
model,
|
|
1078
|
+
nodeIndex,
|
|
1079
|
+
startFraction,
|
|
1080
|
+
endFraction,
|
|
1081
|
+
start,
|
|
1082
|
+
end,
|
|
1083
|
+
traceStart,
|
|
1084
|
+
traceEnd,
|
|
1085
|
+
mins,
|
|
1086
|
+
maxs,
|
|
1087
|
+
contentMask,
|
|
1088
|
+
trace,
|
|
1089
|
+
brushCheckCount
|
|
1090
|
+
} = params;
|
|
1091
|
+
if (trace.fraction <= startFraction) {
|
|
1092
|
+
return;
|
|
1093
|
+
}
|
|
1094
|
+
if (nodeIndex < 0) {
|
|
1095
|
+
const leafIndex = -1 - nodeIndex;
|
|
1096
|
+
const leaf = model.leaves[leafIndex];
|
|
1097
|
+
const brushStart = leaf.firstLeafBrush;
|
|
1098
|
+
const brushEnd = brushStart + leaf.numLeafBrushes;
|
|
1099
|
+
for (let i = brushStart; i < brushEnd; i += 1) {
|
|
1100
|
+
const brushIndex = model.leafBrushes[i];
|
|
1101
|
+
const brush = model.brushes[brushIndex];
|
|
1102
|
+
if ((brush.contents & contentMask) === 0) continue;
|
|
1103
|
+
if (!brush.sides.length) continue;
|
|
1104
|
+
if (brush.checkcount === brushCheckCount) continue;
|
|
1105
|
+
brush.checkcount = brushCheckCount;
|
|
1106
|
+
clipBoxToBrush({ start: traceStart, end: traceEnd, mins, maxs, brush, trace });
|
|
1107
|
+
if (trace.allsolid) {
|
|
1108
|
+
return;
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
return;
|
|
1112
|
+
}
|
|
1113
|
+
const node = model.nodes[nodeIndex];
|
|
1114
|
+
const plane = node.plane;
|
|
1115
|
+
const offset = planeOffsetForBounds(plane, mins, maxs);
|
|
1116
|
+
const startDist = planeDistanceToPoint(plane, start) + offset;
|
|
1117
|
+
const endDist = planeDistanceToPoint(plane, end) + offset;
|
|
1118
|
+
if (startDist >= 0 && endDist >= 0) {
|
|
1119
|
+
recursiveHullCheck({
|
|
1120
|
+
model,
|
|
1121
|
+
nodeIndex: node.children[0],
|
|
1122
|
+
startFraction,
|
|
1123
|
+
endFraction,
|
|
1124
|
+
start,
|
|
1125
|
+
end,
|
|
1126
|
+
traceStart,
|
|
1127
|
+
traceEnd,
|
|
1128
|
+
mins,
|
|
1129
|
+
maxs,
|
|
1130
|
+
contentMask,
|
|
1131
|
+
trace,
|
|
1132
|
+
brushCheckCount
|
|
1133
|
+
});
|
|
1134
|
+
return;
|
|
1135
|
+
}
|
|
1136
|
+
if (startDist < 0 && endDist < 0) {
|
|
1137
|
+
recursiveHullCheck({
|
|
1138
|
+
model,
|
|
1139
|
+
nodeIndex: node.children[1],
|
|
1140
|
+
startFraction,
|
|
1141
|
+
endFraction,
|
|
1142
|
+
start,
|
|
1143
|
+
end,
|
|
1144
|
+
traceStart,
|
|
1145
|
+
traceEnd,
|
|
1146
|
+
mins,
|
|
1147
|
+
maxs,
|
|
1148
|
+
contentMask,
|
|
1149
|
+
trace,
|
|
1150
|
+
brushCheckCount
|
|
1151
|
+
});
|
|
1152
|
+
return;
|
|
1153
|
+
}
|
|
1154
|
+
let side = 0;
|
|
1155
|
+
let idist = 1 / (startDist - endDist);
|
|
1156
|
+
let fraction1 = (startDist - DIST_EPSILON) * idist;
|
|
1157
|
+
let fraction2 = (startDist + DIST_EPSILON) * idist;
|
|
1158
|
+
if (startDist < endDist) {
|
|
1159
|
+
side = 1;
|
|
1160
|
+
fraction1 = (startDist + DIST_EPSILON) * idist;
|
|
1161
|
+
fraction2 = (startDist - DIST_EPSILON) * idist;
|
|
1162
|
+
}
|
|
1163
|
+
if (fraction1 < 0) fraction1 = 0;
|
|
1164
|
+
else if (fraction1 > 1) fraction1 = 1;
|
|
1165
|
+
if (fraction2 < 0) fraction2 = 0;
|
|
1166
|
+
else if (fraction2 > 1) fraction2 = 1;
|
|
1167
|
+
const midFraction = startFraction + (endFraction - startFraction) * fraction1;
|
|
1168
|
+
const midPoint = lerpPoint(start, end, fraction1);
|
|
1169
|
+
recursiveHullCheck({
|
|
1170
|
+
model,
|
|
1171
|
+
nodeIndex: node.children[side],
|
|
1172
|
+
startFraction,
|
|
1173
|
+
endFraction: midFraction,
|
|
1174
|
+
start,
|
|
1175
|
+
end: midPoint,
|
|
1176
|
+
traceStart,
|
|
1177
|
+
traceEnd,
|
|
1178
|
+
mins,
|
|
1179
|
+
maxs,
|
|
1180
|
+
contentMask,
|
|
1181
|
+
trace,
|
|
1182
|
+
brushCheckCount
|
|
1183
|
+
});
|
|
1184
|
+
const updatedFraction = trace.fraction;
|
|
1185
|
+
if (updatedFraction <= midFraction) {
|
|
1186
|
+
return;
|
|
1187
|
+
}
|
|
1188
|
+
const midFraction2 = startFraction + (endFraction - startFraction) * fraction2;
|
|
1189
|
+
const midPoint2 = lerpPoint(start, end, fraction2);
|
|
1190
|
+
recursiveHullCheck({
|
|
1191
|
+
model,
|
|
1192
|
+
nodeIndex: node.children[1 - side],
|
|
1193
|
+
startFraction: midFraction2,
|
|
1194
|
+
endFraction,
|
|
1195
|
+
start: midPoint2,
|
|
1196
|
+
end,
|
|
1197
|
+
traceStart,
|
|
1198
|
+
traceEnd,
|
|
1199
|
+
mins,
|
|
1200
|
+
maxs,
|
|
1201
|
+
contentMask,
|
|
1202
|
+
trace,
|
|
1203
|
+
brushCheckCount
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1206
|
+
function traceBox(params) {
|
|
1207
|
+
const { model, start, end } = params;
|
|
1208
|
+
const mins = params.mins ?? ZERO_VEC3;
|
|
1209
|
+
const maxs = params.maxs ?? ZERO_VEC3;
|
|
1210
|
+
const contentMask = params.contentMask ?? 4294967295;
|
|
1211
|
+
const headnode = params.headnode ?? 0;
|
|
1212
|
+
const trace = createDefaultTrace();
|
|
1213
|
+
const brushCheckCount = nextBrushCheckCount();
|
|
1214
|
+
recursiveHullCheck({
|
|
1215
|
+
model,
|
|
1216
|
+
nodeIndex: headnode,
|
|
1217
|
+
startFraction: 0,
|
|
1218
|
+
endFraction: 1,
|
|
1219
|
+
start,
|
|
1220
|
+
end,
|
|
1221
|
+
traceStart: start,
|
|
1222
|
+
traceEnd: end,
|
|
1223
|
+
mins,
|
|
1224
|
+
maxs,
|
|
1225
|
+
contentMask,
|
|
1226
|
+
trace,
|
|
1227
|
+
brushCheckCount
|
|
1228
|
+
});
|
|
1229
|
+
return finalizeTrace(trace, start, end);
|
|
1230
|
+
}
|
|
1231
|
+
function pointContents(point, model, headnode = 0) {
|
|
1232
|
+
const leafIndex = findLeafIndex(point, model, headnode);
|
|
1233
|
+
return computeLeafContents(model, leafIndex, point);
|
|
1234
|
+
}
|
|
1235
|
+
function pointContentsMany(points, model, headnode = 0) {
|
|
1236
|
+
const leafCache = /* @__PURE__ */ new Map();
|
|
1237
|
+
return points.map((point) => {
|
|
1238
|
+
const leafIndex = findLeafIndex(point, model, headnode);
|
|
1239
|
+
const leaf = model.leaves[leafIndex];
|
|
1240
|
+
if (leaf.numLeafBrushes === 0) {
|
|
1241
|
+
const cached = leafCache.get(leafIndex);
|
|
1242
|
+
if (cached !== void 0) {
|
|
1243
|
+
return cached;
|
|
1244
|
+
}
|
|
1245
|
+
leafCache.set(leafIndex, leaf.contents);
|
|
1246
|
+
return leaf.contents;
|
|
1247
|
+
}
|
|
1248
|
+
return computeLeafContents(model, leafIndex, point);
|
|
1249
|
+
});
|
|
1250
|
+
}
|
|
1251
|
+
function boxContents(origin, mins, maxs, model, headnode = 0) {
|
|
1252
|
+
const brushCheckCount = nextBrushCheckCount();
|
|
1253
|
+
let contents = 0;
|
|
1254
|
+
function traverse(nodeIndex) {
|
|
1255
|
+
if (nodeIndex < 0) {
|
|
1256
|
+
const leafIndex = -1 - nodeIndex;
|
|
1257
|
+
const leaf = model.leaves[leafIndex];
|
|
1258
|
+
contents |= leaf.contents;
|
|
1259
|
+
const brushStart = leaf.firstLeafBrush;
|
|
1260
|
+
const brushEnd = brushStart + leaf.numLeafBrushes;
|
|
1261
|
+
for (let i = brushStart; i < brushEnd; i += 1) {
|
|
1262
|
+
const brushIndex = model.leafBrushes[i];
|
|
1263
|
+
const brush = model.brushes[brushIndex];
|
|
1264
|
+
if (brush.checkcount === brushCheckCount) continue;
|
|
1265
|
+
brush.checkcount = brushCheckCount;
|
|
1266
|
+
if (brush.sides.length === 0) continue;
|
|
1267
|
+
const result = testBoxInBrush(origin, mins, maxs, brush);
|
|
1268
|
+
if (result.startsolid) {
|
|
1269
|
+
contents |= result.contents;
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
return;
|
|
1273
|
+
}
|
|
1274
|
+
const node = model.nodes[nodeIndex];
|
|
1275
|
+
const plane = node.plane;
|
|
1276
|
+
const offset = planeOffsetMagnitude(plane, mins, maxs);
|
|
1277
|
+
const dist = planeDistanceToPoint(plane, origin);
|
|
1278
|
+
if (offset === 0) {
|
|
1279
|
+
traverse(dist >= 0 ? node.children[0] : node.children[1]);
|
|
1280
|
+
return;
|
|
1281
|
+
}
|
|
1282
|
+
if (dist > offset) {
|
|
1283
|
+
traverse(node.children[0]);
|
|
1284
|
+
return;
|
|
1285
|
+
}
|
|
1286
|
+
if (dist < -offset) {
|
|
1287
|
+
traverse(node.children[1]);
|
|
1288
|
+
return;
|
|
1289
|
+
}
|
|
1290
|
+
traverse(node.children[0]);
|
|
1291
|
+
traverse(node.children[1]);
|
|
1292
|
+
}
|
|
1293
|
+
traverse(headnode);
|
|
1294
|
+
return contents;
|
|
1295
|
+
}
|
|
1296
|
+
function inPVS(p1, p2, model, headnode = 0) {
|
|
1297
|
+
const { visibility } = model;
|
|
1298
|
+
if (!visibility) return true;
|
|
1299
|
+
const cluster1 = clusterForPoint(p1, model, headnode);
|
|
1300
|
+
const cluster2 = clusterForPoint(p2, model, headnode);
|
|
1301
|
+
return clusterVisible(visibility, cluster1, cluster2, false);
|
|
1302
|
+
}
|
|
1303
|
+
function inPHS(p1, p2, model, headnode = 0) {
|
|
1304
|
+
const { visibility } = model;
|
|
1305
|
+
if (!visibility) return true;
|
|
1306
|
+
const cluster1 = clusterForPoint(p1, model, headnode);
|
|
1307
|
+
const cluster2 = clusterForPoint(p2, model, headnode);
|
|
1308
|
+
return clusterVisible(visibility, cluster1, cluster2, true);
|
|
1309
|
+
}
|
|
1310
|
+
function axisAlignedPlane(normal, dist, type) {
|
|
1311
|
+
return { normal, dist, type, signbits: computePlaneSignBits(normal) };
|
|
1312
|
+
}
|
|
1313
|
+
function makeEntityBrush(link) {
|
|
1314
|
+
const sx = link.surfaceFlags ?? 0;
|
|
1315
|
+
const xMax = link.origin.x + link.maxs.x;
|
|
1316
|
+
const xMin = link.origin.x + link.mins.x;
|
|
1317
|
+
const yMax = link.origin.y + link.maxs.y;
|
|
1318
|
+
const yMin = link.origin.y + link.mins.y;
|
|
1319
|
+
const zMax = link.origin.z + link.maxs.z;
|
|
1320
|
+
const zMin = link.origin.z + link.mins.z;
|
|
1321
|
+
const planes = [
|
|
1322
|
+
axisAlignedPlane({ x: 1, y: 0, z: 0 }, xMax, 0),
|
|
1323
|
+
axisAlignedPlane({ x: -1, y: 0, z: 0 }, -xMin, 0),
|
|
1324
|
+
axisAlignedPlane({ x: 0, y: 1, z: 0 }, yMax, 1),
|
|
1325
|
+
axisAlignedPlane({ x: 0, y: -1, z: 0 }, -yMin, 1),
|
|
1326
|
+
axisAlignedPlane({ x: 0, y: 0, z: 1 }, zMax, 2),
|
|
1327
|
+
axisAlignedPlane({ x: 0, y: 0, z: -1 }, -zMin, 2)
|
|
1328
|
+
];
|
|
1329
|
+
const sides = planes.map((plane) => ({ plane, surfaceFlags: sx }));
|
|
1330
|
+
return { contents: link.contents, sides, checkcount: 0 };
|
|
1331
|
+
}
|
|
1332
|
+
function makeEntityState(link) {
|
|
1333
|
+
const brush = makeEntityBrush(link);
|
|
1334
|
+
return {
|
|
1335
|
+
...link,
|
|
1336
|
+
brush,
|
|
1337
|
+
bounds: {
|
|
1338
|
+
mins: {
|
|
1339
|
+
x: link.origin.x + link.mins.x,
|
|
1340
|
+
y: link.origin.y + link.mins.y,
|
|
1341
|
+
z: link.origin.z + link.mins.z
|
|
1342
|
+
},
|
|
1343
|
+
maxs: {
|
|
1344
|
+
x: link.origin.x + link.maxs.x,
|
|
1345
|
+
y: link.origin.y + link.maxs.y,
|
|
1346
|
+
z: link.origin.z + link.maxs.z
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
};
|
|
1350
|
+
}
|
|
1351
|
+
function boundsIntersect(a, b) {
|
|
1352
|
+
return !(a.mins.x > b.maxs.x || a.maxs.x < b.mins.x || a.mins.y > b.maxs.y || a.maxs.y < b.mins.y || a.mins.z > b.maxs.z || a.maxs.z < b.mins.z);
|
|
1353
|
+
}
|
|
1354
|
+
function pickBetterTrace(best, candidate) {
|
|
1355
|
+
if (candidate.allsolid && !best.allsolid) return true;
|
|
1356
|
+
if (candidate.startsolid && !best.startsolid) return true;
|
|
1357
|
+
return candidate.fraction < best.fraction;
|
|
1358
|
+
}
|
|
1359
|
+
var CollisionEntityIndex = class {
|
|
1360
|
+
constructor() {
|
|
1361
|
+
this.entities = /* @__PURE__ */ new Map();
|
|
1362
|
+
}
|
|
1363
|
+
link(entity) {
|
|
1364
|
+
this.entities.set(entity.id, makeEntityState(entity));
|
|
1365
|
+
}
|
|
1366
|
+
unlink(entityId) {
|
|
1367
|
+
this.entities.delete(entityId);
|
|
1368
|
+
}
|
|
1369
|
+
trace(params) {
|
|
1370
|
+
const { passId } = params;
|
|
1371
|
+
const mins = params.mins ?? ZERO_VEC3;
|
|
1372
|
+
const maxs = params.maxs ?? ZERO_VEC3;
|
|
1373
|
+
const contentMask = params.contentMask ?? 4294967295;
|
|
1374
|
+
let bestTrace;
|
|
1375
|
+
let bestEntity = null;
|
|
1376
|
+
if (params.model) {
|
|
1377
|
+
bestTrace = traceBox(params);
|
|
1378
|
+
} else {
|
|
1379
|
+
bestTrace = finalizeTrace(createDefaultTrace(), params.start, params.end);
|
|
1380
|
+
}
|
|
1381
|
+
for (const entity of this.entities.values()) {
|
|
1382
|
+
if (entity.id === passId) continue;
|
|
1383
|
+
if ((entity.contents & contentMask) === 0) continue;
|
|
1384
|
+
const trace = createDefaultTrace();
|
|
1385
|
+
clipBoxToBrush({ start: params.start, end: params.end, mins, maxs, brush: entity.brush, trace });
|
|
1386
|
+
if (trace.contents === 0) {
|
|
1387
|
+
trace.contents = entity.contents;
|
|
1388
|
+
}
|
|
1389
|
+
const candidate = finalizeTrace(trace, params.start, params.end);
|
|
1390
|
+
if (pickBetterTrace(bestTrace, candidate)) {
|
|
1391
|
+
bestTrace = candidate;
|
|
1392
|
+
bestEntity = entity.id;
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
return { ...bestTrace, entityId: bestEntity };
|
|
1396
|
+
}
|
|
1397
|
+
gatherTriggerTouches(origin, mins, maxs, mask = CONTENTS_TRIGGER) {
|
|
1398
|
+
const results = [];
|
|
1399
|
+
const queryBounds = {
|
|
1400
|
+
mins: addVec3(origin, mins),
|
|
1401
|
+
maxs: addVec3(origin, maxs)
|
|
1402
|
+
};
|
|
1403
|
+
for (const entity of this.entities.values()) {
|
|
1404
|
+
if ((entity.contents & mask) === 0) continue;
|
|
1405
|
+
if (boundsIntersect(queryBounds, entity.bounds)) {
|
|
1406
|
+
results.push(entity.id);
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
return results;
|
|
1410
|
+
}
|
|
1411
|
+
};
|
|
953
1412
|
|
|
954
1413
|
// src/protocol/cvar.ts
|
|
955
1414
|
var CvarFlags = /* @__PURE__ */ ((CvarFlags2) => {
|
|
@@ -1017,6 +1476,124 @@ function configStringSize(index) {
|
|
|
1017
1476
|
return CS_MAX_STRING_LENGTH;
|
|
1018
1477
|
}
|
|
1019
1478
|
|
|
1479
|
+
// src/protocol/contracts.ts
|
|
1480
|
+
function normalize(object) {
|
|
1481
|
+
return object ?? {};
|
|
1482
|
+
}
|
|
1483
|
+
function validateContract(table, requiredKeys, options = {}) {
|
|
1484
|
+
const normalized = normalize(table);
|
|
1485
|
+
const missing = [];
|
|
1486
|
+
const nonFunctions = [];
|
|
1487
|
+
for (const key of requiredKeys) {
|
|
1488
|
+
if (!(key in normalized)) {
|
|
1489
|
+
missing.push(key);
|
|
1490
|
+
continue;
|
|
1491
|
+
}
|
|
1492
|
+
if (typeof normalized[key] !== "function") {
|
|
1493
|
+
nonFunctions.push(key);
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
const extras = options.allowExtra === false ? Object.keys(normalized).filter((key) => !requiredKeys.includes(key)) : [];
|
|
1497
|
+
return { missing, nonFunctions, extras };
|
|
1498
|
+
}
|
|
1499
|
+
function assertContract(table, requiredKeys, options = {}) {
|
|
1500
|
+
const { missing, nonFunctions, extras } = validateContract(table, requiredKeys, options);
|
|
1501
|
+
if (missing.length === 0 && nonFunctions.length === 0 && extras.length === 0) {
|
|
1502
|
+
return;
|
|
1503
|
+
}
|
|
1504
|
+
const pieces = [];
|
|
1505
|
+
if (missing.length > 0) {
|
|
1506
|
+
pieces.push(`missing: ${missing.join(", ")}`);
|
|
1507
|
+
}
|
|
1508
|
+
if (nonFunctions.length > 0) {
|
|
1509
|
+
pieces.push(`non-functions: ${nonFunctions.join(", ")}`);
|
|
1510
|
+
}
|
|
1511
|
+
if (extras.length > 0) {
|
|
1512
|
+
pieces.push(`extras: ${extras.join(", ")}`);
|
|
1513
|
+
}
|
|
1514
|
+
const label = options.name ?? "contract";
|
|
1515
|
+
throw new Error(`${label} validation failed (${pieces.join("; ")})`);
|
|
1516
|
+
}
|
|
1517
|
+
var GAME_IMPORT_KEYS = [
|
|
1518
|
+
"Broadcast_Print",
|
|
1519
|
+
"Com_Print",
|
|
1520
|
+
"Client_Print",
|
|
1521
|
+
"Center_Print",
|
|
1522
|
+
"sound",
|
|
1523
|
+
"positioned_sound",
|
|
1524
|
+
"local_sound",
|
|
1525
|
+
"configstring",
|
|
1526
|
+
"get_configstring",
|
|
1527
|
+
"Com_Error",
|
|
1528
|
+
"modelindex",
|
|
1529
|
+
"soundindex",
|
|
1530
|
+
"imageindex",
|
|
1531
|
+
"setmodel",
|
|
1532
|
+
"trace",
|
|
1533
|
+
"clip",
|
|
1534
|
+
"pointcontents",
|
|
1535
|
+
"inPVS",
|
|
1536
|
+
"inPHS",
|
|
1537
|
+
"SetAreaPortalState",
|
|
1538
|
+
"AreasConnected",
|
|
1539
|
+
"linkentity",
|
|
1540
|
+
"unlinkentity",
|
|
1541
|
+
"BoxEdicts",
|
|
1542
|
+
"multicast",
|
|
1543
|
+
"unicast"
|
|
1544
|
+
];
|
|
1545
|
+
var GAME_EXPORT_KEYS = [
|
|
1546
|
+
"PreInit",
|
|
1547
|
+
"Init",
|
|
1548
|
+
"Shutdown",
|
|
1549
|
+
"SpawnEntities",
|
|
1550
|
+
"WriteGameJson",
|
|
1551
|
+
"ReadGameJson",
|
|
1552
|
+
"WriteLevelJson",
|
|
1553
|
+
"ReadLevelJson",
|
|
1554
|
+
"CanSave",
|
|
1555
|
+
"ClientConnect",
|
|
1556
|
+
"ClientThink",
|
|
1557
|
+
"RunFrame",
|
|
1558
|
+
"Pmove"
|
|
1559
|
+
];
|
|
1560
|
+
var CGAME_IMPORT_KEYS = [
|
|
1561
|
+
"Com_Print",
|
|
1562
|
+
"get_configstring",
|
|
1563
|
+
"Com_Error",
|
|
1564
|
+
"TagMalloc",
|
|
1565
|
+
"TagFree",
|
|
1566
|
+
"AddCommandString",
|
|
1567
|
+
"CL_FrameValid",
|
|
1568
|
+
"CL_FrameTime",
|
|
1569
|
+
"CL_ClientTime",
|
|
1570
|
+
"CL_ServerFrame",
|
|
1571
|
+
"Draw_RegisterPic",
|
|
1572
|
+
"Draw_GetPicSize",
|
|
1573
|
+
"SCR_DrawChar",
|
|
1574
|
+
"SCR_DrawPic",
|
|
1575
|
+
"SCR_DrawColorPic"
|
|
1576
|
+
];
|
|
1577
|
+
var CGAME_EXPORT_KEYS = [
|
|
1578
|
+
"Init",
|
|
1579
|
+
"Shutdown",
|
|
1580
|
+
"DrawHUD",
|
|
1581
|
+
"TouchPics",
|
|
1582
|
+
"LayoutFlags",
|
|
1583
|
+
"GetActiveWeaponWheelWeapon",
|
|
1584
|
+
"GetOwnedWeaponWheelWeapons",
|
|
1585
|
+
"GetWeaponWheelAmmoCount",
|
|
1586
|
+
"GetPowerupWheelCount",
|
|
1587
|
+
"GetHitMarkerDamage",
|
|
1588
|
+
"Pmove",
|
|
1589
|
+
"ParseConfigString",
|
|
1590
|
+
"ParseCenterPrint",
|
|
1591
|
+
"ClearNotify",
|
|
1592
|
+
"ClearCenterprint",
|
|
1593
|
+
"NotifyMessage",
|
|
1594
|
+
"GetMonsterFlashOffset"
|
|
1595
|
+
];
|
|
1596
|
+
|
|
1020
1597
|
// src/pmove/constants.ts
|
|
1021
1598
|
var WaterLevel = /* @__PURE__ */ ((WaterLevel3) => {
|
|
1022
1599
|
WaterLevel3[WaterLevel3["None"] = 0] = "None";
|
|
@@ -1832,7 +2409,7 @@ function buildFlyWishVelocity(params) {
|
|
|
1832
2409
|
|
|
1833
2410
|
// src/pmove/water.ts
|
|
1834
2411
|
function getWaterLevel(params) {
|
|
1835
|
-
const { origin, mins, viewheight, pointContents } = params;
|
|
2412
|
+
const { origin, mins, viewheight, pointContents: pointContents2 } = params;
|
|
1836
2413
|
const sample2 = viewheight - mins.z;
|
|
1837
2414
|
const sample1 = sample2 / 2;
|
|
1838
2415
|
const point = {
|
|
@@ -1840,18 +2417,18 @@ function getWaterLevel(params) {
|
|
|
1840
2417
|
y: origin.y,
|
|
1841
2418
|
z: origin.z + mins.z + 1
|
|
1842
2419
|
};
|
|
1843
|
-
let contents =
|
|
2420
|
+
let contents = pointContents2(point);
|
|
1844
2421
|
if ((contents & MASK_WATER) === 0) {
|
|
1845
2422
|
return { waterlevel: 0 /* None */, watertype: CONTENTS_NONE };
|
|
1846
2423
|
}
|
|
1847
2424
|
const watertype = contents;
|
|
1848
2425
|
let waterlevel = 1 /* Feet */;
|
|
1849
2426
|
let point2 = { x: point.x, y: point.y, z: origin.z + mins.z + sample1 };
|
|
1850
|
-
contents =
|
|
2427
|
+
contents = pointContents2(point2);
|
|
1851
2428
|
if ((contents & MASK_WATER) !== 0) {
|
|
1852
2429
|
waterlevel = 2 /* Waist */;
|
|
1853
2430
|
let point3 = { x: point.x, y: point.y, z: origin.z + mins.z + sample2 };
|
|
1854
|
-
contents =
|
|
2431
|
+
contents = pointContents2(point3);
|
|
1855
2432
|
if ((contents & MASK_WATER) !== 0) {
|
|
1856
2433
|
waterlevel = 3 /* Under */;
|
|
1857
2434
|
}
|
|
@@ -2041,7 +2618,7 @@ function categorizePosition(params) {
|
|
|
2041
2618
|
maxs,
|
|
2042
2619
|
viewheight,
|
|
2043
2620
|
trace,
|
|
2044
|
-
pointContents
|
|
2621
|
+
pointContents: pointContents2
|
|
2045
2622
|
} = params;
|
|
2046
2623
|
let pmFlags = params.pmFlags;
|
|
2047
2624
|
let pmTime = params.pmTime;
|
|
@@ -2096,7 +2673,7 @@ function categorizePosition(params) {
|
|
|
2096
2673
|
origin,
|
|
2097
2674
|
mins,
|
|
2098
2675
|
viewheight,
|
|
2099
|
-
pointContents
|
|
2676
|
+
pointContents: pointContents2
|
|
2100
2677
|
});
|
|
2101
2678
|
return {
|
|
2102
2679
|
pmFlags,
|
|
@@ -2438,7 +3015,7 @@ function checkSpecialMovement(params) {
|
|
|
2438
3015
|
maxs,
|
|
2439
3016
|
viewheight,
|
|
2440
3017
|
trace,
|
|
2441
|
-
pointContents,
|
|
3018
|
+
pointContents: pointContents2,
|
|
2442
3019
|
onGround,
|
|
2443
3020
|
overbounce = DEFAULT_OVERBOUNCE2,
|
|
2444
3021
|
stepSize = WATERJUMP_STEP_TOLERANCE,
|
|
@@ -2518,7 +3095,7 @@ function checkSpecialMovement(params) {
|
|
|
2518
3095
|
if (onGround && Math.abs(origin.z - downTrace.endpos.z) <= stepSize) {
|
|
2519
3096
|
return { pmFlags, pmTime, velocity, performedWaterJump: false };
|
|
2520
3097
|
}
|
|
2521
|
-
const landingWater = getWaterLevel({ origin: downTrace.endpos, mins, viewheight, pointContents });
|
|
3098
|
+
const landingWater = getWaterLevel({ origin: downTrace.endpos, mins, viewheight, pointContents: pointContents2 });
|
|
2522
3099
|
if (landingWater.waterlevel >= 2 /* Waist */) {
|
|
2523
3100
|
return { pmFlags, pmTime, velocity, performedWaterJump: false };
|
|
2524
3101
|
}
|
|
@@ -2614,8 +3191,40 @@ function clampViewAngles(params) {
|
|
|
2614
3191
|
const vectors = angleVectors(viewangles);
|
|
2615
3192
|
return { viewangles, ...vectors };
|
|
2616
3193
|
}
|
|
3194
|
+
|
|
3195
|
+
// src/protocol/usercmd.ts
|
|
3196
|
+
var DEFAULT_FORWARD_SPEED = 200;
|
|
3197
|
+
var DEFAULT_SIDE_SPEED = 200;
|
|
3198
|
+
var DEFAULT_UP_SPEED = 200;
|
|
3199
|
+
var DEFAULT_YAW_SPEED = 140;
|
|
3200
|
+
var DEFAULT_PITCH_SPEED = 150;
|
|
3201
|
+
var DEFAULT_MOUSE_SENSITIVITY = 3;
|
|
3202
|
+
function clampPitch2(pitch) {
|
|
3203
|
+
const normalized = angleMod(pitch);
|
|
3204
|
+
if (normalized > 89 && normalized < 180) return 89;
|
|
3205
|
+
if (normalized < 271 && normalized >= 180) return 271;
|
|
3206
|
+
return normalized;
|
|
3207
|
+
}
|
|
3208
|
+
function addViewAngles(current, delta) {
|
|
3209
|
+
return {
|
|
3210
|
+
x: clampPitch2(current.x + delta.x),
|
|
3211
|
+
y: angleMod(current.y + delta.y),
|
|
3212
|
+
z: angleMod(current.z + delta.z)
|
|
3213
|
+
};
|
|
3214
|
+
}
|
|
3215
|
+
function mouseDeltaToViewDelta(delta, options) {
|
|
3216
|
+
const yawScale = options.sensitivityX ?? options.sensitivity;
|
|
3217
|
+
const pitchScale = (options.sensitivityY ?? options.sensitivity) * (options.invertY ? -1 : 1);
|
|
3218
|
+
return {
|
|
3219
|
+
x: delta.deltaY * pitchScale,
|
|
3220
|
+
y: delta.deltaX * yawScale,
|
|
3221
|
+
z: 0
|
|
3222
|
+
};
|
|
3223
|
+
}
|
|
2617
3224
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2618
3225
|
0 && (module.exports = {
|
|
3226
|
+
CGAME_EXPORT_KEYS,
|
|
3227
|
+
CGAME_IMPORT_KEYS,
|
|
2619
3228
|
CONTENTS_AREAPORTAL,
|
|
2620
3229
|
CONTENTS_AUX,
|
|
2621
3230
|
CONTENTS_CURRENT_0,
|
|
@@ -2641,13 +3250,23 @@ function clampViewAngles(params) {
|
|
|
2641
3250
|
CONTENTS_SLIME,
|
|
2642
3251
|
CONTENTS_SOLID,
|
|
2643
3252
|
CONTENTS_TRANSLUCENT,
|
|
3253
|
+
CONTENTS_TRIGGER,
|
|
2644
3254
|
CONTENTS_WATER,
|
|
2645
3255
|
CONTENTS_WINDOW,
|
|
2646
3256
|
CS_MAX_STRING_LENGTH,
|
|
2647
3257
|
CS_MAX_STRING_LENGTH_OLD,
|
|
3258
|
+
CollisionEntityIndex,
|
|
2648
3259
|
ConfigStringIndex,
|
|
2649
3260
|
CvarFlags,
|
|
3261
|
+
DEFAULT_FORWARD_SPEED,
|
|
3262
|
+
DEFAULT_MOUSE_SENSITIVITY,
|
|
3263
|
+
DEFAULT_PITCH_SPEED,
|
|
3264
|
+
DEFAULT_SIDE_SPEED,
|
|
3265
|
+
DEFAULT_UP_SPEED,
|
|
3266
|
+
DEFAULT_YAW_SPEED,
|
|
2650
3267
|
DIST_EPSILON,
|
|
3268
|
+
GAME_EXPORT_KEYS,
|
|
3269
|
+
GAME_IMPORT_KEYS,
|
|
2651
3270
|
LAST_VISIBLE_CONTENTS,
|
|
2652
3271
|
MASK_ALL,
|
|
2653
3272
|
MASK_BLOCK_SIGHT,
|
|
@@ -2712,6 +3331,7 @@ function clampViewAngles(params) {
|
|
|
2712
3331
|
addPmFlag,
|
|
2713
3332
|
addPointToBounds,
|
|
2714
3333
|
addVec3,
|
|
3334
|
+
addViewAngles,
|
|
2715
3335
|
angleMod,
|
|
2716
3336
|
angleVectors,
|
|
2717
3337
|
applyPmoveAccelerate,
|
|
@@ -2721,6 +3341,8 @@ function clampViewAngles(params) {
|
|
|
2721
3341
|
applyPmoveFlyMove,
|
|
2722
3342
|
applyPmoveFriction,
|
|
2723
3343
|
applyPmoveWaterMove,
|
|
3344
|
+
assertContract,
|
|
3345
|
+
boxContents,
|
|
2724
3346
|
boxOnPlaneSide,
|
|
2725
3347
|
boxesIntersect,
|
|
2726
3348
|
buildAirGroundWish,
|
|
@@ -2756,18 +3378,23 @@ function clampViewAngles(params) {
|
|
|
2756
3378
|
hasAnyContents,
|
|
2757
3379
|
hasPmFlag,
|
|
2758
3380
|
hasSurfaceFlags,
|
|
3381
|
+
inPHS,
|
|
3382
|
+
inPVS,
|
|
2759
3383
|
initialSnapPosition,
|
|
2760
3384
|
isAtLeastWaistDeep,
|
|
2761
3385
|
isUnderwater,
|
|
2762
3386
|
lengthSquaredVec3,
|
|
2763
3387
|
lengthVec3,
|
|
2764
3388
|
lerpAngle,
|
|
3389
|
+
mouseDeltaToViewDelta,
|
|
2765
3390
|
multiplyVec3,
|
|
2766
3391
|
negateVec3,
|
|
2767
3392
|
normalizeVec3,
|
|
2768
3393
|
perpendicularVec3,
|
|
2769
3394
|
planeDistanceToPoint,
|
|
2770
3395
|
pmoveCmdScale,
|
|
3396
|
+
pointContents,
|
|
3397
|
+
pointContentsMany,
|
|
2771
3398
|
pointInsideBrush,
|
|
2772
3399
|
pointOnPlaneSide,
|
|
2773
3400
|
projectPointOnPlane,
|
|
@@ -2786,6 +3413,8 @@ function clampViewAngles(params) {
|
|
|
2786
3413
|
stepSlideMove,
|
|
2787
3414
|
subtractVec3,
|
|
2788
3415
|
testBoxInBrush,
|
|
3416
|
+
traceBox,
|
|
3417
|
+
validateContract,
|
|
2789
3418
|
vectorToAngles,
|
|
2790
3419
|
vectorToYaw,
|
|
2791
3420
|
waterCurrentVelocity
|