removed couple Math.floorDiv and Mod as for positive inputs they are slower and give the same result as standard operands
This commit is contained in:
@@ -243,8 +243,8 @@ public class LodBufferBuilder
|
||||
if (lodDim.doesRegionNeedBufferRegen(xRegion, zRegion) || fullRegen)
|
||||
{
|
||||
RegionPos regionPos = new RegionPos(
|
||||
xRegion + lodDim.getCenterRegionPosX() - Math.floorDiv(lodDim.getWidth(), 2),
|
||||
zRegion + lodDim.getCenterRegionPosZ() - Math.floorDiv(lodDim.getWidth(), 2));
|
||||
xRegion + lodDim.getCenterRegionPosX() - lodDim.getWidth() / 2,
|
||||
zRegion + lodDim.getCenterRegionPosZ() - lodDim.getWidth() / 2);
|
||||
|
||||
// local position in the vbo and bufferBuilder arrays
|
||||
BufferBuilder[] currentBuffers = buildableBuffers[xRegion][zRegion];
|
||||
@@ -311,7 +311,7 @@ public class LodBufferBuilder
|
||||
|
||||
for (int index = 0; index < posToRender.getNumberOfPos(); index++)
|
||||
{
|
||||
bufferIndex = Math.floorMod(index, currentBuffers.length);
|
||||
bufferIndex = index % currentBuffers.length;
|
||||
detailLevel = posToRender.getNthDetailLevel(index);
|
||||
posX = posToRender.getNthPosX(index);
|
||||
posZ = posToRender.getNthPosZ(index);
|
||||
|
||||
@@ -34,6 +34,7 @@ import com.seibel.lod.enums.VerticalQuality;
|
||||
import com.seibel.lod.objects.LodDimension;
|
||||
import com.seibel.lod.objects.LodRegion;
|
||||
import com.seibel.lod.objects.LodWorld;
|
||||
import com.seibel.lod.proxy.ClientProxy;
|
||||
import com.seibel.lod.util.ColorUtil;
|
||||
import com.seibel.lod.util.DataPointUtil;
|
||||
import com.seibel.lod.util.DetailDistanceUtil;
|
||||
@@ -204,6 +205,7 @@ public class LodBuilder
|
||||
{
|
||||
if (chunk == null)
|
||||
throw new IllegalArgumentException("generateLodFromChunk given a null chunk");
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
int startX;
|
||||
int startZ;
|
||||
@@ -216,13 +218,12 @@ public class LodBuilder
|
||||
return;
|
||||
|
||||
// determine how many LODs to generate horizontally
|
||||
HorizontalResolution detail;
|
||||
byte minDetailLevel = region.getMinDetailLevel();
|
||||
detail = DetailDistanceUtil.getLodGenDetail(minDetailLevel);
|
||||
HorizontalResolution detail = DetailDistanceUtil.getLodGenDetail(minDetailLevel);
|
||||
|
||||
|
||||
// determine how many LODs to generate vertically
|
||||
VerticalQuality verticalQuality = LodConfig.CLIENT.graphics.qualityOption.verticalQuality.get();
|
||||
//VerticalQuality verticalQuality = LodConfig.CLIENT.graphics.qualityOption.verticalQuality.get();
|
||||
byte detailLevel = detail.detailLevel;
|
||||
|
||||
|
||||
@@ -236,10 +237,6 @@ public class LodBuilder
|
||||
endX = detail.endX[i];
|
||||
endZ = detail.endZ[i];
|
||||
|
||||
posX = LevelPosUtil.convert((byte) 0, chunk.getPos().x * 16 + startX, detail.detailLevel);
|
||||
posZ = LevelPosUtil.convert((byte) 0, chunk.getPos().z * 16 + startZ, detail.detailLevel);
|
||||
|
||||
|
||||
long[] data;
|
||||
long[] dataToMergeVertical = createVerticalDataToMerge(detail, chunk, config, startX, startZ, endX, endZ);
|
||||
data = DataPointUtil.mergeMultiData(dataToMergeVertical, DataPointUtil.worldHeight, DetailDistanceUtil.getMaxVerticalData(detailLevel));
|
||||
@@ -247,9 +244,16 @@ public class LodBuilder
|
||||
|
||||
//lodDim.clear(detailLevel, posX, posZ);
|
||||
if (data != null && data.length != 0)
|
||||
lodDim.addVerticalData(detailLevel, posX, posZ, data,false);
|
||||
{
|
||||
posX = LevelPosUtil.convert((byte) 0, chunk.getPos().x * 16 + startX, detail.detailLevel);
|
||||
posZ = LevelPosUtil.convert((byte) 0, chunk.getPos().z * 16 + startZ, detail.detailLevel);
|
||||
lodDim.addVerticalData(detailLevel, posX, posZ, data, false);
|
||||
}
|
||||
}
|
||||
lodDim.updateData(LodUtil.CHUNK_DETAIL_LEVEL, chunk.getPos().x, chunk.getPos().z);
|
||||
|
||||
startTime = System.currentTimeMillis() - startTime;
|
||||
ClientProxy.LOGGER.info("gen time: " + startTime + " ms.");
|
||||
}
|
||||
|
||||
/** creates a vertical DataPoint */
|
||||
@@ -284,8 +288,8 @@ public class LodBuilder
|
||||
|
||||
for (index = 0; index < size * size; index++)
|
||||
{
|
||||
xRel = Math.floorMod(index, size) + startX;
|
||||
zRel = Math.floorDiv(index, size) + startZ;
|
||||
xRel = startX + index % size;
|
||||
zRel = startZ + index / size;
|
||||
xAbs = chunkPos.getMinBlockX() + xRel;
|
||||
zAbs = chunkPos.getMinBlockZ() + zRel;
|
||||
|
||||
|
||||
@@ -866,7 +866,7 @@ public class LodDimension
|
||||
public void setRegionWidth(int newWidth)
|
||||
{
|
||||
width = newWidth;
|
||||
halfWidth = Math.floorDiv(width, 2);
|
||||
halfWidth = width/ 2;
|
||||
|
||||
regions = new LodRegion[width][width];
|
||||
isRegionDirty = new boolean[width][width];
|
||||
|
||||
@@ -97,12 +97,13 @@ public class DetailDistanceUtil
|
||||
return (byte) minDetail;
|
||||
int distanceUnit = LodConfig.CLIENT.graphics.qualityOption.horizontalScale.get().distanceUnit;
|
||||
if (LodConfig.CLIENT.graphics.qualityOption.horizontalQuality.get() == HorizontalQuality.LOWEST)
|
||||
detail = (byte) Math.floorDiv(distance, distanceUnit);
|
||||
detail = (byte) distance / distanceUnit;
|
||||
else
|
||||
{
|
||||
double base = LodConfig.CLIENT.graphics.qualityOption.horizontalQuality.get().quadraticBase;
|
||||
double logBase = Math.log(base);
|
||||
detail = (byte) (Math.log(Math.floorDiv(distance, distanceUnit)) / logBase);
|
||||
//noinspection IntegerDivisionInFloatingPointContext
|
||||
detail = (byte) (Math.log(distance / distanceUnit) / logBase);
|
||||
}
|
||||
return (byte) LodUtil.clamp(minDetail, detail, maxDetail - 1);
|
||||
}
|
||||
|
||||
@@ -201,8 +201,8 @@ public class LodUtil
|
||||
/** Convert a 2D absolute position into a quad tree relative position. */
|
||||
public static RegionPos convertGenericPosToRegionPos(int x, int z, int detailLevel)
|
||||
{
|
||||
int relativePosX = Math.floorDiv(x, (int) Math.pow(2, LodUtil.REGION_DETAIL_LEVEL - detailLevel));
|
||||
int relativePosZ = Math.floorDiv(z, (int) Math.pow(2, LodUtil.REGION_DETAIL_LEVEL - detailLevel));
|
||||
int relativePosX = Math.floorDiv(x, 1 << (LodUtil.REGION_DETAIL_LEVEL - detailLevel));
|
||||
int relativePosZ = Math.floorDiv(z, 1 << (LodUtil.REGION_DETAIL_LEVEL - detailLevel));
|
||||
|
||||
return new RegionPos(relativePosX, relativePosZ);
|
||||
}
|
||||
@@ -210,7 +210,7 @@ public class LodUtil
|
||||
/** Convert a 2D absolute position into a quad tree relative position. */
|
||||
public static int convertLevelPos(int pos, int currentDetailLevel, int targetDetailLevel)
|
||||
{
|
||||
return Math.floorDiv(pos, (int) Math.pow(2, targetDetailLevel - currentDetailLevel));
|
||||
return pos / (1 << (targetDetailLevel - currentDetailLevel));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -128,7 +128,7 @@ public class ThreadMapUtil
|
||||
int size = 1;
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
array[i] = new long[size * size * DataPointUtil.worldHeight + 1];
|
||||
array[i] = new long[size * size * DataPointUtil.worldHeight + 1];//TODO do we need +1?
|
||||
size = size << 1;
|
||||
}
|
||||
threadBuilderVerticalArrayMap.put(Thread.currentThread().getName(), array);
|
||||
|
||||
Reference in New Issue
Block a user