853 lines
		
	
	
		
			37 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			853 lines
		
	
	
		
			37 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
| package electrosphere.engine;
 | |
| 
 | |
| import electrosphere.auth.AuthenticationManager;
 | |
| import electrosphere.collision.dispatch.CollisionObject;
 | |
| import electrosphere.controls.ControlHandler;
 | |
| import electrosphere.entity.Entity;
 | |
| import electrosphere.entity.EntityDataStrings;
 | |
| import electrosphere.entity.EntityUtils;
 | |
| import electrosphere.entity.state.BehaviorTree;
 | |
| import electrosphere.entity.state.collidable.Impulse;
 | |
| import electrosphere.entity.state.movement.ApplyRotationTree;
 | |
| import electrosphere.game.collision.CollisionEngine;
 | |
| import electrosphere.entity.types.creature.CreatureUtils;
 | |
| import electrosphere.entity.types.debug.DebugVisualizerUtils;
 | |
| import electrosphere.entity.types.item.ItemUtils;
 | |
| import electrosphere.game.client.cells.DrawCellManager;
 | |
| import electrosphere.game.client.player.ClientPlayerData;
 | |
| import electrosphere.game.client.terrain.manager.ClientTerrainManager;
 | |
| import electrosphere.game.client.world.ClientWorldData;
 | |
| import electrosphere.game.collision.CommonWorldData;
 | |
| import electrosphere.game.simulation.MacroSimulation;
 | |
| import electrosphere.game.server.terrain.manager.ServerTerrainManager;
 | |
| import electrosphere.game.server.world.ServerWorldData;
 | |
| import electrosphere.entity.types.attach.AttachUtils;
 | |
| import electrosphere.entity.types.camera.CameraEntityUtils;
 | |
| import electrosphere.entity.types.particle.ParticleUtils;
 | |
| import electrosphere.entity.types.collision.CollisionObjUtils;
 | |
| import electrosphere.entity.types.foliage.FoliageUtils;
 | |
| import electrosphere.entity.types.structure.StructureUtils;
 | |
| import electrosphere.game.collision.PhysicsUtils;
 | |
| import electrosphere.game.collision.collidable.Collidable;
 | |
| import electrosphere.game.server.ai.creature.MindlessAttacker;
 | |
| import electrosphere.game.server.effects.ParticleEffects;
 | |
| import electrosphere.game.server.saves.SaveUtils;
 | |
| import electrosphere.game.server.terrain.models.TerrainModification;
 | |
| import electrosphere.game.server.town.Town;
 | |
| import electrosphere.game.server.world.MacroData;
 | |
| import electrosphere.game.server.datacell.DataCellManager;
 | |
| import electrosphere.game.simulation.MicroSimulation;
 | |
| import electrosphere.logger.LoggerInterface;
 | |
| import electrosphere.main.Globals;
 | |
| import electrosphere.menu.MenuGenerators;
 | |
| import electrosphere.menu.MenuGeneratorsMultiplayer;
 | |
| import electrosphere.menu.WindowStrings;
 | |
| import electrosphere.menu.WindowUtils;
 | |
| import electrosphere.net.NetUtils;
 | |
| import electrosphere.net.client.ClientNetworking;
 | |
| import electrosphere.net.server.Server;
 | |
| import electrosphere.renderer.Mesh;
 | |
| import electrosphere.renderer.Model;
 | |
| import electrosphere.renderer.ModelUtils;
 | |
| import electrosphere.renderer.RenderUtils;
 | |
| import electrosphere.renderer.RenderingEngine;
 | |
| import electrosphere.renderer.actor.Actor;
 | |
| import electrosphere.renderer.actor.ActorTextureMask;
 | |
| import electrosphere.renderer.actor.ActorUtils;
 | |
| import electrosphere.renderer.texture.Texture;
 | |
| import electrosphere.engine.assetmanager.AssetDataStrings;
 | |
| import electrosphere.game.client.targeting.crosshair.Crosshair;
 | |
| import electrosphere.game.server.ai.creature.OpportunisticAttacker;
 | |
| import electrosphere.game.server.pathfinding.NavMeshPathfinder;
 | |
| import electrosphere.game.server.pathfinding.navmesh.NavCube;
 | |
| import electrosphere.game.server.pathfinding.navmesh.NavMesh;
 | |
| import electrosphere.game.server.unit.UnitUtils;
 | |
| import electrosphere.renderer.ui.DrawableElement;
 | |
| import electrosphere.renderer.ui.WidgetUtils;
 | |
| import electrosphere.renderer.ui.Window;
 | |
| import electrosphere.util.Utilities;
 | |
| 
 | |
| import java.util.LinkedList;
 | |
| import java.util.List;
 | |
| import java.util.Random;
 | |
| import java.util.concurrent.Semaphore;
 | |
| import java.util.concurrent.TimeUnit;
 | |
| import java.util.logging.Level;
 | |
| import java.util.logging.Logger;
 | |
| import org.joml.Quaternionf;
 | |
| import org.joml.Vector2i;
 | |
| import org.joml.Vector3d;
 | |
| import org.joml.Vector3f;
 | |
| 
 | |
| /**
 | |
|  *
 | |
|  * @author amaterasu
 | |
|  */
 | |
