Relocate Source to proper directory.

This commit is contained in:
AlgorithmX2
2014-09-23 19:26:27 -05:00
parent fe927ce65d
commit 386d18a059
785 changed files with 35585 additions and 35580 deletions
@@ -0,0 +1,36 @@
package appeng.me.pathfinding;
import appeng.api.networking.IGridConnectionVisitor;
import appeng.api.networking.IGridConnection;
import appeng.api.networking.IGridNode;
import appeng.me.GridConnection;
import appeng.me.GridNode;
public class AdHocChannelUpdater implements IGridConnectionVisitor
{
final private int usedChannels;
public AdHocChannelUpdater(int used) {
usedChannels = used;
}
@Override
public boolean visitNode(IGridNode n)
{
GridNode gn = (GridNode) n;
gn.setControllerRoute( null, true );
gn.incrementChannelCount( usedChannels );
gn.finalizeChannels();
return true;
}
@Override
public void visitConnection(IGridConnection gcc)
{
GridConnection gc = (GridConnection) gcc;
gc.setControllerRoute( null, true );
gc.incrementChannelCount( usedChannels );
gc.finalizeChannels();
}
}
@@ -0,0 +1,26 @@
package appeng.me.pathfinding;
import appeng.api.networking.IGridConnectionVisitor;
import appeng.api.networking.IGridConnection;
import appeng.api.networking.IGridNode;
import appeng.me.GridConnection;
import appeng.me.GridNode;
public class ControllerChannelUpdater implements IGridConnectionVisitor
{
@Override
public boolean visitNode(IGridNode n)
{
GridNode gn = (GridNode) n;
gn.finalizeChannels();
return true;
}
@Override
public void visitConnection(IGridConnection gcc)
{
GridConnection gc = (GridConnection) gcc;
gc.finalizeChannels();
}
}
@@ -0,0 +1,59 @@
package appeng.me.pathfinding;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.networking.IGridVisitor;
import appeng.tile.networking.TileController;
public class ControllerValidator implements IGridVisitor
{
int minX;
int minY;
int minZ;
int maxX;
int maxY;
int maxZ;
public boolean isValid = true;
public int found = 0;
public ControllerValidator(int x, int y, int z) {
minX = x;
minY = y;
minZ = z;
maxX = x;
maxY = y;
maxZ = z;
}
@Override
public boolean visitNode(IGridNode n)
{
IGridHost host = n.getMachine();
if ( isValid && host instanceof TileController )
{
TileController c = (TileController) host;
minX = Math.min( c.xCoord, minX );
maxX = Math.max( c.xCoord, maxX );
minY = Math.min( c.yCoord, minY );
maxY = Math.max( c.yCoord, maxY );
minZ = Math.min( c.zCoord, minZ );
maxZ = Math.max( c.zCoord, maxZ );
if ( maxX - minX < 7 && maxY - minY < 7 && maxZ - minZ < 7 )
{
found++;
return true;
}
isValid = false;
}
else
return false;
return isValid;
}
}
@@ -0,0 +1,44 @@
package appeng.me.pathfinding;
import java.util.EnumSet;
import appeng.api.networking.GridFlags;
import appeng.api.util.IReadOnlyCollection;
public interface IPathItem
{
IPathItem getControllerRoute();
void setControllerRoute(IPathItem fast, boolean zeroOut);
/**
* used to determine if the finder can continue.
*/
boolean canSupportMoreChannels();
/**
* find possible choices for other pathing.
*/
IReadOnlyCollection<IPathItem> getPossibleOptions();
/**
* add one to the channel count, this is mostly for cables.
*/
void incrementChannelCount(int usedChannels);
/**
* get the grid flags for this IPathItem.
*
* @return the flag set.
*/
public EnumSet<GridFlags> getFlags();
/**
* channels are done, wrap it up.
*
* @return
*/
void finalizeChannels();
}
@@ -0,0 +1,141 @@
package appeng.me.pathfinding;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import appeng.api.networking.GridFlags;
import appeng.api.networking.IGridMultiblock;
import appeng.api.networking.IGridNode;
import appeng.me.cache.PathGridCache;
public class PathSegment
{
public boolean isDead;
static class RouteComplete extends Exception
{
private static final long serialVersionUID = 810456465120286110L;
};
PathGridCache pgc;
public PathSegment(PathGridCache myPGC, List open, Set semiopen, Set closed)
{
this.open = open;
this.semiopen = semiopen;
this.closed = closed;
pgc = myPGC;
isDead = false;
}
List<IPathItem> open;
Set<IPathItem> semiopen;
Set<IPathItem> closed;
public boolean step()
{
List<IPathItem> oldOpen = open;
open = new LinkedList();
for (IPathItem i : oldOpen)
{
for (IPathItem pi : i.getPossibleOptions())
{
EnumSet<GridFlags> flags = pi.getFlags();
if ( !closed.contains( pi ) )
{
pi.setControllerRoute( i, true );
if ( flags.contains( GridFlags.REQUIRE_CHANNEL ) )
{
// close the semi open.
if ( !semiopen.contains( pi ) )
{
boolean worked = false;
if ( flags.contains( GridFlags.COMPRESSED_CHANNEL ) )
worked = useDenseChannel( pi );
else
worked = useChannel( pi );
if ( worked && flags.contains( GridFlags.MULTIBLOCK ) )
{
Iterator<IGridNode> oni = ((IGridMultiblock) ((IGridNode) pi).getGridBlock()).getMultiblockNodes();
while (oni.hasNext())
{
IGridNode otherNodes = oni.next();
if ( otherNodes != pi )
semiopen.add( (IPathItem) otherNodes );
}
}
}
else
{
pi.incrementChannelCount( 1 ); // give a channel.
semiopen.remove( pi );
}
}
closed.add( pi );
open.add( pi );
}
}
}
return open.isEmpty();
}
private boolean useChannel(IPathItem start)
{
IPathItem pi = start;
while (pi != null)
{
if ( !pi.canSupportMoreChannels() )
return false;
pi = pi.getControllerRoute();
}
pi = start;
while (pi != null)
{
pgc.channelsByBlocks++;
pi.incrementChannelCount( 1 );
pi = pi.getControllerRoute();
}
pgc.channelsInUse++;
return true;
}
private boolean useDenseChannel(IPathItem start)
{
IPathItem pi = start;
while (pi != null)
{
if ( !pi.canSupportMoreChannels() || pi.getFlags().contains( GridFlags.CANNOT_CARRY_COMPRESSED ) )
return false;
pi = pi.getControllerRoute();
}
pi = start;
while (pi != null)
{
pgc.channelsByBlocks++;
pi.incrementChannelCount( 1 );
pi = pi.getControllerRoute();
}
pgc.channelsInUse++;
return true;
}
}