diff --git a/VBO/src/game/Game.java b/VBO/src/game/Game.java deleted file mode 100644 index 1ccb69a..0000000 --- a/VBO/src/game/Game.java +++ /dev/null @@ -1,47 +0,0 @@ -package game; - -import world.*; - -public class Game { - - private World world; - private int update = 0; - - public Game(){ - world= new World(0,120,50); - } - - public void update(){ - if(update >= 2){ - world.update(); - update = 0; - } - update++; - } - - public void render(){ - world.render(); - } - - public void renderGUI(){ - - } - - public World getWorld() { - return world; - } - - public void setWorld(World world) { - this.world = world; - } - - public int getUpdate() { - return update; - } - - public void setUpdate(int update) { - this.update = update; - } - - -} diff --git a/VBO/src/blocks/Block.java b/VBO/src/mrdev023/blocks/Block.java similarity index 96% rename from VBO/src/blocks/Block.java rename to VBO/src/mrdev023/blocks/Block.java index 10deae3..7caccda 100644 --- a/VBO/src/blocks/Block.java +++ b/VBO/src/mrdev023/blocks/Block.java @@ -1,12 +1,9 @@ -package blocks; +package mrdev023.blocks; +import mrdev023.math.*; -import math.Color4f; -import math.Vector3f; - - public abstract class Block { public static final Block OAK_WOOD = new OakWoodBlock(), diff --git a/VBO/src/blocks/FirLeafBlock.java b/VBO/src/mrdev023/blocks/FirLeafBlock.java similarity index 65% rename from VBO/src/blocks/FirLeafBlock.java rename to VBO/src/mrdev023/blocks/FirLeafBlock.java index 5ddb8e6..9dabc0d 100644 --- a/VBO/src/blocks/FirLeafBlock.java +++ b/VBO/src/mrdev023/blocks/FirLeafBlock.java @@ -1,6 +1,6 @@ -package blocks; +package mrdev023.blocks; -import math.Color4f; +import mrdev023.math.*; public class FirLeafBlock extends Block{ diff --git a/VBO/src/blocks/FirWoodBlock.java b/VBO/src/mrdev023/blocks/FirWoodBlock.java similarity index 66% rename from VBO/src/blocks/FirWoodBlock.java rename to VBO/src/mrdev023/blocks/FirWoodBlock.java index 47567af..40bffa7 100644 --- a/VBO/src/blocks/FirWoodBlock.java +++ b/VBO/src/mrdev023/blocks/FirWoodBlock.java @@ -1,6 +1,6 @@ -package blocks; +package mrdev023.blocks; -import math.Color4f; +import mrdev023.math.*; public class FirWoodBlock extends WoodBlock{ diff --git a/VBO/src/blocks/GrassBlock.java b/VBO/src/mrdev023/blocks/GrassBlock.java similarity index 64% rename from VBO/src/blocks/GrassBlock.java rename to VBO/src/mrdev023/blocks/GrassBlock.java index aa3c3a6..b10ee69 100644 --- a/VBO/src/blocks/GrassBlock.java +++ b/VBO/src/mrdev023/blocks/GrassBlock.java @@ -1,6 +1,6 @@ -package blocks; +package mrdev023.blocks; -import math.Color4f; +import mrdev023.math.*; public class GrassBlock extends Block{ public GrassBlock() { diff --git a/VBO/src/blocks/LeafBlock.java b/VBO/src/mrdev023/blocks/LeafBlock.java similarity index 63% rename from VBO/src/blocks/LeafBlock.java rename to VBO/src/mrdev023/blocks/LeafBlock.java index d49356d..1d62e28 100644 --- a/VBO/src/blocks/LeafBlock.java +++ b/VBO/src/mrdev023/blocks/LeafBlock.java @@ -1,6 +1,6 @@ -package blocks; +package mrdev023.blocks; -import math.Color4f; +import mrdev023.math.*; public class LeafBlock extends Block{ diff --git a/VBO/src/blocks/OakWoodBlock.java b/VBO/src/mrdev023/blocks/OakWoodBlock.java similarity index 66% rename from VBO/src/blocks/OakWoodBlock.java rename to VBO/src/mrdev023/blocks/OakWoodBlock.java index b5afb91..1738713 100644 --- a/VBO/src/blocks/OakWoodBlock.java +++ b/VBO/src/mrdev023/blocks/OakWoodBlock.java @@ -1,6 +1,6 @@ -package blocks; +package mrdev023.blocks; -import math.*; +import mrdev023.math.*; public class OakWoodBlock extends WoodBlock{ diff --git a/VBO/src/blocks/TransparentBlock.java b/VBO/src/mrdev023/blocks/TransparentBlock.java similarity index 65% rename from VBO/src/blocks/TransparentBlock.java rename to VBO/src/mrdev023/blocks/TransparentBlock.java index edaeb2d..24cdac0 100644 --- a/VBO/src/blocks/TransparentBlock.java +++ b/VBO/src/mrdev023/blocks/TransparentBlock.java @@ -1,6 +1,6 @@ -package blocks; +package mrdev023.blocks; -import math.Color4f; +import mrdev023.math.*; public class TransparentBlock extends Block { diff --git a/VBO/src/blocks/WoodBlock.java b/VBO/src/mrdev023/blocks/WoodBlock.java similarity index 60% rename from VBO/src/blocks/WoodBlock.java rename to VBO/src/mrdev023/blocks/WoodBlock.java index c3f6f14..6fe0ca8 100644 --- a/VBO/src/blocks/WoodBlock.java +++ b/VBO/src/mrdev023/blocks/WoodBlock.java @@ -1,6 +1,6 @@ -package blocks; +package mrdev023.blocks; -import math.Color4f; +import mrdev023.math.*; public class WoodBlock extends Block{ diff --git a/VBO/src/game/PlayerRayCast.java b/VBO/src/mrdev023/entity/PlayerRayCast.java similarity index 85% rename from VBO/src/game/PlayerRayCast.java rename to VBO/src/mrdev023/entity/PlayerRayCast.java index 424ddbb..6bbd083 100644 --- a/VBO/src/game/PlayerRayCast.java +++ b/VBO/src/mrdev023/entity/PlayerRayCast.java @@ -1,9 +1,10 @@ -package game; +package mrdev023.entity; import java.util.*; -import math.*; -import world.*; +import mrdev023.math.*; +import mrdev023.rendering.*; +import mrdev023.world.*; public class PlayerRayCast { diff --git a/VBO/src/mrdev023/game/Game.java b/VBO/src/mrdev023/game/Game.java new file mode 100644 index 0000000..d76ffd9 --- /dev/null +++ b/VBO/src/mrdev023/game/Game.java @@ -0,0 +1,39 @@ +package mrdev023.game; + +import mrdev023.world.*; + +public abstract class Game { + + protected World world; + protected int update = 0; + + public Game(World world){ + this.world = world; + } + + public abstract void update(); + + public abstract void render(); + + public abstract void renderGUI(); + + public World getWorld() { + return world; + } + + public void setWorld(World world) { + this.world = world; + } + + public int getUpdate() { + return update; + } + + public void setUpdate(int update) { + this.update = update; + } + + public void destroyGame(){ + world.destroyWorld(); + } +} diff --git a/VBO/src/mrdev023/game/MultiGame.java b/VBO/src/mrdev023/game/MultiGame.java new file mode 100644 index 0000000..6b95127 --- /dev/null +++ b/VBO/src/mrdev023/game/MultiGame.java @@ -0,0 +1,27 @@ +package mrdev023.game; + +import mrdev023.world.*; + +public class MultiGame extends Game{ + + public MultiGame(long seed) { + super(new MultiWorld(seed,120,50)); + } + + public void render(){ + this.world.render(); + } + + public void update(){ + if(update >= 2){ + world.update(); + update = 0; + } + update++; + } + + public void renderGUI() { + + } + +} diff --git a/VBO/src/mrdev023/game/SoloGame.java b/VBO/src/mrdev023/game/SoloGame.java new file mode 100644 index 0000000..90ee3ab --- /dev/null +++ b/VBO/src/mrdev023/game/SoloGame.java @@ -0,0 +1,27 @@ +package mrdev023.game; + +import mrdev023.world.*; + + +public class SoloGame extends Game{ + + public SoloGame() { + super(new SoloWorld(0,120,50)); + } + + public void render(){ + this.world.render(); + } + + public void update(){ + if(update >= 2){ + world.update(); + update = 0; + } + update++; + } + + public void renderGUI() { + + } +} diff --git a/VBO/src/mrdev023/game/gamestate/GameState.java b/VBO/src/mrdev023/game/gamestate/GameState.java new file mode 100644 index 0000000..db431fb --- /dev/null +++ b/VBO/src/mrdev023/game/gamestate/GameState.java @@ -0,0 +1,13 @@ +package mrdev023.game.gamestate; + +public enum GameState { + + MAIN_MENU,SOLO_GAME,MULTI_GAME,OPTION_GAME,ABOUT_GAME; + + GameState(){ + + } + + + +} diff --git a/VBO/src/main/Main.java b/VBO/src/mrdev023/gameEngine/GameEngine.java similarity index 77% rename from VBO/src/main/Main.java rename to VBO/src/mrdev023/gameEngine/GameEngine.java index fe7baa2..14acb98 100644 --- a/VBO/src/main/Main.java +++ b/VBO/src/mrdev023/gameEngine/GameEngine.java @@ -1,15 +1,17 @@ -package main; - -import game.*; +package mrdev023.gameEngine; import java.util.concurrent.*; import org.lwjgl.input.*; import org.lwjgl.opengl.*; -import world.*; +import mrdev023.game.*; +import mrdev023.main.*; +import mrdev023.rendering.*; +import mrdev023.update.*; +import mrdev023.world.*; -public class Main { +public class GameEngine { private static boolean IsRunning = true; private static long current = System.currentTimeMillis(),current2, elapsedInfo = 0, @@ -20,29 +22,17 @@ public class Main { private static final String TITLE = "Test VBO"; private static final int width = 1280, height = 720; - -// private static AffinityLock al; - public static ExecutorService mainPool; - private static Game game; - - /** - * @param args - * @Info Fonction principal - */ - public static void main(String[] args) { -// mainPool = ForkJoinPool.commonPool(); - mainPool = Executors.newWorkStealingPool(); -// AffinityLock.cpuLayout(new NoCpuLayout(Runtime.getRuntime().availableProcessors() + 8)); -// al = AffinityLock.acquireLock(); -// System.out.println(AffinityLock.cpuLayout().coresPerSocket()) + + public static void initWindow(){ + Main.mainPool = Executors.newWorkStealingPool(); try { Display.setTitle(TITLE); Display.setDisplayMode(new DisplayMode(width, height)); Display.setResizable(true); Display.create(); Camera.initCamera(); - game = new Game(); + game = new SoloGame(); Mouse.setGrabbed(true); loop(); } catch (Exception e) { @@ -50,14 +40,6 @@ public class Main { } } - public static Runnable addThread(Runnable t,String name){ - mainPool.submit(t); -// mainPool.execute(t); -// new Thread(t, name).start(); -// System.out.println("Details" + AffinityLock.dumpLocks()); - return t; - } - /** * @Info Boucle principal avec Timer */ @@ -112,6 +94,12 @@ public class Main { Display.update(); } + destroy(); + } + + public static void destroy(){ + game.destroyGame(); + Display.destroy(); } public static String getStringByNoString(Object... a){ @@ -184,4 +172,5 @@ public class Main { return game; } + } diff --git a/VBO/src/mrdev023/main/Main.java b/VBO/src/mrdev023/main/Main.java new file mode 100644 index 0000000..973753d --- /dev/null +++ b/VBO/src/mrdev023/main/Main.java @@ -0,0 +1,43 @@ +package mrdev023.main; + + +import java.util.concurrent.*; + +import mrdev023.game.*; +import mrdev023.gameEngine.*; +import mrdev023.rendering.*; +import mrdev023.server.*; +import mrdev023.update.*; +import mrdev023.world.*; + +import org.lwjgl.input.*; +import org.lwjgl.opengl.*; + +public class Main { + + public static ExecutorService mainPool; + + /** + * @param args + * @Info Fonction principal + */ + public static void main(String[] args) { + boolean IsServer = false; + + for(String arg : args){ + if(arg.equals("-server"))IsServer = true; + } + + if(IsServer){ + Server.initServer(); + }else{ + GameEngine.initWindow(); + } + } + + public static Runnable addThread(Runnable t,String name){ + mainPool.submit(t); + return t; + } + +} diff --git a/VBO/src/math/Color4f.java b/VBO/src/mrdev023/math/Color4f.java similarity index 92% rename from VBO/src/math/Color4f.java rename to VBO/src/mrdev023/math/Color4f.java index 21649f7..e9fac7a 100644 --- a/VBO/src/math/Color4f.java +++ b/VBO/src/mrdev023/math/Color4f.java @@ -1,4 +1,4 @@ -package math; +package mrdev023.math; public class Color4f { diff --git a/VBO/src/math/Vector2f.java b/VBO/src/mrdev023/math/Vector2f.java similarity index 86% rename from VBO/src/math/Vector2f.java rename to VBO/src/mrdev023/math/Vector2f.java index 6cf0a90..dd882f2 100644 --- a/VBO/src/math/Vector2f.java +++ b/VBO/src/mrdev023/math/Vector2f.java @@ -1,4 +1,4 @@ -package math; +package mrdev023.math; public class Vector2f { diff --git a/VBO/src/math/Vector3f.java b/VBO/src/mrdev023/math/Vector3f.java similarity index 92% rename from VBO/src/math/Vector3f.java rename to VBO/src/mrdev023/math/Vector3f.java index b7f113f..41c5a80 100644 --- a/VBO/src/math/Vector3f.java +++ b/VBO/src/mrdev023/math/Vector3f.java @@ -1,4 +1,4 @@ -package math; +package mrdev023.math; public class Vector3f { diff --git a/VBO/src/mrdev023/network/Client.java b/VBO/src/mrdev023/network/Client.java new file mode 100644 index 0000000..109f22e --- /dev/null +++ b/VBO/src/mrdev023/network/Client.java @@ -0,0 +1,5 @@ +package mrdev023.network; + +public class Client { + +} diff --git a/VBO/src/game/Camera.java b/VBO/src/mrdev023/rendering/Camera.java similarity index 86% rename from VBO/src/game/Camera.java rename to VBO/src/mrdev023/rendering/Camera.java index 9944378..b86f34b 100644 --- a/VBO/src/game/Camera.java +++ b/VBO/src/mrdev023/rendering/Camera.java @@ -1,10 +1,13 @@ -package game; +package mrdev023.rendering; import static org.lwjgl.opengl.GL11.*; -import world.*; -import blocks.*; -import main.*; -import math.*; +import mrdev023.blocks.*; +import mrdev023.entity.*; +import mrdev023.gameEngine.*; +import mrdev023.main.*; +import mrdev023.math.*; +import mrdev023.world.*; +import mrdev023.world.chunk.*; public class Camera { @@ -22,14 +25,14 @@ public class Camera { } public static void renderCamera() { - if (position.getY() < (int)((new Noise(Main.getGame().getWorld().seed, Main + if (position.getY() < (int)((new Noise(GameEngine.getGame().getWorld().seed, GameEngine .getGame().getWorld().octave, - Main.getGame().getWorld().amplitude).getNoise(position.getX(), + GameEngine.getGame().getWorld().amplitude).getNoise(position.getX(), position.getZ())) + 1)) { - position.setY((int)((new Noise(Main.getGame().getWorld().seed, Main + position.setY((int)((new Noise(GameEngine.getGame().getWorld().seed, GameEngine .getGame().getWorld().octave, - Main.getGame().getWorld().amplitude).getNoise(position.getX(), + GameEngine.getGame().getWorld().amplitude).getNoise(position.getX(), position.getZ())) + 2)); } glLoadIdentity(); @@ -116,7 +119,7 @@ public class Camera { } public static boolean isColliding(float xa, float ya, float za) { - World world = Main.getGame().getWorld(); + World world = GameEngine.getGame().getWorld(); float r = 0.3f; boolean nx = false, ny = false, nz = false; diff --git a/VBO/src/game/DisplayManager.java b/VBO/src/mrdev023/rendering/DisplayManager.java similarity index 91% rename from VBO/src/game/DisplayManager.java rename to VBO/src/mrdev023/rendering/DisplayManager.java index 5b2be4e..6181648 100644 --- a/VBO/src/game/DisplayManager.java +++ b/VBO/src/mrdev023/rendering/DisplayManager.java @@ -1,9 +1,9 @@ -package game; +package mrdev023.rendering; import static org.lwjgl.opengl.GL11.*; import static org.lwjgl.util.glu.GLU.*; -import main.*; +import mrdev023.gameEngine.*; +import mrdev023.update.*; -import org.lwjgl.input.*; import org.lwjgl.opengl.*; import org.lwjgl.util.glu.*; @@ -40,7 +40,7 @@ public class DisplayManager { * @Info Fait le rendu 3d */ public static void render3D(){ - Main.getGame().render(); + GameEngine.getGame().render(); if(Update.getSelectedBlock() != null && Update.getSelectedVector() !=null){ renderBlock((int)Update.getSelectedVector().x,(int)Update.getSelectedVector().y,(int)Update.getSelectedVector().z); } @@ -62,7 +62,7 @@ public class DisplayManager { * @Info Fait le rendu 2d */ public static void render2D(){ - Main.getGame().renderGUI(); + GameEngine.getGame().renderGUI(); } /** diff --git a/VBO/src/game/VBO.java b/VBO/src/mrdev023/rendering/VBO.java similarity index 79% rename from VBO/src/game/VBO.java rename to VBO/src/mrdev023/rendering/VBO.java index e44218e..6747ee0 100644 --- a/VBO/src/game/VBO.java +++ b/VBO/src/mrdev023/rendering/VBO.java @@ -1,4 +1,4 @@ -package game; +package mrdev023.rendering; import static org.lwjgl.opengl.GL11.*; import static org.lwjgl.opengl.GL15.*; import static org.lwjgl.opengl.GL20.*; @@ -15,6 +15,7 @@ public class VBO { private int vboID = 0; private FloatBuffer buffer; private ArrayList floatlist = new ArrayList(); + private static final int FLOAT_SIZE = 4; public VBO(){ this.vboID = createVBO(); @@ -88,8 +89,14 @@ public class VBO { glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); - glVertexPointer(3, GL_FLOAT, 7 * 4, 0); - glColorPointer(4, GL_FLOAT, 7 * 4, 12); + + glVertexPointer(3, GL_FLOAT, (3 + 4) * FLOAT_SIZE, 0); + glColorPointer(4, GL_FLOAT, (3 + 4) * FLOAT_SIZE, 3 * FLOAT_SIZE); + + //x,y,z,r,g,b,a,nx,ny,nz + //glVertexPointer(3, GL_FLOAT, (3 + 4 + 3) * FLOAT_SIZE, 0); + //glColorPointer(4, GL_FLOAT, (3 + 4 + 3) * FLOAT_SIZE, 3 * FLOAT_SIZE); + //glNormalPointer(4, GL_FLOAT, (3 + 4 + 3) * FLOAT_SIZE, (3 + 4) * FLOAT_SIZE); // glVertexAttribPointer(0,3,GL_FLOAT,false,7 * 4,0); // glVertexAttribPointer(1,4,GL_FLOAT,false,7 * 4,12); diff --git a/VBO/src/mrdev023/server/Server.java b/VBO/src/mrdev023/server/Server.java new file mode 100644 index 0000000..5479c19 --- /dev/null +++ b/VBO/src/mrdev023/server/Server.java @@ -0,0 +1,9 @@ +package mrdev023.server; + +public class Server { + + public static void initServer(){ + + } + +} diff --git a/VBO/src/game/Update.java b/VBO/src/mrdev023/update/Update.java similarity index 74% rename from VBO/src/game/Update.java rename to VBO/src/mrdev023/update/Update.java index 30e1748..4f7ef01 100644 --- a/VBO/src/game/Update.java +++ b/VBO/src/mrdev023/update/Update.java @@ -1,12 +1,13 @@ -package game; -import main.*; -import math.*; +package mrdev023.update; +import mrdev023.blocks.*; +import mrdev023.gameEngine.*; +import mrdev023.main.*; +import mrdev023.math.*; +import mrdev023.rendering.*; import org.lwjgl.input.*; import org.lwjgl.opengl.*; -import blocks.*; - public class Update { @@ -45,7 +46,7 @@ public class Update { while(Keyboard.next()){ if(Keyboard.getEventKeyState()){ if(Keyboard.getEventKey() == Keyboard.KEY_ESCAPE){ - Main.setRunning(false); + GameEngine.setRunning(false); } if(Keyboard.getEventKey() == Keyboard.KEY_F2){ Mouse.setGrabbed(!Mouse.isGrabbed()); @@ -110,7 +111,7 @@ public class Update { za *= 0.9f; if(Display.isCloseRequested()){ - Main.setRunning(false); + GameEngine.setRunning(false); } } @@ -118,15 +119,15 @@ public class Update { * @Info Fonction de mettre a jour le display et d'autre choses predefinie */ public static void update(){ - Main.getGame().update(); + GameEngine.getGame().update(); Camera.getPlayerRaycast().update(); - if(Camera.getPlayerRaycast().getBlock(Main.getGame().getWorld()) != null){ + if(Camera.getPlayerRaycast().getBlock(GameEngine.getGame().getWorld()) != null){ boolean nx = false, ny = false, nz = false; - if(Camera.getPlayerRaycast().getBlock(Main.getGame().getWorld()).x < 0)nx = true; - if(Camera.getPlayerRaycast().getBlock(Main.getGame().getWorld()).y < 0)ny = true; - if(Camera.getPlayerRaycast().getBlock(Main.getGame().getWorld()).z < 0)nz = true; - selectedBlock = Main.getGame().getWorld().getBlock((int)Camera.getPlayerRaycast().getBlock(Main.getGame().getWorld()).getX(), (int)Camera.getPlayerRaycast().getBlock(Main.getGame().getWorld()).getY(), (int)Camera.getPlayerRaycast().getBlock(Main.getGame().getWorld()).getZ(),nx,ny,nz); - selectedVector = new Vector3f(Camera.getPlayerRaycast().getBlock(Main.getGame().getWorld()).getX(), Camera.getPlayerRaycast().getBlock(Main.getGame().getWorld()).getY(), Camera.getPlayerRaycast().getBlock(Main.getGame().getWorld()).getZ()); + if(Camera.getPlayerRaycast().getBlock(GameEngine.getGame().getWorld()).x < 0)nx = true; + if(Camera.getPlayerRaycast().getBlock(GameEngine.getGame().getWorld()).y < 0)ny = true; + if(Camera.getPlayerRaycast().getBlock(GameEngine.getGame().getWorld()).z < 0)nz = true; + selectedBlock = GameEngine.getGame().getWorld().getBlock((int)Camera.getPlayerRaycast().getBlock(GameEngine.getGame().getWorld()).getX(), (int)Camera.getPlayerRaycast().getBlock(GameEngine.getGame().getWorld()).getY(), (int)Camera.getPlayerRaycast().getBlock(GameEngine.getGame().getWorld()).getZ(),nx,ny,nz); + selectedVector = new Vector3f(Camera.getPlayerRaycast().getBlock(GameEngine.getGame().getWorld()).getX(), Camera.getPlayerRaycast().getBlock(GameEngine.getGame().getWorld()).getY(), Camera.getPlayerRaycast().getBlock(GameEngine.getGame().getWorld()).getZ()); }else{ selectedBlock = null; selectedVector = null; diff --git a/VBO/src/mrdev023/world/MultiWorld.java b/VBO/src/mrdev023/world/MultiWorld.java new file mode 100644 index 0000000..46b7f8c --- /dev/null +++ b/VBO/src/mrdev023/world/MultiWorld.java @@ -0,0 +1,21 @@ +package mrdev023.world; + +public class MultiWorld extends World{ + + public MultiWorld(long seed, int octave, int amplitude) { + super(seed, octave, amplitude); + } + + @Override + public void update() { + // TODO Auto-generated method stub + + } + + @Override + public void render() { + // TODO Auto-generated method stub + + } + +} diff --git a/VBO/src/mrdev023/world/SoloWorld.java b/VBO/src/mrdev023/world/SoloWorld.java new file mode 100644 index 0000000..bfcbd41 --- /dev/null +++ b/VBO/src/mrdev023/world/SoloWorld.java @@ -0,0 +1,59 @@ +package mrdev023.world; + +import java.util.*; + +import mrdev023.rendering.*; +import mrdev023.world.chunk.*; + +public class SoloWorld extends World{ + + public SoloWorld(long seed, int octave, int amplitude) { + super(seed, octave, amplitude); + } + + public void update() { + long current = System.currentTimeMillis(); + int xa = (int)((Camera.getPosition().getX()-((float)Chunk.SIZE/2.0f))/(float)Chunk.SIZE) - VIEW_CHUNK; + int xb = (int)((Camera.getPosition().getX()-((float)Chunk.SIZE/2.0f))/(float)Chunk.SIZE) + VIEW_CHUNK; + int za = (int)((Camera.getPosition().getZ()-((float)Chunk.SIZE/2.0f))/(float)Chunk.SIZE) - VIEW_CHUNK; + int zb = (int)((Camera.getPosition().getZ()-((float)Chunk.SIZE/2.0f))/(float)Chunk.SIZE) + VIEW_CHUNK; + + int delta_x = xb - xa; + int delta_z = zb - za; + for(int i = 0; i <= delta_x;i++){ + for(int k = 0;k <= delta_z;k++){ +// for(int j = 0; j < HEIGHT; j++){ + if(getChunk((xa + i), 0, (za + k)) != null)continue; + Chunk ch = new Chunk((xa + i),0,(za + k),this); + chunks.add(ch); +// } + } + } + ArrayList removeList = new ArrayList(); + for(int i = 0; i < chunks.size();i++){ + Chunk c = chunks.get(i); + if(c.getPosition().getX() < xa || c.getPosition().getX() > xb || c.getPosition().getZ() < za || c.getPosition().getZ() > zb){ + c.destroyChunk(); + removeList.add(c); + }else{ + if(!c.isLoaded() && !c.isGenerated() && !c.isCurrentGenerate() && !c.isDestroy())c.createChunk(this); + if(!c.isLoaded() && c.isGenerated() && !c.isDestroy())c.loadBufferData(); + if(!c.isDestroy())c.update(); + } + } + for(Chunk c: removeList){ + removeByChunk(c); + } + removeList.clear(); + updateWorldTime = System.currentTimeMillis() - current; + } + + public void render() { + for(Chunk c : chunks){ + if(c.isLoaded()){ + c.render(); + } + } + } + +} diff --git a/VBO/src/world/World.java b/VBO/src/mrdev023/world/World.java similarity index 64% rename from VBO/src/world/World.java rename to VBO/src/mrdev023/world/World.java index 0fc8235..e4eee2d 100644 --- a/VBO/src/world/World.java +++ b/VBO/src/mrdev023/world/World.java @@ -1,14 +1,15 @@ -package world; +package mrdev023.world; import static org.lwjgl.opengl.GL11.*; -import game.*; import java.util.*; -import math.*; -import blocks.*; +import mrdev023.blocks.*; +import mrdev023.math.*; +import mrdev023.rendering.*; +import mrdev023.world.chunk.*; -public class World { +public abstract class World { public long seed; public int octave,amplitude; @@ -34,50 +35,9 @@ public class World { } public static long updateWorldTime = 0; - public void update(){ - long current = System.currentTimeMillis(); - int xa = (int)((Camera.getPosition().getX()-((float)Chunk.SIZE/2.0f))/(float)Chunk.SIZE) - VIEW_CHUNK; - int xb = (int)((Camera.getPosition().getX()-((float)Chunk.SIZE/2.0f))/(float)Chunk.SIZE) + VIEW_CHUNK; - int za = (int)((Camera.getPosition().getZ()-((float)Chunk.SIZE/2.0f))/(float)Chunk.SIZE) - VIEW_CHUNK; - int zb = (int)((Camera.getPosition().getZ()-((float)Chunk.SIZE/2.0f))/(float)Chunk.SIZE) + VIEW_CHUNK; - - int delta_x = xb - xa; - int delta_z = zb - za; - for(int i = 0; i <= delta_x;i++){ - for(int k = 0;k <= delta_z;k++){ -// for(int j = 0; j < HEIGHT; j++){ - if(getChunk((xa + i), 0, (za + k)) != null)continue; - Chunk ch = new Chunk((xa + i),0,(za + k),this); - chunks.add(ch); -// } - } - } - ArrayList removeList = new ArrayList(); - for(int i = 0; i < chunks.size();i++){ - Chunk c = chunks.get(i); - if(c.getPosition().getX() < xa || c.getPosition().getX() > xb || c.getPosition().getZ() < za || c.getPosition().getZ() > zb){ - c.destroyChunk(); - removeList.add(c); - }else{ - if(!c.isLoaded() && !c.isGenerated() && !c.isCurrentGenerate() && !c.isDestroy())c.createChunk(this); - if(!c.isLoaded() && c.isGenerated() && !c.isDestroy())c.loadBufferData(); - if(!c.isDestroy())c.update(); - } - } - for(Chunk c: removeList){ - removeByChunk(c); - } - removeList.clear(); - updateWorldTime = System.currentTimeMillis() - current; - } - public void render(){ - for(Chunk c : chunks){ - if(c.isLoaded()){ - c.render(); - } - } - } + public abstract void update(); + public abstract void render(); public void renderPoints(Vector2f... a){ glPointSize(10); @@ -213,6 +173,12 @@ public class World { return VIEW_CHUNK; } - + public void destroyWorld(){ + for(Chunk c : chunks){ + c.destroyChunk(); + c = null; + } + chunks.clear(); + } } diff --git a/VBO/src/world/Chunk.java b/VBO/src/mrdev023/world/chunk/Chunk.java similarity index 67% rename from VBO/src/world/Chunk.java rename to VBO/src/mrdev023/world/chunk/Chunk.java index f9e4641..9df6b5d 100644 --- a/VBO/src/world/Chunk.java +++ b/VBO/src/mrdev023/world/chunk/Chunk.java @@ -1,15 +1,11 @@ -package world; +package mrdev023.world.chunk; -import game.*; - -import java.util.*; -import java.util.concurrent.*; - -import vanilla.java.affinity.*; -import world.trees.*; -import blocks.*; -import main.*; -import math.*; +import mrdev023.blocks.*; +import mrdev023.gameEngine.*; +import mrdev023.main.*; +import mrdev023.math.*; +import mrdev023.rendering.*; +import mrdev023.world.*; public class Chunk { @@ -102,7 +98,7 @@ public class Chunk { } public void loopChunk(int x, int y, int z) { - world = Main.getGame().getWorld(); + world = GameEngine.getGame().getWorld(); int xx = this.x * SIZE + x; int yy = this.y * SIZE + y; int zz = this.z * SIZE + z; @@ -297,95 +293,4 @@ public class Chunk { } -} - -class Generate implements Runnable { - - private Chunk chunk; - private World world; - - public Generate(Chunk chunk, World world) { - this.chunk = chunk; - this.world = world; - } - - /* - * boolean grounded = noise.getNoise(xx, zz) > yy - 1 && noise.getNoise(xx, zz) < yy; - - float percentOfSpawnTree = 0.005f; - if(random.nextFloat() < percentOfSpawnTree && grounded){ - if(random.nextInt(2) == 0) - Tree.addOak(world, xx, yy, zz); - else - Tree.addFir(world, xx, yy, zz); - }(non-Javadoc) - * @see java.lang.Runnable#run() - */ - - public void run() { - long current = System.currentTimeMillis(); - long elapsed1 = 0; - boolean IsError = true; - Noise noise = new Noise(world.seed, world.octave, world.amplitude);; - Random random = new Random(world.seed); - Noise colorVariationNoise = new Noise(world.seed,world.octave,2); - for (int x = 0; x < chunk.SIZE; x++) { - for (int z = 0; z < chunk.SIZE; z++) { - int xa = (int)((Camera.getPosition().getX()-((float)Chunk.SIZE/2.0f))/(float)Chunk.SIZE) - World.VIEW_CHUNK; - int xb = (int)((Camera.getPosition().getX()-((float)Chunk.SIZE/2.0f))/(float)Chunk.SIZE) + World.VIEW_CHUNK; - int za = (int)((Camera.getPosition().getZ()-((float)Chunk.SIZE/2.0f))/(float)Chunk.SIZE) - World.VIEW_CHUNK; - int zb = (int)((Camera.getPosition().getZ()-((float)Chunk.SIZE/2.0f))/(float)Chunk.SIZE) + World.VIEW_CHUNK; - if(chunk.getX() < xa || chunk.getX() > xb || chunk.getZ() < za || chunk.getZ() > zb ){ - System.out.println(Thread.currentThread().getName() + " stopped | " + (System.currentTimeMillis()-current)); - Thread.currentThread().stop(); - return; - } - int xx = chunk.getX() * chunk.SIZE + x; - int zz = chunk.getZ() * chunk.SIZE + z; - - - Color4f green = new Color4f(0.2f,0.6f,0); - Color4f yellow = new Color4f(0.36f,0.77f,0.17f); - float v = colorVariationNoise.getNoise(xx, zz); - - Color4f finalColor = Color4f.interpolate(yellow, green, v); - - chunk.blocks[x][(int)noise.getNoise(xx, zz)][z] = new GrassBlock().setColor(finalColor); - - } - } - elapsed1 = System.currentTimeMillis() - current; - while(IsError){ - IsError = false; - try{ -// synchronized (world.chunks) { - for (int i = 0; i < chunk.SIZE; i++) { -// for (int j = 0; j < chunk.SIZE; j++) { - for (int k = 0; k < chunk.SIZE; k++) { - int xa = (int)((Camera.getPosition().getX()-((float)Chunk.SIZE/2.0f))/(float)Chunk.SIZE) - World.VIEW_CHUNK; - int xb = (int)((Camera.getPosition().getX()-((float)Chunk.SIZE/2.0f))/(float)Chunk.SIZE) + World.VIEW_CHUNK; - int za = (int)((Camera.getPosition().getZ()-((float)Chunk.SIZE/2.0f))/(float)Chunk.SIZE) - World.VIEW_CHUNK; - int zb = (int)((Camera.getPosition().getZ()-((float)Chunk.SIZE/2.0f))/(float)Chunk.SIZE) + World.VIEW_CHUNK; - if(chunk.getX() < xa || chunk.getX() > xb || chunk.getZ() < za || chunk.getZ() > zb ){ - System.out.println(Thread.currentThread().getName() + " stopped | " + (System.currentTimeMillis()-current)); - Thread.currentThread().stop(); - return; - } - int xx = chunk.getX() * chunk.SIZE + i; - int zz = chunk.getZ() * chunk.SIZE + k; - chunk.loopChunk(i, (int)noise.getNoise(xx, zz), k); - } -// } - } -// } - chunk.setGenerated(true); - }catch (Exception e){ - e.printStackTrace(); - IsError = true; - } - } - System.out.println(Thread.currentThread().getName() + " terminated | loop1:" + elapsed1 + "ms loop2:" + (System.currentTimeMillis()-current) + "ms"); - Thread.currentThread().stop(); - } - -} +} \ No newline at end of file diff --git a/VBO/src/mrdev023/world/chunk/Generate.java b/VBO/src/mrdev023/world/chunk/Generate.java new file mode 100644 index 0000000..816a557 --- /dev/null +++ b/VBO/src/mrdev023/world/chunk/Generate.java @@ -0,0 +1,100 @@ +package mrdev023.world.chunk; + +import java.util.*; + +import mrdev023.blocks.*; +import mrdev023.math.*; +import mrdev023.rendering.*; +import mrdev023.world.*; +import mrdev023.world.chunk.*; + +class Generate implements Runnable { + + private Chunk chunk; + private World world; + + public Generate(Chunk chunk, World world) { + this.chunk = chunk; + this.world = world; + } + + /* + * boolean grounded = noise.getNoise(xx, zz) > yy - 1 && noise.getNoise(xx, zz) < yy; + + float percentOfSpawnTree = 0.005f; + if(random.nextFloat() < percentOfSpawnTree && grounded){ + if(random.nextInt(2) == 0) + Tree.addOak(world, xx, yy, zz); + else + Tree.addFir(world, xx, yy, zz); + }(non-Javadoc) + * @see java.lang.Runnable#run() + */ + + public void run() { + long current = System.currentTimeMillis(); + long elapsed1 = 0; + boolean IsError = true; + Noise noise = new Noise(world.seed, world.octave, world.amplitude);; + Random random = new Random(world.seed); + Noise colorVariationNoise = new Noise(world.seed,world.octave,2); + for (int x = 0; x < chunk.SIZE; x++) { + for (int z = 0; z < chunk.SIZE; z++) { + int xa = (int)((Camera.getPosition().getX()-((float)Chunk.SIZE/2.0f))/(float)Chunk.SIZE) - World.VIEW_CHUNK; + int xb = (int)((Camera.getPosition().getX()-((float)Chunk.SIZE/2.0f))/(float)Chunk.SIZE) + World.VIEW_CHUNK; + int za = (int)((Camera.getPosition().getZ()-((float)Chunk.SIZE/2.0f))/(float)Chunk.SIZE) - World.VIEW_CHUNK; + int zb = (int)((Camera.getPosition().getZ()-((float)Chunk.SIZE/2.0f))/(float)Chunk.SIZE) + World.VIEW_CHUNK; + if(chunk.getX() < xa || chunk.getX() > xb || chunk.getZ() < za || chunk.getZ() > zb ){ + System.out.println(Thread.currentThread().getName() + " stopped | " + (System.currentTimeMillis()-current)); + Thread.currentThread().stop(); + return; + } + int xx = chunk.getX() * chunk.SIZE + x; + int zz = chunk.getZ() * chunk.SIZE + z; + + + Color4f green = new Color4f(0.2f,0.6f,0); + Color4f yellow = new Color4f(0.36f,0.77f,0.17f); + float v = colorVariationNoise.getNoise(xx, zz); + + Color4f finalColor = Color4f.interpolate(yellow, green, v); + + chunk.blocks[x][(int)noise.getNoise(xx, zz)][z] = new GrassBlock().setColor(finalColor); + + } + } + elapsed1 = System.currentTimeMillis() - current; + while(IsError){ + IsError = false; + try{ +// synchronized (world.chunks) { + for (int i = 0; i < chunk.SIZE; i++) { +// for (int j = 0; j < chunk.SIZE; j++) { + for (int k = 0; k < chunk.SIZE; k++) { + int xa = (int)((Camera.getPosition().getX()-((float)Chunk.SIZE/2.0f))/(float)Chunk.SIZE) - World.VIEW_CHUNK; + int xb = (int)((Camera.getPosition().getX()-((float)Chunk.SIZE/2.0f))/(float)Chunk.SIZE) + World.VIEW_CHUNK; + int za = (int)((Camera.getPosition().getZ()-((float)Chunk.SIZE/2.0f))/(float)Chunk.SIZE) - World.VIEW_CHUNK; + int zb = (int)((Camera.getPosition().getZ()-((float)Chunk.SIZE/2.0f))/(float)Chunk.SIZE) + World.VIEW_CHUNK; + if(chunk.getX() < xa || chunk.getX() > xb || chunk.getZ() < za || chunk.getZ() > zb ){ + System.out.println(Thread.currentThread().getName() + " stopped | " + (System.currentTimeMillis()-current)); + Thread.currentThread().stop(); + return; + } + int xx = chunk.getX() * chunk.SIZE + i; + int zz = chunk.getZ() * chunk.SIZE + k; + chunk.loopChunk(i, (int)noise.getNoise(xx, zz), k); + } +// } + } +// } + chunk.setGenerated(true); + }catch (Exception e){ + e.printStackTrace(); + IsError = true; + } + } + System.out.println(Thread.currentThread().getName() + " terminated | loop1:" + elapsed1 + "ms loop2:" + (System.currentTimeMillis()-current) + "ms"); + Thread.currentThread().stop(); + } + +} diff --git a/VBO/src/world/Noise.java b/VBO/src/mrdev023/world/chunk/Noise.java similarity index 91% rename from VBO/src/world/Noise.java rename to VBO/src/mrdev023/world/chunk/Noise.java index 0160684..aa1f983 100644 --- a/VBO/src/world/Noise.java +++ b/VBO/src/mrdev023/world/chunk/Noise.java @@ -1,8 +1,8 @@ -package world; +package mrdev023.world.chunk; -import java.util.Random; +import java.util.*; -import math.Vector2f; +import mrdev023.math.*; public class Noise { diff --git a/VBO/src/world/trees/Tree.java b/VBO/src/mrdev023/world/trees/Tree.java similarity index 89% rename from VBO/src/world/trees/Tree.java rename to VBO/src/mrdev023/world/trees/Tree.java index f79ef97..f6df071 100644 --- a/VBO/src/world/trees/Tree.java +++ b/VBO/src/mrdev023/world/trees/Tree.java @@ -1,7 +1,7 @@ -package world.trees; +package mrdev023.world.trees; -import world.*; -import blocks.*; +import mrdev023.blocks.*; +import mrdev023.world.*; public class Tree {