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