[WIP] IngameHUD
parent
bf1a947cc6
commit
7b189e71d9
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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<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);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
if (Window.shouldRender()) gingerRegister.game.render();
|
||||
}
|
||||
}
|
||||
Litecraft.getInstance().exit();
|
||||
gingerRegister.game.exit();
|
||||
}
|
||||
|
||||
public void update(GameData data)
|
||||
|
|
|
@ -23,14 +23,14 @@ public class TextureButton
|
|||
guiTexture = new GuiTexture(Loader.loadTextureDirectly(texture), position, scale);
|
||||
}
|
||||
|
||||
public void hide(List<GuiTexture> guiTexture)
|
||||
public void hide(List<GuiTexture> 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> guiTexture)
|
||||
public void show(List<GuiTexture> guiTextureList)
|
||||
{
|
||||
if (shown)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
guiTexture.add(this.guiTexture);
|
||||
guiTextureList.add(this.guiTexture);
|
||||
this.shown = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -31,6 +31,8 @@ public class GuiRenderer extends Renderer
|
|||
{ shader.cleanUp(); }
|
||||
|
||||
public void render(List<GuiTexture> guis)
|
||||
{
|
||||
if (guis != null)
|
||||
{
|
||||
shader.start();
|
||||
GL30.glBindVertexArray(quad.getVaoID());
|
||||
|
@ -38,6 +40,7 @@ public class GuiRenderer extends Renderer
|
|||
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);
|
||||
|
@ -52,4 +55,5 @@ public class GuiRenderer extends Renderer
|
|||
GL30.glBindVertexArray(0);
|
||||
shader.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,9 @@ public abstract class Screen
|
|||
{
|
||||
public List<GuiTexture> elements;
|
||||
|
||||
public abstract void render();
|
||||
public abstract void render(); // FIXME: This never gets called!!!
|
||||
|
||||
public abstract void tick();
|
||||
|
||||
public abstract void close();
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 878 B |
Binary file not shown.
Before Width: | Height: | Size: 301 KiB |
Loading…
Reference in New Issue