Closed aquilax closed 8 years ago
Thanks for looking into this. Code looks good but I have some concerns about comparing the two canvasses on every draw - I think you're right in that using a dirty bit will be much more efficient! I'll have a look into it.
As discussed on Gitter, a dirty bit isn't going to work easily, because the Draws happen independently of each other so there's no way to know if, when rendering a cell, that's the last time it will be rendered to. Because we always render cells on top of cells, even if they're empty or background, there's no way to know if the dirty bit should be set - in effect, it always is.
With this in mind, I'm going to go ahead and merge this for now. I think it's unlikely we'll have a situation where the screen is different on every Draw (as that would involve some insanely fast-moving objects), so the extra pass over the canvas is unlikely to degrade performance overall. Thanks @aquilax!
Tagging issue #18
Since drawing to the canvas looks to be the bottleneck, this change keeps the last canvas to the
Screen
structure and checks if the canvas has changed between the draws.This is rather crude approach but the performance could be is significant, depending on the usage:
from:
to:
NOTE: The running times are different so, better look at the percentages.
A better approach could be setting a
dirty
flag when something changes. That would eliminate the need of looping through the canvas.