Skip to content

Commit

Permalink
optimized onTick with cached typeIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
pfcDorn committed Dec 11, 2024
1 parent 72c0bc2 commit c12b3d5
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/BasicBehaveEngine/nodes/lifecycle/onTick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c12b3d5

Please sign in to comment.