fix merge

pull/12/head
valoeghese 2020-02-28 10:18:01 +13:00
commit d01aebc4b5
7 changed files with 38 additions and 49 deletions

View File

@ -2,6 +2,7 @@ package com.github.halotroop.litecraft;
import java.util.Random; import java.util.Random;
import org.joml.Vector4i;
import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFW;
import com.github.halotroop.litecraft.save.LitecraftSave; import com.github.halotroop.litecraft.save.LitecraftSave;
@ -31,19 +32,17 @@ public class Litecraft extends Game
private LitecraftSave save; private LitecraftSave save;
private Ginger ginger3D; private Ginger ginger3D;
private static Litecraft INSTANCE; private static Litecraft INSTANCE;
//temp stuff to test out fbo fixes //temp stuff to test out fbo fixes
int oldWindowWidth = Window.width; int oldWindowWidth = Window.width;
int oldWindowHeight = Window.height; int oldWindowHeight = Window.height;
public int fps, ups, tps, binds;
public int realFPS = 0; public Vector4i dbgStats;
private int fps, ups, tps;
private long frameTimer; private long frameTimer;
public Litecraft() public Litecraft()
{ {
INSTANCE = this; Litecraft.INSTANCE = this;
dbgStats = new Vector4i();
Constants.movementSpeed = 0.5f; Constants.movementSpeed = 0.5f;
Constants.turnSpeed = 0.00006f; Constants.turnSpeed = 0.00006f;
Constants.gravity = new org.joml.Vector3f(0, -0.0000000005f, 0); Constants.gravity = new org.joml.Vector3f(0, -0.0000000005f, 0);
@ -51,7 +50,6 @@ public class Litecraft extends Game
Window.create(1200, 800, "LiteCraft", 60); Window.create(1200, 800, "LiteCraft", 60);
KeyCallbackHandler.trackWindow(Window.window); KeyCallbackHandler.trackWindow(Window.window);
MouseCallbackHandler.trackWindow(Window.window); MouseCallbackHandler.trackWindow(Window.window);
setupKeybinds(); setupKeybinds();
Block b = Blocks.AIR; // make sure blocks are initialised Block b = Blocks.AIR; // make sure blocks are initialised
@ -61,35 +59,26 @@ public class Litecraft extends Game
TexturedModel dirtModel = ModelLoader.loadGenericCube("block/cubes/stone/brick/stonebrick.png"); TexturedModel dirtModel = ModelLoader.loadGenericCube("block/cubes/stone/brick/stonebrick.png");
StaticCube.scaleCube(1f); StaticCube.scaleCube(1f);
Player player = new Player(dirtModel, new Vector3f(0, 0, -3), 0, 180f, 0, new Vector3f(0.2f, 0.2f, 0.2f)); Player player = new Player(dirtModel, new Vector3f(0, 0, -3), 0, 180f, 0, new Vector3f(0.2f, 0.2f, 0.2f));
Camera camera = new FirstPersonCamera(player); Camera camera = new FirstPersonCamera(player);
player.isVisible = false; player.isVisible = false;
ginger3D = new Ginger(); ginger3D = new Ginger();
data = new GameData(player, camera, 20); data = new GameData(player, camera, 20);
data.handleGuis = false; data.handleGuis = false;
ginger3D.setup(new MasterRenderer(camera), this); ginger3D.setup(new MasterRenderer(camera), INSTANCE);
FontType font = new FontType(Loader.loadFontAtlas("candara.png"), "candara.fnt"); FontType font = new FontType(Loader.loadFontAtlas("candara.png"), "candara.fnt");
ginger3D.setGlobalFont(font); ginger3D.setGlobalFont(font);
Light sun = new Light(new Vector3f(100, 105, -100), new Vector3f(1.3f, 1.3f, 1.3f), new Vector3f(0.0001f, 0.0001f, 0.0001f)); Light sun = new Light(new Vector3f(100, 105, -100), new Vector3f(1.3f, 1.3f, 1.3f), new Vector3f(0.0001f, 0.0001f, 0.0001f));
data.lights.add(sun); data.lights.add(sun);
data.entities.add(player); data.entities.add(player);
oldWindowWidth = Window.width; oldWindowWidth = Window.width;
oldWindowHeight = Window.height; oldWindowHeight = Window.height;
frameTimer = System.currentTimeMillis(); frameTimer = System.currentTimeMillis();
//start the game loop //start the game loop
ginger3D.startGame(); ginger3D.startGame();
} }
private void setupKeybinds() private void setupKeybinds()
{ { Input.addPressCallback(Keybind.EXIT, this::exit); }
Input.addPressCallback(Keybind.EXIT, this::exit);
}
@Override @Override
public void exit() public void exit()
@ -102,34 +91,30 @@ public class Litecraft extends Game
@Override @Override
public void render() public void render()
{ {
ups++;
fps++; fps++;
//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
{ {
realFPS = fps; this.dbgStats.set(fps, ups, tps, 0);
fps = 0; this.fps = 0;
ups = 0; this.ups = 0;
tps = 0; this.tps = 0;
frameTimer += 1000; // reset the wait time this.frameTimer += 1000; // reset the wait time
} }
if (ginger3D.gingerRegister.currentScreen == null)
if(ginger3D.gingerRegister.currentScreen == null) {
ginger3D.openScreen(new TitleScreen()); ginger3D.openScreen(new TitleScreen());
}
ginger3D.update(data); ginger3D.update(data);
if (oldWindowHeight != Window.height || oldWindowWidth != Window.width) if (oldWindowHeight != Window.height || oldWindowWidth != Window.width)
{
ginger3D.contrastFbo.resizeFBOs(); ginger3D.contrastFbo.resizeFBOs();
}
oldWindowWidth = Window.width; oldWindowWidth = Window.width;
oldWindowHeight = Window.height; oldWindowHeight = Window.height;
ginger3D.gingerRegister.masterRenderer.renderShadowMap(data.entities, data.lights.get(0)); ginger3D.gingerRegister.masterRenderer.renderShadowMap(data.entities, data.lights.get(0));
if (this.world != null) if (this.world != null)
{ ginger3D.renderWorld(this, this.world); } ginger3D.renderWorld(this, this.world);
ginger3D.renderOverlays(this); ginger3D.renderOverlays(this);
ginger3D.postRender(); ginger3D.postRender();
dbgStats.w = binds;
this.binds = 0;
} }
@Override @Override
@ -138,18 +123,15 @@ public class Litecraft extends Game
Input.invokeAllListeners(); Input.invokeAllListeners();
data.player.updateMovement(); data.player.updateMovement();
tps++; tps++;
if (Window.isKeyDown(GLFW.GLFW_KEY_TAB))
if(Window.isKeyDown(GLFW.GLFW_KEY_TAB)) {
ginger3D.gingerRegister.wireframe = !ginger3D.gingerRegister.wireframe; ginger3D.gingerRegister.wireframe = !ginger3D.gingerRegister.wireframe;
}
} }
public static Litecraft getInstance() { public static Litecraft getInstance()
return INSTANCE; { return INSTANCE; }
}
public void onPlayButtonClick() { public void onPlayButtonClick()
{
if (world == null) if (world == null)
{ {
this.save = new LitecraftSave("test", false); this.save = new LitecraftSave("test", false);

View File

@ -1,12 +1,14 @@
package com.github.halotroop.litecraft.screens; package com.github.halotroop.litecraft.screens;
import java.util.*; import java.util.ArrayList;
import org.joml.Vector4i;
import com.github.halotroop.litecraft.Litecraft; import com.github.halotroop.litecraft.Litecraft;
import com.github.hydos.ginger.engine.api.*; 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;
import com.github.hydos.ginger.engine.font.*; import com.github.hydos.ginger.engine.font.GUIText;
import com.github.hydos.ginger.engine.io.Window; import com.github.hydos.ginger.engine.io.Window;
import com.github.hydos.ginger.engine.math.vectors.Vector2f; import com.github.hydos.ginger.engine.math.vectors.Vector2f;
import com.github.hydos.ginger.engine.screen.Screen; import com.github.hydos.ginger.engine.screen.Screen;
@ -33,15 +35,17 @@ public class TitleScreen extends Screen
} }
@Override @Override
public void render() public void render() // FIXME: This never gets called!!!
{ {
} }
@Override @Override
public void tick() public void tick()
{ {
Vector4i dbg = Litecraft.getInstance().dbgStats;
buildText.setText("FPS: "+dbg.x()+" UPS: "+dbg.y+" TPS: "+dbg.z+" Binds: "+dbg.w);
playButton.update(); playButton.update();
buildText.setText("Fps: " + Litecraft.getInstance().realFPS);
if (playButton.isClicked()) if (playButton.isClicked())
{ {
Window.lockMouse(); Window.lockMouse();

View File

@ -1,7 +1,5 @@
package com.github.halotroop.litecraft.types.block; package com.github.halotroop.litecraft.types.block;
import java.util.*;
import com.github.halotroop.litecraft.world.Chunk; import com.github.halotroop.litecraft.world.Chunk;
import com.github.hydos.ginger.engine.elements.objects.RenderObject; import com.github.hydos.ginger.engine.elements.objects.RenderObject;
import com.github.hydos.ginger.engine.math.vectors.Vector3f; import com.github.hydos.ginger.engine.math.vectors.Vector3f;

View File

@ -4,13 +4,14 @@ import java.util.*;
import org.lwjgl.opengl.*; import org.lwjgl.opengl.*;
import com.github.halotroop.litecraft.Litecraft;
import com.github.halotroop.litecraft.types.block.BlockEntity; import com.github.halotroop.litecraft.types.block.BlockEntity;
import com.github.hydos.ginger.engine.api.GingerRegister; import com.github.hydos.ginger.engine.api.GingerRegister;
import com.github.hydos.ginger.engine.elements.objects.RenderObject; import com.github.hydos.ginger.engine.elements.objects.RenderObject;
import com.github.hydos.ginger.engine.io.Window; import com.github.hydos.ginger.engine.io.Window;
import com.github.hydos.ginger.engine.math.Maths; import com.github.hydos.ginger.engine.math.Maths;
import com.github.hydos.ginger.engine.math.matrixes.Matrix4f; import com.github.hydos.ginger.engine.math.matrixes.Matrix4f;
import com.github.hydos.ginger.engine.render.*; import com.github.hydos.ginger.engine.render.Renderer;
import com.github.hydos.ginger.engine.render.models.*; import com.github.hydos.ginger.engine.render.models.*;
import com.github.hydos.ginger.engine.render.shaders.StaticShader; import com.github.hydos.ginger.engine.render.shaders.StaticShader;
import com.github.hydos.ginger.engine.render.texture.ModelTexture; import com.github.hydos.ginger.engine.render.texture.ModelTexture;
@ -40,6 +41,7 @@ public class BlockRenderer extends Renderer
GL20.glEnableVertexAttribArray(0); GL20.glEnableVertexAttribArray(0);
GL20.glEnableVertexAttribArray(1); GL20.glEnableVertexAttribArray(1);
GL20.glEnableVertexAttribArray(2); GL20.glEnableVertexAttribArray(2);
Litecraft.getInstance().binds++;
} }
private void prepTexture(ModelTexture texture, int textureID) { private void prepTexture(ModelTexture texture, int textureID) {
@ -90,6 +92,7 @@ public class BlockRenderer extends Renderer
{ {
if (entity != null && entity.getModel() != null) { if (entity != null && entity.getModel() != null) {
prepTexture(entity.getModel().getTexture(), entity.getModel().getTexture().getTextureID()); prepTexture(entity.getModel().getTexture(), entity.getModel().getTexture().getTextureID());
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
prepBlockInstance(entity); prepBlockInstance(entity);
GL11.glDrawElements(GL11.GL_TRIANGLES, model.getRawModel().getVertexCount(), GL11.GL_UNSIGNED_INT, 0); GL11.glDrawElements(GL11.GL_TRIANGLES, model.getRawModel().getVertexCount(), GL11.GL_UNSIGNED_INT, 0);

View File

@ -1,5 +1,6 @@
package com.github.hydos.ginger.engine.api; package com.github.hydos.ginger.engine.api;
import com.github.halotroop.litecraft.Litecraft;
import com.github.halotroop.litecraft.logic.Timer; import com.github.halotroop.litecraft.logic.Timer;
import com.github.halotroop.litecraft.logic.Timer.TickListener; import com.github.halotroop.litecraft.logic.Timer.TickListener;
import com.github.halotroop.litecraft.world.World; import com.github.halotroop.litecraft.world.World;
@ -112,12 +113,14 @@ public class Ginger
{ {
while (!Window.closed()) while (!Window.closed())
{ {
Litecraft.getInstance().ups++;
if (Window.isUpdating()) if (Window.isUpdating())
{ {
timer.tick(); timer.tick();
gingerRegister.game.render(); gingerRegister.game.render();
} }
} }
Litecraft.getInstance().exit();
} }
public void update(GameData data) public void update(GameData data)

View File

@ -2,7 +2,7 @@ package com.github.hydos.ginger.engine.font;
import java.util.*; import java.util.*;
import com.github.hydos.ginger.engine.api.*; import com.github.hydos.ginger.engine.api.Ginger;
import com.github.hydos.ginger.engine.render.renderers.FontRenderer; import com.github.hydos.ginger.engine.render.renderers.FontRenderer;
import com.github.hydos.ginger.engine.utils.Loader; import com.github.hydos.ginger.engine.utils.Loader;

View File

@ -6,7 +6,6 @@ import static org.lwjgl.system.MemoryStack.stackPush;
import java.io.IOException; import java.io.IOException;
import java.nio.*; import java.nio.*;
import org.lwjgl.stb.STBImage;
import org.lwjgl.system.MemoryStack; import org.lwjgl.system.MemoryStack;
import com.github.hydos.ginger.engine.render.tools.IOUtil; import com.github.hydos.ginger.engine.render.tools.IOUtil;