quake2ts 0.0.187 → 0.0.189

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.
Files changed (67) hide show
  1. package/package.json +1 -1
  2. package/packages/cgame/dist/index.cjs +256 -0
  3. package/packages/cgame/dist/index.cjs.map +1 -0
  4. package/packages/cgame/dist/index.d.cts +101 -0
  5. package/packages/cgame/dist/index.d.ts +99 -1
  6. package/packages/cgame/dist/index.js +250 -28
  7. package/packages/cgame/dist/index.js.map +1 -0
  8. package/packages/client/dist/browser/index.global.js +5 -5
  9. package/packages/client/dist/browser/index.global.js.map +1 -1
  10. package/packages/client/dist/cjs/index.cjs +34 -0
  11. package/packages/client/dist/cjs/index.cjs.map +1 -1
  12. package/packages/client/dist/esm/index.js +48 -14
  13. package/packages/client/dist/esm/index.js.map +1 -1
  14. package/packages/client/dist/tsconfig.tsbuildinfo +1 -1
  15. package/packages/engine/dist/browser/index.global.js +9 -9
  16. package/packages/engine/dist/browser/index.global.js.map +1 -1
  17. package/packages/engine/dist/cjs/index.cjs +17 -0
  18. package/packages/engine/dist/cjs/index.cjs.map +1 -1
  19. package/packages/engine/dist/esm/index.js +17 -0
  20. package/packages/engine/dist/esm/index.js.map +1 -1
  21. package/packages/engine/dist/tsconfig.tsbuildinfo +1 -1
  22. package/packages/game/dist/browser/index.global.js +2 -2
  23. package/packages/game/dist/browser/index.global.js.map +1 -1
  24. package/packages/game/dist/cjs/index.cjs +202 -161
  25. package/packages/game/dist/cjs/index.cjs.map +1 -1
  26. package/packages/game/dist/esm/index.js +202 -161
  27. package/packages/game/dist/esm/index.js.map +1 -1
  28. package/packages/game/dist/tsconfig.tsbuildinfo +1 -1
  29. package/packages/game/dist/types/entities/pool.d.ts +1 -0
  30. package/packages/game/dist/types/entities/pool.d.ts.map +1 -1
  31. package/packages/game/dist/types/entities/system.d.ts +2 -1
  32. package/packages/game/dist/types/entities/system.d.ts.map +1 -1
  33. package/packages/game/dist/types/imports.d.ts +1 -0
  34. package/packages/game/dist/types/imports.d.ts.map +1 -1
  35. package/packages/game/dist/types/index.d.ts +1 -1
  36. package/packages/game/dist/types/index.d.ts.map +1 -1
  37. package/packages/game/dist/types/inventory/ammo.d.ts +2 -24
  38. package/packages/game/dist/types/inventory/ammo.d.ts.map +1 -1
  39. package/packages/game/dist/types/inventory/playerInventory.d.ts +2 -47
  40. package/packages/game/dist/types/inventory/playerInventory.d.ts.map +1 -1
  41. package/packages/game/dist/types/physics/collision.d.ts.map +1 -1
  42. package/packages/server/dist/index.cjs +19 -1
  43. package/packages/server/dist/index.d.cts +1 -0
  44. package/packages/server/dist/index.d.ts +1 -0
  45. package/packages/server/dist/index.js +20 -2
  46. package/packages/shared/dist/browser/index.global.js +1 -1
  47. package/packages/shared/dist/browser/index.global.js.map +1 -1
  48. package/packages/shared/dist/cjs/index.cjs +153 -0
  49. package/packages/shared/dist/cjs/index.cjs.map +1 -1
  50. package/packages/shared/dist/esm/index.js +142 -0
  51. package/packages/shared/dist/esm/index.js.map +1 -1
  52. package/packages/shared/dist/tsconfig.tsbuildinfo +1 -1
  53. package/packages/shared/dist/types/index.d.ts +1 -0
  54. package/packages/shared/dist/types/index.d.ts.map +1 -1
  55. package/packages/shared/dist/types/items/ammo.d.ts +33 -0
  56. package/packages/shared/dist/types/items/ammo.d.ts.map +1 -0
  57. package/packages/shared/dist/types/items/index.d.ts +7 -0
  58. package/packages/shared/dist/types/items/index.d.ts.map +1 -0
  59. package/packages/shared/dist/types/items/powerups.d.ts +31 -0
  60. package/packages/shared/dist/types/items/powerups.d.ts.map +1 -0
  61. package/packages/shared/dist/types/items/weapons.d.ts +25 -0
  62. package/packages/shared/dist/types/items/weapons.d.ts.map +1 -0
  63. package/packages/shared/dist/types/protocol/index.d.ts +2 -0
  64. package/packages/shared/dist/types/protocol/index.d.ts.map +1 -1
  65. package/packages/tools/dist/tsconfig.tsbuildinfo +1 -1
  66. package/packages/cgame/dist/index.d.mts +0 -3
  67. package/packages/cgame/dist/index.mjs +0 -7
