diff --git a/assets/Data/creatures.json b/assets/Data/entity/creatures.json similarity index 85% rename from assets/Data/creatures.json rename to assets/Data/entity/creatures.json index 649e0bad..18981532 100644 --- a/assets/Data/creatures.json +++ b/assets/Data/entity/creatures.json @@ -5,7 +5,7 @@ { - "creatureId" : "CUBE_MAN", + "id" : "CUBE_MAN", "hitboxes" : [], "tokens" : [ "SENTIENT", @@ -41,9 +41,9 @@ ], "files" : [ - "Data/creatures/human.json", - "Data/creatures/animals.json", - "Data/creatures/test.json" + "Data/entity/creatures/human.json", + "Data/entity/creatures/animals.json", + "Data/entity/creatures/test.json" ] } diff --git a/assets/Data/creatures/animals.json b/assets/Data/entity/creatures/animals.json similarity index 96% rename from assets/Data/creatures/animals.json rename to assets/Data/entity/creatures/animals.json index 1e5eb424..49024f05 100644 --- a/assets/Data/creatures/animals.json +++ b/assets/Data/entity/creatures/animals.json @@ -1,7 +1,7 @@ { "creatures" : [ { - "creatureId" : "Deer", + "id" : "Deer", "hitboxes" : [ { "type": "hurt", diff --git a/assets/Data/creatures/elf.json b/assets/Data/entity/creatures/elf.json similarity index 99% rename from assets/Data/creatures/elf.json rename to assets/Data/entity/creatures/elf.json index b388468b..e61825eb 100644 --- a/assets/Data/creatures/elf.json +++ b/assets/Data/entity/creatures/elf.json @@ -1,7 +1,7 @@ { "creatures" : [ { - "creatureId" : "elf", + "id" : "elf", "hitboxes" : [ { "type": "hurt", diff --git a/assets/Data/creatures/goblin.json b/assets/Data/entity/creatures/goblin.json similarity index 99% rename from assets/Data/creatures/goblin.json rename to assets/Data/entity/creatures/goblin.json index 6c3e795b..358c0bec 100644 --- a/assets/Data/creatures/goblin.json +++ b/assets/Data/entity/creatures/goblin.json @@ -1,7 +1,7 @@ { "creatures" : [ { - "creatureId" : "goblin", + "id" : "goblin", "hitboxes" : [ { "type": "hurt", diff --git a/assets/Data/creatures/human.json b/assets/Data/entity/creatures/human.json similarity index 99% rename from assets/Data/creatures/human.json rename to assets/Data/entity/creatures/human.json index c47c14cf..feba38b8 100644 --- a/assets/Data/creatures/human.json +++ b/assets/Data/entity/creatures/human.json @@ -1,7 +1,7 @@ { "creatures" : [ { - "creatureId" : "human", + "id" : "human", "hitboxes" : [ { "type": "hurt", @@ -63,7 +63,8 @@ "CAN_EQUIP", "INVENTORY", "OUTLINE", - "PLAYABLE" + "PLAYABLE", + "UNIT_CONTROLS" ], "visualAttributes" : [ { diff --git a/assets/Data/creatures/test.json b/assets/Data/entity/creatures/test.json similarity index 100% rename from assets/Data/creatures/test.json rename to assets/Data/entity/creatures/test.json diff --git a/assets/Data/foliage.json b/assets/Data/entity/foliage.json similarity index 95% rename from assets/Data/foliage.json rename to assets/Data/entity/foliage.json index 0a541833..3503f705 100644 --- a/assets/Data/foliage.json +++ b/assets/Data/entity/foliage.json @@ -1,7 +1,7 @@ { "foliageList" : [ { - "name" : "FallOak1", + "id" : "FallOak1", "tokens" : [ "BLENDER_ROTATION" ], @@ -19,7 +19,7 @@ "modelPath" : "Models/falloak1.fbx" }, { - "name" : "Green Grass", + "id" : "Green Grass", "tokens" : [ "AMBIENT", "REACTS_TO_WIND", @@ -32,12 +32,13 @@ "modelPath" : "Models/foliage/grass2.fbx" }, { - "name" : "oak", + "id" : "oak", "tokens" : [ "TREE", "REACTS_TO_WIND", "GROWS_BACK", - "FLAMMABLE" + "FLAMMABLE", + "SEEDED" ], "growthModel": { "growthRate" : 0.001 diff --git a/assets/Data/items.json b/assets/Data/entity/items.json similarity index 97% rename from assets/Data/items.json rename to assets/Data/entity/items.json index c8722167..f7efac8c 100644 --- a/assets/Data/items.json +++ b/assets/Data/entity/items.json @@ -4,7 +4,7 @@ { - "itemId" : "Katana", + "id" : "Katana", "modelPath" : "Models/items/weapons/katana1alt.fbx", "weaponData" : { "weaponClass" : "sword1h", @@ -53,7 +53,7 @@ "iconPath" : "Textures/icons/itemIconWeapon.png" }, { - "itemId" : "Katana2H", + "id" : "Katana2H", "modelPath" : "Models/items/weapons/katana1alt.glb", "weaponData" : { "weaponClass" : "sword2h", @@ -124,7 +124,7 @@ "iconPath" : "Textures/icons/itemIconWeapon.png" }, { - "itemId" : "bow1", + "id" : "bow1", "modelPath": "Models/bow1.fbx", "weaponData" : { "weaponClass" : "bow2h", @@ -157,7 +157,7 @@ }, { - "itemId" : "shorts1", + "id" : "shorts1", "modelPath": "Models/items/itemEntityShorts.fbx", "equipData": { "equipClass" : "clothing", @@ -195,7 +195,7 @@ }, { - "itemId" : "hairshort1", + "id" : "hairshort1", "modelPath": "Models/itemEntityShorts.fbx", "equipData": { "equipClass" : "trait", @@ -233,7 +233,7 @@ }, { - "itemId" : "boots1", + "id" : "boots1", "modelPath": "Models/boots1.glb", "tokens" : [ "GRAVITY", @@ -272,7 +272,7 @@ }, { - "itemId" : "shirt1", + "id" : "shirt1", "modelPath": "Models/itemEntityShorts.fbx", "tokens" : [ "GRAVITY", diff --git a/assets/Data/objects.json b/assets/Data/entity/objects.json similarity index 100% rename from assets/Data/objects.json rename to assets/Data/entity/objects.json diff --git a/assets/Data/particles.json b/assets/Data/entity/particles.json similarity index 100% rename from assets/Data/particles.json rename to assets/Data/entity/particles.json diff --git a/assets/Data/projectile.json b/assets/Data/entity/projectile.json similarity index 100% rename from assets/Data/projectile.json rename to assets/Data/entity/projectile.json diff --git a/assets/Data/structures.json b/assets/Data/entity/structures.json similarity index 100% rename from assets/Data/structures.json rename to assets/Data/entity/structures.json diff --git a/assets/Data/civilizations.json b/assets/Data/game/civilizations.json similarity index 100% rename from assets/Data/civilizations.json rename to assets/Data/game/civilizations.json diff --git a/assets/Data/races.json b/assets/Data/game/races.json similarity index 100% rename from assets/Data/races.json rename to assets/Data/game/races.json diff --git a/assets/Data/symbolism.json b/assets/Data/game/symbolism.json similarity index 100% rename from assets/Data/symbolism.json rename to assets/Data/game/symbolism.json diff --git a/assets/Data/units/units.json b/assets/Data/game/units/units.json similarity index 100% rename from assets/Data/units/units.json rename to assets/Data/game/units/units.json diff --git a/assets/Data/voxelTypes.json b/assets/Data/game/voxelTypes.json similarity index 100% rename from assets/Data/voxelTypes.json rename to assets/Data/game/voxelTypes.json diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index c14fcc74..9fce9fcb 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -739,6 +739,7 @@ SSBO implementation Rearch instanced actor ParticleService implementation Fix SSBO implementation misusing BufferUtils +Massive entity spawning refactor to collapse entity type permutations # TODO diff --git a/net/entity.json b/net/entity.json index db26d93e..8aba58c8 100644 --- a/net/entity.json +++ b/net/entity.json @@ -121,14 +121,6 @@ "name" : "propertyValue", "type" : "FIXED_INT" }, - { - "name" : "treeType", - "type" : "FIXED_INT" - }, - { - "name" : "treeStatus", - "type" : "FIXED_INT" - }, { "name" : "time", "type" : "FIXED_LONG" @@ -145,79 +137,19 @@ "name" : "bTreeID", "type" : "FIXED_INT" }, - { - "name" : "propertyID", - "type" : "FIXED_INT" - }, { "name" : "propertyValueInt", "type" : "FIXED_INT" - }, - { - "name" : "propertyValueFloat", - "type" : "FIXED_FLOAT" - }, - { - "name" : "propertyValueDouble", - "type" : "FIXED_DOUBLE" - }, - { - "name" : "propertyValueString", - "type" : "VAR_STRING" - }, - { - "name" : "foliageSeed", - "type" : "FIXED_LONG" } ], "messageTypes" : [ { "messageName" : "Create", - "description" : "Spawns an empty entity on the client", + "description" : "Spawns an entity on the client", "data" : [ "entityID", "entityCategory", "entitySubtype", - "positionX", - "positionY", - "positionZ" - ] - }, - { - "messageName" : "SpawnCreature", - "description" : "Spawns a creature on the client", - "data" : [ - "entityID", - "creatureTemplate", - "positionX", - "positionY", - "positionZ", - "rotationX", - "rotationY", - "rotationZ", - "rotationW" - ] - }, - { - "messageName" : "SpawnItem", - "description" : "Spawns an item on the client", - "data" : [ - "entityID", - "creatureTemplate", - "positionX", - "positionY", - "positionZ", - "rotationX", - "rotationY", - "rotationZ", - "rotationW" - ] - }, - { - "messageName" : "SpawnObject", - "description" : "Spawns a generic object", - "data" : [ - "entityID", "creatureTemplate", "positionX", "positionY", @@ -301,22 +233,6 @@ "targetID" ] }, - { - "messageName" : "SpawnFoliageSeed", - "description" : "Spawns a foliage object on the client with a given seed value", - "data" : [ - "entityID", - "creatureTemplate", - "foliageSeed", - "positionX", - "positionY", - "positionZ", - "rotationX", - "rotationY", - "rotationZ", - "rotationW" - ] - }, { "messageName" : "updateEntityViewDir", "description" : "Updates the server's value for where the player is looking", diff --git a/src/main/java/electrosphere/audio/AudioEngine.java b/src/main/java/electrosphere/audio/AudioEngine.java index 44d4dd2d..34fa7e00 100644 --- a/src/main/java/electrosphere/audio/AudioEngine.java +++ b/src/main/java/electrosphere/audio/AudioEngine.java @@ -1,7 +1,7 @@ package electrosphere.audio; +import electrosphere.client.entity.camera.CameraEntityUtils; import electrosphere.engine.Globals; -import electrosphere.entity.types.camera.CameraEntityUtils; import electrosphere.logger.LoggerInterface; import electrosphere.util.math.MathUtils; diff --git a/src/main/java/electrosphere/audio/VirtualAudioSourceManager.java b/src/main/java/electrosphere/audio/VirtualAudioSourceManager.java index 29ce2174..64c7e955 100644 --- a/src/main/java/electrosphere/audio/VirtualAudioSourceManager.java +++ b/src/main/java/electrosphere/audio/VirtualAudioSourceManager.java @@ -10,8 +10,8 @@ import java.util.concurrent.CopyOnWriteArrayList; import org.joml.Vector3d; import org.joml.Vector3f; +import electrosphere.client.entity.camera.CameraEntityUtils; import electrosphere.engine.Globals; -import electrosphere.entity.types.camera.CameraEntityUtils; import electrosphere.logger.LoggerInterface; /** diff --git a/src/main/java/electrosphere/audio/collision/HitboxAudioService.java b/src/main/java/electrosphere/audio/collision/HitboxAudioService.java index b910c043..e11612e9 100644 --- a/src/main/java/electrosphere/audio/collision/HitboxAudioService.java +++ b/src/main/java/electrosphere/audio/collision/HitboxAudioService.java @@ -9,7 +9,6 @@ import electrosphere.engine.Globals; import electrosphere.entity.Entity; import electrosphere.entity.types.creature.CreatureUtils; import electrosphere.entity.types.item.ItemUtils; -import electrosphere.entity.types.object.ObjectUtils; import electrosphere.game.data.collidable.HitboxData; import electrosphere.logger.LoggerInterface; @@ -134,8 +133,8 @@ public class HitboxAudioService { String message = "Getting audio for unhandled hurtbox collision type!\n" + "Is creature: " + CreatureUtils.isCreature(receiverEntity) + "\n" + "Is item: " + ItemUtils.isItem(receiverEntity) + "\n" + - "Is weapon: " + ItemUtils.isWeapon(receiverEntity) + "\n" + - "Is object: " + ObjectUtils.isObject(receiverEntity); + "Is weapon: " + ItemUtils.isWeapon(receiverEntity) + ; if(ItemUtils.isItem(receiverEntity)){ message = message + "\nItem Type: " + ItemUtils.getType(receiverEntity); } diff --git a/src/main/java/electrosphere/client/collision/ClientHitboxCollision.java b/src/main/java/electrosphere/client/collision/ClientHitboxCollision.java index f53e1be4..83aab7e9 100644 --- a/src/main/java/electrosphere/client/collision/ClientHitboxCollision.java +++ b/src/main/java/electrosphere/client/collision/ClientHitboxCollision.java @@ -7,7 +7,6 @@ import electrosphere.engine.Globals; import electrosphere.entity.Entity; import electrosphere.entity.types.creature.CreatureUtils; import electrosphere.entity.types.item.ItemUtils; -import electrosphere.entity.types.object.ObjectUtils; import electrosphere.game.data.collidable.HitboxData; import electrosphere.logger.LoggerInterface; @@ -111,8 +110,8 @@ public class ClientHitboxCollision { String message = "Getting audio for unhandled hurtbox collision type!\n" + "Is creature: " + CreatureUtils.isCreature(receiverEntity) + "\n" + "Is item: " + ItemUtils.isItem(receiverEntity) + "\n" + - "Is weapon: " + ItemUtils.isWeapon(receiverEntity) + "\n" + - "Is object: " + ObjectUtils.isObject(receiverEntity); + "Is weapon: " + ItemUtils.isWeapon(receiverEntity) + ; if(ItemUtils.isItem(receiverEntity)){ message = message + "\nItem Type: " + ItemUtils.getType(receiverEntity); } diff --git a/src/main/java/electrosphere/client/effects/ParticleEffects.java b/src/main/java/electrosphere/client/effects/ParticleEffects.java index 41953be5..e266131f 100644 --- a/src/main/java/electrosphere/client/effects/ParticleEffects.java +++ b/src/main/java/electrosphere/client/effects/ParticleEffects.java @@ -1,10 +1,10 @@ package electrosphere.client.effects; +import electrosphere.client.entity.particle.ParticleUtils; import electrosphere.engine.Globals; import electrosphere.entity.ClientEntityUtils; import electrosphere.entity.Entity; import electrosphere.entity.EntityUtils; -import electrosphere.entity.types.particle.ParticleUtils; import electrosphere.game.data.particle.ParticleData; import java.util.Random; diff --git a/src/main/java/electrosphere/entity/types/camera/CameraEntityUtils.java b/src/main/java/electrosphere/client/entity/camera/CameraEntityUtils.java similarity index 99% rename from src/main/java/electrosphere/entity/types/camera/CameraEntityUtils.java rename to src/main/java/electrosphere/client/entity/camera/CameraEntityUtils.java index 40cb53ee..f2579391 100644 --- a/src/main/java/electrosphere/entity/types/camera/CameraEntityUtils.java +++ b/src/main/java/electrosphere/client/entity/camera/CameraEntityUtils.java @@ -1,4 +1,4 @@ -package electrosphere.entity.types.camera; +package electrosphere.client.entity.camera; import electrosphere.engine.Globals; import electrosphere.entity.Entity; diff --git a/src/main/java/electrosphere/client/targeting/crosshair/Crosshair.java b/src/main/java/electrosphere/client/entity/crosshair/Crosshair.java similarity index 92% rename from src/main/java/electrosphere/client/targeting/crosshair/Crosshair.java rename to src/main/java/electrosphere/client/entity/crosshair/Crosshair.java index e100a192..14a6847b 100644 --- a/src/main/java/electrosphere/client/targeting/crosshair/Crosshair.java +++ b/src/main/java/electrosphere/client/entity/crosshair/Crosshair.java @@ -1,11 +1,11 @@ -package electrosphere.client.targeting.crosshair; +package electrosphere.client.entity.crosshair; +import electrosphere.client.entity.camera.CameraEntityUtils; import electrosphere.engine.Globals; import electrosphere.entity.Entity; import electrosphere.entity.EntityCreationUtils; import electrosphere.entity.EntityTags; import electrosphere.entity.EntityUtils; -import electrosphere.entity.types.camera.CameraEntityUtils; import org.joml.Vector3d; @@ -25,7 +25,7 @@ public class Crosshair { public static void initCrossHairEntity(){ crossHairEntity = EntityCreationUtils.createClientSpatialEntity(); EntityCreationUtils.makeEntityDrawable(crossHairEntity, "/Models/engine/lockoncrosshair1.fbx"); - EntityUtils.setVisible(crossHairEntity, false); + // EntityUtils.setVisible(crossHairEntity, false); } @@ -49,10 +49,10 @@ public class Crosshair { if(target != null){ // System.out.println("Found target!"); currentTarget = target; - EntityUtils.setVisible(crossHairEntity, true); + // EntityUtils.setVisible(crossHairEntity, true); } else { currentTarget = null; - EntityUtils.setVisible(crossHairEntity, false); + // EntityUtils.setVisible(crossHairEntity, false); } } // } else { diff --git a/src/main/java/electrosphere/entity/types/debug/DebugVisualizerUtils.java b/src/main/java/electrosphere/client/entity/debug/DebugVisualizerUtils.java similarity index 98% rename from src/main/java/electrosphere/entity/types/debug/DebugVisualizerUtils.java rename to src/main/java/electrosphere/client/entity/debug/DebugVisualizerUtils.java index 25311a4b..16a8a153 100644 --- a/src/main/java/electrosphere/entity/types/debug/DebugVisualizerUtils.java +++ b/src/main/java/electrosphere/client/entity/debug/DebugVisualizerUtils.java @@ -1,4 +1,4 @@ -package electrosphere.entity.types.debug; +package electrosphere.client.entity.debug; import java.util.function.Consumer; diff --git a/src/main/java/electrosphere/entity/types/instance/InstanceTemplate.java b/src/main/java/electrosphere/client/entity/instance/InstanceTemplate.java similarity index 97% rename from src/main/java/electrosphere/entity/types/instance/InstanceTemplate.java rename to src/main/java/electrosphere/client/entity/instance/InstanceTemplate.java index f06244da..96ed4a86 100644 --- a/src/main/java/electrosphere/entity/types/instance/InstanceTemplate.java +++ b/src/main/java/electrosphere/client/entity/instance/InstanceTemplate.java @@ -1,4 +1,4 @@ -package electrosphere.entity.types.instance; +package electrosphere.client.entity.instance; import java.util.Map; diff --git a/src/main/java/electrosphere/entity/types/instance/InstancedEntityUtils.java b/src/main/java/electrosphere/client/entity/instance/InstancedEntityUtils.java similarity index 98% rename from src/main/java/electrosphere/entity/types/instance/InstancedEntityUtils.java rename to src/main/java/electrosphere/client/entity/instance/InstancedEntityUtils.java index 7a2a3766..582aed0e 100644 --- a/src/main/java/electrosphere/entity/types/instance/InstancedEntityUtils.java +++ b/src/main/java/electrosphere/client/entity/instance/InstancedEntityUtils.java @@ -1,4 +1,4 @@ -package electrosphere.entity.types.instance; +package electrosphere.client.entity.instance; import org.joml.Quaterniond; import org.joml.Vector3d; diff --git a/src/main/java/electrosphere/entity/types/particle/ParticleUtils.java b/src/main/java/electrosphere/client/entity/particle/ParticleUtils.java similarity index 98% rename from src/main/java/electrosphere/entity/types/particle/ParticleUtils.java rename to src/main/java/electrosphere/client/entity/particle/ParticleUtils.java index b2b1d553..f318ffd4 100644 --- a/src/main/java/electrosphere/entity/types/particle/ParticleUtils.java +++ b/src/main/java/electrosphere/client/entity/particle/ParticleUtils.java @@ -1,4 +1,4 @@ -package electrosphere.entity.types.particle; +package electrosphere.client.entity.particle; import electrosphere.engine.Globals; import electrosphere.entity.DrawableUtils; diff --git a/src/main/java/electrosphere/client/foliagemanager/FoliageCell.java b/src/main/java/electrosphere/client/foliagemanager/FoliageCell.java index 2166d310..f3a34bf5 100644 --- a/src/main/java/electrosphere/client/foliagemanager/FoliageCell.java +++ b/src/main/java/electrosphere/client/foliagemanager/FoliageCell.java @@ -18,13 +18,13 @@ import org.joml.Vector3f; import org.joml.Vector3i; import org.lwjgl.BufferUtils; +import electrosphere.client.entity.camera.CameraEntityUtils; import electrosphere.client.terrain.cache.ChunkData; import electrosphere.engine.Globals; import electrosphere.entity.Entity; import electrosphere.entity.EntityCreationUtils; import electrosphere.entity.EntityUtils; import electrosphere.entity.state.foliage.AmbientFoliage; -import electrosphere.entity.types.camera.CameraEntityUtils; import electrosphere.game.data.foliage.type.FoliageType; import electrosphere.renderer.OpenGLState; import electrosphere.renderer.RenderPipelineState; diff --git a/src/main/java/electrosphere/client/instancing/InstanceUpdater.java b/src/main/java/electrosphere/client/instancing/InstanceUpdater.java index a6ce1b84..29bd6815 100644 --- a/src/main/java/electrosphere/client/instancing/InstanceUpdater.java +++ b/src/main/java/electrosphere/client/instancing/InstanceUpdater.java @@ -4,11 +4,11 @@ import java.util.Set; import org.joml.Vector3d; +import electrosphere.client.entity.camera.CameraEntityUtils; import electrosphere.engine.Globals; import electrosphere.entity.Entity; import electrosphere.entity.EntityTags; import electrosphere.entity.EntityUtils; -import electrosphere.entity.types.camera.CameraEntityUtils; import electrosphere.renderer.actor.instance.InstancedActor; /** diff --git a/src/main/java/electrosphere/client/sim/ClientSimulation.java b/src/main/java/electrosphere/client/sim/ClientSimulation.java index f4f75c81..99f71f53 100644 --- a/src/main/java/electrosphere/client/sim/ClientSimulation.java +++ b/src/main/java/electrosphere/client/sim/ClientSimulation.java @@ -2,9 +2,10 @@ package electrosphere.client.sim; import org.joml.Vector3d; +import electrosphere.client.entity.camera.CameraEntityUtils; +import electrosphere.client.entity.crosshair.Crosshair; import electrosphere.client.fluid.manager.ClientFluidManager; import electrosphere.client.instancing.InstanceUpdater; -import electrosphere.client.targeting.crosshair.Crosshair; import electrosphere.client.terrain.manager.ClientTerrainManager; import electrosphere.engine.Globals; import electrosphere.entity.Entity; @@ -13,7 +14,6 @@ import electrosphere.entity.EntityUtils; import electrosphere.entity.state.collidable.ClientCollidableTree; import electrosphere.entity.state.equip.ClientEquipState; import electrosphere.entity.types.attach.AttachUtils; -import electrosphere.entity.types.camera.CameraEntityUtils; import electrosphere.entity.types.creature.CreatureUtils; import electrosphere.entity.types.item.ItemUtils; import electrosphere.renderer.actor.Actor; diff --git a/src/main/java/electrosphere/controls/CameraHandler.java b/src/main/java/electrosphere/controls/CameraHandler.java index 5867a19f..f60e5a23 100644 --- a/src/main/java/electrosphere/controls/CameraHandler.java +++ b/src/main/java/electrosphere/controls/CameraHandler.java @@ -4,12 +4,12 @@ import org.joml.Quaternionf; import org.joml.Vector3d; import org.joml.Vector3f; -import electrosphere.client.targeting.crosshair.Crosshair; +import electrosphere.client.entity.camera.CameraEntityUtils; +import electrosphere.client.entity.crosshair.Crosshair; import electrosphere.collision.CollisionEngine; import electrosphere.engine.Globals; import electrosphere.entity.Entity; import electrosphere.entity.EntityUtils; -import electrosphere.entity.types.camera.CameraEntityUtils; import electrosphere.net.parser.net.message.EntityMessage; import electrosphere.renderer.ui.events.MouseEvent; import electrosphere.util.math.MathUtils; diff --git a/src/main/java/electrosphere/controls/ControlHandler.java b/src/main/java/electrosphere/controls/ControlHandler.java index e0761a6a..1726e0b9 100644 --- a/src/main/java/electrosphere/controls/ControlHandler.java +++ b/src/main/java/electrosphere/controls/ControlHandler.java @@ -73,8 +73,9 @@ import org.joml.Vector3d; import org.joml.Vector3f; import electrosphere.audio.VirtualAudioSourceManager.VirtualAudioSourceType; +import electrosphere.client.entity.camera.CameraEntityUtils; +import electrosphere.client.entity.crosshair.Crosshair; import electrosphere.client.item.ItemActions; -import electrosphere.client.targeting.crosshair.Crosshair; import electrosphere.client.terrain.editing.TerrainEditing; import electrosphere.collision.CollisionEngine; import electrosphere.controls.Control.ControlMethod; @@ -94,7 +95,6 @@ import electrosphere.entity.state.movement.groundmove.ClientGroundMovementTree.M import electrosphere.entity.state.movement.jump.ClientJumpTree; import electrosphere.entity.state.movement.sprint.ClientSprintTree; import electrosphere.entity.state.movement.walk.ClientWalkTree; -import electrosphere.entity.types.camera.CameraEntityUtils; import electrosphere.entity.types.creature.CreatureUtils; import electrosphere.logger.LoggerInterface; import electrosphere.menu.WindowStrings; diff --git a/src/main/java/electrosphere/engine/loadingthreads/ClientLoading.java b/src/main/java/electrosphere/engine/loadingthreads/ClientLoading.java index 539a7cd7..e937ea0e 100644 --- a/src/main/java/electrosphere/engine/loadingthreads/ClientLoading.java +++ b/src/main/java/electrosphere/engine/loadingthreads/ClientLoading.java @@ -5,10 +5,11 @@ import java.util.concurrent.TimeUnit; import org.joml.Vector3f; +import electrosphere.client.entity.camera.CameraEntityUtils; +import electrosphere.client.entity.crosshair.Crosshair; import electrosphere.client.fluid.cells.FluidCellManager; import electrosphere.client.foliagemanager.ClientFoliageManager; import electrosphere.client.sim.ClientSimulation; -import electrosphere.client.targeting.crosshair.Crosshair; import electrosphere.client.terrain.cells.DrawCellManager; import electrosphere.controls.ControlHandler; import electrosphere.engine.Globals; @@ -19,7 +20,6 @@ import electrosphere.entity.DrawableUtils; import electrosphere.entity.Entity; import electrosphere.entity.EntityCreationUtils; import electrosphere.entity.EntityUtils; -import electrosphere.entity.types.camera.CameraEntityUtils; import electrosphere.logger.LoggerInterface; import electrosphere.menu.MenuGenerators; import electrosphere.menu.WindowStrings; diff --git a/src/main/java/electrosphere/engine/loadingthreads/LoadingUtils.java b/src/main/java/electrosphere/engine/loadingthreads/LoadingUtils.java index 908ae35c..36f5696e 100644 --- a/src/main/java/electrosphere/engine/loadingthreads/LoadingUtils.java +++ b/src/main/java/electrosphere/engine/loadingthreads/LoadingUtils.java @@ -158,7 +158,7 @@ public class LoadingUtils { // //send default template back String race = Globals.gameConfigCurrent.getCreatureTypeLoader().getPlayableRaces().get(0); - CreatureData type = Globals.gameConfigCurrent.getCreatureTypeLoader().getCreature(race); + CreatureData type = Globals.gameConfigCurrent.getCreatureTypeLoader().getType(race); CreatureTemplate template = CreatureTemplate.create(race); for(VisualAttribute attribute : type.getVisualAttributes()){ if(attribute.getType().equals(VisualAttribute.TYPE_BONE)){ diff --git a/src/main/java/electrosphere/entity/EntityCreationUtils.java b/src/main/java/electrosphere/entity/EntityCreationUtils.java index c4724869..a4701de6 100644 --- a/src/main/java/electrosphere/entity/EntityCreationUtils.java +++ b/src/main/java/electrosphere/entity/EntityCreationUtils.java @@ -14,6 +14,18 @@ import electrosphere.server.datacell.utils.ServerEntityTagUtils; import electrosphere.server.poseactor.PoseActorUtils; public class EntityCreationUtils { + + /** + * Spawns an entity that has a position in the world, but isn't necessarily drawable + * @return the entity + */ + protected static Entity spawnSpatialEntity(){ + Entity rVal = new Entity(); + rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3d(0,0,0)); + rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, new Quaterniond().identity()); + rVal.putData(EntityDataStrings.DATA_STRING_SCALE, new Vector3f(1,1,1)); + return rVal; + } /** * Creates a server entity in the given realm and position. This uses spatial entity as a server entity can't (currently) exist outside of a realm. @@ -22,7 +34,7 @@ public class EntityCreationUtils { * @return The entity */ public static Entity createServerEntity(Realm realm, Vector3d position){ - Entity rVal = EntityUtils.spawnSpatialEntity(); + Entity rVal = EntityCreationUtils.spawnSpatialEntity(); //register to global entity id lookup table EntityLookupUtils.registerServerEntity(rVal); //assign to realm @@ -63,7 +75,7 @@ public class EntityCreationUtils { * @return The entity */ public static Entity createClientSpatialEntity(){ - Entity rVal = EntityUtils.spawnSpatialEntity(); + Entity rVal = EntityCreationUtils.spawnSpatialEntity(); Globals.clientSceneWrapper.getScene().registerEntity(rVal); return rVal; } diff --git a/src/main/java/electrosphere/entity/EntityDataStrings.java b/src/main/java/electrosphere/entity/EntityDataStrings.java index 8b4e9944..dcc6182d 100644 --- a/src/main/java/electrosphere/entity/EntityDataStrings.java +++ b/src/main/java/electrosphere/entity/EntityDataStrings.java @@ -4,6 +4,12 @@ package electrosphere.entity; * Data strings for entities */ public class EntityDataStrings { + + /** + * Serialization + */ + public static final String SHOULD_SERIALIZE = "shouldSerialize"; + public static final String SHOULD_SYNCHRONIZE = "shouldSynchronize"; /* @@ -236,18 +242,11 @@ public class EntityDataStrings { */ public static final String IS_PARTICLE = "isParticle"; public static final String TREE_CLIENTPARTICLETREE = "treeClientParticleTree"; - - - /* - Structure entity - */ - public static final String STRUCTURE_IS_STRUCTURE = "structureIsStructure"; - public static final String STRUCTURE_TYPE = "structureType"; + /* Foliage entity */ - public static final String FOLIAGE_IS_FOLIAGE = "foliageIsFoliage"; public static final String FOLIAGE_TYPE = "foliageType"; public static final String FOLIAGE_AMBIENT_TREE = "foliageAmbientTree"; public static final String FOLIAGE_SEED = "foliageSeed"; diff --git a/src/main/java/electrosphere/entity/EntityUtils.java b/src/main/java/electrosphere/entity/EntityUtils.java index 1218951c..d2648d98 100644 --- a/src/main/java/electrosphere/entity/EntityUtils.java +++ b/src/main/java/electrosphere/entity/EntityUtils.java @@ -2,13 +2,10 @@ package electrosphere.entity; import electrosphere.engine.Globals; import electrosphere.renderer.actor.Actor; -import electrosphere.renderer.actor.ActorUtils; import electrosphere.server.datacell.Realm; import electrosphere.server.datacell.ServerDataCell; import electrosphere.server.datacell.utils.EntityLookupUtils; import electrosphere.server.poseactor.PoseActor; -import electrosphere.server.poseactor.PoseActorUtils; -import electrosphere.util.math.MathUtils; import org.joml.Quaterniond; import org.joml.Vector3d; @@ -31,88 +28,6 @@ public class EntityUtils { return (Vector3f)e.getData(EntityDataStrings.DATA_STRING_SCALE); } - public static String getModelPath(Entity e){ - return (String)e.getData(EntityDataStrings.DATA_STRING_MODEL_PATH); - } - - /** - * Creates an entity with an associated actor - * @param modelPath The model path of the model for the actor - * @return The entity - */ - protected static Entity spawnDrawableEntity(String modelPath){ - Entity rVal = new Entity(); - rVal.putData(EntityDataStrings.DATA_STRING_ACTOR, ActorUtils.createActorFromModelPath(modelPath)); -// rVal.putData(EntityDataStrings.DATA_STRING_MODEL_PATH, modelPath); - rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3d(0,0,0)); - rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, new Quaterniond().identity()); - rVal.putData(EntityDataStrings.DATA_STRING_SCALE, new Vector3f(1,1,1)); - rVal.putData(EntityDataStrings.DATA_STRING_DRAW, true); - rVal.putData(EntityDataStrings.DRAW_SOLID_PASS, true); - Globals.clientScene.registerEntity(rVal); - Globals.clientScene.registerEntityToTag(rVal, EntityTags.DRAWABLE); - return rVal; - } - - /** - * Creates an entity with an actor based on a model that already exists or is actively being loaded, not sure - * @param modelPath The path to the model in asset manager - * @return The entity - */ - protected static Entity spawnDrawableEntityWithPreexistingModel(String modelPath){ - Entity rVal = new Entity(); - rVal.putData(EntityDataStrings.DATA_STRING_ACTOR, ActorUtils.createActorOfLoadingModel(modelPath)); - rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3d(0,0,0)); - rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, new Quaterniond().rotateAxis(0, MathUtils.getOriginVector())); - rVal.putData(EntityDataStrings.DATA_STRING_SCALE, new Vector3f(1,1,1)); - rVal.putData(EntityDataStrings.DATA_STRING_DRAW, true); - rVal.putData(EntityDataStrings.DRAW_SOLID_PASS, true); - Globals.clientScene.registerEntity(rVal); - Globals.clientScene.registerEntityToTag(rVal, EntityTags.DRAWABLE); - return rVal; - } - - /** - * Spawns an entity with a backing pose actor (server side presumably) - * @param modelPath The model path to back the pose actor - * @return The entity - */ - protected static Entity spawnPoseableEntity(String modelPath){ - Entity rVal = new Entity(); - rVal.putData(EntityDataStrings.POSE_ACTOR, PoseActorUtils.createPoseActorFromModelPath(modelPath)); -// rVal.putData(EntityDataStrings.DATA_STRING_MODEL_PATH, modelPath); - rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3d(0,0,0)); - rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, new Quaterniond().identity()); - rVal.putData(EntityDataStrings.DATA_STRING_SCALE, new Vector3f(1,1,1)); - rVal.putData(EntityDataStrings.DATA_STRING_DRAW, true); - rVal.putData(EntityDataStrings.DRAW_SOLID_PASS, true); - return rVal; - } - - protected static Entity spawnUIEntity(String modelPath){ - Entity rVal = new Entity(); - rVal.putData(EntityDataStrings.DATA_STRING_ACTOR, ActorUtils.createActorFromModelPath(modelPath)); - rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3d(0,0,0)); - rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, new Quaterniond().rotateAxis(0, MathUtils.getOriginVector())); - rVal.putData(EntityDataStrings.DATA_STRING_SCALE, new Vector3f(1,1,1)); - rVal.putData(EntityDataStrings.DATA_STRING_UI_ELEMENT, true); - Globals.clientScene.registerEntity(rVal); - Globals.clientScene.registerEntityToTag(rVal, EntityTags.UI); - return rVal; - } - - /** - * Spawns an entity that has a position in the world, but isn't necessarily drawable - * @return the entity - */ - protected static Entity spawnSpatialEntity(){ - Entity rVal = new Entity(); - rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3d(0,0,0)); - rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, new Quaterniond().identity()); - rVal.putData(EntityDataStrings.DATA_STRING_SCALE, new Vector3f(1,1,1)); - return rVal; - } - /** * Cleans up the entity and deregisters it from all tracking datastructures * @param e The entity to clean up @@ -157,52 +72,4 @@ public class EntityUtils { return (PoseActor)e.getData(EntityDataStrings.POSE_ACTOR); } - public static void setVisible(Entity entity, boolean visible){ - entity.putData(EntityDataStrings.DATA_STRING_DRAW, visible); - } - - public static void setDraw(Entity entity, boolean draw){ - entity.putData(EntityDataStrings.DATA_STRING_DRAW, draw); - } - - public static boolean getDraw(Entity entity){ - return (boolean)entity.getData(EntityDataStrings.DATA_STRING_DRAW); - } - - /** - * Gets the type of the entity - * @param entity The entity - * @return The type - */ - public static int getEntityType(Entity entity){ - return (int)entity.getData(EntityDataStrings.ENTITY_TYPE); - } - - /** - * Sets the entity type - * @param entity the entity - * @param type the type - */ - public static void setEntityType(Entity entity, int type){ - entity.putData(EntityDataStrings.ENTITY_TYPE, type); - } - - /** - * Gets the subtype of this entity - * @param entity The entity - * @return The subtype - */ - public static String getEntitySubtype(Entity entity){ - return (String)entity.getData(EntityDataStrings.ENTITY_SUBTYPE); - } - - /** - * Sets the subtype of this entity - * @param entity The entity - * @param subtype The subtype - */ - public static void setEntitySubtype(Entity entity, String subtype){ - entity.putData(EntityDataStrings.ENTITY_SUBTYPE, subtype); - } - } diff --git a/src/main/java/electrosphere/entity/btree/StateTransitionUtil.java b/src/main/java/electrosphere/entity/btree/StateTransitionUtil.java index a6694505..b73ae40b 100644 --- a/src/main/java/electrosphere/entity/btree/StateTransitionUtil.java +++ b/src/main/java/electrosphere/entity/btree/StateTransitionUtil.java @@ -7,9 +7,9 @@ import electrosphere.engine.Globals; import electrosphere.entity.Entity; import electrosphere.entity.EntityUtils; import electrosphere.entity.state.client.firstPerson.FirstPersonTree; -import electrosphere.game.data.common.TreeDataAnimation; -import electrosphere.game.data.common.TreeDataAudio; -import electrosphere.game.data.common.TreeDataState; +import electrosphere.game.data.common.treedata.TreeDataAnimation; +import electrosphere.game.data.common.treedata.TreeDataAudio; +import electrosphere.game.data.common.treedata.TreeDataState; import electrosphere.logger.LoggerInterface; import electrosphere.renderer.actor.Actor; import electrosphere.server.poseactor.PoseActor; diff --git a/src/main/java/electrosphere/entity/scene/SceneLoader.java b/src/main/java/electrosphere/entity/scene/SceneLoader.java index 29df2b24..44226c56 100644 --- a/src/main/java/electrosphere/entity/scene/SceneLoader.java +++ b/src/main/java/electrosphere/entity/scene/SceneLoader.java @@ -5,9 +5,9 @@ import org.joml.Vector3d; import electrosphere.engine.Globals; import electrosphere.entity.Entity; import electrosphere.entity.EntityUtils; +import electrosphere.entity.types.common.CommonEntityUtils; import electrosphere.entity.types.creature.CreatureUtils; import electrosphere.entity.types.item.ItemUtils; -import electrosphere.entity.types.object.ObjectUtils; import electrosphere.game.server.world.ServerWorldData; import electrosphere.server.content.ServerContentManager; import electrosphere.server.datacell.GriddedDataCellManager; @@ -100,7 +100,7 @@ public class SceneLoader { case EntityDescriptor.TYPE_OBJECT: { Vector3d position = new Vector3d(descriptor.posX,descriptor.posY,descriptor.posZ); - Entity newEntity = ObjectUtils.serverSpawnBasicObject(realm, position, descriptor.subtype); + Entity newEntity = CommonEntityUtils.serverSpawnBasicObject(realm, position, descriptor.subtype); EntityUtils.getPosition(newEntity).set(descriptor.posX,descriptor.posY,descriptor.posZ); EntityUtils.getRotation(newEntity).set((float)descriptor.rotX, (float)descriptor.rotY, (float)descriptor.rotZ, (float)descriptor.rotW); } break; diff --git a/src/main/java/electrosphere/entity/state/attack/ClientAttackTree.java b/src/main/java/electrosphere/entity/state/attack/ClientAttackTree.java index 3de5dd4d..0e6ed77f 100644 --- a/src/main/java/electrosphere/entity/state/attack/ClientAttackTree.java +++ b/src/main/java/electrosphere/entity/state/attack/ClientAttackTree.java @@ -17,7 +17,7 @@ import electrosphere.entity.types.attach.AttachUtils; import electrosphere.entity.types.collision.CollisionObjUtils; import electrosphere.entity.types.creature.CreatureUtils; import electrosphere.entity.types.item.ItemUtils; -import electrosphere.game.data.common.TreeDataState; +import electrosphere.game.data.common.treedata.TreeDataState; import electrosphere.game.data.creature.type.attack.AttackMove; import electrosphere.game.data.item.type.WeaponData; import electrosphere.net.parser.net.message.EntityMessage; diff --git a/src/main/java/electrosphere/entity/state/attack/ServerAttackTree.java b/src/main/java/electrosphere/entity/state/attack/ServerAttackTree.java index 2dd5acba..d5a2e4d0 100644 --- a/src/main/java/electrosphere/entity/state/attack/ServerAttackTree.java +++ b/src/main/java/electrosphere/entity/state/attack/ServerAttackTree.java @@ -25,7 +25,7 @@ import electrosphere.entity.types.collision.CollisionObjUtils; import electrosphere.entity.types.creature.CreatureUtils; import electrosphere.entity.types.item.ItemUtils; import electrosphere.entity.types.projectile.ProjectileUtils; -import electrosphere.game.data.common.TreeDataState; +import electrosphere.game.data.common.treedata.TreeDataState; import electrosphere.game.data.creature.type.attack.AttackMove; import electrosphere.game.data.creature.type.equip.EquipPoint; import electrosphere.game.data.item.type.WeaponData; diff --git a/src/main/java/electrosphere/entity/state/client/firstPerson/FirstPersonTree.java b/src/main/java/electrosphere/entity/state/client/firstPerson/FirstPersonTree.java index a76167cc..c0337250 100644 --- a/src/main/java/electrosphere/entity/state/client/firstPerson/FirstPersonTree.java +++ b/src/main/java/electrosphere/entity/state/client/firstPerson/FirstPersonTree.java @@ -5,7 +5,7 @@ import electrosphere.entity.Entity; import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityUtils; import electrosphere.entity.btree.BehaviorTree; -import electrosphere.game.data.common.TreeDataAnimation; +import electrosphere.game.data.common.treedata.TreeDataAnimation; import electrosphere.renderer.actor.Actor; /** diff --git a/src/main/java/electrosphere/entity/state/equip/ClientEquipState.java b/src/main/java/electrosphere/entity/state/equip/ClientEquipState.java index 251aec17..e04aa596 100644 --- a/src/main/java/electrosphere/entity/state/equip/ClientEquipState.java +++ b/src/main/java/electrosphere/entity/state/equip/ClientEquipState.java @@ -19,7 +19,7 @@ import electrosphere.entity.state.gravity.GravityUtils; import electrosphere.entity.types.attach.AttachUtils; import electrosphere.entity.types.creature.CreatureUtils; import electrosphere.entity.types.item.ItemUtils; -import electrosphere.game.data.common.TreeDataAnimation; +import electrosphere.game.data.common.treedata.TreeDataAnimation; import electrosphere.game.data.creature.type.equip.EquipPoint; import electrosphere.game.data.item.type.EquipWhitelist; import electrosphere.game.data.item.type.Item; @@ -155,8 +155,6 @@ public class ClientEquipState implements BehaviorTree { if(PhysicsEntityUtils.containsDBody(toEquip) && toEquip.containsKey(EntityDataStrings.PHYSICS_COLLIDABLE)){ Globals.clientSceneWrapper.getCollisionEngine().destroyPhysics(toEquip); } - //hide toEquip actor - EntityUtils.setDraw(toEquip, false); //make untargetable Globals.clientSceneWrapper.getScene().removeEntityFromTag(toEquip, EntityTags.TARGETABLE); break; diff --git a/src/main/java/electrosphere/entity/state/equip/ServerEquipState.java b/src/main/java/electrosphere/entity/state/equip/ServerEquipState.java index 9df7185c..eb4aa51a 100644 --- a/src/main/java/electrosphere/entity/state/equip/ServerEquipState.java +++ b/src/main/java/electrosphere/entity/state/equip/ServerEquipState.java @@ -26,7 +26,7 @@ import electrosphere.entity.state.inventory.UnrelationalInventoryState; import electrosphere.entity.types.attach.AttachUtils; import electrosphere.entity.types.creature.CreatureUtils; import electrosphere.entity.types.item.ItemUtils; -import electrosphere.game.data.common.TreeDataAnimation; +import electrosphere.game.data.common.treedata.TreeDataAnimation; import electrosphere.game.data.creature.type.block.BlockSystem; import electrosphere.game.data.creature.type.block.BlockVariant; import electrosphere.game.data.creature.type.equip.EquipPoint; @@ -130,8 +130,6 @@ public class ServerEquipState implements BehaviorTree { Realm inWorldRealm = Globals.realmManager.getEntityRealm(inWorldItem); inWorldRealm.getCollisionEngine().destroyPhysics(inWorldItem); } - //hide toEquip actor - EntityUtils.setDraw(inWorldItem, false); //make untargetable ServerEntityTagUtils.removeTagFromEntity(inWorldItem, EntityTags.TARGETABLE); break; diff --git a/src/main/java/electrosphere/entity/state/idle/ClientIdleTree.java b/src/main/java/electrosphere/entity/state/idle/ClientIdleTree.java index a486a34d..4f7c5a60 100644 --- a/src/main/java/electrosphere/entity/state/idle/ClientIdleTree.java +++ b/src/main/java/electrosphere/entity/state/idle/ClientIdleTree.java @@ -47,7 +47,7 @@ public class ClientIdleTree implements BehaviorTree { state = IdleTreeState.IDLE; parent = e; //check if this is a creature, if so add its idle data - CreatureData creatureType = Globals.gameConfigCurrent.getCreatureTypeLoader().getCreature(CreatureUtils.getType(parent)); + CreatureData creatureType = Globals.gameConfigCurrent.getCreatureTypeLoader().getType(CreatureUtils.getType(parent)); if(creatureType != null){ idleData = creatureType.getIdleData(); } diff --git a/src/main/java/electrosphere/entity/state/movement/fall/ServerFallTree.java b/src/main/java/electrosphere/entity/state/movement/fall/ServerFallTree.java index 3f49b311..5ebf57a4 100644 --- a/src/main/java/electrosphere/entity/state/movement/fall/ServerFallTree.java +++ b/src/main/java/electrosphere/entity/state/movement/fall/ServerFallTree.java @@ -8,7 +8,7 @@ import electrosphere.entity.btree.StateTransitionUtil; import electrosphere.entity.btree.StateTransitionUtil.StateTransitionUtilItem; import electrosphere.entity.state.gravity.ServerGravityTree; import electrosphere.entity.state.movement.jump.ServerJumpTree; -import electrosphere.game.data.common.TreeDataAnimation; +import electrosphere.game.data.common.treedata.TreeDataAnimation; import electrosphere.game.data.creature.type.movement.FallMovementSystem; import electrosphere.server.poseactor.PoseActor; diff --git a/src/main/java/electrosphere/entity/state/movement/groundmove/ServerGroundMovementTree.java b/src/main/java/electrosphere/entity/state/movement/groundmove/ServerGroundMovementTree.java index 73542b42..b1b8a1ec 100644 --- a/src/main/java/electrosphere/entity/state/movement/groundmove/ServerGroundMovementTree.java +++ b/src/main/java/electrosphere/entity/state/movement/groundmove/ServerGroundMovementTree.java @@ -4,10 +4,10 @@ package electrosphere.entity.state.movement.groundmove; import electrosphere.server.datacell.utils.ServerBehaviorTreeUtils; import electrosphere.net.parser.net.message.SynchronizationMessage; import electrosphere.entity.state.gravity.GravityUtils; +import electrosphere.client.entity.camera.CameraEntityUtils; import electrosphere.collision.PhysicsEntityUtils; import electrosphere.collision.collidable.Collidable; import electrosphere.engine.Globals; -import electrosphere.entity.types.camera.CameraEntityUtils; import electrosphere.entity.types.creature.CreatureUtils; import electrosphere.game.data.creature.type.movement.GroundMovementSystem; import electrosphere.entity.Entity; diff --git a/src/main/java/electrosphere/entity/state/physicssync/ClientPhysicsSyncTree.java b/src/main/java/electrosphere/entity/state/physicssync/ClientPhysicsSyncTree.java index e2fbaf85..2577d919 100644 --- a/src/main/java/electrosphere/entity/state/physicssync/ClientPhysicsSyncTree.java +++ b/src/main/java/electrosphere/entity/state/physicssync/ClientPhysicsSyncTree.java @@ -4,6 +4,7 @@ import org.joml.Quaterniond; import org.joml.Vector3d; import org.ode4j.ode.DBody; +import electrosphere.client.entity.camera.CameraEntityUtils; import electrosphere.collision.PhysicsEntityUtils; import electrosphere.collision.PhysicsUtils; import electrosphere.engine.Globals; @@ -11,7 +12,6 @@ import electrosphere.entity.Entity; import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityUtils; import electrosphere.entity.btree.BehaviorTree; -import electrosphere.entity.types.camera.CameraEntityUtils; import electrosphere.entity.types.creature.CreatureUtils; import electrosphere.net.parser.net.message.EntityMessage; diff --git a/src/main/java/electrosphere/entity/state/server/ServerPlayerViewDirTree.java b/src/main/java/electrosphere/entity/state/server/ServerPlayerViewDirTree.java index 13483f54..1c28a70c 100644 --- a/src/main/java/electrosphere/entity/state/server/ServerPlayerViewDirTree.java +++ b/src/main/java/electrosphere/entity/state/server/ServerPlayerViewDirTree.java @@ -2,12 +2,12 @@ package electrosphere.entity.state.server; import org.joml.Quaterniond; +import electrosphere.client.entity.camera.CameraEntityUtils; import electrosphere.controls.CameraHandler; import electrosphere.entity.Entity; import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityUtils; import electrosphere.entity.btree.BehaviorTree; -import electrosphere.entity.types.camera.CameraEntityUtils; import electrosphere.entity.types.creature.CreatureUtils; diff --git a/src/main/java/electrosphere/entity/types/EntityTypes.java b/src/main/java/electrosphere/entity/types/EntityTypes.java new file mode 100644 index 00000000..7f8e1ab0 --- /dev/null +++ b/src/main/java/electrosphere/entity/types/EntityTypes.java @@ -0,0 +1,73 @@ +package electrosphere.entity.types; + +/** + * Types of entities + */ +public class EntityTypes { + + + /** + *
The distinct types of entities
+ * The non-common entity types have a unique creation flow + */ + public static enum EntityType { + /** + * A creature + */ + CREATURE(0), + /** + * An item + */ + ITEM(1), + /** + * The common entity type + */ + COMMON(2), + /** + * A piece of foliage + */ + FOLIAGE(3); + + /** + * the value of the enum + */ + private final int value; + + /** + * Constructor + * @param newValue The value + */ + EntityType(final int newValue){ + value = newValue; + } + + /** + * Gets the value of the enum + * @return The value + */ + public int getValue(){ + return value; + } + + } + + /** + * Gets an entity type from a value + * @param value The value + * @return The corresponding entity type + */ + public static EntityType fromInt(int value){ + switch(value){ + case 0: + return EntityType.CREATURE; + case 1: + return EntityType.ITEM; + case 2: + return EntityType.COMMON; + case 3: + return EntityType.FOLIAGE; + } + throw new IllegalArgumentException("Trying to get invalid entity type! " + value); + } + +} diff --git a/src/main/java/electrosphere/entity/types/collision/CollisionObjUtils.java b/src/main/java/electrosphere/entity/types/collision/CollisionObjUtils.java index 16a21ebb..aeab90a0 100644 --- a/src/main/java/electrosphere/entity/types/collision/CollisionObjUtils.java +++ b/src/main/java/electrosphere/entity/types/collision/CollisionObjUtils.java @@ -2,20 +2,16 @@ package electrosphere.entity.types.collision; import org.joml.Quaterniond; import org.joml.Vector3d; -import org.joml.Vector3f; import org.ode4j.ode.DBody; -import electrosphere.collision.CollisionBodyCreation; import electrosphere.collision.CollisionEngine; import electrosphere.collision.PhysicsEntityUtils; import electrosphere.collision.PhysicsUtils; import electrosphere.collision.collidable.Collidable; import electrosphere.engine.Globals; import electrosphere.entity.Entity; -import electrosphere.entity.EntityCreationUtils; import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityUtils; -import electrosphere.entity.types.attach.AttachUtils; import electrosphere.server.datacell.Realm; /** @@ -23,207 +19,6 @@ import electrosphere.server.datacell.Realm; */ public class CollisionObjUtils { - public static Entity clientSpawnCollisionPlane(Vector3f scale, Vector3d position, Quaterniond rotation){ - Entity rVal = EntityCreationUtils.createClientSpatialEntity(); - - float mass = 1.0f; - - DBody planeObject = CollisionBodyCreation.createPlaneBody(Globals.clientSceneWrapper.getCollisionEngine(),new Vector3d(scale),Collidable.TYPE_STATIC_BIT); - PhysicsUtils.setRigidBodyTransform(Globals.clientSceneWrapper.getCollisionEngine(), position, rotation, planeObject); - Collidable collidable = new Collidable(rVal, Collidable.TYPE_STRUCTURE, true); - Globals.clientSceneWrapper.getCollisionEngine().registerCollisionObject(planeObject, collidable); - - rVal.putData(EntityDataStrings.COLLISION_ENTITY_TYPE_PLANE, true); - rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3d(position.x,position.y,position.z)); - rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, rotation); - rVal.putData(EntityDataStrings.DATA_STRING_SCALE, scale); - rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLISION_OBJECT, planeObject); - rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLIDABLE, collidable); - rVal.putData(EntityDataStrings.PHYSICS_MASS, mass); - rVal.putData(EntityDataStrings.DATA_STRING_DRAW, true); - - return rVal; - } - - public static Entity serverSpawnCollisionPlane(Realm realm, Vector3f scale, Vector3d position, Quaterniond rotation){ - Entity rVal = EntityCreationUtils.createServerEntity(realm, new Vector3d(position)); - - float mass = 1.0f; - - DBody planeObject = CollisionBodyCreation.createPlaneBody(realm.getCollisionEngine(),new Vector3d(scale),Collidable.TYPE_STATIC_BIT); - PhysicsUtils.setRigidBodyTransform(realm.getCollisionEngine(), position, rotation, planeObject); - Collidable collidable = new Collidable(rVal, Collidable.TYPE_STRUCTURE, true); - realm.getCollisionEngine().registerCollisionObject(planeObject, collidable); - - rVal.putData(EntityDataStrings.COLLISION_ENTITY_TYPE_PLANE, true); - rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3d(position.x,position.y,position.z)); - rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, rotation); - rVal.putData(EntityDataStrings.DATA_STRING_SCALE, scale); - rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLISION_OBJECT, planeObject); - rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLIDABLE, collidable); - rVal.putData(EntityDataStrings.PHYSICS_MASS, mass); - rVal.putData(EntityDataStrings.DATA_STRING_DRAW, true); - - return rVal; - } - - - public static Entity clientSpawnCollisionCube(Vector3f scale, Vector3d position, Quaterniond rotation){ - Entity rVal = EntityCreationUtils.createClientSpatialEntity(); - - float mass = 1.0f; - - DBody cubeObject = CollisionBodyCreation.createCubeBody(Globals.clientSceneWrapper.getCollisionEngine(),new Vector3d(scale),Collidable.TYPE_STATIC_BIT); - PhysicsUtils.setRigidBodyTransform(Globals.clientSceneWrapper.getCollisionEngine(), position, rotation, cubeObject); - Collidable collidable = new Collidable(rVal, Collidable.TYPE_STRUCTURE, true); - Globals.clientSceneWrapper.getCollisionEngine().registerCollisionObject(cubeObject, collidable); - - rVal.putData(EntityDataStrings.COLLISION_ENTITY_TYPE_CUBE, true); - rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3d(position.x,position.y,position.z)); - rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, rotation); - rVal.putData(EntityDataStrings.DATA_STRING_SCALE, scale); - rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLISION_OBJECT, cubeObject); - rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLIDABLE, collidable); - rVal.putData(EntityDataStrings.PHYSICS_MASS, mass); - rVal.putData(EntityDataStrings.DATA_STRING_DRAW, true); - - return rVal; - } - - public static Entity serverSpawnCollisionCube(Realm realm, Vector3f scale, Vector3d position, Quaterniond rotation){ - Entity rVal = EntityCreationUtils.createServerEntity(realm, new Vector3d(position)); - - float mass = 1.0f; - - DBody cubeObject = CollisionBodyCreation.createCubeBody(realm.getCollisionEngine(),new Vector3d(scale),Collidable.TYPE_STATIC_BIT); - PhysicsUtils.setRigidBodyTransform(realm.getCollisionEngine(), position, rotation, cubeObject); - Collidable collidable = new Collidable(rVal, Collidable.TYPE_STRUCTURE, true); - realm.getCollisionEngine().registerCollisionObject(cubeObject, collidable); - - rVal.putData(EntityDataStrings.COLLISION_ENTITY_TYPE_CUBE, true); - rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3d(position.x,position.y,position.z)); - rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, rotation); - rVal.putData(EntityDataStrings.DATA_STRING_SCALE, scale); - rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLISION_OBJECT, cubeObject); - rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLIDABLE, collidable); - rVal.putData(EntityDataStrings.PHYSICS_MASS, mass); - rVal.putData(EntityDataStrings.DATA_STRING_DRAW, true); - - return rVal; - } - - public static Entity clientSpawnCollisionCylinder(Vector3f scale, Vector3d position, Quaterniond rotation){ - Entity rVal = EntityCreationUtils.createClientSpatialEntity(); - - float mass = 1.0f; - DBody cubeObject = CollisionBodyCreation.createCylinderBody(Globals.clientSceneWrapper.getCollisionEngine(),scale.x,scale.y,Collidable.TYPE_STATIC_BIT); - PhysicsUtils.setRigidBodyTransform(Globals.clientSceneWrapper.getCollisionEngine(), position, rotation, cubeObject); - Collidable collidable = new Collidable(rVal, Collidable.TYPE_STRUCTURE, true); - Globals.clientSceneWrapper.getCollisionEngine().registerCollisionObject(cubeObject, collidable); - - rVal.putData(EntityDataStrings.COLLISION_ENTITY_TYPE_CYLINDER, true); - rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3d(position.x,position.y,position.z)); - rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, rotation); - rVal.putData(EntityDataStrings.DATA_STRING_SCALE, scale); - rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLISION_OBJECT, cubeObject); - rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLIDABLE, collidable); - rVal.putData(EntityDataStrings.PHYSICS_MASS, mass); - rVal.putData(EntityDataStrings.DATA_STRING_DRAW, true); - - return rVal; - } - - public static Entity serverSpawnCollisionCylinder(Realm realm, Vector3f scale, Vector3d position, Quaterniond rotation){ - Entity rVal = EntityCreationUtils.createServerEntity(realm, new Vector3d(position)); - - float mass = 1.0f; - DBody cubeObject = CollisionBodyCreation.createCylinderBody(realm.getCollisionEngine(),scale.x,scale.y,Collidable.TYPE_STATIC_BIT); - PhysicsUtils.setRigidBodyTransform(realm.getCollisionEngine(), position, rotation, cubeObject); - Collidable collidable = new Collidable(rVal, Collidable.TYPE_STRUCTURE, true); - realm.getCollisionEngine().registerCollisionObject(cubeObject, collidable); - - rVal.putData(EntityDataStrings.COLLISION_ENTITY_TYPE_CYLINDER, true); - rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3d(position.x,position.y,position.z)); - rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, rotation); - rVal.putData(EntityDataStrings.DATA_STRING_SCALE, scale); - rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLISION_OBJECT, cubeObject); - rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLIDABLE, collidable); - rVal.putData(EntityDataStrings.PHYSICS_MASS, mass); - rVal.putData(EntityDataStrings.DATA_STRING_DRAW, true); - - return rVal; - } - - - public static Entity clientAttachCollisionPlane(Vector3f scale, Vector3d position, Quaterniond rotation, Entity parent){ - Entity rVal = clientSpawnCollisionPlane(scale, position, rotation); - - AttachUtils.attachEntityToEntity(parent, rVal); - - float mass = 1.0f; - parent.putData(EntityDataStrings.PHYSICS_MASS, mass); - - return rVal; - } - - public static Entity serverAttachCollisionPlane(Vector3f scale, Vector3d position, Quaterniond rotation, Entity parent){ - Realm parentRealm = Globals.realmManager.getEntityRealm(parent); - Entity rVal = serverSpawnCollisionPlane(parentRealm, scale, position, rotation); - - AttachUtils.attachEntityToEntity(parent, rVal); - - float mass = 1.0f; - parent.putData(EntityDataStrings.PHYSICS_MASS, mass); - - return rVal; - } - - public static Entity clientAttachCollisionCube(Vector3f scale, Vector3d position, Quaterniond rotation, Entity parent){ - Entity rVal = clientSpawnCollisionCube(scale, position, rotation); - - AttachUtils.attachEntityToEntity(parent, rVal); - - float mass = 1.0f; - parent.putData(EntityDataStrings.PHYSICS_MASS, mass); - - return rVal; - } - - public static Entity serverAttachCollisionCube(Vector3f scale, Vector3d position, Quaterniond rotation, Entity parent){ - Realm parentRealm = Globals.realmManager.getEntityRealm(parent); - Entity rVal = serverSpawnCollisionCube(parentRealm, scale, position, rotation); - - AttachUtils.attachEntityToEntity(parent, rVal); - - float mass = 1.0f; - parent.putData(EntityDataStrings.PHYSICS_MASS, mass); - - return rVal; - } - - public static Entity clientAttachCollisionCylinder(Vector3f scale, Vector3d position, Quaterniond rotation, Entity parent){ - Entity rVal = clientSpawnCollisionCylinder(scale, position, rotation); - - AttachUtils.attachEntityToEntity(parent, rVal); - - float mass = 1.0f; - parent.putData(EntityDataStrings.PHYSICS_MASS, mass); - - return rVal; - } - - public static Entity serverAttachCollisionCylinder(Vector3f scale, Vector3d position, Quaterniond rotation, Entity parent){ - Realm parentRealm = Globals.realmManager.getEntityRealm(parent); - Entity rVal = serverSpawnCollisionCylinder(parentRealm, scale, position, rotation); - - AttachUtils.attachEntityToEntity(parent, rVal); - - float mass = 1.0f; - parent.putData(EntityDataStrings.PHYSICS_MASS, mass); - - return rVal; - } - /** * Attach a collision object to a provided entity * @param entity The entity to attach a collision object to @@ -234,7 +29,6 @@ public class CollisionObjUtils { public static void clientAttachCollisionObjectToEntity(Entity entity, DBody collisionObject, float mass, String collidableType){ Vector3d position = EntityUtils.getPosition(entity); Quaterniond rotation = EntityUtils.getRotation(entity); - Vector3f scale = EntityUtils.getScale(entity); Collidable collidable = new Collidable(entity, collidableType, true); Globals.clientSceneWrapper.getCollisionEngine().registerCollisionObject(collisionObject, collidable); @@ -257,7 +51,6 @@ public class CollisionObjUtils { */ public static void serverAttachCollisionObjectToEntity(Entity entity, DBody collisionObject, float mass, String collidableType){ Vector3d position = EntityUtils.getPosition(entity); - Vector3f scale = EntityUtils.getScale(entity); Collidable collidable = new Collidable(entity, collidableType, true); Realm realm = Globals.realmManager.getEntityRealm(entity); realm.getCollisionEngine().registerCollisionObject(collisionObject, collidable); diff --git a/src/main/java/electrosphere/entity/types/common/CommonEntityUtils.java b/src/main/java/electrosphere/entity/types/common/CommonEntityUtils.java new file mode 100644 index 00000000..753cc48d --- /dev/null +++ b/src/main/java/electrosphere/entity/types/common/CommonEntityUtils.java @@ -0,0 +1,823 @@ +package electrosphere.entity.types.common; + +import org.joml.Quaterniond; +import org.joml.Vector3d; +import org.ode4j.ode.DBody; + +import electrosphere.collision.PhysicsEntityUtils; +import electrosphere.collision.collidable.Collidable; +import electrosphere.engine.Globals; +import electrosphere.engine.assetmanager.PhysicsMeshQueueItem; +import electrosphere.entity.Entity; +import electrosphere.entity.EntityCreationUtils; +import electrosphere.entity.EntityDataStrings; +import electrosphere.entity.EntityTags; +import electrosphere.entity.EntityUtils; +import electrosphere.entity.ServerEntityUtils; +import electrosphere.entity.btree.BehaviorTree; +import electrosphere.entity.state.attack.ClientAttackTree; +import electrosphere.entity.state.attack.ServerAttackTree; +import electrosphere.entity.state.attack.ShooterTree; +import electrosphere.entity.state.block.ClientBlockTree; +import electrosphere.entity.state.block.ServerBlockTree; +import electrosphere.entity.state.equip.ClientEquipState; +import electrosphere.entity.state.equip.ServerEquipState; +import electrosphere.entity.state.gravity.ClientGravityTree; +import electrosphere.entity.state.gravity.ServerGravityTree; +import electrosphere.entity.state.hitbox.HitboxCollectionState; +import electrosphere.entity.state.idle.ClientIdleTree; +import electrosphere.entity.state.idle.ServerIdleTree; +import electrosphere.entity.state.inventory.ClientInventoryState; +import electrosphere.entity.state.inventory.InventoryUtils; +import electrosphere.entity.state.inventory.RelationalInventoryState; +import electrosphere.entity.state.inventory.ServerInventoryState; +import electrosphere.entity.state.inventory.UnrelationalInventoryState; +import electrosphere.entity.state.life.ClientLifeTree; +import electrosphere.entity.state.life.ServerLifeTree; +import electrosphere.entity.state.movement.fall.ClientFallTree; +import electrosphere.entity.state.movement.fall.ServerFallTree; +import electrosphere.entity.state.movement.groundmove.ClientGroundMovementTree; +import electrosphere.entity.state.movement.groundmove.ServerGroundMovementTree; +import electrosphere.entity.state.movement.jump.ClientJumpTree; +import electrosphere.entity.state.movement.jump.ServerJumpTree; +import electrosphere.entity.state.movement.sprint.ClientSprintTree; +import electrosphere.entity.state.movement.sprint.ServerSprintTree; +import electrosphere.entity.state.movement.walk.ClientWalkTree; +import electrosphere.entity.state.movement.walk.ServerWalkTree; +import electrosphere.entity.state.physicssync.upright.ClientAlwaysUprightTree; +import electrosphere.entity.state.physicssync.upright.ServerAlwaysUprightTree; +import electrosphere.entity.state.rotator.RotatorHierarchyNode; +import electrosphere.entity.state.rotator.RotatorTree; +import electrosphere.entity.state.rotator.ServerRotatorTree; +import electrosphere.entity.types.EntityTypes.EntityType; +import electrosphere.entity.types.collision.CollisionObjUtils; +import electrosphere.entity.types.creature.CreatureUtils; +import electrosphere.game.data.collidable.CollidableTemplate; +import electrosphere.game.data.common.CommonEntityType; +import electrosphere.game.data.creature.type.CreatureData; +import electrosphere.game.data.creature.type.SprintSystem; +import electrosphere.game.data.creature.type.attack.AttackMove; +import electrosphere.game.data.creature.type.movement.FallMovementSystem; +import electrosphere.game.data.creature.type.movement.GroundMovementSystem; +import electrosphere.game.data.creature.type.movement.JumpMovementSystem; +import electrosphere.game.data.creature.type.movement.MovementSystem; +import electrosphere.game.data.creature.type.movement.WalkMovementSystem; +import electrosphere.game.data.creature.type.rotator.RotatorConstraint; +import electrosphere.game.data.creature.type.rotator.RotatorItem; +import electrosphere.game.data.creature.type.rotator.RotatorSystem; +import electrosphere.game.data.foliage.type.FoliageType; +import electrosphere.game.data.item.type.Item; +import electrosphere.net.parser.net.message.EntityMessage; +import electrosphere.net.parser.net.message.NetworkMessage; +import electrosphere.net.server.player.Player; +import electrosphere.renderer.actor.Actor; +import electrosphere.renderer.actor.ActorBoneRotator; +import electrosphere.renderer.actor.ActorUtils; +import electrosphere.server.datacell.Realm; +import electrosphere.server.datacell.utils.ServerBehaviorTreeUtils; +import electrosphere.server.datacell.utils.ServerEntityTagUtils; +import electrosphere.server.poseactor.PoseActor; +import electrosphere.util.math.MathUtils; + +/** + * Utilities for creating all entity types + */ +public class CommonEntityUtils { + + /** + * Performs transforms common to all entity types given an entity and a template + * @param entity The entity to perform transforms on + * @param template The type of entity + * @return The entity + */ + public static Entity clientSpawnBasicCreature(Entity entity, CommonEntityType rawType){ + + // + //Set typing stuff + // + CommonEntityUtils.setTyping(entity,rawType); + + //tracks whether to generate a drawable or not + boolean generateDrawable = true; + + // + // + // Tokens that should be processed before other work is done + // + // + for(String token : rawType.getTokens()){ + switch(token){ + case "GENERATE_COLLISION_OBJECT": { + Globals.assetManager.addCollisionMeshToQueue(new PhysicsMeshQueueItem(Globals.clientSceneWrapper.getCollisionEngine(),rawType.getModelPath())); + Globals.clientSceneWrapper.getScene().registerBehaviorTree(new BehaviorTree() {public void simulate(float deltaTime) { + DBody collisionObject = Globals.assetManager.fetchCollisionObject(Globals.clientSceneWrapper.getCollisionEngine(),rawType.getModelPath()); + if(collisionObject != null){ + Globals.clientSceneWrapper.getScene().deregisterBehaviorTree(this); + CollisionObjUtils.clientAttachCollisionObjectToEntity(entity, collisionObject, 0, Collidable.TYPE_OBJECT); + } + }}); + } break; + case "GENERATE_COLLISION_TERRAIN": { + Globals.assetManager.addCollisionMeshToQueue(new PhysicsMeshQueueItem(Globals.clientSceneWrapper.getCollisionEngine(),rawType.getModelPath())); + Globals.clientSceneWrapper.getScene().registerBehaviorTree(new BehaviorTree() {public void simulate(float deltaTime) { + DBody collisionObject = Globals.assetManager.fetchCollisionObject(Globals.clientSceneWrapper.getCollisionEngine(),rawType.getModelPath()); + if(collisionObject != null){ + Globals.clientSceneWrapper.getScene().deregisterBehaviorTree(this); + CollisionObjUtils.clientAttachCollisionObjectToEntity(entity, collisionObject, 0, Collidable.TYPE_TERRAIN); + } + }}); + } break; + case "SEEDED": { + generateDrawable = false; + } break; + } + } + + // + // + //Drawable stuff + // + // + if(rawType.getModelPath() != null && EntityUtils.getActor(entity) == null && generateDrawable == true){ + EntityCreationUtils.makeEntityDrawable(entity, rawType.getModelPath()); + entity.putData(EntityDataStrings.DRAW_CAST_SHADOW, true); + } + Actor creatureActor = EntityUtils.getActor(entity); + + /// + /// + /// HITBOX DATA + /// + /// + if(rawType.getHitboxes() != null){ + HitboxCollectionState.attachHitboxState(Globals.clientSceneWrapper.getHitboxManager(), false, entity, rawType.getHitboxes()); + } + + + // + // + // PHYSICS + // + // + if(rawType.getCollidable() != null){ + CollidableTemplate physicsTemplate = rawType.getCollidable(); + PhysicsEntityUtils.clientAttachCollidableTemplate(entity, physicsTemplate); + } + + // + // + // MOVEMENT SYSTEMS + // + // + if(rawType.getMovementSystems() != null){ + for(MovementSystem movementSystem : rawType.getMovementSystems()){ + switch(movementSystem.getType()){ + // + // Generic ground + case GroundMovementSystem.GROUND_MOVEMENT_SYSTEM: + GroundMovementSystem groundMovementSystem = (GroundMovementSystem)movementSystem; + ClientGroundMovementTree moveTree = ClientGroundMovementTree.attachTree(entity, CollisionObjUtils.getCollidable(entity), groundMovementSystem); + if(groundMovementSystem.getAnimationStartup() != null){ + moveTree.setAnimationStartUp(groundMovementSystem.getAnimationStartup().getNameThirdPerson()); + } + if(groundMovementSystem.getAnimationLoop() != null){ + moveTree.setAnimationMain(groundMovementSystem.getAnimationLoop().getNameThirdPerson()); + } + if(groundMovementSystem.getAnimationWindDown()!= null){ + moveTree.setAnimationSlowDown(groundMovementSystem.getAnimationWindDown().getNameThirdPerson()); + } + //sprint system + if(groundMovementSystem.getSprintSystem() != null){ + SprintSystem sprintSystem = groundMovementSystem.getSprintSystem(); + ClientSprintTree sprintTree = ClientSprintTree.attachTree(entity, sprintSystem); + if(sprintSystem.getAnimationStartUp()!= null){ + moveTree.setAnimationSprintStartUp(sprintSystem.getAnimationStartUp().getNameThirdPerson()); + } + if(sprintSystem.getAnimationMain()!= null){ + moveTree.setAnimationSprint(sprintSystem.getAnimationMain().getNameThirdPerson()); + } + if(sprintSystem.getAnimationWindDown()!= null){ + moveTree.setAnimationSprintWindDown(sprintSystem.getAnimationWindDown().getNameThirdPerson()); + } + moveTree.setSprintTree(sprintTree); + Globals.clientScene.registerEntityToTag(entity, EntityTags.SPRINTABLE); + } + //round out end of move system + entity.putData(EntityDataStrings.CLIENT_MOVEMENT_BT, moveTree); + CreatureUtils.setFacingVector(entity, MathUtils.getOriginVector()); + entity.putData(EntityDataStrings.DATA_STRING_MAX_NATURAL_VELOCITY, groundMovementSystem.getMaxVelocity()); + entity.putData(EntityDataStrings.DATA_STRING_ACCELERATION, groundMovementSystem.getAcceleration()); + entity.putData(EntityDataStrings.DATA_STRING_VELOCITY, 0f); + Globals.clientScene.registerBehaviorTree(moveTree); + Globals.clientScene.registerEntityToTag(entity, EntityTags.MOVEABLE); + break; + // + // Jump + case JumpMovementSystem.JUMP_MOVEMENT_SYSTEM: + JumpMovementSystem jumpMovementSystem = (JumpMovementSystem)movementSystem; + ClientJumpTree jumpTree = ClientJumpTree.attachTree(entity, jumpMovementSystem); + if(jumpMovementSystem.getAnimationJump() != null){ + jumpTree.setAnimationJump(jumpMovementSystem.getAnimationJump().getNameThirdPerson()); + } + if(CreatureUtils.clientGetEntityMovementTree(entity) != null && CreatureUtils.clientGetEntityMovementTree(entity) instanceof ClientGroundMovementTree){ + ((ClientGroundMovementTree)CreatureUtils.clientGetEntityMovementTree(entity)).setClientJumpTree(jumpTree); + } + if(ClientFallTree.getFallTree(entity)!=null){ + ClientFallTree.getFallTree(entity).setJumpTree(jumpTree); + } + break; + // + // Falling + case FallMovementSystem.FALL_MOVEMENT_SYSTEM: + FallMovementSystem fallMovementSystem = (FallMovementSystem)movementSystem; + ClientFallTree fallTree = new ClientFallTree(entity, fallMovementSystem); + if(CreatureUtils.clientGetEntityMovementTree(entity) != null && CreatureUtils.clientGetEntityMovementTree(entity) instanceof ClientGroundMovementTree){ + ((ClientGroundMovementTree)CreatureUtils.clientGetEntityMovementTree(entity)).setClientFallTree(fallTree); + } + if(ClientJumpTree.getClientJumpTree(entity)!=null){ + fallTree.setJumpTree(ClientJumpTree.getClientJumpTree(entity)); + } + entity.putData(EntityDataStrings.FALL_TREE, fallTree); + Globals.clientScene.registerBehaviorTree(fallTree); + break; + case WalkMovementSystem.WALK_MOVEMENT_SYSTEM: { + ClientWalkTree.attachTree(entity, (WalkMovementSystem)movementSystem); + } break; + } + } + } + if(rawType.getEquipPoints() != null && rawType.getEquipPoints().size() > 0){ + ClientEquipState.attachTree(entity, rawType.getEquipPoints()); + entity.putData(EntityDataStrings.EQUIP_INVENTORY, RelationalInventoryState.buildRelationalInventoryStateFromEquipList(rawType.getEquipPoints())); + } + if(rawType.getBlockSystem() != null){ + ClientBlockTree.attachTree(entity, rawType.getBlockSystem()); + } + if(rawType.getTokens() != null){ + for(String token : rawType.getTokens()){ + switch(token){ + case "ATTACKER": + ClientAttackTree.attachTree(entity); + entity.putData(EntityDataStrings.ATTACK_MOVE_TYPE_ACTIVE, null); + Globals.clientScene.registerEntityToTag(entity, EntityTags.ATTACKER); + //add all attack moves + if(rawType.getAttackMoves() != null && rawType.getAttackMoves().size() > 0){ + for(AttackMove attackMove : rawType.getAttackMoves()){ + entity.putData(attackMove.getType(), rawType.getAttackMoveResolver().getMoveset(attackMove.getType())); + // switch(attackMove.getType()){ + // case EntityDataStrings.ATTACK_MOVE_TYPE_MELEE_SWING_ONE_HAND: + // rVal.putData(EntityDataStrings.ATTACK_MOVE_TYPE_MELEE_SWING_ONE_HAND, rawType.getAttackMoveResolver().getMoveset(EntityDataStrings.ATTACK_MOVE_TYPE_MELEE_SWING_ONE_HAND)); + // break; + // case EntityDataStrings.ATTACK_MOVE_TYPE_BOW_TWO_HAND: + // rVal.putData(EntityDataStrings.ATTACK_MOVE_TYPE_MELEE_SWING_ONE_HAND, rawType.getAttackMoveResolver().getMoveset(EntityDataStrings.ATTACK_MOVE_TYPE_MELEE_SWING_ONE_HAND)); + // break; + // } + } + } + break; + case "SHOOTER": { + ShooterTree shooterTree = new ShooterTree(entity); + ShooterTree.setShooterTree(entity, shooterTree); + Globals.clientScene.registerBehaviorTree(shooterTree); + } break; + case "GRAVITY": { + Collidable collidable = (Collidable)entity.getData(EntityDataStrings.PHYSICS_COLLIDABLE); + DBody collisionObject = PhysicsEntityUtils.getDBody(entity); + ClientGravityTree.attachTree(entity, collidable, collisionObject, 30); + entity.putData(EntityDataStrings.GRAVITY_ENTITY, true); + } break; + case "TARGETABLE": { + Globals.clientScene.registerEntityToTag(entity, EntityTags.TARGETABLE); + } break; + case "INVENTORY": + entity.putData(EntityDataStrings.NATURAL_INVENTORY,UnrelationalInventoryState.createUnrelationalInventory(10)); + InventoryUtils.clientSetInventoryState(entity, ClientInventoryState.clientCreateInventoryState(entity)); + break; + case "OUTLINE": { + entity.putData(EntityDataStrings.DRAW_OUTLINE, true); + } break; + case "UNIT_CONTROLS": { + ClientAlwaysUprightTree.attachTree(entity); + CreatureUtils.setFacingVector(entity, MathUtils.getOriginVector()); + } break; + case "TERRAIN_COLLISION": { + CollisionObjUtils.getCollidable(entity).overrideType(Collidable.TYPE_TERRAIN); + } break; + case "BLENDER_ROTATION": { + ActorUtils.applyBlenderRotation(entity); + } break; + case "SPAWNPOINT": { + //ignore on client + } break; + } + } + } + //rotator system + if(rawType.getRotatorSystem() != null){ + RotatorSystem system = rawType.getRotatorSystem(); + RotatorTree rotatorTree = new RotatorTree(entity); + for(RotatorItem item : system.getRotatorItems()){ + //put actor rotator + ActorBoneRotator newRotator = new ActorBoneRotator(); + creatureActor.addBoneRotator(item.getBoneName(), newRotator); + //construct node for tree + RotatorHierarchyNode hierarchyNode = new RotatorHierarchyNode(); + hierarchyNode.setBone(item.getBoneName()); + for(RotatorConstraint constraint : item.getConstraints()){ + hierarchyNode.addRotatorConstraint(new electrosphere.entity.state.rotator.RotatorConstraint(constraint)); + } + rotatorTree.addRotatorNode(hierarchyNode); + } + entity.putData(EntityDataStrings.CLIENT_ROTATOR_TREE, rotatorTree); + Globals.clientScene.registerBehaviorTree(rotatorTree); + } + //bone groups + if(rawType.getBoneGroups() != null){ + creatureActor.setBoneGroups(rawType.getBoneGroups()); + } + //add health system + if(rawType.getHealthSystem() != null){ + ClientLifeTree.attachTree(entity,rawType.getHealthSystem()); + Globals.clientScene.registerEntityToTag(entity, EntityTags.LIFE_STATE); + } + //idle tree & generic stuff all creatures have + if(rawType.getIdleData() != null){ + ClientIdleTree idleTree = new ClientIdleTree(entity); + entity.putData(EntityDataStrings.TREE_IDLE, idleTree); + Globals.clientScene.registerBehaviorTree(idleTree); + } + + return entity; + } + + + /** + * Spawns a server-side creature + * @param realm The realm to spawn the creature in + * @param position The position of the creature in that realm + * @param type The type of creature + * @param template The creature template to use + * @return The creature entity + */ + public static Entity serverSpawnBasicCreature(Realm realm, Vector3d position, Entity entity, CommonEntityType rawType){ + + // + //Set typing stuff + // + CommonEntityUtils.setTyping(entity,rawType); + CommonEntityUtils.serverAttachToTag(entity,rawType); + + //tracks whether to generate a drawable or not + boolean generateDrawable = true; + + // + // + // Tokens that should be processed before other work is done + // + // + for(String token : rawType.getTokens()){ + switch(token){ + case "GENERATE_COLLISION_OBJECT": { + Globals.assetManager.addCollisionMeshToQueue(new PhysicsMeshQueueItem(realm.getCollisionEngine(),rawType.getModelPath())); + ServerBehaviorTreeUtils.attachBTreeToEntity(entity, new BehaviorTree() {public void simulate(float deltaTime) { + DBody collisionObject = Globals.assetManager.fetchCollisionObject(realm.getCollisionEngine(),rawType.getModelPath()); + if(collisionObject != null){ + ServerBehaviorTreeUtils.detatchBTreeFromEntity(entity, this); + CollisionObjUtils.serverAttachCollisionObjectToEntity(entity, collisionObject, 0, Collidable.TYPE_OBJECT); + } + }}); + } break; + case "GENERATE_COLLISION_TERRAIN": { + Globals.assetManager.addCollisionMeshToQueue(new PhysicsMeshQueueItem(realm.getCollisionEngine(),rawType.getModelPath())); + ServerBehaviorTreeUtils.attachBTreeToEntity(entity, new BehaviorTree() {public void simulate(float deltaTime) { + DBody collisionObject = Globals.assetManager.fetchCollisionObject(realm.getCollisionEngine(),rawType.getModelPath()); + if(collisionObject != null){ + ServerBehaviorTreeUtils.detatchBTreeFromEntity(entity, this); + CollisionObjUtils.serverAttachCollisionObjectToEntity(entity, collisionObject, 0, Collidable.TYPE_TERRAIN); + } + }}); + } break; + case "SEEDED": { + generateDrawable = false; + } break; + } + } + + // + // + //Posing stuff + // + // + if(rawType.getModelPath() != null && EntityUtils.getPoseActor(entity) == null && generateDrawable == true){ + EntityCreationUtils.makeEntityPoseable(entity, rawType.getModelPath()); + } + PoseActor creatureActor = EntityUtils.getPoseActor(entity); + // + // + // Hitbox stuff + // + // + if(rawType.getHitboxes() != null){ + HitboxCollectionState.attachHitboxState(realm.getHitboxManager(), true, entity, rawType.getHitboxes()); + } + // + // + // Physics stuff + // + // + if(rawType.getCollidable() != null){ + CollidableTemplate physicsTemplate = rawType.getCollidable(); + PhysicsEntityUtils.serverAttachCollidableTemplate(realm, entity, physicsTemplate); + } + // + // + // MOVEMENT SYSTEMS + // + // + if(rawType.getMovementSystems() != null){ + for(MovementSystem movementSystem : rawType.getMovementSystems()){ + switch(movementSystem.getType()){ + // + // Generic ground + case GroundMovementSystem.GROUND_MOVEMENT_SYSTEM: + GroundMovementSystem groundMovementSystem = (GroundMovementSystem)movementSystem; + ServerGroundMovementTree moveTree = ServerGroundMovementTree.attachTree(entity,CollisionObjUtils.getCollidable(entity),groundMovementSystem); + if(groundMovementSystem.getAnimationStartup() != null){ + moveTree.setAnimationStartUp(groundMovementSystem.getAnimationStartup().getNameThirdPerson()); + } + if(groundMovementSystem.getAnimationLoop() != null){ + moveTree.setAnimationMain(groundMovementSystem.getAnimationLoop().getNameThirdPerson()); + } + if(groundMovementSystem.getAnimationWindDown()!= null){ + moveTree.setAnimationSlowDown(groundMovementSystem.getAnimationWindDown().getNameThirdPerson()); + } + //sprint system + if(groundMovementSystem.getSprintSystem() != null){ + SprintSystem sprintSystem = groundMovementSystem.getSprintSystem(); + ServerSprintTree sprintTree = ServerSprintTree.attachTree(entity, sprintSystem); + if(sprintSystem.getAnimationStartUp()!= null){ + moveTree.setAnimationSprintStartUp(sprintSystem.getAnimationStartUp().getNameThirdPerson()); + } + if(sprintSystem.getAnimationMain()!= null){ + moveTree.setAnimationSprint(sprintSystem.getAnimationMain().getNameThirdPerson()); + } + if(sprintSystem.getAnimationWindDown()!= null){ + moveTree.setAnimationSprintWindDown(sprintSystem.getAnimationWindDown().getNameThirdPerson()); + } + sprintTree.setServerGroundMovementTree(moveTree); + moveTree.setServerSprintTree(sprintTree); + ServerEntityTagUtils.attachTagToEntity(entity, EntityTags.SPRINTABLE); + } + //round out end of move system + entity.putData(EntityDataStrings.SERVER_MOVEMENT_BT, moveTree); + CreatureUtils.setFacingVector(entity, MathUtils.getOriginVector()); + entity.putData(EntityDataStrings.DATA_STRING_MAX_NATURAL_VELOCITY, groundMovementSystem.getMaxVelocity()); + entity.putData(EntityDataStrings.DATA_STRING_ACCELERATION, groundMovementSystem.getAcceleration()); + entity.putData(EntityDataStrings.DATA_STRING_VELOCITY, 0f); + ServerBehaviorTreeUtils.attachBTreeToEntity(entity, moveTree); + ServerEntityTagUtils.attachTagToEntity(entity, EntityTags.MOVEABLE); + break; + // + // Jump + case JumpMovementSystem.JUMP_MOVEMENT_SYSTEM: + JumpMovementSystem jumpMovementSystem = (JumpMovementSystem)movementSystem; + ServerJumpTree jumpTree = ServerJumpTree.attachTree(entity, jumpMovementSystem); + if(jumpMovementSystem.getAnimationJump() != null){ + jumpTree.setAnimationJump(jumpMovementSystem.getAnimationJump().getNameThirdPerson()); + } + if(CreatureUtils.serverGetEntityMovementTree(entity) != null && CreatureUtils.serverGetEntityMovementTree(entity) instanceof ClientGroundMovementTree){ + ((ServerGroundMovementTree)CreatureUtils.serverGetEntityMovementTree(entity)).setServerJumpTree(jumpTree); + } + if(ServerFallTree.getFallTree(entity)!=null){ + ServerFallTree.getFallTree(entity).setServerJumpTree(jumpTree); + } + break; + // + // Falling + case FallMovementSystem.FALL_MOVEMENT_SYSTEM: + FallMovementSystem fallMovementSystem = (FallMovementSystem)movementSystem; + ServerFallTree fallTree = new ServerFallTree(entity,fallMovementSystem); + if(CreatureUtils.serverGetEntityMovementTree(entity) != null && CreatureUtils.serverGetEntityMovementTree(entity) instanceof ClientGroundMovementTree){ + ((ServerGroundMovementTree)CreatureUtils.serverGetEntityMovementTree(entity)).setServerFallTree(fallTree); + } + if(ServerJumpTree.getServerJumpTree(entity)!=null){ + fallTree.setServerJumpTree(ServerJumpTree.getServerJumpTree(entity)); + } + entity.putData(EntityDataStrings.FALL_TREE, fallTree); + ServerBehaviorTreeUtils.attachBTreeToEntity(entity, fallTree); + break; + case WalkMovementSystem.WALK_MOVEMENT_SYSTEM: { + ServerWalkTree.attachTree(entity, (WalkMovementSystem)movementSystem); + } break; + } + } + } + + // + // + // EQUIP STATE + // + // + if(rawType.getEquipPoints() != null && rawType.getEquipPoints().size() > 0){ + ServerEquipState.attachTree(entity, rawType.getEquipPoints()); + entity.putData(EntityDataStrings.EQUIP_INVENTORY, RelationalInventoryState.buildRelationalInventoryStateFromEquipList(rawType.getEquipPoints())); + } + + // + // + // BLOCK STATE + // + // + if(rawType.getBlockSystem() != null){ + ServerBlockTree.attachTree(entity, rawType.getBlockSystem()); + } + + // + // + // TOKENS + // + // + if(rawType.getTokens() != null){ + for(String token : rawType.getTokens()){ + switch(token){ + case "ATTACKER": { + ServerAttackTree.attachTree(entity); + entity.putData(EntityDataStrings.ATTACK_MOVE_TYPE_ACTIVE, null); + ServerEntityTagUtils.attachTagToEntity(entity, EntityTags.ATTACKER); + //add all attack moves + if(rawType.getAttackMoves() != null && rawType.getAttackMoves().size() > 0){ + for(AttackMove attackMove : rawType.getAttackMoves()){ + entity.putData(attackMove.getType(), rawType.getAttackMoveResolver().getMoveset(attackMove.getType())); + // switch(attackMove.getType()){ + // case EntityDataStrings.ATTACK_MOVE_TYPE_MELEE_SWING_ONE_HAND: + // rVal.putData(EntityDataStrings.ATTACK_MOVE_TYPE_MELEE_SWING_ONE_HAND, rawType.getAttackMoveResolver().getMoveset(EntityDataStrings.ATTACK_MOVE_TYPE_MELEE_SWING_ONE_HAND)); + // break; + // case EntityDataStrings.ATTACK_MOVE_TYPE_BOW_TWO_HAND: + // rVal.putData(EntityDataStrings.ATTACK_MOVE_TYPE_MELEE_SWING_ONE_HAND, rawType.getAttackMoveResolver().getMoveset(EntityDataStrings.ATTACK_MOVE_TYPE_MELEE_SWING_ONE_HAND)); + // break; + // } + } + } + } break; + case "SHOOTER": { + ShooterTree shooterTree = new ShooterTree(entity); + ShooterTree.setShooterTree(entity, shooterTree); + ServerBehaviorTreeUtils.attachBTreeToEntity(entity, shooterTree); + } break; + case "GRAVITY": { + Collidable collidable = (Collidable)entity.getData(EntityDataStrings.PHYSICS_COLLIDABLE); + DBody collisionObject = PhysicsEntityUtils.getDBody(entity); + ServerGravityTree.attachTree(entity, collidable, collisionObject, 30); + entity.putData(EntityDataStrings.GRAVITY_ENTITY, true); + } break; + case "TARGETABLE": { + ServerEntityTagUtils.attachTagToEntity(entity, EntityTags.TARGETABLE); + } break; + case "INVENTORY": { + entity.putData(EntityDataStrings.NATURAL_INVENTORY,UnrelationalInventoryState.createUnrelationalInventory(10)); + InventoryUtils.serverSetInventoryState(entity, ServerInventoryState.serverCreateInventoryState(entity)); + } break; + case "OUTLINE": { + entity.putData(EntityDataStrings.DRAW_OUTLINE, true); + } break; + case "UNIT_CONTROLS": { + ServerAlwaysUprightTree.attachTree(entity); + CreatureUtils.setFacingVector(entity, MathUtils.getOriginVector()); + } break; + case "TERRAIN_COLLISION": { + CollisionObjUtils.getCollidable(entity).overrideType(Collidable.TYPE_TERRAIN); + } break; + case "BLENDER_ROTATION": { + ActorUtils.applyBlenderRotation(entity); + } break; + case "SPAWNPOINT": { + realm.registerSpawnPoint(position); + } break; + } + } + } + + //rotator system + if(rawType.getRotatorSystem() != null){ + RotatorSystem system = rawType.getRotatorSystem(); + ServerRotatorTree rotatorTree = new ServerRotatorTree(entity); + for(RotatorItem item : system.getRotatorItems()){ + //put actor rotator + ActorBoneRotator newRotator = new ActorBoneRotator(); + creatureActor.addBoneRotator(item.getBoneName(), newRotator); + //construct node for tree + RotatorHierarchyNode hierarchyNode = new RotatorHierarchyNode(); + hierarchyNode.setBone(item.getBoneName()); + for(RotatorConstraint constraint : item.getConstraints()){ + hierarchyNode.addRotatorConstraint(new electrosphere.entity.state.rotator.RotatorConstraint(constraint)); + } + rotatorTree.addRotatorNode(hierarchyNode); + } + entity.putData(EntityDataStrings.SERVER_ROTATOR_TREE, rotatorTree); + ServerBehaviorTreeUtils.attachBTreeToEntity(entity, rotatorTree); + } + + //bone groups + if(rawType.getBoneGroups() != null){ + creatureActor.setBoneGroups(rawType.getBoneGroups()); + } + + /// + /// + /// AI (This SHOULD only be applied on the server with the way AI architected currently) + /// + /// + if(rawType.getAITrees() != null){ + Globals.aiManager.attachAI(entity, rawType.getAITrees()); + } + + //add health system + if(rawType.getHealthSystem() != null){ + ServerLifeTree.attachTree(entity, rawType.getHealthSystem()); + ServerEntityTagUtils.attachTagToEntity(entity, EntityTags.LIFE_STATE); + } + //idle tree & generic stuff all creatures have + if(rawType.getIdleData() != null){ + ServerIdleTree.attachTree(entity, rawType.getIdleData()); + } + + + return entity; + } + + /** + * Spawns an object in the client scene + * @param type The type of object + * @return The object entity + */ + public static Entity clientSpawnBasicObject(String type){ + CommonEntityType rawType = Globals.gameConfigCurrent.getObjectTypeMap().getType(type); + Entity rVal = EntityCreationUtils.createClientSpatialEntity(); + // + // + //Common entity transforms + // + // + CommonEntityUtils.clientSpawnBasicCreature(rVal, rawType); + + // + // + //Object specific transforms + // + // + + return rVal; + } + + + + /** + * Spawns a server-side object + * @param type The type of object to spawn + * @return The object + */ + public static Entity serverSpawnBasicObject(Realm realm, Vector3d position, String type){ + CommonEntityType rawType = Globals.gameConfigCurrent.getObjectTypeMap().getType(type); + Entity rVal = EntityCreationUtils.createServerEntity(realm, position); + + // + // + //Common entity transforms + // + // + CommonEntityUtils.serverSpawnBasicCreature(realm, position, rVal, rawType); + + // + // + //Object specific transforms + // + // + + //position entity + //this needs to be called at the end of this function. + //Burried underneath this is function call to initialize a server side entity. + //The server initialization logic checks what type of entity this is, if this function is called prior to its type being stored + //the server will not be able to synchronize it properly. + ServerEntityUtils.initiallyPositionEntity(realm,rVal,position); + + return rVal; + } + + /** + * Sets the object to a given player + * @param player The player + * @param item The object entity + */ + public static void sendEntityToPlayer(Player player, Entity object){ + int id = object.getId(); + String type = CommonEntityUtils.getEntitySubtype(object); + Vector3d position = EntityUtils.getPosition(object); + Quaterniond rotation = EntityUtils.getRotation(object); + //construct the spawn message and attach to player + NetworkMessage message = EntityMessage.constructCreateMessage( + id, + EntityType.COMMON.getValue(), + type, + "", + position.x, + position.y, + position.z, + rotation.x, + rotation.y, + rotation.z, + rotation.w + ); + player.addMessage(message); + } + + /** + * Sets the typing data + * @param entity The entity + * @param type The type + */ + private static void setTyping(Entity entity, CommonEntityType type){ + if(type instanceof CreatureData){ + CommonEntityUtils.setEntityType(entity, EntityType.CREATURE); + CommonEntityUtils.setEntitySubtype(entity, type.getId()); + } else if(type instanceof Item){ + CommonEntityUtils.setEntityType(entity, EntityType.ITEM); + CommonEntityUtils.setEntitySubtype(entity, type.getId()); + } else if(type instanceof FoliageType){ + CommonEntityUtils.setEntityType(entity, EntityType.FOLIAGE); + CommonEntityUtils.setEntitySubtype(entity, type.getId()); + } else { + CommonEntityUtils.setEntityType(entity, EntityType.COMMON); + CommonEntityUtils.setEntitySubtype(entity, type.getId()); + } + } + + /** + * Attachs the entity to the specified tag + * @param entity The entity + * @param type The type + */ + private static void serverAttachToTag(Entity entity, CommonEntityType type){ + if(type instanceof CreatureData){ + ServerEntityTagUtils.attachTagToEntity(entity, EntityTags.CREATURE); + } else if(type instanceof Item){ + ServerEntityTagUtils.attachTagToEntity(entity, EntityTags.ITEM); + } else if(type instanceof FoliageType){ + ServerEntityTagUtils.attachTagToEntity(entity, EntityTags.FOLIAGE); + } + } + + /** + * Gets the type of the entity + * @param entity The entity + * @return The type + */ + public static EntityType getEntityType(Entity entity){ + return (EntityType)entity.getData(EntityDataStrings.ENTITY_TYPE); + } + + /** + * Sets the entity type + * @param entity the entity + * @param type the type + */ + public static void setEntityType(Entity entity, EntityType type){ + entity.putData(EntityDataStrings.ENTITY_TYPE, type); + } + + /** + * Gets the subtype of this entity + * @param entity The entity + * @return The subtype + */ + public static String getEntitySubtype(Entity entity){ + return (String)entity.getData(EntityDataStrings.ENTITY_SUBTYPE); + } + + /** + * Sets the subtype of this entity + * @param entity The entity + * @param subtype The subtype + */ + public static void setEntitySubtype(Entity entity, String subtype){ + entity.putData(EntityDataStrings.ENTITY_SUBTYPE, subtype); + } + + /** + * Checks if the entity should be serialized + * @param entity The entity + * @return true if should be serialized, false otherwise + */ + public static boolean shouldBeSerialized(Entity entity){ + return entity.containsKey(EntityDataStrings.SHOULD_SERIALIZE); + } + + /** + * Checks if the entity should be synchronized between server and client + * @param entity The entity + * @return true if should be synchronized, false otherwise + */ + public static boolean shouldBeSynchronized(Entity entity){ + return entity.containsKey(EntityDataStrings.SHOULD_SYNCHRONIZE); + } + +} diff --git a/src/main/java/electrosphere/entity/types/creature/CreatureTemplate.java b/src/main/java/electrosphere/entity/types/creature/CreatureTemplate.java index c64e3d61..df9eb85f 100644 --- a/src/main/java/electrosphere/entity/types/creature/CreatureTemplate.java +++ b/src/main/java/electrosphere/entity/types/creature/CreatureTemplate.java @@ -110,7 +110,7 @@ public class CreatureTemplate { */ public static CreatureTemplate createDefault(String creatureType){ CreatureTemplate storedTemplate = CreatureTemplate.create(creatureType); - CreatureData rawType = Globals.gameConfigCurrent.getCreatureTypeLoader().getCreature(creatureType); + CreatureData rawType = Globals.gameConfigCurrent.getCreatureTypeLoader().getType(creatureType); if(rawType.getVisualAttributes() != null){ for(VisualAttribute attributeType : rawType.getVisualAttributes()){ if(attributeType.getType().equals("remesh")){ diff --git a/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java b/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java index 3c07ea5e..79546ff6 100644 --- a/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java +++ b/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java @@ -2,10 +2,7 @@ package electrosphere.entity.types.creature; import org.joml.Quaterniond; import org.joml.Vector3d; -import org.ode4j.ode.DBody; -import electrosphere.collision.PhysicsEntityUtils; -import electrosphere.collision.collidable.Collidable; import electrosphere.engine.Globals; import electrosphere.entity.Entity; import electrosphere.entity.EntityCreationUtils; @@ -16,54 +13,16 @@ import electrosphere.entity.ServerEntityUtils; import electrosphere.entity.btree.BehaviorTree; import electrosphere.entity.state.attack.ClientAttackTree; import electrosphere.entity.state.attack.ServerAttackTree; -import electrosphere.entity.state.attack.ShooterTree; -import electrosphere.entity.state.block.ClientBlockTree; -import electrosphere.entity.state.block.ServerBlockTree; import electrosphere.entity.state.client.firstPerson.FirstPersonTree; -import electrosphere.entity.state.equip.ClientEquipState; import electrosphere.entity.state.equip.ServerEquipState; -import electrosphere.entity.state.gravity.ClientGravityTree; -import electrosphere.entity.state.gravity.ServerGravityTree; -import electrosphere.entity.state.hitbox.HitboxCollectionState; import electrosphere.entity.state.idle.ClientIdleTree; -import electrosphere.entity.state.idle.ServerIdleTree; -import electrosphere.entity.state.inventory.ClientInventoryState; -import electrosphere.entity.state.inventory.InventoryUtils; -import electrosphere.entity.state.inventory.RelationalInventoryState; -import electrosphere.entity.state.inventory.ServerInventoryState; -import electrosphere.entity.state.inventory.UnrelationalInventoryState; -import electrosphere.entity.state.life.ClientLifeTree; -import electrosphere.entity.state.life.ServerLifeTree; -import electrosphere.entity.state.movement.fall.ClientFallTree; -import electrosphere.entity.state.movement.fall.ServerFallTree; import electrosphere.entity.state.movement.groundmove.ClientGroundMovementTree; import electrosphere.entity.state.movement.groundmove.ServerGroundMovementTree; -import electrosphere.entity.state.movement.jump.ClientJumpTree; -import electrosphere.entity.state.movement.jump.ServerJumpTree; -import electrosphere.entity.state.movement.sprint.ServerSprintTree; -import electrosphere.entity.state.movement.sprint.ClientSprintTree; -import electrosphere.entity.state.movement.walk.ClientWalkTree; -import electrosphere.entity.state.movement.walk.ServerWalkTree; -import electrosphere.entity.state.physicssync.upright.ClientAlwaysUprightTree; -import electrosphere.entity.state.physicssync.upright.ServerAlwaysUprightTree; -import electrosphere.entity.state.rotator.RotatorHierarchyNode; -import electrosphere.entity.state.rotator.RotatorTree; -import electrosphere.entity.state.rotator.ServerRotatorTree; -import electrosphere.entity.types.collision.CollisionObjUtils; +import electrosphere.entity.types.EntityTypes.EntityType; +import electrosphere.entity.types.common.CommonEntityUtils; import electrosphere.entity.types.creature.CreatureEquipData.EquippedItem; import electrosphere.entity.types.item.ItemUtils; -import electrosphere.game.data.collidable.CollidableTemplate; import electrosphere.game.data.creature.type.CreatureData; -import electrosphere.game.data.creature.type.SprintSystem; -import electrosphere.game.data.creature.type.attack.AttackMove; -import electrosphere.game.data.creature.type.movement.FallMovementSystem; -import electrosphere.game.data.creature.type.movement.GroundMovementSystem; -import electrosphere.game.data.creature.type.movement.JumpMovementSystem; -import electrosphere.game.data.creature.type.movement.MovementSystem; -import electrosphere.game.data.creature.type.movement.WalkMovementSystem; -import electrosphere.game.data.creature.type.rotator.RotatorConstraint; -import electrosphere.game.data.creature.type.rotator.RotatorItem; -import electrosphere.game.data.creature.type.rotator.RotatorSystem; import electrosphere.game.data.creature.type.visualattribute.AttributeVariant; import electrosphere.game.data.creature.type.visualattribute.VisualAttribute; import electrosphere.logger.LoggerInterface; @@ -73,22 +32,15 @@ import electrosphere.net.parser.net.message.NetworkMessage; import electrosphere.net.server.player.Player; import electrosphere.net.synchronization.transport.StateCollection; import electrosphere.renderer.actor.Actor; -import electrosphere.renderer.actor.ActorBoneRotator; import electrosphere.renderer.actor.ActorStaticMorph; import electrosphere.server.datacell.Realm; -import electrosphere.server.datacell.utils.ServerBehaviorTreeUtils; -import electrosphere.server.datacell.utils.ServerEntityTagUtils; import electrosphere.server.poseactor.PoseActor; import electrosphere.util.Utilities; -import electrosphere.util.math.MathUtils; /** * Utilities for creating creatures on the client and server */ public class CreatureUtils { - - //The entity type int for creatures - public static final int ENTITY_TYPE_CREATURE = 0; /** * Spawns a client-side creature entity @@ -97,166 +49,21 @@ public class CreatureUtils { * @return The creature entity */ public static Entity clientSpawnBasicCreature(String type, CreatureTemplate template){ - CreatureData rawType = Globals.gameConfigCurrent.getCreatureTypeLoader().getCreature(type); + CreatureData rawType = Globals.gameConfigCurrent.getCreatureTypeLoader().getType(type); Entity rVal = EntityCreationUtils.createClientSpatialEntity(); - EntityCreationUtils.makeEntityDrawable(rVal, rawType.getModelPath()); - Actor creatureActor = EntityUtils.getActor(rVal); - EntityUtils.setEntityType(rVal, ENTITY_TYPE_CREATURE); - EntityUtils.setEntitySubtype(rVal, type); - - - /// - /// - /// HITBOX DATA - /// - /// - HitboxCollectionState.attachHitboxState(Globals.clientSceneWrapper.getHitboxManager(), false, rVal, rawType.getHitboxes()); - // + //perform common transforms // - // PHYSICS - // - // - if(rawType.getCollidable() != null){ - CollidableTemplate physicsTemplate = rawType.getCollidable(); - PhysicsEntityUtils.clientAttachCollidableTemplate(rVal, physicsTemplate); - ClientAlwaysUprightTree.attachTree(rVal); - } + CommonEntityUtils.clientSpawnBasicCreature(rVal, rawType); // + //Perform creature-specific transforms // - // MOVEMENT SYSTEMS - // - // - for(MovementSystem movementSystem : rawType.getMovementSystems()){ - switch(movementSystem.getType()){ - // - // Generic ground - case GroundMovementSystem.GROUND_MOVEMENT_SYSTEM: - GroundMovementSystem groundMovementSystem = (GroundMovementSystem)movementSystem; - ClientGroundMovementTree moveTree = ClientGroundMovementTree.attachTree(rVal, CollisionObjUtils.getCollidable(rVal), groundMovementSystem); - if(groundMovementSystem.getAnimationStartup() != null){ - moveTree.setAnimationStartUp(groundMovementSystem.getAnimationStartup().getNameThirdPerson()); - } - if(groundMovementSystem.getAnimationLoop() != null){ - moveTree.setAnimationMain(groundMovementSystem.getAnimationLoop().getNameThirdPerson()); - } - if(groundMovementSystem.getAnimationWindDown()!= null){ - moveTree.setAnimationSlowDown(groundMovementSystem.getAnimationWindDown().getNameThirdPerson()); - } - //sprint system - if(groundMovementSystem.getSprintSystem() != null){ - SprintSystem sprintSystem = groundMovementSystem.getSprintSystem(); - ClientSprintTree sprintTree = ClientSprintTree.attachTree(rVal, sprintSystem); - if(sprintSystem.getAnimationStartUp()!= null){ - moveTree.setAnimationSprintStartUp(sprintSystem.getAnimationStartUp().getNameThirdPerson()); - } - if(sprintSystem.getAnimationMain()!= null){ - moveTree.setAnimationSprint(sprintSystem.getAnimationMain().getNameThirdPerson()); - } - if(sprintSystem.getAnimationWindDown()!= null){ - moveTree.setAnimationSprintWindDown(sprintSystem.getAnimationWindDown().getNameThirdPerson()); - } - moveTree.setSprintTree(sprintTree); - Globals.clientScene.registerEntityToTag(rVal, EntityTags.SPRINTABLE); - } - //round out end of move system - rVal.putData(EntityDataStrings.CLIENT_MOVEMENT_BT, moveTree); - CreatureUtils.setFacingVector(rVal, MathUtils.getOriginVector()); - rVal.putData(EntityDataStrings.DATA_STRING_MAX_NATURAL_VELOCITY, groundMovementSystem.getMaxVelocity()); - rVal.putData(EntityDataStrings.DATA_STRING_ACCELERATION, groundMovementSystem.getAcceleration()); - rVal.putData(EntityDataStrings.DATA_STRING_VELOCITY, 0f); - Globals.clientScene.registerBehaviorTree(moveTree); - Globals.clientScene.registerEntityToTag(rVal, EntityTags.MOVEABLE); - break; - // - // Jump - case JumpMovementSystem.JUMP_MOVEMENT_SYSTEM: - JumpMovementSystem jumpMovementSystem = (JumpMovementSystem)movementSystem; - ClientJumpTree jumpTree = ClientJumpTree.attachTree(rVal, jumpMovementSystem); - if(jumpMovementSystem.getAnimationJump() != null){ - jumpTree.setAnimationJump(jumpMovementSystem.getAnimationJump().getNameThirdPerson()); - } - if(CreatureUtils.clientGetEntityMovementTree(rVal) != null && CreatureUtils.clientGetEntityMovementTree(rVal) instanceof ClientGroundMovementTree){ - ((ClientGroundMovementTree)CreatureUtils.clientGetEntityMovementTree(rVal)).setClientJumpTree(jumpTree); - } - if(ClientFallTree.getFallTree(rVal)!=null){ - ClientFallTree.getFallTree(rVal).setJumpTree(jumpTree); - } - break; - // - // Falling - case FallMovementSystem.FALL_MOVEMENT_SYSTEM: - FallMovementSystem fallMovementSystem = (FallMovementSystem)movementSystem; - ClientFallTree fallTree = new ClientFallTree(rVal, fallMovementSystem); - if(CreatureUtils.clientGetEntityMovementTree(rVal) != null && CreatureUtils.clientGetEntityMovementTree(rVal) instanceof ClientGroundMovementTree){ - ((ClientGroundMovementTree)CreatureUtils.clientGetEntityMovementTree(rVal)).setClientFallTree(fallTree); - } - if(ClientJumpTree.getClientJumpTree(rVal)!=null){ - fallTree.setJumpTree(ClientJumpTree.getClientJumpTree(rVal)); - } - rVal.putData(EntityDataStrings.FALL_TREE, fallTree); - Globals.clientScene.registerBehaviorTree(fallTree); - break; - case WalkMovementSystem.WALK_MOVEMENT_SYSTEM: { - ClientWalkTree.attachTree(rVal, (WalkMovementSystem)movementSystem); - } break; - } - } - if(rawType.getEquipPoints() != null && rawType.getEquipPoints().size() > 0){ - ClientEquipState.attachTree(rVal, rawType.getEquipPoints()); - rVal.putData(EntityDataStrings.EQUIP_INVENTORY, RelationalInventoryState.buildRelationalInventoryStateFromEquipList(rawType.getEquipPoints())); - } - if(rawType.getBlockSystem() != null){ - ClientBlockTree.attachTree(rVal, rawType.getBlockSystem()); - } - for(String token : rawType.getTokens()){ - switch(token){ - case "ATTACKER": - ClientAttackTree.attachTree(rVal); - rVal.putData(EntityDataStrings.ATTACK_MOVE_TYPE_ACTIVE, null); - Globals.clientScene.registerEntityToTag(rVal, EntityTags.ATTACKER); - //add all attack moves - if(rawType.getAttackMoves() != null && rawType.getAttackMoves().size() > 0){ - for(AttackMove attackMove : rawType.getAttackMoves()){ - rVal.putData(attackMove.getType(), rawType.getAttackMoveResolver().getMoveset(attackMove.getType())); - // switch(attackMove.getType()){ - // case EntityDataStrings.ATTACK_MOVE_TYPE_MELEE_SWING_ONE_HAND: - // rVal.putData(EntityDataStrings.ATTACK_MOVE_TYPE_MELEE_SWING_ONE_HAND, rawType.getAttackMoveResolver().getMoveset(EntityDataStrings.ATTACK_MOVE_TYPE_MELEE_SWING_ONE_HAND)); - // break; - // case EntityDataStrings.ATTACK_MOVE_TYPE_BOW_TWO_HAND: - // rVal.putData(EntityDataStrings.ATTACK_MOVE_TYPE_MELEE_SWING_ONE_HAND, rawType.getAttackMoveResolver().getMoveset(EntityDataStrings.ATTACK_MOVE_TYPE_MELEE_SWING_ONE_HAND)); - // break; - // } - } - } - break; - case "SHOOTER": { - ShooterTree shooterTree = new ShooterTree(rVal); - ShooterTree.setShooterTree(rVal, shooterTree); - Globals.clientScene.registerBehaviorTree(shooterTree); - } break; - case "GRAVITY": - Collidable collidable = (Collidable)rVal.getData(EntityDataStrings.PHYSICS_COLLIDABLE); - DBody collisionObject = PhysicsEntityUtils.getDBody(rVal); - ClientGravityTree.attachTree(rVal, collidable, collisionObject, 30); - rVal.putData(EntityDataStrings.GRAVITY_ENTITY, true); - break; - case "TARGETABLE": - Globals.clientScene.registerEntityToTag(rVal, EntityTags.TARGETABLE); - break; - case "INVENTORY": - rVal.putData(EntityDataStrings.NATURAL_INVENTORY,UnrelationalInventoryState.createUnrelationalInventory(10)); - InventoryUtils.clientSetInventoryState(rVal, ClientInventoryState.clientCreateInventoryState(rVal)); - break; - case "OUTLINE": - rVal.putData(EntityDataStrings.DRAW_OUTLINE, true); - break; - } - } + Actor creatureActor = EntityUtils.getActor(rVal); + //variants - CreatureTemplate storedTemplate = CreatureTemplate.create(rawType.getCreatureId()); + CreatureTemplate storedTemplate = CreatureTemplate.create(rawType.getId()); if(rawType.getVisualAttributes() != null){ ActorStaticMorph staticMorph = null; for(VisualAttribute attributeType : rawType.getVisualAttributes()){ @@ -321,44 +128,12 @@ public class CreatureUtils { } } //set race - storedTemplate.creatureType = rawType.getCreatureId(); + storedTemplate.creatureType = rawType.getId(); //store template on creature CreatureUtils.setCreatureTemplate(rVal, storedTemplate); - //rotator system - if(rawType.getRotatorSystem() != null){ - RotatorSystem system = rawType.getRotatorSystem(); - RotatorTree rotatorTree = new RotatorTree(rVal); - for(RotatorItem item : system.getRotatorItems()){ - //put actor rotator - ActorBoneRotator newRotator = new ActorBoneRotator(); - creatureActor.addBoneRotator(item.getBoneName(), newRotator); - //construct node for tree - RotatorHierarchyNode hierarchyNode = new RotatorHierarchyNode(); - hierarchyNode.setBone(item.getBoneName()); - for(RotatorConstraint constraint : item.getConstraints()){ - hierarchyNode.addRotatorConstraint(new electrosphere.entity.state.rotator.RotatorConstraint(constraint)); - } - rotatorTree.addRotatorNode(hierarchyNode); - } - rVal.putData(EntityDataStrings.CLIENT_ROTATOR_TREE, rotatorTree); - Globals.clientScene.registerBehaviorTree(rotatorTree); - } - //bone groups - if(rawType.getBoneGroups() != null){ - creatureActor.setBoneGroups(rawType.getBoneGroups()); - } - //add health system - if(rawType.getHealthSystem() != null){ - ClientLifeTree.attachTree(rVal,rawType.getHealthSystem()); - Globals.clientScene.registerEntityToTag(rVal, EntityTags.LIFE_STATE); - } - //idle tree & generic stuff all creatures have - ClientIdleTree idleTree = new ClientIdleTree(rVal); - rVal.putData(EntityDataStrings.TREE_IDLE, idleTree); - Globals.clientScene.registerBehaviorTree(idleTree); + + //register to correct tag Globals.clientScene.registerEntityToTag(rVal, EntityTags.CREATURE); - CreatureUtils.setFacingVector(rVal, MathUtils.getOriginVector()); - rVal.putData(EntityDataStrings.DRAW_CAST_SHADOW, true); return rVal; } @@ -372,179 +147,26 @@ public class CreatureUtils { * @return The creature entity */ public static Entity serverSpawnBasicCreature(Realm realm, Vector3d position, String type, CreatureTemplate template){ - CreatureData rawType = Globals.gameConfigCurrent.getCreatureTypeLoader().getCreature(type); + CreatureData rawType = Globals.gameConfigCurrent.getCreatureTypeLoader().getType(type); Entity rVal = EntityCreationUtils.createServerEntity(realm, position); - EntityCreationUtils.makeEntityPoseable(rVal, rawType.getModelPath()); - + + // + // + //Common transforms + // + // + CommonEntityUtils.serverSpawnBasicCreature(realm, position, rVal, rawType); + + // + // + //Creature specific transforms + // + // PoseActor creatureActor = EntityUtils.getPoseActor(rVal); - // - // - // Hitbox stuff - // - // - HitboxCollectionState.attachHitboxState(realm.getHitboxManager(), true, rVal, rawType.getHitboxes()); - // - // - // Physics stuff - // - // - if(rawType.getCollidable() != null){ - CollidableTemplate physicsTemplate = rawType.getCollidable(); - PhysicsEntityUtils.serverAttachCollidableTemplate(realm, rVal, physicsTemplate); - ServerAlwaysUprightTree.attachTree(rVal); - } - // - // - // MOVEMENT SYSTEMS - // - // - for(MovementSystem movementSystem : rawType.getMovementSystems()){ - switch(movementSystem.getType()){ - // - // Generic ground - case GroundMovementSystem.GROUND_MOVEMENT_SYSTEM: - GroundMovementSystem groundMovementSystem = (GroundMovementSystem)movementSystem; - ServerGroundMovementTree moveTree = ServerGroundMovementTree.attachTree(rVal,CollisionObjUtils.getCollidable(rVal),groundMovementSystem); - if(groundMovementSystem.getAnimationStartup() != null){ - moveTree.setAnimationStartUp(groundMovementSystem.getAnimationStartup().getNameThirdPerson()); - } - if(groundMovementSystem.getAnimationLoop() != null){ - moveTree.setAnimationMain(groundMovementSystem.getAnimationLoop().getNameThirdPerson()); - } - if(groundMovementSystem.getAnimationWindDown()!= null){ - moveTree.setAnimationSlowDown(groundMovementSystem.getAnimationWindDown().getNameThirdPerson()); - } - //sprint system - if(groundMovementSystem.getSprintSystem() != null){ - SprintSystem sprintSystem = groundMovementSystem.getSprintSystem(); - ServerSprintTree sprintTree = ServerSprintTree.attachTree(rVal, sprintSystem); - if(sprintSystem.getAnimationStartUp()!= null){ - moveTree.setAnimationSprintStartUp(sprintSystem.getAnimationStartUp().getNameThirdPerson()); - } - if(sprintSystem.getAnimationMain()!= null){ - moveTree.setAnimationSprint(sprintSystem.getAnimationMain().getNameThirdPerson()); - } - if(sprintSystem.getAnimationWindDown()!= null){ - moveTree.setAnimationSprintWindDown(sprintSystem.getAnimationWindDown().getNameThirdPerson()); - } - sprintTree.setServerGroundMovementTree(moveTree); - moveTree.setServerSprintTree(sprintTree); - ServerEntityTagUtils.attachTagToEntity(rVal, EntityTags.SPRINTABLE); - } - //round out end of move system - rVal.putData(EntityDataStrings.SERVER_MOVEMENT_BT, moveTree); - CreatureUtils.setFacingVector(rVal, MathUtils.getOriginVector()); - rVal.putData(EntityDataStrings.DATA_STRING_MAX_NATURAL_VELOCITY, groundMovementSystem.getMaxVelocity()); - rVal.putData(EntityDataStrings.DATA_STRING_ACCELERATION, groundMovementSystem.getAcceleration()); - rVal.putData(EntityDataStrings.DATA_STRING_VELOCITY, 0f); - ServerBehaviorTreeUtils.attachBTreeToEntity(rVal, moveTree); - ServerEntityTagUtils.attachTagToEntity(rVal, EntityTags.MOVEABLE); - break; - // - // Jump - case JumpMovementSystem.JUMP_MOVEMENT_SYSTEM: - JumpMovementSystem jumpMovementSystem = (JumpMovementSystem)movementSystem; - ServerJumpTree jumpTree = ServerJumpTree.attachTree(rVal, jumpMovementSystem); - if(jumpMovementSystem.getAnimationJump() != null){ - jumpTree.setAnimationJump(jumpMovementSystem.getAnimationJump().getNameThirdPerson()); - } - if(CreatureUtils.serverGetEntityMovementTree(rVal) != null && CreatureUtils.serverGetEntityMovementTree(rVal) instanceof ClientGroundMovementTree){ - ((ServerGroundMovementTree)CreatureUtils.serverGetEntityMovementTree(rVal)).setServerJumpTree(jumpTree); - } - if(ServerFallTree.getFallTree(rVal)!=null){ - ServerFallTree.getFallTree(rVal).setServerJumpTree(jumpTree); - } - break; - // - // Falling - case FallMovementSystem.FALL_MOVEMENT_SYSTEM: - FallMovementSystem fallMovementSystem = (FallMovementSystem)movementSystem; - ServerFallTree fallTree = new ServerFallTree(rVal,fallMovementSystem); - if(CreatureUtils.serverGetEntityMovementTree(rVal) != null && CreatureUtils.serverGetEntityMovementTree(rVal) instanceof ClientGroundMovementTree){ - ((ServerGroundMovementTree)CreatureUtils.serverGetEntityMovementTree(rVal)).setServerFallTree(fallTree); - } - if(ServerJumpTree.getServerJumpTree(rVal)!=null){ - fallTree.setServerJumpTree(ServerJumpTree.getServerJumpTree(rVal)); - } - rVal.putData(EntityDataStrings.FALL_TREE, fallTree); - ServerBehaviorTreeUtils.attachBTreeToEntity(rVal, fallTree); - break; - case WalkMovementSystem.WALK_MOVEMENT_SYSTEM: { - ServerWalkTree.attachTree(rVal, (WalkMovementSystem)movementSystem); - } break; - } - } + - // - // - // EQUIP STATE - // - // - if(rawType.getEquipPoints() != null && rawType.getEquipPoints().size() > 0){ - ServerEquipState.attachTree(rVal, rawType.getEquipPoints()); - rVal.putData(EntityDataStrings.EQUIP_INVENTORY, RelationalInventoryState.buildRelationalInventoryStateFromEquipList(rawType.getEquipPoints())); - } - - // - // - // BLOCK STATE - // - // - if(rawType.getBlockSystem() != null){ - ServerBlockTree.attachTree(rVal, rawType.getBlockSystem()); - } - - // - // - // TOKENS - // - // - for(String token : rawType.getTokens()){ - switch(token){ - case "ATTACKER": { - ServerAttackTree.attachTree(rVal); - rVal.putData(EntityDataStrings.ATTACK_MOVE_TYPE_ACTIVE, null); - ServerEntityTagUtils.attachTagToEntity(rVal, EntityTags.ATTACKER); - //add all attack moves - if(rawType.getAttackMoves() != null && rawType.getAttackMoves().size() > 0){ - for(AttackMove attackMove : rawType.getAttackMoves()){ - rVal.putData(attackMove.getType(), rawType.getAttackMoveResolver().getMoveset(attackMove.getType())); - // switch(attackMove.getType()){ - // case EntityDataStrings.ATTACK_MOVE_TYPE_MELEE_SWING_ONE_HAND: - // rVal.putData(EntityDataStrings.ATTACK_MOVE_TYPE_MELEE_SWING_ONE_HAND, rawType.getAttackMoveResolver().getMoveset(EntityDataStrings.ATTACK_MOVE_TYPE_MELEE_SWING_ONE_HAND)); - // break; - // case EntityDataStrings.ATTACK_MOVE_TYPE_BOW_TWO_HAND: - // rVal.putData(EntityDataStrings.ATTACK_MOVE_TYPE_MELEE_SWING_ONE_HAND, rawType.getAttackMoveResolver().getMoveset(EntityDataStrings.ATTACK_MOVE_TYPE_MELEE_SWING_ONE_HAND)); - // break; - // } - } - } - } break; - case "SHOOTER": { - ShooterTree shooterTree = new ShooterTree(rVal); - ShooterTree.setShooterTree(rVal, shooterTree); - ServerBehaviorTreeUtils.attachBTreeToEntity(rVal, shooterTree); - } break; - case "GRAVITY": { - Collidable collidable = (Collidable)rVal.getData(EntityDataStrings.PHYSICS_COLLIDABLE); - DBody collisionObject = PhysicsEntityUtils.getDBody(rVal); - ServerGravityTree.attachTree(rVal, collidable, collisionObject, 30); - rVal.putData(EntityDataStrings.GRAVITY_ENTITY, true); - } break; - case "TARGETABLE": { - ServerEntityTagUtils.attachTagToEntity(rVal, EntityTags.TARGETABLE); - } break; - case "INVENTORY": { - rVal.putData(EntityDataStrings.NATURAL_INVENTORY,UnrelationalInventoryState.createUnrelationalInventory(10)); - InventoryUtils.serverSetInventoryState(rVal, ServerInventoryState.serverCreateInventoryState(rVal)); - } break; - case "OUTLINE": { - rVal.putData(EntityDataStrings.DRAW_OUTLINE, true); - } break; - } - } //variants - CreatureTemplate storedTemplate = CreatureTemplate.create(rawType.getCreatureId()); + CreatureTemplate storedTemplate = CreatureTemplate.create(rawType.getId()); if(rawType.getVisualAttributes() != null){ ActorStaticMorph staticMorph = null; for(VisualAttribute attributeType : rawType.getVisualAttributes()){ @@ -608,59 +230,10 @@ public class CreatureUtils { } } //set race - storedTemplate.creatureType = rawType.getCreatureId(); + storedTemplate.creatureType = rawType.getId(); //store template on creature CreatureUtils.setCreatureTemplate(rVal, storedTemplate); - //rotator system - if(rawType.getRotatorSystem() != null){ - RotatorSystem system = rawType.getRotatorSystem(); - ServerRotatorTree rotatorTree = new ServerRotatorTree(rVal); - for(RotatorItem item : system.getRotatorItems()){ - //put actor rotator - ActorBoneRotator newRotator = new ActorBoneRotator(); - creatureActor.addBoneRotator(item.getBoneName(), newRotator); - //construct node for tree - RotatorHierarchyNode hierarchyNode = new RotatorHierarchyNode(); - hierarchyNode.setBone(item.getBoneName()); - for(RotatorConstraint constraint : item.getConstraints()){ - hierarchyNode.addRotatorConstraint(new electrosphere.entity.state.rotator.RotatorConstraint(constraint)); - } - rotatorTree.addRotatorNode(hierarchyNode); - } - rVal.putData(EntityDataStrings.SERVER_ROTATOR_TREE, rotatorTree); - ServerBehaviorTreeUtils.attachBTreeToEntity(rVal, rotatorTree); - } - - //bone groups - if(rawType.getBoneGroups() != null){ - creatureActor.setBoneGroups(rawType.getBoneGroups()); - } - - /// - /// - /// AI (This SHOULD only be applied on the server with the way AI architected currently) - /// - /// - if(rawType.getAITrees() != null){ - Globals.aiManager.attachAI(rVal, rawType.getAITrees()); - } - - //add health system - if(rawType.getHealthSystem() != null){ - ServerLifeTree.attachTree(rVal, rawType.getHealthSystem()); - ServerEntityTagUtils.attachTagToEntity(rVal, EntityTags.LIFE_STATE); - } - //idle tree & generic stuff all creatures have - if(rawType.getIdleData() != null){ - ServerIdleTree.attachTree(rVal, rawType.getIdleData()); - } - CreatureUtils.setFacingVector(rVal, MathUtils.getOriginVector()); - rVal.putData(EntityDataStrings.DRAW_CAST_SHADOW, true); - //required for synchronization manager - ServerEntityTagUtils.attachTagToEntity(rVal, EntityTags.CREATURE); - EntityUtils.setEntityType(rVal, ENTITY_TYPE_CREATURE); - EntityUtils.setEntitySubtype(rVal, type); //position entity //this needs to be called at the end of this function. @@ -687,7 +260,7 @@ public class CreatureUtils { String type, CreatureTemplate template ){ - CreatureData rawType = Globals.gameConfigCurrent.getCreatureTypeLoader().getCreature(type); + CreatureData rawType = Globals.gameConfigCurrent.getCreatureTypeLoader().getType(type); Entity rVal = EntityCreationUtils.createClientSpatialEntity(); if(rawType.getViewModelData() != null){ @@ -718,8 +291,10 @@ public class CreatureUtils { Vector3d position = EntityUtils.getPosition(creature); Quaterniond rotation = EntityUtils.getRotation(creature); String template = Utilities.stringify(CreatureUtils.getCreatureTemplate(creature)); - NetworkMessage message = EntityMessage.constructSpawnCreatureMessage( + NetworkMessage message = EntityMessage.constructCreateMessage( id, + EntityType.CREATURE.getValue(), + CreatureUtils.getType(creature), template, position.x, position.y, @@ -800,7 +375,7 @@ public class CreatureUtils { * @return the type */ public static String getType(Entity e){ - return (String)EntityUtils.getEntitySubtype(e); + return (String)CommonEntityUtils.getEntitySubtype(e); } public static int getControllerPlayerId(Entity e){ @@ -821,10 +396,7 @@ public class CreatureUtils { * @return true if it is a creature, false otherwise */ public static boolean isCreature(Entity e){ - if(!e.containsKey(EntityDataStrings.ENTITY_TYPE)){ - return false; - } - return (int)e.getData(EntityDataStrings.ENTITY_TYPE) == ENTITY_TYPE_CREATURE; + return CommonEntityUtils.getEntityType(e) == EntityType.CREATURE; } public static ClientAttackTree clientGetAttackTree(Entity e){ diff --git a/src/main/java/electrosphere/entity/types/foliage/FoliageUtils.java b/src/main/java/electrosphere/entity/types/foliage/FoliageUtils.java index a602730c..6d64132a 100644 --- a/src/main/java/electrosphere/entity/types/foliage/FoliageUtils.java +++ b/src/main/java/electrosphere/entity/types/foliage/FoliageUtils.java @@ -8,13 +8,14 @@ import electrosphere.entity.EntityTags; import electrosphere.entity.EntityUtils; import electrosphere.entity.ServerEntityUtils; import electrosphere.entity.state.client.ambientaudio.ClientAmbientAudioTree; +import electrosphere.entity.types.EntityTypes.EntityType; +import electrosphere.entity.types.common.CommonEntityUtils; import electrosphere.entity.types.tree.ProceduralTree; import electrosphere.game.data.foliage.type.AmbientAudio; import electrosphere.game.data.foliage.type.FoliageType; import electrosphere.net.parser.net.message.EntityMessage; import electrosphere.net.parser.net.message.NetworkMessage; import electrosphere.net.server.player.Player; -import electrosphere.renderer.actor.ActorUtils; import electrosphere.server.datacell.Realm; import electrosphere.server.datacell.utils.ServerEntityTagUtils; @@ -26,9 +27,6 @@ import org.joml.Vector3d; */ public class FoliageUtils { - //the entity type value - public static final int ENTITY_TYPE_FOLIAGE = 3; - /** * Spawns a basic foliage object * @param type The type of foliage object @@ -43,22 +41,25 @@ public class FoliageUtils { rVal = EntityCreationUtils.createClientSpatialEntity(); EntityCreationUtils.makeEntityDrawable(rVal, rawType.getModelPath()); } + // + // + //Common entity transforms + // + // + CommonEntityUtils.clientSpawnBasicCreature(rVal, rawType); - for(String token : rawType.getTokens()){ - switch(token){ - case "BLENDER_ROTATION": - ActorUtils.applyBlenderRotation(rVal); - break; - case "PARTICLE_SPAWNER": - - break; - } + // + // + //Foliage specific transforms + // + // + + //audio + if(rawType.getAmbientAudio()!=null){ + AmbientAudio ambientAudio = rawType.getAmbientAudio(); + ClientAmbientAudioTree.attachTree(rVal, ambientAudio); } - //idle tree & generic stuff all creatures have -// rVal.putData(EntityDataStrings.IDLE_TREE, new IdleTree(rVal)); -// Globals.entityManager.registerCreatureEntity(rVal); - rVal.putData(EntityDataStrings.FOLIAGE_IS_FOLIAGE, true); - rVal.putData(EntityDataStrings.FOLIAGE_TYPE, type); + return rVal; } @@ -75,24 +76,20 @@ public class FoliageUtils { FoliageType rawType = Globals.gameConfigCurrent.getFoliageMap().getFoliage(type); Entity rVal = ProceduralTree.serverGenerateProceduralTree(realm, position, rawType, seed); - for(String token : rawType.getTokens()){ - switch(token){ - case "BLENDER_ROTATION": - ActorUtils.applyBlenderRotation(rVal); - break; - case "PARTICLE_SPAWNER": - - break; - } - } - //audio - if(rawType.getAmbientAudio()!=null){ - AmbientAudio ambientAudio = rawType.getAmbientAudio(); - ClientAmbientAudioTree.attachTree(rVal, ambientAudio); - } + // + // + //Common entity transforms + // + // + CommonEntityUtils.serverSpawnBasicCreature(realm, position, rVal, rawType); + + // + // + //Foliage specific transforms + // + // // ServerEntityTagUtils.attachTagToEntity(rVal, EntityTags.FOLIAGE); - rVal.putData(EntityDataStrings.FOLIAGE_IS_FOLIAGE, true); rVal.putData(EntityDataStrings.FOLIAGE_TYPE, rawType); rVal.putData(EntityDataStrings.FOLIAGE_SEED, seed); rVal.putData(EntityDataStrings.FOLIAGE_IS_SEEDED, true); @@ -132,7 +129,7 @@ public class FoliageUtils { * @return true if is foliage, false otherwise */ public static boolean isFoliage(Entity entity){ - return entity.getData(EntityDataStrings.FOLIAGE_IS_FOLIAGE)!=null; + return CommonEntityUtils.getEntityType(entity) == EntityType.FOLIAGE; } /** @@ -157,10 +154,11 @@ public class FoliageUtils { Quaterniond rotation = EntityUtils.getRotation(foliage); if(FoliageUtils.hasSeed(foliage)){ long seed = FoliageUtils.getFoliageSeed(foliage); - NetworkMessage message = EntityMessage.constructSpawnFoliageSeedMessage( + NetworkMessage message = EntityMessage.constructCreateMessage( id, - type.getName(), - seed, + EntityType.FOLIAGE.getValue(), + type.getId(), + seed + "", position.x, position.y, position.z, diff --git a/src/main/java/electrosphere/entity/types/item/ItemUtils.java b/src/main/java/electrosphere/entity/types/item/ItemUtils.java index d0560635..d2405347 100644 --- a/src/main/java/electrosphere/entity/types/item/ItemUtils.java +++ b/src/main/java/electrosphere/entity/types/item/ItemUtils.java @@ -16,11 +16,11 @@ import electrosphere.entity.EntityTags; import electrosphere.entity.EntityUtils; import electrosphere.entity.ServerEntityUtils; import electrosphere.entity.state.AnimationPriorities; -import electrosphere.entity.state.gravity.ClientGravityTree; import electrosphere.entity.state.gravity.ServerGravityTree; import electrosphere.entity.state.hitbox.HitboxCollectionState; +import electrosphere.entity.types.EntityTypes.EntityType; import electrosphere.entity.types.attach.AttachUtils; -import electrosphere.game.data.collidable.CollidableTemplate; +import electrosphere.entity.types.common.CommonEntityUtils; import electrosphere.game.data.item.type.EquipData; import electrosphere.game.data.item.type.EquipWhitelist; import electrosphere.game.data.item.type.Item; @@ -39,16 +39,25 @@ import electrosphere.server.poseactor.PoseActor; */ public class ItemUtils { - //The item creature type - public static final int ENTITY_TYPE_ITEM = 1; - //generic item icon filepath static final String genericItemIconPath = "Textures/icons/itemIconItemGeneric.png"; public static Entity clientSpawnBasicItem(String name){ Item item = Globals.gameConfigCurrent.getItemMap().getItem(name); Entity rVal = EntityCreationUtils.createClientSpatialEntity(); - EntityCreationUtils.makeEntityDrawable(rVal, item.getModelPath()); + + // + // + //Common entity transforms + // + // + CommonEntityUtils.clientSpawnBasicCreature(rVal, item); + + // + // + //Item specific transforms + // + // if(item.getWeaponData() != null){ rVal.putData(EntityDataStrings.ITEM_IS_WEAPON, true); WeaponData weaponData = item.getWeaponData(); @@ -58,28 +67,6 @@ public class ItemUtils { rVal.putData(EntityDataStrings.ITEM_WEAPON_CLASS,weaponData.getWeaponClass()); rVal.putData(EntityDataStrings.ITEM_WEAPON_DATA_RAW,weaponData); } - //physics - if(item.getCollidable() != null){ - CollidableTemplate physicsTemplate = item.getCollidable(); - PhysicsEntityUtils.clientAttachCollidableTemplate(rVal, physicsTemplate); - } - //tokens - for(String token : item.getTokens()){ - switch(token){ - case "GRAVITY": - Collidable collidable = (Collidable)rVal.getData(EntityDataStrings.PHYSICS_COLLIDABLE); - DBody collisionObject = PhysicsEntityUtils.getDBody(rVal); - ClientGravityTree.attachTree(rVal, collidable, collisionObject, 30); - rVal.putData(EntityDataStrings.GRAVITY_ENTITY, true); - break; - case "TARGETABLE": - Globals.clientSceneWrapper.getScene().registerEntityToTag(rVal, EntityTags.TARGETABLE); - break; - case "OUTLINE": - rVal.putData(EntityDataStrings.DRAW_OUTLINE, true); - break; - } - } if(item.getIdleAnim() != null){ rVal.putData(EntityDataStrings.ANIM_IDLE,item.getIdleAnim()); } @@ -103,12 +90,8 @@ public class ItemUtils { rVal.putData(EntityDataStrings.ITEM_EQUIP_CLASS,equipData.getEquipClass()); } } - rVal.putData(EntityDataStrings.DRAW_CAST_SHADOW, true); - EntityUtils.setEntityType(rVal, ENTITY_TYPE_ITEM); rVal.putData(EntityDataStrings.ITEM_IS_IN_INVENTORY, false); - EntityUtils.setEntitySubtype(rVal, name); -// rVal.putData(EntityDataStrings.DATA_STRING_SCALE, new Vector3f(0.005f,0.005f,0.005f)); -// rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, new Quaternionf().identity().rotateY((float)(-Math.PI/2)).rotateZ(-(float)(Math.PI/2))); + Globals.clientSceneWrapper.getScene().registerEntityToTag(rVal, EntityTags.ITEM); return rVal; } @@ -126,8 +109,19 @@ public class ItemUtils { Item item = Globals.gameConfigCurrent.getItemMap().getItem(name); //must correct the position such that it spawns inside the realm Vector3d correctedPosition = ServerEntityUtils.guaranteePositionIsInBounds(realm, position); - Entity rVal = EntityCreationUtils.createServerEntity(realm, correctedPosition);// EntityUtils.spawnDrawableEntity(item.getModelPath()); - EntityCreationUtils.makeEntityPoseable(rVal, item.getModelPath()); + Entity rVal = EntityCreationUtils.createServerEntity(realm, correctedPosition); + // + // + //Common entity transforms + // + // + CommonEntityUtils.serverSpawnBasicCreature(realm, position, rVal, item); + + // + // + //Item specific transforms + // + // if(item.getWeaponData() != null){ rVal.putData(EntityDataStrings.ITEM_IS_WEAPON, true); WeaponData weaponData = item.getWeaponData(); @@ -137,11 +131,6 @@ public class ItemUtils { rVal.putData(EntityDataStrings.ITEM_WEAPON_CLASS,weaponData.getWeaponClass()); rVal.putData(EntityDataStrings.ITEM_WEAPON_DATA_RAW,weaponData); } - //physics - if(item.getCollidable() != null){ - CollidableTemplate physicsTemplate = item.getCollidable(); - PhysicsEntityUtils.serverAttachCollidableTemplate(realm, rVal, physicsTemplate); - } //tokens for(String token : item.getTokens()){ switch(token){ @@ -181,17 +170,9 @@ public class ItemUtils { rVal.putData(EntityDataStrings.ITEM_EQUIP_CLASS,equipData.getEquipClass()); } } - rVal.putData(EntityDataStrings.DRAW_CAST_SHADOW, true); rVal.putData(EntityDataStrings.ITEM_IS_IN_INVENTORY, false); -// rVal.putData(EntityDataStrings.DATA_STRING_SCALE, new Vector3f(0.005f,0.005f,0.005f)); -// rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, new Quaternionf().identity().rotateY((float)(-Math.PI/2)).rotateZ(-(float)(Math.PI/2))); - //required for synchronization manager - ServerEntityTagUtils.attachTagToEntity(rVal, EntityTags.ITEM); - EntityUtils.setEntityType(rVal, ENTITY_TYPE_ITEM); - EntityUtils.setEntitySubtype(rVal, name); - //position entity //this needs to be called at the end of this function. @@ -264,23 +245,28 @@ public class ItemUtils { } public static void sendEntityToPlayer(Player player, Entity item){ - int id = item.getId(); - String type = ItemUtils.getType(item); - Vector3d position = EntityUtils.getPosition(item); - Quaterniond rotation = EntityUtils.getRotation(item); - //construct the spawn message and attach to player - NetworkMessage message = EntityMessage.constructSpawnItemMessage( - id, - type, - position.x, - position.y, - position.z, - rotation.x, - rotation.y, - rotation.z, - rotation.w - ); - player.addMessage(message); + boolean shouldSend = ItemUtils.itemShouldBeSentToClient(item); + if(shouldSend){ + int id = item.getId(); + String type = ItemUtils.getType(item); + Vector3d position = EntityUtils.getPosition(item); + Quaterniond rotation = EntityUtils.getRotation(item); + //construct the spawn message and attach to player + NetworkMessage message = EntityMessage.constructCreateMessage( + id, + EntityType.ITEM.getValue(), + type, + "", + position.x, + position.y, + position.z, + rotation.x, + rotation.y, + rotation.z, + rotation.w + ); + player.addMessage(message); + } } @@ -293,10 +279,7 @@ public class ItemUtils { if(e == null){ return false; } - if(!e.containsKey(EntityDataStrings.ENTITY_TYPE)){ - return false; - } - return (int)e.getData(EntityDataStrings.ENTITY_TYPE) == ENTITY_TYPE_ITEM; + return CommonEntityUtils.getEntityType(e) == EntityType.ITEM; } /** @@ -333,7 +316,7 @@ public class ItemUtils { * @return The type */ public static String getType(Entity item){ - return EntityUtils.getEntitySubtype(item); + return CommonEntityUtils.getEntitySubtype(item); } public static boolean isWeapon(Entity item){ @@ -410,10 +393,10 @@ public class ItemUtils { } rVal.putData(EntityDataStrings.ITEM_ICON,ItemUtils.getItemIcon(item)); rVal.putData(EntityDataStrings.ITEM_EQUIP_CLASS, item.getData(EntityDataStrings.ITEM_EQUIP_CLASS)); - EntityUtils.setEntityType(rVal, ENTITY_TYPE_ITEM); + CommonEntityUtils.setEntityType(rVal, EntityType.ITEM); rVal.putData(EntityDataStrings.ITEM_IS_IN_INVENTORY, true); ItemUtils.setContainingParent(rVal, containingParent); - EntityUtils.setEntitySubtype(rVal, EntityUtils.getEntitySubtype(item)); + CommonEntityUtils.setEntitySubtype(rVal, CommonEntityUtils.getEntitySubtype(item)); Globals.clientSceneWrapper.getScene().registerEntity(rVal); Globals.clientSceneWrapper.getScene().registerEntityToTag(rVal, EntityTags.ITEM); return rVal; @@ -436,10 +419,10 @@ public class ItemUtils { } rVal.putData(EntityDataStrings.ITEM_ICON,ItemUtils.getItemIcon(item)); rVal.putData(EntityDataStrings.ITEM_EQUIP_CLASS, item.getData(EntityDataStrings.ITEM_EQUIP_CLASS)); - EntityUtils.setEntityType(rVal, ENTITY_TYPE_ITEM); + CommonEntityUtils.setEntityType(rVal, EntityType.ITEM); rVal.putData(EntityDataStrings.ITEM_IS_IN_INVENTORY, true); ItemUtils.setContainingParent(rVal, containingParent); - EntityUtils.setEntitySubtype(rVal, EntityUtils.getEntitySubtype(item)); + CommonEntityUtils.setEntitySubtype(rVal, CommonEntityUtils.getEntitySubtype(item)); return rVal; } else { return null; diff --git a/src/main/java/electrosphere/entity/types/object/ObjectUtils.java b/src/main/java/electrosphere/entity/types/object/ObjectUtils.java index cdb7768e..a3f2e63b 100644 --- a/src/main/java/electrosphere/entity/types/object/ObjectUtils.java +++ b/src/main/java/electrosphere/entity/types/object/ObjectUtils.java @@ -1,265 +1,8 @@ package electrosphere.entity.types.object; -import org.joml.Quaterniond; -import org.joml.Vector3d; -import org.ode4j.ode.DBody; - -import electrosphere.collision.PhysicsEntityUtils; -import electrosphere.collision.collidable.Collidable; -import electrosphere.engine.Globals; -import electrosphere.engine.assetmanager.PhysicsMeshQueueItem; -import electrosphere.entity.Entity; -import electrosphere.entity.EntityCreationUtils; -import electrosphere.entity.EntityDataStrings; -import electrosphere.entity.EntityTags; -import electrosphere.entity.EntityUtils; -import electrosphere.entity.ServerEntityUtils; -import electrosphere.entity.btree.BehaviorTree; -import electrosphere.entity.state.gravity.ClientGravityTree; -import electrosphere.entity.state.gravity.ServerGravityTree; -import electrosphere.entity.state.hitbox.HitboxCollectionState; -import electrosphere.entity.state.idle.ClientIdleTree; -import electrosphere.entity.state.inventory.ClientInventoryState; -import electrosphere.entity.state.inventory.InventoryUtils; -import electrosphere.entity.state.inventory.ServerInventoryState; -import electrosphere.entity.state.inventory.UnrelationalInventoryState; -import electrosphere.entity.types.collision.CollisionObjUtils; -import electrosphere.game.data.collidable.CollidableTemplate; -import electrosphere.game.data.object.type.ObjectData; -import electrosphere.net.parser.net.message.EntityMessage; -import electrosphere.net.parser.net.message.NetworkMessage; -import electrosphere.net.server.player.Player; -import electrosphere.server.datacell.Realm; -import electrosphere.server.datacell.utils.ServerBehaviorTreeUtils; -import electrosphere.server.datacell.utils.ServerEntityTagUtils; - public class ObjectUtils { //the entity type value - public static final int ENTITY_TYPE_OBJECT = 2; - - /** - * Spawns an object in the client scene - * @param type The type of object - * @return The object entity - */ - public static Entity clientSpawnBasicObject(String type){ - ObjectData rawType = Globals.gameConfigCurrent.getObjectTypeLoader().getObject(type); - Entity rVal = EntityCreationUtils.createClientSpatialEntity(); - if(rawType.getModelPath() != null){ - EntityCreationUtils.makeEntityDrawable(rVal, rawType.getModelPath()); - } - //forward-searching tokens - for(String token : rawType.getTokens()){ - switch(token){ - case "GENERATE_COLLISION_OBJECT": { - Globals.assetManager.addCollisionMeshToQueue(new PhysicsMeshQueueItem(Globals.clientSceneWrapper.getCollisionEngine(),rawType.getModelPath())); - Globals.clientSceneWrapper.getScene().registerBehaviorTree(new BehaviorTree() {public void simulate(float deltaTime) { - DBody collisionObject = Globals.assetManager.fetchCollisionObject(Globals.clientSceneWrapper.getCollisionEngine(),rawType.getModelPath()); - if(collisionObject != null){ - Globals.clientSceneWrapper.getScene().deregisterBehaviorTree(this); - CollisionObjUtils.clientAttachCollisionObjectToEntity(rVal, collisionObject, 0, Collidable.TYPE_OBJECT); - } - }}); - } break; - case "GENERATE_COLLISION_TERRAIN": { - Globals.assetManager.addCollisionMeshToQueue(new PhysicsMeshQueueItem(Globals.clientSceneWrapper.getCollisionEngine(),rawType.getModelPath())); - Globals.clientSceneWrapper.getScene().registerBehaviorTree(new BehaviorTree() {public void simulate(float deltaTime) { - DBody collisionObject = Globals.assetManager.fetchCollisionObject(Globals.clientSceneWrapper.getCollisionEngine(),rawType.getModelPath()); - if(collisionObject != null){ - Globals.clientSceneWrapper.getScene().deregisterBehaviorTree(this); - CollisionObjUtils.clientAttachCollisionObjectToEntity(rVal, collisionObject, 0, Collidable.TYPE_TERRAIN); - } - }}); - } break; - } - } - // - //main entity construction - //physics - if(rawType.getCollidable() != null){ - CollidableTemplate physicsTemplate = rawType.getCollidable(); - PhysicsEntityUtils.clientAttachCollidableTemplate(rVal, physicsTemplate); - } - //tokens - for(String token : rawType.getTokens()){ - switch(token){ - case "GRAVITY": - Collidable collidable = (Collidable)rVal.getData(EntityDataStrings.PHYSICS_COLLIDABLE); - DBody collisionObject = PhysicsEntityUtils.getDBody(rVal); - ClientGravityTree.attachTree(rVal, collidable, collisionObject, 30); - rVal.putData(EntityDataStrings.GRAVITY_ENTITY, true); - break; - case "TARGETABLE": - Globals.clientSceneWrapper.getScene().registerEntityToTag(rVal, EntityTags.TARGETABLE); - break; - case "INVENTORY": - rVal.putData(EntityDataStrings.NATURAL_INVENTORY,UnrelationalInventoryState.createUnrelationalInventory(10)); - InventoryUtils.clientSetInventoryState(rVal, ClientInventoryState.clientCreateInventoryState(rVal)); - break; - case "OUTLINE": - rVal.putData(EntityDataStrings.DRAW_OUTLINE, true); - break; - case "TERRAIN_COLLISION": { - CollisionObjUtils.getCollidable(rVal).overrideType(Collidable.TYPE_TERRAIN); - } break; - case "SPAWNPOINT": { - //ignore on client - } break; - } - } - if(rawType.getHitboxData() != null){ - HitboxCollectionState.attachHitboxState(Globals.clientSceneWrapper.getHitboxManager(), false, rVal, rawType.getHitboxData()); - } - //add health system - // rVal.putData(EntityDataStrings.LIFE_STATE, new LifeState(rVal, rawType.getHealthSystem())); - // Globals.entityManager.registerLifeStateEntity(rVal); - //idle tree & generic stuff all objects have - rVal.putData(EntityDataStrings.TREE_IDLE, new ClientIdleTree(rVal)); - rVal.putData(EntityDataStrings.DRAW_CAST_SHADOW, true); - rVal.putData(EntityDataStrings.ENTITY_TYPE, ENTITY_TYPE_OBJECT); - rVal.putData(EntityDataStrings.ENTITY_SUBTYPE, type); - return rVal; - } - - - - /** - * Spawns a server-side object - * @param type The type of object to spawn - * @return The object - */ - public static Entity serverSpawnBasicObject(Realm realm, Vector3d position, String type){ - ObjectData rawType = Globals.gameConfigCurrent.getObjectTypeLoader().getObject(type); - Entity rVal = EntityCreationUtils.createServerEntity(realm, position); - - if(rawType.getModelPath() != null){ - EntityCreationUtils.makeEntityPoseable(rVal, rawType.getModelPath()); - } - //forward-searching tokens - for(String token : rawType.getTokens()){ - switch(token){ - case "GENERATE_COLLISION_OBJECT": { - Globals.assetManager.addCollisionMeshToQueue(new PhysicsMeshQueueItem(realm.getCollisionEngine(),rawType.getModelPath())); - ServerBehaviorTreeUtils.attachBTreeToEntity(rVal, new BehaviorTree() {public void simulate(float deltaTime) { - DBody collisionObject = Globals.assetManager.fetchCollisionObject(realm.getCollisionEngine(),rawType.getModelPath()); - if(collisionObject != null){ - ServerBehaviorTreeUtils.detatchBTreeFromEntity(rVal, this); - CollisionObjUtils.serverAttachCollisionObjectToEntity(rVal, collisionObject, 0, Collidable.TYPE_OBJECT); - } - }}); - } break; - case "GENERATE_COLLISION_TERRAIN": { - Globals.assetManager.addCollisionMeshToQueue(new PhysicsMeshQueueItem(realm.getCollisionEngine(),rawType.getModelPath())); - ServerBehaviorTreeUtils.attachBTreeToEntity(rVal, new BehaviorTree() {public void simulate(float deltaTime) { - DBody collisionObject = Globals.assetManager.fetchCollisionObject(realm.getCollisionEngine(),rawType.getModelPath()); - if(collisionObject != null){ - ServerBehaviorTreeUtils.detatchBTreeFromEntity(rVal, this); - CollisionObjUtils.serverAttachCollisionObjectToEntity(rVal, collisionObject, 0, Collidable.TYPE_TERRAIN); - } - }}); - } break; - } - } - // - //main entity construction - //physics - if(rawType.getCollidable() != null){ - CollidableTemplate physicsTemplate = rawType.getCollidable(); - PhysicsEntityUtils.serverAttachCollidableTemplate(realm, rVal, physicsTemplate); - } - //tokens - for(String token : rawType.getTokens()){ - switch(token){ - case "GRAVITY": - Collidable collidable = (Collidable)rVal.getData(EntityDataStrings.PHYSICS_COLLIDABLE); - DBody collisionObject = PhysicsEntityUtils.getDBody(rVal); - ServerGravityTree.attachTree(rVal, collidable, collisionObject, 30); - rVal.putData(EntityDataStrings.GRAVITY_ENTITY, true); - break; - case "TARGETABLE": - ServerEntityTagUtils.attachTagToEntity(rVal, EntityTags.TARGETABLE); - break; - case "INVENTORY": - rVal.putData(EntityDataStrings.NATURAL_INVENTORY,UnrelationalInventoryState.createUnrelationalInventory(10)); - InventoryUtils.serverSetInventoryState(rVal, ServerInventoryState.serverCreateInventoryState(rVal)); - break; - case "OUTLINE": - rVal.putData(EntityDataStrings.DRAW_OUTLINE, true); - break; - case "TERRAIN_COLLISION": { - CollisionObjUtils.getCollidable(rVal).overrideType(Collidable.TYPE_TERRAIN); - } break; - case "SPAWNPOINT": { - realm.registerSpawnPoint(position); - } break; - } - } - if(rawType.getHitboxData() != null){ - HitboxCollectionState.attachHitboxState(realm.getHitboxManager(), true, rVal, rawType.getHitboxData()); - } - - - //required for synchronization manager - ServerEntityTagUtils.attachTagToEntity(rVal, EntityTags.OBJECT); - EntityUtils.setEntityType(rVal, ENTITY_TYPE_OBJECT); - EntityUtils.setEntitySubtype(rVal, type); - - - //position entity - //this needs to be called at the end of this function. - //Burried underneath this is function call to initialize a server side entity. - //The server initialization logic checks what type of entity this is, if this function is called prior to its type being stored - //the server will not be able to synchronize it properly. - ServerEntityUtils.initiallyPositionEntity(realm,rVal,position); - - return rVal; - } - - /** - * Checks if the provided entity is an object - * @param entity The entity - * @return true if it is an object, false otherwise - */ - public static boolean isObject(Entity entity){ - if(!entity.containsKey(EntityDataStrings.ENTITY_TYPE)){ - return false; - } - return (int)entity.getData(EntityDataStrings.ENTITY_TYPE) == ENTITY_TYPE_OBJECT; - } - - /** - * Gets the type of object - * @param e the entity - * @return the type - */ - public static String getType(Entity e){ - return (String)EntityUtils.getEntitySubtype(e); - } - - /** - * Sets the object to a given player - * @param player The player - * @param item The object entity - */ - public static void sendEntityToPlayer(Player player, Entity object){ - int id = object.getId(); - String type = ObjectUtils.getType(object); - Vector3d position = EntityUtils.getPosition(object); - Quaterniond rotation = EntityUtils.getRotation(object); - //construct the spawn message and attach to player - NetworkMessage message = EntityMessage.constructSpawnObjectMessage( - id, - type, - position.x, - position.y, - position.z, - rotation.x, - rotation.y, - rotation.z, - rotation.w - ); - player.addMessage(message); - } + public static final int ENTITY_TYPE_COMMON = 2; } diff --git a/src/main/java/electrosphere/entity/types/structure/StructureUtils.java b/src/main/java/electrosphere/entity/types/structure/StructureUtils.java deleted file mode 100644 index 52734537..00000000 --- a/src/main/java/electrosphere/entity/types/structure/StructureUtils.java +++ /dev/null @@ -1,101 +0,0 @@ -package electrosphere.entity.types.structure; - -import electrosphere.engine.Globals; -import electrosphere.entity.Entity; -import electrosphere.entity.EntityCreationUtils; -import electrosphere.entity.EntityDataStrings; -import electrosphere.entity.EntityUtils; -import electrosphere.entity.types.collision.CollisionObjUtils; -import electrosphere.game.data.structure.type.model.CollisionObjectTemplate; -import electrosphere.game.data.structure.type.model.StructureType; -import electrosphere.net.parser.net.message.EntityMessage; -import electrosphere.net.parser.net.message.NetworkMessage; -import electrosphere.net.server.player.Player; -import electrosphere.server.datacell.Realm; - -import org.joml.Matrix4f; -import org.joml.Quaterniond; -import org.joml.Quaternionf; -import org.joml.Vector3d; -import org.joml.Vector3f; -import org.joml.Vector4f; - -/** - * Structure entity utility functions - */ -public class StructureUtils { - - //the entity type value - public static final int ENTITY_TYPE_STRUCTURE = 4; - - - public static Entity clientSpawnBasicStructure(String type, Vector3f position, Quaternionf rotation){ - StructureType rawType = Globals.gameConfigCurrent.getStructureTypeMap().getType(type); - Entity rVal = EntityCreationUtils.createClientSpatialEntity(); - EntityCreationUtils.makeEntityDrawable(rVal, rawType.getModelPath()); - EntityUtils.getPosition(rVal).set(position); - EntityUtils.getRotation(rVal).set(rotation); - for(CollisionObjectTemplate template : rawType.getCollision()){ - switch(template.getType()){ - case CollisionObjectTemplate.TYPE_CUBE: - Matrix4f rotationTransform = new Matrix4f().rotate(rotation); - Vector4f rotatedPosition = rotationTransform.transform(new Vector4f(template.getPositionX(),template.getPositionY(),template.getPositionZ(),1.0f)); - Vector3d cubePosition = new Vector3d(position).add(rotatedPosition.x,rotatedPosition.y,rotatedPosition.z); - Quaterniond cubeRotation = new Quaterniond(rotation).mul(new Quaterniond(template.getRotationX(),template.getRotationY(),template.getRotationZ(),template.getRotationW())).normalize(); - CollisionObjUtils.clientAttachCollisionCube(new Vector3f(template.getScaleX(),template.getScaleY(),template.getScaleZ()), cubePosition, cubeRotation, rVal); -// Collidable collidable = new Collidable(rVal, Collidable.TYPE_STRUCTURE); -// Globals.collisionEngine.registerPhysicsEntity(rVal); -// Globals.collisionEngine.registerCollisionObject(rigidBody, collidable); - break; - case CollisionObjectTemplate.TYPE_PLANE: - throw new UnsupportedOperationException("Haven't implemented plane collision on structures"); - } - } - rVal.putData(EntityDataStrings.STRUCTURE_IS_STRUCTURE,true); - rVal.putData(EntityDataStrings.STRUCTURE_TYPE,type); - return rVal; - } - - public static Entity serverSpawnBasicStructure(String type, Realm realm, Vector3d position, Quaternionf rotation){ - StructureType rawType = Globals.gameConfigCurrent.getStructureTypeMap().getType(type); - Entity rVal = EntityCreationUtils.createServerEntity(realm, position); - EntityCreationUtils.makeEntityPoseable(rVal, rawType.getModelPath()); - EntityUtils.getPosition(rVal).set(position); - EntityUtils.getRotation(rVal).set(rotation); - for(CollisionObjectTemplate template : rawType.getCollision()){ - switch(template.getType()){ - case CollisionObjectTemplate.TYPE_CUBE: - Matrix4f rotationTransform = new Matrix4f().rotate(rotation); - Vector4f rotatedPosition = rotationTransform.transform(new Vector4f(template.getPositionX(),template.getPositionY(),template.getPositionZ(),1.0f)); - Vector3d cubePosition = new Vector3d((float)position.x,(float)position.y,(float)position.z).add(rotatedPosition.x,rotatedPosition.y,rotatedPosition.z); - Quaterniond cubeRotation = new Quaterniond(rotation).mul(new Quaterniond(template.getRotationX(),template.getRotationY(),template.getRotationZ(),template.getRotationW())).normalize(); - CollisionObjUtils.serverAttachCollisionCube(new Vector3f(template.getScaleX(),template.getScaleY(),template.getScaleZ()), cubePosition, cubeRotation, rVal); -// Collidable collidable = new Collidable(rVal, Collidable.TYPE_STRUCTURE); -// Globals.collisionEngine.registerPhysicsEntity(rVal); -// Globals.collisionEngine.registerCollisionObject(rigidBody, collidable); - break; - case CollisionObjectTemplate.TYPE_PLANE: - throw new UnsupportedOperationException("Haven't implemented plane collision on structures"); - } - } - rVal.putData(EntityDataStrings.STRUCTURE_IS_STRUCTURE,true); - rVal.putData(EntityDataStrings.STRUCTURE_TYPE,type); - return rVal; - } - - public static boolean isStructure(Entity entity){ - return entity.containsKey(EntityDataStrings.STRUCTURE_IS_STRUCTURE); - } - - public static String getType(Entity structure){ - return (String)structure.getData(EntityDataStrings.STRUCTURE_TYPE); - } - - public static void sendStructureToPlayer(Player player, Entity structure){ - int id = structure.getId(); - String type = StructureUtils.getType(structure); - Vector3d position = EntityUtils.getPosition(structure); - NetworkMessage message = EntityMessage.constructCreateMessage(id, EntityDataStrings.ENTITY_CATEGORY_STRUCTURE, type, (float)position.x, (float)position.y, (float)position.z); - player.addMessage(message); - } -} diff --git a/src/main/java/electrosphere/entity/types/tree/ProceduralTree.java b/src/main/java/electrosphere/entity/types/tree/ProceduralTree.java index b24374f6..c7d558f7 100644 --- a/src/main/java/electrosphere/entity/types/tree/ProceduralTree.java +++ b/src/main/java/electrosphere/entity/types/tree/ProceduralTree.java @@ -16,6 +16,8 @@ import org.joml.Vector4d; import org.joml.Vector4f; import org.ode4j.ode.DBody; +import electrosphere.client.entity.instance.InstanceTemplate; +import electrosphere.client.entity.instance.InstancedEntityUtils; import electrosphere.collision.CollisionBodyCreation; import electrosphere.collision.PhysicsEntityUtils; import electrosphere.collision.collidable.Collidable; @@ -26,8 +28,6 @@ import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityUtils; import electrosphere.entity.btree.BehaviorTree; import electrosphere.entity.types.attach.AttachUtils; -import electrosphere.entity.types.instance.InstanceTemplate; -import electrosphere.entity.types.instance.InstancedEntityUtils; import electrosphere.game.data.foliage.type.FoliageType; import electrosphere.game.data.foliage.type.TreeModel; import electrosphere.renderer.actor.instance.InstancedActor; diff --git a/src/main/java/electrosphere/entity/types/waypoint/WaypointUtils.java b/src/main/java/electrosphere/entity/types/waypoint/WaypointUtils.java deleted file mode 100644 index 3825d810..00000000 --- a/src/main/java/electrosphere/entity/types/waypoint/WaypointUtils.java +++ /dev/null @@ -1,8 +0,0 @@ -package electrosphere.entity.types.waypoint; - -/** - * Waypoint entity utility functions - */ -public class WaypointUtils { - -} diff --git a/src/main/java/electrosphere/game/data/Config.java b/src/main/java/electrosphere/game/data/Config.java index cb6e817e..67a3e56e 100644 --- a/src/main/java/electrosphere/game/data/Config.java +++ b/src/main/java/electrosphere/game/data/Config.java @@ -4,15 +4,15 @@ import java.util.LinkedList; import java.util.List; import electrosphere.game.data.audio.SurfaceAudioCollection; +import electrosphere.game.data.common.CommonEntityLoader; +import electrosphere.game.data.common.CommonEntityMap; +import electrosphere.game.data.common.CommonEntityType; import electrosphere.game.data.creature.type.CreatureData; import electrosphere.game.data.creature.type.CreatureTypeLoader; import electrosphere.game.data.creature.type.attack.AttackMoveResolver; import electrosphere.game.data.creature.type.model.CreatureTypeMap; import electrosphere.game.data.foliage.type.model.FoliageTypeMap; import electrosphere.game.data.item.type.model.ItemTypeMap; -import electrosphere.game.data.object.type.ObjectData; -import electrosphere.game.data.object.type.model.ObjectTypeLoader; -import electrosphere.game.data.object.type.model.ObjectTypeMap; import electrosphere.game.data.particle.ParticleDefinition; import electrosphere.game.data.projectile.ProjectileTypeHolder; import electrosphere.game.data.structure.type.model.StructureTypeMap; @@ -33,7 +33,7 @@ public class Config { StructureTypeMap structureTypeMap; ItemTypeMap itemMap; FoliageTypeMap foliageMap; - ObjectTypeLoader objectTypeLoader; + CommonEntityMap objectTypeLoader; SymbolMap symbolMap; RaceMap raceMap; ProjectileTypeHolder projectileTypeHolder; @@ -65,20 +65,20 @@ public class Config { */ public static Config loadDefaultConfig(){ Config config = new Config(); - config.creatureTypeLoader = loadCreatureTypes("Data/creatures.json"); - config.itemMap = FileUtils.loadObjectFromAssetPath("Data/items.json", ItemTypeMap.class); - config.structureTypeMap = FileUtils.loadObjectFromAssetPath("Data/structures.json", StructureTypeMap.class); - config.foliageMap = FileUtils.loadObjectFromAssetPath("Data/foliage.json", FoliageTypeMap.class); - config.objectTypeLoader = loadObjectTypes("Data/objects.json"); - config.symbolMap = FileUtils.loadObjectFromAssetPath("Data/symbolism.json", SymbolMap.class); - config.raceMap = FileUtils.loadObjectFromAssetPath("Data/races.json", RaceMap.class); - config.voxelData = FileUtils.loadObjectFromAssetPath("Data/voxelTypes.json", VoxelData.class); - config.projectileTypeHolder = FileUtils.loadObjectFromAssetPath("Data/projectile.json", ProjectileTypeHolder.class); + config.creatureTypeLoader = loadCreatureTypes("Data/entity/creatures.json"); + config.itemMap = FileUtils.loadObjectFromAssetPath("Data/entity/items.json", ItemTypeMap.class); + config.structureTypeMap = FileUtils.loadObjectFromAssetPath("Data/entity/structures.json", StructureTypeMap.class); + config.foliageMap = FileUtils.loadObjectFromAssetPath("Data/entity/foliage.json", FoliageTypeMap.class); + config.objectTypeLoader = loadCommonEntityTypes("Data/entity/objects.json"); + config.symbolMap = FileUtils.loadObjectFromAssetPath("Data/game/symbolism.json", SymbolMap.class); + config.raceMap = FileUtils.loadObjectFromAssetPath("Data/game/races.json", RaceMap.class); + config.voxelData = FileUtils.loadObjectFromAssetPath("Data/game/voxelTypes.json", VoxelData.class); + config.projectileTypeHolder = FileUtils.loadObjectFromAssetPath("Data/entity/projectile.json", ProjectileTypeHolder.class); config.hintData = FileUtils.loadObjectFromAssetPath("Data/tutorial/hints.json", HintDefinition.class); config.surfaceAudioCollection = FileUtils.loadObjectFromAssetPath("Data/audio/surface.json", SurfaceAudioCollection.class); - config.particleDefinition = FileUtils.loadObjectFromAssetPath("Data/particles.json", ParticleDefinition.class); + config.particleDefinition = FileUtils.loadObjectFromAssetPath("Data/entity/particles.json", ParticleDefinition.class); config.projectileTypeHolder.init(); - config.unitLoader = UnitLoader.create(FileUtils.loadObjectFromAssetPath("Data/units/units.json", UnitDefinitionFile.class)); + config.unitLoader = UnitLoader.create(FileUtils.loadObjectFromAssetPath("Data/game/units/units.json", UnitDefinitionFile.class)); //validate ConfigValidator.valdiate(config); @@ -87,6 +87,42 @@ public class Config { return config; } + /** + * Reads a child entity defintion file + * @param filename The filename + * @return The list of entities in the file + */ + static List