[Refactor] Post-JOML rewrite cleanup
parent
bf376068ad
commit
f88dd6f1d8
|
@ -1,9 +1,8 @@
|
|||
package com.github.halotroop.litecraft;
|
||||
|
||||
import org.joml.*;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.joml.Vector4i;
|
||||
import org.joml.*;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import com.github.halotroop.litecraft.save.LitecraftSave;
|
||||
|
@ -53,10 +52,7 @@ public class Litecraft extends Game
|
|||
KeyCallbackHandler.trackWindow(Window.window);
|
||||
MouseCallbackHandler.trackWindow(Window.window);
|
||||
setupKeybinds();
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
Block b = Blocks.AIR; // make sure blocks are initialised
|
||||
|
||||
@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");
|
||||
|
@ -92,17 +88,17 @@ public class Litecraft extends Game
|
|||
if (this.world != null)
|
||||
{
|
||||
this.world.unloadAllChunks();
|
||||
|
||||
try
|
||||
{ this.save.saveGlobalData(this.world.getSeed(), this.player); }
|
||||
{
|
||||
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();
|
||||
ginger3D.cleanup();
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
|
@ -119,23 +115,17 @@ 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)
|
||||
this.ginger3D.openScreen(new TitleScreen());
|
||||
|
||||
this.ginger3D.update(data);
|
||||
|
||||
if (oldWindowHeight != Window.height || oldWindowWidth != Window.width)
|
||||
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)
|
||||
this.ginger3D.renderWorld(this, this.world);
|
||||
|
||||
this.ginger3D.renderOverlays(this);
|
||||
this.ginger3D.postRender();
|
||||
this.dbgStats.w = binds;
|
||||
|
@ -158,11 +148,9 @@ public class Litecraft extends Game
|
|||
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
|
||||
}
|
||||
|
||||
|
@ -173,6 +161,6 @@ public class Litecraft extends Game
|
|||
this.save = new LitecraftSave("test", false);
|
||||
this.world = this.save.getWorldOrCreate(Dimensions.OVERWORLD);
|
||||
this.setGingerPlayer(this.world.player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,7 +2,9 @@ package com.github.halotroop.litecraft.logic;
|
|||
|
||||
import tk.valoeghese.sod.BinaryData;
|
||||
|
||||
public interface DataStorage {
|
||||
public interface DataStorage
|
||||
{
|
||||
void read(BinaryData data);
|
||||
|
||||
void write(BinaryData data);
|
||||
}
|
||||
|
|
|
@ -12,10 +12,10 @@ public class Timer
|
|||
{
|
||||
void onTick(float deltaTime);
|
||||
}
|
||||
|
||||
private double lastTick;
|
||||
private double nextTick;
|
||||
private int tickRate;
|
||||
|
||||
private Set<TickListener> tickListeners = new HashSet<>();
|
||||
|
||||
public Timer(int tickRate)
|
||||
|
|
|
@ -6,7 +6,7 @@ import java.util.Random;
|
|||
import org.joml.Vector3f;
|
||||
|
||||
import com.github.halotroop.litecraft.world.*;
|
||||
import com.github.halotroop.litecraft.world.gen.*;
|
||||
import com.github.halotroop.litecraft.world.gen.Dimension;
|
||||
import com.github.hydos.ginger.engine.elements.objects.Player;
|
||||
|
||||
import tk.valoeghese.sod.*;
|
||||
|
@ -17,7 +17,6 @@ public final class LitecraftSave
|
|||
{
|
||||
StringBuilder sb = new StringBuilder(SAVE_DIR).append(name);
|
||||
File saveDir = new File(sb.toString());
|
||||
|
||||
if (mustCreateNew)
|
||||
{
|
||||
while (saveDir.exists())
|
||||
|
@ -26,7 +25,6 @@ public final class LitecraftSave
|
|||
saveDir = new File(sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
this.file = saveDir;
|
||||
this.file.mkdirs();
|
||||
}
|
||||
|
@ -36,19 +34,16 @@ public final class LitecraftSave
|
|||
public boolean saveChunk(Chunk chunk)
|
||||
{
|
||||
StringBuilder fileLocBuilder = new StringBuilder(this.file.getPath())
|
||||
.append('/').append(chunk.dimension)
|
||||
.append('/').append(chunk.chunkX)
|
||||
.append('/').append(chunk.chunkZ);
|
||||
.append('/').append(chunk.dimension)
|
||||
.append('/').append(chunk.chunkX)
|
||||
.append('/').append(chunk.chunkZ);
|
||||
File chunkDir = new File(fileLocBuilder.toString());
|
||||
chunkDir.mkdirs(); // create directory for file if it does not exist
|
||||
|
||||
// format: <save dir>/<dim>/<chunkX>/<chunkZ>/<chunkY>.sod
|
||||
File chunkFile = new File(fileLocBuilder.append('/').append(chunk.chunkY).append(".sod").toString());
|
||||
|
||||
try
|
||||
{
|
||||
chunkFile.createNewFile();
|
||||
|
||||
BinaryData data = new BinaryData(); // create new empty binary data
|
||||
chunk.write(data); // write the chunk info to the binary data
|
||||
return data.write(chunkFile); // write the data to the file, return whether an io exception occurred
|
||||
|
@ -64,15 +59,13 @@ public final class LitecraftSave
|
|||
{
|
||||
// format: <save dir>/<dim>/<chunkX>/<chunkZ>/<chunkY>.sod
|
||||
File chunkFile = new File(new StringBuilder(this.file.getPath())
|
||||
.append('/').append(dimension)
|
||||
.append('/').append(chunkX)
|
||||
.append('/').append(chunkZ)
|
||||
.append('/').append(chunkY).append(".sod").toString());
|
||||
|
||||
.append('/').append(dimension)
|
||||
.append('/').append(chunkX)
|
||||
.append('/').append(chunkZ)
|
||||
.append('/').append(chunkY).append(".sod").toString());
|
||||
if (chunkFile.isFile())
|
||||
{
|
||||
BinaryData data = BinaryData.read(chunkFile);
|
||||
|
||||
Chunk result = new Chunk(chunkX, chunkY, chunkZ, dimension); // create chunk
|
||||
result.read(data); // load the chunk data we have just read into the chunk
|
||||
return result;
|
||||
|
@ -83,7 +76,6 @@ public final class LitecraftSave
|
|||
public World getWorldOrCreate(Dimension<?> dim)
|
||||
{
|
||||
File globalDataFile = new File(this.file.getPath() + "/global_data.sod");
|
||||
|
||||
if (globalDataFile.isFile()) // load world
|
||||
{
|
||||
BinaryData data = BinaryData.read(globalDataFile); // read data from the world file
|
||||
|
@ -91,7 +83,6 @@ public final class LitecraftSave
|
|||
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
|
||||
|
@ -100,8 +91,9 @@ public final class LitecraftSave
|
|||
playerZ = playerData.readFloat(2);
|
||||
}
|
||||
catch (Throwable e)
|
||||
{ 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."); }
|
||||
|
||||
{
|
||||
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(playerX, playerY, playerZ); // spawn player in world
|
||||
return world;
|
||||
|
@ -109,7 +101,6 @@ public final class LitecraftSave
|
|||
else // create world
|
||||
{
|
||||
long seed = new Random().nextLong();
|
||||
|
||||
try
|
||||
{
|
||||
globalDataFile.createNewFile(); // create world file
|
||||
|
@ -120,7 +111,6 @@ public final class LitecraftSave
|
|||
// If this fails the world seed will not be consistent across saves
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
World world = new World(seed, 2, dim, this); // create new world with generated seed
|
||||
world.spawnPlayer(); // spawn player in world
|
||||
return world;
|
||||
|
@ -131,11 +121,10 @@ public final class LitecraftSave
|
|||
{
|
||||
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)
|
||||
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
|
||||
|
|
|
@ -16,13 +16,11 @@ import com.github.hydos.ginger.engine.screen.Screen;
|
|||
* YeS
|
||||
*/
|
||||
public class TitleScreen extends Screen
|
||||
{
|
||||
{
|
||||
GUIText buildText;
|
||||
|
||||
Ginger ginger3D;
|
||||
|
||||
TextureButton playButton;
|
||||
|
||||
|
||||
public TitleScreen()
|
||||
{
|
||||
ginger3D = Ginger.getInstance();
|
||||
|
@ -32,18 +30,16 @@ public class TitleScreen extends Screen
|
|||
buildText = ginger3D.registerText("LiteCraft", 3, new Vector2f(0, 0), 1f, true, "PLAYBUTTON");
|
||||
buildText.setBorderWidth(0.5f);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void render() // FIXME: This never gets called!!!
|
||||
{
|
||||
|
||||
}
|
||||
{}
|
||||
|
||||
@Override
|
||||
public void tick()
|
||||
{
|
||||
Vector4i dbg = Litecraft.getInstance().dbgStats;
|
||||
buildText.setText("FPS: "+dbg.x()+" UPS: "+dbg.y+" TPS: "+dbg.z+" Binds: "+dbg.w);
|
||||
buildText.setText("FPS: " + dbg.x() + " UPS: " + dbg.y + " TPS: " + dbg.z + " Binds: " + dbg.w);
|
||||
playButton.update();
|
||||
if (playButton.isClicked())
|
||||
{
|
||||
|
|
|
@ -55,9 +55,7 @@ public class Block
|
|||
}
|
||||
|
||||
public static final Block getBlock(String identifier)
|
||||
{
|
||||
return IDENTIFIER_TO_BLOCK.get(identifier);
|
||||
}
|
||||
{ return IDENTIFIER_TO_BLOCK.get(identifier); }
|
||||
|
||||
private static final Map<String, Block> IDENTIFIER_TO_BLOCK = new HashMap<>();
|
||||
}
|
||||
|
|
|
@ -7,14 +7,11 @@ import com.github.hydos.ginger.engine.elements.objects.RenderObject;
|
|||
|
||||
public class BlockEntity extends RenderObject
|
||||
{
|
||||
|
||||
|
||||
public BlockEntity(Block block, Vector3f position)
|
||||
{
|
||||
super(block.model, position, 0, 0, 0, new Vector3f(1f, 1f, 1f));
|
||||
}
|
||||
|
||||
public void processCulling(Chunk chunk) {
|
||||
{ super(block.model, position, 0, 0, 0, new Vector3f(1f, 1f, 1f)); }
|
||||
|
||||
public void processCulling(Chunk chunk)
|
||||
{
|
||||
Vector3f southNeighbourBlockLocation = this.getPosition();
|
||||
southNeighbourBlockLocation.x--;
|
||||
}
|
||||
|
|
|
@ -12,12 +12,8 @@ public final class OctaveSimplexNoise
|
|||
{
|
||||
this.samplers = new SimplexNoise[octaves];
|
||||
this.clamp = 1D / (1D - (1D / Math.pow(2, octaves)));
|
||||
|
||||
for (int i = 0; i < octaves; ++i)
|
||||
{
|
||||
samplers[i] = new SimplexNoise(rand.nextLong());
|
||||
}
|
||||
|
||||
{ samplers[i] = new SimplexNoise(rand.nextLong()); }
|
||||
this.spread = spread;
|
||||
this.amplitudeLow = amplitudeLow;
|
||||
this.amplitudeHigh = amplitudeHigh;
|
||||
|
@ -27,13 +23,11 @@ public final class OctaveSimplexNoise
|
|||
{
|
||||
double amplFreq = 0.5D;
|
||||
double result = 0;
|
||||
|
||||
for (SimplexNoise sampler : this.samplers)
|
||||
{
|
||||
result += (amplFreq * sampler.sample(x / (amplFreq * this.spread), y / (amplFreq * this.spread)));
|
||||
amplFreq *= 0.5D;
|
||||
}
|
||||
|
||||
result = result * this.clamp;
|
||||
return result > 0 ? result * this.amplitudeHigh : result * this.amplitudeLow;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -5,5 +5,6 @@ import com.github.halotroop.litecraft.types.block.Block;
|
|||
public interface BlockAccess
|
||||
{
|
||||
Block getBlock(int x, int y, int z);
|
||||
|
||||
void setBlock(int x, int y, int z, Block block);
|
||||
}
|
|
@ -22,8 +22,8 @@ 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); }
|
||||
|
||||
private final Block[] blocks = new Block[CHUNK_SIZE*CHUNK_SIZE*CHUNK_SIZE];
|
||||
private BlockEntity[] blockEntities = new BlockEntity[CHUNK_SIZE*CHUNK_SIZE*CHUNK_SIZE];
|
||||
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;
|
||||
|
@ -53,57 +53,46 @@ public class Chunk implements BlockAccess, WorldGenConstants, DataStorage
|
|||
public Block getBlock(int x, int y, int z)
|
||||
{
|
||||
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];
|
||||
{ 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)
|
||||
{
|
||||
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];
|
||||
{ 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)
|
||||
{
|
||||
|
||||
if (render)
|
||||
{
|
||||
if (dirty)
|
||||
{
|
||||
dirty = false;
|
||||
renderedBlocks = new BlockEntity[CHUNK_SIZE*CHUNK_SIZE*CHUNK_SIZE];
|
||||
for(int x = 0; x < CHUNK_SIZE; x++)
|
||||
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++)
|
||||
for (int y = 0; y < CHUNK_SIZE; y++)
|
||||
{
|
||||
for(int z = 0; z < CHUNK_SIZE; z++)
|
||||
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)
|
||||
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;
|
||||
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;
|
||||
}
|
||||
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(renderedBlocks);
|
||||
}
|
||||
}
|
||||
|
@ -120,11 +109,9 @@ public class Chunk implements BlockAccess, WorldGenConstants, DataStorage
|
|||
if (z > MAX_POS)
|
||||
z = MAX_POS;
|
||||
else if (z < 0) z = 0;
|
||||
this.blocks[x*CHUNK_SIZE*CHUNK_SIZE + z*CHUNK_SIZE + y] = block;
|
||||
this.blocks[x * CHUNK_SIZE * CHUNK_SIZE + z * CHUNK_SIZE + y] = block;
|
||||
if (this.render)
|
||||
{
|
||||
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.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;
|
||||
}
|
||||
|
||||
|
@ -138,20 +125,18 @@ public class Chunk implements BlockAccess, WorldGenConstants, DataStorage
|
|||
{
|
||||
for (int z = 0; z < CHUNK_SIZE; ++z)
|
||||
{
|
||||
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));
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (this.render) // else if it has been changed to false
|
||||
{
|
||||
blockEntities = new BlockEntity[CHUNK_SIZE*CHUNK_SIZE*CHUNK_SIZE];
|
||||
}
|
||||
{ blockEntities = new BlockEntity[CHUNK_SIZE * CHUNK_SIZE * CHUNK_SIZE]; }
|
||||
this.render = render;
|
||||
dirty = true;
|
||||
}
|
||||
|
@ -163,9 +148,7 @@ public class Chunk implements BlockAccess, WorldGenConstants, DataStorage
|
|||
public void read(BinaryData data)
|
||||
{
|
||||
Int2ObjectMap<Block> palette = new Int2ObjectArrayMap<>();
|
||||
|
||||
DataSection paletteData = data.get("palette");
|
||||
|
||||
boolean readInt = true; // whether the thing from the palette to be read is int
|
||||
int intIdCache = 0;
|
||||
for (Object o : paletteData)
|
||||
|
@ -181,9 +164,7 @@ public class Chunk implements BlockAccess, WorldGenConstants, DataStorage
|
|||
readInt = true;
|
||||
}
|
||||
}
|
||||
|
||||
DataSection blockData = data.get("block");
|
||||
|
||||
long posHash = 0L; // also the index
|
||||
for (int z = 0; z < CHUNK_SIZE; ++z) // z, y, x order for data saving and loading so we can use incremental pos hashes
|
||||
{
|
||||
|
@ -191,7 +172,7 @@ public class Chunk implements BlockAccess, WorldGenConstants, DataStorage
|
|||
{
|
||||
for (int x = 0; x < CHUNK_SIZE; ++x)
|
||||
{
|
||||
blocks[x*CHUNK_SIZE*CHUNK_SIZE + z*CHUNK_SIZE + y] = palette.get(blockData.readInt((int) posHash));
|
||||
blocks[x * CHUNK_SIZE * CHUNK_SIZE + z * CHUNK_SIZE + y] = palette.get(blockData.readInt((int) posHash));
|
||||
++posHash;
|
||||
}
|
||||
}
|
||||
|
@ -204,36 +185,30 @@ public class Chunk implements BlockAccess, WorldGenConstants, DataStorage
|
|||
public void write(BinaryData data)
|
||||
{
|
||||
Object2IntMap<Block> palette = new Object2IntArrayMap<>(); // block to int id
|
||||
|
||||
DataSection paletteData = new DataSection();
|
||||
DataSection blockData = new DataSection();
|
||||
|
||||
long posHash = 0L;
|
||||
nextId = 0;
|
||||
|
||||
ToIntFunction<Block> nextIdProvider = b -> nextId++;
|
||||
|
||||
for (int z = 0; z < CHUNK_SIZE; ++z) // z, y, x order for data saving and loading so we can use incremental pos hashes
|
||||
{
|
||||
for (int y = 0; y < CHUNK_SIZE; ++y)
|
||||
{
|
||||
for (int x = 0; x < CHUNK_SIZE; ++x)
|
||||
{
|
||||
Block b = blocks[x*CHUNK_SIZE*CHUNK_SIZE + z*CHUNK_SIZE + y];
|
||||
Block b = blocks[x * CHUNK_SIZE * CHUNK_SIZE + z * CHUNK_SIZE + y];
|
||||
blockData.writeInt(palette.computeIntIfAbsent(b, nextIdProvider));
|
||||
++posHash;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
palette.forEach((b, id) -> {
|
||||
palette.forEach((b, id) ->
|
||||
{
|
||||
paletteData.writeInt(id);
|
||||
paletteData.writeString(b.identifier);
|
||||
});
|
||||
|
||||
data.put("palette", paletteData);
|
||||
data.put("block", blockData);
|
||||
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,10 +22,8 @@ public class World implements BlockAccess, WorldGenConstants
|
|||
private final ChunkGenerator chunkGenerator;
|
||||
private final BlockAccess genBlockAccess;
|
||||
private final LitecraftSave save;
|
||||
|
||||
private final long seed;
|
||||
private final int dimension;
|
||||
|
||||
public Player player;
|
||||
|
||||
// This will likely become the main public constructor after we add dynamic chunkloading
|
||||
|
@ -54,42 +52,35 @@ public class World implements BlockAccess, WorldGenConstants
|
|||
public World(long seed, int size, Dimension<?> dim, LitecraftSave save)
|
||||
{
|
||||
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 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)
|
||||
{
|
||||
Chunk chunk = this.chunks.computeIfAbsent(posHash(chunkX, chunkY, chunkZ), pos -> {
|
||||
Chunk chunk = this.chunks.computeIfAbsent(posHash(chunkX, chunkY, chunkZ), pos ->
|
||||
{
|
||||
Chunk readChunk = save.readChunk(chunkX, chunkY, chunkZ, this.dimension);
|
||||
return readChunk == null ? this.chunkGenerator.generateChunk(chunkX, chunkY, chunkZ) : readChunk;
|
||||
});
|
||||
|
||||
if (chunk.isFullyGenerated()) return chunk;
|
||||
|
||||
this.populateChunk(chunkX, chunkY, chunkZ, chunk.chunkStartX, chunk.chunkStartY, chunk.chunkStartZ);
|
||||
chunk.setFullyGenerated(true);
|
||||
return chunk;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether the chunk was unloaded without errors. Will often, but not always, be equal to whether the chunk was already in memory.
|
||||
*/
|
||||
/** @return whether the chunk was unloaded without errors. Will often, but not always, be equal to whether the chunk was already in memory. */
|
||||
public boolean unloadChunk(int chunkX, int chunkY, int chunkZ)
|
||||
{
|
||||
long posHash = posHash(chunkX, chunkY, chunkZ);
|
||||
Chunk chunk = this.chunks.get(posHash);
|
||||
|
||||
// If the chunk is not in memory, it does not need to be unloaded
|
||||
if (chunk == null) return false;
|
||||
|
||||
// Otherwise save the chunk
|
||||
boolean result = this.save.saveChunk(chunk);
|
||||
this.chunks.remove(posHash);
|
||||
|
@ -99,16 +90,11 @@ public class World implements BlockAccess, WorldGenConstants
|
|||
private void populateChunk(int chunkX, int chunkY, int chunkZ, int chunkStartX, int chunkStartY, int chunkStartZ)
|
||||
{
|
||||
Random rand = new Random(this.seed + 5828671L * chunkX + -47245139L * chunkY + 8972357 * (long) chunkZ);
|
||||
|
||||
for (WorldModifier modifier : this.worldModifiers)
|
||||
{
|
||||
modifier.modifyWorld(this.genBlockAccess, rand, chunkStartX, chunkStartY, chunkStartZ);
|
||||
}
|
||||
{ modifier.modifyWorld(this.genBlockAccess, rand, chunkStartX, chunkStartY, chunkStartZ); }
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a chunk that has not neccesarily gone through chunk populating. Used in chunk populating to prevent infinite recursion.
|
||||
*/
|
||||
/** @return a chunk that has not neccesarily gone through chunk populating. Used in chunk populating to prevent infinite recursion. */
|
||||
Chunk getGenChunk(int chunkX, int chunkY, int chunkZ)
|
||||
{ return this.chunks.computeIfAbsent(posHash(chunkX, chunkY, chunkZ), pos -> this.chunkGenerator.generateChunk(chunkX, chunkY, chunkZ)); }
|
||||
|
||||
|
@ -128,14 +114,13 @@ public class World implements BlockAccess, WorldGenConstants
|
|||
|
||||
//used for model combining and culling
|
||||
public Chunk optimiseChunk(Chunk chunk)
|
||||
{
|
||||
return chunk;
|
||||
}
|
||||
{ return chunk; }
|
||||
|
||||
public void render(BlockRenderer blockRenderer)
|
||||
{
|
||||
Chunk chunk = getChunk(0, -1, 0);
|
||||
if(chunk!= null) {
|
||||
if (chunk != null)
|
||||
{
|
||||
blockRenderer.prepareModel(chunk.getBlockEntity(0, 0, 0).getModel());
|
||||
this.chunks.forEach((pos, c) -> c.render(blockRenderer));
|
||||
blockRenderer.unbindModel();
|
||||
|
@ -146,25 +131,21 @@ public class World implements BlockAccess, WorldGenConstants
|
|||
{
|
||||
LongList chunkPositions = new LongArrayList();
|
||||
if (this.chunks != null)
|
||||
this.chunks.forEach((pos, chunk) -> { // for every chunk in memory
|
||||
this.chunks.forEach((pos, chunk) ->
|
||||
{ // for every chunk in memory
|
||||
chunkPositions.add((long) pos); // add pos to chunk positions list for removal later
|
||||
this.save.saveChunk(chunk); // save chunk
|
||||
});
|
||||
|
||||
chunkPositions.forEach((LongConsumer) (pos -> this.chunks.remove(pos))); // remove all chunks
|
||||
}
|
||||
|
||||
public long getSeed()
|
||||
{
|
||||
return this.seed;
|
||||
}
|
||||
{ return this.seed; }
|
||||
|
||||
private static final class GenerationWorld implements BlockAccess, WorldGenConstants
|
||||
{
|
||||
GenerationWorld(World parent)
|
||||
{
|
||||
this.parent = parent;
|
||||
}
|
||||
{ this.parent = parent; }
|
||||
|
||||
public final World parent;
|
||||
|
||||
|
|
|
@ -42,8 +42,9 @@ public class BlockRenderer extends Renderer implements WorldGenConstants
|
|||
GL20.glEnableVertexAttribArray(2);
|
||||
Litecraft.getInstance().binds++;
|
||||
}
|
||||
|
||||
private void prepTexture(ModelTexture texture, int textureID) {
|
||||
|
||||
private void prepTexture(ModelTexture texture, int textureID)
|
||||
{
|
||||
shader.loadFakeLightingVariable(texture.isUseFakeLighting());
|
||||
shader.loadShine(texture.getShineDamper(), texture.getReflectivity());
|
||||
GL13.glActiveTexture(GL13.GL_TEXTURE0);
|
||||
|
@ -59,22 +60,20 @@ public class BlockRenderer extends Renderer implements WorldGenConstants
|
|||
}
|
||||
|
||||
public void render(BlockEntity[] renderList)
|
||||
{
|
||||
{
|
||||
shader.start();
|
||||
shader.loadSkyColour(Window.getColour());
|
||||
shader.loadViewMatrix(GingerRegister.getInstance().game.data.camera);
|
||||
TexturedModel model = renderList[0].getModel();
|
||||
if(GingerRegister.getInstance().wireframe)
|
||||
{
|
||||
GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
|
||||
}
|
||||
for(int x = 0; x < CHUNK_SIZE; x++)
|
||||
if (GingerRegister.getInstance().wireframe)
|
||||
{ GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE); }
|
||||
for (int x = 0; x < CHUNK_SIZE; x++)
|
||||
{
|
||||
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];
|
||||
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());
|
||||
|
@ -84,11 +83,8 @@ public class BlockRenderer extends Renderer implements WorldGenConstants
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(GingerRegister.getInstance().wireframe)
|
||||
{
|
||||
GL11.glPolygonMode( GL11.GL_FRONT_AND_BACK,GL11.GL_FILL);
|
||||
}
|
||||
if (GingerRegister.getInstance().wireframe)
|
||||
{ GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL); }
|
||||
shader.stop();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,9 +21,8 @@ public abstract class Dimension<T extends ChunkGenerator>
|
|||
return this;
|
||||
}
|
||||
|
||||
public WorldModifier[] getWorldModifierArray() {
|
||||
return this.worldModifiers.toArray(WorldModifier[]::new);
|
||||
}
|
||||
public WorldModifier[] getWorldModifierArray()
|
||||
{ return this.worldModifiers.toArray(WorldModifier[]::new); }
|
||||
|
||||
public abstract T createChunkGenerator(long seed);
|
||||
|
||||
|
|
|
@ -21,35 +21,26 @@ public class OverworldChunkGenerator implements ChunkGenerator, WorldGenConstant
|
|||
public Chunk generateChunk(int chunkX, int chunkY, int chunkZ)
|
||||
{
|
||||
Chunk chunk = new Chunk(chunkX, chunkY, chunkZ, this.dimension);
|
||||
|
||||
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, (double) (chunk.chunkStartZ + z));
|
||||
|
||||
int height = (int) this.noise.sample(totalX, chunk.chunkStartZ + z);
|
||||
for (int y = 0; y < CHUNK_SIZE; ++y)
|
||||
{
|
||||
int totalY = chunk.chunkStartY + y;
|
||||
Block block = Blocks.AIR;
|
||||
|
||||
if (totalY < height - 3)
|
||||
{
|
||||
block = Blocks.DIRT;
|
||||
}
|
||||
else if (totalY < height)
|
||||
{
|
||||
block = Blocks.STONE;
|
||||
}
|
||||
|
||||
{ block = Blocks.STONE; }
|
||||
chunk.setBlock(x, y, z, block);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return chunk;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,13 +3,9 @@ package com.github.halotroop.litecraft.world.gen;
|
|||
public class OverworldDimension extends Dimension<OverworldChunkGenerator>
|
||||
{
|
||||
public OverworldDimension(int id)
|
||||
{
|
||||
super(id);
|
||||
}
|
||||
{ super(id); }
|
||||
|
||||
@Override
|
||||
public OverworldChunkGenerator createChunkGenerator(long seed)
|
||||
{
|
||||
return new OverworldChunkGenerator(seed, this.id);
|
||||
}
|
||||
{ return new OverworldChunkGenerator(seed, this.id); }
|
||||
}
|
|
@ -4,6 +4,7 @@ import java.util.Random;
|
|||
|
||||
import com.github.halotroop.litecraft.world.BlockAccess;
|
||||
|
||||
public interface WorldModifier {
|
||||
public interface WorldModifier
|
||||
{
|
||||
void modifyWorld(BlockAccess world, Random rand, int chunkStartX, int chunkStartY, int chunkStartZ);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ import com.github.hydos.ginger.engine.utils.Loader;
|
|||
public class Ginger
|
||||
{
|
||||
private static Ginger INSTANCE;
|
||||
|
||||
public GingerRegister gingerRegister;
|
||||
public MousePicker picker;
|
||||
public FontType globalFont;
|
||||
|
@ -30,11 +29,10 @@ public class Ginger
|
|||
{
|
||||
@Override
|
||||
public void onTick(float deltaTime)
|
||||
{
|
||||
gingerRegister.game.tick();
|
||||
if(gingerRegister.currentScreen != null) {
|
||||
gingerRegister.currentScreen.tick();
|
||||
}
|
||||
{
|
||||
gingerRegister.game.tick();
|
||||
if (gingerRegister.currentScreen != null)
|
||||
{ gingerRegister.currentScreen.tick(); }
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -47,11 +45,9 @@ public class Ginger
|
|||
TextMaster.cleanUp();
|
||||
Loader.cleanUp();
|
||||
}
|
||||
|
||||
|
||||
public void openScreen(Screen screen)
|
||||
{
|
||||
gingerRegister.currentScreen = screen;
|
||||
}
|
||||
{ gingerRegister.currentScreen = screen; }
|
||||
|
||||
public void postRender()
|
||||
{ Window.swapBuffers(); }
|
||||
|
@ -74,9 +70,8 @@ public class Ginger
|
|||
public void renderOverlays(Game game)
|
||||
{
|
||||
gingerRegister.masterRenderer.renderGuis(game.data.guis);
|
||||
if(gingerRegister.currentScreen != null) {
|
||||
gingerRegister.masterRenderer.renderGuis(gingerRegister.currentScreen.elements);
|
||||
}
|
||||
if (gingerRegister.currentScreen != null)
|
||||
{ gingerRegister.masterRenderer.renderGuis(gingerRegister.currentScreen.elements); }
|
||||
TextMaster.render();
|
||||
}
|
||||
|
||||
|
@ -90,7 +85,6 @@ public class Ginger
|
|||
PostProcessing.doPostProcessing(contrastFbo.colorTexture);
|
||||
if (game.data.handleGuis)
|
||||
{ renderOverlays(game); }
|
||||
|
||||
}
|
||||
|
||||
public void setGlobalFont(FontType font)
|
||||
|
@ -133,7 +127,6 @@ public class Ginger
|
|||
ParticleMaster.update(data.camera);
|
||||
}
|
||||
|
||||
public static Ginger getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
public static Ginger getInstance()
|
||||
{ return INSTANCE; }
|
||||
}
|
|
@ -15,20 +15,21 @@ public class GingerRegister
|
|||
{
|
||||
private static GingerRegister INSTANCE;
|
||||
public MasterRenderer masterRenderer;
|
||||
|
||||
public static GingerRegister getInstance()
|
||||
{ return INSTANCE; }
|
||||
|
||||
public GingerThreading threadRegister;
|
||||
public List<GUIText> texts;
|
||||
public List<TextureButton> guiButtons;
|
||||
public List<Fbo> fbos;
|
||||
|
||||
public Game game;
|
||||
public Screen currentScreen;
|
||||
public boolean wireframe = false;
|
||||
|
||||
public GingerRegister()
|
||||
{
|
||||
INSTANCE = this;
|
||||
{
|
||||
INSTANCE = this;
|
||||
threadRegister = new GingerThreading();
|
||||
}
|
||||
|
||||
|
|
|
@ -36,11 +36,9 @@ public class FirstPersonCamera extends Camera
|
|||
@Override
|
||||
public void move()
|
||||
{
|
||||
|
||||
position.x = player.getPosition().x;
|
||||
position.z = player.getPosition().z;
|
||||
position.y = player.getPosition().y;
|
||||
|
||||
roll = player.getRotX();
|
||||
yaw = -player.getRotY() + 180 + Window.getNormalizedMouseCoordinates().x() * 70;
|
||||
pitch = player.getRotZ() + -Window.getNormalizedMouseCoordinates().y() * 70;
|
||||
|
|
|
@ -23,34 +23,28 @@ public class Player extends RenderObject
|
|||
position.z -= Math.cos(ry) * Constants.movementSpeed;
|
||||
position.x += Math.sin(ry) * Constants.movementSpeed;
|
||||
}
|
||||
|
||||
if (Window.isKeyDown(GLFW.GLFW_KEY_A))
|
||||
{
|
||||
position.z -= Math.cos(ry) * Constants.movementSpeed;
|
||||
position.x -= Math.sin(ry) * Constants.movementSpeed;
|
||||
position.x -= Math.sin(ry) * Constants.movementSpeed;
|
||||
}
|
||||
|
||||
if (Window.isKeyDown(GLFW.GLFW_KEY_S))
|
||||
{
|
||||
position.z += Math.cos(ry) * Constants.movementSpeed;
|
||||
position.x -= Math.sin(ry) * Constants.movementSpeed;
|
||||
}
|
||||
|
||||
if (Window.isKeyDown(GLFW.GLFW_KEY_D))
|
||||
{
|
||||
position.z += Math.cos(ry) * Constants.movementSpeed;
|
||||
position.x += Math.sin(ry) * Constants.movementSpeed;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
{ position.y -= Constants.movementSpeed; }
|
||||
}
|
||||
|
||||
private void jump()
|
||||
|
@ -69,6 +63,6 @@ public class Player extends RenderObject
|
|||
upwardsSpeed += Constants.gravity.y() * Window.getTime();
|
||||
isInAir = false;
|
||||
upwardsSpeed = 0;
|
||||
// super.getPosition().y = 0;
|
||||
// super.getPosition().y = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,18 +21,15 @@ public class RenderObject
|
|||
this.rotZ = rotZ;
|
||||
this.scale = scale;
|
||||
}
|
||||
|
||||
public void x(float x) {
|
||||
this.position.x = x;
|
||||
}
|
||||
|
||||
public void y(float y) {
|
||||
this.position.y = y;
|
||||
}
|
||||
|
||||
public void z(float z) {
|
||||
this.position.z = z;
|
||||
}
|
||||
|
||||
public void x(float x)
|
||||
{ this.position.x = x; }
|
||||
|
||||
public void y(float y)
|
||||
{ this.position.y = y; }
|
||||
|
||||
public void z(float z)
|
||||
{ this.position.z = z; }
|
||||
|
||||
public TexturedModel getModel()
|
||||
{ return model; }
|
||||
|
|
|
@ -43,7 +43,7 @@ public class TextMaster
|
|||
public static void render()
|
||||
{ renderer.render(texts); }
|
||||
|
||||
public static void render(GUIText buildText)
|
||||
public static void render(GUIText buildText)
|
||||
{
|
||||
Map<FontType, List<GUIText>> oldTexts = texts;
|
||||
List<GUIText> oldFontText = texts.get(Ginger.getInstance().globalFont);
|
||||
|
|
|
@ -6,6 +6,7 @@ public class TextMeshCreator
|
|||
{
|
||||
protected static final double LINE_HEIGHT = 0.03f;
|
||||
protected static final int SPACE_ASCII = 32;
|
||||
|
||||
private static void addTexCoords(List<Float> texCoords, double x, double y, double maxX, double maxY)
|
||||
{
|
||||
texCoords.add((float) x);
|
||||
|
|
|
@ -192,8 +192,5 @@ public class Window
|
|||
}
|
||||
|
||||
public static void fullscreen()
|
||||
{
|
||||
Window.fullscreen = !Window.isFullscreen();
|
||||
|
||||
}
|
||||
{ Window.fullscreen = !Window.isFullscreen(); }
|
||||
}
|
||||
|
|
|
@ -17,6 +17,6 @@ public class ModelLoader
|
|||
public static TexturedModel loadModel(String objPath, String texturePath)
|
||||
{
|
||||
Mesh data = OBJFileLoader.loadModel(objPath);
|
||||
return new TexturedModel(Loader.loadToVAO(data.getVertices(), data.getIndices(),data.getNormals(), data.getTextureCoords()), new ModelTexture(texturePath));
|
||||
return new TexturedModel(Loader.loadToVAO(data.getVertices(), data.getIndices(), data.getNormals(), data.getTextureCoords()), new ModelTexture(texturePath));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ public class OBJFileLoader
|
|||
if (mesh.mNumUVComponents().get(0) != 0)
|
||||
{
|
||||
AIVector3D texture = mesh.mTextureCoords(0).get(i);
|
||||
meshTextureCoord.set(texture.x(),texture.y());
|
||||
meshTextureCoord.set(texture.x(), texture.y());
|
||||
}
|
||||
vertexList[i] = new Vertex(meshVertex, meshNormal, meshTextureCoord);
|
||||
}
|
||||
|
|
|
@ -7,44 +7,32 @@ public class StaticCube
|
|||
//@formatter:off
|
||||
public static float[] vertices =
|
||||
{
|
||||
|
||||
//North (back) face
|
||||
-0.5f, 0.5f, -0.5f,
|
||||
-0.5f, -0.5f, -0.5f,
|
||||
0.5f, -0.5f, -0.5f,
|
||||
0.5f, 0.5f, -0.5f,
|
||||
|
||||
|
||||
//South (front) face
|
||||
-0.5f, 0.5f, 0.5f,
|
||||
-0.5f, -0.5f, 0.5f,
|
||||
0.5f, -0.5f, 0.5f,
|
||||
0.5f, 0.5f, 0.5f,
|
||||
|
||||
|
||||
|
||||
0.5f, 0.5f, -0.5f,
|
||||
0.5f, -0.5f, -0.5f,
|
||||
0.5f, -0.5f, 0.5f,
|
||||
0.5f, 0.5f, 0.5f,
|
||||
|
||||
|
||||
|
||||
-0.5f, 0.5f, -0.5f,
|
||||
-0.5f, -0.5f, -0.5f,
|
||||
-0.5f, -0.5f, 0.5f,
|
||||
-0.5f, 0.5f, 0.5f,
|
||||
|
||||
//Top face
|
||||
-0.5f, 0.5f, 0.5f,
|
||||
-0.5f, 0.5f, -0.5f,
|
||||
0.5f, 0.5f, -0.5f,
|
||||
0.5f, 0.5f, 0.5f,
|
||||
|
||||
|
||||
//Bottom face
|
||||
-0.5f, -0.5f, 0.5f,
|
||||
-0.5f, -0.5f, -0.5f,
|
||||
-0.5f, -0.5f, -0.5f,
|
||||
0.5f, -0.5f, -0.5f,
|
||||
0.5f, -0.5f, 0.5f
|
||||
};
|
||||
|
@ -77,44 +65,33 @@ public class StaticCube
|
|||
};
|
||||
public static int[] indices =
|
||||
{
|
||||
0, 1, 3,
|
||||
3, 1, 2,
|
||||
|
||||
4, 5, 7,
|
||||
7, 5, 6,
|
||||
|
||||
8, 9, 11,
|
||||
11, 9, 10,
|
||||
|
||||
12, 13, 15,
|
||||
15, 13, 14,
|
||||
|
||||
16, 17, 19,
|
||||
19, 17, 18,
|
||||
|
||||
20, 21, 23,
|
||||
23, 21, 22
|
||||
|
||||
0, 1, 3,
|
||||
3, 1, 2,
|
||||
4, 5, 7,
|
||||
7, 5, 6,
|
||||
8, 9, 11,
|
||||
11, 9, 10,
|
||||
12, 13, 15,
|
||||
15, 13, 14,
|
||||
16, 17, 19,
|
||||
19, 17, 18,
|
||||
20, 21, 23,
|
||||
23, 21, 22
|
||||
};
|
||||
//@formatter:on
|
||||
|
||||
private static Mesh mesh = null;
|
||||
|
||||
public static Mesh getCube()
|
||||
public static Mesh getCube()
|
||||
{
|
||||
if (mesh == null)
|
||||
{
|
||||
mesh = new Mesh(vertices, textureCoords, new float[vertices.length], indices, vertices.length);
|
||||
}
|
||||
if (mesh == null)
|
||||
{ mesh = new Mesh(vertices, textureCoords, new float[vertices.length], indices, vertices.length); }
|
||||
return mesh;
|
||||
}
|
||||
|
||||
public static void scaleCube(float multiplier)
|
||||
public static void scaleCube(float multiplier)
|
||||
{
|
||||
for (int i = 0; i < vertices.length; i++)
|
||||
{
|
||||
vertices[i] = vertices[i] * multiplier;
|
||||
}
|
||||
{ vertices[i] = vertices[i] * multiplier; }
|
||||
mesh = new Mesh(vertices, textureCoords, new float[vertices.length], indices, vertices.length);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,13 +32,13 @@ public class ParticleSystem
|
|||
{ direction.z *= -1; }
|
||||
return new Vector3f(direction.x, direction.y, direction.z);
|
||||
}
|
||||
|
||||
private float pps, averageSpeed, gravityComplient, averageLifeLength, averageScale;
|
||||
private float speedError, lifeError, scaleError = 0;
|
||||
private boolean randomRotation = false;
|
||||
private Vector3f direction;
|
||||
private float directionDeviation = 0;
|
||||
private ParticleTexture texture;
|
||||
|
||||
private Random random = new Random();
|
||||
|
||||
public ParticleSystem(ParticleTexture texture, float pps, float speed, float gravityComplient, float lifeLength, float scale)
|
||||
|
|
|
@ -22,15 +22,16 @@ public class MasterRenderer
|
|||
public static final float FOV = 80f;
|
||||
public static final float NEAR_PLANE = 0.1f;
|
||||
private static final float FAR_PLANE = 1000f;
|
||||
|
||||
public static void disableCulling()
|
||||
{ GL11.glDisable(GL11.GL_CULL_FACE); }
|
||||
|
||||
|
||||
public static void enableCulling()
|
||||
{
|
||||
// GL11.glEnable(GL11.GL_CULL_FACE);
|
||||
// GL11.glCullFace(GL11.GL_BACK);
|
||||
// GL11.glEnable(GL11.GL_CULL_FACE);
|
||||
// GL11.glCullFace(GL11.GL_BACK);
|
||||
}
|
||||
|
||||
|
||||
public BlockRenderer blockRenderer;
|
||||
private StaticShader entityShader;
|
||||
public ObjectRenderer entityRenderer;
|
||||
|
@ -40,9 +41,7 @@ public class MasterRenderer
|
|||
private NormalMappingRenderer normalRenderer;
|
||||
private Matrix4f projectionMatrix;
|
||||
private ShadowMapMasterRenderer shadowMapRenderer;
|
||||
|
||||
private Map<TexturedModel, List<RenderObject>> entities = new HashMap<TexturedModel, List<RenderObject>>();
|
||||
|
||||
private Map<TexturedModel, List<RenderObject>> normalMapEntities = new HashMap<TexturedModel, List<RenderObject>>();
|
||||
|
||||
public MasterRenderer(Camera camera)
|
||||
|
@ -75,7 +74,7 @@ public class MasterRenderer
|
|||
float frustum_length = FAR_PLANE - NEAR_PLANE;
|
||||
projectionMatrix._m00(x_scale);
|
||||
projectionMatrix._m11(y_scale);
|
||||
projectionMatrix._m22 (-((FAR_PLANE + NEAR_PLANE) / frustum_length));
|
||||
projectionMatrix._m22(-((FAR_PLANE + NEAR_PLANE) / frustum_length));
|
||||
projectionMatrix._m23(-1);
|
||||
projectionMatrix._m32(-((2 * NEAR_PLANE * FAR_PLANE) / frustum_length));
|
||||
projectionMatrix._m33(0);
|
||||
|
|
|
@ -66,11 +66,11 @@ public class ObjectRenderer extends Renderer
|
|||
List<RenderObject> batch = entities.get(model);
|
||||
for (RenderObject entity : batch)
|
||||
{
|
||||
if(entity.isVisible) {
|
||||
if (entity.isVisible)
|
||||
{
|
||||
prepareInstance(entity);
|
||||
GL11.glDrawElements(GL11.GL_TRIANGLES, model.getRawModel().getVertexCount(), GL11.GL_UNSIGNED_INT, 0);
|
||||
}
|
||||
|
||||
}
|
||||
unbindTexturedModel();
|
||||
}
|
||||
|
@ -85,14 +85,15 @@ public class ObjectRenderer extends Renderer
|
|||
}
|
||||
|
||||
public void render(List<BlockEntity> renderList)
|
||||
{
|
||||
{
|
||||
prepare();
|
||||
shader.start();
|
||||
shader.loadSkyColour(Window.getColour());
|
||||
shader.loadViewMatrix(GingerRegister.getInstance().game.data.camera);
|
||||
for (RenderObject entity : renderList)
|
||||
{
|
||||
if (entity != null && entity.getModel() != null) {
|
||||
if (entity != null && entity.getModel() != null)
|
||||
{
|
||||
TexturedModel model = entity.getModel();
|
||||
prepareTexturedModel(model);
|
||||
prepareInstance(entity);
|
||||
|
@ -102,5 +103,4 @@ public class ObjectRenderer extends Renderer
|
|||
}
|
||||
shader.stop();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -34,9 +34,9 @@ public abstract class ShaderProgram
|
|||
}
|
||||
return shaderID;
|
||||
}
|
||||
|
||||
private int programID;
|
||||
private int vertexShaderID;
|
||||
|
||||
private int fragmentShaderID;
|
||||
|
||||
public ShaderProgram(String vertexFile, String fragmentFile)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.github.hydos.ginger.engine.render.texture;
|
||||
|
||||
public enum ColorDepth {
|
||||
R,RG,RGB,RGBA
|
||||
public enum ColorDepth
|
||||
{
|
||||
R, RG, RGB, RGBA
|
||||
}
|
||||
|
|
|
@ -39,9 +39,7 @@ public class Image
|
|||
}
|
||||
|
||||
private ByteBuffer image;
|
||||
|
||||
private int width, height;
|
||||
|
||||
private IntBuffer comp;
|
||||
|
||||
Image(int width, int heigh, ByteBuffer image, IntBuffer comp)
|
||||
|
@ -86,13 +84,13 @@ public class Image
|
|||
|
||||
public int getHeight()
|
||||
{ return height; }
|
||||
|
||||
public ByteBuffer getImage()
|
||||
{ return image; }
|
||||
|
||||
public int getWidth()
|
||||
{ return width; }
|
||||
|
||||
public IntBuffer getComp() {
|
||||
return comp;
|
||||
}
|
||||
public IntBuffer getComp()
|
||||
{ return comp; }
|
||||
}
|
|
@ -27,9 +27,7 @@ public class MousePicker
|
|||
{
|
||||
float half = start + ((finish - start) / 2f);
|
||||
if (count >= RECURSION_COUNT)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
{ return null; }
|
||||
if (intersectionInRange(start, half, ray))
|
||||
{
|
||||
return binarySearch(count + 1, start, half, ray);
|
||||
|
@ -88,9 +86,7 @@ public class MousePicker
|
|||
}
|
||||
|
||||
private boolean isUnderGround(Vector3f testPoint)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
{ return false; }
|
||||
|
||||
private Vector4f toEyeCoords(Vector4f clipCoords)
|
||||
{
|
||||
|
|
|
@ -6,9 +6,9 @@ import com.github.hydos.ginger.engine.elements.GuiTexture;
|
|||
|
||||
public abstract class Screen
|
||||
{
|
||||
|
||||
public List<GuiTexture> elements;
|
||||
|
||||
public abstract void render();
|
||||
|
||||
public abstract void tick();
|
||||
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ public class ShadowFrameBuffer
|
|||
GL30.glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, frameBuffer);
|
||||
GL11.glViewport(0, 0, width, height);
|
||||
}
|
||||
|
||||
/** Creates a depth buffer texture attachment.
|
||||
*
|
||||
* @param width
|
||||
|
@ -45,6 +46,7 @@ public class ShadowFrameBuffer
|
|||
GL32.glFramebufferTexture(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, texture, 0);
|
||||
return texture;
|
||||
}
|
||||
|
||||
/** Creates a frame buffer and binds it so that attachments can be added to
|
||||
* it. The draw buffer is set to none, indicating that there's no colour
|
||||
* buffer to be rendered to.
|
||||
|
@ -58,12 +60,10 @@ public class ShadowFrameBuffer
|
|||
GL11.glReadBuffer(GL11.GL_NONE);
|
||||
return frameBuffer;
|
||||
}
|
||||
|
||||
private final int WIDTH;
|
||||
|
||||
private final int HEIGHT;
|
||||
|
||||
private int fbo;
|
||||
|
||||
private int shadowMap;
|
||||
|
||||
/** Initialises the frame buffer and shadow map of a certain size.
|
||||
|
|
|
@ -17,6 +17,7 @@ import com.github.hydos.ginger.engine.render.models.TexturedModel;
|
|||
public class ShadowMapMasterRenderer
|
||||
{
|
||||
private static final int SHADOW_MAP_SIZE = 5120 * 2;
|
||||
|
||||
/** Create the offset for part of the conversion to shadow map space. This
|
||||
* conversion is necessary to convert from one coordinate system to the
|
||||
* coordinate system that we can use to sample to shadow map.
|
||||
|
@ -29,6 +30,7 @@ public class ShadowMapMasterRenderer
|
|||
offset.scale(new Vector3f(0.5f, 0.5f, 0.5f));
|
||||
return offset;
|
||||
}
|
||||
|
||||
private ShadowFrameBuffer shadowFbo;
|
||||
private ShadowShader shader;
|
||||
private ShadowBox shadowBox;
|
||||
|
@ -36,7 +38,6 @@ public class ShadowMapMasterRenderer
|
|||
private Matrix4f lightViewMatrix = new Matrix4f();
|
||||
private Matrix4f projectionViewMatrix = new Matrix4f();
|
||||
private Matrix4f offset = createOffset();
|
||||
|
||||
private ShadowMapEntityRenderer entityRenderer;
|
||||
|
||||
/** Creates instances of the important objects needed for rendering the scene
|
||||
|
|
|
@ -96,9 +96,7 @@ public class Loader
|
|||
{ return new TerrainTexture(new ModelTexture("terrain/" + string).getTextureID()); }
|
||||
|
||||
public static int loadTexture(String path)
|
||||
{
|
||||
return loadTextureDirectly("/textures/" + path);
|
||||
}
|
||||
{ return loadTextureDirectly("/textures/" + path); }
|
||||
|
||||
public static int loadTextureDirectly(String path)
|
||||
{
|
||||
|
@ -107,9 +105,12 @@ public class Loader
|
|||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);
|
||||
GL11.glTexParameterf(GL11.GL_TEXTURE_2D, 10241, 9729.0f);
|
||||
GL11.glTexParameterf(GL11.GL_TEXTURE_2D, 10240, 9729.0f);
|
||||
if(texture.getComp().get() == 3) {
|
||||
if (texture.getComp().get() == 3)
|
||||
{
|
||||
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, texture.getWidth(), texture.getHeight(), 0, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, texture.getImage());
|
||||
}else {
|
||||
}
|
||||
else
|
||||
{
|
||||
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, texture.getWidth(), texture.getHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, texture.getImage());
|
||||
}
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
|
||||
|
|
|
@ -5,7 +5,7 @@ import org.joml.Vector3f;
|
|||
public class Constants
|
||||
{
|
||||
//player variables
|
||||
public static Vector3f gravity = new Vector3f(0,0,0);
|
||||
public static Vector3f gravity = new Vector3f(0, 0, 0);
|
||||
public static float jumpPower = 0;
|
||||
public static float turnSpeed = 0;
|
||||
public static double movementSpeed = 1;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
package com.github.hydos.ginger.voxelUtils;
|
||||
|
||||
public class BlockMesher {
|
||||
|
||||
public class BlockMesher
|
||||
{
|
||||
}
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package com.github.hydos.multiThreading;
|
||||
|
||||
public abstract class GingerThread extends Thread{
|
||||
|
||||
public abstract class GingerThread extends Thread
|
||||
{
|
||||
public boolean isRunning;
|
||||
|
||||
public String threadName;
|
||||
|
||||
}
|
||||
|
|
|
@ -2,16 +2,13 @@ package com.github.hydos.multiThreading;
|
|||
|
||||
import java.util.*;
|
||||
|
||||
public class GingerThreading {
|
||||
|
||||
public class GingerThreading
|
||||
{
|
||||
public List<GingerThread> threads;
|
||||
|
||||
public GingerThreading() {
|
||||
threads = new ArrayList<GingerThread>();
|
||||
}
|
||||
|
||||
public void registerThread(GingerThread thread) {
|
||||
threads.add(thread);
|
||||
}
|
||||
|
||||
|
||||
public GingerThreading()
|
||||
{ threads = new ArrayList<GingerThread>(); }
|
||||
|
||||
public void registerThread(GingerThread thread)
|
||||
{ threads.add(thread); }
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@ package tk.valoeghese.gateways.client.io;
|
|||
public final class InitialPressHandler implements KeyListener
|
||||
{
|
||||
private boolean activatedPreviously = false;
|
||||
|
||||
private final KeyCallback callback;
|
||||
|
||||
public InitialPressHandler(KeyCallback callback)
|
||||
{ this.callback = callback; }
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ import org.lwjgl.glfw.*;
|
|||
public class KeyCallbackHandler extends GLFWKeyCallback
|
||||
{
|
||||
private static final KeyCallbackHandler INSTANCE = new KeyCallbackHandler();
|
||||
|
||||
public static boolean[] keys = new boolean[GLFW.GLFW_KEY_LAST];
|
||||
|
||||
public static void trackWindow(long window)
|
||||
|
|
|
@ -8,7 +8,6 @@ import org.lwjgl.glfw.*;
|
|||
public class MouseCallbackHandler extends GLFWMouseButtonCallback
|
||||
{
|
||||
private static final MouseCallbackHandler INSTANCE = new MouseCallbackHandler();
|
||||
|
||||
public static boolean[] buttons = new boolean[GLFW.GLFW_MOUSE_BUTTON_LAST];
|
||||
|
||||
public static void trackWindow(long window)
|
||||
|
|
|
@ -28,11 +28,8 @@ public class DataSection implements Iterable<Object>
|
|||
public <T extends Enum<?>> T readEnum(int index, T[] values)
|
||||
{
|
||||
Integer i = (Integer) this.data.get(index);
|
||||
|
||||
if (i == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (i == null)
|
||||
{ return null; }
|
||||
return values[i];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue