From 889b44585550192f82e10428808b82f79363d6d1 Mon Sep 17 00:00:00 2001 From: parly Date: Tue, 1 Oct 2019 15:21:37 +0900 Subject: [PATCH] Add time unit conversion Task execution times are stored in the config file in milliseconds, but they're stored internally in nanoseconds. This commit adds time unit conversions from milliseconds to nanoseconds. Fixes #9 --- .../java/dan200/computercraft/shared/util/Config.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/dan200/computercraft/shared/util/Config.java b/src/main/java/dan200/computercraft/shared/util/Config.java index d4851f6fc..f7f80d85c 100644 --- a/src/main/java/dan200/computercraft/shared/util/Config.java +++ b/src/main/java/dan200/computercraft/shared/util/Config.java @@ -72,12 +72,12 @@ public class Config @Comment( "\nThe 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." ) - public long max_main_global_time = (int) TimeUnit.NANOSECONDS.toMillis( ComputerCraft.maxMainGlobalTime ); + public long max_main_global_time = TimeUnit.NANOSECONDS.toMillis( ComputerCraft.maxMainGlobalTime ); @Comment( "\nThe 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." ) - public long max_main_computer_time = (int) TimeUnit.NANOSECONDS.toMillis( ComputerCraft.maxMainComputerTime ); + public long max_main_computer_time = TimeUnit.NANOSECONDS.toMillis( ComputerCraft.maxMainComputerTime ); } public static class Http @@ -234,8 +234,8 @@ public class Config // Execution ComputerCraft.computer_threads = Math.max( 1, config.execution.computer_threads ); - ComputerCraft.maxMainGlobalTime = Math.max( 1, config.execution.max_main_global_time ); - ComputerCraft.maxMainComputerTime = Math.max( 1, config.execution.max_main_computer_time ); + ComputerCraft.maxMainGlobalTime = TimeUnit.MILLISECONDS.toNanos( Math.max( 1, config.execution.max_main_global_time ) ); + ComputerCraft.maxMainComputerTime = TimeUnit.MILLISECONDS.toNanos( Math.max( 1, config.execution.max_main_computer_time ) ); // HTTP ComputerCraft.http_enable = config.http.enabled;