octree cache busting when sync teleport dist
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good

This commit is contained in:
austin 2025-04-30 15:44:07 -04:00
parent e207269489
commit 756f3ead55
7 changed files with 62 additions and 7 deletions

View File

@ -1619,6 +1619,7 @@ Craftable wooden floor fab
Using up charges destroys the item (including toolbar instances) Using up charges destroys the item (including toolbar instances)
Crafting can consume charges Crafting can consume charges
Products from crafting can add charges to existing items Products from crafting can add charges to existing items
Cache busting when physics sync pulls player entity TELEPORT distances

View File

@ -147,6 +147,11 @@ public class ClientDrawCellManager {
*/ */
boolean initialized = false; boolean initialized = false;
/**
* Used to bust the distance cache from external calls
*/
boolean bustDistCache = false;
/** /**
* Constructor * Constructor
* @param voxelTextureAtlas The voxel texture atlas * @param voxelTextureAtlas The voxel texture atlas
@ -171,6 +176,10 @@ public class ClientDrawCellManager {
Vector3d playerPos = EntityUtils.getPosition(Globals.playerEntity); Vector3d playerPos = EntityUtils.getPosition(Globals.playerEntity);
Vector3i playerWorldPos = Globals.clientWorldData.convertRealToWorldSpace(playerPos); Vector3i playerWorldPos = Globals.clientWorldData.convertRealToWorldSpace(playerPos);
int distCache = this.getDistCache(this.lastPlayerPos, playerWorldPos); int distCache = this.getDistCache(this.lastPlayerPos, playerWorldPos);
if(this.bustDistCache){
this.bustDistCache = false;
distCache = this.chunkTree.getMaxLevel();
}
this.lastPlayerPos.set(playerWorldPos); this.lastPlayerPos.set(playerWorldPos);
//the sets to iterate through //the sets to iterate through
updatedLastFrame = true; updatedLastFrame = true;
@ -1084,6 +1093,13 @@ public class ClientDrawCellManager {
return false; return false;
} }
/**
* Busts the distance cache
*/
public void bustDistanceCache(){
this.bustDistCache = true;
}
} }

View File

@ -158,6 +158,11 @@ public class FoliageCellManager {
*/ */
List<Vector3i> breakPoints = new LinkedList<Vector3i>(); List<Vector3i> breakPoints = new LinkedList<Vector3i>();
/**
* Used to bust the distance cache from external calls
*/
boolean bustDistCache = false;
/** /**
* Constructor * Constructor
* @param worldDim The size of the world in chunks * @param worldDim The size of the world in chunks
@ -193,8 +198,9 @@ public class FoliageCellManager {
Vector3d playerPos = EntityUtils.getPosition(Globals.playerEntity); Vector3d playerPos = EntityUtils.getPosition(Globals.playerEntity);
Vector3i absVoxelPos = Globals.clientWorldData.convertRealToAbsoluteVoxelSpace(playerPos); Vector3i absVoxelPos = Globals.clientWorldData.convertRealToAbsoluteVoxelSpace(playerPos);
int distCache = this.getDistCache(this.lastPlayerPos, absVoxelPos); int distCache = this.getDistCache(this.lastPlayerPos, absVoxelPos);
if(absVoxelPos.distance(this.lastPlayerPos) > TELEPORT_DISTANCE){ if(bustDistCache || absVoxelPos.distance(this.lastPlayerPos) > TELEPORT_DISTANCE){
distCache = BUST_META_CELLS; distCache = BUST_META_CELLS;
bustDistCache = false;
} }
this.lastPlayerPos.set(absVoxelPos); this.lastPlayerPos.set(absVoxelPos);
//the sets to iterate through //the sets to iterate through
@ -927,5 +933,12 @@ public class FoliageCellManager {
this.breakPoints.add(absVoxelPos); this.breakPoints.add(absVoxelPos);
} }
/**
* Busts the distance cache
*/
public void bustDistanceCache(){
this.bustDistCache = true;
}
} }

View File

