block chunk memory pooling
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
This commit is contained in:
parent
c3be78565d
commit
8c44525493
@ -21,7 +21,7 @@
|
||||
"craftingTag" : "HAND",
|
||||
"ingredients": [
|
||||
{
|
||||
"itemType": "mat:Log",
|
||||
"itemType": "mat:Rock",
|
||||
"count": 1
|
||||
}
|
||||
],
|
||||
|
||||
@ -1646,6 +1646,7 @@ New AI behaviors
|
||||
- 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
|
||||
Block chunk memory pooling
|
||||
|
||||
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import electrosphere.mem.BlockChunkPool;
|
||||
import electrosphere.server.physics.block.diskmap.ServerBlockChunkDiskMap;
|
||||
import electrosphere.util.math.HashUtils;
|
||||
|
||||
@ -142,11 +143,29 @@ public class BlockChunkCache {
|
||||
BlockChunkData fullRes = cacheMapFullRes.remove(oldKey);
|
||||
if(fullRes != null && this.chunkDiskMap != null){
|
||||
this.chunkDiskMap.saveToDisk(fullRes);
|
||||
BlockChunkPool.release(fullRes.getType());
|
||||
BlockChunkPool.release(fullRes.getMetadata());
|
||||
}
|
||||
BlockChunkData halfRes = cacheMapHalfRes.remove(oldKey);
|
||||
BlockChunkData quarterRes = cacheMapQuarterRes.remove(oldKey);
|
||||
BlockChunkData eighthRes = cacheMapEighthRes.remove(oldKey);
|
||||
BlockChunkData sixteenthRes = cacheMapSixteenthRes.remove(oldKey);
|
||||
if(halfRes != null){
|
||||
BlockChunkPool.release(halfRes.getType());
|
||||
BlockChunkPool.release(halfRes.getMetadata());
|
||||
}
|
||||
if(quarterRes != null){
|
||||
BlockChunkPool.release(quarterRes.getType());
|
||||
BlockChunkPool.release(quarterRes.getMetadata());
|
||||
}
|
||||
if(eighthRes != null){
|
||||
BlockChunkPool.release(eighthRes.getType());
|
||||
BlockChunkPool.release(eighthRes.getMetadata());
|
||||
}
|
||||
if(sixteenthRes != null){
|
||||
BlockChunkPool.release(sixteenthRes.getType());
|
||||
BlockChunkPool.release(sixteenthRes.getMetadata());
|
||||
}
|
||||
cacheMapHalfRes.remove(oldKey);
|
||||
cacheMapQuarterRes.remove(oldKey);
|
||||
cacheMapEighthRes.remove(oldKey);
|
||||
cacheMapSixteenthRes.remove(oldKey);
|
||||
}
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ package electrosphere.client.block;
|
||||
|
||||
import org.joml.Vector3i;
|
||||
|
||||
import electrosphere.mem.BlockChunkPool;
|
||||
import electrosphere.renderer.meshgen.BlockMeshgenData;
|
||||
import electrosphere.server.physics.terrain.manager.ServerTerrainChunk;
|
||||
|
||||
@ -129,8 +130,8 @@ public class BlockChunkData implements BlockMeshgenData {
|
||||
*/
|
||||
public static BlockChunkData allocate(){
|
||||
BlockChunkData rVal = new BlockChunkData();
|
||||
rVal.setType(new short[CHUNK_DATA_WIDTH * CHUNK_DATA_WIDTH * CHUNK_DATA_WIDTH]);
|
||||
rVal.setMetadata(new short[CHUNK_DATA_WIDTH * CHUNK_DATA_WIDTH * CHUNK_DATA_WIDTH]);
|
||||
rVal.setType(BlockChunkPool.getShort());
|
||||
rVal.setMetadata(BlockChunkPool.getShort());
|
||||
return rVal;
|
||||
}
|
||||
|
||||
@ -147,8 +148,8 @@ public class BlockChunkData implements BlockMeshgenData {
|
||||
* Allocates the arrays in a given homogenous data chunk
|
||||
*/
|
||||
private void allocateFromHomogenous(){
|
||||
this.setType(new short[CHUNK_DATA_WIDTH * CHUNK_DATA_WIDTH * CHUNK_DATA_WIDTH]);
|
||||
this.setMetadata(new short[CHUNK_DATA_WIDTH * CHUNK_DATA_WIDTH * CHUNK_DATA_WIDTH]);
|
||||
this.setType(BlockChunkPool.getShort());
|
||||
this.setMetadata(BlockChunkPool.getShort());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
53
src/main/java/electrosphere/mem/BlockChunkPool.java
Normal file
53
src/main/java/electrosphere/mem/BlockChunkPool.java
Normal file
@ -0,0 +1,53 @@
|
||||
package electrosphere.mem;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import electrosphere.client.block.BlockChunkData;
|
||||
|
||||
/**
|
||||
* A pool for temporary vectors
|
||||
*/
|
||||
public class BlockChunkPool {
|
||||
|
||||
/**
|
||||
* Structure to store not-in-use objects
|
||||
*/
|
||||
static List<short[]> shortPool = new LinkedList<short[]>();
|
||||
|
||||
/**
|
||||
* Lock for thread-safeing operations
|
||||
*/
|
||||
static ReentrantLock lock = new ReentrantLock();
|
||||
|
||||
/**
|
||||
* Gets a short[] from the pool. Allocates if no free one is available.
|
||||
* @param type The type of the message
|
||||
* @return A short[]
|
||||
*/
|
||||
public static short[] getShort(){
|
||||
short[] rVal = null;
|
||||
lock.lock();
|
||||
if(shortPool.size() > 0){
|
||||
rVal = shortPool.remove(0);
|
||||
} else {
|
||||
rVal = new short[BlockChunkData.CHUNK_DATA_WIDTH * BlockChunkData.CHUNK_DATA_WIDTH * BlockChunkData.CHUNK_DATA_WIDTH];
|
||||
}
|
||||
lock.unlock();
|
||||
return rVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Releases a Vector3f back into the pool
|
||||
* @param data The object to release
|
||||
*/
|
||||
public static void release(short[] data){
|
||||
lock.lock();
|
||||
if(data != null){
|
||||
BlockChunkPool.shortPool.add(data);
|
||||
}
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
}
|
||||
@ -49,6 +49,10 @@ public class EntityProtocol implements ClientProtocolTemplate<EntityMessage> {
|
||||
Globals.profiler.beginAggregateCpuSample("EntityProtocol.handleEntityMessage");
|
||||
LoggerInterface.loggerNetworking.DEBUG_LOOP("Parse entity message of type " + message.getMessageSubtype());
|
||||
|
||||
if(Globals.clientScene != null && Globals.clientSynchronizationManager.isDeleted(message.getentityID())){
|
||||
return;
|
||||
}
|
||||
|
||||
//error check
|
||||
if(Globals.clientScene != null && Globals.clientSceneWrapper.getEntityFromServerId(message.getentityID()) == null && !idModifyingMessages.contains(message.getMessageSubtype())){
|
||||
LoggerInterface.loggerNetworking.WARNING("Client received packet for entity that is not in the client scene!");
|
||||
|
||||
@ -192,6 +192,15 @@ public class ClientSynchronizationManager {
|
||||
this.deletedEntityIds.add(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if an entity has been deleted by the server
|
||||
* @param entityId The entity's id
|
||||
* @return true if it has been deleted, false otherwise
|
||||
*/
|
||||
public boolean isDeleted(int entityId){
|
||||
return this.deletedEntityIds.contains(entityId);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> Automatically generated </p>
|
||||
* <p>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user