Basic reformat, hit once, hope never again
This commit is contained in:
+125
-130
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.me.cache;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@@ -36,31 +37,138 @@ import appeng.me.cluster.implementations.SpatialPylonCluster;
|
||||
import appeng.tile.spatial.TileSpatialIOPort;
|
||||
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;
|
||||
|
||||
final IGrid myGrid;
|
||||
|
||||
public SpatialPylonCache(IGrid g) {
|
||||
public SpatialPylonCache( IGrid g )
|
||||
{
|
||||
this.myGrid = g;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long requiredPower()
|
||||
@MENetworkEventSubscribe
|
||||
public void bootingRender( MENetworkBootingStatusChange c )
|
||||
{
|
||||
return this.powerRequired;
|
||||
this.reset( this.myGrid );
|
||||
}
|
||||
|
||||
public void reset( IGrid grid )
|
||||
{
|
||||
int reqX = 0;
|
||||
int reqY = 0;
|
||||
int reqZ = 0;
|
||||
int requirePylonBlocks = 1;
|
||||
|
||||
double minPower = 0;
|
||||
double maxPower = 0;
|
||||
|
||||
this.clusters = new HashMap<SpatialPylonCluster, SpatialPylonCluster>();
|
||||
this.ioPorts = new LinkedList<TileSpatialIOPort>();
|
||||
|
||||
for( IGridNode gm : grid.getMachines( TileSpatialIOPort.class ) )
|
||||
{
|
||||
this.ioPorts.add( (TileSpatialIOPort) gm.getMachine() );
|
||||
}
|
||||
|
||||
IReadOnlyCollection<IGridNode> set = grid.getMachines( TileSpatialPylon.class );
|
||||
for( IGridNode gm : set )
|
||||
{
|
||||
if( gm.meetsChannelRequirements() )
|
||||
{
|
||||
SpatialPylonCluster c = ( (TileSpatialPylon) gm.getMachine() ).getCluster();
|
||||
if( c != null )
|
||||
this.clusters.put( c, c );
|
||||
}
|
||||
}
|
||||
|
||||
this.captureMax = null;
|
||||
this.captureMin = null;
|
||||
this.isValid = true;
|
||||
|
||||
int pylonBlocks = 0;
|
||||
for( SpatialPylonCluster cl : this.clusters.values() )
|
||||
{
|
||||
if( this.captureMax == null )
|
||||
this.captureMax = cl.max.copy();
|
||||
if( this.captureMin == null )
|
||||
this.captureMin = cl.min.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.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 );
|
||||
}
|
||||
|
||||
if( this.hasRegion() )
|
||||
{
|
||||
this.isValid = this.captureMax.x - this.captureMin.x > 1 && this.captureMax.y - this.captureMin.y > 1 && this.captureMax.z - this.captureMin.z > 1;
|
||||
|
||||
for( SpatialPylonCluster cl : this.clusters.values() )
|
||||
{
|
||||
switch( cl.currentAxis )
|
||||
{
|
||||
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 ) );
|
||||
|
||||
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 ) );
|
||||
|
||||
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 ) );
|
||||
|
||||
break;
|
||||
case UNFORMED:
|
||||
this.isValid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
reqX = this.captureMax.x - this.captureMin.x;
|
||||
reqY = this.captureMax.y - this.captureMin.y;
|
||||
reqZ = this.captureMax.z - this.captureMin.z;
|
||||
requirePylonBlocks = Math.max( 6, ( ( reqX * reqZ + reqX * reqY + reqY * reqZ ) * 3 ) / 8 );
|
||||
|
||||
this.efficiency = (double) pylonBlocks / (double) requirePylonBlocks;
|
||||
|
||||
if( this.efficiency > 1.0 )
|
||||
this.efficiency = 1.0;
|
||||
if( this.efficiency < 0.0 )
|
||||
this.efficiency = 0.0;
|
||||
|
||||
minPower = (double) reqX * (double) reqY * reqZ * AEConfig.instance.spatialPowerMultiplier;
|
||||
maxPower = Math.pow( minPower, AEConfig.instance.spatialPowerExponent );
|
||||
}
|
||||
|
||||
double affective_efficiency = Math.pow( this.efficiency, 0.25 );
|
||||
this.powerRequired = (long) ( affective_efficiency * minPower + ( 1.0 - affective_efficiency ) * maxPower );
|
||||
|
||||
for( SpatialPylonCluster cl : this.clusters.values() )
|
||||
{
|
||||
boolean myWasValid = cl.isValid;
|
||||
cl.isValid = this.isValid;
|
||||
if( myWasValid != this.isValid )
|
||||
cl.updateStatus( false );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -87,116 +195,10 @@ public class SpatialPylonCache implements ISpatialCache
|
||||
return this.captureMax;
|
||||
}
|
||||
|
||||
public void reset(IGrid grid)
|
||||
@Override
|
||||
public long requiredPower()
|
||||
{
|
||||
int reqX = 0;
|
||||
int reqY = 0;
|
||||
int reqZ = 0;
|
||||
int requirePylonBlocks = 1;
|
||||
|
||||
double minPower = 0;
|
||||
double maxPower = 0;
|
||||
|
||||
this.clusters = new HashMap<SpatialPylonCluster, SpatialPylonCluster>();
|
||||
this.ioPorts = new LinkedList<TileSpatialIOPort>();
|
||||
|
||||
for (IGridNode gm : grid.getMachines( TileSpatialIOPort.class ))
|
||||
{
|
||||
this.ioPorts.add( (TileSpatialIOPort) gm.getMachine() );
|
||||
}
|
||||
|
||||
IReadOnlyCollection<IGridNode> set = grid.getMachines( TileSpatialPylon.class );
|
||||
for (IGridNode gm : set)
|
||||
{
|
||||
if ( gm.meetsChannelRequirements() )
|
||||
{
|
||||
SpatialPylonCluster c = ((TileSpatialPylon) gm.getMachine()).getCluster();
|
||||
if ( c != null )
|
||||
this.clusters.put( c, c );
|
||||
}
|
||||
}
|
||||
|
||||
this.captureMax = null;
|
||||
this.captureMin = null;
|
||||
this.isValid = true;
|
||||
|
||||
int pylonBlocks = 0;
|
||||
for (SpatialPylonCluster cl : this.clusters.values())
|
||||
{
|
||||
if ( this.captureMax == null )
|
||||
this.captureMax = cl.max.copy();
|
||||
if ( this.captureMin == null )
|
||||
this.captureMin = cl.min.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.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 );
|
||||
}
|
||||
|
||||
if ( this.hasRegion() )
|
||||
{
|
||||
this.isValid = this.captureMax.x - this.captureMin.x > 1 && this.captureMax.y - this.captureMin.y > 1 && this.captureMax.z - this.captureMin.z > 1;
|
||||
|
||||
for (SpatialPylonCluster cl : this.clusters.values())
|
||||
{
|
||||
switch (cl.currentAxis)
|
||||
{
|
||||
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));
|
||||
|
||||
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));
|
||||
|
||||
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));
|
||||
|
||||
break;
|
||||
case UNFORMED:
|
||||
this.isValid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
reqX = this.captureMax.x - this.captureMin.x;
|
||||
reqY = this.captureMax.y - this.captureMin.y;
|
||||
reqZ = this.captureMax.z - this.captureMin.z;
|
||||
requirePylonBlocks = Math.max( 6, ((reqX * reqZ + reqX * reqY + reqY * reqZ) * 3) / 8 );
|
||||
|
||||
this.efficiency = (double) pylonBlocks / (double) requirePylonBlocks;
|
||||
|
||||
if ( this.efficiency > 1.0 )
|
||||
this.efficiency = 1.0;
|
||||
if ( this.efficiency < 0.0 )
|
||||
this.efficiency = 0.0;
|
||||
|
||||
minPower = (double) reqX * (double) reqY * reqZ * AEConfig.instance.spatialPowerMultiplier;
|
||||
maxPower = Math.pow( minPower, AEConfig.instance.spatialPowerExponent );
|
||||
}
|
||||
|
||||
double affective_efficiency = Math.pow( this.efficiency, 0.25 );
|
||||
this.powerRequired = (long) (affective_efficiency * minPower + (1.0 - affective_efficiency) * maxPower);
|
||||
|
||||
for (SpatialPylonCluster cl : this.clusters.values())
|
||||
{
|
||||
boolean myWasValid = cl.isValid;
|
||||
cl.isValid = this.isValid;
|
||||
if ( myWasValid != this.isValid )
|
||||
cl.updateStatus( false );
|
||||
}
|
||||
return this.powerRequired;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -205,45 +207,38 @@ public class SpatialPylonCache implements ISpatialCache
|
||||
return (float) this.efficiency * 100;
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void bootingRender(MENetworkBootingStatusChange c)
|
||||
{
|
||||
this.reset( this.myGrid );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateTick()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNode(IGridNode node, IGridHost machine)
|
||||
public void removeNode( IGridNode node, IGridHost machine )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeNode(IGridNode node, IGridHost machine)
|
||||
public void addNode( IGridNode node, IGridHost machine )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSplit(IGridStorage storageB)
|
||||
public void onSplit( IGridStorage storageB )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onJoin(IGridStorage storageB)
|
||||
public void onJoin( IGridStorage storageB )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populateGridStorage(IGridStorage storage)
|
||||
public void populateGridStorage( IGridStorage storage )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user