Skip to content

Commit 18aeca6

Browse files
committed
fix(game-engine): improve performance of graphic entity module frame parsing
1 parent a9c6d7a commit 18aeca6

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

engine/modules/entities/src/main/resources/view/entity-module/GraphicEntityModule.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ export class GraphicEntityModule {
8484
this.extrapolationMap[entity.id] = { ...entity.defaultState }
8585
}
8686

87-
const currentState = this.extrapolationMap[entity.id]
8887
const subStates = entity.states[frameNumber]
8988

9089
// Sort on t to begin extrapolation
@@ -94,20 +93,23 @@ export class GraphicEntityModule {
9493
// Create a subState at t=1
9594
entity.addState(1, {}, frameNumber, frameInfo)
9695
}
97-
let prevState = currentState
96+
97+
let prevState = this.extrapolationMap[entity.id] // currentState
9898
// If the entity had a state in the previous frame get the last one of them
9999
if (entity.states[previousFrameNumber] && previousFrameNumber !== frameNumber) {
100100
prevState = entity.states[previousFrameNumber][entity.states[previousFrameNumber].length - 1]
101101
}
102-
for (const state of subStates) {
102+
103+
entity.states[frameNumber] = subStates.map((subState) => {
103104
// Extrapolate through existing substates, updating the extrapolationMap in the process (currentState)
104-
Object.assign(currentState, state)
105-
Object.assign(state, currentState)
105+
const state = this.extrapolationMap[entity.id] = { ...this.extrapolationMap[entity.id], ...subState}
106+
106107
if (typeof entity.computeAnimationProgressTime === 'function') {
107108
entity.computeAnimationProgressTime(prevState, state)
108109
}
109110
prevState = state
110-
}
111+
return state
112+
})
111113
})
112114
}
113115

0 commit comments

Comments
 (0)