Merge branch 'liteCraft' into worldgen

pull/12/head
valoeghese 2020-03-01 16:09:07 +13:00
commit eeb514fab0
5 changed files with 35 additions and 45 deletions

View File

@ -73,16 +73,7 @@ public class Litecraft extends Game
{ {
fps += 1; // This section updates the debug stats once per real-time second, regardless of how many frames have been rendered fps += 1; // This section updates the debug stats once per real-time second, regardless of how many frames have been rendered
if (System.currentTimeMillis() > frameTimer + 1000) if (System.currentTimeMillis() > frameTimer + 1000)
{ updateDebugStats();
this.dbgStats.set(fps, ups, tps, threadWaitlist);
this.fps = 0;
this.ups = 0;
this.tps = 0;
this.frameTimer += 1000;
}
/**
* And now, the actual rendering:
*/
// Render shadows // Render shadows
GingerRegister.getInstance().masterRenderer.renderShadowMap(data.entities, data.lights.get(0)); GingerRegister.getInstance().masterRenderer.renderShadowMap(data.entities, data.lights.get(0));
// If there's a world, render it! // If there's a world, render it!
@ -93,9 +84,21 @@ public class Litecraft extends Game
Window.swapBuffers(); Window.swapBuffers();
} }
// Updates the debug stats once per real-time second, regardless of how many frames have been rendered
private void updateDebugStats()
{
this.dbgStats.set(fps, ups, tps, threadWaitlist);
this.fps=0;
this.ups=0;
this.tps=0;
this.frameTimer += 1000;
}
public void update() public void update()
{ {
Input.invokeAllListeners(); Input.invokeAllListeners();
data.player.updateMovement();
data.camera.updateMovement();
} }
private void setupConstants() private void setupConstants()
@ -135,16 +138,13 @@ public class Litecraft extends Game
Input.addPressCallback(Keybind.EXIT, this::exit); Input.addPressCallback(Keybind.EXIT, this::exit);
Input.addInitialPressCallback(Keybind.FULLSCREEN, Window::fullscreen); Input.addInitialPressCallback(Keybind.FULLSCREEN, Window::fullscreen);
Input.addInitialPressCallback(Keybind.WIREFRAME, GingerRegister.getInstance()::toggleWireframe); Input.addInitialPressCallback(Keybind.WIREFRAME, GingerRegister.getInstance()::toggleWireframe);
Input.addPressCallback(Keybind.MOVE_FORWARD, () -> this.movePlayer(RelativeDirection.FORWARD)); Input.addPressCallback(Keybind.MOVE_FORWARD, () -> this.player.move(RelativeDirection.FORWARD));
Input.addPressCallback(Keybind.MOVE_BACKWARD, () -> this.movePlayer(RelativeDirection.BACKWARD)); Input.addPressCallback(Keybind.MOVE_BACKWARD, () -> this.player.move(RelativeDirection.BACKWARD));
Input.addPressCallback(Keybind.STRAFE_LEFT, () -> this.movePlayer(RelativeDirection.LEFT)); Input.addPressCallback(Keybind.STRAFE_LEFT, () -> this.player.move(RelativeDirection.LEFT));
Input.addPressCallback(Keybind.STRAFE_RIGHT, () -> this.movePlayer(RelativeDirection.RIGHT)); Input.addPressCallback(Keybind.STRAFE_RIGHT, () -> this.player.move(RelativeDirection.RIGHT));
Input.addPressCallback(Keybind.FLY_UP, () -> this.movePlayer(RelativeDirection.UP)); Input.addPressCallback(Keybind.FLY_UP, () -> this.player.move(RelativeDirection.UP));
Input.addPressCallback(Keybind.FLY_DOWN, () -> this.movePlayer(RelativeDirection.DOWN)); Input.addPressCallback(Keybind.FLY_DOWN, () -> this.player.move(RelativeDirection.DOWN));
} }
private void movePlayer(RelativeDirection direction)
{ this.player.move(direction); }
private void setupWindow() private void setupWindow()
{ {

View File

@ -11,7 +11,7 @@ public class Block
{ // add properties to this builder! { // add properties to this builder!
private boolean visible = true; private boolean visible = true;
private boolean fullCube = true; private boolean fullCube = true;
private boolean canCaveCarve = false; private boolean canCaveCarve = true;
private final String identifier; private final String identifier;
public Properties(String identifier) public Properties(String identifier)
@ -29,9 +29,9 @@ public class Block
return this; return this;
} }
public Properties canCaveCarve(boolean canCaveCarve) public Properties cannotCarveCave()
{ {
this.canCaveCarve = canCaveCarve; this.canCaveCarve = false;
return this; return this;
} }
} }

