thacuber2a03 / BlockDate

A random tetrimino game made for the Playdate console.
124 stars 11 forks source link

Optimize draw calls for better performance and precompute grid #13

Closed symphonite closed 2 years ago

symphonite commented 2 years ago

Updated the draw function to only update when the screen has actually changed. This does require assigning refreshNeeded when the board state has changed or screenClearNeeded when you need to both refresh and clear the entire screen. I have updated every case that needs it.

In general I am trying to avoid full screen clears when possible and now it only happens when the intro timers are running, a new piece is placed, or an effect is playing. I think with more optimizations it can probably be minimized even further for effects, but that'll require a bit more work.

I'm also precomputing the grid display on initialization into its own images (one for big blocks and one for regular) instead of recalculating them on every draw call. This greatly reduces the cost to draw the grid.

This was all tested on an actual Playdate device and the performance difference between this and 1.5.1 is definitely noticable.

thacuber2a03 commented 2 years ago

Let's gooooo!!!!!