Reputation: 63
It's not clear if it's ok to update values outside of the animate()
loop.
Would updates outside the loop affect render performance?
The only disadvantage I can see is some updates may be partially complete, having to wait for the next animate call to fully appear.
Any disadvantage I am missing?
function animate() {
requestAnimationFrame( animate )
updatePositions()
}
vs.
function animate() {
requestAnimationFrame( animate )
}
function onWebSocketUpdate() {
updatePositions()
}
Another way of looking at it:
onWebSocketUpdate(data) {
// Option 1
// ws directly applies the update
model.update(data)
// Option 2
// ws saves data to buffer
buffer.push(data)
// when animate() runs, it pops buffer data
model.update(buffer.pop())
}
Upvotes: 1
Views: 353
Reputation: 81
If your web socket sends updates to change an object position (which is the case I guess) you have two cases:
updatePositions()
inside the animate()
. You don't need more than one position update in between frames.animate()
. You'll save some performance by not calling updatePositions()
on every frameUpvotes: 1