quake2ts 0.0.408 → 0.0.412

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 (53) hide show
  1. package/package.json +1 -1
  2. package/packages/client/dist/browser/index.global.js +16 -16
  3. package/packages/client/dist/browser/index.global.js.map +1 -1
  4. package/packages/client/dist/cjs/index.cjs +492 -81
  5. package/packages/client/dist/cjs/index.cjs.map +1 -1
  6. package/packages/client/dist/esm/index.js +492 -81
  7. package/packages/client/dist/esm/index.js.map +1 -1
  8. package/packages/client/dist/tsconfig.tsbuildinfo +1 -1
  9. package/packages/client/dist/types/demo/handler.d.ts +3 -0
  10. package/packages/client/dist/types/demo/handler.d.ts.map +1 -1
  11. package/packages/client/dist/types/effects-system.d.ts +17 -0
  12. package/packages/client/dist/types/effects-system.d.ts.map +1 -0
  13. package/packages/client/dist/types/index.d.ts +2 -0
  14. package/packages/client/dist/types/index.d.ts.map +1 -1
  15. package/packages/client/dist/types/net/connection.d.ts +21 -4
  16. package/packages/client/dist/types/net/connection.d.ts.map +1 -1
  17. package/packages/engine/dist/browser/index.global.js +14 -14
  18. package/packages/engine/dist/browser/index.global.js.map +1 -1
  19. package/packages/engine/dist/cjs/index.cjs +142 -14
  20. package/packages/engine/dist/cjs/index.cjs.map +1 -1
  21. package/packages/engine/dist/esm/index.js +141 -14
  22. package/packages/engine/dist/esm/index.js.map +1 -1
  23. package/packages/engine/dist/tsconfig.tsbuildinfo +1 -1
  24. package/packages/engine/dist/types/assets/headlessLoader.d.ts +11 -0
  25. package/packages/engine/dist/types/assets/headlessLoader.d.ts.map +1 -0
  26. package/packages/engine/dist/types/assets/vfs.d.ts +1 -0
  27. package/packages/engine/dist/types/assets/vfs.d.ts.map +1 -1
  28. package/packages/engine/dist/types/editor/bsp-inspector.d.ts +28 -0
  29. package/packages/engine/dist/types/editor/bsp-inspector.d.ts.map +1 -0
  30. package/packages/engine/dist/types/index.d.ts +1 -1
  31. package/packages/engine/dist/types/index.d.ts.map +1 -1
  32. package/packages/engine/dist/types/render/bsp/generator.d.ts +25 -0
  33. package/packages/engine/dist/types/render/bsp/generator.d.ts.map +1 -0
  34. package/packages/engine/dist/types/render/bsp/geometry.d.ts.map +1 -1
  35. package/packages/engine/dist/types/render/camera.d.ts +15 -0
  36. package/packages/engine/dist/types/render/camera.d.ts.map +1 -1
  37. package/packages/engine/dist/types/render/cameraController.d.ts +28 -0
  38. package/packages/engine/dist/types/render/cameraController.d.ts.map +1 -0
  39. package/packages/engine/dist/types/render/debug.d.ts +20 -0
  40. package/packages/engine/dist/types/render/debug.d.ts.map +1 -0
  41. package/packages/engine/dist/types/render/options.d.ts +9 -0
  42. package/packages/engine/dist/types/render/options.d.ts.map +1 -0
  43. package/packages/engine/dist/types/render/renderer.d.ts +4 -1
  44. package/packages/engine/dist/types/render/renderer.d.ts.map +1 -1
  45. package/packages/engine/dist/types/render/types.d.ts +22 -0
  46. package/packages/engine/dist/types/render/types.d.ts.map +1 -0
  47. package/packages/game/dist/tsconfig.tsbuildinfo +1 -1
  48. package/packages/game/dist/types/editor/metadata.d.ts +31 -0
  49. package/packages/game/dist/types/editor/metadata.d.ts.map +1 -0
  50. package/packages/game/dist/types/editor/search.d.ts +9 -0
  51. package/packages/game/dist/types/editor/search.d.ts.map +1 -0
  52. package/packages/game/dist/types/editor/selection.d.ts +19 -0
  53. package/packages/game/dist/types/editor/selection.d.ts.map +1 -0
@@ -50,6 +50,7 @@ __export(index_exports, {
50
50
  DemoReader: () => DemoReader,
51
51
  DemoRecorder: () => DemoRecorder,
52
52
  DemoValidator: () => DemoValidator,
53
+ DynamicLightManager: () => DynamicLightManager,
53
54
  EngineHost: () => EngineHost,
54
55
  EngineRuntime: () => EngineRuntime,
55
56
  FileType: () => FileType,
@@ -377,6 +378,7 @@ function normalizeVec3(a) {
377
378
  var DEG2RAD_FACTOR = Math.PI / 180;
378
379
  var RAD2DEG_FACTOR = 180 / Math.PI;
379
380
  var DEG2RAD = DEG2RAD_FACTOR;
381
+ var RAD2DEG = RAD2DEG_FACTOR;
380
382
  var ANORMS = [
381
383
  [-0.525731, 0, 0.850651],
382
384
  [-0.442863, 0.238856, 0.864188],
@@ -2034,6 +2036,28 @@ var VirtualFileSystem = class {
2034
2036
  async readBinaryFile(path) {
2035
2037
  return this.readFile(path);
2036
2038
  }
2039
+ streamFile(path, chunkSize = 1024 * 1024) {
2040
+ const source = this.files.get(normalizePath(path));
2041
+ if (!source) {
2042
+ throw new Error(`File not found in VFS: ${path}`);
2043
+ }
2044
+ const { archive, entry } = source;
2045
+ const fullData = archive.readFile(path);
2046
+ let offset = 0;
2047
+ const totalSize = fullData.length;
2048
+ return new ReadableStream({
2049
+ pull(controller) {
2050
+ if (offset >= totalSize) {
2051
+ controller.close();
2052
+ return;
2053
+ }
2054
+ const end = Math.min(offset + chunkSize, totalSize);
2055
+ const chunk = fullData.slice(offset, end);
2056
+ offset = end;
2057
+ controller.enqueue(chunk);
2058
+ }
2059
+ });
2060
+ }
2037
2061
  async readTextFile(path) {
2038
2062
  const data = await this.readFile(path);
2039
2063
  return new TextDecoder("utf-8").decode(data);
@@ -5684,6 +5708,43 @@ function gatherVisibleFaces(map, cameraPosition, frustum) {
5684
5708
 
5685
5709
  // src/render/dlight.ts
5686
5710
  var MAX_DLIGHTS = 32;
5711
+ var DynamicLightManager = class {
5712
+ constructor() {
5713
+ this.lights = [];
5714
+ }
5715
+ /**
5716
+ * Adds a dynamic light or updates an existing one with the same key.
5717
+ */
5718
+ addLight(dlight, time) {
5719
+ if (dlight.key !== void 0) {
5720
+ const index = this.lights.findIndex((l) => l.key === dlight.key);
5721
+ if (index !== -1) {
5722
+ this.lights[index] = dlight;
5723
+ return;
5724
+ }
5725
+ }
5726
+ this.lights.push(dlight);
5727
+ }
5728
+ /**
5729
+ * Clears all lights (e.g., map change).
5730
+ */
5731
+ clear() {
5732
+ this.lights = [];
5733
+ }
5734
+ /**
5735
+ * Updates the list of active lights, removing expired ones.
5736
+ * @param time Current game time in seconds.
5737
+ */
5738
+ update(time) {
5739
+ this.lights = this.lights.filter((l) => l.die > time);
5740
+ }
5741
+ /**
5742
+ * Returns the current list of active lights.
5743
+ */
5744
+ getActiveLights() {
5745
+ return this.lights;
5746
+ }
5747
+ };
5687
5748
 
5688
5749
  // src/render/geometry.ts
5689
5750
  function generateWireframeIndices(indices) {
@@ -6535,15 +6596,21 @@ var Camera = class {
6535
6596
  return this._position;
6536
6597
  }
6537
6598
  set position(value) {
6538
- import_gl_matrix.vec3.copy(this._position, value);
6539
- this._dirty = true;
6599
+ if (!import_gl_matrix.vec3.equals(this._position, value)) {
6600
+ import_gl_matrix.vec3.copy(this._position, value);
6601
+ this._dirty = true;
6602
+ this.triggerMoveEvent();
6603
+ }
6540
6604
  }
6541
6605
  get angles() {
6542
6606
  return this._angles;
6543
6607
  }
6544
6608
  set angles(value) {
6545
- import_gl_matrix.vec3.copy(this._angles, value);
6546
- this._dirty = true;
6609
+ if (!import_gl_matrix.vec3.equals(this._angles, value)) {
6610
+ import_gl_matrix.vec3.copy(this._angles, value);
6611
+ this._dirty = true;
6612
+ this.triggerMoveEvent();
6613
+ }
6547
6614
  }
6548
6615
  get bobAngles() {
6549
6616
  return this._bobAngles;
@@ -6587,6 +6654,47 @@ var Camera = class {
6587
6654
  this._aspect = value;
6588
6655
  this._dirty = true;
6589
6656
  }
6657
+ // API Methods
6658
+ setPosition(x, y, z) {
6659
+ const newPos = import_gl_matrix.vec3.fromValues(x, y, z);
6660
+ if (!import_gl_matrix.vec3.equals(this._position, newPos)) {
6661
+ import_gl_matrix.vec3.copy(this._position, newPos);
6662
+ this._dirty = true;
6663
+ this.triggerMoveEvent();
6664
+ }
6665
+ }
6666
+ setRotation(pitch, yaw, roll) {
6667
+ const newAngles = import_gl_matrix.vec3.fromValues(pitch, yaw, roll);
6668
+ if (!import_gl_matrix.vec3.equals(this._angles, newAngles)) {
6669
+ import_gl_matrix.vec3.copy(this._angles, newAngles);
6670
+ this._dirty = true;
6671
+ this.triggerMoveEvent();
6672
+ }
6673
+ }
6674
+ setFov(fov) {
6675
+ this.fov = fov;
6676
+ }
6677
+ setAspectRatio(aspect) {
6678
+ this.aspect = aspect;
6679
+ }
6680
+ lookAt(target) {
6681
+ const direction = import_gl_matrix.vec3.create();
6682
+ import_gl_matrix.vec3.subtract(direction, target, this._position);
6683
+ const len = import_gl_matrix.vec3.length(direction);
6684
+ if (len < 1e-3) return;
6685
+ const yaw = Math.atan2(direction[1], direction[0]) * RAD2DEG;
6686
+ const hyp = Math.hypot(direction[0], direction[1]);
6687
+ const pitch = -Math.atan2(direction[2], hyp) * RAD2DEG;
6688
+ this.setRotation(pitch, yaw, 0);
6689
+ }
6690
+ triggerMoveEvent() {
6691
+ if (this.onCameraMove) {
6692
+ this.onCameraMove({
6693
+ position: import_gl_matrix.vec3.clone(this._position),
6694
+ angles: import_gl_matrix.vec3.clone(this._angles)
6695
+ });
6696
+ }
6697
+ }
6590
6698
  get viewMatrix() {
6591
6699
  this.updateMatrices();
6592
6700
  return this._viewMatrix;
@@ -6610,6 +6718,25 @@ var Camera = class {
6610
6718
  );
6611
6719
  return projectionMatrix;
6612
6720
  }
6721
+ screenToWorldRay(screenX, screenY) {
6722
+ const ndcX = screenX * 2 - 1;
6723
+ const ndcY = 1 - screenY * 2;
6724
+ const clipStart = import_gl_matrix.vec3.fromValues(ndcX, ndcY, -1);
6725
+ const clipEnd = import_gl_matrix.vec3.fromValues(ndcX, ndcY, 1);
6726
+ const invViewProj = import_gl_matrix.mat4.create();
6727
+ import_gl_matrix.mat4.invert(invViewProj, this.viewProjectionMatrix);
6728
+ const worldStart = import_gl_matrix.vec3.create();
6729
+ const worldEnd = import_gl_matrix.vec3.create();
6730
+ import_gl_matrix.vec3.transformMat4(worldStart, clipStart, invViewProj);
6731
+ import_gl_matrix.vec3.transformMat4(worldEnd, clipEnd, invViewProj);
6732
+ const direction = import_gl_matrix.vec3.create();
6733
+ import_gl_matrix.vec3.subtract(direction, worldEnd, worldStart);
6734
+ import_gl_matrix.vec3.normalize(direction, direction);
6735
+ return {
6736
+ origin: import_gl_matrix.vec3.clone(this._position),
6737
+ direction
6738
+ };
6739
+ }
6613
6740
  updateMatrices() {
6614
6741
  if (!this._dirty) {
6615
6742
  return;
@@ -6623,20 +6750,20 @@ var Camera = class {
6623
6750
  );
6624
6751
  const quakeToGl = import_gl_matrix.mat4.fromValues(
6625
6752
  0,
6626
- -1,
6627
6753
  0,
6754
+ -1,
6628
6755
  0,
6629
- // column 0: Quake X -> WebGL (0, -1, 0)
6756
+ // column 0: Quake X -> WebGL -Z
6757
+ -1,
6630
6758
  0,
6631
6759
  0,
6632
- 1,
6633
6760
  0,
6634
- // column 1: Quake Y -> WebGL (0, 0, 1)
6635
- -1,
6761
+ // column 1: Quake Y -> WebGL -X
6636
6762
  0,
6763
+ 1,
6637
6764
  0,
6638
6765
  0,
6639
- // column 2: Quake Z -> WebGL (-1, 0, 0)
6766
+ // column 2: Quake Z -> WebGL Y
6640
6767
  0,
6641
6768
  0,
6642
6769
  0,
@@ -6661,12 +6788,12 @@ var Camera = class {
6661
6788
  const rotatedPosQuake = import_gl_matrix.vec3.create();
6662
6789
  import_gl_matrix.vec3.transformMat4(rotatedPosQuake, negativePosition, rotationQuake);
6663
6790
  const translationGl = import_gl_matrix.vec3.fromValues(
6664
- rotatedPosQuake[1] || 0,
6665
- // Y in Quake -> X in WebGL (negation already applied above)
6791
+ rotatedPosQuake[1] ? -rotatedPosQuake[1] : 0,
6792
+ // Y in Quake -> -X in WebGL
6666
6793
  rotatedPosQuake[2] || 0,
6667
6794
  // Z in Quake -> Y in WebGL
6668
- rotatedPosQuake[0] || 0
6669
- // X in Quake -> Z in WebGL (negation already applied above)
6795
+ rotatedPosQuake[0] ? -rotatedPosQuake[0] : 0
6796
+ // X in Quake -> -Z in WebGL
6670
6797
  );
6671
6798
  import_gl_matrix.mat4.copy(this._viewMatrix, rotationGl);
6672
6799
  this._viewMatrix[12] = translationGl[0];
@@ -13730,6 +13857,7 @@ function createEngine(imports) {
13730
13857
  DemoReader,
13731
13858
  DemoRecorder,
13732
13859
  DemoValidator,
13860
+ DynamicLightManager,
13733
13861
  EngineHost,
13734
13862
  EngineRuntime,
13735
13863
  FileType,