mirror of https://github.com/buggins/dlangui.git
fix dminer performance
This commit is contained in:
parent
12c7c3a4be
commit
2e540d1809
|
|
@ -6,7 +6,7 @@ import dminer.core.world;
|
||||||
import dlangui.graphics.scene.mesh;
|
import dlangui.graphics.scene.mesh;
|
||||||
|
|
||||||
|
|
||||||
//version = FAST_VISIBILITY_PATH;
|
version = FAST_VISIBILITY_PATH;
|
||||||
|
|
||||||
// Y range: 0..CHUNK_DY-1
|
// Y range: 0..CHUNK_DY-1
|
||||||
immutable int CHUNK_DY = 128;
|
immutable int CHUNK_DY = 128;
|
||||||
|
|
@ -1529,6 +1529,7 @@ struct VisibilityCheckIterator {
|
||||||
Vector3d camPos;
|
Vector3d camPos;
|
||||||
SmallChunk * startChunk;
|
SmallChunk * startChunk;
|
||||||
ChunkVisitor visitor;
|
ChunkVisitor visitor;
|
||||||
|
int maxHeight;
|
||||||
int maxDistance;
|
int maxDistance;
|
||||||
int maxDistanceSquared;
|
int maxDistanceSquared;
|
||||||
VisibilityCheckChunk[] plannedChunks;
|
VisibilityCheckChunk[] plannedChunks;
|
||||||
|
|
@ -1549,17 +1550,19 @@ struct VisibilityCheckIterator {
|
||||||
// mask test
|
// mask test
|
||||||
if (!mask)
|
if (!mask)
|
||||||
return;
|
return;
|
||||||
|
if (p.y > maxHeight + 16 && p.y > startPos.y)
|
||||||
|
return;
|
||||||
// distance test
|
// distance test
|
||||||
Vector3d diff = (p + Vector3d(4,4,4)) - camPos;
|
Vector3d diff = (p + Vector3d(4,4,4)) - camPos;
|
||||||
if (diff.squaredLength() > maxDistanceSquared)
|
if (diff.squaredLength() > maxDistanceSquared)
|
||||||
return;
|
return;
|
||||||
int distance = diff.squaredLength;
|
int distance = diff.squaredLength;
|
||||||
if (distance > 10*10) {
|
if (distance > 16*16) {
|
||||||
diff = (diff * 256 + cameraDirection * 16) / 256;
|
diff = (diff * 256 + cameraDirection * 16) / 256;
|
||||||
//diff += cameraDirection;
|
//diff += cameraDirection;
|
||||||
// direction test (TODO)
|
// direction test (TODO)
|
||||||
int dot = diff.dot(cameraDirection);
|
int dot = diff.dot(cameraDirection);
|
||||||
if (dot < 12000)
|
if (dot < 8000)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//....
|
//....
|
||||||
|
|
@ -1619,6 +1622,9 @@ struct VisibilityCheckIterator {
|
||||||
visitedChunks.length = 0;
|
visitedChunks.length = 0;
|
||||||
maxDistanceSquared = maxDistance * maxDistance;
|
maxDistanceSquared = maxDistance * maxDistance;
|
||||||
this.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;
|
Vector3d cameraDirection;
|
||||||
void visitVisibleChunks(ChunkVisitor visitor, Vector3d cameraDirection) {
|
void visitVisibleChunks(ChunkVisitor visitor, Vector3d cameraDirection) {
|
||||||
|
|
|
||||||
|
|
@ -178,7 +178,7 @@ class World {
|
||||||
/// get max Y position of non-empty cell in region (x +- size, z +- size)
|
/// get max Y position of non-empty cell in region (x +- size, z +- size)
|
||||||
int regionHeight(int x, int z, int size) {
|
int regionHeight(int x, int z, int size) {
|
||||||
int top = -1;
|
int top = -1;
|
||||||
int delta = size / 8 + 1;
|
int delta = size + 1;
|
||||||
for (int dx = x - delta; dx <= x + delta; dx += 8) {
|
for (int dx = x - delta; dx <= x + delta; dx += 8) {
|
||||||
for (int dz = z - delta; dz <= z + delta; dz += 8) {
|
for (int dz = z - delta; dz <= z + delta; dz += 8) {
|
||||||
if (ChunkStack * stack = getCellChunkStack(x, z)) {
|
if (ChunkStack * stack = getCellChunkStack(x, z)) {
|
||||||
|
|
|
||||||
|
|
@ -132,9 +132,9 @@ class MinerDrawable : MaterialDrawableObject, ChunkVisitor {
|
||||||
float camDist = (_camPosition - chunkPos).length;
|
float camDist = (_camPosition - chunkPos).length;
|
||||||
vec3 chunkDirection = (chunkPos - (_camPosition - (_camForwardVector * 12))).normalized;
|
vec3 chunkDirection = (chunkPos - (_camPosition - (_camForwardVector * 12))).normalized;
|
||||||
float dot = _camForwardVector.dot(chunkDirection);
|
float dot = _camForwardVector.dot(chunkDirection);
|
||||||
float threshold = 0.87;
|
float threshold = 0.80;
|
||||||
if (camDist < 12)
|
if (camDist < 16)
|
||||||
threshold = 0.5;
|
threshold = 0.2;
|
||||||
//Log.d("visit() chunkPos ", chunkPos, " chunkDir ", chunkDirection, " camDir ", " dot ", dot, " threshold ", threshold);
|
//Log.d("visit() chunkPos ", chunkPos, " chunkDir ", chunkDirection, " camDir ", " dot ", dot, " threshold ", threshold);
|
||||||
|
|
||||||
if (dot < threshold) { // cos(45)
|
if (dot < threshold) { // cos(45)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue