Queues started
This commit is contained in:
parent
934f949881
commit
20d0867755
3 changed files with 144 additions and 0 deletions
|
|
@ -0,0 +1,101 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Logic;
|
||||
|
||||
import org.tinylog.Logger;
|
||||
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Properties;
|
||||
|
||||
public class EngineConfig {
|
||||
private static final long DEFAULT_ACCURACY = 0;
|
||||
private static final int DEFAULT_TICKRATE = 60;
|
||||
private static final int DEFAULT_WIDTH = 640;
|
||||
private static final int DEFAULT_HEIGHT = 480;
|
||||
private static final String FILENAME = "terrain4j.properties";
|
||||
private static EngineConfig instance;
|
||||
private long accuracy;
|
||||
private int TickRate;
|
||||
private int Width;
|
||||
private int Height;
|
||||
public static int FrameRate_PRIMARYTHREAD =0;
|
||||
public static int TPS =0;
|
||||
public static int FrameRate_MAINENGINETHREAD =0;
|
||||
public static int FrameRate_RENDER =0;
|
||||
public static int RENDERFRAMES =0;
|
||||
public static boolean VSYNC = false;
|
||||
private boolean vkValidated;
|
||||
private String PhysicalDeviceName;
|
||||
|
||||
|
||||
private EngineConfig() {
|
||||
var EngineConfig = new Properties();
|
||||
Path path = Paths.get("");
|
||||
InputStream stream = EngineConfig.class.getResourceAsStream(path.toAbsolutePath().toString() + "/" + FILENAME);
|
||||
boolean SuccessfulLoad = false;
|
||||
if (stream != null) {
|
||||
try {
|
||||
EngineConfig.load(stream);
|
||||
SuccessfulLoad = true;
|
||||
} catch (IOException excp) {
|
||||
Logger.error("File [{}] not read", FILENAME, excp);
|
||||
}
|
||||
}
|
||||
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 {
|
||||
assert stream != null;
|
||||
stream.close();
|
||||
} catch(IOException excp) {
|
||||
Logger.error("stream unable to be closed", excp);
|
||||
}
|
||||
} else{
|
||||
try {
|
||||
EngineConfig.setProperty("frame_accuracy", "0");
|
||||
EngineConfig.setProperty("main_tick_rate", "60");
|
||||
EngineConfig.setProperty("display_width", "640");
|
||||
EngineConfig.setProperty("display_height", "480");
|
||||
EngineConfig.setProperty("vsync", "false");
|
||||
EngineConfig.store(new FileWriter(path.toAbsolutePath().toString() + "/" + FILENAME), "created new properties file");
|
||||
} catch (IOException excp2) {
|
||||
Logger.error("File [{}] not written", FILENAME, excp2);
|
||||
}
|
||||
accuracy = DEFAULT_ACCURACY;
|
||||
TickRate = DEFAULT_TICKRATE;
|
||||
}
|
||||
vkValidated = Boolean.parseBoolean(EngineConfig.getOrDefault("vkValidated", false).toString());
|
||||
}
|
||||
|
||||
public boolean VkValidated(){
|
||||
return vkValidated;
|
||||
}
|
||||
|
||||
public static synchronized EngineConfig getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new EngineConfig();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
public int getWidth(){
|
||||
return Width;
|
||||
}
|
||||
public int getHeight(){
|
||||
return Height;
|
||||
}
|
||||
public long getAccuracy() {
|
||||
return accuracy;
|
||||
}
|
||||
public int getTickRate() {
|
||||
return TickRate;
|
||||
}
|
||||
public String GetPhysicalDeviceName(){
|
||||
return PhysicalDeviceName;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,15 +1,36 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Logic;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DeviceLayers.Device;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DeviceLayers.PhysicalDevice;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.Surface;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.VulkanInstance;
|
||||
|
||||
public class VulkanContext {
|
||||
private final VulkanInstance Instance;
|
||||
private final Device device;
|
||||
private Surface surface;
|
||||
private final PhysicalDevice PhysDevice;
|
||||
|
||||
public VulkanContext(){
|
||||
var EngineGlobals = EngineConfig.getInstance();
|
||||
Instance = new VulkanInstance(EngineGlobals.VkValidated());
|
||||
PhysDevice = PhysicalDevice.createPhysicalDevice(Instance,EngineGlobals.getPhysDeviceName());
|
||||
|
||||
}
|
||||
|
||||
public void cleanup(){
|
||||
surface.cleanup(Instance);
|
||||
device.cleanup();
|
||||
PhysDevice.cleanup();
|
||||
Instance.cleanup();
|
||||
}
|
||||
public Device GetDevice(){
|
||||
return device;
|
||||
}
|
||||
public PhysicalDevice GetPhysicalDevice(){
|
||||
return PhysDevice;
|
||||
}
|
||||
public Surface GetSurface(){
|
||||
return surface;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,26 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Vulkan.Structure;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.VulkanContext;
|
||||
import org.lwjgl.PointerBuffer;
|
||||
import org.lwjgl.system.MemoryStack;
|
||||
import org.lwjgl.vulkan.VkQueue;
|
||||
import org.tinylog.Logger;
|
||||
|
||||
import static org.lwjgl.vulkan.VK13.*;
|
||||
|
||||
public class Queue {
|
||||
private final int QueueFamilyIndex;
|
||||
private final VkQueue VulkanQueue;
|
||||
|
||||
public Queue(VulkanContext vkContext, int QueueFamilyIndex, int QueueIndex){
|
||||
Logger.debug("Vulkan: Creating A Queue");
|
||||
|
||||
this.QueueFamilyIndex = QueueFamilyIndex;
|
||||
try(var MemStack = MemoryStack.stackPush()){
|
||||
PointerBuffer QueuePointer = MemStack.mallocPointer(1);
|
||||
vkGetDeviceQueue(vkContext.GetDevice().FetchVulkanDevice(), QueueFamilyIndex, QueueIndex, QueuePointer);
|
||||
long Queue = QueuePointer.get(0);
|
||||
VulkanQueue = new VkQueue(Queue, vkContext.GetDevice().FetchVulkanDevice());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue