Upgrade chunk performance
This commit is contained in:
parent
64b1ab1c6d
commit
521e58acb9
5 changed files with 155 additions and 181 deletions
|
@ -10,11 +10,12 @@ import org.lwjgl.opengl.*;
|
||||||
import rendering.*;
|
import rendering.*;
|
||||||
import vanilla.java.affinity.*;
|
import vanilla.java.affinity.*;
|
||||||
import vanilla.java.affinity.impl.*;
|
import vanilla.java.affinity.impl.*;
|
||||||
|
import world.*;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
private static boolean IsRunning = true;
|
private static boolean IsRunning = true;
|
||||||
private static long current = System.currentTimeMillis(), elapsedInfo = 0,
|
private static long current = System.currentTimeMillis(),current2, elapsedInfo = 0,
|
||||||
elapsed = 0, previous = 0;
|
elapsed = 0, previous = 0;
|
||||||
private static long timeTicks = 0, timeFps = 0;
|
private static long timeTicks = 0, timeFps = 0;
|
||||||
private static int FPS = 0, TICKS = 0, LAST_TICKS = 60, LAST_FPS = 60;
|
private static int FPS = 0, TICKS = 0, LAST_TICKS = 60, LAST_FPS = 60;
|
||||||
|
@ -72,6 +73,7 @@ public class Main {
|
||||||
/**
|
/**
|
||||||
* @Info Boucle principal avec Timer
|
* @Info Boucle principal avec Timer
|
||||||
*/
|
*/
|
||||||
|
public static long time = 0;
|
||||||
public static void loop() {
|
public static void loop() {
|
||||||
while (IsRunning) {
|
while (IsRunning) {
|
||||||
previous = current;
|
previous = current;
|
||||||
|
@ -84,13 +86,14 @@ public class Main {
|
||||||
DisplayManager.updateDisplay();
|
DisplayManager.updateDisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
current2 = System.nanoTime();
|
||||||
if (elapsed >= 1000 / 60) {
|
if (elapsed >= 1000 / 60) {
|
||||||
Update.updateMouse();
|
Update.updateMouse();
|
||||||
Update.updateKeyboard();
|
Update.updateKeyboard();
|
||||||
Update.update();
|
Update.update();
|
||||||
TICKS++;
|
TICKS++;
|
||||||
elapsed = 0;
|
elapsed = 0;
|
||||||
timeTicks = System.currentTimeMillis() - current;
|
timeTicks = System.nanoTime() - current2;
|
||||||
} else {
|
} else {
|
||||||
DisplayManager.clearScreen();
|
DisplayManager.clearScreen();
|
||||||
DisplayManager.preRender3D();
|
DisplayManager.preRender3D();
|
||||||
|
@ -102,23 +105,25 @@ public class Main {
|
||||||
DisplayManager.preRender2D();
|
DisplayManager.preRender2D();
|
||||||
DisplayManager.render2D();
|
DisplayManager.render2D();
|
||||||
FPS++;
|
FPS++;
|
||||||
timeFps = System.currentTimeMillis() - current;
|
timeFps = System.nanoTime() - current2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (elapsedInfo >= 1000) {
|
if (elapsedInfo >= 1000) {
|
||||||
LAST_FPS = FPS;
|
LAST_FPS = FPS;
|
||||||
LAST_TICKS = TICKS;
|
LAST_TICKS = TICKS;
|
||||||
Display.setTitle(TITLE + " | FPS:" + LAST_FPS + " TICKS:"
|
Display.setTitle(TITLE + " | FPS:" + (int)(1000000000.0f/timeFps) + " TICKS:"
|
||||||
+ LAST_TICKS + " timeFps:" + timeFps + "ms timeTicks:"
|
+ (int)(1000000000.0f/timeTicks) + " timeFps:" + timeFps + "ns timeTicks:"
|
||||||
+ timeTicks + "ms" + " | PX:"
|
+ timeTicks + "ns" + " | PX:"
|
||||||
+ Camera.getPosition().getX() + " PY:"
|
+ Camera.getPosition().getX() + " PY:"
|
||||||
+ Camera.getPosition().getY() + " PZ:"
|
+ Camera.getPosition().getY() + " PZ:"
|
||||||
+ Camera.getPosition().getZ() + " | "
|
+ Camera.getPosition().getZ() + " | "
|
||||||
+ mainPool);
|
+ World.updateWorldTime + " " + DisplayManager.getDelta());
|
||||||
FPS = 0;
|
FPS = 0;
|
||||||
TICKS = 0;
|
TICKS = 0;
|
||||||
elapsedInfo = 0;
|
elapsedInfo = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Display.update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -105,7 +105,6 @@ public class Update {
|
||||||
*/
|
*/
|
||||||
public static void update(){
|
public static void update(){
|
||||||
Main.getGame().update();
|
Main.getGame().update();
|
||||||
Display.update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package main;
|
package main;
|
||||||
import static org.lwjgl.opengl.GL15.*;
|
|
||||||
import static org.lwjgl.opengl.GL11.*;
|
import static org.lwjgl.opengl.GL11.*;
|
||||||
import static org.lwjgl.opengl.GL13.*;
|
import static org.lwjgl.opengl.GL15.*;
|
||||||
import static org.lwjgl.opengl.GL20.*;
|
import static org.lwjgl.opengl.GL20.*;
|
||||||
|
|
||||||
import java.nio.*;
|
import java.nio.*;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
import org.lwjgl.*;
|
import org.lwjgl.*;
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ public class VBO {
|
||||||
private int bufferSize = 0;
|
private int bufferSize = 0;
|
||||||
private int vboID = 0;
|
private int vboID = 0;
|
||||||
private FloatBuffer buffer;
|
private FloatBuffer buffer;
|
||||||
|
private ArrayList<Float> floatlist = new ArrayList<Float>();
|
||||||
|
|
||||||
public VBO(){
|
public VBO(){
|
||||||
this.vboID = createVBO();
|
this.vboID = createVBO();
|
||||||
|
@ -40,18 +41,8 @@ public class VBO {
|
||||||
|
|
||||||
public void addDataByFloatArray(float[] a){
|
public void addDataByFloatArray(float[] a){
|
||||||
if(a == null)return;
|
if(a == null)return;
|
||||||
if(buffer != null){
|
for(float c :a){
|
||||||
int size = buffer.limit();
|
floatlist.add(c);
|
||||||
float[] previousBuffer = new float[size];
|
|
||||||
buffer.get(previousBuffer);
|
|
||||||
buffer.clear();
|
|
||||||
buffer = BufferUtils.createFloatBuffer(size + a.length);
|
|
||||||
buffer.put(previousBuffer).put(a);
|
|
||||||
buffer.flip();
|
|
||||||
}else{
|
|
||||||
buffer = BufferUtils.createFloatBuffer(a.length);
|
|
||||||
buffer.put(a);
|
|
||||||
buffer.flip();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,20 +53,11 @@ public class VBO {
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public void addDataByFloatList(float... a){
|
public void addDataByFloatList(float... a){
|
||||||
if(a == null)return;
|
if(a == null)return;
|
||||||
if(buffer != null){
|
for(float c :a){
|
||||||
int size = buffer.limit();
|
floatlist.add(c);
|
||||||
float[] previousBuffer = new float[size];
|
|
||||||
buffer.get(previousBuffer);
|
|
||||||
buffer.clear();
|
|
||||||
buffer = BufferUtils.createFloatBuffer(size + a.length);
|
|
||||||
buffer.put(previousBuffer).put(a);
|
|
||||||
buffer.flip();
|
|
||||||
}else{
|
|
||||||
buffer = BufferUtils.createFloatBuffer(a.length);
|
|
||||||
buffer.put(a);
|
|
||||||
buffer.flip();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,6 +67,11 @@ public class VBO {
|
||||||
* @Info Stocke le FloatBuffer dans le GPU
|
* @Info Stocke le FloatBuffer dans le GPU
|
||||||
*/
|
*/
|
||||||
public void bufferData(){
|
public void bufferData(){
|
||||||
|
buffer = BufferUtils.createFloatBuffer(floatlist.size());
|
||||||
|
for(Float f : floatlist){
|
||||||
|
buffer.put(f);
|
||||||
|
}
|
||||||
|
buffer.flip();
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vboID);
|
glBindBuffer(GL_ARRAY_BUFFER, vboID);
|
||||||
glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW);
|
||||||
// glBufferSubData(vboID, 0, buffer);
|
// glBufferSubData(vboID, 0, buffer);
|
||||||
|
|
|
@ -11,7 +11,7 @@ import math.*;
|
||||||
|
|
||||||
public class Chunk {
|
public class Chunk {
|
||||||
|
|
||||||
public final static int SIZE = 8;
|
public final static int SIZE = 16;
|
||||||
private int x, y, z;
|
private int x, y, z;
|
||||||
private VBO vbo;
|
private VBO vbo;
|
||||||
private World world;
|
private World world;
|
||||||
|
@ -111,12 +111,12 @@ public class Chunk {
|
||||||
boolean right = true;
|
boolean right = true;
|
||||||
boolean back = true;
|
boolean back = true;
|
||||||
boolean front = true;
|
boolean front = true;
|
||||||
up = world.getBlock(xx, yy + 1, zz) == null;
|
// up = world.getBlock(xx, yy + 1, zz) == null;
|
||||||
down = world.getBlock(xx, yy - 1, zz) == null;
|
// down = world.getBlock(xx, yy - 1, zz) == null;
|
||||||
left = world.getBlock(xx - 1, yy, zz) == null;
|
// left = world.getBlock(xx - 1, yy, zz) == null;
|
||||||
right = world.getBlock(xx + 1, yy, zz) == null;
|
// right = world.getBlock(xx + 1, yy, zz) == null;
|
||||||
front = world.getBlock(xx, yy, zz - 1) == null;
|
// front = world.getBlock(xx, yy, zz - 1) == null;
|
||||||
back = world.getBlock(xx, yy, zz + 1) == null;
|
// back = world.getBlock(xx, yy, zz + 1) == null;
|
||||||
if (!up && !down && !left && !right && !front && !back)
|
if (!up && !down && !left && !right && !front && !back)
|
||||||
return;
|
return;
|
||||||
if (blocks[x][y][z] == null)
|
if (blocks[x][y][z] == null)
|
||||||
|
@ -133,22 +133,22 @@ public class Chunk {
|
||||||
// aa ab bb ba
|
// aa ab bb ba
|
||||||
float[] a = new float[] { 1, 1, 1, 1 };
|
float[] a = new float[] { 1, 1, 1, 1 };
|
||||||
|
|
||||||
if (world.getBlock(xx - 1, yy + 1, zz) != null
|
// if (world.getBlock(xx - 1, yy + 1, zz) != null
|
||||||
|| world.getBlock(xx - 1, yy + 1, zz - 1) != null
|
// || world.getBlock(xx - 1, yy + 1, zz - 1) != null
|
||||||
|| world.getBlock(xx, yy + 1, zz - 1) != null)
|
// || world.getBlock(xx, yy + 1, zz - 1) != null)
|
||||||
a[0] = ao;
|
// a[0] = ao;
|
||||||
if (world.getBlock(xx + 1, yy + 1, zz) != null
|
// if (world.getBlock(xx + 1, yy + 1, zz) != null
|
||||||
|| world.getBlock(xx + 1, yy + 1, zz - 1) != null
|
// || world.getBlock(xx + 1, yy + 1, zz - 1) != null
|
||||||
|| world.getBlock(xx, yy + 1, zz - 1) != null)
|
// || world.getBlock(xx, yy + 1, zz - 1) != null)
|
||||||
a[1] = ao;
|
// a[1] = ao;
|
||||||
if (world.getBlock(xx + 1, yy + 1, zz) != null
|
// if (world.getBlock(xx + 1, yy + 1, zz) != null
|
||||||
|| world.getBlock(xx + 1, yy + 1, zz + 1) != null
|
// || world.getBlock(xx + 1, yy + 1, zz + 1) != null
|
||||||
|| world.getBlock(xx, yy + 1, zz + 1) != null)
|
// || world.getBlock(xx, yy + 1, zz + 1) != null)
|
||||||
a[2] = ao;
|
// a[2] = ao;
|
||||||
if (world.getBlock(xx - 1, yy + 1, zz) != null
|
// if (world.getBlock(xx - 1, yy + 1, zz) != null
|
||||||
|| world.getBlock(xx - 1, yy + 1, zz + 1) != null
|
// || world.getBlock(xx - 1, yy + 1, zz + 1) != null
|
||||||
|| world.getBlock(xx, yy + 1, zz + 1) != null)
|
// || world.getBlock(xx, yy + 1, zz + 1) != null)
|
||||||
a[3] = ao;
|
// a[3] = ao;
|
||||||
|
|
||||||
vbo.addDataByFloatArray(b.getDataUp(xx, yy, zz, a));
|
vbo.addDataByFloatArray(b.getDataUp(xx, yy, zz, a));
|
||||||
}
|
}
|
||||||
|
@ -156,22 +156,22 @@ public class Chunk {
|
||||||
float[] a = new float[] { 1, 1, 1, 1 };
|
float[] a = new float[] { 1, 1, 1, 1 };
|
||||||
// ambient occlusion
|
// ambient occlusion
|
||||||
|
|
||||||
if (world.getBlock(xx - 1, yy - 1, zz) != null
|
// if (world.getBlock(xx - 1, yy - 1, zz) != null
|
||||||
|| world.getBlock(xx - 1, yy - 1, zz - 1) != null
|
// || world.getBlock(xx - 1, yy - 1, zz - 1) != null
|
||||||
|| world.getBlock(xx, yy - 1, zz - 1) != null)
|
// || world.getBlock(xx, yy - 1, zz - 1) != null)
|
||||||
a[1] = ao;
|
// a[1] = ao;
|
||||||
if (world.getBlock(xx + 1, yy - 1, zz) != null
|
// if (world.getBlock(xx + 1, yy - 1, zz) != null
|
||||||
|| world.getBlock(xx + 1, yy - 1, zz - 1) != null
|
// || world.getBlock(xx + 1, yy - 1, zz - 1) != null
|
||||||
|| world.getBlock(xx, yy - 1, zz - 1) != null)
|
// || world.getBlock(xx, yy - 1, zz - 1) != null)
|
||||||
a[0] = ao;
|
// a[0] = ao;
|
||||||
if (world.getBlock(xx + 1, yy - 1, zz) != null
|
// if (world.getBlock(xx + 1, yy - 1, zz) != null
|
||||||
|| world.getBlock(xx + 1, yy - 1, zz + 1) != null
|
// || world.getBlock(xx + 1, yy - 1, zz + 1) != null
|
||||||
|| world.getBlock(xx, yy - 1, zz + 1) != null)
|
// || world.getBlock(xx, yy - 1, zz + 1) != null)
|
||||||
a[3] = ao;
|
// a[3] = ao;
|
||||||
if (world.getBlock(xx - 1, yy - 1, zz) != null
|
// if (world.getBlock(xx - 1, yy - 1, zz) != null
|
||||||
|| world.getBlock(xx - 1, yy - 1, zz + 1) != null
|
// || world.getBlock(xx - 1, yy - 1, zz + 1) != null
|
||||||
|| world.getBlock(xx, yy - 1, zz + 1) != null)
|
// || world.getBlock(xx, yy - 1, zz + 1) != null)
|
||||||
a[2] = ao;
|
// a[2] = ao;
|
||||||
|
|
||||||
// affiche la face si il n'y a rien en dessous
|
// affiche la face si il n'y a rien en dessous
|
||||||
vbo.addDataByFloatArray(b.getDataDown(xx, yy, zz, a));
|
vbo.addDataByFloatArray(b.getDataDown(xx, yy, zz, a));
|
||||||
|
@ -179,88 +179,88 @@ public class Chunk {
|
||||||
if (left) {
|
if (left) {
|
||||||
float[] a = new float[] { 1, 1, 1, 1 };
|
float[] a = new float[] { 1, 1, 1, 1 };
|
||||||
|
|
||||||
if (world.getBlock(xx - 1, yy - 1, zz) != null
|
// if (world.getBlock(xx - 1, yy - 1, zz) != null
|
||||||
|| world.getBlock(xx - 1, yy - 1, zz - 1) != null
|
// || world.getBlock(xx - 1, yy - 1, zz - 1) != null
|
||||||
|| world.getBlock(xx - 1, yy, zz - 1) != null)
|
// || world.getBlock(xx - 1, yy, zz - 1) != null)
|
||||||
a[0] = ao;
|
// a[0] = ao;
|
||||||
if (world.getBlock(xx - 1, yy + 1, zz) != null
|
// if (world.getBlock(xx - 1, yy + 1, zz) != null
|
||||||
|| world.getBlock(xx - 1, yy + 1, zz - 1) != null
|
// || world.getBlock(xx - 1, yy + 1, zz - 1) != null
|
||||||
|| world.getBlock(xx - 1, yy, zz - 1) != null)
|
// || world.getBlock(xx - 1, yy, zz - 1) != null)
|
||||||
a[1] = ao;
|
// a[1] = ao;
|
||||||
if (world.getBlock(xx - 1, yy + 1, zz) != null
|
// if (world.getBlock(xx - 1, yy + 1, zz) != null
|
||||||
|| world.getBlock(xx - 1, yy + 1, zz + 1) != null
|
// || world.getBlock(xx - 1, yy + 1, zz + 1) != null
|
||||||
|| world.getBlock(xx - 1, yy, zz + 1) != null)
|
// || world.getBlock(xx - 1, yy, zz + 1) != null)
|
||||||
a[2] = ao;
|
// a[2] = ao;
|
||||||
if (world.getBlock(xx - 1, yy - 1, zz) != null
|
// if (world.getBlock(xx - 1, yy - 1, zz) != null
|
||||||
|| world.getBlock(xx - 1, yy - 1, zz + 1) != null
|
// || world.getBlock(xx - 1, yy - 1, zz + 1) != null
|
||||||
|| world.getBlock(xx - 1, yy, zz + 1) != null)
|
// || world.getBlock(xx - 1, yy, zz + 1) != null)
|
||||||
a[3] = ao;
|
// a[3] = ao;
|
||||||
|
|
||||||
vbo.addDataByFloatArray(b.getDataLeft(xx, yy, zz, a));
|
vbo.addDataByFloatArray(b.getDataLeft(xx, yy, zz, a));
|
||||||
}
|
}
|
||||||
if (right) {
|
if (right) {
|
||||||
float[] a = new float[] { 1, 1, 1, 1 };
|
float[] a = new float[] { 1, 1, 1, 1 };
|
||||||
|
|
||||||
if (world.getBlock(xx + 1, yy - 1, zz) != null
|
// if (world.getBlock(xx + 1, yy - 1, zz) != null
|
||||||
|| world.getBlock(xx + 1, yy - 1, zz - 1) != null
|
// || world.getBlock(xx + 1, yy - 1, zz - 1) != null
|
||||||
|| world.getBlock(xx + 1, yy, zz - 1) != null)
|
// || world.getBlock(xx + 1, yy, zz - 1) != null)
|
||||||
a[1] = ao;
|
// a[1] = ao;
|
||||||
if (world.getBlock(xx + 1, yy + 1, zz) != null
|
// if (world.getBlock(xx + 1, yy + 1, zz) != null
|
||||||
|| world.getBlock(xx + 1, yy + 1, zz - 1) != null
|
// || world.getBlock(xx + 1, yy + 1, zz - 1) != null
|
||||||
|| world.getBlock(xx + 1, yy, zz - 1) != null)
|
// || world.getBlock(xx + 1, yy, zz - 1) != null)
|
||||||
a[0] = ao;
|
// a[0] = ao;
|
||||||
if (world.getBlock(xx + 1, yy + 1, zz) != null
|
// if (world.getBlock(xx + 1, yy + 1, zz) != null
|
||||||
|| world.getBlock(xx + 1, yy + 1, zz + 1) != null
|
// || world.getBlock(xx + 1, yy + 1, zz + 1) != null
|
||||||
|| world.getBlock(xx + 1, yy, zz + 1) != null)
|
// || world.getBlock(xx + 1, yy, zz + 1) != null)
|
||||||
a[3] = ao;
|
// a[3] = ao;
|
||||||
if (world.getBlock(xx + 1, yy - 1, zz) != null
|
// if (world.getBlock(xx + 1, yy - 1, zz) != null
|
||||||
|| world.getBlock(xx + 1, yy - 1, zz + 1) != null
|
// || world.getBlock(xx + 1, yy - 1, zz + 1) != null
|
||||||
|| world.getBlock(xx + 1, yy, zz + 1) != null)
|
// || world.getBlock(xx + 1, yy, zz + 1) != null)
|
||||||
a[2] = ao;
|
// a[2] = ao;
|
||||||
|
|
||||||
vbo.addDataByFloatArray(b.getDataRight(xx, yy, zz, a));
|
vbo.addDataByFloatArray(b.getDataRight(xx, yy, zz, a));
|
||||||
}
|
}
|
||||||
if (front) {
|
if (front) {
|
||||||
float[] a = new float[] { 1, 1, 1, 1 };
|
float[] a = new float[] { 1, 1, 1, 1 };
|
||||||
|
|
||||||
if (world.getBlock(xx, yy - 1, zz - 1) != null
|
// if (world.getBlock(xx, yy - 1, zz - 1) != null
|
||||||
|| world.getBlock(xx - 1, yy - 1, zz - 1) != null
|
// || world.getBlock(xx - 1, yy - 1, zz - 1) != null
|
||||||
|| world.getBlock(xx - 1, yy, zz - 1) != null)
|
// || world.getBlock(xx - 1, yy, zz - 1) != null)
|
||||||
a[0] = ao;
|
// a[0] = ao;
|
||||||
if (world.getBlock(xx, yy + 1, zz - 1) != null
|
// if (world.getBlock(xx, yy + 1, zz - 1) != null
|
||||||
|| world.getBlock(xx - 1, yy + 1, zz - 1) != null
|
// || world.getBlock(xx - 1, yy + 1, zz - 1) != null
|
||||||
|| world.getBlock(xx - 1, yy, zz - 1) != null)
|
// || world.getBlock(xx - 1, yy, zz - 1) != null)
|
||||||
a[3] = ao;
|
// a[3] = ao;
|
||||||
if (world.getBlock(xx, yy + 1, zz - 1) != null
|
// if (world.getBlock(xx, yy + 1, zz - 1) != null
|
||||||
|| world.getBlock(xx + 1, yy + 1, zz - 1) != null
|
// || world.getBlock(xx + 1, yy + 1, zz - 1) != null
|
||||||
|| world.getBlock(xx + 1, yy, zz - 1) != null)
|
// || world.getBlock(xx + 1, yy, zz - 1) != null)
|
||||||
a[2] = ao;
|
// a[2] = ao;
|
||||||
if (world.getBlock(xx, yy - 1, zz - 1) != null
|
// if (world.getBlock(xx, yy - 1, zz - 1) != null
|
||||||
|| world.getBlock(xx + 1, yy - 1, zz - 1) != null
|
// || world.getBlock(xx + 1, yy - 1, zz - 1) != null
|
||||||
|| world.getBlock(xx + 1, yy, zz - 1) != null)
|
// || world.getBlock(xx + 1, yy, zz - 1) != null)
|
||||||
a[1] = ao;
|
// a[1] = ao;
|
||||||
|
|
||||||
vbo.addDataByFloatArray(b.getDataFront(xx, yy, zz, a));
|
vbo.addDataByFloatArray(b.getDataFront(xx, yy, zz, a));
|
||||||
}
|
}
|
||||||
if (back) {
|
if (back) {
|
||||||
float[] a = new float[] { 1, 1, 1, 1 };
|
float[] a = new float[] { 1, 1, 1, 1 };
|
||||||
|
|
||||||
if (world.getBlock(xx, yy - 1, zz + 1) != null
|
// if (world.getBlock(xx, yy - 1, zz + 1) != null
|
||||||
|| world.getBlock(xx - 1, yy - 1, zz + 1) != null
|
// || world.getBlock(xx - 1, yy - 1, zz + 1) != null
|
||||||
|| world.getBlock(xx - 1, yy, zz + 1) != null)
|
// || world.getBlock(xx - 1, yy, zz + 1) != null)
|
||||||
a[1] = ao;
|
// a[1] = ao;
|
||||||
if (world.getBlock(xx, yy + 1, zz + 1) != null
|
// if (world.getBlock(xx, yy + 1, zz + 1) != null
|
||||||
|| world.getBlock(xx - 1, yy + 1, zz + 1) != null
|
// || world.getBlock(xx - 1, yy + 1, zz + 1) != null
|
||||||
|| world.getBlock(xx - 1, yy, zz + 1) != null)
|
// || world.getBlock(xx - 1, yy, zz + 1) != null)
|
||||||
a[2] = ao;
|
// a[2] = ao;
|
||||||
if (world.getBlock(xx, yy + 1, zz + 1) != null
|
// if (world.getBlock(xx, yy + 1, zz + 1) != null
|
||||||
|| world.getBlock(xx + 1, yy + 1, zz + 1) != null
|
// || world.getBlock(xx + 1, yy + 1, zz + 1) != null
|
||||||
|| world.getBlock(xx + 1, yy, zz + 1) != null)
|
// || world.getBlock(xx + 1, yy, zz + 1) != null)
|
||||||
a[3] = ao;
|
// a[3] = ao;
|
||||||
if (world.getBlock(xx, yy - 1, zz + 1) != null
|
// if (world.getBlock(xx, yy - 1, zz + 1) != null
|
||||||
|| world.getBlock(xx + 1, yy - 1, zz + 1) != null
|
// || world.getBlock(xx + 1, yy - 1, zz + 1) != null
|
||||||
|| world.getBlock(xx + 1, yy, zz + 1) != null)
|
// || world.getBlock(xx + 1, yy, zz + 1) != null)
|
||||||
a[0] = ao;
|
// a[0] = ao;
|
||||||
|
|
||||||
vbo.addDataByFloatArray(b.getDataBack(xx, yy, zz, a));
|
vbo.addDataByFloatArray(b.getDataBack(xx, yy, zz, a));
|
||||||
}
|
}
|
||||||
|
@ -321,19 +321,13 @@ class Generate implements Runnable {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
// AffinityLock al = null;
|
|
||||||
// int cpuId = 0;
|
|
||||||
// try{
|
|
||||||
// al = AffinityLock.acquireLock();
|
|
||||||
// }catch(Exception e){}
|
|
||||||
long current = System.currentTimeMillis();
|
long current = System.currentTimeMillis();
|
||||||
|
long elapsed1 = 0;
|
||||||
boolean IsError = true;
|
boolean IsError = true;
|
||||||
Noise noise = new Noise(world.seed, 30, 7);
|
Noise noise = new Noise(world.seed, 30, 7);
|
||||||
Random random = new Random(world.seed);
|
Random random = new Random(world.seed);
|
||||||
for (int x = 0; x < chunk.SIZE; x++) {
|
for (int x = 0; x < chunk.SIZE; x++) {
|
||||||
for (int z = 0; z < chunk.SIZE; z++) {
|
for (int z = 0; z < chunk.SIZE; z++) {
|
||||||
// for (int y = 0; y < chunk.SIZE; y++) {
|
|
||||||
|
|
||||||
int xa = (int)((Camera.getPosition().getX()-((float)Chunk.SIZE/2.0f))/(float)Chunk.SIZE) - World.VIEW_CHUNK;
|
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 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 za = (int)((Camera.getPosition().getZ()-((float)Chunk.SIZE/2.0f))/(float)Chunk.SIZE) - World.VIEW_CHUNK;
|
||||||
|
@ -344,32 +338,19 @@ class Generate implements Runnable {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int xx = chunk.getX() * chunk.SIZE + x;
|
int xx = chunk.getX() * chunk.SIZE + x;
|
||||||
// int yy = chunk.getY() * chunk.SIZE + y;
|
|
||||||
int zz = chunk.getZ() * chunk.SIZE + z;
|
int zz = chunk.getZ() * chunk.SIZE + z;
|
||||||
// if(noise.getNoise(xx, zz) > yy){
|
|
||||||
// chunk.blocks[x][y][z] = Block.GRASS;
|
|
||||||
// }else{
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
chunk.blocks[x][(int)noise.getNoise(xx, zz)][z] = Block.GRASS;
|
chunk.blocks[x][(int)noise.getNoise(xx, zz)][z] = Block.GRASS;
|
||||||
//
|
|
||||||
// float percentOfSpawnTree = 0.0005f;
|
|
||||||
// if(random.nextFloat() < percentOfSpawnTree){
|
|
||||||
// if(random.nextInt(2) == 0)
|
|
||||||
// Tree.addOak(world, xx, (int)noise.getNoise(xx, zz) - 1, zz);
|
|
||||||
// else
|
|
||||||
// Tree.addFir(world, xx, (int)noise.getNoise(xx, zz) - 1, zz);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
elapsed1 = System.currentTimeMillis() - current;
|
||||||
while(IsError){
|
while(IsError){
|
||||||
IsError = false;
|
IsError = false;
|
||||||
try{
|
try{
|
||||||
synchronized (world.chunks) {
|
// synchronized (world.chunks) {
|
||||||
for (int i = 0; i < chunk.SIZE; i++) {
|
for (int i = 0; i < chunk.SIZE; i++) {
|
||||||
for (int j = 0; j < chunk.SIZE; j++) {
|
// for (int j = 0; j < chunk.SIZE; j++) {
|
||||||
for (int k = 0; k < chunk.SIZE; k++) {
|
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 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 xb = (int)((Camera.getPosition().getX()-((float)Chunk.SIZE/2.0f))/(float)Chunk.SIZE) + World.VIEW_CHUNK;
|
||||||
|
@ -380,19 +361,21 @@ class Generate implements Runnable {
|
||||||
Thread.currentThread().stop();
|
Thread.currentThread().stop();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
chunk.loopChunk(i, j, k);
|
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);
|
chunk.setGenerated(true);
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
IsError = true;
|
IsError = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.println(Thread.currentThread().getName() + " terminated | " + (System.currentTimeMillis()-current));
|
System.out.println(Thread.currentThread().getName() + " terminated | loop1:" + elapsed1 + "ms loop2:" + (System.currentTimeMillis()-current) + "ms");
|
||||||
Thread.currentThread().stop();
|
Thread.currentThread().stop();
|
||||||
// al.release();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ public class World {
|
||||||
public long seed;
|
public long seed;
|
||||||
public final int SIZE = 1,HEIGHT = 1;
|
public final int SIZE = 1,HEIGHT = 1;
|
||||||
public static final float GRAVITY = 1;
|
public static final float GRAVITY = 1;
|
||||||
public static final int VIEW_CHUNK = 8;
|
public static final int VIEW_CHUNK = 4;
|
||||||
public static WorldNoise worldNoise;
|
public static WorldNoise worldNoise;
|
||||||
|
|
||||||
public ArrayList<Chunk> chunks = new ArrayList<Chunk>();
|
public ArrayList<Chunk> chunks = new ArrayList<Chunk>();
|
||||||
|
@ -30,7 +30,9 @@ public class World {
|
||||||
for(Chunk ch : chunks)ch.createChunk(this);
|
for(Chunk ch : chunks)ch.createChunk(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static long updateWorldTime = 0;
|
||||||
public void update(){
|
public void update(){
|
||||||
|
long current = System.currentTimeMillis();
|
||||||
int xa = (int)((Camera.getPosition().getX()-((float)Chunk.SIZE/2.0f))/(float)Chunk.SIZE) - VIEW_CHUNK;
|
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 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 za = (int)((Camera.getPosition().getZ()-((float)Chunk.SIZE/2.0f))/(float)Chunk.SIZE) - VIEW_CHUNK;
|
||||||
|
@ -41,12 +43,11 @@ public class World {
|
||||||
int delta_z = zb - za;
|
int delta_z = zb - za;
|
||||||
for(int i = 0; i <= delta_x;i++){
|
for(int i = 0; i <= delta_x;i++){
|
||||||
for(int k = 0;k <= delta_z;k++){
|
for(int k = 0;k <= delta_z;k++){
|
||||||
for(int j = 0; j < HEIGHT; j++){
|
// for(int j = 0; j < HEIGHT; j++){
|
||||||
if(getChunk((xa + i), 0, (za + k)) == null){
|
if(getChunk((xa + i), 0, (za + k)) != null)continue;
|
||||||
Chunk ch = new Chunk((xa + i),j,(za + k),this,worldNoise);
|
Chunk ch = new Chunk((xa + i),0,(za + k),this,worldNoise);
|
||||||
chunks.add(ch);
|
chunks.add(ch);
|
||||||
}
|
// }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ArrayList<Chunk> removeList = new ArrayList<Chunk>();
|
ArrayList<Chunk> removeList = new ArrayList<Chunk>();
|
||||||
|
@ -55,18 +56,17 @@ public class World {
|
||||||
if(c.getPosition().getX() < xa || c.getPosition().getX() > xb || c.getPosition().getZ() < za || c.getPosition().getZ() > zb){
|
if(c.getPosition().getX() < xa || c.getPosition().getX() > xb || c.getPosition().getZ() < za || c.getPosition().getZ() > zb){
|
||||||
c.destroyChunk();
|
c.destroyChunk();
|
||||||
removeList.add(c);
|
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){
|
for(Chunk c: removeList){
|
||||||
removeByChunk(c);
|
removeByChunk(c);
|
||||||
}
|
}
|
||||||
removeList.clear();
|
removeList.clear();
|
||||||
for(Chunk c : chunks){
|
updateWorldTime = System.currentTimeMillis() - current;
|
||||||
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();
|
|
||||||
}
|
|
||||||
System.gc();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render(){
|
public void render(){
|
||||||
|
|
Reference in a new issue