diff --git a/src/main/java/electrosphere/client/ClientState.java b/src/main/java/electrosphere/client/ClientState.java index 124fa76a..c9f85ceb 100644 --- a/src/main/java/electrosphere/client/ClientState.java +++ b/src/main/java/electrosphere/client/ClientState.java @@ -1,17 +1,24 @@ package electrosphere.client; import electrosphere.client.block.ClientBlockManager; +import electrosphere.client.block.cells.ClientBlockCellManager; import electrosphere.client.chemistry.ClientChemistryCollisionCallback; import electrosphere.client.entity.character.ClientCharacterManager; 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.foliage.FoliageCellManager; import electrosphere.client.terrain.manager.ClientTerrainManager; import electrosphere.collision.CollisionEngine; +import electrosphere.data.common.CommonEntityType; +import electrosphere.data.voxel.VoxelType; import electrosphere.entity.scene.Scene; import electrosphere.net.client.ClientNetworking; +import electrosphere.net.server.player.Player; import electrosphere.net.synchronization.client.ClientSynchronizationManager; /** @@ -42,7 +49,7 @@ public class ClientState { /** * The synchronization manager on the client */ - public ClientSynchronizationManager clientSynchronizationManager; + public ClientSynchronizationManager clientSynchronizationManager = new ClientSynchronizationManager(); /** * The client network connection @@ -74,6 +81,51 @@ public class ClientState { */ public ClientBlockManager clientBlockManager = new ClientBlockManager(); + /** + * Terrain cell manager + */ + public ClientDrawCellManager clientDrawCellManager; + + /** + * Block cell manager + */ + public ClientBlockCellManager clientBlockCellManager; + + /** + * client level editor data management + */ + public ClientLevelEditorData clientLevelEditorData = new ClientLevelEditorData(); + + /** + * client current selected voxel type + */ + public VoxelType clientSelectedVoxelType = null; + + /** + * the selected type of entity to spawn + */ + public CommonEntityType selectedSpawntype = null; + + /** + * Client player data + */ + public Player clientPlayer; + + /** + * Current auth username + */ + public String clientUsername; + + /** + * Current auth password + */ + public String clientPassword; + + /** + * client player data + */ + public ClientPlayerData clientPlayerData = new ClientPlayerData(); + /** * Constructor */ diff --git a/src/main/java/electrosphere/client/script/ScriptClientVoxelUtils.java b/src/main/java/electrosphere/client/script/ScriptClientVoxelUtils.java index 76f299e7..4c787153 100644 --- a/src/main/java/electrosphere/client/script/ScriptClientVoxelUtils.java +++ b/src/main/java/electrosphere/client/script/ScriptClientVoxelUtils.java @@ -54,9 +54,9 @@ public class ScriptClientVoxelUtils { if(cursorPos == null){ cursorPos = new Vector3d(centerPos).add(new Vector3d(eyePos).mul(-CollisionEngine.DEFAULT_INTERACT_DISTANCE)); } - if(Globals.clientSelectedVoxelType != null){ - TerrainEditing.editTerrain(cursorPos, 1.1f, Globals.clientSelectedVoxelType.getId(), EDIT_INCREMENT); - Globals.movementAudioService.getAudioPath(Globals.clientSelectedVoxelType.getId(), InteractionType.STEP_SHOE_REG); + if(Globals.clientState.clientSelectedVoxelType != null){ + TerrainEditing.editTerrain(cursorPos, 1.1f, Globals.clientState.clientSelectedVoxelType.getId(), EDIT_INCREMENT); + Globals.movementAudioService.getAudioPath(Globals.clientState.clientSelectedVoxelType.getId(), InteractionType.STEP_SHOE_REG); } } } diff --git a/src/main/java/electrosphere/client/sim/ClientSimulation.java b/src/main/java/electrosphere/client/sim/ClientSimulation.java index a5beeb41..9bc053b8 100644 --- a/src/main/java/electrosphere/client/sim/ClientSimulation.java +++ b/src/main/java/electrosphere/client/sim/ClientSimulation.java @@ -202,9 +202,9 @@ 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.clientState.clientWorldData != null){ + if(Globals.clientState.clientDrawCellManager != null && Globals.clientState.clientWorldData != null){ //Cell manager do your things - Globals.clientDrawCellManager.update(); + Globals.clientState.clientDrawCellManager.update(); } } @@ -222,8 +222,8 @@ public class ClientSimulation { * Updates the block cell manager */ private void updateBlockCellManager(){ - if(Globals.clientBlockCellManager != null && Globals.clientState.clientWorldData != null){ - Globals.clientBlockCellManager.update(); + if(Globals.clientState.clientBlockCellManager != null && Globals.clientState.clientWorldData != null){ + Globals.clientState.clientBlockCellManager.update(); } } diff --git a/src/main/java/electrosphere/client/ui/components/SpawnSelectionPanel.java b/src/main/java/electrosphere/client/ui/components/SpawnSelectionPanel.java index 1903da8f..1a354966 100644 --- a/src/main/java/electrosphere/client/ui/components/SpawnSelectionPanel.java +++ b/src/main/java/electrosphere/client/ui/components/SpawnSelectionPanel.java @@ -119,7 +119,7 @@ public class SpawnSelectionPanel { newButton.setOnClick(new ClickEventCallback() {public boolean execute(ClickEvent event){ //set voxel type to this type onSelectType.accept(type); - Globals.selectedSpawntype = type; + Globals.clientState.selectedSpawntype = type; return false; }}); containerDiv.addChild(newButton); diff --git a/src/main/java/electrosphere/client/ui/components/VoxelSelectionPanel.java b/src/main/java/electrosphere/client/ui/components/VoxelSelectionPanel.java index feabe12a..e7ac0f6b 100644 --- a/src/main/java/electrosphere/client/ui/components/VoxelSelectionPanel.java +++ b/src/main/java/electrosphere/client/ui/components/VoxelSelectionPanel.java @@ -131,7 +131,7 @@ public class VoxelSelectionPanel { newButton.setMarginRight(MARGIN_EACH_SIDE); newButton.setMarginTop(MARGIN_EACH_SIDE); //set color if this is the selected voxel type - if(type == Globals.clientSelectedVoxelType){ + if(type == Globals.clientState.clientSelectedVoxelType){ newButton.setColor(ELEMENT_COLOR_SELECTED); } //label @@ -158,7 +158,7 @@ public class VoxelSelectionPanel { newButton.setOnClick(new ClickEventCallback() {public boolean execute(ClickEvent event){ //set voxel type to this type onSelectType.accept(type); - Globals.clientSelectedVoxelType = type; + Globals.clientState.clientSelectedVoxelType = type; VoxelSelectionPanel.fillInVoxelSelectors(scrollable, searchString, onSelectType); return false; }}); 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 725573b8..f20f151c 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 @@ -32,13 +32,13 @@ public class ImGuiChunkMonitor { //ui framework text ImGui.text("Chunk Monitor"); - if(Globals.clientDrawCellManager != null){ - Globals.clientDrawCellManager.updateStatus(); - ImGui.text("Full res chunks: " + Globals.clientDrawCellManager.getMaxResCount()); - ImGui.text("Terrain node count: " + Globals.clientDrawCellManager.getNodeCount()); + if(Globals.clientState.clientDrawCellManager != null){ + Globals.clientState.clientDrawCellManager.updateStatus(); + ImGui.text("Full res chunks: " + Globals.clientState.clientDrawCellManager.getMaxResCount()); + ImGui.text("Terrain node count: " + Globals.clientState.clientDrawCellManager.getNodeCount()); } - if(Globals.clientBlockCellManager != null){ - ImGui.text("Block node count: " + Globals.clientBlockCellManager.getNodeCount()); + if(Globals.clientState.clientBlockCellManager != null){ + ImGui.text("Block node count: " + Globals.clientState.clientBlockCellManager.getNodeCount()); } if(Globals.clientState.foliageCellManager != null){ ImGui.text("Foliage node count: " + Globals.clientState.foliageCellManager.getNodeCount()); 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 24313acc..5803b2c2 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 @@ -35,7 +35,7 @@ public class ImGuiClientServices { if(ImGui.collapsingHeader("Draw Cells")){ if(ImGui.button("Debug DrawCell at camera position")){ Vector3i cameraWorldPos = Globals.clientState.clientWorldData.convertRealToWorldSpace(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); - DrawCell cell = Globals.clientDrawCellManager.getDrawCell(cameraWorldPos.x, cameraWorldPos.y, cameraWorldPos.z); + DrawCell cell = Globals.clientState.clientDrawCellManager.getDrawCell(cameraWorldPos.x, cameraWorldPos.y, cameraWorldPos.z); LoggerInterface.loggerEngine.WARNING("" + cell); LoggerInterface.loggerEngine.WARNING("Chunk topology:"); diff --git a/src/main/java/electrosphere/client/ui/menu/debug/server/ImGuiFluidMonitor.java b/src/main/java/electrosphere/client/ui/menu/debug/server/ImGuiFluidMonitor.java index dca50d3c..b54534c3 100644 --- a/src/main/java/electrosphere/client/ui/menu/debug/server/ImGuiFluidMonitor.java +++ b/src/main/java/electrosphere/client/ui/menu/debug/server/ImGuiFluidMonitor.java @@ -28,7 +28,7 @@ public class ImGuiFluidMonitor { @Override public void exec() { if(ImGui.collapsingHeader("Server Data")){ - ServerFluidManager fluidManager = Globals.playerManager.getPlayerRealm(Globals.clientPlayer).getServerWorldData().getServerFluidManager(); + ServerFluidManager fluidManager = Globals.playerManager.getPlayerRealm(Globals.clientState.clientPlayer).getServerWorldData().getServerFluidManager(); //server engine details ImGui.text("Fluids Debug"); ImGui.text("State: " + (fluidManager.getSimulate() ? "on" : "off")); @@ -67,7 +67,7 @@ public class ImGuiFluidMonitor { * Prints debug data about the chunk at 0,0,1 */ private static void printChunkDebugData(){ - ServerFluidManager fluidManager = Globals.playerManager.getPlayerRealm(Globals.clientPlayer).getServerWorldData().getServerFluidManager(); + ServerFluidManager fluidManager = Globals.playerManager.getPlayerRealm(Globals.clientState.clientPlayer).getServerWorldData().getServerFluidManager(); ServerFluidChunk chunk = fluidManager.getChunk(0, 0, 1); ImGui.text("Pressure: " + chunk.getTotalPressure()); ImGui.text("Velocity magnitude: " + chunk.getTotalVelocityMag()); diff --git a/src/main/java/electrosphere/client/ui/menu/debug/server/ImGuiTestGen.java b/src/main/java/electrosphere/client/ui/menu/debug/server/ImGuiTestGen.java index 783a20e4..9a515770 100644 --- a/src/main/java/electrosphere/client/ui/menu/debug/server/ImGuiTestGen.java +++ b/src/main/java/electrosphere/client/ui/menu/debug/server/ImGuiTestGen.java @@ -49,7 +49,7 @@ public class ImGuiTestGen { gridManager.evictAll(); //clear client - Globals.clientDrawCellManager.evictAll(); + Globals.clientState.clientDrawCellManager.evictAll(); Globals.clientState.clientTerrainManager.evictAll(); }); } @@ -85,8 +85,8 @@ public class ImGuiTestGen { } //Toggles whether the client draws cell manager should update or not - if(ImGui.button("Toggle ClientDrawCellManager updates " + (Globals.clientDrawCellManager.getShouldUpdate() ? "off" : "on"))){ - Globals.clientDrawCellManager.setShouldUpdate(!Globals.clientDrawCellManager.getShouldUpdate()); + if(ImGui.button("Toggle ClientDrawCellManager updates " + (Globals.clientState.clientDrawCellManager.getShouldUpdate() ? "off" : "on"))){ + Globals.clientState.clientDrawCellManager.setShouldUpdate(!Globals.clientState.clientDrawCellManager.getShouldUpdate()); } } diff --git a/src/main/java/electrosphere/client/ui/menu/editor/ImGuiStructureTab.java b/src/main/java/electrosphere/client/ui/menu/editor/ImGuiStructureTab.java index 53e02c53..6d193528 100644 --- a/src/main/java/electrosphere/client/ui/menu/editor/ImGuiStructureTab.java +++ b/src/main/java/electrosphere/client/ui/menu/editor/ImGuiStructureTab.java @@ -20,19 +20,19 @@ public class ImGuiStructureTab { * Draws the contents of the structure tab */ protected static void draw(){ - if(Globals.clientLevelEditorData.getCurrentFab() == null){ + if(Globals.clientState.clientLevelEditorData.getCurrentFab() == null){ ImGui.text("No structure currently being edited"); if(ImGui.button("Discover structure")){ ClientBlockSelection.selectAllBlocks(); AreaSelection area = Globals.cursorState.getAreaSelection(); if(area != null){ BlockFab blockFab = ClientBlockSelection.convertSelectionToFab(); - Globals.clientLevelEditorData.setCurrentFab(blockFab); - Globals.clientLevelEditorData.setCurrentFabOrigin(area.getRectStart()); + Globals.clientState.clientLevelEditorData.setCurrentFab(blockFab); + Globals.clientState.clientLevelEditorData.setCurrentFabOrigin(area.getRectStart()); } } } else { - BlockFab currentFab = Globals.clientLevelEditorData.getCurrentFab(); + BlockFab currentFab = Globals.clientState.clientLevelEditorData.getCurrentFab(); if(ImGui.button("Convert current selection to room")){ AreaSelection currentSelection = Globals.cursorState.getAreaSelection(); if(currentSelection != null){ @@ -50,11 +50,11 @@ public class ImGuiStructureTab { * Draws the details tab */ protected static void drawDetails(){ - if(Globals.clientLevelEditorData.getCurrentFab() == null){ + if(Globals.clientState.clientLevelEditorData.getCurrentFab() == null){ ImGui.text("Select a fab to show details here"); } else { - BlockFab currentFab = Globals.clientLevelEditorData.getCurrentFab(); - ImGui.text("Origin: " + Globals.clientLevelEditorData.getCurrentFabOrigin()); + BlockFab currentFab = Globals.clientState.clientLevelEditorData.getCurrentFab(); + ImGui.text("Origin: " + Globals.clientState.clientLevelEditorData.getCurrentFabOrigin()); ImGui.text("Dimensions: " + currentFab.getDimensions()); BlockFabMetadata fabMetadata = currentFab.getFabMetadata(); if(fabMetadata.getAreas() != null){ diff --git a/src/main/java/electrosphere/client/ui/menu/ingame/MenuGeneratorsTerrainEditing.java b/src/main/java/electrosphere/client/ui/menu/ingame/MenuGeneratorsTerrainEditing.java index 296a5936..b5746d7a 100644 --- a/src/main/java/electrosphere/client/ui/menu/ingame/MenuGeneratorsTerrainEditing.java +++ b/src/main/java/electrosphere/client/ui/menu/ingame/MenuGeneratorsTerrainEditing.java @@ -52,7 +52,7 @@ public class MenuGeneratorsTerrainEditing { //attach scrollable after search input for organzation purposes terrainEditingSidePanelWindow.addChild(VoxelSelectionPanel.createVoxelTypeSelectionPanel((VoxelType type) -> { - Globals.clientSelectedVoxelType = type; + Globals.clientState.clientSelectedVoxelType = type; })); Globals.signalSystem.post(SignalType.YOGA_APPLY,terrainEditingSidePanelWindow); @@ -85,7 +85,7 @@ public class MenuGeneratorsTerrainEditing { //attach scrollable after search input for organzation purposes entitySelectionWindow.addChild(SpawnSelectionPanel.createEntityTypeSelectionPanel((CommonEntityType type) -> { - Globals.selectedSpawntype = type; + Globals.clientState.selectedSpawntype = type; })); Globals.signalSystem.post(SignalType.YOGA_APPLY,entitySelectionWindow); diff --git a/src/main/java/electrosphere/client/ui/menu/mainmenu/MenuGeneratorsMultiplayer.java b/src/main/java/electrosphere/client/ui/menu/mainmenu/MenuGeneratorsMultiplayer.java index 7a4f006a..2c695400 100644 --- a/src/main/java/electrosphere/client/ui/menu/mainmenu/MenuGeneratorsMultiplayer.java +++ b/src/main/java/electrosphere/client/ui/menu/mainmenu/MenuGeneratorsMultiplayer.java @@ -179,8 +179,8 @@ public class MenuGeneratorsMultiplayer { rVal.addChild(Button.createButton("Connect", () -> { NetUtils.setAddress(addressInput.getText()); NetUtils.setPort(Integer.parseInt(portInput.getText())); - Globals.clientUsername = usernameInput.getText(); - Globals.clientPassword = AuthenticationManager.getHashedString(passwordInput.getText()); + Globals.clientState.clientUsername = usernameInput.getText(); + Globals.clientState.clientPassword = AuthenticationManager.getHashedString(passwordInput.getText()); LoadingThread clientThread = new LoadingThread(LoadingThreadType.CHARACTER_SERVER); Globals.RUN_CLIENT = true; Globals.RUN_SERVER = false; diff --git a/src/main/java/electrosphere/client/ui/menu/mainmenu/worldgen/MenuWorldSelect.java b/src/main/java/electrosphere/client/ui/menu/mainmenu/worldgen/MenuWorldSelect.java index d9683004..8327ea96 100644 --- a/src/main/java/electrosphere/client/ui/menu/mainmenu/worldgen/MenuWorldSelect.java +++ b/src/main/java/electrosphere/client/ui/menu/mainmenu/worldgen/MenuWorldSelect.java @@ -55,9 +55,9 @@ public class MenuWorldSelect { spacer.addChild(Button.createButton(saveName.toUpperCase(), () -> { if(SaveUtils.saveHasWorldFile(saveName.toLowerCase())){ //need to log client in - Globals.clientUsername = "username"; - Globals.clientPassword = AuthenticationManager.getHashedString("password"); - LoadingThread serverThread = new LoadingThread(LoadingThreadType.MAIN_GAME, saveName, Globals.clientUsername, Globals.clientPassword); + Globals.clientState.clientUsername = "username"; + Globals.clientState.clientPassword = AuthenticationManager.getHashedString("password"); + LoadingThread serverThread = new LoadingThread(LoadingThreadType.MAIN_GAME, saveName, Globals.clientState.clientUsername, Globals.clientState.clientPassword); Globals.RUN_CLIENT = true; Globals.RUN_SERVER = true; Globals.threadManager.start(serverThread); diff --git a/src/main/java/electrosphere/client/ui/menu/script/ScriptLevelEditorUtils.java b/src/main/java/electrosphere/client/ui/menu/script/ScriptLevelEditorUtils.java index 7fa671bc..8b1740d7 100644 --- a/src/main/java/electrosphere/client/ui/menu/script/ScriptLevelEditorUtils.java +++ b/src/main/java/electrosphere/client/ui/menu/script/ScriptLevelEditorUtils.java @@ -31,9 +31,9 @@ public class ScriptLevelEditorUtils { */ @Export public static void spawnEntity(){ - if(Globals.selectedSpawntype != null){ - if(Globals.selectedSpawntype instanceof CreatureData){ - LoggerInterface.loggerEngine.INFO("spawn " + Globals.selectedSpawntype.getId() + "!"); + if(Globals.clientState.selectedSpawntype != null){ + if(Globals.clientState.selectedSpawntype instanceof CreatureData){ + LoggerInterface.loggerEngine.INFO("spawn " + Globals.clientState.selectedSpawntype.getId() + "!"); Vector3d eyePos = new Vector3d(CameraEntityUtils.getCameraEye(Globals.playerCamera)); Vector3d centerPos = new Vector3d(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); Realm realm = Globals.realmManager.getRealms().iterator().next(); @@ -43,9 +43,9 @@ public class ScriptLevelEditorUtils { cursorPos = new Vector3d(centerPos).add(new Vector3d(eyePos).normalize().mul(-CollisionEngine.DEFAULT_INTERACT_DISTANCE)); } cursorPos = cursorPos.add(cursorVerticalOffset); - CreatureUtils.serverSpawnBasicCreature(realm, cursorPos, Globals.selectedSpawntype.getId(), null); - } else if(Globals.selectedSpawntype instanceof Item){ - LoggerInterface.loggerEngine.INFO("spawn " + Globals.selectedSpawntype.getId() + "!"); + CreatureUtils.serverSpawnBasicCreature(realm, cursorPos, Globals.clientState.selectedSpawntype.getId(), null); + } else if(Globals.clientState.selectedSpawntype instanceof Item){ + LoggerInterface.loggerEngine.INFO("spawn " + Globals.clientState.selectedSpawntype.getId() + "!"); Vector3d eyePos = new Vector3d(CameraEntityUtils.getCameraEye(Globals.playerCamera)); Vector3d centerPos = new Vector3d(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); Realm realm = Globals.realmManager.getRealms().iterator().next(); @@ -55,9 +55,9 @@ public class ScriptLevelEditorUtils { cursorPos = new Vector3d(centerPos).add(new Vector3d(eyePos).normalize().mul(-CollisionEngine.DEFAULT_INTERACT_DISTANCE)); } cursorPos = cursorPos.add(cursorVerticalOffset); - ItemUtils.serverSpawnBasicItem(realm, cursorPos, Globals.selectedSpawntype.getId()); - } else if(Globals.selectedSpawntype instanceof FoliageType){ - LoggerInterface.loggerEngine.INFO("spawn " + Globals.selectedSpawntype.getId() + "!"); + ItemUtils.serverSpawnBasicItem(realm, cursorPos, Globals.clientState.selectedSpawntype.getId()); + } else if(Globals.clientState.selectedSpawntype instanceof FoliageType){ + LoggerInterface.loggerEngine.INFO("spawn " + Globals.clientState.selectedSpawntype.getId() + "!"); Vector3d eyePos = new Vector3d(CameraEntityUtils.getCameraEye(Globals.playerCamera)); Vector3d centerPos = new Vector3d(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); Realm realm = Globals.realmManager.getRealms().iterator().next(); @@ -67,9 +67,9 @@ public class ScriptLevelEditorUtils { cursorPos = new Vector3d(centerPos).add(new Vector3d(eyePos).normalize().mul(-CollisionEngine.DEFAULT_INTERACT_DISTANCE)); } cursorPos = cursorPos.add(cursorVerticalOffset); - FoliageUtils.serverSpawnTreeFoliage(realm, cursorPos, Globals.selectedSpawntype.getId()); + FoliageUtils.serverSpawnTreeFoliage(realm, cursorPos, Globals.clientState.selectedSpawntype.getId()); } else { - LoggerInterface.loggerEngine.INFO("spawn " + Globals.selectedSpawntype.getId() + "!"); + LoggerInterface.loggerEngine.INFO("spawn " + Globals.clientState.selectedSpawntype.getId() + "!"); Vector3d eyePos = new Vector3d(CameraEntityUtils.getCameraEye(Globals.playerCamera)); Vector3d centerPos = new Vector3d(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); Realm realm = Globals.realmManager.getRealms().iterator().next(); @@ -79,7 +79,7 @@ public class ScriptLevelEditorUtils { cursorPos = new Vector3d(centerPos).add(new Vector3d(eyePos).normalize().mul(-CollisionEngine.DEFAULT_INTERACT_DISTANCE)); } cursorPos = cursorPos.add(cursorVerticalOffset); - CommonEntityUtils.serverSpawnBasicObject(realm, cursorPos, Globals.selectedSpawntype.getId()); + CommonEntityUtils.serverSpawnBasicObject(realm, cursorPos, Globals.clientState.selectedSpawntype.getId()); } } } diff --git a/src/main/java/electrosphere/engine/Globals.java b/src/main/java/electrosphere/engine/Globals.java index b7dbf796..83ac76bb 100644 --- a/src/main/java/electrosphere/engine/Globals.java +++ b/src/main/java/electrosphere/engine/Globals.java @@ -14,14 +14,10 @@ import electrosphere.audio.movement.MovementAudioService; import electrosphere.auth.AuthenticationManager; import electrosphere.client.ClientState; import electrosphere.client.block.cells.BlockTextureAtlas; -import electrosphere.client.block.cells.ClientBlockCellManager; import electrosphere.client.chemistry.ClientChemistryCollisionCallback; import electrosphere.client.entity.particle.ParticleService; import electrosphere.client.fluid.cells.FluidCellManager; -import electrosphere.client.player.ClientPlayerData; -import electrosphere.client.scene.ClientLevelEditorData; import electrosphere.client.scene.ClientSceneWrapper; -import electrosphere.client.terrain.cells.ClientDrawCellManager; import electrosphere.client.terrain.cells.VoxelTextureAtlas; import electrosphere.client.ui.menu.WindowUtils; import electrosphere.collision.CollisionEngine; @@ -32,7 +28,6 @@ import electrosphere.controls.ControlHandler; import electrosphere.controls.MouseCallback; import electrosphere.controls.ScrollCallback; import electrosphere.controls.cursor.CursorState; -import electrosphere.data.common.CommonEntityType; import electrosphere.data.particle.ParticleDefinition; import electrosphere.data.settings.UserSettings; import electrosphere.data.voxel.VoxelType; @@ -52,9 +47,7 @@ import electrosphere.logger.LoggerInterface; import electrosphere.net.config.NetConfig; import electrosphere.net.monitor.NetMonitor; import electrosphere.net.server.Server; -import electrosphere.net.server.player.Player; import electrosphere.net.server.player.PlayerManager; -import electrosphere.net.synchronization.client.ClientSynchronizationManager; import electrosphere.net.synchronization.server.EntityValueTrackingService; import electrosphere.net.synchronization.server.ServerSynchronizationManager; import electrosphere.renderer.RenderUtils; @@ -236,9 +229,6 @@ public class Globals { //Player manager // public static PlayerManager playerManager; - public static Player clientPlayer; - public static String clientUsername; - public static String clientPassword; // //Generic OpenGL Statements @@ -332,14 +322,8 @@ public class Globals { //instanced actor manager public static InstanceManager clientInstanceManager = new InstanceManager(); - //client player data - public static ClientPlayerData clientPlayerData = new ClientPlayerData(); - //chunk stuff - //draw cell manager - public static ClientDrawCellManager clientDrawCellManager; public static VoxelTextureAtlas voxelTextureAtlas = new VoxelTextureAtlas(); - public static ClientBlockCellManager clientBlockCellManager; public static BlockTextureAtlas blockTextureAtlas = new BlockTextureAtlas(); //fluid cell manager @@ -364,9 +348,6 @@ public class Globals { //collision world data public static CollisionWorldData commonWorldData; - - //client level editor data management - public static ClientLevelEditorData clientLevelEditorData = new ClientLevelEditorData(); //the player camera entity @@ -386,11 +367,6 @@ public class Globals { * The target of the interaction */ public static Entity interactionTarget = null; - - //client current selected voxel type - public static VoxelType clientSelectedVoxelType = null; - //the selected type of entity to spawn - public static CommonEntityType selectedSpawntype = null; //skybox entity public static Entity skybox; @@ -495,7 +471,7 @@ public class Globals { // //Values that depend on the loaded config - Globals.clientSelectedVoxelType = (VoxelType)gameConfigCurrent.getVoxelData().getTypes().toArray()[1]; + Globals.clientState.clientSelectedVoxelType = (VoxelType)gameConfigCurrent.getVoxelData().getTypes().toArray()[1]; //player manager playerManager = new PlayerManager(); //behavior tree tracking service @@ -504,8 +480,6 @@ public class Globals { if(Globals.userSettings.getNetRunNetMonitor()){ netMonitor = new NetMonitor(); } - //client synchronization manager - Globals.clientState.clientSynchronizationManager = new ClientSynchronizationManager(); //profiler profiler = new Profiler(); Globals.serverSynchronizationManager = new ServerSynchronizationManager(); @@ -689,12 +663,10 @@ public class Globals { Globals.playerEntity = null; Globals.playerCamera = null; Globals.firstPersonEntity = null; - Globals.clientPlayer = null; Globals.playerManager = new PlayerManager(); Globals.clientState.clientScene = new Scene(); Globals.clientState.clientSceneWrapper = new ClientSceneWrapper(Globals.clientState.clientScene, new CollisionEngine(), CollisionEngine.create(new ClientChemistryCollisionCallback()), new CollisionEngine()); Globals.clientState = new ClientState(); - Globals.clientState.clientSynchronizationManager = new ClientSynchronizationManager(); Globals.server = null; Globals.serverSynchronizationManager = new ServerSynchronizationManager(); if(Globals.aiManager != null){ diff --git a/src/main/java/electrosphere/engine/loadingthreads/ChunkGenerationTestLoading.java b/src/main/java/electrosphere/engine/loadingthreads/ChunkGenerationTestLoading.java index 3b831392..1f8e903b 100644 --- a/src/main/java/electrosphere/engine/loadingthreads/ChunkGenerationTestLoading.java +++ b/src/main/java/electrosphere/engine/loadingthreads/ChunkGenerationTestLoading.java @@ -77,8 +77,8 @@ public class ChunkGenerationTestLoading { //init authentication LoadingUtils.initAuthenticationManager(false); //initialize the local connection - Globals.clientUsername = "leveleditor"; - Globals.clientPassword = AuthenticationManager.getHashedString("leveleditor"); + Globals.clientState.clientUsername = "leveleditor"; + Globals.clientState.clientPassword = AuthenticationManager.getHashedString("leveleditor"); ServerConnectionHandler serverPlayerConnection = LoadingUtils.initLocalConnection(true); //wait for player object creation while(Globals.playerManager.getPlayers().size() < 1 || !Globals.clientState.clientConnection.isInitialized()){ diff --git a/src/main/java/electrosphere/engine/loadingthreads/ClientLoading.java b/src/main/java/electrosphere/engine/loadingthreads/ClientLoading.java index d901fc56..54636e5f 100644 --- a/src/main/java/electrosphere/engine/loadingthreads/ClientLoading.java +++ b/src/main/java/electrosphere/engine/loadingthreads/ClientLoading.java @@ -336,14 +336,14 @@ public class ClientLoading { } //initialize draw cell manager // Globals.drawCellManager = new DrawCellManager(Globals.clientTerrainManager, 0, 0, 0); - Globals.clientDrawCellManager = new ClientDrawCellManager(Globals.voxelTextureAtlas, Globals.clientState.clientWorldData.getWorldDiscreteSize()); + Globals.clientState.clientDrawCellManager = new ClientDrawCellManager(Globals.voxelTextureAtlas, Globals.clientState.clientWorldData.getWorldDiscreteSize()); //Alerts the client simulation that it should start loading terrain Globals.clientState.clientSimulation.setLoadingTerrain(true); //wait for all the terrain data to arrive int i = 0; while( blockForInit && - !Globals.clientDrawCellManager.isInitialized() && + !Globals.clientState.clientDrawCellManager.isInitialized() && Globals.threadManager.shouldKeepRunning() ){ i++; @@ -420,14 +420,14 @@ public class ClientLoading { throw new IllegalStateException(message); } } - Globals.clientBlockCellManager = new ClientBlockCellManager(Globals.blockTextureAtlas, Globals.clientState.clientWorldData.getWorldDiscreteSize()); + Globals.clientState.clientBlockCellManager = new ClientBlockCellManager(Globals.blockTextureAtlas, Globals.clientState.clientWorldData.getWorldDiscreteSize()); //Alerts the client simulation that it should start loading blocks Globals.clientState.clientSimulation.setLoadingTerrain(true); //wait for all the block data to arrive int i = 0; while( blockForInit && - !Globals.clientBlockCellManager.isInitialized() && + !Globals.clientState.clientBlockCellManager.isInitialized() && Globals.threadManager.shouldKeepRunning() ){ i++; diff --git a/src/main/java/electrosphere/engine/loadingthreads/DebugSPWorldLoading.java b/src/main/java/electrosphere/engine/loadingthreads/DebugSPWorldLoading.java index 0a332023..e12d5258 100644 --- a/src/main/java/electrosphere/engine/loadingthreads/DebugSPWorldLoading.java +++ b/src/main/java/electrosphere/engine/loadingthreads/DebugSPWorldLoading.java @@ -45,8 +45,8 @@ public class DebugSPWorldLoading { //init authentication LoadingUtils.initAuthenticationManager(false); //initialize the local connection - Globals.clientUsername = "testuser"; - Globals.clientPassword = AuthenticationManager.getHashedString("testpass"); + Globals.clientState.clientUsername = "testuser"; + Globals.clientState.clientPassword = AuthenticationManager.getHashedString("testpass"); ServerConnectionHandler serverPlayerConnection = LoadingUtils.initLocalConnection(true); //wait for player object creation while(Globals.playerManager.getPlayers().size() < 1){ diff --git a/src/main/java/electrosphere/engine/loadingthreads/LevelEditorLoading.java b/src/main/java/electrosphere/engine/loadingthreads/LevelEditorLoading.java index 6853f4bd..2b263d80 100644 --- a/src/main/java/electrosphere/engine/loadingthreads/LevelEditorLoading.java +++ b/src/main/java/electrosphere/engine/loadingthreads/LevelEditorLoading.java @@ -73,8 +73,8 @@ public class LevelEditorLoading { //init authentication LoadingUtils.initAuthenticationManager(false); //initialize the local connection - Globals.clientUsername = "leveleditor"; - Globals.clientPassword = AuthenticationManager.getHashedString("leveleditor"); + Globals.clientState.clientUsername = "leveleditor"; + Globals.clientState.clientPassword = AuthenticationManager.getHashedString("leveleditor"); ServerConnectionHandler serverPlayerConnection = LoadingUtils.initLocalConnection(true); //wait for player object creation while(Globals.playerManager.getPlayers().size() < 1 || !Globals.clientState.clientConnection.isInitialized()){ diff --git a/src/main/java/electrosphere/engine/loadingthreads/LevelLoading.java b/src/main/java/electrosphere/engine/loadingthreads/LevelLoading.java index 96a24a5c..fad62fe1 100644 --- a/src/main/java/electrosphere/engine/loadingthreads/LevelLoading.java +++ b/src/main/java/electrosphere/engine/loadingthreads/LevelLoading.java @@ -43,8 +43,8 @@ public class LevelLoading { //init authentication LoadingUtils.initAuthenticationManager(false); //initialize the local connection - Globals.clientUsername = "leveleditor"; - Globals.clientPassword = AuthenticationManager.getHashedString("leveleditor"); + Globals.clientState.clientUsername = "leveleditor"; + Globals.clientState.clientPassword = AuthenticationManager.getHashedString("leveleditor"); ServerConnectionHandler serverPlayerConnection = LoadingUtils.initLocalConnection(true); //wait for player object creation while(Globals.playerManager.getPlayers().size() < 1){ diff --git a/src/main/java/electrosphere/engine/loadingthreads/ServerLoading.java b/src/main/java/electrosphere/engine/loadingthreads/ServerLoading.java index e5128d3f..42aee8f5 100644 --- a/src/main/java/electrosphere/engine/loadingthreads/ServerLoading.java +++ b/src/main/java/electrosphere/engine/loadingthreads/ServerLoading.java @@ -49,8 +49,8 @@ public class ServerLoading { //init authentication LoadingUtils.initAuthenticationManager(false); //initialize the local connection - Globals.clientUsername = username; - Globals.clientPassword = password; + Globals.clientState.clientUsername = username; + Globals.clientState.clientPassword = password; //initialize the "real" objects simulation LoadingUtils.initMicroSimulation(); //init game specific stuff (ie different skybox colors) diff --git a/src/main/java/electrosphere/engine/loadingthreads/ViewportLoading.java b/src/main/java/electrosphere/engine/loadingthreads/ViewportLoading.java index 91a0c85f..3d735fdc 100644 --- a/src/main/java/electrosphere/engine/loadingthreads/ViewportLoading.java +++ b/src/main/java/electrosphere/engine/loadingthreads/ViewportLoading.java @@ -44,8 +44,8 @@ public class ViewportLoading { LoggerInterface.loggerEngine.INFO("run server: " + Globals.RUN_SERVER + " run client: " + Globals.RUN_CLIENT); ViewportLoading.initInMemoryDB(); LoadingUtils.initAuthenticationManager(true); - Globals.clientUsername = "leveleditor"; - Globals.clientPassword = AuthenticationManager.getHashedString("leveleditor"); + Globals.clientState.clientUsername = "leveleditor"; + Globals.clientState.clientPassword = AuthenticationManager.getHashedString("leveleditor"); LoadingUtils.initLocalConnection(true); //wait for player object creation while(Globals.playerManager.getPlayers().size() < 1){ diff --git a/src/main/java/electrosphere/entity/state/physicssync/ClientPhysicsSyncTree.java b/src/main/java/electrosphere/entity/state/physicssync/ClientPhysicsSyncTree.java index ff975621..f2b836cc 100644 --- a/src/main/java/electrosphere/entity/state/physicssync/ClientPhysicsSyncTree.java +++ b/src/main/java/electrosphere/entity/state/physicssync/ClientPhysicsSyncTree.java @@ -63,7 +63,7 @@ public class ClientPhysicsSyncTree implements BehaviorTree { //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.clientState.clientDrawCellManager.bustDistanceCache(); Globals.clientState.foliageCellManager.bustDistanceCache(); } } diff --git a/src/main/java/electrosphere/net/client/protocol/AuthProtocol.java b/src/main/java/electrosphere/net/client/protocol/AuthProtocol.java index aa8b03f9..83978554 100644 --- a/src/main/java/electrosphere/net/client/protocol/AuthProtocol.java +++ b/src/main/java/electrosphere/net/client/protocol/AuthProtocol.java @@ -18,11 +18,11 @@ public class AuthProtocol implements ClientProtocolTemplate { case AUTHREQUEST: //Try login //TODO: actually get user/pass - Globals.clientState.clientConnection.queueOutgoingMessage(AuthMessage.constructAuthDetailsMessage(Globals.clientUsername,Globals.clientPassword)); + Globals.clientState.clientConnection.queueOutgoingMessage(AuthMessage.constructAuthDetailsMessage(Globals.clientState.clientUsername,Globals.clientState.clientPassword)); break; case AUTHSUCCESS: //clean password hash from memory - Globals.clientPassword = ""; + Globals.clientState.clientPassword = ""; //request playable races Globals.clientState.clientConnection.queueOutgoingMessage(LoreMessage.constructRequestRacesMessage()); //request characters available to this player diff --git a/src/main/java/electrosphere/net/client/protocol/EntityProtocol.java b/src/main/java/electrosphere/net/client/protocol/EntityProtocol.java index be4b8da4..7f98e6fb 100644 --- a/src/main/java/electrosphere/net/client/protocol/EntityProtocol.java +++ b/src/main/java/electrosphere/net/client/protocol/EntityProtocol.java @@ -187,7 +187,7 @@ public class EntityProtocol implements ClientProtocolTemplate { String creatureTypeRaw = CreatureUtils.getType(target); CreatureData creatureType = Globals.gameConfigCurrent.getCreatureTypeLoader().getType(creatureTypeRaw); ViewModelData viewModelData = creatureType.getViewModelData(); - if(Globals.clientPlayer != null && message.getpropertyValue() == Globals.clientPlayer.getId()){ + if(Globals.clientState.clientPlayer != null && message.getpropertyValue() == Globals.clientState.clientPlayer.getId()){ LoggerInterface.loggerNetworking.DEBUG("Set this player's entity id!"); Globals.clientCharacterID = message.getentityID(); Globals.playerEntity = target; diff --git a/src/main/java/electrosphere/net/client/protocol/PlayerProtocol.java b/src/main/java/electrosphere/net/client/protocol/PlayerProtocol.java index f2bdef52..6f688228 100644 --- a/src/main/java/electrosphere/net/client/protocol/PlayerProtocol.java +++ b/src/main/java/electrosphere/net/client/protocol/PlayerProtocol.java @@ -23,11 +23,11 @@ public class PlayerProtocol implements ClientProtocolTemplate { Globals.profiler.beginCpuSample("PlayerProtocol.handlePlayerMessage"); switch(message.getMessageSubtype()){ case SET_ID: - Globals.clientPlayer = new Player(message.getplayerID(), Player.CLIENT_DB_ID); - LoggerInterface.loggerNetworking.DEBUG("[CLIENT] Player ID is " + Globals.clientPlayer.getId()); + Globals.clientState.clientPlayer = new Player(message.getplayerID(), Player.CLIENT_DB_ID); + LoggerInterface.loggerNetworking.DEBUG("[CLIENT] Player ID is " + Globals.clientState.clientPlayer.getId()); break; case SETINITIALDISCRETEPOSITION: { - Globals.clientPlayerData.setWorldPos(new Vector3i(message.getinitialDiscretePositionX(), message.getinitialDiscretePositionY(), message.getinitialDiscretePositionZ())); + Globals.clientState.clientPlayerData.setWorldPos(new Vector3i(message.getinitialDiscretePositionX(), message.getinitialDiscretePositionY(), message.getinitialDiscretePositionZ())); } break; } Globals.profiler.endCpuSample(); diff --git a/src/main/java/electrosphere/net/client/protocol/TerrainProtocol.java b/src/main/java/electrosphere/net/client/protocol/TerrainProtocol.java index 41fbb50b..034b1ff1 100644 --- a/src/main/java/electrosphere/net/client/protocol/TerrainProtocol.java +++ b/src/main/java/electrosphere/net/client/protocol/TerrainProtocol.java @@ -117,7 +117,7 @@ public class TerrainProtocol implements ClientProtocolTemplate { ){ // //mark terrain chunk for update - Globals.clientDrawCellManager.markUpdateable(worldPosToUpdate.x, worldPosToUpdate.y, worldPosToUpdate.z); + Globals.clientState.clientDrawCellManager.markUpdateable(worldPosToUpdate.x, worldPosToUpdate.y, worldPosToUpdate.z); // //update foliage manager @@ -229,8 +229,8 @@ public class TerrainProtocol implements ClientProtocolTemplate { ){ // //mark terrain chunk for update - Globals.clientBlockCellManager.markUpdateable(worldPosToUpdate.x, worldPosToUpdate.y, worldPosToUpdate.z); - Globals.clientBlockCellManager.markHomogenous(worldPosToUpdate.x, worldPosToUpdate.y, worldPosToUpdate.z, false); + Globals.clientState.clientBlockCellManager.markUpdateable(worldPosToUpdate.x, worldPosToUpdate.y, worldPosToUpdate.z); + Globals.clientState.clientBlockCellManager.markHomogenous(worldPosToUpdate.x, worldPosToUpdate.y, worldPosToUpdate.z, false); } } } break; diff --git a/src/main/java/electrosphere/net/server/Server.java b/src/main/java/electrosphere/net/server/Server.java index 2b7af256..1c8b2a4c 100644 --- a/src/main/java/electrosphere/net/server/Server.java +++ b/src/main/java/electrosphere/net/server/Server.java @@ -155,7 +155,7 @@ public class Server implements Runnable { public void broadcastMessage(NetworkMessage message){ connectListLock.acquireUninterruptibly(); for(ServerConnectionHandler client : activeConnections){ - if(Globals.clientPlayer == null || client.playerID != Globals.clientPlayer.getId()){ + if(Globals.clientState.clientPlayer == null || client.playerID != Globals.clientState.clientPlayer.getId()){ client.addMessagetoOutgoingQueue(message); } } diff --git a/src/main/java/electrosphere/net/server/protocol/AuthProtocol.java b/src/main/java/electrosphere/net/server/protocol/AuthProtocol.java index 77fb45b9..5feb3ae5 100644 --- a/src/main/java/electrosphere/net/server/protocol/AuthProtocol.java +++ b/src/main/java/electrosphere/net/server/protocol/AuthProtocol.java @@ -25,8 +25,8 @@ public class AuthProtocol implements ServerProtocolTemplate { Player newPlayer = new Player(connectionHandler, loginId); Globals.playerManager.registerPlayer(newPlayer); //there is a race condition here where if a local non-server client connects first then it breaks - if(connectionHandler.getIPAddress().contains("127.0.0.1") && Globals.RUN_CLIENT == true && Globals.clientPlayer == null){ - Globals.clientPlayer = newPlayer; + if(connectionHandler.getIPAddress().contains("127.0.0.1") && Globals.RUN_CLIENT == true && Globals.clientState.clientPlayer == null){ + Globals.clientState.clientPlayer = newPlayer; } connectionHandler.addMessagetoOutgoingQueue(PlayerMessage.constructSet_IDMessage(connectionHandler.getPlayerId())); } else { diff --git a/src/main/java/electrosphere/script/ScriptEngine.java b/src/main/java/electrosphere/script/ScriptEngine.java index 1a7aa686..9c4d1135 100644 --- a/src/main/java/electrosphere/script/ScriptEngine.java +++ b/src/main/java/electrosphere/script/ScriptEngine.java @@ -127,7 +127,7 @@ public class ScriptEngine extends SignalServiceImpl { */ public static final Object[][] hostSingletops = new Object[][]{ {"timekeeper",Globals.timekeeper}, - {"currentPlayer",Globals.clientPlayer}, + {"currentPlayer",Globals.clientState.clientPlayer}, {"loggerScripts",LoggerInterface.loggerScripts}, }; diff --git a/src/main/java/electrosphere/server/datacell/ServerDataCell.java b/src/main/java/electrosphere/server/datacell/ServerDataCell.java index b97f3e34..4beb2f6a 100644 --- a/src/main/java/electrosphere/server/datacell/ServerDataCell.java +++ b/src/main/java/electrosphere/server/datacell/ServerDataCell.java @@ -112,7 +112,7 @@ public class ServerDataCell { */ public void broadcastNetworkMessage(NetworkMessage message){ for(Player player : activePlayers){ - if(player != Globals.clientPlayer){ + if(player != Globals.clientState.clientPlayer){ player.addMessage(message); } }