2D Sprite Renderer and sprite framework, Began additional OpenGL Renderer, started transitioning multiplayer networking to use Java NIO
This commit is contained in:
parent
5a05b9d65e
commit
3e886e5ba8
165 changed files with 4460 additions and 5485 deletions
86
build.gradle
86
build.gradle
|
|
@ -5,14 +5,10 @@ buildscript {
|
|||
mavenCentral()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.gradleup.shadow:shadow-gradle-plugin:8.3.5'
|
||||
}
|
||||
}
|
||||
plugins {
|
||||
id 'application'
|
||||
id 'java'
|
||||
id 'com.gradleup.shadow' version '8.3.5'
|
||||
}
|
||||
project.ext.lwjglVersion = "3.4.1"
|
||||
project.ext.jomlVersion = "1.10.8"
|
||||
|
|
@ -22,43 +18,20 @@ project.ext.steamworks4jVersion = "1.9.0"
|
|||
project.ext.steamworks4jserverVersion = "1.9.0"
|
||||
project.ext.imguiVersion = "1.92.0"
|
||||
|
||||
switch (OperatingSystem.current()) {
|
||||
case OperatingSystem.LINUX:
|
||||
project.ext.lwjglNatives = "natives-linux"
|
||||
def osArch = System.getProperty("os.arch")
|
||||
if (osArch.startsWith("arm") || osArch.startsWith("aarch64")) {
|
||||
project.ext.lwjglNatives += osArch.contains("64") || osArch.startsWith("armv8") ? "-arm64" : "-arm32"
|
||||
} else if (osArch.startsWith("ppc")) {
|
||||
project.ext.lwjglNatives += "-ppc64le"
|
||||
} else if (osArch.startsWith("riscv")) {
|
||||
project.ext.lwjglNatives += "-riscv64"
|
||||
}
|
||||
break
|
||||
case OperatingSystem.MAC_OS:
|
||||
project.ext.lwjglNatives = System.getProperty("os.arch").startsWith("aarch64") ? "natives-macos-arm64" : "natives-macos"
|
||||
break
|
||||
case OperatingSystem.WINDOWS:
|
||||
def osArch = System.getProperty("os.arch")
|
||||
project.ext.lwjglNatives = osArch.contains("64")
|
||||
? "natives-windows${osArch.startsWith("aarch64") ? "-arm64" : ""}"
|
||||
: "natives-windows-x86"
|
||||
break
|
||||
}
|
||||
|
||||
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
application {
|
||||
mainClass.set('net.halbear.Executable.Init')
|
||||
mainClass.set('net.halbear.Executable.Launcher')
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation platform("org.lwjgl:lwjgl-bom:$lwjglVersion")
|
||||
implementation 'org.tinylog:tinylog-api:2.7.0'
|
||||
implementation 'org.tinylog:tinylog-impl:2.7.0'
|
||||
|
||||
// Core LWJGL modules
|
||||
implementation "org.lwjgl:lwjgl"
|
||||
implementation "org.lwjgl:lwjgl-assimp"
|
||||
implementation "org.lwjgl:lwjgl-fmod"
|
||||
|
|
@ -76,22 +49,29 @@ dependencies {
|
|||
implementation "org.lwjgl:lwjgl-stb"
|
||||
implementation "org.lwjgl:lwjgl-vma"
|
||||
implementation "org.lwjgl:lwjgl-vulkan"
|
||||
implementation "org.lwjgl:lwjgl::$lwjglNatives"
|
||||
implementation "org.lwjgl:lwjgl-assimp::$lwjglNatives"
|
||||
implementation "org.lwjgl:lwjgl-freetype::$lwjglNatives"
|
||||
implementation "org.lwjgl:lwjgl-glfw::$lwjglNatives"
|
||||
implementation "org.lwjgl:lwjgl-jemalloc::$lwjglNatives"
|
||||
implementation "org.lwjgl:lwjgl-llvm::$lwjglNatives"
|
||||
implementation "org.lwjgl:lwjgl-lmdb::$lwjglNatives"
|
||||
implementation "org.lwjgl:lwjgl-meshoptimizer::$lwjglNatives"
|
||||
implementation "org.lwjgl:lwjgl-openal::$lwjglNatives"
|
||||
implementation "org.lwjgl:lwjgl-rpmalloc::$lwjglNatives"
|
||||
implementation "org.lwjgl:lwjgl-remotery:${lwjglVersion}"
|
||||
runtimeOnly "org.lwjgl:lwjgl-remotery:${lwjglVersion}:${lwjglNatives}"
|
||||
implementation "org.lwjgl:lwjgl-shaderc::$lwjglNatives"
|
||||
implementation "org.lwjgl:lwjgl-stb::$lwjglNatives"
|
||||
implementation "org.lwjgl:lwjgl-vma::$lwjglNatives"
|
||||
if (lwjglNatives == "natives-macos" || lwjglNatives == "natives-macos-arm64") implementation "org.lwjgl:lwjgl-vulkan::$lwjglNatives"
|
||||
|
||||
// Define targeted native platforms explicitly
|
||||
def targetNatives = ["natives-windows", "natives-linux"]
|
||||
|
||||
// Loop through and bundle natives for both Windows and Linux
|
||||
targetNatives.each { target ->
|
||||
runtimeOnly "org.lwjgl:lwjgl::$target"
|
||||
runtimeOnly "org.lwjgl:lwjgl-assimp::$target"
|
||||
runtimeOnly "org.lwjgl:lwjgl-freetype::$target"
|
||||
runtimeOnly "org.lwjgl:lwjgl-glfw::$target"
|
||||
runtimeOnly "org.lwjgl:lwjgl-jemalloc::$target"
|
||||
runtimeOnly "org.lwjgl:lwjgl-llvm::$target"
|
||||
runtimeOnly "org.lwjgl:lwjgl-lmdb::$target"
|
||||
runtimeOnly "org.lwjgl:lwjgl-meshoptimizer::$target"
|
||||
runtimeOnly "org.lwjgl:lwjgl-openal::$target"
|
||||
runtimeOnly "org.lwjgl:lwjgl-rpmalloc::$target"
|
||||
runtimeOnly "org.lwjgl:lwjgl-remotery:${lwjglVersion}:$target"
|
||||
runtimeOnly "org.lwjgl:lwjgl-shaderc::$target"
|
||||
runtimeOnly "org.lwjgl:lwjgl-stb::$target"
|
||||
runtimeOnly "org.lwjgl:lwjgl-vma::$target"
|
||||
}
|
||||
|
||||
implementation "org.joml:joml:${jomlVersion}"
|
||||
implementation "org.joml:joml-primitives:${jomlprimitivesVersion}"
|
||||
implementation "org.lwjglx:lwjgl3-awt:${lwjgl3awtVersion}"
|
||||
|
|
@ -99,20 +79,18 @@ dependencies {
|
|||
implementation "com.code-disaster.steamworks4j:steamworks4j-server:${steamworks4jserverVersion}"
|
||||
implementation 'com.google.code.gson:gson:2.14.0'
|
||||
implementation "org.jcommander:jcommander:3.0"
|
||||
|
||||
['', '-opengl', '-glfw'].each {
|
||||
implementation "org.lwjgl:lwjgl$it:$lwjglVersion"
|
||||
implementation "org.lwjgl:lwjgl$it::natives-windows"
|
||||
runtimeOnly "org.lwjgl:lwjgl$it::natives-windows"
|
||||
runtimeOnly "org.lwjgl:lwjgl$it::natives-linux"
|
||||
}
|
||||
|
||||
// ImGui Setup
|
||||
implementation "io.github.spair:imgui-java-binding:$imguiVersion"
|
||||
implementation "io.github.spair:imgui-java-lwjgl3:$imguiVersion"
|
||||
|
||||
implementation "io.github.spair:imgui-java-natives-windows:$imguiVersion"
|
||||
}
|
||||
|
||||
tasks.named('startShadowScripts') {
|
||||
// Dynamically override the legacy property binding with the modern provider mapping
|
||||
conventionMapping.map('mainClassName') {
|
||||
application.mainClass.get()
|
||||
}
|
||||
// ImGui Natives for both OS environments
|
||||
runtimeOnly "io.github.spair:imgui-java-natives-windows:$imguiVersion"
|
||||
runtimeOnly "io.github.spair:imgui-java-natives-linux:$imguiVersion"
|
||||
}
|
||||
2912
hs_err_pid8656.log
2912
hs_err_pid8656.log
File diff suppressed because one or more lines are too long
9
resources/EngineResources/GLShaders/scene_frag.glsl
Normal file
9
resources/EngineResources/GLShaders/scene_frag.glsl
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#version 330
|
||||
|
||||
in vec3 outColour;
|
||||
out vec4 fragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
fragColor = vec4(outColour, 1.0);
|
||||
}
|
||||
12
resources/EngineResources/GLShaders/scene_vert.glsl
Normal file
12
resources/EngineResources/GLShaders/scene_vert.glsl
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#version 330
|
||||
|
||||
layout (location=0) in vec3 position;
|
||||
layout (location=1) in vec3 colour;
|
||||
|
||||
out vec3 outColour;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(position, 1.0);
|
||||
outColour = colour;
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@ layout(location = 0) in vec2 inUV;
|
|||
|
||||
layout(location = 0) out vec4 outColor;
|
||||
layout(push_constant) uniform pc {
|
||||
layout(offset = 24) uint textureIndex;
|
||||
layout(offset = 28) uint textureIndex;
|
||||
} push_constants;
|
||||
|
||||
layout(set = 1, binding = 0) uniform sampler2D spriteTextures[MAX_TEXTURES];
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ layout(location = 0) in vec2 inUV;
|
|||
|
||||
layout(location = 0) out vec4 outColor;
|
||||
layout(push_constant) uniform pc {
|
||||
layout(offset = 24) uint textureIndex;
|
||||
layout(offset = 28) uint textureIndex;
|
||||
} push_constants;
|
||||
|
||||
layout(set = 1, binding = 0) uniform sampler2D spriteTextures[MAX_TEXTURES];
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ layout(push_constant) uniform pc {
|
|||
vec2 modelSize;
|
||||
vec2 position;
|
||||
vec2 screenSize;
|
||||
|
||||
float zAmount;
|
||||
} push_constants;
|
||||
|
||||
layout(set = 0, binding = 0) uniform ViewUniform{
|
||||
|
|
@ -22,7 +22,7 @@ layout(set = 0, binding = 0) uniform ViewUniform{
|
|||
void main() {
|
||||
vec2 ScaledPos = inPos * push_constants.modelSize;
|
||||
vec2 worldPos = push_constants.position + ScaledPos;
|
||||
worldPos += viewUniform.camPos;
|
||||
worldPos += (viewUniform.camPos * push_constants.zAmount);
|
||||
vec2 ndc = vec2(
|
||||
(worldPos.x / push_constants.screenSize.x) * 2.0 - 1.0,
|
||||
(worldPos.y / push_constants.screenSize.y) * 2.0 - 1.0
|
||||
|
|
|
|||
|
|
@ -10,8 +10,7 @@ import java.util.UUID;
|
|||
|
||||
//Halbear was here
|
||||
public class Init {
|
||||
public static void main(String[] args){
|
||||
Configuration.set("writer.file", "ClientLog" + UUID.randomUUID() +".t4jlog");
|
||||
public static void StartClient(){
|
||||
Logger.info("\nLaunching New Terrain4J Powered Software!");
|
||||
var GameEngine = new PrimaryRuntime(EngineConfig.getInstance().GetSoftwareName(), new GameCore());
|
||||
Logger.info("Launched Terrain4J Engine");
|
||||
|
|
|
|||
49
src/main/java/net/halbear/Executable/Launcher.java
Normal file
49
src/main/java/net/halbear/Executable/Launcher.java
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
package net.halbear.Executable;
|
||||
|
||||
import com.beust.jcommander.JCommander;
|
||||
import com.beust.jcommander.Parameter;
|
||||
import com.beust.jcommander.ParameterException;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Rendering.ModelCompiler;
|
||||
import org.tinylog.Logger;
|
||||
import org.tinylog.configuration.Configuration;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Launcher {
|
||||
|
||||
@Parameter(names = "-server", description = "is this a server")
|
||||
private boolean Server = false;
|
||||
public static void main(String[] args){
|
||||
var Main = new Launcher();
|
||||
var jCommander = JCommander.newBuilder().addObject(Main).build();
|
||||
try{
|
||||
jCommander.parse(args);
|
||||
Main.Launch(args);
|
||||
} catch(ParameterException exception){
|
||||
jCommander.usage();
|
||||
} catch(IOException exception){
|
||||
System.out.println("Error Starting Game:" + exception);
|
||||
}
|
||||
}
|
||||
|
||||
private static void Launch(Boolean server, String[] args){
|
||||
if(server){
|
||||
try {
|
||||
net.halbear.Executable.Server.StartServer(args);
|
||||
} catch (IOException exception){
|
||||
System.out.println("Error Starting Server:" + exception);
|
||||
}
|
||||
} else{
|
||||
Init.StartClient();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void Launch(String[] args) throws IOException{
|
||||
if(Server) Configuration.set("writer.file", "ServerLog.t4jlog");
|
||||
else Configuration.set("writer.file", "ClientLog" + UUID.randomUUID() +".t4jlog");
|
||||
Launch(EngineConfig.getInstance().GetServer(),args);
|
||||
}
|
||||
}
|
||||
|
|
@ -3,11 +3,15 @@ package net.halbear.Executable;
|
|||
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.GameCore;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.PrimaryRuntime;
|
||||
import net.halbear.Terrain4J.EngineCore.ServerNetworking.ClientSession;
|
||||
import net.halbear.Terrain4J.EngineCore.ServerNetworking.Packet;
|
||||
import net.halbear.Terrain4J.EngineCore.ServerNetworking.ServerSideNetworkUtils;
|
||||
import net.halbear.Terrain4J.EngineCore.Threads.EngineThread;
|
||||
import net.halbear.Terrain4J.EngineCore.Threads.RenderThread;
|
||||
import net.halbear.Terrain4J.EngineCore.Threads.ServerConnectionThread;
|
||||
import net.halbear.Terrain4J.EngineCore.Threads.ServerSelectorMasterThread;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.tinylog.Logger;
|
||||
import org.tinylog.configuration.Configuration;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ServerSocket;
|
||||
|
|
@ -15,14 +19,31 @@ import java.net.Socket;
|
|||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class Server {
|
||||
public static Map<UUID, ServerConnectionThread> ConnectedClients = new ConcurrentHashMap<>();
|
||||
public static Map<UUID, String> ClientNames = new ConcurrentHashMap<>();
|
||||
|
||||
private static ServerSelectorMasterThread ServerNetworker;
|
||||
|
||||
public static ServerSelectorMasterThread GetServerNetworker(){
|
||||
return ServerNetworker;
|
||||
}
|
||||
|
||||
public static final Queue<Packet> OutGoingPacketQueue = new ConcurrentLinkedQueue<>();
|
||||
public static final Queue<Packet> IncomingPacketQueue = new ConcurrentLinkedQueue<>();
|
||||
|
||||
public static void CollectIncomingPackets(){
|
||||
ClientSession.GetClientSessionInstances().forEach((uuid, client)->{
|
||||
client.CollectIncomingPackets(IncomingPacketQueue);
|
||||
});
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void LegacyCollectIncomingPackets(){
|
||||
ConnectedClients.forEach((uuid,client)->{
|
||||
client.CollectIncomingPackets(IncomingPacketQueue);
|
||||
});
|
||||
|
|
@ -31,11 +52,24 @@ public class Server {
|
|||
public static void ProcessIncomingPackets(){
|
||||
Packet packet;
|
||||
while((packet = IncomingPacketQueue.poll()) != null){
|
||||
ServerConnectionThread.ProcessClientPacket(packet);
|
||||
ServerSideNetworkUtils.ProcessClientPacket(packet);
|
||||
}
|
||||
}
|
||||
|
||||
public static void ProcessOutgoingPackets(){
|
||||
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void LegacyProcessIncomingPackets(){
|
||||
Packet packet;
|
||||
while((packet = IncomingPacketQueue.poll()) != null){
|
||||
ServerSideNetworkUtils.LegacyProcessClientPacket(packet);
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void LegacyProcessOutgoingPackets(){
|
||||
Packet packet;
|
||||
while((packet = OutGoingPacketQueue.poll()) != null){
|
||||
Packet packetToSend = packet;
|
||||
|
|
@ -46,22 +80,27 @@ public class Server {
|
|||
}
|
||||
}
|
||||
|
||||
public static void RemoveClient(UUID clientID){
|
||||
@Deprecated
|
||||
public static void LegacyRemoveClient(UUID clientID){
|
||||
Logger.debug("Removing client with UUID {}",clientID);
|
||||
ServerConnectionThread connection = ConnectedClients.remove(clientID);
|
||||
if(connection != null){
|
||||
connection.DestroyOwnedActor();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
Configuration.set("writer.file", "ServerLog.t4jlog");
|
||||
static boolean LegacyNetworking = false;
|
||||
|
||||
public static void StartServer(String[] args) throws IOException {
|
||||
|
||||
|
||||
ServerSocket server = new ServerSocket(ServerConnectionThread.ServerPort);
|
||||
Logger.info("\nLaunching New Terrain4J Powered Software!");
|
||||
|
||||
RenderThread.Headless = true;
|
||||
PrimaryRuntime.Server = true;
|
||||
PrimaryRuntime.IsServer = true;
|
||||
|
||||
if(LegacyNetworking){
|
||||
Thread acceptThread = new Thread(() -> {
|
||||
while(true) {
|
||||
try {
|
||||
|
|
@ -71,12 +110,142 @@ public class Server {
|
|||
Logger.error(e, "Failed to accept client connection");
|
||||
}
|
||||
}
|
||||
}, "Terrain4J Server Accept Thread");
|
||||
}, "Terrain4J Server Connection Listener Thread");
|
||||
|
||||
acceptThread.start();
|
||||
|
||||
}
|
||||
else {
|
||||
ServerNetworker = new ServerSelectorMasterThread();
|
||||
ServerNetworker.Initialise();
|
||||
}
|
||||
var GameEngine = new PrimaryRuntime(EngineConfig.getInstance().GetSoftwareName(), new GameCore());
|
||||
Logger.info("Launched Terrain4J Engine");
|
||||
GameEngine.run();
|
||||
}
|
||||
|
||||
private static final Map<String, Boolean> ProfanityFilter = new HashMap<>();
|
||||
private static final Map<String, String> LEET_MAP = new HashMap<>();
|
||||
private static final Pattern TextFilterPattern;
|
||||
|
||||
static{
|
||||
ProfanityFilter.put("fuck", true);
|
||||
ProfanityFilter.put("shit", true);
|
||||
ProfanityFilter.put("bitch", true);
|
||||
ProfanityFilter.put("motherfucker",true);
|
||||
ProfanityFilter.put("nigger",true);
|
||||
ProfanityFilter.put("nigga",true);
|
||||
ProfanityFilter.put("pussy",true);
|
||||
ProfanityFilter.put("cunt",true);
|
||||
ProfanityFilter.put("slut",true);
|
||||
ProfanityFilter.put("whore",true);
|
||||
|
||||
LEET_MAP.put("(3", "ce");
|
||||
LEET_MAP.put("(", "c");
|
||||
LEET_MAP.put("|)", "d");
|
||||
LEET_MAP.put("|", "i");
|
||||
LEET_MAP.put("!", "i");
|
||||
LEET_MAP.put("3", "e");
|
||||
LEET_MAP.put("£", "e");
|
||||
LEET_MAP.put("1", "l");
|
||||
LEET_MAP.put("0", "o");
|
||||
LEET_MAP.put("[]", "o");
|
||||
LEET_MAP.put("{}", "o");
|
||||
LEET_MAP.put("*", "o");
|
||||
LEET_MAP.put("4", "a");
|
||||
LEET_MAP.put("@", "a");
|
||||
LEET_MAP.put("5", "s");
|
||||
LEET_MAP.put("$", "s");
|
||||
LEET_MAP.put("7", "t");
|
||||
|
||||
StringBuilder patternBuilder = new StringBuilder();
|
||||
LEET_MAP.keySet().stream()
|
||||
.sorted((a, b) -> Integer.compare(b.length(), a.length()))
|
||||
.forEach(key -> patternBuilder.append(Pattern.quote(key)).append("|"));
|
||||
|
||||
String regex = patternBuilder.substring(0, patternBuilder.length() - 1);
|
||||
TextFilterPattern = Pattern.compile(regex);
|
||||
}
|
||||
|
||||
public static String ProcessStringFiltering(String TextIn){
|
||||
Logger.debug("Incoming String: " + TextIn);
|
||||
String AutoFileredTextIn = TextIn; //TextIn.replaceAll("[^\\dA-Za-z ]", "#");
|
||||
String Lower = TextIn.toLowerCase();
|
||||
|
||||
Matcher matcher = TextFilterPattern.matcher(Lower);
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
while (matcher.find()) {
|
||||
String token = matcher.group();
|
||||
String replacement = LEET_MAP.get(token);
|
||||
matcher.appendReplacement(result, Matcher.quoteReplacement(replacement));
|
||||
}
|
||||
matcher.appendTail(result);
|
||||
|
||||
return getConstructedText(result, AutoFileredTextIn);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String getConstructedText(StringBuilder result, String AutoFileredTextIn) {
|
||||
String translated = result.toString();
|
||||
Logger.debug("regex checked String: " + translated);
|
||||
String[] words = translated.split("\\s+");
|
||||
String[] OriginalWords = AutoFileredTextIn.split("\\s+");
|
||||
|
||||
String ConstructedText = "";
|
||||
boolean ContainsProfanity = false;
|
||||
for (int i = 0; i < words.length; i++) {
|
||||
String word = words[i];
|
||||
if(ProfanityFilter.containsKey(words[i])){
|
||||
ConstructedText += "[Censored] ";
|
||||
ContainsProfanity = true;
|
||||
} else{
|
||||
ConstructedText += (words.length == OriginalWords.length ? OriginalWords[i] : word) + " ";
|
||||
}
|
||||
}
|
||||
return ConstructedText;
|
||||
}
|
||||
|
||||
public static void ProcessCommand(String TextIn){
|
||||
String formatted = TextIn.trim().toLowerCase().replace("\\s|[\\_\\-\\/\\\\]","");
|
||||
switch (formatted){
|
||||
case "help":
|
||||
case "?":
|
||||
case "helpme":
|
||||
case "docs":
|
||||
case "documentation":
|
||||
PrimaryRuntime.printLog("Here are a list of commands!\n\t help -> list's all of the available commands\n\t stop -> stops the server with a clean shutdown\n\t quit -> forcibly kills the server\n\t stats -> server info dump\n");
|
||||
break;
|
||||
case "stats":
|
||||
List<String[]> profiling = EngineConfig.getInstance().GetSystemProfiling();
|
||||
String Profiling = "";
|
||||
for(int i = 0; i < profiling.size(); i++){
|
||||
Profiling += String.join("\n", profiling.get(i));
|
||||
}
|
||||
|
||||
AtomicReference<String> PlayerConnections = new AtomicReference<>("");
|
||||
|
||||
Server.ConnectedClients.forEach((uuid, client)->{
|
||||
String Username = "N/A";
|
||||
if(Server.ClientNames.containsKey(uuid)){
|
||||
Username = Server.ClientNames.get(uuid);
|
||||
}
|
||||
PlayerConnections.set(PlayerConnections.get() + "\nConnection UUID: " + uuid.toString() + "\n\tIP address -> " + client.getIP() + "\n\tUsername -> " + Username);
|
||||
});
|
||||
|
||||
PrimaryRuntime.printLog("\nServer Runtime Info:\n\tPlayers Connected: " + Server.ConnectedClients.size() +"\n" + PlayerConnections.get() + "\n\n" + Profiling);
|
||||
break;
|
||||
case "stop":
|
||||
case "end":
|
||||
PrimaryRuntime.printLog("Stopping Server");
|
||||
EngineThread.running = false;
|
||||
PrimaryRuntime.CanClose = true;
|
||||
break;
|
||||
case "quit":
|
||||
case "kill":
|
||||
case "exit":
|
||||
System.exit(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Display;
|
||||
|
||||
import org.lwjgl.system.MemoryStack;
|
||||
import org.tinylog.Logger;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
|
|
@ -28,7 +29,7 @@ public class GLFWImageParser {
|
|||
IntBuffer height = MemStack.mallocInt(1);
|
||||
image = stbi_load(path, width, height, channels, 4);
|
||||
if (image == null) {
|
||||
System.out.println("Could not load or find image inputted.");
|
||||
Logger.debug("Could not load or find image inputted.");
|
||||
}
|
||||
Width = width.get();
|
||||
Height = height.get();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,161 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Display;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineInstance;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.InitData;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Rendering.VulkanContext;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.PrimaryRuntime;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.OpenGL.GlModels.GLMesh;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.OpenGL.Rendering.ForwardRenderer;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.OpenGL.Rendering.SceneRender;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.GUI.GuiRenderer;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Pipeline.Images.TextureCache;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.VkModel.MaterialData;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.VkModel.MaterialsCache;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.VkModel.ModelData;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.OpenGL.GlModels.ModelsCache;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DeviceLayers.CommandBuffer;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DisplayToScreen.SceneRenderer;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Util.VulkanUtils;
|
||||
import org.lwjgl.opengl.GL;
|
||||
import org.lwjgl.opengl.GLCapabilities;
|
||||
import org.tinylog.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.lwjgl.glfw.GLFW.glfwMakeContextCurrent;
|
||||
import static org.lwjgl.glfw.GLFW.glfwSwapBuffers;
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
public class OpenGLRenderer implements Renderer{
|
||||
private int CurrentFrame;
|
||||
private boolean Resize = false;
|
||||
private List<MaterialData> Materials = new ArrayList<>();
|
||||
private List<ModelData> Models = new ArrayList<>();
|
||||
private final MaterialsCache materialsCache;
|
||||
private TextureCache textureCache;
|
||||
private EngineConfig.AntiAliasType CurrentAAMode;
|
||||
private final ModelsCache modelsCache;
|
||||
private final boolean Deferred;
|
||||
private float LastGamma = 0.8545f;
|
||||
private GLCapabilities glCapabilities = null;
|
||||
private SceneRender sceneRenderer = null;
|
||||
|
||||
public OpenGLRenderer(EngineInstance engineInstance) {
|
||||
textureCache = new TextureCache();
|
||||
materialsCache = new MaterialsCache();
|
||||
modelsCache = new ModelsCache();
|
||||
Resize = false;
|
||||
CurrentAAMode = EngineConfig.getInstance().RenderAAType();
|
||||
LastGamma = EngineConfig.getInstance().GetGamma();
|
||||
Deferred = EngineConfig.getInstance().DeferredRendering();
|
||||
}
|
||||
public static boolean LoggedNullCapabilities = false;
|
||||
@Override
|
||||
public void render(EngineInstance engineInstance) {
|
||||
if(!Initialised){
|
||||
glfwMakeContextCurrent(PrimaryRuntime.GetEngineInstance().window().getHandle());
|
||||
glCapabilities = GL.createCapabilities();
|
||||
glClearColor(0.0f, 0.0f, 0.1f, 0.0f);
|
||||
if(!LoggedNullCapabilities){
|
||||
Logger.debug("Creating OpenGL Context On Render Thread");
|
||||
LoggedNullCapabilities = true;
|
||||
}
|
||||
sceneRenderer = new ForwardRenderer();
|
||||
Models.addAll(initData.Models());
|
||||
Models.forEach(model->{
|
||||
float Left = -0.9f * (float)Math.random();
|
||||
float right = Left + 0.1f + 0.25f * (float)Math.random();
|
||||
float bottom = -1.0f + 2 * (float)Math.random();
|
||||
float top = bottom + 0.1f + 0.25f * (float)Math.random();
|
||||
float middle = Left + (right - Left)/2;
|
||||
float[] positions = new float[]{
|
||||
Left, top, 0.0f,
|
||||
Left, bottom, 0.0f,
|
||||
right, bottom, 0.0f,
|
||||
right, top, 0.0f
|
||||
};
|
||||
float[] colours = new float[]{
|
||||
0.5f, 0.0f, 0.0f,
|
||||
0.0f, 0.5f, 0.0f,
|
||||
0.0f, 0.0f, 0.5f,
|
||||
0.0f, 0.5f, 0.5f,
|
||||
};
|
||||
int[] indices = new int[]{
|
||||
0, 1, 3, 3, 1, 2,
|
||||
};
|
||||
GLMesh mesh = new GLMesh(positions, colours, indices);
|
||||
modelsCache.addMesh(model.ID(),mesh);
|
||||
});
|
||||
Initialised = true;
|
||||
}
|
||||
if(glCapabilities == null) {
|
||||
glfwMakeContextCurrent(engineInstance.window().getHandle());
|
||||
glCapabilities = GL.createCapabilities();
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
if(!LoggedNullCapabilities){
|
||||
Logger.debug("Creating OpenGL Context On Render Thread");
|
||||
LoggedNullCapabilities = true;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Window window = engineInstance.window();
|
||||
glViewport(0, 0, window.getWidth(), window.getHeight());
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
sceneRenderer.Render(engineInstance.scene(), modelsCache);
|
||||
|
||||
glfwSwapBuffers(engineInstance.window().getHandle());
|
||||
}
|
||||
|
||||
public TextureCache GetTextureCache(){return textureCache;}
|
||||
public MaterialsCache GetMaterialsCache(){return materialsCache;}
|
||||
public VulkanContext GetVulkanContext(){return null;}
|
||||
|
||||
public EngineConfig.AntiAliasType GetCurrentAAMode(){return CurrentAAMode;}
|
||||
|
||||
public boolean GetDeferred(){return Deferred;}
|
||||
|
||||
@Override
|
||||
public SceneRenderer GetSceneRender() {
|
||||
return null;
|
||||
}
|
||||
private boolean Initialised = false;
|
||||
private InitData initData = null;
|
||||
@Override
|
||||
public void Initialise(InitData initData) {
|
||||
Initialised = false;
|
||||
this.initData = initData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuiRenderer GetGUIRenderer() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long GetGuiTexture(long ID) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void cleanup() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DeferredRender(EngineInstance engineInstance) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ForwardRender(EngineInstance engineInstance) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Display;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineInstance;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.InitData;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Rendering.SkyBox;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Rendering.VulkanContext;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.GUI.GuiRenderer;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.GUI.GuiTexture;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.DeferredRendering.LightRenderer;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Pipeline.Images.TextureCache;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.PostProcessing.PostProcess;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.VkModel.MaterialData;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.VkModel.MaterialsCache;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.VkModel.ModelData;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.VkModel.ModelsCache;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.SpriteRendering.SpriteRenderer;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DeviceLayers.CommandBuffer;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DeviceLayers.CommandPool;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DeviceLayers.GPUSynchronisation.Fence;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DeviceLayers.GPUSynchronisation.Semaphore;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DeviceLayers.Queues.Queue;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DisplayToScreen.DeferredSceneRender;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DisplayToScreen.ForwardSceneRender;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DisplayToScreen.SceneRenderer;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.SwapChain.SwapChain;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.SwapChain.SwapChainRender;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Util.VulkanUtils;
|
||||
import org.lwjgl.system.MemoryStack;
|
||||
import org.lwjgl.vulkan.VkCommandBufferSubmitInfo;
|
||||
import org.lwjgl.vulkan.VkExtent2D;
|
||||
import org.lwjgl.vulkan.VkSemaphoreSubmitInfo;
|
||||
import org.tinylog.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.lwjgl.vulkan.VK13.*;
|
||||
|
||||
public interface Renderer {
|
||||
public TextureCache GetTextureCache();
|
||||
public MaterialsCache GetMaterialsCache();
|
||||
public VulkanContext GetVulkanContext();
|
||||
|
||||
public EngineConfig.AntiAliasType GetCurrentAAMode();
|
||||
public SceneRenderer GetSceneRender();
|
||||
|
||||
public boolean GetDeferred();
|
||||
|
||||
|
||||
public void Initialise(InitData initData);
|
||||
|
||||
public GuiRenderer GetGUIRenderer();
|
||||
public long GetGuiTexture(long ID);
|
||||
|
||||
public void cleanup() ;
|
||||
public void DeferredRender(EngineInstance engineInstance);
|
||||
|
||||
public void ForwardRender(EngineInstance engineInstance);
|
||||
|
||||
public void render(EngineInstance engineInstance);
|
||||
}
|
||||
|
|
@ -6,24 +6,25 @@ import net.halbear.Terrain4J.EngineCore.Logic.InitData;
|
|||
import net.halbear.Terrain4J.EngineCore.Logic.Rendering.SkyBox;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Rendering.VulkanContext;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.PrimaryRuntime;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.GUI.GuiRenderer;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.GUI.GuiTexture;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.DeferredRendering.LightRenderer;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Pipeline.Images.TextureCache;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.PostProcessing.PostProcess;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.VkModel.*;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.SpriteRendering.SpriteRenderer;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DeviceLayers.CommandBuffer;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DeviceLayers.CommandPool;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DeviceLayers.GPUSynchronisation.Fence;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DeviceLayers.GPUSynchronisation.Semaphore;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DeviceLayers.Queues.Queue;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DisplayToScreen.DeferredSceneRender;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DisplayToScreen.ForwardSceneRender;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DisplayToScreen.SceneRenderer;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.SwapChain.SwapChain;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.SwapChain.SwapChainRender;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Util.VulkanUtils;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.GUI.GuiRenderer;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.GUI.GuiTexture;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.DeferredRendering.LightRenderer;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Pipeline.Images.TextureCache;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.PostProcessing.PostProcess;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.VkModel.*;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.SpriteRendering.SpriteRenderer;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DeviceLayers.CommandBuffer;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DeviceLayers.CommandPool;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DeviceLayers.GPUSynchronisation.Fence;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DeviceLayers.GPUSynchronisation.Semaphore;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DeviceLayers.Queues.Queue;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DisplayToScreen.DeferredSceneRender;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DisplayToScreen.ForwardSceneRender;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DisplayToScreen.SceneRenderer;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.SwapChain.SwapChain;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.SwapChain.SwapChainRender;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Util.VulkanUtils;
|
||||
import net.halbear.Terrain4J.EngineCore.Threads.RenderThread;
|
||||
import org.lwjgl.system.MemoryStack;
|
||||
import org.lwjgl.vulkan.VkCommandBufferSubmitInfo;
|
||||
import org.lwjgl.vulkan.VkExtent2D;
|
||||
|
|
@ -36,7 +37,7 @@ import java.util.List;
|
|||
|
||||
import static org.lwjgl.vulkan.VK13.*;
|
||||
|
||||
public class Render {
|
||||
public class VulkanRenderer implements Renderer {
|
||||
|
||||
private final ModelsCache modelsCache;
|
||||
|
||||
|
|
@ -74,7 +75,7 @@ public class Render {
|
|||
|
||||
public boolean GetDeferred(){return Deferred;}
|
||||
|
||||
public Render(EngineInstance engineInstance) {
|
||||
public VulkanRenderer(EngineInstance engineInstance) {
|
||||
Deferred = EngineConfig.getInstance().DeferredRendering();
|
||||
RendererContext = new VulkanContext(engineInstance.window());
|
||||
CurrentFrame = 0;
|
||||
|
|
@ -252,10 +253,10 @@ public class Render {
|
|||
}
|
||||
|
||||
public void render(EngineInstance engineInstance){
|
||||
if(! RenderThread.AllowRender()) return;
|
||||
if(Deferred) DeferredRender(engineInstance);
|
||||
else ForwardRender(engineInstance);
|
||||
}
|
||||
|
||||
private void resize(EngineInstance engineInstance){
|
||||
Window window = engineInstance.window();
|
||||
if(window.getWidth() == 0 && window.getHeight() == 0){
|
||||
|
|
@ -4,20 +4,27 @@ import net.halbear.Terrain4J.EngineCore.Input.KeyboardInput;
|
|||
import net.halbear.Terrain4J.EngineCore.Input.MouseListener;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.PrimaryRuntime;
|
||||
import org.joml.Vector2i;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.lwjgl.glfw.GLFWImage;
|
||||
import org.lwjgl.glfw.GLFWVidMode;
|
||||
import org.lwjgl.glfw.GLFWWindowFocusCallback;
|
||||
import org.lwjgl.opengl.GL;
|
||||
import org.lwjgl.opengl.GLCapabilities;
|
||||
import org.lwjgl.system.MemoryStack;
|
||||
import org.lwjgl.system.MemoryUtil;
|
||||
import org.tinylog.Logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
import static net.halbear.Terrain4J.EngineCore.Main.Scene.GUIs.StartMenu.GameStarted;
|
||||
import static net.halbear.Terrain4J.EngineCore.Main.Scene.GUIs.StartMenu.ShowSettings;
|
||||
import static org.lwjgl.glfw.Callbacks.glfwFreeCallbacks;
|
||||
import static org.lwjgl.glfw.GLFW.*;
|
||||
import static org.lwjgl.glfw.GLFWVulkan.glfwVulkanSupported;
|
||||
import static org.lwjgl.opengl.GL11.GL_TRUE;
|
||||
import static org.lwjgl.opengl.GL11.glClearColor;
|
||||
|
||||
public class Window {
|
||||
private final long handle;
|
||||
|
|
@ -25,18 +32,85 @@ public class Window {
|
|||
private final MouseListener mouseInput;
|
||||
private int height;
|
||||
private int width;
|
||||
private int x;
|
||||
private int y;
|
||||
private boolean displayFPS = false;
|
||||
private String Title = "Terrain4J Application";
|
||||
private final EngineConfig.RenderAPI LinkedApi;
|
||||
|
||||
public boolean CursorLocked = false;
|
||||
public boolean ForceCursorUnlock = false;
|
||||
|
||||
public Window(String title){
|
||||
public String GetTitle(){return Title;}
|
||||
public EngineConfig.RenderAPI GetLinkedApi(){return LinkedApi;}
|
||||
|
||||
public static Window RefreshRendererAttachment(Window windowIn){
|
||||
if(PrimaryRuntime.IsServer) return null;
|
||||
Logger.debug("Creating new Window Instance");
|
||||
Vector2i inSize = windowIn.GetSize();
|
||||
Vector2i inPos = windowIn.GetPosition();
|
||||
String Title = windowIn.GetTitle();
|
||||
windowIn.cleanup();
|
||||
windowIn.setShouldClose();
|
||||
Window newWindow = new Window(Title);
|
||||
newWindow.SetProperties(inSize.x, inSize.y, inPos.x, inPos.y);
|
||||
return newWindow;
|
||||
}
|
||||
|
||||
public void SetProperties(int width, int height, int x, int y){
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
glfwSetWindowSize(handle, width, height);
|
||||
glfwSetWindowPos(handle, x, y);
|
||||
}
|
||||
|
||||
public Vector2i GetSize(){
|
||||
try (MemoryStack MemStack = MemoryStack.stackPush()) {
|
||||
IntBuffer pWidth = MemStack.mallocInt(1);
|
||||
IntBuffer pHeight = MemStack.mallocInt(1);
|
||||
|
||||
GLFW.glfwGetWindowSize(handle, pWidth, pHeight);
|
||||
|
||||
int width = pWidth.get(0);
|
||||
int height = pHeight.get(0);
|
||||
return new Vector2i(width, height);
|
||||
}
|
||||
}
|
||||
|
||||
public Vector2i GetPosition(){
|
||||
try (MemoryStack MemStack = MemoryStack.stackPush()) {
|
||||
IntBuffer pLeft = MemStack.mallocInt(1);
|
||||
IntBuffer pRight = MemStack.mallocInt(1);
|
||||
|
||||
GLFW.glfwGetWindowPos(handle, pLeft, pRight);
|
||||
|
||||
int width = pLeft.get(0);
|
||||
int height = pRight.get(0);
|
||||
return new Vector2i(width, height);
|
||||
}
|
||||
}
|
||||
|
||||
public Window(String title){
|
||||
this(title, EngineConfig.getInstance().GetRenderingAPI());
|
||||
}
|
||||
public Window(String title, EngineConfig.RenderAPI api){
|
||||
if(PrimaryRuntime.IsServer) {
|
||||
handle = 0;
|
||||
LinkedApi = null;
|
||||
keyboardInput = null;
|
||||
mouseInput = null;
|
||||
return;
|
||||
}
|
||||
this.Title = title;
|
||||
this.LinkedApi = api;
|
||||
if (!glfwInit()) {
|
||||
throw new RuntimeException("Unable to initialize GLFW");
|
||||
}
|
||||
if (!glfwVulkanSupported()) {
|
||||
throw new RuntimeException("Cannot find a compatible Vulkan installable client driver (ICD)");
|
||||
if (!glfwVulkanSupported() && EngineConfig.getInstance().GetRenderingAPI() == EngineConfig.RenderAPI.Vulkan) {
|
||||
Logger.error("Cannot find a compatible Vulkan installable client driver (ICD)");
|
||||
EngineConfig.getInstance().SetRenderingAPI(EngineConfig.RenderAPI.OpenGL);
|
||||
}
|
||||
GLFWVidMode vidMode = glfwGetVideoMode(glfwGetPrimaryMonitor());
|
||||
if (vidMode == null) {
|
||||
|
|
@ -46,8 +120,25 @@ public class Window {
|
|||
height = vidMode.height();//Globals.getInstance().getHeight();
|
||||
|
||||
glfwDefaultWindowHints();
|
||||
|
||||
switch (api){
|
||||
case Vulkan:
|
||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||
break;
|
||||
case OpenGL:
|
||||
default:
|
||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
|
||||
if (EngineConfig.getInstance().CompatibilityMode()) {
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE);
|
||||
} else {
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
glfwWindowHint(GLFW_MAXIMIZED, GLFW_FALSE);
|
||||
glfwWindowHint(GLFW_ALPHA_BITS, 0);
|
||||
glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_FALSE);
|
||||
|
|
@ -66,6 +157,11 @@ public class Window {
|
|||
height = h;
|
||||
});
|
||||
|
||||
glfwSetErrorCallback((int errorCode, long msgPtr) ->
|
||||
Logger.error("Error code [{}], msg [{}]", errorCode, MemoryUtil.memUTF8(msgPtr))
|
||||
);
|
||||
|
||||
|
||||
File IconLocation = new File("src/main/resources" + EngineConfig.getInstance().FetchIcon());
|
||||
GLFWImage Icon = GLFWImage.malloc();
|
||||
GLFWImage.Buffer IconBuffer = GLFWImage.malloc(1);
|
||||
|
|
@ -99,7 +195,7 @@ public class Window {
|
|||
PrimaryRuntime.UpdateFrameAccuracy();
|
||||
}
|
||||
});
|
||||
glfwMakeContextCurrent(handle);
|
||||
if(LinkedApi == EngineConfig.RenderAPI.Vulkan)glfwMakeContextCurrent(handle);
|
||||
if (EngineConfig.VSYNC) glfwSwapInterval(1);
|
||||
else glfwSwapInterval(0);
|
||||
mouseInput = new MouseListener(handle);
|
||||
|
|
@ -115,6 +211,7 @@ public class Window {
|
|||
}
|
||||
|
||||
public void cleanup() {
|
||||
if(PrimaryRuntime.IsServer) return;
|
||||
glfwFreeCallbacks(handle);
|
||||
glfwDestroyWindow(handle);
|
||||
glfwTerminate();
|
||||
|
|
@ -131,7 +228,12 @@ public class Window {
|
|||
public MouseListener getMouseInput(){
|
||||
return mouseInput;
|
||||
}
|
||||
public void pollOpenGLEvents(){
|
||||
if(PrimaryRuntime.IsServer) return;
|
||||
if(LinkedApi != EngineConfig.RenderAPI.OpenGL) return;
|
||||
}
|
||||
public void pollEvents() {
|
||||
if(PrimaryRuntime.IsServer) return;
|
||||
if((!GameStarted || ShowSettings || ForceCursorUnlock) && CursorLocked) UnlockCursor();
|
||||
else if (GameStarted && !ShowSettings && !CursorLocked) LockCursor();
|
||||
if (keyboardInput.keySinglePress(GLFW_KEY_V)) {
|
||||
|
|
@ -153,6 +255,7 @@ public class Window {
|
|||
if (displayFPS) glfwSetWindowTitle(handle, EngineConfig.SOFTWARE_TITLE + " - FPS: " + EngineConfig.FrameRate_PRIMARYTHREAD + " TPS: " + EngineConfig.TPS + " RenderFPS: " + EngineConfig.FrameRate_RENDERTHREAD + " VSYNC: " + EngineConfig.VSYNC);
|
||||
}
|
||||
public void SetVsync(){
|
||||
if(PrimaryRuntime.IsServer) return;
|
||||
Logger.info("Vsync Swap");
|
||||
if (EngineConfig.VSYNC) {
|
||||
glfwSwapInterval(0);
|
||||
|
|
@ -163,11 +266,15 @@ public class Window {
|
|||
EngineConfig.VSYNC = true;
|
||||
}
|
||||
}
|
||||
public void setShouldClose() {
|
||||
public void setShouldClose()
|
||||
{
|
||||
if(PrimaryRuntime.IsServer) return;
|
||||
|
||||
glfwSetWindowShouldClose(handle, true);
|
||||
}
|
||||
public boolean shouldClose() {
|
||||
//return false;
|
||||
if(PrimaryRuntime.IsServer) return true;
|
||||
return glfwWindowShouldClose(handle);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Input;
|
||||
|
||||
import imgui.ImGui;
|
||||
import imgui.ImGuiIO;
|
||||
import imgui.flag.ImGuiKey;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.GUI.GuiUtils;
|
||||
import org.lwjgl.glfw.GLFWCharCallbackI;
|
||||
import org.lwjgl.glfw.GLFWKeyCallbackI;
|
||||
|
||||
|
|
@ -28,6 +32,12 @@ public class KeyboardInput implements GLFWKeyCallbackI {
|
|||
glfwPollEvents();
|
||||
}
|
||||
public void KeyCallback(long Window, int key, int scancode, int action, int mods){
|
||||
|
||||
ImGui.getIO().addKeyEvent(ImGuiKey.Backspace, key == (GLFW_KEY_BACKSPACE) && (action == GLFW_PRESS || action == GLFW_REPEAT));
|
||||
ImGui.getIO().addKeyEvent(ImGuiKey.Delete, key == (GLFW_KEY_DELETE) && (action == GLFW_PRESS || action == GLFW_REPEAT));
|
||||
ImGui.getIO().addKeyEvent(ImGuiKey.LeftArrow, key == (GLFW_KEY_LEFT) && (action == GLFW_PRESS || action == GLFW_REPEAT));
|
||||
ImGui.getIO().addKeyEvent(ImGuiKey.RightArrow, key == (GLFW_KEY_RIGHT) && (action == GLFW_PRESS || action == GLFW_REPEAT));
|
||||
|
||||
if (!keysPressed.contains(key) && action == GLFW_PRESS){
|
||||
keysPressed.add(key);
|
||||
} else if (keysPressed.contains(key) && action == GLFW_RELEASE){
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Logic;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Main.PrimaryRuntime;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DisplayToScreen.DeferredSceneRender;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DisplayToScreen.ForwardSceneRender;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.GUIs.SettingsMenu;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DisplayToScreen.DeferredSceneRender;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DisplayToScreen.ForwardSceneRender;
|
||||
import net.halbear.Terrain4J.EngineCore.ServerNetworking.ClientSideNetworkUtils;
|
||||
import net.halbear.Terrain4J.EngineCore.Threads.ClientConnectionThread;
|
||||
import net.halbear.Terrain4J.EngineCore.Threads.RenderThread;
|
||||
import org.tinylog.Logger;
|
||||
|
||||
import java.io.*;
|
||||
|
|
@ -80,6 +84,12 @@ public class EngineConfig {
|
|||
public boolean RenderCollisionMesh = true;
|
||||
public float PhysicsSpeed = 1.0f;
|
||||
|
||||
public String UserDisplayName = "player";
|
||||
public String ServerIPAddress = "localhost";
|
||||
public int ServerPort = 25565;
|
||||
|
||||
public RenderAPI RenderingAPI = RenderAPI.Vulkan;
|
||||
|
||||
public float MusicVolume = 0.0f;
|
||||
public float SoundVolume = 0.0f;
|
||||
public float WeaponVolume = 0.0f;
|
||||
|
|
@ -87,6 +97,56 @@ public class EngineConfig {
|
|||
|
||||
public float PlayerOnline = 1.0f;
|
||||
|
||||
public boolean IsServer = false;
|
||||
|
||||
public boolean GetServer(){return IsServer;}
|
||||
|
||||
public void SetServer(boolean NewServer) {IsServer = NewServer;}
|
||||
|
||||
public String GetUserDisplayName(){return UserDisplayName;}
|
||||
public void SetUserDisplayName(String NewName) {
|
||||
UserDisplayName = NewName;
|
||||
EngineConfigVar.setProperty("user_display_name",UserDisplayName);
|
||||
try {
|
||||
EngineConfigVar.store(new FileWriter(path.toAbsolutePath().toString() + "/" + FILENAME), "created new properties file");
|
||||
} catch (IOException e) {
|
||||
Logger.error("Failed to write to config file: [{}]", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public int GetServerPort(){return ServerPort;}
|
||||
public void SetServerPort(int NewPort) {
|
||||
ServerPort = NewPort;
|
||||
EngineConfigVar.setProperty("server_port", String.valueOf(ServerPort));
|
||||
try {
|
||||
EngineConfigVar.store(new FileWriter(path.toAbsolutePath().toString() + "/" + FILENAME), "created new properties file");
|
||||
} catch (IOException e) {
|
||||
Logger.error("Failed to write to config file: [{}]", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public String GetServerIP(){return ServerIPAddress;}
|
||||
public void SetServerIP(String NewIP) {
|
||||
ServerIPAddress = NewIP;
|
||||
EngineConfigVar.setProperty("server_ip",ServerIPAddress);
|
||||
try {
|
||||
EngineConfigVar.store(new FileWriter(path.toAbsolutePath().toString() + "/" + FILENAME), "created new properties file");
|
||||
} catch (IOException e) {
|
||||
Logger.error("Failed to write to config file: [{}]", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public enum RenderAPI{
|
||||
Vulkan,
|
||||
OpenGL
|
||||
}
|
||||
|
||||
public RenderAPI GetRenderingAPI(){return RenderingAPI;}
|
||||
public synchronized void SetRenderingAPI(RenderAPI API){
|
||||
RenderingAPI = API;
|
||||
Logger.debug("Rendering API changed to: " + API);
|
||||
}
|
||||
|
||||
public float PhysicsSpeed(){return PhysicsSpeed;}
|
||||
public void SetPhysicsSpeed(float NewSpeed){PhysicsSpeed =NewSpeed;}
|
||||
|
||||
|
|
@ -166,6 +226,17 @@ public class EngineConfig {
|
|||
MSAAx8
|
||||
}
|
||||
|
||||
public RenderAPI GetRenderAPI(String strIn){
|
||||
String formatted = strIn.toLowerCase().replace("\\s|[\\_\\-\\/\\\\]","");
|
||||
switch (formatted){
|
||||
case "vulkan":
|
||||
return RenderAPI.Vulkan;
|
||||
case "opengl":
|
||||
default:
|
||||
return RenderAPI.OpenGL;
|
||||
}
|
||||
}
|
||||
|
||||
public int GetRenderSampleCount(){
|
||||
switch(AAMode){
|
||||
case MSAAx2:
|
||||
|
|
@ -183,9 +254,12 @@ public class EngineConfig {
|
|||
}
|
||||
}
|
||||
|
||||
private Properties EngineConfigVar;
|
||||
private Path path;
|
||||
|
||||
private EngineConfig() {
|
||||
var EngineConfigVar = new Properties();
|
||||
Path path = Paths.get("");
|
||||
EngineConfigVar = new Properties();
|
||||
path = Paths.get("");
|
||||
File ConfigFile = new File(path.toAbsolutePath().toString() + "/" + FILENAME);
|
||||
boolean SuccessfulLoad = false;
|
||||
try(InputStream stream = new FileInputStream(path.toAbsolutePath().toString() + "/" + FILENAME)){
|
||||
|
|
@ -223,6 +297,8 @@ public class EngineConfig {
|
|||
IconName = (EngineConfigVar.getOrDefault("Software_Icon", "ProgramIcon.png").toString());
|
||||
LoadingScreenLocation = (EngineConfigVar.getOrDefault("LoadingScreenLocation", LoadingScreenLocation).toString());
|
||||
IconPath = (EngineConfigVar.getOrDefault("Software_Icon_Path", "/WindowResources/Icon/").toString());
|
||||
UserDisplayName = (EngineConfigVar.getOrDefault("user_display_name", "player").toString());
|
||||
ServerIPAddress = (EngineConfigVar.getOrDefault("server_ip", "localhost").toString());
|
||||
CapMainToTickRate = Boolean.parseBoolean(EngineConfigVar.getOrDefault("cap_main_to_tickrate", true).toString());
|
||||
CapFastToTickRate = Boolean.parseBoolean(EngineConfigVar.getOrDefault("cap_fast_to_tickrate", true).toString());
|
||||
CapPrimaryToTickRate = Boolean.parseBoolean(EngineConfigVar.getOrDefault("cap_master_to_tickrate", false).toString());
|
||||
|
|
@ -239,6 +315,7 @@ public class EngineConfig {
|
|||
MaxDescriptors = Integer.parseInt(EngineConfigVar.getOrDefault("MaxDescriptors", "1000").toString());
|
||||
VSYNC = Boolean.parseBoolean(EngineConfigVar.getOrDefault("vsync", true).toString());
|
||||
vkValidated = Boolean.parseBoolean(EngineConfigVar.getOrDefault("vkValidated", false).toString());
|
||||
IsServer = Boolean.parseBoolean(EngineConfigVar.getOrDefault("server", false).toString());
|
||||
RequestedImages = Integer.parseInt(EngineConfigVar.getOrDefault("RequestedImages", 3).toString());
|
||||
ShaderDebug =Boolean.parseBoolean(EngineConfigVar.getOrDefault("Debug_Shaders", false).toString());
|
||||
RecompileShaders =Boolean.parseBoolean(EngineConfigVar.getOrDefault("ShaderRecompiling", true).toString());
|
||||
|
|
@ -249,8 +326,12 @@ public class EngineConfig {
|
|||
renderer = Integer.parseInt(EngineConfigVar.getOrDefault("Renderer", 1).toString()) == 0 ? Renderer.Forward: Renderer.Deferred;
|
||||
ShadowMapSize = Integer.parseInt(EngineConfigVar.getOrDefault("ShadowMapSize", 16).toString());
|
||||
MaxVulkanCrashesAllowed = Integer.parseInt(EngineConfigVar.getOrDefault("MaxAllowedVulkanCrashes", 10).toString());
|
||||
ServerPort = Integer.parseInt(EngineConfigVar.getOrDefault("server_port", 25565).toString());
|
||||
CompatibilityMode = Boolean.parseBoolean(EngineConfigVar.getOrDefault("compatibility_mode", false).toString());
|
||||
AlphaToCoverage = Boolean.parseBoolean(EngineConfigVar.getOrDefault("AlphaToCoverage", false).toString());
|
||||
RenderingAPI = GetRenderAPI(EngineConfigVar.getOrDefault("RenderingAPI", "VULKAN").toString());
|
||||
ClientSideNetworkUtils.ServerPort = ServerPort;
|
||||
ClientSideNetworkUtils.ServerIP = ServerIPAddress;
|
||||
ForwardSceneRender.SetDualPassRendering(Boolean.parseBoolean(EngineConfigVar.getOrDefault("DualPassRendering", true).toString()));
|
||||
DeferredSceneRender.SetDualPassRendering(Boolean.parseBoolean(EngineConfigVar.getOrDefault("DualPassRendering", true).toString()));
|
||||
switch(AAValue){
|
||||
|
|
@ -289,6 +370,9 @@ public class EngineConfig {
|
|||
EngineConfigVar.setProperty("master_tick_rate", String.valueOf(DEFAULT_TICKRATE));
|
||||
EngineConfigVar.setProperty("display_width","1280");
|
||||
EngineConfigVar.setProperty("display_height","720");
|
||||
EngineConfigVar.setProperty("user_display_name","player");
|
||||
EngineConfigVar.setProperty("server_ip","localhost");
|
||||
EngineConfigVar.setProperty("server_port","25565");
|
||||
EngineConfigVar.setProperty("vsync","true");
|
||||
EngineConfigVar.setProperty("vkValidated","false");
|
||||
EngineConfigVar.setProperty("Debug_Shaders","false");
|
||||
|
|
@ -298,9 +382,11 @@ public class EngineConfig {
|
|||
EngineConfigVar.setProperty("field_of_view","60");
|
||||
EngineConfigVar.setProperty("z_near_plane","1");
|
||||
EngineConfigVar.setProperty("z_far_plane","100");
|
||||
EngineConfigVar.setProperty("RenderingAPI","VULKAN");
|
||||
EngineConfigVar.setProperty("DefaultTexturePath",DefaultTexturePath);
|
||||
EngineConfigVar.setProperty("MaxDescriptors","1000");
|
||||
EngineConfigVar.setProperty("anti_alias_mode","1");
|
||||
EngineConfigVar.setProperty("server","false");
|
||||
EngineConfigVar.setProperty("LoadingScreenLocation",LoadingScreenLocation);
|
||||
EngineConfigVar.store(new FileWriter(path.toAbsolutePath().toString() + "/" + FILENAME), "created new properties file");
|
||||
Logger.debug("Wrote New Config File [{}]", ConfigFile.getAbsolutePath());
|
||||
|
|
@ -313,7 +399,6 @@ public class EngineConfig {
|
|||
}
|
||||
|
||||
|
||||
|
||||
public static synchronized EngineConfig getInstance() {
|
||||
if (instance == null) {instance = new EngineConfig();}
|
||||
return instance;
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Logic;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Audio.AudioManager;
|
||||
import net.halbear.Terrain4J.EngineCore.Display.Render;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.PrimaryRuntime;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.IScene;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.Scene;
|
||||
import net.halbear.Terrain4J.EngineCore.Display.Window;
|
||||
import net.halbear.Terrain4J.EngineCore.Threads.FastTickThread;
|
||||
import net.halbear.Terrain4J.EngineCore.Threads.MainThread;
|
||||
import net.halbear.Terrain4J.EngineCore.Threads.RenderThread;
|
||||
|
||||
public record EngineInstance(Window window, IScene scene, PrimaryRuntime PrimaryThread, AudioManager audioManager) {
|
||||
|
||||
public EngineInstance SetWindow(Window newWindow){
|
||||
return new EngineInstance(newWindow, scene, PrimaryThread, audioManager);
|
||||
}
|
||||
|
||||
public void cleanup(){
|
||||
window.cleanup();
|
||||
audioManager.CleanUp();
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Logic;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.GUI.GuiTexture;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.VkModel.MaterialData;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.VkModel.ModelData;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.GUI.GuiTexture;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.VkModel.MaterialData;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.VkModel.ModelData;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,38 +0,0 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Logic.Physics;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.Actor;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
public record CollisionSensor(Vector3f Offset, String ActorID) {
|
||||
public Vector3f GetTransformedCollisionSensor() {
|
||||
Actor actor = Actor.Actors.get(ActorID);
|
||||
if (actor != null) {
|
||||
CollisionSensor newSensor = new CollisionSensor(new Vector3f().set(Offset), ActorID);
|
||||
Vector3f PivotOffset = new Vector3f().set(actor.GetPivotOffset()).add(actor.GetAditionalPivotOffset());
|
||||
return newSensor.TransformPosition(PivotOffset).TransformRotation(actor.GetRotation()).TransformPosition(PivotOffset.negate()).TransformScale(actor.GetScale()).TransformPosition(actor.GetPosition()).Offset;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public CollisionSensor TransformRotation(Quaternionf quaternionf){
|
||||
if(quaternionf == null ) return this;
|
||||
Vector3f newV1 = new Vector3f(Offset);
|
||||
newV1.rotate(quaternionf);
|
||||
CollisionSensor newPoly = new CollisionSensor(newV1,ActorID);
|
||||
return newPoly;
|
||||
}
|
||||
public CollisionSensor TransformScale(Vector3f Scale){
|
||||
if(Scale == null ) return this;
|
||||
Vector3f newV1 = new Vector3f(Offset);
|
||||
newV1.mul(Scale);
|
||||
CollisionSensor newPoly = new CollisionSensor(newV1,ActorID);
|
||||
return newPoly;
|
||||
}
|
||||
public CollisionSensor TransformPosition(Vector3f Position){
|
||||
if(Position == null ) return this;
|
||||
Vector3f newV1 = new Vector3f(Offset);
|
||||
newV1.add(Position);
|
||||
CollisionSensor newPoly = new CollisionSensor(newV1,ActorID);
|
||||
return newPoly;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Logic.Physics;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.LegacyCollision.CollisionMesh;
|
||||
import org.joml.Vector2f;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
|
|
@ -13,5 +12,4 @@ public interface IPhysicsController {
|
|||
public String MeshID();
|
||||
public void PhysicsTick(float DeltaTime, float TargetFrameRate);
|
||||
public List<String> Collisions();
|
||||
public void CollisionEvent(CollisionMesh collidingMesh, Vector3f PositionDifference, Vector2f CollisionScale);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +0,0 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Logic.Physics.LegacyCollision;
|
||||
|
||||
import org.joml.Vector3f;
|
||||
|
||||
public record CollisionIndexPoly(int Index1, int Index2, int Index3) {
|
||||
public CollisionPoly GetCollisionPoly(CollisionMesh mesh){
|
||||
Vector3f[] vertices = mesh.GetTransformedVertices(new int[]{Index1,Index2,Index3});
|
||||
CollisionPoly polygon = new CollisionPoly(vertices[0],vertices[1],vertices[2],new Vector3f());
|
||||
polygon.CalculateCentre();
|
||||
return polygon;
|
||||
}
|
||||
public CollisionPoly GetRawCollisionPoly(CollisionMesh mesh){
|
||||
Vector3f[] vertices = mesh.GetUntransformedVertices(new int[]{Index1,Index2,Index3});
|
||||
CollisionPoly polygon = new CollisionPoly(vertices[0],vertices[1],vertices[2],new Vector3f());
|
||||
polygon.CalculateCentre();
|
||||
return polygon;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,87 +0,0 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Logic.Physics.LegacyCollision;
|
||||
|
||||
import org.joml.Vector3f;
|
||||
import org.joml.primitives.AABBf;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class CollisionManager {
|
||||
public static Map<String,CollisionMesh> CollisionMeshes = new HashMap<>();
|
||||
public static Map<String,List<String>> CollisionChunks = new HashMap<>();
|
||||
public static List<String> AlwaysCheckMeshes = new ArrayList<>();
|
||||
public static int ChunkWidth = 64;
|
||||
|
||||
public static void AddNewMesh(CollisionMesh mesh){
|
||||
CollisionMeshes.put(mesh.ID, mesh);
|
||||
AABBf Bounds = mesh.GetVoxelCollider();
|
||||
if(Bounds != null) {
|
||||
Vector3f LowestPoints = new Vector3f(Bounds.minX, Bounds.minY, Bounds.minZ).div(ChunkWidth);
|
||||
LowestPoints.x = (int) Math.floor(LowestPoints.x);
|
||||
LowestPoints.y = (int) Math.floor(LowestPoints.y);
|
||||
LowestPoints.z = (int) Math.floor(LowestPoints.z);
|
||||
Vector3f LargestPoints = new Vector3f(Bounds.maxX, Bounds.maxY, Bounds.maxZ).div(ChunkWidth);
|
||||
LargestPoints.x = (int) Math.ceil(LargestPoints.x);
|
||||
LargestPoints.y = (int) Math.ceil(LargestPoints.y);
|
||||
LargestPoints.z = (int) Math.ceil(LargestPoints.z);
|
||||
for (int x = (int) LowestPoints.x; x < LargestPoints.x + 1; x++) {
|
||||
for (int y = (int) LowestPoints.y; y < LargestPoints.y + 1; y++) {
|
||||
for (int z = (int) LowestPoints.z; z < LargestPoints.z + 1; z++) {
|
||||
String ChunkPosition = x + ":" + y + ":" + z;
|
||||
if (!CollisionChunks.containsKey(ChunkPosition)) {
|
||||
List<String> newStrList = new ArrayList<>();
|
||||
CollisionChunks.put(ChunkPosition, newStrList);
|
||||
}
|
||||
CollisionChunks.get(ChunkPosition).add(mesh.ID);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else{
|
||||
AlwaysCheckMeshes.add(mesh.ID);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<String> GetCollisionMeshesAtChunk(String Chunk){
|
||||
return CollisionChunks.get(Chunk) == null ? new ArrayList<>() : CollisionChunks.get(Chunk);
|
||||
}
|
||||
|
||||
public static List<CollisionMesh> GetAllCollisionMeshes(){return CollisionMeshes.values().stream().toList();}
|
||||
|
||||
public static synchronized void UpdateCollisionChunks(){
|
||||
Map<String,List<String>> newMap = new HashMap<>();
|
||||
List<CollisionMesh> meshes = GetAllCollisionMeshes();
|
||||
List<String> AlwaysShowMesh = new ArrayList<>();
|
||||
for(int i = 0; i < meshes.size(); i++){
|
||||
CollisionMesh mesh = meshes.get(i);
|
||||
AABBf Bounds = mesh.GetVoxelCollider();
|
||||
if(Bounds != null) {
|
||||
Vector3f LowestPoints = new Vector3f(Bounds.minX, Bounds.minY, Bounds.minZ).div(ChunkWidth);
|
||||
LowestPoints.x = (int) Math.floor(LowestPoints.x);
|
||||
LowestPoints.y = (int) Math.floor(LowestPoints.y);
|
||||
LowestPoints.z = (int) Math.floor(LowestPoints.z);
|
||||
Vector3f LargestPoints = new Vector3f(Bounds.maxX, Bounds.maxY, Bounds.maxZ).div(ChunkWidth);
|
||||
LargestPoints.x = (int) Math.ceil(LargestPoints.x);
|
||||
LargestPoints.y = (int) Math.ceil(LargestPoints.y);
|
||||
LargestPoints.z = (int) Math.ceil(LargestPoints.z);
|
||||
for (int x = (int) LowestPoints.x; x < LargestPoints.x + 1; x++) {
|
||||
for (int y = (int) LowestPoints.y; y < LargestPoints.y + 1; y++) {
|
||||
for (int z = (int) LowestPoints.z; z < LargestPoints.z + 1; z++) {
|
||||
String ChunkPosition = x + ":" + y + ":" + z;
|
||||
if (!CollisionChunks.containsKey(ChunkPosition)) {
|
||||
List<String> newStrList = new ArrayList<>();
|
||||
CollisionChunks.put(ChunkPosition, newStrList);
|
||||
}
|
||||
CollisionChunks.get(ChunkPosition).add(mesh.ID);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else{
|
||||
AlwaysShowMesh.add(mesh.ID);
|
||||
}
|
||||
}
|
||||
AlwaysCheckMeshes = (AlwaysShowMesh);
|
||||
CollisionChunks = (newMap);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,285 +0,0 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Logic.Physics.LegacyCollision;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.LegacyPhysicsController;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.Actor;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Util.Maths.T4Math;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.VkModel.MeshData;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.VkModel.ModelData;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Util.VulkanUtils;
|
||||
import org.joml.Intersectionf;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector2f;
|
||||
import org.joml.Vector3f;
|
||||
import org.joml.primitives.AABBf;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
public class CollisionMesh {
|
||||
public final List<Vector3f> Vertices;
|
||||
public final List<CollisionIndexPoly> Polygons;
|
||||
public final Map<String, Integer> VertexLookup;
|
||||
public Vector3f TopRightFront = new Vector3f(0,0,0);
|
||||
public Vector3f BottomLeftBack = new Vector3f(0,0,0);
|
||||
public Vector3f WorldPosition = new Vector3f(0,0,0);
|
||||
public Quaternionf Rotation = new Quaternionf();
|
||||
public Vector3f Scale = new Vector3f(1f,1f,1f);
|
||||
public final String ID;
|
||||
public final String ParentID;
|
||||
public AABBf Voxel;
|
||||
|
||||
public List<Vector3f> GetVertices(){return Vertices;}
|
||||
|
||||
public CollisionMesh(String ID, String ActorID){
|
||||
this.ID = ID;
|
||||
if(ActorID != "NULL") {
|
||||
Scale = new Vector3f(Actor.Actors.get(ActorID).GetScale());
|
||||
Rotation = new Quaternionf(Actor.Actors.get(ActorID).GetRotation());
|
||||
}
|
||||
ParentID = ActorID;
|
||||
VertexLookup = new HashMap<>();
|
||||
Polygons = new ArrayList<>();
|
||||
Vertices = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void RegisterMesh(){
|
||||
CollisionManager.AddNewMesh(this);
|
||||
}
|
||||
|
||||
public AABBf GetVoxelCollider(){
|
||||
//if(TopRightFront == null || BottomLeftBack == null) return null;
|
||||
//if(Voxel == null){
|
||||
Vector3f PivotOffset = Actor.Actors.get(ParentID) != null ? new Vector3f(Actor.Actors.get(ParentID).GetPivotOffset()).add(Actor.Actors.get(ParentID).GetAditionalPivotOffset()) : new Vector3f(0,0,0);
|
||||
Vector3f TLF = new Vector3f(TopRightFront);
|
||||
Vector3f BRB = new Vector3f(BottomLeftBack);
|
||||
TLF = TLF.add(PivotOffset).rotate(Rotation).sub(PivotOffset).mul(Scale).add(WorldPosition);
|
||||
BRB = BRB.add(PivotOffset).rotate(Rotation).sub(PivotOffset).mul(Scale).add(WorldPosition);
|
||||
this.Voxel = new AABBf(BRB,TLF);
|
||||
//}
|
||||
return Voxel;
|
||||
}
|
||||
|
||||
public CollisionMesh SetWorldPosition(Vector3f newPos){
|
||||
this.WorldPosition = new Vector3f(newPos);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void SetScaleTransform(Vector3f Scale){
|
||||
this.Scale = new Vector3f(Scale);
|
||||
}
|
||||
|
||||
public void SetRotationTransform(Quaternionf quaternionf){
|
||||
this.Rotation = new Quaternionf(quaternionf);
|
||||
}
|
||||
|
||||
public void GenerateCollisionMeshFromVulkanModel(ModelData vkModel) throws IOException {
|
||||
Polygons.clear();
|
||||
DataInputStream VertexInput = new DataInputStream(new BufferedInputStream(
|
||||
new FileInputStream(vkModel.VertexPath())));
|
||||
DataInputStream IndexInput = new DataInputStream(new BufferedInputStream(
|
||||
new FileInputStream(vkModel.IndexPath())));
|
||||
List<float[]> Vertices = new ArrayList<>();
|
||||
int totalFloatCount = 0;
|
||||
|
||||
for (MeshData meshData : vkModel.Meshes()) {
|
||||
int floatsToRead = meshData.VertexSize() / VulkanUtils.FLOAT_SIZE;
|
||||
float[] meshFloats = new float[floatsToRead];
|
||||
for (int i = 0; i < floatsToRead; i++) {
|
||||
meshFloats[i] = VertexInput.readFloat();
|
||||
}
|
||||
Vertices.add(meshFloats);
|
||||
totalFloatCount += floatsToRead;
|
||||
}
|
||||
|
||||
float[] FullMeshFloatArr = new float[totalFloatCount];
|
||||
int iterator = 0;
|
||||
for (float[] meshFloats : Vertices) {
|
||||
System.arraycopy(meshFloats, 0, FullMeshFloatArr, iterator, meshFloats.length);
|
||||
iterator += meshFloats.length;
|
||||
}
|
||||
List<int[]> Indices = new ArrayList<>();
|
||||
int IndexCount = 0;
|
||||
int vertexOffset = 0;
|
||||
int vertexStride = 14;
|
||||
for (MeshData meshData : vkModel.Meshes()) {
|
||||
int intsToRead = meshData.IndexSize() / VulkanUtils.INT_SIZE;
|
||||
int[] meshIndices = new int[intsToRead];
|
||||
for (int i = 0; i < intsToRead; i++) {
|
||||
meshIndices[i] = IndexInput.readInt() + vertexOffset;
|
||||
}
|
||||
Indices.add(meshIndices);
|
||||
IndexCount += intsToRead;
|
||||
int meshVertexCount = (meshData.VertexSize() / VulkanUtils.FLOAT_SIZE) / vertexStride;
|
||||
vertexOffset += meshVertexCount;
|
||||
}
|
||||
int[] FullMeshIndexArr = new int[IndexCount];
|
||||
iterator = 0;
|
||||
for (int[] meshIndices : Indices) {
|
||||
System.arraycopy(meshIndices, 0, FullMeshIndexArr, iterator, meshIndices.length);
|
||||
iterator += meshIndices.length;
|
||||
}
|
||||
for(int i = 0; i < IndexCount/(3); i++){
|
||||
Vector3f[] points = new Vector3f[3];
|
||||
for(int j = 0; j < 3; j++){
|
||||
int Start = (i * 3) + j;
|
||||
int elementOffset = FullMeshIndexArr[Start] * vertexStride;
|
||||
points[j] = new Vector3f(
|
||||
(FullMeshFloatArr[elementOffset]),
|
||||
(FullMeshFloatArr[elementOffset + 1]),
|
||||
(FullMeshFloatArr[elementOffset + 2])
|
||||
);
|
||||
}
|
||||
AddNewCollisionPoly(points[0],points[1],points[2]);
|
||||
}
|
||||
}
|
||||
|
||||
public void CheckAABbounds(Vector3f v1, Vector3f v2, Vector3f v3){
|
||||
float localMinX = Math.min(v1.x, Math.min(v2.x, v3.x));
|
||||
float localMinY = Math.min(v1.y, Math.min(v2.y, v3.y));
|
||||
float localMinZ = Math.min(v1.z, Math.min(v2.z, v3.z));
|
||||
float localMaxX = Math.max(v1.x, Math.max(v2.x, v3.x));
|
||||
float localMaxY = Math.max(v1.y, Math.max(v2.y, v3.y));
|
||||
float localMaxZ = Math.max(v1.z, Math.max(v2.z, v3.z));
|
||||
TopRightFront.x = Math.max(TopRightFront.x, localMaxX);
|
||||
TopRightFront.y = Math.max(TopRightFront.y, localMaxY);
|
||||
TopRightFront.z = Math.max(TopRightFront.z, localMaxZ);
|
||||
BottomLeftBack.x = Math.min(BottomLeftBack.x, localMinX);
|
||||
BottomLeftBack.y = Math.min(BottomLeftBack.y, localMinY);
|
||||
BottomLeftBack.z = Math.min(BottomLeftBack.z, localMinZ);
|
||||
}
|
||||
|
||||
public void GenerateSensorsFromVertices(){
|
||||
if(Actor.Actors.get(ParentID) != null &&Actor.Actors.get(ParentID).PhysicsType == Actor.PhysicsControllerType.T4JLegacyCollision) {
|
||||
LegacyPhysicsController physicsController = (LegacyPhysicsController)Actor.Actors.get(ParentID).GetPhysicsController();
|
||||
physicsController.collisionSensors.clear();
|
||||
for(int i = 0; i < Vertices.size(); i++){
|
||||
physicsController.AddCollisionSensor(Vertices.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void AddNewCollisionPoly(Vector3f v1, Vector3f v2, Vector3f v3){
|
||||
Vector3f[] vertices = new Vector3f[]{v1,v2,v3};
|
||||
int[] Index = new int[3];
|
||||
for(int i = 0; i < 3; i++) {
|
||||
String Vertex = vertices[i].x + "_" + vertices[i].y + "_" + vertices[i].z;
|
||||
Index[i] = Vertices.size();
|
||||
if (VertexLookup.containsKey(Vertex)) {
|
||||
Index[i] = VertexLookup.get(Vertex);
|
||||
} else {
|
||||
Vertices.add(new Vector3f(vertices[i]));
|
||||
VertexLookup.put(Vertex, Index[i]);
|
||||
}
|
||||
}
|
||||
CollisionIndexPoly newPoly = new CollisionIndexPoly(Index[0],Index[1],Index[2]);
|
||||
Polygons.add(newPoly);
|
||||
CheckAABbounds(v1,v2,v3);
|
||||
}
|
||||
|
||||
public boolean CheckAABBCollisionAgainstAABB(Vector3f inTopLeftFront, Vector3f inBottomRightBack){
|
||||
AABBf OtherVoxel = new AABBf(inBottomRightBack,inTopLeftFront);
|
||||
Vector3f TLF = new Vector3f(TopRightFront);
|
||||
Vector3f BRB = new Vector3f(BottomLeftBack);
|
||||
TLF = TLF.mul(Scale).rotate(Rotation).add(WorldPosition);
|
||||
BRB = BRB.mul(Scale).rotate(Rotation).add(WorldPosition);
|
||||
AABBf ThisVoxel = new AABBf(BRB,TLF);
|
||||
this.Voxel = ThisVoxel;
|
||||
return ThisVoxel.intersectsAABB(OtherVoxel);
|
||||
}
|
||||
|
||||
public boolean CheckAABBCollisionAgainstAABB(AABBf OtherVoxel){
|
||||
Vector3f PivotOffset = Actor.Actors.get(ParentID) != null ? new Vector3f(Actor.Actors.get(ParentID).GetPivotOffset()).add(Actor.Actors.get(ParentID).GetAditionalPivotOffset()) : new Vector3f(0,0,0);
|
||||
Vector3f TLF = new Vector3f(TopRightFront);
|
||||
Vector3f BRB = new Vector3f(BottomLeftBack);
|
||||
TLF = TLF.add(PivotOffset).rotate(Rotation).sub(PivotOffset).mul(Scale).add(WorldPosition);
|
||||
BRB = BRB.add(PivotOffset).rotate(Rotation).sub(PivotOffset).mul(Scale).add(WorldPosition);
|
||||
AABBf ThisVoxel = new AABBf(BRB,TLF);
|
||||
this.Voxel = ThisVoxel;
|
||||
return ThisVoxel.intersectsAABB(OtherVoxel);
|
||||
}
|
||||
|
||||
public boolean CheckAABCollision(Vector3f Origin, Vector3f Sensor){
|
||||
Vector3f LineDirection = new Vector3f(Sensor).sub(Origin);
|
||||
Vector2f Result = new Vector2f();
|
||||
Vector3f TLF = new Vector3f(TopRightFront);
|
||||
Vector3f BRB = new Vector3f(BottomLeftBack);
|
||||
TLF = TLF.mul(Scale).rotate(Rotation).add(WorldPosition);
|
||||
BRB = BRB.mul(Scale).rotate(Rotation).add(WorldPosition);
|
||||
AABBf ThisVoxel = new AABBf(BRB,TLF);
|
||||
return Intersectionf.intersectRayAab(Origin, LineDirection,BRB,TLF,Result) && Result.x <= 1.0f && Result.y >= 0.0f;
|
||||
}
|
||||
|
||||
public boolean SimpleCheckCollision(Vector3f Origin, Vector3f Sensor){
|
||||
Vector3f LineDirection = new Vector3f(Sensor).sub(Origin);
|
||||
Vector2f Result = new Vector2f(0,0);
|
||||
CollisionPoly[] polygons = GetAllPolygons();
|
||||
if(Intersectionf.intersectRayAab(Origin, LineDirection, BottomLeftBack, TopRightFront,Result) && Result.x <= 1.0f && Result.y >= 0.0f){
|
||||
for (CollisionPoly polygon : polygons) {
|
||||
if (T4Math.Math3D.DoesLineCollideWithPoly(Origin, Sensor, new Vector3f[]{polygon.v1(), polygon.v2(), polygon.v3()})) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Vector3f[] GetTransformedVertices(int[] index){
|
||||
Vector3f PivotOffset = Actor.Actors.get(ParentID) != null ? new Vector3f(Actor.Actors.get(ParentID).GetPivotOffset()).add(Actor.Actors.get(ParentID).GetAditionalPivotOffset()) : new Vector3f(0,0,0);
|
||||
Vector3f[] vertices = new Vector3f[index.length];
|
||||
Vector3f Vertex = new Vector3f();
|
||||
for(int i = 0; i < vertices.length; i++) {
|
||||
if (index[i] < Vertices.size() && Vertices.get(index[i]) != null) {
|
||||
Vertex.set((Vertices.get(index[i])));
|
||||
Vertex.add(PivotOffset).rotate(Rotation).sub(PivotOffset).mul(Scale).add(WorldPosition);
|
||||
vertices[i] = new Vector3f(Vertex);
|
||||
}
|
||||
}
|
||||
return vertices;
|
||||
}
|
||||
|
||||
public Vector3f[] GetUntransformedVertices(int[] index){
|
||||
Vector3f[] vertices = new Vector3f[index.length];
|
||||
Vector3f Vertex = new Vector3f();
|
||||
for(int i = 0; i < vertices.length; i++) {
|
||||
if (index[i] < Vertices.size() && Vertices.get(index[i]) != null) {
|
||||
Vertex.set((Vertices.get(index[i])));
|
||||
vertices[i] = new Vector3f(Vertex);
|
||||
}
|
||||
}
|
||||
return vertices;
|
||||
}
|
||||
|
||||
public Vector3f GetTransformedVertex(int index){
|
||||
Vector3f PivotOffset = Actor.Actors.get(ParentID) != null ? new Vector3f(Actor.Actors.get(ParentID).GetPivotOffset()).add(Actor.Actors.get(ParentID).GetAditionalPivotOffset()) : new Vector3f(0,0,0);
|
||||
if(index > Vertices.size() || index < 0) return null;
|
||||
Vector3f Vertex = new Vector3f(Vertices.get(index));
|
||||
Vertex.add(PivotOffset).rotate(Rotation).sub(PivotOffset).mul(Scale).add(WorldPosition);
|
||||
return Vertex;
|
||||
}
|
||||
|
||||
public CollisionPoly[] GetAllPolygons(){
|
||||
int Rows = Polygons.size();
|
||||
CollisionPoly[] PolygonArr = new CollisionPoly[Rows * 3];
|
||||
Vector3f PivotOffset = Actor.Actors.get(ParentID) != null ? new Vector3f(Actor.Actors.get(ParentID).GetPivotOffset()).add(Actor.Actors.get(ParentID).GetAditionalPivotOffset()) : new Vector3f(0,0,0);
|
||||
for(int row = 0; row < Rows; row++){
|
||||
CollisionIndexPoly IndexPoly = Polygons.get(row);
|
||||
CollisionPoly CollisionPoly = IndexPoly.GetRawCollisionPoly(this);
|
||||
PolygonArr[row] = CollisionPoly.TransformPosition(PivotOffset).TransformRotation(Rotation).TransformPosition(PivotOffset.negate()).TransformScale(Scale).TransformPosition(WorldPosition);
|
||||
}
|
||||
return PolygonArr;
|
||||
}
|
||||
|
||||
public Vector3f[] GetAllVertices(){
|
||||
Vector3f PivotOffset = Actor.Actors.get(ParentID) != null ? new Vector3f(Actor.Actors.get(ParentID).GetPivotOffset()).add(Actor.Actors.get(ParentID).GetAditionalPivotOffset()) : new Vector3f(0,0,0);
|
||||
Vector3f[] vertices = new Vector3f[Vertices.size()];
|
||||
Vector3f Vertex = new Vector3f();
|
||||
for(int i = 0; i < vertices.length; i++) {
|
||||
if (Vertices.get(i) != null) {
|
||||
Vertex.set((Vertices.get(i)));
|
||||
Vertex.add(PivotOffset).rotate(Rotation).sub(PivotOffset).mul(Scale).add(WorldPosition);
|
||||
vertices[i] = new Vector3f(Vertex);
|
||||
}
|
||||
}
|
||||
return vertices;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,76 +0,0 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Logic.Physics.LegacyCollision;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Util.Maths.T4Math;
|
||||
import org.joml.Math;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
public record CollisionPoly(Vector3f v1, Vector3f v2, Vector3f v3, Vector3f Centre) {
|
||||
public Vector3f CalculateCentre(){
|
||||
float x = v1.x + v2.x + v3.x;
|
||||
float y = v1.y + v2.y + v3.y;
|
||||
float z = v1.z + v2.z + v3.z;
|
||||
x/=3f;
|
||||
y/=3f;
|
||||
z/=3f;
|
||||
Centre.set(new Vector3f(x,y,z));
|
||||
return Centre;
|
||||
}
|
||||
public Vector3f[] GetVertices(){return new Vector3f[]{v1,v2,v3};}
|
||||
public CollisionPoly TransformRotation(Quaternionf quaternionf){
|
||||
if(quaternionf == null ) return this;
|
||||
Vector3f newV1 = new Vector3f(v1);
|
||||
newV1.rotate(quaternionf);
|
||||
Vector3f newV2 = new Vector3f(v2);
|
||||
newV2.rotate(quaternionf);
|
||||
Vector3f newV3 = new Vector3f(v3);
|
||||
newV3.rotate(quaternionf);
|
||||
CollisionPoly newPoly = new CollisionPoly(newV1,newV2,newV3,new Vector3f());
|
||||
newPoly.CalculateCentre();
|
||||
return newPoly;
|
||||
}
|
||||
public CollisionPoly TransformScale(Vector3f Scale){
|
||||
if(Scale == null ) return this;
|
||||
Vector3f newV1 = new Vector3f(v1);
|
||||
newV1.mul(Scale);
|
||||
Vector3f newV2 = new Vector3f(v2);
|
||||
newV2.mul(Scale);
|
||||
Vector3f newV3 = new Vector3f(v3);
|
||||
newV3.mul(Scale);
|
||||
CollisionPoly newPoly = new CollisionPoly(newV1,newV2,newV3,new Vector3f());
|
||||
newPoly.CalculateCentre();
|
||||
return newPoly;
|
||||
}
|
||||
public CollisionPoly TransformPosition(Vector3f Position){
|
||||
if(Position == null ) return this;
|
||||
Vector3f newV1 = new Vector3f(v1);
|
||||
newV1.add(Position);
|
||||
Vector3f newV2 = new Vector3f(v2);
|
||||
newV2.add(Position);
|
||||
Vector3f newV3 = new Vector3f(v3);
|
||||
newV3.add(Position);
|
||||
CollisionPoly newPoly = new CollisionPoly(newV1,newV2,newV3,new Vector3f());
|
||||
newPoly.CalculateCentre();
|
||||
return newPoly;
|
||||
}
|
||||
public static CollisionPoly TransformPosition(Vector3f Position, CollisionPoly OriginalPoly){
|
||||
Vector3f newV1 = new Vector3f(OriginalPoly.v1).add(Position);
|
||||
Vector3f newV2 = new Vector3f(OriginalPoly.v2).add(Position);
|
||||
Vector3f newV3 = new Vector3f(OriginalPoly.v3).add(Position);
|
||||
CollisionPoly newPoly = new CollisionPoly(newV1,newV2,newV3,new Vector3f());
|
||||
newPoly.CalculateCentre();
|
||||
return newPoly;
|
||||
}
|
||||
public Vector3f CalculateNormal(){
|
||||
Vector3f U = new Vector3f(v2.sub(v1));
|
||||
Vector3f V = new Vector3f(v3.sub(v1));
|
||||
|
||||
Vector3f N = new Vector3f(U.mul(V));
|
||||
float Nx = (U.x * V.z) - (U.z * V.y);
|
||||
float Ny = (U.z * V.x) - (U.x * V.z);
|
||||
float Nz = (U.x * V.y) - (U.y * V.x);
|
||||
|
||||
float Length = (float) Math.sqrt(T4Math.Square(Nx)+T4Math.Square(Ny)+T4Math.Square(Nz));
|
||||
return new Vector3f(Nx/Length, Ny/Length, Nz/Length);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,343 +0,0 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Logic.Physics;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.LegacyCollision.CollisionManager;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.LegacyCollision.CollisionMesh;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.LegacyCollision.CollisionPoly;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.Actor;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Util.Maths.T4Math;
|
||||
import org.joml.Vector2f;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static net.halbear.Terrain4J.EngineCore.Logic.Physics.LegacyCollision.CollisionManager.ChunkWidth;
|
||||
import static net.halbear.Terrain4J.EngineCore.Main.Util.Maths.T4Math.Physics.*;
|
||||
|
||||
public class LegacyPhysicsController implements IPhysicsController {
|
||||
|
||||
public enum CollisionType{
|
||||
PolyToPoly,
|
||||
Sensor
|
||||
}
|
||||
|
||||
|
||||
public List<CollisionSensor> collisionSensors;
|
||||
public Vector3f Velocities = new Vector3f(0,0,0);
|
||||
public Vector3f WeightBalance = new Vector3f(0,0,0);
|
||||
public float MassKG = 10.0f;
|
||||
public Vector3f TerminalVelocitiesMS = new Vector3f(36f,6.6f,36f);
|
||||
public Vector3f Drag = new Vector3f(0.2f,0.2f,0.2f);
|
||||
public Vector3f DragCoefficients = new Vector3f(0.1f,0.1f,0.1f);
|
||||
public Vector3f CrossSectionAreas = new Vector3f(1.8f * 0.9f, 0.6f * 0.9f, 1.8f * 0.6f);
|
||||
public Vector3f WeightDistribution = new Vector3f(2.0f,5.0f,7.0f);
|
||||
public float FallingAcceleration = 0.0f;
|
||||
public float Bounciness = 0.3f;
|
||||
String CurrentChunkPosition = "NULL";
|
||||
public CollisionType MeshCollision;
|
||||
|
||||
private final Vector3f Velocity = new Vector3f();
|
||||
private final Vector3f Position = new Vector3f();
|
||||
private final Vector3f NextPosition = new Vector3f();
|
||||
private final Vector3f localVelocityStep = new Vector3f();
|
||||
private final Vector3f displacement = new Vector3f();
|
||||
private final Vector3f slidingCorrection = new Vector3f();
|
||||
private final Vector3f sensorSubtraction = new Vector3f();
|
||||
private final Vector3f pivotOffsetCache = new Vector3f();
|
||||
|
||||
private final List<Vector3f> transformedSensorsCache = new ArrayList<>();
|
||||
|
||||
public final List<String> Collisions = new ArrayList<>();
|
||||
|
||||
//public record CollisionResult(boolean Intersects,Vector3f StartPoint,Vector3f EndPoint){
|
||||
//
|
||||
//}
|
||||
public static class CollisionResult{
|
||||
public boolean Intersects = false;
|
||||
public Vector3f StartPoint = null;
|
||||
public Vector3f EndPoint = null;
|
||||
public Vector3f CollisionNormal = null;
|
||||
public float CollisionDepth;
|
||||
}
|
||||
|
||||
public void SetCollisionType(CollisionType collisionType){
|
||||
this.MeshCollision = collisionType;
|
||||
}
|
||||
public CollisionType GetCollisionType(){return MeshCollision;}
|
||||
|
||||
public final String ID;
|
||||
public final String ParentID;
|
||||
|
||||
public void ImpulseVelocity(Vector3f Velocity){
|
||||
Velocities.add(Velocity);
|
||||
}
|
||||
|
||||
public LegacyPhysicsController(String ActorID, CollisionType collisionType){
|
||||
MeshCollision = collisionType;
|
||||
collisionSensors = new ArrayList<>();
|
||||
ID = ActorID + "_PHYSICS_CONTROLLER";
|
||||
ParentID = ActorID;
|
||||
WorldPhysicsManager.PhysicsObjects.put(ID, this);
|
||||
WorldPhysicsManager.ActiveControllers.add(ID);
|
||||
Actor actor = Actor.Actors.get(ParentID);
|
||||
Vector3f WorldPos = new Vector3f(actor.GetPosition()).div(ChunkWidth);
|
||||
WorldPos.x = (int)Math.floor(WorldPos.x);
|
||||
WorldPos.y = (int)Math.floor(WorldPos.y);
|
||||
WorldPos.z = (int)Math.floor(WorldPos.z);
|
||||
CurrentChunkPosition = WorldPos.x + ":" + WorldPos.y + ":" + WorldPos.z;
|
||||
DragCoefficients = CalculateDragCoefficients(TerminalVelocitiesMS, MassKG,CrossSectionAreas, actor.GetScale());
|
||||
}
|
||||
|
||||
public LegacyPhysicsController AddCollisionSensor(Vector3f RelativeOffset){
|
||||
collisionSensors.add(new CollisionSensor(RelativeOffset, ParentID));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean ApplyRotationalForce() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String ID() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String ActorID() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String MeshID() {
|
||||
return "";
|
||||
}
|
||||
|
||||
//aaaaand i give up on this system, time to attempt something completely different
|
||||
public void PhysicsTick(float DeltaTime, float TargetFrameRate){
|
||||
Actor actor = Actor.Actors.get(ParentID);
|
||||
if (actor == null) return;
|
||||
|
||||
Position.set(actor.GetPosition());
|
||||
NextPosition.set(Position);
|
||||
|
||||
localVelocityStep.set(Velocities).mul(DeltaTime);
|
||||
NextPosition.add(localVelocityStep);
|
||||
|
||||
boolean ValidMovement = true;
|
||||
Vector3f scale = new Vector3f(1,1,1);
|
||||
Drag = CalculateDrag(TerminalVelocitiesMS, DragCoefficients,CrossSectionAreas, scale);
|
||||
FallingAcceleration = CalculateFallSpeed(MassKG, Drag, scale);
|
||||
|
||||
Velocities.y -= (FallingAcceleration / (TargetFrameRate * 2f)) * DeltaTime;
|
||||
|
||||
float dragFactor = 1f - (WorldPhysicsManager.Drag * DeltaTime);
|
||||
Velocities.set(Velocities.x * dragFactor, Velocities.y, Velocities.z * dragFactor);
|
||||
|
||||
List<CollisionMesh> CollisionMeshesToCycleThrough = CollisionManager.GetAllCollisionMeshes();
|
||||
if (MeshCollision == CollisionType.Sensor && collisionSensors != null && !collisionSensors.isEmpty()) {
|
||||
ValidMovement = CalculateSensorCollision(CollisionMeshesToCycleThrough, actor);
|
||||
} else if (MeshCollision == CollisionType.PolyToPoly) {
|
||||
ValidMovement = CalculateMeshCollision(CollisionMeshesToCycleThrough, actor);
|
||||
}
|
||||
|
||||
actor.SetPosition(NextPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> Collisions() {
|
||||
return Collisions;
|
||||
}
|
||||
|
||||
public boolean CalculateMeshCollision(List<CollisionMesh> CollisionMeshesToCycleThrough, Actor actor){
|
||||
float skinThickness = 0.001f;
|
||||
CollisionMesh thisCollisionMesh = actor.GetCollisionMesh();
|
||||
// Logger.debug("POLY TO POLY");
|
||||
if (thisCollisionMesh == null) return false;
|
||||
|
||||
CollisionPoly[] thisPolygons = thisCollisionMesh.GetAllPolygons();
|
||||
boolean hasCollidedThisFrame = false;
|
||||
for (int i = 0; i < CollisionMeshesToCycleThrough.size(); i++) {
|
||||
CollisionMesh collisionMesh = CollisionMeshesToCycleThrough.get(i);
|
||||
|
||||
if (collisionMesh != null &&
|
||||
!Objects.equals(collisionMesh.ID, thisCollisionMesh.ID) && !Collisions.contains(collisionMesh.ID) &&
|
||||
collisionMesh.CheckAABBCollisionAgainstAABB(thisCollisionMesh.GetVoxelCollider())) {
|
||||
CollisionPoly[] polygons = collisionMesh.GetAllPolygons();
|
||||
|
||||
for (int k = 0; k < thisPolygons.length; k++) {
|
||||
for (int j = 0; j < polygons.length; j++) {
|
||||
|
||||
CollisionResult result = T4Math.ComplexCollision.ComputePolyToPolyIntersection(thisPolygons[k], polygons[j]);
|
||||
|
||||
if (result != null && result.Intersects) {
|
||||
hasCollidedThisFrame = true;
|
||||
Collisions.add(collisionMesh.ID);
|
||||
|
||||
float totalPushDistance = result.CollisionDepth + skinThickness;
|
||||
displacement.set(result.CollisionNormal).mul(totalPushDistance);
|
||||
if(result.CollisionDepth < 0.01f) {
|
||||
NextPosition.set(Position).add(0,displacement.y,0);
|
||||
}
|
||||
float velocityAlongNormal = Velocities.dot(result.CollisionNormal);
|
||||
// if (velocityAlongNormal < 0) {
|
||||
// slidingCorrection.set(result.CollisionNormal).mul(velocityAlongNormal);
|
||||
// Velocities.sub(slidingCorrection);
|
||||
// Velocities.mul(0.98f); // Apply wall friction sliding damping
|
||||
// }
|
||||
Velocities.mul(result.CollisionNormal).mul(Bounciness);
|
||||
// thisCollisionMesh.updatePositionContext(NextPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return !hasCollidedThisFrame;
|
||||
|
||||
|
||||
/*float skinThickness = 0.001f;
|
||||
float totalPushDistance = 0;
|
||||
Vector3f displacement = new Vector3f();
|
||||
Vector3f slidingCorrection = new Vector3f();
|
||||
CollisionMesh thisCollisionMesh = actor.GetCollisionMesh();
|
||||
boolean ValidMovement = true;
|
||||
if(thisCollisionMesh == null) return false;
|
||||
CollisionPoly[] thisPolygons = thisCollisionMesh.GetAllPolygons();
|
||||
for (int i = 0; i < CollisionMeshesToCycleThrough.size(); i++) {
|
||||
CollisionMesh collisionMesh = CollisionMeshesToCycleThrough.get(i);
|
||||
if (collisionMesh != null && !Objects.equals(collisionMesh.ID, thisCollisionMesh.ID) && collisionMesh.CheckAABBCollisionAgainstAABB(thisCollisionMesh.GetVoxelCollider())) {
|
||||
CollisionPoly[] polygons = collisionMesh.GetAllPolygons();
|
||||
for(int k = 0; k < thisPolygons.length; k++) {
|
||||
for (int j = 0; j < polygons.length; j++) {
|
||||
CollisionResult result = T4Math.ComplexCollision.ComputePolyToPolyIntersection(thisPolygons[k], polygons[j]);
|
||||
if(result != null && result.Intersects){
|
||||
totalPushDistance = result.CollisionDepth + skinThickness;
|
||||
displacement.set(result.CollisionNormal).mul(totalPushDistance);
|
||||
float velocityAlongNormal = Velocities.dot(result.CollisionNormal);
|
||||
if(velocityAlongNormal < 0){
|
||||
slidingCorrection.set(result.CollisionNormal).mul(velocityAlongNormal);
|
||||
Velocities.sub(slidingCorrection);
|
||||
Velocities.mul(0.98f);
|
||||
}
|
||||
//Velocities.y = -Velocities.y * Bounciness;//Velocities.mul(result.CollisionNormal).mul(Bounciness);
|
||||
Logger.debug(displacement + "<- DISPLACEMENT " + NextPosition + "<- NEXTPOS " + Position + "<- POS");
|
||||
NextPosition.add(displacement);
|
||||
ValidMovement = false;
|
||||
}
|
||||
if (!ValidMovement) break;
|
||||
}
|
||||
if (!ValidMovement) break;
|
||||
}
|
||||
}
|
||||
if (!ValidMovement) break;
|
||||
}
|
||||
return ValidMovement;*/
|
||||
}
|
||||
|
||||
public void CollisionEvent(CollisionMesh collidingMesh, Vector3f PositionDifference, Vector2f CollisionScale){
|
||||
Collisions.add(collidingMesh.ID);
|
||||
if (Math.abs(PositionDifference.x) > 0.01f && Math.abs(PositionDifference.z) > 0.01f) {
|
||||
NextPosition.add(PositionDifference);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean CalculateSensorCollision(List<CollisionMesh> CollisionMeshesToCycleThrough, Actor actor){
|
||||
boolean hasCollidedThisFrame = false;
|
||||
|
||||
Actor parentActor = Actor.Actors.get(ParentID);
|
||||
if (parentActor != null) {
|
||||
pivotOffsetCache.set(parentActor.GetPivotOffset()).add(parentActor.GetAditionalPivotOffset());
|
||||
} else {
|
||||
pivotOffsetCache.set(0, 0, 0);
|
||||
}
|
||||
|
||||
while (transformedSensorsCache.size() < collisionSensors.size()) {
|
||||
transformedSensorsCache.add(new Vector3f());
|
||||
}
|
||||
for (int j = 0; j < collisionSensors.size(); j++) {
|
||||
transformedSensorsCache.get(j).set(collisionSensors.get(j).GetTransformedCollisionSensor());
|
||||
}
|
||||
Vector2f CollisionScale = new Vector2f();
|
||||
for (int i = 0; i < CollisionMeshesToCycleThrough.size(); i++) {
|
||||
CollisionMesh collisionMesh = CollisionMeshesToCycleThrough.get(i);
|
||||
|
||||
if (collisionMesh != null &&
|
||||
!Objects.equals(collisionMesh.ID, actor.GetCollisionMesh().ID) && !Collisions.contains(collisionMesh.ID)&&
|
||||
collisionMesh.CheckAABBCollisionAgainstAABB(actor.GetCollisionMesh().GetVoxelCollider())) {
|
||||
|
||||
CollisionPoly[] polygons = collisionMesh.GetAllPolygons();
|
||||
|
||||
for (int j = 0; j < polygons.length; j++) {
|
||||
CollisionPoly poly = polygons[j];
|
||||
if (poly == null) continue;
|
||||
|
||||
for (int k = 0; k < collisionSensors.size(); k++) {
|
||||
|
||||
Vector3f CollisionPoint = T4Math.Math3D.LineCollisionPointWithPoly(
|
||||
NextPosition, transformedSensorsCache.get(k), poly.GetVertices(),CollisionScale);
|
||||
|
||||
if (CollisionPoint != null) {
|
||||
hasCollidedThisFrame = true;
|
||||
|
||||
sensorSubtraction.set(NextPosition).sub(CollisionPoint);
|
||||
if (Math.abs(sensorSubtraction.x) > 0.01f && Math.abs(sensorSubtraction.z) > 0.01f) {
|
||||
NextPosition.sub(sensorSubtraction);
|
||||
} else {
|
||||
NextPosition.sub(0, sensorSubtraction.y, 0);
|
||||
}
|
||||
Collisions.add(collisionMesh.ID);
|
||||
if(collisionMesh.ParentID != "NULL" && Actor.Actors.get(collisionMesh.ParentID) != null){
|
||||
Actor.Actors.get(collisionMesh.ParentID).GetPhysicsController().CollisionEvent(Actor.Actors.get(ParentID).GetCollisionMesh(),sensorSubtraction,CollisionScale);
|
||||
}
|
||||
Velocities.y = -Velocities.y * Bounciness;
|
||||
if (Math.abs(Velocities.y) < 0.05f) {
|
||||
Velocities.y = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return !hasCollidedThisFrame;
|
||||
|
||||
/*boolean ValidMovement = true;
|
||||
Vector3f PivotOffset = Actor.Actors.get(ParentID) != null ? new Vector3f(Actor.Actors.get(ParentID).GetPivotOffset()).add(Actor.Actors.get(ParentID).GetAditionalPivotOffset()) : new Vector3f(0, 0, 0);
|
||||
List<Vector3f> CollidingSensors = new ArrayList<>();
|
||||
for (int j = 0; j < collisionSensors.size(); j++) {
|
||||
CollidingSensors.add(new Vector3f().set(collisionSensors.get(j).GetTransformedCollisionSensor()));
|
||||
}
|
||||
Vector3f Subtraction = new Vector3f();
|
||||
if (!CollidingSensors.isEmpty()) {
|
||||
for (int i = 0; i < CollisionMeshesToCycleThrough.size(); i++) {
|
||||
CollisionMesh collisionMesh = CollisionMeshesToCycleThrough.get(i);
|
||||
if (collisionMesh != null && !Objects.equals(collisionMesh.ID, actor.GetCollisionMesh().ID) && collisionMesh.CheckAABBCollisionAgainstAABB(actor.GetCollisionMesh().GetVoxelCollider())) {
|
||||
CollisionPoly[] polygons = collisionMesh.GetAllPolygons();
|
||||
for (int j = 0; j < polygons.length; j++) {
|
||||
CollisionPoly poly = polygons[j];
|
||||
if (poly != null) {
|
||||
for (int k = 0; k < CollidingSensors.size(); k++) {
|
||||
Vector3f CollisionPoint = T4Math.Math3D.LineCollisionPointWithPoly(NextPosition, CollidingSensors.get(k), new Vector3f[]{poly.v1(), poly.v2(), poly.v3()});
|
||||
if (CollisionPoint != null) {
|
||||
Subtraction.set(NextPosition).sub(CollisionPoint);
|
||||
if (Math.abs(Subtraction.x) > 0.1f && Math.abs(Subtraction.z) > 0.1f) {
|
||||
NextPosition.sub(Subtraction);
|
||||
} else {
|
||||
NextPosition.sub(0, Subtraction.y, 0);
|
||||
}
|
||||
Velocities.y = -Velocities.y * Bounciness;
|
||||
if (Math.abs(Velocities.y) < 0.05f) Velocities.y = 0;
|
||||
ValidMovement = false;
|
||||
}
|
||||
if (!ValidMovement) break;
|
||||
}
|
||||
}
|
||||
if (!ValidMovement) break;
|
||||
}
|
||||
}
|
||||
if (!ValidMovement) break;
|
||||
}
|
||||
}
|
||||
return ValidMovement;*/
|
||||
}
|
||||
}
|
||||
|
|
@ -114,7 +114,7 @@ public class ConvexMesh {
|
|||
|
||||
int[][] e = {{0,1},{1,2},{2,3},{3,0},{4,5},{5,6},{6,7},{7,4},{0,4},{1,5},{2,6},{3,7}};
|
||||
mesh.Edges.addAll(Arrays.asList(e));
|
||||
if(!PrimaryRuntime.Server && !RenderThread.Headless) {
|
||||
if(!PrimaryRuntime.IsServer && !RenderThread.Headless) {
|
||||
PrimaryRuntime.GetEngineInstance().scene().AddActor(new VisualisedCollisionActor("VISUALISEDACTOR" + mesh.MeshID.toString(), mesh.Position, mesh.MeshID));
|
||||
}
|
||||
return mesh;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Logic.Physics.RigidBody;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.IPhysicsController;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.LegacyPhysicsController;
|
||||
import org.joml.Matrix3f;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
|
|
|
|||
|
|
@ -1,20 +1,16 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Logic.Physics.RigidBody;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.LegacyCollision.CollisionMesh;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.IPhysicsController;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.WorldPhysicsManager;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.PrimaryRuntime;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.Actor;
|
||||
import net.halbear.Terrain4J.EngineCore.ServerNetworking.ClientSideNetworkUtils;
|
||||
import net.halbear.Terrain4J.EngineCore.Threads.ClientConnectionThread;
|
||||
import org.joml.Vector2f;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static net.halbear.Terrain4J.EngineCore.Logic.Physics.RigidBody.RigidBody.RigidBodies;
|
||||
import static net.halbear.Terrain4J.EngineCore.Logic.Physics.RigidBody.RigidBody.RigidBodyRegister;
|
||||
import static net.halbear.Terrain4J.EngineCore.Main.Util.Maths.T4Math.Physics.CalculateDrag;
|
||||
import static net.halbear.Terrain4J.EngineCore.Main.Util.Maths.T4Math.Physics.CalculateFallSpeed;
|
||||
|
||||
public class RigidPhysicsController implements IPhysicsController {
|
||||
|
||||
|
|
@ -105,11 +101,11 @@ public class RigidPhysicsController implements IPhysicsController {
|
|||
public void PhysicsTick(float DeltaTime, float TargetFrameRate) {
|
||||
Actor actor = Actor.Actors.get(ActorID);
|
||||
|
||||
if(!PrimaryRuntime.Server
|
||||
&& ClientConnectionThread.Connected
|
||||
if(!PrimaryRuntime.IsServer
|
||||
&& ClientSideNetworkUtils.Connected
|
||||
&& actor != null
|
||||
&& actor.IsServerSynced()
|
||||
&& !ActorID.equals(ClientConnectionThread.OwnedActorID)) {
|
||||
&& !ClientSideNetworkUtils.OwnsActor(ActorID)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -121,7 +117,7 @@ public class RigidPhysicsController implements IPhysicsController {
|
|||
rigidBody.Integrate(DeltaTime, new Vector3f(0,-1.8f,0));
|
||||
if(Actor.Actors.get(ActorID) != null) {
|
||||
Actor.Actors.get(ActorID).SetPosition(new Vector3f(rigidBody.Position));
|
||||
if(ApplyRotation) Actor.Actors.get(ActorID).SetRotation(rigidBody.Rotation);
|
||||
if(ApplyRotation && Actor.Actors.get(ActorID) != null) Actor.Actors.get(ActorID).SetRotation(rigidBody.Rotation);
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
|
@ -149,8 +145,4 @@ public class RigidPhysicsController implements IPhysicsController {
|
|||
return Collisions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void CollisionEvent(CollisionMesh collidingMesh, Vector3f PositionDifference, Vector2f CollisionScale) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
|
|||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.RigidBody.*;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.PrimaryRuntime;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.Actor;
|
||||
import net.halbear.Terrain4J.EngineCore.ServerNetworking.ClientSideNetworkUtils;
|
||||
import net.halbear.Terrain4J.EngineCore.Threads.ClientConnectionThread;
|
||||
import net.halbear.Terrain4J.EngineCore.Threads.InstancedPhysicsThread;
|
||||
import org.joml.Vector2f;
|
||||
|
|
@ -30,6 +31,7 @@ public class WorldPhysicsManager {
|
|||
private static boolean SingleThread = false;
|
||||
private static List<InstancedPhysicsThread> physicsThreads = new ArrayList<>();
|
||||
|
||||
@Deprecated
|
||||
public static void SteppedPhysicsTick(float DeltaTime, float TargetFrameTime){
|
||||
int ThreadsNeeded = (int)Math.floor(ActiveControllers.size()/100f);
|
||||
SingleThread = ThreadsNeeded <= 1;
|
||||
|
|
@ -63,6 +65,7 @@ public class WorldPhysicsManager {
|
|||
// }
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void SteppedPhysicsTick2(float DeltaTime, float TargetFrameTime){
|
||||
DeltaTime *= EngineConfig.getInstance().PhysicsSpeed();
|
||||
if(EngineConfig.getInstance().IsEngineThrottled()) return;
|
||||
|
|
@ -88,6 +91,7 @@ public class WorldPhysicsManager {
|
|||
PhysicsObjects.get(ActiveControllers.get(i)).Collisions().clear();
|
||||
}
|
||||
}
|
||||
|
||||
private static void ResolveAllCollisions() {
|
||||
List<String> ids = RigidBody.RigidBodies;
|
||||
|
||||
|
|
@ -135,7 +139,7 @@ public class WorldPhysicsManager {
|
|||
}
|
||||
|
||||
private static boolean IsClientRemoteNetworkBody(RigidBody body) {
|
||||
if (PrimaryRuntime.Server || !ClientConnectionThread.Connected || body == null) {
|
||||
if (PrimaryRuntime.IsServer || !ClientSideNetworkUtils.Connected || body == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -146,7 +150,7 @@ public class WorldPhysicsManager {
|
|||
Actor actor = GetActorForRigidBody(body);
|
||||
return actor != null
|
||||
&& actor.IsServerSynced()
|
||||
&& !actor.GetID().equals(ClientConnectionThread.OwnedActorID);
|
||||
&& !actor.GetID().equals(ClientSideNetworkUtils.OwnedActorID);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -204,6 +208,7 @@ public class WorldPhysicsManager {
|
|||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private static void SyncRigidBodiesToActors(){
|
||||
for (int i = 0; i < ActiveControllers.size(); i++) {
|
||||
IPhysicsController controller = PhysicsObjects.get(ActiveControllers.get(i));
|
||||
|
|
@ -214,10 +219,10 @@ public class WorldPhysicsManager {
|
|||
|
||||
if(actor == null || body == null) continue;
|
||||
|
||||
if(!PrimaryRuntime.Server
|
||||
&& ClientConnectionThread.Connected
|
||||
if(!PrimaryRuntime.IsServer
|
||||
&& ClientSideNetworkUtils.Connected
|
||||
&& actor.IsServerSynced()
|
||||
&& !actor.GetID().equals(ClientConnectionThread.OwnedActorID)) {
|
||||
&& !actor.GetID().equals(ClientSideNetworkUtils.OwnedActorID)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,11 +5,11 @@ import com.beust.jcommander.Parameter;
|
|||
import com.beust.jcommander.ParameterException;
|
||||
import com.google.gson.FieldNamingPolicy;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.VkModel.MaterialData;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.VkModel.MeshData;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.VkModel.ModelBinaryData;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.VkModel.ModelData;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Util.VulkanUtils;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.VkModel.MaterialData;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.VkModel.MeshData;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.VkModel.ModelBinaryData;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.VkModel.ModelData;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Util.VulkanUtils;
|
||||
import org.joml.Vector4f;
|
||||
import org.lwjgl.PointerBuffer;
|
||||
import org.lwjgl.assimp.*;
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ package net.halbear.Terrain4J.EngineCore.Logic.Rendering;
|
|||
|
||||
import com.google.gson.FieldNamingPolicy;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.VkModel.MaterialData;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.VkModel.ModelData;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.VkModel.MaterialData;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.VkModel.ModelData;
|
||||
import org.tinylog.Logger;
|
||||
|
||||
import java.nio.file.Files;
|
||||
|
|
@ -28,7 +28,7 @@ public class ModelLoader { // Model Utility class kinda like a model version of
|
|||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
Logger.debug("Loaded Material Data: [{}]", Result.toString());
|
||||
//Logger.debug("Loaded Material Data: [{}]", Result.toString());
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
|
@ -42,7 +42,7 @@ public class ModelLoader { // Model Utility class kinda like a model version of
|
|||
}catch(Exception e){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
Logger.debug("Loaded Material Data: [{}]",Result.toString());
|
||||
//Logger.debug("Loaded Material Data: [{}]",Result.toString());
|
||||
return Result;
|
||||
}
|
||||
public static ModelData LoadModel(String Path){
|
||||
|
|
|
|||
|
|
@ -2,14 +2,14 @@ package net.halbear.Terrain4J.EngineCore.Logic.Rendering;
|
|||
|
||||
import net.halbear.Terrain4J.EngineCore.Display.Window;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Pipeline.PipelineCache;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Shader.DescriptorAllocator;
|
||||
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.DisplayToScreen.Surface;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.SwapChain.SwapChain;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.VulkanInstance;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Util.VulkanMemoryAllocator;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Pipeline.PipelineCache;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Shader.DescriptorAllocator;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DeviceLayers.Device;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DeviceLayers.PhysicalDevice;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DisplayToScreen.Surface;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.SwapChain.SwapChain;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.VulkanInstance;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Util.VulkanMemoryAllocator;
|
||||
import org.tinylog.Logger;
|
||||
|
||||
public class VulkanContext {
|
||||
|
|
|
|||
|
|
@ -11,12 +11,10 @@ import net.halbear.Terrain4J.EngineCore.Audio.SoundListener;
|
|||
import net.halbear.Terrain4J.EngineCore.Display.Window;
|
||||
import net.halbear.Terrain4J.EngineCore.Input.KeyboardInput;
|
||||
import net.halbear.Terrain4J.EngineCore.Input.MouseListener;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.LegacyCollision.CollisionMesh;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineInstance;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.GameLogic;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.InitData;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.LegacyPhysicsController;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.RigidBody.ConvexMesh;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.RigidBody.RigidBody;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.RigidBody.RigidPhysicsController;
|
||||
|
|
@ -26,27 +24,24 @@ import net.halbear.Terrain4J.EngineCore.Main.Scene.*;
|
|||
import net.halbear.Terrain4J.EngineCore.Main.Scene.GUIs.*;
|
||||
import net.halbear.Terrain4J.EngineCore.Profiling.CPUMonitor;
|
||||
import net.halbear.Terrain4J.EngineCore.Profiling.GPUProfiler;
|
||||
import net.halbear.Terrain4J.EngineCore.ServerNetworking.ClientSideNetworkUtils;
|
||||
import net.halbear.Terrain4J.EngineCore.ServerNetworking.ServerSideNetworkUtils;
|
||||
import net.halbear.Terrain4J.EngineCore.Threads.ClientConnectionThread;
|
||||
import net.halbear.Terrain4J.EngineCore.Threads.RenderThread;
|
||||
import net.halbear.Terrain4J.EngineCore.Threads.ServerConnectionThread;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.GUI.GuiTexture;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.VkModel.MaterialData;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.VkModel.ModelData;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DisplayToScreen.ForwardSceneRender;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.GUI.GuiTexture;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.VkModel.MaterialData;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.VkModel.ModelData;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DisplayToScreen.ForwardSceneRender;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Vector2f;
|
||||
import org.joml.Vector3f;
|
||||
import org.lwjgl.openal.AL11;
|
||||
import org.tinylog.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.lwjgl.glfw.GLFW.*;
|
||||
|
||||
public class GameCore implements GameLogic {
|
||||
|
||||
private static final float MOUSE_SENSITIVITY = 0.1f;
|
||||
|
|
@ -114,11 +109,20 @@ public class GameCore implements GameLogic {
|
|||
|
||||
String texturePath = "resources/EngineResources/Texture/Terrain4JTitleImage.png";
|
||||
|
||||
for(int i = 0; i < 200; i++) {
|
||||
int TestSpriteCount = 0;
|
||||
|
||||
for(int i = 0; i < TestSpriteCount; i++) {
|
||||
float height = 16 + (float)(128f* Math.random());
|
||||
scene.AddSprite(new Sprite("Title" + i, texturePath, new Vector2f(3440.0f * (float) Math.random(), 1440.0f * (float) Math.random()), new Vector2f(height,height), new Vector2f(1,1)));
|
||||
scene.AddSprite(
|
||||
new SpriteVk("Title" + i,
|
||||
texturePath,
|
||||
new Vector2f(3440.0f * (float) Math.random(), 1440.0f * (float) Math.random()), //position
|
||||
new Vector2f(1,1), //size (width is modified to respect the aspect ratio of the image)
|
||||
new Vector2f(height,height)) // scale
|
||||
.SetCameraZValue(1-(16/height))
|
||||
);
|
||||
}
|
||||
boolean createOfflinePlayer = !PrimaryRuntime.Server && !ClientConnectionThread.Connected;
|
||||
boolean createOfflinePlayer = !PrimaryRuntime.IsServer && !ClientSideNetworkUtils.Connected;
|
||||
|
||||
materials.addAll(MelonaMat);
|
||||
materials.addAll(CollisionVisualisationMat);
|
||||
|
|
@ -138,7 +142,7 @@ public class GameCore implements GameLogic {
|
|||
|
||||
List<GuiTexture> guiTextures = new ArrayList<>();
|
||||
|
||||
if(!PrimaryRuntime.Server && !RenderThread.Headless) {
|
||||
if(!PrimaryRuntime.IsServer && !RenderThread.Headless) {
|
||||
var LoadingScreenTexture = new GuiTexture(EngineConfig.getInstance().GetLoadingScreenImageLocation());
|
||||
loadingScreen = new LoadingScreen(LoadingScreenTexture);
|
||||
|
||||
|
|
@ -165,7 +169,7 @@ public class GameCore implements GameLogic {
|
|||
for(int i = 0; i < ActorEditorComponents.size(); i++){
|
||||
ActorEditorComponents.get(i).UpdateAll();
|
||||
}
|
||||
if(PrimaryRuntime.Server) {
|
||||
if(PrimaryRuntime.IsServer) {
|
||||
for (int x = -5; x < 6; x++) {
|
||||
for (int y = -5; y < 6; y++) {
|
||||
SpawnNewStaticActor(engineInstance, new Vector3f(x * 4f, -4 * (float) Math.random(), y * 4f), new Vector3f(0, 0, 0), new Vector3f(1, 1, 1));
|
||||
|
|
@ -175,11 +179,16 @@ public class GameCore implements GameLogic {
|
|||
SpawnNewActor(engineInstance, new Vector3f(-5 + (float)Math.random() * 10,10 + (float)Math.random() * 10, -5 + (float)Math.random() * 10), new Vector3f(0, 0, 0), new Vector3f(1, 1, 1));
|
||||
}
|
||||
}
|
||||
Settings.textBuffer.set(ClientConnectionThread.ServerIP);
|
||||
Settings.textBuffer.set(ClientSideNetworkUtils.ServerIP);
|
||||
Settings.UsernameBuffer.set("Player");
|
||||
return new InitData(models,materials,guiTextures);
|
||||
}
|
||||
|
||||
public void Reset(){
|
||||
EngineInstance instance = PrimaryRuntime.GetEngineInstance();
|
||||
instance.scene().Reset();
|
||||
}
|
||||
|
||||
private static final Vector3f SpawnPosition = new Vector3f();
|
||||
private static final Vector3f SpawnDirection = new Vector3f();
|
||||
private static final Matrix4f rotationMatrix = new Matrix4f();
|
||||
|
|
@ -207,8 +216,8 @@ public class GameCore implements GameLogic {
|
|||
|
||||
scene.AddActor(Melona);
|
||||
|
||||
if(PrimaryRuntime.Server) {
|
||||
ServerConnectionThread.BroadcastCreateActorPacket(Melona);
|
||||
if(PrimaryRuntime.IsServer) {
|
||||
ServerSideNetworkUtils.BroadcastCreateActorPacket(Melona);
|
||||
}
|
||||
|
||||
RigidPhysicsController physicsController = (RigidPhysicsController) Melona.GetPhysicsController();
|
||||
|
|
@ -239,6 +248,7 @@ public class GameCore implements GameLogic {
|
|||
RigidBody.RigidBodyRegister.get(physicsController.RigidBodyID).LockRotation();
|
||||
|
||||
scene.AddActor(player);
|
||||
scene.NetworkedActors().add(player.GetID());
|
||||
return player;
|
||||
}
|
||||
|
||||
|
|
@ -255,8 +265,8 @@ public class GameCore implements GameLogic {
|
|||
Melona.CreatePhysicsController( ConvexMesh.Box(0.5f,0.5f,0.5f),20);
|
||||
Melona.SetServerSynced(true);
|
||||
|
||||
if(PrimaryRuntime.Server) {
|
||||
ServerConnectionThread.BroadcastCreateActorPacket(Melona);
|
||||
if(PrimaryRuntime.IsServer) {
|
||||
ServerSideNetworkUtils.BroadcastCreateActorPacket(Melona);
|
||||
}
|
||||
|
||||
RigidPhysicsController physicsController = (RigidPhysicsController) Melona.GetPhysicsController();
|
||||
|
|
@ -280,18 +290,18 @@ public class GameCore implements GameLogic {
|
|||
}
|
||||
|
||||
private void InitiateAudio(EngineInstance engineInstance) {
|
||||
if (RenderThread.Headless || PrimaryRuntime.Server) return;
|
||||
if (RenderThread.Headless || PrimaryRuntime.IsServer) return;
|
||||
AudioManager audioManager = engineInstance.audioManager();
|
||||
Camera camera = engineInstance.scene().GetCamera();
|
||||
audioManager.SetAttenuationModel(AL11.AL_EXPONENT_DISTANCE);
|
||||
audioManager.SetListener(new SoundListener(camera.GetPosition()));
|
||||
engineInstance.scene().SetUpAudio(engineInstance, audioManager);
|
||||
}
|
||||
public void SwitchBGM(EngineInstance engineInstance, Scene scene, String path) {
|
||||
AudioInstance bgm = scene.audioInstances.get("BGM");
|
||||
public void SwitchBGM(EngineInstance engineInstance, IScene scene, String path) {
|
||||
AudioInstance bgm = scene.audioInstances().get("BGM");
|
||||
if (bgm == null) {
|
||||
scene.SetUpAudio(engineInstance, engineInstance.audioManager());
|
||||
bgm = scene.audioInstances.get("BGM");
|
||||
bgm = scene.audioInstances().get("BGM");
|
||||
}
|
||||
bgm.Pause();
|
||||
bgm.ChangePath(path, engineInstance.audioManager());
|
||||
|
|
@ -300,7 +310,7 @@ public class GameCore implements GameLogic {
|
|||
|
||||
@Override
|
||||
public void CameraInput(EngineInstance engineInstance, long FrameDiffNanoSeconds) {
|
||||
if(PrimaryRuntime.Server || RenderThread.Headless || engineInstance.window() == null) {
|
||||
if(PrimaryRuntime.IsServer || RenderThread.Headless || engineInstance.window() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -328,10 +338,12 @@ public class GameCore implements GameLogic {
|
|||
engineInstance.audioManager().UpdateListenerPosition(camera);
|
||||
}
|
||||
|
||||
long CumulativeFrameTime = 0;
|
||||
@Override
|
||||
public void RenderThreadInput(EngineInstance engineInstance, long FrameDiffNanoSeconds) {
|
||||
if(ClientConnectionThread.Connected && !"NULL".equals(ClientConnectionThread.OwnedActorID)) {
|
||||
PlayerActorID = ClientConnectionThread.OwnedActorID;
|
||||
CumulativeFrameTime += FrameDiffNanoSeconds;
|
||||
if(ClientSideNetworkUtils.Connected && !"NULL".equals(ClientSideNetworkUtils.GetPlayerControlledActorID())) {
|
||||
PlayerActorID = ClientSideNetworkUtils.GetPlayerControlledActorID();
|
||||
}
|
||||
|
||||
Actor player = Actor.Actors.get(PlayerActorID);
|
||||
|
|
@ -343,12 +355,12 @@ public class GameCore implements GameLogic {
|
|||
if(actor != null
|
||||
&& actor.IsServerSynced()
|
||||
&& !actor.IsStaticRigidBody()
|
||||
&& !actor.GetID().equals(ClientConnectionThread.OwnedActorID)) {
|
||||
&& !actor.GetID().equals(ClientSideNetworkUtils.GetPlayerControlledActorID())) {
|
||||
actor.InterpolateNetworkTarget(0.12f);
|
||||
}
|
||||
}
|
||||
|
||||
if(PrimaryRuntime.Server || RenderThread.Headless) return;
|
||||
if(PrimaryRuntime.IsServer || RenderThread.Headless) return;
|
||||
engineInstance.scene().CameraTick(FrameDiffNanoSeconds);
|
||||
if(ChangeGraphicsSettings){
|
||||
if(NextAAMode != -1){
|
||||
|
|
@ -362,21 +374,25 @@ public class GameCore implements GameLogic {
|
|||
} else{
|
||||
LastFrameTime = System.nanoTime();
|
||||
}
|
||||
if(CumulativeFrameTime >= 16_000_000) {
|
||||
HandleGui(engineInstance, FrameDiffNanoSeconds);
|
||||
CumulativeFrameTime = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Input(EngineInstance engineInstance, long FrameDiffNanoSeconds) {
|
||||
if(PrimaryRuntime.Server || RenderThread.Headless) return;
|
||||
if(PrimaryRuntime.IsServer || RenderThread.Headless) return;
|
||||
|
||||
IScene scene = engineInstance.scene();
|
||||
scene.GlobalInput(engineInstance,FrameDiffNanoSeconds, null, MOVEMENT_SPEED,this);
|
||||
|
||||
if(ClientConnectionThread.Connected) {
|
||||
if("NULL".equals(ClientConnectionThread.OwnedActorID)) {
|
||||
if(ClientSideNetworkUtils.Connected) {
|
||||
if("NULL".equals(ClientSideNetworkUtils.GetPlayerControlledActorID())) {
|
||||
return;
|
||||
}
|
||||
|
||||
Actor ownedActor = Actor.Actors.get(ClientConnectionThread.OwnedActorID);
|
||||
Actor ownedActor = Actor.Actors.get(ClientSideNetworkUtils.GetPlayerControlledActorID());
|
||||
if(!(ownedActor instanceof PlayerActor networkPlayer)) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -388,7 +404,7 @@ public class GameCore implements GameLogic {
|
|||
}
|
||||
}
|
||||
|
||||
PlayerActorID = ClientConnectionThread.OwnedActorID;
|
||||
PlayerActorID = ClientSideNetworkUtils.GetPlayerControlledActorID();
|
||||
// Logger.trace(
|
||||
// "Input using network player [{}], camera [{}]",
|
||||
// networkPlayer.GetID(),
|
||||
|
|
@ -407,7 +423,7 @@ public class GameCore implements GameLogic {
|
|||
}
|
||||
|
||||
private boolean HandleGui(EngineInstance engineInstance, long frameTimeNS){
|
||||
if(PrimaryRuntime.Server || RenderThread.Headless) return false;
|
||||
if(PrimaryRuntime.IsServer || RenderThread.Headless) return false;
|
||||
FetchingMetrics = true;
|
||||
ImGuiIO imGuiIO = ImGui.getIO();
|
||||
MouseListener mouseListener = engineInstance.window().getMouseInput();
|
||||
|
|
@ -415,11 +431,11 @@ public class GameCore implements GameLogic {
|
|||
imGuiIO.addMousePosEvent(mousePosition.x,mousePosition.y);
|
||||
imGuiIO.addMouseButtonEvent(0,mouseListener.isLeftButtonPressed());
|
||||
imGuiIO.addMouseButtonEvent(1,mouseListener.isRightButtonPressed());
|
||||
KeyboardInput input = engineInstance.window().getKeyboardInput();
|
||||
int windowFlags = ImGuiWindowFlags.NoDecoration
|
||||
| ImGuiWindowFlags.AlwaysAutoResize
|
||||
| ImGuiWindowFlags.NoSavedSettings
|
||||
| ImGuiWindowFlags.NoFocusOnAppearing
|
||||
| ImGuiWindowFlags.NoNav
|
||||
| ImGuiWindowFlags.NoMove;
|
||||
ImGui.newFrame();
|
||||
if(LoadingLevel){
|
||||
|
|
@ -452,7 +468,7 @@ public class GameCore implements GameLogic {
|
|||
|
||||
@Override
|
||||
public void Update(EngineInstance engineInstance, long FrameDiffNanoSeconds) {
|
||||
if(!PrimaryRuntime.Server && !RenderThread.Headless) {
|
||||
if(!PrimaryRuntime.IsServer && !RenderThread.Headless) {
|
||||
for (int i = 0; i < VisualisedCollisionActor.CollisionVisuals.size(); i++) {
|
||||
VisualisedCollisionActor.CollisionVisuals.get(i).Update();
|
||||
}
|
||||
|
|
@ -468,43 +484,45 @@ public class GameCore implements GameLogic {
|
|||
float PhysicsFramerate = 24f;
|
||||
float PhysicsFrameTime = 1000f/PhysicsFramerate;
|
||||
float DeltaTime = (float)FrameDiffNanoSeconds/(PhysicsFrameTime*1000000f);
|
||||
if(PrimaryRuntime.Server){
|
||||
Server.CollectIncomingPackets();
|
||||
Server.ProcessIncomingPackets();
|
||||
if(PrimaryRuntime.IsServer){
|
||||
Server.LegacyCollectIncomingPackets();
|
||||
Server.LegacyProcessIncomingPackets();
|
||||
|
||||
WorldPhysicsManager.PhysicsTick2(DeltaTime, PhysicsFramerate);
|
||||
|
||||
if(PrimaryRuntime.GetFastThread().Ticks(6) == 0) {
|
||||
for(Actor actor : engineInstance.scene().GetActors()) {
|
||||
if(actor.IsServerSynced() && !actor.IsStaticRigidBody()) {
|
||||
ServerConnectionThread.SendEntityUpdatePacket(actor);
|
||||
ServerSideNetworkUtils.SendEntityUpdatePacket(actor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Server.ProcessOutgoingPackets();
|
||||
Server.LegacyProcessOutgoingPackets();
|
||||
} else {
|
||||
ClientConnectionThread.DecodePackets(engineInstance, this, engineInstance.scene());
|
||||
ClientSideNetworkUtils.DecodePackets(engineInstance, this, engineInstance.scene());
|
||||
WorldPhysicsManager.PhysicsTick2(DeltaTime, PhysicsFramerate);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void SecondUpdate(EngineInstance engineInstance) {
|
||||
if(PrimaryRuntime.Server || RenderThread.Headless) return;
|
||||
if(PrimaryRuntime.IsServer || RenderThread.Headless || PrimaryRuntime.GetRenderThread() == null) return;
|
||||
SettingPerformanceMetrics.clear();
|
||||
List<String[]> Metrics = new ArrayList<>();
|
||||
String[] ISceneDetails = new String[8];
|
||||
String[] ISceneDetails = new String[9];
|
||||
Vector3f Position = engineInstance.scene().GetCamera().GetPosition();
|
||||
Vector2f Position2D = engineInstance.scene().Get2DCamera().GetPosition();
|
||||
Vector3f Rotation = engineInstance.scene().GetCamera().GetRotation();
|
||||
ISceneDetails[0] = String.format("INSTANCE INFORMATION: ");
|
||||
ISceneDetails[1] = String.format(" Camera Position: X: %.2f Y: %.2f Z: %.2f",Position.x ,Position.y ,Position.z);
|
||||
ISceneDetails[2] = String.format(" Camera Rotation: X: %.2f° Y: %.2f° Z: %.2f°",Rotation.x *EngineConfig.RadToDeg,Rotation.y *EngineConfig.RadToDeg ,Rotation.z *EngineConfig.RadToDeg);
|
||||
ISceneDetails[3] = String.format(" Anti Aliasing: " + EngineConfig.getInstance().RenderAAType().name());
|
||||
ISceneDetails[4] = String.format(" Renderer: " + (PrimaryRuntime.GetRenderThread().GetRenderer().GetDeferred() ? " Deferred" : "Forward"));
|
||||
ISceneDetails[5] = String.format(" Pipeline: " + (ForwardSceneRender.DualPassRendering() ? " Dual Pass" : "Single Pass"));
|
||||
ISceneDetails[6] = String.format(" AlphaToCoverage: " + EngineConfig.getInstance().AlphaToCoverage());
|
||||
ISceneDetails[7] = String.format(" FOV: %.2f°",(EngineConfig.getInstance().GetFOV()*EngineConfig.RadToDeg));
|
||||
ISceneDetails[2] = String.format(" 2DCamera Position: X: %.2f Y: %.2f",Position2D.x ,Position2D.y);
|
||||
ISceneDetails[3] = String.format(" Camera Rotation: X: %.2f° Y: %.2f° Z: %.2f°",Rotation.x *EngineConfig.RadToDeg,Rotation.y *EngineConfig.RadToDeg ,Rotation.z *EngineConfig.RadToDeg);
|
||||
ISceneDetails[4] = String.format(" Anti Aliasing: " + EngineConfig.getInstance().RenderAAType().name());
|
||||
ISceneDetails[5] = String.format(" Renderer: " + (!RenderThread.AllowRender() ? "NO RENDERER" : (PrimaryRuntime.GetRenderThread().GetRenderer().GetDeferred() ? " Deferred" : "Forward")));
|
||||
ISceneDetails[6] = String.format(" Pipeline: " + (ForwardSceneRender.DualPassRendering() ? " Dual Pass" : "Single Pass"));
|
||||
ISceneDetails[7] = String.format(" AlphaToCoverage: " + EngineConfig.getInstance().AlphaToCoverage());
|
||||
ISceneDetails[8] = String.format(" FOV: %.2f°",(EngineConfig.getInstance().GetFOV()*EngineConfig.RadToDeg));
|
||||
String[] DeviceInfo = new String[5];
|
||||
DeviceInfo[0] = String.format("SYSTEM INFORMATION: ");
|
||||
DeviceInfo[1] = String.format(" CPU: " + EngineConfig.getInstance().GetCPUDetails());
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Main;
|
||||
|
||||
import net.halbear.Executable.Server;
|
||||
import net.halbear.Terrain4J.EngineCore.Audio.AudioManager;
|
||||
import net.halbear.Terrain4J.EngineCore.Display.Window;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
|
||||
|
|
@ -9,12 +10,14 @@ import net.halbear.Terrain4J.EngineCore.Logic.InitData;
|
|||
import net.halbear.Terrain4J.EngineCore.Logic.Rendering.VulkanContext;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.Scene;
|
||||
import net.halbear.Terrain4J.EngineCore.Profiling.CPUMonitor;
|
||||
import net.halbear.Terrain4J.EngineCore.ServerNetworking.ClientSideNetworkUtils;
|
||||
import net.halbear.Terrain4J.EngineCore.Threads.ClientConnectionThread;
|
||||
import net.halbear.Terrain4J.EngineCore.Threads.FastTickThread;
|
||||
import net.halbear.Terrain4J.EngineCore.Threads.MainThread;
|
||||
import net.halbear.Terrain4J.EngineCore.Threads.RenderThread;
|
||||
import org.tinylog.Logger;
|
||||
|
||||
import java.io.Console;
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
|
|
@ -22,11 +25,14 @@ import java.net.URL;
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Scanner;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import static net.halbear.Terrain4J.EngineCore.Logic.EngineConfig.RenderAPI.OpenGL;
|
||||
|
||||
public class PrimaryRuntime {
|
||||
public static boolean Server = false;
|
||||
public static boolean IsServer = false;
|
||||
private int Frames = 0;
|
||||
private int TickFrames = 0;
|
||||
private double TickRate = 0;
|
||||
|
|
@ -46,7 +52,7 @@ public class PrimaryRuntime {
|
|||
private static GameLogic gameLogic;
|
||||
|
||||
public static ClientConnectionThread ServerCon;
|
||||
public static Thread ServerThread;
|
||||
public static Thread MultiplayerConnectionThread;
|
||||
public static GameLogic GetGameCore(){return gameLogic;}
|
||||
|
||||
public PrimaryRuntime(String windowTitle, GameLogic appLogic) {
|
||||
|
|
@ -64,7 +70,7 @@ public class PrimaryRuntime {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (Server) {
|
||||
if (IsServer) {
|
||||
window = null;
|
||||
gameLogic = appLogic;
|
||||
engineInstance = new EngineInstance(null, new Scene(null), this, null);
|
||||
|
|
@ -77,25 +83,39 @@ public class PrimaryRuntime {
|
|||
InitData initData = appLogic.Initialise(engineInstance);
|
||||
PrimaryThread = new MainThread(engineInstance, appLogic);
|
||||
FastThread = new FastTickThread(engineInstance, appLogic);
|
||||
DrawingThread = new RenderThread(window, engineInstance, initData, appLogic);
|
||||
cpuProfiler = new CPUMonitor();
|
||||
if(!Server) {
|
||||
if(!IsServer) {
|
||||
ServerCon = new ClientConnectionThread();
|
||||
ServerThread = new Thread(ServerCon);
|
||||
ServerThread.start();
|
||||
MultiplayerConnectionThread = new Thread(ServerCon);
|
||||
MultiplayerConnectionThread.start();
|
||||
DrawingThread = new RenderThread(engineInstance, initData, appLogic);
|
||||
}
|
||||
cpuProfiler = new CPUMonitor();
|
||||
EngineConfig.getInstance().SetCPU(CPUMonitor.getCpuName(), CPUMonitor.getCoreCount());
|
||||
Thread.currentThread().setName("Terrain4J Primary Runtime Thread");
|
||||
}
|
||||
|
||||
public static void RejoinMultiplayer(){
|
||||
MultiplayerConnectionThread.interrupt();
|
||||
try{
|
||||
MultiplayerConnectionThread.join();
|
||||
} catch (InterruptedException e){
|
||||
Logger.error("Cant rejoin multiplayer thread: [{}]",e.getMessage());
|
||||
}
|
||||
ServerCon = new ClientConnectionThread();
|
||||
MultiplayerConnectionThread = new Thread(ServerCon);
|
||||
MultiplayerConnectionThread.start();
|
||||
}
|
||||
|
||||
public static void StartPingTimer() {
|
||||
Timer timer = new Timer();
|
||||
ClientConnectionThread.pinging = true;
|
||||
ClientSideNetworkUtils.pinging = true;
|
||||
timer.scheduleAtFixedRate(new TimerTask() {;
|
||||
@Override
|
||||
public void run() {
|
||||
String text = "Pinging : " + PingServer(ClientConnectionThread.ServerIP, false);
|
||||
if (ClientConnectionThread.Connected){
|
||||
ClientConnectionThread.pinging = false;
|
||||
String text = "Pinging : " + PingServer(ClientSideNetworkUtils.ServerIP, false);
|
||||
Logger.debug(text);
|
||||
if (ClientSideNetworkUtils.Connected || !running){
|
||||
ClientSideNetworkUtils.pinging = false;
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
|
|
@ -115,19 +135,19 @@ public class PrimaryRuntime {
|
|||
return "Client Problem, Check Internet Connection";
|
||||
}
|
||||
if (responseCode >= 500) {
|
||||
return "Server Problem, Unable To Connect";
|
||||
return "IsServer Problem, Unable To Connect";
|
||||
} else return "Online";
|
||||
} catch ( MalformedURLException e) {
|
||||
//System.out.println(e);
|
||||
//Logger.debug(e);
|
||||
return "Bad URL";
|
||||
} catch ( IOException e ) {
|
||||
//System.out.println(e);
|
||||
return "Connection Error, Server Unreachable";
|
||||
//Logger.debug(e);
|
||||
return "Connection Error, IsServer Unreachable";
|
||||
}
|
||||
} else if (!ClientConnectionThread.Connected) {
|
||||
} else if (!ClientSideNetworkUtils.Connected) {
|
||||
ServerCon = new ClientConnectionThread();
|
||||
ServerThread = new Thread(ServerCon);
|
||||
ServerThread.start();
|
||||
MultiplayerConnectionThread = new Thread(ServerCon);
|
||||
MultiplayerConnectionThread.start();
|
||||
|
||||
}
|
||||
return "Connecting...";
|
||||
|
|
@ -164,6 +184,19 @@ public class PrimaryRuntime {
|
|||
Logger.error(e, "Primary runtime input update failed");
|
||||
}
|
||||
}
|
||||
|
||||
private static final String RESET_LINE = "\r\033[K";
|
||||
private static final String PROMPT = "Next Command -> ";
|
||||
|
||||
public static synchronized void printLog(String message) {
|
||||
System.out.print(RESET_LINE);
|
||||
|
||||
System.out.println(message);
|
||||
|
||||
System.out.print(PROMPT);
|
||||
System.out.flush();
|
||||
}
|
||||
|
||||
public void run(){
|
||||
UpdateTickRateThreshold();
|
||||
|
||||
|
|
@ -175,18 +208,22 @@ public class PrimaryRuntime {
|
|||
OriginalFrameAccuracy = FrameAccuracy;
|
||||
Logger.debug("Primary Thread Started");
|
||||
|
||||
if(Server) {
|
||||
if(IsServer) {
|
||||
Logger.info("Terrain4J dedicated server running without GLFW/Vulkan/OpenAL");
|
||||
Console console = System.console();
|
||||
|
||||
System.out.println("=========================================");
|
||||
System.out.println(" Terrain4J Game Server ");
|
||||
System.out.println("=========================================");
|
||||
|
||||
printLog("\nServer Successfully Started, Type 'Help' on how to use the commands");
|
||||
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
|
||||
while(running) {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
break;
|
||||
Server.ProcessCommand(scanner.nextLine());
|
||||
}
|
||||
}
|
||||
|
||||
scanner.close();
|
||||
ShutDownStart = System.nanoTime();
|
||||
Logger.debug("Closing dedicated server [{}]", EngineConfig.getInstance().GetSoftwareName());
|
||||
FastThread.KillThread();
|
||||
|
|
@ -210,6 +247,14 @@ public class PrimaryRuntime {
|
|||
TickDiff += cycleDiff;
|
||||
SecondCounter += cycleDiff;
|
||||
if (FrameDiff >= FrameAccuracy){
|
||||
if(window.GetLinkedApi() != EngineConfig.getInstance().GetRenderingAPI()) {
|
||||
SwitchRenderAPI();
|
||||
continue;
|
||||
}
|
||||
if(window.GetLinkedApi() == OpenGL){
|
||||
window.pollOpenGLEvents();
|
||||
}
|
||||
|
||||
window.pollEvents();
|
||||
Frames++;
|
||||
if (TickDiff >= TickRate) {
|
||||
|
|
@ -232,9 +277,9 @@ public class PrimaryRuntime {
|
|||
}
|
||||
InitialTime = now;
|
||||
}
|
||||
ClientConnectionThread.Connected = false;
|
||||
if(ServerThread != null) {
|
||||
ServerThread.interrupt();
|
||||
ClientSideNetworkUtils.Connected = false;
|
||||
if(MultiplayerConnectionThread != null) {
|
||||
MultiplayerConnectionThread.interrupt();
|
||||
}
|
||||
|
||||
ShutDownStart = System.nanoTime();
|
||||
|
|
@ -245,6 +290,47 @@ public class PrimaryRuntime {
|
|||
cleanup();
|
||||
}
|
||||
|
||||
public static synchronized void PauseGameThreads() throws InterruptedException {
|
||||
// PrimaryThread.FetchThread().wait();
|
||||
// FastThread.FetchThread().wait();
|
||||
}
|
||||
|
||||
public static synchronized void ResumeGameThreads() {
|
||||
// PrimaryThread.FetchThread().notify();
|
||||
// FastThread.FetchThread().notify();
|
||||
}
|
||||
|
||||
public synchronized void SwitchRenderAPI(){
|
||||
InitData data = DrawingThread.GetInitData();
|
||||
RenderThread.AllowRender(false);
|
||||
try {
|
||||
PauseGameThreads();
|
||||
} catch (InterruptedException e) {
|
||||
Logger.error("Failed to pause game threads: " + e.getMessage());
|
||||
}
|
||||
DrawingThread.KillThread();
|
||||
try {
|
||||
Logger.debug("Joining Drawing Thread");
|
||||
DrawingThread.FetchThread().join();
|
||||
} catch (InterruptedException e) {
|
||||
Logger.error("Failed to wait for DrawingThread to terminate cleanly: " + e.getMessage());
|
||||
}
|
||||
Logger.debug("Joined Drawing Thread");
|
||||
DrawingThread.cleanup();
|
||||
Window oldWindow = window;
|
||||
window = Window.RefreshRendererAttachment(oldWindow);
|
||||
engineInstance = engineInstance.SetWindow(window);
|
||||
|
||||
if (window.GetLinkedApi() == OpenGL) {
|
||||
org.lwjgl.glfw.GLFW.glfwMakeContextCurrent(0);
|
||||
}
|
||||
|
||||
Logger.debug("Render API of new Window: " + window.GetLinkedApi() + " | Engine Instance Window API: " + engineInstance.window().GetLinkedApi());
|
||||
RenderThread.AllowRender(true);
|
||||
DrawingThread = new RenderThread(engineInstance,data,gameLogic);
|
||||
DrawingThread.StartThread();
|
||||
ResumeGameThreads();
|
||||
}
|
||||
|
||||
public static EngineInstance GetEngineInstance(){
|
||||
return engineInstance;
|
||||
|
|
@ -274,5 +360,6 @@ public class PrimaryRuntime {
|
|||
Logger.debug("Closing Primary Thread, Thread: [{}]",Thread.currentThread().toString());
|
||||
double ShutDownTime = Math.floor(((double)(System.nanoTime() - ShutDownStart)/1000000.0)*1000.0)/1000.0;
|
||||
Logger.info("Successful stable Shut Down of Terrain4J in [{}] MilliSeconds", ShutDownTime);
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,10 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Main.Scene;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.LegacyCollision.CollisionMesh;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.IPhysicsController;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.LegacyPhysicsController;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.RigidBody.ConvexMesh;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.RigidBody.RigidBody;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.RigidBody.RigidCollision;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.RigidBody.RigidPhysicsController;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.VkModel.ModelData;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.VkModel.ModelData;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
|
|
@ -36,7 +33,6 @@ public class Actor{
|
|||
protected final Vector3f Position;
|
||||
protected final Vector3f PositionOffset;
|
||||
protected final Quaternionf Rotation;
|
||||
protected CollisionMesh collisionMesh;
|
||||
protected Vector3f Scale;
|
||||
private IPhysicsController physicsController;
|
||||
protected final Vector3f PivotOffset;
|
||||
|
|
@ -52,9 +48,6 @@ public class Actor{
|
|||
this.PhysicsType = type;
|
||||
}
|
||||
|
||||
public CollisionMesh GetCollisionMesh(){
|
||||
return collisionMesh;
|
||||
}
|
||||
|
||||
public Actor(String ID, String ModelID, Vector3f Position){
|
||||
this.ID = ID;
|
||||
|
|
@ -148,17 +141,6 @@ public class Actor{
|
|||
return this;
|
||||
}
|
||||
|
||||
public Actor CreatePhysicsController(LegacyPhysicsController.CollisionType collisionType){
|
||||
physicsController = new LegacyPhysicsController(ID, collisionType);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Actor GenerateCollisionMesh(ModelData modelData) throws IOException {
|
||||
collisionMesh = new CollisionMesh(ID + "_COLLISION_MESH", ID);
|
||||
collisionMesh.GenerateCollisionMeshFromVulkanModel(modelData);
|
||||
collisionMesh.RegisterMesh();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Actor ResetRotation(){
|
||||
Rotation.x = 0;
|
||||
|
|
@ -197,7 +179,6 @@ public class Actor{
|
|||
public Actor SetPosition(Vector3f position){
|
||||
Position.set(position);
|
||||
UpdateModelMatrix();
|
||||
if(collisionMesh != null)collisionMesh.SetWorldPosition(Position);
|
||||
return this;
|
||||
}
|
||||
public Actor SetPosition(float x, float y, float z){
|
||||
|
|
@ -244,7 +225,6 @@ public class Actor{
|
|||
rigidBody.Position.set(Position);
|
||||
this.Position.set(Position);
|
||||
UpdateModelMatrix();
|
||||
if(collisionMesh != null) collisionMesh.SetWorldPosition(this.Position);
|
||||
}
|
||||
|
||||
private RigidBody GetRigidBody() {
|
||||
|
|
|
|||
|
|
@ -1,16 +1,11 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Main.Scene;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.IPhysicsController;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.LegacyCollision.CollisionMesh;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.LegacyPhysicsController;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.RigidBody.ConvexMesh;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.RigidBody.RigidPhysicsController;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.VkModel.ModelData;
|
||||
import org.joml.Matrix4f;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.VkModel.ModelData;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
|
@ -44,12 +39,6 @@ public class ActorElement extends Actor {
|
|||
public Actor CreatePhysicsController(ConvexMesh mesh, float Mass){
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
|
||||
public Actor CreatePhysicsController(LegacyPhysicsController.CollisionType collisionType){
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
|
||||
public Actor GenerateCollisionMesh(ModelData modelData) {
|
||||
return this;
|
||||
|
|
|
|||
|
|
@ -2,23 +2,35 @@ package net.halbear.Terrain4J.EngineCore.Main.Scene;
|
|||
|
||||
import org.joml.Vector2f;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Camera2D {
|
||||
public static final Map<String, Camera2D> CameraRegistry = new HashMap<>();
|
||||
|
||||
|
||||
private final Vector2f Position;
|
||||
private final Vector2f Rotation;
|
||||
private final Vector2f Scale;
|
||||
private final String ID;
|
||||
|
||||
public Camera2D(Vector2f position, Vector2f rotation) {
|
||||
public Camera2D(String ID,Vector2f position, Vector2f rotation) {
|
||||
this.ID = ID;
|
||||
Position = position;
|
||||
Rotation = rotation;
|
||||
Scale = new Vector2f(1.0f, 1.0f);
|
||||
CameraRegistry.put(ID, this);
|
||||
}
|
||||
|
||||
public Camera2D(){
|
||||
public Camera2D(String ID){
|
||||
Position = new Vector2f();
|
||||
this.ID = ID;
|
||||
Rotation = new Vector2f();
|
||||
Scale = new Vector2f(1.0f, 1.0f);
|
||||
CameraRegistry.put(ID, this);
|
||||
}
|
||||
|
||||
|
||||
public Vector2f GetScale() {
|
||||
return Scale;
|
||||
}
|
||||
|
|
@ -41,6 +53,11 @@ public class Camera2D {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Camera2D AddPosition(Vector2f offset) {
|
||||
SetPosition(Position.add(offset));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Camera2D SetPosition(Vector2f position) {
|
||||
Position.set(position);
|
||||
return this;
|
||||
|
|
|
|||
|
|
@ -32,11 +32,6 @@ public class EditorActorComponent implements IMoveableActorComponent{
|
|||
@Override
|
||||
public void UpdateAll() {
|
||||
actor.GetPosition().set(Position.x,Position.y,Position.z);
|
||||
if(actor.GetCollisionMesh() != null) {
|
||||
actor.GetCollisionMesh().SetWorldPosition(new Vector3f(Position.x,Position.y,Position.z));
|
||||
actor.GetCollisionMesh().SetRotationTransform(actor.GetRotation());
|
||||
actor.GetCollisionMesh().SetScaleTransform(actor.GetScale());
|
||||
}
|
||||
ActorGimbal.SetPosition(new Vector3f(Position.x, Position.y, Position.z).add(actor.GetPivotOffset()).add(actor.GetAditionalPivotOffset()));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Main.Scene.GUIs;
|
||||
|
||||
import imgui.ImDrawList;
|
||||
import imgui.ImGui;
|
||||
import imgui.ImGuiViewport;
|
||||
import imgui.ImVec2;
|
||||
|
|
@ -10,17 +9,9 @@ import imgui.flag.ImGuiStyleVar;
|
|||
import imgui.flag.ImGuiWindowFlags;
|
||||
import imgui.type.ImInt;
|
||||
import imgui.type.ImString;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineInstance;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.AudioInstance;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.GameCore;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.PrimaryRuntime;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.GUIOverlay;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.Scene;
|
||||
import net.halbear.Terrain4J.EngineCore.Threads.ClientConnectionThread;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DisplayToScreen.DeferredSceneRender;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DisplayToScreen.ForwardSceneRender;
|
||||
import org.tinylog.Logger;
|
||||
|
||||
public class CreditsMenu implements GUIOverlay {
|
||||
public int[] Music = new int[]{100};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,72 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Main.Scene.GUIs;
|
||||
|
||||
import imgui.ImGui;
|
||||
import imgui.flag.ImGuiChildFlags;
|
||||
import imgui.flag.ImGuiCond;
|
||||
import imgui.flag.ImGuiWindowFlags;
|
||||
import imgui.type.ImFloat;
|
||||
import imgui.type.ImString;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineInstance;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.GameCore;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.PrimaryRuntime;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.GUIOverlay;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DisplayToScreen.DeferredSceneRender;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DisplayToScreen.ForwardSceneRender;
|
||||
import net.halbear.Terrain4J.EngineCore.ServerNetworking.ClientSideNetworkUtils;
|
||||
import net.halbear.Terrain4J.EngineCore.Threads.ClientConnectionThread;
|
||||
import org.tinylog.Logger;
|
||||
|
||||
import java.nio.CharBuffer;
|
||||
|
||||
public class GameChat implements GUIOverlay {
|
||||
public static final ImString ChatBuffer = new ImString(128);
|
||||
public static boolean IsChatOpen = false;
|
||||
private int LastChatCount = 0;
|
||||
private static String CurrentChatMessage = "";
|
||||
public static String GetChatMessage(){
|
||||
return CurrentChatMessage;
|
||||
}
|
||||
|
||||
public static void SubmitChatMessage(){
|
||||
if(CurrentChatMessage.isBlank()) return;
|
||||
ClientSideNetworkUtils.CreateGameChatPacket(CurrentChatMessage);
|
||||
CurrentChatMessage = "";
|
||||
ChatBuffer.clear();
|
||||
IsChatOpen = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void RenderGUI(EngineInstance engineInstance, long frameTimeNS, GameCore parent) {
|
||||
int windowFlags = ImGuiWindowFlags.NoDecoration
|
||||
| ImGuiWindowFlags.AlwaysAutoResize
|
||||
| ImGuiWindowFlags.NoSavedSettings
|
||||
| ImGuiWindowFlags.NoFocusOnAppearing
|
||||
| ImGuiWindowFlags.NoMove;
|
||||
double FrameTimeMS = (frameTimeNS/1000000.0);
|
||||
double AverageGPUTimeMS = EngineConfig.LAST_AVERAGE_GPU_TIME/1000000.0;
|
||||
ImGui.setNextWindowPos(0,0, ImGuiCond.Always);
|
||||
//ImGui.setNextWindowSize(300,100);
|
||||
ImGui.begin("Game Chat",windowFlags);
|
||||
float width = ImGui.getIO().getDisplaySizeX();
|
||||
ImGui.beginChild("ScrollingRegion", width/5, 200, ImGuiChildFlags.None, ImGuiWindowFlags.HorizontalScrollbar);
|
||||
{
|
||||
ClientSideNetworkUtils.GameChats.forEach((Log, Username ) -> {
|
||||
ImGui.text((Log.FromServer() ? "" : Username +": ") + Log.message());
|
||||
});
|
||||
if(ClientSideNetworkUtils.GameChats.size() != LastChatCount){
|
||||
ImGui.setScrollHereY(1.0f);
|
||||
LastChatCount = ClientSideNetworkUtils.GameChats.size();
|
||||
}
|
||||
}
|
||||
if(IsChatOpen){
|
||||
if (ImGui.inputText("Chat", ChatBuffer)) {
|
||||
CurrentChatMessage = ChatBuffer.get();
|
||||
}
|
||||
} else{
|
||||
ImGui.text("Press T to type in chat");
|
||||
}
|
||||
ImGui.endChild();
|
||||
ImGui.end();
|
||||
}
|
||||
}
|
||||
|
|
@ -5,13 +5,8 @@ import imgui.ImGui;
|
|||
import imgui.ImVec2;
|
||||
import imgui.flag.ImGuiCol;
|
||||
import imgui.flag.ImGuiWindowFlags;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.LegacyCollision.CollisionManager;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.LegacyCollision.CollisionMesh;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.LegacyCollision.CollisionPoly;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineInstance;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.CollisionSensor;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.LegacyPhysicsController;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.GameCore;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.Actor;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.GUIOverlay;
|
||||
|
|
@ -25,6 +20,7 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Deprecated
|
||||
public class Gimbal implements GUIOverlay {
|
||||
private IMoveableActorComponent parent;
|
||||
public static Map<String, Gimbal> gimbalMap = new HashMap<>();
|
||||
|
|
@ -55,27 +51,6 @@ public class Gimbal implements GUIOverlay {
|
|||
|
||||
ImGui.begin("WorldSpaceUIOverlay", flags);
|
||||
ImGui.getStyle().setAntiAliasedLines(true);
|
||||
if(EngineConfig.getInstance().RenderCollisionMesh){
|
||||
List<CollisionMesh> meshes = CollisionManager.GetAllCollisionMeshes();
|
||||
for(int i = 0; i < meshes.size(); i++){
|
||||
CollisionMesh mesh = meshes.get(i);
|
||||
CollisionPoly[] polygons = mesh.GetAllPolygons();
|
||||
for(int j = 0; j < polygons.length; j++){
|
||||
DrawCollisionPolygon(engineInstance.scene().GetCamera().GetViewMatrix(), engineInstance.scene().GetProjection().GetProjectionMatrix(),winWidth,winHeight,polygons[j]);
|
||||
}
|
||||
if(mesh.ParentID != "NULL" && Actor.Actors.get(mesh.ParentID) != null) {
|
||||
Actor actor = Actor.Actors.get(mesh.ParentID);
|
||||
if(actor.PhysicsType == Actor.PhysicsControllerType.T4JLegacyCollision) {
|
||||
LegacyPhysicsController physicsController = (LegacyPhysicsController) actor.GetPhysicsController();
|
||||
List<CollisionSensor> RawCollisionSesnors = physicsController.collisionSensors;
|
||||
// Vector3f[] CollisionSensors = new Vector3f[RawCollisionSesnors.size()];
|
||||
for (int j = 0; j < RawCollisionSesnors.size(); j++) {
|
||||
DrawCollisionSensor(engineInstance.scene().GetCamera().GetViewMatrix(), engineInstance.scene().GetProjection().GetProjectionMatrix(), winWidth, winHeight, RawCollisionSesnors.get(j).GetTransformedCollisionSensor(), actor.GetPosition());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for(int i = 0; i < gimbals.size(); i++){
|
||||
gimbals.get(i).DrawGimbalInWorld(engineInstance.scene().GetCamera().GetViewMatrix(), engineInstance.scene().GetProjection().GetProjectionMatrix(),winWidth,winHeight);
|
||||
}
|
||||
|
|
@ -130,24 +105,24 @@ public class Gimbal implements GUIOverlay {
|
|||
drawList.addCircle(new ImVec2(v1.x,v1.y),6,colour,5f);
|
||||
}
|
||||
|
||||
public static void DrawCollisionPolygon(Matrix4f viewMatrix, Matrix4f projMatrix, int winWidth, int winHeight, CollisionPoly polygon){
|
||||
if(polygon == null || polygon.v1() == null || polygon.v2() == null || polygon.v3() == null) return;
|
||||
Vector3f v1 = T4Math.Math3D.GetScreenCoordFromWorldSpace(polygon.v1(), viewMatrix, projMatrix, winWidth, winHeight);
|
||||
Vector3f v2 = T4Math.Math3D.GetScreenCoordFromWorldSpace(polygon.v2(), viewMatrix, projMatrix, winWidth, winHeight);
|
||||
Vector3f v3 = T4Math.Math3D.GetScreenCoordFromWorldSpace(polygon.v3(), viewMatrix, projMatrix, winWidth, winHeight);
|
||||
if(v1 == null || v2 == null || v3 == null) return;
|
||||
ImDrawList drawList = ImGui.getBackgroundDrawList();
|
||||
int colour = ImGui.getColorU32(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
drawList.addLine(v1.x, v1.y, v2.x, v2.y, colour, 1f);
|
||||
drawList.addLine(v2.x, v2.y, v3.x, v3.y, colour, 1f);
|
||||
drawList.addLine(v3.x, v3.y, v1.x, v1.y, colour, 1f);
|
||||
colour = ImGui.getColorU32(0.0f, 0.4f, 1.0f, 0.1f);
|
||||
drawList.addTriangleFilled(
|
||||
new ImVec2(v1.x,v1.y),
|
||||
new ImVec2(v2.x,v2.y),
|
||||
new ImVec2(v3.x,v3.y)
|
||||
,colour);
|
||||
}
|
||||
// public static void DrawCollisionPolygon(Matrix4f viewMatrix, Matrix4f projMatrix, int winWidth, int winHeight, CollisionPoly polygon){
|
||||
// if(polygon == null || polygon.v1() == null || polygon.v2() == null || polygon.v3() == null) return;
|
||||
// Vector3f v1 = T4Math.Math3D.GetScreenCoordFromWorldSpace(polygon.v1(), viewMatrix, projMatrix, winWidth, winHeight);
|
||||
// Vector3f v2 = T4Math.Math3D.GetScreenCoordFromWorldSpace(polygon.v2(), viewMatrix, projMatrix, winWidth, winHeight);
|
||||
// Vector3f v3 = T4Math.Math3D.GetScreenCoordFromWorldSpace(polygon.v3(), viewMatrix, projMatrix, winWidth, winHeight);
|
||||
// if(v1 == null || v2 == null || v3 == null) return;
|
||||
// ImDrawList drawList = ImGui.getBackgroundDrawList();
|
||||
// int colour = ImGui.getColorU32(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
// drawList.addLine(v1.x, v1.y, v2.x, v2.y, colour, 1f);
|
||||
// drawList.addLine(v2.x, v2.y, v3.x, v3.y, colour, 1f);
|
||||
// drawList.addLine(v3.x, v3.y, v1.x, v1.y, colour, 1f);
|
||||
// colour = ImGui.getColorU32(0.0f, 0.4f, 1.0f, 0.1f);
|
||||
// drawList.addTriangleFilled(
|
||||
// new ImVec2(v1.x,v1.y),
|
||||
// new ImVec2(v2.x,v2.y),
|
||||
// new ImVec2(v3.x,v3.y)
|
||||
// ,colour);
|
||||
// }
|
||||
|
||||
public void DrawGimbalInWorld(Matrix4f viewMatrix, Matrix4f projMatrix, int winWidth, int winHeight) {
|
||||
Vector3f CentrePoint = new Vector3f(Position);
|
||||
|
|
|
|||
|
|
@ -1,22 +1,16 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Main.Scene.GUIs;
|
||||
|
||||
import imgui.ImDrawList;
|
||||
import imgui.ImGui;
|
||||
import imgui.ImGuiViewport;
|
||||
import imgui.flag.ImGuiCol;
|
||||
import imgui.flag.ImGuiCond;
|
||||
import imgui.flag.ImGuiWindowFlags;
|
||||
import imgui.type.ImFloat;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineInstance;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.GameCore;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.PrimaryRuntime;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.GUIOverlay;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.GUI.GuiTexture;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DisplayToScreen.DeferredSceneRender;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DisplayToScreen.ForwardSceneRender;
|
||||
import org.joml.Vector3f;
|
||||
import org.tinylog.Logger;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.GUI.GuiTexture;
|
||||
|
||||
public class LoadingScreen implements GUIOverlay {
|
||||
private final ImFloat GammaValue = new ImFloat(0.8545f);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package net.halbear.Terrain4J.EngineCore.Main.Scene.GUIs;
|
|||
|
||||
import imgui.ImGui;
|
||||
import imgui.flag.ImGuiCond;
|
||||
import imgui.flag.ImGuiInputTextFlags;
|
||||
import imgui.flag.ImGuiWindowFlags;
|
||||
import imgui.type.ImFloat;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
|
||||
|
|
@ -10,9 +9,8 @@ import net.halbear.Terrain4J.EngineCore.Logic.EngineInstance;
|
|||
import net.halbear.Terrain4J.EngineCore.Main.GameCore;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.PrimaryRuntime;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.GUIOverlay;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DisplayToScreen.DeferredSceneRender;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DisplayToScreen.ForwardSceneRender;
|
||||
import org.joml.Vector3f;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DisplayToScreen.DeferredSceneRender;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DisplayToScreen.ForwardSceneRender;
|
||||
import org.tinylog.Logger;
|
||||
|
||||
public class PerformanceOverlay implements GUIOverlay {
|
||||
|
|
@ -39,6 +37,16 @@ public class PerformanceOverlay implements GUIOverlay {
|
|||
ImGui.separator();
|
||||
ImGui.text("GRAPHICS SETTINGS:");
|
||||
ImGui.text(" ");
|
||||
ImGui.text("Rendering API:");
|
||||
if(ImGui.button("Vulkan")){
|
||||
Logger.debug("Switch to Vulkan");
|
||||
EngineConfig.getInstance().SetRenderingAPI(EngineConfig.RenderAPI.Vulkan);
|
||||
}
|
||||
ImGui.sameLine();
|
||||
if(ImGui.button("OpenGL")){
|
||||
Logger.debug("Switch to OpenGL");
|
||||
EngineConfig.getInstance().SetRenderingAPI(EngineConfig.RenderAPI.OpenGL);
|
||||
}
|
||||
ImGui.text("Presets:");
|
||||
if(ImGui.button("Lowest")){
|
||||
parent.ChangeGraphicsSettings = true;
|
||||
|
|
@ -47,7 +55,7 @@ public class PerformanceOverlay implements GUIOverlay {
|
|||
ForwardSceneRender.SetDualPassRendering(false);
|
||||
DeferredSceneRender.SetDualPassRendering(false);
|
||||
EngineConfig.getInstance().SetAlphaToCoverage(false);
|
||||
PrimaryRuntime.GetRenderThread().GetRenderer().GetSceneRender().RebuildPipelines(PrimaryRuntime.GetRenderThread().GetRenderer().GetVulkanContext());
|
||||
if(engineInstance.window().GetLinkedApi() == EngineConfig.RenderAPI.Vulkan)PrimaryRuntime.GetRenderThread().GetRenderer().GetSceneRender().RebuildPipelines(PrimaryRuntime.GetRenderThread().GetRenderer().GetVulkanContext());
|
||||
}
|
||||
ImGui.sameLine();
|
||||
if(ImGui.button("Medium")){
|
||||
|
|
@ -57,7 +65,7 @@ public class PerformanceOverlay implements GUIOverlay {
|
|||
ForwardSceneRender.SetDualPassRendering(true);
|
||||
DeferredSceneRender.SetDualPassRendering(true);
|
||||
EngineConfig.getInstance().SetAlphaToCoverage(true);
|
||||
PrimaryRuntime.GetRenderThread().GetRenderer().GetSceneRender().RebuildPipelines(PrimaryRuntime.GetRenderThread().GetRenderer().GetVulkanContext());
|
||||
if(engineInstance.window().GetLinkedApi() == EngineConfig.RenderAPI.Vulkan)PrimaryRuntime.GetRenderThread().GetRenderer().GetSceneRender().RebuildPipelines(PrimaryRuntime.GetRenderThread().GetRenderer().GetVulkanContext());
|
||||
}
|
||||
ImGui.sameLine();
|
||||
if(ImGui.button("Highest")){
|
||||
|
|
@ -67,7 +75,7 @@ public class PerformanceOverlay implements GUIOverlay {
|
|||
ForwardSceneRender.SetDualPassRendering(true);
|
||||
DeferredSceneRender.SetDualPassRendering(true);
|
||||
EngineConfig.getInstance().SetAlphaToCoverage(false);
|
||||
PrimaryRuntime.GetRenderThread().GetRenderer().GetSceneRender().RebuildPipelines(PrimaryRuntime.GetRenderThread().GetRenderer().GetVulkanContext());
|
||||
if(engineInstance.window().GetLinkedApi() == EngineConfig.RenderAPI.Vulkan)PrimaryRuntime.GetRenderThread().GetRenderer().GetSceneRender().RebuildPipelines(PrimaryRuntime.GetRenderThread().GetRenderer().GetVulkanContext());
|
||||
}
|
||||
ImGui.text(" ");
|
||||
ImGui.text("anti aliasing:");
|
||||
|
|
@ -132,14 +140,14 @@ public class PerformanceOverlay implements GUIOverlay {
|
|||
parent.ChangeGraphicsSettings = true;
|
||||
parent.CoolDown = 500;
|
||||
EngineConfig.getInstance().SetAlphaToCoverage(false);
|
||||
PrimaryRuntime.GetRenderThread().GetRenderer().GetSceneRender().RebuildPipelines(PrimaryRuntime.GetRenderThread().GetRenderer().GetVulkanContext());
|
||||
if(engineInstance.window().GetLinkedApi() == EngineConfig.RenderAPI.Vulkan)PrimaryRuntime.GetRenderThread().GetRenderer().GetSceneRender().RebuildPipelines(PrimaryRuntime.GetRenderThread().GetRenderer().GetVulkanContext());
|
||||
}
|
||||
ImGui.sameLine();
|
||||
if(ImGui.button("AlphaToCoverage True")){
|
||||
parent.ChangeGraphicsSettings = true;
|
||||
parent.CoolDown = 500;
|
||||
EngineConfig.getInstance().SetAlphaToCoverage(true);
|
||||
PrimaryRuntime.GetRenderThread().GetRenderer().GetSceneRender().RebuildPipelines(PrimaryRuntime.GetRenderThread().GetRenderer().GetVulkanContext());
|
||||
if(engineInstance.window().GetLinkedApi() == EngineConfig.RenderAPI.Vulkan) PrimaryRuntime.GetRenderThread().GetRenderer().GetSceneRender().RebuildPipelines(PrimaryRuntime.GetRenderThread().GetRenderer().GetVulkanContext());
|
||||
}
|
||||
ImGui.inputFloat("Gamma", GammaValue, 0.0025f, 0.22725f, "%.4f");
|
||||
if (ImGui.isItemDeactivatedAfterEdit()) {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,7 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Main.Scene.GUIs;
|
||||
|
||||
import imgui.ImDrawList;
|
||||
import imgui.ImGui;
|
||||
import imgui.ImGuiViewport;
|
||||
import imgui.ImVec2;
|
||||
import imgui.flag.ImGuiCol;
|
||||
import imgui.flag.ImGuiCond;
|
||||
import imgui.flag.ImGuiStyleVar;
|
||||
import imgui.flag.ImGuiWindowFlags;
|
||||
import imgui.*;
|
||||
import imgui.flag.*;
|
||||
import imgui.type.ImInt;
|
||||
import imgui.type.ImString;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
|
||||
|
|
@ -17,9 +11,11 @@ import net.halbear.Terrain4J.EngineCore.Main.GameCore;
|
|||
import net.halbear.Terrain4J.EngineCore.Main.PrimaryRuntime;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.GUIOverlay;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.Scene;
|
||||
import net.halbear.Terrain4J.EngineCore.ServerNetworking.ClientSideNetworkUtils;
|
||||
import net.halbear.Terrain4J.EngineCore.Threads.ClientConnectionThread;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DisplayToScreen.DeferredSceneRender;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DisplayToScreen.ForwardSceneRender;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DisplayToScreen.DeferredSceneRender;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DisplayToScreen.ForwardSceneRender;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.tinylog.Logger;
|
||||
|
||||
public class SettingsMenu implements GUIOverlay {
|
||||
|
|
@ -31,6 +27,19 @@ public class SettingsMenu implements GUIOverlay {
|
|||
public final ImString textBuffer = new ImString(100);
|
||||
public final ImString UsernameBuffer = new ImString(24);
|
||||
|
||||
public SettingsMenu(){
|
||||
textBuffer.set(EngineConfig.getInstance().GetServerIP());
|
||||
ServerPort.set(EngineConfig.getInstance().GetServerPort());
|
||||
UsernameBuffer.set(EngineConfig.getInstance().GetUserDisplayName());
|
||||
Music[0] = (int)(EngineConfig.getInstance().MusicVolume * 100);
|
||||
SFX[0] = (int)(EngineConfig.getInstance().SoundVolume * 100);
|
||||
Weapons[0] = (int)(EngineConfig.getInstance().WeaponVolume * 100);
|
||||
Ambient[0] = (int)(EngineConfig.getInstance().AmbientVolume * 100);
|
||||
AudioInstance.ApplyUniversalVolume();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void RenderGUI(EngineInstance engineInstance, long frameTimeNS, GameCore parent) {
|
||||
if (!StartMenu.ShowSettings) return;
|
||||
|
|
@ -39,7 +48,6 @@ public class SettingsMenu implements GUIOverlay {
|
|||
| ImGuiWindowFlags.AlwaysAutoResize
|
||||
| ImGuiWindowFlags.NoSavedSettings
|
||||
| ImGuiWindowFlags.NoFocusOnAppearing
|
||||
| ImGuiWindowFlags.NoNav
|
||||
| ImGuiWindowFlags.NoMove;
|
||||
|
||||
float CenterX = viewport.getWorkPosX() + viewport.getWorkSizeX() / 2.0f;
|
||||
|
|
@ -52,6 +60,7 @@ public class SettingsMenu implements GUIOverlay {
|
|||
ImGui.pushStyleVar(ImGuiStyleVar.WindowRounding, 8f);
|
||||
|
||||
ImGui.begin("Start Menu", menuFlags);
|
||||
ImGuiIO io = ImGui.getIO();
|
||||
ImDrawList drawList = ImGui.getForegroundDrawList();
|
||||
ImGui.setWindowFontScale(4.0f);
|
||||
if (ImGui.button("Return")) {
|
||||
|
|
@ -67,8 +76,8 @@ public class SettingsMenu implements GUIOverlay {
|
|||
StartMenu.GameStarted = false;
|
||||
}
|
||||
ImGui.sameLine();
|
||||
int color = ImGui.getColorU32(ClientConnectionThread.Connected ? 0.0f : 1.0f, ClientConnectionThread.Connected ? 1.0f : 0.0f, 0.0f, 1.0f);
|
||||
String text = ClientConnectionThread.Connected ? "ONLINE" : "OFFLINE";
|
||||
int color = ImGui.getColorU32(ClientSideNetworkUtils.Connected ? 0.0f : 1.0f, ClientSideNetworkUtils.Connected ? 1.0f : 0.0f, 0.0f, 1.0f);
|
||||
String text = ClientSideNetworkUtils.Connected ? "ONLINE" : "OFFLINE";
|
||||
float rightEdge = ImGui.getMainViewport().getPos().x + ImGui.getMainViewport().getSize().x;
|
||||
ImVec2 textSize = new ImVec2();
|
||||
ImGui.calcTextSize(textSize, text);
|
||||
|
|
@ -92,19 +101,21 @@ public class SettingsMenu implements GUIOverlay {
|
|||
ImGui.setWindowFontScale(3f);
|
||||
ImGui.text("User Configuration");
|
||||
if (ImGui.inputText("Player Username", UsernameBuffer)) {
|
||||
|
||||
EngineConfig.getInstance().SetUserDisplayName(UsernameBuffer.get());
|
||||
}
|
||||
ImGui.text("Server Configuration");
|
||||
if (ImGui.inputText("Server IP Address", textBuffer)) {
|
||||
ClientConnectionThread.ServerIP = textBuffer.get();
|
||||
ClientSideNetworkUtils.ServerIP = textBuffer.get();
|
||||
}
|
||||
if (ImGui.inputInt("Server Port", ServerPort)) {
|
||||
ClientConnectionThread.ServerPort = ServerPort.get();
|
||||
ClientSideNetworkUtils.ServerPort = ServerPort.get();
|
||||
}
|
||||
ImGui.text("Players Online: " + (ClientConnectionThread.Connected ? ClientConnectionThread.PlayersOnline : "Not Connected to Server"));
|
||||
ImGui.text("Client UUID: " + (ClientConnectionThread.Connected ? ClientConnectionThread.clientUUID : "Not Connected to Server"));
|
||||
ImGui.text("Players Online: " + (ClientSideNetworkUtils.Connected ? ClientSideNetworkUtils.PlayersOnline : "Not Connected to Server"));
|
||||
ImGui.text("Client UUID: " + (ClientSideNetworkUtils.Connected ? ClientSideNetworkUtils.clientUUID : "Not Connected to Server"));
|
||||
if (ImGui.button("Apply and reconnect")) {
|
||||
|
||||
EngineConfig.getInstance().SetServerIP(ClientSideNetworkUtils.ServerIP);
|
||||
EngineConfig.getInstance().SetServerPort(ClientSideNetworkUtils.ServerPort);
|
||||
ClientSideNetworkUtils.Reconnect();
|
||||
}
|
||||
ImGui.endTabItem();
|
||||
}
|
||||
|
|
@ -169,6 +180,17 @@ public class SettingsMenu implements GUIOverlay {
|
|||
ImGui.setWindowFontScale(4.0f);
|
||||
ImGui.text("Graphics Settings");
|
||||
ImGui.setWindowFontScale(3f);
|
||||
ImGui.text("Rendering API:");
|
||||
ImGui.text("Active Renderer: " + EngineConfig.getInstance().GetRenderingAPI().name());
|
||||
if(ImGui.button("Vulkan")){
|
||||
Logger.debug("Switch to Vulkan");
|
||||
EngineConfig.getInstance().SetRenderingAPI(EngineConfig.RenderAPI.Vulkan);
|
||||
}
|
||||
ImGui.sameLine();
|
||||
if(ImGui.button("OpenGL")){
|
||||
Logger.debug("Switch to OpenGL");
|
||||
EngineConfig.getInstance().SetRenderingAPI(EngineConfig.RenderAPI.OpenGL);
|
||||
}
|
||||
ImGui.text("Presets:");
|
||||
if(ImGui.button("Lowest")){
|
||||
parent.ChangeGraphicsSettings = true;
|
||||
|
|
@ -177,7 +199,7 @@ public class SettingsMenu implements GUIOverlay {
|
|||
ForwardSceneRender.SetDualPassRendering(false);
|
||||
DeferredSceneRender.SetDualPassRendering(false);
|
||||
EngineConfig.getInstance().SetAlphaToCoverage(false);
|
||||
PrimaryRuntime.GetRenderThread().GetRenderer().GetSceneRender().RebuildPipelines(PrimaryRuntime.GetRenderThread().GetRenderer().GetVulkanContext());
|
||||
if(engineInstance.window().GetLinkedApi() == EngineConfig.RenderAPI.Vulkan)PrimaryRuntime.GetRenderThread().GetRenderer().GetSceneRender().RebuildPipelines(PrimaryRuntime.GetRenderThread().GetRenderer().GetVulkanContext());
|
||||
}
|
||||
ImGui.sameLine();
|
||||
if(ImGui.button("Medium")){
|
||||
|
|
@ -187,7 +209,7 @@ public class SettingsMenu implements GUIOverlay {
|
|||
ForwardSceneRender.SetDualPassRendering(true);
|
||||
DeferredSceneRender.SetDualPassRendering(true);
|
||||
EngineConfig.getInstance().SetAlphaToCoverage(true);
|
||||
PrimaryRuntime.GetRenderThread().GetRenderer().GetSceneRender().RebuildPipelines(PrimaryRuntime.GetRenderThread().GetRenderer().GetVulkanContext());
|
||||
if(engineInstance.window().GetLinkedApi() == EngineConfig.RenderAPI.Vulkan)PrimaryRuntime.GetRenderThread().GetRenderer().GetSceneRender().RebuildPipelines(PrimaryRuntime.GetRenderThread().GetRenderer().GetVulkanContext());
|
||||
}
|
||||
ImGui.sameLine();
|
||||
if(ImGui.button("Highest")){
|
||||
|
|
@ -197,9 +219,10 @@ public class SettingsMenu implements GUIOverlay {
|
|||
ForwardSceneRender.SetDualPassRendering(true);
|
||||
DeferredSceneRender.SetDualPassRendering(true);
|
||||
EngineConfig.getInstance().SetAlphaToCoverage(false);
|
||||
PrimaryRuntime.GetRenderThread().GetRenderer().GetSceneRender().RebuildPipelines(PrimaryRuntime.GetRenderThread().GetRenderer().GetVulkanContext());
|
||||
if(engineInstance.window().GetLinkedApi() == EngineConfig.RenderAPI.Vulkan)PrimaryRuntime.GetRenderThread().GetRenderer().GetSceneRender().RebuildPipelines(PrimaryRuntime.GetRenderThread().GetRenderer().GetVulkanContext());
|
||||
}
|
||||
ImGui.text("anti aliasing:");
|
||||
ImGui.text("Selected AA: " + EngineConfig.getInstance().RenderAAType().name());
|
||||
if(ImGui.button("No AA")){
|
||||
parent.ChangeGraphicsSettings = true;
|
||||
parent.CoolDown = 2000;
|
||||
|
|
@ -230,6 +253,7 @@ public class SettingsMenu implements GUIOverlay {
|
|||
parent.NextAAMode = 4;
|
||||
}
|
||||
ImGui.text("pipeline:");
|
||||
ImGui.text("Selected Pass mode: " + (DeferredSceneRender.DualPassRendering() ? "Dual Pass" : "Single pass"));
|
||||
if(ImGui.button("Single Pass")){
|
||||
parent.ChangeGraphicsSettings = true;
|
||||
parent.CoolDown = 500;
|
||||
|
|
@ -244,6 +268,7 @@ public class SettingsMenu implements GUIOverlay {
|
|||
DeferredSceneRender.SetDualPassRendering(true);
|
||||
}
|
||||
ImGui.text("pipeline lighting method:");
|
||||
ImGui.text("Selected Lighting: " + (EngineConfig.getInstance().DeferredRendering() ? "Deferred" : "Forward"));
|
||||
if(ImGui.button("No Lighting")){
|
||||
parent.ChangeGraphicsSettings = true;
|
||||
parent.CoolDown = 500;
|
||||
|
|
@ -259,18 +284,19 @@ public class SettingsMenu implements GUIOverlay {
|
|||
// PrimaryRuntime.GetRenderThread().RefreshRenderer();
|
||||
}
|
||||
ImGui.text("Translucency rendering method:");
|
||||
ImGui.text("Selected Translucency: " + (EngineConfig.getInstance().DeferredRendering() ? "Blend Alpha" : "Dither Alpha"));
|
||||
if(ImGui.button("Alpha Blending (translucency)")){
|
||||
parent.ChangeGraphicsSettings = true;
|
||||
parent.CoolDown = 500;
|
||||
EngineConfig.getInstance().SetAlphaToCoverage(false);
|
||||
PrimaryRuntime.GetRenderThread().GetRenderer().GetSceneRender().RebuildPipelines(PrimaryRuntime.GetRenderThread().GetRenderer().GetVulkanContext());
|
||||
if(engineInstance.window().GetLinkedApi() == EngineConfig.RenderAPI.Vulkan)PrimaryRuntime.GetRenderThread().GetRenderer().GetSceneRender().RebuildPipelines(PrimaryRuntime.GetRenderThread().GetRenderer().GetVulkanContext());
|
||||
}
|
||||
ImGui.sameLine();
|
||||
if(ImGui.button("Alpha To Coverage (Dithering)")){
|
||||
parent.ChangeGraphicsSettings = true;
|
||||
parent.CoolDown = 500;
|
||||
EngineConfig.getInstance().SetAlphaToCoverage(true);
|
||||
PrimaryRuntime.GetRenderThread().GetRenderer().GetSceneRender().RebuildPipelines(PrimaryRuntime.GetRenderThread().GetRenderer().GetVulkanContext());
|
||||
if(engineInstance.window().GetLinkedApi() == EngineConfig.RenderAPI.Vulkan)PrimaryRuntime.GetRenderThread().GetRenderer().GetSceneRender().RebuildPipelines(PrimaryRuntime.GetRenderThread().GetRenderer().GetVulkanContext());
|
||||
}
|
||||
ImGui.endTabItem();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,25 +1,16 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Main.Scene.GUIs;
|
||||
|
||||
import imgui.ImDrawList;
|
||||
import imgui.ImGui;
|
||||
import imgui.ImGuiViewport;
|
||||
import imgui.flag.ImGuiCol;
|
||||
import imgui.flag.ImGuiCond;
|
||||
import imgui.flag.ImGuiStyleVar;
|
||||
import imgui.flag.ImGuiWindowFlags;
|
||||
import imgui.type.ImFloat;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineInstance;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.GameCore;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.PrimaryRuntime;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.GUIOverlay;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.GUI.GuiTexture;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DisplayToScreen.DeferredSceneRender;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DisplayToScreen.ForwardSceneRender;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.AudioInstance;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.Scene;
|
||||
import org.joml.Vector3f;
|
||||
import org.tinylog.Logger;
|
||||
|
||||
public class StartMenu implements GUIOverlay {
|
||||
public static boolean GameStarted = false;
|
||||
|
|
|
|||
|
|
@ -3,19 +3,21 @@ package net.halbear.Terrain4J.EngineCore.Main.Scene;
|
|||
import net.halbear.Terrain4J.EngineCore.Audio.AudioManager;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineInstance;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Rendering.SkyBox;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.AudioInstance;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.GameCore;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.DynamicMesh.DynamicTerrainMesh;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Projection.Project3D;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.DynamicMesh.DynamicTerrainMesh;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Projection.Project3D;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
|
||||
public interface IScene {
|
||||
|
||||
public void CameraTick(long FrameDiffNanoSeconds);
|
||||
public Map<String, CameraFrame> GetCameraFrameReg();
|
||||
public CameraFrame GetCameraFrame(String Name);
|
||||
public Scene AddCameraFrame(String Name, CameraFrame frame);
|
||||
public IScene AddCameraFrame(String Name, CameraFrame frame);
|
||||
public void StartCameraTrack(String StartFrame, String EndFrame, int TickAmount);
|
||||
public void SetActiveCameraFrame(String frameName);
|
||||
public Camera GetCamera();
|
||||
|
|
@ -25,6 +27,7 @@ public interface IScene {
|
|||
public void RemoveAllActors();
|
||||
public Actor RemoveActor(Actor actor);
|
||||
public void Input(EngineInstance engineInstance, long FrameDiffNanoSeconds, PlayerActor playerActor, float MOVEMENT_SPEED,GameCore parent);
|
||||
public void GlobalInput(EngineInstance engineInstance, long FrameDiffNanoSeconds, PlayerActor playerActor, float MOVEMENT_SPEED,GameCore parent);
|
||||
public void Update(EngineInstance engineInstance, long FrameDiffNanoSeconds);
|
||||
public void UpdateFastThread(EngineInstance engineInstance, long FrameDiffNanoSeconds);
|
||||
public void SecondUpdate(EngineInstance engineInstance);
|
||||
|
|
@ -40,4 +43,7 @@ public interface IScene {
|
|||
public void CreateTerrainMesh();
|
||||
public List<Sprite> GetSprites();
|
||||
public Camera2D Get2DCamera();
|
||||
public Map<String, AudioInstance> audioInstances();
|
||||
public void Reset();
|
||||
public Queue<String> NetworkedActors();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Main.Scene;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.RigidBody.ConvexMesh;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.RigidBody.RigidBody;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.RigidBody.RigidPhysicsController;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.PrimaryRuntime;
|
||||
import net.halbear.Terrain4J.EngineCore.ServerNetworking.ClientSideNetworkUtils;
|
||||
import net.halbear.Terrain4J.EngineCore.Threads.ClientConnectionThread;
|
||||
import net.halbear.Terrain4J.EngineCore.Threads.RenderThread;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
import org.tinylog.Logger;
|
||||
|
||||
|
|
@ -25,7 +24,7 @@ public class PlayerActor extends Actor{
|
|||
this.AttachedCameraID = AttachedCameraID;
|
||||
PlayerCam = Camera.CameraRegistry.get(AttachedCameraID);
|
||||
super(ID, ModelID, Position);
|
||||
if(!Objects.equals(ClientConnectionThread.OwnedActorID, ID) && !RenderThread.Headless && !PrimaryRuntime.Server){
|
||||
if(!ClientSideNetworkUtils.OwnsActor(ID) && !RenderThread.Headless && !PrimaryRuntime.IsServer){
|
||||
ActorElement newMelona = new ActorElement("PlayerModel" + ID, MelonaModelID, ID,new Vector3f(0,0,0));
|
||||
newMelona.SetScale(1.3f);
|
||||
newMelona.SetPositionOffset(0,-0.85f,0);
|
||||
|
|
@ -84,10 +83,10 @@ public class PlayerActor extends Actor{
|
|||
Position.add(CameraOffset);
|
||||
PlayerCam.SetPosition(Position.x, Position.y, Position.z);
|
||||
|
||||
if(!PrimaryRuntime.Server
|
||||
&& ClientConnectionThread.Connected
|
||||
&& GetID().equals(ClientConnectionThread.OwnedActorID)) {
|
||||
ClientConnectionThread.SendEntityUpdatePacket(this);
|
||||
if(!PrimaryRuntime.IsServer
|
||||
&& ClientSideNetworkUtils.Connected
|
||||
&& ClientSideNetworkUtils.OwnsActor(GetID())) {
|
||||
ClientSideNetworkUtils.SendEntityUpdatePacket(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,36 +6,29 @@ import net.halbear.Terrain4J.EngineCore.Input.KeyboardInput;
|
|||
import net.halbear.Terrain4J.EngineCore.Input.MouseListener;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineInstance;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.RigidBody.RigidBody;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.RigidBody.RigidPhysicsController;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Rendering.SkyBox;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.AudioInstance;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.GameCore;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.PrimaryRuntime;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.GUIs.GameChat;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.GUIs.Gimbal;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.GUIs.PerformanceOverlay;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.GUIs.StartMenu;
|
||||
import net.halbear.Terrain4J.EngineCore.Threads.ClientConnectionThread;
|
||||
import net.halbear.Terrain4J.EngineCore.Threads.RenderThread;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.DynamicMesh.DynamicTerrainMesh;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Projection.Project3D;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.Item;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.DynamicMesh.DynamicTerrainMesh;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Projection.Project3D;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.AudioInstance.AudioType;
|
||||
import org.joml.Vector2f;
|
||||
import org.joml.Vector3f;
|
||||
import org.tinylog.Logger;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
import static net.halbear.Terrain4J.EngineCore.Threads.ClientConnectionThread.UpdateEntityModelID;
|
||||
import static net.halbear.Terrain4J.EngineCore.ServerNetworking.ClientSideNetworkUtils.*;
|
||||
import static org.lwjgl.glfw.GLFW.*;
|
||||
import static org.lwjgl.glfw.GLFW.GLFW_KEY_A;
|
||||
import static org.lwjgl.glfw.GLFW.GLFW_KEY_D;
|
||||
import static org.lwjgl.glfw.GLFW.GLFW_KEY_LEFT_CONTROL;
|
||||
import static org.lwjgl.glfw.GLFW.GLFW_KEY_LEFT_SHIFT;
|
||||
import static org.lwjgl.glfw.GLFW.GLFW_KEY_S;
|
||||
import static org.lwjgl.glfw.GLFW.GLFW_KEY_SPACE;
|
||||
import static org.lwjgl.glfw.GLFW.GLFW_KEY_W;
|
||||
|
||||
public class Scene implements IScene {
|
||||
|
||||
|
|
@ -45,6 +38,7 @@ public class Scene implements IScene {
|
|||
|
||||
private final Map<String, Actor> Actors;
|
||||
private final List<String> ActiveActors;
|
||||
private final Queue<String> NetworkedActors = new ConcurrentLinkedQueue<>();
|
||||
|
||||
private final Camera2D camera2D;
|
||||
private final Map<String, Sprite> Sprites;
|
||||
|
|
@ -95,7 +89,10 @@ public class Scene implements IScene {
|
|||
public DynamicTerrainMesh GetTerrainMesh() {
|
||||
return terrainMesh;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, AudioInstance> audioInstances() {
|
||||
return audioInstances;
|
||||
}
|
||||
@Override
|
||||
public void CreateTerrainMesh() {
|
||||
int Width = 32;
|
||||
|
|
@ -143,7 +140,7 @@ public class Scene implements IScene {
|
|||
ActiveSprites = new ArrayList<>();
|
||||
CameraFrames = new HashMap<>();
|
||||
var EngConfig = EngineConfig.getInstance();
|
||||
camera2D = new Camera2D();
|
||||
camera2D = new Camera2D("DebugCamera");
|
||||
camera = new Camera("DebugCamera");
|
||||
LastCameraFrame = new CameraFrame(camera.GetPosition(),camera.GetRotation(),camera.GetFOV(), "NO_FRAME");
|
||||
|
||||
|
|
@ -153,9 +150,11 @@ public class Scene implements IScene {
|
|||
Projection = new Project3D(camera.GetFOV(),EngConfig.GetZNearPlane(), EngConfig.GetZFarPlane(),
|
||||
projectionWidth, projectionHeight);
|
||||
|
||||
if(!PrimaryRuntime.Server && !RenderThread.Headless) {
|
||||
if(!PrimaryRuntime.IsServer && !RenderThread.Headless) {
|
||||
GUIReg.put("PerformanceOverlay",new PerformanceOverlay());
|
||||
ActiveGUIs.add("PerformanceOverlay");
|
||||
// ActiveGUIs.add("PerformanceOverlay");
|
||||
GUIReg.put("ChatLog",new GameChat());
|
||||
ActiveGUIs.add("ChatLog");
|
||||
}
|
||||
}
|
||||
public ISceneLightingManager GetLightingManager(){return lightingManager;}
|
||||
|
|
@ -207,6 +206,18 @@ public class Scene implements IScene {
|
|||
}
|
||||
}
|
||||
|
||||
public void Reset(){
|
||||
Actor actor;
|
||||
while((actor = Actors.get(NetworkedActors.poll())) != null) {
|
||||
RemoveActor(actor);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Queue<String> NetworkedActors() {
|
||||
return NetworkedActors;
|
||||
}
|
||||
|
||||
public Map<String, CameraFrame> GetCameraFrameReg(){return CameraFrames;}
|
||||
public CameraFrame GetCameraFrame(String Name){return CameraFrames.get(Name);}
|
||||
public Scene AddCameraFrame(String Name, CameraFrame frame){
|
||||
|
|
@ -224,7 +235,7 @@ public class Scene implements IScene {
|
|||
|
||||
@Override
|
||||
public void SetUpAudio(EngineInstance engineInstance, AudioManager manager) {
|
||||
if(RenderThread.Headless || PrimaryRuntime.Server) return;
|
||||
if(RenderThread.Headless || PrimaryRuntime.IsServer) return;
|
||||
AudioInstance newInstance = new AudioInstance("resources/EngineResources/audio/music/MENUMUSIC_RetroFutureClean.ogg","BGM",manager,true);
|
||||
newInstance.Play();
|
||||
audioInstances.put("BGM",newInstance);
|
||||
|
|
@ -306,10 +317,21 @@ public class Scene implements IScene {
|
|||
if(input.keySinglePress(GLFW_KEY_F3)){
|
||||
GUI_MODE = (GUI_MODE + 1) % 2;
|
||||
}
|
||||
if(input.keyPressed(GLFW_KEY_ENTER)) {
|
||||
parent.SpawnNewActor(engineInstance, new Vector3f( (float)(5 * Math.random()),20 + (float)(10 * Math.random()), (float)(5 * Math.random())),new Vector3f(-1f + (float)(2 * Math.random()),-1f + (float)(2 * Math.random()),-1f + (float)(2 * Math.random())),new Vector3f((float)Math.random(),(float)Math.random(),(float)Math.random()));
|
||||
if(GameChat.IsChatOpen){
|
||||
if(input.keyPressed(GLFW_KEY_ENTER)){
|
||||
GameChat.IsChatOpen = false;
|
||||
GameChat.SubmitChatMessage();
|
||||
}
|
||||
if(!RenderThread.Headless && !PrimaryRuntime.Server && playerActor!= null) {
|
||||
if(input.keyPressed(GLFW_KEY_ESCAPE)){
|
||||
GameChat.IsChatOpen = false;
|
||||
GameChat.ChatBuffer.clear();
|
||||
}
|
||||
}
|
||||
if(!GameChat.IsChatOpen){
|
||||
if(input.keyPressed(GLFW_KEY_T)){
|
||||
GameChat.IsChatOpen = true;
|
||||
}
|
||||
if(!RenderThread.Headless && !PrimaryRuntime.IsServer && playerActor!= null) {
|
||||
if (input.keySinglePress(GLFW_KEY_M)) {
|
||||
playerActor.SetModelID(MusketItem.ModelID());
|
||||
UpdateEntityModelID(playerActor.ID, MusketItem.ModelID());
|
||||
|
|
@ -329,56 +351,75 @@ public class Scene implements IScene {
|
|||
GunCockSFX.Play();
|
||||
}
|
||||
}
|
||||
if (input.keySinglePress(GLFW_KEY_ESCAPE)) {
|
||||
parent.StartMenuActive = true;
|
||||
parent.startMenu.GameStarted = true;
|
||||
StartMenu.ShowSettings = true;
|
||||
parent.SwitchBGM(engineInstance, this, "resources/EngineResources/audio/music/MENUMUSIC_RetroFutureClean.ogg");
|
||||
}
|
||||
MouseListener mouseListener = window.getMouseInput();
|
||||
if(!parent.StartMenuActive && !StartMenu.ShowSettings && !StartMenu.ShowCredits ) {
|
||||
if (mouseListener.isRightButtonPressed()) {
|
||||
CurrentWeapon.SetPositionOffset(new Vector3f(0f,1.15f,-1.25f));
|
||||
CurrentWeapon.SetPositionOffset(new Vector3f(0f, 1.15f, -1.25f));
|
||||
} else {
|
||||
CurrentWeapon.SetPositionOffset(new Vector3f(0.5f,1.15f,-1.25f));
|
||||
CurrentWeapon.SetPositionOffset(new Vector3f(0.5f, 1.15f, -1.25f));
|
||||
}
|
||||
if(mouseListener.isLeftButtonPressed()) {
|
||||
if (CurrentItem != null&& playerActor != null) {
|
||||
if (mouseListener.isLeftButtonPressed()) {
|
||||
if (CurrentItem != null && playerActor != null) {
|
||||
long NewTime = System.nanoTime();
|
||||
float FireRate = 1000f/CurrentItem.FireRate();
|
||||
if (NewTime - LastGunFire > 1_000_000f * FireRate ){
|
||||
float FireRate = 1000f / CurrentItem.FireRate();
|
||||
if (NewTime - LastGunFire > 1_000_000f * FireRate) {
|
||||
LastGunFire = NewTime;
|
||||
ClientConnectionThread.FireWeapon(playerActor.PositionOffset, CurrentItem.Damage(), 100, camera, playerActor.ID);
|
||||
FireWeapon(playerActor.PositionOffset, CurrentItem.Damage(), 100, camera, playerActor.ID);
|
||||
// MusketFireSFX.Play();
|
||||
}
|
||||
}
|
||||
}
|
||||
if(input.keyPressed(GLFW_KEY_1)) {
|
||||
if (input.keyPressed(GLFW_KEY_1)) {
|
||||
Gimbal.universalType = Gimbal.GimbalType.Move;
|
||||
}
|
||||
if(input.keyPressed(GLFW_KEY_2)) {
|
||||
if (input.keyPressed(GLFW_KEY_2)) {
|
||||
Gimbal.universalType = Gimbal.GimbalType.Resize;
|
||||
}
|
||||
if(input.keyPressed(GLFW_KEY_3)) {
|
||||
if (input.keyPressed(GLFW_KEY_3)) {
|
||||
Gimbal.universalType = Gimbal.GimbalType.Rotate;
|
||||
}
|
||||
if(input.keyPressed(GLFW_KEY_TAB)){
|
||||
for(int i = 0; i < parent.ActorEditorComponents.size(); i++){
|
||||
if (input.keyPressed(GLFW_KEY_TAB)) {
|
||||
for (int i = 0; i < parent.ActorEditorComponents.size(); i++) {
|
||||
parent.ActorEditorComponents.get(i).UpdateAll();
|
||||
}
|
||||
}
|
||||
if(input.keySinglePress(GLFW_KEY_F2)) {
|
||||
if (input.keySinglePress(GLFW_KEY_F2)) {
|
||||
EngineConfig.getInstance().SetRenderCollisionMesh(!EngineConfig.getInstance().RenderCollisionMeshes());
|
||||
}
|
||||
|
||||
if(playerActor == null || CurrentWeapon == null || playerController == null) {
|
||||
if (playerActor == null || CurrentWeapon == null || playerController == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
playerController.GetControls().Input(input, FrameDiffNanoSeconds, CurrentWeapon, MOVEMENT_SPEED, parent, this);
|
||||
}
|
||||
}
|
||||
if(GUI_MODE == 0 && !ActiveGUIs.contains("PerformanceOverlay")) ActiveGUIs.add("PerformanceOverlay");
|
||||
else if (GUI_MODE != 0) ActiveGUIs.remove("PerformanceOverlay");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void GlobalInput(EngineInstance engineInstance, long FrameDiffNanoSeconds, PlayerActor playerActor, float MOVEMENT_SPEED, GameCore parent) {
|
||||
IScene scene = engineInstance.scene();
|
||||
Window window = engineInstance.window();
|
||||
|
||||
KeyboardInput input = window.getKeyboardInput();
|
||||
float MovementDist = (float)(FrameDiffNanoSeconds / 1000000L) * MOVEMENT_SPEED;
|
||||
if(input.keyPressed(GLFW_KEY_D)) {
|
||||
scene.Get2DCamera().AddPosition(new Vector2f(1,0));
|
||||
}
|
||||
if(input.keyPressed(GLFW_KEY_A)) {
|
||||
scene.Get2DCamera().AddPosition(new Vector2f(-1,0));
|
||||
}
|
||||
|
||||
if (input.keySinglePress(GLFW_KEY_ESCAPE)) {
|
||||
parent.StartMenuActive = !parent.StartMenuActive;
|
||||
StartMenu.GameStarted = parent.StartMenuActive;
|
||||
StartMenu.ShowSettings = parent.StartMenuActive;
|
||||
parent.SwitchBGM(engineInstance, this, "resources/EngineResources/audio/music/MENUMUSIC_RetroFutureClean.ogg");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Update(EngineInstance engineInstance, long FrameDiffNanoSeconds) {
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,234 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Main.Scene;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Audio.AudioManager;
|
||||
import net.halbear.Terrain4J.EngineCore.Display.Window;
|
||||
import net.halbear.Terrain4J.EngineCore.Input.KeyboardInput;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineInstance;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Rendering.SkyBox;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.AudioInstance;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.GameCore;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.PrimaryRuntime;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.GUIs.StartMenu;
|
||||
import net.halbear.Terrain4J.EngineCore.Threads.RenderThread;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.DynamicMesh.DynamicTerrainMesh;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Projection.Project3D;
|
||||
import org.joml.Vector2f;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.lwjgl.glfw.GLFW.*;
|
||||
|
||||
public class Scene2D implements IScene{
|
||||
|
||||
public List<String> ActiveGUIs = new ArrayList<>();
|
||||
public Map<String, GUIOverlay> GUIReg = new HashMap<>();
|
||||
private final Camera2D camera2D;
|
||||
private final Map<String, Sprite> UnsortedSprites;
|
||||
private final List<String> ActiveSprites;
|
||||
|
||||
public int TotalTransitionTicks = 1000;
|
||||
public float CurrentTransitionTick = 0;
|
||||
private Vector2f LastMousePos = new Vector2f(0,0);
|
||||
public Map<String, AudioInstance> audioInstances;
|
||||
public IPlayerController playerController;
|
||||
public int Jumps = 0;
|
||||
public final int MaxJumps = 2;
|
||||
public int GroundedGraceTicks = 0;
|
||||
public final int MaxGroundedGraceTicks = 8;
|
||||
public String CurrentCam = "DefaultCamera";
|
||||
|
||||
public Scene2D()
|
||||
{
|
||||
UnsortedSprites = new HashMap<>();
|
||||
ActiveSprites = new ArrayList<>();
|
||||
audioInstances = new HashMap<>();
|
||||
camera2D = new Camera2D("DefaultCamera");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void CameraTick(long FrameDiffNanoSeconds) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, CameraFrame> GetCameraFrameReg() {
|
||||
return Map.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CameraFrame GetCameraFrame(String Name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IScene AddCameraFrame(String Name, CameraFrame frame) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void StartCameraTrack(String StartFrame, String EndFrame, int TickAmount) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void SetActiveCameraFrame(String frameName) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Camera GetCamera() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void AddActor(Actor NewActor) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Actor> GetActors() {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Project3D GetProjection() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void RemoveAllActors() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Actor RemoveActor(Actor actor) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Input(EngineInstance engineInstance, long FrameDiffNanoSeconds, PlayerActor playerActor, float MOVEMENT_SPEED, GameCore parent) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void GlobalInput(EngineInstance engineInstance, long FrameDiffNanoSeconds, PlayerActor playerActor, float MOVEMENT_SPEED, GameCore parent) {
|
||||
IScene scene = engineInstance.scene();
|
||||
Window window = engineInstance.window();
|
||||
|
||||
KeyboardInput input = window.getKeyboardInput();
|
||||
|
||||
if (input.keySinglePress(GLFW_KEY_ESCAPE)) {
|
||||
parent.StartMenuActive = !parent.StartMenuActive;
|
||||
StartMenu.GameStarted = parent.StartMenuActive;
|
||||
StartMenu.ShowSettings = parent.StartMenuActive;
|
||||
parent.SwitchBGM(engineInstance, this, "resources/EngineResources/audio/music/MENUMUSIC_RetroFutureClean.ogg");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void Update(EngineInstance engineInstance, long FrameDiffNanoSeconds) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void UpdateFastThread(EngineInstance engineInstance, long FrameDiffNanoSeconds) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void SecondUpdate(EngineInstance engineInstance) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void RenderThreadInput(EngineInstance engineInstance, long FrameDiffNanoSeconds) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void RenderGUIs(EngineInstance engineInstance, long frameTimeNS, GameCore parent) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void CameraInput(EngineInstance engineInstance, long FrameDiffNanoSeconds) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String GetActiveCameraFrame() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void SetUpAudio(EngineInstance engineInstance, AudioManager manager) {
|
||||
if(RenderThread.Headless || PrimaryRuntime.IsServer) return;
|
||||
AudioInstance newInstance = new AudioInstance("resources/EngineResources/audio/music/MENUMUSIC_RetroFutureClean.ogg","BGM",manager,true);
|
||||
newInstance.Play();
|
||||
audioInstances.put("BGM",newInstance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISceneLightingManager GetLightingManager() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SkyBox GetSkyBox() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void SetSkyBox(SkyBox skyBox) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public DynamicTerrainMesh GetTerrainMesh() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void CreateTerrainMesh() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Sprite> GetSprites() {
|
||||
List<Sprite> actors = new ArrayList<>();
|
||||
for(int i = 0; i < ActiveSprites.size(); i++){
|
||||
actors.add(UnsortedSprites.get(ActiveSprites.get(i)));
|
||||
}
|
||||
return actors;
|
||||
}
|
||||
|
||||
public void AddUnsortedSprite(Sprite NewActor){
|
||||
if(NewActor == null) return;
|
||||
|
||||
UnsortedSprites.put(NewActor.GetID(), NewActor);
|
||||
|
||||
if(!ActiveSprites.contains(NewActor.GetID())) {
|
||||
ActiveSprites.add(NewActor.GetID());
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public Camera2D Get2DCamera() {
|
||||
return camera2D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, AudioInstance> audioInstances() {
|
||||
return audioInstances;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Reset() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Queue<String> NetworkedActors() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,118 +1,47 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Main.Scene;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Rendering.VulkanContext;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Pipeline.Images.TextureCache;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.VkModel.ModelsCache;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.Sprites.SpriteState;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Pipeline.Images.TextureCache;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.VkModel.ModelsCache;
|
||||
import org.joml.Vector2f;
|
||||
import org.joml.Vector4f;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static net.halbear.Terrain4J.EngineCore.Vulkan.SpriteRendering.SpriteMeshGenerator.GenerateModelFromTexture;
|
||||
import static net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.SpriteRendering.SpriteMeshGenerator.GenerateModelFromTexture;
|
||||
|
||||
public class Sprite {
|
||||
public static final Map<String, Sprite> SpriteRegistry = new HashMap<>();
|
||||
public interface Sprite {
|
||||
public static final Map<String, Sprite> SpriteRegistry = new LinkedHashMap<>();
|
||||
public static final Map<String, SpriteState> SpriteStateRegistry = new LinkedHashMap<>();
|
||||
|
||||
private String ModelID;
|
||||
private final String textureId;
|
||||
private final Vector2f position;
|
||||
private final Vector2f scale;
|
||||
private final Vector2f size;
|
||||
private final Vector4f colour;
|
||||
private float rotation;
|
||||
private int layer;
|
||||
private final String ID;
|
||||
private int texturePosition;
|
||||
public Sprite SetCameraZValue(float CameraZValue);
|
||||
public float GetCameraZValue();
|
||||
|
||||
public Sprite(String ID, String textureId, Vector2f position, Vector2f Size, Vector2f Scale) {
|
||||
this.ID = ID;
|
||||
this.ModelID = "TO_BE_FULFILLED_LATER";
|
||||
this.textureId = textureId;
|
||||
this.position = new Vector2f().set(position);
|
||||
this.scale = new Vector2f().set(Scale);
|
||||
this.size = new Vector2f().set(Size);
|
||||
this.colour = new Vector4f(1.0f);
|
||||
this.rotation = 0.0f;
|
||||
this.layer = 0;
|
||||
SpriteRegistry.put(ID, this);
|
||||
}
|
||||
public Sprite(String ID, String ModelID, String textureId, Vector2f position, Vector2f Scale, Vector2f Size) {
|
||||
this.ID = ID;
|
||||
this.ModelID = ModelID;
|
||||
this.textureId = textureId;
|
||||
this.position = new Vector2f().set(position);
|
||||
this.scale = new Vector2f().set(Scale);
|
||||
this.size = new Vector2f().set(Size);
|
||||
this.colour = new Vector4f(1.0f);
|
||||
this.rotation = 0.0f;
|
||||
this.layer = 0;
|
||||
SpriteRegistry.put(ID, this);
|
||||
}
|
||||
public Sprite CompileSprite(TextureCache textureCache, ModelsCache modelsCache, VulkanContext VkCtx);
|
||||
|
||||
public Sprite(String ID, String TextureID, Vector2f Position, Vector2f Scale, Vector2f Size, TextureCache textureCache, ModelsCache modelsCache, VulkanContext VkCtx){
|
||||
this.ID = ID;
|
||||
this.textureId = TextureID;
|
||||
this.ModelID = GenerateModelFromTexture(textureCache, modelsCache, VkCtx, TextureID, Size.y);
|
||||
texturePosition = textureCache.GetPosition(textureId);
|
||||
this.position = new Vector2f().set(Position);
|
||||
this.scale = new Vector2f().set(Scale);
|
||||
this.size = new Vector2f().set(Size);
|
||||
this.colour = new Vector4f(1.0f);
|
||||
SpriteRegistry.put(ID, this);
|
||||
}
|
||||
public int GetTexturePosition();
|
||||
|
||||
public Sprite CompileSprite(TextureCache textureCache, ModelsCache modelsCache, VulkanContext VkCtx){
|
||||
this.ModelID = GenerateModelFromTexture(textureCache, modelsCache, VkCtx, textureId, this.size.y);
|
||||
texturePosition = textureCache.GetPosition(textureId);
|
||||
return this;
|
||||
}
|
||||
public String GetID();
|
||||
|
||||
public int GetTexturePosition(){
|
||||
return texturePosition;
|
||||
}
|
||||
public String GetModelID();
|
||||
|
||||
public String GetID(){
|
||||
return ID;
|
||||
}
|
||||
public String GetTextureID();
|
||||
|
||||
public String GetModelID() {
|
||||
return ModelID;
|
||||
}
|
||||
public Vector2f GetPosition();
|
||||
|
||||
public String GetTextureID() {
|
||||
return textureId;
|
||||
}
|
||||
public Vector2f GetSize();
|
||||
|
||||
public Vector2f GetPosition() {
|
||||
return position;
|
||||
}
|
||||
public Vector2f GetScale();
|
||||
|
||||
public Vector2f GetSize() {
|
||||
return size;
|
||||
}
|
||||
public Vector4f GetColour();
|
||||
|
||||
public Vector2f GetScale() {
|
||||
return scale;
|
||||
}
|
||||
public float GetRotation();
|
||||
|
||||
public Vector4f GetColour() {
|
||||
return colour;
|
||||
}
|
||||
public void SetRotation(float rotation);
|
||||
|
||||
public float GetRotation() {
|
||||
return rotation;
|
||||
}
|
||||
public int GetLayer();
|
||||
|
||||
public void SetRotation(float rotation) {
|
||||
this.rotation = rotation;
|
||||
}
|
||||
|
||||
public int GetLayer() {
|
||||
return layer;
|
||||
}
|
||||
|
||||
public void SetLayer(int layer) {
|
||||
this.layer = layer;
|
||||
}
|
||||
public void SetLayer(int layer);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,131 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Main.Scene;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Rendering.VulkanContext;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.Sprites.SpriteState;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Pipeline.Images.TextureCache;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.VkModel.ModelsCache;
|
||||
import org.joml.Vector2f;
|
||||
import org.joml.Vector4f;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.SpriteRendering.SpriteMeshGenerator.GenerateModelFromTexture;
|
||||
|
||||
public class SpriteVk implements Sprite {
|
||||
public static boolean SPRITE_STATE_MAP_INITIALIZED = false;
|
||||
|
||||
private String ModelID;
|
||||
private final String textureId;
|
||||
private final Vector2f position;
|
||||
private final Vector2f scale;
|
||||
private final Vector2f size;
|
||||
private final Vector4f colour;
|
||||
private float rotation;
|
||||
private int layer;
|
||||
private final String ID;
|
||||
private int texturePosition;
|
||||
private float CameraZValue = 1.0f;
|
||||
|
||||
public SpriteVk SetCameraZValue(float CameraZValue) {
|
||||
this.CameraZValue = CameraZValue;
|
||||
return this;
|
||||
}
|
||||
public float GetCameraZValue() {
|
||||
return CameraZValue;
|
||||
}
|
||||
|
||||
public SpriteVk(String ID, String textureId, Vector2f position, Vector2f Size, Vector2f Scale) {
|
||||
this.ID = ID;
|
||||
this.ModelID = "TO_BE_FULFILLED_LATER";
|
||||
this.textureId = textureId;
|
||||
this.position = new Vector2f().set(position);
|
||||
this.scale = new Vector2f().set(Scale);
|
||||
this.size = new Vector2f().set(Size);
|
||||
this.colour = new Vector4f(1.0f);
|
||||
this.rotation = 0.0f;
|
||||
this.layer = 0;
|
||||
SpriteRegistry.put(ID, this);
|
||||
}
|
||||
public SpriteVk(String ID, int texturePosition, String ModelID, String textureId, Vector2f position, Vector2f Scale, Vector2f Size) {
|
||||
this.ID = ID;
|
||||
this.ModelID = ModelID;
|
||||
this.textureId = textureId;
|
||||
this.texturePosition = texturePosition;
|
||||
this.position = new Vector2f().set(position);
|
||||
this.scale = new Vector2f().set(Scale);
|
||||
this.size = new Vector2f().set(Size);
|
||||
this.colour = new Vector4f(1.0f);
|
||||
this.rotation = 0.0f;
|
||||
this.layer = 0;
|
||||
SpriteRegistry.put(ID, this);
|
||||
}
|
||||
|
||||
public SpriteVk(String ID, String TextureID, Vector2f Position, Vector2f Scale, Vector2f Size, TextureCache textureCache, ModelsCache modelsCache, VulkanContext VkCtx){
|
||||
this.ID = ID;
|
||||
this.textureId = TextureID;
|
||||
this.ModelID = GenerateModelFromTexture(textureCache, modelsCache, VkCtx, TextureID, Size.y);
|
||||
texturePosition = textureCache.GetPosition(textureId);
|
||||
this.position = new Vector2f().set(Position);
|
||||
this.scale = new Vector2f().set(Scale);
|
||||
this.size = new Vector2f().set(Size);
|
||||
this.colour = new Vector4f(1.0f);
|
||||
SpriteRegistry.put(ID, this);
|
||||
}
|
||||
|
||||
public SpriteVk CompileSprite(TextureCache textureCache, ModelsCache modelsCache, VulkanContext VkCtx){
|
||||
this.ModelID = GenerateModelFromTexture(textureCache, modelsCache, VkCtx, textureId, this.size.y);
|
||||
texturePosition = textureCache.GetPosition(textureId);
|
||||
SpriteStateRegistry.put(ID, new SpriteState(ModelID, textureId, ID, texturePosition, 0));
|
||||
SPRITE_STATE_MAP_INITIALIZED = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int GetTexturePosition(){
|
||||
return texturePosition;
|
||||
}
|
||||
|
||||
public String GetID(){
|
||||
return ID;
|
||||
}
|
||||
|
||||
public String GetModelID() {
|
||||
return ModelID;
|
||||
}
|
||||
|
||||
public String GetTextureID() {
|
||||
return textureId;
|
||||
}
|
||||
|
||||
public Vector2f GetPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public Vector2f GetSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public Vector2f GetScale() {
|
||||
return scale;
|
||||
}
|
||||
|
||||
public Vector4f GetColour() {
|
||||
return colour;
|
||||
}
|
||||
|
||||
public float GetRotation() {
|
||||
return rotation;
|
||||
}
|
||||
|
||||
public void SetRotation(float rotation) {
|
||||
this.rotation = rotation;
|
||||
}
|
||||
|
||||
public int GetLayer() {
|
||||
return layer;
|
||||
}
|
||||
|
||||
public void SetLayer(int layer) {
|
||||
this.layer = layer;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Main.Scene.Sprites;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.Sprite;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class LevelEntities implements SpriteCollection {
|
||||
@Override
|
||||
public CollectionType CollectionType() {
|
||||
return CollectionType.Entities;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String CollectionName() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Sprite> GetSprites() {
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Main.Scene.Sprites;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.Sprite;
|
||||
import org.joml.Vector2i;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class LimitlessTileMap implements SpriteCollection{
|
||||
|
||||
private final String Name;
|
||||
private final Map<Vector2i, Integer> TileMap = new LinkedHashMap<>();
|
||||
private final List<Sprite> Tiles = new ArrayList<>();
|
||||
|
||||
public LimitlessTileMap(String Name){
|
||||
this.Name = Name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String CollectionName() {
|
||||
return Name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Sprite> GetSprites() {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CollectionType CollectionType() {
|
||||
return CollectionType.LimitlessTileMap;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Main.Scene.Sprites;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.Sprite;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.SpriteVk;
|
||||
import org.joml.Vector2i;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface SpriteCollection {
|
||||
|
||||
public static Map<Integer, SpriteState> SPRITE_STATE_MAP = new LinkedHashMap<>();
|
||||
public static Map<Integer, SpriteState> GetSpriteStateMap() {
|
||||
if(!SpriteVk.SPRITE_STATE_MAP_INITIALIZED){
|
||||
Map<String,SpriteState> states = Sprite.SpriteStateRegistry;
|
||||
Vector2i i = new Vector2i(0,0);
|
||||
SPRITE_STATE_MAP.put(i.x, null);
|
||||
i.x++;
|
||||
states.forEach((name, state)->{
|
||||
SPRITE_STATE_MAP.put(i.x, state);
|
||||
i.x++;
|
||||
});
|
||||
}
|
||||
return SPRITE_STATE_MAP;
|
||||
}
|
||||
|
||||
public enum CollectionType{
|
||||
Entities,
|
||||
TileMap,
|
||||
LimitlessTileMap
|
||||
}
|
||||
|
||||
public CollectionType CollectionType();
|
||||
public String CollectionName();
|
||||
public List<Sprite> GetSprites();
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Main.Scene.Sprites;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.Sprite;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SpriteLayer {
|
||||
private int ZIndex = 0;
|
||||
private final List<SpriteCollection> Sprites = new ArrayList<>();
|
||||
|
||||
public SpriteLayer(int ZIndex){
|
||||
this.ZIndex = ZIndex;
|
||||
}
|
||||
|
||||
public int GetZindex(){return ZIndex;}
|
||||
|
||||
public SpriteCollection GetSpriteCollection(int index){return Sprites.get(index);}
|
||||
|
||||
public List<SpriteCollection> GetSpriteCollections(){return Sprites;}
|
||||
|
||||
public SpriteLayer AddNewCollection(SpriteCollection collection){
|
||||
Sprites.add(collection);
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<Sprite> GetSprites(){
|
||||
List<Sprite> sprites = new ArrayList<>();
|
||||
Sprites.forEach(spriteCollection -> sprites.addAll(spriteCollection.GetSprites()));
|
||||
return sprites;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Main.Scene.Sprites;
|
||||
|
||||
public record SpriteState(String ModelID,String TextureID, String StateName,int texturePosition, float Z) {
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Main.Scene.Sprites;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.Sprite;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.SpriteVk;
|
||||
import org.joml.Vector2f;
|
||||
import org.joml.Vector2i;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Tilemap implements SpriteCollection {
|
||||
|
||||
private final String Name;
|
||||
private int[][] TileMap;
|
||||
private final List<Sprite> Tiles = new ArrayList<>();
|
||||
private Vector2i TilemapPosition;
|
||||
private Vector2i TilemapSize;
|
||||
private boolean CacheUpToDate = false;
|
||||
private int TextureResolution = 8;
|
||||
|
||||
public Tilemap(String Name, Vector2i TilemapSize, Vector2i TilemapPosition){
|
||||
this.Name = Name;
|
||||
this.TilemapSize = TilemapSize;
|
||||
this.TilemapPosition = TilemapPosition;
|
||||
TileMap = new int[TilemapSize.x][TilemapSize.y];
|
||||
}
|
||||
|
||||
public Tilemap SetTile(Vector2i TilePosition, int TileID){
|
||||
if(TilePosition.x < 0 || TilePosition.x >= TilemapSize.x || TilePosition.y < 0 || TilePosition.y >= TilemapSize.y) return this;
|
||||
TileMap[TilePosition.x][TilePosition.y] = TileID;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int GetTile(Vector2i TilePosition){
|
||||
if(TilePosition.x < 0 || TilePosition.x >= TilemapSize.x || TilePosition.y < 0 || TilePosition.y >= TilemapSize.y) return -1;
|
||||
return TileMap[TilePosition.x][TilePosition.y];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String CollectionName() {
|
||||
return Name;
|
||||
}
|
||||
|
||||
private void CacheTiles(){
|
||||
Tiles.clear();
|
||||
Map<Integer, SpriteState> spriteStateMap = SpriteCollection.GetSpriteStateMap();
|
||||
for(int x = 0; x < TilemapSize.x; x++){
|
||||
for(int y = 0; y < TilemapSize.y; y++){
|
||||
if(TileMap[x][y] != -1){
|
||||
Tiles.add(new SpriteVk(Name + x + "_"+ y, spriteStateMap.get(TileMap[x][y]).texturePosition(), spriteStateMap.get(TileMap[x][y]).ModelID(), spriteStateMap.get(TileMap[x][y]).TextureID(), new Vector2f(TextureResolution * x + TilemapPosition.x, TextureResolution * y + TilemapPosition.y),new Vector2f(1,1),new Vector2f(TextureResolution,TextureResolution)).SetCameraZValue(spriteStateMap.get(TileMap[x][y]).Z()));
|
||||
}
|
||||
}
|
||||
}
|
||||
CacheUpToDate = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Sprite> GetSprites() {
|
||||
if(!CacheUpToDate) CacheTiles();
|
||||
return Tiles;
|
||||
}
|
||||
@Override
|
||||
public CollectionType CollectionType() {
|
||||
return CollectionType.TileMap;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -15,7 +15,7 @@ public class VisualisedCollisionActor extends Actor{
|
|||
final UUID LinkedMesh;
|
||||
public VisualisedCollisionActor(String ID, Vector3f Position, UUID LinkedMesh) {
|
||||
super(ID, CollisionCubeModelID, Position);
|
||||
if(!PrimaryRuntime.Server && !RenderThread.Headless) {
|
||||
if(!PrimaryRuntime.IsServer && !RenderThread.Headless) {
|
||||
this.LinkedMesh = LinkedMesh;
|
||||
CollisionVisuals.add(this);
|
||||
} else{
|
||||
|
|
@ -23,7 +23,7 @@ public class VisualisedCollisionActor extends Actor{
|
|||
}
|
||||
}
|
||||
public void Update(){
|
||||
if(PrimaryRuntime.Server || RenderThread.Headless) return;
|
||||
if(PrimaryRuntime.IsServer || RenderThread.Headless) return;
|
||||
ConvexMesh mesh = ConvexMesh.MeshRegistry.get(LinkedMesh);
|
||||
if(mesh != null) {
|
||||
SetScale(new Vector3f(mesh.hxhyhz).mul(2.01f));
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Main.Util.Maths;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.LegacyCollision.CollisionPoly;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.LegacyPhysicsController;
|
||||
import org.joml.*;
|
||||
|
||||
import java.lang.Math;
|
||||
|
|
@ -61,105 +59,6 @@ public class T4Math {
|
|||
|
||||
}
|
||||
|
||||
public static class ComplexCollision{
|
||||
public static LegacyPhysicsController.CollisionResult ComputePolyToPolyIntersection(CollisionPoly poly1, CollisionPoly poly2){
|
||||
LegacyPhysicsController.CollisionResult result = new LegacyPhysicsController.CollisionResult();
|
||||
if(poly1 == null || poly2 == null) return null;
|
||||
Vector3f[] vertices1 = new Vector3f[]{new Vector3f().set(poly1.v1()),new Vector3f().set(poly1.v2()),new Vector3f().set(poly1.v3())};
|
||||
Vector3f[] vertices2 = new Vector3f[]{new Vector3f().set(poly2.v1()),new Vector3f().set(poly2.v2()),new Vector3f().set(poly2.v3())};
|
||||
Vector3f e1 = new Vector3f().set(poly1.v2()).sub(poly1.v1());
|
||||
Vector3f e2 = new Vector3f().set(poly1.v3()).sub(poly1.v1());
|
||||
Vector3f Normal1 = new Vector3f().set(e1).cross(e2).normalize();
|
||||
float Distance1 = -Normal1.dot(poly1.v1());
|
||||
|
||||
float[] du = new float[3];
|
||||
for(int i = 0; i < 3; i++) du[i] = Math.abs(Normal1.dot(vertices2[i]) + Distance1) < Math3D.epsilon ? 0 : Normal1.dot(vertices2[i]) + Distance1;
|
||||
if ((du[0] > 0 && du[1] > 0 && du[2] > 0) || (du[0] < 0 && du[1] < 0 && du[2] < 0)) return result;
|
||||
|
||||
|
||||
Vector3f f1 = new Vector3f().set(poly2.v2()).sub(poly2.v1());
|
||||
Vector3f f2 = new Vector3f().set(poly2.v3()).sub(poly2.v1());
|
||||
Vector3f Normal2 = new Vector3f().set(f1).cross(f2).normalize();
|
||||
float Distance2 = -Normal2.dot(poly2.v1());
|
||||
|
||||
float[] dv = new float[3];
|
||||
for(int i = 0; i < 3; i++) dv[i] = Math.abs(Normal2.dot(vertices1[i]) + Distance2) < Math3D.epsilon ? 0 : Normal2.dot(vertices1[i]) + Distance2;
|
||||
if ((dv[0] > 0 && dv[1] > 0 && dv[2] > 0) || (dv[0] < 0 && dv[1] < 0 && dv[2] < 0)) return result;
|
||||
|
||||
Vector3f IntersectionDirection = new Vector3f().set(Normal1).cross(Normal2);
|
||||
if (IntersectionDirection.lengthSquared() < Math3D.epsilon) {
|
||||
return result;
|
||||
}
|
||||
IntersectionDirection.normalize();
|
||||
|
||||
Vector3f[] Segment1 = GetIntersectionPoints(poly1, dv);
|
||||
Vector3f[] Segment2 = GetIntersectionPoints(poly2, du);
|
||||
|
||||
if (Segment1 == null || Segment2 == null) return result;
|
||||
|
||||
return ComputerSegmentOverlap(Segment1, Segment2, IntersectionDirection,Normal1);
|
||||
}
|
||||
|
||||
public static Vector3f[] GetIntersectionPoints(CollisionPoly poly, float[] d){
|
||||
Vector3f[] vertices1 = new Vector3f[]{new Vector3f().set(poly.v1()),new Vector3f().set(poly.v2()),new Vector3f().set(poly.v3())};
|
||||
Vector3f[] Points = new Vector3f[2];
|
||||
int Count = 0;
|
||||
for(int i = 0; i < 3; i++) {
|
||||
int next = (i + 1) % 3;
|
||||
if (d[i] * d[next] < 0 || (d[i] == 0 && d[next] != 0) || (d[i] != 0 && d[next] == 0)) {
|
||||
float Factor = d[i] / (d[i] - d[next]);
|
||||
if (Float.isNaN(Factor) || Float.isInfinite(Factor)) Factor = 0.0f;
|
||||
Vector3f Intersect = new Vector3f().set(vertices1[next]).sub(vertices1[i])
|
||||
.mul(Factor).add(vertices1[i]);
|
||||
if(Count < 2){
|
||||
Points[Count++] = Intersect;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Count == 2 ? Points : null;
|
||||
}
|
||||
|
||||
public static LegacyPhysicsController.CollisionResult ComputerSegmentOverlap(Vector3f[] Segment1, Vector3f[] Segment2, Vector3f Direction, Vector3f CollisionNormal){
|
||||
LegacyPhysicsController.CollisionResult result = new LegacyPhysicsController.CollisionResult();
|
||||
|
||||
float Poly1Min = Segment1[0].dot(Direction);
|
||||
float Poly1Max = Segment1[1].dot(Direction);
|
||||
Vector3f point1Min = Segment1[0], point1Max = Segment1[1];
|
||||
if(Poly1Min > Poly1Max){
|
||||
float temp = Poly1Max;
|
||||
Poly1Max = Poly1Min;
|
||||
Poly1Min = temp;
|
||||
Vector3f pTemp = point1Min;
|
||||
point1Min = point1Max;
|
||||
point1Max = pTemp;
|
||||
}
|
||||
float Poly2Min = Segment2[0].dot(Direction);
|
||||
float Poly2Max = Segment2[1].dot(Direction);
|
||||
Vector3f point2Min = Segment2[0], point2Max = Segment2[1];
|
||||
if(Poly2Min > Poly2Max){
|
||||
float temp = Poly2Max;
|
||||
Poly2Max = Poly2Min;
|
||||
Poly2Min = temp;
|
||||
Vector3f pTemp = point2Min;
|
||||
point2Min = point2Max;
|
||||
point2Max = pTemp;
|
||||
}
|
||||
|
||||
if (Poly1Max < Poly2Min - Math3D.epsilon || Poly2Max < Poly1Min - Math3D.epsilon) return result;
|
||||
|
||||
float overlapMin = Math.max(Poly1Min, Poly2Min);
|
||||
float overlapMax = Math.min(Poly1Max, Poly2Max);
|
||||
float segmentLength = overlapMax - overlapMin;
|
||||
|
||||
result.Intersects = true;
|
||||
result.StartPoint = new Vector3f((Poly1Min > Poly2Min) ? point1Min : point2Min);
|
||||
result.EndPoint = new Vector3f((Poly1Max < Poly2Max) ? point1Max : point2Max);
|
||||
result.CollisionNormal = new Vector3f(CollisionNormal);
|
||||
result.CollisionDepth = segmentLength;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Math3D {
|
||||
public static float epsilon = 1e-8f;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,9 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Profiling;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DeviceLayers.Device;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Util.VulkanUtils;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DeviceLayers.Device;
|
||||
import org.lwjgl.system.MemoryStack;
|
||||
import org.lwjgl.vulkan.*;
|
||||
|
||||
import java.nio.LongBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,73 @@
|
|||
package net.halbear.Terrain4J.EngineCore.RenderingAPI.OpenGL.GlModels;
|
||||
|
||||
import org.lwjgl.opengl.GL30;
|
||||
import org.lwjgl.system.MemoryUtil;
|
||||
|
||||
import java.nio.FloatBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.lwjgl.opengl.GL15.*;
|
||||
import static org.lwjgl.opengl.GL20.glEnableVertexAttribArray;
|
||||
import static org.lwjgl.opengl.GL20.glVertexAttribPointer;
|
||||
import static org.lwjgl.opengl.GL30.*;
|
||||
|
||||
public class GLMesh {
|
||||
private int VertexCount;
|
||||
private int VAO_ID;
|
||||
private List<Integer> VBO_ID_List;
|
||||
|
||||
public GLMesh(float[] vertices, float[] colours, int[] indices) {
|
||||
this.VertexCount = indices.length;
|
||||
VBO_ID_List = new ArrayList<>();
|
||||
|
||||
VAO_ID = glGenVertexArrays();
|
||||
glBindVertexArray(VAO_ID);
|
||||
|
||||
int vboId = glGenBuffers();
|
||||
VBO_ID_List.add(vboId);
|
||||
FloatBuffer positionsBuffer = MemoryUtil.memCallocFloat(vertices.length);
|
||||
positionsBuffer.put(0, vertices);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vboId);
|
||||
glBufferData(GL_ARRAY_BUFFER, positionsBuffer, GL_STATIC_DRAW);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);
|
||||
|
||||
vboId = glGenBuffers();
|
||||
VBO_ID_List.add(vboId);
|
||||
FloatBuffer coloursBuffer = MemoryUtil.memCallocFloat(colours.length);
|
||||
coloursBuffer.put(0, colours);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vboId);
|
||||
glBufferData(GL_ARRAY_BUFFER, coloursBuffer, GL_STATIC_DRAW);
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribPointer(1, 3, GL_FLOAT, false, 0, 0);
|
||||
|
||||
vboId = glGenBuffers();
|
||||
VBO_ID_List.add(vboId);
|
||||
IntBuffer indicesBuffer = MemoryUtil.memCallocInt(indices.length);
|
||||
indicesBuffer.put(0, indices);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboId);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL_STATIC_DRAW);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindVertexArray(0);
|
||||
|
||||
MemoryUtil.memFree(positionsBuffer);
|
||||
MemoryUtil.memFree(coloursBuffer);
|
||||
MemoryUtil.memFree(indicesBuffer);
|
||||
}
|
||||
|
||||
public void CleanUp() {
|
||||
VBO_ID_List.forEach(GL30::glDeleteBuffers);
|
||||
glDeleteVertexArrays(VAO_ID);
|
||||
}
|
||||
|
||||
public int GetVertexCount() {
|
||||
return VertexCount;
|
||||
}
|
||||
|
||||
public final int GetVaoID() {
|
||||
return VAO_ID;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
package net.halbear.Terrain4J.EngineCore.RenderingAPI.OpenGL.GlModels;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.VkModel.MeshData;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record GLModel(String ID, List<GLMesh> Meshes, String VertexPath, String IndexPath) {
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package net.halbear.Terrain4J.EngineCore.RenderingAPI.OpenGL.GlModels;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ModelsCache {
|
||||
private final Map<String, GLMesh> MeshMap;
|
||||
public ModelsCache(){
|
||||
MeshMap = new HashMap<>();
|
||||
}
|
||||
|
||||
public void addMesh(String meshId, GLMesh mesh) {
|
||||
MeshMap.put(meshId, mesh);
|
||||
}
|
||||
|
||||
public void cleanup() {
|
||||
MeshMap.values().forEach(GLMesh::CleanUp);
|
||||
}
|
||||
|
||||
public Map<String, GLMesh> getMeshMap() {
|
||||
return MeshMap;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package net.halbear.Terrain4J.EngineCore.RenderingAPI.OpenGL;
|
||||
|
||||
import org.tinylog.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class OpenGlUtils {
|
||||
private OpenGlUtils(){}
|
||||
|
||||
public static String ReadFile(String filePath){
|
||||
String string = "";
|
||||
try{
|
||||
string = new String(Files.readAllBytes(Paths.get(filePath)));
|
||||
} catch (IOException e){
|
||||
Logger.error("Failed to read file: [{}] with error: [{}]", filePath, e.getMessage());
|
||||
}
|
||||
return string;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
package net.halbear.Terrain4J.EngineCore.RenderingAPI.OpenGL.Rendering;
|
||||
|
||||
import imgui.extension.imguizmo.flag.Mode;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.IScene;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.OpenGL.GlModels.GLMesh;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.OpenGL.GlModels.ModelsCache;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.OpenGL.Shader.ShaderProgram;
|
||||
import org.tinylog.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
import static org.lwjgl.opengl.GL20.GL_FRAGMENT_SHADER;
|
||||
import static org.lwjgl.opengl.GL20.GL_VERTEX_SHADER;
|
||||
import static org.lwjgl.opengl.GL30.glBindVertexArray;
|
||||
|
||||
public class ForwardRenderer implements SceneRender{
|
||||
|
||||
private ShaderProgram shaderProgram;
|
||||
|
||||
public ForwardRenderer(){
|
||||
List<ShaderProgram.ShaderModuleGL> shaderModules = new ArrayList<>();
|
||||
shaderModules.add(new ShaderProgram.ShaderModuleGL("resources/EngineResources/GLShaders/scene_vert.glsl", GL_VERTEX_SHADER));
|
||||
shaderModules.add(new ShaderProgram.ShaderModuleGL("resources/EngineResources/GLShaders/scene_frag.glsl", GL_FRAGMENT_SHADER));
|
||||
shaderProgram = new ShaderProgram(shaderModules);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void CleanUp() {
|
||||
shaderProgram.CleanUp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Render(IScene scene, ModelsCache modelsCache) {
|
||||
shaderProgram.Bind();
|
||||
modelsCache.getMeshMap().forEach((key , value)->{
|
||||
glBindVertexArray(value.GetVaoID());
|
||||
glDrawElements(GL_TRIANGLES, value.GetVertexCount(), GL_UNSIGNED_INT, 0);
|
||||
});
|
||||
// scene.GetActors().forEach(actor -> {
|
||||
// GLMesh mesh = modelsCache.getMeshMap().get(actor.GetModelID());
|
||||
// glBindVertexArray(mesh.GetVaoID());
|
||||
// glDrawArrays(GL_TRIANGLES, 0, mesh.GetVertexCount());
|
||||
// }
|
||||
// );
|
||||
|
||||
glBindVertexArray(0);
|
||||
|
||||
shaderProgram.UnBind();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package net.halbear.Terrain4J.EngineCore.RenderingAPI.OpenGL.Rendering;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.IScene;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.OpenGL.GlModels.ModelsCache;
|
||||
|
||||
public interface SceneRender {
|
||||
public void CleanUp();
|
||||
public void Render(IScene scene, ModelsCache modelsCache) ;
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
package net.halbear.Terrain4J.EngineCore.RenderingAPI.OpenGL.Shader;
|
||||
|
||||
public class ShaderModuleGL {
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
package net.halbear.Terrain4J.EngineCore.RenderingAPI.OpenGL.Shader;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.OpenGL.OpenGlUtils;
|
||||
import org.lwjgl.opengl.GL30;
|
||||
import org.tinylog.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.lwjgl.opengl.GL20.*;
|
||||
|
||||
public class ShaderProgram {
|
||||
private final int ProgramID;
|
||||
public ShaderProgram(List<ShaderModuleGL> shaderModules){
|
||||
ProgramID = glCreateProgram();
|
||||
if(ProgramID == 0){
|
||||
Logger.error("Failed to create shader program");
|
||||
}
|
||||
List<Integer> ShaderModules = new ArrayList<>();
|
||||
shaderModules.forEach(shaderModule -> {
|
||||
ShaderModules.add(CreateShader(OpenGlUtils.ReadFile(shaderModule.ShaderFile), shaderModule.ShaderType));
|
||||
});
|
||||
|
||||
LinkShaderProgram(ShaderModules);
|
||||
}
|
||||
|
||||
public void Bind(){
|
||||
glUseProgram(ProgramID);
|
||||
}
|
||||
|
||||
public void CleanUp(){
|
||||
UnBind();
|
||||
if(ProgramID != 0){
|
||||
glDeleteProgram(ProgramID);
|
||||
}
|
||||
}
|
||||
|
||||
protected int CreateShader(String ShaderCode, int ShaderType){
|
||||
int ShaderID = glCreateShader(ShaderType);
|
||||
if(ShaderID == 0){
|
||||
Logger.error("Failed to create shader of Type: " + ShaderType);
|
||||
}
|
||||
glShaderSource(ShaderID, ShaderCode);
|
||||
glCompileShader(ShaderID);
|
||||
if(glGetShaderi(ShaderID, GL_COMPILE_STATUS) == GL_FALSE){
|
||||
Logger.error("Failed to compile shader: [{}]",glGetShaderInfoLog(ShaderID, 1024));
|
||||
}
|
||||
|
||||
glAttachShader(ProgramID, ShaderID);
|
||||
|
||||
return ShaderID;
|
||||
}
|
||||
|
||||
public int GetProgramID(){return ProgramID;}
|
||||
|
||||
public void LinkShaderProgram(List<Integer> ShaderModules){
|
||||
glLinkProgram(ProgramID);
|
||||
if(glGetProgrami(ProgramID, GL_LINK_STATUS) == GL_FALSE){
|
||||
Logger.error("Failed to link shader program: [{}]", glGetProgramInfoLog(ProgramID, 1024));
|
||||
}
|
||||
|
||||
ShaderModules.forEach(ShaderID -> glDetachShader(ProgramID, ShaderID));
|
||||
ShaderModules.forEach(GL30::glDeleteShader);
|
||||
}
|
||||
|
||||
public void UnBind(){glUseProgram(0);}
|
||||
|
||||
public void Validate(){
|
||||
glValidateProgram(ProgramID);
|
||||
if(glGetProgrami(ProgramID, GL_VALIDATE_STATUS) == GL_FALSE){
|
||||
Logger.error("Failed to validate shader program: [{}]", glGetProgramInfoLog(ProgramID, 1024));
|
||||
}
|
||||
}
|
||||
|
||||
public record ShaderModuleGL(String ShaderFile, int ShaderType){}
|
||||
}
|
||||
|
|
@ -1,25 +1,24 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Vulkan.GUI;
|
||||
package net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.GUI;
|
||||
|
||||
import imgui.*;
|
||||
import imgui.glfw.ImGuiImplGlfw;
|
||||
import imgui.type.ImInt;
|
||||
import net.halbear.Terrain4J.EngineCore.Input.KeyboardInput;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineInstance;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Rendering.VulkanContext;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Pipeline.DefaultPipeline;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Pipeline.Images.*;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Pipeline.Pipeline;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Pipeline.PipelineBuildInfo;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Pipeline.PushConstantsRange;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.PostProcessing.PostProcess;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Shader.*;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DeviceLayers.CommandBuffer;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DeviceLayers.CommandPool;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DeviceLayers.Device;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DeviceLayers.Queues.Queue;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Util.VulkanBuffer;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Util.VulkanUtils;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Pipeline.DefaultPipeline;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Pipeline.Images.*;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Pipeline.Pipeline;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Pipeline.PipelineBuildInfo;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Pipeline.PushConstantsRange;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.PostProcessing.PostProcess;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Shader.*;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DeviceLayers.CommandBuffer;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DeviceLayers.CommandPool;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DeviceLayers.Device;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DeviceLayers.Queues.Queue;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Util.VulkanBuffer;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Util.VulkanUtils;
|
||||
import org.lwjgl.system.MemoryStack;
|
||||
import org.lwjgl.system.MemoryUtil;
|
||||
import org.lwjgl.util.shaderc.Shaderc;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Vulkan.GUI;
|
||||
package net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.GUI;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Vulkan.GUI;
|
||||
package net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.GUI;
|
||||
|
||||
import imgui.ImGui;
|
||||
import imgui.ImGuiIO;
|
||||
|
|
@ -128,8 +128,8 @@ public class GuiUtils {
|
|||
@Override
|
||||
public void invoke(long WindowHandle, int c){
|
||||
ImGuiIO imGuiIO = ImGui.getIO();
|
||||
if(!imGuiIO.getWantCaptureKeyboard()) return;
|
||||
imGuiIO.addInputCharacter(c);
|
||||
// if(!imGuiIO.getWantCaptureKeyboard()) return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -137,12 +137,16 @@ public class GuiUtils {
|
|||
@Override
|
||||
public void invoke(long WindowHandle, int Key, int ScanCode, int Action, int Mods){
|
||||
ImGuiIO imGuiIO = ImGui.getIO();
|
||||
if(!imGuiIO.getWantCaptureKeyboard()) return;
|
||||
if(Action == GLFW_PRESS){
|
||||
if(Action == GLFW_PRESS || Action == GLFW_REPEAT){
|
||||
imGuiIO.addKeyEvent(GetImGuiKey(Key),true);
|
||||
} else if(Action == GLFW_RELEASE){
|
||||
imGuiIO.addKeyEvent(GetImGuiKey(Key),false);
|
||||
}
|
||||
imGuiIO.setKeyCtrl((Mods & GLFW_MOD_CONTROL) != 0);
|
||||
imGuiIO.setKeyShift((Mods & GLFW_MOD_SHIFT) != 0);
|
||||
imGuiIO.setKeyAlt((Mods & GLFW_MOD_ALT) != 0);
|
||||
imGuiIO.setKeySuper((Mods & GLFW_MOD_SUPER) != 0);
|
||||
//if(!imGuiIO.getWantCaptureKeyboard()) return;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Vulkan.GUI;
|
||||
package net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.GUI;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Util.VulkanUtils;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Util.VulkanUtils;
|
||||
import org.lwjgl.vulkan.VkPipelineVertexInputStateCreateInfo;
|
||||
import org.lwjgl.vulkan.VkVertexInputAttributeDescription;
|
||||
import org.lwjgl.vulkan.VkVertexInputBindingDescription;
|
||||
|
|
@ -1,25 +1,24 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.DeferredRendering;
|
||||
package net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.DeferredRendering;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineInstance;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Rendering.VulkanContext;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.ILight;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.IScene;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.Light;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.SceneLightingManager;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.EmptyVertexBufferStruct;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Pipeline.DefaultPipeline;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Pipeline.Images.Attachment;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Pipeline.Images.Image;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Pipeline.Pipeline;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Pipeline.PipelineBuildInfo;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Shader.*;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DeviceLayers.CommandBuffer;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DeviceLayers.Device;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DisplayToScreen.ImageView;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.SwapChain.SwapChain;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Util.VulkanBuffer;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Util.VulkanUtils;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.EmptyVertexBufferStruct;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Pipeline.DefaultPipeline;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Pipeline.Images.Attachment;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Pipeline.Images.Image;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Pipeline.Pipeline;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Pipeline.PipelineBuildInfo;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Shader.*;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DeviceLayers.CommandBuffer;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DeviceLayers.Device;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DisplayToScreen.ImageView;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.SwapChain.SwapChain;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Util.VulkanBuffer;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Util.VulkanUtils;
|
||||
import org.lwjgl.system.MemoryStack;
|
||||
import org.lwjgl.system.MemoryUtil;
|
||||
import org.lwjgl.util.shaderc.Shaderc;
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.DeferredRendering;
|
||||
package net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.DeferredRendering;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Rendering.VulkanContext;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Pipeline.Images.Attachment;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Pipeline.Images.Attachment;
|
||||
import org.lwjgl.vulkan.VkExtent2D;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.DynamicMesh;
|
||||
package net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.DynamicMesh;
|
||||
|
||||
public class DeferredResource {
|
||||
public final long bufferHandle;
|
||||
|
|
@ -1,9 +1,8 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.DynamicMesh;
|
||||
package net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.DynamicMesh;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DeviceLayers.CommandBuffer;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DeviceLayers.Device;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Util.VulkanBuffer;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Util.VulkanUtils;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DeviceLayers.CommandBuffer;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DeviceLayers.Device;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Util.VulkanUtils;
|
||||
import org.lwjgl.PointerBuffer;
|
||||
import org.lwjgl.system.MemoryStack;
|
||||
import org.lwjgl.vulkan.VkBufferCopy;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Vulkan.Rendering;
|
||||
package net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering;
|
||||
|
||||
import org.lwjgl.vulkan.VkPipelineVertexInputStateCreateInfo;
|
||||
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Pipeline;
|
||||
package net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Pipeline;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Rendering.VulkanContext;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Shader.DescriptorSetLayout;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Shader.ShaderModule;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DeviceLayers.Device;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Util.VulkanUtils;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Shader.DescriptorSetLayout;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Shader.ShaderModule;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DeviceLayers.Device;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Util.VulkanUtils;
|
||||
import org.lwjgl.system.MemoryStack;
|
||||
import org.lwjgl.vulkan.*;
|
||||
import org.tinylog.Logger;
|
||||
|
|
@ -28,8 +28,6 @@ import static org.lwjgl.vulkan.VK13.VK_DYNAMIC_STATE_SCISSOR;
|
|||
import static org.lwjgl.vulkan.VK13.VK_DYNAMIC_STATE_VIEWPORT;
|
||||
import static org.lwjgl.vulkan.VK13.VK_FORMAT_UNDEFINED;
|
||||
import static org.lwjgl.vulkan.VK13.VK_FRONT_FACE_CLOCKWISE;
|
||||
import static org.lwjgl.vulkan.VK13.VK_NULL_HANDLE;
|
||||
import static org.lwjgl.vulkan.VK13.VK_SAMPLE_COUNT_1_BIT;
|
||||
import static org.lwjgl.vulkan.VK13.VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
|
||||
import static org.lwjgl.vulkan.VK13.vkCreateGraphicsPipelines;
|
||||
import static org.lwjgl.vulkan.VK13.vkCreatePipelineLayout;
|
||||
|
|
@ -1,8 +1,7 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Pipeline;
|
||||
package net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Pipeline;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Display.GLFWImageParser;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Pipeline.Images.ImageSrc;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Pipeline.Images.ImageSrc;
|
||||
import org.lwjgl.system.MemoryStack;
|
||||
import org.tinylog.Logger;
|
||||
|
||||
|
|
@ -16,12 +15,12 @@ public class GraphUtils {
|
|||
private GraphUtils(){ }
|
||||
|
||||
public static void CleanImageData(ImageSrc imageSrc){
|
||||
Logger.debug("Loading Image Data [{}]",imageSrc.data());
|
||||
// Logger.debug("Loading Image Data [{}]",imageSrc.data());
|
||||
stbi_image_free(imageSrc.data());
|
||||
}
|
||||
|
||||
public static ImageSrc LoadImage(String Filename) throws IOException{
|
||||
Logger.debug("Loading Image [{}]",Filename);
|
||||
// Logger.debug("Loading Image [{}]",Filename);
|
||||
ImageSrc newImage;
|
||||
ByteBuffer image;
|
||||
try (MemoryStack MemStack = MemoryStack.stackPush()) {
|
||||
|
|
@ -1,10 +1,9 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Pipeline.Images;
|
||||
package net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Pipeline.Images;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Rendering.VulkanContext;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DisplayToScreen.ImageView;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DisplayToScreen.ImageView;
|
||||
|
||||
import static org.lwjgl.util.vma.Vma.VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT;
|
||||
import static org.lwjgl.vulkan.VK13.*;
|
||||
public class Attachment {
|
||||
private final Image VkImage;
|
||||
|
|
@ -1,17 +1,15 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Pipeline.Images;
|
||||
package net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Pipeline.Images;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Rendering.VulkanContext;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Pipeline.GraphUtils;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DeviceLayers.CommandBuffer;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DisplayToScreen.ImageView;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Util.VulkanBuffer;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Pipeline.GraphUtils;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DeviceLayers.CommandBuffer;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DisplayToScreen.ImageView;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Util.VulkanBuffer;
|
||||
import org.lwjgl.system.MemoryStack;
|
||||
import org.lwjgl.system.MemoryUtil;
|
||||
import org.lwjgl.vulkan.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.LongBuffer;
|
||||
|
||||
import static org.lwjgl.system.MemoryUtil.memByteBuffer;
|
||||
import static org.lwjgl.util.vma.Vma.VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT;
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Pipeline.Images;
|
||||
package net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Pipeline.Images;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Rendering.VulkanContext;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DeviceLayers.CommandBuffer;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DisplayToScreen.ImageView;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DeviceLayers.CommandBuffer;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DisplayToScreen.ImageView;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
|
|
@ -1,15 +1,11 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Pipeline.Images;
|
||||
package net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Pipeline.Images;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Rendering.VulkanContext;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DeviceLayers.Device;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Util.VulkanUtils;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Util.VulkanUtils;
|
||||
import org.lwjgl.PointerBuffer;
|
||||
import org.lwjgl.system.MemoryStack;
|
||||
import org.lwjgl.util.vma.VmaAllocationCreateInfo;
|
||||
import org.lwjgl.vulkan.VkImageCreateInfo;
|
||||
import org.lwjgl.vulkan.VkMemoryAllocateInfo;
|
||||
import org.lwjgl.vulkan.VkMemoryRequirements;
|
||||
|
||||
import java.nio.LongBuffer;
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Pipeline.Images;
|
||||
package net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Pipeline.Images;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
|
|
@ -1,22 +1,19 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Pipeline.Images;
|
||||
package net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Pipeline.Images;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Rendering.VulkanContext;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Util.Maths.T4Math;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DeviceLayers.CommandBuffer;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DisplayToScreen.ImageView;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Util.VulkanBuffer;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Util.VulkanUtils;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DeviceLayers.CommandBuffer;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DisplayToScreen.ImageView;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Util.VulkanBuffer;
|
||||
import org.lwjgl.system.MemoryStack;
|
||||
import org.lwjgl.system.MemoryUtil;
|
||||
import org.lwjgl.vulkan.*;
|
||||
import org.tinylog.Logger;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import static org.lwjgl.util.vma.Vma.VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT;
|
||||
import static org.lwjgl.util.vma.Vma.VMA_MEMORY_USAGE_AUTO;
|
||||
import static org.lwjgl.vulkan.VK10.*;
|
||||
import static org.lwjgl.vulkan.VK13.VK_ACCESS_2_NONE;
|
||||
import static org.lwjgl.vulkan.VK13.vkCmdPipelineBarrier2;
|
||||
|
||||
public class Texture implements ITexture {
|
||||
|
|
@ -1,13 +1,12 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Pipeline.Images;
|
||||
package net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Pipeline.Images;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Rendering.VulkanContext;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Pipeline.GraphUtils;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Pipeline.IndexedLinkedHashMap;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.VkModel.VulkanMaterial;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DeviceLayers.CommandBuffer;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DeviceLayers.CommandPool;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DeviceLayers.Queues.Queue;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Pipeline.GraphUtils;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Pipeline.IndexedLinkedHashMap;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DeviceLayers.CommandBuffer;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DeviceLayers.CommandPool;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DeviceLayers.Queues.Queue;
|
||||
import org.tinylog.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
@ -1,9 +1,8 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Pipeline;
|
||||
package net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Pipeline;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class IndexedLinkedHashMap<K,V> extends LinkedHashMap<K,V> {
|
||||
private final List<K> IndexList = new ArrayList<>();
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Pipeline;
|
||||
package net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Pipeline;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Rendering.VulkanContext;
|
||||
|
||||
|
|
@ -1,10 +1,8 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Pipeline;
|
||||
package net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Pipeline;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Shader.DescriptorSet;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Shader.DescriptorSetLayout;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Shader.ShaderModule;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Shader.DescriptorSetLayout;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Shader.ShaderModule;
|
||||
import org.lwjgl.vulkan.VkPipelineVertexInputStateCreateInfo;
|
||||
import org.lwjgl.vulkan.VkPushConstantRange;
|
||||
|
||||
import static org.lwjgl.vulkan.VK10.VK_FORMAT_UNDEFINED;
|
||||
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Pipeline;
|
||||
package net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Pipeline;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DeviceLayers.Device;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Util.VulkanUtils;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DeviceLayers.Device;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Util.VulkanUtils;
|
||||
import org.lwjgl.system.MemoryStack;
|
||||
import org.lwjgl.vulkan.VkPipelineCacheCreateInfo;
|
||||
import org.tinylog.Logger;
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
package net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Pipeline;
|
||||
|
||||
public record PushConstantsRange(int Stage, int Offset, int Size) {
|
||||
}
|
||||
|
|
@ -1,19 +1,19 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.PostProcessing;
|
||||
package net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.PostProcessing;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Rendering.VulkanContext;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.EmptyVertexBufferStruct;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Pipeline.DefaultPipeline;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Pipeline.Images.Attachment;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Pipeline.Images.Image;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Pipeline.Pipeline;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Pipeline.PipelineBuildInfo;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Shader.*;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DeviceLayers.CommandBuffer;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DeviceLayers.Device;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.SwapChain.SwapChain;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Util.VulkanBuffer;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Util.VulkanUtils;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.EmptyVertexBufferStruct;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Pipeline.DefaultPipeline;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Pipeline.Images.Attachment;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Pipeline.Images.Image;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Pipeline.Pipeline;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Pipeline.PipelineBuildInfo;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Shader.*;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DeviceLayers.CommandBuffer;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DeviceLayers.Device;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.SwapChain.SwapChain;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Util.VulkanBuffer;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Util.VulkanUtils;
|
||||
import org.lwjgl.system.MemoryStack;
|
||||
import org.lwjgl.system.MemoryUtil;
|
||||
import org.lwjgl.util.shaderc.Shaderc;
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.PostProcessing;
|
||||
package net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.PostProcessing;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Util.VulkanUtils;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Util.VulkanUtils;
|
||||
import org.lwjgl.system.MemoryUtil;
|
||||
import org.lwjgl.vulkan.VkSpecializationInfo;
|
||||
import org.lwjgl.vulkan.VkSpecializationMapEntry;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Projection;
|
||||
package net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Projection;
|
||||
|
||||
import org.joml.Matrix4f;
|
||||
|
||||
|
|
@ -1,9 +1,8 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Shader;
|
||||
package net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Shader;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DeviceLayers.Device;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DeviceLayers.PhysicalDevice;
|
||||
import org.lwjgl.vulkan.VkPhysicalDeviceFeatures2;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DeviceLayers.Device;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DeviceLayers.PhysicalDevice;
|
||||
import org.lwjgl.vulkan.VkPhysicalDeviceLimits;
|
||||
import org.tinylog.Logger;
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Shader;
|
||||
package net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Shader;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DeviceLayers.Device;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DeviceLayers.Device;
|
||||
import org.lwjgl.system.MemoryStack;
|
||||
import org.lwjgl.vulkan.VkDescriptorPoolCreateInfo;
|
||||
import org.lwjgl.vulkan.VkDescriptorPoolSize;
|
||||
|
|
@ -9,7 +9,7 @@ import org.tinylog.Logger;
|
|||
import java.nio.LongBuffer;
|
||||
import java.util.List;
|
||||
|
||||
import static net.halbear.Terrain4J.EngineCore.Vulkan.Util.VulkanUtils.vkCheck;
|
||||
import static net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Util.VulkanUtils.vkCheck;
|
||||
import static org.lwjgl.vulkan.VK10.*;
|
||||
|
||||
public class DescriptorPool {
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Shader;
|
||||
package net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Shader;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DeviceLayers.Device;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DisplayToScreen.ImageView;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Util.VulkanBuffer;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DeviceLayers.Device;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Structure.DisplayToScreen.ImageView;
|
||||
import net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Util.VulkanBuffer;
|
||||
import org.lwjgl.system.MemoryStack;
|
||||
import org.lwjgl.vulkan.VkDescriptorBufferInfo;
|
||||
import org.lwjgl.vulkan.VkDescriptorImageInfo;
|
||||
|
|
@ -14,7 +14,7 @@ import java.nio.LongBuffer;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static net.halbear.Terrain4J.EngineCore.Vulkan.Util.VulkanUtils.vkCheck;
|
||||
import static net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Util.VulkanUtils.vkCheck;
|
||||
import static org.lwjgl.vulkan.VK10.*;
|
||||
|
||||
public class DescriptorSet {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Shader;
|
||||
package net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Shader;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Rendering.VulkanContext;
|
||||
import org.lwjgl.system.MemoryStack;
|
||||
|
|
@ -8,7 +8,7 @@ import org.tinylog.Logger;
|
|||
|
||||
import java.nio.LongBuffer;
|
||||
|
||||
import static net.halbear.Terrain4J.EngineCore.Vulkan.Util.VulkanUtils.vkCheck;
|
||||
import static net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Util.VulkanUtils.vkCheck;
|
||||
import static org.lwjgl.vulkan.VK10.vkCreateDescriptorSetLayout;
|
||||
import static org.lwjgl.vulkan.VK10.vkDestroyDescriptorSetLayout;
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Shader;
|
||||
package net.halbear.Terrain4J.EngineCore.RenderingAPI.Vulkan.Rendering.Shader;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
|
||||
import org.lwjgl.util.shaderc.Shaderc;
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue