Merge branch 'worldgen' of https://github.com/halotroop/Ginger3D into worldgen
commit
e285e752b0
|
@ -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
|
||||
if (System.currentTimeMillis() > frameTimer + 1000)
|
||||
{
|
||||
this.dbgStats.set(fps, ups, tps, threadWaitlist);
|
||||
this.fps = 0;
|
||||
this.ups = 0;
|
||||
this.tps = 0;
|
||||
this.frameTimer += 1000;
|
||||
}
|
||||
/**
|
||||
* And now, the actual rendering:
|
||||
*/
|
||||
updateDebugStats();
|
||||
// Render shadows
|
||||
GingerRegister.getInstance().masterRenderer.renderShadowMap(data.entities, data.lights.get(0));
|
||||
// If there's a world, render it!
|
||||
|
@ -93,9 +84,21 @@ public class Litecraft extends Game
|
|||
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()
|
||||
{
|
||||
Input.invokeAllListeners();
|
||||
data.player.updateMovement();
|
||||
data.camera.updateMovement();
|
||||
}
|
||||
|
||||
private void setupConstants()
|
||||
|
@ -135,16 +138,13 @@ public class Litecraft extends Game
|
|||
Input.addPressCallback(Keybind.EXIT, this::exit);
|
||||
Input.addInitialPressCallback(Keybind.FULLSCREEN, Window::fullscreen);
|
||||
Input.addInitialPressCallback(Keybind.WIREFRAME, GingerRegister.getInstance()::toggleWireframe);
|
||||
Input.addPressCallback(Keybind.MOVE_FORWARD, () -> this.movePlayer(RelativeDirection.FORWARD));
|
||||
Input.addPressCallback(Keybind.MOVE_BACKWARD, () -> this.movePlayer(RelativeDirection.BACKWARD));
|
||||
Input.addPressCallback(Keybind.STRAFE_LEFT, () -> this.movePlayer(RelativeDirection.LEFT));
|
||||
Input.addPressCallback(Keybind.STRAFE_RIGHT, () -> this.movePlayer(RelativeDirection.RIGHT));
|
||||
Input.addPressCallback(Keybind.FLY_UP, () -> this.movePlayer(RelativeDirection.UP));
|
||||
Input.addPressCallback(Keybind.FLY_DOWN, () -> this.movePlayer(RelativeDirection.DOWN));
|
||||
Input.addPressCallback(Keybind.MOVE_FORWARD, () -> this.player.move(RelativeDirection.FORWARD));
|
||||
Input.addPressCallback(Keybind.MOVE_BACKWARD, () -> this.player.move(RelativeDirection.BACKWARD));
|
||||
Input.addPressCallback(Keybind.STRAFE_LEFT, () -> this.player.move(RelativeDirection.LEFT));
|
||||
Input.addPressCallback(Keybind.STRAFE_RIGHT, () -> this.player.move(RelativeDirection.RIGHT));
|
||||
Input.addPressCallback(Keybind.FLY_UP, () -> this.player.move(RelativeDirection.UP));
|
||||
Input.addPressCallback(Keybind.FLY_DOWN, () -> this.player.move(RelativeDirection.DOWN));
|
||||
}
|
||||
|
||||
private void movePlayer(RelativeDirection direction)
|
||||
{ this.player.move(direction); }
|
||||
|
||||
private void setupWindow()
|
||||
{
|
||||
|
|
|
@ -11,7 +11,7 @@ public class Block
|
|||
{ // add properties to this builder!
|
||||
private boolean visible = true;
|
||||
private boolean fullCube = true;
|
||||
private boolean canCaveCarve = false;
|
||||
private float caveCarveThreshold = -1f; // cannot carve
|
||||
private final String identifier;
|
||||
|
||||
public Properties(String identifier)
|
||||
|
@ -29,15 +29,16 @@ public class Block
|
|||
return this;
|
||||
}
|
||||
|
||||
public Properties canCaveCarve(boolean canCaveCarve)
|
||||
public Properties caveCarveThreshold(float threshold)
|
||||
{
|
||||
this.canCaveCarve = canCaveCarve;
|
||||
this.caveCarveThreshold = threshold;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public final TexturedModel model;
|
||||
private final boolean visible, fullCube, canCaveCarve;
|
||||
private final boolean visible, fullCube;
|
||||
private final float caveCarveThreshold;
|
||||
public final String identifier;
|
||||
|
||||
public boolean isFullCube()
|
||||
|
@ -46,8 +47,8 @@ public class Block
|
|||
public boolean isVisible()
|
||||
{ return this.visible; }
|
||||
|
||||
public boolean canCaveCarve()
|
||||
{ return this.canCaveCarve; }
|
||||
public float getCaveCarveThreshold()
|
||||
{ return this.caveCarveThreshold; }
|
||||
|
||||
protected Block(Properties properties)
|
||||
{ this((TexturedModel) null, properties); }
|
||||
|
@ -61,7 +62,7 @@ public class Block
|
|||
this.visible = properties.visible;
|
||||
this.fullCube = properties.fullCube;
|
||||
this.identifier = properties.identifier;
|
||||
this.canCaveCarve = properties.canCaveCarve;
|
||||
this.caveCarveThreshold = properties.caveCarveThreshold;
|
||||
IDENTIFIER_TO_BLOCK.put(this.identifier, this);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,13 +4,13 @@ import com.github.halotroop.litecraft.types.block.Block.Properties;
|
|||
|
||||
public final class Blocks
|
||||
{
|
||||
public static final Block AIR = new Block(new Properties("air").visible(false));
|
||||
public static final Block GRASS = new Block(new Properties("block/cubes/soil/grass/grass_top.png").canCaveCarve(true));
|
||||
public static final Block DIRT = new Block("block/cubes/soil/dirt.png", new Properties("dirt").canCaveCarve(true));
|
||||
public static final Block ANDESITE = new Block("block/cubes/stone/basic/andesite.png", new Properties("andesite").canCaveCarve(true));
|
||||
public static final Block DIORITE = new Block("block/cubes/stone/basic/diorite.png", new Properties("diorite").canCaveCarve(true));
|
||||
public static final Block GRANITE = new Block("block/cubes/stone/basic/granite.png", new Properties("granite").canCaveCarve(true));
|
||||
public static final Block GNEISS = new Block("block/cubes/stone/basic/gneiss.png", new Properties("gneiss").canCaveCarve(true));
|
||||
public static final Block AIR = new Block(new Properties("air").visible(false).fullCube(false));
|
||||
public static final Block GRASS = new Block(new Properties("block/cubes/soil/grass/grass_top.png").caveCarveThreshold(0.04f));
|
||||
public static final Block DIRT = new Block("block/cubes/soil/dirt.png", new Properties("dirt").caveCarveThreshold(0.04f));
|
||||
public static final Block ANDESITE = new Block("block/cubes/stone/basic/andesite.png", new Properties("andesite").caveCarveThreshold(0.08f));
|
||||
public static final Block DIORITE = new Block("block/cubes/stone/basic/diorite.png", new Properties("diorite").caveCarveThreshold(0.05f));
|
||||
public static final Block GRANITE = new Block("block/cubes/stone/basic/granite.png", new Properties("granite").caveCarveThreshold(0.06f));
|
||||
public static final Block GNEISS = new Block("block/cubes/stone/basic/gneiss.png", new Properties("gneiss").caveCarveThreshold(0.09f));
|
||||
|
||||
public static Block init()
|
||||
{
|
||||
|
|
|
@ -82,25 +82,17 @@ public class Chunk implements BlockAccess, WorldGenConstants, SODSerializable
|
|||
{
|
||||
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)
|
||||
{
|
||||
renderedBlocks[index(x, y, z)] = block;
|
||||
continue;
|
||||
}
|
||||
// check for air. Yes this is stupid, TODO fix this
|
||||
try {
|
||||
if (getBlockInstance(x - 1, y, z).getModel() == null || getBlockInstance(x + 1, y, z).getModel() == null ||
|
||||
getBlockInstance(x, y - 1, z).getModel() == null || getBlockInstance(x, y + 1, z).getModel() == null ||
|
||||
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
|
||||
}
|
||||
// Check for non-full-cubes around the block
|
||||
if ((!getBlock(x - 1, y, z).isFullCube() || !getBlock(x + 1, y, z).isFullCube() || !getBlock(x, y - 1, z).isFullCube()
|
||||
|| !getBlock(x, y + 1, z).isFullCube() || !getBlock(x, y, z - 1).isFullCube() || !getBlock(x, y, z + 1).isFullCube()))
|
||||
renderedBlocks[index(x, y, z)] = block;
|
||||
|
||||
}
|
||||
blockRenderer.render(renderedBlocks);
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package com.github.halotroop.litecraft.world.gen;
|
||||
package com.github.halotroop.litecraft.world.gen.modifier;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import com.github.halotroop.litecraft.types.block.Blocks;
|
||||
import com.github.halotroop.litecraft.types.block.*;
|
||||
import com.github.halotroop.litecraft.util.noise.OctaveSimplexNoise;
|
||||
import com.github.halotroop.litecraft.world.BlockAccess;
|
||||
import com.github.halotroop.litecraft.world.gen.modifier.WorldModifier;
|
||||
import com.github.halotroop.litecraft.world.gen.WorldGenConstants;
|
||||
|
||||
public class CavesModifier implements WorldModifier, WorldGenConstants
|
||||
{
|
||||
|
@ -16,7 +16,7 @@ public class CavesModifier implements WorldModifier, WorldGenConstants
|
|||
public void initialize(long seed)
|
||||
{
|
||||
Random rand = new Random(seed);
|
||||
this.caveNoise = new OctaveSimplexNoise(rand, 1, 45.0, 1.0, 1.0);
|
||||
this.caveNoise = new OctaveSimplexNoise(rand, 2, 65.0, 1.0, 1.0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -36,8 +36,8 @@ public class CavesModifier implements WorldModifier, WorldGenConstants
|
|||
{
|
||||
int scOffsetY = subChunkY << 2; // sub chunk offset y
|
||||
int scTotalY = scOffsetY + chunkStartY;
|
||||
double scSampleY = (double) scTotalY * 2.0;
|
||||
double scUpperYOffset = 4.0 * 2.0;
|
||||
double scSampleY = (double) scTotalY * 1.5; // squish caves along y axis a bit
|
||||
double scUpperYOffset = 4.0 * 1.5;
|
||||
// calculate noise at each corner of the cube [lower|upper][south|north][west|east]
|
||||
double noiseLSW = this.caveNoise.sample(scTotalX, scSampleY, scTotalZ); // base = lower south west
|
||||
double noiseUSW = this.caveNoise.sample(scTotalX, scSampleY + scUpperYOffset, scTotalZ);
|
||||
|
@ -81,14 +81,11 @@ public class CavesModifier implements WorldModifier, WorldGenConstants
|
|||
{
|
||||
int totalX = subX + scTotalX;
|
||||
// calculate whether to replace block with air
|
||||
// if the noise is within the threshold for caves
|
||||
if (-THRESHOLD < lerpNoise && lerpNoise < THRESHOLD)
|
||||
// if the noise is within the threshold for that block for caves
|
||||
float threshold = world.getBlock(totalX, totalY, totalZ).getCaveCarveThreshold();
|
||||
if (-threshold < lerpNoise && lerpNoise < threshold)
|
||||
{
|
||||
// if the cave can carve into the block
|
||||
if (world.getBlock(totalX, totalY, totalZ).canCaveCarve())
|
||||
{
|
||||
world.setBlock(totalX, totalY, totalZ, Blocks.AIR);
|
||||
}
|
||||
world.setBlock(totalX, totalY, totalZ, Blocks.AIR);
|
||||
}
|
||||
// add progress to the noise
|
||||
lerpNoise += lerpProg;
|
|
@ -134,8 +134,6 @@ public class Ginger
|
|||
public void update(GameData data)
|
||||
{
|
||||
registry.game.update();
|
||||
data.player.updateMovement();
|
||||
data.camera.updateMovement();
|
||||
picker.update();
|
||||
GingerUtils.update();
|
||||
ParticleMaster.update(data.camera);
|
||||
|
|
Loading…
Reference in New Issue