Update
This commit is contained in:
parent
d6b9d09d50
commit
1e19b37301
32 changed files with 457 additions and 292 deletions
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,12 +1,9 @@
|
||||||
package blocks;
|
package mrdev023.blocks;
|
||||||
|
|
||||||
|
import mrdev023.math.*;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import math.Color4f;
|
|
||||||
import math.Vector3f;
|
|
||||||
|
|
||||||
|
|
||||||
public abstract class Block {
|
public abstract class Block {
|
||||||
|
|
||||||
public static final Block OAK_WOOD = new OakWoodBlock(),
|
public static final Block OAK_WOOD = new OakWoodBlock(),
|
|
@ -1,6 +1,6 @@
|
||||||
package blocks;
|
package mrdev023.blocks;
|
||||||
|
|
||||||
import math.Color4f;
|
import mrdev023.math.*;
|
||||||
|
|
||||||
public class FirLeafBlock extends Block{
|
public class FirLeafBlock extends Block{
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package blocks;
|
package mrdev023.blocks;
|
||||||
|
|
||||||
import math.Color4f;
|
import mrdev023.math.*;
|
||||||
|
|
||||||
public class FirWoodBlock extends WoodBlock{
|
public class FirWoodBlock extends WoodBlock{
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package blocks;
|
package mrdev023.blocks;
|
||||||
|
|
||||||
import math.Color4f;
|
import mrdev023.math.*;
|
||||||
|
|
||||||
public class GrassBlock extends Block{
|
public class GrassBlock extends Block{
|
||||||
public GrassBlock() {
|
public GrassBlock() {
|
|
@ -1,6 +1,6 @@
|
||||||
package blocks;
|
package mrdev023.blocks;
|
||||||
|
|
||||||
import math.Color4f;
|
import mrdev023.math.*;
|
||||||
|
|
||||||
public class LeafBlock extends Block{
|
public class LeafBlock extends Block{
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package blocks;
|
package mrdev023.blocks;
|
||||||
|
|
||||||
import math.*;
|
import mrdev023.math.*;
|
||||||
|
|
||||||
public class OakWoodBlock extends WoodBlock{
|
public class OakWoodBlock extends WoodBlock{
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package blocks;
|
package mrdev023.blocks;
|
||||||
|
|
||||||
import math.Color4f;
|
import mrdev023.math.*;
|
||||||
|
|
||||||
public class TransparentBlock extends Block {
|
public class TransparentBlock extends Block {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package blocks;
|
package mrdev023.blocks;
|
||||||
|
|
||||||
import math.Color4f;
|
import mrdev023.math.*;
|
||||||
|
|
||||||
public class WoodBlock extends Block{
|
public class WoodBlock extends Block{
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
package game;
|
package mrdev023.entity;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import math.*;
|
import mrdev023.math.*;
|
||||||
import world.*;
|
import mrdev023.rendering.*;
|
||||||
|
import mrdev023.world.*;
|
||||||
|
|
||||||
public class PlayerRayCast {
|
public class PlayerRayCast {
|
||||||
|
|
39
VBO/src/mrdev023/game/Game.java
Normal file
39
VBO/src/mrdev023/game/Game.java
Normal file
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
27
VBO/src/mrdev023/game/MultiGame.java
Normal file
27
VBO/src/mrdev023/game/MultiGame.java
Normal file
|
@ -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() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
27
VBO/src/mrdev023/game/SoloGame.java
Normal file
27
VBO/src/mrdev023/game/SoloGame.java
Normal file
|
@ -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() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
13
VBO/src/mrdev023/game/gamestate/GameState.java
Normal file
13
VBO/src/mrdev023/game/gamestate/GameState.java
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
package mrdev023.game.gamestate;
|
||||||
|
|
||||||
|
public enum GameState {
|
||||||
|
|
||||||
|
MAIN_MENU,SOLO_GAME,MULTI_GAME,OPTION_GAME,ABOUT_GAME;
|
||||||
|
|
||||||
|
GameState(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -1,15 +1,17 @@
|
||||||
package main;
|
package mrdev023.gameEngine;
|
||||||
|
|
||||||
import game.*;
|
|
||||||
|
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
|
|
||||||
import org.lwjgl.input.*;
|
import org.lwjgl.input.*;
|
||||||
import org.lwjgl.opengl.*;
|
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 boolean IsRunning = true;
|
||||||
private static long current = System.currentTimeMillis(),current2, elapsedInfo = 0,
|
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 String TITLE = "Test VBO";
|
||||||
private static final int width = 1280, height = 720;
|
private static final int width = 1280, height = 720;
|
||||||
|
|
||||||
|
|
||||||
// private static AffinityLock al;
|
|
||||||
public static ExecutorService mainPool;
|
|
||||||
|
|
||||||
private static Game game;
|
private static Game game;
|
||||||
|
|
||||||
/**
|
public static void initWindow(){
|
||||||
* @param args
|
Main.mainPool = Executors.newWorkStealingPool();
|
||||||
* @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())
|
|
||||||
try {
|
try {
|
||||||
Display.setTitle(TITLE);
|
Display.setTitle(TITLE);
|
||||||
Display.setDisplayMode(new DisplayMode(width, height));
|
Display.setDisplayMode(new DisplayMode(width, height));
|
||||||
Display.setResizable(true);
|
Display.setResizable(true);
|
||||||
Display.create();
|
Display.create();
|
||||||
Camera.initCamera();
|
Camera.initCamera();
|
||||||
game = new Game();
|
game = new SoloGame();
|
||||||
Mouse.setGrabbed(true);
|
Mouse.setGrabbed(true);
|
||||||
loop();
|
loop();
|
||||||
} catch (Exception e) {
|
} 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
|
* @Info Boucle principal avec Timer
|
||||||
*/
|
*/
|
||||||
|
@ -112,6 +94,12 @@ public class Main {
|
||||||
|
|
||||||
Display.update();
|
Display.update();
|
||||||
}
|
}
|
||||||
|
destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void destroy(){
|
||||||
|
game.destroyGame();
|
||||||
|
Display.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getStringByNoString(Object... a){
|
public static String getStringByNoString(Object... a){
|
||||||
|
@ -184,4 +172,5 @@ public class Main {
|
||||||
return game;
|
return game;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
43
VBO/src/mrdev023/main/Main.java
Normal file
43
VBO/src/mrdev023/main/Main.java
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package math;
|
package mrdev023.math;
|
||||||
|
|
||||||
public class Color4f {
|
public class Color4f {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package math;
|
package mrdev023.math;
|
||||||
|
|
||||||
|
|
||||||
public class Vector2f {
|
public class Vector2f {
|
|
@ -1,4 +1,4 @@
|
||||||
package math;
|
package mrdev023.math;
|
||||||
|
|
||||||
|
|
||||||
public class Vector3f {
|
public class Vector3f {
|
5
VBO/src/mrdev023/network/Client.java
Normal file
5
VBO/src/mrdev023/network/Client.java
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
package mrdev023.network;
|
||||||
|
|
||||||
|
public class Client {
|
||||||
|
|
||||||
|
}
|
|
@ -1,10 +1,13 @@
|
||||||
package game;
|
package mrdev023.rendering;
|
||||||
|
|
||||||
import static org.lwjgl.opengl.GL11.*;
|
import static org.lwjgl.opengl.GL11.*;
|
||||||
import world.*;
|
import mrdev023.blocks.*;
|
||||||
import blocks.*;
|
import mrdev023.entity.*;
|
||||||
import main.*;
|
import mrdev023.gameEngine.*;
|
||||||
import math.*;
|
import mrdev023.main.*;
|
||||||
|
import mrdev023.math.*;
|
||||||
|
import mrdev023.world.*;
|
||||||
|
import mrdev023.world.chunk.*;
|
||||||
|
|
||||||
public class Camera {
|
public class Camera {
|
||||||
|
|
||||||
|
@ -22,14 +25,14 @@ public class Camera {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void renderCamera() {
|
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,
|
.getGame().getWorld().octave,
|
||||||
Main.getGame().getWorld().amplitude).getNoise(position.getX(),
|
GameEngine.getGame().getWorld().amplitude).getNoise(position.getX(),
|
||||||
position.getZ())) + 1)) {
|
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,
|
.getGame().getWorld().octave,
|
||||||
Main.getGame().getWorld().amplitude).getNoise(position.getX(),
|
GameEngine.getGame().getWorld().amplitude).getNoise(position.getX(),
|
||||||
position.getZ())) + 2));
|
position.getZ())) + 2));
|
||||||
}
|
}
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
@ -116,7 +119,7 @@ public class Camera {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isColliding(float xa, float ya, float za) {
|
public static boolean isColliding(float xa, float ya, float za) {
|
||||||
World world = Main.getGame().getWorld();
|
World world = GameEngine.getGame().getWorld();
|
||||||
float r = 0.3f;
|
float r = 0.3f;
|
||||||
|
|
||||||
boolean nx = false, ny = false, nz = false;
|
boolean nx = false, ny = false, nz = false;
|
|
@ -1,9 +1,9 @@
|
||||||
package game;
|
package mrdev023.rendering;
|
||||||
import static org.lwjgl.opengl.GL11.*;
|
import static org.lwjgl.opengl.GL11.*;
|
||||||
import static org.lwjgl.util.glu.GLU.*;
|
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.opengl.*;
|
||||||
import org.lwjgl.util.glu.*;
|
import org.lwjgl.util.glu.*;
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ public class DisplayManager {
|
||||||
* @Info Fait le rendu 3d
|
* @Info Fait le rendu 3d
|
||||||
*/
|
*/
|
||||||
public static void render3D(){
|
public static void render3D(){
|
||||||
Main.getGame().render();
|
GameEngine.getGame().render();
|
||||||
if(Update.getSelectedBlock() != null && Update.getSelectedVector() !=null){
|
if(Update.getSelectedBlock() != null && Update.getSelectedVector() !=null){
|
||||||
renderBlock((int)Update.getSelectedVector().x,(int)Update.getSelectedVector().y,(int)Update.getSelectedVector().z);
|
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
|
* @Info Fait le rendu 2d
|
||||||
*/
|
*/
|
||||||
public static void render2D(){
|
public static void render2D(){
|
||||||
Main.getGame().renderGUI();
|
GameEngine.getGame().renderGUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
|
@ -1,4 +1,4 @@
|
||||||
package game;
|
package mrdev023.rendering;
|
||||||
import static org.lwjgl.opengl.GL11.*;
|
import static org.lwjgl.opengl.GL11.*;
|
||||||
import static org.lwjgl.opengl.GL15.*;
|
import static org.lwjgl.opengl.GL15.*;
|
||||||
import static org.lwjgl.opengl.GL20.*;
|
import static org.lwjgl.opengl.GL20.*;
|
||||||
|
@ -15,6 +15,7 @@ public class VBO {
|
||||||
private int vboID = 0;
|
private int vboID = 0;
|
||||||
private FloatBuffer buffer;
|
private FloatBuffer buffer;
|
||||||
private ArrayList<Float> floatlist = new ArrayList<Float>();
|
private ArrayList<Float> floatlist = new ArrayList<Float>();
|
||||||
|
private static final int FLOAT_SIZE = 4;
|
||||||
|
|
||||||
public VBO(){
|
public VBO(){
|
||||||
this.vboID = createVBO();
|
this.vboID = createVBO();
|
||||||
|
@ -88,8 +89,14 @@ public class VBO {
|
||||||
glEnableClientState(GL_VERTEX_ARRAY);
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
glEnableClientState(GL_COLOR_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(0,3,GL_FLOAT,false,7 * 4,0);
|
||||||
// glVertexAttribPointer(1,4,GL_FLOAT,false,7 * 4,12);
|
// glVertexAttribPointer(1,4,GL_FLOAT,false,7 * 4,12);
|
9
VBO/src/mrdev023/server/Server.java
Normal file
9
VBO/src/mrdev023/server/Server.java
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
package mrdev023.server;
|
||||||
|
|
||||||
|
public class Server {
|
||||||
|
|
||||||
|
public static void initServer(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,12 +1,13 @@
|
||||||
package game;
|
package mrdev023.update;
|
||||||
import main.*;
|
import mrdev023.blocks.*;
|
||||||
import math.*;
|
import mrdev023.gameEngine.*;
|
||||||
|
import mrdev023.main.*;
|
||||||
|
import mrdev023.math.*;
|
||||||
|
import mrdev023.rendering.*;
|
||||||
|
|
||||||
import org.lwjgl.input.*;
|
import org.lwjgl.input.*;
|
||||||
import org.lwjgl.opengl.*;
|
import org.lwjgl.opengl.*;
|
||||||
|
|
||||||
import blocks.*;
|
|
||||||
|
|
||||||
|
|
||||||
public class Update {
|
public class Update {
|
||||||
|
|
||||||
|
@ -45,7 +46,7 @@ public class Update {
|
||||||
while(Keyboard.next()){
|
while(Keyboard.next()){
|
||||||
if(Keyboard.getEventKeyState()){
|
if(Keyboard.getEventKeyState()){
|
||||||
if(Keyboard.getEventKey() == Keyboard.KEY_ESCAPE){
|
if(Keyboard.getEventKey() == Keyboard.KEY_ESCAPE){
|
||||||
Main.setRunning(false);
|
GameEngine.setRunning(false);
|
||||||
}
|
}
|
||||||
if(Keyboard.getEventKey() == Keyboard.KEY_F2){
|
if(Keyboard.getEventKey() == Keyboard.KEY_F2){
|
||||||
Mouse.setGrabbed(!Mouse.isGrabbed());
|
Mouse.setGrabbed(!Mouse.isGrabbed());
|
||||||
|
@ -110,7 +111,7 @@ public class Update {
|
||||||
za *= 0.9f;
|
za *= 0.9f;
|
||||||
|
|
||||||
if(Display.isCloseRequested()){
|
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
|
* @Info Fonction de mettre a jour le display et d'autre choses predefinie
|
||||||
*/
|
*/
|
||||||
public static void update(){
|
public static void update(){
|
||||||
Main.getGame().update();
|
GameEngine.getGame().update();
|
||||||
Camera.getPlayerRaycast().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;
|
boolean nx = false, ny = false, nz = false;
|
||||||
if(Camera.getPlayerRaycast().getBlock(Main.getGame().getWorld()).x < 0)nx = true;
|
if(Camera.getPlayerRaycast().getBlock(GameEngine.getGame().getWorld()).x < 0)nx = true;
|
||||||
if(Camera.getPlayerRaycast().getBlock(Main.getGame().getWorld()).y < 0)ny = true;
|
if(Camera.getPlayerRaycast().getBlock(GameEngine.getGame().getWorld()).y < 0)ny = true;
|
||||||
if(Camera.getPlayerRaycast().getBlock(Main.getGame().getWorld()).z < 0)nz = true;
|
if(Camera.getPlayerRaycast().getBlock(GameEngine.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);
|
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(Main.getGame().getWorld()).getX(), Camera.getPlayerRaycast().getBlock(Main.getGame().getWorld()).getY(), Camera.getPlayerRaycast().getBlock(Main.getGame().getWorld()).getZ());
|
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{
|
}else{
|
||||||
selectedBlock = null;
|
selectedBlock = null;
|
||||||
selectedVector = null;
|
selectedVector = null;
|
21
VBO/src/mrdev023/world/MultiWorld.java
Normal file
21
VBO/src/mrdev023/world/MultiWorld.java
Normal file
|
@ -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
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
59
VBO/src/mrdev023/world/SoloWorld.java
Normal file
59
VBO/src/mrdev023/world/SoloWorld.java
Normal file
|
@ -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<Chunk> removeList = new ArrayList<Chunk>();
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,14 +1,15 @@
|
||||||
package world;
|
package mrdev023.world;
|
||||||
|
|
||||||
import static org.lwjgl.opengl.GL11.*;
|
import static org.lwjgl.opengl.GL11.*;
|
||||||
import game.*;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import math.*;
|
import mrdev023.blocks.*;
|
||||||
import blocks.*;
|
import mrdev023.math.*;
|
||||||
|
import mrdev023.rendering.*;
|
||||||
|
import mrdev023.world.chunk.*;
|
||||||
|
|
||||||
public class World {
|
public abstract class World {
|
||||||
|
|
||||||
public long seed;
|
public long seed;
|
||||||
public int octave,amplitude;
|
public int octave,amplitude;
|
||||||
|
@ -34,50 +35,9 @@ public class World {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long updateWorldTime = 0;
|
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<Chunk> removeList = new ArrayList<Chunk>();
|
|
||||||
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(){
|
public abstract void update();
|
||||||
for(Chunk c : chunks){
|
public abstract void render();
|
||||||
if(c.isLoaded()){
|
|
||||||
c.render();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void renderPoints(Vector2f... a){
|
public void renderPoints(Vector2f... a){
|
||||||
glPointSize(10);
|
glPointSize(10);
|
||||||
|
@ -213,6 +173,12 @@ public class World {
|
||||||
return VIEW_CHUNK;
|
return VIEW_CHUNK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void destroyWorld(){
|
||||||
|
for(Chunk c : chunks){
|
||||||
|
c.destroyChunk();
|
||||||
|
c = null;
|
||||||
|
}
|
||||||
|
chunks.clear();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,15 +1,11 @@
|
||||||
package world;
|
package mrdev023.world.chunk;
|
||||||
|
|
||||||
import game.*;
|
import mrdev023.blocks.*;
|
||||||
|
import mrdev023.gameEngine.*;
|
||||||
import java.util.*;
|
import mrdev023.main.*;
|
||||||
import java.util.concurrent.*;
|
import mrdev023.math.*;
|
||||||
|
import mrdev023.rendering.*;
|
||||||
import vanilla.java.affinity.*;
|
import mrdev023.world.*;
|
||||||
import world.trees.*;
|
|
||||||
import blocks.*;
|
|
||||||
import main.*;
|
|
||||||
import math.*;
|
|
||||||
|
|
||||||
public class Chunk {
|
public class Chunk {
|
||||||
|
|
||||||
|
@ -102,7 +98,7 @@ public class Chunk {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loopChunk(int x, int y, int z) {
|
public void loopChunk(int x, int y, int z) {
|
||||||
world = Main.getGame().getWorld();
|
world = GameEngine.getGame().getWorld();
|
||||||
int xx = this.x * SIZE + x;
|
int xx = this.x * SIZE + x;
|
||||||
int yy = this.y * SIZE + y;
|
int yy = this.y * SIZE + y;
|
||||||
int zz = this.z * SIZE + z;
|
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
100
VBO/src/mrdev023/world/chunk/Generate.java
Normal file
100
VBO/src/mrdev023/world/chunk/Generate.java
Normal file
|
@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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 {
|
public class Noise {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package world.trees;
|
package mrdev023.world.trees;
|
||||||
|
|
||||||
import world.*;
|
import mrdev023.blocks.*;
|
||||||
import blocks.*;
|
import mrdev023.world.*;
|
||||||
|
|
||||||
|
|
||||||
public class Tree {
|
public class Tree {
|
Reference in a new issue