Skip to content

Commit

Permalink
Add proper moonrise configuration
Browse files Browse the repository at this point in the history
The config is stored under `moonrise.yaml` in the working
directory. Comments document each option.
  • Loading branch information
Spottedleaf committed Jun 11, 2024
1 parent 23f201e commit fff73cf
Show file tree
Hide file tree
Showing 28 changed files with 1,325 additions and 56 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ dependencies {
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

shadow('ca.spottedleaf:concurrentutil:0.0.1-SNAPSHOT')
shadow('org.yaml:snakeyaml:2.2')
}

processResources {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
package ca.spottedleaf.moonrise.common.config;

import ca.spottedleaf.moonrise.common.config.adapter.TypeAdapterRegistry;
import ca.spottedleaf.moonrise.common.config.annotation.Adaptable;
import ca.spottedleaf.moonrise.common.config.annotation.Serializable;
import ca.spottedleaf.moonrise.common.config.type.Duration;
import java.util.concurrent.TimeUnit;

@Adaptable
public final class MoonriseConfig {

@Serializable(
comment = """
Do not change, used internally.
"""
)
public int version = 1;

@Serializable
public ChunkLoading chunkLoading = new ChunkLoading();

@Adaptable
public static final class ChunkLoading {

@Serializable(
comment = """
Chunk loading/generation/sending rate targets for the chunk system. These values are the
maximum rates at which the player chunk loader will attempt to load/generate/send chunks to
players. Actual resulting rates will depend on hardware.
"""
)
public Basic basic = new Basic();


@Adaptable
public static final class Basic {
@Serializable(
comment = """
The maximum number of chunks to send to any given player, per second.
"""
)
public double playerMaxSendRate = -1.0;

@Serializable(
comment = """
The maximum number of chunks to load from disk for any given player, per second.
"""
)
public double playerMaxLoadRate = -1.0;

@Serializable(
comment = """
The maximum number of chunks to generate for any given player, per second.
"""
)
public double playerMaxGenRate = -1.0;
}

@Serializable(
comment = """
Advanced configuration options for player chunk loading. You shouldn't be touching these
unless you have a reason.
"""
)
public Advanced advanced = new Advanced();

@Adaptable
public static final class Advanced {

@Serializable(
comment = """
Whether to avoid sending chunks to players who have a view distance
configured lower than the server's.
"""
)
public boolean autoConfigSendDistance = true;

@Serializable(
comment = """
The maximum amount of pending chunk loads per player. If
this value is less-than 1, then the player chunk loader will
automatically determine a value.
This value should be used to tune the saturation of the chunk system.
"""
)
public int playerMaxConcurrentChunkLoads = 0;

@Serializable(
comment = """
The maximum amount of pending chunk generations per player. If
this value is less-than 1, then the player chunk loader will
automatically determine a value.
This value should be used to tune the saturation of the chunk system.
"""
)
public int playerMaxConcurrentChunkGenerates = 0;
}
}

@Serializable
public ChunkSaving chunkSaving = new ChunkSaving();

@Adaptable
public static final class ChunkSaving {

@Serializable(
comment = """
The interval at which chunks should be incrementally autosaved.
"""
)
public Duration autoSaveInterval = Duration.parse("5m");

@Serializable(
comment = """
The maximum number of chunks to incrementally autosave each tick. If
the value is <= 0, then no chunks will be incrementally saved.
"""
)
public int maxAutoSaveChunksPerTick = 12;
}

@Serializable(
comment = """
Set the number of shared worker threads to be used by chunk rendering,
chunk loading, chunk generation. If the value is <= 0, then the number
of threads will automatically be determined.
"""
)
public int workerThreads = -1;

@Serializable
public ChunkSystem chunkSystem = new ChunkSystem();

@Adaptable
public static final class ChunkSystem {

@Serializable(
comment = """
Set the number of threads dedicated to RegionFile I/O operations.
If the value is <= 0, then the number of threads used is 1. Configuring
a higher value than 1 is only recommended on SSDs (HDDs scale negatively)
and when you have determined that I/O is the bottleneck for chunk loading/saving.
"""
)
public int ioThreads = -1;

@Serializable(
comment = """
Whether to run generation population in parallel. By default this is set to false,
as mods affecting world gen are not safe to run in parallel. If you have no mods affecting
gen and are saturating the population generation (~10 threads of the worker pool generating
chunks), you may set this to true to possibly increase generation speed.
"""
)
public boolean populationGenParallelism = false;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ca.spottedleaf.moonrise.common.config.adapter;

import java.lang.reflect.Type;

public abstract class TypeAdapter<T, S> {

public abstract T deserialize(final TypeAdapterRegistry registry, final Object input, final Type type);

public abstract S serialize(final TypeAdapterRegistry registry, final T value, final Type type);

}
Loading

0 comments on commit fff73cf

Please sign in to comment.