package electrosphere.engine.loadingthreads; import java.util.Random; import org.joml.Quaternionf; import org.joml.Vector3d; import electrosphere.engine.Globals; import electrosphere.engine.assetmanager.AssetDataStrings; import electrosphere.entity.Entity; import electrosphere.entity.EntityCreationUtils; import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityUtils; import electrosphere.entity.ServerEntityUtils; import electrosphere.game.server.world.ServerWorldData; import electrosphere.logger.LoggerInterface; import electrosphere.server.content.ServerContentManager; import electrosphere.server.saves.SaveUtils; import electrosphere.server.terrain.manager.ServerTerrainManager; import electrosphere.util.FileUtils; public class ArenaLoading { protected static void loadArenaGameServer(){ //init server arena terrain manager separately initServerArenaTerrainManager(); //init the data of the world initServerArenaWorldData(); //init data cell manager // LoadingUtils.initTerrainDataCellManager(); //for testing purposes FileUtils.recursivelyDelete("/Users/satellite/temp/saves/arena"); //init database connection SaveUtils.initSave("arena"); //connect to database SaveUtils.loadSave("arena"); //init authentication LoadingUtils.initAuthenticationManager(); //initialize the server thread (server only) LoadingUtils.initServerThread(); //init gridded datacell manager LoadingUtils.initGriddedRealm(); //initialize the "virtual" objects simulation //not really relevant in arena mode // initMacroSimulation(); //initialize the "real" objects simulation LoadingUtils.initMicroSimulation(); //create arena entities creatingRandomEntities(); //set simulations to ready if they exist LoadingUtils.setSimulationsToReady(); LoggerInterface.loggerEngine.INFO("[Server]Finished loading arena world"); } private static void initServerArenaTerrainManager(){ Globals.serverTerrainManager = ServerTerrainManager.constructArenaTerrainManager(); } private static void initServerArenaWorldData(){ Globals.serverWorldData = ServerWorldData.createArenaWorld(); Globals.serverContentManager = ServerContentManager.createServerContentManager(); Globals.spawnPoint = new Vector3d(1,0.1,1); // Globals.serverTerrainManager.getChunk(0, 0).addModification(new TerrainModification(0,0,5,5,5)); } private 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.initiallyPositionEntity(sword, new Vector3d(1,0.4f,2)); // EntityUtils.getRotation(sword).set(new Quaternionf().rotationY((float)(Math.PI/2.0))); // Entity leafBlock = EntityCreationUtils.createClientSpatialEntity(); // EntityCreationUtils.makeEntityDrawable(leafBlock, "Models/foliageBlockTemplate1Test1.fbx"); // EntityUtils.getPosition(leafBlock).set(3,3,3); //floating island 1 // Entity island1 = ObjectUtils.spawnBasicObject("floatingisland1"); // EntityUtils.getRotation(island1).set(new Quaternionf().rotationX(-(float)(Math.PI/2.0))); // EntityUtils.getScale(island1).set(0.3f); // EntityUtils.initiallyPositionEntity(island1, new Vector3d(5,0.5,5)); //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); //work on smoke shader // Entity myCube = EntityUtils.spawnDrawableEntity("Models/unitcube.fbx"); // EntityUtils.getActor(myCube).maskShader("Cube", "Shaders/smoke1/smoke1.vs", "Shaders/smoke1/smoke1.fs"); // Globals.assetManager.addShaderToQueue("Shaders/smoke1/smoke1.vs", "Shaders/smoke1/smoke1.fs"); // myCube.putData(EntityDataStrings.DRAW_TRANSPARENT_PASS, true); // EntityUtils.getPosition(myCube).set(3,1,3); // SceneLoader loader = new SceneLoader(); // loader.serverInstantiateSceneFile("Scenes/testscene1/testscene1.json"); // Entity chunk = TerrainChunk.createTerrainChunkEntity(); // Random rand = new Random(); // for(int i = 0; i < 100; i++){ // Entity leaves = EntityUtils.spawnDrawableEntity(AssetDataStrings.LEAVES_MODEL); // float rad = rand.nextFloat(); // float angle = (float)(rand.nextFloat() * 2.0 * Math.PI); // Vector3d position = new Vector3d(Math.cos(angle) * rad + 4,1 + (rand.nextFloat() - 0.5),Math.sin(angle) * rad + 4); // Quaternionf rotation = new Quaternionf(rand.nextFloat(), rand.nextFloat(), rand.nextFloat(), rand.nextFloat()).normalize(); // ServerEntityUtils.repositionEntity(leaves, position); // EntityUtils.getPosition(leaves).set(position); // EntityUtils.getRotation(leaves).slerp(rotation, 0.3f); // leaves.removeData(EntityDataStrings.DRAW_SOLID_PASS); // leaves.putData(EntityDataStrings.DRAW_TRANSPARENT_PASS, true); // } // 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)); } }