Performance changes for chunking
This commit is contained in:
parent
bfd7abfd68
commit
3baf78f599
2
.gitignore
vendored
2
.gitignore
vendored
@ -1 +1,3 @@
|
|||||||
/target/
|
/target/
|
||||||
|
|
||||||
|
/src/main/resources/Config/terrain.json
|
||||||
|
|||||||
@ -31,9 +31,9 @@ public class CellManager {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
int drawRadius = 1;
|
int drawRadius = 15;
|
||||||
int drawStepdownInterval = 2;
|
int drawStepdownInterval = 2;
|
||||||
int drawStepdownValue = 20;
|
int drawStepdownValue = 2;
|
||||||
|
|
||||||
public CellManager(TerrainManager terrainManager, float realX, float realY){
|
public CellManager(TerrainManager terrainManager, float realX, float realY){
|
||||||
this.terrainManager = terrainManager;
|
this.terrainManager = terrainManager;
|
||||||
@ -140,8 +140,8 @@ public class CellManager {
|
|||||||
currentCellY >= 0 &&
|
currentCellY >= 0 &&
|
||||||
currentCellY < terrainManager.getWorldDiscreteSize()
|
currentCellY < terrainManager.getWorldDiscreteSize()
|
||||||
){
|
){
|
||||||
int dist = Math.abs(targetX - drawRadius) * Math.abs(targetY - drawRadius);
|
int dist = (int)Math.sqrt((targetX - drawRadius)*(targetX - drawRadius) + (targetY - drawRadius) * (targetY - drawRadius));//Math.abs(targetX - drawRadius) * Math.abs(targetY - drawRadius);
|
||||||
int stride = Math.min(100, Math.max(1, dist / drawStepdownInterval * drawStepdownValue));
|
int stride = Math.min(terrainManager.getChunkWidth()/2, Math.max(1, dist / drawStepdownInterval * drawStepdownValue));
|
||||||
while(terrainManager.getChunkWidth() % stride != 0){
|
while(terrainManager.getChunkWidth() % stride != 0){
|
||||||
stride = stride + 1;
|
stride = stride + 1;
|
||||||
}
|
}
|
||||||
@ -178,8 +178,8 @@ public class CellManager {
|
|||||||
currentCellY >= 0 &&
|
currentCellY >= 0 &&
|
||||||
currentCellY < terrainManager.getWorldDiscreteSize()
|
currentCellY < terrainManager.getWorldDiscreteSize()
|
||||||
){
|
){
|
||||||
int dist = Math.abs(targetX - drawRadius) * Math.abs(targetY - drawRadius);
|
int dist = (int)Math.sqrt((targetX - drawRadius)*(targetX - drawRadius) + (targetY - drawRadius) * (targetY - drawRadius)); //Math.abs(targetX - drawRadius) * Math.abs(targetY - drawRadius);
|
||||||
int stride = Math.min(100, Math.max(1, dist / drawStepdownInterval * drawStepdownValue));
|
int stride = Math.min(terrainManager.getChunkWidth()/2, Math.max(1, dist / drawStepdownInterval * drawStepdownValue));
|
||||||
while(terrainManager.getChunkWidth() % stride != 0){
|
while(terrainManager.getChunkWidth() % stride != 0){
|
||||||
stride = stride + 1;
|
stride = stride + 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,12 +19,12 @@ public class TerrainManager {
|
|||||||
|
|
||||||
|
|
||||||
//The size of the world in discrete units * must be multiple of 200
|
//The size of the world in discrete units * must be multiple of 200
|
||||||
int worldSizeDiscrete = 2000;
|
int worldSizeDiscrete;
|
||||||
|
|
||||||
//The vertical multiplier applied to the statically generated terrain
|
//The vertical multiplier applied to the statically generated terrain
|
||||||
int verticalInterpolationRatio = 20;
|
int verticalInterpolationRatio;
|
||||||
|
|
||||||
int dynamicInterpolationRatio = 1000;
|
int dynamicInterpolationRatio;
|
||||||
|
|
||||||
TerrainModel model;
|
TerrainModel model;
|
||||||
|
|
||||||
|
|||||||
@ -338,7 +338,7 @@ public class Main {
|
|||||||
static void initWorld(){
|
static void initWorld(){
|
||||||
|
|
||||||
float[][] elevation;
|
float[][] elevation;
|
||||||
terrainManager = new TerrainManager(2000,200,200);
|
terrainManager = new TerrainManager(2000,200,100);
|
||||||
if(Globals.mainConfig.loadTerrain){
|
if(Globals.mainConfig.loadTerrain){
|
||||||
terrainManager.load();
|
terrainManager.load();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -99,7 +99,7 @@ public class ShaderProgram {
|
|||||||
}
|
}
|
||||||
String fragmentShaderSource = tempForReadingShaders;
|
String fragmentShaderSource = tempForReadingShaders;
|
||||||
//Creates a new shader object and assigns its 'pointer' to the integer "vertexShader"
|
//Creates a new shader object and assigns its 'pointer' to the integer "vertexShader"
|
||||||
rVal.vertexShader = glCreateShader(GL_VERTEX_SHADER);
|
rVal.vertexShader = glCreateShader(GL20.GL_VERTEX_SHADER);
|
||||||
//This alerts openGL to the presence of a vertex shader and points the shader at its source
|
//This alerts openGL to the presence of a vertex shader and points the shader at its source
|
||||||
glShaderSource(rVal.vertexShader, vertexShaderSource);
|
glShaderSource(rVal.vertexShader, vertexShaderSource);
|
||||||
//Compiles the source for the vertex shader object
|
//Compiles the source for the vertex shader object
|
||||||
@ -109,6 +109,8 @@ public class ShaderProgram {
|
|||||||
success = glGetShaderi(rVal.vertexShader, GL_COMPILE_STATUS);
|
success = glGetShaderi(rVal.vertexShader, GL_COMPILE_STATUS);
|
||||||
if (success != GL_TRUE) {
|
if (success != GL_TRUE) {
|
||||||
System.out.println("Vertex Shader failed to compile!");
|
System.out.println("Vertex Shader failed to compile!");
|
||||||
|
System.out.println("Source is: ");
|
||||||
|
System.out.println(GL20.glGetShaderSource(rVal.vertexShader));
|
||||||
throw new RuntimeException(GL20.glGetShaderInfoLog(rVal.vertexShader));
|
throw new RuntimeException(GL20.glGetShaderInfoLog(rVal.vertexShader));
|
||||||
}
|
}
|
||||||
//Creates and opengl object for a fragment shader and assigns its 'pointer' to the integer fragmentShader
|
//Creates and opengl object for a fragment shader and assigns its 'pointer' to the integer fragmentShader
|
||||||
@ -121,6 +123,8 @@ public class ShaderProgram {
|
|||||||
success = glGetShaderi(rVal.fragmentShader, GL_COMPILE_STATUS);
|
success = glGetShaderi(rVal.fragmentShader, GL_COMPILE_STATUS);
|
||||||
if (success != GL_TRUE) {
|
if (success != GL_TRUE) {
|
||||||
System.out.println("Fragment Shader failed to compile!");
|
System.out.println("Fragment Shader failed to compile!");
|
||||||
|
System.out.println("Source is: ");
|
||||||
|
System.out.println(GL20.glGetShaderSource(rVal.fragmentShader));
|
||||||
throw new RuntimeException(GL20.glGetShaderInfoLog(rVal.fragmentShader));
|
throw new RuntimeException(GL20.glGetShaderInfoLog(rVal.fragmentShader));
|
||||||
}
|
}
|
||||||
//This creates a shader program opengl object and assigns its 'pointer' to the integer shaderProgram
|
//This creates a shader program opengl object and assigns its 'pointer' to the integer shaderProgram
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user