Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load spawn area chunks on start-up #107

Closed
aramperes opened this issue Sep 3, 2019 · 2 comments
Closed

Load spawn area chunks on start-up #107

aramperes opened this issue Sep 3, 2019 · 2 comments
Labels
enhancement New feature or request performance
Milestone

Comments

@aramperes
Copy link
Contributor

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.

@caelunshun
Copy link
Member

caelunshun commented Sep 3, 2019

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);
    }
}

@caelunshun
Copy link
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.

@caelunshun caelunshun added enhancement New feature or request performance labels Sep 3, 2019
@caelunshun caelunshun added this to the 0.5 milestone Sep 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request performance
Projects
None yet
Development

No branches or pull requests

2 participants