@quake2ts/test-utils 0.0.818 → 0.0.823

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -226,7 +226,9 @@ __export(index_exports, {
226
226
  createSpawnTestContext: () => createSpawnTestContext,
227
227
  createStorageTestScenario: () => createStorageTestScenario,
228
228
  createSurfaceMock: () => createSurfaceMock,
229
+ createTestBspMap: () => createTestBspMap,
229
230
  createTestContext: () => createTestContext,
231
+ createTestLightmap: () => createTestLightmap,
230
232
  createTraceMock: () => createTraceMock,
231
233
  createTransform: () => createTransform,
232
234
  createTriggerEntityFactory: () => createTriggerEntityFactory,
@@ -494,6 +496,140 @@ function makeBrushFromMinsMaxs(mins, maxs, contents = import_shared.CONTENTS_SOL
494
496
  sides: planes.map((plane) => ({ plane, surfaceFlags: 0 }))
495
497
  };
496
498
  }
499
+ function createTestBspMap(options = {}) {
500
+ const vertices = [];
501
+ const edges = [];
502
+ const surfEdges = [];
503
+ const faces = [];
504
+ const texInfos = [];
505
+ const lightMapInfo = [];
506
+ let lightMapDataSize = 0;
507
+ if (options.surfaces) {
508
+ for (const surface of options.surfaces) {
509
+ if (surface.lightmap) {
510
+ lightMapDataSize += surface.lightmap.length;
511
+ }
512
+ }
513
+ }
514
+ const lightMaps = new Uint8Array(lightMapDataSize);
515
+ let currentLightMapOffset = 0;
516
+ if (options.surfaces) {
517
+ for (const surface of options.surfaces) {
518
+ const firstEdge = surfEdges.length;
519
+ const startVertexIndex = vertices.length;
520
+ for (const v of surface.vertices) {
521
+ vertices.push(v);
522
+ }
523
+ for (let i = 0; i < surface.vertices.length; i++) {
524
+ const v1 = startVertexIndex + i;
525
+ const v2 = startVertexIndex + (i + 1) % surface.vertices.length;
526
+ edges.push({ vertices: [v1, v2] });
527
+ surfEdges.push(edges.length - 1);
528
+ }
529
+ const defaultTexInfo = {
530
+ s: [1, 0, 0],
531
+ sOffset: 0,
532
+ t: [0, 1, 0],
533
+ tOffset: 0,
534
+ flags: 0,
535
+ value: 0,
536
+ texture: "test_texture",
537
+ nextTexInfo: -1
538
+ };
539
+ const texInfo = { ...defaultTexInfo, ...surface.texInfo };
540
+ texInfos.push(texInfo);
541
+ let lightOffset = -1;
542
+ let info = void 0;
543
+ if (surface.lightmap) {
544
+ lightOffset = currentLightMapOffset;
545
+ lightMaps.set(surface.lightmap, lightOffset);
546
+ info = { offset: lightOffset, length: surface.lightmap.length };
547
+ currentLightMapOffset += surface.lightmap.length;
548
+ }
549
+ lightMapInfo.push(info);
550
+ faces.push({
551
+ planeIndex: 0,
552
+ // Dummy plane
553
+ side: 0,
554
+ firstEdge,
555
+ numEdges: surface.vertices.length,
556
+ texInfo: texInfos.length - 1,
557
+ styles: surface.styles ?? [255, 255, 255, 255],
558
+ // Default styles
559
+ lightOffset
560
+ });
561
+ }
562
+ }
563
+ const header = { version: 38, lumps: /* @__PURE__ */ new Map() };
564
+ const entities = {
565
+ raw: "",
566
+ entities: options.entities || [],
567
+ worldspawn: void 0,
568
+ getUniqueClassnames: () => []
569
+ };
570
+ const planes = [{ normal: [0, 0, 1], dist: 0, type: 0 }];
571
+ const nodes = [];
572
+ const leafs = [{
573
+ contents: 0,
574
+ cluster: 0,
575
+ area: 0,
576
+ mins: [-1e3, -1e3, -1e3],
577
+ maxs: [1e3, 1e3, 1e3],
578
+ firstLeafFace: 0,
579
+ numLeafFaces: faces.length,
580
+ firstLeafBrush: 0,
581
+ numLeafBrushes: 0
582
+ }];
583
+ const leafLists = {
584
+ leafFaces: [faces.map((_, i) => i)],
585
+ leafBrushes: [[]]
586
+ };
587
+ const models = [{
588
+ mins: [-1e3, -1e3, -1e3],
589
+ maxs: [1e3, 1e3, 1e3],
590
+ origin: [0, 0, 0],
591
+ headNode: 0,
592
+ firstFace: 0,
593
+ numFaces: faces.length
594
+ }];
595
+ const data = {
596
+ header,
597
+ entities,
598
+ planes,
599
+ vertices,
600
+ nodes,
601
+ texInfo: texInfos,
602
+ faces,
603
+ lightMaps,
604
+ lightMapInfo,
605
+ leafs,
606
+ leafLists,
607
+ edges,
608
+ surfEdges: Int32Array.from(surfEdges),
609
+ models,
610
+ brushes: [],
611
+ brushSides: [],
612
+ visibility: void 0,
613
+ areas: [],
614
+ areaPortals: []
615
+ };
616
+ return {
617
+ ...data,
618
+ pickEntity: () => null,
619
+ findLeaf: () => leafs[0],
620
+ calculatePVS: () => void 0
621
+ };
622
+ }
623
+ function createTestLightmap(width, height, r, g, b) {
624
+ const size = width * height * 3;
625
+ const data = new Uint8Array(size);
626
+ for (let i = 0; i < size; i += 3) {
627
+ data[i] = r;
628
+ data[i + 1] = g;
629
+ data[i + 2] = b;
630
+ }
631
+ return data;
632
+ }
497
633
 
498
634
  // src/shared/pak-loader.ts
499
635
  var fs = __toESM(require("fs"), 1);
@@ -3600,6 +3736,7 @@ function createMockRenderer(overrides) {
3600
3736
  setLodBias: import_vitest12.vi.fn(),
3601
3737
  setAreaPortalState: import_vitest12.vi.fn(),
3602
3738
  renderInstanced: import_vitest12.vi.fn(),
3739
+ uploadBspGeometry: import_vitest12.vi.fn().mockReturnValue({ surfaces: [], lightmaps: [] }),
3603
3740
  dispose: import_vitest12.vi.fn(),
3604
3741
  ...overrides
3605
3742
  };
@@ -5847,7 +5984,9 @@ function createVisualTestScenario(sceneName) {
5847
5984
  createSpawnTestContext,
5848
5985
  createStorageTestScenario,
5849
5986
  createSurfaceMock,
5987
+ createTestBspMap,
5850
5988
  createTestContext,
5989
+ createTestLightmap,
5851
5990
  createTraceMock,
5852
5991
  createTransform,
5853
5992
  createTriggerEntityFactory,