29 lines
1.3 KiB
JavaScript
29 lines
1.3 KiB
JavaScript
"use strict";
|
|
|
|
// Layer: entity-runtime/tarinai/policy
|
|
// Owns Tarinai update cadence decisions. The simulation creature system asks
|
|
// this policy when an individual should run at realtime vs low-frequency cadence.
|
|
(function (global) {
|
|
const helpers = () => global.TarinaiSimulationRuntime?.helpers || {};
|
|
|
|
function updateInterval(worldRef, tarinai, visibleRect) {
|
|
if (!tarinai || tarinai.dead) return Infinity;
|
|
if (worldRef.selected === tarinai) return 0;
|
|
if ((tarinai.hurtTimer || 0) > 0.04 || (tarinai.pokeFlashTimer || 0) > 0.03 || (tarinai.entryTimer || 0) > 0.01) return 0;
|
|
if (helpers().pointInRect?.(tarinai.x || 0, tarinai.y || 0, visibleRect)) return 0;
|
|
const count = (worldRef.tarinai || []).length;
|
|
const tier = global.TarinaiPerf?.renderQualityTier?.() || "high";
|
|
if (tier === "high" && count <= 36) return 0;
|
|
const farRect = helpers().updateVisibleWorldRect?.(worldRef, 520) || visibleRect;
|
|
return helpers().pointInRect?.(tarinai.x || 0, tarinai.y || 0, farRect) ? 0.22 : 0.70;
|
|
}
|
|
|
|
function shouldRunRealtime(worldRef, tarinai, visibleRect) {
|
|
return updateInterval(worldRef, tarinai, visibleRect) <= 0;
|
|
}
|
|
|
|
global.TarinaiCreatureUpdatePolicy = Object.freeze({
|
|
updateInterval,
|
|
shouldRunRealtime,
|
|
});
|
|
})(typeof window !== "undefined" ? window : globalThis);
|