Align spawn location with town

This commit is contained in:
austin 2021-10-16 20:44:22 -04:00
parent 78ac717283
commit 20baca4884
5 changed files with 56 additions and 43 deletions

View File

@ -27,6 +27,7 @@ import electrosphere.game.server.ai.creature.MindlessAttacker;
import electrosphere.game.server.effects.ParticleEffects; import electrosphere.game.server.effects.ParticleEffects;
import electrosphere.game.server.terrain.models.TerrainModification; import electrosphere.game.server.terrain.models.TerrainModification;
import electrosphere.game.server.town.Town; import electrosphere.game.server.town.Town;
import electrosphere.game.server.world.MacroData;
import electrosphere.game.server.world.datacell.DataCellManager; import electrosphere.game.server.world.datacell.DataCellManager;
import electrosphere.game.state.MicroSimulation; import electrosphere.game.state.MicroSimulation;
import electrosphere.logger.LoggerInterface; import electrosphere.logger.LoggerInterface;
@ -47,6 +48,7 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.joml.Quaternionf; import org.joml.Quaternionf;
import org.joml.Vector2i; import org.joml.Vector2i;
import org.joml.Vector3d;
import org.joml.Vector3f; import org.joml.Vector3f;
/** /**
@ -124,6 +126,15 @@ public class LoadingThread extends Thread {
initServerThread(); initServerThread();
} }
//collision engine
initCollisionEngine(Globals.RUN_SERVER);
//initialize the "virtual" objects simulation
initMacroSimulation();
//initialize the "real" objects simulation
initMicroSimulation();
//initialize the client thread (client) //initialize the client thread (client)
if(Globals.RUN_CLIENT){ if(Globals.RUN_CLIENT){
initClientThread(); initClientThread();
@ -136,9 +147,6 @@ public class LoadingThread extends Thread {
//initialize the cell manager (client) //initialize the cell manager (client)
initDrawCellManager(); initDrawCellManager();
//collision engine
initCollisionEngine(Globals.RUN_SERVER);
//initialize the basic graphical entities of the world (skybox, camera) //initialize the basic graphical entities of the world (skybox, camera)
initWorldBaseGraphicalEntities(); initWorldBaseGraphicalEntities();
@ -150,12 +158,6 @@ public class LoadingThread extends Thread {
} }
} }
//initialize the "virtual" objects simulation
initMacroSimulation();
//initialize the "real" objects simulation
initMicroSimulation();
//hide cursor //hide cursor
Globals.controlHandler.hideMouse(); Globals.controlHandler.hideMouse();
@ -204,6 +206,15 @@ public class LoadingThread extends Thread {
initServerThread(); initServerThread();
} }
//collision engine
initCollisionEngine(Globals.RUN_SERVER);
//initialize the "virtual" objects simulation
initMacroSimulation();
//initialize the "real" objects simulation
initMicroSimulation();
//initialize the client thread (client) //initialize the client thread (client)
if(Globals.RUN_CLIENT){ if(Globals.RUN_CLIENT){
initClientThread(); initClientThread();
@ -216,9 +227,6 @@ public class LoadingThread extends Thread {
//initialize the cell manager (client) //initialize the cell manager (client)
initDrawCellManager(); initDrawCellManager();
//collision engine
initCollisionEngine(Globals.RUN_SERVER);
//initialize the basic graphical entities of the world (skybox, camera) //initialize the basic graphical entities of the world (skybox, camera)
initWorldBaseGraphicalEntities(); initWorldBaseGraphicalEntities();
@ -231,12 +239,6 @@ public class LoadingThread extends Thread {
} }
} }
//initialize the "virtual" objects simulation
initMacroSimulation();
//initialize the "real" objects simulation
initMicroSimulation();
//hide cursor //hide cursor
Globals.controlHandler.hideMouse(); Globals.controlHandler.hideMouse();
@ -344,13 +346,13 @@ public class LoadingThread extends Thread {
} }
static void createServerWorld(){ static void createServerWorld(){
Vector2i townLoc = Town.findValidTownLocation(); // Vector2i townLoc = Town.findValidTownLocation();
if(townLoc != null){ // if(townLoc != null){
int chunkSize = Globals.serverTerrainManager.getChunkWidth(); // int chunkSize = Globals.serverTerrainManager.getChunkWidth();
Globals.spawnPoint = new Vector3f(townLoc.x * chunkSize, (float)Globals.serverTerrainManager.getHeightAtPosition(townLoc.x * chunkSize,townLoc.y * chunkSize), townLoc.y * chunkSize); // Globals.spawnPoint = new Vector3f(townLoc.x * chunkSize, (float)Globals.serverTerrainManager.getHeightAtPosition(townLoc.x * chunkSize,townLoc.y * chunkSize), townLoc.y * chunkSize);
// System.out.println("Setting spawn point @ " + Globals.spawnPoint); //// System.out.println("Setting spawn point @ " + Globals.spawnPoint);
// Town.createTown(townLoc.x,townLoc.y); //// Town.createTown(townLoc.x,townLoc.y);
} // }
} }
static void initServerGameWorldData(){ static void initServerGameWorldData(){
@ -472,7 +474,15 @@ public class LoadingThread extends Thread {
} }
static void initMacroSimulation(){ static void initMacroSimulation(){
Globals.macroData = MacroData.generateWorld(0);
// Globals.macroData.describeWorld();
Globals.macroSimulation = new MacroSimulation(); Globals.macroSimulation = new MacroSimulation();
Globals.macroSimulation.simulate();
Town startTown = Globals.macroData.getTowns().get(0);
Vector2i firstPos = startTown.getPositions().get(0);
double startX = firstPos.x * Globals.serverTerrainManager.getChunkWidth();
double startZ = firstPos.y * Globals.serverTerrainManager.getChunkWidth();
Globals.spawnPoint.set((float)startX,(float)Globals.commonWorldData.getElevationAtPoint(new Vector3d(startX,0,startZ)),(float)startZ);
} }

View File

@ -86,7 +86,7 @@ public class MovementTree {
// Model entityModel = Globals.assetManager.fetchModel(EntityUtils.getEntityModelPath(parent)); // Model entityModel = Globals.assetManager.fetchModel(EntityUtils.getEntityModelPath(parent));
Vector3d position = EntityUtils.getPosition(parent); Vector3d position = EntityUtils.getPosition(parent);
Vector3f movementVector = CreatureUtils.getMovementVector(parent); Vector3f movementVector = CreatureUtils.getMovementVector(parent);
float movementYaw = CameraEntityUtils.getCameraYaw(Globals.playerCamera); // float movementYaw = CameraEntityUtils.getCameraYaw(Globals.playerCamera);
Quaternionf movementQuaternion = new Quaternionf().rotationTo(new Vector3f(0,0,1), movementVector).normalize(); Quaternionf movementQuaternion = new Quaternionf().rotationTo(new Vector3f(0,0,1), movementVector).normalize();
Quaternionf rotation = EntityUtils.getRotation(parent); Quaternionf rotation = EntityUtils.getRotation(parent);
Vector3d newPosition; Vector3d newPosition;

View File

@ -108,6 +108,10 @@ public class Town {
return rVal; return rVal;
} }
public List<Vector2i> getPositions(){
return positions;
}
public void addStructure(Structure structure){ public void addStructure(Structure structure){
structures.add(structure); structures.add(structure);
} }

View File

@ -98,7 +98,6 @@ public class MacroSimulation {
} }
} }
if(placementPos != null){ if(placementPos != null){
System.out.println("Added shelter");
Structure placedStructure = VirtualStructureUtils.placeStructureAtPoint(placementPos.x, placementPos.y, buildingTypeToPlace); Structure placedStructure = VirtualStructureUtils.placeStructureAtPoint(placementPos.x, placementPos.y, buildingTypeToPlace);
CharacterUtils.addShelter(chara, placedStructure); CharacterUtils.addShelter(chara, placedStructure);
VirtualStructureUtils.addResident(placedStructure, chara); VirtualStructureUtils.addResident(placedStructure, chara);

View File

@ -120,22 +120,22 @@ public class Main {
//world gen testing //world gen testing
//gen terrain //gen terrain
Globals.serverTerrainManager = new ServerTerrainManager(2000,50,100,0.0f,0); // Globals.serverTerrainManager = new ServerTerrainManager(2000,50,100,0.0f,0);
Globals.serverTerrainManager.load(); // Globals.serverTerrainManager.load();
Globals.serverWorldData = ServerWorldData.createGameWorld(Globals.serverTerrainManager); // Globals.serverWorldData = ServerWorldData.createGameWorld(Globals.serverTerrainManager);
//gen world // //gen world
Globals.macroData = MacroData.generateWorld(0); // Globals.macroData = MacroData.generateWorld(0);
Globals.macroData.describeWorld(); // Globals.macroData.describeWorld();
boolean run = true; // boolean run = true;
Globals.macroSimulation = new MacroSimulation(); // Globals.macroSimulation = new MacroSimulation();
while(run){ // while(run){
Globals.macroSimulation.simulate(); // Globals.macroSimulation.simulate();
try { // try {
TimeUnit.MILLISECONDS.sleep(1000); // TimeUnit.MILLISECONDS.sleep(1000);
} catch (InterruptedException ex) { // } catch (InterruptedException ex) {
ex.printStackTrace(); // ex.printStackTrace();
} // }
} // }
//debug: create terrain/world viewer //debug: create terrain/world viewer
// TerrainViewer.runViewer(); // TerrainViewer.runViewer();