1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-11-08 01:12:59 +00:00

Expose max computer/global times as config options

These do have a direct impact on server performance, so are definitely
worthwhile exposing.
This commit is contained in:
SquidDev
2019-03-21 13:31:58 +00:00
parent 5d05205d69
commit 245bf26480
9 changed files with 124 additions and 72 deletions

View File

@@ -23,6 +23,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import static dan200.computercraft.ComputerCraft.DEFAULT_HTTP_BLACKLIST;
import static dan200.computercraft.ComputerCraft.DEFAULT_HTTP_WHITELIST;
@@ -32,6 +33,7 @@ public class Config
private static final int MODEM_MAX_RANGE = 100000;
private static final String CATEGORY_GENERAL = "general";
private static final String CATEGORY_EXECUTION = "execution";
private static final String CATEGORY_HTTP = "http";
private static final String CATEGORY_PERIPHERAL = "peripheral";
private static final String CATEGORY_TURTLE = "turtle";
@@ -44,9 +46,12 @@ public class Config
private static Property disableLua51Features;
private static Property defaultComputerSettings;
private static Property debugEnabled;
private static Property computerThreads;
private static Property logComputerErrors;
private static Property computerThreads;
private static Property maxMainGlobalTime;
private static Property maxMainComputerTime;
private static Property httpEnable;
private static Property httpWebsocketEnable;
private static Property httpWhitelist;
@@ -97,21 +102,16 @@ public class Config
maximumFilesOpen.setMinValue( 0 );
disableLua51Features = config.get( CATEGORY_GENERAL, "disable_lua51_features", ComputerCraft.disable_lua51_features );
disableLua51Features.setComment( "Set this to true to disable Lua 5.1 functions that will be removed in a future update. Useful for ensuring forward compatibility of your programs now." );
disableLua51Features.setComment( "Set this to true to disable Lua 5.1 functions that will be removed in a future " +
"update. Useful for ensuring forward compatibility of your programs now." );
defaultComputerSettings = config.get( CATEGORY_GENERAL, "default_computer_settings", ComputerCraft.default_computer_settings );
defaultComputerSettings.setComment( "A comma seperated list of default system settings to set on new computers. Example: \"shell.autocomplete=false,lua.autocomplete=false,edit.autocomplete=false\" will disable all autocompletion" );
defaultComputerSettings.setComment( "A comma seperated list of default system settings to set on new computers. Example: " +
"\"shell.autocomplete=false,lua.autocomplete=false,edit.autocomplete=false\" will disable all autocompletion" );
debugEnabled = config.get( CATEGORY_GENERAL, "debug_enabled", ComputerCraft.debug_enable );
debugEnabled.setComment( "Enable Lua's debug library. This is sandboxed to each computer, so is generally safe to be used by players." );
computerThreads = config.get( CATEGORY_GENERAL, "computer_threads", ComputerCraft.computer_threads );
computerThreads
.setMinValue( 1 )
.setRequiresMcRestart( true )
.setComment( "Set the number of threads computers can run on. A higher number means more computers can run at once, but may induce lag.\n" +
"Please note that some mods may not work with a thread count higher than 1. Use with caution." );
logComputerErrors = config.get( CATEGORY_GENERAL, "log_computer_errors", ComputerCraft.logPeripheralErrors );
logComputerErrors.setComment( "Log exceptions thrown by peripherals and other Lua objects.\n" +
"This makes it easier for mod authors to debug problems, but may result in log spam should people use buggy methods." );
@@ -119,7 +119,42 @@ public class Config
setOrder(
CATEGORY_GENERAL,
computerSpaceLimit, floppySpaceLimit, maximumFilesOpen,
disableLua51Features, defaultComputerSettings, debugEnabled, computerThreads, logComputerErrors
disableLua51Features, defaultComputerSettings, debugEnabled, logComputerErrors
);
}
{ // Execution
renameProperty( CATEGORY_GENERAL, "computer_threads", CATEGORY_EXECUTION, "computer_threads" );
config.getCategory( CATEGORY_EXECUTION )
.setComment( "Controls execution behaviour of computers. This is largely intended for fine-tuning " +
"servers, and generally shouldn't need to be touched" );
computerThreads = config.get( CATEGORY_EXECUTION, "computer_threads", ComputerCraft.computer_threads );
computerThreads
.setMinValue( 1 )
.setRequiresMcRestart( true )
.setComment( "Set the number of threads computers can run on. A higher number means more computers can " +
"run at once, but may induce lag.\n" +
"Please note that some mods may not work with a thread count higher than 1. Use with caution." );
maxMainGlobalTime = config.get( CATEGORY_EXECUTION, "max_main_global_time", (int) TimeUnit.NANOSECONDS.toMillis( ComputerCraft.maxMainGlobalTime ) );
maxMainGlobalTime
.setMinValue( 1 )
.setComment( "The maximum time that can be spent executing tasks in a single tick, in milliseconds.\n" +
"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." );
maxMainComputerTime = config.get( CATEGORY_EXECUTION, "max_main_computer_time", (int) TimeUnit.NANOSECONDS.toMillis( ComputerCraft.maxMainComputerTime ) );
maxMainComputerTime
.setMinValue( 1 )
.setComment( "The ideal maximum time a computer can execute for in a tick, in milliseconds.\n" +
"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." );
setOrder(
CATEGORY_EXECUTION,
computerThreads, maxMainGlobalTime, maxMainComputerTime
);
}
@@ -129,20 +164,28 @@ public class Config
renameProperty( CATEGORY_GENERAL, "http_whitelist", CATEGORY_HTTP, "whitelist" );
renameProperty( CATEGORY_GENERAL, "http_blacklist", CATEGORY_HTTP, "blacklist" );
config.getCategory( CATEGORY_HTTP )
.setComment( "Controls the HTTP API" );
httpEnable = config.get( CATEGORY_HTTP, "enabled", ComputerCraft.http_enable );
httpEnable.setComment( "Enable the \"http\" API on Computers (see \"http_whitelist\" and \"http_blacklist\" for more fine grained control than this)" );
httpEnable.setComment( "Enable the \"http\" API on Computers (see \"http_whitelist\" and \"http_blacklist\" for " +
"more fine grained control than this)" );
httpWebsocketEnable = config.get( CATEGORY_HTTP, "websocket_enabled", ComputerCraft.http_websocket_enable );
httpWebsocketEnable.setComment( "Enable use of http websockets. This requires the \"http_enable\" option to also be true." );
httpWhitelist = config.get( CATEGORY_HTTP, "whitelist", DEFAULT_HTTP_WHITELIST );
httpWhitelist.setComment( "A list of wildcards for domains or IP ranges that can be accessed through the \"http\" API on Computers.\n" +
"Set this to \"*\" to access to the entire internet. Example: \"*.pastebin.com\" will restrict access to just subdomains of pastebin.com.\n" +
httpWhitelist.setComment( "A list of wildcards for domains or IP ranges that can be accessed through the " +
"\"http\" API on Computers.\n" +
"Set this to \"*\" to access to the entire internet. Example: \"*.pastebin.com\" will restrict access to " +
"just subdomains of pastebin.com.\n" +
"You can use domain names (\"pastebin.com\"), wilcards (\"*.pastebin.com\") or CIDR notation (\"127.0.0.0/8\")." );
httpBlacklist = config.get( CATEGORY_HTTP, "blacklist", DEFAULT_HTTP_BLACKLIST );
httpBlacklist.setComment( "A list of wildcards for domains or IP ranges that cannot be accessed through the \"http\" API on Computers.\n" +
"If this is empty then all whitelisted domains will be accessible. Example: \"*.github.com\" will block access to all subdomains of github.com.\n" +
httpBlacklist.setComment( "A list of wildcards for domains or IP ranges that cannot be accessed through the " +
"\"http\" API on Computers.\n" +
"If this is empty then all whitelisted domains will be accessible. Example: \"*.github.com\" will block " +
"access to all subdomains of github.com.\n" +
"You can use domain names (\"pastebin.com\"), wilcards (\"*.pastebin.com\") or CIDR notation (\"127.0.0.0/8\")." );
httpTimeout = config.get( CATEGORY_HTTP, "timeout", ComputerCraft.httpTimeout );
@@ -150,15 +193,18 @@ public class Config
httpTimeout.setMinValue( 0 );
httpMaxRequests = config.get( CATEGORY_HTTP, "max_requests", ComputerCraft.httpMaxRequests );
httpMaxRequests.setComment( "The number of http requests a computer can make at one time. Additional requests will be queued, and sent when the running requests have finished. Set to 0 for unlimited." );
httpMaxRequests.setComment( "The number of http requests a computer can make at one time. Additional requests " +
"will be queued, and sent when the running requests have finished. Set to 0 for unlimited." );
httpMaxRequests.setMinValue( 0 );
httpMaxDownload = config.get( CATEGORY_HTTP, "max_download", (int) ComputerCraft.httpMaxDownload );
httpMaxDownload.setComment( "The maximum size (in bytes) that a computer can download in a single request. Note that responses may receive more data than allowed, but this data will not be returned to the client." );
httpMaxDownload.setComment( "The maximum size (in bytes) that a computer can download in a single request. " +
"Note that responses may receive more data than allowed, but this data will not be returned to the client." );
httpMaxDownload.setMinValue( 0 );
httpMaxUpload = config.get( CATEGORY_HTTP, "max_upload", (int) ComputerCraft.httpMaxUpload );
httpMaxUpload.setComment( "The maximum size (in bytes) that a computer can upload in a single request. This includes headers and POST text." );
httpMaxUpload.setComment( "The maximum size (in bytes) that a computer can upload in a single request. This " +
"includes headers and POST text." );
httpMaxUpload.setMinValue( 0 );
httpMaxWebsockets = config.get( CATEGORY_HTTP, "max_websockets", ComputerCraft.httpMaxWebsockets );
@@ -185,6 +231,9 @@ public class Config
renameProperty( CATEGORY_GENERAL, "modem_highAltitudeRangeDuringStorm", CATEGORY_PERIPHERAL, "modem_high_altitude_range_during_storm" );
renameProperty( CATEGORY_GENERAL, "maxNotesPerTick", CATEGORY_PERIPHERAL, "max_notes_per_tick" );
config.getCategory( CATEGORY_PERIPHERAL )
.setComment( "Various options relating to peripherals." );
commandBlockEnabled = config.get( CATEGORY_PERIPHERAL, "command_block_enabled", ComputerCraft.enableCommandBlock );
commandBlockEnabled.setComment( "Enable Command Block peripheral support" );
@@ -226,6 +275,9 @@ public class Config
renameProperty( CATEGORY_GENERAL, "turtlesCanPush", CATEGORY_TURTLE, "can_push" );
renameProperty( CATEGORY_GENERAL, "turtle_disabled_actions", CATEGORY_TURTLE, "disabled_actions" );
config.getCategory( CATEGORY_HTTP )
.setComment( "Various options relating to turtles." );
turtlesNeedFuel = config.get( CATEGORY_TURTLE, "need_fuel", ComputerCraft.turtlesNeedFuel );
turtlesNeedFuel.setComment( "Set whether Turtles require fuel to move" );
@@ -238,10 +290,12 @@ public class Config
advancedTurtleFuelLimit.setMinValue( 0 );
turtlesObeyBlockProtection = config.get( CATEGORY_TURTLE, "obey_block_protection", ComputerCraft.turtlesObeyBlockProtection );
turtlesObeyBlockProtection.setComment( "If set to true, Turtles will be unable to build, dig, or enter protected areas (such as near the server spawn point)" );
turtlesObeyBlockProtection.setComment( "If set to true, Turtles will be unable to build, dig, or enter protected " +
"areas (such as near the server spawn point)" );
turtlesCanPush = config.get( CATEGORY_TURTLE, "can_push", ComputerCraft.turtlesCanPush );
turtlesCanPush.setComment( "If set to true, Turtles will push entities out of the way instead of stopping if there is space to do so" );
turtlesCanPush.setComment( "If set to true, Turtles will push entities out of the way instead of stopping if " +
"there is space to do so" );
turtleDisabledActions = config.get( CATEGORY_TURTLE, "disabled_actions", new String[0] );
turtleDisabledActions.setComment( "A list of turtle actions which are disabled." );
@@ -252,11 +306,12 @@ public class Config
);
}
setupLanguage( config.getCategory( CATEGORY_GENERAL ), "gui.computercraft:config" );
for( String child : config.getCategoryNames() )
{
if( child.equals( CATEGORY_GENERAL ) ) continue;
setupLanguage( config.getCategory( child ), "gui.computercraft:config." + child );
setupLanguage(
config.getCategory( child ),
child.equals( CATEGORY_GENERAL ) ? "gui.computercraft:config" : "gui.computercraft:config." + child
);
}
sync();
@@ -374,9 +429,13 @@ public class Config
ComputerCraft.disable_lua51_features = disableLua51Features.getBoolean();
ComputerCraft.default_computer_settings = defaultComputerSettings.getString();
ComputerCraft.debug_enable = debugEnabled.getBoolean();
ComputerCraft.computer_threads = computerThreads.getInt();
ComputerCraft.logPeripheralErrors = logComputerErrors.getBoolean();
// Execution
ComputerCraft.computer_threads = computerThreads.getInt();
ComputerCraft.maxMainGlobalTime = TimeUnit.MILLISECONDS.toNanos( Math.max( 1, maxMainGlobalTime.getLong() ) );
ComputerCraft.maxMainComputerTime = TimeUnit.MILLISECONDS.toNanos( Math.max( 1, maxMainComputerTime.getLong() ) );
// HTTP
ComputerCraft.http_enable = httpEnable.getBoolean();
ComputerCraft.http_websocket_enable = httpWebsocketEnable.getBoolean();