[7 Days to Mine]

[7 Days to Mine]

351k Downloads

City Generation Causing Server Lag - Suggestion to Use Separate Thread for City Generation

chu025 opened this issue ยท 0 comments

commented

Content:
Hello,

I have encountered an issue with the Seven Days to Die mod where the city generation process causes the world to become unresponsive, leading to significant server lag. This affects the overall performance and player experience on the server.

Problem:
The city generation is currently being handled on the main thread, which causes the world to hang and the server to lag during the process. This is especially problematic when generating large cities or when multiple cities are being generated simultaneously.

Suggestion:
To improve performance and reduce server lag, I suggest handling city generation in a separate thread instead of the main thread. This would allow the world to remain responsive and minimize the impact on server performance during city generation.

Example Code:
Here is an example of how you might implement city generation in a separate thread:
public class CityGenerator {
// Example method to generate a city
public void generateCity(World world, int x, int z) {
// Run the city generation in a separate thread
new Thread(() -> {
// Your city generation logic here
generateCityInThread(world, x, z);
}).start();
}

private void generateCityInThread(World world, int x, int z) {
    // Example city generation logic
    // Ensure thread-safety when accessing/modifying the world
    synchronized (world) {
        // City generation code
    }
}

}
Benefits:

Improved server performance and responsiveness.
Reduced impact on gameplay during city generation.
Better player experience due to minimized lag.
Thank you for considering this suggestion. I hope it helps improve the performance and playability of the mod.

Best regards