stable
This commit is contained in:
parent
fbdac9ebf1
commit
86226ccc94
97 changed files with 5790 additions and 2307 deletions
|
|
@ -1,30 +1,22 @@
|
|||
"use strict";
|
||||
|
||||
(function (global) {
|
||||
const REALTIME_ITEM_TYPES = new Set(["ball", "genkotsu", "firecracker", "fan", "magnet"]);
|
||||
const PIN_ITEM_TYPES = new Set(["pushpin", "oshibyo"]);
|
||||
const SCHEDULED_ITEM_TYPES = [
|
||||
"ball", "genkotsu", "firecracker", "pushpin", "oshibyo",
|
||||
"plushie", "grass_bed", "zunchi", "duplicator", "water", "trace", "splat", "ant_corpse", "food",
|
||||
"sweet", "love_mochi", "fight_mochi", "sleep_drug", "laxative", "protein", "niteropu", "ammo", "mystery_drug", "mercury", "giant_drug", "dwarf_drug", "zunda_juice",
|
||||
"stone", "bed", "nest_box", "ant_nest", "signboard", "fence_v", "fence_h", "bounce_fence", "bounce_fence_v", "gate_fence", "fan", "magnet",
|
||||
];
|
||||
const policy = () => global.TarinaiItemUpdatePolicy || {};
|
||||
|
||||
function itemUpdateInterval(item) {
|
||||
if (!item || item.dead) return Infinity;
|
||||
if (REALTIME_ITEM_TYPES.has(item.type)) return 0;
|
||||
if (PIN_ITEM_TYPES.has(item.type)) return 0;
|
||||
if (item.isStructure && item.type === "plushie") return 0;
|
||||
if (item.isStructure && item.type === "grass_bed") return 3.0;
|
||||
if ((item.dropTimer || 0) > 0 || Math.hypot(item.vx || 0, item.vy || 0) > 0.08) return 0;
|
||||
if (item.type === "zunchi") return 2.4;
|
||||
if (item.type === "grass") return Infinity;
|
||||
if (item.type === "duplicator") return 0.5;
|
||||
if (item.type === "water") return 1.8;
|
||||
if (item.type === "trace" || item.type === "splat") return 1.2;
|
||||
if (item.type === "ant_corpse") return 3.5;
|
||||
if (typeof isServingFoodType === "function" && isServingFoodType(item.type)) return 5.0;
|
||||
return Infinity;
|
||||
const interval = policy().itemUpdateInterval?.(item);
|
||||
return Number.isFinite(interval) ? interval : Infinity;
|
||||
}
|
||||
|
||||
function candidateItems(worldRef) {
|
||||
if (policy().candidateItems) return policy().candidateItems(worldRef);
|
||||
return (worldRef?.items || []).filter(it => it && !it.dead && it.type !== "grass");
|
||||
}
|
||||
|
||||
function ensureBuckets(worldRef) {
|
||||
if (policy().ensureBuckets) return policy().ensureBuckets(worldRef);
|
||||
if (worldRef?.ensureItemBuckets) worldRef.ensureItemBuckets("item-update-scheduler");
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function heapPush(heap, entry) {
|
||||
|
|
@ -66,19 +58,6 @@
|
|||
].join(":");
|
||||
}
|
||||
|
||||
function ensureBuckets(worldRef) {
|
||||
if (worldRef?.ensureItemBuckets) worldRef.ensureItemBuckets("item-update-scheduler");
|
||||
}
|
||||
|
||||
function candidateItems(worldRef) {
|
||||
if (!worldRef?.itemsOfType) return (worldRef.items || []).filter(it => it && !it.dead && it.type !== "grass");
|
||||
const out = [];
|
||||
for (const type of SCHEDULED_ITEM_TYPES) {
|
||||
const bucket = worldRef.itemsOfType(type) || [];
|
||||
for (const it of bucket) if (it && !it.dead) out.push(it);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function scheduleItem(state, item, now, interval = itemUpdateInterval(item)) {
|
||||
if (!item || item.dead || !Number.isFinite(interval)) return false;
|
||||
|
|
@ -132,7 +111,8 @@
|
|||
continue;
|
||||
}
|
||||
if (interval <= 0) {
|
||||
item.update(dt, worldRef);
|
||||
if (global.TarinaiItemRuntime?.updateOne) global.TarinaiItemRuntime.updateOne(item, dt, worldRef);
|
||||
else item.update(dt, worldRef);
|
||||
item._schedulerLastAt = now;
|
||||
ran += 1;
|
||||
if (Number.isFinite(itemUpdateInterval(item)) && itemUpdateInterval(item) <= 0) nextRealtime.push(item);
|
||||
|
|
@ -163,7 +143,8 @@
|
|||
continue;
|
||||
}
|
||||
const elapsed = Math.min(10, Math.max(0.001, now - (item._schedulerLastAt ?? entry.time - interval)));
|
||||
item.update(elapsed, worldRef);
|
||||
if (global.TarinaiItemRuntime?.updateOne) global.TarinaiItemRuntime.updateOne(item, elapsed, worldRef);
|
||||
else item.update(elapsed, worldRef);
|
||||
item._schedulerLastAt = now;
|
||||
ran += 1;
|
||||
dueRuns += 1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue