fix blocks caching
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good

This commit is contained in:
austin 2025-05-02 13:32:10 -04:00
parent 059a2ef52f
commit c3be78565d
6 changed files with 27 additions and 5 deletions

View File

@ -1645,6 +1645,7 @@ New AI behaviors
- Build structure
- Stops targeting trees if they're dead
Fix bug where sync messages eternally bounce if the entity was already deleted
Fix blocks not saving to disk when being ejected from cache

View File

@ -8,6 +8,7 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;
import electrosphere.server.physics.block.diskmap.ServerBlockChunkDiskMap;
import electrosphere.util.math.HashUtils;
/**
@ -65,6 +66,19 @@ public class BlockChunkCache {
*/
ReentrantLock lock = new ReentrantLock();
/**
* The disk map
*/
ServerBlockChunkDiskMap chunkDiskMap;
/**
* Constructor
* @param chunkDiskMap If supplied, will be used to save chunks as they are ejected
*/
public BlockChunkCache(ServerBlockChunkDiskMap chunkDiskMap){
this.chunkDiskMap = chunkDiskMap;
}
/**
* Gets the collection of server block chunks that are cached
* @return The collection of chunks
@ -125,7 +139,10 @@ public class BlockChunkCache {
cache.put(key, chunk);
while(queryRecencyQueue.size() > cacheSize){
Long oldKey = queryRecencyQueue.remove(queryRecencyQueue.size() - 1);
cacheMapFullRes.remove(oldKey);
BlockChunkData fullRes = cacheMapFullRes.remove(oldKey);
if(fullRes != null && this.chunkDiskMap != null){
this.chunkDiskMap.saveToDisk(fullRes);
}
cacheMapHalfRes.remove(oldKey);
cacheMapQuarterRes.remove(oldKey);
cacheMapEighthRes.remove(oldKey);

View File

@ -83,7 +83,7 @@ public class ClientBlockManager {
* Constructor
*/
public ClientBlockManager(){
blockCache = new BlockChunkCache();
blockCache = new BlockChunkCache(null);
}

View File

@ -108,7 +108,7 @@ public class ClientTerrainManager {
*/
public ClientTerrainManager(){
terrainCache = new ClientTerrainCache(CACHE_SIZE);
blockCache = new BlockChunkCache();
blockCache = new BlockChunkCache(null);
}

View File

@ -41,7 +41,9 @@ public class StructureRepairUtils {
Vector3i chunkPos = ServerWorldData.convertRealToChunkSpace(offsetPos);
Vector3i blockPos = ServerWorldData.convertRealToLocalBlockSpace(offsetPos);
BlockChunkData blockChunkData = griddedDataCellManager.getBlocksAtPosition(chunkPos);
if(blockChunkData.getType(blockPos.x, blockPos.y, blockPos.z) != fab.getType(x, y, z)){
short existingBlockType = blockChunkData.getType(blockPos.x, blockPos.y, blockPos.z);
short desiredType = fab.getType(x, y, z);
if(existingBlockType != desiredType){
return new Vector3i(x,y,z);
}
}

View File

@ -33,7 +33,7 @@ public class ServerBlockManager {
* The cache of chunks
*/
@Exclude
BlockChunkCache chunkCache = new BlockChunkCache();
BlockChunkCache chunkCache;
/**
* The map of chunk position <-> file on disk containing chunk data
@ -66,6 +66,7 @@ public class ServerBlockManager {
*/
public void generate(){
this.chunkDiskMap = ServerBlockChunkDiskMap.init();
this.chunkCache = new BlockChunkCache(this.chunkDiskMap);
}
/**
@ -92,6 +93,7 @@ public class ServerBlockManager {
public void load(String saveName){
//load chunk disk map
this.chunkDiskMap = ServerBlockChunkDiskMap.init(saveName);
this.chunkCache = new BlockChunkCache(this.chunkDiskMap);
}
/**