mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-10-23 01:47:38 +00:00
Move MainThread config to its own class
This means the config is no longer stored as static fields, which is a little cleaner. Would like to move everything else in the future, but this is a good first step.
This commit is contained in:
@@ -12,6 +12,7 @@ import dan200.computercraft.core.ComputerContext;
|
||||
import dan200.computercraft.core.computer.ComputerThread;
|
||||
import dan200.computercraft.core.computer.GlobalEnvironment;
|
||||
import dan200.computercraft.core.computer.mainthread.MainThread;
|
||||
import dan200.computercraft.core.computer.mainthread.MainThreadConfig;
|
||||
import dan200.computercraft.core.lua.CobaltLuaMachine;
|
||||
import dan200.computercraft.core.lua.ILuaMachine;
|
||||
import dan200.computercraft.impl.AbstractComputerCraftAPI;
|
||||
@@ -65,7 +66,7 @@ public final class ServerContext {
|
||||
private ServerContext(MinecraftServer server) {
|
||||
this.server = server;
|
||||
storageDir = server.getWorldPath(FOLDER);
|
||||
mainThread = new MainThread();
|
||||
mainThread = new MainThread(mainThreadConfig);
|
||||
context = new ComputerContext(
|
||||
new Environment(server),
|
||||
new ComputerThread(ConfigSpec.computerThreads.get()),
|
||||
@@ -215,4 +216,16 @@ public final class ServerContext {
|
||||
return ComputerCraftAPI.MOD_ID + "/" + ComputerCraftAPI.getInstalledVersion();
|
||||
}
|
||||
}
|
||||
|
||||
private static final MainThreadConfig mainThreadConfig = new MainThreadConfig() {
|
||||
@Override
|
||||
public long maxGlobalTime() {
|
||||
return TimeUnit.MILLISECONDS.toNanos(ConfigSpec.maxMainGlobalTime.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long maxComputerTime() {
|
||||
return TimeUnit.MILLISECONDS.toNanos(ConfigSpec.maxMainComputerTime.get());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@@ -9,6 +9,7 @@ import dan200.computercraft.core.CoreConfig;
|
||||
import dan200.computercraft.core.Logging;
|
||||
import dan200.computercraft.core.apis.http.NetworkUtils;
|
||||
import dan200.computercraft.core.apis.http.options.Action;
|
||||
import dan200.computercraft.core.computer.mainthread.MainThreadConfig;
|
||||
import dan200.computercraft.shared.peripheral.monitor.MonitorRenderer;
|
||||
import dan200.computercraft.shared.platform.PlatformHelper;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@@ -155,14 +156,14 @@ public final class ConfigSpec {
|
||||
milliseconds.
|
||||
Note, we will quite possibly go over this limit, as there's no way to tell how
|
||||
long a will take - this aims to be the upper bound of the average time.""")
|
||||
.defineInRange("max_main_global_time", (int) TimeUnit.NANOSECONDS.toMillis(CoreConfig.maxMainGlobalTime), 1, Integer.MAX_VALUE);
|
||||
.defineInRange("max_main_global_time", (int) TimeUnit.NANOSECONDS.toMillis(MainThreadConfig.DEFAULT_MAX_GLOBAL_TIME), 1, Integer.MAX_VALUE);
|
||||
|
||||
maxMainComputerTime = builder
|
||||
.comment("""
|
||||
The ideal maximum time a computer can execute for in a tick, in milliseconds.
|
||||
Note, we will quite possibly go over this limit, as there's no way to tell how
|
||||
long a will take - this aims to be the upper bound of the average time.""")
|
||||
.defineInRange("max_main_computer_time", (int) TimeUnit.NANOSECONDS.toMillis(CoreConfig.maxMainComputerTime), 1, Integer.MAX_VALUE);
|
||||
.defineInRange("max_main_computer_time", (int) TimeUnit.NANOSECONDS.toMillis(MainThreadConfig.DEFAULT_MAX_COMPUTER_TIME), 1, Integer.MAX_VALUE);
|
||||
|
||||
builder.pop();
|
||||
}
|
||||
@@ -348,10 +349,6 @@ public final class ConfigSpec {
|
||||
CoreConfig.defaultComputerSettings = defaultComputerSettings.get();
|
||||
Config.commandRequireCreative = commandRequireCreative.get();
|
||||
|
||||
// Execution
|
||||
CoreConfig.maxMainGlobalTime = TimeUnit.MILLISECONDS.toNanos(maxMainGlobalTime.get());
|
||||
CoreConfig.maxMainComputerTime = TimeUnit.MILLISECONDS.toNanos(maxMainComputerTime.get());
|
||||
|
||||
// Update our log filter if needed.
|
||||
var logFilter = MarkerFilter.createFilter(
|
||||
Logging.COMPUTER_ERROR.getName(),
|
||||
|
Reference in New Issue
Block a user