From 6bbcc4af5009a2009349aa221081f7722ff5fb59 Mon Sep 17 00:00:00 2001 From: austin Date: Sat, 7 Aug 2021 17:35:27 -0400 Subject: [PATCH] Add user settings --- assets/Config/settings.json | 16 +++ .../game/config/UserSettings.java | 128 ++++++++++++++++++ src/main/java/electrosphere/main/Globals.java | 7 +- src/main/java/electrosphere/main/Main.java | 4 + 4 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 assets/Config/settings.json create mode 100644 src/main/java/electrosphere/game/config/UserSettings.java diff --git a/assets/Config/settings.json b/assets/Config/settings.json new file mode 100644 index 00000000..380f674f --- /dev/null +++ b/assets/Config/settings.json @@ -0,0 +1,16 @@ +{ + "gameplayGenerateWorld" : false, + + "displayWidth" : 1920, + "displayHeight" : 1080, + + "graphicsFOV" : 90.0, + + "graphicsPerformanceEnableVSync" : false, + "graphicsPerformanceDrawShadows" : true, + + "graphicsDebugDrawCollisionSpheres" : false, + "graphicsDebugDrawPhysicsObjects" : false, + "graphicsDebugDrawMovementVectors" : false + +} \ No newline at end of file diff --git a/src/main/java/electrosphere/game/config/UserSettings.java b/src/main/java/electrosphere/game/config/UserSettings.java new file mode 100644 index 00000000..5e21bbf0 --- /dev/null +++ b/src/main/java/electrosphere/game/config/UserSettings.java @@ -0,0 +1,128 @@ +package electrosphere.game.config; + +import electrosphere.main.Globals; +import electrosphere.util.FileLoadingUtils; + +/** + * + * @author amaterasu + */ +public class UserSettings { + + + // + //Gameplay settings + // + boolean gameplayGenerateWorld; + + + // + //Display settings + // + int displayWidth; + int displayHeight; + + + // + //Graphics settings + // + //general + float graphicsFOV; + //performance + boolean graphicsPerformanceEnableVSync; + boolean graphicsPerformanceDrawShadows; + //debug + boolean graphicsDebugDrawCollisionSpheres; + boolean graphicsDebugDrawPhysicsObjects; + boolean graphicsDebugDrawMovementVectors; + + + + + + + + + public boolean gameplayGenerateWorld() { + return gameplayGenerateWorld; + } + + public int getDisplayWidth() { + return displayWidth; + } + + public int getDisplayHeight() { + return displayHeight; + } + + public float getGraphicsFOV() { + return graphicsFOV; + } + + public boolean graphicsPerformanceEnableVSync() { + return graphicsPerformanceEnableVSync; + } + + public boolean graphicsPerformanceDrawShadows() { + return graphicsPerformanceDrawShadows; + } + + public boolean graphicsDebugDrawCollisionSpheres() { + return graphicsDebugDrawCollisionSpheres; + } + + public boolean graphicsDebugDrawPhysicsObjects() { + return graphicsDebugDrawPhysicsObjects; + } + + public boolean graphicsDebugDrawMovementVectors() { + return graphicsDebugDrawMovementVectors; + } + + + + + + + + + + + + + + static UserSettings getDefault(){ + UserSettings rVal = new UserSettings(); + + //display settings + rVal.displayHeight = 1080; + rVal.displayWidth = 1920; + + //gameplay settings + rVal.gameplayGenerateWorld = true; + + //graphics settings + rVal.graphicsDebugDrawCollisionSpheres = false; + rVal.graphicsDebugDrawMovementVectors = false; + rVal.graphicsDebugDrawPhysicsObjects = false; + rVal.graphicsFOV = 90.0f; + rVal.graphicsPerformanceDrawShadows = true; + rVal.graphicsPerformanceEnableVSync = true; + + return rVal; + } + + + public static void loadUserSettings(){ + Globals.userSettings = FileLoadingUtils.loadObjectFromAssetPath("/Config/settings.json", UserSettings.class); + if(Globals.userSettings == null){ + Globals.userSettings = getDefault(); + } + Globals.WINDOW_WIDTH = Globals.userSettings.displayWidth; + Globals.WINDOW_HEIGHT = Globals.userSettings.displayHeight; + Globals.FOV = Globals.userSettings.graphicsFOV; + } + + + +} diff --git a/src/main/java/electrosphere/main/Globals.java b/src/main/java/electrosphere/main/Globals.java index 5216b323..ca89c0f5 100644 --- a/src/main/java/electrosphere/main/Globals.java +++ b/src/main/java/electrosphere/main/Globals.java @@ -18,6 +18,7 @@ import electrosphere.game.client.terrain.manager.ClientTerrainManager; import electrosphere.game.client.world.ClientWorldData; import electrosphere.game.collision.CommonWorldData; import electrosphere.engine.LoadingThread; +import electrosphere.game.config.UserSettings; import electrosphere.game.server.ai.AIManager; import electrosphere.game.server.character.Character; import electrosphere.game.config.creature.type.model.CreatureTypeMap; @@ -67,7 +68,11 @@ import org.lwjgl.glfw.GLFWErrorCallback; * @author amaterasu */ public class Globals { - + + // + //Top level user settings object + // + public static UserSettings userSettings; // //Rendering Engine diff --git a/src/main/java/electrosphere/main/Main.java b/src/main/java/electrosphere/main/Main.java index c4e49b8f..d1b41566 100644 --- a/src/main/java/electrosphere/main/Main.java +++ b/src/main/java/electrosphere/main/Main.java @@ -15,6 +15,7 @@ import electrosphere.entity.types.item.ItemUtils; import electrosphere.entity.types.attach.AttachUtils; import electrosphere.engine.LoadingThread; import electrosphere.game.client.ClientFunctions; +import electrosphere.game.config.UserSettings; import electrosphere.game.state.MicroSimulation; import electrosphere.logger.LoggerInterface; import electrosphere.renderer.RenderingEngine; @@ -100,6 +101,9 @@ public class Main { // // + //load user settings + UserSettings.loadUserSettings(); + //initialize logging interfaces LoggerInterface.initLoggers();