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/browser/index.d.mts +3 -5
- package/dist/browser/index.d.ts +3 -5
- package/dist/browser/index.js +39 -26
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.mjs +39 -26
- package/dist/browser/index.mjs.map +1 -1
- package/dist/bundle.js +41 -28
- package/dist/bundle.js.map +1 -1
- package/dist/node/index.d.mts +3 -5
- package/dist/node/index.d.ts +3 -5
- package/dist/node/index.js +39 -26
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +39 -26
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/browser/index.d.mts
CHANGED
|
@@ -584,13 +584,11 @@ declare class BatchedExecutor {
|
|
|
584
584
|
readonly interval: number;
|
|
585
585
|
readonly batch: number;
|
|
586
586
|
private readonly queue;
|
|
587
|
-
private readonly task;
|
|
588
587
|
constructor(interval?: number, batch?: number);
|
|
589
|
-
submit(task: Task):
|
|
590
|
-
|
|
591
|
-
private runNext;
|
|
588
|
+
submit<T>(task: Task<T>): Promise<T>;
|
|
589
|
+
stop(): void;
|
|
592
590
|
}
|
|
593
|
-
type Task = () =>
|
|
591
|
+
type Task<T = unknown> = () => T | Promise<T>;
|
|
594
592
|
|
|
595
593
|
declare function prefix(prefix?: string): string;
|
|
596
594
|
|
package/dist/browser/index.d.ts
CHANGED
|
@@ -584,13 +584,11 @@ declare class BatchedExecutor {
|
|
|
584
584
|
readonly interval: number;
|
|
585
585
|
readonly batch: number;
|
|
586
586
|
private readonly queue;
|
|
587
|
-
private readonly task;
|
|
588
587
|
constructor(interval?: number, batch?: number);
|
|
589
|
-
submit(task: Task):
|
|
590
|
-
|
|
591
|
-
private runNext;
|
|
588
|
+
submit<T>(task: Task<T>): Promise<T>;
|
|
589
|
+
stop(): void;
|
|
592
590
|
}
|
|
593
|
-
type Task = () =>
|
|
591
|
+
type Task<T = unknown> = () => T | Promise<T>;
|
|
594
592
|
|
|
595
593
|
declare function prefix(prefix?: string): string;
|
|
596
594
|
|
package/dist/browser/index.js
CHANGED
|
@@ -1655,24 +1655,20 @@ var AssetLoadError = class extends Error {
|
|
|
1655
1655
|
};
|
|
1656
1656
|
|
|
1657
1657
|
// src/util/BatchedExecutor.ts
|
|
1658
|
+
var import_jobqu2 = require("jobqu");
|
|
1658
1659
|
var BatchedExecutor = class {
|
|
1659
1660
|
constructor(interval = 1, batch = 30) {
|
|
1661
|
+
if (!Number.isFinite(interval) || interval < 0) throw new RangeError("Batch interval must be finite and nonnegative");
|
|
1662
|
+
if (!Number.isInteger(batch) || batch < 1) throw new RangeError("Batch size must be a positive integer");
|
|
1660
1663
|
this.interval = interval;
|
|
1661
1664
|
this.batch = batch;
|
|
1662
|
-
this.queue =
|
|
1663
|
-
this.task = setInterval(() => this.run());
|
|
1665
|
+
this.queue = new import_jobqu2.JobQueue(async (task) => task(), { interval, maxPerRun: batch, maxActive: batch });
|
|
1664
1666
|
}
|
|
1665
1667
|
submit(task) {
|
|
1666
|
-
this.queue.
|
|
1668
|
+
return this.queue.add(() => task());
|
|
1667
1669
|
}
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
this.runNext();
|
|
1671
|
-
}
|
|
1672
|
-
}
|
|
1673
|
-
runNext() {
|
|
1674
|
-
let next = this.queue.shift();
|
|
1675
|
-
if (next) next();
|
|
1670
|
+
stop() {
|
|
1671
|
+
this.queue.end();
|
|
1676
1672
|
}
|
|
1677
1673
|
};
|
|
1678
1674
|
|
|
@@ -7364,22 +7360,39 @@ var MineRenderWorld = class {
|
|
|
7364
7360
|
const chunk = Chunk.isAir(value) ? this.getChunkAt(posOrX) : this.getOrCreateChunkAt(posOrX);
|
|
7365
7361
|
return chunk?.setBlockAt(posOrX, value);
|
|
7366
7362
|
}
|
|
7367
|
-
async placeMultiBlock(multiblock, useBatches = true, executor
|
|
7368
|
-
const keys =
|
|
7369
|
-
|
|
7370
|
-
|
|
7371
|
-
|
|
7372
|
-
|
|
7373
|
-
|
|
7374
|
-
|
|
7375
|
-
|
|
7376
|
-
|
|
7377
|
-
|
|
7378
|
-
|
|
7363
|
+
async placeMultiBlock(multiblock, useBatches = true, executor) {
|
|
7364
|
+
const keys = /* @__PURE__ */ new Map();
|
|
7365
|
+
for (const block of multiblock.blocks) {
|
|
7366
|
+
if (Chunk.isAir(block)) continue;
|
|
7367
|
+
const key = AssetKey.parse("blockstates", block.type);
|
|
7368
|
+
keys.set(key.serialize(), key);
|
|
7369
|
+
}
|
|
7370
|
+
await BlockStates.getAll(keys.values());
|
|
7371
|
+
if (!useBatches) {
|
|
7372
|
+
for (const block of multiblock.blocks) await this.setBlockAt(block.position, block);
|
|
7373
|
+
return;
|
|
7374
|
+
}
|
|
7375
|
+
const positions = /* @__PURE__ */ new Map();
|
|
7376
|
+
for (const block of multiblock.blocks) {
|
|
7377
|
+
const key = block.position.join(",");
|
|
7378
|
+
const group = positions.get(key);
|
|
7379
|
+
if (group) group.push(block);
|
|
7380
|
+
else positions.set(key, [block]);
|
|
7381
|
+
}
|
|
7382
|
+
const groups = [...positions.values()];
|
|
7383
|
+
const queue = executor ?? new BatchedExecutor();
|
|
7384
|
+
try {
|
|
7385
|
+
for (let i = 0; i < groups.length; i += queue.batch) {
|
|
7386
|
+
const results = await Promise.allSettled(groups.slice(i, i + queue.batch).map(
|
|
7387
|
+
(blocks) => queue.submit(async () => {
|
|
7388
|
+
for (const block of blocks) await this.setBlockAt(block.position, block);
|
|
7389
|
+
})
|
|
7390
|
+
));
|
|
7391
|
+
const failure = results.find((result) => result.status === "rejected");
|
|
7392
|
+
if (failure?.status === "rejected") throw failure.reason;
|
|
7379
7393
|
}
|
|
7380
|
-
}
|
|
7381
|
-
|
|
7382
|
-
await place(block);
|
|
7394
|
+
} finally {
|
|
7395
|
+
if (!executor) queue.stop();
|
|
7383
7396
|
}
|
|
7384
7397
|
}
|
|
7385
7398
|
async clear() {
|