remove requested blocking

This commit is contained in:
austin 2024-11-05 14:56:26 -05:00
parent e14c8ec68a
commit db2886c0c7
3 changed files with 8 additions and 54 deletions

View File

@ -24,11 +24,6 @@ public class ClientTerrainCache {
List<Long> cacheList = new CopyOnWriteArrayList<Long>();
//A map of chunk to its world position
Map<ChunkData,Vector3i> chunkPositionMap = new ConcurrentHashMap<ChunkData,Vector3i>();
/**
* The map tracking chunks that have been requested
*/
Map<Long,Boolean> requestedChunks = new ConcurrentHashMap<Long,Boolean>();
/**
* Constructor
@ -50,9 +45,7 @@ public class ClientTerrainCache {
chunkPositionMap.put(chunkData,new Vector3i(worldX,worldY,worldZ));
while(cacheList.size() > cacheSize){
Long currentChunk = cacheList.remove(0);
ChunkData data = cacheMap.remove(currentChunk);
Vector3i worldPos = data.getWorldPos();
requestedChunks.remove(getKey(worldPos.x,worldPos.y,worldPos.z));
cacheMap.remove(currentChunk);
}
}
@ -119,34 +112,5 @@ public class ClientTerrainCache {
public Vector3i getChunkPosition(ChunkData chunk){
return chunkPositionMap.get(chunk);
}
/**
* Gets the number of cells that have been requested
* @return The number of cells that have been requested
*/
public int getRequestedCellCount(){
return this.requestedChunks.size();
}
/**
* Checks if a chunk has been requested or not
* @param worldX The x coordinate in the world
* @param worldY The y coordinate in the world
* @param worldZ The z coordinate in the world
* @return true if it has been requested, false otherwise
*/
public boolean hasRequested(int worldX, int worldY, int worldZ){
return this.requestedChunks.containsKey(getKey(worldX, worldY, worldZ));
}
/**
* Marks a chunk as requested
* @param worldX The x coordinate in the world
* @param worldY The y coordinate in the world
* @param worldZ The z coordinate in the world
*/
public void markAsRequested(int worldX, int worldY, int worldZ){
this.requestedChunks.put(getKey(worldX, worldY, worldZ),true);
}
}

View File

@ -192,14 +192,12 @@ public class ClientTerrainManager {
* @param stride The stride of the data
*/
public void requestChunk(int worldX, int worldY, int worldZ, int stride){
if(!this.terrainCache.hasRequested(worldX, worldY, worldZ)){
Globals.clientConnection.queueOutgoingMessage(TerrainMessage.constructRequestReducedChunkDataMessage(
worldX,
worldY,
worldZ,
stride
));
}
Globals.clientConnection.queueOutgoingMessage(TerrainMessage.constructRequestReducedChunkDataMessage(
worldX,
worldY,
worldZ,
stride
));
}
/**
@ -287,13 +285,5 @@ public class ClientTerrainManager {
public Vector3i getPositionOfChunk(ChunkData chunk){
return terrainCache.getChunkPosition(chunk);
}
/**
* Gets the number of chunks that have been requested
* @return The number of chunks
*/
public int getRequestedCellCount(){
return this.terrainCache.getRequestedCellCount();
}
}

View File

@ -300,7 +300,7 @@ public class ClientLoading {
while(blockForInit && Globals.clientDrawCellManager.updatedLastFrame() && Globals.threadManager.shouldKeepRunning()){
i++;
if(i % DRAW_CELL_UPDATE_RATE == 0){
WindowUtils.updateLoadingWindow("WAITING ON SERVER TO SEND TERRAIN (" + Globals.clientTerrainManager.getAllChunks().size() + "/" + Globals.clientTerrainManager.getRequestedCellCount() + ")");
WindowUtils.updateLoadingWindow("WAITING ON SERVER TO SEND TERRAIN (" + Globals.clientTerrainManager.getAllChunks().size() + ")");
}
try {
TimeUnit.MILLISECONDS.sleep(10);