diff --git a/src/main/java/com/github/halotroop/litecraft/Litecraft.java b/src/main/java/com/github/halotroop/litecraft/Litecraft.java index 9e02a91..9721160 100644 --- a/src/main/java/com/github/halotroop/litecraft/Litecraft.java +++ b/src/main/java/com/github/halotroop/litecraft/Litecraft.java @@ -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); - } + } } } \ No newline at end of file diff --git a/src/main/java/com/github/halotroop/litecraft/logic/DataStorage.java b/src/main/java/com/github/halotroop/litecraft/logic/DataStorage.java index 2ae4f38..b58c192 100644 --- a/src/main/java/com/github/halotroop/litecraft/logic/DataStorage.java +++ b/src/main/java/com/github/halotroop/litecraft/logic/DataStorage.java @@ -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); } diff --git a/src/main/java/com/github/halotroop/litecraft/logic/Timer.java b/src/main/java/com/github/halotroop/litecraft/logic/Timer.java index 4cdd587..75be1d2 100644 --- a/src/main/java/com/github/halotroop/litecraft/logic/Timer.java +++ b/src/main/java/com/github/halotroop/litecraft/logic/Timer.java @@ -12,10 +12,10 @@ public class Timer { void onTick(float deltaTime); } + private double lastTick; private double nextTick; private int tickRate; - private Set tickListeners = new HashSet<>(); public Timer(int tickRate) diff --git a/src/main/java/com/github/halotroop/litecraft/save/LitecraftSave.java b/src/main/java/com/github/halotroop/litecraft/save/LitecraftSave.java index b901e55..2359cc8 100644 --- a/src/main/java/com/github/halotroop/litecraft/save/LitecraftSave.java +++ b/src/main/java/com/github/halotroop/litecraft/save/LitecraftSave.java @@ -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: ////.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: ////.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 diff --git a/src/main/java/com/github/halotroop/litecraft/screens/TitleScreen.java b/src/main/java/com/github/halotroop/litecraft/screens/TitleScreen.java index 78ae3ce..1bec389 100644 --- a/src/main/java/com/github/halotroop/litecraft/screens/TitleScreen.java +++ b/src/main/java/com/github/halotroop/litecraft/screens/TitleScreen.java @@ -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()) { diff --git a/src/main/java/com/github/halotroop/litecraft/types/block/Block.java b/src/main/java/com/github/halotroop/litecraft/types/block/Block.java index 7c4ebb6..62f9376 100644 --- a/src/main/java/com/github/halotroop/litecraft/types/block/Block.java +++ b/src/main/java/com/github/halotroop/litecraft/types/block/Block.java @@ -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 IDENTIFIER_TO_BLOCK = new HashMap<>(); } diff --git a/src/main/java/com/github/halotroop/litecraft/types/block/BlockEntity.java b/src/main/java/com/github/halotroop/litecraft/types/block/BlockEntity.java index ec91ade..1bf2d42 100644 --- a/src/main/java/com/github/halotroop/litecraft/types/block/BlockEntity.java +++ b/src/main/java/com/github/halotroop/litecraft/types/block/BlockEntity.java @@ -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--; } diff --git a/src/main/java/com/github/halotroop/litecraft/util/noise/OctaveSimplexNoise.java b/src/main/java/com/github/halotroop/litecraft/util/noise/OctaveSimplexNoise.java index c37f500..8ed977a 100644 --- a/src/main/java/com/github/halotroop/litecraft/util/noise/OctaveSimplexNoise.java +++ b/src/main/java/com/github/halotroop/litecraft/util/noise/OctaveSimplexNoise.java @@ -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; } diff --git a/src/main/java/com/github/halotroop/litecraft/util/noise/SimplexNoise.java b/src/main/java/com/github/halotroop/litecraft/util/noise/SimplexNoise.java index 212c9b1..46b9e77 100644 --- a/src/main/java/com/github/halotroop/litecraft/util/noise/SimplexNoise.java +++ b/src/main/java/com/github/halotroop/litecraft/util/noise/SimplexNoise.java @@ -15,51 +15,51 @@ package com.github.halotroop.litecraft.util.noise; * of any particular randomization library, so results * will be the same when ported to other languages. */ -public class SimplexNoise { - private static final double STRETCH_CONSTANT_2D = -0.211324865405187; //(1/Math.sqrt(2+1)-1)/2; - private static final double SQUISH_CONSTANT_2D = 0.366025403784439; //(Math.sqrt(2+1)-1)/2; - private static final double STRETCH_CONSTANT_3D = -1.0 / 6; //(1/Math.sqrt(3+1)-1)/3; - private static final double SQUISH_CONSTANT_3D = 1.0 / 3; //(Math.sqrt(3+1)-1)/3; - +public class SimplexNoise +{ + private static final double STRETCH_CONSTANT_2D = -0.211324865405187; //(1/Math.sqrt(2+1)-1)/2; + private static final double SQUISH_CONSTANT_2D = 0.366025403784439; //(Math.sqrt(2+1)-1)/2; + private static final double STRETCH_CONSTANT_3D = -1.0 / 6; //(1/Math.sqrt(3+1)-1)/3; + private static final double SQUISH_CONSTANT_3D = 1.0 / 3; //(Math.sqrt(3+1)-1)/3; private static final double NORM_CONSTANT_2D = 47; private static final double NORM_CONSTANT_3D = 103; - private static final long DEFAULT_SEED = 0; //Gradients for 2D. They approximate the directions to the //vertices of an octagon from the center. - private static byte[] gradients2D = new byte[]{ - 5, 2, 2, 5, - -5, 2, -2, 5, - 5, -2, 2, -5, - -5, -2, -2, -5, + private static byte[] gradients2D = new byte[] + { + 5, 2, 2, 5, + -5, 2, -2, 5, + 5, -2, 2, -5, + -5, -2, -2, -5, }; - //Gradients for 3D. They approximate the directions to the //vertices of a rhombicuboctahedron from the center, skewed so //that the triangular and square facets can be inscribed inside //circles of the same radius. - private static byte[] gradients3D = new byte[]{ - -11, 4, 4, -4, 11, 4, -4, 4, 11, - 11, 4, 4, 4, 11, 4, 4, 4, 11, - -11, -4, 4, -4, -11, 4, -4, -4, 11, - 11, -4, 4, 4, -11, 4, 4, -4, 11, - -11, 4, -4, -4, 11, -4, -4, 4, -11, - 11, 4, -4, 4, 11, -4, 4, 4, -11, - -11, -4, -4, -4, -11, -4, -4, -4, -11, - 11, -4, -4, 4, -11, -4, 4, -4, -11, + private static byte[] gradients3D = new byte[] + { + -11, 4, 4, -4, 11, 4, -4, 4, 11, + 11, 4, 4, 4, 11, 4, 4, 4, 11, + -11, -4, 4, -4, -11, 4, -4, -4, 11, + 11, -4, 4, 4, -11, 4, 4, -4, 11, + -11, 4, -4, -4, 11, -4, -4, 4, -11, + 11, 4, -4, 4, 11, -4, 4, 4, -11, + -11, -4, -4, -4, -11, -4, -4, -4, -11, + 11, -4, -4, 4, -11, -4, 4, -4, -11, }; private short[] perm; private short[] permGradIndex3D; private long seed = -1L; - public SimplexNoise() { - this(DEFAULT_SEED); - } + public SimplexNoise() + { this(DEFAULT_SEED); } //Initializes the class using a permutation array generated from a 64-bit seed. //Generates a proper permutation (i.e. doesn't merely perform N successive pair swaps on a base array) //Uses a simple 64-bit LCG. - public SimplexNoise(long seed) { + public SimplexNoise(long seed) + { this.seed = seed; perm = new short[256]; permGradIndex3D = new short[256]; @@ -69,7 +69,8 @@ public class SimplexNoise { seed = seed * 6364136223846793005L + 1442695040888963407L; seed = seed * 6364136223846793005L + 1442695040888963407L; seed = seed * 6364136223846793005L + 1442695040888963407L; - for (int i = 255; i >= 0; i--) { + for (int i = 255; i >= 0; i--) + { seed = seed * 6364136223846793005L + 1442695040888963407L; int r = (int) ((seed + 31) % (i + 1)); if (r < 0) @@ -78,109 +79,112 @@ public class SimplexNoise { permGradIndex3D[i] = (short) ((perm[i] % (gradients3D.length / 3)) * 3); source[r] = source[i]; } - - } - private static int fastFloor(double x) { + private static int fastFloor(double x) + { int xi = (int) x; return x < xi ? xi - 1 : xi; } - /** - * Function added to noise by Valoeghese to get seed. - */ - public long getSeed() { - return this.seed; - } + /** Function added to noise by Valoeghese to get seed. */ + public long getSeed() + { return this.seed; } //2D OpenSimplex Noise. - public double sample(double x, double y) { - + public double sample(double x, double y) + { //Place input coordinates onto grid. double stretchOffset = (x + y) * STRETCH_CONSTANT_2D; double xs = x + stretchOffset; double ys = y + stretchOffset; - //Floor to get grid coordinates of rhombus (stretched square) super-cell origin. int xsb = (int) Math.floor(xs); int ysb = (int) Math.floor(ys); - //Skew out to get actual coordinates of rhombus origin. We'll need these later. double squishOffset = (xsb + ysb) * SQUISH_CONSTANT_2D; double xb = xsb + squishOffset; double yb = ysb + squishOffset; - //Compute grid coordinates relative to rhombus origin. double xins = xs - xsb; double yins = ys - ysb; - //Sum those together to get a value that determines which region we're in. double inSum = xins + yins; - //Positions relative to origin point. double dx0 = x - xb; double dy0 = y - yb; - //We'll be defining these inside the next block and using them afterwards. double dx_ext, dy_ext; int xsv_ext, ysv_ext; - double value = 0; - //Contribution (1,0) double dx1 = dx0 - 1 - SQUISH_CONSTANT_2D; double dy1 = dy0 - 0 - SQUISH_CONSTANT_2D; double attn1 = 2 - dx1 * dx1 - dy1 * dy1; - if (attn1 > 0) { + if (attn1 > 0) + { attn1 *= attn1; value += attn1 * attn1 * extrapolate(xsb + 1, ysb + 0, dx1, dy1); } - //Contribution (0,1) double dx2 = dx0 - 0 - SQUISH_CONSTANT_2D; double dy2 = dy0 - 1 - SQUISH_CONSTANT_2D; double attn2 = 2 - dx2 * dx2 - dy2 * dy2; - if (attn2 > 0) { + if (attn2 > 0) + { attn2 *= attn2; value += attn2 * attn2 * extrapolate(xsb + 0, ysb + 1, dx2, dy2); } - - if (inSum <= 1) { //We're inside the triangle (2-Simplex) at (0,0) + if (inSum <= 1) + { //We're inside the triangle (2-Simplex) at (0,0) double zins = 1 - inSum; - if (zins > xins || zins > yins) { //(0,0) is one of the closest two triangular vertices - if (xins > yins) { + if (zins > xins || zins > yins) + { //(0,0) is one of the closest two triangular vertices + if (xins > yins) + { xsv_ext = xsb + 1; ysv_ext = ysb - 1; dx_ext = dx0 - 1; dy_ext = dy0 + 1; - } else { + } + else + { xsv_ext = xsb - 1; ysv_ext = ysb + 1; dx_ext = dx0 + 1; dy_ext = dy0 - 1; } - } else { //(1,0) and (0,1) are the closest two vertices. + } + else + { //(1,0) and (0,1) are the closest two vertices. xsv_ext = xsb + 1; ysv_ext = ysb + 1; dx_ext = dx0 - 1 - 2 * SQUISH_CONSTANT_2D; dy_ext = dy0 - 1 - 2 * SQUISH_CONSTANT_2D; } - } else { //We're inside the triangle (2-Simplex) at (1,1) + } + else + { //We're inside the triangle (2-Simplex) at (1,1) double zins = 2 - inSum; - if (zins < xins || zins < yins) { //(0,0) is one of the closest two triangular vertices - if (xins > yins) { + if (zins < xins || zins < yins) + { //(0,0) is one of the closest two triangular vertices + if (xins > yins) + { xsv_ext = xsb + 2; ysv_ext = ysb + 0; dx_ext = dx0 - 2 - 2 * SQUISH_CONSTANT_2D; dy_ext = dy0 + 0 - 2 * SQUISH_CONSTANT_2D; - } else { + } + else + { xsv_ext = xsb + 0; ysv_ext = ysb + 2; dx_ext = dx0 + 0 - 2 * SQUISH_CONSTANT_2D; dy_ext = dy0 - 2 - 2 * SQUISH_CONSTANT_2D; } - } else { //(1,0) and (0,1) are the closest two vertices. + } + else + { //(1,0) and (0,1) are the closest two vertices. dx_ext = dx0; dy_ext = dy0; xsv_ext = xsb; @@ -191,385 +195,432 @@ public class SimplexNoise { dx0 = dx0 - 1 - 2 * SQUISH_CONSTANT_2D; dy0 = dy0 - 1 - 2 * SQUISH_CONSTANT_2D; } - //Contribution (0,0) or (1,1) double attn0 = 2 - dx0 * dx0 - dy0 * dy0; - if (attn0 > 0) { + if (attn0 > 0) + { attn0 *= attn0; value += attn0 * attn0 * extrapolate(xsb, ysb, dx0, dy0); } - //Extra Vertex double attn_ext = 2 - dx_ext * dx_ext - dy_ext * dy_ext; - if (attn_ext > 0) { + if (attn_ext > 0) + { attn_ext *= attn_ext; value += attn_ext * attn_ext * extrapolate(xsv_ext, ysv_ext, dx_ext, dy_ext); } - return value / NORM_CONSTANT_2D; } //3D OpenSimplex Noise. - public double sample(double x, double y, double z) { - + public double sample(double x, double y, double z) + { //Place input coordinates on simplectic honeycomb. double stretchOffset = (x + y + z) * STRETCH_CONSTANT_3D; double xs = x + stretchOffset; double ys = y + stretchOffset; double zs = z + stretchOffset; - //Floor to get simplectic honeycomb coordinates of rhombohedron (stretched cube) super-cell origin. int xsb = fastFloor(xs); int ysb = fastFloor(ys); int zsb = fastFloor(zs); - //Skew out to get actual coordinates of rhombohedron origin. We'll need these later. double squishOffset = (xsb + ysb + zsb) * SQUISH_CONSTANT_3D; double xb = xsb + squishOffset; double yb = ysb + squishOffset; double zb = zsb + squishOffset; - //Compute simplectic honeycomb coordinates relative to rhombohedral origin. double xins = xs - xsb; double yins = ys - ysb; double zins = zs - zsb; - //Sum those together to get a value that determines which region we're in. double inSum = xins + yins + zins; - //Positions relative to origin point. double dx0 = x - xb; double dy0 = y - yb; double dz0 = z - zb; - //We'll be defining these inside the next block and using them afterwards. double dx_ext0, dy_ext0, dz_ext0; double dx_ext1, dy_ext1, dz_ext1; int xsv_ext0, ysv_ext0, zsv_ext0; int xsv_ext1, ysv_ext1, zsv_ext1; - double value = 0; - if (inSum <= 1) { //We're inside the tetrahedron (3-Simplex) at (0,0,0) - + if (inSum <= 1) + { //We're inside the tetrahedron (3-Simplex) at (0,0,0) //Determine which two of (0,0,1), (0,1,0), (1,0,0) are closest. byte aPoint = 0x01; double aScore = xins; byte bPoint = 0x02; double bScore = yins; - if (aScore >= bScore && zins > bScore) { + if (aScore >= bScore && zins > bScore) + { bScore = zins; bPoint = 0x04; - } else if (aScore < bScore && zins > aScore) { + } + else if (aScore < bScore && zins > aScore) + { aScore = zins; aPoint = 0x04; } - //Now we determine the two lattice points not part of the tetrahedron that may contribute. //This depends on the closest two tetrahedral vertices, including (0,0,0) double wins = 1 - inSum; - if (wins > aScore || wins > bScore) { //(0,0,0) is one of the closest two tetrahedral vertices. + if (wins > aScore || wins > bScore) + { //(0,0,0) is one of the closest two tetrahedral vertices. byte c = (bScore > aScore ? bPoint : aPoint); //Our other closest vertex is the closest out of a and b. - - if ((c & 0x01) == 0) { + if ((c & 0x01) == 0) + { xsv_ext0 = xsb - 1; xsv_ext1 = xsb; dx_ext0 = dx0 + 1; dx_ext1 = dx0; - } else { + } + else + { xsv_ext0 = xsv_ext1 = xsb + 1; dx_ext0 = dx_ext1 = dx0 - 1; } - - if ((c & 0x02) == 0) { + if ((c & 0x02) == 0) + { ysv_ext0 = ysv_ext1 = ysb; dy_ext0 = dy_ext1 = dy0; - if ((c & 0x01) == 0) { + if ((c & 0x01) == 0) + { ysv_ext1 -= 1; dy_ext1 += 1; - } else { + } + else + { ysv_ext0 -= 1; dy_ext0 += 1; } - } else { + } + else + { ysv_ext0 = ysv_ext1 = ysb + 1; dy_ext0 = dy_ext1 = dy0 - 1; } - - if ((c & 0x04) == 0) { + if ((c & 0x04) == 0) + { zsv_ext0 = zsb; zsv_ext1 = zsb - 1; dz_ext0 = dz0; dz_ext1 = dz0 + 1; - } else { + } + else + { zsv_ext0 = zsv_ext1 = zsb + 1; dz_ext0 = dz_ext1 = dz0 - 1; } - } else { //(0,0,0) is not one of the closest two tetrahedral vertices. + } + else + { //(0,0,0) is not one of the closest two tetrahedral vertices. byte c = (byte) (aPoint | bPoint); //Our two extra vertices are determined by the closest two. - - if ((c & 0x01) == 0) { + if ((c & 0x01) == 0) + { xsv_ext0 = xsb; xsv_ext1 = xsb - 1; dx_ext0 = dx0 - 2 * SQUISH_CONSTANT_3D; dx_ext1 = dx0 + 1 - SQUISH_CONSTANT_3D; - } else { + } + else + { xsv_ext0 = xsv_ext1 = xsb + 1; dx_ext0 = dx0 - 1 - 2 * SQUISH_CONSTANT_3D; dx_ext1 = dx0 - 1 - SQUISH_CONSTANT_3D; } - - if ((c & 0x02) == 0) { + if ((c & 0x02) == 0) + { ysv_ext0 = ysb; ysv_ext1 = ysb - 1; dy_ext0 = dy0 - 2 * SQUISH_CONSTANT_3D; dy_ext1 = dy0 + 1 - SQUISH_CONSTANT_3D; - } else { + } + else + { ysv_ext0 = ysv_ext1 = ysb + 1; dy_ext0 = dy0 - 1 - 2 * SQUISH_CONSTANT_3D; dy_ext1 = dy0 - 1 - SQUISH_CONSTANT_3D; } - - if ((c & 0x04) == 0) { + if ((c & 0x04) == 0) + { zsv_ext0 = zsb; zsv_ext1 = zsb - 1; dz_ext0 = dz0 - 2 * SQUISH_CONSTANT_3D; dz_ext1 = dz0 + 1 - SQUISH_CONSTANT_3D; - } else { + } + else + { zsv_ext0 = zsv_ext1 = zsb + 1; dz_ext0 = dz0 - 1 - 2 * SQUISH_CONSTANT_3D; dz_ext1 = dz0 - 1 - SQUISH_CONSTANT_3D; } } - //Contribution (0,0,0) double attn0 = 2 - dx0 * dx0 - dy0 * dy0 - dz0 * dz0; - if (attn0 > 0) { + if (attn0 > 0) + { attn0 *= attn0; value += attn0 * attn0 * extrapolate(xsb + 0, ysb + 0, zsb + 0, dx0, dy0, dz0); } - //Contribution (1,0,0) double dx1 = dx0 - 1 - SQUISH_CONSTANT_3D; double dy1 = dy0 - 0 - SQUISH_CONSTANT_3D; double dz1 = dz0 - 0 - SQUISH_CONSTANT_3D; double attn1 = 2 - dx1 * dx1 - dy1 * dy1 - dz1 * dz1; - if (attn1 > 0) { + if (attn1 > 0) + { attn1 *= attn1; value += attn1 * attn1 * extrapolate(xsb + 1, ysb + 0, zsb + 0, dx1, dy1, dz1); } - //Contribution (0,1,0) double dx2 = dx0 - 0 - SQUISH_CONSTANT_3D; double dy2 = dy0 - 1 - SQUISH_CONSTANT_3D; double dz2 = dz1; double attn2 = 2 - dx2 * dx2 - dy2 * dy2 - dz2 * dz2; - if (attn2 > 0) { + if (attn2 > 0) + { attn2 *= attn2; value += attn2 * attn2 * extrapolate(xsb + 0, ysb + 1, zsb + 0, dx2, dy2, dz2); } - //Contribution (0,0,1) double dx3 = dx2; double dy3 = dy1; double dz3 = dz0 - 1 - SQUISH_CONSTANT_3D; double attn3 = 2 - dx3 * dx3 - dy3 * dy3 - dz3 * dz3; - if (attn3 > 0) { + if (attn3 > 0) + { attn3 *= attn3; value += attn3 * attn3 * extrapolate(xsb + 0, ysb + 0, zsb + 1, dx3, dy3, dz3); } - } else if (inSum >= 2) { //We're inside the tetrahedron (3-Simplex) at (1,1,1) - + } + else if (inSum >= 2) + { //We're inside the tetrahedron (3-Simplex) at (1,1,1) //Determine which two tetrahedral vertices are the closest, out of (1,1,0), (1,0,1), (0,1,1) but not (1,1,1). byte aPoint = 0x06; double aScore = xins; byte bPoint = 0x05; double bScore = yins; - if (aScore <= bScore && zins < bScore) { + if (aScore <= bScore && zins < bScore) + { bScore = zins; bPoint = 0x03; - } else if (aScore > bScore && zins < aScore) { + } + else if (aScore > bScore && zins < aScore) + { aScore = zins; aPoint = 0x03; } - //Now we determine the two lattice points not part of the tetrahedron that may contribute. //This depends on the closest two tetrahedral vertices, including (1,1,1) double wins = 3 - inSum; - if (wins < aScore || wins < bScore) { //(1,1,1) is one of the closest two tetrahedral vertices. + if (wins < aScore || wins < bScore) + { //(1,1,1) is one of the closest two tetrahedral vertices. byte c = (bScore < aScore ? bPoint : aPoint); //Our other closest vertex is the closest out of a and b. - - if ((c & 0x01) != 0) { + if ((c & 0x01) != 0) + { xsv_ext0 = xsb + 2; xsv_ext1 = xsb + 1; dx_ext0 = dx0 - 2 - 3 * SQUISH_CONSTANT_3D; dx_ext1 = dx0 - 1 - 3 * SQUISH_CONSTANT_3D; - } else { + } + else + { xsv_ext0 = xsv_ext1 = xsb; dx_ext0 = dx_ext1 = dx0 - 3 * SQUISH_CONSTANT_3D; } - - if ((c & 0x02) != 0) { + if ((c & 0x02) != 0) + { ysv_ext0 = ysv_ext1 = ysb + 1; dy_ext0 = dy_ext1 = dy0 - 1 - 3 * SQUISH_CONSTANT_3D; - if ((c & 0x01) != 0) { + if ((c & 0x01) != 0) + { ysv_ext1 += 1; dy_ext1 -= 1; - } else { + } + else + { ysv_ext0 += 1; dy_ext0 -= 1; } - } else { + } + else + { ysv_ext0 = ysv_ext1 = ysb; dy_ext0 = dy_ext1 = dy0 - 3 * SQUISH_CONSTANT_3D; } - - if ((c & 0x04) != 0) { + if ((c & 0x04) != 0) + { zsv_ext0 = zsb + 1; zsv_ext1 = zsb + 2; dz_ext0 = dz0 - 1 - 3 * SQUISH_CONSTANT_3D; dz_ext1 = dz0 - 2 - 3 * SQUISH_CONSTANT_3D; - } else { + } + else + { zsv_ext0 = zsv_ext1 = zsb; dz_ext0 = dz_ext1 = dz0 - 3 * SQUISH_CONSTANT_3D; } - } else { //(1,1,1) is not one of the closest two tetrahedral vertices. + } + else + { //(1,1,1) is not one of the closest two tetrahedral vertices. byte c = (byte) (aPoint & bPoint); //Our two extra vertices are determined by the closest two. - - if ((c & 0x01) != 0) { + if ((c & 0x01) != 0) + { xsv_ext0 = xsb + 1; xsv_ext1 = xsb + 2; dx_ext0 = dx0 - 1 - SQUISH_CONSTANT_3D; dx_ext1 = dx0 - 2 - 2 * SQUISH_CONSTANT_3D; - } else { + } + else + { xsv_ext0 = xsv_ext1 = xsb; dx_ext0 = dx0 - SQUISH_CONSTANT_3D; dx_ext1 = dx0 - 2 * SQUISH_CONSTANT_3D; } - - if ((c & 0x02) != 0) { + if ((c & 0x02) != 0) + { ysv_ext0 = ysb + 1; ysv_ext1 = ysb + 2; dy_ext0 = dy0 - 1 - SQUISH_CONSTANT_3D; dy_ext1 = dy0 - 2 - 2 * SQUISH_CONSTANT_3D; - } else { + } + else + { ysv_ext0 = ysv_ext1 = ysb; dy_ext0 = dy0 - SQUISH_CONSTANT_3D; dy_ext1 = dy0 - 2 * SQUISH_CONSTANT_3D; } - - if ((c & 0x04) != 0) { + if ((c & 0x04) != 0) + { zsv_ext0 = zsb + 1; zsv_ext1 = zsb + 2; dz_ext0 = dz0 - 1 - SQUISH_CONSTANT_3D; dz_ext1 = dz0 - 2 - 2 * SQUISH_CONSTANT_3D; - } else { + } + else + { zsv_ext0 = zsv_ext1 = zsb; dz_ext0 = dz0 - SQUISH_CONSTANT_3D; dz_ext1 = dz0 - 2 * SQUISH_CONSTANT_3D; } } - //Contribution (1,1,0) double dx3 = dx0 - 1 - 2 * SQUISH_CONSTANT_3D; double dy3 = dy0 - 1 - 2 * SQUISH_CONSTANT_3D; double dz3 = dz0 - 0 - 2 * SQUISH_CONSTANT_3D; double attn3 = 2 - dx3 * dx3 - dy3 * dy3 - dz3 * dz3; - if (attn3 > 0) { + if (attn3 > 0) + { attn3 *= attn3; value += attn3 * attn3 * extrapolate(xsb + 1, ysb + 1, zsb + 0, dx3, dy3, dz3); } - //Contribution (1,0,1) double dx2 = dx3; double dy2 = dy0 - 0 - 2 * SQUISH_CONSTANT_3D; double dz2 = dz0 - 1 - 2 * SQUISH_CONSTANT_3D; double attn2 = 2 - dx2 * dx2 - dy2 * dy2 - dz2 * dz2; - if (attn2 > 0) { + if (attn2 > 0) + { attn2 *= attn2; value += attn2 * attn2 * extrapolate(xsb + 1, ysb + 0, zsb + 1, dx2, dy2, dz2); } - //Contribution (0,1,1) double dx1 = dx0 - 0 - 2 * SQUISH_CONSTANT_3D; double dy1 = dy3; double dz1 = dz2; double attn1 = 2 - dx1 * dx1 - dy1 * dy1 - dz1 * dz1; - if (attn1 > 0) { + if (attn1 > 0) + { attn1 *= attn1; value += attn1 * attn1 * extrapolate(xsb + 0, ysb + 1, zsb + 1, dx1, dy1, dz1); } - //Contribution (1,1,1) dx0 = dx0 - 1 - 3 * SQUISH_CONSTANT_3D; dy0 = dy0 - 1 - 3 * SQUISH_CONSTANT_3D; dz0 = dz0 - 1 - 3 * SQUISH_CONSTANT_3D; double attn0 = 2 - dx0 * dx0 - dy0 * dy0 - dz0 * dz0; - if (attn0 > 0) { + if (attn0 > 0) + { attn0 *= attn0; value += attn0 * attn0 * extrapolate(xsb + 1, ysb + 1, zsb + 1, dx0, dy0, dz0); } - } else { //We're inside the octahedron (Rectified 3-Simplex) in between. + } + else + { //We're inside the octahedron (Rectified 3-Simplex) in between. double aScore; byte aPoint; boolean aIsFurtherSide; double bScore; byte bPoint; boolean bIsFurtherSide; - //Decide between point (0,0,1) and (1,1,0) as closest double p1 = xins + yins; - if (p1 > 1) { + if (p1 > 1) + { aScore = p1 - 1; aPoint = 0x03; aIsFurtherSide = true; - } else { + } + else + { aScore = 1 - p1; aPoint = 0x04; aIsFurtherSide = false; } - //Decide between point (0,1,0) and (1,0,1) as closest double p2 = xins + zins; - if (p2 > 1) { + if (p2 > 1) + { bScore = p2 - 1; bPoint = 0x05; bIsFurtherSide = true; - } else { + } + else + { bScore = 1 - p2; bPoint = 0x02; bIsFurtherSide = false; } - //The closest out of the two (1,0,0) and (0,1,1) will replace the furthest out of the two decided above, if closer. double p3 = yins + zins; - if (p3 > 1) { + if (p3 > 1) + { double score = p3 - 1; - if (aScore <= bScore && aScore < score) { + if (aScore <= bScore && aScore < score) + { aScore = score; aPoint = 0x06; aIsFurtherSide = true; - } else if (aScore > bScore && bScore < score) { + } + else if (aScore > bScore && bScore < score) + { bScore = score; bPoint = 0x06; bIsFurtherSide = true; } - } else { + } + else + { double score = 1 - p3; - if (aScore <= bScore && aScore < score) { + if (aScore <= bScore && aScore < score) + { aScore = score; aPoint = 0x01; aIsFurtherSide = false; - } else if (aScore > bScore && bScore < score) { + } + else if (aScore > bScore && bScore < score) + { bScore = score; bPoint = 0x01; bIsFurtherSide = false; } } - //Where each of the two closest points are determines how the extra two vertices are calculated. - if (aIsFurtherSide == bIsFurtherSide) { - if (aIsFurtherSide) { //Both closest points on (1,1,1) side - + if (aIsFurtherSide == bIsFurtherSide) + { + if (aIsFurtherSide) + { //Both closest points on (1,1,1) side //One of the two extra points is (1,1,1) dx_ext0 = dx0 - 1 - 3 * SQUISH_CONSTANT_3D; dy_ext0 = dy0 - 1 - 3 * SQUISH_CONSTANT_3D; @@ -577,24 +628,28 @@ public class SimplexNoise { xsv_ext0 = xsb + 1; ysv_ext0 = ysb + 1; zsv_ext0 = zsb + 1; - //Other extra point is based on the shared axis. byte c = (byte) (aPoint & bPoint); - if ((c & 0x01) != 0) { + if ((c & 0x01) != 0) + { dx_ext1 = dx0 - 2 - 2 * SQUISH_CONSTANT_3D; dy_ext1 = dy0 - 2 * SQUISH_CONSTANT_3D; dz_ext1 = dz0 - 2 * SQUISH_CONSTANT_3D; xsv_ext1 = xsb + 2; ysv_ext1 = ysb; zsv_ext1 = zsb; - } else if ((c & 0x02) != 0) { + } + else if ((c & 0x02) != 0) + { dx_ext1 = dx0 - 2 * SQUISH_CONSTANT_3D; dy_ext1 = dy0 - 2 - 2 * SQUISH_CONSTANT_3D; dz_ext1 = dz0 - 2 * SQUISH_CONSTANT_3D; xsv_ext1 = xsb; ysv_ext1 = ysb + 2; zsv_ext1 = zsb; - } else { + } + else + { dx_ext1 = dx0 - 2 * SQUISH_CONSTANT_3D; dy_ext1 = dy0 - 2 * SQUISH_CONSTANT_3D; dz_ext1 = dz0 - 2 - 2 * SQUISH_CONSTANT_3D; @@ -602,8 +657,9 @@ public class SimplexNoise { ysv_ext1 = ysb; zsv_ext1 = zsb + 2; } - } else {//Both closest points on (0,0,0) side - + } + else + {//Both closest points on (0,0,0) side //One of the two extra points is (0,0,0) dx_ext0 = dx0; dy_ext0 = dy0; @@ -611,24 +667,28 @@ public class SimplexNoise { xsv_ext0 = xsb; ysv_ext0 = ysb; zsv_ext0 = zsb; - //Other extra point is based on the omitted axis. byte c = (byte) (aPoint | bPoint); - if ((c & 0x01) == 0) { + if ((c & 0x01) == 0) + { dx_ext1 = dx0 + 1 - SQUISH_CONSTANT_3D; dy_ext1 = dy0 - 1 - SQUISH_CONSTANT_3D; dz_ext1 = dz0 - 1 - SQUISH_CONSTANT_3D; xsv_ext1 = xsb - 1; ysv_ext1 = ysb + 1; zsv_ext1 = zsb + 1; - } else if ((c & 0x02) == 0) { + } + else if ((c & 0x02) == 0) + { dx_ext1 = dx0 - 1 - SQUISH_CONSTANT_3D; dy_ext1 = dy0 + 1 - SQUISH_CONSTANT_3D; dz_ext1 = dz0 - 1 - SQUISH_CONSTANT_3D; xsv_ext1 = xsb + 1; ysv_ext1 = ysb - 1; zsv_ext1 = zsb + 1; - } else { + } + else + { dx_ext1 = dx0 - 1 - SQUISH_CONSTANT_3D; dy_ext1 = dy0 - 1 - SQUISH_CONSTANT_3D; dz_ext1 = dz0 + 1 - SQUISH_CONSTANT_3D; @@ -637,32 +697,41 @@ public class SimplexNoise { zsv_ext1 = zsb - 1; } } - } else { //One point on (0,0,0) side, one point on (1,1,1) side + } + else + { //One point on (0,0,0) side, one point on (1,1,1) side byte c1, c2; - if (aIsFurtherSide) { + if (aIsFurtherSide) + { c1 = aPoint; c2 = bPoint; - } else { + } + else + { c1 = bPoint; c2 = aPoint; } - //One contribution is a permutation of (1,1,-1) - if ((c1 & 0x01) == 0) { + if ((c1 & 0x01) == 0) + { dx_ext0 = dx0 + 1 - SQUISH_CONSTANT_3D; dy_ext0 = dy0 - 1 - SQUISH_CONSTANT_3D; dz_ext0 = dz0 - 1 - SQUISH_CONSTANT_3D; xsv_ext0 = xsb - 1; ysv_ext0 = ysb + 1; zsv_ext0 = zsb + 1; - } else if ((c1 & 0x02) == 0) { + } + else if ((c1 & 0x02) == 0) + { dx_ext0 = dx0 - 1 - SQUISH_CONSTANT_3D; dy_ext0 = dy0 + 1 - SQUISH_CONSTANT_3D; dz_ext0 = dz0 - 1 - SQUISH_CONSTANT_3D; xsv_ext0 = xsb + 1; ysv_ext0 = ysb - 1; zsv_ext0 = zsb + 1; - } else { + } + else + { dx_ext0 = dx0 - 1 - SQUISH_CONSTANT_3D; dy_ext0 = dy0 - 1 - SQUISH_CONSTANT_3D; dz_ext0 = dz0 + 1 - SQUISH_CONSTANT_3D; @@ -670,7 +739,6 @@ public class SimplexNoise { ysv_ext0 = ysb + 1; zsv_ext0 = zsb - 1; } - //One contribution is a permutation of (0,0,2) dx_ext1 = dx0 - 2 * SQUISH_CONSTANT_3D; dy_ext1 = dy0 - 2 * SQUISH_CONSTANT_3D; @@ -678,106 +746,112 @@ public class SimplexNoise { xsv_ext1 = xsb; ysv_ext1 = ysb; zsv_ext1 = zsb; - if ((c2 & 0x01) != 0) { + if ((c2 & 0x01) != 0) + { dx_ext1 -= 2; xsv_ext1 += 2; - } else if ((c2 & 0x02) != 0) { + } + else if ((c2 & 0x02) != 0) + { dy_ext1 -= 2; ysv_ext1 += 2; - } else { + } + else + { dz_ext1 -= 2; zsv_ext1 += 2; } } - //Contribution (1,0,0) double dx1 = dx0 - 1 - SQUISH_CONSTANT_3D; double dy1 = dy0 - 0 - SQUISH_CONSTANT_3D; double dz1 = dz0 - 0 - SQUISH_CONSTANT_3D; double attn1 = 2 - dx1 * dx1 - dy1 * dy1 - dz1 * dz1; - if (attn1 > 0) { + if (attn1 > 0) + { attn1 *= attn1; value += attn1 * attn1 * extrapolate(xsb + 1, ysb + 0, zsb + 0, dx1, dy1, dz1); } - //Contribution (0,1,0) double dx2 = dx0 - 0 - SQUISH_CONSTANT_3D; double dy2 = dy0 - 1 - SQUISH_CONSTANT_3D; double dz2 = dz1; double attn2 = 2 - dx2 * dx2 - dy2 * dy2 - dz2 * dz2; - if (attn2 > 0) { + if (attn2 > 0) + { attn2 *= attn2; value += attn2 * attn2 * extrapolate(xsb + 0, ysb + 1, zsb + 0, dx2, dy2, dz2); } - //Contribution (0,0,1) double dx3 = dx2; double dy3 = dy1; double dz3 = dz0 - 1 - SQUISH_CONSTANT_3D; double attn3 = 2 - dx3 * dx3 - dy3 * dy3 - dz3 * dz3; - if (attn3 > 0) { + if (attn3 > 0) + { attn3 *= attn3; value += attn3 * attn3 * extrapolate(xsb + 0, ysb + 0, zsb + 1, dx3, dy3, dz3); } - //Contribution (1,1,0) double dx4 = dx0 - 1 - 2 * SQUISH_CONSTANT_3D; double dy4 = dy0 - 1 - 2 * SQUISH_CONSTANT_3D; double dz4 = dz0 - 0 - 2 * SQUISH_CONSTANT_3D; double attn4 = 2 - dx4 * dx4 - dy4 * dy4 - dz4 * dz4; - if (attn4 > 0) { + if (attn4 > 0) + { attn4 *= attn4; value += attn4 * attn4 * extrapolate(xsb + 1, ysb + 1, zsb + 0, dx4, dy4, dz4); } - //Contribution (1,0,1) double dx5 = dx4; double dy5 = dy0 - 0 - 2 * SQUISH_CONSTANT_3D; double dz5 = dz0 - 1 - 2 * SQUISH_CONSTANT_3D; double attn5 = 2 - dx5 * dx5 - dy5 * dy5 - dz5 * dz5; - if (attn5 > 0) { + if (attn5 > 0) + { attn5 *= attn5; value += attn5 * attn5 * extrapolate(xsb + 1, ysb + 0, zsb + 1, dx5, dy5, dz5); } - //Contribution (0,1,1) double dx6 = dx0 - 0 - 2 * SQUISH_CONSTANT_3D; double dy6 = dy4; double dz6 = dz5; double attn6 = 2 - dx6 * dx6 - dy6 * dy6 - dz6 * dz6; - if (attn6 > 0) { + if (attn6 > 0) + { attn6 *= attn6; value += attn6 * attn6 * extrapolate(xsb + 0, ysb + 1, zsb + 1, dx6, dy6, dz6); } } - //First extra vertex double attn_ext0 = 2 - dx_ext0 * dx_ext0 - dy_ext0 * dy_ext0 - dz_ext0 * dz_ext0; - if (attn_ext0 > 0) { + if (attn_ext0 > 0) + { attn_ext0 *= attn_ext0; value += attn_ext0 * attn_ext0 * extrapolate(xsv_ext0, ysv_ext0, zsv_ext0, dx_ext0, dy_ext0, dz_ext0); } - //Second extra vertex double attn_ext1 = 2 - dx_ext1 * dx_ext1 - dy_ext1 * dy_ext1 - dz_ext1 * dz_ext1; - if (attn_ext1 > 0) { + if (attn_ext1 > 0) + { attn_ext1 *= attn_ext1; value += attn_ext1 * attn_ext1 * extrapolate(xsv_ext1, ysv_ext1, zsv_ext1, dx_ext1, dy_ext1, dz_ext1); } - return value / NORM_CONSTANT_3D; } - private double extrapolate(int xsb, int ysb, double dx, double dy) { + private double extrapolate(int xsb, int ysb, double dx, double dy) + { int index = perm[(perm[xsb & 0xFF] + ysb) & 0xFF] & 0x0E; return gradients2D[index] * dx - + gradients2D[index + 1] * dy; + + gradients2D[index + 1] * dy; } - private double extrapolate(int xsb, int ysb, int zsb, double dx, double dy, double dz) { + private double extrapolate(int xsb, int ysb, int zsb, double dx, double dy, double dz) + { int index = permGradIndex3D[(perm[(perm[xsb & 0xFF] + ysb) & 0xFF] + zsb) & 0xFF]; return gradients3D[index] * dx - + gradients3D[index + 1] * dy - + gradients3D[index + 2] * dz; + + gradients3D[index + 1] * dy + + gradients3D[index + 2] * dz; } } \ No newline at end of file diff --git a/src/main/java/com/github/halotroop/litecraft/world/BlockAccess.java b/src/main/java/com/github/halotroop/litecraft/world/BlockAccess.java index aac0cfd..db7982c 100644 --- a/src/main/java/com/github/halotroop/litecraft/world/BlockAccess.java +++ b/src/main/java/com/github/halotroop/litecraft/world/BlockAccess.java @@ -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); } \ No newline at end of file diff --git a/src/main/java/com/github/halotroop/litecraft/world/Chunk.java b/src/main/java/com/github/halotroop/litecraft/world/Chunk.java index 064e42d..1710e55 100644 --- a/src/main/java/com/github/halotroop/litecraft/world/Chunk.java +++ b/src/main/java/com/github/halotroop/litecraft/world/Chunk.java @@ -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 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 palette = new Object2IntArrayMap<>(); // block to int id - DataSection paletteData = new DataSection(); DataSection blockData = new DataSection(); - long posHash = 0L; nextId = 0; - ToIntFunction 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; } } diff --git a/src/main/java/com/github/halotroop/litecraft/world/World.java b/src/main/java/com/github/halotroop/litecraft/world/World.java index 8f14d69..71a8b51 100644 --- a/src/main/java/com/github/halotroop/litecraft/world/World.java +++ b/src/main/java/com/github/halotroop/litecraft/world/World.java @@ -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; diff --git a/src/main/java/com/github/halotroop/litecraft/world/block/BlockRenderer.java b/src/main/java/com/github/halotroop/litecraft/world/block/BlockRenderer.java index c93b659..57b1672 100644 --- a/src/main/java/com/github/halotroop/litecraft/world/block/BlockRenderer.java +++ b/src/main/java/com/github/halotroop/litecraft/world/block/BlockRenderer.java @@ -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(); } } diff --git a/src/main/java/com/github/halotroop/litecraft/world/gen/Dimension.java b/src/main/java/com/github/halotroop/litecraft/world/gen/Dimension.java index 3cb90a2..e3d9724 100644 --- a/src/main/java/com/github/halotroop/litecraft/world/gen/Dimension.java +++ b/src/main/java/com/github/halotroop/litecraft/world/gen/Dimension.java @@ -21,9 +21,8 @@ public abstract class Dimension 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); diff --git a/src/main/java/com/github/halotroop/litecraft/world/gen/OverworldChunkGenerator.java b/src/main/java/com/github/halotroop/litecraft/world/gen/OverworldChunkGenerator.java index 09bbc27..4e39388 100644 --- a/src/main/java/com/github/halotroop/litecraft/world/gen/OverworldChunkGenerator.java +++ b/src/main/java/com/github/halotroop/litecraft/world/gen/OverworldChunkGenerator.java @@ -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; } - } diff --git a/src/main/java/com/github/halotroop/litecraft/world/gen/OverworldDimension.java b/src/main/java/com/github/halotroop/litecraft/world/gen/OverworldDimension.java index d4c5062..b47663d 100644 --- a/src/main/java/com/github/halotroop/litecraft/world/gen/OverworldDimension.java +++ b/src/main/java/com/github/halotroop/litecraft/world/gen/OverworldDimension.java @@ -3,13 +3,9 @@ package com.github.halotroop.litecraft.world.gen; public class OverworldDimension extends Dimension { 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); } } \ No newline at end of file diff --git a/src/main/java/com/github/halotroop/litecraft/world/gen/WorldModifier.java b/src/main/java/com/github/halotroop/litecraft/world/gen/WorldModifier.java index 5151cfb..f956dd4 100644 --- a/src/main/java/com/github/halotroop/litecraft/world/gen/WorldModifier.java +++ b/src/main/java/com/github/halotroop/litecraft/world/gen/WorldModifier.java @@ -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); } diff --git a/src/main/java/com/github/hydos/ginger/engine/api/Ginger.java b/src/main/java/com/github/hydos/ginger/engine/api/Ginger.java index 9c29d01..9e2c419 100644 --- a/src/main/java/com/github/hydos/ginger/engine/api/Ginger.java +++ b/src/main/java/com/github/hydos/ginger/engine/api/Ginger.java @@ -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; } } \ No newline at end of file diff --git a/src/main/java/com/github/hydos/ginger/engine/api/GingerRegister.java b/src/main/java/com/github/hydos/ginger/engine/api/GingerRegister.java index a6d0eb2..73d80d9 100644 --- a/src/main/java/com/github/hydos/ginger/engine/api/GingerRegister.java +++ b/src/main/java/com/github/hydos/ginger/engine/api/GingerRegister.java @@ -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 texts; public List guiButtons; public List fbos; - public Game game; public Screen currentScreen; public boolean wireframe = false; public GingerRegister() - { - INSTANCE = this; + { + INSTANCE = this; threadRegister = new GingerThreading(); } diff --git a/src/main/java/com/github/hydos/ginger/engine/cameras/FirstPersonCamera.java b/src/main/java/com/github/hydos/ginger/engine/cameras/FirstPersonCamera.java index a83552f..98fd38a 100644 --- a/src/main/java/com/github/hydos/ginger/engine/cameras/FirstPersonCamera.java +++ b/src/main/java/com/github/hydos/ginger/engine/cameras/FirstPersonCamera.java @@ -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; diff --git a/src/main/java/com/github/hydos/ginger/engine/elements/objects/Player.java b/src/main/java/com/github/hydos/ginger/engine/elements/objects/Player.java index 533bd24..d8ab7b6 100644 --- a/src/main/java/com/github/hydos/ginger/engine/elements/objects/Player.java +++ b/src/main/java/com/github/hydos/ginger/engine/elements/objects/Player.java @@ -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; } } diff --git a/src/main/java/com/github/hydos/ginger/engine/elements/objects/RenderObject.java b/src/main/java/com/github/hydos/ginger/engine/elements/objects/RenderObject.java index 3b395cd..865eb5a 100644 --- a/src/main/java/com/github/hydos/ginger/engine/elements/objects/RenderObject.java +++ b/src/main/java/com/github/hydos/ginger/engine/elements/objects/RenderObject.java @@ -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; } diff --git a/src/main/java/com/github/hydos/ginger/engine/font/TextMaster.java b/src/main/java/com/github/hydos/ginger/engine/font/TextMaster.java index 9003e29..dee98e5 100644 --- a/src/main/java/com/github/hydos/ginger/engine/font/TextMaster.java +++ b/src/main/java/com/github/hydos/ginger/engine/font/TextMaster.java @@ -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> oldTexts = texts; List oldFontText = texts.get(Ginger.getInstance().globalFont); diff --git a/src/main/java/com/github/hydos/ginger/engine/font/TextMeshCreator.java b/src/main/java/com/github/hydos/ginger/engine/font/TextMeshCreator.java index 575ae15..2d901b1 100644 --- a/src/main/java/com/github/hydos/ginger/engine/font/TextMeshCreator.java +++ b/src/main/java/com/github/hydos/ginger/engine/font/TextMeshCreator.java @@ -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 texCoords, double x, double y, double maxX, double maxY) { texCoords.add((float) x); diff --git a/src/main/java/com/github/hydos/ginger/engine/io/Window.java b/src/main/java/com/github/hydos/ginger/engine/io/Window.java index 7e0c3ae..b9406dd 100644 --- a/src/main/java/com/github/hydos/ginger/engine/io/Window.java +++ b/src/main/java/com/github/hydos/ginger/engine/io/Window.java @@ -192,8 +192,5 @@ public class Window } public static void fullscreen() - { - Window.fullscreen = !Window.isFullscreen(); - - } + { Window.fullscreen = !Window.isFullscreen(); } } diff --git a/src/main/java/com/github/hydos/ginger/engine/obj/ModelLoader.java b/src/main/java/com/github/hydos/ginger/engine/obj/ModelLoader.java index ffb6752..8481a00 100644 --- a/src/main/java/com/github/hydos/ginger/engine/obj/ModelLoader.java +++ b/src/main/java/com/github/hydos/ginger/engine/obj/ModelLoader.java @@ -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)); } } diff --git a/src/main/java/com/github/hydos/ginger/engine/obj/OBJFileLoader.java b/src/main/java/com/github/hydos/ginger/engine/obj/OBJFileLoader.java index ba5ea55..93ad164 100644 --- a/src/main/java/com/github/hydos/ginger/engine/obj/OBJFileLoader.java +++ b/src/main/java/com/github/hydos/ginger/engine/obj/OBJFileLoader.java @@ -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); } diff --git a/src/main/java/com/github/hydos/ginger/engine/obj/shapes/StaticCube.java b/src/main/java/com/github/hydos/ginger/engine/obj/shapes/StaticCube.java index 12bb10a..618dd06 100644 --- a/src/main/java/com/github/hydos/ginger/engine/obj/shapes/StaticCube.java +++ b/src/main/java/com/github/hydos/ginger/engine/obj/shapes/StaticCube.java @@ -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); } } diff --git a/src/main/java/com/github/hydos/ginger/engine/particle/ParticleSystem.java b/src/main/java/com/github/hydos/ginger/engine/particle/ParticleSystem.java index 8261b61..3d11401 100644 --- a/src/main/java/com/github/hydos/ginger/engine/particle/ParticleSystem.java +++ b/src/main/java/com/github/hydos/ginger/engine/particle/ParticleSystem.java @@ -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) diff --git a/src/main/java/com/github/hydos/ginger/engine/render/MasterRenderer.java b/src/main/java/com/github/hydos/ginger/engine/render/MasterRenderer.java index c262b12..c621cf4 100644 --- a/src/main/java/com/github/hydos/ginger/engine/render/MasterRenderer.java +++ b/src/main/java/com/github/hydos/ginger/engine/render/MasterRenderer.java @@ -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> entities = new HashMap>(); - private Map> normalMapEntities = new HashMap>(); 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); diff --git a/src/main/java/com/github/hydos/ginger/engine/render/renderers/ObjectRenderer.java b/src/main/java/com/github/hydos/ginger/engine/render/renderers/ObjectRenderer.java index 6e8ab32..b310f8b 100644 --- a/src/main/java/com/github/hydos/ginger/engine/render/renderers/ObjectRenderer.java +++ b/src/main/java/com/github/hydos/ginger/engine/render/renderers/ObjectRenderer.java @@ -66,11 +66,11 @@ public class ObjectRenderer extends Renderer List 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 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(); } - } diff --git a/src/main/java/com/github/hydos/ginger/engine/render/shaders/ShaderProgram.java b/src/main/java/com/github/hydos/ginger/engine/render/shaders/ShaderProgram.java index ace1277..c50d5eb 100644 --- a/src/main/java/com/github/hydos/ginger/engine/render/shaders/ShaderProgram.java +++ b/src/main/java/com/github/hydos/ginger/engine/render/shaders/ShaderProgram.java @@ -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) diff --git a/src/main/java/com/github/hydos/ginger/engine/render/texture/ColorDepth.java b/src/main/java/com/github/hydos/ginger/engine/render/texture/ColorDepth.java index a5aaaef..8ae8065 100644 --- a/src/main/java/com/github/hydos/ginger/engine/render/texture/ColorDepth.java +++ b/src/main/java/com/github/hydos/ginger/engine/render/texture/ColorDepth.java @@ -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 } diff --git a/src/main/java/com/github/hydos/ginger/engine/render/texture/Image.java b/src/main/java/com/github/hydos/ginger/engine/render/texture/Image.java index 0951918..5b791b1 100644 --- a/src/main/java/com/github/hydos/ginger/engine/render/texture/Image.java +++ b/src/main/java/com/github/hydos/ginger/engine/render/texture/Image.java @@ -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; } } \ No newline at end of file diff --git a/src/main/java/com/github/hydos/ginger/engine/render/tools/MousePicker.java b/src/main/java/com/github/hydos/ginger/engine/render/tools/MousePicker.java index 433de84..25ae50b 100644 --- a/src/main/java/com/github/hydos/ginger/engine/render/tools/MousePicker.java +++ b/src/main/java/com/github/hydos/ginger/engine/render/tools/MousePicker.java @@ -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) { diff --git a/src/main/java/com/github/hydos/ginger/engine/screen/Screen.java b/src/main/java/com/github/hydos/ginger/engine/screen/Screen.java index 75ed679..63b6c1b 100644 --- a/src/main/java/com/github/hydos/ginger/engine/screen/Screen.java +++ b/src/main/java/com/github/hydos/ginger/engine/screen/Screen.java @@ -6,9 +6,9 @@ import com.github.hydos.ginger.engine.elements.GuiTexture; public abstract class Screen { - public List elements; + public abstract void render(); + public abstract void tick(); - } diff --git a/src/main/java/com/github/hydos/ginger/engine/shadow/ShadowFrameBuffer.java b/src/main/java/com/github/hydos/ginger/engine/shadow/ShadowFrameBuffer.java index dcfaa5c..d31b95c 100644 --- a/src/main/java/com/github/hydos/ginger/engine/shadow/ShadowFrameBuffer.java +++ b/src/main/java/com/github/hydos/ginger/engine/shadow/ShadowFrameBuffer.java @@ -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. diff --git a/src/main/java/com/github/hydos/ginger/engine/shadow/ShadowMapMasterRenderer.java b/src/main/java/com/github/hydos/ginger/engine/shadow/ShadowMapMasterRenderer.java index 1527fbb..06f0014 100644 --- a/src/main/java/com/github/hydos/ginger/engine/shadow/ShadowMapMasterRenderer.java +++ b/src/main/java/com/github/hydos/ginger/engine/shadow/ShadowMapMasterRenderer.java @@ -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 diff --git a/src/main/java/com/github/hydos/ginger/engine/utils/Loader.java b/src/main/java/com/github/hydos/ginger/engine/utils/Loader.java index 4e787e5..5f6cd6a 100644 --- a/src/main/java/com/github/hydos/ginger/engine/utils/Loader.java +++ b/src/main/java/com/github/hydos/ginger/engine/utils/Loader.java @@ -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); diff --git a/src/main/java/com/github/hydos/ginger/main/settings/Constants.java b/src/main/java/com/github/hydos/ginger/main/settings/Constants.java index 9707dcb..d21c17c 100644 --- a/src/main/java/com/github/hydos/ginger/main/settings/Constants.java +++ b/src/main/java/com/github/hydos/ginger/main/settings/Constants.java @@ -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; diff --git a/src/main/java/com/github/hydos/ginger/voxelUtils/BlockMesher.java b/src/main/java/com/github/hydos/ginger/voxelUtils/BlockMesher.java index 5c5e47b..d861621 100644 --- a/src/main/java/com/github/hydos/ginger/voxelUtils/BlockMesher.java +++ b/src/main/java/com/github/hydos/ginger/voxelUtils/BlockMesher.java @@ -1,5 +1,5 @@ package com.github.hydos.ginger.voxelUtils; -public class BlockMesher { - +public class BlockMesher +{ } diff --git a/src/main/java/com/github/hydos/multiThreading/GingerThread.java b/src/main/java/com/github/hydos/multiThreading/GingerThread.java index bc2d9eb..4d3497c 100644 --- a/src/main/java/com/github/hydos/multiThreading/GingerThread.java +++ b/src/main/java/com/github/hydos/multiThreading/GingerThread.java @@ -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; - } diff --git a/src/main/java/com/github/hydos/multiThreading/GingerThreading.java b/src/main/java/com/github/hydos/multiThreading/GingerThreading.java index 8ad90bf..bc3e741 100644 --- a/src/main/java/com/github/hydos/multiThreading/GingerThreading.java +++ b/src/main/java/com/github/hydos/multiThreading/GingerThreading.java @@ -2,16 +2,13 @@ package com.github.hydos.multiThreading; import java.util.*; -public class GingerThreading { - +public class GingerThreading +{ public List threads; - - public GingerThreading() { - threads = new ArrayList(); - } - - public void registerThread(GingerThread thread) { - threads.add(thread); - } - + + public GingerThreading() + { threads = new ArrayList(); } + + public void registerThread(GingerThread thread) + { threads.add(thread); } } diff --git a/src/main/java/tk/valoeghese/gateways/client/io/InitialPressHandler.java b/src/main/java/tk/valoeghese/gateways/client/io/InitialPressHandler.java index 26eddaa..9747f7b 100644 --- a/src/main/java/tk/valoeghese/gateways/client/io/InitialPressHandler.java +++ b/src/main/java/tk/valoeghese/gateways/client/io/InitialPressHandler.java @@ -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; } diff --git a/src/main/java/tk/valoeghese/gateways/client/io/KeyCallbackHandler.java b/src/main/java/tk/valoeghese/gateways/client/io/KeyCallbackHandler.java index 5cdeeec..bb8e5a3 100644 --- a/src/main/java/tk/valoeghese/gateways/client/io/KeyCallbackHandler.java +++ b/src/main/java/tk/valoeghese/gateways/client/io/KeyCallbackHandler.java @@ -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) diff --git a/src/main/java/tk/valoeghese/gateways/client/io/MouseCallbackHandler.java b/src/main/java/tk/valoeghese/gateways/client/io/MouseCallbackHandler.java index 568a7e8..9c949a9 100644 --- a/src/main/java/tk/valoeghese/gateways/client/io/MouseCallbackHandler.java +++ b/src/main/java/tk/valoeghese/gateways/client/io/MouseCallbackHandler.java @@ -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) diff --git a/src/main/java/tk/valoeghese/sod/DataSection.java b/src/main/java/tk/valoeghese/sod/DataSection.java index 6536b08..410c291 100644 --- a/src/main/java/tk/valoeghese/sod/DataSection.java +++ b/src/main/java/tk/valoeghese/sod/DataSection.java @@ -28,11 +28,8 @@ public class DataSection implements Iterable public > 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]; }