From de260b5283de4db0abc3105c503c644fd76b3257 Mon Sep 17 00:00:00 2001 From: yueh Date: Tue, 16 Jun 2015 13:38:39 +0200 Subject: [PATCH] Splitted channeldata into two ints Previously it did encode the current and previous used channels into the same as well as mask it with 0xFF. Which lead to an overflow every 256 gridnodes requiring a channel. This will not happen at > 2^31 Also removes the need to bitshift them for every access. Fixes #1510 --- src/main/java/appeng/me/GridNode.java | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main/java/appeng/me/GridNode.java b/src/main/java/appeng/me/GridNode.java index a7c3bb9f..f0d2813e 100644 --- a/src/main/java/appeng/me/GridNode.java +++ b/src/main/java/appeng/me/GridNode.java @@ -72,7 +72,8 @@ public class GridNode implements IGridNode, IPathItem private Object visitorIterationNumber = null; // connection criteria private int compressedData = 0; - private int channelData = 0; + private int usedChannels = 0; + private int lastUsedChannels = 0; public GridNode( IGridBlock what ) { @@ -91,7 +92,7 @@ public class GridNode implements IGridNode, IPathItem public int usedChannels() { - return this.channelData >> 8; + return this.lastUsedChannels; } public Class getMachineClass() @@ -359,7 +360,7 @@ public class GridNode implements IGridNode, IPathItem @Override public boolean meetsChannelRequirements() { - return ( !this.gridProxy.getFlags().contains( GridFlags.REQUIRE_CHANNEL ) || this.getUsedChannels() > 0 ); + return( !this.gridProxy.getFlags().contains( GridFlags.REQUIRE_CHANNEL ) || this.getUsedChannels() > 0 ); } @Override @@ -385,7 +386,7 @@ public class GridNode implements IGridNode, IPathItem public int getUsedChannels() { - return this.channelData & 0xff; + return this.usedChannels; } public void FindConnections() @@ -583,7 +584,7 @@ public class GridNode implements IGridNode, IPathItem public void setGridStorage( GridStorage s ) { this.myStorage = s; - this.channelData = 0; + this.usedChannels = 0; } @Override @@ -602,7 +603,7 @@ public class GridNode implements IGridNode, IPathItem { if( zeroOut ) { - this.channelData &= ~0xff; + this.usedChannels = 0; } int idx = this.connections.indexOf( fast ); @@ -633,7 +634,7 @@ public class GridNode implements IGridNode, IPathItem @Override public void incrementChannelCount( int usedChannels ) { - this.channelData += usedChannels; + this.usedChannels += usedChannels; } @Override @@ -652,8 +653,7 @@ public class GridNode implements IGridNode, IPathItem if( this.getLastUsedChannels() != this.getUsedChannels() ) { - this.channelData &= 0xff; - this.channelData |= this.channelData << 8; + this.lastUsedChannels = this.usedChannels; if( this.getInternalGrid() != null ) { @@ -664,7 +664,7 @@ public class GridNode implements IGridNode, IPathItem public int getLastUsedChannels() { - return ( this.channelData >> 8 ) & 0xff; + return lastUsedChannels; } private static class MachineSecurityBreak implements Callable @@ -685,7 +685,6 @@ public class GridNode implements IGridNode, IPathItem } } - private static class ConnectionComparator implements Comparator { private final IGridNode gn;