From eabc21e53c8a43ba430be49642b63d1615adb6f2 Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Thu, 28 Aug 2014 03:40:06 -0500 Subject: [PATCH] GridNode compress data into integer. --- me/GridNode.java | 56 ++++++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/me/GridNode.java b/me/GridNode.java index fb0261f9..1c397494 100644 --- a/me/GridNode.java +++ b/me/GridNode.java @@ -37,6 +37,7 @@ public class GridNode implements IGridNode, IPathItem { final static private MENetworkChannelsChanged event = new MENetworkChannelsChanged(); + final static private int channelCount[] = new int[] { 0, 8, 32 }; final List Connections = new LinkedList(); GridStorage myStorage = null; @@ -47,13 +48,42 @@ public class GridNode implements IGridNode, IPathItem Object visitorIterationNumber = null; // connection criteria - AEColor myColor = AEColor.Transparent; - EnumSet validDirections = EnumSet.noneOf( ForgeDirection.class ); + private int compressedData = 0; + + @Override + public void updateState() + { + EnumSet set = gridProxy.getFlags(); + + compressedData = set.contains( GridFlags.CANNOT_CARRY ) ? 0 : (set.contains( GridFlags.DENSE_CAPACITY ) ? 2 : 1); + + compressedData = compressedData | (gridProxy.getGridColor().ordinal() << 3); + + for (ForgeDirection dir : gridProxy.getConnectableSides()) + compressedData = compressedData | (1 << (dir.ordinal() + 8)); + + FindConnections(); + getInternalGrid(); + } + + public int getMaxChannels() + { + return channelCount[compressedData & 0x03]; + } + + public AEColor getColor() + { + return AEColor.values()[(compressedData >> 3) & 0x1F]; + } + + private boolean isValidDirection(ForgeDirection dir) + { + return (compressedData & (1 << (8 + dir.ordinal()))) > 0; + } // old power draw, used to diff public double previousDraw = 0.0; - private int maxChannels = 8; private int channelData = 0; public long lastSecurityKey = -1; @@ -71,11 +101,6 @@ public class GridNode implements IGridNode, IPathItem return channelData >> 8; } - public AEColor getColor() - { - return myColor; - } - public GridNode(IGridBlock what) { gridProxy = what; } @@ -137,17 +162,6 @@ public class GridNode implements IGridNode, IPathItem return gridProxy.getMachine(); } - @Override - public void updateState() - { - EnumSet set = gridProxy.getFlags(); - maxChannels = set.contains( GridFlags.CANNOT_CARRY ) ? 0 : (set.contains( GridFlags.DENSE_CAPACITY ) ? 32 : 8); - myColor = gridProxy.getGridColor(); - validDirections = gridProxy.getConnectableSides(); - FindConnections(); - getInternalGrid(); - } - @Override public void beginVisition(IGridVisitor g) { @@ -399,7 +413,7 @@ public class GridNode implements IGridNode, IPathItem public boolean canConnect(GridNode from, ForgeDirection dir) { - if ( !validDirections.contains( dir ) ) + if ( !isValidDirection( dir ) ) return false; if ( !from.getColor().matches( getColor() ) ) @@ -502,7 +516,7 @@ public class GridNode implements IGridNode, IPathItem @Override public boolean canSupportMoreChannels() { - return getUsedChannels() < maxChannels; + return getUsedChannels() < getMaxChannels(); } @Override