From 59b899b1d732997caccf1611d89718b93229e15b Mon Sep 17 00:00:00 2001 From: austin Date: Thu, 7 Nov 2024 12:08:00 -0500 Subject: [PATCH] support for sixteenth resolution chunks --- .../terrain/cache/ClientTerrainCache.java | 8 +++ .../terrain/cells/ClientDrawCellManager.java | 69 +++++++++++++++---- .../terrain/manager/ClientTerrainManager.java | 7 +- .../terrain/manager/ServerChunkCache.java | 8 +++ 4 files changed, 78 insertions(+), 14 deletions(-) diff --git a/src/main/java/electrosphere/client/terrain/cache/ClientTerrainCache.java b/src/main/java/electrosphere/client/terrain/cache/ClientTerrainCache.java index 0536d585..589f0952 100644 --- a/src/main/java/electrosphere/client/terrain/cache/ClientTerrainCache.java +++ b/src/main/java/electrosphere/client/terrain/cache/ClientTerrainCache.java @@ -42,6 +42,11 @@ public class ClientTerrainCache { */ Map cacheMapEighthRes = new ConcurrentHashMap(); + /** + * The map of sixteenth res chunk key -> chunk data + */ + Map cacheMapSixteenthRes = new ConcurrentHashMap(); + /** * The list of keys in the cache */ @@ -178,6 +183,9 @@ public class ClientTerrainCache { case 3: { return cacheMapEighthRes; } + case 4: { + return cacheMapEighthRes; + } default: { throw new Error("Invalid stride probided! " + stride); } diff --git a/src/main/java/electrosphere/client/terrain/cells/ClientDrawCellManager.java b/src/main/java/electrosphere/client/terrain/cells/ClientDrawCellManager.java index 10f93fb2..d09385c8 100644 --- a/src/main/java/electrosphere/client/terrain/cells/ClientDrawCellManager.java +++ b/src/main/java/electrosphere/client/terrain/cells/ClientDrawCellManager.java @@ -48,7 +48,12 @@ public class ClientDrawCellManager { /** * The distance for eighth resolution */ - public static final double EIGHTH_RES_DIST = 28 * ServerTerrainChunk.CHUNK_DIMENSION; + public static final double EIGHTH_RES_DIST = 32 * ServerTerrainChunk.CHUNK_DIMENSION; + + /** + * The distance for sixteenth resolution + */ + public static final double SIXTEENTH_RES_DIST = 48 * ServerTerrainChunk.CHUNK_DIMENSION; /** * Lod value for a full res chunk @@ -70,6 +75,16 @@ public class ClientDrawCellManager { */ public static final int EIGHTH_RES_LOD = 3; + /** + * Lod value for a sixteenth res chunk + */ + public static final int SIXTEENTH_RES_LOD = 4; + + /** + * Lod value for evaluating all lod levels + */ + public static final int ALL_RES_LOD = 5; + /** * The octree holding all the chunks to evaluate */ @@ -153,6 +168,12 @@ public class ClientDrawCellManager { if(!updatedLastFrame){ updatedLastFrame = this.recursivelyUpdateCells(rootNode, playerPos, EIGHTH_RES_LOD); } + if(!updatedLastFrame){ + updatedLastFrame = this.recursivelyUpdateCells(rootNode, playerPos, SIXTEENTH_RES_LOD); + } + if(!updatedLastFrame){ + updatedLastFrame = this.recursivelyUpdateCells(rootNode, playerPos, ALL_RES_LOD); + } } Globals.profiler.endCpuSample(); } @@ -277,17 +298,22 @@ public class ClientDrawCellManager { node.canSplit() && ( ( - node.getLevel() < this.chunkTree.getMaxLevel() - 3 && + node.getLevel() < this.chunkTree.getMaxLevel() - SIXTEENTH_RES_LOD && + this.getMinDistance(pos, node) <= SIXTEENTH_RES_DIST + ) + || + ( + node.getLevel() < this.chunkTree.getMaxLevel() - EIGHTH_RES_LOD && this.getMinDistance(pos, node) <= EIGHTH_RES_DIST ) || ( - node.getLevel() < this.chunkTree.getMaxLevel() - 2 && + node.getLevel() < this.chunkTree.getMaxLevel() - QUARTER_RES_LOD && this.getMinDistance(pos, node) <= QUARTER_RES_DIST ) || ( - node.getLevel() < this.chunkTree.getMaxLevel() - 1 && + node.getLevel() < this.chunkTree.getMaxLevel() - HALF_RES_LOD && this.getMinDistance(pos, node) <= HALF_RES_DIST ) || @@ -426,23 +452,28 @@ public class ClientDrawCellManager { !node.isLeaf() && ( ( - node.getLevel() == this.chunkTree.getMaxLevel() - 1 && + node.getLevel() == this.chunkTree.getMaxLevel() - HALF_RES_LOD && this.getMinDistance(pos, node) > FULL_RES_DIST ) || ( - node.getLevel() == this.chunkTree.getMaxLevel() - 2 && + node.getLevel() == this.chunkTree.getMaxLevel() - QUARTER_RES_LOD && this.getMinDistance(pos, node) > HALF_RES_DIST ) || ( - node.getLevel() == this.chunkTree.getMaxLevel() - 3 && + node.getLevel() == this.chunkTree.getMaxLevel() - EIGHTH_RES_LOD && this.getMinDistance(pos, node) > QUARTER_RES_DIST ) || ( + node.getLevel() == this.chunkTree.getMaxLevel() - SIXTEENTH_RES_LOD && this.getMinDistance(pos, node) > EIGHTH_RES_DIST ) + || + ( + this.getMinDistance(pos, node) > SIXTEENTH_RES_DIST + ) ) ; } @@ -468,22 +499,28 @@ public class ClientDrawCellManager { ) || ( - node.getLevel() == this.chunkTree.getMaxLevel() - 1 + node.getLevel() == this.chunkTree.getMaxLevel() - HALF_RES_LOD && this.getMinDistance(pos, node) <= QUARTER_RES_DIST ) || ( - node.getLevel() == this.chunkTree.getMaxLevel() - 2 + node.getLevel() == this.chunkTree.getMaxLevel() - QUARTER_RES_LOD && this.getMinDistance(pos, node) <= EIGHTH_RES_DIST ) || ( - node.getLevel() == this.chunkTree.getMaxLevel() - 3 + node.getLevel() == this.chunkTree.getMaxLevel() - EIGHTH_RES_LOD && this.getMinDistance(pos, node) <= EIGHTH_RES_DIST ) + || + ( + node.getLevel() == this.chunkTree.getMaxLevel() - SIXTEENTH_RES_LOD + && + this.getMinDistance(pos, node) <= SIXTEENTH_RES_DIST + ) ) ; } @@ -509,22 +546,28 @@ public class ClientDrawCellManager { ) || ( - node.getLevel() == this.chunkTree.getMaxLevel() - 1 + node.getLevel() == this.chunkTree.getMaxLevel() - HALF_RES_LOD && this.getMinDistance(pos, node) <= QUARTER_RES_DIST ) || ( - node.getLevel() == this.chunkTree.getMaxLevel() - 2 + node.getLevel() == this.chunkTree.getMaxLevel() - QUARTER_RES_LOD && this.getMinDistance(pos, node) <= EIGHTH_RES_DIST ) || ( - node.getLevel() == this.chunkTree.getMaxLevel() - 3 + node.getLevel() == this.chunkTree.getMaxLevel() - EIGHTH_RES_LOD && this.getMinDistance(pos, node) <= EIGHTH_RES_DIST ) + || + ( + node.getLevel() == this.chunkTree.getMaxLevel() - SIXTEENTH_RES_LOD + && + this.getMinDistance(pos, node) <= SIXTEENTH_RES_DIST + ) ) ; } diff --git a/src/main/java/electrosphere/client/terrain/manager/ClientTerrainManager.java b/src/main/java/electrosphere/client/terrain/manager/ClientTerrainManager.java index 5a3af2c1..f253cef0 100644 --- a/src/main/java/electrosphere/client/terrain/manager/ClientTerrainManager.java +++ b/src/main/java/electrosphere/client/terrain/manager/ClientTerrainManager.java @@ -41,6 +41,11 @@ public class ClientTerrainManager { * Locks the terrain manager (eg if adding message from network) */ static Semaphore lock = new Semaphore(1); + + /** + * Maximum concurrent terrain requests + */ + public static final int MAX_CONCURRENT_REQUESTS = 500; //The interpolation ratio of terrain public static final int INTERPOLATION_RATIO = ServerTerrainManager.SERVER_TERRAIN_MANAGER_INTERPOLATION_RATIO; @@ -207,7 +212,7 @@ public class ClientTerrainManager { public boolean requestChunk(int worldX, int worldY, int worldZ, int stride){ boolean rVal = false; lock.acquireUninterruptibly(); - if(!this.requestedMap.containsKey(this.getRequestKey(worldX, worldY, worldZ, stride))){ + if(this.requestedMap.size() < MAX_CONCURRENT_REQUESTS && !this.requestedMap.containsKey(this.getRequestKey(worldX, worldY, worldZ, stride))){ Globals.clientConnection.queueOutgoingMessage(TerrainMessage.constructRequestReducedChunkDataMessage( worldX, worldY, diff --git a/src/main/java/electrosphere/server/terrain/manager/ServerChunkCache.java b/src/main/java/electrosphere/server/terrain/manager/ServerChunkCache.java index 633e49a7..da685ea8 100644 --- a/src/main/java/electrosphere/server/terrain/manager/ServerChunkCache.java +++ b/src/main/java/electrosphere/server/terrain/manager/ServerChunkCache.java @@ -46,6 +46,11 @@ public class ServerChunkCache { */ Map cacheMapEighthRes = new ConcurrentHashMap(); + /** + * The map of sixteenth res chunk key -> chunk data + */ + Map cacheMapSixteenthRes = new ConcurrentHashMap(); + /** * Tracks how recently a chunk has been queries for (used for evicting old chunks from cache) */ @@ -208,6 +213,9 @@ public class ServerChunkCache { case 3: { return cacheMapEighthRes; } + case 4: { + return cacheMapSixteenthRes; + } default: { throw new Error("Invalid stride probided! " + stride); }