fixed the properties file and loading issues
This commit is contained in:
parent
3bf2ebd06f
commit
81a4b31dc4
3 changed files with 72 additions and 29 deletions
|
|
@ -2,9 +2,7 @@ package net.halbear.Terrain4J.EngineCore.Logic;
|
||||||
|
|
||||||
import org.tinylog.Logger;
|
import org.tinylog.Logger;
|
||||||
|
|
||||||
import java.io.FileWriter;
|
import java.io.*;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
@ -15,6 +13,7 @@ public class EngineConfig {
|
||||||
private static final int DEFAULT_WIDTH = 640;
|
private static final int DEFAULT_WIDTH = 640;
|
||||||
private static final int DEFAULT_HEIGHT = 480;
|
private static final int DEFAULT_HEIGHT = 480;
|
||||||
private static final String FILENAME = "terrain4j.properties";
|
private static final String FILENAME = "terrain4j.properties";
|
||||||
|
private static String SOFTWARE_TITLE;
|
||||||
private static EngineConfig instance;
|
private static EngineConfig instance;
|
||||||
private long accuracy;
|
private long accuracy;
|
||||||
private int TickRate;
|
private int TickRate;
|
||||||
|
|
@ -31,51 +30,67 @@ public class EngineConfig {
|
||||||
|
|
||||||
|
|
||||||
private EngineConfig() {
|
private EngineConfig() {
|
||||||
var EngineConfig = new Properties();
|
var EngineConfigVar = new Properties();
|
||||||
Path path = Paths.get("");
|
Path path = Paths.get("");
|
||||||
InputStream stream = EngineConfig.class.getResourceAsStream("/" + FILENAME);
|
File ConfigFile = new File(path.toAbsolutePath().toString() + "/" + FILENAME);
|
||||||
boolean SuccessfulLoad = false;
|
boolean SuccessfulLoad = false;
|
||||||
if (stream != null) {
|
try(InputStream stream = new FileInputStream(path.toAbsolutePath().toString() + "/" + FILENAME)){
|
||||||
try {
|
try {
|
||||||
EngineConfig.load(stream);
|
|
||||||
|
EngineConfigVar.load(stream);
|
||||||
SuccessfulLoad = true;
|
SuccessfulLoad = true;
|
||||||
Logger.debug("File [{}] read", FILENAME);
|
Logger.debug("File [{}] read", FILENAME);
|
||||||
} catch (IOException excp) {
|
} catch (IOException excp) {
|
||||||
Logger.error("File [{}] not read", FILENAME, excp);
|
Logger.error("File [{}] not read", FILENAME, excp);
|
||||||
}
|
}
|
||||||
} else{
|
|
||||||
Logger.debug("FileStream for file [{}] is null, Filepath [{}] not found", FILENAME,path.toAbsolutePath().toString() + "/" + FILENAME);
|
|
||||||
|
|
||||||
}
|
|
||||||
if (SuccessfulLoad){
|
|
||||||
PhysicalDeviceName = EngineConfig.getOrDefault("PhysicalDeviceName", DEFAULT_ACCURACY).toString();
|
|
||||||
accuracy = Long.parseLong(EngineConfig.getOrDefault("frame_accuracy", DEFAULT_ACCURACY).toString());
|
|
||||||
TickRate = Integer.parseInt(EngineConfig.getOrDefault("main_tick_rate", DEFAULT_TICKRATE).toString());
|
|
||||||
Width = Integer.parseInt(EngineConfig.getOrDefault("display_width", DEFAULT_TICKRATE).toString());
|
|
||||||
Height = Integer.parseInt(EngineConfig.getOrDefault("display_height", DEFAULT_TICKRATE).toString());
|
|
||||||
VSYNC = Boolean.parseBoolean(EngineConfig.getOrDefault("vsync", false).toString());
|
|
||||||
try {
|
try {
|
||||||
assert stream != null;
|
assert stream != null;
|
||||||
stream.close();
|
stream.close();
|
||||||
} catch(IOException excp) {
|
} catch(IOException excp) {
|
||||||
Logger.error("stream unable to be closed", excp);
|
Logger.error("stream unable to be closed", excp);
|
||||||
}
|
}
|
||||||
} else{
|
} catch(IOException | NullPointerException error){
|
||||||
|
Logger.error("FileStream for file [{}] is null, Error: [{}]", ConfigFile.getAbsolutePath(),error);
|
||||||
|
}
|
||||||
|
if (!SuccessfulLoad){
|
||||||
|
InputStream NewStream = (EngineConfig.class.getResourceAsStream("terrain4j.properties"));
|
||||||
try {
|
try {
|
||||||
EngineConfig.setProperty("vkValidated", "true");
|
EngineConfigVar.load(NewStream);
|
||||||
EngineConfig.setProperty("frame_accuracy", "0");
|
SuccessfulLoad = true;
|
||||||
EngineConfig.setProperty("main_tick_rate", "120");
|
} catch (IOException error){
|
||||||
EngineConfig.setProperty("display_width", "640");
|
Logger.error("FileStream for file [{}] is null, Error: [{}]", "terrain4j.properties",error);
|
||||||
EngineConfig.setProperty("display_height", "480");
|
}
|
||||||
EngineConfig.setProperty("vsync", "false");
|
}
|
||||||
EngineConfig.store(new FileWriter(path.toAbsolutePath().toString() + "/" + FILENAME), "created new properties file");
|
if(SuccessfulLoad) {
|
||||||
|
SOFTWARE_TITLE = EngineConfigVar.getOrDefault("Software_Title", "Terrain4J").toString();
|
||||||
|
PhysicalDeviceName = EngineConfigVar.getOrDefault("PhysicalDeviceName", "").toString();
|
||||||
|
accuracy = Long.parseLong(EngineConfigVar.getOrDefault("frame_accuracy", DEFAULT_ACCURACY).toString());
|
||||||
|
TickRate = Integer.parseInt(EngineConfigVar.getOrDefault("main_tick_rate", DEFAULT_TICKRATE).toString());
|
||||||
|
Width = Integer.parseInt(EngineConfigVar.getOrDefault("display_width", "1280").toString());
|
||||||
|
Height = Integer.parseInt(EngineConfigVar.getOrDefault("display_height", "720").toString());
|
||||||
|
VSYNC = Boolean.parseBoolean(EngineConfigVar.getOrDefault("vsync", false).toString());
|
||||||
|
vkValidated = Boolean.parseBoolean(EngineConfigVar.getOrDefault("vkValidated", false).toString());
|
||||||
|
Logger.debug("\n\nsuccessfully loaded configuration: \n{}\n\n",EngineConfigVar.toString());
|
||||||
|
}
|
||||||
|
else if(!ConfigFile.exists()){
|
||||||
|
try {
|
||||||
|
EngineConfigVar.setProperty("Software_Title","Terrain4J Software");
|
||||||
|
EngineConfigVar.setProperty("PhysicalDeviceName",null);
|
||||||
|
EngineConfigVar.setProperty("frame_accuracy", String.valueOf(DEFAULT_ACCURACY));
|
||||||
|
EngineConfigVar.setProperty("main_tick_rate", String.valueOf(DEFAULT_TICKRATE));
|
||||||
|
EngineConfigVar.setProperty("display_width","1280");
|
||||||
|
EngineConfigVar.setProperty("display_height","720");
|
||||||
|
EngineConfigVar.setProperty("vsync","true");
|
||||||
|
EngineConfigVar.setProperty("vkValidated","false");
|
||||||
|
EngineConfigVar.store(new FileWriter(path.toAbsolutePath().toString() + "/" + FILENAME), "created new properties file");
|
||||||
|
Logger.debug("Wrote New Config File [{}]", ConfigFile.getAbsolutePath());
|
||||||
} catch (IOException excp2) {
|
} catch (IOException excp2) {
|
||||||
Logger.error("File [{}] not written", FILENAME, excp2);
|
Logger.error("File [{}] not written", FILENAME, excp2);
|
||||||
}
|
}
|
||||||
accuracy = DEFAULT_ACCURACY;
|
} else{
|
||||||
TickRate = DEFAULT_TICKRATE;
|
Logger.debug("Config File [{}] exists but was unable to be loaded",ConfigFile.getAbsolutePath());
|
||||||
}
|
}
|
||||||
vkValidated = Boolean.parseBoolean(EngineConfig.getOrDefault("vkValidated", false).toString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean VkValidated(){
|
public boolean VkValidated(){
|
||||||
|
|
|
||||||
18
src/main/resources/terrain4j.properties
Normal file
18
src/main/resources/terrain4j.properties
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
#created new properties file
|
||||||
|
#Tue Jan 20 08:16:32 GMT 2026
|
||||||
|
#Default Window dimensions
|
||||||
|
display_height=480
|
||||||
|
display_width=640
|
||||||
|
#the precision of frames, set this to 16000 and it will limit the whole engine to 64FPS
|
||||||
|
frame_accuracy=0
|
||||||
|
#event tick rate for game process
|
||||||
|
main_tick_rate=120
|
||||||
|
#Vulkan Debugging toggle
|
||||||
|
vkValidated=true
|
||||||
|
|
||||||
|
vsync=false
|
||||||
|
#This is the name of the GPU you want the engine to use
|
||||||
|
PhysicalDeviceName=
|
||||||
|
#Title that shows up on app window
|
||||||
|
Software_Title=Terrain4J Game Engine
|
||||||
|
|
||||||
|
|
@ -1,8 +1,18 @@
|
||||||
#created new properties file
|
#created new properties file
|
||||||
#Tue Jan 20 08:16:32 GMT 2026
|
#Tue Jan 20 08:16:32 GMT 2026
|
||||||
|
#Default Window dimensions
|
||||||
display_height=480
|
display_height=480
|
||||||
display_width=640
|
display_width=640
|
||||||
|
#the precision of frames, set this to 16000 and it will limit the whole engine to 64FPS
|
||||||
frame_accuracy=0
|
frame_accuracy=0
|
||||||
|
#event tick rate for game process
|
||||||
main_tick_rate=120
|
main_tick_rate=120
|
||||||
|
#Vulkan Debugging toggle
|
||||||
vkValidated=true
|
vkValidated=true
|
||||||
|
|
||||||
vsync=false
|
vsync=false
|
||||||
|
#This is the name of the GPU you want the engine to use
|
||||||
|
PhysicalDeviceName=
|
||||||
|
#Title that shows up on app window
|
||||||
|
Software_Title=Terrain4J Game Engine
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue