55 lines
1.8 KiB
JavaScript
55 lines
1.8 KiB
JavaScript
"use strict";
|
|
|
|
// Layer: entity-runtime/tarinai/pipeline
|
|
// Owns the ordered Tarinai update pipeline. Runtime calls this instead of
|
|
// depending on the monolithic prototype update body. The legacy step is retained
|
|
// as a compatibility fallback while concrete steps are split out incrementally.
|
|
(function (global) {
|
|
const CONCRETE_STEP_NAMES = Object.freeze([
|
|
"TarinaiFrameUpdateStep",
|
|
"TarinaiAiUpdateStep",
|
|
"TarinaiEnvironmentUpdateStep",
|
|
"TarinaiMovementUpdateStep",
|
|
"TarinaiHealthUpdateStep",
|
|
]);
|
|
|
|
function concreteSteps() {
|
|
return CONCRETE_STEP_NAMES.map(name => global[name]).filter(step => step && typeof step.update === "function");
|
|
}
|
|
|
|
function canRunConcretePipeline() {
|
|
return concreteSteps().length === CONCRETE_STEP_NAMES.length;
|
|
}
|
|
|
|
function runConcrete(tarinai, dt, context) {
|
|
for (const step of concreteSteps()) {
|
|
const result = step.update(tarinai, dt, context) || {};
|
|
if (result.done) return result.ok !== false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
function runLegacy(tarinai, dt, context) {
|
|
const step = global.TarinaiLegacyUpdateStep;
|
|
if (step && typeof step.update === "function") return step.update(tarinai, dt, context).ok !== false;
|
|
const legacyUpdate = context.legacyUpdate;
|
|
if (typeof legacyUpdate !== "function") return false;
|
|
legacyUpdate.call(tarinai, dt);
|
|
return true;
|
|
}
|
|
|
|
function updateOne(tarinai, dt, options = {}) {
|
|
if (!tarinai || tarinai.dead) return false;
|
|
const context = {
|
|
legacyUpdate: options.legacyUpdate,
|
|
wasSleepingAtFrameStart: false,
|
|
};
|
|
return canRunConcretePipeline() ? runConcrete(tarinai, dt, context) : runLegacy(tarinai, dt, context);
|
|
}
|
|
|
|
global.TarinaiUpdatePipeline = Object.freeze({
|
|
stepNames: CONCRETE_STEP_NAMES,
|
|
canRunConcretePipeline,
|
|
updateOne,
|
|
});
|
|
})(typeof window !== "undefined" ? window : globalThis);
|