Overhaul build process + launcher + file loading

This commit is contained in:
austin 2021-06-25 23:19:09 -04:00
parent 6bea0cc24f
commit 40565a1c83
83 changed files with 164 additions and 245 deletions

4
.gitignore vendored
View File

@ -9,7 +9,9 @@
/Models
/Models/**.*
/launcher/src/main.exe
/build
/launcher/launcher.exe
/Telephone-*.jar
/hs_err_pid*

View File

@ -0,0 +1 @@
{"state":"TITLE_MENU","controlsMap":{"moveForward":87,"menuType9":57,"menuTypeBackspace":259,"moveBackward":83,"menuType0":48,"menuType.":46,"fall":341,"moveRight":68,"menuSelect":257,"menuType7":55,"menuDecrement":265,"menuBackout":256,"menuType8":56,"moveLeft":65,"menuType5":53,"menuType6":54,"menuType3":51,"menuType4":52,"menuIncrement":264,"menuType1":49,"jump":32,"menuType2":50},"controlsState":{"moveForward":false,"menuType9":false,"menuTypeBackspace":false,"moveBackward":false,"menuType0":false,"menuType.":false,"fall":false,"moveRight":false,"menuSelect":false,"menuType7":false,"menuDecrement":false,"menuBackout":false,"menuType8":false,"moveLeft":false,"menuType5":false,"menuType6":false,"menuType3":false,"menuType4":false,"menuIncrement":false,"menuType1":false,"jump":false,"menuType2":false}}

File diff suppressed because one or more lines are too long

View File

Before

Width:  |  Height:  |  Size: 937 KiB

After

Width:  |  Height:  |  Size: 937 KiB

View File

Before

Width:  |  Height:  |  Size: 192 KiB

After

Width:  |  Height:  |  Size: 192 KiB

View File

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View File

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 27 KiB

View File

Before

Width:  |  Height:  |  Size: 44 KiB

After

Width:  |  Height:  |  Size: 44 KiB

View File

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

View File

Before

Width:  |  Height:  |  Size: 137 B

After

Width:  |  Height:  |  Size: 137 B

View File

Before

Width:  |  Height:  |  Size: 967 B

After

Width:  |  Height:  |  Size: 967 B

View File

Before

Width:  |  Height:  |  Size: 967 B

After

Width:  |  Height:  |  Size: 967 B

View File

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

Before

Width:  |  Height:  |  Size: 70 KiB

After

Width:  |  Height:  |  Size: 70 KiB

View File

Before

Width:  |  Height:  |  Size: 195 B

After

Width:  |  Height:  |  Size: 195 B

View File

Before

Width:  |  Height:  |  Size: 233 B

After

Width:  |  Height:  |  Size: 233 B

View File

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

View File

Before

Width:  |  Height:  |  Size: 165 B

After

Width:  |  Height:  |  Size: 165 B

12
build.sh Normal file
View File

@ -0,0 +1,12 @@
rm -rf ./build
mkdir build
mkdir ./build/assets
mvn package
cp ./target/Renderer-0.1.jar ./build/engine.jar
cd ./launcher/
make clean
make build
cd ..
cp ./launcher/launcher.exe ./build/
unzip ./launcher/jdk.zip -d ./build/
cp -r ./assets/* ./build/assets/

5
launcher/Makefile Normal file
View File

@ -0,0 +1,5 @@
build: ./src/main.c
gcc ./src/main.c -o launcher
clean:
rm ./launcher.exe

View File

@ -25,7 +25,7 @@ int main(){
//get jar location
char jarPath[MAX_PATH_SIZE + 50];
strcpy(jarPath,currentWorkingDirectory);
strcat(jarPath,"\\Renderer.jar");
strcat(jarPath,"\\engine.jar");
logVar("javaPath: ",javaPath);
logVar("jarPath: ",jarPath);
printf("%s\n",jarPath);

View File

@ -1,113 +0,0 @@
package electrosphere.cfg;
import com.google.gson.Gson;
import electrosphere.main.Globals;
import electrosphere.main.Main;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author satellite
*/
//Main configuration file for application
public class MainConfig {
//localconfig.json version
public static final int CONFIG_FILE_VERSION = 4;
//physical file version
public int version;
//Main directory of project resources
public String projectMainDirectory;
//
//Networking related
//
//should we run a server at all?
public boolean runServer;
public boolean runClient;
public String serverAddress;
//
//Rendering related
//
//should the renderer run at all?
public boolean runRenderer;
//
//Terrain
//
//Do we load terrain?
public boolean loadTerrain;
//If load terrain, where from?
public String loadTerrainLocation;
/**
* Generate a localconfig.json and save it to our resources dir
*/
public static void generateMainConfig(){
System.out.println("localconfig.json either doesn't exist or is out of date");
System.out.println("Would you like to generate a new one?(1-y/0-n)");
Scanner scan = new Scanner(System.in);
if(scan.nextInt() == 0){
System.err.println("Bad localconfig.json");
System.exit(1);
}
Globals.mainConfig = new MainConfig();
System.out.println("What is the main resources directory?");
System.out.println("(Suggested: \"" + Main.class.getResource("/").getPath() + "\"");
Globals.mainConfig.projectMainDirectory = scan.next();
System.out.println("Where would you like to save quickload terrain to?");
System.out.println("(Suggested: \"" + Globals.mainConfig.projectMainDirectory + "/src/main/resources/Config/terrain.json" + "\"");
Globals.mainConfig.loadTerrainLocation = scan.next();
System.out.println("Would you like to load terrain from file?(1-y/0-n)");
if(scan.nextInt() == 1){
Globals.mainConfig.loadTerrain = true;
} else {
Globals.mainConfig.loadTerrain = false;
}
System.out.println("Would you like to run the server?(1-y/0-n)");
if(scan.nextInt() == 1){
Globals.mainConfig.runServer = true;
} else {
Globals.mainConfig.runServer = false;
}
System.out.println("Would you like to run the client?(1-y/0-n)");
if(scan.nextInt() == 1){
Globals.mainConfig.runClient = true;
} else {
Globals.mainConfig.runClient = false;
}
System.out.println("Would you like to run the renderer?(1-y/0-n)");
if(scan.nextInt() == 1){
Globals.mainConfig.runRenderer = true;
} else {
Globals.mainConfig.runRenderer = false;
}
Globals.mainConfig.version = MainConfig.CONFIG_FILE_VERSION;
System.out.println("Saving config to " + Globals.mainConfig.projectMainDirectory + "/src/main/resources/Config/localconfig.json");
Gson gson = new Gson();
try {
Files.write(
new File(Globals.mainConfig.projectMainDirectory + "/src/main/resources/Config/localconfig.json").toPath(),
gson.toJson(Globals.mainConfig).getBytes()
);
} catch (IOException ex) {
System.err.println("Failed to save!!");
ex.printStackTrace();
System.exit(1);
}
System.out.println("Saved");
}
}

