From 118d68a64ef5d2f81a41bdc84bfe59ce056aa947 Mon Sep 17 00:00:00 2001 From: halotroop2288 Date: Wed, 4 Mar 2020 12:17:52 -0800 Subject: [PATCH 1/6] Nice capitalization. --- .classpath | 11 ++---- .../github/hydos/ginger/VulkanStarter.java | 4 +-- .../ginger/engine/vulkan/VKConstants.java | 2 +- .../ginger/engine/vulkan/api/GingerVK.java | 16 ++++----- .../ginger/engine/vulkan/io/VkWindow.java | 10 +++--- .../ginger/engine/vulkan/utils/VKUtils.java | 34 +++++++++---------- 6 files changed, 34 insertions(+), 43 deletions(-) diff --git a/.classpath b/.classpath index a93fc90..6c19c79 100644 --- a/.classpath +++ b/.classpath @@ -1,6 +1,6 @@ - + @@ -16,18 +16,11 @@ - + - - - - - - - diff --git a/src/main/java/com/github/hydos/ginger/VulkanStarter.java b/src/main/java/com/github/hydos/ginger/VulkanStarter.java index 2470024..f5b6734 100644 --- a/src/main/java/com/github/hydos/ginger/VulkanStarter.java +++ b/src/main/java/com/github/hydos/ginger/VulkanStarter.java @@ -4,7 +4,7 @@ import org.lwjgl.glfw.GLFW; import com.github.hydos.ginger.engine.common.info.RenderAPI; import com.github.hydos.ginger.engine.common.io.Window; -import com.github.hydos.ginger.engine.vulkan.api.GingerVk; +import com.github.hydos.ginger.engine.vulkan.api.*; /** @author hydos06 * the non ARR vulkan test example */ @@ -29,7 +29,7 @@ public class VulkanStarter } private void initVulkan() { - new GingerVk().start("Vulkan demo"); + new GingerVK().start("Vulkan demo"); } private void mainLoop() { diff --git a/src/main/java/com/github/hydos/ginger/engine/vulkan/VKConstants.java b/src/main/java/com/github/hydos/ginger/engine/vulkan/VKConstants.java index 9cc0d63..0dca3b0 100644 --- a/src/main/java/com/github/hydos/ginger/engine/vulkan/VKConstants.java +++ b/src/main/java/com/github/hydos/ginger/engine/vulkan/VKConstants.java @@ -2,7 +2,7 @@ package com.github.hydos.ginger.engine.vulkan; import org.lwjgl.vulkan.*; -public class VkConstants +public class VKConstants { public static VkInstance vulkanInstance; diff --git a/src/main/java/com/github/hydos/ginger/engine/vulkan/api/GingerVK.java b/src/main/java/com/github/hydos/ginger/engine/vulkan/api/GingerVK.java index e2923b8..75cd493 100644 --- a/src/main/java/com/github/hydos/ginger/engine/vulkan/api/GingerVK.java +++ b/src/main/java/com/github/hydos/ginger/engine/vulkan/api/GingerVK.java @@ -1,18 +1,16 @@ package com.github.hydos.ginger.engine.vulkan.api; import com.github.hydos.ginger.engine.vulkan.io.VkWindow; -import com.github.hydos.ginger.engine.vulkan.utils.VkUtils; +import com.github.hydos.ginger.engine.vulkan.utils.VKUtils; -public class GingerVk +public class GingerVK { - - public void start(String gameName) { + public void start(String gameName) + { System.out.println("Game " + gameName + " successfuly started in Vulkan mode."); - VkUtils.createInstance(); + VKUtils.createInstance(); VkWindow.createSurface(); - VkUtils.createPhysicalDevice(); - VkUtils.createLogicalDevice(); + VKUtils.createPhysicalDevice(); + VKUtils.createLogicalDevice(); } - - } diff --git a/src/main/java/com/github/hydos/ginger/engine/vulkan/io/VkWindow.java b/src/main/java/com/github/hydos/ginger/engine/vulkan/io/VkWindow.java index f54b79c..7b60e6d 100644 --- a/src/main/java/com/github/hydos/ginger/engine/vulkan/io/VkWindow.java +++ b/src/main/java/com/github/hydos/ginger/engine/vulkan/io/VkWindow.java @@ -7,8 +7,8 @@ import org.lwjgl.system.MemoryStack; import org.lwjgl.vulkan.VK12; import com.github.hydos.ginger.engine.common.io.Window; -import com.github.hydos.ginger.engine.vulkan.VkConstants; -import com.github.hydos.ginger.engine.vulkan.utils.VkUtils; +import com.github.hydos.ginger.engine.vulkan.VKConstants; +import com.github.hydos.ginger.engine.vulkan.utils.*; /** * used for window related vulkan only things @@ -23,13 +23,13 @@ public class VkWindow { LongBuffer pSurface = stack.longs(VK12.VK_NULL_HANDLE); - int status = GLFWVulkan.glfwCreateWindowSurface(VkConstants.vulkanInstance, Window.getWindow(), null, pSurface); + int status = GLFWVulkan.glfwCreateWindowSurface(VKConstants.vulkanInstance, Window.getWindow(), null, pSurface); if(status != VK12.VK_SUCCESS) { - throw new VulkanException("Failed to create vulkan surface for window reason: " + VkUtils.translateVulkanResult(status)); + throw new VulkanException("Failed to create vulkan surface for window reason: " + VKUtils.translateVulkanResult(status)); } - VkConstants.windowSurface = pSurface.get(0); + VKConstants.windowSurface = pSurface.get(0); } } } diff --git a/src/main/java/com/github/hydos/ginger/engine/vulkan/utils/VKUtils.java b/src/main/java/com/github/hydos/ginger/engine/vulkan/utils/VKUtils.java index f18fbd1..2d0c155 100644 --- a/src/main/java/com/github/hydos/ginger/engine/vulkan/utils/VKUtils.java +++ b/src/main/java/com/github/hydos/ginger/engine/vulkan/utils/VKUtils.java @@ -8,9 +8,9 @@ import org.lwjgl.glfw.*; import org.lwjgl.system.MemoryStack; import org.lwjgl.vulkan.*; -import com.github.hydos.ginger.engine.vulkan.VkConstants; +import com.github.hydos.ginger.engine.vulkan.VKConstants; -public class VkUtils +public class VKUtils { private static PointerBuffer getRequiredExtensions() { @@ -50,7 +50,7 @@ public class VkUtils throw new RuntimeException("Failed to create instance"); } - VkConstants.vulkanInstance = new VkInstance(instancePtr.get(0), createInfo); + VKConstants.vulkanInstance = new VkInstance(instancePtr.get(0), createInfo); } } @@ -59,7 +59,7 @@ public class VkUtils IntBuffer deviceCount = stack.ints(0); - VK12.vkEnumeratePhysicalDevices(VkConstants.vulkanInstance, deviceCount, null); + VK12.vkEnumeratePhysicalDevices(VKConstants.vulkanInstance, deviceCount, null); if(deviceCount.get(0) == 0) { throw new RuntimeException("Failed to find GPUs with Vulkan support"); @@ -67,13 +67,13 @@ public class VkUtils PointerBuffer ppPhysicalDevices = stack.mallocPointer(deviceCount.get(0)); - VK12.vkEnumeratePhysicalDevices(VkConstants.vulkanInstance, deviceCount, ppPhysicalDevices); + VK12.vkEnumeratePhysicalDevices(VKConstants.vulkanInstance, deviceCount, ppPhysicalDevices); VkPhysicalDevice device = null; for(int i = 0;i < ppPhysicalDevices.capacity();i++) { - device = new VkPhysicalDevice(ppPhysicalDevices.get(i), VkConstants.vulkanInstance); + device = new VkPhysicalDevice(ppPhysicalDevices.get(i), VKConstants.vulkanInstance); } @@ -81,7 +81,7 @@ public class VkUtils throw new RuntimeException("Failed to find a suitable GPU"); } - VkConstants.physicalDevice = device; + VKConstants.physicalDevice = device; } } @@ -129,19 +129,19 @@ public class VkUtils PointerBuffer pDevice = stack.pointers(VK12.VK_NULL_HANDLE); - if(VK12.vkCreateDevice(VkConstants.physicalDevice, createInfo, null, pDevice) != VK12.VK_SUCCESS) { + if(VK12.vkCreateDevice(VKConstants.physicalDevice, createInfo, null, pDevice) != VK12.VK_SUCCESS) { throw new RuntimeException("Failed to create logical device"); } - VkConstants.device = new VkDevice(pDevice.get(0), VkConstants.physicalDevice, createInfo); + VKConstants.device = new VkDevice(pDevice.get(0), VKConstants.physicalDevice, createInfo); PointerBuffer pQueue = stack.pointers(VK12.VK_NULL_HANDLE); - VK12.vkGetDeviceQueue(VkConstants.device, indices.graphicsFamily, 0, pQueue); - VkConstants.graphicsQueue = new VkQueue(pQueue.get(0), VkConstants.device); + VK12.vkGetDeviceQueue(VKConstants.device, indices.graphicsFamily, 0, pQueue); + VKConstants.graphicsQueue = new VkQueue(pQueue.get(0), VKConstants.device); - VK12.vkGetDeviceQueue(VkConstants.device, indices.presentFamily, 0, pQueue); - VkConstants.presentQueue = new VkQueue(pQueue.get(0), VkConstants.device); + VK12.vkGetDeviceQueue(VKConstants.device, indices.presentFamily, 0, pQueue); + VKConstants.presentQueue = new VkQueue(pQueue.get(0), VKConstants.device); } } @@ -153,11 +153,11 @@ public class VkUtils IntBuffer queueFamilyCount = stack.ints(0); - VK12.vkGetPhysicalDeviceQueueFamilyProperties(VkConstants.physicalDevice, queueFamilyCount, null); + VK12.vkGetPhysicalDeviceQueueFamilyProperties(VKConstants.physicalDevice, queueFamilyCount, null); VkQueueFamilyProperties.Buffer queueFamilies = VkQueueFamilyProperties.mallocStack(queueFamilyCount.get(0), stack); - VK12.vkGetPhysicalDeviceQueueFamilyProperties(VkConstants.physicalDevice, queueFamilyCount, queueFamilies); + VK12.vkGetPhysicalDeviceQueueFamilyProperties(VKConstants.physicalDevice, queueFamilyCount, queueFamilies); IntBuffer presentSupport = stack.ints(VK12.VK_FALSE); @@ -168,8 +168,8 @@ public class VkUtils } KHRSurface.vkGetPhysicalDeviceSurfaceSupportKHR( - VkConstants.physicalDevice, - i, VkConstants.windowSurface, + VKConstants.physicalDevice, + i, VKConstants.windowSurface, presentSupport); if(presentSupport.get(0) == VK12.VK_TRUE) { From ba367bf1f5d9b93a8754c22eae6ab4b6b0cb7501 Mon Sep 17 00:00:00 2001 From: halotroop2288 Date: Wed, 4 Mar 2020 12:24:32 -0800 Subject: [PATCH 2/6] [Refactor] Changes for consistency --- .../com/github/halotroop/litecraft/Litecraft.java | 7 ++++--- .../ginger/engine/common/api/GingerEngine.java | 4 ++-- .../ginger/engine/common/api/GingerRegister.java | 4 ++-- .../hydos/ginger/engine/opengl/api/GingerGL.java | 4 ++-- .../{Fbo.java => FrameBufferObject.java} | 4 ++-- .../opengl/postprocessing/ImageRenderer.java | 14 +++++++------- .../{api/GingerUtils.java => utils/GLUtils.java} | 4 ++-- .../hydos/ginger/engine/vulkan/api/GingerVK.java | 4 ++-- .../vulkan/io/{VkWindow.java => VKWindow.java} | 3 +-- 9 files changed, 24 insertions(+), 24 deletions(-) rename src/main/java/com/github/hydos/ginger/engine/opengl/postprocessing/{Fbo.java => FrameBufferObject.java} (98%) rename src/main/java/com/github/hydos/ginger/engine/opengl/{api/GingerUtils.java => utils/GLUtils.java} (93%) rename src/main/java/com/github/hydos/ginger/engine/vulkan/io/{VkWindow.java => VKWindow.java} (97%) diff --git a/src/main/java/com/github/halotroop/litecraft/Litecraft.java b/src/main/java/com/github/halotroop/litecraft/Litecraft.java index 79e002c..1a4a5bf 100644 --- a/src/main/java/com/github/halotroop/litecraft/Litecraft.java +++ b/src/main/java/com/github/halotroop/litecraft/Litecraft.java @@ -21,7 +21,8 @@ import com.github.hydos.ginger.engine.opengl.api.*; import com.github.hydos.ginger.engine.opengl.postprocessing.PostProcessing; import com.github.hydos.ginger.engine.opengl.render.MasterRenderer; import com.github.hydos.ginger.engine.opengl.render.models.GLTexturedModel; -import com.github.hydos.ginger.engine.opengl.utils.GLLoader; +import com.github.hydos.ginger.engine.opengl.utils.*; + import tk.valoeghese.gateways.client.io.*; public class Litecraft extends Game @@ -98,7 +99,7 @@ public class Litecraft extends Game public void renderWorld(Game game) { GameData data = game.data; - GingerUtils.preRenderScene(((GingerGL)engine).getRegistry().masterRenderer); + GLUtils.preRenderScene(((GingerGL)engine).getRegistry().masterRenderer); ((GingerGL)engine).contrastFbo.bindFBO(); ((GingerGL)engine).getRegistry().masterRenderer.renderScene(data.entities, data.normalMapEntities, data.lights, data.camera, data.clippingPlane); ((GingerGL)engine).contrastFbo.unbindFBO(); @@ -129,7 +130,7 @@ public class Litecraft extends Game KeyCallbackHandler.trackWindow(Window.getWindow()); MouseCallbackHandler.trackWindow(Window.getWindow()); // set up ginger utilities - GingerUtils.init(); + GLUtils.init(); switch (Window.renderAPI) { diff --git a/src/main/java/com/github/hydos/ginger/engine/common/api/GingerEngine.java b/src/main/java/com/github/hydos/ginger/engine/common/api/GingerEngine.java index 59d4b56..e32c806 100644 --- a/src/main/java/com/github/hydos/ginger/engine/common/api/GingerEngine.java +++ b/src/main/java/com/github/hydos/ginger/engine/common/api/GingerEngine.java @@ -5,7 +5,7 @@ import com.github.hydos.ginger.engine.common.io.Window; import com.github.hydos.ginger.engine.common.screen.Screen; import com.github.hydos.ginger.engine.common.util.Timer; import com.github.hydos.ginger.engine.common.util.Timer.TickListener; -import com.github.hydos.ginger.engine.opengl.api.GingerUtils; +import com.github.hydos.ginger.engine.opengl.utils.GLUtils; public abstract class GingerEngine { @@ -42,7 +42,7 @@ public abstract class GingerEngine // Things that should be run as often as possible, without limits public void update() { - GingerUtils.update(); + GLUtils.update(); Window.update(); } diff --git a/src/main/java/com/github/hydos/ginger/engine/common/api/GingerRegister.java b/src/main/java/com/github/hydos/ginger/engine/common/api/GingerRegister.java index 1b3b3c3..66abd75 100644 --- a/src/main/java/com/github/hydos/ginger/engine/common/api/GingerRegister.java +++ b/src/main/java/com/github/hydos/ginger/engine/common/api/GingerRegister.java @@ -6,7 +6,7 @@ import com.github.hydos.ginger.engine.common.api.game.Game; import com.github.hydos.ginger.engine.common.elements.buttons.TextureButton; import com.github.hydos.ginger.engine.common.font.GUIText; import com.github.hydos.ginger.engine.common.screen.Screen; -import com.github.hydos.ginger.engine.opengl.postprocessing.Fbo; +import com.github.hydos.ginger.engine.opengl.postprocessing.FrameBufferObject; import com.github.hydos.ginger.engine.opengl.render.MasterRenderer; /** Used if a game wants to access engine variables safely */ @@ -20,7 +20,7 @@ public class GingerRegister public List texts; public List guiButtons; - public List fbos; + public List frameBufferObjects; public Game game; public Screen currentScreen; public boolean wireframe = false; diff --git a/src/main/java/com/github/hydos/ginger/engine/opengl/api/GingerGL.java b/src/main/java/com/github/hydos/ginger/engine/opengl/api/GingerGL.java index 89fd60b..324105f 100644 --- a/src/main/java/com/github/hydos/ginger/engine/opengl/api/GingerGL.java +++ b/src/main/java/com/github/hydos/ginger/engine/opengl/api/GingerGL.java @@ -19,7 +19,7 @@ public class GingerGL extends GingerEngine { public MousePicker picker; public FontType globalFont; - public Fbo contrastFbo; + public FrameBufferObject contrastFbo; public void cleanup() { @@ -77,7 +77,7 @@ public class GingerGL extends GingerEngine getRegistry().registerGame(game); timer = new Timer(game.data.tickSpeed); timer.addTickListener(gameTickListener); - contrastFbo = new Fbo(new ContrastChanger()); + contrastFbo = new FrameBufferObject(new ContrastChanger()); getRegistry().masterRenderer = masterRenderer; picker = new MousePicker(game.data.camera, masterRenderer.getProjectionMatrix()); PostProcessing.init(); diff --git a/src/main/java/com/github/hydos/ginger/engine/opengl/postprocessing/Fbo.java b/src/main/java/com/github/hydos/ginger/engine/opengl/postprocessing/FrameBufferObject.java similarity index 98% rename from src/main/java/com/github/hydos/ginger/engine/opengl/postprocessing/Fbo.java rename to src/main/java/com/github/hydos/ginger/engine/opengl/postprocessing/FrameBufferObject.java index 38bd3de..357b2ac 100644 --- a/src/main/java/com/github/hydos/ginger/engine/opengl/postprocessing/Fbo.java +++ b/src/main/java/com/github/hydos/ginger/engine/opengl/postprocessing/FrameBufferObject.java @@ -11,7 +11,7 @@ import org.lwjgl.system.Callback; import com.github.hydos.ginger.engine.common.fbo.FboCallbackHandler; import com.github.hydos.ginger.engine.common.io.Window; -public class Fbo +public class FrameBufferObject { long window; int width = 1024; @@ -34,7 +34,7 @@ public class Fbo GLFWFramebufferSizeCallback fbCallback; Callback debugProc; - public Fbo(FboCallbackHandler handler) + public FrameBufferObject(FboCallbackHandler handler) { this.handler = handler; this.window = Window.getWindow(); diff --git a/src/main/java/com/github/hydos/ginger/engine/opengl/postprocessing/ImageRenderer.java b/src/main/java/com/github/hydos/ginger/engine/opengl/postprocessing/ImageRenderer.java index d4cf3c0..2459452 100644 --- a/src/main/java/com/github/hydos/ginger/engine/opengl/postprocessing/ImageRenderer.java +++ b/src/main/java/com/github/hydos/ginger/engine/opengl/postprocessing/ImageRenderer.java @@ -4,27 +4,27 @@ import org.lwjgl.opengl.GL11; public class ImageRenderer { - private Fbo fbo; + private FrameBufferObject frameBufferObject; protected ImageRenderer() {} protected ImageRenderer(int width, int height) - { this.fbo = new Fbo(new ContrastChanger()); } + { this.frameBufferObject = new FrameBufferObject(new ContrastChanger()); } protected void cleanUp() {} protected int getOutputTexture() - { return fbo.colorTexture; } + { return frameBufferObject.colorTexture; } protected void renderQuad() { - if (fbo != null) - { fbo.bindFBO(); } + if (frameBufferObject != null) + { frameBufferObject.bindFBO(); } GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); GL11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, 4); - if (fbo != null) - { fbo.unbindFBO(); } + if (frameBufferObject != null) + { frameBufferObject.unbindFBO(); } } } diff --git a/src/main/java/com/github/hydos/ginger/engine/opengl/api/GingerUtils.java b/src/main/java/com/github/hydos/ginger/engine/opengl/utils/GLUtils.java similarity index 93% rename from src/main/java/com/github/hydos/ginger/engine/opengl/api/GingerUtils.java rename to src/main/java/com/github/hydos/ginger/engine/opengl/utils/GLUtils.java index 460c4ec..bf04320 100644 --- a/src/main/java/com/github/hydos/ginger/engine/opengl/api/GingerUtils.java +++ b/src/main/java/com/github/hydos/ginger/engine/opengl/utils/GLUtils.java @@ -1,4 +1,4 @@ -package com.github.hydos.ginger.engine.opengl.api; +package com.github.hydos.ginger.engine.opengl.utils; import com.github.hydos.ginger.engine.common.font.TextMaster; import com.github.hydos.ginger.engine.common.obj.ModelLoader; @@ -7,7 +7,7 @@ import com.github.hydos.ginger.engine.opengl.render.MasterRenderer; import com.github.hydos.ginger.engine.opengl.render.models.*; import com.github.hydos.ginger.engine.opengl.render.texture.ModelTexture; -public class GingerUtils +public class GLUtils { public static GLTexturedModel createTexturedModel(String texturePath, String modelPath) { diff --git a/src/main/java/com/github/hydos/ginger/engine/vulkan/api/GingerVK.java b/src/main/java/com/github/hydos/ginger/engine/vulkan/api/GingerVK.java index 75cd493..28766b8 100644 --- a/src/main/java/com/github/hydos/ginger/engine/vulkan/api/GingerVK.java +++ b/src/main/java/com/github/hydos/ginger/engine/vulkan/api/GingerVK.java @@ -1,6 +1,6 @@ package com.github.hydos.ginger.engine.vulkan.api; -import com.github.hydos.ginger.engine.vulkan.io.VkWindow; +import com.github.hydos.ginger.engine.vulkan.io.VKWindow; import com.github.hydos.ginger.engine.vulkan.utils.VKUtils; public class GingerVK @@ -9,7 +9,7 @@ public class GingerVK { System.out.println("Game " + gameName + " successfuly started in Vulkan mode."); VKUtils.createInstance(); - VkWindow.createSurface(); + VKWindow.createSurface(); VKUtils.createPhysicalDevice(); VKUtils.createLogicalDevice(); } diff --git a/src/main/java/com/github/hydos/ginger/engine/vulkan/io/VkWindow.java b/src/main/java/com/github/hydos/ginger/engine/vulkan/io/VKWindow.java similarity index 97% rename from src/main/java/com/github/hydos/ginger/engine/vulkan/io/VkWindow.java rename to src/main/java/com/github/hydos/ginger/engine/vulkan/io/VKWindow.java index 7b60e6d..202d35e 100644 --- a/src/main/java/com/github/hydos/ginger/engine/vulkan/io/VkWindow.java +++ b/src/main/java/com/github/hydos/ginger/engine/vulkan/io/VKWindow.java @@ -13,9 +13,8 @@ import com.github.hydos.ginger.engine.vulkan.utils.*; /** * used for window related vulkan only things * @author hydos - * */ -public class VkWindow +public class VKWindow { public static void createSurface() { From 33b0cf77878f809432b7510f3ad367c2b30858da Mon Sep 17 00:00:00 2001 From: halotroop2288 Date: Wed, 4 Mar 2020 12:40:12 -0800 Subject: [PATCH 3/6] Abstracted Camera --- .../github/halotroop/litecraft/Litecraft.java | 2 +- .../ginger/engine/common/cameras/Camera.java | 97 ++----------------- .../common/cameras/FirstPersonCamera.java | 7 +- .../common/cameras/ThirdPersonCamera.java | 85 ++++++++++++++++ 4 files changed, 95 insertions(+), 96 deletions(-) create mode 100644 src/main/java/com/github/hydos/ginger/engine/common/cameras/ThirdPersonCamera.java diff --git a/src/main/java/com/github/halotroop/litecraft/Litecraft.java b/src/main/java/com/github/halotroop/litecraft/Litecraft.java index 1a4a5bf..6998f4f 100644 --- a/src/main/java/com/github/halotroop/litecraft/Litecraft.java +++ b/src/main/java/com/github/halotroop/litecraft/Litecraft.java @@ -189,7 +189,7 @@ public class Litecraft extends Game { Input.invokeAllListeners(); ((PlayerEntity) this.player).updateMovement(); - data.camera.updateMovement(); + camera.updateMovement(); } } diff --git a/src/main/java/com/github/hydos/ginger/engine/common/cameras/Camera.java b/src/main/java/com/github/hydos/ginger/engine/common/cameras/Camera.java index 4f7074e..e85cbbc 100644 --- a/src/main/java/com/github/hydos/ginger/engine/common/cameras/Camera.java +++ b/src/main/java/com/github/hydos/ginger/engine/common/cameras/Camera.java @@ -1,92 +1,20 @@ package com.github.hydos.ginger.engine.common.cameras; import org.joml.Vector3f; -import org.lwjgl.glfw.*; import com.github.hydos.ginger.engine.common.elements.objects.RenderObject; -import com.github.hydos.ginger.engine.common.io.Window; -public class Camera +public abstract class Camera { - private float distanceFromPlayer = 5; - private float angleAroundPlayer = 0; - private Vector3f position = new Vector3f(0, 0, 0); - private float pitch, yaw; - private float roll; public RenderObject player; - - public Camera(RenderObject playerEntity) - { this.player = playerEntity; } - - public Camera(Vector3f vector3f, RenderObject player) - { - this.position = vector3f; - this.player = player; - } - - private void calculateAngleAroundPlayer() - { - if (Window.isMouseDown(1)) - { - float angleChange = (float) (Window.dx * 0.3f); - angleAroundPlayer -= angleChange; - } - } - - private void calculateCameraPosition(float horizDistance, float verticDistance) - { - float theta = player.getRotY() + angleAroundPlayer; - float offsetX = (float) (horizDistance * Math.sin(Math.toRadians(theta))); - float offsetZ = (float) (horizDistance * Math.cos(Math.toRadians(theta))); - position.x = player.getPosition().x - offsetX; - position.z = player.getPosition().z - offsetZ; - position.y = player.getPosition().y + verticDistance; - } - - private float calculateHorizontalDistance() - { - float hD = (float) (distanceFromPlayer * Math.cos(Math.toRadians(pitch))); - if (hD < 0) - hD = 0; - return hD; - } - - private void calculatePitch() - { - if (Window.isMouseDown(1)) - { - float pitchChange = (float) (Window.dy * 0.2f); - pitch += pitchChange; - if (pitch < 0) - { - pitch = 0; - } - else if (pitch > 90) - { pitch = 90; } - } - } - - private float calculateVerticalDistance() - { return (float) (distanceFromPlayer * Math.sin(Math.toRadians(pitch + 4))); } - - private void calculateZoom() - { - GLFW.glfwSetScrollCallback(Window.getWindow(), new GLFWScrollCallback() - { - @Override - public void invoke(long win, double dx, double dy) - { - float zoomLevel = (float) dy * 0.1f; - distanceFromPlayer -= zoomLevel; - } - }); - } - - public float getPitch() - { return pitch; } + private float pitch, yaw, roll; + private Vector3f position = new Vector3f(0, 0, 0); public Vector3f getPosition() { return position; } + + public float getPitch() + { return pitch; } public float getRoll() { return roll; } @@ -97,17 +25,6 @@ public class Camera public void invertPitch() { this.pitch = -pitch; } - public void updateMovement() - { - calculateZoom(); - calculatePitch(); - calculateAngleAroundPlayer(); - float horizontalDistance = calculateHorizontalDistance(); - float verticalDistance = calculateVerticalDistance(); - calculateCameraPosition(horizontalDistance, verticalDistance); - this.yaw = 180 - (player.getRotY() + angleAroundPlayer); - } - public void setPitch(float pitch) { this.pitch = pitch; } @@ -116,4 +33,6 @@ public class Camera public void setRoll(float roll) { this.roll = roll; } + + public abstract void updateMovement(); } diff --git a/src/main/java/com/github/hydos/ginger/engine/common/cameras/FirstPersonCamera.java b/src/main/java/com/github/hydos/ginger/engine/common/cameras/FirstPersonCamera.java index 90127e2..a3b7535 100644 --- a/src/main/java/com/github/hydos/ginger/engine/common/cameras/FirstPersonCamera.java +++ b/src/main/java/com/github/hydos/ginger/engine/common/cameras/FirstPersonCamera.java @@ -13,27 +13,22 @@ public class FirstPersonCamera extends Camera public FirstPersonCamera(RenderObject playerEntity) { - super(playerEntity); + this.player = playerEntity; playerEntity.setVisible(false); } - @Override public float getPitch() { return pitch; } - @Override public Vector3f getPosition() { return position; } - @Override public float getRoll() { return roll; } - @Override public float getYaw() { return yaw; } - @Override public void updateMovement() { position.x = player.getPosition().x; diff --git a/src/main/java/com/github/hydos/ginger/engine/common/cameras/ThirdPersonCamera.java b/src/main/java/com/github/hydos/ginger/engine/common/cameras/ThirdPersonCamera.java new file mode 100644 index 0000000..66f7576 --- /dev/null +++ b/src/main/java/com/github/hydos/ginger/engine/common/cameras/ThirdPersonCamera.java @@ -0,0 +1,85 @@ +package com.github.hydos.ginger.engine.common.cameras; + +import org.lwjgl.glfw.*; + +import com.github.hydos.ginger.engine.common.elements.objects.RenderObject; +import com.github.hydos.ginger.engine.common.io.Window; + +public class ThirdPersonCamera extends Camera +{ + public ThirdPersonCamera(RenderObject playerEntity) + { + this.player = playerEntity; + } + + private float distanceFromPlayer = 5; + private float angleAroundPlayer = 0; + private void calculatePitch() + { + if (Window.isMouseDown(1)) + { + float pitchChange = (float) (Window.dy * 0.2f); + setPitch(getPitch() + pitchChange); + if (getPitch() < 0) + { + setPitch(0); + } + else if (getPitch() > 90) + { setPitch(90); } + } + } + + public void updateMovement() + { + calculateZoom(); + calculatePitch(); + calculateAngleAroundPlayer(); + float horizontalDistance = calculateHorizontalDistance(); + float verticalDistance = calculateVerticalDistance(); + calculateCameraPosition(horizontalDistance, verticalDistance); + this.setYaw(180 - (player.getRotY() + angleAroundPlayer)); + } + + private float calculateHorizontalDistance() + { + float hD = (float) (distanceFromPlayer * Math.cos(Math.toRadians(getPitch()))); + if (hD < 0) + hD = 0; + return hD; + } + + private float calculateVerticalDistance() + { return (float) (distanceFromPlayer * Math.sin(Math.toRadians(getPitch() + 4))); } + + private void calculateZoom() + { + GLFW.glfwSetScrollCallback(Window.getWindow(), new GLFWScrollCallback() + { + @Override + public void invoke(long win, double dx, double dy) + { + float zoomLevel = (float) dy * 0.1f; + distanceFromPlayer -= zoomLevel; + } + }); + } + + private void calculateAngleAroundPlayer() + { + if (Window.isMouseDown(1)) + { + float angleChange = (float) (Window.dx * 0.3f); + angleAroundPlayer -= angleChange; + } + } + + private void calculateCameraPosition(float horizDistance, float verticDistance) + { + float theta = player.getRotY() + angleAroundPlayer; + float offsetX = (float) (horizDistance * Math.sin(Math.toRadians(theta))); + float offsetZ = (float) (horizDistance * Math.cos(Math.toRadians(theta))); + getPosition().x = player.getPosition().x - offsetX; + getPosition().z = player.getPosition().z - offsetZ; + getPosition().y = player.getPosition().y + verticDistance; + } +} From 4969939fdc58f19e3594690659942e586568f7e2 Mon Sep 17 00:00:00 2001 From: halotroop2288 Date: Wed, 4 Mar 2020 12:43:14 -0800 Subject: [PATCH 4/6] [Refactor] Changes for consistency part 2 (FBO is an acryonym) --- .../{FboCallbackHandler.java => FBOCallbackHandler.java} | 2 +- .../com/github/hydos/ginger/engine/common/io/Window.java | 2 +- .../engine/opengl/postprocessing/ContrastChanger.java | 4 ++-- .../engine/opengl/postprocessing/FrameBufferObject.java | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) rename src/main/java/com/github/hydos/ginger/engine/common/fbo/{FboCallbackHandler.java => FBOCallbackHandler.java} (78%) diff --git a/src/main/java/com/github/hydos/ginger/engine/common/fbo/FboCallbackHandler.java b/src/main/java/com/github/hydos/ginger/engine/common/fbo/FBOCallbackHandler.java similarity index 78% rename from src/main/java/com/github/hydos/ginger/engine/common/fbo/FboCallbackHandler.java rename to src/main/java/com/github/hydos/ginger/engine/common/fbo/FBOCallbackHandler.java index 8281895..d6bd767 100644 --- a/src/main/java/com/github/hydos/ginger/engine/common/fbo/FboCallbackHandler.java +++ b/src/main/java/com/github/hydos/ginger/engine/common/fbo/FBOCallbackHandler.java @@ -1,6 +1,6 @@ package com.github.hydos.ginger.engine.common.fbo; -public abstract class FboCallbackHandler +public abstract class FBOCallbackHandler { public void cleanUp() {} diff --git a/src/main/java/com/github/hydos/ginger/engine/common/io/Window.java b/src/main/java/com/github/hydos/ginger/engine/common/io/Window.java index 0883a2f..c6d54bb 100644 --- a/src/main/java/com/github/hydos/ginger/engine/common/io/Window.java +++ b/src/main/java/com/github/hydos/ginger/engine/common/io/Window.java @@ -48,7 +48,7 @@ public class Window static double newY = 0; public static GLCapabilities glContext; public static int actualWidth, actualHeight; - //temp stuff to test out fbo fixes + // FIXME: temp stuff to test out FBO fixes private static int oldWindowWidth = Window.getWidth(); private static int oldWindowHeight = Window.getHeight(); diff --git a/src/main/java/com/github/hydos/ginger/engine/opengl/postprocessing/ContrastChanger.java b/src/main/java/com/github/hydos/ginger/engine/opengl/postprocessing/ContrastChanger.java index 1e8b5bd..e6b4abd 100644 --- a/src/main/java/com/github/hydos/ginger/engine/opengl/postprocessing/ContrastChanger.java +++ b/src/main/java/com/github/hydos/ginger/engine/opengl/postprocessing/ContrastChanger.java @@ -2,9 +2,9 @@ package com.github.hydos.ginger.engine.opengl.postprocessing; import org.lwjgl.opengl.*; -import com.github.hydos.ginger.engine.common.fbo.FboCallbackHandler; +import com.github.hydos.ginger.engine.common.fbo.FBOCallbackHandler; -public class ContrastChanger extends FboCallbackHandler +public class ContrastChanger extends FBOCallbackHandler { private ImageRenderer renderer; private ContrastShader shader; diff --git a/src/main/java/com/github/hydos/ginger/engine/opengl/postprocessing/FrameBufferObject.java b/src/main/java/com/github/hydos/ginger/engine/opengl/postprocessing/FrameBufferObject.java index 357b2ac..69bd897 100644 --- a/src/main/java/com/github/hydos/ginger/engine/opengl/postprocessing/FrameBufferObject.java +++ b/src/main/java/com/github/hydos/ginger/engine/opengl/postprocessing/FrameBufferObject.java @@ -8,7 +8,7 @@ import java.nio.ByteBuffer; import org.lwjgl.glfw.*; import org.lwjgl.system.Callback; -import com.github.hydos.ginger.engine.common.fbo.FboCallbackHandler; +import com.github.hydos.ginger.engine.common.fbo.FBOCallbackHandler; import com.github.hydos.ginger.engine.common.io.Window; public class FrameBufferObject @@ -20,7 +20,7 @@ public class FrameBufferObject boolean destroyed; Object lock = new Object(); /* cool ginger feature which handles fbos once they need to be rendered */ - public FboCallbackHandler handler; + public FBOCallbackHandler handler; /* Multisampled FBO objects */ public int multisampledColorRenderBuffer; int multisampledDepthRenderBuffer; @@ -34,7 +34,7 @@ public class FrameBufferObject GLFWFramebufferSizeCallback fbCallback; Callback debugProc; - public FrameBufferObject(FboCallbackHandler handler) + public FrameBufferObject(FBOCallbackHandler handler) { this.handler = handler; this.window = Window.getWindow(); From 8d6220386f8e169d1058127bc677029bab104904 Mon Sep 17 00:00:00 2001 From: halotroop2288 Date: Wed, 4 Mar 2020 12:54:06 -0800 Subject: [PATCH 5/6] Render Overlays without asking for an instance of the game --- src/main/java/com/github/halotroop/litecraft/Litecraft.java | 3 +-- .../github/hydos/ginger/engine/common/api/GingerEngine.java | 3 +-- .../hydos/ginger/engine/common/obj/shapes/StaticCube.java | 3 +-- .../com/github/hydos/ginger/engine/opengl/api/GingerGL.java | 4 ++-- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/github/halotroop/litecraft/Litecraft.java b/src/main/java/com/github/halotroop/litecraft/Litecraft.java index 6998f4f..b218805 100644 --- a/src/main/java/com/github/halotroop/litecraft/Litecraft.java +++ b/src/main/java/com/github/halotroop/litecraft/Litecraft.java @@ -81,7 +81,7 @@ public class Litecraft extends Game // If there's a world, render it! if (this.world != null) renderWorld(this); // Render any overlays (GUIs, HUDs) - this.engine.renderOverlays(this); + this.engine.renderOverlays(); // Put what's stored in the inactive framebuffer on the screen Window.swapBuffers(); } @@ -104,7 +104,6 @@ public class Litecraft extends Game ((GingerGL)engine).getRegistry().masterRenderer.renderScene(data.entities, data.normalMapEntities, data.lights, data.camera, data.clippingPlane); ((GingerGL)engine).contrastFbo.unbindFBO(); PostProcessing.doPostProcessing(((GingerGL)engine).contrastFbo.colorTexture); - if (data.handleGuis) ((GingerGL)engine).renderOverlays(game); } public void update() diff --git a/src/main/java/com/github/hydos/ginger/engine/common/api/GingerEngine.java b/src/main/java/com/github/hydos/ginger/engine/common/api/GingerEngine.java index e32c806..88fec91 100644 --- a/src/main/java/com/github/hydos/ginger/engine/common/api/GingerEngine.java +++ b/src/main/java/com/github/hydos/ginger/engine/common/api/GingerEngine.java @@ -1,6 +1,5 @@ package com.github.hydos.ginger.engine.common.api; -import com.github.hydos.ginger.engine.common.api.game.Game; import com.github.hydos.ginger.engine.common.io.Window; import com.github.hydos.ginger.engine.common.screen.Screen; import com.github.hydos.ginger.engine.common.util.Timer; @@ -50,5 +49,5 @@ public abstract class GingerEngine public abstract void openScreen(Screen screen); - public abstract void renderOverlays(Game game); + public abstract void renderOverlays(); } diff --git a/src/main/java/com/github/hydos/ginger/engine/common/obj/shapes/StaticCube.java b/src/main/java/com/github/hydos/ginger/engine/common/obj/shapes/StaticCube.java index c04afff..b9ff4b3 100644 --- a/src/main/java/com/github/hydos/ginger/engine/common/obj/shapes/StaticCube.java +++ b/src/main/java/com/github/hydos/ginger/engine/common/obj/shapes/StaticCube.java @@ -83,8 +83,7 @@ public class StaticCube public static Mesh getCube() { - if (mesh == null) - { mesh = new Mesh(vertices, textureCoords, new float[vertices.length], indices, vertices.length); } + if (mesh == null) mesh = new Mesh(vertices, textureCoords, new float[vertices.length], indices, vertices.length); return mesh; } } diff --git a/src/main/java/com/github/hydos/ginger/engine/opengl/api/GingerGL.java b/src/main/java/com/github/hydos/ginger/engine/opengl/api/GingerGL.java index 324105f..51d17c9 100644 --- a/src/main/java/com/github/hydos/ginger/engine/opengl/api/GingerGL.java +++ b/src/main/java/com/github/hydos/ginger/engine/opengl/api/GingerGL.java @@ -60,9 +60,9 @@ public class GingerGL extends GingerEngine return text; } - public void renderOverlays(Game game) + public void renderOverlays() { - getRegistry().masterRenderer.renderGuis(game.data.guis); + getRegistry().masterRenderer.renderGuis(getRegistry().game.data.guis); if (getRegistry().currentScreen != null) getRegistry().masterRenderer.renderGuis(getRegistry().currentScreen.elements); TextMaster.render(); } From fc2191419eeecdbfe0d8dfd1e77f11aea919c9c9 Mon Sep 17 00:00:00 2001 From: halotroop2288 Date: Wed, 4 Mar 2020 13:11:07 -0800 Subject: [PATCH 6/6] Fixed chunk rendering issues and possibly framerate issues --- .../github/halotroop/litecraft/Litecraft.java | 36 ++++++++++--------- .../github/halotroop/litecraft/StarterGL.java | 3 +- .../halotroop/litecraft/world/World.java | 11 +++--- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/github/halotroop/litecraft/Litecraft.java b/src/main/java/com/github/halotroop/litecraft/Litecraft.java index b218805..3aa1d67 100644 --- a/src/main/java/com/github/halotroop/litecraft/Litecraft.java +++ b/src/main/java/com/github/halotroop/litecraft/Litecraft.java @@ -37,15 +37,19 @@ public class Litecraft extends Game public Vector4i dbgStats = new Vector4i(); private long frameTimer; - public Litecraft() + public Litecraft(int windowWidth, int windowHeight, float frameLimit) { Litecraft.INSTANCE = this; // set constants this.setupConstants(); - this.setupGinger(1280, 720, 60); - Blocks.init(); // make sure blocks are initialised + this.setupGinger(windowWidth, windowHeight, frameLimit); + // make sure blocks are initialised ??? (Currently does nothing) + Blocks.init(); this.frameTimer = System.currentTimeMillis(); - setupKeybinds(); // setup keybinds + // setup keybinds + setupKeybinds(); + // Open the title screen if nothing is already open. + if (GingerRegister.getInstance().currentScreen == null && world == null) ((GingerGL)engine).openScreen(new TitleScreen()); // start the game loop this.engine.startGameLoop(); } @@ -79,7 +83,7 @@ public class Litecraft extends Game // Render shadows GingerRegister.getInstance().masterRenderer.renderShadowMap(data.entities, data.lights.get(0)); // If there's a world, render it! - if (this.world != null) renderWorld(this); + if (this.world != null) renderWorld(); // Render any overlays (GUIs, HUDs) this.engine.renderOverlays(); // Put what's stored in the inactive framebuffer on the screen @@ -96,14 +100,17 @@ public class Litecraft extends Game this.frameTimer += 1000; } - public void renderWorld(Game game) + public void renderWorld() { - GameData data = game.data; - GLUtils.preRenderScene(((GingerGL)engine).getRegistry().masterRenderer); - ((GingerGL)engine).contrastFbo.bindFBO(); - ((GingerGL)engine).getRegistry().masterRenderer.renderScene(data.entities, data.normalMapEntities, data.lights, data.camera, data.clippingPlane); - ((GingerGL)engine).contrastFbo.unbindFBO(); - PostProcessing.doPostProcessing(((GingerGL)engine).contrastFbo.colorTexture); + GameData data = GingerRegister.getInstance().game.data; + if (Window.renderAPI == RenderAPI.OpenGL) + { + GLUtils.preRenderScene(((GingerGL)engine).getRegistry().masterRenderer); + ((GingerGL)engine).contrastFbo.bindFBO(); + ((GingerGL)engine).getRegistry().masterRenderer.renderScene(data.entities, data.normalMapEntities, data.lights, data.camera, data.clippingPlane); + ((GingerGL)engine).contrastFbo.unbindFBO(); + PostProcessing.doPostProcessing(((GingerGL)engine).contrastFbo.colorTexture); + } } public void update() @@ -180,10 +187,7 @@ public class Litecraft extends Game @Override public void tick() { - tps += 1; - // Open the title screen if it's not already open. - if (GingerRegister.getInstance().currentScreen == null && world == null) ((GingerGL)engine).openScreen(new TitleScreen()); - + tps += 1; if (this.player instanceof PlayerEntity && camera != null) { Input.invokeAllListeners(); diff --git a/src/main/java/com/github/halotroop/litecraft/StarterGL.java b/src/main/java/com/github/halotroop/litecraft/StarterGL.java index 5266289..3b3a30b 100644 --- a/src/main/java/com/github/halotroop/litecraft/StarterGL.java +++ b/src/main/java/com/github/halotroop/litecraft/StarterGL.java @@ -11,6 +11,7 @@ public class StarterGL System.out.println("GLFW version: " + GLFW.glfwGetVersionString()); System.out.println("LWJGL version: " + Version.getVersion()); // Put SoundSystem version here - new Litecraft(); + // TODO: Put a commandline reader here to check for desired width, height, and frame limit! + new Litecraft(1280, 720, 60); } } diff --git a/src/main/java/com/github/halotroop/litecraft/world/World.java b/src/main/java/com/github/halotroop/litecraft/world/World.java index d907db5..e0afe89 100644 --- a/src/main/java/com/github/halotroop/litecraft/world/World.java +++ b/src/main/java/com/github/halotroop/litecraft/world/World.java @@ -178,14 +178,11 @@ public class World implements BlockAccess, WorldGenConstants public void render(BlockRenderer blockRenderer) { blockRenderer.prepareModel(this.dummy.getModel()); - try + this.chunks.forEach((pos, c) -> { - this.chunks.forEach((pos, c) -> c.render(blockRenderer)); - } - catch (NullPointerException e) - { - System.out.println("Null chunk - we should look into fixing this"); - } + if (c != null && c.isFullyGenerated()) + c.render(blockRenderer); + }); blockRenderer.unbindModel(); }