Skip to content

Commit

Permalink
Fix using power of regionSize where actual regionSize value should be…
Browse files Browse the repository at this point in the history
… used.

Signed-off-by: Ross Allan <rallanpcl@gmail.com>
  • Loading branch information
LunNova committed Jul 3, 2013
1 parent 492676c commit b77fa0c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 7 additions & 6 deletions src/common/nallar/tickthreading/minecraft/TickManager.java
Expand Up @@ -40,7 +40,8 @@ public final class TickManager {
private static final byte lockXMinus = 1 << 2;
private static final byte lockZPlus = 1 << 3;
private static final byte lockZMinus = 1 << 4;
public static final int regionSize = 31 - Integer.numberOfLeadingZeros(TickThreading.instance.regionSize);
public static final int regionSize = TickThreading.instance.regionSize;
public static final int regionSizePower = 31 - Integer.numberOfLeadingZeros(regionSize);
public boolean profilingEnabled = false;
private double averageTickLength = 0;
private long lastTickLength = 0;
Expand Down Expand Up @@ -73,8 +74,8 @@ public TileEntityTickRegion getTileEntityRegion(int hashCode) {

@SuppressWarnings ("NumericCastThatLosesPrecision")
private TileEntityTickRegion getOrCreateRegion(TileEntity tileEntity) {
int regionX = tileEntity.xCoord >> regionSize;
int regionZ = tileEntity.zCoord >> regionSize;
int regionX = tileEntity.xCoord >> regionSizePower;
int regionZ = tileEntity.zCoord >> regionSizePower;
int hashCode = getHashCodeFromRegionCoords(regionX, regionZ);
TileEntityTickRegion callable = tileEntityCallables.get(hashCode);
if (callable == null) {
Expand All @@ -96,8 +97,8 @@ public EntityTickRegion getEntityRegion(int hashCode) {

@SuppressWarnings ("NumericCastThatLosesPrecision")
private EntityTickRegion getOrCreateRegion(Entity entity) {
int regionX = (entity.chunkCoordX << 4) >> regionSize;
int regionZ = (entity.chunkCoordZ << 4) >> regionSize;
int regionX = (entity.chunkCoordX << 4) >> regionSizePower;
int regionZ = (entity.chunkCoordZ << 4) >> regionSizePower;
int hashCode = getHashCodeFromRegionCoords(regionX, regionZ);
EntityTickRegion callable = entityCallables.get(hashCode);
if (callable == null) {
Expand All @@ -122,7 +123,7 @@ public static int getHashCode(Entity entity) {
}

public static int getHashCode(int x, int z) {
return getHashCodeFromRegionCoords(x >> regionSize, z >> regionSize);
return getHashCodeFromRegionCoords(x >> regionSizePower, z >> regionSizePower);
}

public static int getHashCodeFromRegionCoords(int x, int z) {
Expand Down
Expand Up @@ -53,8 +53,8 @@ public float getAverageTickTime() {
public TableFormatter writeStats(TableFormatter tf) {
return tf
.row(this.getShortTypeName())
.row(regionX * manager.regionSize)
.row(regionZ * manager.regionSize)
.row(regionX * TickManager.regionSize)
.row(regionZ * TickManager.regionSize)
.row(size())
.row(getAverageTickTime());
}
Expand Down

0 comments on commit b77fa0c

Please sign in to comment.