afonsolage / projekto

Voxel game made with Bevy Engine
MIT License
59 stars 4 forks source link

Terraformation and rendering separation #22

Closed afonsolage closed 2 years ago

afonsolage commented 2 years ago

Closes #19 Closes #8

This PR separates the terraformation and rendering in such a way that there is a radius for terraformation and a (likely) smaller radius for rendering, so whenever we have to render, the data is already ready on memory.

afonsolage commented 2 years ago

Right now rendering uses WorldRes which is unavailable when there is some terraformation tasks. We should save "mesh ready" data somewhere else so rendering can use it when it's ready, without the need to wait for

afonsolage commented 2 years ago

Before saving all mesh related data on disk, I had to pick another change from stale PR #9, since it would be better to save all chunk information in a single struct, because the heavy tasks is iterating over voxels, which is already in a cache-friendly struct ChunkStorage, so there is no need (IMO) to also save all chunk data (kinds, vertices, light and so on) in it's own data structure (Vector, HashMap, etc) to have better cache-friendless.

Now it's time to de facto move everything which isn't rendering from, well, rendering and move to terraformation.

afonsolage commented 2 years ago

Moved all procedural mesh generation and related functions to terraformation. The next step is to rework the event system that existed before, since now the rendering will load and unload meshes regardless of terraformation.

Also the chunk save method should be moved to happens after all vertices computations. Currently it's doing nothing!

afonsolage commented 2 years ago

It's way better now, since the chunk heavy work is done in another task, so it doesn't block rendering. To the main/rendering task, it just have to create a mesh from vertices, which is very cheap.

There are two regression tho: 1- Some chunks aren't loaded or rendered (dunno which) when walking over the initial landscape area; 2- The FPS has dropped drastically. Needs to investigate why.

afonsolage commented 2 years ago

I don't have sure if the problem 1 is related to this, but since neighborhood isn't saved on disk, because ChunkStorageskips it, I should either save it on disk or recompute whenever it's loaded from disk.

I'll try to do the former, since the later can introduce some bugs and could potentially add needless computation.

afonsolage commented 2 years ago

In the end the regression 1 was just a problem with bevy built-in systems being cleared at the end of frame, while VoxWorld was busy.

Now it's time to check regression 2 (if it is really a regression)

afonsolage commented 2 years ago

This branch avg FPS: 35 Main avg FPS: 30

Even tho the FPS is really low, this PR doesn't introduce a FPS regression, so let's ignore 2.

Now both regression has been dealt, lest continue. Just some cleanup and code organization and it's done.

afonsolage commented 2 years ago

Everything seems fine (famous last words)