From 3c10d423514f4f4a22097109efcc26f783eef2b1 Mon Sep 17 00:00:00 2001 From: austin Date: Thu, 15 May 2025 11:53:51 -0400 Subject: [PATCH] client state --- docs/src/progress/renderertodo.md | 3 ++ .../electrosphere/client/ClientState.java | 15 +++++++ .../client/block/ClientBlockSelection.java | 18 ++++---- .../block/cells/ClientBlockCellManager.java | 12 +++--- .../client/fluid/cells/FluidCellManager.java | 42 +++++++++---------- .../interact/ClientInteractionEngine.java | 8 ++-- .../client/interact/select/AreaSelection.java | 6 +-- .../client/script/ScriptClientAreaUtils.java | 4 +- .../client/script/ScriptClientVoxelUtils.java | 4 +- .../client/sim/ClientSimulation.java | 6 +-- .../terrain/cells/ClientDrawCellManager.java | 24 +++++------ .../client/terrain/editing/BlockEditing.java | 8 ++-- .../client/terrain/foliage/FoliageCell.java | 8 ++-- .../terrain/foliage/FoliageCellManager.java | 26 ++++++------ .../terrain/sampling/ClientVoxelSampler.java | 4 +- .../menu/debug/client/ImGuiChunkMonitor.java | 2 +- .../debug/client/ImGuiClientServices.java | 8 ++-- .../collision/CollisionWorldData.java | 35 ++++++++-------- .../java/electrosphere/engine/Globals.java | 17 +++++--- .../engine/loadingthreads/ClientLoading.java | 16 +++---- .../loadingthreads/ViewportLoading.java | 2 +- .../engine/service/ServiceManager.java | 6 ++- .../collidable/ClientCollidableTree.java | 14 +++---- .../editor/ClientEditorMovementTree.java | 8 ++-- .../net/client/protocol/TerrainProtocol.java | 16 +++---- .../physics/DataCellPhysicsManager.java | 2 +- .../cells/ClientDrawCellManagerTests.java | 2 +- .../StateCleanupCheckerExtension.java | 2 +- 28 files changed, 171 insertions(+), 147 deletions(-) create mode 100644 src/main/java/electrosphere/client/ClientState.java diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index e31c5bb5..89b99278 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -1801,6 +1801,9 @@ Fix reloading client world repeatedly AI manager thread safeing AI manager better error handling Delete deprecated classes +Create ClientState global +Properly reset ClientState +Move clientWorldData to clientState diff --git a/src/main/java/electrosphere/client/ClientState.java b/src/main/java/electrosphere/client/ClientState.java new file mode 100644 index 00000000..f990bcb0 --- /dev/null +++ b/src/main/java/electrosphere/client/ClientState.java @@ -0,0 +1,15 @@ +package electrosphere.client; + +import electrosphere.client.scene.ClientWorldData; + +/** + * State on the client + */ +public class ClientState { + + /** + * Data on the currently loaded world + */ + public ClientWorldData clientWorldData; + +} diff --git a/src/main/java/electrosphere/client/block/ClientBlockSelection.java b/src/main/java/electrosphere/client/block/ClientBlockSelection.java index c0f79fb5..65da719a 100644 --- a/src/main/java/electrosphere/client/block/ClientBlockSelection.java +++ b/src/main/java/electrosphere/client/block/ClientBlockSelection.java @@ -28,9 +28,9 @@ public class ClientBlockSelection { boolean encountered = false; - for(int x = 0; x < Globals.clientWorldData.getWorldDiscreteSize(); x++){ - for(int y = 0; y < Globals.clientWorldData.getWorldDiscreteSize(); y++){ - for(int z = 0; z < Globals.clientWorldData.getWorldDiscreteSize(); z++){ + for(int x = 0; x < Globals.clientState.clientWorldData.getWorldDiscreteSize(); x++){ + for(int y = 0; y < Globals.clientState.clientWorldData.getWorldDiscreteSize(); y++){ + for(int z = 0; z < Globals.clientState.clientWorldData.getWorldDiscreteSize(); z++){ chunkPos = new Vector3i(x,y,z); BlockChunkData blockChunkData = Globals.clientBlockManager.getChunkDataAtWorldPoint(chunkPos, 0); @@ -57,8 +57,8 @@ public class ClientBlockSelection { } } - Vector3d localMin = Globals.clientWorldData.convertBlockToRealSpace(chunkPos, minVoxelPos); - Vector3d localMax = Globals.clientWorldData.convertBlockToRealSpace(chunkPos, maxVoxelPos); + Vector3d localMin = Globals.clientState.clientWorldData.convertBlockToRealSpace(chunkPos, minVoxelPos); + Vector3d localMax = Globals.clientState.clientWorldData.convertBlockToRealSpace(chunkPos, maxVoxelPos); if(!encountered){ encountered = true; @@ -90,13 +90,13 @@ public class ClientBlockSelection { */ public static BlockFab convertSelectionToFab(){ AreaSelection selection = Globals.cursorState.getAreaSelection(); - Vector3i startChunk = Globals.clientWorldData.convertRealToWorldSpace(selection.getRectStart()); - Vector3i endChunk = Globals.clientWorldData.convertRealToWorldSpace(selection.getRectEnd()); + Vector3i startChunk = Globals.clientState.clientWorldData.convertRealToWorldSpace(selection.getRectStart()); + Vector3i endChunk = Globals.clientState.clientWorldData.convertRealToWorldSpace(selection.getRectEnd()); if(!startChunk.equals(endChunk)){ throw new Error("Unsupported case! Selected are coverts multiple chunks.. " + startChunk + " " + endChunk); } - Vector3i blockStart = Globals.clientWorldData.convertRealToBlockSpace(selection.getRectStart()); - Vector3i blockEnd = Globals.clientWorldData.convertRealToBlockSpace(selection.getRectEnd()); + Vector3i blockStart = Globals.clientState.clientWorldData.convertRealToBlockSpace(selection.getRectStart()); + Vector3i blockEnd = Globals.clientState.clientWorldData.convertRealToBlockSpace(selection.getRectEnd()); BlockChunkData chunk = Globals.clientBlockManager.getChunkDataAtWorldPoint(startChunk, 0); if(chunk == null){ diff --git a/src/main/java/electrosphere/client/block/cells/ClientBlockCellManager.java b/src/main/java/electrosphere/client/block/cells/ClientBlockCellManager.java index d8bd952c..9bb2ad29 100644 --- a/src/main/java/electrosphere/client/block/cells/ClientBlockCellManager.java +++ b/src/main/java/electrosphere/client/block/cells/ClientBlockCellManager.java @@ -139,7 +139,7 @@ public class ClientBlockCellManager { Globals.profiler.beginCpuSample("ClientBlockCellManager.update"); if(shouldUpdate && Globals.playerEntity != null){ Vector3d playerPos = EntityUtils.getPosition(Globals.playerEntity); - Vector3i playerWorldPos = Globals.clientWorldData.convertRealToWorldSpace(playerPos); + Vector3i playerWorldPos = Globals.clientState.clientWorldData.convertRealToWorldSpace(playerPos); int distCache = this.getDistCache(this.lastPlayerPos, playerWorldPos); this.lastPlayerPos.set(playerWorldPos); //the sets to iterate through @@ -657,8 +657,8 @@ public class ClientBlockCellManager { */ public boolean isFullLOD(Vector3i worldPos){ Vector3d playerRealPos = EntityUtils.getPosition(Globals.playerEntity); - Vector3d chunkMin = Globals.clientWorldData.convertWorldToRealSpace(worldPos); - Vector3d chunkMax = Globals.clientWorldData.convertWorldToRealSpace(new Vector3i(worldPos).add(1,1,1)); + Vector3d chunkMin = Globals.clientState.clientWorldData.convertWorldToRealSpace(worldPos); + Vector3d chunkMax = Globals.clientState.clientWorldData.convertWorldToRealSpace(new Vector3i(worldPos).add(1,1,1)); return GeomUtils.getMinDistanceAABB(playerRealPos, chunkMin, chunkMax) <= FULL_RES_DIST; } @@ -706,11 +706,11 @@ public class ClientBlockCellManager { Vector3i worldPos = node.getMinBound(); if( worldPos.x >= 0 && - worldPos.x < Globals.clientWorldData.getWorldDiscreteSize() && + worldPos.x < Globals.clientState.clientWorldData.getWorldDiscreteSize() && worldPos.y >= 0 && - worldPos.y < Globals.clientWorldData.getWorldDiscreteSize() && + worldPos.y < Globals.clientState.clientWorldData.getWorldDiscreteSize() && worldPos.z >= 0 && - worldPos.z < Globals.clientWorldData.getWorldDiscreteSize() && + worldPos.z < Globals.clientState.clientWorldData.getWorldDiscreteSize() && !Globals.clientBlockManager.containsChunkDataAtWorldPoint(worldPos.x, worldPos.y, worldPos.z, lod) ){ //client should request chunk data from server for each chunk necessary to create the model diff --git a/src/main/java/electrosphere/client/fluid/cells/FluidCellManager.java b/src/main/java/electrosphere/client/fluid/cells/FluidCellManager.java index a87748a4..152e2290 100644 --- a/src/main/java/electrosphere/client/fluid/cells/FluidCellManager.java +++ b/src/main/java/electrosphere/client/fluid/cells/FluidCellManager.java @@ -83,8 +83,8 @@ public class FluidCellManager { * @param discreteY The initial discrete position Y coordinate */ public FluidCellManager(ClientTerrainManager clientTerrainManager, int discreteX, int discreteY, int discreteZ){ - if(Globals.clientWorldData != null){ - worldBoundDiscreteMax = (int)(Globals.clientWorldData.getWorldBoundMin().x / ServerTerrainChunk.CHUNK_DIMENSION * 1.0f); + if(Globals.clientState.clientWorldData != null){ + worldBoundDiscreteMax = (int)(Globals.clientState.clientWorldData.getWorldBoundMin().x / ServerTerrainChunk.CHUNK_DIMENSION * 1.0f); } cells = new HashSet(); hasNotRequested = new HashSet(); @@ -130,11 +130,11 @@ public class FluidCellManager { if( worldPos.x >= 0 && - worldPos.x < Globals.clientWorldData.getWorldDiscreteSize() && + worldPos.x < Globals.clientState.clientWorldData.getWorldDiscreteSize() && worldPos.y >= 0 && - worldPos.y < Globals.clientWorldData.getWorldDiscreteSize() && + worldPos.y < Globals.clientState.clientWorldData.getWorldDiscreteSize() && worldPos.z >= 0 && - worldPos.z < Globals.clientWorldData.getWorldDiscreteSize() + worldPos.z < Globals.clientState.clientWorldData.getWorldDiscreteSize() ){ // if(!hasRequested.contains(targetKey)){ //client should request chunk data from server @@ -160,11 +160,11 @@ public class FluidCellManager { Vector3i worldPos = getVectorFromKey(targetKey); if( worldPos.x >= 0 && - worldPos.x < Globals.clientWorldData.getWorldDiscreteSize() && + worldPos.x < Globals.clientState.clientWorldData.getWorldDiscreteSize() && worldPos.y >= 0 && - worldPos.y < Globals.clientWorldData.getWorldDiscreteSize() && + worldPos.y < Globals.clientState.clientWorldData.getWorldDiscreteSize() && worldPos.z >= 0 && - worldPos.z < Globals.clientWorldData.getWorldDiscreteSize() + worldPos.z < Globals.clientState.clientWorldData.getWorldDiscreteSize() ){ if(containsChunkDataAtWorldPoint(worldPos.x, worldPos.y, worldPos.z)){ FluidCell cell = FluidCell.generateFluidCell( @@ -194,11 +194,11 @@ public class FluidCellManager { Vector3i worldPos = this.getVectorFromKey(targetKey); if( worldPos.x >= 0 && - worldPos.x < Globals.clientWorldData.getWorldDiscreteSize() && + worldPos.x < Globals.clientState.clientWorldData.getWorldDiscreteSize() && worldPos.y >= 0 && - worldPos.y < Globals.clientWorldData.getWorldDiscreteSize() && + worldPos.y < Globals.clientState.clientWorldData.getWorldDiscreteSize() && worldPos.z >= 0 && - worldPos.z < Globals.clientWorldData.getWorldDiscreteSize() + worldPos.z < Globals.clientState.clientWorldData.getWorldDiscreteSize() ){ // if(Math.abs(drawRadius + 1 - targetX) < physicsRadius && Math.abs(drawRadius + 1 - targetY) < physicsRadius){ // needsPhysics[targetX][targetY] = true; @@ -315,30 +315,30 @@ public class FluidCellManager { * Queues new cells that are in bounds but not currently accounted for */ private void queueNewCells(){ - if(Globals.playerEntity != null && Globals.clientWorldData != null){ + if(Globals.playerEntity != null && Globals.clientState.clientWorldData != null){ Vector3d playerPos = EntityUtils.getPosition(Globals.playerEntity); for(int x = -(int)drawRadius; x < drawRadius; x = x + ChunkData.CHUNK_DATA_SIZE){ for(int y = -(int)drawRadius; y < drawRadius; y = y + ChunkData.CHUNK_DATA_SIZE){ for(int z = -(int)drawRadius; z < drawRadius; z = z + ChunkData.CHUNK_DATA_SIZE){ Vector3d newPos = new Vector3d(playerPos.x + x, playerPos.y + y, playerPos.z + z); Vector3i worldPos = new Vector3i( - Globals.clientWorldData.convertRealToChunkSpace(newPos.x), - Globals.clientWorldData.convertRealToChunkSpace(newPos.y), - Globals.clientWorldData.convertRealToChunkSpace(newPos.z) + Globals.clientState.clientWorldData.convertRealToChunkSpace(newPos.x), + Globals.clientState.clientWorldData.convertRealToChunkSpace(newPos.y), + Globals.clientState.clientWorldData.convertRealToChunkSpace(newPos.z) ); Vector3d chunkRealSpace = new Vector3d( - Globals.clientWorldData.convertChunkToRealSpace(worldPos.x), - Globals.clientWorldData.convertChunkToRealSpace(worldPos.y), - Globals.clientWorldData.convertChunkToRealSpace(worldPos.z) + Globals.clientState.clientWorldData.convertChunkToRealSpace(worldPos.x), + Globals.clientState.clientWorldData.convertChunkToRealSpace(worldPos.y), + Globals.clientState.clientWorldData.convertChunkToRealSpace(worldPos.z) ); if( playerPos.distance(chunkRealSpace) < drawRadius && worldPos.x >= 0 && - worldPos.x < Globals.clientWorldData.getWorldDiscreteSize() && + worldPos.x < Globals.clientState.clientWorldData.getWorldDiscreteSize() && worldPos.y >= 0 && - worldPos.y < Globals.clientWorldData.getWorldDiscreteSize() && + worldPos.y < Globals.clientState.clientWorldData.getWorldDiscreteSize() && worldPos.z >= 0 && - worldPos.z < Globals.clientWorldData.getWorldDiscreteSize() + worldPos.z < Globals.clientState.clientWorldData.getWorldDiscreteSize() ){ String key = getCellKey( worldPos.x, diff --git a/src/main/java/electrosphere/client/interact/ClientInteractionEngine.java b/src/main/java/electrosphere/client/interact/ClientInteractionEngine.java index 54f9cb64..e8ce8207 100644 --- a/src/main/java/electrosphere/client/interact/ClientInteractionEngine.java +++ b/src/main/java/electrosphere/client/interact/ClientInteractionEngine.java @@ -277,9 +277,9 @@ public class ClientInteractionEngine { collisionPosition.x >= 0 && collisionPosition.y >= 0 && collisionPosition.z >= 0 ){ //grab block at point - BlockChunkData blockChunkData = Globals.clientBlockManager.getChunkDataAtWorldPoint(Globals.clientWorldData.convertRealToWorldSpace(collisionPosition), 0); + BlockChunkData blockChunkData = Globals.clientBlockManager.getChunkDataAtWorldPoint(Globals.clientState.clientWorldData.convertRealToWorldSpace(collisionPosition), 0); if(blockChunkData != null){ - Vector3i blockPos = Globals.clientWorldData.convertRealToBlockSpace(new Vector3d(collisionPosition).add(new Vector3d(eyePos).mul(-BlockChunkData.BLOCK_SIZE_MULTIPLIER / 2.0f))); + Vector3i blockPos = Globals.clientState.clientWorldData.convertRealToBlockSpace(new Vector3d(collisionPosition).add(new Vector3d(eyePos).mul(-BlockChunkData.BLOCK_SIZE_MULTIPLIER / 2.0f))); if(!blockChunkData.isEmpty(blockPos.x, blockPos.y, blockPos.z)){ short type = blockChunkData.getType(blockPos.x, blockPos.y, blockPos.z); String text = Globals.gameConfigCurrent.getBlockData().getTypeFromId(type).getName(); @@ -291,9 +291,9 @@ public class ClientInteractionEngine { } //if we didn't find a block type, try terrain if(!set){ - ChunkData chunkData = Globals.clientTerrainManager.getChunkDataAtWorldPoint(Globals.clientWorldData.convertRealToWorldSpace(collisionPosition), 0); + ChunkData chunkData = Globals.clientTerrainManager.getChunkDataAtWorldPoint(Globals.clientState.clientWorldData.convertRealToWorldSpace(collisionPosition), 0); if(chunkData != null){ - int voxelType = chunkData.getType(Globals.clientWorldData.convertRealToVoxelSpace(new Vector3d(collisionPosition).add(new Vector3d(ServerTerrainChunk.VOXEL_SIZE / 2.0f)))); + int voxelType = chunkData.getType(Globals.clientState.clientWorldData.convertRealToVoxelSpace(new Vector3d(collisionPosition).add(new Vector3d(ServerTerrainChunk.VOXEL_SIZE / 2.0f)))); if(voxelType != ServerTerrainChunk.VOXEL_TYPE_AIR){ String text = Globals.gameConfigCurrent.getVoxelData().getTypeFromId(voxelType).getName(); InteractionTargetMenu.setInteractionTargetString(text); diff --git a/src/main/java/electrosphere/client/interact/select/AreaSelection.java b/src/main/java/electrosphere/client/interact/select/AreaSelection.java index da272b16..6a8e1090 100644 --- a/src/main/java/electrosphere/client/interact/select/AreaSelection.java +++ b/src/main/java/electrosphere/client/interact/select/AreaSelection.java @@ -151,7 +151,7 @@ public class AreaSelection { currVoxelPos.y % BlockChunkData.CHUNK_DATA_WIDTH, currVoxelPos.z % BlockChunkData.CHUNK_DATA_WIDTH ); - if(!Globals.clientWorldData.chunkInBounds(currChunkPos)){ + if(!Globals.clientState.clientWorldData.chunkInBounds(currChunkPos)){ switch(increment % 6){ case 0: { if(expandPositiveX){ @@ -324,13 +324,13 @@ public class AreaSelection { } } - Vector3d startPos = new Vector3d(Globals.clientWorldData.convertBlockToRealSpace(chunkPos, blockPos)) + Vector3d startPos = new Vector3d(Globals.clientState.clientWorldData.convertBlockToRealSpace(chunkPos, blockPos)) .add( startOffset.x * BlockChunkData.BLOCK_SIZE_MULTIPLIER, startOffset.y * BlockChunkData.BLOCK_SIZE_MULTIPLIER, startOffset.z * BlockChunkData.BLOCK_SIZE_MULTIPLIER ); - Vector3d endPos = new Vector3d(Globals.clientWorldData.convertBlockToRealSpace(chunkPos, blockPos)) + Vector3d endPos = new Vector3d(Globals.clientState.clientWorldData.convertBlockToRealSpace(chunkPos, blockPos)) .add( endOffset.x * BlockChunkData.BLOCK_SIZE_MULTIPLIER, endOffset.y * BlockChunkData.BLOCK_SIZE_MULTIPLIER, diff --git a/src/main/java/electrosphere/client/script/ScriptClientAreaUtils.java b/src/main/java/electrosphere/client/script/ScriptClientAreaUtils.java index 8c406817..3d2ea4d9 100644 --- a/src/main/java/electrosphere/client/script/ScriptClientAreaUtils.java +++ b/src/main/java/electrosphere/client/script/ScriptClientAreaUtils.java @@ -21,8 +21,8 @@ public class ScriptClientAreaUtils { public static void selectAreaRectangular(){ // Vector3d blockCursorPos = Globals.cursorState.getBlockCursorPos(); Vector3d cursorPos = new Vector3d(EntityUtils.getPosition(Globals.playerCursor)); - Vector3i chunkPos = Globals.clientWorldData.convertRealToWorldSpace(cursorPos); - Vector3i blockPos = Globals.clientWorldData.convertRealToBlockSpace(cursorPos); + Vector3i chunkPos = Globals.clientState.clientWorldData.convertRealToWorldSpace(cursorPos); + Vector3i blockPos = Globals.clientState.clientWorldData.convertRealToBlockSpace(cursorPos); AreaSelection selection = AreaSelection.selectRectangularBlockCavity(chunkPos, blockPos, AreaSelection.DEFAULT_SELECTION_RADIUS); Globals.cursorState.selectRectangularArea(selection); CursorState.makeAreaVisible(); diff --git a/src/main/java/electrosphere/client/script/ScriptClientVoxelUtils.java b/src/main/java/electrosphere/client/script/ScriptClientVoxelUtils.java index 71063182..2196d728 100644 --- a/src/main/java/electrosphere/client/script/ScriptClientVoxelUtils.java +++ b/src/main/java/electrosphere/client/script/ScriptClientVoxelUtils.java @@ -144,8 +144,8 @@ public class ScriptClientVoxelUtils { if(Globals.cursorState.getSelectedFabPath() != null){ String fabPath = Globals.cursorState.getSelectedFabPath(); Vector3d fabCursorPos = EntityUtils.getPosition(CursorState.getFabCursor()); - Vector3i chunkPos = Globals.clientWorldData.convertRealToWorldSpace(fabCursorPos); - Vector3i voxelPos = Globals.clientWorldData.convertRealToBlockSpace(fabCursorPos); + Vector3i chunkPos = Globals.clientState.clientWorldData.convertRealToWorldSpace(fabCursorPos); + Vector3i voxelPos = Globals.clientState.clientWorldData.convertRealToBlockSpace(fabCursorPos); int rotation = Globals.cursorState.getFabCursorRotation(); Globals.clientConnection.queueOutgoingMessage(TerrainMessage.constructRequestPlaceFabMessage( chunkPos.x, chunkPos.y, chunkPos.z, diff --git a/src/main/java/electrosphere/client/sim/ClientSimulation.java b/src/main/java/electrosphere/client/sim/ClientSimulation.java index 118a46d3..3fe03463 100644 --- a/src/main/java/electrosphere/client/sim/ClientSimulation.java +++ b/src/main/java/electrosphere/client/sim/ClientSimulation.java @@ -195,7 +195,7 @@ public class ClientSimulation { /// /// C L I E N T C E L L M A N A G E R /// - if(Globals.clientDrawCellManager != null && Globals.clientWorldData != null){ + if(Globals.clientDrawCellManager != null && Globals.clientState.clientWorldData != null){ //Cell manager do your things Globals.clientDrawCellManager.update(); } @@ -206,7 +206,7 @@ public class ClientSimulation { */ private void updateFluidCellManager(){ //fluid work - if(Globals.fluidCellManager != null && Globals.clientWorldData != null && Globals.RUN_FLUIDS){ + if(Globals.fluidCellManager != null && Globals.clientState.clientWorldData != null && Globals.RUN_FLUIDS){ Globals.fluidCellManager.update(); } } @@ -215,7 +215,7 @@ public class ClientSimulation { * Updates the block cell manager */ private void updateBlockCellManager(){ - if(Globals.clientBlockCellManager != null && Globals.clientWorldData != null){ + if(Globals.clientBlockCellManager != null && Globals.clientState.clientWorldData != null){ Globals.clientBlockCellManager.update(); } } diff --git a/src/main/java/electrosphere/client/terrain/cells/ClientDrawCellManager.java b/src/main/java/electrosphere/client/terrain/cells/ClientDrawCellManager.java index d61bc593..94108c86 100644 --- a/src/main/java/electrosphere/client/terrain/cells/ClientDrawCellManager.java +++ b/src/main/java/electrosphere/client/terrain/cells/ClientDrawCellManager.java @@ -174,7 +174,7 @@ public class ClientDrawCellManager { Globals.profiler.beginCpuSample("ClientDrawCellManager.update"); if(shouldUpdate && Globals.playerEntity != null){ Vector3d playerPos = EntityUtils.getPosition(Globals.playerEntity); - Vector3i playerWorldPos = Globals.clientWorldData.convertRealToWorldSpace(playerPos); + Vector3i playerWorldPos = Globals.clientState.clientWorldData.convertRealToWorldSpace(playerPos); int distCache = this.getDistCache(this.lastPlayerPos, playerWorldPos); if(this.bustDistCache){ this.bustDistCache = false; @@ -804,8 +804,8 @@ public class ClientDrawCellManager { */ public boolean isFullLOD(Vector3i worldPos){ Vector3d playerRealPos = EntityUtils.getPosition(Globals.playerEntity); - Vector3d chunkMin = Globals.clientWorldData.convertWorldToRealSpace(worldPos); - Vector3d chunkMax = Globals.clientWorldData.convertWorldToRealSpace(new Vector3i(worldPos).add(1,1,1)); + Vector3d chunkMin = Globals.clientState.clientWorldData.convertWorldToRealSpace(worldPos); + Vector3d chunkMax = Globals.clientState.clientWorldData.convertWorldToRealSpace(new Vector3i(worldPos).add(1,1,1)); return GeomUtils.getMinDistanceAABB(playerRealPos, chunkMin, chunkMax) <= FULL_RES_DIST; } @@ -843,11 +843,11 @@ public class ClientDrawCellManager { Vector3i worldPos = node.getMinBound(); if( worldPos.x >= 0 && - worldPos.x < Globals.clientWorldData.getWorldDiscreteSize() && + worldPos.x < Globals.clientState.clientWorldData.getWorldDiscreteSize() && worldPos.y >= 0 && - worldPos.y < Globals.clientWorldData.getWorldDiscreteSize() && + worldPos.y < Globals.clientState.clientWorldData.getWorldDiscreteSize() && worldPos.z >= 0 && - worldPos.z < Globals.clientWorldData.getWorldDiscreteSize() && + worldPos.z < Globals.clientState.clientWorldData.getWorldDiscreteSize() && !Globals.clientTerrainManager.containsChunkDataAtWorldPoint(worldPos.x, worldPos.y, worldPos.z, lod) ){ //client should request chunk data from server for each chunk necessary to create the model @@ -887,11 +887,11 @@ public class ClientDrawCellManager { } if( posToCheck.x >= 0 && - posToCheck.x < Globals.clientWorldData.getWorldDiscreteSize() && + posToCheck.x < Globals.clientState.clientWorldData.getWorldDiscreteSize() && posToCheck.y >= 0 && - posToCheck.y < Globals.clientWorldData.getWorldDiscreteSize() && + posToCheck.y < Globals.clientState.clientWorldData.getWorldDiscreteSize() && posToCheck.z >= 0 && - posToCheck.z < Globals.clientWorldData.getWorldDiscreteSize() && + posToCheck.z < Globals.clientState.clientWorldData.getWorldDiscreteSize() && !Globals.clientTerrainManager.containsChunkDataAtWorldPoint(posToCheck.x, posToCheck.y, posToCheck.z, highResLod) ){ LoggerInterface.loggerNetworking.DEBUG("(Client) Send Request for terrain at " + posToCheck); @@ -951,11 +951,11 @@ public class ClientDrawCellManager { } if( posToCheck.x >= 0 && - posToCheck.x < Globals.clientWorldData.getWorldDiscreteSize() && + posToCheck.x < Globals.clientState.clientWorldData.getWorldDiscreteSize() && posToCheck.y >= 0 && - posToCheck.y < Globals.clientWorldData.getWorldDiscreteSize() && + posToCheck.y < Globals.clientState.clientWorldData.getWorldDiscreteSize() && posToCheck.z >= 0 && - posToCheck.z < Globals.clientWorldData.getWorldDiscreteSize() && + posToCheck.z < Globals.clientState.clientWorldData.getWorldDiscreteSize() && !Globals.clientTerrainManager.containsChunkDataAtWorldPoint(posToCheck.x, posToCheck.y, posToCheck.z, highResLod) ){ return false; diff --git a/src/main/java/electrosphere/client/terrain/editing/BlockEditing.java b/src/main/java/electrosphere/client/terrain/editing/BlockEditing.java index 284c0bc4..d86510cb 100644 --- a/src/main/java/electrosphere/client/terrain/editing/BlockEditing.java +++ b/src/main/java/electrosphere/client/terrain/editing/BlockEditing.java @@ -16,9 +16,9 @@ public class BlockEditing { * @param metadata The metadata of the block */ public static void editBlock(short type, short metadata){ - Vector3i cornerVoxel = Globals.clientWorldData.convertRealToBlockSpace(Globals.cursorState.getBlockCursorPos()); + Vector3i cornerVoxel = Globals.clientState.clientWorldData.convertRealToBlockSpace(Globals.cursorState.getBlockCursorPos()); int blockSize = Globals.cursorState.getBlockSize(); - Vector3i chunkPos = Globals.clientWorldData.convertRealToWorldSpace(Globals.cursorState.getBlockCursorPos()); + Vector3i chunkPos = Globals.clientState.clientWorldData.convertRealToWorldSpace(Globals.cursorState.getBlockCursorPos()); ScriptClientVoxelUtils.clientRequestEditBlock(chunkPos, cornerVoxel, type, metadata, blockSize); } @@ -26,9 +26,9 @@ public class BlockEditing { * Destroy blocks */ public static void destroyBlock(){ - Vector3i cornerVoxel = Globals.clientWorldData.convertRealToBlockSpace(Globals.cursorState.getBlockCursorPos()); + Vector3i cornerVoxel = Globals.clientState.clientWorldData.convertRealToBlockSpace(Globals.cursorState.getBlockCursorPos()); int blockSize = Globals.cursorState.getBlockSize(); - Vector3i chunkPos = Globals.clientWorldData.convertRealToWorldSpace(Globals.cursorState.getBlockCursorPos()); + Vector3i chunkPos = Globals.clientState.clientWorldData.convertRealToWorldSpace(Globals.cursorState.getBlockCursorPos()); ScriptClientVoxelUtils.clientRequestEditBlock(chunkPos, cornerVoxel, (short)0, (short)0, blockSize); } diff --git a/src/main/java/electrosphere/client/terrain/foliage/FoliageCell.java b/src/main/java/electrosphere/client/terrain/foliage/FoliageCell.java index 0721ae1a..d8890167 100644 --- a/src/main/java/electrosphere/client/terrain/foliage/FoliageCell.java +++ b/src/main/java/electrosphere/client/terrain/foliage/FoliageCell.java @@ -199,8 +199,8 @@ public class FoliageCell { ){ FoliageCell rVal = new FoliageCell(); rVal.lod = lod; - rVal.worldPos = Globals.clientWorldData.convertAbsoluteVoxelToWorldSpace(voxelAbsPos); - rVal.voxelPos = Globals.clientWorldData.convertAbsoluteVoxelToRelativeVoxelSpace(voxelAbsPos); + rVal.worldPos = Globals.clientState.clientWorldData.convertAbsoluteVoxelToWorldSpace(voxelAbsPos); + rVal.voxelPos = Globals.clientState.clientWorldData.convertAbsoluteVoxelToRelativeVoxelSpace(voxelAbsPos); return rVal; } @@ -213,8 +213,8 @@ public class FoliageCell { ){ FoliageCell rVal = new FoliageCell(); rVal.lod = lod; - rVal.worldPos = Globals.clientWorldData.convertAbsoluteVoxelToWorldSpace(voxelAbsPos); - rVal.voxelPos = Globals.clientWorldData.convertAbsoluteVoxelToRelativeVoxelSpace(voxelAbsPos); + rVal.worldPos = Globals.clientState.clientWorldData.convertAbsoluteVoxelToWorldSpace(voxelAbsPos); + rVal.voxelPos = Globals.clientState.clientWorldData.convertAbsoluteVoxelToRelativeVoxelSpace(voxelAbsPos); rVal.hasGenerated = true; rVal.homogenous = true; return rVal; diff --git a/src/main/java/electrosphere/client/terrain/foliage/FoliageCellManager.java b/src/main/java/electrosphere/client/terrain/foliage/FoliageCellManager.java index 31d023ce..f335906a 100644 --- a/src/main/java/electrosphere/client/terrain/foliage/FoliageCellManager.java +++ b/src/main/java/electrosphere/client/terrain/foliage/FoliageCellManager.java @@ -196,7 +196,7 @@ public class FoliageCellManager { Globals.profiler.beginCpuSample("FoliageCellManager.update"); if(shouldUpdate && Globals.playerEntity != null && Globals.userSettings.getGraphicsPerformanceEnableFoliageManager()){ Vector3d playerPos = EntityUtils.getPosition(Globals.playerEntity); - Vector3i absVoxelPos = Globals.clientWorldData.convertRealToAbsoluteVoxelSpace(playerPos); + Vector3i absVoxelPos = Globals.clientState.clientWorldData.convertRealToAbsoluteVoxelSpace(playerPos); int distCache = this.getDistCache(this.lastPlayerPos, absVoxelPos); if(bustDistCache || absVoxelPos.distance(this.lastPlayerPos) > TELEPORT_DISTANCE){ distCache = BUST_META_CELLS; @@ -743,8 +743,8 @@ public class FoliageCellManager { */ public boolean isFullLOD(Vector3i worldPos){ Vector3d playerRealPos = EntityUtils.getPosition(Globals.playerEntity); - Vector3d chunkMin = Globals.clientWorldData.convertWorldToRealSpace(worldPos); - Vector3d chunkMax = Globals.clientWorldData.convertWorldToRealSpace(new Vector3i(worldPos).add(1,1,1)); + Vector3d chunkMin = Globals.clientState.clientWorldData.convertWorldToRealSpace(worldPos); + Vector3d chunkMax = Globals.clientState.clientWorldData.convertWorldToRealSpace(new Vector3i(worldPos).add(1,1,1)); return GeomUtils.getMinDistanceAABB(playerRealPos, chunkMin, chunkMax) <= FULL_RES_DIST; } @@ -768,9 +768,9 @@ public class FoliageCellManager { * @param voxelZ The voxel z position */ public void markUpdateable(int worldX, int worldY, int worldZ, int voxelX, int voxelY, int voxelZ){ - int absVoxelX = Globals.clientWorldData.convertRelativeVoxelToAbsoluteVoxelSpace(voxelX,worldX); - int absVoxelY = Globals.clientWorldData.convertRelativeVoxelToAbsoluteVoxelSpace(voxelY,worldY); - int absVoxelZ = Globals.clientWorldData.convertRelativeVoxelToAbsoluteVoxelSpace(voxelZ,worldZ); + int absVoxelX = Globals.clientState.clientWorldData.convertRelativeVoxelToAbsoluteVoxelSpace(voxelX,worldX); + int absVoxelY = Globals.clientState.clientWorldData.convertRelativeVoxelToAbsoluteVoxelSpace(voxelY,worldY); + int absVoxelZ = Globals.clientState.clientWorldData.convertRelativeVoxelToAbsoluteVoxelSpace(voxelZ,worldZ); FoliageCell foliageCell = this.getFoliageCell(absVoxelX, absVoxelY, absVoxelZ); foliageCell.ejectChunkData(); foliageCell.setHasGenerated(false); @@ -787,9 +787,9 @@ public class FoliageCellManager { for(int x = 0; x < ServerTerrainChunk.CHUNK_DIMENSION; x++){ for(int y = 0; y < ServerTerrainChunk.CHUNK_DIMENSION; y++){ for(int z = 0; z < ServerTerrainChunk.CHUNK_DIMENSION; z++){ - int absVoxelX = Globals.clientWorldData.convertRelativeVoxelToAbsoluteVoxelSpace(x,worldX); - int absVoxelY = Globals.clientWorldData.convertRelativeVoxelToAbsoluteVoxelSpace(y,worldY); - int absVoxelZ = Globals.clientWorldData.convertRelativeVoxelToAbsoluteVoxelSpace(z,worldZ); + int absVoxelX = Globals.clientState.clientWorldData.convertRelativeVoxelToAbsoluteVoxelSpace(x,worldX); + int absVoxelY = Globals.clientState.clientWorldData.convertRelativeVoxelToAbsoluteVoxelSpace(y,worldY); + int absVoxelZ = Globals.clientState.clientWorldData.convertRelativeVoxelToAbsoluteVoxelSpace(z,worldZ); FoliageCell foliageCell = this.getFoliageCell(absVoxelX, absVoxelY, absVoxelZ); foliageCell.ejectChunkData(); foliageCell.setHasGenerated(false); @@ -806,14 +806,14 @@ public class FoliageCellManager { */ private boolean requestChunks(WorldOctTree.WorldOctTreeNode node){ //min bound is in absolute voxel coordinates, need to convert to world coordinates - Vector3i worldPos = Globals.clientWorldData.convertAbsoluteVoxelToWorldSpace(node.getMinBound()); + Vector3i worldPos = Globals.clientState.clientWorldData.convertAbsoluteVoxelToWorldSpace(node.getMinBound()); if( worldPos.x >= 0 && - worldPos.x < Globals.clientWorldData.getWorldDiscreteSize() && + worldPos.x < Globals.clientState.clientWorldData.getWorldDiscreteSize() && worldPos.y >= 0 && - worldPos.y < Globals.clientWorldData.getWorldDiscreteSize() && + worldPos.y < Globals.clientState.clientWorldData.getWorldDiscreteSize() && worldPos.z >= 0 && - worldPos.z < Globals.clientWorldData.getWorldDiscreteSize() && + worldPos.z < Globals.clientState.clientWorldData.getWorldDiscreteSize() && !Globals.clientTerrainManager.containsChunkDataAtWorldPoint(worldPos.x, worldPos.y, worldPos.z, ChunkData.NO_STRIDE) ){ //client should request chunk data from server for each chunk necessary to create the model diff --git a/src/main/java/electrosphere/client/terrain/sampling/ClientVoxelSampler.java b/src/main/java/electrosphere/client/terrain/sampling/ClientVoxelSampler.java index b60bf00c..c0d12d64 100644 --- a/src/main/java/electrosphere/client/terrain/sampling/ClientVoxelSampler.java +++ b/src/main/java/electrosphere/client/terrain/sampling/ClientVoxelSampler.java @@ -35,8 +35,8 @@ public class ClientVoxelSampler { */ public static int getVoxelType(Vector3d realPos){ int voxelId = 0; - Vector3i chunkSpacePos = Globals.clientWorldData.convertRealToWorldSpace(realPos); - Vector3i voxelSpacePos = Globals.clientWorldData.convertRealToVoxelSpace(realPos); + Vector3i chunkSpacePos = Globals.clientState.clientWorldData.convertRealToWorldSpace(realPos); + Vector3i voxelSpacePos = Globals.clientState.clientWorldData.convertRealToVoxelSpace(realPos); if(Globals.clientTerrainManager.containsChunkDataAtWorldPoint(chunkSpacePos, ChunkData.NO_STRIDE)){ ChunkData chunkData = Globals.clientTerrainManager.getChunkDataAtWorldPoint(chunkSpacePos, ChunkData.NO_STRIDE); voxelId = chunkData.getType(voxelSpacePos); diff --git a/src/main/java/electrosphere/client/ui/menu/debug/client/ImGuiChunkMonitor.java b/src/main/java/electrosphere/client/ui/menu/debug/client/ImGuiChunkMonitor.java index 24541d08..5736a21d 100644 --- a/src/main/java/electrosphere/client/ui/menu/debug/client/ImGuiChunkMonitor.java +++ b/src/main/java/electrosphere/client/ui/menu/debug/client/ImGuiChunkMonitor.java @@ -45,7 +45,7 @@ public class ImGuiChunkMonitor { } if(ImGui.button("Break at chunk")){ if(Globals.foliageCellManager != null){ - Vector3i absVoxelPos = Globals.clientWorldData.convertRealToAbsoluteVoxelSpace(EntityUtils.getPosition(Globals.playerEntity)); + Vector3i absVoxelPos = Globals.clientState.clientWorldData.convertRealToAbsoluteVoxelSpace(EntityUtils.getPosition(Globals.playerEntity)); Globals.foliageCellManager.addBreakPoint(absVoxelPos); } } diff --git a/src/main/java/electrosphere/client/ui/menu/debug/client/ImGuiClientServices.java b/src/main/java/electrosphere/client/ui/menu/debug/client/ImGuiClientServices.java index 6cff3e09..7e69f7c0 100644 --- a/src/main/java/electrosphere/client/ui/menu/debug/client/ImGuiClientServices.java +++ b/src/main/java/electrosphere/client/ui/menu/debug/client/ImGuiClientServices.java @@ -34,7 +34,7 @@ public class ImGuiClientServices { if(ImGui.collapsingHeader("Draw Cells")){ if(ImGui.button("Debug DrawCell at camera position")){ - Vector3i cameraWorldPos = Globals.clientWorldData.convertRealToWorldSpace(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); + Vector3i cameraWorldPos = Globals.clientState.clientWorldData.convertRealToWorldSpace(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); DrawCell cell = Globals.clientDrawCellManager.getDrawCell(cameraWorldPos.x, cameraWorldPos.y, cameraWorldPos.z); LoggerInterface.loggerEngine.WARNING("" + cell); @@ -60,17 +60,17 @@ public class ImGuiClientServices { } } if(ImGui.button("Print debug info for FoliageCell at camera position")){ - Vector3i cameraWorldPos = Globals.clientWorldData.convertRealToWorldSpace(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); + Vector3i cameraWorldPos = Globals.clientState.clientWorldData.convertRealToWorldSpace(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); FoliageCell cell = Globals.foliageCellManager.getFoliageCell(cameraWorldPos.x, cameraWorldPos.y, cameraWorldPos.z); LoggerInterface.loggerEngine.WARNING("" + cell); } if(ImGui.button("Debug FoliageCell evaluation at camera position")){ - Vector3i cameraWorldPos = Globals.clientWorldData.convertRealToWorldSpace(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); + Vector3i cameraWorldPos = Globals.clientState.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")){ - Vector3i cameraWorldPos = Globals.clientWorldData.convertRealToWorldSpace(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); + Vector3i cameraWorldPos = Globals.clientState.clientWorldData.convertRealToWorldSpace(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); Globals.clientTerrainManager.requestChunk(cameraWorldPos.x, cameraWorldPos.y, cameraWorldPos.z, 0); } } diff --git a/src/main/java/electrosphere/collision/CollisionWorldData.java b/src/main/java/electrosphere/collision/CollisionWorldData.java index bffe31df..f25b8d78 100644 --- a/src/main/java/electrosphere/collision/CollisionWorldData.java +++ b/src/main/java/electrosphere/collision/CollisionWorldData.java @@ -1,7 +1,7 @@ package electrosphere.collision; -import electrosphere.client.scene.ClientWorldData; import electrosphere.client.terrain.manager.ClientTerrainManager; +import electrosphere.engine.Globals; import electrosphere.server.datacell.ServerWorldData; import electrosphere.server.physics.terrain.manager.ServerTerrainManager; @@ -11,66 +11,65 @@ public class CollisionWorldData { - ClientWorldData clientWorldData; ClientTerrainManager clientTerrainManager; ServerWorldData serverWorldData; ServerTerrainManager serverTerrainManager; + + public CollisionWorldData(){ + + } public CollisionWorldData(ServerWorldData serverWorldData){ this.serverWorldData = serverWorldData; } - - public CollisionWorldData(ClientWorldData clientWorldData){ - this.clientWorldData = clientWorldData; - } public Vector3f getWorldBoundMin(){ - if(clientWorldData != null){ - return clientWorldData.getWorldBoundMin(); + if(Globals.clientState.clientWorldData != null){ + return Globals.clientState.clientWorldData.getWorldBoundMin(); } else { return serverWorldData.getWorldBoundMin(); } } public Vector3f getWorldBoundMax(){ - if(clientWorldData != null){ - return clientWorldData.getWorldBoundMax(); + if(Globals.clientState.clientWorldData != null){ + return Globals.clientState.clientWorldData.getWorldBoundMax(); } else { return serverWorldData.getWorldBoundMax(); } } public int convertRealToWorld(double real){ - if(clientWorldData != null){ - return clientWorldData.convertRealToChunkSpace(real); + if(Globals.clientState.clientWorldData != null){ + return Globals.clientState.clientWorldData.convertRealToChunkSpace(real); } else { return ServerWorldData.convertRealToChunkSpace(real); } } public double convertWorldToReal(int world){ - if(clientWorldData != null){ - return clientWorldData.convertChunkToRealSpace(world); + if(Globals.clientState.clientWorldData != null){ + return Globals.clientState.clientWorldData.convertChunkToRealSpace(world); } else { return ServerWorldData.convertChunkToRealSpace(world); } } public int getDynamicInterpolationRatio(){ - if(clientWorldData != null){ - return clientWorldData.getWorldDiscreteSize(); + if(Globals.clientState.clientWorldData != null){ + return Globals.clientState.clientWorldData.getWorldDiscreteSize(); } else { return serverWorldData.getDynamicInterpolationRatio(); } } public int getWorldDiscreteSize(){ - if(clientWorldData != null){ - return clientWorldData.getWorldDiscreteSize(); + if(Globals.clientState.clientWorldData != null){ + return Globals.clientState.clientWorldData.getWorldDiscreteSize(); } else { return serverWorldData.getWorldSizeDiscrete(); } diff --git a/src/main/java/electrosphere/engine/Globals.java b/src/main/java/electrosphere/engine/Globals.java index e77daed5..4ac81856 100644 --- a/src/main/java/electrosphere/engine/Globals.java +++ b/src/main/java/electrosphere/engine/Globals.java @@ -12,6 +12,7 @@ import electrosphere.audio.VirtualAudioSourceManager; import electrosphere.audio.collision.HitboxAudioService; import electrosphere.audio.movement.MovementAudioService; import electrosphere.auth.AuthenticationManager; +import electrosphere.client.ClientState; import electrosphere.client.block.ClientBlockManager; import electrosphere.client.block.cells.BlockTextureAtlas; import electrosphere.client.block.cells.ClientBlockCellManager; @@ -23,7 +24,6 @@ import electrosphere.client.fluid.manager.ClientFluidManager; import electrosphere.client.player.ClientPlayerData; import electrosphere.client.scene.ClientLevelEditorData; import electrosphere.client.scene.ClientSceneWrapper; -import electrosphere.client.scene.ClientWorldData; import electrosphere.client.sim.ClientSimulation; import electrosphere.client.terrain.cells.ClientDrawCellManager; import electrosphere.client.terrain.cells.VoxelTextureAtlas; @@ -351,7 +351,6 @@ public class Globals { public static FoliageCellManager foliageCellManager; //client world data - public static ClientWorldData clientWorldData; public static ClientCharacterManager clientCharacterManager = new ClientCharacterManager(); //client gridded manager @@ -430,7 +429,11 @@ public class Globals { public static Entity draggedItem = null; public static Object dragSourceInventory = null; public static Entity targetContainer = null; - + + /** + * State for the client + */ + public static ClientState clientState = new ClientState(); @@ -490,6 +493,10 @@ public class Globals { RENDER_FLAG_RENDER_WHITE_BACKGROUND = false; RENDER_FLAG_RENDER_UI = true; RENDER_FLAG_RENDER_UI_BOUNDS = false; + + //client state + Globals.clientState = new ClientState(); + //load in default texture map textureMapDefault = TextureMap.construct("Textures/default_texture_map.json"); //load model pretransforms @@ -719,7 +726,7 @@ public class Globals { Globals.playerManager = new PlayerManager(); Globals.clientScene = new Scene(); Globals.clientSceneWrapper = new ClientSceneWrapper(Globals.clientScene, new CollisionEngine(), CollisionEngine.create(new ClientChemistryCollisionCallback()), new CollisionEngine()); - Globals.clientWorldData = null; + Globals.clientState = new ClientState(); Globals.clientSynchronizationManager = new ClientSynchronizationManager(); Globals.server = null; Globals.serverSynchronizationManager = new ServerSynchronizationManager(); @@ -748,7 +755,7 @@ public class Globals { Globals.realmManager = null; Globals.clientSceneWrapper = null; Globals.clientScene = null; - Globals.clientWorldData = null; + Globals.clientState = null; Globals.audioEngine = null; Globals.renderingEngine = null; Globals.threadManager = null; diff --git a/src/main/java/electrosphere/engine/loadingthreads/ClientLoading.java b/src/main/java/electrosphere/engine/loadingthreads/ClientLoading.java index cedd0177..a4998bd8 100644 --- a/src/main/java/electrosphere/engine/loadingthreads/ClientLoading.java +++ b/src/main/java/electrosphere/engine/loadingthreads/ClientLoading.java @@ -320,7 +320,7 @@ public class ClientLoading { static void initDrawCellManager(boolean blockForInit){ int iterations = 0; WindowUtils.updateLoadingWindow("WAITING ON WORLD DATA"); - while(blockForInit && (Globals.clientWorldData == null || InitialAssetLoading.atlasQueuedTexture == null || !InitialAssetLoading.atlasQueuedTexture.hasLoaded()) && Globals.threadManager.shouldKeepRunning()){ + while(blockForInit && (Globals.clientState.clientWorldData == null || InitialAssetLoading.atlasQueuedTexture == null || !InitialAssetLoading.atlasQueuedTexture.hasLoaded()) && Globals.threadManager.shouldKeepRunning()){ try { TimeUnit.MILLISECONDS.sleep(10); iterations++; @@ -329,14 +329,14 @@ public class ClientLoading { } if(iterations > MAX_DRAW_CELL_WAIT){ String message = "Draw cell took too long to init!\n" + - Globals.clientWorldData + "\n" + + Globals.clientState.clientWorldData + "\n" + InitialAssetLoading.atlasQueuedTexture.hasLoaded(); throw new IllegalStateException(message); } } //initialize draw cell manager // Globals.drawCellManager = new DrawCellManager(Globals.clientTerrainManager, 0, 0, 0); - Globals.clientDrawCellManager = new ClientDrawCellManager(Globals.voxelTextureAtlas, Globals.clientWorldData.getWorldDiscreteSize()); + Globals.clientDrawCellManager = new ClientDrawCellManager(Globals.voxelTextureAtlas, Globals.clientState.clientWorldData.getWorldDiscreteSize()); //Alerts the client simulation that it should start loading terrain Globals.clientSimulation.setLoadingTerrain(true); //wait for all the terrain data to arrive @@ -366,7 +366,7 @@ public class ClientLoading { //wait for world data WindowUtils.updateLoadingWindow("WAITING ON WORLD DATA"); - while(blockForInit && Globals.clientWorldData == null && Globals.threadManager.shouldKeepRunning()){ + while(blockForInit && Globals.clientState.clientWorldData == null && Globals.threadManager.shouldKeepRunning()){ try { TimeUnit.MILLISECONDS.sleep(10); } catch (InterruptedException ex) { @@ -406,7 +406,7 @@ public class ClientLoading { static void initBlockCellManager(boolean blockForInit){ int iterations = 0; WindowUtils.updateLoadingWindow("WAITING ON WORLD DATA"); - while(blockForInit && (Globals.clientWorldData == null || InitialAssetLoading.atlasQueuedTexture == null || !InitialAssetLoading.atlasQueuedTexture.hasLoaded()) && Globals.threadManager.shouldKeepRunning()){ + while(blockForInit && (Globals.clientState.clientWorldData == null || InitialAssetLoading.atlasQueuedTexture == null || !InitialAssetLoading.atlasQueuedTexture.hasLoaded()) && Globals.threadManager.shouldKeepRunning()){ try { TimeUnit.MILLISECONDS.sleep(10); iterations++; @@ -415,12 +415,12 @@ public class ClientLoading { } if(iterations > MAX_DRAW_CELL_WAIT){ String message = "Draw cell took too long to init!\n" + - Globals.clientWorldData + "\n" + + Globals.clientState.clientWorldData + "\n" + InitialAssetLoading.atlasQueuedTexture.hasLoaded(); throw new IllegalStateException(message); } } - Globals.clientBlockCellManager = new ClientBlockCellManager(Globals.blockTextureAtlas, Globals.clientWorldData.getWorldDiscreteSize()); + Globals.clientBlockCellManager = new ClientBlockCellManager(Globals.blockTextureAtlas, Globals.clientState.clientWorldData.getWorldDiscreteSize()); //Alerts the client simulation that it should start loading blocks Globals.clientSimulation.setLoadingTerrain(true); //wait for all the block data to arrive @@ -446,7 +446,7 @@ public class ClientLoading { * Starts up the foliage manager */ private static void initFoliageManager(){ - Globals.foliageCellManager = new FoliageCellManager(Globals.clientWorldData.getWorldDiscreteSize()); + Globals.foliageCellManager = new FoliageCellManager(Globals.clientState.clientWorldData.getWorldDiscreteSize()); Globals.foliageCellManager.init(); // Globals.foliageCellManager.start(); } diff --git a/src/main/java/electrosphere/engine/loadingthreads/ViewportLoading.java b/src/main/java/electrosphere/engine/loadingthreads/ViewportLoading.java index cd013fc1..28ee90fd 100644 --- a/src/main/java/electrosphere/engine/loadingthreads/ViewportLoading.java +++ b/src/main/java/electrosphere/engine/loadingthreads/ViewportLoading.java @@ -68,7 +68,7 @@ public class ViewportLoading { Globals.clientConnection.queueOutgoingMessage(TerrainMessage.constructRequestMetadataMessage()); //block for client world data - while(Globals.clientWorldData == null){ + while(Globals.clientState.clientWorldData == null){ try { TimeUnit.MILLISECONDS.sleep(10); } catch (InterruptedException e) { diff --git a/src/main/java/electrosphere/engine/service/ServiceManager.java b/src/main/java/electrosphere/engine/service/ServiceManager.java index 182b096c..4b1f4f69 100644 --- a/src/main/java/electrosphere/engine/service/ServiceManager.java +++ b/src/main/java/electrosphere/engine/service/ServiceManager.java @@ -66,8 +66,10 @@ public class ServiceManager { * Fires all functions required to unload a scene. */ public void unloadScene(){ - for(Service serivce : this.trackedServices){ - serivce.unloadScene(); + if(this.trackedServices != null){ + for(Service serivce : this.trackedServices){ + serivce.unloadScene(); + } } } diff --git a/src/main/java/electrosphere/entity/state/collidable/ClientCollidableTree.java b/src/main/java/electrosphere/entity/state/collidable/ClientCollidableTree.java index 6fb19f90..b0942cd8 100644 --- a/src/main/java/electrosphere/entity/state/collidable/ClientCollidableTree.java +++ b/src/main/java/electrosphere/entity/state/collidable/ClientCollidableTree.java @@ -53,15 +53,15 @@ public class ClientCollidableTree implements BehaviorTree { Quaterniond rotation = EntityUtils.getRotation(parent); Vector3d newPosition = new Vector3d(position); //bound to world bounds - if(Globals.clientWorldData != null){ - if(newPosition.x < Globals.clientWorldData.getWorldBoundMin().x){ - newPosition.x = Globals.clientWorldData.getWorldBoundMin().x; + if(Globals.clientState.clientWorldData != null){ + if(newPosition.x < Globals.clientState.clientWorldData.getWorldBoundMin().x){ + newPosition.x = Globals.clientState.clientWorldData.getWorldBoundMin().x; } - if(newPosition.y < Globals.clientWorldData.getWorldBoundMin().y){ - newPosition.y = Globals.clientWorldData.getWorldBoundMin().y; + if(newPosition.y < Globals.clientState.clientWorldData.getWorldBoundMin().y){ + newPosition.y = Globals.clientState.clientWorldData.getWorldBoundMin().y; } - if(newPosition.z < Globals.clientWorldData.getWorldBoundMin().z){ - newPosition.z = Globals.clientWorldData.getWorldBoundMin().z; + if(newPosition.z < Globals.clientState.clientWorldData.getWorldBoundMin().z){ + newPosition.z = Globals.clientState.clientWorldData.getWorldBoundMin().z; } } PhysicsUtils.setRigidBodyTransform(Globals.clientSceneWrapper.getCollisionEngine(), newPosition, rotation, body); diff --git a/src/main/java/electrosphere/entity/state/movement/editor/ClientEditorMovementTree.java b/src/main/java/electrosphere/entity/state/movement/editor/ClientEditorMovementTree.java index 34754012..a18c4721 100644 --- a/src/main/java/electrosphere/entity/state/movement/editor/ClientEditorMovementTree.java +++ b/src/main/java/electrosphere/entity/state/movement/editor/ClientEditorMovementTree.java @@ -2,7 +2,6 @@ package electrosphere.entity.state.movement.editor; import electrosphere.entity.state.gravity.GravityUtils; -import electrosphere.client.scene.ClientWorldData; import electrosphere.data.creature.movement.EditorMovementSystem; import electrosphere.engine.Globals; import electrosphere.entity.types.creature.CreatureUtils; @@ -197,7 +196,6 @@ public class ClientEditorMovementTree implements BehaviorTree { float maxNaturalVelocity = EDITOR_MAX_VELOCITY; Entity serverEntity = EntityLookupUtils.getEntityById(Globals.clientSceneWrapper.mapClientToServerId(parent.getId())); - ClientWorldData clientWorldData = Globals.clientWorldData; // //rotation update @@ -260,7 +258,7 @@ public class ClientEditorMovementTree implements BehaviorTree { rotation.set(movementQuaternion); position.set(new Vector3d(position).add(new Vector3d(movementVector).mul(velocity))); if(serverEntity != null){ - if(position.x >= 0 && position.y >= 0 && position.z >= 0 && position.x < clientWorldData.getWorldBoundMax().x && position.y < clientWorldData.getWorldBoundMax().y && position.z < clientWorldData.getWorldBoundMax().z){ + if(position.x >= 0 && position.y >= 0 && position.z >= 0 && position.x < Globals.clientState.clientWorldData.getWorldBoundMax().x && position.y < Globals.clientState.clientWorldData.getWorldBoundMax().y && position.z < Globals.clientState.clientWorldData.getWorldBoundMax().z){ ServerEntityUtils.repositionEntity(serverEntity, new Vector3d(position)); } } @@ -277,7 +275,7 @@ public class ClientEditorMovementTree implements BehaviorTree { rotation.set(movementQuaternion); position.set(new Vector3d(position).add(new Vector3d(movementVector).mul(velocity))); if(serverEntity != null){ - if(position.x >= 0 && position.y >= 0 && position.z >= 0 && position.x < clientWorldData.getWorldBoundMax().x && position.y < clientWorldData.getWorldBoundMax().y && position.z < clientWorldData.getWorldBoundMax().z){ + if(position.x >= 0 && position.y >= 0 && position.z >= 0 && position.x < Globals.clientState.clientWorldData.getWorldBoundMax().x && position.y < Globals.clientState.clientWorldData.getWorldBoundMax().y && position.z < Globals.clientState.clientWorldData.getWorldBoundMax().z){ ServerEntityUtils.repositionEntity(serverEntity, new Vector3d(position)); } } @@ -300,7 +298,7 @@ public class ClientEditorMovementTree implements BehaviorTree { rotation.set(movementQuaternion); position.set(new Vector3d(position).add(new Vector3d(movementVector).mul(velocity))); if(serverEntity != null){ - if(position.x >= 0 && position.y >= 0 && position.z >= 0 && position.x < clientWorldData.getWorldBoundMax().x && position.y < clientWorldData.getWorldBoundMax().y && position.z < clientWorldData.getWorldBoundMax().z){ + if(position.x >= 0 && position.y >= 0 && position.z >= 0 && position.x < Globals.clientState.clientWorldData.getWorldBoundMax().x && position.y < Globals.clientState.clientWorldData.getWorldBoundMax().y && position.z < Globals.clientState.clientWorldData.getWorldBoundMax().z){ ServerEntityUtils.repositionEntity(serverEntity, new Vector3d(position)); } } diff --git a/src/main/java/electrosphere/net/client/protocol/TerrainProtocol.java b/src/main/java/electrosphere/net/client/protocol/TerrainProtocol.java index dff10c2a..b430ebf1 100644 --- a/src/main/java/electrosphere/net/client/protocol/TerrainProtocol.java +++ b/src/main/java/electrosphere/net/client/protocol/TerrainProtocol.java @@ -31,7 +31,7 @@ public class TerrainProtocol implements ClientProtocolTemplate { Globals.profiler.beginAggregateCpuSample("TerrainProtocol.handleTerrainMessage"); switch(message.getMessageSubtype()){ case RESPONSEMETADATA: - Globals.clientWorldData = new ClientWorldData( + Globals.clientState.clientWorldData = new ClientWorldData( //Vector3f worldMinPoint, Vector3f worldMaxPoint, int dynamicInterpolationRatio, float randomDampener, int worldDiscreteSize new Vector3f( message.getworldMinX(), @@ -45,7 +45,7 @@ public class TerrainProtocol implements ClientProtocolTemplate { ), message.getworldSizeDiscrete() ); - Globals.clientSceneWrapper.getCollisionEngine().setCollisionWorldData(new CollisionWorldData(Globals.clientWorldData)); + Globals.clientSceneWrapper.getCollisionEngine().setCollisionWorldData(new CollisionWorldData()); Globals.clientConnection.getMessageProtocol().setHasReceivedWorld(true); break; case SPAWNPOSITION: @@ -111,9 +111,9 @@ public class TerrainProtocol implements ClientProtocolTemplate { //mark all relevant drawcells as updateable for(Vector3i worldPosToUpdate : positionsToUpdate){ if( - worldPosToUpdate.x >= 0 && worldPosToUpdate.x < Globals.clientWorldData.getWorldDiscreteSize() && - worldPosToUpdate.y >= 0 && worldPosToUpdate.y < Globals.clientWorldData.getWorldDiscreteSize() && - worldPosToUpdate.z >= 0 && worldPosToUpdate.z < Globals.clientWorldData.getWorldDiscreteSize() + worldPosToUpdate.x >= 0 && worldPosToUpdate.x < Globals.clientState.clientWorldData.getWorldDiscreteSize() && + worldPosToUpdate.y >= 0 && worldPosToUpdate.y < Globals.clientState.clientWorldData.getWorldDiscreteSize() && + worldPosToUpdate.z >= 0 && worldPosToUpdate.z < Globals.clientState.clientWorldData.getWorldDiscreteSize() ){ // //mark terrain chunk for update @@ -223,9 +223,9 @@ public class TerrainProtocol implements ClientProtocolTemplate { //mark all relevant drawcells as updateable for(Vector3i worldPosToUpdate : positionsToUpdate){ if( - worldPosToUpdate.x >= 0 && worldPosToUpdate.x < Globals.clientWorldData.getWorldDiscreteSize() && - worldPosToUpdate.y >= 0 && worldPosToUpdate.y < Globals.clientWorldData.getWorldDiscreteSize() && - worldPosToUpdate.z >= 0 && worldPosToUpdate.z < Globals.clientWorldData.getWorldDiscreteSize() + worldPosToUpdate.x >= 0 && worldPosToUpdate.x < Globals.clientState.clientWorldData.getWorldDiscreteSize() && + worldPosToUpdate.y >= 0 && worldPosToUpdate.y < Globals.clientState.clientWorldData.getWorldDiscreteSize() && + worldPosToUpdate.z >= 0 && worldPosToUpdate.z < Globals.clientState.clientWorldData.getWorldDiscreteSize() ){ // //mark terrain chunk for update diff --git a/src/main/java/electrosphere/server/datacell/physics/DataCellPhysicsManager.java b/src/main/java/electrosphere/server/datacell/physics/DataCellPhysicsManager.java index 7dd37faa..458a7515 100644 --- a/src/main/java/electrosphere/server/datacell/physics/DataCellPhysicsManager.java +++ b/src/main/java/electrosphere/server/datacell/physics/DataCellPhysicsManager.java @@ -66,7 +66,7 @@ public class DataCellPhysicsManager { * @param discreteY The initial discrete position Y coordinate */ public DataCellPhysicsManager(Realm realm, int discreteX, int discreteY, int discreteZ){ - worldBoundDiscreteMax = (int)(Globals.clientWorldData.getWorldBoundMin().x / ServerTerrainChunk.CHUNK_DIMENSION * 1.0f); + worldBoundDiscreteMax = (int)(Globals.clientState.clientWorldData.getWorldBoundMin().x / ServerTerrainChunk.CHUNK_DIMENSION * 1.0f); cells = new HashSet(); invalid = new HashSet(); updateable = new HashSet(); diff --git a/src/test/java/electrosphere/client/terrain/cells/ClientDrawCellManagerTests.java b/src/test/java/electrosphere/client/terrain/cells/ClientDrawCellManagerTests.java index b6e56eed..cb8a7814 100644 --- a/src/test/java/electrosphere/client/terrain/cells/ClientDrawCellManagerTests.java +++ b/src/test/java/electrosphere/client/terrain/cells/ClientDrawCellManagerTests.java @@ -35,7 +35,7 @@ public class ClientDrawCellManagerTests { public void testJoinCase(){ int worldDiscreteSize = 64; - Globals.clientWorldData = new ClientWorldData(new Vector3f(0), new Vector3f(worldDiscreteSize * ServerTerrainChunk.CHUNK_DIMENSION), worldDiscreteSize); + Globals.clientState.clientWorldData = new ClientWorldData(new Vector3f(0), new Vector3f(worldDiscreteSize * ServerTerrainChunk.CHUNK_DIMENSION), worldDiscreteSize); ClientDrawCellManager manager = new ClientDrawCellManager(null, 64); Vector3i playerPos = new Vector3i(0,0,0); WorldOctTreeNode node = WorldOctTreeNode.constructorForTests(manager.chunkTree, 1, new Vector3i(16,0,0), new Vector3i(32,16,16)); diff --git a/src/test/java/electrosphere/test/template/extensions/StateCleanupCheckerExtension.java b/src/test/java/electrosphere/test/template/extensions/StateCleanupCheckerExtension.java index a3e86652..e79ed498 100644 --- a/src/test/java/electrosphere/test/template/extensions/StateCleanupCheckerExtension.java +++ b/src/test/java/electrosphere/test/template/extensions/StateCleanupCheckerExtension.java @@ -30,7 +30,7 @@ public class StateCleanupCheckerExtension implements AfterEachCallback { Globals.playerManager, LoggerInterface.loggerEngine, RenderingEngine.screenFramebuffer, - Globals.clientWorldData, + Globals.clientState, }; for(Object object : objectsToCheck){ if(object != null){