From b7ea4e75d335084063227a62f30ab17c6a40ea0c Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Sat, 30 Aug 2014 14:50:00 -0500 Subject: [PATCH] Allow Config to adjust CPU Calculation time per tick. --- core/AEConfig.java | 8 ++++++++ hooks/TickHandler.java | 16 +++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/core/AEConfig.java b/core/AEConfig.java index 8be74caf..2bdd78c0 100644 --- a/core/AEConfig.java +++ b/core/AEConfig.java @@ -130,6 +130,8 @@ public class AEConfig extends Configuration implements IConfigureableObject, ICo public double metoriteClusterChance = 0.1; public double metoriteSpawnChance = 0.3; + public int craftingCalculationTimePerTick = 5; + @SubscribeEvent public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent eventArgs) { @@ -301,6 +303,12 @@ public class AEConfig extends Configuration implements IConfigureableObject, ICo spatialPowerScaler = get( "spatialio", "spatialPowerScaler", spatialPowerScaler ).getDouble( spatialPowerScaler ); } + if ( isFeatureEnabled( AEFeature.CraftingCPU ) ) + { + craftingCalculationTimePerTick = get( "craftingcpu", "craftingCalculationTimePerTick", craftingCalculationTimePerTick ).getInt( + craftingCalculationTimePerTick ); + } + if ( isFeatureEnabled( AEFeature.VersionChecker ) ) { try diff --git a/hooks/TickHandler.java b/hooks/TickHandler.java index 87161927..fe453de7 100644 --- a/hooks/TickHandler.java +++ b/hooks/TickHandler.java @@ -16,6 +16,7 @@ import appeng.api.AEApi; import appeng.api.networking.IGridNode; import appeng.api.parts.CableRenderMode; import appeng.api.util.AEColor; +import appeng.core.AEConfig; import appeng.core.AELog; import appeng.core.CommonHelper; import appeng.core.sync.packets.PacketPaintedEntity; @@ -210,12 +211,17 @@ public class TickHandler WorldTickEvent wte = (WorldTickEvent) ev; synchronized (craftingJobs) { - Iterator i = craftingJobs.get( wte.world ).iterator(); - while (i.hasNext()) + Collection jobSet = craftingJobs.get( wte.world ); + if ( !jobSet.isEmpty() ) { - CraftingJob cj = i.next(); - if ( !cj.simulateFor( 5 ) ) - i.remove(); + int simTime = Math.max( 1, AEConfig.instance.craftingCalculationTimePerTick / jobSet.size() ); + Iterator i = jobSet.iterator(); + while (i.hasNext()) + { + CraftingJob cj = i.next(); + if ( !cj.simulateFor( simTime ) ) + i.remove(); + } } } }