Arena mode distinction

This commit is contained in:
austin 2021-06-03 22:04:08 -04:00
parent 607abd392c
commit a3269b962d
7 changed files with 131 additions and 40 deletions

View File

@ -25,7 +25,17 @@ public class DrawCell {
Entity modelEntity; Entity modelEntity;
ShaderProgram program; ShaderProgram program;
/**
* Catches for this function: drawArray's dimensions need to be equal to drawWidth and 1 greater than cellWidth
* because the model creation code for terrain heightmaps sucks :D
* 6/3/2021
* @param drawArray
* @param drawWidth
* @param cellX
* @param cellY
* @param cellWidth
* @param program
*/
public DrawCell(float[][] drawArray, int drawWidth, int cellX, int cellY, int cellWidth, ShaderProgram program){ public DrawCell(float[][] drawArray, int drawWidth, int cellX, int cellY, int cellWidth, ShaderProgram program){
this.drawArray = drawArray; this.drawArray = drawArray;
this.drawWidth = drawWidth; this.drawWidth = drawWidth;

View File

@ -19,6 +19,11 @@ public class DrawCellManager {
int cellX; int cellX;
int cellY; int cellY;
//the dimensions of the world that this cell manager can handles
int cellWidth;
int cellHeight;
//the width of a minicell in this manager //the width of a minicell in this manager
int miniCellWidth; int miniCellWidth;
@ -38,6 +43,13 @@ public class DrawCellManager {
int drawStepdownValue = 5; int drawStepdownValue = 5;
//signals the update function to handle dynamic cell generation from terrainmodel
boolean DRAW_CELL_MANAGER_FLAG_UPDATE_DYNAMIC_TERRAIN = true;
//signals the drawcell manager to generate an arena instead of dynamic terrain
boolean DRAW_CELL_MANAGER_FLAG_GENERATE_ARENA = false;
public DrawCellManager(TerrainManager terrainManager, float realX, float realY){ public DrawCellManager(TerrainManager terrainManager, float realX, float realY){
this.terrainManager = terrainManager; this.terrainManager = terrainManager;
this.miniCellWidth = miniCellWidth; this.miniCellWidth = miniCellWidth;
@ -58,6 +70,21 @@ public class DrawCellManager {
program = Globals.defaultMeshShader; program = Globals.defaultMeshShader;
} }
DrawCellManager(){
}
public static DrawCellManager createArenaDrawCellManager(){
DrawCellManager rVal = new DrawCellManager();
rVal.cells = new DrawCell[2][2];
rVal.DRAW_CELL_MANAGER_FLAG_UPDATE_DYNAMIC_TERRAIN = false;
rVal.DRAW_CELL_MANAGER_FLAG_GENERATE_ARENA = true;
rVal.cellWidth = 2;
rVal.cellHeight = 2;
rVal.program = Globals.defaultMeshShader;
return rVal;
}
public int getCellX(){ public int getCellX(){
return cellX; return cellX;
} }
@ -74,7 +101,7 @@ public class DrawCellManager {
cellY = y; cellY = y;
} }
public void updateInvalidCell(){ void updateInvalidCell(){
int targetX = 0; int targetX = 0;
int targetY = 0; int targetY = 0;
boolean found = false; boolean found = false;
@ -116,7 +143,7 @@ public class DrawCellManager {
} }
} }
public void makeCellDrawable(){ void makeCellDrawable(){
int targetX = 0; int targetX = 0;
int targetY = 0; int targetY = 0;
boolean found = false; boolean found = false;
@ -154,7 +181,7 @@ public class DrawCellManager {
} }
} }
public void updateCellModel(){ void updateCellModel(){
int targetX = 0; int targetX = 0;
int targetY = 0; int targetY = 0;
boolean found = false; boolean found = false;
@ -195,6 +222,7 @@ public class DrawCellManager {
public boolean containsInvalidCell(){ public boolean containsInvalidCell(){
if(DRAW_CELL_MANAGER_FLAG_UPDATE_DYNAMIC_TERRAIN){
for(int x = 0;x < drawRadius * 2 + 1; x++){ for(int x = 0;x < drawRadius * 2 + 1; x++){
for(int y = 0; y < drawRadius * 2 + 1; y++){ for(int y = 0; y < drawRadius * 2 + 1; y++){
if(!valid[x][y]){ if(!valid[x][y]){
@ -202,6 +230,9 @@ public class DrawCellManager {
} }
} }
} }
} else if(DRAW_CELL_MANAGER_FLAG_GENERATE_ARENA){
return cells[0][0] == null || cells[1][0] == null || cells[0][1] == null | cells[1][1] == null;
}
return false; return false;
} }
@ -303,6 +334,7 @@ public class DrawCellManager {
} }
public void calculateDeltas(Vector3f oldPosition, Vector3f newPosition){ public void calculateDeltas(Vector3f oldPosition, Vector3f newPosition){
if(DRAW_CELL_MANAGER_FLAG_UPDATE_DYNAMIC_TERRAIN){
if(transformRealSpaceToCellSpace(newPosition.x()) < transformRealSpaceToCellSpace(oldPosition.x())){ if(transformRealSpaceToCellSpace(newPosition.x()) < transformRealSpaceToCellSpace(oldPosition.x())){
shiftChunksNegX(); shiftChunksNegX();
setCellX(transformRealSpaceToCellSpace(newPosition.x())); setCellX(transformRealSpaceToCellSpace(newPosition.x()));
@ -323,8 +355,10 @@ public class DrawCellManager {
setCellY(transformRealSpaceToCellSpace(newPosition.z())); setCellY(transformRealSpaceToCellSpace(newPosition.z()));
} }
} }
}
public void update(){ public void update(){
if(DRAW_CELL_MANAGER_FLAG_UPDATE_DYNAMIC_TERRAIN){
if(containsInvalidCell()){ if(containsInvalidCell()){
updateInvalidCell(); updateInvalidCell();
} else if(containsUndrawableCell()){ } else if(containsUndrawableCell()){
@ -332,10 +366,63 @@ public class DrawCellManager {
} else if(containsUpdateableCell()){ } else if(containsUpdateableCell()){
updateCellModel(); updateCellModel();
} }
} else if(DRAW_CELL_MANAGER_FLAG_GENERATE_ARENA){
if(cells[0][0] == null){
int arenaChunkWidth = 100;
cells[0][0] = new DrawCell(
new float[arenaChunkWidth + 1][arenaChunkWidth + 1],
arenaChunkWidth + 1,
0,
0,
arenaChunkWidth,
program
);
cells[0][0].generateDrawableEntity(1);
} else if(cells[0][1] == null){
int arenaChunkWidth = 100;
cells[0][1] = new DrawCell(
new float[arenaChunkWidth + 1][arenaChunkWidth + 1],
arenaChunkWidth + 1,
0,
1,
arenaChunkWidth,
program
);
cells[0][1].generateDrawableEntity(1);
} else if(cells[1][0] == null){
int arenaChunkWidth = 100;
cells[1][0] = new DrawCell(
new float[arenaChunkWidth + 1][arenaChunkWidth + 1],
arenaChunkWidth + 1,
1,
0,
arenaChunkWidth,
program
);
cells[1][0].generateDrawableEntity(1);
} else if(cells[1][1] == null){
int arenaChunkWidth = 100;
cells[1][1] = new DrawCell(
new float[arenaChunkWidth + 1][arenaChunkWidth + 1],
arenaChunkWidth + 1,
1,
1,
arenaChunkWidth,
program
);
cells[1][1].generateDrawableEntity(1);
}
}
} }
public float getElevationAtRealPoint(float realPointX, float realPointY){ public float getElevationAtRealPoint(float realPointX, float realPointY){
if(DRAW_CELL_MANAGER_FLAG_UPDATE_DYNAMIC_TERRAIN){
return terrainManager.getHeightAtPosition(realPointX, realPointY); return terrainManager.getHeightAtPosition(realPointX, realPointY);
} }
if(DRAW_CELL_MANAGER_FLAG_GENERATE_ARENA){
return 0;
}
return 0;
}
} }

View File

@ -1,16 +0,0 @@
package electrosphere.game.collision;
import electrosphere.entity.Entity;
/**
*
* @author amaterasu
*/
public class CollisionEngine {
public static boolean collisionCheck(Entity entity){
boolean rVal = false;
return rVal;
}
}

View File

@ -93,7 +93,7 @@ public class LoadingThread extends Thread {
} }
//initialize the cell manager (client) //initialize the cell manager (client)
initCellManager(); initDynamicCellManager();
//initialize the basic graphical entities of the world (skybox, camera) //initialize the basic graphical entities of the world (skybox, camera)
initWorldBaseGraphicalEntities(); initWorldBaseGraphicalEntities();
@ -123,8 +123,7 @@ public class LoadingThread extends Thread {
case LOAD_ARENA: case LOAD_ARENA:
loadingBox.setDraw(true); loadingBox.setDraw(true);
//initialize the terrain manager (server only) Globals.spawnPoint = new Vector3f(1,0,1);
initTerrainManager();
//initialize the server thread (server only) //initialize the server thread (server only)
if(FLAG_INIT_SERVER){ if(FLAG_INIT_SERVER){
@ -137,7 +136,7 @@ public class LoadingThread extends Thread {
} }
//initialize the cell manager (client) //initialize the cell manager (client)
initCellManager(); initArenaCellManager();
//initialize the basic graphical entities of the world (skybox, camera) //initialize the basic graphical entities of the world (skybox, camera)
initWorldBaseGraphicalEntities(); initWorldBaseGraphicalEntities();
@ -252,7 +251,7 @@ public class LoadingThread extends Thread {
static void initCellManager(){ static void initDynamicCellManager(){
Globals.drawCellManager = new DrawCellManager(Globals.terrainManager, Globals.spawnPoint.x, Globals.spawnPoint.z); Globals.drawCellManager = new DrawCellManager(Globals.terrainManager, Globals.spawnPoint.x, Globals.spawnPoint.z);
while(Globals.drawCellManager.containsInvalidCell()){ while(Globals.drawCellManager.containsInvalidCell()){
@ -274,6 +273,16 @@ public class LoadingThread extends Thread {
} }
} }
static void initArenaCellManager(){
Globals.drawCellManager = DrawCellManager.createArenaDrawCellManager();
while(Globals.drawCellManager.containsInvalidCell()){
try {
TimeUnit.MILLISECONDS.sleep(10);
} catch (InterruptedException ex) {
}
}
}
static void initWorldBaseGraphicalEntities(){ static void initWorldBaseGraphicalEntities(){
/* /*

View File

@ -33,6 +33,7 @@ public class MenuTransition {
break; break;
//arena //arena
case 2: case 2:
m.dispose();
Globals.loadingThread = new LoadingThread(LoadingThread.LOAD_ARENA); Globals.loadingThread = new LoadingThread(LoadingThread.LOAD_ARENA);
Globals.loadingThread.setFLAG_INIT_CLIENT(true); Globals.loadingThread.setFLAG_INIT_CLIENT(true);
Globals.loadingThread.setFLAG_INIT_SERVER(true); Globals.loadingThread.setFLAG_INIT_SERVER(true);

View File

@ -85,9 +85,9 @@ public class ServerConnectionHandler implements Runnable {
System.exit(1); System.exit(1);
} }
//spawn player in world //spawn player in world
Entity newPlayerCharacter = CreatureUtils.spawnBasicCreature(0, 0.001f, 0.025f); Entity newPlayerCharacter = CreatureUtils.spawnBasicCreature(0, 0.001f, 0.55f);
EntityUtils.getEntityScale(newPlayerCharacter).set(0.005f); EntityUtils.getEntityScale(newPlayerCharacter).set(0.005f);
EntityUtils.getEntityPosition(newPlayerCharacter).set(10 - 0.5f,Globals.terrainManager.getHeightAtPosition(10, 10),10 - 0.5f); EntityUtils.getEntityPosition(newPlayerCharacter).set(Globals.spawnPoint.x,Globals.drawCellManager.getElevationAtRealPoint(Globals.spawnPoint.x, Globals.spawnPoint.z),Globals.spawnPoint.z);
CreatureUtils.setControllerPlayerId(newPlayerCharacter, playerID); CreatureUtils.setControllerPlayerId(newPlayerCharacter, playerID);
if(Globals.mainConfig.runServer && Main.playerId == -1){ if(Globals.mainConfig.runServer && Main.playerId == -1){
Globals.playerCharacter = newPlayerCharacter; Globals.playerCharacter = newPlayerCharacter;

View File

@ -163,7 +163,6 @@ public class ModelUtils {
return rVal; return rVal;
} }
public static Model createTerrainModelPrecomputedShader(float[][] heightfield, ShaderProgram program, int stride){ public static Model createTerrainModelPrecomputedShader(float[][] heightfield, ShaderProgram program, int stride){
Model rVal = new Model(); Model rVal = new Model();
rVal.meshes = new ArrayList(); rVal.meshes = new ArrayList();
@ -174,6 +173,7 @@ public class ModelUtils {
int actualWidth = (int)Math.ceil(1.0f * width / (1.0f * stride)); int actualWidth = (int)Math.ceil(1.0f * width / (1.0f * stride));
int actualHeight = (int)Math.ceil(1.0f * height / (1.0f * stride)); int actualHeight = (int)Math.ceil(1.0f * height / (1.0f * stride));
// System.out.println(actualWidth + " " + actualHeight); // System.out.println(actualWidth + " " + actualHeight);
// System.out.println((actualWidth - 1) * (actualHeight - 1)); // System.out.println((actualWidth - 1) * (actualHeight - 1));