[WIP] IngameHUD

pull/12/head
Caroline Bell 2020-02-28 21:56:17 -08:00
parent bf1a947cc6
commit 7b189e71d9
15 changed files with 110 additions and 79 deletions

View File

@ -9,7 +9,6 @@ import com.github.halotroop.litecraft.screens.TitleScreen;
import com.github.halotroop.litecraft.types.block.Blocks; import com.github.halotroop.litecraft.types.block.Blocks;
import com.github.halotroop.litecraft.util.RelativeDirection; import com.github.halotroop.litecraft.util.RelativeDirection;
import com.github.halotroop.litecraft.world.World; 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.*;
import com.github.hydos.ginger.engine.api.game.*; import com.github.hydos.ginger.engine.api.game.*;
import com.github.hydos.ginger.engine.cameras.*; import com.github.hydos.ginger.engine.cameras.*;
@ -34,8 +33,8 @@ public class Litecraft extends Game
public Player player; public Player player;
private Camera camera; private Camera camera;
//temp stuff to test out fbo fixes //temp stuff to test out fbo fixes
int oldWindowWidth = Window.width; int oldWindowWidth = Window.getWidth();
int oldWindowHeight = Window.height; int oldWindowHeight = Window.getHeight();
public int fps, ups, tps, binds; public int fps, ups, tps, binds;
public Vector4i dbgStats; public Vector4i dbgStats;
private long frameTimer; private long frameTimer;
@ -52,8 +51,8 @@ public class Litecraft extends Game
GingerUtils.init(); // set up ginger utilities GingerUtils.init(); // set up ginger utilities
// set up Ginger3D stuff // set up Ginger3D stuff
this.setupGinger(); this.setupGinger();
this.oldWindowWidth = Window.width; this.oldWindowWidth = Window.getWidth();
this.oldWindowHeight = Window.height; this.oldWindowHeight = Window.getHeight();
this.frameTimer = System.currentTimeMillis(); this.frameTimer = System.currentTimeMillis();
setupKeybinds(); // set up keybinds setupKeybinds(); // set up keybinds
//start the game loop //start the game loop
@ -117,7 +116,7 @@ public class Litecraft extends Game
this.world.unloadAllChunks(); this.world.unloadAllChunks();
try try
{ {
this.save.saveGlobalData(this.world.getSeed(), this.player); this.getSave().saveGlobalData(this.world.getSeed(), this.player);
} }
catch (IOException e) catch (IOException e)
{ {
@ -140,23 +139,21 @@ public class Litecraft extends Game
//FPS stuff sorry if i forget to remove whitespace //FPS stuff sorry if i forget to remove whitespace
if (System.currentTimeMillis() > frameTimer + 1000) // wait for one second 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.fps = 0;
this.ups = 0; this.ups = 0;
this.tps = 0; this.tps = 0;
this.frameTimer += 1000; // reset the wait time this.frameTimer += 1000; // reset the wait time
} }
// TODO pls comment this code // TODO pls comment this code
if (ginger3D.gingerRegister.currentScreen == null) if (ginger3D.gingerRegister.currentScreen == null) ginger3D.openScreen(new TitleScreen());
this.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.
this.ginger3D.update(data); if (oldWindowHeight != Window.getHeight() || oldWindowWidth != Window.getWidth() && Window.getHeight() > 10 && Window.getWidth() > 10)
if (oldWindowHeight != Window.height || oldWindowWidth != Window.width && Window.height > 10 && Window.width > 10)
this.ginger3D.contrastFbo.resizeFBOs(); this.ginger3D.contrastFbo.resizeFBOs();
this.oldWindowWidth = Window.width; this.oldWindowWidth = Window.getWidth();
this.oldWindowHeight = Window.height; this.oldWindowHeight = Window.getHeight();
this.ginger3D.gingerRegister.masterRenderer.renderShadowMap(data.entities, data.lights.get(0)); this.ginger3D.gingerRegister.masterRenderer.renderShadowMap(data.entities, data.lights.get(0));
if (this.world != null) if (this.world != null) this.ginger3D.renderWorld(this, this.world);
this.ginger3D.renderWorld(this, this.world);
this.ginger3D.renderOverlays(this); this.ginger3D.renderOverlays(this);
this.ginger3D.postRender(); this.ginger3D.postRender();
this.dbgStats.w = binds; this.dbgStats.w = binds;
@ -174,18 +171,19 @@ public class Litecraft extends Game
public static Litecraft getInstance() public static Litecraft getInstance()
{ return INSTANCE; } { return INSTANCE; }
public void onPlayButtonClick() public World getWorld()
{ return this.world; }
public LitecraftSave getSave()
{ {
if (world == null) return save;
{
this.save = new LitecraftSave("cegregatedordinaldata", false);
this.world = this.save.getWorldOrCreate(Dimensions.OVERWORLD);
ginger3D.setGingerPlayer(this.world.player);
}
} }
public World getWorld() public void changeWorld(World world)
{ this.world = world; }
public void setSave(LitecraftSave save)
{ {
return this.world; this.save = save;
} }
} }