| public class LoadingThread extends Thread {
 | |
|     
 | |
|     public static final int LOAD_TITLE_MENU = 0;
 | |
|     public static final int LOAD_MAIN_GAME = 1;
 | |
|     public static final int LOAD_ARENA = 2;
 | |
|     public static final int LOAD_CHARACTER_SERVER = 3;
 | |
|     public static final int LOAD_CLIENT_WORLD = 4;
 | |
|     
 | |
|     int threadType;
 | |
|     
 | |
|     Semaphore lock;
 | |
|     
 | |
|     public LoadingThread(int type){
 | |
|         threadType = type;
 | |
|         lock = new Semaphore(1);
 | |
|     }
 | |
|     
 | |
|     @Override
 | |
|     public void run(){
 | |
|         lock.acquireUninterruptibly();
 | |
|         Window loadingWindow = (Window)Globals.elementManager.getWindow(WindowStrings.WINDOW_LOADING);
 | |
|         switch(threadType){
 | |
|             
 | |
|             
 | |
|             
 | |
|             
 | |
|             
 | |
|             
 | |
|             
 | |
|             
 | |
|             case LOAD_TITLE_MENU:
 | |
|                 WindowUtils.recursiveSetVisible(loadingWindow,false);
 | |
|                 WindowUtils.focusWindow(WindowStrings.WINDOW_MENU_MAIN);
 | |
|                 WindowUtils.recursiveSetVisible(Globals.elementManager.getWindow(WindowStrings.WINDOW_MENU_MAIN), true);
 | |
|                 break;
 | |
|                 
 | |
|                 
 | |
|                 
 | |
|                 
 | |
|                 
 | |
|                 
 | |
|                 
 | |
|                 
 | |
|                 
 | |
|             case LOAD_MAIN_GAME:
 | |
|                 
 | |
|                 
 | |
|                 //initialize the terrain manager (server only)
 | |
| //                if(Globals.RUN_SERVER){
 | |
| //                    initServerGameTerrainManager();
 | |
| //                }
 | |
|                 
 | |
|                 //TODO: Globals.serverTerrainManager = new ServerTerrainManager(2000,50,100,randomDampener,0);
 | |
|                 Globals.serverTerrainManager = new ServerTerrainManager(2000,50,100,0.0f,0);
 | |
|                 SaveUtils.loadSave(Globals.currentSaveName);
 | |
|                 Globals.dataCellManager = new DataCellManager(Globals.serverWorldData);
 | |
|                 //TODO: set spawnpoint
 | |
|                 //TODO: Globals.serverWorldData = ServerWorldData.createGameWorld(Globals.serverTerrainManager);
 | |
|                 //TODO: Globals.dataCellManager = new DataCellManager(Globals.serverWorldData);
 | |
| //                    Globals.serverWorldData = ServerWorldData.createGameWorld(Globals.serverTerrainManager);
 | |
| //                    Globals.dataCellManager = new DataCellManager(Globals.serverWorldData);
 | |
|                 LoggerInterface.loggerEngine.INFO("run server: " + Globals.RUN_SERVER + " run client: " + Globals.RUN_CLIENT);
 | |
|                 //init the data of the world
 | |
| //                    initServerGameWorldData();
 | |
|                 initDataCellManager();
 | |
|                 //init authentication
 | |
|                 initAuthenticationManager();
 | |
|                 //initialize the server thread (server only)
 | |
|                 initServerThread();
 | |
|                 //initialize the "virtual" objects simulation
 | |
|                 initMacroSimulation();
 | |
|                 //initialize the "real" objects simulation
 | |
|                 initMicroSimulation();
 | |
|                 //collision engine
 | |
|                 initCommonWorldData(Globals.RUN_SERVER);
 | |
|                 //init draw cell manager
 | |
|                 initDrawCellManager();
 | |
|                 //init game specific stuff (ie different skybox colors)
 | |
|                 initGameGraphicalEntities();
 | |
|                 //set simulations to ready if they exist
 | |
|                 setSimulationsToReady();
 | |
|                 //log
 | |
|                 LoggerInterface.loggerEngine.INFO("[Server]Finished loading main world");
 | |
|                 break;
 | |
|                 
 | |
|                 
 | |
|                 
 | |
|                 
 | |
|                 
 | |
|                 
 | |
|                 
 | |
|                 
 | |
|                 
 | |
|             case LOAD_ARENA:    
 | |
|                 //init server arena terrain manager separately
 | |
|                 initServerArenaTerrainManager();
 | |
|                 //init the data of the world
 | |
|                 initServerArenaWorldData();
 | |
|                 //init data cell manager
 | |
|                 initDataCellManager();
 | |
|                 //init authentication
 | |
|                 initAuthenticationManager();
 | |
|                 //initialize the server thread (server only)
 | |
|                 initServerThread();
 | |
|                 //collision engine
 | |
|                 initCommonWorldData(Globals.RUN_SERVER);
 | |
|                 //init draw cell manager
 | |
|                 initDrawCellManager();
 | |
|                 //initialize the "virtual" objects simulation
 | |
|                 //not really relevant in arena mode
 | |
| //                initMacroSimulation();
 | |
|                 //initialize the "real" objects simulation
 | |
|                 initMicroSimulation();
 | |
|                 //init arena specific stuff (ie different skybox colors)
 | |
|                 initArenaGraphicalEntities();
 | |
|                 //create arena entities
 | |
|                 creatingRandomEntities();
 | |
|                 //set simulations to ready if they exist
 | |
|                 setSimulationsToReady();
 | |
|                 LoggerInterface.loggerEngine.INFO("[Server]Finished loading arena world");
 | |
|                 break;
 | |
|             
 | |
|             case LOAD_CHARACTER_SERVER:
 | |
|                 WindowUtils.recursiveSetVisible(Globals.elementManager.getWindow(WindowStrings.WINDOW_MENU_MAIN), false);
 | |
|                 WindowUtils.replaceMainMenuContents(MenuGenerators.createEmptyMainMenu());
 | |
|                 loadingWindow.setVisible(true);
 | |
|                 //disable menu input
 | |
|                 Globals.controlHandler.setHandlerState(ControlHandler.ControlsState.NO_INPUT);
 | |
|                 //initialize the client thread (client)
 | |
|                 initClientThread();
 | |
|                 //while we don't know what races are playable, wait
 | |
|                 while(Globals.gameConfigCurrent.getCreatureTypeLoader().getPlayableRaces().size() == 0){
 | |
|                     try {
 | |
|                         TimeUnit.MILLISECONDS.sleep(5);
 | |
|                     } catch (InterruptedException ex) {}
 | |
|                 }
 | |
|                 //once we have them, bring up the character creation interface
 | |
|                 //init character creation window
 | |
|                 //eventually should replace with at ui to select an already created character or create a new one
 | |
|                 WindowUtils.replaceMainMenuContents(MenuGeneratorsMultiplayer.createMultiplayerCharacterCreationWindow());
 | |
|                 //make loading dialog disappear
 | |
|                 loadingWindow.setVisible(false);
 | |
|                 //make character creation window visible
 | |
|                 WindowUtils.recursiveSetVisible(Globals.elementManager.getWindow(WindowStrings.WINDOW_MENU_MAIN), true);
 | |
|                 //recapture window
 | |
|                 Globals.controlHandler.setShouldRecapture(true);
 | |
|                 //log
 | |
|                 LoggerInterface.loggerEngine.INFO("[Client]Finished loading character creation menu");
 | |
|                 //set menu controls again
 | |
|                 Globals.controlHandler.setHandlerState(ControlHandler.ControlsState.TITLE_MENU);
 | |
|                 break;
 | |
|                 
 | |
|             case LOAD_CLIENT_WORLD:
 | |
|                 WindowUtils.recursiveSetVisible(Globals.elementManager.getWindow(WindowStrings.WINDOW_MENU_MAIN), false);
 | |
|                 WindowUtils.replaceMainMenuContents(MenuGenerators.createEmptyMainMenu());
 | |
|                 loadingWindow.setVisible(true);
 | |
|                 //disable menu input
 | |
|                 Globals.controlHandler.setHandlerState(ControlHandler.ControlsState.NO_INPUT);
 | |
|                 //collision engine
 | |
|                 if(!Globals.RUN_SERVER){
 | |
|                     initCommonWorldData(Globals.RUN_SERVER);
 | |
|                 }
 | |
|                 //initialize the "real" objects simulation
 | |
|                 initMicroSimulation();
 | |
|                 //init client terrain manager
 | |
|                 initClientTerrainManager();
 | |
|                 //initialize the cell manager (client)
 | |
|                 initDrawCellManager();
 | |
|                 //initialize the basic graphical entities of the world (skybox, camera)
 | |
|                 initWorldBaseGraphicalEntities();
 | |
|                 //init arena specific stuff (ie different skybox colors)
 | |
|                 if(!Globals.RUN_SERVER){
 | |
|                     initArenaGraphicalEntities();
 | |
|                 }
 | |
|                 //sets micro and macro sims to ready if they exist
 | |
|                 if(!Globals.RUN_SERVER){
 | |
|                     setSimulationsToReady();
 | |
|                 }
 | |
|                 //hide cursor
 | |
|                 Globals.controlHandler.hideMouse();
 | |
|                 //make loading window disappear
 | |
|                 loadingWindow.setVisible(false);
 | |
|                 //recapture screen
 | |
|                 Globals.controlHandler.setShouldRecapture(true);
 | |
|                 //set rendering flags to main game mode
 | |
|                 Globals.RENDER_FLAG_RENDER_SHADOW_MAP = true;
 | |
|                 Globals.RENDER_FLAG_RENDER_SCREEN_FRAMEBUFFER_CONTENT = true;
 | |
|                 Globals.RENDER_FLAG_RENDER_SCREEN_FRAMEBUFFER = true;
 | |
|                 Globals.RENDER_FLAG_RENDER_UI = true;
 | |
|                 Globals.RENDER_FLAG_RENDER_BLACK_BACKGROUND = false;
 | |
|                 Globals.RENDER_FLAG_RENDER_WHITE_BACKGROUND = false;
 | |
|                 LoggerInterface.loggerEngine.INFO("[Client]Finished loading main game");
 | |
|                 //set controls state
 | |
|                 Globals.controlHandler.setHandlerState(ControlHandler.ControlsState.MAIN_GAME);
 | |
|                 break;
 | |
|                 
 | |
|                 
 | |
|                 
 | |
|                 
 | |
|                 
 | |
|                 
 | |
|                 
 | |
|         }
 | |
|         lock.release();
 | |
|     }
 | |
|     
 | |
|     
 | |
|     public boolean isDone(){
 | |
|         boolean rVal = lock.tryAcquire();
 | |
|         if(rVal == true){
 | |
|             lock.release();
 | |
|         }
 | |
|         return rVal;
 | |
|     }
 | |
|     
 | |
|     
 | |
|     
 | |
|     static void initServerGameTerrainManager(){
 | |
|         
 | |
|         /*
 | |
|         Actually initialize the terrain manager
 | |
|         */
 | |
|         float randomDampener = 0.0f; //0.25f;
 | |
|         Globals.serverTerrainManager = new ServerTerrainManager(2000,50,100,randomDampener,0);
 | |
|         if(Globals.RUN_SERVER){
 | |
|             if(Globals.userSettings.gameplayGenerateWorld()){
 | |
|                 Globals.serverTerrainManager.generate();
 | |
|                 Globals.serverTerrainManager.save();
 | |
|             } else {
 | |
|                 SaveUtils.loadSave(Globals.currentSaveName);
 | |
|             }
 | |
|         }
 | |
|         
 | |
|         /*
 | |
|         Set spawn point
 | |
|         */
 | |
|         int playerStartX = 0;
 | |
|         int playerStartY = 0;
 | |
|         int discreteSize = Globals.serverTerrainManager.getWorldDiscreteSize();
 | |
|         int chunkSize = Globals.serverTerrainManager.getChunkWidth();
 | |
|         boolean found = false;
 | |
|         for(int x = 0; x < discreteSize; x++){
 | |
|             for(int y = 0; y < discreteSize; y++){
 | |
|                 if(Globals.serverTerrainManager.getDiscreteValue(x, y)>1800){
 | |
|                     playerStartX = x;
 | |
|                     playerStartY = y;
 | |
|                     found = true;
 | |
|                 }
 | |
|                 if(found){
 | |
|                     break;
 | |
|                 }
 | |
|             }
 | |
|             if(found){
 | |
|                 break;
 | |
|             }
 | |
|         }
 | |
|         
 | |
| //        Globals.spawnPoint = new Vector3f(playerStartX * chunkSize, Globals.serverTerrainManager.getHeightAtPosition(playerStartX * chunkSize,playerStartY * chunkSize), playerStartY * chunkSize);
 | |
|         
 | |
|         
 | |
|         
 | |
|     }
 | |
|     
 | |
|     static void initServerArenaTerrainManager(){
 | |
|         Globals.serverTerrainManager = ServerTerrainManager.constructArenaTerrainManager();
 | |
|     }
 | |
|     
 | |
|     static void initClientTerrainManager(){
 | |
|         while(!Globals.clientConnection.getClientProtocol().hasReceivedWorld()){
 | |
|             try {
 | |
|                 TimeUnit.MILLISECONDS.sleep(5);
 | |
|             } catch (InterruptedException ex) {
 | |
|             }
 | |
|         }
 | |
|         Globals.clientTerrainManager = new ClientTerrainManager(Globals.clientWorldData);
 | |
|     }
 | |
|     
 | |
|     static void initServerArenaWorldData(){
 | |
|         Globals.serverWorldData = ServerWorldData.createArenaWorld();
 | |
|         Globals.spawnPoint = new Vector3d(1,0.1,1);
 | |
| //        Globals.serverTerrainManager.getChunk(0, 0).addModification(new TerrainModification(0,0,5,5,5));
 | |
|     }
 | |
|     
 | |
|     static void initServerGameWorldData(){
 | |
|         Globals.serverWorldData = ServerWorldData.createGameWorld(Globals.serverTerrainManager);
 | |
|     }
 | |
|     
 | |
|     static void initCommonWorldData(boolean FLAG_INIT_SERVER){
 | |
|         if(Globals.commonWorldData == null){
 | |
|             if(FLAG_INIT_SERVER){
 | |
|                 Globals.commonWorldData = new CommonWorldData(Globals.serverWorldData, Globals.serverTerrainManager);
 | |
|                 if(Globals.macroSimulation != null){
 | |
|                     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);
 | |
|                 }
 | |
|             } else {
 | |
|                 Globals.commonWorldData = new CommonWorldData(Globals.clientWorldData, Globals.clientTerrainManager);
 | |
|             }
 | |
|         }
 | |
|     }
 | |
