diff --git a/src/main/java/com/github/halotroop/litecraft/Litecraft.java b/src/main/java/com/github/halotroop/litecraft/Litecraft.java index 383c0a4..f18c1dc 100644 --- a/src/main/java/com/github/halotroop/litecraft/Litecraft.java +++ b/src/main/java/com/github/halotroop/litecraft/Litecraft.java @@ -64,7 +64,7 @@ public class Litecraft extends Game System.exit(0); } - /* + /** * Things that ARE rendering: Anything that results in something being drawn to the frame buffer * Things that are NOT rendering: Things that happen to update between frames but do not result in things being drawn to the screen */ @@ -80,7 +80,7 @@ public class Litecraft extends Game this.tps = 0; this.frameTimer += 1000; } - /* + /** * And now, the actual rendering: */ // Render shadows @@ -153,7 +153,7 @@ public class Litecraft extends Game MouseCallbackHandler.trackWindow(Window.getWindow()); } - /* + /** * Things that should be ticked: Entities when deciding an action, in-game timers (such as smelting), the in-game time * Things that should not be ticked: Rendering, input, player movement */ diff --git a/src/main/java/com/github/halotroop/litecraft/logic/DataStorage.java b/src/main/java/com/github/halotroop/litecraft/logic/SODSerializable.java similarity index 81% rename from src/main/java/com/github/halotroop/litecraft/logic/DataStorage.java rename to src/main/java/com/github/halotroop/litecraft/logic/SODSerializable.java index b58c192..995bc61 100644 --- a/src/main/java/com/github/halotroop/litecraft/logic/DataStorage.java +++ b/src/main/java/com/github/halotroop/litecraft/logic/SODSerializable.java @@ -2,7 +2,7 @@ package com.github.halotroop.litecraft.logic; import tk.valoeghese.sod.BinaryData; -public interface DataStorage +public interface SODSerializable { void read(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 c54eaa3..317ccae 100644 --- a/src/main/java/com/github/halotroop/litecraft/logic/Timer.java +++ b/src/main/java/com/github/halotroop/litecraft/logic/Timer.java @@ -4,7 +4,7 @@ import java.util.*; import com.github.hydos.multithreading.GingerThread; -/* +/** * @author Jack Wilsdon (Stack Exchange) * https://codereview.stackexchange.com/questions/111855/ticker-for-game-timing */ 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 193cfc7..cbf2596 100644 --- a/src/main/java/com/github/halotroop/litecraft/save/LitecraftSave.java +++ b/src/main/java/com/github/halotroop/litecraft/save/LitecraftSave.java @@ -57,7 +57,7 @@ public final class LitecraftSave } } - public Chunk readChunk(int chunkX, int chunkY, int chunkZ, int dimension) + public Chunk readChunk(World world, int chunkX, int chunkY, int chunkZ, int dimension) { // format: ////.sod File chunkFile = new File(new StringBuilder(this.file.getPath()) @@ -68,7 +68,7 @@ public final class LitecraftSave if (chunkFile.isFile()) { BinaryData data = BinaryData.read(chunkFile); - Chunk result = new Chunk(chunkX, chunkY, chunkZ, dimension); // create chunk + Chunk result = new Chunk(world, chunkX, chunkY, chunkZ, dimension); // create chunk result.read(data); // load the chunk data we have just read into the chunk return result; } 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 820c580..1865002 100644 --- a/src/main/java/com/github/halotroop/litecraft/screens/TitleScreen.java +++ b/src/main/java/com/github/halotroop/litecraft/screens/TitleScreen.java @@ -14,7 +14,7 @@ import com.github.hydos.ginger.engine.font.GUIText; import com.github.hydos.ginger.engine.io.Window; import com.github.hydos.ginger.engine.screen.Screen; -/* +/** * YeS */ public class TitleScreen extends Screen 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 46b9e77..decd4c4 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 @@ -1,6 +1,6 @@ package com.github.halotroop.litecraft.util.noise; -/* +/** * OpenSimplex Noise in Java. * (Using implementation by Kurt Spencer) * 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 1a558d9..b81040e 100644 --- a/src/main/java/com/github/halotroop/litecraft/world/Chunk.java +++ b/src/main/java/com/github/halotroop/litecraft/world/Chunk.java @@ -1,10 +1,11 @@ package com.github.halotroop.litecraft.world; +import java.util.Arrays; import java.util.function.ToIntFunction; import org.joml.Vector3f; -import com.github.halotroop.litecraft.logic.DataStorage; +import com.github.halotroop.litecraft.logic.SODSerializable; import com.github.halotroop.litecraft.types.block.*; import com.github.halotroop.litecraft.world.block.BlockRenderer; import com.github.halotroop.litecraft.world.gen.WorldGenConstants; @@ -13,9 +14,9 @@ import it.unimi.dsi.fastutil.ints.*; import it.unimi.dsi.fastutil.objects.*; import tk.valoeghese.sod.*; -public class Chunk implements BlockAccess, WorldGenConstants, DataStorage +public class Chunk implements BlockAccess, WorldGenConstants, SODSerializable { - /* + /** * @param x in-chunk x coordinate. * @param y in-chunk y coordinate. * @param z in-chunk z coordinate. @@ -32,9 +33,10 @@ public class Chunk implements BlockAccess, WorldGenConstants, DataStorage private boolean fullyGenerated = false; public final int dimension; private boolean dirty = true; - private BlockInstance[] renderedBlocks; + private World world; + private BlockInstance[] renderedBlocks = new BlockInstance[CHUNK_SIZE * CHUNK_SIZE * CHUNK_SIZE]; - public Chunk(int chunkX, int chunkY, int chunkZ, int dimension) + public Chunk(World world, int chunkX, int chunkY, int chunkZ, int dimension) { this.chunkX = chunkX; this.chunkY = chunkY; @@ -43,6 +45,7 @@ public class Chunk implements BlockAccess, WorldGenConstants, DataStorage this.chunkStartY = chunkY << POS_SHIFT; this.chunkStartZ = chunkZ << POS_SHIFT; this.dimension = dimension; + this.world = world; } public boolean doRender() @@ -55,14 +58,14 @@ 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!"); } + { throw new RuntimeException("Block [" + x + ", " + y + ", " + z + "] out of chunk bounds!"); } return blocks[index(x, y, z)]; } public BlockInstance getBlockInstance(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!"); } + { throw new RuntimeException("Block [" + x + ", " + y + ", " + z + "] out of chunk bounds!"); } return this.blockEntities[index(x, y, z)]; } @@ -72,12 +75,13 @@ public class Chunk implements BlockAccess, WorldGenConstants, DataStorage { if (dirty) dirty = false; - renderedBlocks = new BlockInstance[CHUNK_SIZE * CHUNK_SIZE * CHUNK_SIZE]; + Arrays.fill(renderedBlocks, null); for (int x = 0; x < CHUNK_SIZE; x++) for (int y = 0; y < CHUNK_SIZE; y++) for (int z = 0; z < CHUNK_SIZE; z++) { BlockInstance block = getBlockInstance(x, y, z); + if (x == 0 || x == CHUNK_SIZE - 1 || z == 0 || z == CHUNK_SIZE - 1 || y == 0 || y == CHUNK_SIZE - 1) { renderedBlocks[index(x, y, z)] = block; @@ -88,19 +92,21 @@ public class Chunk implements BlockAccess, WorldGenConstants, DataStorage if (getBlockInstance(x - 1, y, z).getModel() == null || getBlockInstance(x + 1, y, z).getModel() == null || getBlockInstance(x, y - 1, z).getModel() == null || getBlockInstance(x, y + 1, z).getModel() == null || getBlockInstance(x, y, z - 1).getModel() == null || getBlockInstance(x, y, z + 1).getModel() == null) + { renderedBlocks[index(x, y, z)] = block; + } } catch (NullPointerException e) { // this seems to be a hotspot for errors e.printStackTrace(); // so I can add a debug breakpoint on this line - throw e; + throw e; // e } } blockRenderer.render(renderedBlocks); } } - /* + /** * Change the block in this exact position * @param x, y, z The coordinate position of block to overwrite * @param block The block to place there @@ -122,7 +128,7 @@ public class Chunk implements BlockAccess, WorldGenConstants, DataStorage dirty = true; } - /* + /** * Set whether or not the chunk should render */ public void setRender(boolean render) 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 ce52446..6e44a87 100644 --- a/src/main/java/com/github/halotroop/litecraft/world/World.java +++ b/src/main/java/com/github/halotroop/litecraft/world/World.java @@ -98,8 +98,8 @@ public class World implements BlockAccess, WorldGenConstants { 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; + Chunk readChunk = save.readChunk(this, chunkX, chunkY, chunkZ, this.dimension); + return readChunk == null ? this.chunkGenerator.generateChunk(this, chunkX, chunkY, chunkZ) : readChunk; }); if (chunk.isFullyGenerated()) return chunk; this.populateChunk(chunkX, chunkY, chunkZ, chunk.chunkStartX, chunk.chunkStartY, chunk.chunkStartZ); @@ -114,9 +114,9 @@ public class World implements BlockAccess, WorldGenConstants if (result != null) return result; // try read a chunk from memory - result = save.readChunk(chunkX, chunkY, chunkZ, this.dimension); + result = save.readChunk(this, chunkX, chunkY, chunkZ, this.dimension); // if neither of those work, generate the chunk - return result == null ? this.chunkGenerator.generateChunk(chunkX, chunkY, chunkZ) : result; + return result == null ? this.chunkGenerator.generateChunk(this, chunkX, chunkY, chunkZ) : result; } /** @return whether the chunk was unloaded without errors. Will often, but not always, be equal to whether the chunk was already in memory. */ @@ -145,7 +145,7 @@ public class World implements BlockAccess, WorldGenConstants /** @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)); } + { return this.chunks.computeIfAbsent(posHash(chunkX, chunkY, chunkZ), pos -> this.chunkGenerator.generateChunk(this, chunkX, chunkY, chunkZ)); } long posHash(int chunkX, int chunkY, int chunkZ) { return ((long) chunkX & 0x3FF) | (((long) chunkY & 0x3FF) << 10) | (((long) chunkZ & 0x3FF) << 20); } diff --git a/src/main/java/com/github/halotroop/litecraft/world/gen/ChunkGenerator.java b/src/main/java/com/github/halotroop/litecraft/world/gen/ChunkGenerator.java index 16b0016..3903540 100644 --- a/src/main/java/com/github/halotroop/litecraft/world/gen/ChunkGenerator.java +++ b/src/main/java/com/github/halotroop/litecraft/world/gen/ChunkGenerator.java @@ -1,8 +1,9 @@ package com.github.halotroop.litecraft.world.gen; import com.github.halotroop.litecraft.world.Chunk; +import com.github.halotroop.litecraft.world.World; public interface ChunkGenerator { - Chunk generateChunk(int chunkX, int chunkY, int chunkZ); + Chunk generateChunk(World world, int chunkX, int chunkY, int chunkZ); } diff --git a/src/main/java/com/github/halotroop/litecraft/world/gen/EarthChunkGenerator.java b/src/main/java/com/github/halotroop/litecraft/world/gen/EarthChunkGenerator.java index 24ee674..ccf481c 100644 --- a/src/main/java/com/github/halotroop/litecraft/world/gen/EarthChunkGenerator.java +++ b/src/main/java/com/github/halotroop/litecraft/world/gen/EarthChunkGenerator.java @@ -5,6 +5,7 @@ import java.util.Random; import com.github.halotroop.litecraft.types.block.*; import com.github.halotroop.litecraft.util.noise.OctaveSimplexNoise; import com.github.halotroop.litecraft.world.Chunk; +import com.github.halotroop.litecraft.world.World; public class EarthChunkGenerator implements ChunkGenerator, WorldGenConstants { @@ -21,9 +22,9 @@ public class EarthChunkGenerator implements ChunkGenerator, WorldGenConstants private final int dimension; @Override - public Chunk generateChunk(int chunkX, int chunkY, int chunkZ) + public Chunk generateChunk(World world, int chunkX, int chunkY, int chunkZ) { - Chunk chunk = new Chunk(chunkX, chunkY, chunkZ, this.dimension); + Chunk chunk = new Chunk(world, chunkX, chunkY, chunkZ, this.dimension); for (int x = 0; x < CHUNK_SIZE; x++) { double totalX = x + chunk.chunkStartX; diff --git a/src/main/java/com/github/hydos/ginger/engine/api/ResourceManager.java b/src/main/java/com/github/hydos/ginger/engine/api/ResourceManager.java index 77be47e..17095b4 100644 --- a/src/main/java/com/github/hydos/ginger/engine/api/ResourceManager.java +++ b/src/main/java/com/github/hydos/ginger/engine/api/ResourceManager.java @@ -1,6 +1,6 @@ package com.github.hydos.ginger.engine.api; -/* +/** * make your own resource manager if you want! */ public abstract class ResourceManager diff --git a/src/main/java/com/github/hydos/ginger/engine/api/game/GameData.java b/src/main/java/com/github/hydos/ginger/engine/api/game/GameData.java index 8c1f5f9..9fe8e3f 100644 --- a/src/main/java/com/github/hydos/ginger/engine/api/game/GameData.java +++ b/src/main/java/com/github/hydos/ginger/engine/api/game/GameData.java @@ -8,7 +8,7 @@ import com.github.hydos.ginger.engine.cameras.Camera; import com.github.hydos.ginger.engine.elements.GuiTexture; import com.github.hydos.ginger.engine.elements.objects.*; -/* +/** * Used for storing essential engine game data so main class isn't messy * Also in general used with Game Class */ 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 796cbb7..2422081 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 @@ -8,5 +8,5 @@ public class Constants public static Vector3f gravity = new Vector3f(0, 0, 0); public static float jumpPower = 0; public static float turnSpeed = 0; - public static double movementSpeed = 1; + public static double movementSpeed = 2; } 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 9747f7b..979cebb 100644 --- a/src/main/java/tk/valoeghese/gateways/client/io/InitialPressHandler.java +++ b/src/main/java/tk/valoeghese/gateways/client/io/InitialPressHandler.java @@ -1,6 +1,6 @@ package tk.valoeghese.gateways.client.io; -/* +/** * Author: Valoeghese */ public final class InitialPressHandler implements KeyListener diff --git a/src/main/java/tk/valoeghese/gateways/client/io/Input.java b/src/main/java/tk/valoeghese/gateways/client/io/Input.java index 1c72c00..2f46b79 100644 --- a/src/main/java/tk/valoeghese/gateways/client/io/Input.java +++ b/src/main/java/tk/valoeghese/gateways/client/io/Input.java @@ -2,7 +2,7 @@ package tk.valoeghese.gateways.client.io; import java.util.*; -/* +/** * Author: Valoeghese */ public class Input diff --git a/src/main/java/tk/valoeghese/gateways/client/io/KeyCallback.java b/src/main/java/tk/valoeghese/gateways/client/io/KeyCallback.java index fd370a1..bdf0234 100644 --- a/src/main/java/tk/valoeghese/gateways/client/io/KeyCallback.java +++ b/src/main/java/tk/valoeghese/gateways/client/io/KeyCallback.java @@ -1,6 +1,6 @@ package tk.valoeghese.gateways.client.io; -/* +/** * Author: Valoeghese */ public interface KeyCallback 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 bb8e5a3..2335900 100644 --- a/src/main/java/tk/valoeghese/gateways/client/io/KeyCallbackHandler.java +++ b/src/main/java/tk/valoeghese/gateways/client/io/KeyCallbackHandler.java @@ -2,7 +2,7 @@ package tk.valoeghese.gateways.client.io; import org.lwjgl.glfw.*; -/* +/** * Author: Valoeghese */ public class KeyCallbackHandler extends GLFWKeyCallback diff --git a/src/main/java/tk/valoeghese/gateways/client/io/KeyListener.java b/src/main/java/tk/valoeghese/gateways/client/io/KeyListener.java index 24ad811..6d69222 100644 --- a/src/main/java/tk/valoeghese/gateways/client/io/KeyListener.java +++ b/src/main/java/tk/valoeghese/gateways/client/io/KeyListener.java @@ -1,6 +1,6 @@ package tk.valoeghese.gateways.client.io; -/* +/** * Author: Valoeghese */ public interface KeyListener diff --git a/src/main/java/tk/valoeghese/gateways/client/io/Keybind.java b/src/main/java/tk/valoeghese/gateways/client/io/Keybind.java index a054215..4dd0014 100644 --- a/src/main/java/tk/valoeghese/gateways/client/io/Keybind.java +++ b/src/main/java/tk/valoeghese/gateways/client/io/Keybind.java @@ -2,7 +2,7 @@ package tk.valoeghese.gateways.client.io; import org.lwjgl.glfw.GLFW; -/* +/** * Author: Valoeghese */ public enum Keybind 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 9c949a9..7b420d6 100644 --- a/src/main/java/tk/valoeghese/gateways/client/io/MouseCallbackHandler.java +++ b/src/main/java/tk/valoeghese/gateways/client/io/MouseCallbackHandler.java @@ -2,7 +2,7 @@ package tk.valoeghese.gateways.client.io; import org.lwjgl.glfw.*; -/* +/** * Author: Valoeghese */ public class MouseCallbackHandler extends GLFWMouseButtonCallback