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 f051ada..538ad1b 100644 --- a/src/main/java/com/github/halotroop/litecraft/world/World.java +++ b/src/main/java/com/github/halotroop/litecraft/world/World.java @@ -1,16 +1,17 @@ package com.github.halotroop.litecraft.world; import com.github.halotroop.litecraft.types.block.Block; +import com.github.hydos.ginger.engine.render.renderers.ObjectRenderer; import it.unimi.dsi.fastutil.longs.*; public class World implements BlockAccess { - private final Long2ObjectMap chunks = new Long2ObjectArrayMap<>(); + private final Long2ObjectMap chunks; public World(long seed) { - // TODO world stuff + chunks = new Long2ObjectArrayMap<>(); } public Chunk getChunk(int chunkX, int chunkY, int chunkZ) @@ -26,4 +27,18 @@ public class World implements BlockAccess @Override public void setBlock(int x, int y, int z, Block block) { this.getChunk(x >> POS_SHIFT, y >> POS_SHIFT, z >> POS_SHIFT).setBlock(x & MAX_POS, y & MAX_POS, z & MAX_POS, block); } + + public void optimiseChunks() + { this.chunks.forEach((pos, chunk) -> optimiseChunk(chunk)); } + + //used for model combining and culling + public Chunk optimiseChunk(Chunk chunk) + { + //TODO: use this + + return null; + } + + public void render(ObjectRenderer entityRenderer) + { this.chunks.forEach((pos, chunk) -> chunk.render(entityRenderer)); } } diff --git a/src/main/java/com/github/hydos/ginger/Litecraft.java b/src/main/java/com/github/hydos/ginger/Litecraft.java index ce50a7f..af00c1a 100644 --- a/src/main/java/com/github/hydos/ginger/Litecraft.java +++ b/src/main/java/com/github/hydos/ginger/Litecraft.java @@ -1,6 +1,6 @@ package com.github.hydos.ginger; -import com.github.halotroop.litecraft.world.Chunk; +import com.github.halotroop.litecraft.world.*; import com.github.hydos.ginger.engine.api.*; import com.github.hydos.ginger.engine.api.game.*; import com.github.hydos.ginger.engine.cameras.Camera; @@ -18,14 +18,14 @@ import com.github.hydos.ginger.main.settings.Constants; public class Litecraft extends Game { - private Chunk exampleManualChunk; + private World world; private Ginger ginger3D; private boolean isInWorld = false; //temp stuff to test out fbo fixes int oldWindowWidth = Window.width; int oldWindowHeight = Window.height; - + public Litecraft() { Constants.movementSpeed = 0.00005f; @@ -44,8 +44,14 @@ public class Litecraft extends Game data.handleGuis = false; ginger3D.setup(new MasterRenderer(camera), this); //YeS? - exampleManualChunk = Chunk.generateChunk(0, 0, 0); - exampleManualChunk.setRender(true); + world = new World(0L); + + for(int i = 0; i<10;i++) { + for(int k = 0; k<10;k++) { + Chunk exampleManualChunk = world.getChunk(i, -1, k); + exampleManualChunk.setRender(true); + } + } FontType font = new FontType(Loader.loadFontAtlas("candara.png"), "candara.fnt"); ginger3D.setGlobalFont(font); @@ -55,8 +61,8 @@ public class Litecraft extends Game data.entities.add(player); TextureButton playButton = ginger3D.registerButton("/textures/guis/purpur.png", new Vector2f(0, 0), new Vector2f(0.25f, 0.1f)); playButton.show(data.guis); -// GuiTexture title = new GuiTexture(Loader.loadTextureDirectly("/textures/guis/title.png"), new Vector2f(0, 0.8F), new Vector2f(0.25f, 0.1f)); -// data.guis.add(title); + // GuiTexture title = new GuiTexture(Loader.loadTextureDirectly("/textures/guis/title.png"), new Vector2f(0, 0.8F), new Vector2f(0.25f, 0.1f)); + // data.guis.add(title); //start the game loop ginger3D.startGame(); } @@ -78,8 +84,7 @@ public class Litecraft extends Game oldWindowHeight = Window.height; ginger3D.masterRenderer.renderShadowMap(data.entities, data.lights.get(0)); if (isInWorld) - { ginger3D.renderWithoutTerrain(this); } - exampleManualChunk.render(ginger3D.masterRenderer.entityRenderer); + { ginger3D.renderWithoutTerrain(this, world); } ginger3D.renderOverlays(this); ginger3D.postRender(); } 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 4b972a5..c7ee0e5 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 @@ -2,6 +2,7 @@ package com.github.hydos.ginger.engine.api; import com.github.halotroop.litecraft.logic.Timer; import com.github.halotroop.litecraft.logic.Timer.TickListener; +import com.github.halotroop.litecraft.world.World; import com.github.hydos.ginger.engine.api.game.*; import com.github.hydos.ginger.engine.elements.buttons.TextureButton; import com.github.hydos.ginger.engine.font.*; @@ -74,11 +75,11 @@ public class Ginger TextMaster.render(); } - public void renderWithoutTerrain(Game game) + public void renderWithoutTerrain(Game game, World world) { GingerUtils.preRenderScene(masterRenderer); contrastFbo.bindFBO(); - masterRenderer.renderSceneNoTerrain(game.data.entities, game.data.normalMapEntities, game.data.lights, game.data.camera, game.data.clippingPlane); + masterRenderer.renderSceneNoTerrain(game.data.entities, game.data.normalMapEntities, game.data.lights, game.data.camera, game.data.clippingPlane, world); ParticleMaster.renderParticles(game.data.camera); contrastFbo.unbindFBO(); PostProcessing.doPostProcessing(contrastFbo.colorTexture); 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 a23c04c..6db8e64 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 @@ -5,6 +5,7 @@ import java.util.*; import org.joml.Vector4f; import org.lwjgl.opengl.*; +import com.github.halotroop.litecraft.world.World; import com.github.hydos.ginger.engine.cameras.Camera; import com.github.hydos.ginger.engine.elements.GuiTexture; import com.github.hydos.ginger.engine.elements.objects.*; @@ -162,10 +163,11 @@ public class MasterRenderer skyboxRenderer.render(camera); } - public void renderSceneNoTerrain(List entities, List normalEntities, List lights, Camera camera, Vector4f clipPlane) + public void renderSceneNoTerrain(List entities, List normalEntities, List lights, Camera camera, Vector4f clipPlane, World world) { prepare(); renderEntities(entities, camera, lights); + world.render(entityRenderer); renderNormalEntities(normalEntities, lights, camera, clipPlane); skyboxRenderer.render(camera); }