Skip to content
This repository has been archived by the owner on Oct 9, 2019. It is now read-only.

Commit

Permalink
Build-129: Save settings, API changes, removed unused files and fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Guerra24 committed Dec 4, 2015
1 parent dfb93b1 commit 9ffde84
Show file tree
Hide file tree
Showing 30 changed files with 176 additions and 441 deletions.
2 changes: 2 additions & 0 deletions assets/shaders/VertexEntity.glsl
Expand Up @@ -41,6 +41,8 @@ uniform mat4 projectionLightMatrix;
uniform mat4 viewLightMatrix;
uniform mat4 biasMatrix;
uniform vec3 lightPosition;
uniform vec3 cameraPosition;
uniform int translate;

const float gradient = 5.0;

Expand Down
39 changes: 21 additions & 18 deletions src/main/java/net/guerra24/voxel/client/api/API.java
Expand Up @@ -28,6 +28,7 @@
import java.util.Map;

import net.guerra24.voxel.client.api.mod.Mod;
import net.guerra24.voxel.client.core.GameSettings;
import net.guerra24.voxel.client.core.VoxelVariables;
import net.guerra24.voxel.client.util.Logger;
import net.guerra24.voxel.client.world.MobManager;
Expand All @@ -43,14 +44,16 @@ public class API {
/**
* Mods
*/
private static Map<ModKey, Mod> mods;
private static ModLoader modLoader;
private static MobManager mobManager;
private Map<Integer, Mod> mods;
private ModLoader modLoader;
private MobManager mobManager;
private GameSettings gameSettings;

public API() {
mods = new HashMap<ModKey, Mod>();
public API(GameSettings gameSettings) {
mods = new HashMap<Integer, Mod>();
modLoader = new ModLoader();
modLoader.loadMods();
this.gameSettings = gameSettings;
}

/**
Expand All @@ -62,11 +65,12 @@ public API() {
public void preInit() throws VersionException {
Logger.log("Pre Initializing Mods");
for (int x = 0; x < mods.size(); x++) {
mods.get(x).setAPI(this);
if (mods.get(x).getKey().getApiVersion() >= VoxelVariables.apiVersionNum)
mods.get(x).preInit();
else
throw new VersionException("The mod " + mods.get(x).getKey().getName() + " only works in a version equals or more that "
+ VoxelVariables.apiVersion);
throw new VersionException("The mod " + mods.get(x).getKey().getName()
+ " only works in a version equals or more that " + VoxelVariables.apiVersion);
}

}
Expand Down Expand Up @@ -101,14 +105,18 @@ public void postInit() {
* @param result
* Mod
*/
public static void registerMod(Mod mod) {
mods.put(mod.getKey(), mod);
public void registerMod(Mod mod) {
mods.put(mod.getKey().getId(), mod);
}

public static void registetMob(IEntity mob) {
public void registetMob(IEntity mob) {
mobManager.registerMob(mob);
}

public void registerSaveData(String key, String value) {
gameSettings.registerValue(key, value);
}

/**
* Gets the Mod from ID
*
Expand All @@ -117,16 +125,15 @@ public static void registetMob(IEntity mob) {
* @return Mod
*
*/
public static Mod getMod(int id) {
public Mod getMod(ModKey id) {
return mods.get(id);
}

/**
* Get last avaiable ID
*
* @return ID
*/
public static int getLastID() {
public int getTotalMods() {
return mods.size();
}

Expand All @@ -138,12 +145,8 @@ public void dispose() {
mods.clear();
}

public static ModLoader getModLoader() {
return modLoader;
}

public void setMobManager(MobManager mobManager) {
API.mobManager = mobManager;
this.mobManager = mobManager;
}

}
27 changes: 27 additions & 0 deletions src/main/java/net/guerra24/voxel/client/api/mod/Mod.java
Expand Up @@ -24,7 +24,12 @@

package net.guerra24.voxel.client.api.mod;

import com.jmr.wrapper.common.Connection;

import net.guerra24.voxel.client.api.API;
import net.guerra24.voxel.client.api.ModKey;
import net.guerra24.voxel.client.core.Voxel;
import net.guerra24.voxel.client.world.chunks.Chunk;

/**
* Mod
Expand All @@ -35,6 +40,7 @@
public abstract class Mod {

private ModKey key;
private API api;

public Mod(int id, String name, String version, int apiVersion) {
key = new ModKey(id, name, version, apiVersion);
Expand All @@ -44,6 +50,11 @@ public Mod(int id, String name, String version, int apiVersion) {
* Basic Mod Info
*
*/

public void setAPI(API api) {
this.api = api;
}

public abstract void preInit();

/**
Expand All @@ -58,7 +69,23 @@ public Mod(int id, String name, String version, int apiVersion) {
*/
public abstract void postInit();

public abstract void generateChunk(Chunk chunk, int x, int y, int z);

public abstract void updateKeyboard();

public abstract void updateInGame(float delta, Voxel voxel);

public abstract void clientConnect(Connection con);

public abstract void clientUpdate(Connection con);

public abstract void clientDisconnect(Connection con);

public ModKey getKey() {
return key;
}

public API getApi() {
return api;
}
}
61 changes: 61 additions & 0 deletions src/main/java/net/guerra24/voxel/client/core/GameSettings.java
@@ -0,0 +1,61 @@
package net.guerra24.voxel.client.core;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

public class GameSettings {

private Properties prop;
private File settings;

public GameSettings() {
settings = new File(VoxelVariables.settings);
prop = new Properties();
if (settings.exists()) {
try {
prop.load(new FileInputStream(settings));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
VoxelVariables.useShadows = Boolean.parseBoolean(getValue("useShadows"));
VoxelVariables.useVolumetricLight = Boolean.parseBoolean(getValue("useVolumetricLight"));
VoxelVariables.useHQWater = Boolean.parseBoolean(getValue("useHQWater"));
VoxelVariables.useFXAA = Boolean.parseBoolean(getValue("useFXAA"));
} else {
updateSetting();
save();
}
}

public void registerValue(String key, String data) {
prop.setProperty(key, data);
}

public String getValue(String key) {
return prop.getProperty(key);
}

public void save() {
try {
prop.store(new FileOutputStream(settings), "Voxel Settings");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

public void updateSetting() {
registerValue("useShadows", Boolean.toString(VoxelVariables.useShadows));
registerValue("useVolumetricLight", Boolean.toString(VoxelVariables.useVolumetricLight));
registerValue("useHQWater", Boolean.toString(VoxelVariables.useHQWater));
registerValue("useFXAA", Boolean.toString(VoxelVariables.useFXAA));
}

}
2 changes: 1 addition & 1 deletion src/main/java/net/guerra24/voxel/client/core/Voxel.java
Expand Up @@ -127,7 +127,7 @@ else if (amd)
VoxelVariables.useShadows = false;
}
gameResources = new GameResources();
api = new API();
api = new API(gameResources.getGameSettings());
api.preInit();
}

Expand Down
Expand Up @@ -35,7 +35,7 @@ public class VoxelVariables {
* Display Data
*/
public static int FPS = 60;
public static boolean VSYNC = false;
public static boolean VSYNC = true;
public static final String Title = "Voxel";
/**
* Game Settings
Expand All @@ -57,6 +57,7 @@ public class VoxelVariables {
public static boolean runningOnMac = false;
public static boolean autostart = false;
public static boolean christmas = false;
public static final String settings = "assets/game/settings.conf";
/**
* Graphic Settings
*/
Expand All @@ -76,6 +77,7 @@ public class VoxelVariables {
public static int genRadius = radius + radiusLimit;
public static boolean isCustomSeed = false;
public static String seed = "";
public static boolean generateChunks = true;
public static final int CHUNK_SIZE = 16;
public static final int CHUNK_HEIGHT = 16;
public static final int DIM_0 = 0;
Expand Down
Expand Up @@ -25,6 +25,8 @@ public void update(Voxel voxel, GlobalStates states, float delta) {

if (gm.getMenuSystem().optionsMenu.getExitButton().pressed()) {
switchToManMenu = true;
gm.getGameSettings().updateSetting();
gm.getGameSettings().save();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
Expand Down Expand Up @@ -73,7 +75,7 @@ public void update(Voxel voxel, GlobalStates states, float delta) {
@Override
public void render(Voxel voxel, GlobalStates states, float delta) {
GameResources gm = voxel.getGameResources();
gm.getMenuSystem().optionsMenu.update(gm);
gm.getMenuSystem().optionsMenu.update(gm);
if (switchToManMenu) {
gm.getMenuSystem().mainMenu.load(gm);
switchToManMenu = false;
Expand Down
Expand Up @@ -83,7 +83,7 @@ public void normalizePlane(float[][] frustum, int side) {
* @param gm
* GameResources
*/
public void calculateFrustum(Matrix4f projectionMatrix , Camera camera) {
public void calculateFrustum(Matrix4f projectionMatrix, Camera camera) {
float[] clip = new float[16];

Matrix4f.mul(projectionMatrix, Maths.createViewMatrix(camera), clip_);
Expand Down
Expand Up @@ -160,6 +160,7 @@ public void begin(GameResources gm) {
shader.start();
shader.loadProjectionMatrix(projectionMatrix);
shader.loadviewMatrix(gm.getCamera());
shader.loadCameraPosition(gm.getCamera().getPosition());
shader.loadBiasMatrix(gm);
shader.useShadows(VoxelVariables.useShadows);
}
Expand All @@ -186,6 +187,7 @@ private void renderEntity(GameResources gm) {
shader.start();
shader.loadProjectionMatrix(projectionMatrix);
shader.loadviewMatrix(gm.getCamera());
shader.loadCameraPosition(gm.getCamera().getPosition());
entityRenderer.renderEntity(entities, gm);
shader.stop();
entities.clear();
Expand All @@ -196,6 +198,7 @@ private void renderGui(GameResources gm) {
shader.loadProjectionMatrix(
Maths.orthographic(-0.7f * aspectRatio, 0.7f * aspectRatio, -0.7f, 0.7f, -100, 100f));
shader.loadviewMatrix(gm.getCamera());
shader.loadCameraPosition(gm.getCamera().getPosition());
entityRenderer.renderEntity(guiModels, gm);
shader.stop();
guiModels.clear();
Expand Down
Expand Up @@ -152,9 +152,9 @@ public void release() {

glfwDefaultWindowHints();
glfwWindowHint(GLFW_VISIBLE, GL_TRUE);

displayResizable = false;
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);

glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
Expand Down
Expand Up @@ -29,6 +29,7 @@
import net.guerra24.voxel.client.util.Maths;
import net.guerra24.voxel.client.world.entities.Camera;
import net.guerra24.voxel.universal.util.vector.Matrix4f;
import net.guerra24.voxel.universal.util.vector.Vector3f;

/**
* Entity Shader
Expand All @@ -51,7 +52,8 @@ public class EntityShader extends ShaderProgram {
private int loc_texture0;
private int loc_depth0;
private int loc_id;

private int loc_cameraPosition;

private int loc_useShadows;

/**
Expand Down Expand Up @@ -82,7 +84,7 @@ protected void getAllUniformLocations() {
loc_depth0 = super.getUniformLocation("depth0");
loc_useShadows = super.getUniformLocation("useShadows");
loc_id = super.getUniformLocation("id");

loc_cameraPosition = super.getUniformLocation("cameraPosition");
}

/**
Expand All @@ -93,15 +95,18 @@ public void connectTextureUnits() {
super.loadInt(loc_texture0, 0);
super.loadInt(loc_depth0, 1);
}
public void loadId(int id){

public void loadId(int id) {
super.loadInt(loc_id, id);
}

public void loadBlockBright(float value) {
super.loadFloat(loc_blockBright, value);
}


public void loadCameraPosition(Vector3f pos) {
super.loadVector(loc_cameraPosition, pos);
}

public void useShadows(boolean value) {
super.loadBoolean(loc_useShadows, value);
Expand Down
Expand Up @@ -10,7 +10,7 @@ public class ShadowShader extends ShaderProgram {
private int loc_projectionMatrix;
private int loc_transformationMatrix;
private int loc_viewMatrix;

public ShadowShader() {
super(VoxelVariables.VERTEX_FILE_SHADOW, VoxelVariables.FRAGMENT_FILE_SHADOW);
}
Expand All @@ -36,7 +36,7 @@ protected void bindAttributes() {
public void loadTransformationMatrix(Matrix4f matrix) {
super.loadMatrix(loc_transformationMatrix, matrix);
}

/**
* Loads View Matrix to the shader
*
Expand Down

0 comments on commit 9ffde84

Please sign in to comment.