WoochanLee / BalanceTetris

Tetris built with vanilla javascript
9 stars 10 forks source link

Introduce 'renderer.js' with minor optimization #15

Closed DevSDK closed 3 years ago

DevSDK commented 3 years ago

Without separate the renderer, the codes, and logics are growing complexity.

Therefore, Introduce 'renderer.js' which has been separated from the screen. This is more clear and extendable even possible to get performance in further.

The 'renderWithMerge(first, second)' worked as follow:

  1. Receive the arrays
  2. Merge the arrays to represent the current render array
  3. Check the difference from the previously rendered array
  4. Clear and render marked as different blocks
  5. Store current array into the previously rendered array

Statistically, The render function uses 0.5ms like [1].

[1] https://user-images.githubusercontent.com/18409763/111963150-88875f00-8b36-11eb-9258-68b0a2367245.png

WoochanLee commented 3 years ago

There are drawBlocks() function and reDraw() function.

But the reDraw() function is only call drawBlocks()

How about remove reDraw() function, and change all calls to drawBlocks()?

DevSDK commented 3 years ago

How about remove reDraw() function, and change all calls to drawBlocks()?

Done.