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