@@ -983,6 +983,80 @@ var applyPmove = (state, cmd, trace, pointContents2) => {
983
983
  velocity: finalVelocity
984
984
  };
985
985
  };
986
+ var WeaponId = /* @__PURE__ */ ((WeaponId22) => {
987
+ WeaponId22["Blaster"] = "blaster";
988
+ WeaponId22["Shotgun"] = "shotgun";
989
+ WeaponId22["SuperShotgun"] = "super_shotgun";
990
+ WeaponId22["Machinegun"] = "machinegun";
991
+ WeaponId22["Chaingun"] = "chaingun";
992
+ WeaponId22["GrenadeLauncher"] = "grenade_launcher";
993
+ WeaponId22["RocketLauncher"] = "rocket_launcher";
994
+ WeaponId22["HyperBlaster"] = "hyperblaster";
995
+ WeaponId22["Railgun"] = "railgun";
996
+ WeaponId22["BFG10K"] = "bfg10k";
997
+ WeaponId22["Grapple"] = "grapple";
998
+ WeaponId22["ChainFist"] = "chainfist";
999
+ WeaponId22["EtfRifle"] = "etf_rifle";
1000
+ WeaponId22["ProxLauncher"] = "prox_launcher";
1001
+ WeaponId22["IonRipper"] = "ionripper";
1002
+ WeaponId22["PlasmaBeam"] = "plasmabeam";
1003
+ WeaponId22["Phalanx"] = "phalanx";
1004
+ WeaponId22["Disruptor"] = "disruptor";
1005
+ return WeaponId22;
1006
+ })(WeaponId || {});
1007
+ var AmmoType = /* @__PURE__ */ ((AmmoType22) => {
1008
+ AmmoType22[AmmoType22["Bullets"] = 0] = "Bullets";
1009
+ AmmoType22[AmmoType22["Shells"] = 1] = "Shells";
1010
+ AmmoType22[AmmoType22["Rockets"] = 2] = "Rockets";
1011
+ AmmoType22[AmmoType22["Grenades"] = 3] = "Grenades";
1012
+ AmmoType22[AmmoType22["Cells"] = 4] = "Cells";
1013
+ AmmoType22[AmmoType22["Slugs"] = 5] = "Slugs";
1014
+ AmmoType22[AmmoType22["Trap"] = 6] = "Trap";
1015
+ AmmoType22[AmmoType22["Tesla"] = 7] = "Tesla";
1016
+ AmmoType22[AmmoType22["MagSlugs"] = 8] = "MagSlugs";
1017
+ AmmoType22[AmmoType22["Flechettes"] = 9] = "Flechettes";
1018
+ AmmoType22[AmmoType22["Prox"] = 10] = "Prox";
1019
+ AmmoType22[AmmoType22["Nuke"] = 11] = "Nuke";
1020
+ AmmoType22[AmmoType22["Rounds"] = 12] = "Rounds";
1021
+ return AmmoType22;
1022
+ })(AmmoType || {});
1023
+ var AMMO_TYPE_COUNT = Object.keys(AmmoType).length / 2;
1024
+ var AmmoItemId = /* @__PURE__ */ ((AmmoItemId22) => {
1025
+ AmmoItemId22["Shells"] = "ammo_shells";
1026
+ AmmoItemId22["Bullets"] = "ammo_bullets";
1027
+ AmmoItemId22["Rockets"] = "ammo_rockets";
1028
+ AmmoItemId22["Grenades"] = "ammo_grenades";
1029
+ AmmoItemId22["Cells"] = "ammo_cells";
1030
+ AmmoItemId22["Slugs"] = "ammo_slugs";
1031
+ return AmmoItemId22;
1032
+ })(AmmoItemId || {});
1033
+ var PowerupId = /* @__PURE__ */ ((PowerupId22) => {
1034
+ PowerupId22["QuadDamage"] = "quad";
1035
+ PowerupId22["Invulnerability"] = "invulnerability";
1036
+ PowerupId22["EnviroSuit"] = "enviro_suit";
1037
+ PowerupId22["Rebreather"] = "rebreather";
1038
+ PowerupId22["Silencer"] = "silencer";
1039
+ PowerupId22["PowerScreen"] = "power_screen";
1040
+ PowerupId22["PowerShield"] = "power_shield";
1041
+ PowerupId22["QuadFire"] = "quad_fire";
1042
+ PowerupId22["Invisibility"] = "invisibility";
1043
+ PowerupId22["Bandolier"] = "bandolier";
1044
+ PowerupId22["AmmoPack"] = "ammo_pack";
1045
+ PowerupId22["IRGoggles"] = "ir_goggles";
1046
+ PowerupId22["DoubleDamage"] = "double_damage";
1047
+ PowerupId22["SphereVengeance"] = "sphere_vengeance";
1048
+ PowerupId22["SphereHunter"] = "sphere_hunter";
1049
+ PowerupId22["SphereDefender"] = "sphere_defender";
1050
+ PowerupId22["Doppelganger"] = "doppelganger";
1051
+ PowerupId22["TagToken"] = "tag_token";
1052
+ PowerupId22["TechResistance"] = "tech_resistance";
1053
+ PowerupId22["TechStrength"] = "tech_strength";
1054
+ PowerupId22["TechHaste"] = "tech_haste";
1055
+ PowerupId22["TechRegeneration"] = "tech_regeneration";
1056
+ PowerupId22["Flashlight"] = "flashlight";
1057
+ PowerupId22["Compass"] = "compass";
1058
+ return PowerupId22;
1059
+ })(PowerupId || {});
986
1060
 
