afonsolage / projekto

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

Move world genesis, terraforming and processing to separated thread/task_pool #8

Closed afonsolage closed 2 years ago

afonsolage commented 2 years ago

Currently the chunk generation, loading and neighborhood calculation is done on genesis stage of pipeline, but there are other heavy processing tasks, like stated on #7. So in order to solve this, it would be better to move all chunk generation, processing and everything until the final VertexFace and cache it.

Overview

The idea is to store the processed data in sectors. Each one will have 16^3 chunks (see #10 ) and will be stored in its own file. So there are three flows possible:

  1. Sector Exists
    1. Load;
    2. Send event;
  2. Sector Doesn't exists
    1. Generate kinds;
    2. Process Pipeline;
      1. Get Neighborhood;
      2. Faces Occlusion;
      3. Faces Merging;
      4. Vertex Computation;
      5. Save;
      6. Send event;
  3. Sector Updated (or one of its chunks)
    1. Update chunk;
    2. Process Pipeline (2.ii);

The general hierarchy will be world -> sector -> chunk -> voxel, where:

Only a single sector will be updated/processed at a single time, due to it's size.

landscape will query world to get the desired number of chunks as it wants in order to send to rendering pipeline. This will be determined by a draw distance.

The load/unload process of sectors should be triggered when player moves at half way of the current sector.

Drawbacks

  1. Memory usage can be pretty high, if each voxel uses 5 bytes (2 bytes for kind, 1 byte for light, 1 byte for faces occlusion and 1 byte for other data), it will consume 516^316^3*9^3 = 2.1 GB. This can be reduced by using compression, since many voxels will be empty or repeated.

  2. When adding propagation, which we currently doesn't have, the game may slowdown if the propagation happens between more than 1 sector, like light or fire spreading, the worst case scenario can be an edge between 8 sectors, which may take a while to process. This is a corner case and shouldn't be a big problem at all

  3. When a player move quickly and triggers the loading and unloading of sectors, moving back and forth, this may slowdown the game, due the high amount of sectors being loaded/unloaded.

  4. Needs to test the loading/unloading of sectors on slow HDDs and check how it behaves. Currently I'm using M2 SSD, which is very fast and should not be considered a normal use case.

afonsolage commented 2 years ago

This must address also #19

afonsolage commented 2 years ago

Some thoughts on this subject:

Use Bevy Sub App

Use Task Pool :heavy_check_mark:

afonsolage commented 2 years ago

Currently there is a single pipeline which covers from generating chunks, cache, computing vertices, occlusion, merging faces, [..] until the rendering.

We should split this work and have the following setup:

Terraformation

Rendering

Unresolved Questions