This is a small prototype that I made to see how far I could push myself in optimization. So most of this project is just learning myself to render loads of stuff at once in a good way. That also makes it easy to edit the enviroment in this case.
Chunk Rendering
At the start of the game it generates the whole enviroment and puts them into corresponding chunks. Which then makes it possible to draw one chunk at a time instead of a block at a time. I do this by getting all vertices and then draw quads between these vertices. This is way faster than calling draw calls on each block.
Chunk Destruction
Each frame I check if every chunk in a given radius has been updated with a tile update and if it has I reconstuct the chunk to match the new shape. This in turn gives the renderer a new chunk. This solves the issue of getting all vertices every frame, if you instead cache vertices from all chunks at the start of the game and only update these vertices in the renderer when a chunk is updated a whole lot of data shuffling can be saved.
Version 1 & 2
The gif with blue terrain is the first iteration of this prototype and the gif with green terrain is the second iteration. The first one has the issue of the terrain being limited to a fixed size but the second has infinite terrain that loads and unloads depending on where the player is. This gives alot more overhead in performance since I don't have to handle all the chunks that are far away and out of render distance. Version 2 also has way better rendering of the chunks and coupled with that a better way to destroy blocks. In the first version I get all the verticies of all chunks every frame and render them. This is not good since there is way to much data that has to be moved around and copied. I stopped doing this by having a reference to the chunks in the renderer so the renderer just rendered it directly instead of fetching all the verticies every frame.
Block size is also way smaller in version 2 which means I can have more stuff on screen now than in version 1 this is because of the improvements stated in the last paragraph.