|     
 | |
|     static void initDataCellManager(){
 | |
|         Globals.dataCellManager = new DataCellManager(Globals.serverWorldData);
 | |
|         Globals.dataCellManager.init();
 | |
|     }
 | |
|     
 | |
|     
 | |
|     
 | |
|     static void initServerThread(){
 | |
|         //start server networking
 | |
|         if(Globals.RUN_SERVER){
 | |
|             Globals.server = new Server(NetUtils.getPort());
 | |
|             Globals.serverThread = new Thread(Globals.server);
 | |
|             Globals.serverThread.start();
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     static void initAuthenticationManager(){
 | |
|         if(Globals.RUN_SERVER){
 | |
|             Globals.authenticationManager = new AuthenticationManager();
 | |
|         }
 | |
|     }
 | |
|     
 | |
|     
 | |
|     
 | |
|     static void initClientThread(){
 | |
|         //start client networking
 | |
|         Thread clientThread = null;
 | |
|         if(Globals.RUN_CLIENT){
 | |
|             Globals.clientConnection = new ClientNetworking(NetUtils.getAddress(),NetUtils.getPort());
 | |
|             System.out.println(Globals.clientConnection.socket);
 | |
|             clientThread = new Thread(Globals.clientConnection);
 | |
|             clientThread.start();
 | |
|         }
 | |
|     }
 | |
|     
 | |
|     
 | |
|     static void initDrawCellManager(){
 | |
|         if(Globals.drawCellManager == null){
 | |
|             Globals.drawCellManager = new DrawCellManager(
 | |
|                     Globals.commonWorldData,
 | |
|                     Globals.clientTerrainManager,
 | |
|                     Globals.clientPlayerData.getWorldPositionX(),
 | |
|                     Globals.clientPlayerData.getWorldPositionY()
 | |
|     //                Globals.terrainManager.getDynamicInterpolationRatio(),
 | |
|     //                Globals.terrainManager.getRandomDampener()
 | |
|             );
 | |
|         } else {
 | |
|             //set our draw cell manager to actually generate drawable chunks
 | |
|             Globals.drawCellManager.setGenerateDrawables(true);
 | |
|         }
 | |
|         //wait for all the terrain data to arrive
 | |
|         if(Globals.RUN_CLIENT){
 | |
|             while(Globals.drawCellManager.containsInvalidCell()){
 | |
|     //            Globals.drawCellManager.updateInvalidCell();
 | |
|                 try {
 | |
|                     TimeUnit.MILLISECONDS.sleep(10);
 | |
|                 } catch (InterruptedException ex) {
 | |
|                 }
 | |
|     //            System.out.println("invalid cell");
 | |
|             }
 | |
|             
 | |
|             while(Globals.drawCellManager.containsUndrawableCell()){
 | |
|     //            Globals.drawCellManager.makeCellDrawable();
 | |
|                 try {
 | |
|                     TimeUnit.MILLISECONDS.sleep(10);
 | |
|                 } catch (InterruptedException ex) {
 | |
|                 }
 | |
|     //            System.out.println("undrawable");
 | |
|             }
 | |
|             
 | |
|             while(Globals.drawCellManager.containsPhysicsNeedingCell()){
 | |
|                 try {
 | |
|                     TimeUnit.MILLISECONDS.sleep(10);
 | |
|                 } catch (InterruptedException ex) {
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
|         System.out.println("Draw Cell Manager ready");
 | |
|     }
 | |
|     
 | |
| 
 | |
|     static void initGameGraphicalEntities(){
 | |
| 
 | |
| 
 | |
|         float skyR = 100;
 | |
|         float skyG = 150;
 | |
|         float skyB = 200;
 | |
| 
 | |
|         float groundR = 50;
 | |
|         float groundG = 100;
 | |
|         float groundB = 150;
 | |
| 
 | |
|         Globals.skyboxColors.add(new Vector3f(skyR,skyG,skyB));
 | |
|         Globals.skyboxColors.add(new Vector3f(skyR,skyG,skyB));
 | |
|         Globals.skyboxColors.add(new Vector3f(groundR,groundG,groundB));
 | |
|         Globals.skyboxColors.add(new Vector3f(groundR,groundG,groundB));
 | |
|         Globals.skyboxColors.add(new Vector3f(skyR,skyG,skyB));
 | |
|         Globals.skyboxColors.add(new Vector3f(skyR,skyG,skyB));
 | |
|         Globals.skyboxColors.add(new Vector3f(groundR,groundG,groundB));
 | |
|         Globals.skyboxColors.add(new Vector3f(groundR,groundG,groundB));
 | |
| 
 | |
|     }
 | |
| 
 | |
| 
 | |
|     static void initArenaGraphicalEntities(){
 | |
| 
 | |
|         float skyR = 150;
 | |
|         float skyG = 200;
 | |
|         float skyB = 250;
 | |
| 
 | |
|         float groundR = 20;
 | |
|         float groundG = 20;
 | |
|         float groundB = 20;
 | |
| 
 | |
|         Globals.skyboxColors.add(new Vector3f(skyR,skyG,skyB));
 | |
|         Globals.skyboxColors.add(new Vector3f(skyR,skyG,skyB));
 | |
|         Globals.skyboxColors.add(new Vector3f(groundR,groundG,groundB));
 | |
|         Globals.skyboxColors.add(new Vector3f(groundR,groundG,groundB));
 | |
|         Globals.skyboxColors.add(new Vector3f(skyR,skyG,skyB));
 | |
|         Globals.skyboxColors.add(new Vector3f(skyR,skyG,skyB));
 | |
|         Globals.skyboxColors.add(new Vector3f(groundR,groundG,groundB));
 | |
|         Globals.skyboxColors.add(new Vector3f(groundR,groundG,groundB));
 | |
|         
 | |
|         //starry sky true skybox
 | |
|         Entity skybox = EntityUtils.spawnDrawableEntity("Models/skyboxSphere.fbx");
 | |
|         EntityUtils.getRotation(skybox).rotateX((float)(-Math.PI/2.0f));
 | |
|         EntityUtils.getScale(skybox).mul(2000.0f);
 | |
|         Globals.assetManager.queueOverrideMeshShader("Models/skyboxSphere.fbx", "Sphere", "Shaders/skysphere/skysphere.vs", "Shaders/skysphere/skysphere.fs");
 | |
| 
 | |
|         //cloud ring pseudo skybox
 | |
|         Entity cloudRing = EntityUtils.spawnDrawableEntity("Models/cloudRing.fbx");
 | |
|         EntityUtils.getRotation(cloudRing).rotateX((float)(-Math.PI/2.0f));
 | |
|         EntityUtils.getScale(cloudRing).mul(1000.0f);
 | |
|         Globals.entityManager.registerBehaviorTree(new ApplyRotationTree(cloudRing,new Quaternionf().rotationZ(0.0001f)));
 | |
|         Globals.assetManager.queueOverrideMeshShader("Models/cloudRing.fbx", "Sphere", "Shaders/skysphere/skysphere.vs", "Shaders/skysphere/skysphere.fs");
 | |
| 
 | |
|     }
 | |
|     
 | |
|     
 | |
|     static void initWorldBaseGraphicalEntities(){
 | |
|         /*
 | |
|         
 | |
|         Skybox
 | |
|         
 | |
|         */
 | |
|         // Model skyboxModel = Globals.assetManager.fetchModel(AssetDataStrings.ASSET_STRING_SKYBOX_BASIC);
 | |
|         // Globals.skybox = EntityUtils.spawnDrawableEntity(AssetDataStrings.ASSET_STRING_SKYBOX_BASIC);
 | |
|         
 | |
|         
 | |
|         /*
 | |
|         
 | |
|         Player Camera
 | |
|         
 | |
|         */
 | |
|         Globals.playerCamera = CameraEntityUtils.spawnEntityTrackingCameraEntity(new Vector3f(1,0,1), new Vector3f(0,0,0), Globals.playerEntity);
 | |
|         
 | |
|         
 | |
|         
 | |
|         /*
 | |
|         Targeting crosshair
 | |
|         */
 | |
|         Crosshair.initCrossHairEntity();
 | |
|         
 | |
|     }
 | |
|     
 | |
|     static void initMacroSimulation(){
 | |
|         Globals.macroData = MacroData.generateWorld(0);
 | |
| //        Globals.macroData.describeWorld();
 | |
|         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);
 | |
| //        Globals.macroSimulation.setReady(true);
 | |
|     }
 | |
|     
 | |
|     
 | |
|     static void initMicroSimulation(){
 | |
|         if(Globals.microSimulation == null){
 | |
|             Globals.microSimulation = new MicroSimulation();
 | |
|         }
 | |
|     }
 | |
|     
 | |
|     static void setSimulationsToReady(){
 | |
|         Globals.microSimulation.setReady(true);
 | |
|         if(Globals.macroSimulation != null){
 | |
|             Globals.macroSimulation.setReady(true);
 | |
|         }
 | |
|     }
 | |
|     
 | |
|     static void creatingRandomEntities(){
 | |
| //        String unitCubeModelPath = Globals.assetManager.registerModel(ModelUtils.createUnitCube());
 | |
| //        Entity unitCube = EntityUtils.spawnDrawableEntity(unitCubeModelPath);
 | |
| //        EntityUtils.getEntityPosition(unitCube).set(10,2,10);
 | |
|         
 | |
| //        String goundPlaneModelPath = "Models/groundplanemassiveuv.fbx";
 | |
| //        Entity groundPlane = EntityUtils.spawnDrawableEntity(goundPlaneModelPath);
 | |
| //        EntityUtils.getEntityPosition(groundPlane).set(10f,2f,10f);
 | |
| //        EntityUtils.getEntityRotation(groundPlane).rotateAxis((float)Math.PI/2, new Vector3f(1,0,0));
 | |
| //        EntityUtils.getEntityScale(groundPlane).set(5);
 | |
| 
 | |
| //        String unitsphereModelPath = "Models/unitsphere.fbx";
 | |
| //        Entity unitsphere = EntityUtils.spawnDrawableEntity(unitsphereModelPath);
 | |
| //        EntityUtils.getEntityPosition(unitsphere).set(10f,2f,10f);
 | |
| //        EntityUtils.getEntityScale(unitsphere).set(1);
 | |
|         
 | |
| //        String smallCubePath = "Models/SmallCube.fbx";
 | |
| //        Entity originCube = EntityUtils.spawnDrawableEntity(smallCubePath);
 | |
| //        EntityUtils.getEntityPosition(originCube).set(0, 0, 0);
 | |
| //        
 | |
| //        originCube = EntityUtils.spawnDrawableEntity(smallCubePath);
 | |
| //        EntityUtils.getEntityPosition(originCube).set(1, 0, 0);
 | |
| //        
 | |
| //        originCube = EntityUtils.spawnDrawableEntity(smallCubePath);
 | |
| //        EntityUtils.getEntityPosition(originCube).set(0, 0, 1);
 | |
|         
 | |
| //        Entity font = FontUtils.makeFont(7, 1);
 | |
| //        EntityUtils.getEntityPosition(font).set(new Vector3f(0.2f,0.2f,0.0f));
 | |
|         
 | |
| //        for(int i = 0; i < 10; i++){
 | |
| //            Random rand = new Random();
 | |
| //            Entity creature = CreatureUtils.spawnBasicCreature(0, 0.01f, 0.01f);
 | |
| //            EntityUtils.getEntityPosition(creature).set(rand.nextFloat() * 10, rand.nextFloat() * 10, rand.nextFloat() * 10);
 | |
| //            EntityUtils.getEntityScale(creature).set(0.01f);
 | |
| //        }
 | |
| 
 | |
|         //trees \:D/
 | |
| //        for(int i = 0; i < 10; i++){
 | |
| //            Random rand = new Random();
 | |
| //            String treePath = "Models/tree1.fbx";
 | |
| //            Entity tree = EntityUtils.spawnDrawableEntity(treePath);
 | |
| //            EntityUtils.getPosition(tree).set(rand.nextFloat() * 150 + 10, 0, rand.nextFloat() * 150 + 10);
 | |
| ////            EntityUtils.getEntityRotation(tree).rotateAxis((float)-Math.PI/2.0f, new Vector3f(1,0,0));
 | |
| //        }
 | |
| 
 | |
| //        for(int i = 0; i < 250; i++){
 | |
| //            Random rand = new Random();
 | |
| //            String treePath = "Models/falloak1.fbx";
 | |
| //            Entity tree = EntityUtils.spawnDrawableEntity(treePath);
 | |
| //            EntityUtils.getPosition(tree).set(rand.nextFloat() * 105 + 1, 0, rand.nextFloat() * 105 + 1);
 | |
| //            EntityUtils.getRotation(tree).rotateLocalX(-(float)Math.PI/2.0f).rotateZ(rand.nextFloat());
 | |
| // //            EntityUtils.getEntityRotation(tree).rotateAxis((float)-Math.PI/2.0f, new Vector3f(1,0,0));
 | |
| //        }
 | |
|         
 | |
| //        Random rand = new Random();
 | |
| //        for(int i = 0; i < 1000; i++){
 | |
| //            String wheatPath = "Models/wheat2.fbx";
 | |
| //            Entity wheatStalk = EntityUtils.spawnDrawableEntity(wheatPath);
 | |
| //            EntityUtils.getPosition(wheatStalk).set(rand.nextFloat() * 20, 0, rand.nextFloat() * 20);
 | |
| //            EntityUtils.getRotation(wheatStalk).rotateLocalX(-(float)Math.PI/2.0f);
 | |
| //            EntityUtils.getScale(wheatStalk).set(1, 1, 2);
 | |
| //        }
 | |
|         
 | |
| //        String buildingPath = "Models/building1.fbx";
 | |
| //        Entity building = EntityUtils.spawnDrawableEntity(buildingPath);
 | |
| //        EntityUtils.getPosition(building).set(5,1.2f,5);
 | |
| //        EntityUtils.getScale(building).set(0.5f);
 | |
| //        EntityUtils.getRotation(building).rotateLocalY((float)(Math.PI));
 | |
| //        ActorUtils.applyBlenderTransformer(building);
 | |
|         
 | |
|         //spawn evil goblin
 | |
|         // Entity goblin = CreatureUtils.spawnBasicCreature("goblin");
 | |
|         // CollisionObjUtils.positionCharacter(goblin, new Vector3f(4, 0, 4));
 | |
|         // EntityUtils.getScale(goblin).set(0.005f);
 | |
|         // //give evil goblin sword
 | |
|         // Entity goblinSword = ItemUtils.spawnBasicItem("Katana");
 | |
|         // AttachUtils.attachEntityToEntityAtBone(goblin, goblinSword, "Bone.031");
 | |
|         // // attach ai to evil goblin
 | |
|         // MindlessAttacker.attachToCreature(goblin);
 | |
|         // OpportunisticAttacker.attachToCreature(goblin);
 | |
| 
 | |
|         //sword
 | |
|         // Entity sword = ItemUtils.spawnBasicItem("Katana");
 | |
|         // EntityUtils.getPosition(sword).set(new Vector3f(1,0.4f,2));
 | |
|         // EntityUtils.getRotation(sword).set(new Quaternionf().rotationY((float)(Math.PI/2.0)));
 | |
| 
 | |
| 
 | |
| 
 | |
|         //work on ez volumetrics shader
 | |
|         // Entity myCube = EntityUtils.spawnDrawableEntity("Models/unitcube.fbx");
 | |
|         // EntityUtils.getActor(myCube).maskShader("Cube", "Shaders/clouds1/clouds1.vs", "Shaders/clouds1/clouds1.fs");
 | |
|         // Globals.assetManager.addShaderToQueue("Shaders/clouds1/clouds1.vs", "Shaders/clouds1/clouds1.fs");
 | |
|         // myCube.putData(EntityDataStrings.DRAW_TRANSPARENT_PASS, true);
 | |
|         // EntityUtils.getPosition(myCube).set(3,1,3);
 | |
| 
 | |
|         // Globals.entityManager.registerBehaviorTree(new BehaviorTree() {
 | |
|         //     int i = 0;
 | |
|         //     public void simulate(){
 | |
|         //         if(i < 100){
 | |
|         //             i++;
 | |
|         //             CollisionObjUtils.getCollidable(sword).addImpulse(new Impulse(new Vector3d(0,0,1), new Vector3d(-1,0,0), 0.001, Collidable.TYPE_CREATURE));
 | |
|         //             EntityUtils.getPosition(sword).set(1,0.2f,2);
 | |
|         //         }
 | |
|         // }});
 | |
| 
 | |
|         // Globals.entityManager.registerBehaviorTree(new BehaviorTree() {
 | |
|         //     int i = 0;
 | |
|         //     public void simulate(){
 | |
|         //         if(i < 10000){
 | |
|         //             i++;
 | |
|         //             if(i % 100 == 0){
 | |
|         //                 Entity sword = ItemUtils.spawnBasicItem("Katana");
 | |
|         //                 EntityUtils.getPosition(sword).set(new Vector3f(1,1.4f,2));
 | |
|         //                 EntityUtils.getRotation(sword).set(new Quaternionf().rotationY((float)(Math.PI/2.0)));
 | |
|         //             }
 | |
|         //         }
 | |
|         // }});
 | |
| 
 | |
|         
 | |
| 
 | |
|         // DebugVisualizerUtils.spawnVectorVisualizer(new Vector3d(0,0,0), new Vector3d(-1,-1,-1));
 | |
| 
 | |
|         // Entity shorts = ItemUtils.spawnBasicItem("boots1");
 | |
|         // EntityUtils.getPosition(shorts).set(new Vector3f(2,0.1f,2));
 | |
|         // // Entity hair = ItemUtils.spawnBasicItem("hairshort1");
 | |
|         // // EntityUtils.getPosition(hair).set(new Vector3f(2,0.1f,1));
 | |
| 
 | |
| 
 | |
|         // Entity bow = ItemUtils.spawnBasicItem("bow1");
 | |
|         // EntityUtils.getPosition(bow).set(new Vector3f(2,0.1f,1));
 | |
| 
 | |
|         //crate
 | |
|         // Entity crate = EntityUtils.spawnDrawableEntity("Models/crate2.fbx");
 | |
|         // EntityUtils.getPosition(crate).set(5,0.5,5);
 | |
|         // EntityUtils.getScale(crate).set(new Vector3f(0.5f));
 | |
| 
 | |
|         // //center flame
 | |
|         // Entity fire = ParticleUtils.spawnStaticBillboardParticle();
 | |
|         // EntityUtils.getPosition(fire).set(new Vector3f(1,0.2f,1));
 | |
|         // EntityUtils.getScale(fire).set(0.6f);
 | |
|         // Actor fireActor = EntityUtils.getActor(fire);
 | |
|         // fireActor.maskShader("particleBillboard", "Shaders/flame1/flame.vs", "Shaders/flame1/flame.fs");
 | |
|         // Globals.assetManager.addShaderToQueue("Shaders/flame1/flame.vs", "Shaders/flame1/flame.fs");
 | |
| 
 | |
|         // // //campfire
 | |
|         // Entity campfire = EntityUtils.spawnDrawableEntity("Models/campfire1.fbx");
 | |
|         // EntityUtils.getPosition(campfire).set(1,0,1);
 | |
|         // EntityUtils.getRotation(campfire).rotationX(-(float)Math.PI/2.0f);
 | |
|         // campfire.putData(EntityDataStrings.DRAW_OUTLINE, true);
 | |
| 
 | |
|         // //flame
 | |
|         // Entity cube = EntityUtils.spawnDrawableEntity("Models/flame1.fbx");
 | |
|         // //shader mask
 | |
|         // EntityUtils.getActor(cube).maskShader("Sphere", "Shaders/flame2/flame.vs", "Shaders/flame2/flame.fs");
 | |
|         // Globals.assetManager.addShaderToQueue("Shaders/flame2/flame.vs", "Shaders/flame2/flame.fs");
 | |
|         // EntityUtils.getScale(cube).set(0.8f);
 | |
|         // EntityUtils.getPosition(cube).set(1,0.08f,1);
 | |
|         // EntityUtils.getRotation(cube).rotationX(-(float)Math.PI/2.0f);
 | |
|         // //texture mask
 | |
|         // EntityUtils.getActor(cube).addTextureMask(RenderUtils.generateVolumetricTextureMask("Sphere"));
 | |
|         // //set draw volumetric
 | |
|         // cube.putData(EntityDataStrings.DRAW_VOLUMETRIC, true);
 | |
| 
 | |
| 
 | |
|         // Globals.assetManager.addShaderToQueue("Shaders/grass1/grass1.vs", "Shaders/grass1/grass1.gs", "Shaders/grass1/grass1.fs");
 | |
|         // Entity grass = EntityUtils.spawnDrawableEntity("Models/grass1.fbx");
 | |
|         // //shader mask
 | |
|         // EntityUtils.getActor(grass).maskShader("Cube", "Shaders/grass1/grass1.vs", "Shaders/grass1/grass1.gs", "Shaders/grass1/grass1.fs");
 | |
|         // EntityUtils.getPosition(grass).set(3,0,1);
 | |
| 
 | |
|         // queue grass shader
 | |
|         // Globals.assetManager.addShaderToQueue("Shaders/grass1/grass1.vs", "Shaders/grass1/grass1.gs", "Shaders/grass1/grass1.fs");
 | |
|         // for(int x = 0; x < 10; x++){
 | |
|         //     for(int y = 0; y < 10; y++){
 | |
|         //         Entity grass = EntityUtils.spawnDrawableEntity("Models/grass1.fbx");
 | |
|         //         //shader mask
 | |
|         //         EntityUtils.getActor(grass).maskShader("Cube", "Shaders/grass1/grass1.vs", "Shaders/grass1/grass1.gs", "Shaders/grass1/grass1.fs");
 | |
|         //         EntityUtils.getPosition(grass).set(3 + x / 5.0f,0.0,1 + y / 5.0f);
 | |
|         //     }
 | |
|         // }
 | |
| 
 | |
| 
 | |
|         // //water cube
 | |
|         // Entity water = EntityUtils.spawnDrawableEntity("Models/watercube1.fbx");
 | |
|         // EntityUtils.getActor(water).maskShader("Cube", "Shaders/water1/water.vs", "Shaders/water1/water.fs");
 | |
|         // Globals.assetManager.addShaderToQueue("Shaders/water1/water.vs", "Shaders/water1/water.fs");
 | |
|         // // EntityUtils.getPosition(water).set(5,0.51,5);
 | |
|         // // EntityUtils.getRotation(water).rotationX((float)Math.PI/4.0f);
 | |
|         // EntityUtils.getPosition(water).set(5,-0.1,5);
 | |
|         // EntityUtils.getScale(water).set(1,1,1);
 | |
|         // //texture mask
 | |
|         // EntityUtils.getActor(water).addTextureMask(RenderUtils.generateVolumetricTextureMask("Cube"));
 | |
|         // //set draw volumetric
 | |
|         // water.putData(EntityDataStrings.DRAW_VOLUMETRIC, true);
 | |
|         // water.removeData(EntityDataStrings.DRAW_SOLID_PASS);
 | |
|         // water.putData(EntityDataStrings.DRAW_TRANSPARENT_PASS, true);
 | |
| 
 | |
| 
 | |
| 
 | |
|         // //shrine 2
 | |
|         // Entity shrine = EntityUtils.spawnDrawableEntity("Models/shrine2.fbx");
 | |
|         // EntityUtils.getPosition(shrine).set(15,0,15);
 | |
|         // EntityUtils.getRotation(shrine).rotationX((float)-Math.PI/2.0f);
 | |
|         // shrine.putData(EntityDataStrings.DRAW_OUTLINE, true);
 | |
| 
 | |
| 
 | |
| //        goblin = CreatureUtils.spawnBasicCreature("Goblin");
 | |
| //        CollisionObjUtils.positionCharacter(goblin, new Vector3f(3, 0, 4));
 | |
| //        EntityUtils.getScale(goblin).set(0.005f);
 | |
| //        
 | |
| //        goblin = CreatureUtils.spawnBasicCreature("Goblin");
 | |
| //        CollisionObjUtils.positionCharacter(goblin, new Vector3f(4, 0, 3));
 | |
| //        EntityUtils.getScale(goblin).set(0.005f);
 | |
| //        
 | |
| //        goblin = CreatureUtils.spawnBasicCreature("Goblin");
 | |
| //        CollisionObjUtils.positionCharacter(goblin, new Vector3f(3, 0, 3));
 | |
| //        EntityUtils.getScale(goblin).set(0.005f);
 | |
| 
 | |
| //        UnitUtils.spawnTextGoblin(10, 0, 10);
 | |
| 
 | |
| //        StructureUtils.spawnBasicStructure("building1", new Vector3f(5,2.4f,5), new Quaternionf());
 | |
|         
 | |
| //        Entity bow = ItemUtils.spawnBasicItem("Bow");
 | |
| //        EntityUtils.getPosition(bow).set(1, 1, 2);
 | |
|         
 | |
| //        NavMeshPathfinder.navigatePointToPointInMesh(G*lobals.navMeshManager.getMeshes().get(0), new Vector3d(10,0,5), new Vector3d(5,0,10));
 | |
|         
 | |
| //        NavMesh mesh = new NavMesh();
 | |
| //        NavCube cube = new NavCube(5,0,0,10,5,5);
 | |
| //        mesh.addNode(cube);
 | |
| //        Globals.navMeshManager.addMesh(mesh);
 | |
|         
 | |
| //        Entity fallOak = FoliageUtils.spawnBasicFoliage("FallOak1");
 | |
| //        EntityUtils.getPosition(fallOak).set(1,0,3);
 | |
| //        
 | |
| //        Entity spark = ParticleUtils.spawnBillboardParticle("Textures/animetree1leaves1.png", 150000, new Vector3f(0,0,0), 0, 0);
 | |
| //        EntityUtils.getPosition(spark).set(new Vector3f(3,3,3));
 | |
| //        EntityUtils.getScale(spark).mul(1f);
 | |
|         
 | |
| //        System.out.println(Globals.drawCellManager.)
 | |
|         
 | |
| //        Entity deer = CreatureUtils.spawnBasicCreature("Deer");
 | |
| //        EntityUtils.getPosition(deer).set(5, 0.25f, 3);
 | |
|         
 | |
|         
 | |
| //        Model deerModel = Globals.assetManager.fetchModel("Models/deer1.fbx");
 | |
| //        deerModel.describeHighLevel();
 | |
|         
 | |
|         
 | |
| //        CollisionObjUtils.positionCharacter(fallOak, new Vector3f(1, 0, 3));
 | |
| //        
 | |
| //
 | |
| //        Entity testHomie = CreatureUtils.spawnBasicCreature("Human");
 | |
| //        EntityUtils.getScale(testHomie).set(0.005f);
 | |
| //        CreatureUtils.positionCharacter(testHomie, new Vector3f(10,1,10));
 | |
| //        
 | |
| //        Entity sword = ItemUtils.spawnBasicItem("Katana");
 | |
| //        AttachUtils.attachEntityToEntityAtBone(testHomie, sword, "Bone.020");
 | |
|         
 | |
|         
 | |
| //        CollisionObjUtils.spawnCollisionPlane(new Vector3f(1,1,1), new Vector3f(8,2,10), new Quaternionf()); // .rotateLocalX(0.75f)
 | |
|         
 | |
| //        CollisionObjUtils.spawnCollisionCube(new Vector3f(1,1,1), new Vector3f(10,1,10), new Quaternionf());
 | |
|         
 | |
| //        CreatureUtils.positionCharacter(Globals.playerCharacter, new Vector3f(10,3,10));
 | |
|         
 | |
| //        StructureUtils.spawnBasicStructure("building1", new Vector3f(10,2.4f,15), new Quaternionf().rotateLocalY((float)Math.PI));
 | |
|     }
 | |
|     
 | |
|     
 | |
| }
 |