View File

@ -89,7 +89,7 @@ public class ControlHandler {
controlsState = new HashMap();
}
public static void generateExampleControlsMap(){
public static ControlHandler generateExampleControlsMap(){
ControlHandler handler = new ControlHandler();
/*
Main Game controls
@ -172,7 +172,12 @@ public class ControlHandler {
/*
Save to file
*/
Utilities.saveObjectToBakedJsonFile("/Config/keybinds.json", handler);
// Utilities.saveObjectToBakedJsonFile("/Config/keybinds.json", handler);
/*
return
*/
return handler;
}

View File

@ -78,7 +78,7 @@ public class MovementTree {
switch(message.getMessageSubtype()){
case MOVE:
position.set(message.getpositionX(), message.getpositionY(), message.getpositionZ());
if(Globals.mainConfig.runServer){
if(Globals.RUN_SERVER){
Globals.server.broadcastMessage(
EntityMessage.constructMoveMessage(
parent.getId(),

View File

@ -26,6 +26,7 @@ public class ItemUtils {
}
rVal.putData(EntityDataStrings.ITEM_IS_ITEM, true);
rVal.putData(EntityDataStrings.ITEM_TYPE, itemId);
rVal.putData(EntityDataStrings.DATA_STRING_CREATURE_TYPE, itemId);
rVal.putData(EntityDataStrings.DATA_STRING_SCALE, new Vector3f(0.005f,0.005f,0.005f));
rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, new Quaternionf().identity().rotateY((float)(-Math.PI/2)).rotateZ(-(float)(Math.PI/2)));
Globals.entityManager.registerItemEntity(rVal);

View File

@ -16,6 +16,7 @@ public class ClientPlayerData {
public void setInitialDiscretePosition(int x, int y){
initialDiscretePositionX = x;
initialDiscretePositionY = y;
System.out.println("Loaded");
loaded = true;
}

View File

@ -24,8 +24,8 @@ public class Simulation {
}
void init(){
CreatureTypeMap creatureTypeMap = FileLoadingUtils.loadModelObjectFromBakedJsonFile("Data/creatures.json", CreatureTypeMap.class);
CivilizationMap civilizationMap = FileLoadingUtils.loadModelObjectFromBakedJsonFile("Data/civilization.json", CivilizationMap.class);
CreatureTypeMap creatureTypeMap = FileLoadingUtils.loadObjectFromAssetPath("Data/creatures.json", CreatureTypeMap.class);
CivilizationMap civilizationMap = FileLoadingUtils.loadObjectFromAssetPath("Data/civilization.json", CivilizationMap.class);
}
public void simulate(){

View File

@ -83,7 +83,7 @@ public class ServerTerrainManager {
Gson gson = new Gson();
String terrainOutRaw = gson.toJson(model);
try {
Files.write(new File(Globals.mainConfig.loadTerrainLocation).toPath(), terrainOutRaw.getBytes());
Files.write(new File("./Config/terrain.json").toPath(), terrainOutRaw.getBytes());
} catch (IOException ex) {
ex.printStackTrace();
}
@ -91,7 +91,7 @@ public class ServerTerrainManager {
public void load(){
Gson gson = new Gson();
model = FileLoadingUtils.loadModelObjectFromBakedJsonFile(Globals.mainConfig.loadTerrainLocation, TerrainModel.class);
model = FileLoadingUtils.loadObjectFromAssetPath("./Config/terrain.json", TerrainModel.class);
}
public float[][] getTerrainAtChunk(int x, int y){

View File

@ -41,9 +41,6 @@ public class LoadingThread extends Thread {
public static final int LOAD_MAIN_GAME = 1;
public static final int LOAD_ARENA = 2;
boolean FLAG_INIT_SERVER = false;
boolean FLAG_INIT_CLIENT = false;
int threadType;
Semaphore lock;
@ -89,23 +86,24 @@ public class LoadingThread extends Thread {
loadingBox.setDraw(true);
//initialize the terrain manager (server only)
if(FLAG_INIT_SERVER){
if(Globals.RUN_SERVER){
initServerGameTerrainManager();
}
System.out.println("run server: " + Globals.RUN_SERVER + " run client: " + Globals.RUN_CLIENT);
//init the data of the world
if(FLAG_INIT_SERVER){
if(Globals.RUN_SERVER){
initServerGameWorldData();
}
//initialize the server thread (server only)
if(FLAG_INIT_SERVER){
if(Globals.RUN_SERVER){
initServerThread();
}
//initialize the client thread (client)
if(FLAG_INIT_CLIENT){
if(Globals.RUN_CLIENT){
initClientThread();
stallForClientPlayerData();
}
@ -117,7 +115,7 @@ public class LoadingThread extends Thread {
initDynamicCellManager();
//collision engine
initCollisionEngine(FLAG_INIT_SERVER);
initCollisionEngine(Globals.RUN_SERVER);
//initialize the basic graphical entities of the world (skybox, camera)
initWorldBaseGraphicalEntities();
@ -163,12 +161,12 @@ public class LoadingThread extends Thread {
initServerArenaTerrainManager();
//initialize the server thread (server only)
if(FLAG_INIT_SERVER){
if(Globals.RUN_SERVER){
initServerThread();
}
//initialize the client thread (client)
if(FLAG_INIT_CLIENT){
if(Globals.RUN_CLIENT){
initClientThread();
stallForClientPlayerData();
}
@ -180,7 +178,7 @@ public class LoadingThread extends Thread {
initDynamicCellManager();
//collision engine
initCollisionEngine(FLAG_INIT_SERVER);
initCollisionEngine(Globals.RUN_SERVER);
//initialize the basic graphical entities of the world (skybox, camera)
initWorldBaseGraphicalEntities();
@ -237,8 +235,8 @@ public class LoadingThread extends Thread {
*/
float[][] elevation;
Globals.serverTerrainManager = new ServerTerrainManager(2000,200,100,0.25f,0);
if(Globals.mainConfig.runServer){
if(Globals.mainConfig.loadTerrain){
if(Globals.RUN_SERVER){
if(Globals.LOAD_TERRAIN){
Globals.serverTerrainManager.load();
} else {
Globals.serverTerrainManager.generate();
@ -313,11 +311,10 @@ public class LoadingThread extends Thread {
static void initServerThread(){
//start server networking
Thread serverThread = null;
if(Globals.mainConfig.runServer){
if(Globals.RUN_SERVER){
Globals.server = new Server(NetUtils.getPort());
serverThread = new Thread(Globals.server);
serverThread.start();
Globals.serverThread = new Thread(Globals.server);
Globals.serverThread.start();
}
}
@ -326,7 +323,7 @@ public class LoadingThread extends Thread {
static void initClientThread(){
//start client networking
Thread clientThread = null;
if(Globals.mainConfig.runClient){
if(Globals.RUN_CLIENT){
Globals.clientConnection = new ClientNetworking(NetUtils.getAddress(),NetUtils.getPort());
clientThread = new Thread(Globals.clientConnection);
clientThread.start();
@ -458,16 +455,4 @@ public class LoadingThread extends Thread {
EntityUtils.getEntityPosition(testHomie).set(2,0,2);
AttachUtils.attachEntityToEntityAtBone(testHomie, sword, "Bone.020");
}
public void setFLAG_INIT_SERVER(boolean FLAG_INIT_SERVER) {
this.FLAG_INIT_SERVER = FLAG_INIT_SERVER;
}
public void setFLAG_INIT_CLIENT(boolean FLAG_INIT_CLIENT) {
this.FLAG_INIT_CLIENT = FLAG_INIT_CLIENT;
}
}

View File

@ -1,7 +1,5 @@
package electrosphere.main;
import electrosphere.renderer.Camera;
import electrosphere.renderer.light.DirectionalLight;
import electrosphere.renderer.light.PointLight;
import electrosphere.renderer.light.SpotLight;
import electrosphere.renderer.Material;
@ -9,7 +7,6 @@ import electrosphere.renderer.Model;
import electrosphere.renderer.texture.Texture;
import electrosphere.renderer.texture.TextureMap;
import com.google.gson.Gson;
import electrosphere.cfg.MainConfig;
import electrosphere.controls.ControlHandler;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityManager;
@ -60,12 +57,7 @@ import org.lwjgl.glfw.GLFWErrorCallback;
* @author amaterasu
*/
public class Globals {
//
//Config
//
public static MainConfig mainConfig;
//
//Rendering Engine
@ -77,11 +69,14 @@ public class Globals {
//Client connection to server
//
public static ClientNetworking clientConnection;
public static boolean RUN_CLIENT = true;
//
//Server manager thing
//
public static Thread serverThread;
public static Server server;
public static boolean RUN_SERVER = true;
//
@ -148,7 +143,6 @@ public class Globals {
public static Texture blackTexture;
public static DirectionalLight lightDirectionalDefault;
public static ArrayList<PointLight> lightPointListDefault;
public static SpotLight lightSpotDefault;
@ -168,6 +162,7 @@ public class Globals {
public static EntityManager entityManager;
//terrain manager
public static boolean LOAD_TERRAIN = true;
public static ServerTerrainManager serverTerrainManager;
public static Vector3f spawnPoint = new Vector3f(1000,0,1000);
@ -237,7 +232,7 @@ public class Globals {
// try {
//deserializes the texture map from its default path using gson
//also done in one line
textureMapDefault = FileLoadingUtils.loadModelObjectFromBakedJsonFile("Textures/default_texture_map.json", TextureMap.class);
textureMapDefault = FileLoadingUtils.loadObjectFromAssetPath("Textures/default_texture_map.json", TextureMap.class);
// textureMapDefault = gson.fromJson(Files.newBufferedReader(new File(Thread.currentThread().getContextClassLoader().getResource("Textures/default_texture_map.json").getFile()).toPath()), TextureMap.class); //only the best of coding practices :)
// } catch (IOException ex) { ex.printStackTrace(); } //TODO: handle better :tm:
//entity type map
@ -265,9 +260,8 @@ public class Globals {
materialDefault.set_diffuse(textureDiffuseDefault);
materialDefault.set_specular(textureSpecularDefault);
//create default lights
lightDirectionalDefault = new DirectionalLight(new Vector3f(0,-1f,0));
assetManager.registerModelToSpecificString(ModelUtils.createBitmapDisplay(), AssetDataStrings.ASSET_STRING_BITMAP_FONT);
RawFontMap fontMap = FileLoadingUtils.loadModelObjectFromBakedJsonFile("Textures/Fonts/myFontMap.json", RawFontMap.class);
RawFontMap fontMap = FileLoadingUtils.loadObjectFromAssetPath("Textures/Fonts/myFontMap.json", RawFontMap.class);
FontUtils.setFontDataMap(fontMap);
//black texture for backgrouns
blackTexture = new Texture("Textures/b1.png");
@ -286,7 +280,7 @@ public class Globals {
}
static void initEntityTypeMap(){
CreatureTypeList typeList = FileLoadingUtils.loadModelObjectFromBakedJsonFile("Data/entity_map.json", CreatureTypeList.class);
CreatureTypeList typeList = FileLoadingUtils.loadObjectFromAssetPath("Data/entity_map.json", CreatureTypeList.class);
for(CreatureType type : typeList.getTypes()){
entityTypeMap.put(type.getId(), type);
}

View File

@ -1,7 +1,6 @@
package electrosphere.main;
import com.google.gson.Gson;
import electrosphere.cfg.MainConfig;
import electrosphere.controls.ControlHandler;
import electrosphere.entity.CameraEntityUtils;
import electrosphere.entity.types.creature.CreatureUtils;
@ -103,10 +102,6 @@ public class Main {
//set simulation status to loading title menu
SimulationState.simulationState = SimulationStateMachine.LOADING;
//init basic config
Utilities.loadMainConfig();
//controls
initControlHandler();
@ -161,7 +156,7 @@ public class Main {
/// C L I E N T N E T W O R K I N G S T U F F
///
//Why is this its own function? Just to get the networking code out of main()
if(Globals.mainConfig.runClient && Globals.clientConnection != null){
if(Globals.RUN_CLIENT && Globals.clientConnection != null){
Globals.clientConnection.parseMessages();
}
@ -266,6 +261,7 @@ public class Main {
running = false;
if(Globals.server != null){
Globals.server.close();
Globals.serverThread.interrupt();
}
}
@ -286,8 +282,8 @@ public class Main {
public static void initControlHandler(){
// ControlHandler.generateExampleControlsMap();
Globals.controlHandler = FileLoadingUtils.loadModelObjectFromBakedJsonFile("/Config/keybinds.json",ControlHandler.class);
Globals.controlHandler = ControlHandler.generateExampleControlsMap();
// Globals.controlHandler = FileLoadingUtils.loadModelObjectFromBakedJsonFile("/Config/keybinds.json",ControlHandler.class);
}

View File

@ -22,8 +22,8 @@ public class MenuTransition {
case 0:
m.dispose();
Globals.loadingThread = new LoadingThread(LoadingThread.LOAD_MAIN_GAME);
Globals.loadingThread.setFLAG_INIT_CLIENT(true);
Globals.loadingThread.setFLAG_INIT_SERVER(true);
Globals.RUN_CLIENT = true;
Globals.RUN_SERVER = true;
Globals.loadingThread.start();
break;
//multi player
@ -35,8 +35,8 @@ public class MenuTransition {
case 2:
m.dispose();
Globals.loadingThread = new LoadingThread(LoadingThread.LOAD_ARENA);
Globals.loadingThread.setFLAG_INIT_CLIENT(true);
Globals.loadingThread.setFLAG_INIT_SERVER(true);
Globals.RUN_CLIENT = true;
Globals.RUN_SERVER = true;
Globals.loadingThread.start();
break;
//options
@ -52,8 +52,8 @@ public class MenuTransition {
case 0:
m.dispose();
Globals.loadingThread = new LoadingThread(LoadingThread.LOAD_MAIN_GAME);
Globals.loadingThread.setFLAG_INIT_CLIENT(true);
Globals.loadingThread.setFLAG_INIT_SERVER(true);
Globals.RUN_CLIENT = true;
Globals.RUN_SERVER = true;
Globals.loadingThread.start();
break;
//JOIN
@ -76,8 +76,8 @@ public class MenuTransition {
NetUtils.setPort( Integer.parseInt( ( (TextBox)m.getOptions().get(1) ).getText() ) );
m.dispose();
Globals.loadingThread = new LoadingThread(LoadingThread.LOAD_MAIN_GAME);
Globals.loadingThread.setFLAG_INIT_CLIENT(true);
Globals.loadingThread.setFLAG_INIT_SERVER(false);
Globals.RUN_CLIENT = true;
Globals.RUN_SERVER = false;
Globals.loadingThread.start();
break;
//back

View File

@ -99,7 +99,7 @@ public class ServerConnectionHandler implements Runnable {
AttachUtils.attachEntityToEntityAtBone(newPlayerCharacter, sword, "Bone.020");
//set controller id
CreatureUtils.setControllerPlayerId(newPlayerCharacter, playerID);
if(Globals.mainConfig.runServer && Main.playerId == -1){
if(Globals.RUN_SERVER && Main.playerId == -1){
Globals.playerCharacter = newPlayerCharacter;
}
//world metadata
@ -126,7 +126,7 @@ public class ServerConnectionHandler implements Runnable {
//figure out what chunk they're in
//queue messages for that chunk
if(Globals.mainConfig.runServer && Main.playerId == -1){
if(Globals.RUN_SERVER && Main.playerId == -1){
} else {
for(Entity currentEntity : Globals.entityManager.getMoveable()){

View File

@ -1,8 +1,3 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package electrosphere.renderer.light;
import org.joml.Vector3f;
@ -11,7 +6,7 @@ import org.joml.Vector3f;
*
* @author amaterasu
*/
public class DirectionalLight {
public class ItsBroken_DirectionalLight {
Vector3f direction;
Vector3f ambient;
@ -50,7 +45,7 @@ public class DirectionalLight {
return specular;
}
public DirectionalLight(Vector3f direction){
public ItsBroken_DirectionalLight(Vector3f direction){
this.direction = direction;
ambient = new Vector3f(0.05f, 0.05f, 0.05f);
diffuse = new Vector3f(0.4f, 0.4f, 0.4f);
@ -61,7 +56,7 @@ public class DirectionalLight {
specular.normalize();
}
public DirectionalLight(Vector3f direction, Vector3f color){
public ItsBroken_DirectionalLight(Vector3f direction, Vector3f color){
this.direction = direction;
ambient = new Vector3f( color.x * 0.05f, color.y * 0.05f, color.z * 0.05f);
diffuse = new Vector3f( color.x * 0.4f, color.y * 0.4f, color.z * 0.4f);

View File

@ -1,4 +1,4 @@
package electrosphere.renderer.Light;
package electrosphere.renderer.light;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;

View File

@ -1,4 +1,4 @@
package electrosphere.renderer.Light;
package electrosphere.renderer.light;
/**
*

View File

@ -65,7 +65,7 @@ public class ShaderProgram {
//
String tempForReadingShaders = "";
try {
BufferedReader br = new BufferedReader(new InputStreamReader(Main.class.getResourceAsStream(vertex_shader_path)));
BufferedReader br = new BufferedReader(new InputStreamReader(FileLoadingUtils.getAssetFileAsStream(vertex_shader_path)));
try {
StringBuilder sb = new StringBuilder();
String line = br.readLine();
@ -84,7 +84,7 @@ public class ShaderProgram {
String vertexShaderSource = tempForReadingShaders;
//This try-catch block reads the FragmentShader source into memory
try {
BufferedReader br = new BufferedReader(new InputStreamReader(Main.class.getResourceAsStream(fragment_shader_path)));
BufferedReader br = new BufferedReader(new InputStreamReader(FileLoadingUtils.getAssetFileAsStream(fragment_shader_path)));
try {
StringBuilder sb = new StringBuilder();
String line = br.readLine();
@ -178,7 +178,7 @@ public class ShaderProgram {
//
String tempForReadingShaders = "";
try {
BufferedReader br = new BufferedReader(new FileReader(Main.class.getResource("/Shaders/VertexShader.vs").getFile()));
BufferedReader br = new BufferedReader(new FileReader(FileLoadingUtils.getAssetFile("/Shaders/VertexShader.vs")));
try {
StringBuilder sb = new StringBuilder();
String line = br.readLine();
@ -197,7 +197,7 @@ public class ShaderProgram {
String vertexShaderSource = tempForReadingShaders;
//This try-catch block reads the FragmentShader source into memory
try {
BufferedReader br = new BufferedReader(new FileReader(Main.class.getResource("/Shaders/FragmentShader.fs").getFile()));
BufferedReader br = new BufferedReader(new FileReader(FileLoadingUtils.getAssetFile("/Shaders/FragmentShader.fs")));
try {
StringBuilder sb = new StringBuilder();
String line = br.readLine();
@ -282,8 +282,14 @@ public class ShaderProgram {
//
//Read in shader programs
//
String vertexShaderSource = FileLoadingUtils.readStringFromBakedFile(vertex_shader_path);
String fragmentShaderSource = FileLoadingUtils.readStringFromBakedFile(fragment_shader_path);
String vertexShaderSource = "";
String fragmentShaderSource = "";
try {
vertexShaderSource = FileLoadingUtils.getAssetFileAsString(vertex_shader_path);
fragmentShaderSource = FileLoadingUtils.getAssetFileAsString(fragment_shader_path);
} catch(IOException ex){
}
//Creates a new shader object and assigns its 'pointer' to the integer "vertexShader"
rVal.vertexShader = glCreateShader(GL_VERTEX_SHADER);
//This alerts openGL to the presence of a vertex shader and points the shader at its source

View File

@ -51,7 +51,7 @@ public class Texture {
width = 1;
height = 1;
try {
BufferedImage image_data = ImageIO.read(Main.class.getResourceAsStream(FileLoadingUtils.sanitizeBakedFilePath(path)));
BufferedImage image_data = ImageIO.read(FileLoadingUtils.getAssetFile(path));
if (
image_data.getType() == BufferedImage.TYPE_3BYTE_BGR ||
image_data.getType() == BufferedImage.TYPE_INT_RGB

View File

@ -11,6 +11,8 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
public class FileLoadingUtils {
@ -95,7 +97,16 @@ public class FileLoadingUtils {
public static String sanitizeBakedFilePath(String filePath){
// public static String sanitizeBakedFilePath(String filePath){
// String rVal = new String(filePath);
// rVal = rVal.trim();
// if(!rVal.startsWith("/")){
// rVal = "/" + rVal;
// }
// return rVal;
// }
public static String sanitizeAssetFilePath(String filePath){
String rVal = new String(filePath);
rVal = rVal.trim();
if(!rVal.startsWith("/")){
@ -104,12 +115,12 @@ public class FileLoadingUtils {
return rVal;
}
public static String readStringFromBakedFile(String bakedFilePath){
String rVal = "";
String sanitizedFilePath = sanitizeBakedFilePath(bakedFilePath);
rVal = readStreamToString(Main.class.getResourceAsStream(sanitizedFilePath));
return rVal;
}
// public static String readStringFromBakedFile(String bakedFilePath){
// String rVal = "";
// String sanitizedFilePath = sanitizeBakedFilePath(bakedFilePath);
// rVal = readStreamToString(Main.class.getResourceAsStream(sanitizedFilePath));
// return rVal;
// }
public static void serializeObjectToFilePath(String filePath, Object object){
@ -123,31 +134,63 @@ public class FileLoadingUtils {
}
}
public static <T>T loadModelObjectFromBakedJsonFile(String fileName, Class<T> className){
public static File getAssetFile(String pathName){
String sanitizedFilePath = sanitizeAssetFilePath(pathName);
File targetFile = new File("./assets" + sanitizedFilePath);
return targetFile;
}
public static InputStream getAssetFileAsStream(String pathName) throws IOException{
String sanitizedFilePath = sanitizeAssetFilePath(pathName);
File targetFile = new File("./assets" + sanitizedFilePath);
return Files.newInputStream(targetFile.toPath());
}
public static String getAssetFileAsString(String pathName) throws IOException{
String sanitizedFilePath = sanitizeAssetFilePath(pathName);
File targetFile = new File("./assets" + sanitizedFilePath);
return Files.readString(targetFile.toPath());
}
public static <T>T loadObjectFromAssetPath(String pathName, Class<T> className){
T rVal = null;
String sanitizedFilePath = sanitizeBakedFilePath(fileName);
String rawJSON = readStreamToString(Main.class.getResourceAsStream(sanitizedFilePath));
String sanitizedFilePath = sanitizeAssetFilePath(pathName);
String rawJSON = "";
try {
rawJSON = readStreamToString(Files.newInputStream(getAssetFile(sanitizedFilePath).toPath()));
} catch (IOException ex) {
ex.printStackTrace();
}
Gson gson = new Gson();
rVal = gson.fromJson(rawJSON, className);
return rVal;
}
public static File unpackBakedFileToFilePath(String bakedFilePath){
String sanitizedFilePath = sanitizeBakedFilePath(bakedFilePath);
if(!Files.exists(new File("./Models").toPath())){
try {
Files.createDirectory(new File("./Models").toPath());
} catch (IOException ex) {
ex.printStackTrace();
}
}
File targetFile = new File("." + sanitizedFilePath);
try {
Files.write(targetFile.toPath(), Main.class.getResourceAsStream(sanitizedFilePath).readAllBytes(),StandardOpenOption.CREATE,StandardOpenOption.WRITE);
} catch (IOException ex) {
ex.printStackTrace();
}
return targetFile;
}
// public static <T>T loadModelObjectFromBakedJsonFile(String fileName, Class<T> className){
// T rVal = null;
// String sanitizedFilePath = sanitizeBakedFilePath(fileName);
// String rawJSON = readStreamToString(Main.class.getResourceAsStream(sanitizedFilePath));
// Gson gson = new Gson();
// rVal = gson.fromJson(rawJSON, className);
// return rVal;
// }
//
// public static File unpackBakedFileToFilePath(String bakedFilePath){
// String sanitizedFilePath = sanitizeBakedFilePath(bakedFilePath);
// if(!Files.exists(new File("./Models").toPath())){
// try {
// Files.createDirectory(new File("./Models").toPath());
// } catch (IOException ex) {
// ex.printStackTrace();
// }
// }
// File targetFile = new File("." + sanitizedFilePath);
// try {
// Files.write(targetFile.toPath(), Main.class.getResourceAsStream(sanitizedFilePath).readAllBytes(),StandardOpenOption.CREATE,StandardOpenOption.WRITE);
// } catch (IOException ex) {
// ex.printStackTrace();
// }
// return targetFile;
// }
}

View File

@ -29,7 +29,7 @@ public class ModelLoader {
AIScene scene;
// File file = new File(Thread.currentThread().getContextClassLoader().getResource(fileName).getFile());
// Main.class.getResourceAsStream(fileName).readAllBytes();
File toRead = FileLoadingUtils.unpackBakedFileToFilePath(fileName);
File toRead = FileLoadingUtils.getAssetFile(fileName);
scene = aiImportFile(toRead.getAbsolutePath(),
aiProcess_GenSmoothNormals |
aiProcess_JoinIdenticalVertices |

View File

@ -7,7 +7,6 @@ import electrosphere.renderer.ShaderProgram;
import electrosphere.renderer.texture.Texture;
import electrosphere.renderer.texture.TextureMap;
import com.google.gson.Gson;
import electrosphere.cfg.MainConfig;
import electrosphere.main.Globals;
import electrosphere.main.Main;
import java.io.BufferedReader;
@ -104,20 +103,6 @@ public class Utilities {
}
}
public static void loadMainConfig(){
if(Main.class.getResource("/Config/localconfig.json") != null){
Globals.mainConfig = FileLoadingUtils.loadModelObjectFromBakedJsonFile("/Config/localconfig.json", MainConfig.class);
if(Globals.mainConfig.version != MainConfig.CONFIG_FILE_VERSION){
//dynamically generate config and save it
MainConfig.generateMainConfig();
}
} else {
MainConfig.generateMainConfig();
}
}
public static void saveObjectToBakedJsonFile(String fileName, Object object){
URL resourceUrl = Main.class.getResource(fileName);
File file = new File("");

View File

@ -39,7 +39,7 @@ public class TerrainViewer {
// terrainModel = terrainManager.getModel();
// Utilities.saveObjectToBakedJsonFile("/Config/testingTerrain.json", terrainModel);
terrainModel = FileLoadingUtils.loadModelObjectFromBakedJsonFile("/Config/testingTerrain.json", TerrainModel.class);
terrainModel = FileLoadingUtils.loadObjectFromAssetPath("/Config/testingTerrain.json", TerrainModel.class);
Simulation simulation = new Simulation();