From c12b3d51f761b000717f2a54fb02661f15b63f21 Mon Sep 17 00:00:00 2001 From: Robert Dorn Date: Wed, 11 Dec 2024 11:01:39 +0100 Subject: [PATCH] optimized onTick with cached typeIndex --- src/BasicBehaveEngine/nodes/lifecycle/onTick.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/BasicBehaveEngine/nodes/lifecycle/onTick.ts b/src/BasicBehaveEngine/nodes/lifecycle/onTick.ts index b65bb3c..687c0f2 100644 --- a/src/BasicBehaveEngine/nodes/lifecycle/onTick.ts +++ b/src/BasicBehaveEngine/nodes/lifecycle/onTick.ts @@ -4,24 +4,25 @@ export class OnTickNode extends BehaveEngineNode { _startTime = NaN; _lastTickTime = NaN; + _floatTypeIndex = -1; constructor(props: IBehaviourNodeProps) { super(props); this.name = "OnTick"; - - this.outValues.timeSinceStart = {id: "timeSinceStart", value: [NaN], type: this.getTypeIndex('float')}; - this.outValues.timeSinceLastTick = {id: "timeSinceLastTick", value: [NaN], type: this.getTypeIndex('float')}; + this._floatTypeIndex = this.getTypeIndex('float'); + this.outValues.timeSinceStart = { id: "timeSinceStart", value: [NaN], type: this._floatTypeIndex }; + this.outValues.timeSinceLastTick = { id: "timeSinceLastTick", value: [NaN], type: this._floatTypeIndex }; } override processNode(flowSocket?: string) { this.graphEngine.processNodeStarted(this); const tickTime = Date.now(); if (isNaN(this._startTime)) { - this.outValues.timeSinceStart = {id: "timeSinceStart", value: [0], type: this.getTypeIndex('float')}; - this.outValues.timeSinceLastTick = {id: "timeSinceLastTick", value: [0], type: this.getTypeIndex('float')}; + this.outValues.timeSinceStart = { id: "timeSinceStart", value: [0], type: this._floatTypeIndex }; + this.outValues.timeSinceLastTick = { id: "timeSinceLastTick", value: [0], type: this._floatTypeIndex }; this._startTime = tickTime; } else { - this.outValues.timeSinceStart = {id: "timeSinceStart", value: [tickTime - this._startTime], type: this.getTypeIndex('float')}; - this.outValues.timeSinceLastTick = {id: "timeSinceLastTick", value: [tickTime - this._lastTickTime], type: this.getTypeIndex('float')}; + this.outValues.timeSinceStart = { id: "timeSinceStart", value: [tickTime - this._startTime], type: this._floatTypeIndex }; + this.outValues.timeSinceLastTick = { id: "timeSinceLastTick", value: [tickTime - this._lastTickTime], type: this._floatTypeIndex }; } this._lastTickTime = tickTime; return super.processNode(flowSocket);