@ -63,11 +63,16 @@ public class ImGuiDrawCell {
LoggerInterface.loggerEngine.WARNING("Chunk not in cache! " + cameraWorldPos); LoggerInterface.loggerEngine.WARNING("Chunk not in cache! " + cameraWorldPos);
} }
} }
if(ImGui.button("Debug FoliageCell at camera position")){ if(ImGui.button("Print debug info for FoliageCell at camera position")){
Vector3i cameraWorldPos = Globals.clientWorldData.convertRealToWorldSpace(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); Vector3i cameraWorldPos = Globals.clientWorldData.convertRealToWorldSpace(CameraEntityUtils.getCameraCenter(Globals.playerCamera));
FoliageCell cell = Globals.foliageCellManager.getFoliageCell(cameraWorldPos.x, cameraWorldPos.y, cameraWorldPos.z); FoliageCell cell = Globals.foliageCellManager.getFoliageCell(cameraWorldPos.x, cameraWorldPos.y, cameraWorldPos.z);
LoggerInterface.loggerEngine.WARNING("" + cell); LoggerInterface.loggerEngine.WARNING("" + cell);
} }
if(ImGui.button("Debug FoliageCell evaluation at camera position")){
Vector3i cameraWorldPos = Globals.clientWorldData.convertRealToWorldSpace(CameraEntityUtils.getCameraCenter(Globals.playerCamera));
FoliageCell cell = Globals.foliageCellManager.getFoliageCell(cameraWorldPos.x, cameraWorldPos.y, cameraWorldPos.z);
cell.setTripDebug(true);
}
if(ImGui.button("Request terrain at camera position")){ if(ImGui.button("Request terrain at camera position")){
Vector3i cameraWorldPos = Globals.clientWorldData.convertRealToWorldSpace(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); Vector3i cameraWorldPos = Globals.clientWorldData.convertRealToWorldSpace(CameraEntityUtils.getCameraCenter(Globals.playerCamera));
Globals.clientTerrainManager.requestChunk(cameraWorldPos.x, cameraWorldPos.y, cameraWorldPos.z, 1); Globals.clientTerrainManager.requestChunk(cameraWorldPos.x, cameraWorldPos.y, cameraWorldPos.z, 1);

View File

@ -5,6 +5,7 @@ import org.joml.Vector3d;
import org.ode4j.ode.DBody; import org.ode4j.ode.DBody;
import electrosphere.client.entity.camera.CameraEntityUtils; import electrosphere.client.entity.camera.CameraEntityUtils;
import electrosphere.client.terrain.foliage.FoliageCellManager;
import electrosphere.collision.PhysicsEntityUtils; import electrosphere.collision.PhysicsEntityUtils;
import electrosphere.collision.PhysicsUtils; import electrosphere.collision.PhysicsUtils;
import electrosphere.engine.Globals; import electrosphere.engine.Globals;
@ -20,13 +21,19 @@ import electrosphere.net.parser.net.message.EntityMessage;
*/ */
public class ClientPhysicsSyncTree implements BehaviorTree { public class ClientPhysicsSyncTree implements BehaviorTree {
//The parent entity for the tree /**
* The parent entity for the tree
*/
Entity parent; Entity parent;
//The most recent message received from the client /**
* The most recent message received from the client
*/
EntityMessage latestMessage = null; EntityMessage latestMessage = null;
//checks if the message has been pushed to the physics engine or not /**
* checks if the message has been pushed to the physics engine or not
*/
boolean hasPushesMessage = true; boolean hasPushesMessage = true;
/** /**
@ -52,6 +59,15 @@ public class ClientPhysicsSyncTree implements BehaviorTree {
Vector3d angularForce = new Vector3d(); Vector3d angularForce = new Vector3d();
DBody body = PhysicsEntityUtils.getDBody(parent); DBody body = PhysicsEntityUtils.getDBody(parent);
//
//bust distance caches if this is the player's entity and we've traveled a long distance suddenly
if(parent == Globals.playerEntity){
if(position.distance(EntityUtils.getPosition(parent)) > FoliageCellManager.TELEPORT_DISTANCE){
Globals.clientDrawCellManager.bustDistanceCache();
Globals.foliageCellManager.bustDistanceCache();
}
}
// //
//Synchronize data //Synchronize data
EntityUtils.getPosition(parent).set(position); EntityUtils.getPosition(parent).set(position);

View File

@ -87,6 +87,9 @@ public class EntityProtocol implements ClientProtocolTemplate<EntityMessage> {
case COMMON: { case COMMON: {
EntityProtocol.spawnCommon(message); EntityProtocol.spawnCommon(message);
} break; } break;
case ENGINE: {
throw new Error("Unsupported entity type!");
}
} }
Globals.clientConnection.release(message); Globals.clientConnection.release(message);
} break; } break;
@ -159,6 +162,7 @@ public class EntityProtocol implements ClientProtocolTemplate<EntityMessage> {
// TODO // TODO
// //
// //
case INTERACT:
case UPDATEENTITYVIEWDIR: case UPDATEENTITYVIEWDIR:
case KILL: case KILL:
//to be implemented //to be implemented

View File

@ -26,9 +26,9 @@ public class PlayerProtocol implements ClientProtocolTemplate<PlayerMessage> {
Globals.clientPlayer = new Player(message.getplayerID(), Player.CLIENT_DB_ID); Globals.clientPlayer = new Player(message.getplayerID(), Player.CLIENT_DB_ID);
LoggerInterface.loggerNetworking.DEBUG("[CLIENT] Player ID is " + Globals.clientPlayer.getId()); LoggerInterface.loggerNetworking.DEBUG("[CLIENT] Player ID is " + Globals.clientPlayer.getId());
break; break;
case SETINITIALDISCRETEPOSITION: case SETINITIALDISCRETEPOSITION: {
Globals.clientPlayerData.setWorldPos(new Vector3i(message.getinitialDiscretePositionX(), message.getinitialDiscretePositionY(), message.getinitialDiscretePositionZ())); Globals.clientPlayerData.setWorldPos(new Vector3i(message.getinitialDiscretePositionX(), message.getinitialDiscretePositionY(), message.getinitialDiscretePositionZ()));
break; } break;
} }
Globals.profiler.endCpuSample(); Globals.profiler.endCpuSample();
} }