View File

@ -4,13 +4,13 @@ import com.github.halotroop.litecraft.types.block.Block.Properties;
public final class Blocks public final class Blocks
{ {
public static final Block AIR = new Block(new Properties("air").visible(false)); public static final Block AIR = new Block(new Properties("air").visible(false).fullCube(false).cannotCarveCave());
public static final Block GRASS = new Block(new Properties("block/cubes/soil/grass/grass_top.png").canCaveCarve(true)); public static final Block GRASS = new Block(new Properties("block/cubes/soil/grass/grass_top.png"));
public static final Block DIRT = new Block("block/cubes/soil/dirt.png", new Properties("dirt").canCaveCarve(true)); public static final Block DIRT = new Block("block/cubes/soil/dirt.png", new Properties("dirt"));
public static final Block ANDESITE = new Block("block/cubes/stone/basic/andesite.png", new Properties("andesite").canCaveCarve(true)); public static final Block ANDESITE = new Block("block/cubes/stone/basic/andesite.png", new Properties("andesite"));
public static final Block DIORITE = new Block("block/cubes/stone/basic/diorite.png", new Properties("diorite").canCaveCarve(true)); public static final Block DIORITE = new Block("block/cubes/stone/basic/diorite.png", new Properties("diorite"));
public static final Block GRANITE = new Block("block/cubes/stone/basic/granite.png", new Properties("granite").canCaveCarve(true)); public static final Block GRANITE = new Block("block/cubes/stone/basic/granite.png", new Properties("granite"));
public static final Block GNEISS = new Block("block/cubes/stone/basic/gneiss.png", new Properties("gneiss").canCaveCarve(true)); public static final Block GNEISS = new Block("block/cubes/stone/basic/gneiss.png", new Properties("gneiss"));
public static Block init() public static Block init()
{ {

View File

@ -82,25 +82,17 @@ public class Chunk implements BlockAccess, WorldGenConstants, SODSerializable
{ {
BlockInstance block = getBlockInstance(x, y, z); BlockInstance block = getBlockInstance(x, y, z);
// Why are we deliberately rendering blocks on the outside of the chunk???
if (x == 0 || x == CHUNK_SIZE - 1 || z == 0 || z == CHUNK_SIZE - 1 || y == 0 || y == CHUNK_SIZE - 1) if (x == 0 || x == CHUNK_SIZE - 1 || z == 0 || z == CHUNK_SIZE - 1 || y == 0 || y == CHUNK_SIZE - 1)
{ {
renderedBlocks[index(x, y, z)] = block; renderedBlocks[index(x, y, z)] = block;
continue; continue;
} }
// check for air. Yes this is stupid, TODO fix this // Check for non-full-cubes around the block
try { if ((!getBlock(x - 1, y, z).isFullCube() || !getBlock(x + 1, y, z).isFullCube() || !getBlock(x, y - 1, z).isFullCube()
if (getBlockInstance(x - 1, y, z).getModel() == null || getBlockInstance(x + 1, y, z).getModel() == null || || !getBlock(x, y + 1, z).isFullCube() || !getBlock(x, y, z - 1).isFullCube() || !getBlock(x, y, z + 1).isFullCube()))
getBlockInstance(x, y - 1, z).getModel() == null || getBlockInstance(x, y + 1, z).getModel() == null || renderedBlocks[index(x, y, z)] = block;
getBlockInstance(x, y, z - 1).getModel() == null || getBlockInstance(x, y, z + 1).getModel() == null)
{
renderedBlocks[index(x, y, z)] = block;
}
}
catch (NullPointerException e)
{ // this seems to be a hotspot for errors
e.printStackTrace(); // so I can add a debug breakpoint on this line
throw e; // e
}
} }
blockRenderer.render(renderedBlocks); blockRenderer.render(renderedBlocks);
} }

View File

@ -134,8 +134,6 @@ public class Ginger
public void update(GameData data) public void update(GameData data)
{ {
registry.game.update(); registry.game.update();
data.player.updateMovement();
data.camera.updateMovement();
picker.update(); picker.update();
GingerUtils.update(); GingerUtils.update();
ParticleMaster.update(data.camera); ParticleMaster.update(data.camera);