View File

@ -5,6 +5,8 @@ import java.util.ArrayList;
import org.joml.*; import org.joml.*;
import com.github.halotroop.litecraft.Litecraft; 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.api.Ginger;
import com.github.hydos.ginger.engine.elements.GuiTexture; import com.github.hydos.ginger.engine.elements.GuiTexture;
import com.github.hydos.ginger.engine.elements.buttons.TextureButton; 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 public class TitleScreen extends Screen
{ {
GUIText buildText; private GUIText debugText;
Ginger ginger3D; private Ginger ginger3D = Ginger.getInstance();
TextureButton playButton; private TextureButton playButton;
Litecraft litecraft; private Litecraft litecraft = Litecraft.getInstance();
public TitleScreen() public TitleScreen()
{ {
ginger3D = Ginger.getInstance();
elements = new ArrayList<GuiTexture>(); elements = new ArrayList<GuiTexture>();
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); playButton.show(Litecraft.getInstance().data.guis);
buildText = ginger3D.registerText("LiteCraft", 3, new Vector2f(0, 0), 1f, true, "PLAYBUTTON"); debugText = ginger3D.registerText("Loading...", 2, new Vector2f(0, 0), 1f, true, "debugInfo");
buildText.setBorderWidth(0.5f); debugText.setBorderWidth(0.5f);
} }
@Override @Override
public void render() // FIXME: This never gets called!!! public void render()
{} {}
@Override @Override
public void tick() public void tick()
{ {
if(litecraft == null) {
litecraft = Litecraft.getInstance();
}
Vector4i dbg = litecraft.dbgStats; 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(); playButton.update();
if (playButton.isClicked()) if (playButton.isClicked())
{ {
Window.lockMouse(); Window.lockMouse();
playButton.hide(Litecraft.getInstance().data.guis);
Litecraft.getInstance().onPlayButtonClick();//TODO: add world gui so it takes u to world creation place if (Litecraft.getInstance().getWorld() == null)
//TODO: also add a texture to be rendered behind the gui as an option {
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;
} }
} }

View File

@ -28,6 +28,7 @@ public class Ginger
public Fbo contrastFbo; public Fbo contrastFbo;
public GingerThreading threading; public GingerThreading threading;
Timer timer; Timer timer;
TickListener gameTickListener = new TickListener() TickListener gameTickListener = new TickListener()
{ {
@Override @Override
@ -123,13 +124,10 @@ public class Ginger
while (!Window.closed()) while (!Window.closed())
{ {
Litecraft.getInstance().ups++; Litecraft.getInstance().ups++;
if (Window.shouldRender())
{
timer.tick(); timer.tick();
gingerRegister.game.render(); if (Window.shouldRender()) gingerRegister.game.render();
} }
} gingerRegister.game.exit();
Litecraft.getInstance().exit();
} }
public void update(GameData data) public void update(GameData data)

View File

@ -23,14 +23,14 @@ public class TextureButton
guiTexture = new GuiTexture(Loader.loadTextureDirectly(texture), position, scale); guiTexture = new GuiTexture(Loader.loadTextureDirectly(texture), position, scale);
} }
public void hide(List<GuiTexture> guiTexture) public void hide(List<GuiTexture> guiTextureList)
{ {
if (!shown) if (!shown)
{ {
} }
else else
{ {
guiTexture.remove(this.guiTexture); guiTextureList.remove(this.guiTexture);
this.shown = false; this.shown = false;
} }
} }
@ -44,14 +44,14 @@ public class TextureButton
public boolean isShown() public boolean isShown()
{ return shown; } { return shown; }
public void show(List<GuiTexture> guiTexture) public void show(List<GuiTexture> guiTextureList)
{ {
if (shown) if (shown)
{ {
} }
else else
{ {
guiTexture.add(this.guiTexture); guiTextureList.add(this.guiTexture);
this.shown = true; this.shown = true;
} }
} }

View File

