Avoid quadratic behavior from rebuilding the entire crafting cache for

each interface visited. Instead rebuild it at most once per tick, like
cpu clusters.

This is particularly important when channels are disabled, since in
that case even adding a cable visits every grid node.
This commit is contained in:
talchas
2019-12-09 22:39:38 -08:00
parent df2a7c1858
commit 401f1ebb3e
+10 -3
View File
@@ -114,6 +114,7 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
private IStorageGrid storageGrid;
private IEnergyGrid energyGrid;
private boolean updateList = false;
private boolean updatePatterns = false;
public CraftingGridCache( final IGrid grid )
{
@@ -138,6 +139,12 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
this.updateCPUClusters();
}
if( this.updatePatterns )
{
this.updatePatterns = false;
this.updatePatterns();
}
final Iterator<CraftingLinkNexus> craftingLinkIterator = this.craftingLinks.values().iterator();
while( craftingLinkIterator.hasNext() )
{
@@ -185,7 +192,7 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
if( machine instanceof ICraftingProvider )
{
this.craftingProviders.remove( machine );
this.updatePatterns();
this.updatePatterns = true;
}
}
@@ -219,7 +226,7 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
if( machine instanceof ICraftingProvider )
{
this.craftingProviders.add( (ICraftingProvider) machine );
this.updatePatterns();
this.updatePatterns = true;
}
}
@@ -337,7 +344,7 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
@MENetworkEventSubscribe
public void updateCPUClusters( final MENetworkCraftingPatternChange c )
{
this.updatePatterns();
this.updatePatterns = true;
}
@Override