Skip to content

Load spawn area chunks on start-up #107

Closed

Description

@aramperes

In order to speed up the initial player join, chunks surrounding the level's spawn coordinates should be loaded in memory at start-up. It would leverage chunkworker and likely be called in the level initialization.

Activity

  1. caelunshun commented on Sep 3, 2019

    @caelunshun
    Member

    A likely solution is to register an Entity representing the server and then add a chunk hold on spawn chunks for that entity. This will prevent the chunks from being unloaded.

    Note that you wouldn't call the chunk worker directly, since it runs on a separate thread. You have to use ChunkWorkerHandle to communicate with it.

    Something like this:

    let server_entity = world.create_entity().build();
    let mut chunk_holders = world.fetch_mut::<ChunkHolders>();
    let chunk_worker_handle = world.fetch::<ChunkWorkerHandler>();
    
    // Pre-load spawn area and prevent it from being unloaded.
    let view_distance = i32::from(world.fetch::<Arc<Config>>().server.view_distance);
    for x in -view_distance..=view_distance {
        for z in -view_distance..=view_distance {
            let chunk = ChunkPosition::new(x, z);
            chunk_logic::load_chunk(chunk_worker_handle, chunk);
            chunk_holders.add_for_chunk(chunk, server_entity);
        }
    }
  2. caelunshun commented on Sep 3, 2019

    @caelunshun
    Member

    In order to speed up the initial player join

    Although it's not like joining takes all that long, at least in release mode. The main overhead for join times is chunk sending, not loading, according to my profile tests.

  3. added this to the 0.5 milestone on Sep 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementperformance

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions