Add optimization on getPosToGenerate.

This commit is contained in:
tom lee
2022-01-23 19:08:19 +08:00
parent a5a4a3e6e2
commit e9e2af2807
3 changed files with 29 additions and 1 deletions
@@ -138,6 +138,16 @@ public class PosToGenerateContainer
return farSize;
}
public int getMaxNumberOfNearPos()
{
return nearPosToGenerate.length;
}
public int getMaxNumberOfFarPos()
{
return farPosToGenerate.length;
}
// TODO what does getNth mean? could the name be more descriptive or is it just a index?
public int getNthDetail(int n, boolean near)
{
@@ -473,6 +473,7 @@ public class LodDimension
}
if (updated) {
region.needRegenBuffer = 2;
region.needRecheckGenPoint = true;
regenDimensionBuffers = true;
}
});
@@ -534,9 +535,23 @@ public class LodDimension
//boolean isCloseRange = true;
//All of this is handled directly by the region, which scan every pos from top to bottom of the quad tree
LodRegion lodRegion = regions[x][z];
if (lodRegion != null)
if (lodRegion != null && lodRegion.needRecheckGenPoint) {
int nearCount = posToGenerate.getNumberOfNearPos();
int farCount = posToGenerate.getNumberOfFarPos();
boolean checkForFlag = (nearCount < posToGenerate.getMaxNumberOfNearPos() && farCount < posToGenerate.getMaxNumberOfFarPos());
if (checkForFlag) {
lodRegion.needRecheckGenPoint = false;
}
lodRegion.getPosToGenerate(posToGenerate, playerBlockPosX, playerBlockPosZ, allowedPriority, genMode,
isCloseRange);
if (checkForFlag) {
if (nearCount != posToGenerate.getNumberOfNearPos() || farCount != posToGenerate.getNumberOfFarPos()) {
lodRegion.needRecheckGenPoint = true;
}
}
}
});
return posToGenerate;
}
@@ -67,6 +67,7 @@ public class LodRegion {
/** this region's z RegionPos */
public final int regionPosZ;
public volatile boolean needRecheckGenPoint = true;
public volatile int needRegenBuffer = 2;
public volatile boolean needSaving = false;
public volatile int isWriting = 0;
@@ -532,6 +533,7 @@ public class LodRegion {
minDetailLevel = levelContainer.getDetailLevel();
dataContainer[levelContainer.getDetailLevel()] = levelContainer;
needRecheckGenPoint = true;
}
// TODO James thinks cutTree and growTree (which he renamed to match cutTree)
@@ -564,6 +566,7 @@ public class LodRegion {
dataContainer[detailLevelIndex] = dataContainer[detailLevelIndex + 1].expand();
}
minDetailLevel = detailLevel;
needRecheckGenPoint = true;
}
}