Overhaul build process + launcher + file loading
4
.gitignore
vendored
@ -9,7 +9,9 @@
|
|||||||
/Models
|
/Models
|
||||||
/Models/**.*
|
/Models/**.*
|
||||||
|
|
||||||
/launcher/src/main.exe
|
/build
|
||||||
|
|
||||||
|
/launcher/launcher.exe
|
||||||
|
|
||||||
/Telephone-*.jar
|
/Telephone-*.jar
|
||||||
/hs_err_pid*
|
/hs_err_pid*
|
||||||
|
|||||||
1
assets/Config/keybinds.json
Normal 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}}
|
||||||
1
assets/Config/terrain.json
Normal file
|
Before Width: | Height: | Size: 937 KiB After Width: | Height: | Size: 937 KiB |
|
Before Width: | Height: | Size: 192 KiB After Width: | Height: | Size: 192 KiB |
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 21 KiB |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 44 KiB |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 137 B After Width: | Height: | Size: 137 B |
|
Before Width: | Height: | Size: 967 B After Width: | Height: | Size: 967 B |
|
Before Width: | Height: | Size: 967 B After Width: | Height: | Size: 967 B |
|
Before Width: | Height: | Size: 3.6 KiB After Width: | Height: | Size: 3.6 KiB |
|
Before Width: | Height: | Size: 70 KiB After Width: | Height: | Size: 70 KiB |
|
Before Width: | Height: | Size: 195 B After Width: | Height: | Size: 195 B |
|
Before Width: | Height: | Size: 233 B After Width: | Height: | Size: 233 B |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 165 B After Width: | Height: | Size: 165 B |
12
build.sh
Normal 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
@ -0,0 +1,5 @@
|
|||||||
|
build: ./src/main.c
|
||||||
|
gcc ./src/main.c -o launcher
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm ./launcher.exe
|
||||||
@ -25,7 +25,7 @@ int main(){
|
|||||||
//get jar location
|
//get jar location
|
||||||
char jarPath[MAX_PATH_SIZE + 50];
|
char jarPath[MAX_PATH_SIZE + 50];
|
||||||
strcpy(jarPath,currentWorkingDirectory);
|
strcpy(jarPath,currentWorkingDirectory);
|
||||||
strcat(jarPath,"\\Renderer.jar");
|
strcat(jarPath,"\\engine.jar");
|
||||||
logVar("javaPath: ",javaPath);
|
logVar("javaPath: ",javaPath);
|
||||||
logVar("jarPath: ",jarPath);
|
logVar("jarPath: ",jarPath);
|
||||||
printf("%s\n",jarPath);
|
printf("%s\n",jarPath);
|
||||||
|
|||||||
@ -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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -89,7 +89,7 @@ public class ControlHandler {
|
|||||||
controlsState = new HashMap();
|
controlsState = new HashMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void generateExampleControlsMap(){
|
public static ControlHandler generateExampleControlsMap(){
|
||||||
ControlHandler handler = new ControlHandler();
|
ControlHandler handler = new ControlHandler();
|
||||||
/*
|
/*
|
||||||
Main Game controls
|
Main Game controls
|
||||||
@ -172,7 +172,12 @@ public class ControlHandler {
|
|||||||
/*
|
/*
|
||||||
Save to file
|
Save to file
|
||||||
*/
|
*/
|
||||||
Utilities.saveObjectToBakedJsonFile("/Config/keybinds.json", handler);
|
// Utilities.saveObjectToBakedJsonFile("/Config/keybinds.json", handler);
|
||||||
|
|
||||||
|
/*
|
||||||
|
return
|
||||||
|
*/
|
||||||
|
return handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -78,7 +78,7 @@ public class MovementTree {
|
|||||||
switch(message.getMessageSubtype()){
|
switch(message.getMessageSubtype()){
|
||||||
case MOVE:
|
case MOVE:
|
||||||
position.set(message.getpositionX(), message.getpositionY(), message.getpositionZ());
|
position.set(message.getpositionX(), message.getpositionY(), message.getpositionZ());
|
||||||
if(Globals.mainConfig.runServer){
|
if(Globals.RUN_SERVER){
|
||||||
Globals.server.broadcastMessage(
|
Globals.server.broadcastMessage(
|
||||||
EntityMessage.constructMoveMessage(
|
EntityMessage.constructMoveMessage(
|
||||||
parent.getId(),
|
parent.getId(),
|
||||||
|
|||||||
@ -26,6 +26,7 @@ public class ItemUtils {
|
|||||||
}
|
}
|
||||||
rVal.putData(EntityDataStrings.ITEM_IS_ITEM, true);
|
rVal.putData(EntityDataStrings.ITEM_IS_ITEM, true);
|
||||||
rVal.putData(EntityDataStrings.ITEM_TYPE, itemId);
|
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_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)));
|
rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, new Quaternionf().identity().rotateY((float)(-Math.PI/2)).rotateZ(-(float)(Math.PI/2)));
|
||||||
Globals.entityManager.registerItemEntity(rVal);
|
Globals.entityManager.registerItemEntity(rVal);
|
||||||
|
|||||||
@ -16,6 +16,7 @@ public class ClientPlayerData {
|
|||||||
public void setInitialDiscretePosition(int x, int y){
|
public void setInitialDiscretePosition(int x, int y){
|
||||||
initialDiscretePositionX = x;
|
initialDiscretePositionX = x;
|
||||||
initialDiscretePositionY = y;
|
initialDiscretePositionY = y;
|
||||||
|
System.out.println("Loaded");
|
||||||
loaded = true;
|
loaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -24,8 +24,8 @@ public class Simulation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void init(){
|
void init(){
|
||||||
CreatureTypeMap creatureTypeMap = FileLoadingUtils.loadModelObjectFromBakedJsonFile("Data/creatures.json", CreatureTypeMap.class);
|
CreatureTypeMap creatureTypeMap = FileLoadingUtils.loadObjectFromAssetPath("Data/creatures.json", CreatureTypeMap.class);
|
||||||
CivilizationMap civilizationMap = FileLoadingUtils.loadModelObjectFromBakedJsonFile("Data/civilization.json", CivilizationMap.class);
|
CivilizationMap civilizationMap = FileLoadingUtils.loadObjectFromAssetPath("Data/civilization.json", CivilizationMap.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void simulate(){
|
public void simulate(){
|
||||||
|
|||||||
@ -83,7 +83,7 @@ public class ServerTerrainManager {
|
|||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
String terrainOutRaw = gson.toJson(model);
|
String terrainOutRaw = gson.toJson(model);
|
||||||
try {
|
try {
|
||||||
Files.write(new File(Globals.mainConfig.loadTerrainLocation).toPath(), terrainOutRaw.getBytes());
|
Files.write(new File("./Config/terrain.json").toPath(), terrainOutRaw.getBytes());
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -91,7 +91,7 @@ public class ServerTerrainManager {
|
|||||||
|
|
||||||
public void load(){
|
public void load(){
|
||||||
Gson gson = new Gson();
|
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){
|
public float[][] getTerrainAtChunk(int x, int y){
|
||||||
|
|||||||
@ -41,9 +41,6 @@ public class LoadingThread extends Thread {
|
|||||||
public static final int LOAD_MAIN_GAME = 1;
|
public static final int LOAD_MAIN_GAME = 1;
|
||||||
public static final int LOAD_ARENA = 2;
|
public static final int LOAD_ARENA = 2;
|
||||||
|
|
||||||
boolean FLAG_INIT_SERVER = false;
|
|
||||||
boolean FLAG_INIT_CLIENT = false;
|
|
||||||
|
|
||||||
int threadType;
|
int threadType;
|
||||||
|
|
||||||
Semaphore lock;
|
Semaphore lock;
|
||||||
@ -89,23 +86,24 @@ public class LoadingThread extends Thread {
|
|||||||
loadingBox.setDraw(true);
|
loadingBox.setDraw(true);
|
||||||
|
|
||||||
//initialize the terrain manager (server only)
|
//initialize the terrain manager (server only)
|
||||||
if(FLAG_INIT_SERVER){
|
if(Globals.RUN_SERVER){
|
||||||
initServerGameTerrainManager();
|
initServerGameTerrainManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
System.out.println("run server: " + Globals.RUN_SERVER + " run client: " + Globals.RUN_CLIENT);
|
||||||
|
|
||||||
//init the data of the world
|
//init the data of the world
|
||||||
if(FLAG_INIT_SERVER){
|
if(Globals.RUN_SERVER){
|
||||||
initServerGameWorldData();
|
initServerGameWorldData();
|
||||||
}
|
}
|
||||||
|
|
||||||
//initialize the server thread (server only)
|
//initialize the server thread (server only)
|
||||||
if(FLAG_INIT_SERVER){
|
if(Globals.RUN_SERVER){
|
||||||
initServerThread();
|
initServerThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
//initialize the client thread (client)
|
//initialize the client thread (client)
|
||||||
if(FLAG_INIT_CLIENT){
|
if(Globals.RUN_CLIENT){
|
||||||
initClientThread();
|
initClientThread();
|
||||||
stallForClientPlayerData();
|
stallForClientPlayerData();
|
||||||
}
|
}
|
||||||
@ -117,7 +115,7 @@ public class LoadingThread extends Thread {
|
|||||||
initDynamicCellManager();
|
initDynamicCellManager();
|
||||||
|
|
||||||
//collision engine
|
//collision engine
|
||||||
initCollisionEngine(FLAG_INIT_SERVER);
|
initCollisionEngine(Globals.RUN_SERVER);
|
||||||
|
|
||||||
//initialize the basic graphical entities of the world (skybox, camera)
|
//initialize the basic graphical entities of the world (skybox, camera)
|
||||||
initWorldBaseGraphicalEntities();
|
initWorldBaseGraphicalEntities();
|
||||||
@ -163,12 +161,12 @@ public class LoadingThread extends Thread {
|
|||||||
initServerArenaTerrainManager();
|
initServerArenaTerrainManager();
|
||||||
|
|
||||||
//initialize the server thread (server only)
|
//initialize the server thread (server only)
|
||||||
if(FLAG_INIT_SERVER){
|
if(Globals.RUN_SERVER){
|
||||||
initServerThread();
|
initServerThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
//initialize the client thread (client)
|
//initialize the client thread (client)
|
||||||
if(FLAG_INIT_CLIENT){
|
if(Globals.RUN_CLIENT){
|
||||||
initClientThread();
|
initClientThread();
|
||||||
stallForClientPlayerData();
|
stallForClientPlayerData();
|
||||||
}
|
}
|
||||||
@ -180,7 +178,7 @@ public class LoadingThread extends Thread {
|
|||||||
initDynamicCellManager();
|
initDynamicCellManager();
|
||||||
|
|
||||||
//collision engine
|
//collision engine
|
||||||
initCollisionEngine(FLAG_INIT_SERVER);
|
initCollisionEngine(Globals.RUN_SERVER);
|
||||||
|
|
||||||
//initialize the basic graphical entities of the world (skybox, camera)
|
//initialize the basic graphical entities of the world (skybox, camera)
|
||||||
initWorldBaseGraphicalEntities();
|
initWorldBaseGraphicalEntities();
|
||||||
@ -237,8 +235,8 @@ public class LoadingThread extends Thread {
|
|||||||
*/
|
*/
|
||||||
float[][] elevation;
|
float[][] elevation;
|
||||||
Globals.serverTerrainManager = new ServerTerrainManager(2000,200,100,0.25f,0);
|
Globals.serverTerrainManager = new ServerTerrainManager(2000,200,100,0.25f,0);
|
||||||
if(Globals.mainConfig.runServer){
|
if(Globals.RUN_SERVER){
|
||||||
if(Globals.mainConfig.loadTerrain){
|
if(Globals.LOAD_TERRAIN){
|
||||||
Globals.serverTerrainManager.load();
|
Globals.serverTerrainManager.load();
|
||||||
} else {
|
} else {
|
||||||
Globals.serverTerrainManager.generate();
|
Globals.serverTerrainManager.generate();
|
||||||
@ -313,11 +311,10 @@ public class LoadingThread extends Thread {
|
|||||||
|
|
||||||
static void initServerThread(){
|
static void initServerThread(){
|
||||||
//start server networking
|
//start server networking
|
||||||
Thread serverThread = null;
|
if(Globals.RUN_SERVER){
|
||||||
if(Globals.mainConfig.runServer){
|
|
||||||
Globals.server = new Server(NetUtils.getPort());
|
Globals.server = new Server(NetUtils.getPort());
|
||||||
serverThread = new Thread(Globals.server);
|
Globals.serverThread = new Thread(Globals.server);
|
||||||
serverThread.start();
|
Globals.serverThread.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -326,7 +323,7 @@ public class LoadingThread extends Thread {
|
|||||||
static void initClientThread(){
|
static void initClientThread(){
|
||||||
//start client networking
|
//start client networking
|
||||||
Thread clientThread = null;
|
Thread clientThread = null;
|
||||||
if(Globals.mainConfig.runClient){
|
if(Globals.RUN_CLIENT){
|
||||||
Globals.clientConnection = new ClientNetworking(NetUtils.getAddress(),NetUtils.getPort());
|
Globals.clientConnection = new ClientNetworking(NetUtils.getAddress(),NetUtils.getPort());
|
||||||
clientThread = new Thread(Globals.clientConnection);
|
clientThread = new Thread(Globals.clientConnection);
|
||||||
clientThread.start();
|
clientThread.start();
|
||||||
@ -458,16 +455,4 @@ public class LoadingThread extends Thread {
|
|||||||
EntityUtils.getEntityPosition(testHomie).set(2,0,2);
|
EntityUtils.getEntityPosition(testHomie).set(2,0,2);
|
||||||
AttachUtils.attachEntityToEntityAtBone(testHomie, sword, "Bone.020");
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,5 @@
|
|||||||
package electrosphere.main;
|
package electrosphere.main;
|
||||||
|
|
||||||
import electrosphere.renderer.Camera;
|
|
||||||
import electrosphere.renderer.light.DirectionalLight;
|
|
||||||
import electrosphere.renderer.light.PointLight;
|
import electrosphere.renderer.light.PointLight;
|
||||||
import electrosphere.renderer.light.SpotLight;
|
import electrosphere.renderer.light.SpotLight;
|
||||||
import electrosphere.renderer.Material;
|
import electrosphere.renderer.Material;
|
||||||
@ -9,7 +7,6 @@ import electrosphere.renderer.Model;
|
|||||||
import electrosphere.renderer.texture.Texture;
|
import electrosphere.renderer.texture.Texture;
|
||||||
import electrosphere.renderer.texture.TextureMap;
|
import electrosphere.renderer.texture.TextureMap;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import electrosphere.cfg.MainConfig;
|
|
||||||
import electrosphere.controls.ControlHandler;
|
import electrosphere.controls.ControlHandler;
|
||||||
import electrosphere.entity.Entity;
|
import electrosphere.entity.Entity;
|
||||||
import electrosphere.entity.EntityManager;
|
import electrosphere.entity.EntityManager;
|
||||||
@ -60,12 +57,7 @@ import org.lwjgl.glfw.GLFWErrorCallback;
|
|||||||
* @author amaterasu
|
* @author amaterasu
|
||||||
*/
|
*/
|
||||||
public class Globals {
|
public class Globals {
|
||||||
|
|
||||||
//
|
|
||||||
//Config
|
|
||||||
//
|
|
||||||
public static MainConfig mainConfig;
|
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
//Rendering Engine
|
//Rendering Engine
|
||||||
@ -77,11 +69,14 @@ public class Globals {
|
|||||||
//Client connection to server
|
//Client connection to server
|
||||||
//
|
//
|
||||||
public static ClientNetworking clientConnection;
|
public static ClientNetworking clientConnection;
|
||||||
|
public static boolean RUN_CLIENT = true;
|
||||||
|
|
||||||
//
|
//
|
||||||
//Server manager thing
|
//Server manager thing
|
||||||
//
|
//
|
||||||
|
public static Thread serverThread;
|
||||||
public static Server server;
|
public static Server server;
|
||||||
|
public static boolean RUN_SERVER = true;
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -148,7 +143,6 @@ public class Globals {
|
|||||||
|
|
||||||
public static Texture blackTexture;
|
public static Texture blackTexture;
|
||||||
|
|
||||||
public static DirectionalLight lightDirectionalDefault;
|
|
||||||
public static ArrayList<PointLight> lightPointListDefault;
|
public static ArrayList<PointLight> lightPointListDefault;
|
||||||
public static SpotLight lightSpotDefault;
|
public static SpotLight lightSpotDefault;
|
||||||
|
|
||||||
@ -168,6 +162,7 @@ public class Globals {
|
|||||||
public static EntityManager entityManager;
|
public static EntityManager entityManager;
|
||||||
|
|
||||||
//terrain manager
|
//terrain manager
|
||||||
|
public static boolean LOAD_TERRAIN = true;
|
||||||
public static ServerTerrainManager serverTerrainManager;
|
public static ServerTerrainManager serverTerrainManager;
|
||||||
public static Vector3f spawnPoint = new Vector3f(1000,0,1000);
|
public static Vector3f spawnPoint = new Vector3f(1000,0,1000);
|
||||||
|
|
||||||
@ -237,7 +232,7 @@ public class Globals {
|
|||||||
// try {
|
// try {
|
||||||
//deserializes the texture map from its default path using gson
|
//deserializes the texture map from its default path using gson
|
||||||
//also done in one line
|
//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 :)
|
// 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:
|
// } catch (IOException ex) { ex.printStackTrace(); } //TODO: handle better :tm:
|
||||||
//entity type map
|
//entity type map
|
||||||
@ -265,9 +260,8 @@ public class Globals {
|
|||||||
materialDefault.set_diffuse(textureDiffuseDefault);
|
materialDefault.set_diffuse(textureDiffuseDefault);
|
||||||
materialDefault.set_specular(textureSpecularDefault);
|
materialDefault.set_specular(textureSpecularDefault);
|
||||||
//create default lights
|
//create default lights
|
||||||
lightDirectionalDefault = new DirectionalLight(new Vector3f(0,-1f,0));
|
|
||||||
assetManager.registerModelToSpecificString(ModelUtils.createBitmapDisplay(), AssetDataStrings.ASSET_STRING_BITMAP_FONT);
|
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);
|
FontUtils.setFontDataMap(fontMap);
|
||||||
//black texture for backgrouns
|
//black texture for backgrouns
|
||||||
blackTexture = new Texture("Textures/b1.png");
|
blackTexture = new Texture("Textures/b1.png");
|
||||||
@ -286,7 +280,7 @@ public class Globals {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void initEntityTypeMap(){
|
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()){
|
for(CreatureType type : typeList.getTypes()){
|
||||||
entityTypeMap.put(type.getId(), type);
|
entityTypeMap.put(type.getId(), type);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package electrosphere.main;
|
package electrosphere.main;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import electrosphere.cfg.MainConfig;
|
|
||||||
import electrosphere.controls.ControlHandler;
|
import electrosphere.controls.ControlHandler;
|
||||||
import electrosphere.entity.CameraEntityUtils;
|
import electrosphere.entity.CameraEntityUtils;
|
||||||
import electrosphere.entity.types.creature.CreatureUtils;
|
import electrosphere.entity.types.creature.CreatureUtils;
|
||||||
@ -103,10 +102,6 @@ public class Main {
|
|||||||
//set simulation status to loading title menu
|
//set simulation status to loading title menu
|
||||||
SimulationState.simulationState = SimulationStateMachine.LOADING;
|
SimulationState.simulationState = SimulationStateMachine.LOADING;
|
||||||
|
|
||||||
|
|
||||||
//init basic config
|
|
||||||
Utilities.loadMainConfig();
|
|
||||||
|
|
||||||
//controls
|
//controls
|
||||||
initControlHandler();
|
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
|
/// 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()
|
//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();
|
Globals.clientConnection.parseMessages();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,6 +261,7 @@ public class Main {
|
|||||||
running = false;
|
running = false;
|
||||||
if(Globals.server != null){
|
if(Globals.server != null){
|
||||||
Globals.server.close();
|
Globals.server.close();
|
||||||
|
Globals.serverThread.interrupt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -286,8 +282,8 @@ public class Main {
|
|||||||
|
|
||||||
|
|
||||||
public static void initControlHandler(){
|
public static void initControlHandler(){
|
||||||
// ControlHandler.generateExampleControlsMap();
|
Globals.controlHandler = ControlHandler.generateExampleControlsMap();
|
||||||
Globals.controlHandler = FileLoadingUtils.loadModelObjectFromBakedJsonFile("/Config/keybinds.json",ControlHandler.class);
|
// Globals.controlHandler = FileLoadingUtils.loadModelObjectFromBakedJsonFile("/Config/keybinds.json",ControlHandler.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -22,8 +22,8 @@ public class MenuTransition {
|
|||||||
case 0:
|
case 0:
|
||||||
m.dispose();
|
m.dispose();
|
||||||
Globals.loadingThread = new LoadingThread(LoadingThread.LOAD_MAIN_GAME);
|
Globals.loadingThread = new LoadingThread(LoadingThread.LOAD_MAIN_GAME);
|
||||||
Globals.loadingThread.setFLAG_INIT_CLIENT(true);
|
Globals.RUN_CLIENT = true;
|
||||||
Globals.loadingThread.setFLAG_INIT_SERVER(true);
|
Globals.RUN_SERVER = true;
|
||||||
Globals.loadingThread.start();
|
Globals.loadingThread.start();
|
||||||
break;
|
break;
|
||||||
//multi player
|
//multi player
|
||||||
@ -35,8 +35,8 @@ public class MenuTransition {
|
|||||||
case 2:
|
case 2:
|
||||||
m.dispose();
|
m.dispose();
|
||||||
Globals.loadingThread = new LoadingThread(LoadingThread.LOAD_ARENA);
|
Globals.loadingThread = new LoadingThread(LoadingThread.LOAD_ARENA);
|
||||||
Globals.loadingThread.setFLAG_INIT_CLIENT(true);
|
Globals.RUN_CLIENT = true;
|
||||||
Globals.loadingThread.setFLAG_INIT_SERVER(true);
|
Globals.RUN_SERVER = true;
|
||||||
Globals.loadingThread.start();
|
Globals.loadingThread.start();
|
||||||
break;
|
break;
|
||||||
//options
|
//options
|
||||||
@ -52,8 +52,8 @@ public class MenuTransition {
|
|||||||
case 0:
|
case 0:
|
||||||
m.dispose();
|
m.dispose();
|
||||||
Globals.loadingThread = new LoadingThread(LoadingThread.LOAD_MAIN_GAME);
|
Globals.loadingThread = new LoadingThread(LoadingThread.LOAD_MAIN_GAME);
|
||||||
Globals.loadingThread.setFLAG_INIT_CLIENT(true);
|
Globals.RUN_CLIENT = true;
|
||||||
Globals.loadingThread.setFLAG_INIT_SERVER(true);
|
Globals.RUN_SERVER = true;
|
||||||
Globals.loadingThread.start();
|
Globals.loadingThread.start();
|
||||||
break;
|
break;
|
||||||
//JOIN
|
//JOIN
|
||||||
@ -76,8 +76,8 @@ public class MenuTransition {
|
|||||||
NetUtils.setPort( Integer.parseInt( ( (TextBox)m.getOptions().get(1) ).getText() ) );
|
NetUtils.setPort( Integer.parseInt( ( (TextBox)m.getOptions().get(1) ).getText() ) );
|
||||||
m.dispose();
|
m.dispose();
|
||||||
Globals.loadingThread = new LoadingThread(LoadingThread.LOAD_MAIN_GAME);
|
Globals.loadingThread = new LoadingThread(LoadingThread.LOAD_MAIN_GAME);
|
||||||
Globals.loadingThread.setFLAG_INIT_CLIENT(true);
|
Globals.RUN_CLIENT = true;
|
||||||
Globals.loadingThread.setFLAG_INIT_SERVER(false);
|
Globals.RUN_SERVER = false;
|
||||||
Globals.loadingThread.start();
|
Globals.loadingThread.start();
|
||||||
break;
|
break;
|
||||||
//back
|
//back
|
||||||
|
|||||||
@ -99,7 +99,7 @@ public class ServerConnectionHandler implements Runnable {
|
|||||||
AttachUtils.attachEntityToEntityAtBone(newPlayerCharacter, sword, "Bone.020");
|
AttachUtils.attachEntityToEntityAtBone(newPlayerCharacter, sword, "Bone.020");
|
||||||
//set controller id
|
//set controller id
|
||||||
CreatureUtils.setControllerPlayerId(newPlayerCharacter, playerID);
|
CreatureUtils.setControllerPlayerId(newPlayerCharacter, playerID);
|
||||||
if(Globals.mainConfig.runServer && Main.playerId == -1){
|
if(Globals.RUN_SERVER && Main.playerId == -1){
|
||||||
Globals.playerCharacter = newPlayerCharacter;
|
Globals.playerCharacter = newPlayerCharacter;
|
||||||
}
|
}
|
||||||
//world metadata
|
//world metadata
|
||||||
@ -126,7 +126,7 @@ public class ServerConnectionHandler implements Runnable {
|
|||||||
//figure out what chunk they're in
|
//figure out what chunk they're in
|
||||||
|
|
||||||
//queue messages for that chunk
|
//queue messages for that chunk
|
||||||
if(Globals.mainConfig.runServer && Main.playerId == -1){
|
if(Globals.RUN_SERVER && Main.playerId == -1){
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
for(Entity currentEntity : Globals.entityManager.getMoveable()){
|
for(Entity currentEntity : Globals.entityManager.getMoveable()){
|
||||||
|
|||||||
@ -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;
|
package electrosphere.renderer.light;
|
||||||
|
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
@ -11,7 +6,7 @@ import org.joml.Vector3f;
|
|||||||
*
|
*
|
||||||
* @author amaterasu
|
* @author amaterasu
|
||||||
*/
|
*/
|
||||||
public class DirectionalLight {
|
public class ItsBroken_DirectionalLight {
|
||||||
Vector3f direction;
|
Vector3f direction;
|
||||||
|
|
||||||
Vector3f ambient;
|
Vector3f ambient;
|
||||||
@ -50,7 +45,7 @@ public class DirectionalLight {
|
|||||||
return specular;
|
return specular;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DirectionalLight(Vector3f direction){
|
public ItsBroken_DirectionalLight(Vector3f direction){
|
||||||
this.direction = direction;
|
this.direction = direction;
|
||||||
ambient = new Vector3f(0.05f, 0.05f, 0.05f);
|
ambient = new Vector3f(0.05f, 0.05f, 0.05f);
|
||||||
diffuse = new Vector3f(0.4f, 0.4f, 0.4f);
|
diffuse = new Vector3f(0.4f, 0.4f, 0.4f);
|
||||||
@ -61,7 +56,7 @@ public class DirectionalLight {
|
|||||||
specular.normalize();
|
specular.normalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public DirectionalLight(Vector3f direction, Vector3f color){
|
public ItsBroken_DirectionalLight(Vector3f direction, Vector3f color){
|
||||||
this.direction = direction;
|
this.direction = direction;
|
||||||
ambient = new Vector3f( color.x * 0.05f, color.y * 0.05f, color.z * 0.05f);
|
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);
|
diffuse = new Vector3f( color.x * 0.4f, color.y * 0.4f, color.z * 0.4f);
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package electrosphere.renderer.Light;
|
package electrosphere.renderer.light;
|
||||||
|
|
||||||
import electrosphere.entity.Entity;
|
import electrosphere.entity.Entity;
|
||||||
import electrosphere.entity.EntityDataStrings;
|
import electrosphere.entity.EntityDataStrings;
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
package electrosphere.renderer.Light;
|
package electrosphere.renderer.light;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
@ -65,7 +65,7 @@ public class ShaderProgram {
|
|||||||
//
|
//
|
||||||
String tempForReadingShaders = "";
|
String tempForReadingShaders = "";
|
||||||
try {
|
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 {
|
try {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
String line = br.readLine();
|
String line = br.readLine();
|
||||||
@ -84,7 +84,7 @@ public class ShaderProgram {
|
|||||||
String vertexShaderSource = tempForReadingShaders;
|
String vertexShaderSource = tempForReadingShaders;
|
||||||
//This try-catch block reads the FragmentShader source into memory
|
//This try-catch block reads the FragmentShader source into memory
|
||||||
try {
|
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 {
|
try {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
String line = br.readLine();
|
String line = br.readLine();
|
||||||
@ -178,7 +178,7 @@ public class ShaderProgram {
|
|||||||
//
|
//
|
||||||
String tempForReadingShaders = "";
|
String tempForReadingShaders = "";
|
||||||
try {
|
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 {
|
try {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
String line = br.readLine();
|
String line = br.readLine();
|
||||||
@ -197,7 +197,7 @@ public class ShaderProgram {
|
|||||||
String vertexShaderSource = tempForReadingShaders;
|
String vertexShaderSource = tempForReadingShaders;
|
||||||
//This try-catch block reads the FragmentShader source into memory
|
//This try-catch block reads the FragmentShader source into memory
|
||||||
try {
|
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 {
|
try {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
String line = br.readLine();
|
String line = br.readLine();
|
||||||
@ -282,8 +282,14 @@ public class ShaderProgram {
|
|||||||
//
|
//
|
||||||
//Read in shader programs
|
//Read in shader programs
|
||||||
//
|
//
|
||||||
String vertexShaderSource = FileLoadingUtils.readStringFromBakedFile(vertex_shader_path);
|
String vertexShaderSource = "";
|
||||||
String fragmentShaderSource = FileLoadingUtils.readStringFromBakedFile(fragment_shader_path);
|
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"
|
//Creates a new shader object and assigns its 'pointer' to the integer "vertexShader"
|
||||||
rVal.vertexShader = glCreateShader(GL_VERTEX_SHADER);
|
rVal.vertexShader = glCreateShader(GL_VERTEX_SHADER);
|
||||||
//This alerts openGL to the presence of a vertex shader and points the shader at its source
|
//This alerts openGL to the presence of a vertex shader and points the shader at its source
|
||||||
|
|||||||
@ -51,7 +51,7 @@ public class Texture {
|
|||||||
width = 1;
|
width = 1;
|
||||||
height = 1;
|
height = 1;
|
||||||
try {
|
try {
|
||||||
BufferedImage image_data = ImageIO.read(Main.class.getResourceAsStream(FileLoadingUtils.sanitizeBakedFilePath(path)));
|
BufferedImage image_data = ImageIO.read(FileLoadingUtils.getAssetFile(path));
|
||||||
if (
|
if (
|
||||||
image_data.getType() == BufferedImage.TYPE_3BYTE_BGR ||
|
image_data.getType() == BufferedImage.TYPE_3BYTE_BGR ||
|
||||||
image_data.getType() == BufferedImage.TYPE_INT_RGB
|
image_data.getType() == BufferedImage.TYPE_INT_RGB
|
||||||
|
|||||||
@ -11,6 +11,8 @@ import java.nio.file.Files;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.StandardOpenOption;
|
import java.nio.file.StandardOpenOption;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public class FileLoadingUtils {
|
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);
|
String rVal = new String(filePath);
|
||||||
rVal = rVal.trim();
|
rVal = rVal.trim();
|
||||||
if(!rVal.startsWith("/")){
|
if(!rVal.startsWith("/")){
|
||||||
@ -104,12 +115,12 @@ public class FileLoadingUtils {
|
|||||||
return rVal;
|
return rVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String readStringFromBakedFile(String bakedFilePath){
|
// public static String readStringFromBakedFile(String bakedFilePath){
|
||||||
String rVal = "";
|
// String rVal = "";
|
||||||
String sanitizedFilePath = sanitizeBakedFilePath(bakedFilePath);
|
// String sanitizedFilePath = sanitizeBakedFilePath(bakedFilePath);
|
||||||
rVal = readStreamToString(Main.class.getResourceAsStream(sanitizedFilePath));
|
// rVal = readStreamToString(Main.class.getResourceAsStream(sanitizedFilePath));
|
||||||
return rVal;
|
// return rVal;
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
public static void serializeObjectToFilePath(String filePath, Object object){
|
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;
|
T rVal = null;
|
||||||
String sanitizedFilePath = sanitizeBakedFilePath(fileName);
|
String sanitizedFilePath = sanitizeAssetFilePath(pathName);
|
||||||
String rawJSON = readStreamToString(Main.class.getResourceAsStream(sanitizedFilePath));
|
String rawJSON = "";
|
||||||
|
try {
|
||||||
|
rawJSON = readStreamToString(Files.newInputStream(getAssetFile(sanitizedFilePath).toPath()));
|
||||||
|
} catch (IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
rVal = gson.fromJson(rawJSON, className);
|
rVal = gson.fromJson(rawJSON, className);
|
||||||
return rVal;
|
return rVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static File unpackBakedFileToFilePath(String bakedFilePath){
|
// public static <T>T loadModelObjectFromBakedJsonFile(String fileName, Class<T> className){
|
||||||
String sanitizedFilePath = sanitizeBakedFilePath(bakedFilePath);
|
// T rVal = null;
|
||||||
if(!Files.exists(new File("./Models").toPath())){
|
// String sanitizedFilePath = sanitizeBakedFilePath(fileName);
|
||||||
try {
|
// String rawJSON = readStreamToString(Main.class.getResourceAsStream(sanitizedFilePath));
|
||||||
Files.createDirectory(new File("./Models").toPath());
|
// Gson gson = new Gson();
|
||||||
} catch (IOException ex) {
|
// rVal = gson.fromJson(rawJSON, className);
|
||||||
ex.printStackTrace();
|
// return rVal;
|
||||||
}
|
// }
|
||||||
}
|
//
|
||||||
File targetFile = new File("." + sanitizedFilePath);
|
// public static File unpackBakedFileToFilePath(String bakedFilePath){
|
||||||
try {
|
// String sanitizedFilePath = sanitizeBakedFilePath(bakedFilePath);
|
||||||
Files.write(targetFile.toPath(), Main.class.getResourceAsStream(sanitizedFilePath).readAllBytes(),StandardOpenOption.CREATE,StandardOpenOption.WRITE);
|
// if(!Files.exists(new File("./Models").toPath())){
|
||||||
} catch (IOException ex) {
|
// try {
|
||||||
ex.printStackTrace();
|
// Files.createDirectory(new File("./Models").toPath());
|
||||||
}
|
// } catch (IOException ex) {
|
||||||
return targetFile;
|
// 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;
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,7 +29,7 @@ public class ModelLoader {
|
|||||||
AIScene scene;
|
AIScene scene;
|
||||||
// File file = new File(Thread.currentThread().getContextClassLoader().getResource(fileName).getFile());
|
// File file = new File(Thread.currentThread().getContextClassLoader().getResource(fileName).getFile());
|
||||||
// Main.class.getResourceAsStream(fileName).readAllBytes();
|
// Main.class.getResourceAsStream(fileName).readAllBytes();
|
||||||
File toRead = FileLoadingUtils.unpackBakedFileToFilePath(fileName);
|
File toRead = FileLoadingUtils.getAssetFile(fileName);
|
||||||
scene = aiImportFile(toRead.getAbsolutePath(),
|
scene = aiImportFile(toRead.getAbsolutePath(),
|
||||||
aiProcess_GenSmoothNormals |
|
aiProcess_GenSmoothNormals |
|
||||||
aiProcess_JoinIdenticalVertices |
|
aiProcess_JoinIdenticalVertices |
|
||||||
|
|||||||
@ -7,7 +7,6 @@ import electrosphere.renderer.ShaderProgram;
|
|||||||
import electrosphere.renderer.texture.Texture;
|
import electrosphere.renderer.texture.Texture;
|
||||||
import electrosphere.renderer.texture.TextureMap;
|
import electrosphere.renderer.texture.TextureMap;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import electrosphere.cfg.MainConfig;
|
|
||||||
import electrosphere.main.Globals;
|
import electrosphere.main.Globals;
|
||||||
import electrosphere.main.Main;
|
import electrosphere.main.Main;
|
||||||
import java.io.BufferedReader;
|
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){
|
public static void saveObjectToBakedJsonFile(String fileName, Object object){
|
||||||
URL resourceUrl = Main.class.getResource(fileName);
|
URL resourceUrl = Main.class.getResource(fileName);
|
||||||
File file = new File("");
|
File file = new File("");
|
||||||
|
|||||||
@ -39,7 +39,7 @@ public class TerrainViewer {
|
|||||||
// terrainModel = terrainManager.getModel();
|
// terrainModel = terrainManager.getModel();
|
||||||
|
|
||||||
// Utilities.saveObjectToBakedJsonFile("/Config/testingTerrain.json", terrainModel);
|
// 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();
|
Simulation simulation = new Simulation();
|
||||||
|
|
||||||
|
|||||||