987
1061
  // src/combat/damageFlags.ts
988
1062
  var DamageFlags = /* @__PURE__ */ ((DamageFlags2) => {
@@ -1096,39 +1170,13 @@ function applyPowerArmor(damage, flags, hitPoint, _hitNormal, state, options = {
1096
1170
  }
1097
1171
 
1098
1172
  // src/inventory/ammo.ts
1099
- var AmmoType = /* @__PURE__ */ ((AmmoType3) => {
1100
- AmmoType3[AmmoType3["Bullets"] = 0] = "Bullets";
1101
- AmmoType3[AmmoType3["Shells"] = 1] = "Shells";
1102
- AmmoType3[AmmoType3["Rockets"] = 2] = "Rockets";
1103
- AmmoType3[AmmoType3["Grenades"] = 3] = "Grenades";
1104
- AmmoType3[AmmoType3["Cells"] = 4] = "Cells";
1105
- AmmoType3[AmmoType3["Slugs"] = 5] = "Slugs";
1106
- AmmoType3[AmmoType3["Trap"] = 6] = "Trap";
1107
- AmmoType3[AmmoType3["Tesla"] = 7] = "Tesla";
1108
- AmmoType3[AmmoType3["MagSlugs"] = 8] = "MagSlugs";
1109
- AmmoType3[AmmoType3["Flechettes"] = 9] = "Flechettes";
1110
- AmmoType3[AmmoType3["Prox"] = 10] = "Prox";
1111
- AmmoType3[AmmoType3["Nuke"] = 11] = "Nuke";
1112
- AmmoType3[AmmoType3["Rounds"] = 12] = "Rounds";
1113
- return AmmoType3;
1114
- })(AmmoType || {});
1115
- var AMMO_TYPE_COUNT = Object.keys(AmmoType).length / 2;
1116
- var AmmoItemId = /* @__PURE__ */ ((AmmoItemId4) => {
1117
- AmmoItemId4["Shells"] = "ammo_shells";
1118
- AmmoItemId4["Bullets"] = "ammo_bullets";
1119
- AmmoItemId4["Rockets"] = "ammo_rockets";
1120
- AmmoItemId4["Grenades"] = "ammo_grenades";
1121
- AmmoItemId4["Cells"] = "ammo_cells";
1122
- AmmoItemId4["Slugs"] = "ammo_slugs";
1123
- return AmmoItemId4;
1124
- })(AmmoItemId || {});
1125
1173
  var AMMO_ITEM_DEFINITIONS = {
1126
- ["ammo_shells" /* Shells */]: { id: "ammo_shells" /* Shells */, ammoType: 1 /* Shells */, quantity: 10, weaponAmmo: false },
1127
- ["ammo_bullets" /* Bullets */]: { id: "ammo_bullets" /* Bullets */, ammoType: 0 /* Bullets */, quantity: 50, weaponAmmo: false },
1128
- ["ammo_rockets" /* Rockets */]: { id: "ammo_rockets" /* Rockets */, ammoType: 2 /* Rockets */, quantity: 5, weaponAmmo: false },
1129
- ["ammo_grenades" /* Grenades */]: { id: "ammo_grenades" /* Grenades */, ammoType: 3 /* Grenades */, quantity: 5, weaponAmmo: true },
1130
- ["ammo_cells" /* Cells */]: { id: "ammo_cells" /* Cells */, ammoType: 4 /* Cells */, quantity: 50, weaponAmmo: false },
1131
- ["ammo_slugs" /* Slugs */]: { id: "ammo_slugs" /* Slugs */, ammoType: 5 /* Slugs */, quantity: 10, weaponAmmo: false }
1174
+ [AmmoItemId.Shells]: { id: AmmoItemId.Shells, ammoType: AmmoType.Shells, quantity: 10, weaponAmmo: false },
1175
+ [AmmoItemId.Bullets]: { id: AmmoItemId.Bullets, ammoType: AmmoType.Bullets, quantity: 50, weaponAmmo: false },
1176
+ [AmmoItemId.Rockets]: { id: AmmoItemId.Rockets, ammoType: AmmoType.Rockets, quantity: 5, weaponAmmo: false },
1177
+ [AmmoItemId.Grenades]: { id: AmmoItemId.Grenades, ammoType: AmmoType.Grenades, quantity: 5, weaponAmmo: true },
1178
+ [AmmoItemId.Cells]: { id: AmmoItemId.Cells, ammoType: AmmoType.Cells, quantity: 50, weaponAmmo: false },
1179
+ [AmmoItemId.Slugs]: { id: AmmoItemId.Slugs, ammoType: AmmoType.Slugs, quantity: 10, weaponAmmo: false }
1132
1180
  };
1133
1181
  function getAmmoItemDefinition(id) {
1134
1182
  return AMMO_ITEM_DEFINITIONS[id];
@@ -1144,9 +1192,9 @@ function createAmmoInventory(caps = createBaseAmmoCaps(), seed) {
1144
1192
  }
1145
1193
  function createBaseAmmoCaps() {
1146
1194
  const caps = Array(AMMO_TYPE_COUNT).fill(50);
1147
- caps[0 /* Bullets */] = 200;
1148
- caps[1 /* Shells */] = 100;
1149
- caps[4 /* Cells */] = 200;
1195
+ caps[AmmoType.Bullets] = 200;
1196
+ caps[AmmoType.Shells] = 100;
1197
+ caps[AmmoType.Cells] = 200;
1150
1198
  return caps;
1151
1199
  }
1152
1200
  function clampAmmoCounts(counts, caps) {
@@ -1179,54 +1227,6 @@ function pickupAmmo(inventory, itemId, options = {}) {
1179
1227
  }
1180
1228
 
1181
1229
  // src/inventory/playerInventory.ts
1182
- var WeaponId = /* @__PURE__ */ ((WeaponId3) => {
1183
- WeaponId3["Blaster"] = "blaster";
1184
- WeaponId3["Shotgun"] = "shotgun";
1185
- WeaponId3["SuperShotgun"] = "super_shotgun";
1186
- WeaponId3["Machinegun"] = "machinegun";
1187
- WeaponId3["Chaingun"] = "chaingun";
1188
- WeaponId3["GrenadeLauncher"] = "grenade_launcher";
1189
- WeaponId3["RocketLauncher"] = "rocket_launcher";
1190
- WeaponId3["HyperBlaster"] = "hyperblaster";
1191
- WeaponId3["Railgun"] = "railgun";
1192
- WeaponId3["BFG10K"] = "bfg10k";
1193
- WeaponId3["Grapple"] = "grapple";
1194
- WeaponId3["ChainFist"] = "chainfist";
1195
- WeaponId3["EtfRifle"] = "etf_rifle";
1196
- WeaponId3["ProxLauncher"] = "prox_launcher";
1197
- WeaponId3["IonRipper"] = "ionripper";
1198
- WeaponId3["PlasmaBeam"] = "plasmabeam";
1199
- WeaponId3["Phalanx"] = "phalanx";
1200
- WeaponId3["Disruptor"] = "disruptor";
1201
- return WeaponId3;
1202
- })(WeaponId || {});
1203
- var PowerupId = /* @__PURE__ */ ((PowerupId3) => {
1204
- PowerupId3["QuadDamage"] = "quad";
1205
- PowerupId3["Invulnerability"] = "invulnerability";
1206
- PowerupId3["EnviroSuit"] = "enviro_suit";
1207
- PowerupId3["Rebreather"] = "rebreather";
1208
- PowerupId3["Silencer"] = "silencer";
1209
- PowerupId3["PowerScreen"] = "power_screen";
1210
- PowerupId3["PowerShield"] = "power_shield";
1211
- PowerupId3["QuadFire"] = "quad_fire";
1212
- PowerupId3["Invisibility"] = "invisibility";
1213
- PowerupId3["Bandolier"] = "bandolier";
1214
- PowerupId3["AmmoPack"] = "ammo_pack";
1215
- PowerupId3["IRGoggles"] = "ir_goggles";
1216
- PowerupId3["DoubleDamage"] = "double_damage";
1217
- PowerupId3["SphereVengeance"] = "sphere_vengeance";
1218
- PowerupId3["SphereHunter"] = "sphere_hunter";
1219
- PowerupId3["SphereDefender"] = "sphere_defender";
1220
- PowerupId3["Doppelganger"] = "doppelganger";
1221
- PowerupId3["TagToken"] = "tag_token";
1222
- PowerupId3["TechResistance"] = "tech_resistance";
1223
- PowerupId3["TechStrength"] = "tech_strength";
1224
- PowerupId3["TechHaste"] = "tech_haste";
1225
- PowerupId3["TechRegeneration"] = "tech_regeneration";
1226
- PowerupId3["Flashlight"] = "flashlight";
1227
- PowerupId3["Compass"] = "compass";
1228
- return PowerupId3;
1229
- })(PowerupId || {});
1230
1230
  var KeyId = /* @__PURE__ */ ((KeyId2) => {
1231
1231
  KeyId2["Blue"] = "blue";
1232
1232
  KeyId2["Red"] = "red";
@@ -1376,27 +1376,27 @@ function pickupPowerup(client, item, time) {
1376
1376
  let icon = "";
1377
1377
  switch (item.id) {
1378
1378
  case "item_quad":
1379
- powerupId = "quad" /* QuadDamage */;
1379
+ powerupId = PowerupId.QuadDamage;
1380
1380
  icon = "p_quad";
1381
1381
  break;
1382
1382
  case "item_invulnerability":
1383
- powerupId = "invulnerability" /* Invulnerability */;
1383
+ powerupId = PowerupId.Invulnerability;
1384
1384
  icon = "p_invulnerability";
1385
1385
  break;
1386
1386
  case "item_silencer":
1387
- powerupId = "silencer" /* Silencer */;
1387
+ powerupId = PowerupId.Silencer;
1388
1388
  icon = "p_silencer";
1389
1389
  break;
1390
1390
  case "item_rebreather":
1391
- powerupId = "rebreather" /* Rebreather */;
1391
+ powerupId = PowerupId.Rebreather;
1392
1392
  icon = "p_rebreather";
1393
1393
  break;
1394
1394
  case "item_enviro":
1395
- powerupId = "enviro_suit" /* EnviroSuit */;
1395
+ powerupId = PowerupId.EnviroSuit;
1396
1396
  icon = "p_envirosuit";
1397
1397
  break;
1398
1398
  case "item_double":
1399
- powerupId = "double_damage" /* DoubleDamage */;
1399
+ powerupId = PowerupId.DoubleDamage;
1400
1400
  icon = "p_double";
1401
1401
  break;
1402
1402
  }
@@ -1404,9 +1404,9 @@ function pickupPowerup(client, item, time) {
1404
1404
  const expiresAt = inventory.powerups.get(powerupId);
1405
1405
  const newExpiresAt = expiresAt && expiresAt > time ? expiresAt + item.timer * 1e3 : time + item.timer * 1e3;
1406
1406
  inventory.powerups.set(powerupId, newExpiresAt);
1407
- if (powerupId === "quad" /* QuadDamage */) {
1407
+ if (powerupId === PowerupId.QuadDamage) {
1408
1408
  client.quad_time = newExpiresAt / 1e3;
1409
- } else if (powerupId === "double_damage" /* DoubleDamage */) {
1409
+ } else if (powerupId === PowerupId.DoubleDamage) {
1410
1410
  client.double_time = newExpiresAt / 1e3;
1411
1411
  }
1412
1412
  setPickup(inventory, icon, time);
@@ -1675,10 +1675,10 @@ var Entity = class {
1675
1675
  return {
1676
1676
  type,
1677
1677
  get cellCount() {
1678
- return ammo.counts[4 /* Cells */] || 0;
1678
+ return ammo.counts[AmmoType.Cells] || 0;
1679
1679
  },
1680
1680
  set cellCount(v) {
1681
- ammo.counts[4 /* Cells */] = v;
1681
+ ammo.counts[AmmoType.Cells] = v;
1682
1682
  },
1683
1683
  angles: this.angles,
1684
1684
  origin: this.origin,
@@ -2374,15 +2374,16 @@ function checkTriggers(ent, system) {
2374
2374
  if (ent.movetype === 0 /* None */) {
2375
2375
  return;
2376
2376
  }
2377
- system.forEachEntity((other) => {
2378
- if (other === ent) return;
2379
- if (other.solid !== 1 /* Trigger */) return;
2380
- if (!other.touch) return;
2381
- if (ent.absmax.x < other.absmin.x || ent.absmin.x > other.absmax.x) return;
2382
- if (ent.absmax.y < other.absmin.y || ent.absmin.y > other.absmax.y) return;
2383
- if (ent.absmax.z < other.absmin.z || ent.absmin.z > other.absmax.z) return;
2377
+ const candidates = system.findInBox(ent.absmin, ent.absmax);
2378
+ for (const other of candidates) {
2379
+ if (other === ent) continue;
2380
+ if (other.solid !== 1 /* Trigger */) continue;
2381
+ if (!other.touch) continue;
2382
+ if (ent.absmax.x < other.absmin.x || ent.absmin.x > other.absmax.x) continue;
2383
+ if (ent.absmax.y < other.absmin.y || ent.absmin.y > other.absmax.y) continue;
2384
+ if (ent.absmax.z < other.absmin.z || ent.absmin.z > other.absmax.z) continue;
2384
2385
  other.touch(other, ent);
2385
- });
2386
+ }
2386
2387
  }
2387
2388
 
2388
2389
  // src/physics/movement.ts
@@ -2702,6 +2703,9 @@ var EntityPool = class {
2702
2703
  }
2703
2704
  return count;
2704
2705
  }
2706
+ getByIndex(index) {
2707
+ return this.entities[index];
2708
+ }
2705
2709
  [Symbol.iterator]() {
2706
2710
  let current = this.activeHead;
2707
2711
  return {
@@ -2963,7 +2967,7 @@ var EntitySystem = class {
2963
2967
  this.thinkScheduler = new ThinkScheduler();
2964
2968
  this.engine = engine;
2965
2969
  this.deathmatch = deathmatch ?? false;
2966
- this.imports = imports || {
2970
+ const defaultImports = {
2967
2971
  trace: () => ({
2968
2972
  allsolid: false,
2969
2973
  startsolid: false,
@@ -2987,11 +2991,14 @@ var EntitySystem = class {
2987
2991
  z: ent.origin.z + ent.maxs.z
2988
2992
  };
2989
2993
  },
2994
+ areaEdicts: () => null,
2995
+ // Default to null to signal fallback
2990
2996
  multicast: () => {
2991
2997
  },
2992
2998
  unicast: () => {
2993
2999
  }
2994
3000
  };
3001
+ this.imports = { ...defaultImports, ...imports };
2995
3002
  this.gravity = gravity || { x: 0, y: 0, z: 0 };
2996
3003
  this.callbackToName = /* @__PURE__ */ new Map();
2997
3004
  if (callbackRegistry) {
@@ -3109,14 +3116,37 @@ var EntitySystem = class {
3109
3116
  }
3110
3117
  return Array.from(matches).filter((entity) => entity.inUse && !entity.freePending);
3111
3118
  }
3119
+ findInBox(mins, maxs) {
3120
+ const indices = this.imports.areaEdicts(mins, maxs);
3121
+ if (indices === null) {
3122
+ const results2 = [];
3123
+ const bounds = { min: mins, max: maxs };
3124
+ for (const entity of this.pool) {
3125
+ if (!entity.inUse || entity.freePending || entity.solid === 0 /* Not */) continue;
3126
+ if (boundsIntersect(bounds, computeBounds(entity))) {
3127
+ results2.push(entity);
3128
+ }
3129
+ }
3130
+ return results2;
3131
+ }
3132
+ const results = [];
3133
+ for (const index of indices) {
3134
+ const entity = this.pool.getByIndex(index);
3135
+ if (entity && entity.inUse && !entity.freePending) {
3136
+ results.push(entity);
3137
+ }
3138
+ }
3139
+ return results;
3140
+ }
3112
3141
  findByRadius(origin, radius) {
3142
+ const mins = { x: origin.x - radius, y: origin.y - radius, z: origin.z - radius };
3143
+ const maxs = { x: origin.x + radius, y: origin.y + radius, z: origin.z + radius };
3144
+ const candidates = this.findInBox(mins, maxs);
3113
3145
  const matches = [];
3114
- for (const entity of this.pool) {
3115
- if (entity.inUse && !entity.freePending) {
3116
- const distance2 = lengthVec3(subtractVec3(origin, entity.origin));
3117
- if (distance2 <= radius) {
3118
- matches.push(entity);
3119
- }
3146
+ for (const entity of candidates) {
3147
+ const distance2 = lengthVec3(subtractVec3(origin, entity.origin));
3148
+ if (distance2 <= radius) {
3149
+ matches.push(entity);
3120
3150
  }
3121
3151
  }
3122
3152
  return matches;
@@ -3326,35 +3356,19 @@ var EntitySystem = class {
3326
3356
  const world = this.pool.world;
3327
3357
  const activeEntities = [];
3328
3358
  for (const entity of this.pool) {
3329
- if (entity === world) {
3330
- continue;
3331
- }
3332
- if (!entity.inUse || entity.freePending || entity.solid === 0 /* Not */) {
3333
- continue;
3334
- }
3359
+ if (entity === world) continue;
3360
+ if (!entity.inUse || entity.freePending || entity.solid === 0 /* Not */) continue;
3335
3361
  activeEntities.push(entity);
3336
3362
  }
3337
- for (let i = 0; i < activeEntities.length; i += 1) {
3338
- const first = activeEntities[i];
3339
- let firstBounds = null;
3340
- for (let j = i + 1; j < activeEntities.length; j += 1) {
3341
- const second = activeEntities[j];
3342
- if (!first.touch && !second.touch) {
3343
- continue;
3344
- }
3345
- if (!firstBounds) {
3346
- firstBounds = computeBounds(first);
3347
- }
3363
+ for (const first of activeEntities) {
3364
+ const candidates = this.findInBox(first.absmin, first.absmax);
3365
+ const firstBounds = computeBounds(first);
3366
+ for (const second of candidates) {
3367
+ if (first === second) continue;
3368
+ if (!first.touch) continue;
3348
3369
  const secondBounds = computeBounds(second);
3349
- if (!boundsIntersect(firstBounds, secondBounds)) {
3350
- continue;
3351
- }
3352
- if (first.touch) {
3353
- first.touch(first, second);
3354
- }
3355
- if (second.touch) {
3356
- second.touch(second, first);
3357
- }
3370
+ if (!boundsIntersect(firstBounds, secondBounds)) continue;
3371
+ first.touch(first, second);
3358
3372
  }
3359
3373
  }
3360
3374
  }
@@ -4084,7 +4098,7 @@ function chaingunThink(player, sys) {
4084
4098
  if (!player.client) {
4085
4099
  return;
4086
4100
  }
4087
- const weaponState = getWeaponState(player.client.weaponStates, "chaingun" /* Chaingun */);
4101
+ const weaponState = getWeaponState(player.client.weaponStates, WeaponId.Chaingun);
4088
4102
  if (!(player.client.buttons & BUTTON_ATTACK) && weaponState.spinupCount && weaponState.spinupCount > 0) {
4089
4103
  sys.sound(player, 0, "weapons/chngnd1a.wav", 1, 0, 0);
4090
4104
  weaponState.spinupCount = 0;
@@ -4097,7 +4111,7 @@ var WEAPON_ITEMS = {
4097
4111
  type: "weapon",
4098
4112
  id: "weapon_blaster",
4099
4113
  name: "Blaster",
4100
- weaponId: "blaster" /* Blaster */,
4114
+ weaponId: WeaponId.Blaster,
4101
4115
  ammoType: null,
4102
4116
  initialAmmo: 0,
4103
4117
  pickupAmmo: 0,
@@ -4107,8 +4121,8 @@ var WEAPON_ITEMS = {
4107
4121
  type: "weapon",
4108
4122
  id: "weapon_shotgun",
4109
4123
  name: "Shotgun",
4110
- weaponId: "shotgun" /* Shotgun */,
4111
- ammoType: 1 /* Shells */,
4124
+ weaponId: WeaponId.Shotgun,
4125
+ ammoType: AmmoType.Shells,
4112
4126
  initialAmmo: 10,
4113
4127
  pickupAmmo: 10,
4114
4128
  fireRate: 1
@@ -4117,8 +4131,8 @@ var WEAPON_ITEMS = {
4117
4131
  type: "weapon",
4118
4132
  id: "weapon_supershotgun",
4119
4133
  name: "Super Shotgun",
4120
- weaponId: "super_shotgun" /* SuperShotgun */,
4121
- ammoType: 1 /* Shells */,
4134
+ weaponId: WeaponId.SuperShotgun,
4135
+ ammoType: AmmoType.Shells,
4122
4136
  initialAmmo: 10,
4123
4137
  pickupAmmo: 10,
4124
4138
  fireRate: 1
@@ -4127,8 +4141,8 @@ var WEAPON_ITEMS = {
4127
4141
  type: "weapon",
4128
4142
  id: "weapon_machinegun",
4129
4143
  name: "Machinegun",
4130
- weaponId: "machinegun" /* Machinegun */,
4131
- ammoType: 0 /* Bullets */,
4144
+ weaponId: WeaponId.Machinegun,
4145
+ ammoType: AmmoType.Bullets,
4132
4146
  initialAmmo: 50,
4133
4147
  pickupAmmo: 50,
4134
4148
  fireRate: 0.1,
@@ -4138,8 +4152,8 @@ var WEAPON_ITEMS = {
4138
4152
  type: "weapon",
4139
4153
  id: "weapon_chaingun",
4140
4154
  name: "Chaingun",
4141
- weaponId: "chaingun" /* Chaingun */,
4142
- ammoType: 0 /* Bullets */,
4155
+ weaponId: WeaponId.Chaingun,
4156
+ ammoType: AmmoType.Bullets,
4143
4157
  initialAmmo: 50,
4144
4158
  pickupAmmo: 50,
4145
4159
  fireRate: 0.1
@@ -4148,8 +4162,8 @@ var WEAPON_ITEMS = {
4148
4162
  type: "weapon",
4149
4163
  id: "weapon_grenadelauncher",
4150
4164
  name: "Grenade Launcher",
4151
- weaponId: "grenade_launcher" /* GrenadeLauncher */,
4152
- ammoType: 3 /* Grenades */,
4165
+ weaponId: WeaponId.GrenadeLauncher,
4166
+ ammoType: AmmoType.Grenades,
4153
4167
  initialAmmo: 10,
4154
4168
  pickupAmmo: 10,
4155
4169
  fireRate: 1
@@ -4158,8 +4172,8 @@ var WEAPON_ITEMS = {
4158
4172
  type: "weapon",
4159
4173
  id: "weapon_rocketlauncher",
4160
4174
  name: "Rocket Launcher",
4161
- weaponId: "rocket_launcher" /* RocketLauncher */,
4162
- ammoType: 2 /* Rockets */,
4175
+ weaponId: WeaponId.RocketLauncher,
4176
+ ammoType: AmmoType.Rockets,
4163
4177
  initialAmmo: 5,
4164
4178
  pickupAmmo: 5,
4165
4179
  fireRate: 1
@@ -4168,8 +4182,8 @@ var WEAPON_ITEMS = {
4168
4182
  type: "weapon",
4169
4183
  id: "weapon_hyperblaster",
4170
4184
  name: "HyperBlaster",
4171
- weaponId: "hyperblaster" /* HyperBlaster */,
4172
- ammoType: 4 /* Cells */,
4185
+ weaponId: WeaponId.HyperBlaster,
4186
+ ammoType: AmmoType.Cells,
4173
4187
  initialAmmo: 50,
4174
4188
  pickupAmmo: 50,
4175
4189
  fireRate: 0.1
@@ -4178,8 +4192,8 @@ var WEAPON_ITEMS = {
4178
4192
  type: "weapon",
4179
4193
  id: "weapon_railgun",
4180
4194
  name: "Railgun",
4181
- weaponId: "railgun" /* Railgun */,
4182
- ammoType: 5 /* Slugs */,
4195
+ weaponId: WeaponId.Railgun,
4196
+ ammoType: AmmoType.Slugs,
4183
4197
  initialAmmo: 10,
4184
4198
  pickupAmmo: 10,
4185
4199
  fireRate: 1.5
@@ -4188,8 +4202,8 @@ var WEAPON_ITEMS = {
4188
4202
  type: "weapon",
4189
4203
  id: "weapon_bfg",
4190
4204
  name: "BFG10K",
4191
- weaponId: "bfg10k" /* BFG10K */,
4192
- ammoType: 4 /* Cells */,
4205
+ weaponId: WeaponId.BFG10K,
4206
+ ammoType: AmmoType.Cells,
4193
4207
  initialAmmo: 50,
4194
4208
  pickupAmmo: 50,
4195
4209
  fireRate: 1
@@ -13019,13 +13033,29 @@ var WEAPONS = {
13019
13033
 
13020
13034
  // src/index.ts
13021
13035
  var ZERO_VEC38 = { x: 0, y: 0, z: 0 };
13022
- function createGame({ trace, pointcontents, multicast, unicast }, engine, options) {
13036
+ function createGame(imports, engine, options) {
13023
13037
  const gravity = options.gravity;
13024
13038
  const deathmatch = options.deathmatch ?? false;
13025
13039
  const levelClock = new LevelClock();
13026
13040
  const frameLoop = new GameFrameLoop();
13027
13041
  const rng = options.random ?? new RandomGenerator();
13028
- const linkentity = (ent) => {
13042
+ const trace = imports.trace || (() => ({
13043
+ allsolid: false,
13044
+ startsolid: false,
13045
+ fraction: 1,
13046
+ endpos: { x: 0, y: 0, z: 0 },
13047
+ plane: null,
13048
+ surfaceFlags: 0,
13049
+ contents: 0,
13050
+ ent: null
13051
+ }));
13052
+ const pointcontents = imports.pointcontents || (() => 0);
13053
+ const multicast = imports.multicast || (() => {
13054
+ });
13055
+ const unicast = imports.unicast || (() => {
13056
+ });
13057
+ const linkentity = imports.linkentity;
13058
+ const wrappedLinkEntity = (ent) => {
13029
13059
  ent.absmin = {
13030
13060
  x: ent.origin.x + ent.mins.x,
13031
13061
  y: ent.origin.y + ent.mins.y,
@@ -13036,8 +13066,19 @@ function createGame({ trace, pointcontents, multicast, unicast }, engine, option
13036
13066
  y: ent.origin.y + ent.maxs.y,
13037
13067
  z: ent.origin.z + ent.maxs.z
13038
13068
  };
13069
+ if (linkentity) {
13070
+ linkentity(ent);
13071
+ }
13072
+ };
13073
+ const systemImports = {
13074
+ ...imports,
13075
+ trace,
13076
+ pointcontents,
13077
+ linkentity: wrappedLinkEntity,
13078
+ multicast,
13079
+ unicast
13039
13080
  };
13040
- const entities = new EntitySystem(engine, { trace, pointcontents, linkentity, multicast, unicast }, gravity, void 0, void 0, deathmatch);
13081
+ const entities = new EntitySystem(engine, systemImports, gravity, void 0, void 0, deathmatch);
13041
13082
  frameLoop.addStage("prep", (context) => {
13042
13083
  levelClock.tick(context);
13043
13084
  entities.beginFrame(levelClock.current.timeSeconds);
@@ -13061,20 +13102,20 @@ function createGame({ trace, pointcontents, multicast, unicast }, engine, option
13061
13102
  const blend = [0, 0, 0, 0];
13062
13103
  if (!player || !player.client) return blend;
13063
13104
  const inventory = player.client.inventory;
13064
- if (inventory.powerups.has("quad" /* QuadDamage */)) {
13105
+ if (inventory.powerups.has(PowerupId.QuadDamage)) {
13065
13106
  blend[2] = 1;
13066
13107
  blend[3] = 0.08;
13067
13108
  }
13068
- if (inventory.powerups.has("invulnerability" /* Invulnerability */)) {
13109
+ if (inventory.powerups.has(PowerupId.Invulnerability)) {
13069
13110
  blend[0] = 1;
13070
13111
  blend[1] = 1;
13071
13112
  blend[3] = 0.08;
13072
13113
  }
13073
- if (inventory.powerups.has("enviro_suit" /* EnviroSuit */)) {
13114
+ if (inventory.powerups.has(PowerupId.EnviroSuit)) {
13074
13115
  blend[1] = 1;
13075
13116
  blend[3] = 0.08;
13076
13117
  }
13077
- if (inventory.powerups.has("rebreather" /* Rebreather */)) {
13118
+ if (inventory.powerups.has(PowerupId.Rebreather)) {
13078
13119
  blend[0] = 0.4;
13079
13120
  blend[1] = 1;
13080
13121
  blend[2] = 0.4;