call me a millionaire because i've got 1456477fps
This commit is contained in:
parent
81a4b31dc4
commit
44845f781d
10 changed files with 42 additions and 21 deletions
|
|
@ -6,9 +6,9 @@ import org.tinylog.Logger;
|
|||
|
||||
public class Init {
|
||||
public static void main(String[] args){
|
||||
Logger.info("Launching Software");
|
||||
Logger.info("\nLaunching New Terrain4J Powered Software!");
|
||||
var GameEngine = new PrimaryRuntime("Terrain4J", new GameCore());
|
||||
Logger.info("Launched Engine");
|
||||
Logger.info("Launched Terrain4J Engine");
|
||||
GameEngine.run();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import net.halbear.Terrain4J.EngineCore.Input.MouseListener;
|
|||
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
|
||||
import org.lwjgl.glfw.GLFWVidMode;
|
||||
import org.lwjgl.system.MemoryUtil;
|
||||
import org.tinylog.Logger;
|
||||
|
||||
import static org.lwjgl.glfw.Callbacks.glfwFreeCallbacks;
|
||||
import static org.lwjgl.glfw.GLFW.*;
|
||||
|
|
@ -16,7 +17,7 @@ public class Window {
|
|||
private final MouseListener mouseInput;
|
||||
private int height;
|
||||
private int width;
|
||||
private boolean displayFPS = true;
|
||||
private boolean displayFPS = false;
|
||||
|
||||
public Window(String title){
|
||||
if (!glfwInit()) {
|
||||
|
|
@ -69,15 +70,18 @@ public class Window {
|
|||
return mouseInput;
|
||||
}
|
||||
public void pollEvents() {
|
||||
if (displayFPS) glfwSetWindowTitle(handle, "Terrain 4J Engine - FPS: " + EngineConfig.FrameRate_PRIMARYTHREAD + " TPS: " + EngineConfig.TPS + " RenderFPS: " + EngineConfig.FrameRate_RENDER + " VSYNC: " + EngineConfig.VSYNC);
|
||||
if (keyboardInput.keySinglePress(GLFW_KEY_V)) {
|
||||
SetVsync();
|
||||
}
|
||||
keyboardInput.input();
|
||||
mouseInput.input();
|
||||
EngineConfig.RENDERFRAMES++;
|
||||
}
|
||||
public void UpdateWindowTitle(){
|
||||
if (displayFPS) glfwSetWindowTitle(handle, EngineConfig.SOFTWARE_TITLE + " - FPS: " + EngineConfig.FrameRate_PRIMARYTHREAD + " TPS: " + EngineConfig.TPS + " RenderFPS: " + EngineConfig.FrameRate_RENDER + " VSYNC: " + EngineConfig.VSYNC);
|
||||
}
|
||||
public void SetVsync(){
|
||||
Logger.info("Vsync Swap");
|
||||
if (EngineConfig.VSYNC) {
|
||||
glfwSwapInterval(0);
|
||||
EngineConfig.VSYNC = false;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Logic;
|
||||
|
||||
import org.tinylog.Logger;
|
||||
import org.tinylog.core.TinylogLoggingConfiguration;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.Path;
|
||||
|
|
@ -13,7 +14,7 @@ public class EngineConfig {
|
|||
private static final int DEFAULT_WIDTH = 640;
|
||||
private static final int DEFAULT_HEIGHT = 480;
|
||||
private static final String FILENAME = "terrain4j.properties";
|
||||
private static String SOFTWARE_TITLE;
|
||||
public static String SOFTWARE_TITLE;
|
||||
private static EngineConfig instance;
|
||||
private long accuracy;
|
||||
private int TickRate;
|
||||
|
|
@ -44,7 +45,6 @@ public class EngineConfig {
|
|||
Logger.error("File [{}] not read", FILENAME, excp);
|
||||
}
|
||||
try {
|
||||
assert stream != null;
|
||||
stream.close();
|
||||
} catch(IOException excp) {
|
||||
Logger.error("stream unable to be closed", excp);
|
||||
|
|
@ -53,12 +53,18 @@ public class EngineConfig {
|
|||
Logger.error("FileStream for file [{}] is null, Error: [{}]", ConfigFile.getAbsolutePath(),error);
|
||||
}
|
||||
if (!SuccessfulLoad){
|
||||
InputStream NewStream = (EngineConfig.class.getResourceAsStream("terrain4j.properties"));
|
||||
InputStream NewStream = (EngineConfig.class.getResourceAsStream("DefaultEngineConfig.properties"));
|
||||
try {
|
||||
EngineConfigVar.load(NewStream);
|
||||
SuccessfulLoad = true;
|
||||
} catch (IOException error){
|
||||
Logger.error("FileStream for file [{}] is null, Error: [{}]", "terrain4j.properties",error);
|
||||
Logger.error("FileStream for file [{}] is null", "DefaultEngineConfig.properties",error);
|
||||
}
|
||||
try {
|
||||
assert NewStream != null;
|
||||
NewStream.close();
|
||||
} catch (IOException error){
|
||||
Logger.error("FileStream Failed to close",error);
|
||||
}
|
||||
}
|
||||
if(SuccessfulLoad) {
|
||||
|
|
@ -87,10 +93,9 @@ public class EngineConfig {
|
|||
} catch (IOException excp2) {
|
||||
Logger.error("File [{}] not written", FILENAME, excp2);
|
||||
}
|
||||
} else{
|
||||
Logger.debug("Config File [{}] exists but was unable to be loaded",ConfigFile.getAbsolutePath());
|
||||
} else {
|
||||
Logger.debug("Config File [{}] exists but was unable to be loaded", ConfigFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean VkValidated(){
|
||||
|
|
@ -99,6 +104,7 @@ public class EngineConfig {
|
|||
|
||||
public static synchronized EngineConfig getInstance() {
|
||||
if (instance == null) {
|
||||
|
||||
instance = new EngineConfig();
|
||||
}
|
||||
return instance;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,6 @@ package net.halbear.Terrain4J.EngineCore.Logic;
|
|||
public interface GameLogic {
|
||||
void cleanup();
|
||||
void Initialise(EngineInstance engineInstance);
|
||||
void Input(EngineInstance engineInstance, long diffMS);
|
||||
void Update(EngineInstance engineInstance, long diffMS);
|
||||
void Input(EngineInstance engineInstance, long FrameDiffNanoSeconds);
|
||||
void Update(EngineInstance engineInstance, long FrameDiffNanoSeconds);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,12 +15,12 @@ public class GameCore implements GameLogic {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void Input(EngineInstance engineInstance, long diffMS) {
|
||||
public void Input(EngineInstance engineInstance, long FrameDiffNanoSeconds) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Update(EngineInstance engineInstance, long diffMS) {
|
||||
public void Update(EngineInstance engineInstance, long FrameDiffNanoSeconds) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import net.halbear.Terrain4J.EngineCore.Display.Window;
|
|||
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineInstance;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.GameLogic;
|
||||
import org.tinylog.Logger;
|
||||
|
||||
public class PrimaryRuntime {
|
||||
private final EngineInstance engineInstance;
|
||||
|
|
@ -13,6 +14,7 @@ public class PrimaryRuntime {
|
|||
private Window window;
|
||||
private int Frames = 0;
|
||||
private int TickFrames = 0;
|
||||
private double TickRate = 0;
|
||||
|
||||
public PrimaryRuntime(String windowTitle, GameLogic appLogic) {
|
||||
this.gameLogic = appLogic;
|
||||
|
|
@ -29,6 +31,9 @@ public class PrimaryRuntime {
|
|||
public EngineInstance getEngineInstance() {
|
||||
return engineInstance;
|
||||
}
|
||||
public void UpdateTickRate(){
|
||||
TickRate = (double) 1000000000 / (double) EngineConfig.getInstance().getTickRate();
|
||||
}
|
||||
public void run(){
|
||||
long InitialTime = System.nanoTime();
|
||||
long updateTime = InitialTime;
|
||||
|
|
@ -36,6 +41,7 @@ public class PrimaryRuntime {
|
|||
double TickDiff =0;
|
||||
double SecondCounter =0;
|
||||
double tickDiff = 0;
|
||||
TickRate = (double) 1000000000 / (double) EngineConfig.getInstance().getTickRate();
|
||||
while (!window.shouldClose()){
|
||||
long now = System.nanoTime();
|
||||
tickDiff = now - InitialTime;
|
||||
|
|
@ -44,24 +50,24 @@ public class PrimaryRuntime {
|
|||
SecondCounter += tickDiff;
|
||||
if (FrameDiff >= EngineConfig.getInstance().getAccuracy()){
|
||||
window.pollEvents();
|
||||
gameLogic.Input(engineInstance, (now - InitialTime)/ 1000000);
|
||||
gameLogic.Input(engineInstance, (now - InitialTime));
|
||||
Frames++;
|
||||
if (TickDiff/1000 >= (double) 1000000 / (double) EngineConfig.getInstance().getTickRate()) {
|
||||
if (TickDiff >= TickRate) {
|
||||
TickFrames++;
|
||||
long nsTimeDiff = now - updateTime;
|
||||
gameLogic.Update(engineInstance, nsTimeDiff / 1000000);
|
||||
gameLogic.Update(engineInstance, nsTimeDiff);
|
||||
updateTime = now;
|
||||
TickDiff = 0;
|
||||
}
|
||||
if (SecondCounter >= 1000000000){
|
||||
SecondCounter = 0;
|
||||
//System.out.println("FPS: " + Frames + " Ticks: " + TickFrames);
|
||||
EngineConfig.FrameRate_PRIMARYTHREAD = Frames;
|
||||
EngineConfig.FrameRate_RENDER = EngineConfig.RENDERFRAMES;
|
||||
EngineConfig.TPS = TickFrames;
|
||||
Frames = 0;
|
||||
TickFrames = 0;
|
||||
EngineConfig.RENDERFRAMES = 0;
|
||||
Logger.info("FPS: " + EngineConfig.FrameRate_PRIMARYTHREAD + " TPS: " + EngineConfig.TPS + " RenderFPS: " + EngineConfig.FrameRate_RENDER);
|
||||
}
|
||||
render.render(engineInstance);
|
||||
FrameDiff = 0;
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ public class Device {
|
|||
VkExtensionProperties Properties = PropertiesBuffer.get(i);
|
||||
String ExtensionName = Properties.extensionNameString();
|
||||
DeviceExtensions.add(ExtensionName);
|
||||
Logger.trace("[{}] is a supported extension", ExtensionCount);
|
||||
Logger.trace("[{}] is a supported extension", ExtensionName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
5
src/main/resources/tinylog.properties
Normal file
5
src/main/resources/tinylog.properties
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
writer = file
|
||||
writer.file = LastSession.t4jlog
|
||||
writer.format = {date: DD:MM:YYYY} {date: HH:mm:ss.SSS} {level}: {message}
|
||||
writer.level = trace
|
||||
writingthread = true
|
||||
|
|
@ -10,7 +10,7 @@ main_tick_rate=120
|
|||
#Vulkan Debugging toggle
|
||||
vkValidated=true
|
||||
|
||||
vsync=false
|
||||
vsync=true
|
||||
#This is the name of the GPU you want the engine to use
|
||||
PhysicalDeviceName=
|
||||
#Title that shows up on app window
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue