call me a millionaire because i've got 1456477fps

This commit is contained in:
Halbear 2026-01-21 19:37:37 +00:00
parent 81a4b31dc4
commit 44845f781d
10 changed files with 42 additions and 21 deletions

View file

@ -6,9 +6,9 @@ import org.tinylog.Logger;
public class Init { public class Init {
public static void main(String[] args){ public static void main(String[] args){
Logger.info("Launching Software"); Logger.info("\nLaunching New Terrain4J Powered Software!");
var GameEngine = new PrimaryRuntime("Terrain4J", new GameCore()); var GameEngine = new PrimaryRuntime("Terrain4J", new GameCore());
Logger.info("Launched Engine"); Logger.info("Launched Terrain4J Engine");
GameEngine.run(); GameEngine.run();
} }
} }

View file

@ -5,6 +5,7 @@ import net.halbear.Terrain4J.EngineCore.Input.MouseListener;
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig; import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
import org.lwjgl.glfw.GLFWVidMode; import org.lwjgl.glfw.GLFWVidMode;
import org.lwjgl.system.MemoryUtil; import org.lwjgl.system.MemoryUtil;
import org.tinylog.Logger;
import static org.lwjgl.glfw.Callbacks.glfwFreeCallbacks; import static org.lwjgl.glfw.Callbacks.glfwFreeCallbacks;
import static org.lwjgl.glfw.GLFW.*; import static org.lwjgl.glfw.GLFW.*;
@ -16,7 +17,7 @@ public class Window {
private final MouseListener mouseInput; private final MouseListener mouseInput;
private int height; private int height;
private int width; private int width;
private boolean displayFPS = true; private boolean displayFPS = false;
public Window(String title){ public Window(String title){
if (!glfwInit()) { if (!glfwInit()) {
@ -69,7 +70,6 @@ public class Window {
return mouseInput; return mouseInput;
} }
public void pollEvents() { 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)) { if (keyboardInput.keySinglePress(GLFW_KEY_V)) {
SetVsync(); SetVsync();
} }
@ -77,7 +77,11 @@ public class Window {
mouseInput.input(); mouseInput.input();
EngineConfig.RENDERFRAMES++; 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(){ public void SetVsync(){
Logger.info("Vsync Swap");
if (EngineConfig.VSYNC) { if (EngineConfig.VSYNC) {
glfwSwapInterval(0); glfwSwapInterval(0);
EngineConfig.VSYNC = false; EngineConfig.VSYNC = false;

View file

@ -1,6 +1,7 @@
package net.halbear.Terrain4J.EngineCore.Logic; package net.halbear.Terrain4J.EngineCore.Logic;
import org.tinylog.Logger; import org.tinylog.Logger;
import org.tinylog.core.TinylogLoggingConfiguration;
import java.io.*; import java.io.*;
import java.nio.file.Path; import java.nio.file.Path;
@ -13,7 +14,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; public static String SOFTWARE_TITLE;
private static EngineConfig instance; private static EngineConfig instance;
private long accuracy; private long accuracy;
private int TickRate; private int TickRate;
@ -44,7 +45,6 @@ public class EngineConfig {
Logger.error("File [{}] not read", FILENAME, excp); Logger.error("File [{}] not read", FILENAME, excp);
} }
try { try {
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);
@ -53,12 +53,18 @@ public class EngineConfig {
Logger.error("FileStream for file [{}] is null, Error: [{}]", ConfigFile.getAbsolutePath(),error); Logger.error("FileStream for file [{}] is null, Error: [{}]", ConfigFile.getAbsolutePath(),error);
} }
if (!SuccessfulLoad){ if (!SuccessfulLoad){
InputStream NewStream = (EngineConfig.class.getResourceAsStream("terrain4j.properties")); InputStream NewStream = (EngineConfig.class.getResourceAsStream("DefaultEngineConfig.properties"));
try { try {
EngineConfigVar.load(NewStream); EngineConfigVar.load(NewStream);
SuccessfulLoad = true; SuccessfulLoad = true;
} catch (IOException error){ } 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) { if(SuccessfulLoad) {
@ -87,10 +93,9 @@ public class EngineConfig {
} catch (IOException excp2) { } catch (IOException excp2) {
Logger.error("File [{}] not written", FILENAME, excp2); Logger.error("File [{}] not written", FILENAME, excp2);
} }
} else{ } else {
Logger.debug("Config File [{}] exists but was unable to be loaded",ConfigFile.getAbsolutePath()); Logger.debug("Config File [{}] exists but was unable to be loaded", ConfigFile.getAbsolutePath());
} }
} }
public boolean VkValidated(){ public boolean VkValidated(){
@ -99,6 +104,7 @@ public class EngineConfig {
public static synchronized EngineConfig getInstance() { public static synchronized EngineConfig getInstance() {
if (instance == null) { if (instance == null) {
instance = new EngineConfig(); instance = new EngineConfig();
} }
return instance; return instance;

View file

@ -3,6 +3,6 @@ package net.halbear.Terrain4J.EngineCore.Logic;
public interface GameLogic { public interface GameLogic {
void cleanup(); void cleanup();
void Initialise(EngineInstance engineInstance); void Initialise(EngineInstance engineInstance);
void Input(EngineInstance engineInstance, long diffMS); void Input(EngineInstance engineInstance, long FrameDiffNanoSeconds);
void Update(EngineInstance engineInstance, long diffMS); void Update(EngineInstance engineInstance, long FrameDiffNanoSeconds);
} }

View file

@ -15,12 +15,12 @@ public class GameCore implements GameLogic {
} }
@Override @Override
public void Input(EngineInstance engineInstance, long diffMS) { public void Input(EngineInstance engineInstance, long FrameDiffNanoSeconds) {
} }
@Override @Override
public void Update(EngineInstance engineInstance, long diffMS) { public void Update(EngineInstance engineInstance, long FrameDiffNanoSeconds) {
} }
} }

View file

@ -5,6 +5,7 @@ import net.halbear.Terrain4J.EngineCore.Display.Window;
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig; import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
import net.halbear.Terrain4J.EngineCore.Logic.EngineInstance; import net.halbear.Terrain4J.EngineCore.Logic.EngineInstance;
import net.halbear.Terrain4J.EngineCore.Logic.GameLogic; import net.halbear.Terrain4J.EngineCore.Logic.GameLogic;
import org.tinylog.Logger;
public class PrimaryRuntime { public class PrimaryRuntime {
private final EngineInstance engineInstance; private final EngineInstance engineInstance;
@ -13,6 +14,7 @@ public class PrimaryRuntime {
private Window window; private Window window;
private int Frames = 0; private int Frames = 0;
private int TickFrames = 0; private int TickFrames = 0;
private double TickRate = 0;
public PrimaryRuntime(String windowTitle, GameLogic appLogic) { public PrimaryRuntime(String windowTitle, GameLogic appLogic) {
this.gameLogic = appLogic; this.gameLogic = appLogic;
@ -29,6 +31,9 @@ public class PrimaryRuntime {
public EngineInstance getEngineInstance() { public EngineInstance getEngineInstance() {
return engineInstance; return engineInstance;
} }
public void UpdateTickRate(){
TickRate = (double) 1000000000 / (double) EngineConfig.getInstance().getTickRate();
}
public void run(){ public void run(){
long InitialTime = System.nanoTime(); long InitialTime = System.nanoTime();
long updateTime = InitialTime; long updateTime = InitialTime;
@ -36,6 +41,7 @@ public class PrimaryRuntime {
double TickDiff =0; double TickDiff =0;
double SecondCounter =0; double SecondCounter =0;
double tickDiff = 0; double tickDiff = 0;
TickRate = (double) 1000000000 / (double) EngineConfig.getInstance().getTickRate();
while (!window.shouldClose()){ while (!window.shouldClose()){
long now = System.nanoTime(); long now = System.nanoTime();
tickDiff = now - InitialTime; tickDiff = now - InitialTime;
@ -44,24 +50,24 @@ public class PrimaryRuntime {
SecondCounter += tickDiff; SecondCounter += tickDiff;
if (FrameDiff >= EngineConfig.getInstance().getAccuracy()){ if (FrameDiff >= EngineConfig.getInstance().getAccuracy()){
window.pollEvents(); window.pollEvents();
gameLogic.Input(engineInstance, (now - InitialTime)/ 1000000); gameLogic.Input(engineInstance, (now - InitialTime));
Frames++; Frames++;
if (TickDiff/1000 >= (double) 1000000 / (double) EngineConfig.getInstance().getTickRate()) { if (TickDiff >= TickRate) {
TickFrames++; TickFrames++;
long nsTimeDiff = now - updateTime; long nsTimeDiff = now - updateTime;
gameLogic.Update(engineInstance, nsTimeDiff / 1000000); gameLogic.Update(engineInstance, nsTimeDiff);
updateTime = now; updateTime = now;
TickDiff = 0; TickDiff = 0;
} }
if (SecondCounter >= 1000000000){ if (SecondCounter >= 1000000000){
SecondCounter = 0; SecondCounter = 0;
//System.out.println("FPS: " + Frames + " Ticks: " + TickFrames);
EngineConfig.FrameRate_PRIMARYTHREAD = Frames; EngineConfig.FrameRate_PRIMARYTHREAD = Frames;
EngineConfig.FrameRate_RENDER = EngineConfig.RENDERFRAMES; EngineConfig.FrameRate_RENDER = EngineConfig.RENDERFRAMES;
EngineConfig.TPS = TickFrames; EngineConfig.TPS = TickFrames;
Frames = 0; Frames = 0;
TickFrames = 0; TickFrames = 0;
EngineConfig.RENDERFRAMES = 0; EngineConfig.RENDERFRAMES = 0;
Logger.info("FPS: " + EngineConfig.FrameRate_PRIMARYTHREAD + " TPS: " + EngineConfig.TPS + " RenderFPS: " + EngineConfig.FrameRate_RENDER);
} }
render.render(engineInstance); render.render(engineInstance);
FrameDiff = 0; FrameDiff = 0;

View file

@ -82,7 +82,7 @@ public class Device {
VkExtensionProperties Properties = PropertiesBuffer.get(i); VkExtensionProperties Properties = PropertiesBuffer.get(i);
String ExtensionName = Properties.extensionNameString(); String ExtensionName = Properties.extensionNameString();
DeviceExtensions.add(ExtensionName); DeviceExtensions.add(ExtensionName);
Logger.trace("[{}] is a supported extension", ExtensionCount); Logger.trace("[{}] is a supported extension", ExtensionName);
} }
} }
} }

View 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

View file

@ -10,7 +10,7 @@ main_tick_rate=120
#Vulkan Debugging toggle #Vulkan Debugging toggle
vkValidated=true vkValidated=true
vsync=false vsync=true
#This is the name of the GPU you want the engine to use #This is the name of the GPU you want the engine to use
PhysicalDeviceName= PhysicalDeviceName=
#Title that shows up on app window #Title that shows up on app window