attempt merge
commit
bf376068ad
|
@ -1,10 +1,14 @@
|
|||
package com.github.halotroop.litecraft;
|
||||
|
||||
import org.joml.*;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.joml.Vector4i;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import com.github.halotroop.litecraft.save.LitecraftSave;
|
||||
import com.github.halotroop.litecraft.screens.TitleScreen;
|
||||
import com.github.halotroop.litecraft.types.block.*;
|
||||
import com.github.halotroop.litecraft.world.World;
|
||||
import com.github.halotroop.litecraft.world.gen.Dimensions;
|
||||
import com.github.hydos.ginger.engine.api.*;
|
||||
|
@ -28,6 +32,8 @@ public class Litecraft extends Game
|
|||
private LitecraftSave save;
|
||||
private Ginger ginger3D;
|
||||
private static Litecraft INSTANCE;
|
||||
private Player player;
|
||||
private Camera camera;
|
||||
//temp stuff to test out fbo fixes
|
||||
int oldWindowWidth = Window.width;
|
||||
int oldWindowHeight = Window.height;
|
||||
|
@ -48,27 +54,30 @@ public class Litecraft extends Game
|
|||
MouseCallbackHandler.trackWindow(Window.window);
|
||||
setupKeybinds();
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
Block b = Blocks.AIR; // make sure blocks are initialised
|
||||
|
||||
GingerUtils.init();
|
||||
Window.setBackgroundColour(0.2f, 0.2f, 0.6f);
|
||||
TexturedModel dirtModel = ModelLoader.loadGenericCube("block/cubes/stone/brick/stonebrick.png");
|
||||
StaticCube.scaleCube(1f);
|
||||
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);
|
||||
player.isVisible = false;
|
||||
ginger3D = new Ginger();
|
||||
data = new GameData(player, camera, 20);
|
||||
data.handleGuis = false;
|
||||
ginger3D.setup(new MasterRenderer(camera), INSTANCE);
|
||||
this.player = new Player(dirtModel, new Vector3f(0, 0, -3), 0, 180f, 0, new Vector3f(0.2f, 0.2f, 0.2f));
|
||||
this.camera = new FirstPersonCamera(player);
|
||||
this.player.isVisible = false;
|
||||
this.ginger3D = new Ginger();
|
||||
this.data = new GameData(this.player, this.camera, 20);
|
||||
this.data.handleGuis = false;
|
||||
this.ginger3D.setup(new MasterRenderer(this.camera), INSTANCE);
|
||||
FontType font = new FontType(Loader.loadFontAtlas("candara.png"), "candara.fnt");
|
||||
ginger3D.setGlobalFont(font);
|
||||
this.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));
|
||||
data.lights.add(sun);
|
||||
data.entities.add(player);
|
||||
oldWindowWidth = Window.width;
|
||||
oldWindowHeight = Window.height;
|
||||
frameTimer = System.currentTimeMillis();
|
||||
this.data.lights.add(sun);
|
||||
this.data.entities.add(this.player);
|
||||
this.oldWindowWidth = Window.width;
|
||||
this.oldWindowHeight = Window.height;
|
||||
this.frameTimer = System.currentTimeMillis();
|
||||
//start the game loop
|
||||
ginger3D.startGame();
|
||||
this.ginger3D.startGame();
|
||||
}
|
||||
|
||||
private void setupKeybinds()
|
||||
|
@ -81,7 +90,18 @@ public class Litecraft extends Game
|
|||
public void exit()
|
||||
{
|
||||
if (this.world != null)
|
||||
{
|
||||
this.world.unloadAllChunks();
|
||||
|
||||
try
|
||||
{ this.save.saveGlobalData(this.world.getSeed(), this.player); }
|
||||
catch (IOException e)
|
||||
{
|
||||
System.err.println("A critical error occurred while trying to save world data!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
ginger3D.cleanup();
|
||||
System.exit(0);
|
||||
}
|
||||
|
@ -89,7 +109,7 @@ public class Litecraft extends Game
|
|||
@Override
|
||||
public void render()
|
||||
{
|
||||
fps++;
|
||||
this.fps++;
|
||||
//FPS stuff sorry if i forget to remove whitespace
|
||||
if (System.currentTimeMillis() > frameTimer + 1000) // wait for one second
|
||||
{
|
||||
|
@ -99,19 +119,26 @@ public class Litecraft extends Game
|
|||
this.tps = 0;
|
||||
this.frameTimer += 1000; // reset the wait time
|
||||
}
|
||||
|
||||
// TODO pls comment this code
|
||||
if (ginger3D.gingerRegister.currentScreen == null)
|
||||
ginger3D.openScreen(new TitleScreen());
|
||||
ginger3D.update(data);
|
||||
this.ginger3D.openScreen(new TitleScreen());
|
||||
|
||||
this.ginger3D.update(data);
|
||||
|
||||
if (oldWindowHeight != Window.height || oldWindowWidth != Window.width)
|
||||
ginger3D.contrastFbo.resizeFBOs();
|
||||
oldWindowWidth = Window.width;
|
||||
oldWindowHeight = Window.height;
|
||||
ginger3D.gingerRegister.masterRenderer.renderShadowMap(data.entities, data.lights.get(0));
|
||||
this.ginger3D.contrastFbo.resizeFBOs();
|
||||
|
||||
this.oldWindowWidth = Window.width;
|
||||
this.oldWindowHeight = Window.height;
|
||||
this.ginger3D.gingerRegister.masterRenderer.renderShadowMap(data.entities, data.lights.get(0));
|
||||
|
||||
if (this.world != null)
|
||||
ginger3D.renderWorld(this, this.world);
|
||||
ginger3D.renderOverlays(this);
|
||||
ginger3D.postRender();
|
||||
dbgStats.w = binds;
|
||||
this.ginger3D.renderWorld(this, this.world);
|
||||
|
||||
this.ginger3D.renderOverlays(this);
|
||||
this.ginger3D.postRender();
|
||||
this.dbgStats.w = binds;
|
||||
this.binds = 0;
|
||||
}
|
||||
|
||||
|
@ -128,12 +155,24 @@ public class Litecraft extends Game
|
|||
public static Litecraft getInstance()
|
||||
{ return INSTANCE; }
|
||||
|
||||
public void setGingerPlayer(Player player)
|
||||
{
|
||||
this.data.entities.remove(this.player); // remove the old player
|
||||
|
||||
this.data.player = player; // set all the player variables
|
||||
this.player = player;
|
||||
this.camera.player = player;
|
||||
|
||||
this.data.entities.add(this.player); // add the new player
|
||||
}
|
||||
|
||||
public void onPlayButtonClick()
|
||||
{
|
||||
if (world == null)
|
||||
{
|
||||
this.save = new LitecraftSave("test", false);
|
||||
this.world = this.save.getWorldOrCreate(Dimensions.OVERWORLD);
|
||||
this.setGingerPlayer(this.world.player);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,8 +3,11 @@ package com.github.halotroop.litecraft.save;
|
|||
import java.io.*;
|
||||
import java.util.Random;
|
||||
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import com.github.halotroop.litecraft.world.*;
|
||||
import com.github.halotroop.litecraft.world.gen.Dimension;
|
||||
import com.github.halotroop.litecraft.world.gen.*;
|
||||
import com.github.hydos.ginger.engine.elements.objects.Player;
|
||||
|
||||
import tk.valoeghese.sod.*;
|
||||
|
||||
|
@ -79,25 +82,28 @@ public final class LitecraftSave
|
|||
|
||||
public World getWorldOrCreate(Dimension<?> dim)
|
||||
{
|
||||
File worldFile = new File(this.file.getPath() + "/global_data.sod");
|
||||
File globalDataFile = new File(this.file.getPath() + "/global_data.sod");
|
||||
|
||||
if (worldFile.isFile()) // load world
|
||||
if (globalDataFile.isFile()) // load world
|
||||
{
|
||||
BinaryData data = BinaryData.read(worldFile); // read data from the world file
|
||||
BinaryData data = BinaryData.read(globalDataFile); // read data from the world file
|
||||
DataSection properties = data.get("properties"); // get the properties data section from the data that we have just read
|
||||
DataSection playerData = data.get("player");
|
||||
long seed = 0; // default seed if we cannot read it is 0
|
||||
float playerX = 0, playerY = 0, playerZ = -3; // default player x/y/z
|
||||
|
||||
try // try read the seed from the file
|
||||
{
|
||||
seed = properties.readLong(0); // seed is at index 0
|
||||
playerX = playerData.readFloat(0); // player x/y/z is at index 1/2/3 respectively
|
||||
playerY = playerData.readFloat(1);
|
||||
playerZ = playerData.readFloat(2);
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
{ System.out.println("Exception in reading save data! This may be benign, merely an artifact of an update to the contents of the world save data."); }
|
||||
|
||||
World world = new World(seed, 10, dim, this); // create new world with seed read from file or 0, if it could not be read
|
||||
world.spawnPlayer(); // spawn player in world
|
||||
world.spawnPlayer(playerX, playerY, playerZ); // spawn player in world
|
||||
return world;
|
||||
}
|
||||
else // create world
|
||||
|
@ -106,12 +112,8 @@ public final class LitecraftSave
|
|||
|
||||
try
|
||||
{
|
||||
worldFile.createNewFile(); // create world file
|
||||
BinaryData data = new BinaryData(); // create empty binary data
|
||||
DataSection properties = new DataSection(); // create empty data section for properties
|
||||
properties.writeLong(seed); // write seed at index 0
|
||||
data.put("properties", properties); // add properties section
|
||||
data.write(worldFile); // write to file
|
||||
globalDataFile.createNewFile(); // create world file
|
||||
this.writeGlobalData(globalDataFile, seed, new Vector3f(0, 0, -3)); // write global data with default player pos
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
|
@ -125,5 +127,27 @@ public final class LitecraftSave
|
|||
}
|
||||
}
|
||||
|
||||
public void saveGlobalData(long seed, Player player) throws IOException
|
||||
{
|
||||
File globalDataFile = new File(this.file.getPath() + "/global_data.sod");
|
||||
globalDataFile.createNewFile(); // create world file if it doesn't exist.
|
||||
|
||||
writeGlobalData(globalDataFile, seed, player.getPosition());
|
||||
}
|
||||
|
||||
private void writeGlobalData(File globalDataFile, long seed, Vector3f playerPos)
|
||||
{
|
||||
BinaryData data = new BinaryData(); // create empty binary data
|
||||
DataSection properties = new DataSection(); // create empty data section for properties
|
||||
properties.writeLong(seed); // write seed at index 0
|
||||
DataSection playerData = new DataSection();
|
||||
playerData.writeFloat(playerPos.x); // default spawn player x/y/z
|
||||
playerData.writeFloat(playerPos.y);
|
||||
playerData.writeFloat(playerPos.z);
|
||||
data.put("properties", properties); // add properties section to data
|
||||
data.put("player", playerData); // add player section to data
|
||||
data.write(globalDataFile); // write to file
|
||||
}
|
||||
|
||||
private static final String SAVE_DIR = "./saves/";
|
||||
}
|
||||
|
|
|
@ -17,7 +17,5 @@ public class BlockEntity extends RenderObject
|
|||
public void processCulling(Chunk chunk) {
|
||||
Vector3f southNeighbourBlockLocation = this.getPosition();
|
||||
southNeighbourBlockLocation.x--;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.github.halotroop.litecraft.world;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.ToIntFunction;
|
||||
|
||||
import org.joml.Vector3f;
|
||||
|
@ -11,7 +10,6 @@ import com.github.halotroop.litecraft.world.block.BlockRenderer;
|
|||
import com.github.halotroop.litecraft.world.gen.WorldGenConstants;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.*;
|
||||
import it.unimi.dsi.fastutil.longs.*;
|
||||
import it.unimi.dsi.fastutil.objects.*;
|
||||
import tk.valoeghese.sod.*;
|
||||
|
||||
|
@ -24,18 +22,18 @@ public class Chunk implements BlockAccess, WorldGenConstants, DataStorage
|
|||
private static long posHash(int x, int y, int z)
|
||||
{ return ((long) x & MAX_POS) | (((long) y & MAX_POS) << POS_SHIFT) | (((long) z & MAX_POS) << DOUBLE_SHIFT); }
|
||||
|
||||
List<BlockEntity> renderList;
|
||||
private final Long2ObjectMap<Block> blocks = new Long2ObjectArrayMap<>();
|
||||
private final Long2ObjectMap<BlockEntity> blockEntities = new Long2ObjectArrayMap<>();
|
||||
private final Block[] blocks = new Block[CHUNK_SIZE*CHUNK_SIZE*CHUNK_SIZE];
|
||||
private BlockEntity[] blockEntities = new BlockEntity[CHUNK_SIZE*CHUNK_SIZE*CHUNK_SIZE];
|
||||
private boolean render = false;
|
||||
public final int chunkX, chunkY, chunkZ;
|
||||
public final int chunkStartX, chunkStartY, chunkStartZ;
|
||||
private boolean fullyGenerated = false;
|
||||
public final int dimension;
|
||||
private boolean dirty = true;
|
||||
private BlockEntity[] renderedBlocks;
|
||||
|
||||
public Chunk(int chunkX, int chunkY, int chunkZ, int dimension)
|
||||
{
|
||||
renderList = new ArrayList<BlockEntity>();
|
||||
this.chunkX = chunkX;
|
||||
this.chunkY = chunkY;
|
||||
this.chunkZ = chunkZ;
|
||||
|
@ -54,29 +52,59 @@ public class Chunk implements BlockAccess, WorldGenConstants, DataStorage
|
|||
@Override
|
||||
public Block getBlock(int x, int y, int z)
|
||||
{
|
||||
long hash = posHash(x, y, z);
|
||||
return this.blocks.get(hash);
|
||||
if (x > CHUNK_SIZE || y > CHUNK_SIZE || z > CHUNK_SIZE || x < 0 || y < 0 || z < 0)
|
||||
{
|
||||
throw new RuntimeException("Block [" + x + ", " + y + ", " + z + ", " + "] out of chunk bounds!");
|
||||
}
|
||||
|
||||
return blocks[x*CHUNK_SIZE*CHUNK_SIZE + z*CHUNK_SIZE + y];
|
||||
}
|
||||
|
||||
public BlockEntity getBlockEntity(int x, int y, int z)
|
||||
{
|
||||
long hash = posHash(x, y, z);
|
||||
return this.blockEntities.get(hash);
|
||||
if (x > CHUNK_SIZE || y > CHUNK_SIZE || z > CHUNK_SIZE || x < 0 || y < 0 || z < 0)
|
||||
{
|
||||
throw new RuntimeException("Block [" + x + ", " + y + ", " + z + ", " + "] out of chunk bounds!");
|
||||
}
|
||||
|
||||
return this.blockEntities[x*CHUNK_SIZE*CHUNK_SIZE + z*CHUNK_SIZE + y];
|
||||
}
|
||||
|
||||
public void render(BlockRenderer blockRenderer)
|
||||
{
|
||||
renderList.clear();
|
||||
|
||||
if (render)
|
||||
{
|
||||
for(int i = 0; i < CHUNK_SIZE; i++)
|
||||
for(int j = 0; j < CHUNK_SIZE; j++)
|
||||
for(int k = 0; k < CHUNK_SIZE; k++)
|
||||
if (dirty)
|
||||
{
|
||||
dirty = false;
|
||||
renderedBlocks = new BlockEntity[CHUNK_SIZE*CHUNK_SIZE*CHUNK_SIZE];
|
||||
for(int x = 0; x < CHUNK_SIZE; x++)
|
||||
{
|
||||
for(int y = 0; y < CHUNK_SIZE; y++)
|
||||
{
|
||||
BlockEntity block = getBlockEntity(i, j, k);
|
||||
renderList.add(block);
|
||||
for(int z = 0; z < CHUNK_SIZE; z++)
|
||||
{
|
||||
BlockEntity block = getBlockEntity(x, y, z);
|
||||
if (x == 0 || x == CHUNK_SIZE-1 || z == 0 || z == CHUNK_SIZE-1 || y == 0 || y == CHUNK_SIZE-1)
|
||||
{
|
||||
renderedBlocks[x*CHUNK_SIZE*CHUNK_SIZE + z*CHUNK_SIZE + y] = block;
|
||||
continue;
|
||||
}
|
||||
|
||||
// check for air. Yes this is stupid, TODO fix this
|
||||
if (getBlockEntity(x-1, y, z) == null || getBlockEntity(x+1, y, z) == null ||
|
||||
getBlockEntity(x, y-1, z) == null || getBlockEntity(x, y+1, z) == null ||
|
||||
getBlockEntity(x, y, z-1) == null || getBlockEntity(x, y, z+1) == null)
|
||||
{
|
||||
renderedBlocks[x*CHUNK_SIZE*CHUNK_SIZE + z*CHUNK_SIZE + y] = block;
|
||||
}
|
||||
}
|
||||
}
|
||||
blockRenderer.render(renderList);
|
||||
}
|
||||
}
|
||||
|
||||
blockRenderer.render(renderedBlocks);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,12 +120,12 @@ public class Chunk implements BlockAccess, WorldGenConstants, DataStorage
|
|||
if (z > MAX_POS)
|
||||
z = MAX_POS;
|
||||
else if (z < 0) z = 0;
|
||||
long hash = posHash(x, y, z);
|
||||
this.blocks.put(hash, block);
|
||||
this.blocks[x*CHUNK_SIZE*CHUNK_SIZE + z*CHUNK_SIZE + y] = block;
|
||||
if (this.render)
|
||||
{
|
||||
this.blockEntities.put(hash, new BlockEntity(block, new Vector3f(this.chunkStartX + x, this.chunkStartY + y, this.chunkStartZ + z)));
|
||||
this.blockEntities[x*CHUNK_SIZE*CHUNK_SIZE + z*CHUNK_SIZE + y] = new BlockEntity(block, new Vector3f(this.chunkStartX + x, this.chunkStartY + y, this.chunkStartZ + z));
|
||||
}
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
public void setRender(boolean render)
|
||||
|
@ -110,24 +138,22 @@ public class Chunk implements BlockAccess, WorldGenConstants, DataStorage
|
|||
{
|
||||
for (int z = 0; z < CHUNK_SIZE; ++z)
|
||||
{
|
||||
long hash = posHash(x, y, z);
|
||||
Block block = this.blocks.get(hash);
|
||||
if (block.isVisible()) this.blockEntities.put(hash, new BlockEntity(block,
|
||||
Block block = this.blocks[x*CHUNK_SIZE*CHUNK_SIZE + z*CHUNK_SIZE + y];
|
||||
if (block.isVisible()) this.blockEntities[x*CHUNK_SIZE*CHUNK_SIZE + z*CHUNK_SIZE + y] = new BlockEntity(block,
|
||||
new Vector3f(
|
||||
this.chunkStartX + x,
|
||||
this.chunkStartY + y,
|
||||
this.chunkStartZ + z)));
|
||||
this.chunkStartZ + z));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (this.render) // else if it has been changed to false
|
||||
{
|
||||
int length = blockEntities.size();
|
||||
for (int i = length; i >= 0; --i)
|
||||
{ this.blockEntities.remove(i); }
|
||||
blockEntities = new BlockEntity[CHUNK_SIZE*CHUNK_SIZE*CHUNK_SIZE];
|
||||
}
|
||||
this.render = render;
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
public boolean isFullyGenerated()
|
||||
|
@ -165,7 +191,7 @@ public class Chunk implements BlockAccess, WorldGenConstants, DataStorage
|
|||
{
|
||||
for (int x = 0; x < CHUNK_SIZE; ++x)
|
||||
{
|
||||
this.blocks.put(posHash, palette.get(blockData.readInt((int) posHash)));
|
||||
blocks[x*CHUNK_SIZE*CHUNK_SIZE + z*CHUNK_SIZE + y] = palette.get(blockData.readInt((int) posHash));
|
||||
++posHash;
|
||||
}
|
||||
}
|
||||
|
@ -193,7 +219,7 @@ public class Chunk implements BlockAccess, WorldGenConstants, DataStorage
|
|||
{
|
||||
for (int x = 0; x < CHUNK_SIZE; ++x)
|
||||
{
|
||||
Block b = this.blocks.get(posHash);
|
||||
Block b = blocks[x*CHUNK_SIZE*CHUNK_SIZE + z*CHUNK_SIZE + y];
|
||||
blockData.writeInt(palette.computeIntIfAbsent(b, nextIdProvider));
|
||||
++posHash;
|
||||
}
|
||||
|
@ -207,5 +233,7 @@ public class Chunk implements BlockAccess, WorldGenConstants, DataStorage
|
|||
|
||||
data.put("palette", paletteData);
|
||||
data.put("block", blockData);
|
||||
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
package com.github.halotroop.litecraft.world;
|
||||
|
||||
import com.github.halotroop.litecraft.types.block.Block;
|
||||
import com.github.halotroop.litecraft.world.gen.WorldGenConstants;
|
||||
|
||||
final class GenWorld implements BlockAccess, WorldGenConstants
|
||||
{
|
||||
GenWorld(World parent)
|
||||
{
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public final World parent;
|
||||
|
||||
@Override
|
||||
public Block getBlock(int x, int y, int z)
|
||||
{ return this.parent.getGenChunk(x >> POS_SHIFT, y >> POS_SHIFT, z >> POS_SHIFT).getBlock(x & MAX_POS, y & MAX_POS, z & MAX_POS); }
|
||||
|
||||
@Override
|
||||
public void setBlock(int x, int y, int z, Block block)
|
||||
{ this.parent.getGenChunk(x >> POS_SHIFT, y >> POS_SHIFT, z >> POS_SHIFT).setBlock(x & MAX_POS, y & MAX_POS, z & MAX_POS, block); }
|
||||
}
|
|
@ -35,15 +35,19 @@ public class World implements BlockAccess, WorldGenConstants
|
|||
this.seed = seed;
|
||||
this.chunkGenerator = dim.createChunkGenerator(seed);
|
||||
this.worldModifiers = dim.getWorldModifierArray();
|
||||
this.genBlockAccess = new GenWorld(this);
|
||||
this.genBlockAccess = new GenerationWorld(this);
|
||||
this.save = save;
|
||||
this.dimension = dim.id;
|
||||
}
|
||||
|
||||
public void spawnPlayer()
|
||||
{ this.spawnPlayer(0, 0, -3); }
|
||||
|
||||
public void spawnPlayer(float x, float y, float z)
|
||||
{
|
||||
TexturedModel dirtModel = ModelLoader.loadGenericCube("block/cubes/soil/dirt.png");
|
||||
this.player = new Player(dirtModel, new Vector3f(0, 0, -3), 0, 180f, 0, new Vector3f(0.2f, 0.2f, 0.2f));
|
||||
this.player = new Player(dirtModel, new Vector3f(x, y, z), 0, 180f, 0, new Vector3f(0.2f, 0.2f, 0.2f));
|
||||
this.player.isVisible = false;
|
||||
}
|
||||
|
||||
// this constructor will likely not be neccesary when we have dynamic chunkloading
|
||||
|
@ -51,10 +55,14 @@ public class World implements BlockAccess, WorldGenConstants
|
|||
{
|
||||
this(seed, dim, save);
|
||||
|
||||
long time = System.currentTimeMillis();
|
||||
System.out.println("Generating world!");
|
||||
for (int i = (0 - (size/2)); i < (size/2); i++)
|
||||
for (int k = (0 - (size/2)); k < (size/2); k++)
|
||||
for (int y = -2; y < 0; ++y)
|
||||
this.getChunk(i, y, k).setRender(true);
|
||||
|
||||
System.out.println("Generated world in " + (System.currentTimeMillis() - time) + " milliseconds");
|
||||
}
|
||||
|
||||
public Chunk getChunk(int chunkX, int chunkY, int chunkZ)
|
||||
|
@ -121,7 +129,6 @@ public class World implements BlockAccess, WorldGenConstants
|
|||
//used for model combining and culling
|
||||
public Chunk optimiseChunk(Chunk chunk)
|
||||
{
|
||||
|
||||
return chunk;
|
||||
}
|
||||
|
||||
|
@ -129,7 +136,7 @@ public class World implements BlockAccess, WorldGenConstants
|
|||
{
|
||||
Chunk chunk = getChunk(0, -1, 0);
|
||||
if(chunk!= null) {
|
||||
blockRenderer.prepareModel(chunk.getBlockEntity(0, -2, 0).getModel());
|
||||
blockRenderer.prepareModel(chunk.getBlockEntity(0, 0, 0).getModel());
|
||||
this.chunks.forEach((pos, c) -> c.render(blockRenderer));
|
||||
blockRenderer.unbindModel();
|
||||
}
|
||||
|
@ -146,4 +153,27 @@ public class World implements BlockAccess, WorldGenConstants
|
|||
|
||||
chunkPositions.forEach((LongConsumer) (pos -> this.chunks.remove(pos))); // remove all chunks
|
||||
}
|
||||
|
||||
public long getSeed()
|
||||
{
|
||||
return this.seed;
|
||||
}
|
||||
|
||||
private static final class GenerationWorld implements BlockAccess, WorldGenConstants
|
||||
{
|
||||
GenerationWorld(World parent)
|
||||
{
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public final World parent;
|
||||
|
||||
@Override
|
||||
public Block getBlock(int x, int y, int z)
|
||||
{ return this.parent.getGenChunk(x >> POS_SHIFT, y >> POS_SHIFT, z >> POS_SHIFT).getBlock(x & MAX_POS, y & MAX_POS, z & MAX_POS); }
|
||||
|
||||
@Override
|
||||
public void setBlock(int x, int y, int z, Block block)
|
||||
{ this.parent.getGenChunk(x >> POS_SHIFT, y >> POS_SHIFT, z >> POS_SHIFT).setBlock(x & MAX_POS, y & MAX_POS, z & MAX_POS, block); }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
package com.github.halotroop.litecraft.world.block;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.joml.Matrix4f;
|
||||
import org.lwjgl.opengl.*;
|
||||
|
||||
import com.github.halotroop.litecraft.Litecraft;
|
||||
import com.github.halotroop.litecraft.types.block.BlockEntity;
|
||||
import com.github.halotroop.litecraft.world.gen.WorldGenConstants;
|
||||
import com.github.hydos.ginger.engine.api.GingerRegister;
|
||||
import com.github.hydos.ginger.engine.elements.objects.RenderObject;
|
||||
import com.github.hydos.ginger.engine.io.Window;
|
||||
|
@ -16,7 +15,7 @@ import com.github.hydos.ginger.engine.render.models.*;
|
|||
import com.github.hydos.ginger.engine.render.shaders.StaticShader;
|
||||
import com.github.hydos.ginger.engine.render.texture.ModelTexture;
|
||||
|
||||
public class BlockRenderer extends Renderer
|
||||
public class BlockRenderer extends Renderer implements WorldGenConstants
|
||||
{
|
||||
private StaticShader shader;
|
||||
|
||||
|
@ -59,32 +58,37 @@ public class BlockRenderer extends Renderer
|
|||
GL30.glBindVertexArray(0);
|
||||
}
|
||||
|
||||
public void render(List<BlockEntity> renderList)
|
||||
public void render(BlockEntity[] renderList)
|
||||
{
|
||||
shader.start();
|
||||
shader.loadSkyColour(Window.getColour());
|
||||
shader.loadViewMatrix(GingerRegister.getInstance().game.data.camera);
|
||||
TexturedModel model = renderList.get(0).getModel();
|
||||
TexturedModel model = renderList[0].getModel();
|
||||
if(GingerRegister.getInstance().wireframe)
|
||||
{
|
||||
GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE );
|
||||
GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
|
||||
}
|
||||
for (RenderObject entity : renderList)
|
||||
for(int x = 0; x < CHUNK_SIZE; x++)
|
||||
{
|
||||
if (entity != null && entity.getModel() != null) {
|
||||
prepTexture(entity.getModel().getTexture(), entity.getModel().getTexture().getTextureID());
|
||||
prepBlockInstance(entity);
|
||||
GL11.glDrawElements(GL11.GL_TRIANGLES, model.getRawModel().getVertexCount(), GL11.GL_UNSIGNED_INT, 0);
|
||||
|
||||
for (int y = 0; y < CHUNK_SIZE; y++)
|
||||
{
|
||||
for (int z = 0; z < CHUNK_SIZE; z++)
|
||||
{
|
||||
BlockEntity entity = renderList[x*CHUNK_SIZE*CHUNK_SIZE + z*CHUNK_SIZE + y];
|
||||
if (entity != null && entity.getModel() != null)
|
||||
{
|
||||
prepTexture(entity.getModel().getTexture(), entity.getModel().getTexture().getTextureID());
|
||||
prepBlockInstance(entity);
|
||||
GL11.glDrawElements(GL11.GL_TRIANGLES, model.getRawModel().getVertexCount(), GL11.GL_UNSIGNED_INT, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(GingerRegister.getInstance().wireframe)
|
||||
{
|
||||
GL11.glPolygonMode( GL11.GL_FRONT_AND_BACK,GL11.GL_FILL );
|
||||
GL11.glPolygonMode( GL11.GL_FRONT_AND_BACK,GL11.GL_FILL);
|
||||
}
|
||||
shader.stop();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ public abstract class Dimension<T extends ChunkGenerator>
|
|||
}
|
||||
|
||||
public WorldModifier[] getWorldModifierArray() {
|
||||
return this.worldModifiers.toArray(new WorldModifier[0]);
|
||||
return this.worldModifiers.toArray(WorldModifier[]::new);
|
||||
}
|
||||
|
||||
public abstract T createChunkGenerator(long seed);
|
||||
|
|
|
@ -22,13 +22,16 @@ public class OverworldChunkGenerator implements ChunkGenerator, WorldGenConstant
|
|||
{
|
||||
Chunk chunk = new Chunk(chunkX, chunkY, chunkZ, this.dimension);
|
||||
|
||||
for (int x = 0; x < CHUNK_SIZE; ++x) {
|
||||
for (int x = 0; x < CHUNK_SIZE; ++x)
|
||||
{
|
||||
double totalX = x + chunk.chunkStartX;
|
||||
|
||||
for (int z = 0; z < CHUNK_SIZE; ++z) {
|
||||
int height = (int) this.noise.sample(totalX, chunk.chunkStartZ + z);
|
||||
for (int z = 0; z < CHUNK_SIZE; ++z)
|
||||
{
|
||||
int height = (int) this.noise.sample(totalX, (double) (chunk.chunkStartZ + z));
|
||||
|
||||
for (int y = 0; y < CHUNK_SIZE; ++y) {
|
||||
for (int y = 0; y < CHUNK_SIZE; ++y)
|
||||
{
|
||||
int totalY = chunk.chunkStartY + y;
|
||||
Block block = Blocks.AIR;
|
||||
|
||||
|
|
|
@ -12,4 +12,4 @@ public class OverworldDimension extends Dimension<OverworldChunkGenerator>
|
|||
{
|
||||
return new OverworldChunkGenerator(seed, this.id);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,8 +2,8 @@ package com.github.halotroop.litecraft.world.gen;
|
|||
|
||||
public interface WorldGenConstants
|
||||
{
|
||||
static final int POS_SHIFT = 3;
|
||||
static final int DOUBLE_SHIFT = POS_SHIFT * 2;
|
||||
static final int CHUNK_SIZE = (int) Math.pow(2, POS_SHIFT);
|
||||
static final int MAX_POS = CHUNK_SIZE - 1;
|
||||
int POS_SHIFT = 3;
|
||||
int DOUBLE_SHIFT = POS_SHIFT * 2;
|
||||
int CHUNK_SIZE = (int) Math.pow(2, POS_SHIFT);
|
||||
int MAX_POS = CHUNK_SIZE - 1;
|
||||
}
|
||||
|
|
|
@ -44,7 +44,12 @@ public class Player extends RenderObject
|
|||
|
||||
if (Window.isKeyDown(GLFW.GLFW_KEY_SPACE))
|
||||
{
|
||||
jump();
|
||||
// jump();
|
||||
position.y += Constants.movementSpeed;
|
||||
}
|
||||
if (Window.isKeyDown(GLFW.GLFW_KEY_LEFT_SHIFT))
|
||||
{
|
||||
position.y -= Constants.movementSpeed;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,6 +69,6 @@ public class Player extends RenderObject
|
|||
upwardsSpeed += Constants.gravity.y() * Window.getTime();
|
||||
isInAir = false;
|
||||
upwardsSpeed = 0;
|
||||
super.getPosition().y = 0;
|
||||
// super.getPosition().y = 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue