Code improvements.
This commit is contained in:
@ -49,10 +49,7 @@ public abstract class AbstractNode<Loc extends AbstractNodeLoc>
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = (prime * result) + ((_loc == null) ? 0 : _loc.hashCode());
|
||||
return result;
|
||||
return (31 * 1) + ((_loc == null) ? 0 : _loc.hashCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -30,13 +30,7 @@ public abstract class PathFinding
|
||||
{
|
||||
public static PathFinding getInstance()
|
||||
{
|
||||
if (Config.PATHFINDING == 1)
|
||||
{
|
||||
// Higher Memory Usage, Smaller Cpu Usage
|
||||
return GeoPathFinding.getInstance();
|
||||
}
|
||||
// Cell pathfinding, calculated directly from geodata files
|
||||
return CellPathFinding.getInstance();
|
||||
return Config.PATHFINDING == 1 ? GeoPathFinding.getInstance() : CellPathFinding.getInstance();
|
||||
}
|
||||
|
||||
public abstract boolean pathNodesExist(short regionoffset);
|
||||
|
@ -176,43 +176,33 @@ public class CellNodeBuffer
|
||||
nodeN = addNode(x, y - 1, z, false);
|
||||
}
|
||||
|
||||
if (Config.ADVANCED_DIAGONAL_STRATEGY)
|
||||
if (!Config.ADVANCED_DIAGONAL_STRATEGY)
|
||||
{
|
||||
// SouthEast
|
||||
if ((nodeE != null) && (nodeS != null))
|
||||
{
|
||||
if (nodeE.getLoc().canGoSouth() && nodeS.getLoc().canGoEast())
|
||||
{
|
||||
addNode(x + 1, y + 1, z, true);
|
||||
}
|
||||
}
|
||||
|
||||
// SouthWest
|
||||
if ((nodeS != null) && (nodeW != null))
|
||||
{
|
||||
if (nodeW.getLoc().canGoSouth() && nodeS.getLoc().canGoWest())
|
||||
{
|
||||
addNode(x - 1, y + 1, z, true);
|
||||
}
|
||||
}
|
||||
|
||||
// NorthEast
|
||||
if ((nodeN != null) && (nodeE != null))
|
||||
{
|
||||
if (nodeE.getLoc().canGoNorth() && nodeN.getLoc().canGoEast())
|
||||
{
|
||||
addNode(x + 1, y - 1, z, true);
|
||||
}
|
||||
}
|
||||
|
||||
// NorthWest
|
||||
if ((nodeN != null) && (nodeW != null))
|
||||
{
|
||||
if (nodeW.getLoc().canGoNorth() && nodeN.getLoc().canGoWest())
|
||||
{
|
||||
addNode(x - 1, y - 1, z, true);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// SouthEast
|
||||
if ((nodeE != null) && (nodeS != null) && nodeE.getLoc().canGoSouth() && nodeS.getLoc().canGoEast())
|
||||
{
|
||||
addNode(x + 1, y + 1, z, true);
|
||||
}
|
||||
|
||||
// SouthWest
|
||||
if ((nodeS != null) && (nodeW != null) && nodeW.getLoc().canGoSouth() && nodeS.getLoc().canGoWest())
|
||||
{
|
||||
addNode(x - 1, y + 1, z, true);
|
||||
}
|
||||
|
||||
// NorthEast
|
||||
if ((nodeN != null) && (nodeE != null) && nodeE.getLoc().canGoNorth() && nodeN.getLoc().canGoEast())
|
||||
{
|
||||
addNode(x + 1, y - 1, z, true);
|
||||
}
|
||||
|
||||
// NorthWest
|
||||
if ((nodeN != null) && (nodeW != null) && nodeW.getLoc().canGoNorth() && nodeN.getLoc().canGoWest())
|
||||
{
|
||||
addNode(x - 1, y - 1, z, true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -323,21 +313,7 @@ public class CellNodeBuffer
|
||||
private final boolean isHighWeight(int x, int y, int z)
|
||||
{
|
||||
final CellNode result = getNode(x, y, z);
|
||||
if (result == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!result.getLoc().canGoAll())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (Math.abs(result.getLoc().getZ() - z) > 16)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return (result == null) || !result.getLoc().canGoAll() || (Math.abs(result.getLoc().getZ() - z) > 16);
|
||||
}
|
||||
|
||||
private final double getCost(int x, int y, int z, float weight)
|
||||
|
@ -330,8 +330,7 @@ public class GeoPathFinding extends PathFinding
|
||||
neighbors.add(newNode);
|
||||
}
|
||||
}
|
||||
final GeoNode[] result = new GeoNode[neighbors.size()];
|
||||
return neighbors.toArray(result);
|
||||
return neighbors.toArray(new GeoNode[neighbors.size()]);
|
||||
}
|
||||
|
||||
// Private
|
||||
@ -410,9 +409,7 @@ public class GeoPathFinding extends PathFinding
|
||||
return;
|
||||
}
|
||||
|
||||
final byte rx = Byte.parseByte(parts[0]);
|
||||
final byte ry = Byte.parseByte(parts[1]);
|
||||
LoadPathNodeFile(rx, ry);
|
||||
LoadPathNodeFile(Byte.parseByte(parts[0]), Byte.parseByte(parts[1]));
|
||||
});
|
||||
//@formatter:on
|
||||
}
|
||||
|
Reference in New Issue
Block a user