fix dminer performance

This commit is contained in:
Vadim Lopatin 2017-06-23 16:37:42 +03:00
parent 12c7c3a4be
commit 2e540d1809
3 changed files with 13 additions and 7 deletions

View File

@ -6,7 +6,7 @@ import dminer.core.world;
import dlangui.graphics.scene.mesh;
//version = FAST_VISIBILITY_PATH;
version = FAST_VISIBILITY_PATH;
// Y range: 0..CHUNK_DY-1
immutable int CHUNK_DY = 128;
@ -1529,6 +1529,7 @@ struct VisibilityCheckIterator {
Vector3d camPos;
SmallChunk * startChunk;
ChunkVisitor visitor;
int maxHeight;
int maxDistance;
int maxDistanceSquared;
VisibilityCheckChunk[] plannedChunks;
@ -1549,17 +1550,19 @@ struct VisibilityCheckIterator {
// mask test
if (!mask)
return;
if (p.y > maxHeight + 16 && p.y > startPos.y)
return;
// distance test
Vector3d diff = (p + Vector3d(4,4,4)) - camPos;
if (diff.squaredLength() > maxDistanceSquared)
return;
int distance = diff.squaredLength;
if (distance > 10*10) {
if (distance > 16*16) {
diff = (diff * 256 + cameraDirection * 16) / 256;
//diff += cameraDirection;
// direction test (TODO)
int dot = diff.dot(cameraDirection);
if (dot < 12000)
if (dot < 8000)
return;
}
//....
@ -1619,6 +1622,9 @@ struct VisibilityCheckIterator {
visitedChunks.length = 0;
maxDistanceSquared = maxDistance * maxDistance;
this.maxDistance = maxDistance;
maxHeight = world.regionHeight(startPos.x, startPos.z, maxDistance + 8) & 0xFFFFFF8 + 7;
import dlangui.core.logger;
Log.d("startPos: ", startPos, " maxHeight:", maxHeight);
}
Vector3d cameraDirection;
void visitVisibleChunks(ChunkVisitor visitor, Vector3d cameraDirection) {

View File

@ -178,7 +178,7 @@ class World {
/// get max Y position of non-empty cell in region (x +- size, z +- size)
int regionHeight(int x, int z, int size) {
int top = -1;
int delta = size / 8 + 1;
int delta = size + 1;
for (int dx = x - delta; dx <= x + delta; dx += 8) {
for (int dz = z - delta; dz <= z + delta; dz += 8) {
if (ChunkStack * stack = getCellChunkStack(x, z)) {

View File

@ -132,9 +132,9 @@ class MinerDrawable : MaterialDrawableObject, ChunkVisitor {
float camDist = (_camPosition - chunkPos).length;
vec3 chunkDirection = (chunkPos - (_camPosition - (_camForwardVector * 12))).normalized;
float dot = _camForwardVector.dot(chunkDirection);
float threshold = 0.87;
if (camDist < 12)
threshold = 0.5;
float threshold = 0.80;
if (camDist < 16)
threshold = 0.2;
//Log.d("visit() chunkPos ", chunkPos, " chunkDir ", chunkDirection, " camDir ", " dot ", dot, " threshold ", threshold);
if (dot < threshold) { // cos(45)