Merge branch 'liteCraft' into Vulkan

liteCraft
hYdos 2020-03-05 07:41:37 +10:00
commit 2c97efa6e7
20 changed files with 162 additions and 172 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<classpathentry kind="src" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
@ -16,18 +16,11 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<classpathentry kind="src" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@ -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
@ -36,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();
}
@ -78,9 +83,9 @@ 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(this);
this.engine.renderOverlays();
// Put what's stored in the inactive framebuffer on the screen
Window.swapBuffers();
}
@ -95,15 +100,17 @@ public class Litecraft extends Game
this.frameTimer += 1000;
}
public void renderWorld(Game game)
public void renderWorld()
{
GameData data = game.data;
GingerUtils.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);
if (data.handleGuis) ((GingerGL)engine).renderOverlays(game);
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()
@ -129,7 +136,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)
{
@ -180,15 +187,12 @@ 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();
((PlayerEntity) this.player).updateMovement();
data.camera.updateMovement();
camera.updateMovement();
}
}

View File

@ -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);
}
}

View File

@ -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();
}

View File

@ -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 */

View File

@ -1,11 +1,10 @@
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;
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 +41,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();
}
@ -50,5 +49,5 @@ public abstract class GingerEngine
public abstract void openScreen(Screen screen);
public abstract void renderOverlays(Game game);
public abstract void renderOverlays();
}

View File

@ -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<GUIText> texts;
public List<TextureButton> guiButtons;
public List<Fbo> fbos;
public List<FrameBufferObject> frameBufferObjects;
public Game game;
public Screen currentScreen;
public boolean wireframe = false;

View File

@ -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();
}

View File

@ -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;

View File

@ -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;
}
}

View File

@ -1,6 +1,6 @@
package com.github.hydos.ginger.engine.common.fbo;
public abstract class FboCallbackHandler
public abstract class FBOCallbackHandler
{
public void cleanUp()
{}

View File

@ -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();

View File

@ -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;
}
}

View File

@ -19,7 +19,7 @@ public class GingerGL extends GingerEngine
{
public MousePicker picker;
public FontType globalFont;
public Fbo contrastFbo;
public FrameBufferObject contrastFbo;
public void cleanup()
{
@ -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();
}
@ -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();

View File

@ -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;

View File

@ -8,10 +8,10 @@ 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 Fbo
public class FrameBufferObject
{
long window;
int width = 1024;
@ -20,7 +20,7 @@ public class Fbo
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 Fbo
GLFWFramebufferSizeCallback fbCallback;
Callback debugProc;
public Fbo(FboCallbackHandler handler)
public FrameBufferObject(FBOCallbackHandler handler)
{
this.handler = handler;
this.window = Window.getWindow();

View File

@ -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(); }
}
}

View File

@ -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)
{

View File

@ -1,18 +1,17 @@
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
{
public void start(String gameName) {
public void start(String gameName)
{
System.out.println("Game " + gameName + " successfuly started in Vulkan mode.");
VKUtils.createInstance();
VkWindow.createSurface();
VKWindow.createSurface();
VKUtils.createPhysicalDevice();
VKUtils.createLogicalDevice();
}
}

View File

@ -8,14 +8,13 @@ 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.utils.*;
/**
* used for window related vulkan only things
* @author hydos
*
*/
public class VkWindow
public class VKWindow
{
public static void createSurface()
{