tarinai/js/tarinai_update_pipeline.js

38 lines
1.2 KiB
JavaScript
Raw Normal View History

2026-06-26 12:46:32 +09:00
"use strict";
// Layer: entity-runtime/tarinai/pipeline
2026-06-26 19:04:32 +09:00
// Owns the ordered Tarinai update pipeline. There is no monolithic fallback path:
// creature behavior must be handled by the explicit update steps below.
2026-06-26 12:46:32 +09:00
(function (global) {
const CONCRETE_STEP_NAMES = Object.freeze([
"TarinaiFrameUpdateStep",
"TarinaiAiUpdateStep",
"TarinaiEnvironmentUpdateStep",
"TarinaiMovementUpdateStep",
"TarinaiHealthUpdateStep",
]);
2026-06-29 16:21:58 +09:00
let cachedSteps = null;
2026-06-26 12:46:32 +09:00
function concreteSteps() {
2026-06-29 16:21:58 +09:00
if (!cachedSteps) cachedSteps = CONCRETE_STEP_NAMES.map(name => global[name]);
return cachedSteps;
2026-06-26 12:46:32 +09:00
}
2026-06-26 19:04:32 +09:00
function updateOne(tarinai, dt, options = {}) {
2026-06-29 16:21:58 +09:00
if (!tarinai || tarinai.dead) return false;
const steps = concreteSteps();
if (steps.length !== CONCRETE_STEP_NAMES.length) return false;
2026-06-26 19:04:32 +09:00
const context = {
...(options.context || {}),
wasSleepingAtFrameStart: false,
};
2026-06-29 16:21:58 +09:00
for (const step of steps) {
2026-06-26 12:46:32 +09:00
const result = step.update(tarinai, dt, context) || {};
if (result.done) return result.ok !== false;
}
return true;
}
2026-06-29 16:21:58 +09:00
global.TarinaiUpdatePipeline = Object.freeze({ updateOne });
2026-06-26 12:46:32 +09:00
})(typeof window !== "undefined" ? window : globalThis);