From f8534e718a306f5d164807a0f576986eb8651566 Mon Sep 17 00:00:00 2001 From: hYdos Date: Tue, 25 Feb 2020 19:38:44 +1000 Subject: [PATCH] world generation --- .../halotroop/litecraft/world/World.java | 43 +++++++++++++++++-- .../com/github/hydos/ginger/Litecraft.java | 25 +++++++---- .../hydos/ginger/engine/api/Ginger.java | 5 ++- .../ginger/engine/render/MasterRenderer.java | 4 +- 4 files changed, 61 insertions(+), 16 deletions(-) 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 2090f57..afcb326 100644 --- a/src/main/java/com/github/halotroop/litecraft/world/World.java +++ b/src/main/java/com/github/halotroop/litecraft/world/World.java @@ -1,10 +1,45 @@ package com.github.halotroop.litecraft.world; -import com.github.halotroop.litecraft.types.block.Block; +import java.util.*; -public class World //implements TileAccess +import com.github.hydos.ginger.engine.render.renderers.ObjectRenderer; + +public class World { - public World(long seed) - { + public List chunks; + + public World() { + chunks = new ArrayList(); } + + public void generateWorld() { + + } + + public void optimiseChunks() { + for(Chunk c: chunks) { + optimiseChunk(c); + } + } + + public void optimiseChunk(int ID) { + Chunk chunk = chunks.get(ID); + optimiseChunk(chunk); + } + + //used for model combining and culling + public Chunk optimiseChunk(Chunk chunk) { + //TODO: use this + + return null; + } + + public void render(ObjectRenderer entityRenderer) + { + for(Chunk chunk: chunks) { + 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..fe9fa0d 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,16 @@ 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(); + + for(int i = 0; i<10;i++) { + for(int k = 0; k<10;k++) { + Chunk exampleManualChunk = Chunk.generateChunk(i, -1, k); + exampleManualChunk.setRender(true); + world.chunks.add(exampleManualChunk); + } + } + FontType font = new FontType(Loader.loadFontAtlas("candara.png"), "candara.fnt"); ginger3D.setGlobalFont(font); @@ -55,8 +63,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 +86,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); }