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
|
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,17 +138,14 @@ 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()
|
||||||
{
|
{
|
||||||
Window.create(1280, 720, "LiteCraft", 60); // create window
|
Window.create(1280, 720, "LiteCraft", 60); // create window
|
||||||
|
|
|
@ -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 float caveCarveThreshold = -1f; // cannot carve
|
||||||
private final String identifier;
|
private final String identifier;
|
||||||
|
|
||||||
public Properties(String identifier)
|
public Properties(String identifier)
|
||||||
|
@ -29,15 +29,16 @@ public class Block
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Properties canCaveCarve(boolean canCaveCarve)
|
public Properties caveCarveThreshold(float threshold)
|
||||||
{
|
{
|
||||||
this.canCaveCarve = canCaveCarve;
|
this.caveCarveThreshold = threshold;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final TexturedModel model;
|
public final TexturedModel model;
|
||||||
private final boolean visible, fullCube, canCaveCarve;
|
private final boolean visible, fullCube;
|
||||||
|
private final float caveCarveThreshold;
|
||||||
public final String identifier;
|
public final String identifier;
|
||||||
|
|
||||||
public boolean isFullCube()
|
public boolean isFullCube()
|
||||||
|
@ -46,8 +47,8 @@ public class Block
|
||||||
public boolean isVisible()
|
public boolean isVisible()
|
||||||
{ return this.visible; }
|
{ return this.visible; }
|
||||||
|
|
||||||
public boolean canCaveCarve()
|
public float getCaveCarveThreshold()
|
||||||
{ return this.canCaveCarve; }
|
{ return this.caveCarveThreshold; }
|
||||||
|
|
||||||
protected Block(Properties properties)
|
protected Block(Properties properties)
|
||||||
{ this((TexturedModel) null, properties); }
|
{ this((TexturedModel) null, properties); }
|
||||||
|
@ -61,7 +62,7 @@ public class Block
|
||||||
this.visible = properties.visible;
|
this.visible = properties.visible;
|
||||||
this.fullCube = properties.fullCube;
|
this.fullCube = properties.fullCube;
|
||||||
this.identifier = properties.identifier;
|
this.identifier = properties.identifier;
|
||||||
this.canCaveCarve = properties.canCaveCarve;
|
this.caveCarveThreshold = properties.caveCarveThreshold;
|
||||||
IDENTIFIER_TO_BLOCK.put(this.identifier, this);
|
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 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));
|
||||||
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").caveCarveThreshold(0.04f));
|
||||||
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").caveCarveThreshold(0.04f));
|
||||||
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").caveCarveThreshold(0.08f));
|
||||||
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").caveCarveThreshold(0.05f));
|
||||||
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").caveCarveThreshold(0.06f));
|
||||||
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").caveCarveThreshold(0.09f));
|
||||||
|
|
||||||
public static Block init()
|
public static Block init()
|
||||||
{
|
{
|
||||||
|
|
|
@ -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 ||
|
|
||||||
getBlockInstance(x, y, z - 1).getModel() == null || getBlockInstance(x, y, z + 1).getModel() == null)
|
|
||||||
{
|
|
||||||
renderedBlocks[index(x, y, z)] = block;
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package com.github.halotroop.litecraft.world.gen;
|
package com.github.halotroop.litecraft.world.gen.modifier;
|
||||||
|
|
||||||
import java.util.Random;
|
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.util.noise.OctaveSimplexNoise;
|
||||||
import com.github.halotroop.litecraft.world.BlockAccess;
|
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
|
public class CavesModifier implements WorldModifier, WorldGenConstants
|
||||||
{
|
{
|
||||||
|
@ -16,7 +16,7 @@ public class CavesModifier implements WorldModifier, WorldGenConstants
|
||||||
public void initialize(long seed)
|
public void initialize(long seed)
|
||||||
{
|
{
|
||||||
Random rand = new Random(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
|
@Override
|
||||||
|
@ -36,8 +36,8 @@ public class CavesModifier implements WorldModifier, WorldGenConstants
|
||||||
{
|
{
|
||||||
int scOffsetY = subChunkY << 2; // sub chunk offset y
|
int scOffsetY = subChunkY << 2; // sub chunk offset y
|
||||||
int scTotalY = scOffsetY + chunkStartY;
|
int scTotalY = scOffsetY + chunkStartY;
|
||||||
double scSampleY = (double) scTotalY * 2.0;
|
double scSampleY = (double) scTotalY * 1.5; // squish caves along y axis a bit
|
||||||
double scUpperYOffset = 4.0 * 2.0;
|
double scUpperYOffset = 4.0 * 1.5;
|
||||||
// calculate noise at each corner of the cube [lower|upper][south|north][west|east]
|
// 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 noiseLSW = this.caveNoise.sample(scTotalX, scSampleY, scTotalZ); // base = lower south west
|
||||||
double noiseUSW = this.caveNoise.sample(scTotalX, scSampleY + scUpperYOffset, scTotalZ);
|
double noiseUSW = this.caveNoise.sample(scTotalX, scSampleY + scUpperYOffset, scTotalZ);
|
||||||
|
@ -81,15 +81,12 @@ public class CavesModifier implements WorldModifier, WorldGenConstants
|
||||||
{
|
{
|
||||||
int totalX = subX + scTotalX;
|
int totalX = subX + scTotalX;
|
||||||
// calculate whether to replace block with air
|
// calculate whether to replace block with air
|
||||||
// if the noise is within the threshold for caves
|
// if the noise is within the threshold for that block for caves
|
||||||
if (-THRESHOLD < lerpNoise && lerpNoise < THRESHOLD)
|
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
|
// add progress to the noise
|
||||||
lerpNoise += lerpProg;
|
lerpNoise += lerpProg;
|
||||||
}
|
}
|
|
@ -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);
|
||||||
|
|
Loading…
Reference in New Issue