diff --git a/src/main/java/com/github/halotroop/litecraft/Litecraft.java b/src/main/java/com/github/halotroop/litecraft/Litecraft.java index 0ba1640..a8ea1e4 100644 --- a/src/main/java/com/github/halotroop/litecraft/Litecraft.java +++ b/src/main/java/com/github/halotroop/litecraft/Litecraft.java @@ -9,7 +9,6 @@ import com.github.halotroop.litecraft.screens.TitleScreen; import com.github.halotroop.litecraft.types.block.Blocks; import com.github.halotroop.litecraft.util.RelativeDirection; import com.github.halotroop.litecraft.world.World; -import com.github.halotroop.litecraft.world.dimension.Dimensions; import com.github.hydos.ginger.engine.api.*; import com.github.hydos.ginger.engine.api.game.*; import com.github.hydos.ginger.engine.cameras.*; @@ -34,8 +33,8 @@ public class Litecraft extends Game public Player player; private Camera camera; //temp stuff to test out fbo fixes - int oldWindowWidth = Window.width; - int oldWindowHeight = Window.height; + int oldWindowWidth = Window.getWidth(); + int oldWindowHeight = Window.getHeight(); public int fps, ups, tps, binds; public Vector4i dbgStats; private long frameTimer; @@ -52,8 +51,8 @@ public class Litecraft extends Game GingerUtils.init(); // set up ginger utilities // set up Ginger3D stuff this.setupGinger(); - this.oldWindowWidth = Window.width; - this.oldWindowHeight = Window.height; + this.oldWindowWidth = Window.getWidth(); + this.oldWindowHeight = Window.getHeight(); this.frameTimer = System.currentTimeMillis(); setupKeybinds(); // set up keybinds //start the game loop @@ -117,7 +116,7 @@ public class Litecraft extends Game this.world.unloadAllChunks(); try { - this.save.saveGlobalData(this.world.getSeed(), this.player); + this.getSave().saveGlobalData(this.world.getSeed(), this.player); } catch (IOException e) { @@ -140,23 +139,21 @@ public class Litecraft extends Game //FPS stuff sorry if i forget to remove whitespace if (System.currentTimeMillis() > frameTimer + 1000) // wait for one second { - this.dbgStats.set(fps, ups, tps, 0); + this.dbgStats.set(fps, ups, tps, this.threadWaitlist); this.fps = 0; this.ups = 0; this.tps = 0; this.frameTimer += 1000; // reset the wait time } // TODO pls comment this code - if (ginger3D.gingerRegister.currentScreen == null) - this.ginger3D.openScreen(new TitleScreen()); - this.ginger3D.update(data); - if (oldWindowHeight != Window.height || oldWindowWidth != Window.width && Window.height > 10 && Window.width > 10) + if (ginger3D.gingerRegister.currentScreen == null) ginger3D.openScreen(new TitleScreen()); + this.ginger3D.update(data); // FIXME: This should either be renamed to "render" or moved to tick() if it has nothing to do with rendering. + if (oldWindowHeight != Window.getHeight() || oldWindowWidth != Window.getWidth() && Window.getHeight() > 10 && Window.getWidth() > 10) this.ginger3D.contrastFbo.resizeFBOs(); - this.oldWindowWidth = Window.width; - this.oldWindowHeight = Window.height; + this.oldWindowWidth = Window.getWidth(); + this.oldWindowHeight = Window.getHeight(); this.ginger3D.gingerRegister.masterRenderer.renderShadowMap(data.entities, data.lights.get(0)); - if (this.world != null) - this.ginger3D.renderWorld(this, this.world); + if (this.world != null) this.ginger3D.renderWorld(this, this.world); this.ginger3D.renderOverlays(this); this.ginger3D.postRender(); this.dbgStats.w = binds; @@ -174,18 +171,19 @@ public class Litecraft extends Game public static Litecraft getInstance() { return INSTANCE; } - public void onPlayButtonClick() + public World getWorld() + { return this.world; } + + public LitecraftSave getSave() { - if (world == null) - { - this.save = new LitecraftSave("cegregatedordinaldata", false); - this.world = this.save.getWorldOrCreate(Dimensions.OVERWORLD); - ginger3D.setGingerPlayer(this.world.player); - } + return save; } - public World getWorld() + public void changeWorld(World world) + { this.world = world; } + + public void setSave(LitecraftSave save) { - return this.world; + this.save = save; } } \ No newline at end of file diff --git a/src/main/java/com/github/halotroop/litecraft/screens/TitleScreen.java b/src/main/java/com/github/halotroop/litecraft/screens/TitleScreen.java index 5bf5d80..8ee8d81 100644 --- a/src/main/java/com/github/halotroop/litecraft/screens/TitleScreen.java +++ b/src/main/java/com/github/halotroop/litecraft/screens/TitleScreen.java @@ -5,6 +5,8 @@ import java.util.ArrayList; import org.joml.*; import com.github.halotroop.litecraft.Litecraft; +import com.github.halotroop.litecraft.save.LitecraftSave; +import com.github.halotroop.litecraft.world.dimension.Dimensions; import com.github.hydos.ginger.engine.api.Ginger; import com.github.hydos.ginger.engine.elements.GuiTexture; import com.github.hydos.ginger.engine.elements.buttons.TextureButton; @@ -17,40 +19,56 @@ import com.github.hydos.ginger.engine.screen.Screen; */ public class TitleScreen extends Screen { - GUIText buildText; - Ginger ginger3D; - TextureButton playButton; - Litecraft litecraft; + private GUIText debugText; + private Ginger ginger3D = Ginger.getInstance(); + private TextureButton playButton; + private Litecraft litecraft = Litecraft.getInstance(); public TitleScreen() { - ginger3D = Ginger.getInstance(); elements = new ArrayList(); - playButton = ginger3D.registerButton("/textures/guis/purpur.png", new Vector2f(0, 0), new Vector2f(0.25f, 0.1f)); + playButton = ginger3D.registerButton("/textures/guis/playbutton.png", new Vector2f(0, 0), new Vector2f(0.25f, 0.1f)); playButton.show(Litecraft.getInstance().data.guis); - buildText = ginger3D.registerText("LiteCraft", 3, new Vector2f(0, 0), 1f, true, "PLAYBUTTON"); - buildText.setBorderWidth(0.5f); + debugText = ginger3D.registerText("Loading...", 2, new Vector2f(0, 0), 1f, true, "debugInfo"); + debugText.setBorderWidth(0.5f); } @Override - public void render() // FIXME: This never gets called!!! + public void render() {} @Override public void tick() { - if(litecraft == null) { - litecraft = Litecraft.getInstance(); - } Vector4i dbg = litecraft.dbgStats; - buildText.setText("FPS: " + dbg.x() + " Position " + litecraft.player.getPosition().toString() + " World Chunk Threads: " + litecraft.threadWaitlist); + debugText.setText("FPS: " + dbg.x() + " UPS: " + dbg.y + " TPS: " + dbg.z); playButton.update(); if (playButton.isClicked()) { Window.lockMouse(); - playButton.hide(Litecraft.getInstance().data.guis); - Litecraft.getInstance().onPlayButtonClick();//TODO: add world gui so it takes u to world creation place - //TODO: also add a texture to be rendered behind the gui as an option + + if (Litecraft.getInstance().getWorld() == null) + { + Litecraft.getInstance().setSave(new LitecraftSave("cegregatedordinaldata", false)); + Litecraft.getInstance().changeWorld(Litecraft.getInstance().getSave().getWorldOrCreate(Dimensions.OVERWORLD)); + ginger3D.setGingerPlayer(Litecraft.getInstance().getWorld().player); + } + if (Litecraft.getInstance().getWorld() != null) + { + ginger3D.openScreen(new IngameHUD()); + this.close(); + } + //TODO: add world creation gui so it takes u to world creation place + //TODO: add a texture to be rendered behind the gui as an option } } + + @Override + public void close() + { + this.debugText.remove(); + this.debugText = null; + this.playButton.hide(this.elements); + this.playButton = null; + } } diff --git a/src/main/java/com/github/hydos/ginger/engine/api/Ginger.java b/src/main/java/com/github/hydos/ginger/engine/api/Ginger.java index 8343c84..2042096 100644 --- a/src/main/java/com/github/hydos/ginger/engine/api/Ginger.java +++ b/src/main/java/com/github/hydos/ginger/engine/api/Ginger.java @@ -28,6 +28,7 @@ public class Ginger public Fbo contrastFbo; public GingerThreading threading; Timer timer; + TickListener gameTickListener = new TickListener() { @Override @@ -123,13 +124,10 @@ public class Ginger while (!Window.closed()) { Litecraft.getInstance().ups++; - if (Window.shouldRender()) - { - timer.tick(); - gingerRegister.game.render(); - } + timer.tick(); + if (Window.shouldRender()) gingerRegister.game.render(); } - Litecraft.getInstance().exit(); + gingerRegister.game.exit(); } public void update(GameData data) diff --git a/src/main/java/com/github/hydos/ginger/engine/elements/buttons/TextureButton.java b/src/main/java/com/github/hydos/ginger/engine/elements/buttons/TextureButton.java index c907b3f..0617dc0 100644 --- a/src/main/java/com/github/hydos/ginger/engine/elements/buttons/TextureButton.java +++ b/src/main/java/com/github/hydos/ginger/engine/elements/buttons/TextureButton.java @@ -23,14 +23,14 @@ public class TextureButton guiTexture = new GuiTexture(Loader.loadTextureDirectly(texture), position, scale); } - public void hide(List guiTexture) + public void hide(List guiTextureList) { if (!shown) { } else { - guiTexture.remove(this.guiTexture); + guiTextureList.remove(this.guiTexture); this.shown = false; } } @@ -44,14 +44,14 @@ public class TextureButton public boolean isShown() { return shown; } - public void show(List guiTexture) + public void show(List guiTextureList) { if (shown) { } else { - guiTexture.add(this.guiTexture); + guiTextureList.add(this.guiTexture); this.shown = true; } } diff --git a/src/main/java/com/github/hydos/ginger/engine/font/MetaFile.java b/src/main/java/com/github/hydos/ginger/engine/font/MetaFile.java index 560332b..8c95834 100644 --- a/src/main/java/com/github/hydos/ginger/engine/font/MetaFile.java +++ b/src/main/java/com/github/hydos/ginger/engine/font/MetaFile.java @@ -32,7 +32,7 @@ public class MetaFile * - the font file. */ protected MetaFile(String file) { - this.aspectRatio = (double) Window.width / (double) Window.height; + this.aspectRatio = (double) Window.getWidth() / (double) Window.getHeight(); openFile(file); loadPaddingData(); loadLineSizes(); diff --git a/src/main/java/com/github/hydos/ginger/engine/io/Window.java b/src/main/java/com/github/hydos/ginger/engine/io/Window.java index ab88c74..f814e34 100644 --- a/src/main/java/com/github/hydos/ginger/engine/io/Window.java +++ b/src/main/java/com/github/hydos/ginger/engine/io/Window.java @@ -11,11 +11,22 @@ import com.github.hydos.ginger.engine.render.texture.Image; public class Window { + public static int getWidth() + { return width; } + + public static void setWidth(int width) + { Window.width = width; } + + public static int getHeight() + { return height; } + + public static void setHeight(int height) + { Window.height = height; } + public static boolean isFullscreen() { return fullscreen; } - public static int width; - public static int height; + private static int width, height; private static String title; public static long window; private static Vector3f backgroundColour = new Vector3f(118f, 215f, 234f); diff --git a/src/main/java/com/github/hydos/ginger/engine/postprocessing/Fbo.java b/src/main/java/com/github/hydos/ginger/engine/postprocessing/Fbo.java index 51d39d1..78d5f4d 100644 --- a/src/main/java/com/github/hydos/ginger/engine/postprocessing/Fbo.java +++ b/src/main/java/com/github/hydos/ginger/engine/postprocessing/Fbo.java @@ -53,8 +53,8 @@ public class Fbo public void createFBO() { this.window = Window.window; - this.width = Window.width; - this.height = Window.height; + this.width = Window.getWidth(); + this.height = Window.getHeight(); /* Create multisampled FBO */ multisampledColorRenderBuffer = glGenRenderbuffers(); multisampledDepthRenderBuffer = glGenRenderbuffers(); diff --git a/src/main/java/com/github/hydos/ginger/engine/render/MasterRenderer.java b/src/main/java/com/github/hydos/ginger/engine/render/MasterRenderer.java index 74cfb72..ebeb2ec 100644 --- a/src/main/java/com/github/hydos/ginger/engine/render/MasterRenderer.java +++ b/src/main/java/com/github/hydos/ginger/engine/render/MasterRenderer.java @@ -67,7 +67,7 @@ public class MasterRenderer private void createProjectionMatrix() { projectionMatrix = new Matrix4f(); - float aspectRatio = (float) Window.width / (float) Window.height; + float aspectRatio = (float) Window.getWidth() / (float) Window.getHeight(); float y_scale = (float) ((1f / Math.tan(Math.toRadians(FOV / 2f)))); float x_scale = y_scale / aspectRatio; float frustum_length = FAR_PLANE - NEAR_PLANE; diff --git a/src/main/java/com/github/hydos/ginger/engine/render/renderers/GuiRenderer.java b/src/main/java/com/github/hydos/ginger/engine/render/renderers/GuiRenderer.java index 6adbdc3..8da8d0d 100644 --- a/src/main/java/com/github/hydos/ginger/engine/render/renderers/GuiRenderer.java +++ b/src/main/java/com/github/hydos/ginger/engine/render/renderers/GuiRenderer.java @@ -32,24 +32,28 @@ public class GuiRenderer extends Renderer public void render(List guis) { - shader.start(); - GL30.glBindVertexArray(quad.getVaoID()); - GL20.glEnableVertexAttribArray(0); - GL11.glEnable(GL11.GL_BLEND); - GL11.glDisable(GL11.GL_DEPTH_TEST); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - for (GuiTexture gui : guis) + if (guis != null) { - GL13.glActiveTexture(GL13.GL_TEXTURE0); - GL11.glBindTexture(GL11.GL_TEXTURE_2D, gui.getTexture()); - Matrix4f matrix = Maths.createTransformationMatrix(gui.getPosition(), gui.getScale()); - shader.loadTransformation(matrix); - GL11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, quad.getVertexCount()); + shader.start(); + GL30.glBindVertexArray(quad.getVaoID()); + GL20.glEnableVertexAttribArray(0); + GL11.glEnable(GL11.GL_BLEND); + GL11.glDisable(GL11.GL_DEPTH_TEST); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + + for (GuiTexture gui : guis) + { + GL13.glActiveTexture(GL13.GL_TEXTURE0); + GL11.glBindTexture(GL11.GL_TEXTURE_2D, gui.getTexture()); + Matrix4f matrix = Maths.createTransformationMatrix(gui.getPosition(), gui.getScale()); + shader.loadTransformation(matrix); + GL11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, quad.getVertexCount()); + } + GL11.glDisable(GL11.GL_BLEND); + GL11.glEnable(GL11.GL_DEPTH_TEST); + GL20.glDisableVertexAttribArray(0); + GL30.glBindVertexArray(0); + shader.stop(); } - GL11.glDisable(GL11.GL_BLEND); - GL11.glEnable(GL11.GL_DEPTH_TEST); - GL20.glDisableVertexAttribArray(0); - GL30.glBindVertexArray(0); - shader.stop(); } } diff --git a/src/main/java/com/github/hydos/ginger/engine/render/tools/MousePicker.java b/src/main/java/com/github/hydos/ginger/engine/render/tools/MousePicker.java index 3bbccad..d35c06c 100644 --- a/src/main/java/com/github/hydos/ginger/engine/render/tools/MousePicker.java +++ b/src/main/java/com/github/hydos/ginger/engine/render/tools/MousePicker.java @@ -41,7 +41,7 @@ public class MousePicker private Vector3f calculateMouseRay() { float mouseX = (float) Window.getMouseX(); - float mouseY = (float) (Window.height - Window.getMouseY()); + float mouseY = (float) (Window.getHeight() - Window.getMouseY()); Vector2f normalizedCoords = getNormalisedDeviceCoordinates(mouseX, mouseY); Vector4f clipCoords = new Vector4f(normalizedCoords.x, normalizedCoords.y, -1.0f, 1.0f); Vector4f eyeCoords = toEyeCoords(clipCoords); @@ -57,8 +57,8 @@ public class MousePicker private Vector2f getNormalisedDeviceCoordinates(float mouseX, float mouseY) { - float x = (2.0f * mouseX) / Window.width - 1f; - float y = (2.0f * mouseY) / Window.height - 1f; + float x = (2.0f * mouseX) / Window.getWidth() - 1f; + float y = (2.0f * mouseY) / Window.getHeight() - 1f; return new Vector2f(x, y); } diff --git a/src/main/java/com/github/hydos/ginger/engine/screen/Screen.java b/src/main/java/com/github/hydos/ginger/engine/screen/Screen.java index 63b6c1b..931a24b 100644 --- a/src/main/java/com/github/hydos/ginger/engine/screen/Screen.java +++ b/src/main/java/com/github/hydos/ginger/engine/screen/Screen.java @@ -8,7 +8,9 @@ public abstract class Screen { public List elements; - public abstract void render(); + public abstract void render(); // FIXME: This never gets called!!! public abstract void tick(); + + public abstract void close(); } diff --git a/src/main/java/com/github/hydos/ginger/engine/shadow/ShadowBox.java b/src/main/java/com/github/hydos/ginger/engine/shadow/ShadowBox.java index 53b5345..d5efd43 100644 --- a/src/main/java/com/github/hydos/ginger/engine/shadow/ShadowBox.java +++ b/src/main/java/com/github/hydos/ginger/engine/shadow/ShadowBox.java @@ -129,7 +129,7 @@ public class ShadowBox /** @return The aspect ratio of the display (width:height ratio). */ private float getAspectRatio() - { return (float) Window.width / (float) Window.height; } + { return (float) Window.getWidth() / (float) Window.getHeight(); } /** Calculates the center of the "view cuboid" in light space first, and then * converts this to world space using the inverse light's view matrix. diff --git a/src/main/java/com/github/hydos/ginger/engine/shadow/ShadowFrameBuffer.java b/src/main/java/com/github/hydos/ginger/engine/shadow/ShadowFrameBuffer.java index d31b95c..3db0722 100644 --- a/src/main/java/com/github/hydos/ginger/engine/shadow/ShadowFrameBuffer.java +++ b/src/main/java/com/github/hydos/ginger/engine/shadow/ShadowFrameBuffer.java @@ -107,6 +107,6 @@ public class ShadowFrameBuffer protected void unbindFrameBuffer() { GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0); - GL11.glViewport(0, 0, Window.width, Window.height); + GL11.glViewport(0, 0, Window.getWidth(), Window.getHeight()); } } diff --git a/src/main/resources/textures/guis/purpur.png b/src/main/resources/textures/guis/purpur.png deleted file mode 100644 index 4cc55f5..0000000 Binary files a/src/main/resources/textures/guis/purpur.png and /dev/null differ diff --git a/src/main/resources/textures/guis/weird.png b/src/main/resources/textures/guis/weird.png deleted file mode 100644 index 350bdf8..0000000 Binary files a/src/main/resources/textures/guis/weird.png and /dev/null differ