minerender 2.1.0-alpha.35 → 2.1.0-alpha.36

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/bundle.js CHANGED
@@ -11384,7 +11384,7 @@ var MineRender = (() => {
11384
11384
  Object.defineProperty(exports13, "__esModule", { value: true });
11385
11385
  exports13.JobQueue = void 0;
11386
11386
  var Base_1 = require_Base();
11387
- var JobQueue2 = class extends Base_1.RunnerBase {
11387
+ var JobQueue3 = class extends Base_1.RunnerBase {
11388
11388
  /**
11389
11389
  * Create a new queue
11390
11390
  * @param runner function(key):Promise to execute the job
@@ -11418,7 +11418,7 @@ var MineRender = (() => {
11418
11418
  }
11419
11419
  }
11420
11420
  };
11421
- exports13.JobQueue = JobQueue2;
11421
+ exports13.JobQueue = JobQueue3;
11422
11422
  }
11423
11423
  });
11424
11424
 
@@ -70311,24 +70311,20 @@ return ${compiler2.callType("value", tagType)}
70311
70311
  init_dirname();
70312
70312
  init_buffer2();
70313
70313
  init_process2();
70314
+ var import_jobqu2 = __toESM(require_src());
70314
70315
  var BatchedExecutor = class {
70315
70316
  constructor(interval = 1, batch = 30) {
70317
+ if (!Number.isFinite(interval) || interval < 0) throw new RangeError("Batch interval must be finite and nonnegative");
70318
+ if (!Number.isInteger(batch) || batch < 1) throw new RangeError("Batch size must be a positive integer");
70316
70319
  this.interval = interval;
70317
70320
  this.batch = batch;
70318
- this.queue = [];
70319
- this.task = setInterval(() => this.run());
70321
+ this.queue = new import_jobqu2.JobQueue(async (task) => task(), { interval, maxPerRun: batch, maxActive: batch });
70320
70322
  }
70321
70323
  submit(task) {
70322
- this.queue.push(task);
70324
+ return this.queue.add(() => task());
70323
70325
  }
70324
- run() {
70325
- for (let i4 = 0; i4 < this.batch; i4++) {
70326
- this.runNext();
70327
- }
70328
- }
70329
- runNext() {
70330
- let next = this.queue.shift();
70331
- if (next) next();
70326
+ stop() {
70327
+ this.queue.end();
70332
70328
  }
70333
70329
  };
70334
70330
 
@@ -87578,22 +87574,39 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
87578
87574
  const chunk = Chunk.isAir(value) ? this.getChunkAt(posOrX) : this.getOrCreateChunkAt(posOrX);
87579
87575
  return chunk?.setBlockAt(posOrX, value);
87580
87576
  }
87581
- async placeMultiBlock(multiblock, useBatches = true, executor = new BatchedExecutor()) {
87582
- const keys = new Set(multiblock.blocks.map((block) => AssetKey.parse("blockstates", block.type)));
87583
- await BlockStates.getAll(keys);
87584
- const place = async (block) => {
87585
- if (useBatches && typeof executor !== "undefined") {
87586
- await new Promise((resolve, reject) => {
87587
- executor.submit(() => {
87588
- this.setBlockAt(block.position, block).then(resolve).catch(reject);
87589
- });
87590
- });
87591
- } else {
87592
- await this.setBlockAt(block.position, block);
87577
+ async placeMultiBlock(multiblock, useBatches = true, executor) {
87578
+ const keys = /* @__PURE__ */ new Map();
87579
+ for (const block of multiblock.blocks) {
87580
+ if (Chunk.isAir(block)) continue;
87581
+ const key = AssetKey.parse("blockstates", block.type);
87582
+ keys.set(key.serialize(), key);
87583
+ }
87584
+ await BlockStates.getAll(keys.values());
87585
+ if (!useBatches) {
87586
+ for (const block of multiblock.blocks) await this.setBlockAt(block.position, block);
87587
+ return;
87588
+ }
87589
+ const positions = /* @__PURE__ */ new Map();
87590
+ for (const block of multiblock.blocks) {
87591
+ const key = block.position.join(",");
87592
+ const group = positions.get(key);
87593
+ if (group) group.push(block);
87594
+ else positions.set(key, [block]);
87595
+ }
87596
+ const groups = [...positions.values()];
87597
+ const queue2 = executor ?? new BatchedExecutor();
87598
+ try {
87599
+ for (let i4 = 0; i4 < groups.length; i4 += queue2.batch) {
87600
+ const results = await Promise.allSettled(groups.slice(i4, i4 + queue2.batch).map(
87601
+ (blocks) => queue2.submit(async () => {
87602
+ for (const block of blocks) await this.setBlockAt(block.position, block);
87603
+ })
87604
+ ));
87605
+ const failure = results.find((result) => result.status === "rejected");
87606
+ if (failure?.status === "rejected") throw failure.reason;
87593
87607
  }
87594
- };
87595
- for (let block of multiblock.blocks) {
87596
- await place(block);
87608
+ } finally {
87609
+ if (!executor) queue2.stop();
87597
87610
  }
87598
87611
  }
87599
87612
  async clear() {