diff --git a/assets/Data/structures.json b/assets/Data/structures.json index 2d0badb7..629bff44 100644 --- a/assets/Data/structures.json +++ b/assets/Data/structures.json @@ -3,6 +3,7 @@ { "name" : "building1", "modelPath" : "Models/building1.fbx", + "radius" : 10, "collision" : [ { "type" : "CUBE", diff --git a/src/main/java/electrosphere/engine/LoadingThread.java b/src/main/java/electrosphere/engine/LoadingThread.java index 7191404e..432ed618 100644 --- a/src/main/java/electrosphere/engine/LoadingThread.java +++ b/src/main/java/electrosphere/engine/LoadingThread.java @@ -24,6 +24,7 @@ import electrosphere.game.collision.PhysicsUtils; import electrosphere.game.collision.collidable.Collidable; import electrosphere.game.server.ai.creature.MindlessAttacker; import electrosphere.game.server.terrain.models.TerrainModification; +import electrosphere.game.server.town.Town; import electrosphere.game.state.MicroSimulation; import electrosphere.logger.LoggerInterface; import electrosphere.main.Globals; @@ -42,6 +43,7 @@ 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.Vector3f; /** @@ -110,6 +112,7 @@ public class LoadingThread extends Thread { //init the data of the world if(Globals.RUN_SERVER){ initServerGameWorldData(); + createServerWorld(); } //initialize the server thread (server only) @@ -331,6 +334,15 @@ public class LoadingThread extends Thread { Globals.serverTerrainManager.getChunk(0, 0).addModification(new TerrainModification(0,0,5,5,5)); } + static void createServerWorld(){ + Vector2i townLoc = Town.findValidTownLocation(); + if(townLoc != null){ + int chunkSize = Globals.serverTerrainManager.getChunkWidth(); + Globals.spawnPoint = new Vector3f(townLoc.x * chunkSize, Globals.serverTerrainManager.getHeightAtPosition(townLoc.x * chunkSize,townLoc.y * chunkSize), townLoc.y * chunkSize); + Town.createTown(townLoc.x,townLoc.y); + } + } + static void initServerGameWorldData(){ Globals.serverWorldData = ServerWorldData.createGameWorld(Globals.serverTerrainManager); } diff --git a/src/main/java/electrosphere/entity/state/AttackTree.java b/src/main/java/electrosphere/entity/state/AttackTree.java index 0b165126..0abf90d8 100644 --- a/src/main/java/electrosphere/entity/state/AttackTree.java +++ b/src/main/java/electrosphere/entity/state/AttackTree.java @@ -5,7 +5,7 @@ import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityUtils; import electrosphere.entity.types.creature.CreatureUtils; import electrosphere.entity.types.hitbox.HitboxUtils; -import electrosphere.game.server.creature.type.AttackMove; +import electrosphere.game.config.creature.type.AttackMove; import electrosphere.main.Globals; import electrosphere.net.parser.net.message.EntityMessage; import electrosphere.renderer.Actor; diff --git a/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java b/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java index a011fb98..ab748d0b 100644 --- a/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java +++ b/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java @@ -8,16 +8,16 @@ import electrosphere.entity.EntityUtils; import electrosphere.entity.state.movement.MovementTree; import electrosphere.entity.types.hitbox.HitboxData; import electrosphere.entity.types.hitbox.HitboxUtils; -import electrosphere.game.server.creature.type.CreatureType; -import electrosphere.game.server.creature.type.MovementSystem; +import electrosphere.game.config.creature.type.CreatureType; +import electrosphere.game.config.creature.type.MovementSystem; import electrosphere.entity.state.AttackTree; import electrosphere.entity.state.GravityTree; import electrosphere.entity.state.IdleTree; import electrosphere.entity.types.life.LifeState; import electrosphere.game.collision.PhysicsUtils; import electrosphere.game.collision.collidable.Collidable; -import electrosphere.game.server.creature.type.AttackMove; -import electrosphere.game.server.creature.type.PhysicsObject; +import electrosphere.game.config.creature.type.AttackMove; +import electrosphere.game.config.creature.type.PhysicsObject; import electrosphere.main.Globals; import electrosphere.main.Main; import electrosphere.net.parser.net.message.EntityMessage; @@ -54,7 +54,7 @@ public class CreatureUtils { // } public static Entity spawnBasicCreature(String type){ - CreatureType rawType = Globals.creatureMap.getCreature(type); + CreatureType rawType = Globals.gameConfigCurrent.getCreatureMap().getCreature(type); Entity rVal = EntityUtils.spawnDrawableEntity(rawType.getModelPath()); for(HitboxData hitboxdata : rawType.getHitboxes()){ if(hitboxdata.getType().equals("hit")){ diff --git a/src/main/java/electrosphere/entity/types/item/ItemUtils.java b/src/main/java/electrosphere/entity/types/item/ItemUtils.java index d6fb7e1b..811cc7e5 100644 --- a/src/main/java/electrosphere/entity/types/item/ItemUtils.java +++ b/src/main/java/electrosphere/entity/types/item/ItemUtils.java @@ -6,8 +6,8 @@ import electrosphere.entity.EntityUtils; import electrosphere.entity.state.movement.MovementTree; import electrosphere.entity.types.hitbox.HitboxData; import electrosphere.entity.types.hitbox.HitboxUtils; -import electrosphere.game.server.creature.type.CreatureType; -import electrosphere.game.server.item.type.Item; +import electrosphere.game.config.creature.type.CreatureType; +import electrosphere.game.config.item.type.Item; import electrosphere.main.Globals; import electrosphere.renderer.Actor; import electrosphere.renderer.ActorUtils; @@ -21,7 +21,7 @@ import org.joml.Vector3f; */ public class ItemUtils { public static Entity spawnBasicItem(String name){ - Item item = Globals.itemMap.getItem(name); + Item item = Globals.gameConfigCurrent.getItemMap().getItem(name); Entity rVal = EntityUtils.spawnDrawableEntity(item.getModelPath()); for(HitboxData hitboxdata : item.getHitboxes()){ Globals.hitboxManager.registerHitbox(HitboxUtils.spawnRegularHitbox(rVal, hitboxdata.getBone(), hitboxdata.getRadius())); diff --git a/src/main/java/electrosphere/entity/types/life/LifeState.java b/src/main/java/electrosphere/entity/types/life/LifeState.java index f02e3b41..3af5bd07 100644 --- a/src/main/java/electrosphere/entity/types/life/LifeState.java +++ b/src/main/java/electrosphere/entity/types/life/LifeState.java @@ -1,7 +1,7 @@ package electrosphere.entity.types.life; import electrosphere.entity.Entity; -import electrosphere.game.server.creature.type.HealthSystem; +import electrosphere.game.config.creature.type.HealthSystem; public class LifeState { diff --git a/src/main/java/electrosphere/entity/types/structure/StructureUtils.java b/src/main/java/electrosphere/entity/types/structure/StructureUtils.java index 04c63f1f..e5e956ac 100644 --- a/src/main/java/electrosphere/entity/types/structure/StructureUtils.java +++ b/src/main/java/electrosphere/entity/types/structure/StructureUtils.java @@ -5,8 +5,8 @@ import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityUtils; import electrosphere.entity.types.collision.CollisionObjUtils; import electrosphere.game.collision.collidable.Collidable; -import electrosphere.game.server.structure.model.CollisionObjectTemplate; -import electrosphere.game.server.structure.model.StructureType; +import electrosphere.game.config.structure.type.model.CollisionObjectTemplate; +import electrosphere.game.config.structure.type.model.StructureType; import electrosphere.main.Globals; import org.joml.Matrix4f; import org.joml.Quaternionf; @@ -21,7 +21,7 @@ public class StructureUtils { public static Entity spawnBasicStructure(String type, Vector3f position, Quaternionf rotation){ - StructureType rawType = Globals.structureTypeMap.getType(type); + StructureType rawType = Globals.gameConfigCurrent.getStructureTypeMap().getType(type); Entity rVal = EntityUtils.spawnDrawableEntity(rawType.getModelPath()); EntityUtils.getPosition(rVal).set(position); EntityUtils.getRotation(rVal).set(rotation); diff --git a/src/main/java/electrosphere/game/client/terrain/cache/LoadingChunk.java b/src/main/java/electrosphere/game/client/terrain/cache/LoadingChunk.java index 8d18abe8..a82118a9 100644 --- a/src/main/java/electrosphere/game/client/terrain/cache/LoadingChunk.java +++ b/src/main/java/electrosphere/game/client/terrain/cache/LoadingChunk.java @@ -37,6 +37,7 @@ public class LoadingChunk { } public void addModification(int worldX, int worldY, int locationX, int locationY, float value){ +// System.out.println("Client add modification"); ChunkModification newModification = new ChunkModification(worldX, worldY, locationX, locationY, value); modification.add(newModification); } @@ -58,7 +59,8 @@ public class LoadingChunk { ); if(modification != null){ for(ChunkModification modification : modification){ - modification.applyModification(heightmap); +// System.out.println("Apply modification"); + heightmap = modification.applyModification(heightmap); } } return heightmap; diff --git a/src/main/java/electrosphere/game/config/Config.java b/src/main/java/electrosphere/game/config/Config.java new file mode 100644 index 00000000..b91e8d45 --- /dev/null +++ b/src/main/java/electrosphere/game/config/Config.java @@ -0,0 +1,38 @@ +package electrosphere.game.config; + +import electrosphere.game.config.creature.type.model.CreatureTypeMap; +import electrosphere.game.config.item.type.model.ItemTypeMap; +import electrosphere.game.config.structure.type.model.StructureTypeMap; +import electrosphere.util.FileLoadingUtils; + +/** + * + * @author amaterasu + */ +public class Config { + + CreatureTypeMap creatureMap; + StructureTypeMap structureTypeMap; + ItemTypeMap itemMap; + + public static Config loadDefaultConfig(){ + Config config = new Config(); + config.creatureMap = FileLoadingUtils.loadObjectFromAssetPath("Data/creatures.json", CreatureTypeMap.class); + config.itemMap = FileLoadingUtils.loadObjectFromAssetPath("Data/items.json", ItemTypeMap.class); + config.structureTypeMap = FileLoadingUtils.loadObjectFromAssetPath("Data/structures.json", StructureTypeMap.class); + return config; + } + + public CreatureTypeMap getCreatureMap() { + return creatureMap; + } + + public StructureTypeMap getStructureTypeMap() { + return structureTypeMap; + } + + public ItemTypeMap getItemMap() { + return itemMap; + } + +} diff --git a/src/main/java/electrosphere/game/server/creature/type/AttackMove.java b/src/main/java/electrosphere/game/config/creature/type/AttackMove.java similarity index 90% rename from src/main/java/electrosphere/game/server/creature/type/AttackMove.java rename to src/main/java/electrosphere/game/config/creature/type/AttackMove.java index 8fd43400..fcf5e910 100644 --- a/src/main/java/electrosphere/game/server/creature/type/AttackMove.java +++ b/src/main/java/electrosphere/game/config/creature/type/AttackMove.java @@ -1,4 +1,4 @@ -package electrosphere.game.server.creature.type; +package electrosphere.game.config.creature.type; /** * diff --git a/src/main/java/electrosphere/game/server/creature/type/BodyPart.java b/src/main/java/electrosphere/game/config/creature/type/BodyPart.java similarity index 52% rename from src/main/java/electrosphere/game/server/creature/type/BodyPart.java rename to src/main/java/electrosphere/game/config/creature/type/BodyPart.java index 0ba5a070..34e36913 100644 --- a/src/main/java/electrosphere/game/server/creature/type/BodyPart.java +++ b/src/main/java/electrosphere/game/config/creature/type/BodyPart.java @@ -1,4 +1,4 @@ -package electrosphere.game.server.creature.type; +package electrosphere.game.config.creature.type; public class BodyPart { int bodyPartClass; diff --git a/src/main/java/electrosphere/game/server/creature/type/CreatureType.java b/src/main/java/electrosphere/game/config/creature/type/CreatureType.java similarity index 95% rename from src/main/java/electrosphere/game/server/creature/type/CreatureType.java rename to src/main/java/electrosphere/game/config/creature/type/CreatureType.java index 5a67cc9c..d0618ac7 100644 --- a/src/main/java/electrosphere/game/server/creature/type/CreatureType.java +++ b/src/main/java/electrosphere/game/config/creature/type/CreatureType.java @@ -1,4 +1,4 @@ -package electrosphere.game.server.creature.type; +package electrosphere.game.config.creature.type; import electrosphere.entity.types.hitbox.HitboxData; import java.util.List; diff --git a/src/main/java/electrosphere/game/server/creature/type/HealthSystem.java b/src/main/java/electrosphere/game/config/creature/type/HealthSystem.java similarity index 90% rename from src/main/java/electrosphere/game/server/creature/type/HealthSystem.java rename to src/main/java/electrosphere/game/config/creature/type/HealthSystem.java index c26d0390..d0edb02f 100644 --- a/src/main/java/electrosphere/game/server/creature/type/HealthSystem.java +++ b/src/main/java/electrosphere/game/config/creature/type/HealthSystem.java @@ -1,4 +1,4 @@ -package electrosphere.game.server.creature.type; +package electrosphere.game.config.creature.type; /** * diff --git a/src/main/java/electrosphere/game/server/creature/type/MovementSystem.java b/src/main/java/electrosphere/game/config/creature/type/MovementSystem.java similarity index 86% rename from src/main/java/electrosphere/game/server/creature/type/MovementSystem.java rename to src/main/java/electrosphere/game/config/creature/type/MovementSystem.java index 6b3bdbef..8f402a8c 100644 --- a/src/main/java/electrosphere/game/server/creature/type/MovementSystem.java +++ b/src/main/java/electrosphere/game/config/creature/type/MovementSystem.java @@ -1,4 +1,4 @@ -package electrosphere.game.server.creature.type; +package electrosphere.game.config.creature.type; public class MovementSystem { String type; diff --git a/src/main/java/electrosphere/game/server/creature/type/PhysicsObject.java b/src/main/java/electrosphere/game/config/creature/type/PhysicsObject.java similarity index 93% rename from src/main/java/electrosphere/game/server/creature/type/PhysicsObject.java rename to src/main/java/electrosphere/game/config/creature/type/PhysicsObject.java index 6b459593..6069f121 100644 --- a/src/main/java/electrosphere/game/server/creature/type/PhysicsObject.java +++ b/src/main/java/electrosphere/game/config/creature/type/PhysicsObject.java @@ -1,4 +1,4 @@ -package electrosphere.game.server.creature.type; +package electrosphere.game.config.creature.type; /** * diff --git a/src/main/java/electrosphere/game/server/creature/type/model/CreatureTypeMap.java b/src/main/java/electrosphere/game/config/creature/type/model/CreatureTypeMap.java similarity index 76% rename from src/main/java/electrosphere/game/server/creature/type/model/CreatureTypeMap.java rename to src/main/java/electrosphere/game/config/creature/type/model/CreatureTypeMap.java index 52d7a0f4..a8df57a3 100644 --- a/src/main/java/electrosphere/game/server/creature/type/model/CreatureTypeMap.java +++ b/src/main/java/electrosphere/game/config/creature/type/model/CreatureTypeMap.java @@ -1,6 +1,6 @@ -package electrosphere.game.server.creature.type.model; +package electrosphere.game.config.creature.type.model; -import electrosphere.game.server.creature.type.CreatureType; +import electrosphere.game.config.creature.type.CreatureType; import java.util.List; public class CreatureTypeMap { diff --git a/src/main/java/electrosphere/game/server/item/type/Item.java b/src/main/java/electrosphere/game/config/item/type/Item.java similarity index 91% rename from src/main/java/electrosphere/game/server/item/type/Item.java rename to src/main/java/electrosphere/game/config/item/type/Item.java index fe3d8b01..f9c2169a 100644 --- a/src/main/java/electrosphere/game/server/item/type/Item.java +++ b/src/main/java/electrosphere/game/config/item/type/Item.java @@ -1,4 +1,4 @@ -package electrosphere.game.server.item.type; +package electrosphere.game.config.item.type; import electrosphere.entity.types.hitbox.HitboxData; import java.util.List; diff --git a/src/main/java/electrosphere/game/server/item/type/model/ItemTypeMap.java b/src/main/java/electrosphere/game/config/item/type/model/ItemTypeMap.java similarity index 79% rename from src/main/java/electrosphere/game/server/item/type/model/ItemTypeMap.java rename to src/main/java/electrosphere/game/config/item/type/model/ItemTypeMap.java index 1c50be5d..59e9b4a6 100644 --- a/src/main/java/electrosphere/game/server/item/type/model/ItemTypeMap.java +++ b/src/main/java/electrosphere/game/config/item/type/model/ItemTypeMap.java @@ -1,6 +1,6 @@ -package electrosphere.game.server.item.type.model; +package electrosphere.game.config.item.type.model; -import electrosphere.game.server.item.type.Item; +import electrosphere.game.config.item.type.Item; import java.util.List; public class ItemTypeMap { diff --git a/src/main/java/electrosphere/game/server/structure/model/CollisionObjectTemplate.java b/src/main/java/electrosphere/game/config/structure/type/model/CollisionObjectTemplate.java similarity index 95% rename from src/main/java/electrosphere/game/server/structure/model/CollisionObjectTemplate.java rename to src/main/java/electrosphere/game/config/structure/type/model/CollisionObjectTemplate.java index edd12839..0e955246 100644 --- a/src/main/java/electrosphere/game/server/structure/model/CollisionObjectTemplate.java +++ b/src/main/java/electrosphere/game/config/structure/type/model/CollisionObjectTemplate.java @@ -1,4 +1,4 @@ -package electrosphere.game.server.structure.model; +package electrosphere.game.config.structure.type.model; /** * diff --git a/src/main/java/electrosphere/game/server/structure/model/StructureType.java b/src/main/java/electrosphere/game/config/structure/type/model/StructureType.java similarity index 75% rename from src/main/java/electrosphere/game/server/structure/model/StructureType.java rename to src/main/java/electrosphere/game/config/structure/type/model/StructureType.java index 31d31b66..43d34f68 100644 --- a/src/main/java/electrosphere/game/server/structure/model/StructureType.java +++ b/src/main/java/electrosphere/game/config/structure/type/model/StructureType.java @@ -1,4 +1,4 @@ -package electrosphere.game.server.structure.model; +package electrosphere.game.config.structure.type.model; import java.util.List; @@ -10,6 +10,7 @@ public class StructureType { String modelPath; String name; + float radius; List collision; @@ -24,6 +25,10 @@ public class StructureType { public String getName() { return name; } + + public float getRadius() { + return radius; + } diff --git a/src/main/java/electrosphere/game/server/structure/model/StructureTypeMap.java b/src/main/java/electrosphere/game/config/structure/type/model/StructureTypeMap.java similarity index 89% rename from src/main/java/electrosphere/game/server/structure/model/StructureTypeMap.java rename to src/main/java/electrosphere/game/config/structure/type/model/StructureTypeMap.java index 520efb30..48cc39f6 100644 --- a/src/main/java/electrosphere/game/server/structure/model/StructureTypeMap.java +++ b/src/main/java/electrosphere/game/config/structure/type/model/StructureTypeMap.java @@ -1,4 +1,4 @@ -package electrosphere.game.server.structure.model; +package electrosphere.game.config.structure.type.model; import java.util.List; diff --git a/src/main/java/electrosphere/game/server/character/CharacterGenerator.java b/src/main/java/electrosphere/game/server/character/CharacterGenerator.java index e69e2a81..e9ad5526 100644 --- a/src/main/java/electrosphere/game/server/character/CharacterGenerator.java +++ b/src/main/java/electrosphere/game/server/character/CharacterGenerator.java @@ -2,7 +2,7 @@ package electrosphere.game.server.character; import electrosphere.game.server.culture.Culture; import electrosphere.game.server.character.Character; -import electrosphere.game.server.creature.type.CreatureType; +import electrosphere.game.config.creature.type.CreatureType; public class CharacterGenerator { diff --git a/src/main/java/electrosphere/game/server/structure/virtual/Structure.java b/src/main/java/electrosphere/game/server/structure/virtual/Structure.java new file mode 100644 index 00000000..e51a7da0 --- /dev/null +++ b/src/main/java/electrosphere/game/server/structure/virtual/Structure.java @@ -0,0 +1,31 @@ +package electrosphere.game.server.structure.virtual; + +/** + * + * @author amaterasu + */ +public class Structure { + float locationX; + float locationY; + String type; + + public Structure(float locationX, float locationY, String type) { + this.locationX = locationX; + this.locationY = locationY; + this.type = type; + } + + public float getLocationX() { + return locationX; + } + + public float getLocationY() { + return locationY; + } + + public String getType() { + return type; + } + + +} diff --git a/src/main/java/electrosphere/game/server/structure/virtual/StructurePlacer.java b/src/main/java/electrosphere/game/server/structure/virtual/StructurePlacer.java new file mode 100644 index 00000000..16217029 --- /dev/null +++ b/src/main/java/electrosphere/game/server/structure/virtual/StructurePlacer.java @@ -0,0 +1,36 @@ +package electrosphere.game.server.structure.virtual; + +import electrosphere.entity.types.structure.StructureUtils; +import electrosphere.game.config.structure.type.model.StructureType; +import electrosphere.main.Globals; +import org.joml.Quaternionf; +import org.joml.Vector3f; + +/** + * + * @author amaterasu + */ +public class StructurePlacer { + + + public static Structure placeStructureAtPoint(float posX, float posY, String type){ + Structure rVal = new Structure(posX,posY,type); + + float centerHeight = Globals.serverTerrainManager.getHeightAtPosition(posX, posY); + StructureType currentTypeObject = Globals.gameConfigCurrent.getStructureTypeMap().getType(type); + float radius = currentTypeObject.getRadius(); + for(int x = -(int)radius; x < radius; x++){ + for(int y = -(int)radius; y < radius; y++){ + int newWorldX = Globals.serverWorldData.convertRealToChunkSpace(posX + x); + int newWorldY = Globals.serverWorldData.convertRealToChunkSpace(posY + y); + float newLocationX = Globals.serverWorldData.getRelativeLocation(posX + x, newWorldX); + float newLocationY = Globals.serverWorldData.getRelativeLocation(posY + y, newWorldY); +// System.out.println("Set height: " + centerHeight); +// System.out.println("Deform in chunk: " + newWorldX + "," + newWorldY); + Globals.serverTerrainManager.deformTerrainAtLocationToValue(newWorldX, newWorldY, (int)(newLocationX), (int)(newLocationY), centerHeight); + } + } + StructureUtils.spawnBasicStructure(type, new Vector3f(posX,centerHeight + 2.4f,posY), new Quaternionf()); + return rVal; + } +} diff --git a/src/main/java/electrosphere/game/server/terrain/manager/ServerTerrainManager.java b/src/main/java/electrosphere/game/server/terrain/manager/ServerTerrainManager.java index 912eb53c..29d73699 100644 --- a/src/main/java/electrosphere/game/server/terrain/manager/ServerTerrainManager.java +++ b/src/main/java/electrosphere/game/server/terrain/manager/ServerTerrainManager.java @@ -275,7 +275,7 @@ public class ServerTerrainManager { ModificationList modificationList = model.getModifications(x, y); if(modificationList != null){ for(TerrainModification modification : modificationList.getModifications()){ - modification.applyToHeightfield(heightmap); + heightmap = modification.applyToHeightfield(heightmap); } } if(elevationMapCacheContents.size() > cacheSize){ @@ -306,7 +306,15 @@ public class ServerTerrainManager { } public void deformTerrainAtLocationToValue(int worldX, int worldY, int locationX, int locationY, float value){ - +// System.out.println("Add modification at " + worldX + "," + worldY + " subloc " + locationX + "," + locationY); + TerrainModification modification = new TerrainModification(worldX,worldY,locationX,locationY,value); + model.addModification(modification); + String key = getKey(worldX,worldY); + if(elevationMapCache.containsKey(key)){ + ServerTerrainChunk chunk = elevationMapCache.get(key); + chunk.addModification(modification); + chunk.heightMap = modification.applyToHeightfield(chunk.heightMap); + } } } diff --git a/src/main/java/electrosphere/game/server/terrain/models/TerrainModel.java b/src/main/java/electrosphere/game/server/terrain/models/TerrainModel.java index e48b16c5..cf3e93b7 100644 --- a/src/main/java/electrosphere/game/server/terrain/models/TerrainModel.java +++ b/src/main/java/electrosphere/game/server/terrain/models/TerrainModel.java @@ -269,7 +269,7 @@ public class TerrainModel { float[][] rVal = new float[5][5]; for(int i = -2; i < 3; i++){ for(int j = -2; j < 3; j++){ - if(x + i >= 0 && x + i < discreteArrayDimension){ + if(x + i >= 0 && x + i < discreteArrayDimension && y + j >= 0 && y + j < discreteArrayDimension){ rVal[i+2][j+2] = elevation[x+i][y+j]; } else { rVal[i+2][j+2] = 0; @@ -343,7 +343,7 @@ public class TerrainModel { long[][] rVal = new long[5][5]; for(int i = -2; i < 3; i++){ for(int j = -2; j < 3; j++){ - if(x + i >= 0 && x + i < discreteArrayDimension){ + if(x + i >= 0 && x + i < discreteArrayDimension && y + j >= 0 && y + j < discreteArrayDimension){ rVal[i+2][j+2] = chunkRandomizer[x+i][y+j]; } else { rVal[i+2][j+2] = 0; @@ -392,6 +392,7 @@ public class TerrainModel { } public ModificationList getModifications(int worldX, int worldY){ +// System.out.println("Got modifications at " + worldX + " " + worldY); return modifications.get(getModificationKey(worldX, worldY)); } diff --git a/src/main/java/electrosphere/game/server/town/Town.java b/src/main/java/electrosphere/game/server/town/Town.java new file mode 100644 index 00000000..588489b0 --- /dev/null +++ b/src/main/java/electrosphere/game/server/town/Town.java @@ -0,0 +1,66 @@ +package electrosphere.game.server.town; + +import electrosphere.game.server.structure.virtual.StructurePlacer; +import electrosphere.game.server.terrain.manager.ServerTerrainChunk; +import electrosphere.main.Globals; +import java.util.Random; +import org.joml.Vector2i; + +/** + * + * @author amaterasu + */ +public class Town { + + int id; + static int idIncrementer = 0; + + final static int avgDiffThreshold = 10; + public static Vector2i findValidTownLocation(){ + for(int x = 0; x < Globals.serverTerrainManager.getWorldDiscreteSize(); x++){ + for(int y = 0; y < Globals.serverTerrainManager.getWorldDiscreteSize(); y++){ + ServerTerrainChunk chunk = Globals.serverTerrainManager.getChunk(x, y); + float[][] macroValues = chunk.getMacroValues(); + float sum = 0; + int count = 0; + for(int i = 0; i < 5; i++){ + for(int j = 0; j < 5; j++){ + sum = sum + macroValues[i][j]; + count++; + } + } + float average = sum / (float)count; + if(average > 1000){ + float diffSum = 0; + for(int i = 0; i < 5; i++){ + for(int j = 0; j < 5; j++){ + diffSum = diffSum + (float)Math.abs(average - macroValues[i][j]); + } + } + float averageDiff = diffSum / (float)count; + if(averageDiff < avgDiffThreshold){ + return new Vector2i(x,y); + } + } + } + } + return null; + } + + Town(){ + this.id = idIncrementer; + idIncrementer++; + } + + public static Town createTown(int x, int y){ + Town rVal = new Town(); + Random rand = new Random(); + int structCount = (rand.nextInt(3) + 2); + int chunkSize = Globals.serverTerrainManager.getChunkWidth(); + for(int i = 0; i < structCount; i++){ + StructurePlacer.placeStructureAtPoint(x * chunkSize + rand.nextFloat() * 100, y * chunkSize + rand.nextFloat() * 100, "building1"); + } + return rVal; + } + +} diff --git a/src/main/java/electrosphere/game/server/world/ServerWorldData.java b/src/main/java/electrosphere/game/server/world/ServerWorldData.java index 04149a6b..067201c1 100644 --- a/src/main/java/electrosphere/game/server/world/ServerWorldData.java +++ b/src/main/java/electrosphere/game/server/world/ServerWorldData.java @@ -94,6 +94,10 @@ public class ServerWorldData { return (int)Math.floor(real / dynamicInterpolationRatio); } + public float getRelativeLocation(float real, int world){ + return real - (world * dynamicInterpolationRatio); + } + } diff --git a/src/main/java/electrosphere/game/state/MacroSimulation.java b/src/main/java/electrosphere/game/state/MacroSimulation.java index 7c05e9a5..a1b0c10d 100644 --- a/src/main/java/electrosphere/game/state/MacroSimulation.java +++ b/src/main/java/electrosphere/game/state/MacroSimulation.java @@ -2,10 +2,12 @@ package electrosphere.game.state; import electrosphere.game.server.civilization.Civilization; import electrosphere.game.server.civilization.model.CivilizationMap; -import electrosphere.game.server.creature.type.CreatureType; -import electrosphere.game.server.creature.type.model.CreatureTypeMap; +import electrosphere.game.config.creature.type.CreatureType; +import electrosphere.game.config.creature.type.model.CreatureTypeMap; import electrosphere.game.server.culture.Culture; import electrosphere.game.server.culture.religion.Religion; +import electrosphere.game.server.structure.virtual.Structure; +import electrosphere.game.server.town.Town; import electrosphere.util.FileLoadingUtils; import electrosphere.util.Utilities; import java.util.LinkedList; @@ -18,6 +20,8 @@ public class MacroSimulation { List religionList = new LinkedList(); List creatureList = new LinkedList(); List characterList = new LinkedList(); + List townList = new LinkedList(); + List structureList = new LinkedList(); public MacroSimulation(){ init(); diff --git a/src/main/java/electrosphere/main/Globals.java b/src/main/java/electrosphere/main/Globals.java index 1a41f441..867ba772 100644 --- a/src/main/java/electrosphere/main/Globals.java +++ b/src/main/java/electrosphere/main/Globals.java @@ -19,11 +19,14 @@ import electrosphere.game.client.world.ClientWorldData; import electrosphere.game.collision.CommonWorldData; import electrosphere.engine.LoadingThread; import electrosphere.game.server.ai.AIManager; -import electrosphere.game.server.creature.type.model.CreatureTypeMap; -import electrosphere.game.server.item.type.model.ItemTypeMap; -import electrosphere.game.server.structure.model.StructureTypeMap; +import electrosphere.game.server.character.Character; +import electrosphere.game.config.creature.type.model.CreatureTypeMap; +import electrosphere.game.config.item.type.model.ItemTypeMap; +import electrosphere.game.config.structure.type.model.StructureTypeMap; +import electrosphere.game.server.structure.virtual.Structure; import electrosphere.game.state.MacroSimulation; import electrosphere.game.server.terrain.manager.ServerTerrainManager; +import electrosphere.game.server.town.Town; import electrosphere.game.server.world.ServerWorldData; import electrosphere.game.server.world.datacell.DataCellManager; import electrosphere.game.server.world.virtualcell.VirtualCellManager; @@ -54,6 +57,7 @@ import org.joml.Vector3f; import electrosphere.util.ModelLoader; import electrosphere.util.Utilities; import java.util.HashMap; +import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import org.lwjgl.glfw.GLFWErrorCallback; @@ -98,13 +102,16 @@ public class Globals { public static CollisionEngine collisionEngine; + // + // Game config + // + public static electrosphere.game.config.Config gameConfigDefault; + public static electrosphere.game.config.Config gameConfigCurrent; + // //current world // public static ServerWorldData serverWorldData; - public static CreatureTypeMap creatureMap; - public static StructureTypeMap structureTypeMap; - public static ItemTypeMap itemMap; VirtualCellManager virtualCellManager; DataCellManager dataCellManager; @@ -168,7 +175,6 @@ public class Globals { // //keeps track of all entities in game public static EntityManager entityManager; - public static EntityManager serverEntityManager; //terrain manager public static boolean LOAD_TERRAIN = false; @@ -235,6 +241,15 @@ public class Globals { + + + + + // + // + // Renderer flags + // + // public static boolean RENDER_FLAG_RENDER_SHADOW_MAP = false; public static boolean RENDER_FLAG_RENDER_SCREEN_FRAMEBUFFER_CONTENT = false; public static boolean RENDER_FLAG_RENDER_SCREEN_FRAMEBUFFER = false; @@ -253,12 +268,6 @@ public class Globals { textureMapDefault = FileLoadingUtils.loadObjectFromAssetPath("Textures/default_texture_map.json", TextureMap.class); // textureMapDefault = gson.fromJson(Files.newBufferedReader(new File(Thread.currentThread().getContextClassLoader().getResource("Textures/default_texture_map.json").getFile()).toPath()), TextureMap.class); //only the best of coding practices :) // } catch (IOException ex) { ex.printStackTrace(); } //TODO: handle better :tm: - //init creature type map - initCreatureTypeMap(); - //init structure type map - initStructureTypeMap(); - //init item type map - initItemTypeMap(); //create entity manager entityManager = new EntityManager(); //temporary hold for skybox colors @@ -273,6 +282,9 @@ public class Globals { aiManager = new AIManager(); //collision engine collisionEngine = new CollisionEngine(); + //game config + gameConfigDefault = electrosphere.game.config.Config.loadDefaultConfig(); + gameConfigCurrent = gameConfigDefault; } public static void initDefaultGraphicalResources(){ @@ -298,35 +310,17 @@ public class Globals { defaultMeshShader = ShaderProgram.smart_assemble_shader(false,true); //init skybox assetManager.registerModelToSpecificString(RenderUtils.createSkyboxModel(null), AssetDataStrings.ASSET_STRING_SKYBOX_BASIC); - //init hurtbox + //init models assetManager.addModelPathToQueue("Models/unitsphere.fbx"); - //init hitbox assetManager.addModelPathToQueue("Models/unitsphere_1.fbx"); - //init disabled hitbox assetManager.addModelPathToQueue("Models/unitsphere_grey.fbx"); - //init smallcube assetManager.addModelPathToQueue("Models/SmallCube.fbx"); - //init unit cylinder assetManager.addModelPathToQueue("Models/unitcylinder.fbx"); - //init unit plane assetManager.addModelPathToQueue("Models/unitplane.fbx"); - //init unit plane assetManager.addModelPathToQueue("Models/unitcube.fbx"); //as these assets are required for the renderer to work, we go ahead and //load them into memory now. The loading time penalty is worth it I think. Globals.assetManager.loadAssetsInQueue(); } - - static void initCreatureTypeMap(){ - creatureMap = FileLoadingUtils.loadObjectFromAssetPath("Data/creatures.json", CreatureTypeMap.class); - } - - static void initItemTypeMap(){ - itemMap = FileLoadingUtils.loadObjectFromAssetPath("Data/items.json", ItemTypeMap.class); - } - - static void initStructureTypeMap(){ - structureTypeMap = FileLoadingUtils.loadObjectFromAssetPath("Data/structures.json", StructureTypeMap.class); - } } diff --git a/src/main/java/electrosphere/net/server/ServerProtocol.java b/src/main/java/electrosphere/net/server/ServerProtocol.java index 844f53c5..0186fa03 100644 --- a/src/main/java/electrosphere/net/server/ServerProtocol.java +++ b/src/main/java/electrosphere/net/server/ServerProtocol.java @@ -84,6 +84,8 @@ public class ServerProtocol { long randomizerValue22 */ +// System.out.println("Received request for chunk " + message.getworldX() + " " + message.getworldY()); + ServerTerrainChunk chunk = Globals.serverTerrainManager.getChunk(message.getworldX(), message.getworldY()); float[][] macroValues = chunk.getMacroValues();//Globals.serverTerrainManager.getRad5MacroValues(message.getworldX(), message.getworldY()); diff --git a/src/main/java/electrosphere/renderer/RenderingEngine.java b/src/main/java/electrosphere/renderer/RenderingEngine.java index 4bb40be2..7791d731 100644 --- a/src/main/java/electrosphere/renderer/RenderingEngine.java +++ b/src/main/java/electrosphere/renderer/RenderingEngine.java @@ -6,7 +6,7 @@ import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityUtils; import electrosphere.entity.types.hitbox.HitboxData; import electrosphere.entity.types.hitbox.HitboxUtils; -import electrosphere.game.server.creature.type.PhysicsObject; +import electrosphere.game.config.creature.type.PhysicsObject; import electrosphere.logger.LoggerInterface; import electrosphere.main.Globals; import static electrosphere.main.Main.deltaTime; @@ -82,7 +82,7 @@ public class RenderingEngine { static Framebuffer lightDepthBuffer; public static boolean renderHitboxes = false; - public static boolean renderPhysics = true; + public static boolean renderPhysics = false; ShaderProgram activeProgram;