Arena mode distinction
This commit is contained in:
parent
607abd392c
commit
a3269b962d
@ -25,7 +25,17 @@ public class DrawCell {
|
||||
Entity modelEntity;
|
||||
|
||||
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){
|
||||
this.drawArray = drawArray;
|
||||
this.drawWidth = drawWidth;
|
||||
|
||||
@ -19,6 +19,11 @@ public class DrawCellManager {
|
||||
int cellX;
|
||||
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
|
||||
int miniCellWidth;
|
||||
|
||||
@ -38,6 +43,13 @@ public class DrawCellManager {
|
||||
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){
|
||||
this.terrainManager = terrainManager;
|
||||
this.miniCellWidth = miniCellWidth;
|
||||
@ -58,6 +70,21 @@ public class DrawCellManager {
|
||||
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(){
|
||||
return cellX;
|
||||
}
|
||||
@ -74,7 +101,7 @@ public class DrawCellManager {
|
||||
cellY = y;
|
||||
}
|
||||
|
||||
public void updateInvalidCell(){
|
||||
void updateInvalidCell(){
|
||||
int targetX = 0;
|
||||
int targetY = 0;
|
||||
boolean found = false;
|
||||
@ -116,7 +143,7 @@ public class DrawCellManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void makeCellDrawable(){
|
||||
void makeCellDrawable(){
|
||||
int targetX = 0;
|
||||
int targetY = 0;
|
||||
boolean found = false;
|
||||
@ -154,7 +181,7 @@ public class DrawCellManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void updateCellModel(){
|
||||
void updateCellModel(){
|
||||
int targetX = 0;
|
||||
int targetY = 0;
|
||||
boolean found = false;
|
||||
@ -195,12 +222,16 @@ public class DrawCellManager {
|
||||
|
||||
|
||||
public boolean containsInvalidCell(){
|
||||
for(int x = 0;x < drawRadius * 2 + 1; x++){
|
||||
for(int y = 0; y < drawRadius * 2 + 1; y++){
|
||||
if(!valid[x][y]){
|
||||
return true;
|
||||
if(DRAW_CELL_MANAGER_FLAG_UPDATE_DYNAMIC_TERRAIN){
|
||||
for(int x = 0;x < drawRadius * 2 + 1; x++){
|
||||
for(int y = 0; y < drawRadius * 2 + 1; y++){
|
||||
if(!valid[x][y]){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
@ -303,7 +334,8 @@ public class DrawCellManager {
|
||||
}
|
||||
|
||||
public void calculateDeltas(Vector3f oldPosition, Vector3f newPosition){
|
||||
if(transformRealSpaceToCellSpace(newPosition.x()) < transformRealSpaceToCellSpace(oldPosition.x())){
|
||||
if(DRAW_CELL_MANAGER_FLAG_UPDATE_DYNAMIC_TERRAIN){
|
||||
if(transformRealSpaceToCellSpace(newPosition.x()) < transformRealSpaceToCellSpace(oldPosition.x())){
|
||||
shiftChunksNegX();
|
||||
setCellX(transformRealSpaceToCellSpace(newPosition.x()));
|
||||
setCellY(transformRealSpaceToCellSpace(newPosition.z()));
|
||||
@ -322,20 +354,75 @@ public class DrawCellManager {
|
||||
setCellX(transformRealSpaceToCellSpace(newPosition.x()));
|
||||
setCellY(transformRealSpaceToCellSpace(newPosition.z()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void update(){
|
||||
if(containsInvalidCell()){
|
||||
updateInvalidCell();
|
||||
} else if(containsUndrawableCell()){
|
||||
makeCellDrawable();
|
||||
} else if(containsUpdateableCell()){
|
||||
updateCellModel();
|
||||
if(DRAW_CELL_MANAGER_FLAG_UPDATE_DYNAMIC_TERRAIN){
|
||||
if(containsInvalidCell()){
|
||||
updateInvalidCell();
|
||||
} else if(containsUndrawableCell()){
|
||||
makeCellDrawable();
|
||||
} else if(containsUpdateableCell()){
|
||||
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){
|
||||
return terrainManager.getHeightAtPosition(realPointX, realPointY);
|
||||
if(DRAW_CELL_MANAGER_FLAG_UPDATE_DYNAMIC_TERRAIN){
|
||||
return terrainManager.getHeightAtPosition(realPointX, realPointY);
|
||||
}
|
||||
if(DRAW_CELL_MANAGER_FLAG_GENERATE_ARENA){
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
@ -93,7 +93,7 @@ public class LoadingThread extends Thread {
|
||||
}
|
||||
|
||||
//initialize the cell manager (client)
|
||||
initCellManager();
|
||||
initDynamicCellManager();
|
||||
|
||||
//initialize the basic graphical entities of the world (skybox, camera)
|
||||
initWorldBaseGraphicalEntities();
|
||||
@ -123,8 +123,7 @@ public class LoadingThread extends Thread {
|
||||
case LOAD_ARENA:
|
||||
loadingBox.setDraw(true);
|
||||
|
||||
//initialize the terrain manager (server only)
|
||||
initTerrainManager();
|
||||
Globals.spawnPoint = new Vector3f(1,0,1);
|
||||
|
||||
//initialize the server thread (server only)
|
||||
if(FLAG_INIT_SERVER){
|
||||
@ -137,7 +136,7 @@ public class LoadingThread extends Thread {
|
||||
}
|
||||
|
||||
//initialize the cell manager (client)
|
||||
initCellManager();
|
||||
initArenaCellManager();
|
||||
|
||||
//initialize the basic graphical entities of the world (skybox, camera)
|
||||
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);
|
||||
|
||||
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(){
|
||||
/*
|
||||
|
||||
@ -33,6 +33,7 @@ public class MenuTransition {
|
||||
break;
|
||||
//arena
|
||||
case 2:
|
||||
m.dispose();
|
||||
Globals.loadingThread = new LoadingThread(LoadingThread.LOAD_ARENA);
|
||||
Globals.loadingThread.setFLAG_INIT_CLIENT(true);
|
||||
Globals.loadingThread.setFLAG_INIT_SERVER(true);
|
||||
|
||||
@ -85,9 +85,9 @@ public class ServerConnectionHandler implements Runnable {
|
||||
System.exit(1);
|
||||
}
|
||||
//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.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);
|
||||
if(Globals.mainConfig.runServer && Main.playerId == -1){
|
||||
Globals.playerCharacter = newPlayerCharacter;
|
||||
|
||||
@ -163,7 +163,6 @@ public class ModelUtils {
|
||||
return rVal;
|
||||
}
|
||||
|
||||
|
||||
public static Model createTerrainModelPrecomputedShader(float[][] heightfield, ShaderProgram program, int stride){
|
||||
Model rVal = new Model();
|
||||
rVal.meshes = new ArrayList();
|
||||
@ -174,6 +173,7 @@ public class ModelUtils {
|
||||
int actualWidth = (int)Math.ceil(1.0f * width / (1.0f * stride));
|
||||
int actualHeight = (int)Math.ceil(1.0f * height / (1.0f * stride));
|
||||
|
||||
|
||||
// System.out.println(actualWidth + " " + actualHeight);
|
||||
|
||||
// System.out.println((actualWidth - 1) * (actualHeight - 1));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user