@ -32,7 +32,7 @@ public class MetaFile
* - the font file. */ * - the font file. */
protected MetaFile(String file) protected MetaFile(String file)
{ {
this.aspectRatio = (double) Window.width / (double) Window.height; this.aspectRatio = (double) Window.getWidth() / (double) Window.getHeight();
openFile(file); openFile(file);
loadPaddingData(); loadPaddingData();
loadLineSizes(); loadLineSizes();

View File

@ -11,11 +11,22 @@ import com.github.hydos.ginger.engine.render.texture.Image;
public class Window 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() public static boolean isFullscreen()
{ return fullscreen; } { return fullscreen; }
public static int width; private static int width, height;
public static int height;
private static String title; private static String title;
public static long window; public static long window;
private static Vector3f backgroundColour = new Vector3f(118f, 215f, 234f); private static Vector3f backgroundColour = new Vector3f(118f, 215f, 234f);

View File

@ -53,8 +53,8 @@ public class Fbo
public void createFBO() public void createFBO()
{ {
this.window = Window.window; this.window = Window.window;
this.width = Window.width; this.width = Window.getWidth();
this.height = Window.height; this.height = Window.getHeight();
/* Create multisampled FBO */ /* Create multisampled FBO */
multisampledColorRenderBuffer = glGenRenderbuffers(); multisampledColorRenderBuffer = glGenRenderbuffers();
multisampledDepthRenderBuffer = glGenRenderbuffers(); multisampledDepthRenderBuffer = glGenRenderbuffers();

View File

@ -67,7 +67,7 @@ public class MasterRenderer
private void createProjectionMatrix() private void createProjectionMatrix()
{ {
projectionMatrix = new Matrix4f(); 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 y_scale = (float) ((1f / Math.tan(Math.toRadians(FOV / 2f))));
float x_scale = y_scale / aspectRatio; float x_scale = y_scale / aspectRatio;
float frustum_length = FAR_PLANE - NEAR_PLANE; float frustum_length = FAR_PLANE - NEAR_PLANE;

View File

@ -31,6 +31,8 @@ public class GuiRenderer extends Renderer
{ shader.cleanUp(); } { shader.cleanUp(); }
public void render(List<GuiTexture> guis) public void render(List<GuiTexture> guis)
{
if (guis != null)
{ {
shader.start(); shader.start();
GL30.glBindVertexArray(quad.getVaoID()); GL30.glBindVertexArray(quad.getVaoID());
@ -38,6 +40,7 @@ public class GuiRenderer extends Renderer
GL11.glEnable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_BLEND);
GL11.glDisable(GL11.GL_DEPTH_TEST); GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
for (GuiTexture gui : guis) for (GuiTexture gui : guis)
{ {
GL13.glActiveTexture(GL13.GL_TEXTURE0); GL13.glActiveTexture(GL13.GL_TEXTURE0);
@ -52,4 +55,5 @@ public class GuiRenderer extends Renderer
GL30.glBindVertexArray(0); GL30.glBindVertexArray(0);
shader.stop(); shader.stop();
} }
}
} }

View File

@ -41,7 +41,7 @@ public class MousePicker
private Vector3f calculateMouseRay() private Vector3f calculateMouseRay()
{ {
float mouseX = (float) Window.getMouseX(); float mouseX = (float) Window.getMouseX();
float mouseY = (float) (Window.height - Window.getMouseY()); float mouseY = (float) (Window.getHeight() - Window.getMouseY());
Vector2f normalizedCoords = getNormalisedDeviceCoordinates(mouseX, mouseY); Vector2f normalizedCoords = getNormalisedDeviceCoordinates(mouseX, mouseY);
Vector4f clipCoords = new Vector4f(normalizedCoords.x, normalizedCoords.y, -1.0f, 1.0f); Vector4f clipCoords = new Vector4f(normalizedCoords.x, normalizedCoords.y, -1.0f, 1.0f);
Vector4f eyeCoords = toEyeCoords(clipCoords); Vector4f eyeCoords = toEyeCoords(clipCoords);
@ -57,8 +57,8 @@ public class MousePicker
private Vector2f getNormalisedDeviceCoordinates(float mouseX, float mouseY) private Vector2f getNormalisedDeviceCoordinates(float mouseX, float mouseY)
{ {
float x = (2.0f * mouseX) / Window.width - 1f; float x = (2.0f * mouseX) / Window.getWidth() - 1f;
float y = (2.0f * mouseY) / Window.height - 1f; float y = (2.0f * mouseY) / Window.getHeight() - 1f;
return new Vector2f(x, y); return new Vector2f(x, y);
} }

View File

@ -8,7 +8,9 @@ public abstract class Screen
{ {
public List<GuiTexture> elements; public List<GuiTexture> elements;
public abstract void render(); public abstract void render(); // FIXME: This never gets called!!!
public abstract void tick(); public abstract void tick();
public abstract void close();
} }

View File

@ -129,7 +129,7 @@ public class ShadowBox
/** @return The aspect ratio of the display (width:height ratio). */ /** @return The aspect ratio of the display (width:height ratio). */
private float getAspectRatio() 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 /** 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. * converts this to world space using the inverse light's view matrix.

View File

@ -107,6 +107,6 @@ public class ShadowFrameBuffer
protected void unbindFrameBuffer() protected void unbindFrameBuffer()
{ {
GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0); GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);
GL11.glViewport(0, 0, Window.width, Window.height); GL11.glViewport(0, 0, Window.getWidth(), Window.getHeight());
} }
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 878 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 301 KiB