Reduces visibility of internal fields/methods

Reduces the visibility of all fields to private and create setters/getters
when necessary. Exceptions are fields with GuiSync as these need to be
public.

Reduces the visibility of internal methods to private/protected/default when possible.
This commit is contained in:
yueh
2015-10-08 15:42:42 +02:00
parent f054bd699b
commit e94a0cfccf
497 changed files with 7865 additions and 6908 deletions
+9 -4
View File
@@ -88,8 +88,8 @@ import com.google.common.collect.Multimap;
public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper, ICellProvider, IMEInventoryHandler<IAEStack>
{
public static final ExecutorService CRAFTING_POOL;
static final Comparator<ICraftingPatternDetails> COMPARATOR = new Comparator<ICraftingPatternDetails>()
private static final ExecutorService CRAFTING_POOL;
private static final Comparator<ICraftingPatternDetails> COMPARATOR = new Comparator<ICraftingPatternDetails>()
{
@Override
public int compare( final ICraftingPatternDetails firstDetail, final ICraftingPatternDetails nextDetail )
@@ -122,7 +122,7 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
private final Set<IAEItemStack> emitableItems = new HashSet<IAEItemStack>();
private final Map<String, CraftingLinkNexus> craftingLinks = new HashMap<String, CraftingLinkNexus>();
private final Multimap<IAEStack, CraftingWatcher> interests = HashMultimap.create();
public final GenericInterestManager<CraftingWatcher> interestManager = new GenericInterestManager<CraftingWatcher>( this.interests );
private final GenericInterestManager<CraftingWatcher> interestManager = new GenericInterestManager<CraftingWatcher>( this.interests );
private IStorageGrid storageGrid;
private IEnergyGrid energyGrid;
private boolean updateList = false;
@@ -615,7 +615,12 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
return this.craftingCPUClusters.contains( cpu );
}
static class ActiveCpuIterator implements Iterator<ICraftingCPU>
public GenericInterestManager<CraftingWatcher> getInterestManager()
{
return this.interestManager;
}
private static class ActiveCpuIterator implements Iterator<ICraftingCPU>
{
private final Iterator<CraftingCPUCluster> iterator;
+37 -32
View File
@@ -58,42 +58,42 @@ import com.google.common.collect.Multiset;
public class EnergyGridCache implements IEnergyGrid
{
public final TreeSet<EnergyThreshold> interests = new TreeSet<EnergyThreshold>();
final double AvgLength = 40.0;
final Set<IAEPowerStorage> providers = new LinkedHashSet<IAEPowerStorage>();
final Set<IAEPowerStorage> requesters = new LinkedHashSet<IAEPowerStorage>();
final Multiset<IEnergyGridProvider> energyGridProviders = HashMultiset.create();
final IGrid myGrid;
private final TreeSet<EnergyThreshold> interests = new TreeSet<EnergyThreshold>();
private final double AvgLength = 40.0;
private final Set<IAEPowerStorage> providers = new LinkedHashSet<IAEPowerStorage>();
private final Set<IAEPowerStorage> requesters = new LinkedHashSet<IAEPowerStorage>();
private final Multiset<IEnergyGridProvider> energyGridProviders = HashMultiset.create();
private final IGrid myGrid;
private final HashMap<IGridNode, IEnergyWatcher> watchers = new HashMap<IGridNode, IEnergyWatcher>();
private final Set<IEnergyGrid> localSeen = new HashSet<IEnergyGrid>();
/**
* estimated power available.
*/
int availableTicksSinceUpdate = 0;
double globalAvailablePower = 0;
double globalMaxPower = 0;
private int availableTicksSinceUpdate = 0;
private double globalAvailablePower = 0;
private double globalMaxPower = 0;
/**
* idle draw.
*/
double drainPerTick = 0;
double avgDrainPerTick = 0;
double avgInjectionPerTick = 0;
double tickDrainPerTick = 0;
double tickInjectionPerTick = 0;
private double drainPerTick = 0;
private double avgDrainPerTick = 0;
private double avgInjectionPerTick = 0;
private double tickDrainPerTick = 0;
private double tickInjectionPerTick = 0;
/**
* power status
*/
boolean publicHasPower = false;
boolean hasPower = true;
long ticksSinceHasPowerChange = 900;
private boolean publicHasPower = false;
private boolean hasPower = true;
private long ticksSinceHasPowerChange = 900;
/**
* excess power in the system.
*/
double extra = 0;
IAEPowerStorage lastProvider;
IAEPowerStorage lastRequester;
PathGridCache pgc;
double lastStoredPower = -1;
private double extra = 0;
private IAEPowerStorage lastProvider;
private IAEPowerStorage lastRequester;
private PathGridCache pgc;
private double lastStoredPower = -1;
public EnergyGridCache( final IGrid g )
{
@@ -114,8 +114,8 @@ public class EnergyGridCache implements IEnergyGrid
final IGridBlock gb = node.getGridBlock();
final double newDraw = gb.getIdlePowerUsage();
final double diffDraw = newDraw - node.previousDraw;
node.previousDraw = newDraw;
final double diffDraw = newDraw - node.getPreviousDraw();
node.setPreviousDraw( newDraw );
this.drainPerTick += diffDraw;
}
@@ -150,16 +150,16 @@ public class EnergyGridCache implements IEnergyGrid
@Override
public void onUpdateTick()
{
if( !this.interests.isEmpty() )
if( !this.getInterests().isEmpty() )
{
final double oldPower = this.lastStoredPower;
this.lastStoredPower = this.getStoredPower();
final EnergyThreshold low = new EnergyThreshold( Math.min( oldPower, this.lastStoredPower ), null );
final EnergyThreshold high = new EnergyThreshold( Math.max( oldPower, this.lastStoredPower ), null );
for( final EnergyThreshold th : this.interests.subSet( low, true, high, true ) )
for( final EnergyThreshold th : this.getInterests().subSet( low, true, high, true ) )
{
( (EnergyWatcher) th.watcher ).post( this );
( (EnergyWatcher) th.getWatcher() ).post( this );
}
}
@@ -221,7 +221,7 @@ public class EnergyGridCache implements IEnergyGrid
@Override
public double getIdlePowerUsage()
{
return this.drainPerTick + this.pgc.channelPowerUsage;
return this.drainPerTick + this.pgc.getChannelPowerUsage();
}
private void publicPowerState( final boolean newState, final IGrid grid )
@@ -239,7 +239,7 @@ public class EnergyGridCache implements IEnergyGrid
/**
* refresh current stored power.
*/
public void refreshPower()
private void refreshPower()
{
this.availableTicksSinceUpdate = 0;
this.globalAvailablePower = 0;
@@ -520,7 +520,7 @@ public class EnergyGridCache implements IEnergyGrid
// idle draw.
final GridNode gridNode = (GridNode) node;
this.drainPerTick -= gridNode.previousDraw;
this.drainPerTick -= gridNode.getPreviousDraw();
// power storage.
if( machine instanceof IAEPowerStorage )
@@ -571,8 +571,8 @@ public class EnergyGridCache implements IEnergyGrid
// idle draw...
final GridNode gridNode = (GridNode) node;
final IGridBlock gb = gridNode.getGridBlock();
gridNode.previousDraw = gb.getIdlePowerUsage();
this.drainPerTick += gridNode.previousDraw;
gridNode.setPreviousDraw( gb.getIdlePowerUsage() );
this.drainPerTick += gridNode.getPreviousDraw();
// power storage
if( machine instanceof IAEPowerStorage )
@@ -630,4 +630,9 @@ public class EnergyGridCache implements IEnergyGrid
{
storage.dataObject().setDouble( "extraEnergy", this.extra );
}
public TreeSet<EnergyThreshold> getInterests()
{
return this.interests;
}
}
+21 -11
View File
@@ -58,11 +58,11 @@ import com.google.common.collect.SetMultimap;
public class GridStorageCache implements IStorageGrid
{
public final IGrid myGrid;
final HashSet<ICellProvider> activeCellProviders = new HashSet<ICellProvider>();
final HashSet<ICellProvider> inactiveCellProviders = new HashSet<ICellProvider>();
private final IGrid myGrid;
private final HashSet<ICellProvider> activeCellProviders = new HashSet<ICellProvider>();
private final HashSet<ICellProvider> inactiveCellProviders = new HashSet<ICellProvider>();
private final SetMultimap<IAEStack, ItemWatcher> interests = HashMultimap.create();
public final GenericInterestManager<ItemWatcher> interestManager = new GenericInterestManager<ItemWatcher>( this.interests );
private final GenericInterestManager<ItemWatcher> interestManager = new GenericInterestManager<ItemWatcher>( this.interests );
private final NetworkMonitor<IAEItemStack> itemMonitor = new NetworkMonitor<IAEItemStack>( this, StorageChannel.ITEMS );
private final NetworkMonitor<IAEFluidStack> fluidMonitor = new NetworkMonitor<IAEFluidStack>( this, StorageChannel.FLUIDS );
private final HashMap<IGridNode, IStackWatcher> watchers = new HashMap<IGridNode, IStackWatcher>();
@@ -88,7 +88,7 @@ public class GridStorageCache implements IStorageGrid
{
final ICellContainer cc = (ICellContainer) machine;
this.myGrid.postEvent( new MENetworkCellArrayUpdate() );
this.getGrid().postEvent( new MENetworkCellArrayUpdate() );
this.removeCellProvider( cc, new CellChangeTracker() ).applyChanges();
this.inactiveCellProviders.remove( cc );
}
@@ -112,7 +112,7 @@ public class GridStorageCache implements IStorageGrid
final ICellContainer cc = (ICellContainer) machine;
this.inactiveCellProviders.add( cc );
this.myGrid.postEvent( new MENetworkCellArrayUpdate() );
this.getGrid().postEvent( new MENetworkCellArrayUpdate() );
if( node.isActive() )
{
this.addCellProvider( cc, new CellChangeTracker() ).applyChanges();
@@ -146,7 +146,7 @@ public class GridStorageCache implements IStorageGrid
}
public CellChangeTracker addCellProvider( final ICellProvider cc, final CellChangeTracker tracker )
private CellChangeTracker addCellProvider( final ICellProvider cc, final CellChangeTracker tracker )
{
if( this.inactiveCellProviders.contains( cc ) )
{
@@ -173,7 +173,7 @@ public class GridStorageCache implements IStorageGrid
return tracker;
}
public CellChangeTracker removeCellProvider( final ICellProvider cc, final CellChangeTracker tracker )
private CellChangeTracker removeCellProvider( final ICellProvider cc, final CellChangeTracker tracker )
{
if( this.activeCellProviders.contains( cc ) )
{
@@ -259,7 +259,7 @@ public class GridStorageCache implements IStorageGrid
}
}
public IMEInventoryHandler<IAEItemStack> getItemInventoryHandler()
IMEInventoryHandler<IAEItemStack> getItemInventoryHandler()
{
if( this.myItemNetwork == null )
{
@@ -270,7 +270,7 @@ public class GridStorageCache implements IStorageGrid
private void buildNetworkStorage( final StorageChannel chan )
{
final SecurityCache security = this.myGrid.getCache( ISecurityGrid.class );
final SecurityCache security = this.getGrid().getCache( ISecurityGrid.class );
switch( chan )
{
@@ -298,7 +298,7 @@ public class GridStorageCache implements IStorageGrid
}
}
public IMEInventoryHandler<IAEFluidStack> getFluidInventoryHandler()
IMEInventoryHandler<IAEFluidStack> getFluidInventoryHandler()
{
if( this.myFluidNetwork == null )
{
@@ -346,6 +346,16 @@ public class GridStorageCache implements IStorageGrid
return this.fluidMonitor;
}
public GenericInterestManager<ItemWatcher> getInterestManager()
{
return this.interestManager;
}
IGrid getGrid()
{
return this.myGrid;
}
private class CellChangeTrackerRecord
{
+8 -8
View File
@@ -42,7 +42,7 @@ public class NetworkMonitor<T extends IAEStack<T>> extends MEMonitorHandler<T>
private static final Deque<NetworkMonitor<?>> DEPTH = new LinkedList<NetworkMonitor<?>>();
private final GridStorageCache myGridCache;
private final StorageChannel myChannel;
boolean sendEvent = false;
private boolean sendEvent = false;
public NetworkMonitor( final GridStorageCache cache, final StorageChannel chan )
{
@@ -51,7 +51,7 @@ public class NetworkMonitor<T extends IAEStack<T>> extends MEMonitorHandler<T>
this.myChannel = chan;
}
public void forceUpdate()
void forceUpdate()
{
this.hasChanged = true;
@@ -72,12 +72,12 @@ public class NetworkMonitor<T extends IAEStack<T>> extends MEMonitorHandler<T>
}
}
public void onTick()
void onTick()
{
if( this.sendEvent )
{
this.sendEvent = false;
this.myGridCache.myGrid.postEvent( new MENetworkStorageEvent( this, this.myChannel ) );
this.myGridCache.getGrid().postEvent( new MENetworkStorageEvent( this, this.myChannel ) );
}
}
@@ -124,9 +124,9 @@ public class NetworkMonitor<T extends IAEStack<T>> extends MEMonitorHandler<T>
( difference = changedItem.copy() ).setStackSize( -changedItem.getStackSize() );
}
if( this.myGridCache.interestManager.containsKey( changedItem ) )
if( this.myGridCache.getInterestManager().containsKey( changedItem ) )
{
final Collection<ItemWatcher> list = this.myGridCache.interestManager.get( changedItem );
final Collection<ItemWatcher> list = this.myGridCache.getInterestManager().get( changedItem );
if( !list.isEmpty() )
{
IAEStack fullStack = myStorageList.findPrecise( changedItem );
@@ -136,14 +136,14 @@ public class NetworkMonitor<T extends IAEStack<T>> extends MEMonitorHandler<T>
fullStack.setStackSize( 0 );
}
this.myGridCache.interestManager.enableTransactions();
this.myGridCache.getInterestManager().enableTransactions();
for( final ItemWatcher iw : list )
{
iw.getHost().onStackChange( myStorageList, fullStack, difference, src, this.getChannel() );
}
this.myGridCache.interestManager.disableTransactions();
this.myGridCache.getInterestManager().disableTransactions();
}
}
}
+17 -17
View File
@@ -42,7 +42,7 @@ import com.google.common.collect.Multimap;
public class P2PCache implements IGridCache
{
final IGrid myGrid;
private final IGrid myGrid;
private final HashMap<Long, PartP2PTunnel> inputs = new HashMap<Long, PartP2PTunnel>();
private final Multimap<Long, PartP2PTunnel> outputs = LinkedHashMultimap.create();
private final TunnelCollection NullColl = new TunnelCollection<PartP2PTunnel>( null, null );
@@ -101,16 +101,16 @@ public class P2PCache implements IGridCache
// AELog.info( "rmv-" + (t.output ? "output: " : "input: ") + t.freq
// );
if( t.output )
if( t.isOutput() )
{
this.outputs.remove( t.freq, t );
this.outputs.remove( t.getFrequency(), t );
}
else
{
this.inputs.remove( t.freq );
this.inputs.remove( t.getFrequency() );
}
this.updateTunnel( t.freq, !t.output, false );
this.updateTunnel( t.getFrequency(), !t.isOutput(), false );
}
}
@@ -131,16 +131,16 @@ public class P2PCache implements IGridCache
// AELog.info( "add-" + (t.output ? "output: " : "input: ") + t.freq
// );
if( t.output )
if( t.isOutput() )
{
this.outputs.put( t.freq, t );
this.outputs.put( t.getFrequency(), t );
}
else
{
this.inputs.put( t.freq, t );
this.inputs.put( t.getFrequency(), t );
}
this.updateTunnel( t.freq, !t.output, false );
this.updateTunnel( t.getFrequency(), !t.isOutput(), false );
}
}
@@ -188,29 +188,29 @@ public class P2PCache implements IGridCache
{
if( this.outputs.containsValue( t ) )
{
this.outputs.remove( t.freq, t );
this.outputs.remove( t.getFrequency(), t );
}
if( this.inputs.containsValue( t ) )
{
this.inputs.remove( t.freq );
this.inputs.remove( t.getFrequency() );
}
t.freq = newFrequency;
t.setFrequency( newFrequency );
if( t.output )
if( t.isOutput() )
{
this.outputs.put( t.freq, t );
this.outputs.put( t.getFrequency(), t );
}
else
{
this.inputs.put( t.freq, t );
this.inputs.put( t.getFrequency(), t );
}
// AELog.info( "update-" + (t.output ? "output: " : "input: ") + t.freq
// );
this.updateTunnel( t.freq, t.output, true );
this.updateTunnel( t.freq, !t.output, true );
this.updateTunnel( t.getFrequency(), t.isOutput(), true );
this.updateTunnel( t.getFrequency(), !t.isOutput(), true );
}
public TunnelCollection<PartP2PTunnel> getOutputs( final long freq, final Class<? extends PartP2PTunnel> c )
+57 -29
View File
@@ -59,21 +59,20 @@ import appeng.util.Platform;
public class PathGridCache implements IPathingGrid
{
final LinkedList<PathSegment> active = new LinkedList<PathSegment>();
final Set<TileController> controllers = new HashSet<TileController>();
final Set<IGridNode> requireChannels = new HashSet<IGridNode>();
final Set<IGridNode> blockDense = new HashSet<IGridNode>();
final IGrid myGrid;
public int channelsInUse = 0;
public int channelsByBlocks = 0;
public double channelPowerUsage = 0.0;
boolean recalculateControllerNextTick = true;
boolean updateNetwork = true;
boolean booting = false;
ControllerState controllerState = ControllerState.NO_CONTROLLER;
int instance = Integer.MIN_VALUE;
int ticksUntilReady = 20;
int lastChannels = 0;
private final LinkedList<PathSegment> active = new LinkedList<PathSegment>();
private final Set<TileController> controllers = new HashSet<TileController>();
private final Set<IGridNode> requireChannels = new HashSet<IGridNode>();
private final Set<IGridNode> blockDense = new HashSet<IGridNode>();
private final IGrid myGrid;
private int channelsInUse = 0;
private int channelsByBlocks = 0;
private double channelPowerUsage = 0.0;
private boolean recalculateControllerNextTick = true;
private boolean updateNetwork = true;
private boolean booting = false;
private ControllerState controllerState = ControllerState.NO_CONTROLLER;
private int ticksUntilReady = 20;
private int lastChannels = 0;
private HashSet<IPathItem> semiOpen = new HashSet<IPathItem>();
public PathGridCache( final IGrid g )
@@ -98,8 +97,7 @@ public class PathGridCache implements IPathingGrid
this.booting = true;
this.updateNetwork = false;
this.instance++;
this.channelsInUse = 0;
this.setChannelsInUse( 0 );
if( !AEConfig.instance.isFeatureEnabled( AEFeature.Channels ) )
{
@@ -107,8 +105,8 @@ public class PathGridCache implements IPathingGrid
final int nodes = this.myGrid.getNodes().size();
this.ticksUntilReady = 20 + Math.max( 0, nodes / 100 - 20 );
this.channelsByBlocks = nodes * used;
this.channelPowerUsage = this.channelsByBlocks / 128.0;
this.setChannelsByBlocks( nodes * used );
this.setChannelPowerUsage( this.getChannelsByBlocks() / 128.0 );
this.myGrid.getPivot().beginVisit( new AdHocChannelUpdater( used ) );
}
@@ -122,11 +120,11 @@ public class PathGridCache implements IPathingGrid
}
final int nodes = this.myGrid.getNodes().size();
this.channelsInUse = used;
this.setChannelsInUse( used );
this.ticksUntilReady = 20 + Math.max( 0, nodes / 100 - 20 );
this.channelsByBlocks = nodes * used;
this.channelPowerUsage = this.channelsByBlocks / 128.0;
this.setChannelsByBlocks( nodes * used );
this.setChannelPowerUsage( this.getChannelsByBlocks() / 128.0 );
this.myGrid.getPivot().beginVisit( new AdHocChannelUpdater( used ) );
}
@@ -171,7 +169,7 @@ public class PathGridCache implements IPathingGrid
final PathSegment pat = i.next();
if( pat.step() )
{
pat.isDead = true;
pat.setDead( true );
i.remove();
}
}
@@ -194,7 +192,7 @@ public class PathGridCache implements IPathingGrid
this.achievementPost();
this.booting = false;
this.channelPowerUsage = this.channelsByBlocks / 128.0;
this.setChannelPowerUsage( this.getChannelsByBlocks() / 128.0 );
this.myGrid.postEvent( new MENetworkBootingStatusChange() );
}
}
@@ -289,7 +287,7 @@ public class PathGridCache implements IPathingGrid
startingNode.beginVisit( cv );
if( cv.isValid && cv.found == this.controllers.size() )
if( cv.isValid() && cv.getFound() == this.controllers.size() )
{
this.controllerState = ControllerState.CONTROLLER_ONLINE;
}
@@ -341,9 +339,9 @@ public class PathGridCache implements IPathingGrid
private void achievementPost()
{
if( this.lastChannels != this.channelsInUse && AEConfig.instance.isFeatureEnabled( AEFeature.Channels ) )
if( this.lastChannels != this.getChannelsInUse() && AEConfig.instance.isFeatureEnabled( AEFeature.Channels ) )
{
final Achievements currentBracket = this.getAchievementBracket( this.channelsInUse );
final Achievements currentBracket = this.getAchievementBracket( this.getChannelsInUse() );
final Achievements lastBracket = this.getAchievementBracket( this.lastChannels );
if( currentBracket != lastBracket && currentBracket != null )
{
@@ -359,7 +357,7 @@ public class PathGridCache implements IPathingGrid
}
}
}
this.lastChannels = this.channelsInUse;
this.lastChannels = this.getChannelsInUse();
}
private Achievements getAchievementBracket( final int ch )
@@ -417,7 +415,37 @@ public class PathGridCache implements IPathingGrid
// clean up...
this.active.clear();
this.channelsByBlocks = 0;
this.setChannelsByBlocks( 0 );
this.updateNetwork = true;
}
double getChannelPowerUsage()
{
return this.channelPowerUsage;
}
private void setChannelPowerUsage( final double channelPowerUsage )
{
this.channelPowerUsage = channelPowerUsage;
}
public int getChannelsByBlocks()
{
return this.channelsByBlocks;
}
public void setChannelsByBlocks( final int channelsByBlocks )
{
this.channelsByBlocks = channelsByBlocks;
}
public int getChannelsInUse()
{
return this.channelsInUse;
}
public void setChannelsInUse( final int channelsInUse )
{
this.channelsInUse = channelsInUse;
}
}
+10 -5
View File
@@ -44,7 +44,7 @@ import appeng.me.GridNode;
public class SecurityCache implements ISecurityGrid
{
public final IGrid myGrid;
private final IGrid myGrid;
private final List<ISecurityProvider> securityProvider = new ArrayList<ISecurityProvider>();
private final HashMap<Integer, EnumSet<SecurityPermissions>> playerPerms = new HashMap<Integer, EnumSet<SecurityPermissions>>();
private long securityKey = -1;
@@ -102,10 +102,10 @@ public class SecurityCache implements ISecurityGrid
if( lastCode != this.securityKey )
{
this.myGrid.postEvent( new MENetworkSecurityChange() );
for( final IGridNode n : this.myGrid.getNodes() )
this.getGrid().postEvent( new MENetworkSecurityChange() );
for( final IGridNode n : this.getGrid().getNodes() )
{
( (GridNode) n ).lastSecurityKey = this.securityKey;
( (GridNode) n ).setLastSecurityKey( this.securityKey );
}
}
}
@@ -120,7 +120,7 @@ public class SecurityCache implements ISecurityGrid
}
else
{
( (GridNode) gridNode ).lastSecurityKey = this.securityKey;
( (GridNode) gridNode ).setLastSecurityKey( this.securityKey );
}
}
@@ -193,4 +193,9 @@ public class SecurityCache implements ISecurityGrid
}
return -1;
}
public IGrid getGrid()
{
return this.myGrid;
}
}
+23 -24
View File
@@ -41,15 +41,14 @@ import appeng.tile.spatial.TileSpatialPylon;
public class SpatialPylonCache implements ISpatialCache
{
final IGrid myGrid;
long powerRequired = 0;
double efficiency = 0.0;
DimensionalCoord captureMin;
DimensionalCoord captureMax;
boolean isValid = false;
List<TileSpatialIOPort> ioPorts = new LinkedList<TileSpatialIOPort>();
HashMap<SpatialPylonCluster, SpatialPylonCluster> clusters = new HashMap<SpatialPylonCluster, SpatialPylonCluster>();
boolean needsUpdate = false;
private final IGrid myGrid;
private long powerRequired = 0;
private double efficiency = 0.0;
private DimensionalCoord captureMin;
private DimensionalCoord captureMax;
private boolean isValid = false;
private List<TileSpatialIOPort> ioPorts = new LinkedList<TileSpatialIOPort>();
private HashMap<SpatialPylonCluster, SpatialPylonCluster> clusters = new HashMap<SpatialPylonCluster, SpatialPylonCluster>();
public SpatialPylonCache( final IGrid g )
{
@@ -62,7 +61,7 @@ public class SpatialPylonCache implements ISpatialCache
this.reset( this.myGrid );
}
public void reset( final IGrid grid )
private void reset( final IGrid grid )
{
this.clusters = new HashMap<SpatialPylonCluster, SpatialPylonCluster>();
@@ -95,22 +94,22 @@ public class SpatialPylonCache implements ISpatialCache
{
if( this.captureMax == null )
{
this.captureMax = cl.max.copy();
this.captureMax = cl.getMax().copy();
}
if( this.captureMin == null )
{
this.captureMin = cl.min.copy();
this.captureMin = cl.getMin().copy();
}
pylonBlocks += cl.tileCount();
this.captureMin.x = Math.min( this.captureMin.x, cl.min.x );
this.captureMin.y = Math.min( this.captureMin.y, cl.min.y );
this.captureMin.z = Math.min( this.captureMin.z, cl.min.z );
this.captureMin.x = Math.min( this.captureMin.x, cl.getMin().x );
this.captureMin.y = Math.min( this.captureMin.y, cl.getMin().y );
this.captureMin.z = Math.min( this.captureMin.z, cl.getMin().z );
this.captureMax.x = Math.max( this.captureMax.x, cl.max.x );
this.captureMax.y = Math.max( this.captureMax.y, cl.max.y );
this.captureMax.z = Math.max( this.captureMax.z, cl.max.z );
this.captureMax.x = Math.max( this.captureMax.x, cl.getMax().x );
this.captureMax.y = Math.max( this.captureMax.y, cl.getMax().y );
this.captureMax.z = Math.max( this.captureMax.z, cl.getMax().z );
}
double maxPower = 0;
@@ -121,21 +120,21 @@ public class SpatialPylonCache implements ISpatialCache
for( final SpatialPylonCluster cl : this.clusters.values() )
{
switch( cl.currentAxis )
switch( cl.getCurrentAxis() )
{
case X:
this.isValid = this.isValid && ( ( this.captureMax.y == cl.min.y || this.captureMin.y == cl.max.y ) || ( this.captureMax.z == cl.min.z || this.captureMin.z == cl.max.z ) ) && ( ( this.captureMax.y == cl.max.y || this.captureMin.y == cl.min.y ) || ( this.captureMax.z == cl.max.z || this.captureMin.z == cl.min.z ) );
this.isValid = this.isValid && ( ( this.captureMax.y == cl.getMin().y || this.captureMin.y == cl.getMax().y ) || ( this.captureMax.z == cl.getMin().z || this.captureMin.z == cl.getMax().z ) ) && ( ( this.captureMax.y == cl.getMax().y || this.captureMin.y == cl.getMin().y ) || ( this.captureMax.z == cl.getMax().z || this.captureMin.z == cl.getMin().z ) );
break;
case Y:
this.isValid = this.isValid && ( ( this.captureMax.x == cl.min.x || this.captureMin.x == cl.max.x ) || ( this.captureMax.z == cl.min.z || this.captureMin.z == cl.max.z ) ) && ( ( this.captureMax.x == cl.max.x || this.captureMin.x == cl.min.x ) || ( this.captureMax.z == cl.max.z || this.captureMin.z == cl.min.z ) );
this.isValid = this.isValid && ( ( this.captureMax.x == cl.getMin().x || this.captureMin.x == cl.getMax().x ) || ( this.captureMax.z == cl.getMin().z || this.captureMin.z == cl.getMax().z ) ) && ( ( this.captureMax.x == cl.getMax().x || this.captureMin.x == cl.getMin().x ) || ( this.captureMax.z == cl.getMax().z || this.captureMin.z == cl.getMin().z ) );
break;
case Z:
this.isValid = this.isValid && ( ( this.captureMax.y == cl.min.y || this.captureMin.y == cl.max.y ) || ( this.captureMax.x == cl.min.x || this.captureMin.x == cl.max.x ) ) && ( ( this.captureMax.y == cl.max.y || this.captureMin.y == cl.min.y ) || ( this.captureMax.x == cl.max.x || this.captureMin.x == cl.min.x ) );
this.isValid = this.isValid && ( ( this.captureMax.y == cl.getMin().y || this.captureMin.y == cl.getMax().y ) || ( this.captureMax.x == cl.getMin().x || this.captureMin.x == cl.getMax().x ) ) && ( ( this.captureMax.y == cl.getMax().y || this.captureMin.y == cl.getMin().y ) || ( this.captureMax.x == cl.getMax().x || this.captureMin.x == cl.getMin().x ) );
break;
case UNFORMED:
@@ -169,8 +168,8 @@ public class SpatialPylonCache implements ISpatialCache
for( final SpatialPylonCluster cl : this.clusters.values() )
{
final boolean myWasValid = cl.isValid;
cl.isValid = this.isValid;
final boolean myWasValid = cl.isValid();
cl.setValid( this.isValid );
if( myWasValid != this.isValid )
{
cl.updateStatus( false );
+17 -17
View File
@@ -39,11 +39,11 @@ import appeng.me.cache.helpers.TickTracker;
public class TickManagerCache implements ITickManager
{
final IGrid myGrid;
final HashMap<IGridNode, TickTracker> alertable = new HashMap<IGridNode, TickTracker>();
final HashMap<IGridNode, TickTracker> sleeping = new HashMap<IGridNode, TickTracker>();
final HashMap<IGridNode, TickTracker> awake = new HashMap<IGridNode, TickTracker>();
final PriorityQueue<TickTracker> upcomingTicks = new PriorityQueue<TickTracker>();
private final IGrid myGrid;
private final HashMap<IGridNode, TickTracker> alertable = new HashMap<IGridNode, TickTracker>();
private final HashMap<IGridNode, TickTracker> sleeping = new HashMap<IGridNode, TickTracker>();
private final HashMap<IGridNode, TickTracker> awake = new HashMap<IGridNode, TickTracker>();
private final PriorityQueue<TickTracker> upcomingTicks = new PriorityQueue<TickTracker>();
private long currentTick = 0;
public TickManagerCache( final IGrid g )
@@ -83,28 +83,28 @@ public class TickManagerCache implements ITickManager
while( !this.upcomingTicks.isEmpty() )
{
tt = this.upcomingTicks.peek();
final int diff = (int) ( this.currentTick - tt.lastTick );
if( diff >= tt.current_rate )
final int diff = (int) ( this.currentTick - tt.getLastTick() );
if( diff >= tt.getCurrentRate() )
{
// remove tt..
this.upcomingTicks.poll();
final TickRateModulation mod = tt.gt.tickingRequest( tt.node, diff );
final TickRateModulation mod = tt.getGridTickable().tickingRequest( tt.getNode(), diff );
switch( mod )
{
case FASTER:
tt.setRate( tt.current_rate - 2 );
tt.setRate( tt.getCurrentRate() - 2 );
break;
case IDLE:
tt.setRate( tt.request.maxTickRate );
tt.setRate( tt.getRequest().maxTickRate );
break;
case SAME:
break;
case SLEEP:
this.sleepDevice( tt.node );
this.sleepDevice( tt.getNode() );
break;
case SLOWER:
tt.setRate( tt.current_rate + 1 );
tt.setRate( tt.getCurrentRate() + 1 );
break;
case URGENT:
tt.setRate( 0 );
@@ -113,7 +113,7 @@ public class TickManagerCache implements ITickManager
break;
}
if( this.awake.containsKey( tt.node ) )
if( this.awake.containsKey( tt.getNode() ) )
{
this.addToQueue( tt );
}
@@ -127,7 +127,7 @@ public class TickManagerCache implements ITickManager
catch( final Throwable t )
{
final CrashReport crashreport = CrashReport.makeCrashReport( t, "Ticking GridNode" );
final CrashReportCategory crashreportcategory = crashreport.makeCategory( tt.gt.getClass().getSimpleName() + " being ticked." );
final CrashReportCategory crashreportcategory = crashreport.makeCategory( tt.getGridTickable().getClass().getSimpleName() + " being ticked." );
tt.addEntityCrashInfo( crashreportcategory );
throw new ReportedException( crashreport );
}
@@ -135,7 +135,7 @@ public class TickManagerCache implements ITickManager
private void addToQueue( final TickTracker tt )
{
tt.lastTick = this.currentTick;
tt.setLastTick( this.currentTick );
this.upcomingTicks.add( tt );
}
@@ -212,8 +212,8 @@ public class TickManagerCache implements ITickManager
this.awake.put( node, tt );
// configure sort.
tt.lastTick -= tt.request.maxTickRate;
tt.current_rate = tt.request.minTickRate;
tt.setLastTick( tt.getLastTick() - tt.getRequest().maxTickRate );
tt.setCurrentRate( tt.getRequest().minTickRate );
// prevent dupes and tick build up.
this.upcomingTicks.remove( tt );
@@ -25,10 +25,20 @@ import appeng.api.networking.IGridConnection;
public class ConnectionWrapper
{
public IGridConnection connection;
private IGridConnection connection;
public ConnectionWrapper( final IGridConnection gc )
{
this.connection = gc;
this.setConnection( gc );
}
public IGridConnection getConnection()
{
return this.connection;
}
public void setConnection( final IGridConnection connection )
{
this.connection = connection;
}
}
+32 -7
View File
@@ -31,10 +31,10 @@ import appeng.util.IWorldCallable;
public class Connections implements IWorldCallable<Void>
{
public final HashMap<IGridNode, TunnelConnection> connections = new HashMap<IGridNode, TunnelConnection>();
private final HashMap<IGridNode, TunnelConnection> connections = new HashMap<IGridNode, TunnelConnection>();
private final PartP2PTunnelME me;
public boolean create = false;
public boolean destroy = false;
private boolean create = false;
private boolean destroy = false;
public Connections( final PartP2PTunnelME o )
{
@@ -51,13 +51,38 @@ public class Connections implements IWorldCallable<Void>
public void markDestroy()
{
this.create = false;
this.destroy = true;
this.setCreate( false );
this.setDestroy( true );
}
public void markCreate()
{
this.create = true;
this.destroy = false;
this.setCreate( true );
this.setDestroy( false );
}
public HashMap<IGridNode, TunnelConnection> getConnections()
{
return this.connections;
}
public boolean isCreate()
{
return this.create;
}
private void setCreate( final boolean create )
{
this.create = create;
}
public boolean isDestroy()
{
return this.destroy;
}
private void setDestroy( final boolean destroy )
{
this.destroy = destroy;
}
}
+60 -25
View File
@@ -33,23 +33,23 @@ import appeng.parts.AEBasePart;
public class TickTracker implements Comparable<TickTracker>
{
public final TickingRequest request;
public final IGridTickable gt;
public final IGridNode node;
public final TickManagerCache host;
private final TickingRequest request;
private final IGridTickable gt;
private final IGridNode node;
private final TickManagerCache host;
public final long LastFiveTicksTime = 0;
private final long LastFiveTicksTime = 0;
public long lastTick;
public int current_rate;
private long lastTick;
private int currentRate;
public TickTracker( final TickingRequest req, final IGridNode node, final IGridTickable gt, final long currentTick, final TickManagerCache tickManagerCache )
{
this.request = req;
this.gt = gt;
this.node = node;
this.current_rate = ( req.minTickRate + req.maxTickRate ) / 2;
this.lastTick = currentTick;
this.setCurrentRate( ( req.minTickRate + req.maxTickRate ) / 2 );
this.setLastTick( currentTick );
this.host = tickManagerCache;
}
@@ -60,46 +60,81 @@ public class TickTracker implements Comparable<TickTracker>
public void setRate( final int rate )
{
this.current_rate = rate;
this.setCurrentRate( rate );
if( this.current_rate < this.request.minTickRate )
if( this.getCurrentRate() < this.getRequest().minTickRate )
{
this.current_rate = this.request.minTickRate;
this.setCurrentRate( this.getRequest().minTickRate );
}
if( this.current_rate > this.request.maxTickRate )
if( this.getCurrentRate() > this.getRequest().maxTickRate )
{
this.current_rate = this.request.maxTickRate;
this.setCurrentRate( this.getRequest().maxTickRate );
}
}
@Override
public int compareTo( @Nonnull final TickTracker t )
{
final int nextTick = (int) ( ( this.lastTick - this.host.getCurrentTick() ) + this.current_rate );
final int ts_nextTick = (int) ( ( t.lastTick - this.host.getCurrentTick() ) + t.current_rate );
final int nextTick = (int) ( ( this.getLastTick() - this.host.getCurrentTick() ) + this.getCurrentRate() );
final int ts_nextTick = (int) ( ( t.getLastTick() - this.host.getCurrentTick() ) + t.getCurrentRate() );
return nextTick - ts_nextTick;
}
public void addEntityCrashInfo( final CrashReportCategory crashreportcategory )
{
if( this.gt instanceof AEBasePart )
if( this.getGridTickable() instanceof AEBasePart )
{
final AEBasePart part = (AEBasePart) this.gt;
final AEBasePart part = (AEBasePart) this.getGridTickable();
part.addEntityCrashInfo( crashreportcategory );
}
crashreportcategory.addCrashSection( "CurrentTickRate", this.current_rate );
crashreportcategory.addCrashSection( "MinTickRate", this.request.minTickRate );
crashreportcategory.addCrashSection( "MaxTickRate", this.request.maxTickRate );
crashreportcategory.addCrashSection( "MachineType", this.gt.getClass().getName() );
crashreportcategory.addCrashSection( "GridBlockType", this.node.getGridBlock().getClass().getName() );
crashreportcategory.addCrashSection( "ConnectedSides", this.node.getConnectedSides() );
crashreportcategory.addCrashSection( "CurrentTickRate", this.getCurrentRate() );
crashreportcategory.addCrashSection( "MinTickRate", this.getRequest().minTickRate );
crashreportcategory.addCrashSection( "MaxTickRate", this.getRequest().maxTickRate );
crashreportcategory.addCrashSection( "MachineType", this.getGridTickable().getClass().getName() );
crashreportcategory.addCrashSection( "GridBlockType", this.getNode().getGridBlock().getClass().getName() );
crashreportcategory.addCrashSection( "ConnectedSides", this.getNode().getConnectedSides() );
final DimensionalCoord dc = this.node.getGridBlock().getLocation();
final DimensionalCoord dc = this.getNode().getGridBlock().getLocation();
if( dc != null )
{
crashreportcategory.addCrashSection( "Location", dc );
}
}
public int getCurrentRate()
{
return this.currentRate;
}
public void setCurrentRate( final int currentRate )
{
this.currentRate = currentRate;
}
public long getLastTick()
{
return this.lastTick;
}
public void setLastTick( final long lastTick )
{
this.lastTick = lastTick;
}
public IGridNode getNode()
{
return this.node;
}
public IGridTickable getGridTickable()
{
return this.gt;
}
public TickingRequest getRequest()
{
return this.request;
}
}
@@ -29,8 +29,8 @@ import appeng.util.iterators.NullIterator;
public class TunnelCollection<T extends PartP2PTunnel> implements Iterable<T>
{
final Class clz;
Collection<T> tunnelSources;
private final Class clz;
private Collection<T> tunnelSources;
public TunnelCollection( final Collection<T> src, final Class c )
{
+12 -2
View File
@@ -26,12 +26,22 @@ import appeng.parts.p2p.PartP2PTunnelME;
public class TunnelConnection
{
public final PartP2PTunnelME tunnel;
public final IGridConnection c;
private final PartP2PTunnelME tunnel;
private final IGridConnection c;
public TunnelConnection( final PartP2PTunnelME t, final IGridConnection con )
{
this.tunnel = t;
this.c = con;
}
public IGridConnection getConnection()
{
return this.c;
}
public PartP2PTunnelME getTunnel()
{
return this.tunnel;
}
}
+3 -3
View File
@@ -28,9 +28,9 @@ import appeng.parts.p2p.PartP2PTunnel;
public class TunnelIterator<T extends PartP2PTunnel> implements Iterator<T>
{
final Iterator<T> wrapped;
final Class targetType;
T Next;
private final Iterator<T> wrapped;
private final Class targetType;
private T Next;
public TunnelIterator( final Collection<T> tunnelSources, final Class clz )
{