1
0
Fork 0
This commit is contained in:
MrDev023 2015-07-21 14:29:39 +02:00
parent d6b9d09d50
commit 1e19b37301
32 changed files with 457 additions and 292 deletions

View file

@ -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;
}
}

View file

@ -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(),

View file

@ -1,6 +1,6 @@
package blocks;
package mrdev023.blocks;
import math.Color4f;
import mrdev023.math.*;
public class FirLeafBlock extends Block{

View file

@ -1,6 +1,6 @@
package blocks;
package mrdev023.blocks;
import math.Color4f;
import mrdev023.math.*;
public class FirWoodBlock extends WoodBlock{

View file

@ -1,6 +1,6 @@
package blocks;
package mrdev023.blocks;
import math.Color4f;
import mrdev023.math.*;
public class GrassBlock extends Block{
public GrassBlock() {

View file

@ -1,6 +1,6 @@
package blocks;
package mrdev023.blocks;
import math.Color4f;
import mrdev023.math.*;
public class LeafBlock extends Block{

View file

@ -1,6 +1,6 @@
package blocks;
package mrdev023.blocks;
import math.*;
import mrdev023.math.*;
public class OakWoodBlock extends WoodBlock{

View file

@ -1,6 +1,6 @@
package blocks;
package mrdev023.blocks;
import math.Color4f;
import mrdev023.math.*;
public class TransparentBlock extends Block {

View file

@ -1,6 +1,6 @@
package blocks;
package mrdev023.blocks;
import math.Color4f;
import mrdev023.math.*;
public class WoodBlock extends Block{

View file

@ -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 {

View 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();
}
}

View 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() {
}
}

View 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() {
}
}

View file

@ -0,0 +1,13 @@
package mrdev023.game.gamestate;
public enum GameState {
MAIN_MENU,SOLO_GAME,MULTI_GAME,OPTION_GAME,ABOUT_GAME;
GameState(){
}
}

View file

@ -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;
}
}

View 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;
}
}

View file

@ -1,4 +1,4 @@
package math;
package mrdev023.math;
public class Color4f {

View file

@ -1,4 +1,4 @@
package math;
package mrdev023.math;
public class Vector2f {

View file

@ -1,4 +1,4 @@
package math;
package mrdev023.math;
public class Vector3f {

View file

@ -0,0 +1,5 @@
package mrdev023.network;
public class Client {
}

View file

@ -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;

View file

@ -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();
}
/**

View file

@ -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<Float> floatlist = new ArrayList<Float>();
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);

View file

@ -0,0 +1,9 @@
package mrdev023.server;
public class Server {
public static void initServer(){
}
}

View file

@ -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;

View 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
}
}

View 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();
}
}
}
}

View file

@ -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<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();
}
}
}
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();
}
}

View file

@ -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();
}
}
}

View 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();
}
}

View file

@ -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 {

View file

@ -1,7 +1,7 @@
package world.trees;
package mrdev023.world.trees;
import world.*;
import blocks.*;
import mrdev023.blocks.*;
import mrdev023.world.*;
public class Tree {