nearby entity lookup caching
This commit is contained in:
parent
935ee0e416
commit
0493649348
@ -1970,6 +1970,7 @@ Performance improvements
|
||||
- Reduced the visual LOD cutoff
|
||||
- Multiple visual LOD levels
|
||||
- AI does not simulate for low-lod server entities
|
||||
- Nearby entity lookup caching per frame
|
||||
Lod emitter service checker function
|
||||
|
||||
|
||||
|
||||
@ -178,6 +178,11 @@ public class GriddedDataCellManager implements DataCellManager, VoxelCellManager
|
||||
* The pathfinder for the manager
|
||||
*/
|
||||
VoxelPathfinder pathfinder;
|
||||
|
||||
/**
|
||||
* Caches lookups for nearby entities between simulate() calls
|
||||
*/
|
||||
private Map<Long,List<Entity>> nearbyLookupCache = new HashMap<Long,List<Entity>>();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@ -697,6 +702,11 @@ public class GriddedDataCellManager implements DataCellManager, VoxelCellManager
|
||||
loadedCellsLock.lock();
|
||||
|
||||
|
||||
//
|
||||
//clear nearby entity lookup cache
|
||||
this.nearbyLookupCache.clear();
|
||||
|
||||
|
||||
//regenerate physics where relevant
|
||||
terrainEditLock.acquireUninterruptibly();
|
||||
if(physicsQueue.size() > 0){
|
||||
@ -1179,6 +1189,11 @@ public class GriddedDataCellManager implements DataCellManager, VoxelCellManager
|
||||
|
||||
@Override
|
||||
public Collection<Entity> entityLookup(Vector3d pos, double radius) {
|
||||
Vector3i chunkPos = ServerWorldData.convertRealToChunkSpace(pos);
|
||||
long key = this.getServerDataCellKey(chunkPos);
|
||||
if(this.nearbyLookupCache.containsKey(key)){
|
||||
return Collections.unmodifiableCollection(this.nearbyLookupCache.get(key));
|
||||
}
|
||||
List<Entity> rVal = new LinkedList<Entity>();
|
||||
this.loadedCellsLock.lock();
|
||||
for(ServerDataCell cell : this.groundDataCells.values()){
|
||||
@ -1187,8 +1202,9 @@ public class GriddedDataCellManager implements DataCellManager, VoxelCellManager
|
||||
}
|
||||
rVal.addAll(cell.getScene().getEntityList());
|
||||
}
|
||||
this.nearbyLookupCache.put(key,rVal);
|
||||
this.loadedCellsLock.unlock();
|
||||
return rVal;
|
||||
return Collections.unmodifiableCollection(rVal);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Loading…
Reference in New Issue
Block a user