OLEGSHA / Progressia

A GPL sandbox survival game
GNU General Public License v3.0
10 stars 4 forks source link

Optimize chunk sets requested by players #20

Open OLEGSHA opened 2 years ago

OLEGSHA commented 2 years ago

Currently, chunks are loaded in an ellipsoid around the player. This is wasteful: many of the requested chunks are empty or invisible. Instead, the player should not request these chunks.

The relevant code is in ru.windcorp.progressia.server.Player.requestChunksToLoad(Consumer<Vec3i>).

The solution entails three parts:

Although this is up for debate, a reasonable algorithm for step 3 may be

request 3x3x3 cube around player;
iterate chunks around player with flood-fill algorithm:
    start at player location;
    do not pass through opaque chunk walls;
    do not go further than load-distance away from start;
    if a chunk is not empty, request it.