diff --git a/assets/Config/settings.json b/assets/Config/settings.json index cd9e6e31..e6dfc60a 100644 --- a/assets/Config/settings.json +++ b/assets/Config/settings.json @@ -11,6 +11,7 @@ "graphicsPerformanceLODChunkRadius" : 3, "graphicsPerformanceEnableVSync" : false, "graphicsPerformanceDrawShadows" : true, + "graphicsViewRange" : 20000.0, "graphicsDebugDrawCollisionSpheres" : false, "graphicsDebugDrawPhysicsObjects" : false, diff --git a/src/main/java/electrosphere/game/config/UserSettings.java b/src/main/java/electrosphere/game/config/UserSettings.java index 51716b77..94fbf29f 100644 --- a/src/main/java/electrosphere/game/config/UserSettings.java +++ b/src/main/java/electrosphere/game/config/UserSettings.java @@ -39,6 +39,8 @@ public class UserSettings { boolean graphicsDebugDrawPhysicsObjects; boolean graphicsDebugDrawMovementVectors; boolean graphicsDebugDrawNavmesh; + + float graphicsViewRange; @@ -91,6 +93,10 @@ public class UserSettings { return graphicsPerformanceLODChunkRadius; } + public float getGraphicsViewDistance(){ + return graphicsViewRange; + } + public boolean graphicsDebugDrawNavmesh() { return graphicsDebugDrawNavmesh; } @@ -111,6 +117,10 @@ public class UserSettings { public void setGraphicsDebugDrawNavmesh(boolean draw){ this.graphicsDebugDrawNavmesh = draw; } + + public void setGraphicsViewRange(float range){ + graphicsViewRange = range; + } diff --git a/src/main/java/electrosphere/game/server/datacell/ServerDataCell.java b/src/main/java/electrosphere/game/server/datacell/ServerDataCell.java index ec393bd2..4f728265 100644 --- a/src/main/java/electrosphere/game/server/datacell/ServerDataCell.java +++ b/src/main/java/electrosphere/game/server/datacell/ServerDataCell.java @@ -110,7 +110,7 @@ public class ServerDataCell { */ public void broadcastNetworkMessage(NetworkMessage message){ for(Player player : activePlayers){ - if(player != Globals.serverPlayer){ + if(player != Globals.clientPlayer){ player.addMessage(message); } } @@ -121,7 +121,7 @@ public class ServerDataCell { * Commonly, this should be called when a player is added to the cell */ void serializeStateToPlayer(Player player){ - if(player != Globals.serverPlayer){ + if(player != Globals.clientPlayer){ for(Entity entity : loadedEntities){ if(CreatureUtils.isCreature(entity)){ CreatureUtils.sendEntityToPlayer(player, entity); diff --git a/src/main/java/electrosphere/main/Globals.java b/src/main/java/electrosphere/main/Globals.java index d537035a..307c0b8c 100644 --- a/src/main/java/electrosphere/main/Globals.java +++ b/src/main/java/electrosphere/main/Globals.java @@ -174,7 +174,7 @@ public class Globals { //Player manager // public static PlayerManager playerManager; - public static Player serverPlayer; + public static Player clientPlayer; // //Generic OpenGL Statements diff --git a/src/main/java/electrosphere/main/Main.java b/src/main/java/electrosphere/main/Main.java index 130d535e..46a206dd 100644 --- a/src/main/java/electrosphere/main/Main.java +++ b/src/main/java/electrosphere/main/Main.java @@ -71,42 +71,9 @@ public class Main { static double lastFrame = 0.0f; static long frameCount = 0; public static float deltaFrames = 0; - //View Controls - public static float view_Range = 200000.0f; - /* - Mouse Controls - */ - // static float mouse_lastX = 400; - // static float mouse_lastY = 300; - // static double xpos = 400; - // static double ypos = 300; - // static float mouseSensitivity = .1f; - // static double mouse_X_Buffer[] = new double[1]; - // static double mouse_Y_Buffer[] = new double[1]; - // static float cameraSpeed; - // static float yaw = 150; - // static float pitch = 50; - - - - static int playerStartRealX = 0; - static int playerStartRealY = 0; - -// public static Camera cam_Player_Orbit; - //Camera angles using theta-phi system - //Euler angles where theta is applied, then phi - //There is no bank applied to the camera - - public static Model model; - - public static int playerId = -1; - - public static boolean running = true; - public static Entity letterEntity; - //target amount of time per frame public static float targetFrameRate = 60.0f; static float targetFramePeriod = 1.0f/targetFrameRate; diff --git a/src/main/java/electrosphere/net/client/protocol/EntityProtocol.java b/src/main/java/electrosphere/net/client/protocol/EntityProtocol.java index 1f3643a5..8b3d6560 100644 --- a/src/main/java/electrosphere/net/client/protocol/EntityProtocol.java +++ b/src/main/java/electrosphere/net/client/protocol/EntityProtocol.java @@ -53,7 +53,7 @@ public class EntityProtocol { Entity target = Globals.entityManager.getEntityFromId(message.getentityID()); if(target != null){ CreatureUtils.setControllerPlayerId(target, message.getpropertyValue()); - if(message.getpropertyValue() == Main.playerId){ + if(Globals.clientPlayer != null && message.getpropertyValue() == Globals.clientPlayer.getId()){ 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 a27c1c9d..81f1c7b1 100644 --- a/src/main/java/electrosphere/net/client/protocol/PlayerProtocol.java +++ b/src/main/java/electrosphere/net/client/protocol/PlayerProtocol.java @@ -4,14 +4,15 @@ import electrosphere.logger.LoggerInterface; import electrosphere.main.Globals; import electrosphere.main.Main; import electrosphere.net.parser.net.message.PlayerMessage; +import electrosphere.net.server.player.Player; public class PlayerProtocol { protected static void handlePlayerMessage(PlayerMessage message){ switch(message.getMessageSubtype()){ case SET_ID: - Main.playerId = message.getplayerID(); - LoggerInterface.loggerNetworking.DEBUG("Player ID is " + Main.playerId); + Globals.clientPlayer = new Player(message.getplayerID()); + LoggerInterface.loggerNetworking.DEBUG("Player ID is " + Globals.clientPlayer.getId()); break; case SETINITIALDISCRETEPOSITION: Globals.clientPlayerData.setWorldPosition(message.getinitialDiscretePositionX(), message.getinitialDiscretePositionY()); diff --git a/src/main/java/electrosphere/net/server/Server.java b/src/main/java/electrosphere/net/server/Server.java index 4d386067..95deb960 100644 --- a/src/main/java/electrosphere/net/server/Server.java +++ b/src/main/java/electrosphere/net/server/Server.java @@ -1,5 +1,6 @@ package electrosphere.net.server; +import electrosphere.main.Globals; import electrosphere.main.Main; import electrosphere.net.NetUtils; import electrosphere.net.parser.net.message.NetworkMessage; @@ -74,7 +75,7 @@ public class Server implements Runnable{ public void broadcastMessage(NetworkMessage message){ for(ServerConnectionHandler client : clientMap.values()){ - if(client.playerID != Main.playerId){ + if(Globals.clientPlayer == null || client.playerID != Globals.clientPlayer.getId()){ client.addMessagetoOutgoingQueue(message); } } diff --git a/src/main/java/electrosphere/net/server/player/Player.java b/src/main/java/electrosphere/net/server/player/Player.java index 225f62e7..246cec64 100644 --- a/src/main/java/electrosphere/net/server/player/Player.java +++ b/src/main/java/electrosphere/net/server/player/Player.java @@ -32,6 +32,11 @@ public class Player { this.simulationRadius = Globals.userSettings.getGameplayPhysicsCellRadius(); } + //used for when client is creating a player object for itself + public Player(int id){ + this.id = id; + } + public int getId() { return id; } diff --git a/src/main/java/electrosphere/net/server/protocol/AuthProtocol.java b/src/main/java/electrosphere/net/server/protocol/AuthProtocol.java index 3e58b534..97013cf7 100644 --- a/src/main/java/electrosphere/net/server/protocol/AuthProtocol.java +++ b/src/main/java/electrosphere/net/server/protocol/AuthProtocol.java @@ -19,7 +19,7 @@ public class AuthProtocol { Player newPlayer = new Player(connectionHandler); Globals.playerManager.registerPlayer(newPlayer); if(connectionHandler.getIPAddress().contains("127.0.0.1")){ - Globals.serverPlayer = newPlayer; + Globals.clientPlayer = newPlayer; } connectionHandler.addMessagetoOutgoingQueue(PlayerMessage.constructSet_IDMessage(connectionHandler.getPlayerId())); } else { diff --git a/src/main/java/electrosphere/net/server/protocol/CharacterProtocol.java b/src/main/java/electrosphere/net/server/protocol/CharacterProtocol.java index e98b5706..7794823d 100644 --- a/src/main/java/electrosphere/net/server/protocol/CharacterProtocol.java +++ b/src/main/java/electrosphere/net/server/protocol/CharacterProtocol.java @@ -60,7 +60,7 @@ public class CharacterProtocol { // Entity sword = ItemUtils.spawnBasicItem("Katana"); // AttachUtils.attachEntityToEntityAtBone(newPlayerCharacter, sword, "Bone.031"); //set controller id - if(playerObject == Globals.serverPlayer){ + if(playerObject == Globals.clientPlayer){ Globals.playerEntity = newPlayerEntity; } } diff --git a/src/main/java/electrosphere/net/server/protocol/EntityProtocol.java b/src/main/java/electrosphere/net/server/protocol/EntityProtocol.java index 69c1e921..63752f05 100644 --- a/src/main/java/electrosphere/net/server/protocol/EntityProtocol.java +++ b/src/main/java/electrosphere/net/server/protocol/EntityProtocol.java @@ -53,7 +53,7 @@ public class EntityProtocol { void queueChunkState(ServerConnectionHandler connectionHandler){ //queue messages for that chunk - if(Globals.RUN_SERVER && Main.playerId == -1){ + if(Globals.RUN_SERVER && Globals.clientPlayer == null){ } else { for(Entity currentEntity : Globals.entityManager.getMoveable()){ diff --git a/src/main/java/electrosphere/renderer/RenderingEngine.java b/src/main/java/electrosphere/renderer/RenderingEngine.java index 0f684213..e7174ae5 100644 --- a/src/main/java/electrosphere/renderer/RenderingEngine.java +++ b/src/main/java/electrosphere/renderer/RenderingEngine.java @@ -14,7 +14,6 @@ import electrosphere.game.server.pathfinding.navmesh.NavMesh; import electrosphere.game.server.pathfinding.navmesh.NavShape; import electrosphere.logger.LoggerInterface; import electrosphere.main.Globals; -import static electrosphere.main.Main.view_Range; import static electrosphere.renderer.RenderUtils.createScreenTextureVAO; import electrosphere.renderer.actor.Actor; @@ -392,7 +391,7 @@ public class RenderingEngine { float verticalFOV = (float)(Globals.verticalFOV * Math.PI /180.0f); float aspectRatio = (float)Globals.WINDOW_WIDTH / (float)Globals.WINDOW_HEIGHT; float nearClip = 0.001f; - Globals.projectionMatrix.setPerspective(verticalFOV, aspectRatio, nearClip, view_Range); + Globals.projectionMatrix.setPerspective(verticalFOV, aspectRatio, nearClip, Globals.userSettings.getGraphicsViewDistance()); Globals.viewMatrix.translation(new Vector3f(0.0f,0.0f,-3.0f)); }