stable
This commit is contained in:
parent
fbdac9ebf1
commit
86226ccc94
97 changed files with 5790 additions and 2307 deletions
55
js/tarinai_update_pipeline.js
Normal file
55
js/tarinai_update_pipeline.js
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
"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);
|
||||
Loading…
Add table
Add a link
Reference in a new issue