From 8408d840550a507b87be5e86acf05fe87d5255e8 Mon Sep 17 00:00:00 2001 From: austin Date: Thu, 12 Sep 2024 18:51:51 -0400 Subject: [PATCH] massive entity spawning refactor --- assets/Data/{ => entity}/creatures.json | 8 +- .../Data/{ => entity}/creatures/animals.json | 2 +- assets/Data/{ => entity}/creatures/elf.json | 2 +- .../Data/{ => entity}/creatures/goblin.json | 2 +- assets/Data/{ => entity}/creatures/human.json | 5 +- assets/Data/{ => entity}/creatures/test.json | 0 assets/Data/{ => entity}/foliage.json | 9 +- assets/Data/{ => entity}/items.json | 14 +- assets/Data/{ => entity}/objects.json | 0 assets/Data/{ => entity}/particles.json | 0 assets/Data/{ => entity}/projectile.json | 0 assets/Data/{ => entity}/structures.json | 0 assets/Data/{ => game}/civilizations.json | 0 assets/Data/{ => game}/races.json | 0 assets/Data/{ => game}/symbolism.json | 0 assets/Data/{ => game}/units/units.json | 0 assets/Data/{ => game}/voxelTypes.json | 0 docs/src/progress/renderertodo.md | 1 + net/entity.json | 86 +- .../java/electrosphere/audio/AudioEngine.java | 2 +- .../audio/VirtualAudioSourceManager.java | 2 +- .../audio/collision/HitboxAudioService.java | 5 +- .../collision/ClientHitboxCollision.java | 5 +- .../client/effects/ParticleEffects.java | 2 +- .../entity}/camera/CameraEntityUtils.java | 2 +- .../crosshair/Crosshair.java | 10 +- .../entity}/debug/DebugVisualizerUtils.java | 2 +- .../entity}/instance/InstanceTemplate.java | 2 +- .../instance/InstancedEntityUtils.java | 2 +- .../entity}/particle/ParticleUtils.java | 2 +- .../client/foliagemanager/FoliageCell.java | 2 +- .../client/instancing/InstanceUpdater.java | 2 +- .../client/sim/ClientSimulation.java | 4 +- .../electrosphere/controls/CameraHandler.java | 4 +- .../controls/ControlHandler.java | 4 +- .../engine/loadingthreads/ClientLoading.java | 4 +- .../engine/loadingthreads/LoadingUtils.java | 2 +- .../entity/EntityCreationUtils.java | 16 +- .../entity/EntityDataStrings.java | 15 +- .../electrosphere/entity/EntityUtils.java | 133 --- .../entity/btree/StateTransitionUtil.java | 6 +- .../entity/scene/SceneLoader.java | 4 +- .../entity/state/attack/ClientAttackTree.java | 2 +- .../entity/state/attack/ServerAttackTree.java | 2 +- .../client/firstPerson/FirstPersonTree.java | 2 +- .../entity/state/equip/ClientEquipState.java | 4 +- .../entity/state/equip/ServerEquipState.java | 4 +- .../entity/state/idle/ClientIdleTree.java | 2 +- .../state/movement/fall/ServerFallTree.java | 2 +- .../groundmove/ServerGroundMovementTree.java | 2 +- .../physicssync/ClientPhysicsSyncTree.java | 2 +- .../state/server/ServerPlayerViewDirTree.java | 2 +- .../entity/types/EntityTypes.java | 73 ++ .../types/collision/CollisionObjUtils.java | 207 ----- .../types/common/CommonEntityUtils.java | 823 ++++++++++++++++++ .../types/creature/CreatureTemplate.java | 2 +- .../entity/types/creature/CreatureUtils.java | 498 +---------- .../entity/types/foliage/FoliageUtils.java | 74 +- .../entity/types/item/ItemUtils.java | 131 ++- .../entity/types/object/ObjectUtils.java | 259 +----- .../types/structure/StructureUtils.java | 101 --- .../entity/types/tree/ProceduralTree.java | 4 +- .../entity/types/waypoint/WaypointUtils.java | 8 - .../java/electrosphere/game/data/Config.java | 108 +-- .../game/data/ConfigValidator.java | 2 +- .../game/data/common/CommonEntityLoader.java | 36 + .../game/data/common/CommonEntityMap.java | 52 ++ .../game/data/common/CommonEntityType.java | 310 +++++++ .../{ => treedata}/TreeDataAnimation.java | 2 +- .../common/{ => treedata}/TreeDataAudio.java | 2 +- .../common/{ => treedata}/TreeDataState.java | 2 +- .../game/data/creature/type/CreatureData.java | 235 +---- .../creature/type/CreatureDataValidator.java | 8 +- .../creature/type/CreatureTypeLoader.java | 67 +- .../game/data/creature/type/HealthSystem.java | 2 +- .../game/data/creature/type/IdleData.java | 2 +- .../game/data/creature/type/SprintSystem.java | 2 +- .../data/creature/type/attack/AttackMove.java | 2 +- .../creature/type/block/BlockVariant.java | 4 +- .../data/creature/type/equip/EquipPoint.java | 2 +- .../type/movement/FallMovementSystem.java | 2 +- .../type/movement/GroundMovementSystem.java | 2 +- .../type/movement/JumpMovementSystem.java | 2 +- .../game/data/foliage/type/FoliageType.java | 64 +- .../foliage/type/model/FoliageTypeMap.java | 2 +- .../game/data/item/type/Item.java | 45 +- .../data/item/type/model/ItemTypeMap.java | 4 +- .../game/data/object/type/ObjectData.java | 75 -- .../object/type/model/ObjectTypeLoader.java | 48 - .../data/object/type/model/ObjectTypeMap.java | 48 - .../menu/debug/ImGuiEntityMacros.java | 4 +- .../menu/debug/ImGuiPlayerEntity.java | 2 +- .../menu/ingame/MenuGeneratorsInGame.java | 2 +- .../ingame/MenuGeneratorsLevelEditor.java | 39 +- .../mainmenu/MenuGeneratorsMultiplayer.java | 4 +- .../mainmenu/MenuGeneratorsUITesting.java | 2 +- .../net/client/protocol/EntityProtocol.java | 204 +++-- .../net/parser/net/message/EntityMessage.java | 595 +------------ .../parser/net/message/NetworkMessage.java | 20 - .../net/parser/net/message/TypeBytes.java | 22 +- .../net/server/protocol/EntityProtocol.java | 4 - .../electrosphere/renderer/actor/Actor.java | 2 +- .../renderer/light/LightManager.java | 2 +- .../electrosphere/renderer/model/Mesh.java | 2 +- .../pipelines/FirstPersonItemsPipeline.java | 2 +- .../pipelines/MainContentNoOITPipeline.java | 2 +- .../pipelines/MainContentPipeline.java | 2 +- .../pipelines/NormalsForOutlinePipeline.java | 2 +- .../renderer/pipelines/ShadowMapPipeline.java | 2 +- .../pipelines/VolumeBufferPipeline.java | 2 +- .../pipelines/debug/DebugBonesPipeline.java | 2 +- .../pipelines/debug/DebugContentPipeline.java | 2 +- .../ai/nodes/actions/move/FaceTargetNode.java | 2 +- .../serialization/ContentSerialization.java | 87 +- .../server/datacell/ServerDataCell.java | 34 +- .../server/poseactor/PoseActor.java | 2 +- .../util/ds/octree/ChunkTree.java | 1 - .../camera/CameraEntityUtilsUnitTests.java | 1 + 118 files changed, 1901 insertions(+), 2841 deletions(-) rename assets/Data/{ => entity}/creatures.json (85%) rename assets/Data/{ => entity}/creatures/animals.json (96%) rename assets/Data/{ => entity}/creatures/elf.json (99%) rename assets/Data/{ => entity}/creatures/goblin.json (99%) rename assets/Data/{ => entity}/creatures/human.json (99%) rename assets/Data/{ => entity}/creatures/test.json (100%) rename assets/Data/{ => entity}/foliage.json (95%) rename assets/Data/{ => entity}/items.json (97%) rename assets/Data/{ => entity}/objects.json (100%) rename assets/Data/{ => entity}/particles.json (100%) rename assets/Data/{ => entity}/projectile.json (100%) rename assets/Data/{ => entity}/structures.json (100%) rename assets/Data/{ => game}/civilizations.json (100%) rename assets/Data/{ => game}/races.json (100%) rename assets/Data/{ => game}/symbolism.json (100%) rename assets/Data/{ => game}/units/units.json (100%) rename assets/Data/{ => game}/voxelTypes.json (100%) rename src/main/java/electrosphere/{entity/types => client/entity}/camera/CameraEntityUtils.java (99%) rename src/main/java/electrosphere/client/{targeting => entity}/crosshair/Crosshair.java (92%) rename src/main/java/electrosphere/{entity/types => client/entity}/debug/DebugVisualizerUtils.java (98%) rename src/main/java/electrosphere/{entity/types => client/entity}/instance/InstanceTemplate.java (97%) rename src/main/java/electrosphere/{entity/types => client/entity}/instance/InstancedEntityUtils.java (98%) rename src/main/java/electrosphere/{entity/types => client/entity}/particle/ParticleUtils.java (98%) create mode 100644 src/main/java/electrosphere/entity/types/EntityTypes.java create mode 100644 src/main/java/electrosphere/entity/types/common/CommonEntityUtils.java delete mode 100644 src/main/java/electrosphere/entity/types/structure/StructureUtils.java delete mode 100644 src/main/java/electrosphere/entity/types/waypoint/WaypointUtils.java create mode 100644 src/main/java/electrosphere/game/data/common/CommonEntityLoader.java create mode 100644 src/main/java/electrosphere/game/data/common/CommonEntityMap.java create mode 100644 src/main/java/electrosphere/game/data/common/CommonEntityType.java rename src/main/java/electrosphere/game/data/common/{ => treedata}/TreeDataAnimation.java (97%) rename src/main/java/electrosphere/game/data/common/{ => treedata}/TreeDataAudio.java (86%) rename src/main/java/electrosphere/game/data/common/{ => treedata}/TreeDataState.java (92%) delete mode 100644 src/main/java/electrosphere/game/data/object/type/ObjectData.java delete mode 100644 src/main/java/electrosphere/game/data/object/type/model/ObjectTypeLoader.java delete mode 100644 src/main/java/electrosphere/game/data/object/type/model/ObjectTypeMap.java 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 recursiveReadEntityLoader(String filename){ + List typeList = new LinkedList(); + CommonEntityLoader loaderFile = FileUtils.loadObjectFromAssetPath(filename, CommonEntityLoader.class); + //push the types from this file + for(CommonEntityType type : loaderFile.getEntities()){ + typeList.add(type); + } + //push types from any other files + for(String filepath : loaderFile.getFiles()){ + List parsedTypeList = recursiveReadEntityLoader(filepath); + for(CommonEntityType type : parsedTypeList){ + typeList.add(type); + } + } + return typeList; + } + + /** + * Loads all common entity definition files recursively + * @param initialPath The initial path to recurse from + * @return The common entity defintion interface + */ + static CommonEntityMap loadCommonEntityTypes(String initialPath) { + CommonEntityMap rVal = new CommonEntityMap(); + List typeList = recursiveReadEntityLoader(initialPath); + for(CommonEntityType type : typeList){ + rVal.putType(type.getId(), type); + } + return rVal; + } + /** * Reads a child creature defintion file * @param filename The filename @@ -121,53 +157,17 @@ public class Config { if(type.getAttackMoves() != null){ type.setAttackMoveResolver(new AttackMoveResolver(type.getAttackMoves())); } - loader.putCreature(type.getCreatureId(), type); + loader.putType(type.getId(), type); //loop through all creatures and add ones with PLAYABLE token to list of playable races for(String token : type.getTokens()){ if(token.contains("PLAYABLE")){ - loader.putPlayableRace(type.getCreatureId()); + loader.putPlayableRace(type.getId()); } } } return loader; } - /** - * Read a file that define object entity types - * @param filename The filename to read - * @return The list of object definitions - */ - static List readObjectTypeFile(String filename){ - List typeList = new LinkedList(); - ObjectTypeMap typeMap = FileUtils.loadObjectFromAssetPath(filename, ObjectTypeMap.class); - //push the types from this file - for(ObjectData type : typeMap.getObjects()){ - typeList.add(type); - } - //push types from any other files - for(String filepath : typeMap.getFiles()){ - List parsedTypeList = readObjectTypeFile(filepath); - for(ObjectData type : parsedTypeList){ - typeList.add(type); - } - } - return typeList; - } - - /** - * Recursively reads files that define object entities - * @param initialPath The initial path to start recursing from - * @return The object entity interface - */ - static ObjectTypeLoader loadObjectTypes(String initialPath) { - ObjectTypeLoader loader = new ObjectTypeLoader(); - List typeList = readObjectTypeFile(initialPath); - for(ObjectData type : typeList){ - loader.putObject(type.getObjectId(), type); - } - return loader; - } - /** * Gets the interface for creature definitions loaded into memory * @return The interface @@ -220,7 +220,7 @@ public class Config { * Gets the definitions of all object entities in memory * @return The objects */ - public ObjectTypeLoader getObjectTypeLoader() { + public CommonEntityMap getObjectTypeMap() { return objectTypeLoader; } diff --git a/src/main/java/electrosphere/game/data/ConfigValidator.java b/src/main/java/electrosphere/game/data/ConfigValidator.java index fa2b00f9..581cbdc1 100644 --- a/src/main/java/electrosphere/game/data/ConfigValidator.java +++ b/src/main/java/electrosphere/game/data/ConfigValidator.java @@ -16,7 +16,7 @@ public class ConfigValidator { public static void valdiate(Config config){ //validate the creatures CreatureTypeLoader creatureTypeLoader = config.getCreatureTypeLoader(); - for(CreatureData creatureData : creatureTypeLoader.getCreatures()){ + for(CreatureData creatureData : creatureTypeLoader.getTypes()){ CreatureDataValidator.validate(creatureData); } } diff --git a/src/main/java/electrosphere/game/data/common/CommonEntityLoader.java b/src/main/java/electrosphere/game/data/common/CommonEntityLoader.java new file mode 100644 index 00000000..5759bb38 --- /dev/null +++ b/src/main/java/electrosphere/game/data/common/CommonEntityLoader.java @@ -0,0 +1,36 @@ +package electrosphere.game.data.common; + +import java.util.List; + +/** + * A recursive file structure for loading types of entities + */ +public class CommonEntityLoader { + + /** + * The entities in this file + */ + List objects; + + /** + * All child files of this one + */ + List files; + + /** + * Gets the entities stored in this file + * @return The list of entities + */ + public List getEntities(){ + return objects; + } + + /** + * Gets all child files of this one + * @return The list of all child files + */ + public List getFiles(){ + return files; + } + +} diff --git a/src/main/java/electrosphere/game/data/common/CommonEntityMap.java b/src/main/java/electrosphere/game/data/common/CommonEntityMap.java new file mode 100644 index 00000000..286ada35 --- /dev/null +++ b/src/main/java/electrosphere/game/data/common/CommonEntityMap.java @@ -0,0 +1,52 @@ +package electrosphere.game.data.common; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +/** + * A loader from a common entity type + */ +public class CommonEntityMap { + + /** + * The map of entity id -> entity data + */ + Map idTypeMap = new HashMap(); + + /** + * Adds entity data to the loader + * @param name The id of the entity + * @param type The entity data + */ + public void putType(String name, CommonEntityType type){ + idTypeMap.put(name,type); + } + + /** + * Gets entity data from the id of the type + * @param id The id of the type + * @return The entity data if it exists, null otherwise + */ + public CommonEntityType getType(String id){ + return idTypeMap.get(id); + } + + /** + * Gets the collection of all entity data + * @return the collection of all entity data + */ + public Collection getTypes(){ + return idTypeMap.values(); + } + + /** + * Gets the set of all entity data id's stored in the loader + * @return the set of all entity data ids + */ + public Set getTypeIds(){ + return idTypeMap.keySet(); + } + +} diff --git a/src/main/java/electrosphere/game/data/common/CommonEntityType.java b/src/main/java/electrosphere/game/data/common/CommonEntityType.java new file mode 100644 index 00000000..3b629026 --- /dev/null +++ b/src/main/java/electrosphere/game/data/common/CommonEntityType.java @@ -0,0 +1,310 @@ +package electrosphere.game.data.common; + +import java.util.List; + +import electrosphere.game.data.collidable.CollidableTemplate; +import electrosphere.game.data.collidable.HitboxData; +import electrosphere.game.data.creature.type.HealthSystem; +import electrosphere.game.data.creature.type.IdleData; +import electrosphere.game.data.creature.type.LookAtSystem; +import electrosphere.game.data.creature.type.ViewModelData; +import electrosphere.game.data.creature.type.ai.AITreeData; +import electrosphere.game.data.creature.type.attack.AttackMove; +import electrosphere.game.data.creature.type.attack.AttackMoveResolver; +import electrosphere.game.data.creature.type.block.BlockSystem; +import electrosphere.game.data.creature.type.bonegroups.BoneGroup; +import electrosphere.game.data.creature.type.equip.EquipPoint; +import electrosphere.game.data.creature.type.movement.MovementSystem; +import electrosphere.game.data.creature.type.rotator.RotatorSystem; +import electrosphere.game.data.foliage.type.AmbientAudio; +import electrosphere.game.data.foliage.type.GrowthModel; +import electrosphere.game.data.foliage.type.TreeModel; +import electrosphere.game.data.graphics.GraphicsTemplate; + +/** + * Common data that all entity types use + */ +public class CommonEntityType { + + /** + * The id of the creature + */ + String id; + + /** + * The list of hitboxes on the creature + */ + List hitboxes; + + /** + * Various tokens + */ + List tokens; + + /** + * The movement systems available to this creature type + */ + List movementSystems; + + /** + * Rotator systems available to this creature type + */ + RotatorSystem rotatorSystem; + + /** + * The list of equip points on this creature + */ + List equipPoints; + + /** + * The collidable used for this creature type + */ + CollidableTemplate collidable; + + /** + * The list of attack moves available to this creature + */ + List attackMoves; + + /** + * The health system available to this creature + */ + HealthSystem healthSystem; + + /** + * The look at system available for this creature + */ + LookAtSystem lookAtSystem; + + /** + * The model path for this creature + */ + String modelPath; + + /** + * The view model data for this creature + */ + ViewModelData viewModelData; + + /** + * The idle data for this creature + */ + IdleData idleData; + + /** + * The block system for this creature + */ + BlockSystem blockSystem; + + /** + * The configuration data for the ai trees associated with this creature + */ + List aiTrees; + + /** + * The attack move resolver for this creature type + */ + AttackMoveResolver attackMoveResolver; + + /** + * The list of bone groups for this creature + */ + List boneGroups; + + /** + * the model of growth characterists + */ + GrowthModel growthModel; + + /** + * The model for a tree + */ + TreeModel treeModel; + + /** + * The ambient audio model + */ + AmbientAudio ambientAudio; + + /** + * The graphics template for this object + */ + GraphicsTemplate graphicsTemplate; + + /** + * Gets the id for this creature type + * @return The id + */ + public String getId() { + return id; + } + + /** + * Gets the list of hitboxes for this creature + * @return The list of hitbox data + */ + public List getHitboxes() { + return hitboxes; + } + + /** + * Gets the tokens for this creature + * @return The tokens + */ + public List getTokens() { + return tokens; + } + + /** + * Gets the path for the model for this creature + * @return The model path + */ + public String getModelPath() { + return modelPath; + } + + /** + * Gets the list of data of movement types available to this creature + * @return The list of movement type data + */ + public List getMovementSystems() { + return movementSystems; + } + + /** + * Gets the list of attack moves available to this creature type + * @return The list of attack moves + */ + public List getAttackMoves() { + return attackMoves; + } + + /** + * Gets the health system data for this creature type + * @return The health system data + */ + public HealthSystem getHealthSystem() { + return healthSystem; + } + + /** + * Gets the collidable data for this creature type + * @return The collidable data + */ + public CollidableTemplate getCollidable() { + return collidable; + } + + /** + * Gets the look at system configuration for this creature type + * @return The look at system data + */ + public LookAtSystem getLookAtSystem() { + return lookAtSystem; + } + + /** + * Gets the rotator data for this creature type + * @return The rotator data + */ + public RotatorSystem getRotatorSystem() { + return rotatorSystem; + } + + /** + * Gets the list of equip points for this creature type + * @return The list of equip points + */ + public List getEquipPoints(){ + return equipPoints; + } + + /** + * Sets the attack move resolver for this creature type + * @param resolver The resolver + */ + public void setAttackMoveResolver(AttackMoveResolver resolver){ + attackMoveResolver = resolver; + } + + /** + * Gets the attack move resolver for this creature type + * @return The attack move resolver + */ + public AttackMoveResolver getAttackMoveResolver(){ + return attackMoveResolver; + } + + /** + * Gets the first-person view model data for this creature type + * @return The first-person view model data + */ + public ViewModelData getViewModelData(){ + return viewModelData; + } + + /** + * Gets the idle data for this creature type (ie animation data) + * @return The idle data + */ + public IdleData getIdleData(){ + return idleData; + } + + /** + * Gets the block system data for this creature type + * @return The block system data + */ + public BlockSystem getBlockSystem(){ + return blockSystem; + } + + /** + * Gets the AI tree data associated with this creature type + * @return The list of ai tree data + */ + public List getAITrees(){ + return aiTrees; + } + + /** + * Gets the list of bone groups for this creature + * @return The list of bone groups + */ + public List getBoneGroups(){ + return boneGroups; + } + + /** + * Gets the graphics template for this object + * @return the graphics template + */ + public GraphicsTemplate getGraphicsTemplate(){ + return graphicsTemplate; + } + + /** + * Gets the growth model + * @return The growth model + */ + public GrowthModel getGrowthModel(){ + return growthModel; + } + + /** + * Gets the tree model + * @return The tree model + */ + public TreeModel getTreeModel(){ + return treeModel; + } + + /** + * Gets the ambient audio model + * @return The ambient audio model + */ + public AmbientAudio getAmbientAudio(){ + return ambientAudio; + } + +} diff --git a/src/main/java/electrosphere/game/data/common/TreeDataAnimation.java b/src/main/java/electrosphere/game/data/common/treedata/TreeDataAnimation.java similarity index 97% rename from src/main/java/electrosphere/game/data/common/TreeDataAnimation.java rename to src/main/java/electrosphere/game/data/common/treedata/TreeDataAnimation.java index b84dcf59..fffed553 100644 --- a/src/main/java/electrosphere/game/data/common/TreeDataAnimation.java +++ b/src/main/java/electrosphere/game/data/common/treedata/TreeDataAnimation.java @@ -1,4 +1,4 @@ -package electrosphere.game.data.common; +package electrosphere.game.data.common.treedata; import java.util.List; diff --git a/src/main/java/electrosphere/game/data/common/TreeDataAudio.java b/src/main/java/electrosphere/game/data/common/treedata/TreeDataAudio.java similarity index 86% rename from src/main/java/electrosphere/game/data/common/TreeDataAudio.java rename to src/main/java/electrosphere/game/data/common/treedata/TreeDataAudio.java index 5949d410..904719c3 100644 --- a/src/main/java/electrosphere/game/data/common/TreeDataAudio.java +++ b/src/main/java/electrosphere/game/data/common/treedata/TreeDataAudio.java @@ -1,4 +1,4 @@ -package electrosphere.game.data.common; +package electrosphere.game.data.common.treedata; /** * Audio data to use when running a given tree state diff --git a/src/main/java/electrosphere/game/data/common/TreeDataState.java b/src/main/java/electrosphere/game/data/common/treedata/TreeDataState.java similarity index 92% rename from src/main/java/electrosphere/game/data/common/TreeDataState.java rename to src/main/java/electrosphere/game/data/common/treedata/TreeDataState.java index f879384c..050588b3 100644 --- a/src/main/java/electrosphere/game/data/common/TreeDataState.java +++ b/src/main/java/electrosphere/game/data/common/treedata/TreeDataState.java @@ -1,4 +1,4 @@ -package electrosphere.game.data.common; +package electrosphere.game.data.common.treedata; /** * A simple tree state diff --git a/src/main/java/electrosphere/game/data/creature/type/CreatureData.java b/src/main/java/electrosphere/game/data/creature/type/CreatureData.java index 1540fc45..560d7b9c 100644 --- a/src/main/java/electrosphere/game/data/creature/type/CreatureData.java +++ b/src/main/java/electrosphere/game/data/creature/type/CreatureData.java @@ -1,15 +1,6 @@ package electrosphere.game.data.creature.type; -import electrosphere.game.data.collidable.CollidableTemplate; -import electrosphere.game.data.collidable.HitboxData; -import electrosphere.game.data.creature.type.ai.AITreeData; -import electrosphere.game.data.creature.type.attack.AttackMove; -import electrosphere.game.data.creature.type.attack.AttackMoveResolver; -import electrosphere.game.data.creature.type.block.BlockSystem; -import electrosphere.game.data.creature.type.bonegroups.BoneGroup; -import electrosphere.game.data.creature.type.equip.EquipPoint; -import electrosphere.game.data.creature.type.movement.MovementSystem; -import electrosphere.game.data.creature.type.rotator.RotatorSystem; +import electrosphere.game.data.common.CommonEntityType; import electrosphere.game.data.creature.type.visualattribute.VisualAttribute; import java.util.List; @@ -17,121 +8,17 @@ import java.util.List; /** * A given type of creature */ -public class CreatureData { +public class CreatureData extends CommonEntityType { - /** - * The id of the creature - */ - String creatureId; - /** - * The list of hitboxes on the creature - */ - List hitboxes; - - /** - * Various tokens - */ - List tokens; /** * The visual attributes that can be configured on this creature type */ List visualAttributes; - /** - * The movement systems available to this creature type - */ - List movementSystems; - /** - * Rotator systems available to this creature type - */ - RotatorSystem rotatorSystem; - /** - * The list of equip points on this creature - */ - List equipPoints; - - /** - * The collidable used for this creature type - */ - CollidableTemplate collidable; - - /** - * The list of attack moves available to this creature - */ - List attackMoves; - - /** - * The health system available to this creature - */ - HealthSystem healthSystem; - - /** - * The look at system available for this creature - */ - LookAtSystem lookAtSystem; - - /** - * The model path for this creature - */ - String modelPath; - - /** - * The view model data for this creature - */ - ViewModelData viewModelData; - - /** - * The idle data for this creature - */ - IdleData idleData; - - /** - * The block system for this creature - */ - BlockSystem blockSystem; - - /** - * The configuration data for the ai trees associated with this creature - */ - List aiTrees; - - /** - * The attack move resolver for this creature type - */ - AttackMoveResolver attackMoveResolver; - - /** - * The list of bone groups for this creature - */ - List boneGroups; - - /** - * Gets the id for this creature type - * @return The id - */ - public String getCreatureId() { - return creatureId; - } - - /** - * Gets the list of hitboxes for this creature - * @return The list of hitbox data - */ - public List getHitboxes() { - return hitboxes; - } - - /** - * Gets the tokens for this creature - * @return The tokens - */ - public List getTokens() { - return tokens; - } /** * Gets the configurable visual attributes for this creature type @@ -141,125 +28,7 @@ public class CreatureData { return visualAttributes; } - /** - * Gets the path for the model for this creature - * @return The model path - */ - public String getModelPath() { - return modelPath; - } - - /** - * Gets the list of data of movement types available to this creature - * @return The list of movement type data - */ - public List getMovementSystems() { - return movementSystems; - } - - /** - * Gets the list of attack moves available to this creature type - * @return The list of attack moves - */ - public List getAttackMoves() { - return attackMoves; - } - - /** - * Gets the health system data for this creature type - * @return The health system data - */ - public HealthSystem getHealthSystem() { - return healthSystem; - } - - /** - * Gets the collidable data for this creature type - * @return The collidable data - */ - public CollidableTemplate getCollidable() { - return collidable; - } - - /** - * Gets the look at system configuration for this creature type - * @return The look at system data - */ - public LookAtSystem getLookAtSystem() { - return lookAtSystem; - } - /** - * Gets the rotator data for this creature type - * @return The rotator data - */ - public RotatorSystem getRotatorSystem() { - return rotatorSystem; - } - - /** - * Gets the list of equip points for this creature type - * @return The list of equip points - */ - public List getEquipPoints(){ - return equipPoints; - } - - /** - * Sets the attack move resolver for this creature type - * @param resolver The resolver - */ - public void setAttackMoveResolver(AttackMoveResolver resolver){ - attackMoveResolver = resolver; - } - - /** - * Gets the attack move resolver for this creature type - * @return The attack move resolver - */ - public AttackMoveResolver getAttackMoveResolver(){ - return attackMoveResolver; - } - - /** - * Gets the first-person view model data for this creature type - * @return The first-person view model data - */ - public ViewModelData getViewModelData(){ - return viewModelData; - } - - /** - * Gets the idle data for this creature type (ie animation data) - * @return The idle data - */ - public IdleData getIdleData(){ - return idleData; - } - - /** - * Gets the block system data for this creature type - * @return The block system data - */ - public BlockSystem getBlockSystem(){ - return blockSystem; - } - - /** - * Gets the AI tree data associated with this creature type - * @return The list of ai tree data - */ - public List getAITrees(){ - return aiTrees; - } - - /** - * Gets the list of bone groups for this creature - * @return The list of bone groups - */ - public List getBoneGroups(){ - return boneGroups; - } } diff --git a/src/main/java/electrosphere/game/data/creature/type/CreatureDataValidator.java b/src/main/java/electrosphere/game/data/creature/type/CreatureDataValidator.java index ed26f9f6..c2d47531 100644 --- a/src/main/java/electrosphere/game/data/creature/type/CreatureDataValidator.java +++ b/src/main/java/electrosphere/game/data/creature/type/CreatureDataValidator.java @@ -3,7 +3,7 @@ package electrosphere.game.data.creature.type; import java.util.LinkedList; import java.util.List; -import electrosphere.game.data.common.TreeDataAnimation; +import electrosphere.game.data.common.treedata.TreeDataAnimation; import electrosphere.game.data.creature.type.attack.AttackMove; import electrosphere.game.data.creature.type.bonegroups.BoneGroup; import electrosphere.game.data.creature.type.equip.EquipPoint; @@ -47,7 +47,7 @@ public class CreatureDataValidator { String message = "Two bone groups have the same bone in them!\n" + "Bone name: " + boneName + "\n" + "Second group: " + group.getId() + "\n" + - "Creature name: " + data.getCreatureId() + "Creature name: " + data.getId() ; LoggerInterface.loggerEngine.WARNING(message); } else { @@ -64,7 +64,7 @@ public class CreatureDataValidator { String message = "Two bone groups have the same bone in them!\n" + "Bone name: " + boneName + "\n" + "Second group: " + group.getId() + "\n" + - "Creature name: " + data.getCreatureId() + "Creature name: " + data.getId() ; LoggerInterface.loggerEngine.WARNING(message); } else { @@ -132,7 +132,7 @@ public class CreatureDataValidator { if(animation.getPriority() == null && animation.getPriorityCategory() == null){ //same bone used in multiple groups String message = "Animation does not have priority defined!\n" + - "Creature name: " + data.getCreatureId() + "\n" + + "Creature name: " + data.getId() + "\n" + "Animation first person name: " + animation.getNameFirstPerson() + "\n" + "Animation third person name: " + animation.getNameThirdPerson() + "\n" ; diff --git a/src/main/java/electrosphere/game/data/creature/type/CreatureTypeLoader.java b/src/main/java/electrosphere/game/data/creature/type/CreatureTypeLoader.java index 45ab9234..710fd177 100644 --- a/src/main/java/electrosphere/game/data/creature/type/CreatureTypeLoader.java +++ b/src/main/java/electrosphere/game/data/creature/type/CreatureTypeLoader.java @@ -5,6 +5,7 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.Semaphore; /** @@ -12,10 +13,10 @@ import java.util.concurrent.Semaphore; */ public class CreatureTypeLoader { - /** - * The map of creature name -> creature data + /** + * The map of entity id -> entity data */ - Map creatureMap = new HashMap(); + Map idTypeMap = new HashMap(); /** * The list of playable races @@ -27,15 +28,6 @@ public class CreatureTypeLoader { */ Semaphore playableRaceLock = new Semaphore(1); - /** - * Adds creature data to the loader - * @param name The name of the creature - * @param type The creature data - */ - public void putCreature(String name, CreatureData type){ - creatureMap.put(name,type); - } - /** * Adds a playable race to the loader * @param name The race name @@ -44,23 +36,6 @@ public class CreatureTypeLoader { playableRaceNames.add(name); } - /** - * Gets creature data from the name of a creature - * @param name The name of the creature - * @return The creature data if it exists, null otherwise - */ - public CreatureData getCreature(String name){ - return creatureMap.get(name); - } - - /** - * Gets the collection of all creature data - * @return the collection of all creature data - */ - public Collection getCreatures(){ - return creatureMap.values(); - } - /** * Gets the list of playable races * @return The list of playable race names @@ -90,5 +65,39 @@ public class CreatureTypeLoader { playableRaceLock.release(); } + /** + * Adds entity data to the loader + * @param name The id of the entity + * @param type The entity data + */ + public void putType(String name, CreatureData type){ + idTypeMap.put(name,type); + } + + /** + * Gets entity data from the id of the type + * @param id The id of the type + * @return The entity data if it exists, null otherwise + */ + public CreatureData getType(String id){ + return idTypeMap.get(id); + } + + /** + * Gets the collection of all entity data + * @return the collection of all entity data + */ + public Collection getTypes(){ + return idTypeMap.values(); + } + + /** + * Gets the set of all entity data id's stored in the loader + * @return the set of all entity data ids + */ + public Set getTypeIds(){ + return idTypeMap.keySet(); + } + } diff --git a/src/main/java/electrosphere/game/data/creature/type/HealthSystem.java b/src/main/java/electrosphere/game/data/creature/type/HealthSystem.java index ec255071..2a9e6da6 100644 --- a/src/main/java/electrosphere/game/data/creature/type/HealthSystem.java +++ b/src/main/java/electrosphere/game/data/creature/type/HealthSystem.java @@ -1,6 +1,6 @@ package electrosphere.game.data.creature.type; -import electrosphere.game.data.common.TreeDataState; +import electrosphere.game.data.common.treedata.TreeDataState; /** * Data about the health of a creature diff --git a/src/main/java/electrosphere/game/data/creature/type/IdleData.java b/src/main/java/electrosphere/game/data/creature/type/IdleData.java index 2c945258..ce74e2c1 100644 --- a/src/main/java/electrosphere/game/data/creature/type/IdleData.java +++ b/src/main/java/electrosphere/game/data/creature/type/IdleData.java @@ -1,6 +1,6 @@ package electrosphere.game.data.creature.type; -import electrosphere.game.data.common.TreeDataAnimation; +import electrosphere.game.data.common.treedata.TreeDataAnimation; /** * Data about how the creature will behave when in idle state diff --git a/src/main/java/electrosphere/game/data/creature/type/SprintSystem.java b/src/main/java/electrosphere/game/data/creature/type/SprintSystem.java index 527d3859..11b74c95 100644 --- a/src/main/java/electrosphere/game/data/creature/type/SprintSystem.java +++ b/src/main/java/electrosphere/game/data/creature/type/SprintSystem.java @@ -1,6 +1,6 @@ package electrosphere.game.data.creature.type; -import electrosphere.game.data.common.TreeDataAnimation; +import electrosphere.game.data.common.treedata.TreeDataAnimation; /** * Sprint data diff --git a/src/main/java/electrosphere/game/data/creature/type/attack/AttackMove.java b/src/main/java/electrosphere/game/data/creature/type/attack/AttackMove.java index bbaec94a..7155bcc4 100644 --- a/src/main/java/electrosphere/game/data/creature/type/attack/AttackMove.java +++ b/src/main/java/electrosphere/game/data/creature/type/attack/AttackMove.java @@ -1,6 +1,6 @@ package electrosphere.game.data.creature.type.attack; -import electrosphere.game.data.common.TreeDataState; +import electrosphere.game.data.common.treedata.TreeDataState; /** * Data about a single attack move this creature is capable of diff --git a/src/main/java/electrosphere/game/data/creature/type/block/BlockVariant.java b/src/main/java/electrosphere/game/data/creature/type/block/BlockVariant.java index 138b6601..903cded9 100644 --- a/src/main/java/electrosphere/game/data/creature/type/block/BlockVariant.java +++ b/src/main/java/electrosphere/game/data/creature/type/block/BlockVariant.java @@ -2,8 +2,8 @@ package electrosphere.game.data.creature.type.block; import java.util.List; -import electrosphere.game.data.common.TreeDataAnimation; -import electrosphere.game.data.common.TreeDataAudio; +import electrosphere.game.data.common.treedata.TreeDataAnimation; +import electrosphere.game.data.common.treedata.TreeDataAudio; /** * A variant of data that can be loaded into the block system. Variants are for different types of equip states. diff --git a/src/main/java/electrosphere/game/data/creature/type/equip/EquipPoint.java b/src/main/java/electrosphere/game/data/creature/type/equip/EquipPoint.java index 6c250972..a4297de5 100644 --- a/src/main/java/electrosphere/game/data/creature/type/equip/EquipPoint.java +++ b/src/main/java/electrosphere/game/data/creature/type/equip/EquipPoint.java @@ -2,7 +2,7 @@ package electrosphere.game.data.creature.type.equip; import java.util.List; -import electrosphere.game.data.common.TreeDataAnimation; +import electrosphere.game.data.common.treedata.TreeDataAnimation; /** * A portion of the creature that can have an item attached to it diff --git a/src/main/java/electrosphere/game/data/creature/type/movement/FallMovementSystem.java b/src/main/java/electrosphere/game/data/creature/type/movement/FallMovementSystem.java index eba48065..cd90ff81 100644 --- a/src/main/java/electrosphere/game/data/creature/type/movement/FallMovementSystem.java +++ b/src/main/java/electrosphere/game/data/creature/type/movement/FallMovementSystem.java @@ -1,6 +1,6 @@ package electrosphere.game.data.creature.type.movement; -import electrosphere.game.data.common.TreeDataState; +import electrosphere.game.data.common.treedata.TreeDataState; /** * Data about a falling movement system diff --git a/src/main/java/electrosphere/game/data/creature/type/movement/GroundMovementSystem.java b/src/main/java/electrosphere/game/data/creature/type/movement/GroundMovementSystem.java index 03126059..dea7acf0 100644 --- a/src/main/java/electrosphere/game/data/creature/type/movement/GroundMovementSystem.java +++ b/src/main/java/electrosphere/game/data/creature/type/movement/GroundMovementSystem.java @@ -1,6 +1,6 @@ package electrosphere.game.data.creature.type.movement; -import electrosphere.game.data.common.TreeDataAnimation; +import electrosphere.game.data.common.treedata.TreeDataAnimation; import electrosphere.game.data.creature.type.SprintSystem; /** diff --git a/src/main/java/electrosphere/game/data/creature/type/movement/JumpMovementSystem.java b/src/main/java/electrosphere/game/data/creature/type/movement/JumpMovementSystem.java index cdc50e12..2a84baff 100644 --- a/src/main/java/electrosphere/game/data/creature/type/movement/JumpMovementSystem.java +++ b/src/main/java/electrosphere/game/data/creature/type/movement/JumpMovementSystem.java @@ -1,6 +1,6 @@ package electrosphere.game.data.creature.type.movement; -import electrosphere.game.data.common.TreeDataAnimation; +import electrosphere.game.data.common.treedata.TreeDataAnimation; /** * A jump tree's data diff --git a/src/main/java/electrosphere/game/data/foliage/type/FoliageType.java b/src/main/java/electrosphere/game/data/foliage/type/FoliageType.java index 17299708..29c0959c 100644 --- a/src/main/java/electrosphere/game/data/foliage/type/FoliageType.java +++ b/src/main/java/electrosphere/game/data/foliage/type/FoliageType.java @@ -2,46 +2,20 @@ package electrosphere.game.data.foliage.type; import java.util.List; +import electrosphere.game.data.common.CommonEntityType; + /** * A foliage object, ambient or otherwise */ -public class FoliageType { +public class FoliageType extends CommonEntityType { //Denotes an ambient foliage that will be placed on a voxel public static final String TOKEN_AMBIENT = "AMBIENT"; //Denotes an tree object public static final String TOKEN_TREE = "TREE"; - //the name of the foliage type - String name; - //the model path of the foliage - String modelPath; //the physics object(s) for the foliage List physicsObjects; - //the model of growth characterists - GrowthModel growthModel; - //the list of tokens - List tokens; - //The model for a tree - TreeModel treeModel; - //The ambient audio model - AmbientAudio ambientAudio; - - /** - * Gets the name of the foliage type - * @return The name - */ - public String getName() { - return name; - } - - /** - * Gets the model path of the foliage type - * @return The model path - */ - public String getModelPath() { - return modelPath; - } /** * Gets the physics object(s) @@ -50,37 +24,5 @@ public class FoliageType { public List getPhysicsObjects() { return physicsObjects; } - - /** - * Gets the tokens - * @return The tokens - */ - public List getTokens() { - return tokens; - } - - /** - * Gets the growth model - * @return The growth model - */ - public GrowthModel getGrowthModel(){ - return growthModel; - } - - /** - * Gets the tree model - * @return The tree model - */ - public TreeModel getTreeModel(){ - return treeModel; - } - - /** - * Gets the ambient audio model - * @return The ambient audio model - */ - public AmbientAudio getAmbientAudio(){ - return ambientAudio; - } } diff --git a/src/main/java/electrosphere/game/data/foliage/type/model/FoliageTypeMap.java b/src/main/java/electrosphere/game/data/foliage/type/model/FoliageTypeMap.java index e75839c0..cd8e3e22 100644 --- a/src/main/java/electrosphere/game/data/foliage/type/model/FoliageTypeMap.java +++ b/src/main/java/electrosphere/game/data/foliage/type/model/FoliageTypeMap.java @@ -26,7 +26,7 @@ public class FoliageTypeMap { */ public FoliageType getFoliage(String name){ for(FoliageType foliage : foliageList){ - if(foliage.getName().matches(name)){ + if(foliage.getId().matches(name)){ return foliage; } } diff --git a/src/main/java/electrosphere/game/data/item/type/Item.java b/src/main/java/electrosphere/game/data/item/type/Item.java index 3117ac5d..8d6b47dc 100644 --- a/src/main/java/electrosphere/game/data/item/type/Item.java +++ b/src/main/java/electrosphere/game/data/item/type/Item.java @@ -1,22 +1,12 @@ package electrosphere.game.data.item.type; -import electrosphere.game.data.collidable.CollidableTemplate; - -import java.util.List; +import electrosphere.game.data.common.CommonEntityType; /** * Data on a given item */ -public class Item { +public class Item extends CommonEntityType { - //the id of the item - String itemId; - //the model path of the item - String modelPath; - //tokens associated with this item type - List tokens; - //the collidable data for the item - CollidableTemplate collidable; //the idle animation for the item String idleAnim; //the path for the icon texture for this item @@ -26,37 +16,6 @@ public class Item { //The data defining how this item is equipped EquipData equipData; - /** - * the id of the item - * @return - */ - public String getItemId() { - return itemId; - } - - /** - * the model path of the item - * @return - */ - public String getModelPath() { - return modelPath; - } - - /* - * tokens associated with this item type - */ - public List getTokens() { - return tokens; - } - - /** - * the collidable data for the item - * @return - */ - public CollidableTemplate getCollidable(){ - return collidable; - } - /** * the idle animation for the item * @return diff --git a/src/main/java/electrosphere/game/data/item/type/model/ItemTypeMap.java b/src/main/java/electrosphere/game/data/item/type/model/ItemTypeMap.java index 150828b3..789bd3c8 100644 --- a/src/main/java/electrosphere/game/data/item/type/model/ItemTypeMap.java +++ b/src/main/java/electrosphere/game/data/item/type/model/ItemTypeMap.java @@ -15,10 +15,10 @@ public class ItemTypeMap { public Item getItem(String name){ Item rVal = null; for(Item item : items){ - if(item.getItemId().equals(name)){ + if(item.getId().equals(name)){ rVal = item; break; - } else if(item.getItemId().equalsIgnoreCase(name)){ + } else if(item.getId().equalsIgnoreCase(name)){ LoggerInterface.loggerEngine.WARNING("Failed to fetch item type data; however, item with different-capitalized name exists! May be a capitalization error!"); } } diff --git a/src/main/java/electrosphere/game/data/object/type/ObjectData.java b/src/main/java/electrosphere/game/data/object/type/ObjectData.java deleted file mode 100644 index 89423470..00000000 --- a/src/main/java/electrosphere/game/data/object/type/ObjectData.java +++ /dev/null @@ -1,75 +0,0 @@ -package electrosphere.game.data.object.type; - -import electrosphere.game.data.collidable.CollidableTemplate; -import electrosphere.game.data.collidable.HitboxData; -import electrosphere.game.data.graphics.GraphicsTemplate; - -import java.util.List; - -/** - * Metadata about a type of object - */ -public class ObjectData { - - //the id of the object - String objectId; - //the path for the model for this object - String modelPath; - //tokens associated with this object - List tokens; - //the collidable template for this object - CollidableTemplate collidable; - //the graphics template for this object - GraphicsTemplate graphicsTemplate; - //the hitbox data for this object - List hitboxData; - - /** - * Gets the id of the object - * @return the id - */ - public String getObjectId() { - return objectId; - } - - /** - * Gets the model path of the object - * @return the model path - */ - public String getModelPath() { - return modelPath; - } - - /** - * Gets all tokens associated with this object - * @return the list of all tokens - */ - public List getTokens() { - return tokens; - } - - /** - * Gets the collidable data for this object - * @return the collidable data - */ - public CollidableTemplate getCollidable(){ - return collidable; - } - - /** - * Gets the graphics template for this object - * @return the graphics template - */ - public GraphicsTemplate getGraphicsTemplate(){ - return graphicsTemplate; - } - - /** - * Gets the hitbox data for this object - * @return the hitbox data - */ - public List getHitboxData(){ - return this.hitboxData; - } - -} diff --git a/src/main/java/electrosphere/game/data/object/type/model/ObjectTypeLoader.java b/src/main/java/electrosphere/game/data/object/type/model/ObjectTypeLoader.java deleted file mode 100644 index bd26cca6..00000000 --- a/src/main/java/electrosphere/game/data/object/type/model/ObjectTypeLoader.java +++ /dev/null @@ -1,48 +0,0 @@ -package electrosphere.game.data.object.type.model; - -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -import electrosphere.game.data.object.type.ObjectData; - -/** - * An interface for grabbing data about objects available to the game engine - */ -public class ObjectTypeLoader { - - //the map that stores all object types by name - Map objectMap = new HashMap(); - - //the list of all object data - List objectList = new LinkedList(); - - /** - * Gets the list of all object types loaded into memory - * @return The list - */ - public List getAllObjectTypes(){ - return objectList; - } - - /** - * Puts an object in the map - * @param name The name of the object - * @param type The object type data - */ - public void putObject(String name, ObjectData type){ - objectMap.put(name,type); - objectList.add(type); - } - - /** - * Gets object data by its name - * @param name The name of the object type - * @return The object data if it exists, otherwise null - */ - public ObjectData getObject(String name){ - return objectMap.get(name); - } - -} diff --git a/src/main/java/electrosphere/game/data/object/type/model/ObjectTypeMap.java b/src/main/java/electrosphere/game/data/object/type/model/ObjectTypeMap.java deleted file mode 100644 index ff2dbfb4..00000000 --- a/src/main/java/electrosphere/game/data/object/type/model/ObjectTypeMap.java +++ /dev/null @@ -1,48 +0,0 @@ -package electrosphere.game.data.object.type.model; - -import electrosphere.game.data.object.type.ObjectData; -import java.util.List; - -/** - * The raw list of object data read from disk - */ -public class ObjectTypeMap { - - //the objects stored in this file - List objects; - //all children files to recursively parse for more object data - List files; - - /** - * Gets the list of all objects in this file - * @return the list - */ - public List getObjects() { - return objects; - } - - /** - * Gets the object data for an object in this file by its name - * @param name the name of the object - * @return The object data - */ - public ObjectData getObject(String name){ - ObjectData rVal = null; - for(ObjectData item : objects){ - if(item.getObjectId().equals(name)){ - rVal = item; - break; - } - } - return rVal; - } - - /** - * Gets the list of all children files of this file - * @return The list of all children files - */ - public List getFiles(){ - return files; - } - -} diff --git a/src/main/java/electrosphere/menu/debug/ImGuiEntityMacros.java b/src/main/java/electrosphere/menu/debug/ImGuiEntityMacros.java index b1cf7a9a..0cdf1cc7 100644 --- a/src/main/java/electrosphere/menu/debug/ImGuiEntityMacros.java +++ b/src/main/java/electrosphere/menu/debug/ImGuiEntityMacros.java @@ -8,6 +8,7 @@ import org.joml.Quaterniond; import org.joml.Vector3d; import org.ode4j.ode.DBody; +import electrosphere.client.entity.debug.DebugVisualizerUtils; import electrosphere.collision.PhysicsEntityUtils; import electrosphere.engine.Globals; import electrosphere.entity.Entity; @@ -17,7 +18,6 @@ import electrosphere.entity.state.equip.ClientEquipState; import electrosphere.entity.state.server.ServerPlayerViewDirTree; import electrosphere.entity.types.attach.AttachUtils; import electrosphere.entity.types.creature.CreatureUtils; -import electrosphere.entity.types.debug.DebugVisualizerUtils; import electrosphere.entity.types.foliage.FoliageUtils; import electrosphere.entity.types.item.ItemUtils; import electrosphere.game.data.creature.type.equip.EquipPoint; @@ -617,7 +617,7 @@ public class ImGuiEntityMacros { return ItemUtils.getType(entity); } if(FoliageUtils.isFoliage(entity)){ - return FoliageUtils.getFoliageType(entity).getName(); + return FoliageUtils.getFoliageType(entity).getId(); } return "Entity"; } diff --git a/src/main/java/electrosphere/menu/debug/ImGuiPlayerEntity.java b/src/main/java/electrosphere/menu/debug/ImGuiPlayerEntity.java index d84050e8..ef31fd56 100644 --- a/src/main/java/electrosphere/menu/debug/ImGuiPlayerEntity.java +++ b/src/main/java/electrosphere/menu/debug/ImGuiPlayerEntity.java @@ -2,13 +2,13 @@ package electrosphere.menu.debug; import org.ode4j.ode.DBody; +import electrosphere.client.entity.camera.CameraEntityUtils; import electrosphere.collision.PhysicsEntityUtils; import electrosphere.engine.Globals; import electrosphere.entity.Entity; import electrosphere.entity.EntityUtils; import electrosphere.entity.state.attack.ClientAttackTree; import electrosphere.entity.state.server.ServerPlayerViewDirTree; -import electrosphere.entity.types.camera.CameraEntityUtils; import electrosphere.entity.types.creature.CreatureUtils; import electrosphere.renderer.ui.imgui.ImGuiWindow; import electrosphere.renderer.ui.imgui.ImGuiWindow.ImGuiWindowCallback; diff --git a/src/main/java/electrosphere/menu/ingame/MenuGeneratorsInGame.java b/src/main/java/electrosphere/menu/ingame/MenuGeneratorsInGame.java index 1f40611f..b3ca05e6 100644 --- a/src/main/java/electrosphere/menu/ingame/MenuGeneratorsInGame.java +++ b/src/main/java/electrosphere/menu/ingame/MenuGeneratorsInGame.java @@ -343,7 +343,7 @@ public class MenuGeneratorsInGame { Entity playerEntity = Globals.playerEntity; Actor playerActor = EntityUtils.getActor(playerEntity); ActorStaticMorph staticMorph = playerActor.getStaticMorph(); - CreatureData playeCreatureType = Globals.gameConfigCurrent.getCreatureTypeLoader().getCreature(CreatureUtils.getType(playerEntity)); + CreatureData playeCreatureType = Globals.gameConfigCurrent.getCreatureTypeLoader().getType(CreatureUtils.getType(playerEntity)); int offset = 0; for(VisualAttribute attribute : playeCreatureType.getVisualAttributes()){ int posY = offset * 350 + 100; diff --git a/src/main/java/electrosphere/menu/ingame/MenuGeneratorsLevelEditor.java b/src/main/java/electrosphere/menu/ingame/MenuGeneratorsLevelEditor.java index 3bfe03c2..6dc545e6 100644 --- a/src/main/java/electrosphere/menu/ingame/MenuGeneratorsLevelEditor.java +++ b/src/main/java/electrosphere/menu/ingame/MenuGeneratorsLevelEditor.java @@ -5,19 +5,19 @@ import java.util.Random; import org.joml.Vector3d; import org.joml.Vector3f; +import electrosphere.client.entity.camera.CameraEntityUtils; import electrosphere.engine.Globals; import electrosphere.engine.signal.Signal.SignalType; import electrosphere.entity.Entity; import electrosphere.entity.ServerEntityUtils; -import electrosphere.entity.types.camera.CameraEntityUtils; +import electrosphere.entity.types.common.CommonEntityUtils; import electrosphere.entity.types.creature.CreatureUtils; import electrosphere.entity.types.foliage.FoliageUtils; import electrosphere.entity.types.item.ItemUtils; -import electrosphere.entity.types.object.ObjectUtils; +import electrosphere.game.data.common.CommonEntityType; import electrosphere.game.data.creature.type.CreatureData; import electrosphere.game.data.foliage.type.FoliageType; import electrosphere.game.data.item.type.Item; -import electrosphere.game.data.object.type.ObjectData; import electrosphere.game.data.units.UnitDefinition; import electrosphere.logger.LoggerInterface; import electrosphere.menu.WindowStrings; @@ -167,15 +167,15 @@ public class MenuGeneratorsLevelEditor { })); //button for spawning all creatures - for(CreatureData data : Globals.gameConfigCurrent.getCreatureTypeLoader().getCreatures()){ + for(CreatureData data : Globals.gameConfigCurrent.getCreatureTypeLoader().getTypes()){ //spawn creature button - scrollable.addChild(Button.createButton("Spawn " + data.getCreatureId(), () -> { - LoggerInterface.loggerEngine.INFO("spawn " + data.getCreatureId() + "!"); + scrollable.addChild(Button.createButton("Spawn " + data.getId(), () -> { + LoggerInterface.loggerEngine.INFO("spawn " + data.getId() + "!"); Vector3d eyePos = new Vector3d(CameraEntityUtils.getCameraEye(Globals.playerCamera)); Vector3d centerPos = new Vector3d(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); Realm realm = Globals.realmManager.getRealms().iterator().next(); Vector3d cursorPos = realm.getCollisionEngine().rayCastPosition(new Vector3d(centerPos), new Vector3d(eyePos).mul(-1.0), 5.0).add(cursorVerticalOffset); - CreatureUtils.serverSpawnBasicCreature(realm, cursorPos, data.getCreatureId(), null); + CreatureUtils.serverSpawnBasicCreature(realm, cursorPos, data.getId(), null); })); } @@ -230,13 +230,13 @@ public class MenuGeneratorsLevelEditor { //button for spawning all foliage types for(FoliageType data : Globals.gameConfigCurrent.getFoliageMap().getFoliageList()){ //spawn foliage button - scrollable.addChild(Button.createButton("Spawn " + data.getName(), () -> { - LoggerInterface.loggerEngine.INFO("spawn " + data.getName() + "!"); + scrollable.addChild(Button.createButton("Spawn " + data.getId(), () -> { + LoggerInterface.loggerEngine.INFO("spawn " + data.getId() + "!"); Vector3d eyePos = new Vector3d(CameraEntityUtils.getCameraEye(Globals.playerCamera)); Vector3d centerPos = new Vector3d(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); Realm realm = Globals.realmManager.getRealms().iterator().next(); Vector3d cursorPos = realm.getCollisionEngine().rayCastPosition(new Vector3d(centerPos), new Vector3d(eyePos).mul(-1.0), 5.0).add(cursorVerticalOffset); - FoliageUtils.serverSpawnTreeFoliage(realm, cursorPos, data.getName(), new Random().nextLong()); + FoliageUtils.serverSpawnTreeFoliage(realm, cursorPos, data.getId(), new Random().nextLong()); })); } @@ -258,13 +258,13 @@ public class MenuGeneratorsLevelEditor { //button for spawning all foliage types for(Item item : Globals.gameConfigCurrent.getItemMap().getItems()){ //spawn foliage button - scrollable.addChild(Button.createButton("Spawn " + item.getItemId(), () -> { - LoggerInterface.loggerEngine.INFO("spawn " + item.getItemId() + "!"); + scrollable.addChild(Button.createButton("Spawn " + item.getId(), () -> { + LoggerInterface.loggerEngine.INFO("spawn " + item.getId() + "!"); Vector3d eyePos = new Vector3d(CameraEntityUtils.getCameraEye(Globals.playerCamera)); Vector3d centerPos = new Vector3d(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); Realm realm = Globals.realmManager.getRealms().iterator().next(); Vector3d cursorPos = realm.getCollisionEngine().rayCastPosition(new Vector3d(centerPos), new Vector3d(eyePos).mul(-1.0), 5.0).add(cursorVerticalOffset); - ItemUtils.serverSpawnBasicItem(realm, cursorPos, item.getItemId()); + ItemUtils.serverSpawnBasicItem(realm, cursorPos, item.getId()); })); } @@ -285,15 +285,15 @@ public class MenuGeneratorsLevelEditor { })); //button for spawning all foliage types - for(ObjectData object : Globals.gameConfigCurrent.getObjectTypeLoader().getAllObjectTypes()){ + for(CommonEntityType object : Globals.gameConfigCurrent.getObjectTypeMap().getTypes()){ //spawn foliage button - scrollable.addChild(Button.createButton("Spawn " + object.getObjectId(), () -> { - LoggerInterface.loggerEngine.INFO("spawn " + object.getObjectId() + "!"); + scrollable.addChild(Button.createButton("Spawn " + object.getId(), () -> { + LoggerInterface.loggerEngine.INFO("spawn " + object.getId() + "!"); Vector3d eyePos = new Vector3d(CameraEntityUtils.getCameraEye(Globals.playerCamera)); Vector3d centerPos = new Vector3d(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); Realm realm = Globals.realmManager.getRealms().iterator().next(); Vector3d cursorPos = realm.getCollisionEngine().rayCastPosition(new Vector3d(centerPos), new Vector3d(eyePos).mul(-1.0), 5.0).add(cursorVerticalOffset); - ObjectUtils.serverSpawnBasicObject(realm, cursorPos, object.getObjectId()); + CommonEntityUtils.serverSpawnBasicObject(realm, cursorPos, object.getId()); })); } @@ -318,7 +318,6 @@ public class MenuGeneratorsLevelEditor { if( CreatureUtils.isCreature(entity) || ItemUtils.isItem(entity) || - ObjectUtils.isObject(entity) || FoliageUtils.isFoliage(entity) ){ Div div = Div.createDiv(); @@ -363,9 +362,7 @@ public class MenuGeneratorsLevelEditor { } else if(ItemUtils.isItem(e)){ return "Object - " + ItemUtils.getType(e); } else if(FoliageUtils.isFoliage(e)){ - return "Object - " + FoliageUtils.getFoliageType(e).getName(); - } else if(ObjectUtils.isObject(e)){ - return "Object - " + ObjectUtils.getType(e); + return "Object - " + FoliageUtils.getFoliageType(e).getId(); } return "Entity Unknown Type"; } diff --git a/src/main/java/electrosphere/menu/mainmenu/MenuGeneratorsMultiplayer.java b/src/main/java/electrosphere/menu/mainmenu/MenuGeneratorsMultiplayer.java index 5a12029b..c2da3367 100644 --- a/src/main/java/electrosphere/menu/mainmenu/MenuGeneratorsMultiplayer.java +++ b/src/main/java/electrosphere/menu/mainmenu/MenuGeneratorsMultiplayer.java @@ -5,8 +5,8 @@ import java.util.List; import org.joml.Vector3f; +import electrosphere.client.entity.camera.CameraEntityUtils; import electrosphere.engine.Globals; -import electrosphere.entity.types.camera.CameraEntityUtils; import electrosphere.entity.types.creature.CreatureTemplate; import electrosphere.game.data.creature.type.CreatureData; import electrosphere.game.data.creature.type.visualattribute.AttributeVariant; @@ -87,7 +87,7 @@ public class MenuGeneratorsMultiplayer { int horizontalPosition = 300; //figure out race data - CreatureData selectedRaceType = Globals.gameConfigCurrent.getCreatureTypeLoader().getCreature(race); + CreatureData selectedRaceType = Globals.gameConfigCurrent.getCreatureTypeLoader().getType(race); //spawn camera so renderer doesn't crash (once render pipeline is modularized this shouldn't be necessary) Globals.playerCamera = CameraEntityUtils.spawnBasicCameraEntity(new Vector3f(0,0,0), new Vector3f(0,0.3f,1).normalize()); diff --git a/src/main/java/electrosphere/menu/mainmenu/MenuGeneratorsUITesting.java b/src/main/java/electrosphere/menu/mainmenu/MenuGeneratorsUITesting.java index de51cb02..853b358b 100644 --- a/src/main/java/electrosphere/menu/mainmenu/MenuGeneratorsUITesting.java +++ b/src/main/java/electrosphere/menu/mainmenu/MenuGeneratorsUITesting.java @@ -2,8 +2,8 @@ package electrosphere.menu.mainmenu; import org.joml.Vector3f; +import electrosphere.client.entity.camera.CameraEntityUtils; import electrosphere.engine.Globals; -import electrosphere.entity.types.camera.CameraEntityUtils; import electrosphere.menu.WindowUtils; import electrosphere.renderer.actor.ActorUtils; import electrosphere.renderer.ui.elements.ActorPanel; diff --git a/src/main/java/electrosphere/net/client/protocol/EntityProtocol.java b/src/main/java/electrosphere/net/client/protocol/EntityProtocol.java index 4fc4f717..212cdbd4 100644 --- a/src/main/java/electrosphere/net/client/protocol/EntityProtocol.java +++ b/src/main/java/electrosphere/net/client/protocol/EntityProtocol.java @@ -13,13 +13,15 @@ import electrosphere.entity.EntityUtils; import electrosphere.entity.state.equip.ClientEquipState; import electrosphere.entity.state.inventory.InventoryUtils; import electrosphere.entity.state.physicssync.ClientPhysicsSyncTree; +import electrosphere.entity.types.EntityTypes; +import electrosphere.entity.types.EntityTypes.EntityType; import electrosphere.entity.types.attach.AttachUtils; +import electrosphere.entity.types.common.CommonEntityUtils; import electrosphere.entity.types.creature.CreatureEquipData.EquippedItem; import electrosphere.entity.types.creature.CreatureTemplate; import electrosphere.entity.types.creature.CreatureUtils; import electrosphere.entity.types.foliage.FoliageUtils; import electrosphere.entity.types.item.ItemUtils; -import electrosphere.entity.types.object.ObjectUtils; import electrosphere.game.data.creature.type.CreatureData; import electrosphere.game.data.creature.type.ViewModelData; import electrosphere.logger.LoggerInterface; @@ -37,10 +39,6 @@ public class EntityProtocol implements ClientProtocolTemplate { //Messages to ignore when complaining about messages that have nonexistant entity associated static List idModifyingMessages = Arrays.asList(new EntityMessageType[]{ EntityMessageType.CREATE, - EntityMessageType.SPAWNCREATURE, - EntityMessageType.SPAWNFOLIAGESEED, - EntityMessageType.SPAWNITEM, - EntityMessageType.SPAWNOBJECT, EntityMessageType.DESTROY, }); @@ -61,7 +59,6 @@ public class EntityProtocol implements ClientProtocolTemplate { Globals.clientSceneWrapper.dumpIdData(message.getentityID()); } - Entity newlySpawnedEntity; switch(message.getMessageSubtype()){ @@ -75,91 +72,22 @@ public class EntityProtocol implements ClientProtocolTemplate { "Spawn ID " + message.getentityID() + " of type " + message.getentityCategory() + " subtype " + message.getentitySubtype() + " @ " + message.getpositionX() + " " + message.getpositionY() + " " + message.getpositionZ() ); - switch(message.getentityCategory()){ - case 0: - // newlySpawnedEntity = CreatureUtils.spawnBasicCreature(message.getentitySubtype()); - // EntityUtils.getScale(newlySpawnedEntity).set(0.005f); - // EntityUtils.getPosition(newlySpawnedEntity).set(message.getpositionX(),message.getpositionY(),message.getpositionZ()); - // EntityUtils.setEntityID(newlySpawnedEntity, message.getentityID()); - break; - case 1: - newlySpawnedEntity = ItemUtils.clientSpawnBasicItem(message.getentitySubtype()); - EntityUtils.getScale(newlySpawnedEntity).set(0.005f); - EntityUtils.getPosition(newlySpawnedEntity).set(message.getpositionX(),message.getpositionY(),message.getpositionZ()); - Globals.clientSceneWrapper.mapIdToId(newlySpawnedEntity.getId(), message.getentityID()); - break; + EntityType type = EntityTypes.fromInt(message.getentityCategory()); + switch(type){ + case CREATURE: { + spawnCreature(message); + } break; + case ITEM: { + spawnItem(message); + } break; + case FOLIAGE: { + spawnFoliage(message); + } break; + case COMMON: { + spawnCommon(message); + } break; } break; - case SPAWNCREATURE: { - LoggerInterface.loggerNetworking.DEBUG("[CLIENT] Spawn Creature " + message.getentityID() + " at " + message.getpositionX() + " " + message.getpositionY() + " " + message.getpositionZ()); - CreatureTemplate template = Utilities.deserialize(message.getcreatureTemplate(), CreatureTemplate.class); - newlySpawnedEntity = CreatureUtils.clientSpawnBasicCreature(template.getCreatureType(),template); - ClientEntityUtils.initiallyPositionEntity( - newlySpawnedEntity, - new Vector3d(message.getpositionX(),message.getpositionY(),message.getpositionZ()), - new Quaterniond(message.getrotationX(),message.getrotationY(),message.getrotationZ(),message.getrotationW()) - ); - Globals.clientSceneWrapper.mapIdToId(newlySpawnedEntity.getId(), message.getentityID()); - //if the creature template includes an equip section, spawn all the equipped items - if(template != null && template.getCreatureEquipData() != null && template.getCreatureEquipData().getSlots() != null){ - for(String equipSlotId : template.getCreatureEquipData().getSlots()){ - - //add the item to the creature's inventory - EquippedItem itemDefinition = template.getCreatureEquipData().getSlotItem(equipSlotId); - Entity itemInInventory = InventoryUtils.clientConstructInInventoryItem(newlySpawnedEntity,itemDefinition.getItemType()); - - //equip the item to the slot defined in the template - ClientEquipState clientEquipState = ClientEquipState.getEquipState(newlySpawnedEntity); - clientEquipState.attemptEquip(itemInInventory, clientEquipState.getEquipPoint(equipSlotId)); - - //map the constructed item to its server id - Globals.clientSceneWrapper.mapIdToId(itemInInventory.getId(), itemDefinition.getEntityId()); - } - } - //apply state synchronization if present - if(template != null && template.getStateCollection() != null && template.getStateCollection().getValues() != null){ - StateCollection.applyStateCollection(newlySpawnedEntity, template.getStateCollection()); - } - } break; - case SPAWNITEM: { - LoggerInterface.loggerNetworking.DEBUG("[CLIENT] Spawn Item " + message.getentityID() + " at " + message.getpositionX() + " " + message.getpositionY() + " " + message.getpositionZ()); - //spawn item - String itemType = message.getcreatureTemplate(); - newlySpawnedEntity = ItemUtils.clientSpawnBasicItem(itemType); - //position - ClientEntityUtils.initiallyPositionEntity( - newlySpawnedEntity, - new Vector3d(message.getpositionX(),message.getpositionY(),message.getpositionZ()), - new Quaterniond(message.getrotationX(),message.getrotationY(),message.getrotationZ(),message.getrotationW()) - ); - Globals.clientSceneWrapper.mapIdToId(newlySpawnedEntity.getId(), message.getentityID()); - } break; - case SPAWNFOLIAGESEED: { - LoggerInterface.loggerNetworking.DEBUG("[CLIENT] Spawn foliage " + message.getentityID() + " at " + message.getpositionX() + " " + message.getpositionY() + " " + message.getpositionZ()); - String type = message.getcreatureTemplate(); - newlySpawnedEntity = FoliageUtils.spawnBasicFoliage(type,message.getfoliageSeed()); - ClientEntityUtils.initiallyPositionEntity( - newlySpawnedEntity, - new Vector3d(message.getpositionX(),message.getpositionY(),message.getpositionZ()), - new Quaterniond(message.getrotationX(),message.getrotationY(),message.getrotationZ(),message.getrotationW()) - ); - Globals.clientSceneWrapper.mapIdToId(newlySpawnedEntity.getId(), message.getentityID()); - } break; - case SPAWNOBJECT: { - LoggerInterface.loggerNetworking.DEBUG("[CLIENT] Spawn object " + message.getentityID() + " at " + message.getpositionX() + " " + message.getpositionY() + " " + message.getpositionZ()); - //spawn item - String objectType = message.getcreatureTemplate(); - newlySpawnedEntity = ObjectUtils.clientSpawnBasicObject(objectType); - //position - ClientEntityUtils.initiallyPositionEntity( - newlySpawnedEntity, - new Vector3d(message.getpositionX(),message.getpositionY(),message.getpositionZ()), - new Quaterniond(message.getrotationX(),message.getrotationY(),message.getrotationZ(),message.getrotationW()) - ); - Globals.clientSceneWrapper.mapIdToId(newlySpawnedEntity.getId(), message.getentityID()); - } break; - - // // @@ -247,7 +175,7 @@ public class EntityProtocol implements ClientProtocolTemplate { LoggerInterface.loggerNetworking.DEBUG("Set player entity id for entity: " + target.getId() + " to player: " + message.getpropertyValue()); CreatureUtils.setControllerPlayerId(target, message.getpropertyValue()); String creatureTypeRaw = CreatureUtils.getType(target); - CreatureData creatureType = Globals.gameConfigCurrent.getCreatureTypeLoader().getCreature(creatureTypeRaw); + CreatureData creatureType = Globals.gameConfigCurrent.getCreatureTypeLoader().getType(creatureTypeRaw); ViewModelData viewModelData = creatureType.getViewModelData(); if(Globals.clientPlayer != null && message.getpropertyValue() == Globals.clientPlayer.getId()){ LoggerInterface.loggerNetworking.DEBUG("Set this player's entity id!"); @@ -268,4 +196,100 @@ public class EntityProtocol implements ClientProtocolTemplate { } } + /** + * Spawns a creature + * @param message The message + * @return The item + */ + static Entity spawnCreature(EntityMessage message){ + LoggerInterface.loggerNetworking.DEBUG("[CLIENT] Spawn Creature " + message.getentityID() + " at " + message.getpositionX() + " " + message.getpositionY() + " " + message.getpositionZ()); + CreatureTemplate template = Utilities.deserialize(message.getcreatureTemplate(), CreatureTemplate.class); + Entity newlySpawnedEntity = CreatureUtils.clientSpawnBasicCreature(template.getCreatureType(),template); + ClientEntityUtils.initiallyPositionEntity( + newlySpawnedEntity, + new Vector3d(message.getpositionX(),message.getpositionY(),message.getpositionZ()), + new Quaterniond(message.getrotationX(),message.getrotationY(),message.getrotationZ(),message.getrotationW()) + ); + Globals.clientSceneWrapper.mapIdToId(newlySpawnedEntity.getId(), message.getentityID()); + //if the creature template includes an equip section, spawn all the equipped items + if(template != null && template.getCreatureEquipData() != null && template.getCreatureEquipData().getSlots() != null){ + for(String equipSlotId : template.getCreatureEquipData().getSlots()){ + + //add the item to the creature's inventory + EquippedItem itemDefinition = template.getCreatureEquipData().getSlotItem(equipSlotId); + Entity itemInInventory = InventoryUtils.clientConstructInInventoryItem(newlySpawnedEntity,itemDefinition.getItemType()); + + //equip the item to the slot defined in the template + ClientEquipState clientEquipState = ClientEquipState.getEquipState(newlySpawnedEntity); + clientEquipState.attemptEquip(itemInInventory, clientEquipState.getEquipPoint(equipSlotId)); + + //map the constructed item to its server id + Globals.clientSceneWrapper.mapIdToId(itemInInventory.getId(), itemDefinition.getEntityId()); + } + } + //apply state synchronization if present + if(template != null && template.getStateCollection() != null && template.getStateCollection().getValues() != null){ + StateCollection.applyStateCollection(newlySpawnedEntity, template.getStateCollection()); + } + return newlySpawnedEntity; + } + + /** + * Spawns an item + * @param message The network message + * @return The item + */ + static Entity spawnItem(EntityMessage message){ + LoggerInterface.loggerNetworking.DEBUG("[CLIENT] Spawn Item " + message.getentityID() + " at " + message.getpositionX() + " " + message.getpositionY() + " " + message.getpositionZ()); + //spawn item + String itemType = message.getcreatureTemplate(); + Entity newlySpawnedEntity = ItemUtils.clientSpawnBasicItem(itemType); + //position + ClientEntityUtils.initiallyPositionEntity( + newlySpawnedEntity, + new Vector3d(message.getpositionX(),message.getpositionY(),message.getpositionZ()), + new Quaterniond(message.getrotationX(),message.getrotationY(),message.getrotationZ(),message.getrotationW()) + ); + Globals.clientSceneWrapper.mapIdToId(newlySpawnedEntity.getId(), message.getentityID()); + return newlySpawnedEntity; + } + + /** + * Spawns a foliage + * @param message The network message + * @return The foliage + */ + static Entity spawnFoliage(EntityMessage message){ + LoggerInterface.loggerNetworking.DEBUG("[CLIENT] Spawn foliage " + message.getentityID() + " at " + message.getpositionX() + " " + message.getpositionY() + " " + message.getpositionZ()); + String type = message.getentitySubtype(); + Entity newlySpawnedEntity = FoliageUtils.spawnBasicFoliage(type,Long.parseLong(message.getcreatureTemplate())); + ClientEntityUtils.initiallyPositionEntity( + newlySpawnedEntity, + new Vector3d(message.getpositionX(),message.getpositionY(),message.getpositionZ()), + new Quaterniond(message.getrotationX(),message.getrotationY(),message.getrotationZ(),message.getrotationW()) + ); + Globals.clientSceneWrapper.mapIdToId(newlySpawnedEntity.getId(), message.getentityID()); + return newlySpawnedEntity; + } + + /** + * Spawns a common entity + * @param message The message + * @return The entity + */ + static Entity spawnCommon(EntityMessage message){ + LoggerInterface.loggerNetworking.DEBUG("[CLIENT] Spawn object " + message.getentityID() + " at " + message.getpositionX() + " " + message.getpositionY() + " " + message.getpositionZ()); + //spawn item + String objectType = message.getcreatureTemplate(); + Entity newlySpawnedEntity = CommonEntityUtils.clientSpawnBasicObject(objectType); + //position + ClientEntityUtils.initiallyPositionEntity( + newlySpawnedEntity, + new Vector3d(message.getpositionX(),message.getpositionY(),message.getpositionZ()), + new Quaterniond(message.getrotationX(),message.getrotationY(),message.getrotationZ(),message.getrotationW()) + ); + Globals.clientSceneWrapper.mapIdToId(newlySpawnedEntity.getId(), message.getentityID()); + return newlySpawnedEntity; + } + } diff --git a/src/main/java/electrosphere/net/parser/net/message/EntityMessage.java b/src/main/java/electrosphere/net/parser/net/message/EntityMessage.java index fa1b6b91..0fda9679 100644 --- a/src/main/java/electrosphere/net/parser/net/message/EntityMessage.java +++ b/src/main/java/electrosphere/net/parser/net/message/EntityMessage.java @@ -9,9 +9,6 @@ public class EntityMessage extends NetworkMessage { public enum EntityMessageType { CREATE, - SPAWNCREATURE, - SPAWNITEM, - SPAWNOBJECT, MOVEUPDATE, ATTACKUPDATE, STARTATTACK, @@ -19,7 +16,6 @@ public class EntityMessage extends NetworkMessage { DESTROY, SETPROPERTY, ATTACHENTITYTOENTITY, - SPAWNFOLIAGESEED, UPDATEENTITYVIEWDIR, SYNCPHYSICS, } @@ -54,18 +50,11 @@ public class EntityMessage extends NetworkMessage { int treeState; int propertyType; int propertyValue; - int treeType; - int treeStatus; long time; String bone; int targetID; int bTreeID; - int propertyID; int propertyValueInt; - float propertyValueFloat; - double propertyValueDouble; - String propertyValueString; - long foliageSeed; EntityMessage(EntityMessageType messageType){ this.type = MessageType.ENTITY_MESSAGE; @@ -308,22 +297,6 @@ public class EntityMessage extends NetworkMessage { this.propertyValue = propertyValue; } - public int gettreeType() { - return treeType; - } - - public void settreeType(int treeType) { - this.treeType = treeType; - } - - public int gettreeStatus() { - return treeStatus; - } - - public void settreeStatus(int treeStatus) { - this.treeStatus = treeStatus; - } - public long gettime() { return time; } @@ -356,14 +329,6 @@ public class EntityMessage extends NetworkMessage { this.bTreeID = bTreeID; } - public int getpropertyID() { - return propertyID; - } - - public void setpropertyID(int propertyID) { - this.propertyID = propertyID; - } - public int getpropertyValueInt() { return propertyValueInt; } @@ -372,38 +337,6 @@ public class EntityMessage extends NetworkMessage { this.propertyValueInt = propertyValueInt; } - public float getpropertyValueFloat() { - return propertyValueFloat; - } - - public void setpropertyValueFloat(float propertyValueFloat) { - this.propertyValueFloat = propertyValueFloat; - } - - public double getpropertyValueDouble() { - return propertyValueDouble; - } - - public void setpropertyValueDouble(double propertyValueDouble) { - this.propertyValueDouble = propertyValueDouble; - } - - public String getpropertyValueString() { - return propertyValueString; - } - - public void setpropertyValueString(String propertyValueString) { - this.propertyValueString = propertyValueString; - } - - public long getfoliageSeed() { - return foliageSeed; - } - - public void setfoliageSeed(long foliageSeed) { - this.foliageSeed = foliageSeed; - } - static void stripPacketHeader(CircularByteBuffer byteBuffer){ byteBuffer.read(2); } @@ -412,12 +345,6 @@ public class EntityMessage extends NetworkMessage { switch(secondByte){ case TypeBytes.ENTITY_MESSAGE_TYPE_CREATE: return EntityMessage.canParseCreateMessage(byteBuffer); - case TypeBytes.ENTITY_MESSAGE_TYPE_SPAWNCREATURE: - return EntityMessage.canParseSpawnCreatureMessage(byteBuffer); - case TypeBytes.ENTITY_MESSAGE_TYPE_SPAWNITEM: - return EntityMessage.canParseSpawnItemMessage(byteBuffer); - case TypeBytes.ENTITY_MESSAGE_TYPE_SPAWNOBJECT: - return EntityMessage.canParseSpawnObjectMessage(byteBuffer); case TypeBytes.ENTITY_MESSAGE_TYPE_MOVEUPDATE: if(byteBuffer.getRemaining() >= TypeBytes.ENTITY_MESSAGE_TYPE_MOVEUPDATE_SIZE){ return true; @@ -456,8 +383,6 @@ public class EntityMessage extends NetworkMessage { } case TypeBytes.ENTITY_MESSAGE_TYPE_ATTACHENTITYTOENTITY: return EntityMessage.canParseattachEntityToEntityMessage(byteBuffer); - case TypeBytes.ENTITY_MESSAGE_TYPE_SPAWNFOLIAGESEED: - return EntityMessage.canParseSpawnFoliageSeedMessage(byteBuffer); case TypeBytes.ENTITY_MESSAGE_TYPE_UPDATEENTITYVIEWDIR: if(byteBuffer.getRemaining() >= TypeBytes.ENTITY_MESSAGE_TYPE_UPDATEENTITYVIEWDIR_SIZE){ return true; @@ -496,13 +421,38 @@ public class EntityMessage extends NetworkMessage { if(currentStreamLength < 14 + entitySubtypeSize){ return false; } - if(currentStreamLength < 22 + entitySubtypeSize){ + int creatureTemplateSize = 0; + if(currentStreamLength < 18){ + return false; + } else { + temporaryByteQueue.add(byteBuffer.peek(14 + entitySubtypeSize + 0)); + temporaryByteQueue.add(byteBuffer.peek(14 + entitySubtypeSize + 1)); + temporaryByteQueue.add(byteBuffer.peek(14 + entitySubtypeSize + 2)); + temporaryByteQueue.add(byteBuffer.peek(14 + entitySubtypeSize + 3)); + creatureTemplateSize = ByteStreamUtils.popIntFromByteQueue(temporaryByteQueue); + } + if(currentStreamLength < 18 + entitySubtypeSize + creatureTemplateSize){ return false; } - if(currentStreamLength < 30 + entitySubtypeSize){ + if(currentStreamLength < 26 + entitySubtypeSize + creatureTemplateSize){ return false; } - if(currentStreamLength < 38 + entitySubtypeSize){ + if(currentStreamLength < 34 + entitySubtypeSize + creatureTemplateSize){ + return false; + } + if(currentStreamLength < 42 + entitySubtypeSize + creatureTemplateSize){ + return false; + } + if(currentStreamLength < 50 + entitySubtypeSize + creatureTemplateSize){ + return false; + } + if(currentStreamLength < 58 + entitySubtypeSize + creatureTemplateSize){ + return false; + } + if(currentStreamLength < 66 + entitySubtypeSize + creatureTemplateSize){ + return false; + } + if(currentStreamLength < 74 + entitySubtypeSize + creatureTemplateSize){ return false; } return true; @@ -514,231 +464,22 @@ public class EntityMessage extends NetworkMessage { rVal.setentityID(ByteStreamUtils.popIntFromByteQueue(byteBuffer)); rVal.setentityCategory(ByteStreamUtils.popIntFromByteQueue(byteBuffer)); rVal.setentitySubtype(ByteStreamUtils.popStringFromByteQueue(byteBuffer)); + rVal.setcreatureTemplate(ByteStreamUtils.popStringFromByteQueue(byteBuffer)); rVal.setpositionX(ByteStreamUtils.popDoubleFromByteQueue(byteBuffer)); rVal.setpositionY(ByteStreamUtils.popDoubleFromByteQueue(byteBuffer)); rVal.setpositionZ(ByteStreamUtils.popDoubleFromByteQueue(byteBuffer)); + rVal.setrotationX(ByteStreamUtils.popDoubleFromByteQueue(byteBuffer)); + rVal.setrotationY(ByteStreamUtils.popDoubleFromByteQueue(byteBuffer)); + rVal.setrotationZ(ByteStreamUtils.popDoubleFromByteQueue(byteBuffer)); + rVal.setrotationW(ByteStreamUtils.popDoubleFromByteQueue(byteBuffer)); return rVal; } - public static EntityMessage constructCreateMessage(int entityID,int entityCategory,String entitySubtype,double positionX,double positionY,double positionZ){ + public static EntityMessage constructCreateMessage(int entityID,int entityCategory,String entitySubtype,String creatureTemplate,double positionX,double positionY,double positionZ,double rotationX,double rotationY,double rotationZ,double rotationW){ EntityMessage rVal = new EntityMessage(EntityMessageType.CREATE); rVal.setentityID(entityID); rVal.setentityCategory(entityCategory); rVal.setentitySubtype(entitySubtype); - rVal.setpositionX(positionX); - rVal.setpositionY(positionY); - rVal.setpositionZ(positionZ); - rVal.serialize(); - return rVal; - } - - public static boolean canParseSpawnCreatureMessage(CircularByteBuffer byteBuffer){ - int currentStreamLength = byteBuffer.getRemaining(); - List temporaryByteQueue = new LinkedList(); - if(currentStreamLength < 6){ - return false; - } - int creatureTemplateSize = 0; - if(currentStreamLength < 10){ - return false; - } else { - temporaryByteQueue.add(byteBuffer.peek(6 + 0)); - temporaryByteQueue.add(byteBuffer.peek(6 + 1)); - temporaryByteQueue.add(byteBuffer.peek(6 + 2)); - temporaryByteQueue.add(byteBuffer.peek(6 + 3)); - creatureTemplateSize = ByteStreamUtils.popIntFromByteQueue(temporaryByteQueue); - } - if(currentStreamLength < 10 + creatureTemplateSize){ - return false; - } - if(currentStreamLength < 18 + creatureTemplateSize){ - return false; - } - if(currentStreamLength < 26 + creatureTemplateSize){ - return false; - } - if(currentStreamLength < 34 + creatureTemplateSize){ - return false; - } - if(currentStreamLength < 42 + creatureTemplateSize){ - return false; - } - if(currentStreamLength < 50 + creatureTemplateSize){ - return false; - } - if(currentStreamLength < 58 + creatureTemplateSize){ - return false; - } - if(currentStreamLength < 66 + creatureTemplateSize){ - return false; - } - return true; - } - - public static EntityMessage parseSpawnCreatureMessage(CircularByteBuffer byteBuffer){ - EntityMessage rVal = new EntityMessage(EntityMessageType.SPAWNCREATURE); - stripPacketHeader(byteBuffer); - rVal.setentityID(ByteStreamUtils.popIntFromByteQueue(byteBuffer)); - rVal.setcreatureTemplate(ByteStreamUtils.popStringFromByteQueue(byteBuffer)); - rVal.setpositionX(ByteStreamUtils.popDoubleFromByteQueue(byteBuffer)); - rVal.setpositionY(ByteStreamUtils.popDoubleFromByteQueue(byteBuffer)); - rVal.setpositionZ(ByteStreamUtils.popDoubleFromByteQueue(byteBuffer)); - rVal.setrotationX(ByteStreamUtils.popDoubleFromByteQueue(byteBuffer)); - rVal.setrotationY(ByteStreamUtils.popDoubleFromByteQueue(byteBuffer)); - rVal.setrotationZ(ByteStreamUtils.popDoubleFromByteQueue(byteBuffer)); - rVal.setrotationW(ByteStreamUtils.popDoubleFromByteQueue(byteBuffer)); - return rVal; - } - - public static EntityMessage constructSpawnCreatureMessage(int entityID,String creatureTemplate,double positionX,double positionY,double positionZ,double rotationX,double rotationY,double rotationZ,double rotationW){ - EntityMessage rVal = new EntityMessage(EntityMessageType.SPAWNCREATURE); - rVal.setentityID(entityID); - rVal.setcreatureTemplate(creatureTemplate); - rVal.setpositionX(positionX); - rVal.setpositionY(positionY); - rVal.setpositionZ(positionZ); - rVal.setrotationX(rotationX); - rVal.setrotationY(rotationY); - rVal.setrotationZ(rotationZ); - rVal.setrotationW(rotationW); - rVal.serialize(); - return rVal; - } - - public static boolean canParseSpawnItemMessage(CircularByteBuffer byteBuffer){ - int currentStreamLength = byteBuffer.getRemaining(); - List temporaryByteQueue = new LinkedList(); - if(currentStreamLength < 6){ - return false; - } - int creatureTemplateSize = 0; - if(currentStreamLength < 10){ - return false; - } else { - temporaryByteQueue.add(byteBuffer.peek(6 + 0)); - temporaryByteQueue.add(byteBuffer.peek(6 + 1)); - temporaryByteQueue.add(byteBuffer.peek(6 + 2)); - temporaryByteQueue.add(byteBuffer.peek(6 + 3)); - creatureTemplateSize = ByteStreamUtils.popIntFromByteQueue(temporaryByteQueue); - } - if(currentStreamLength < 10 + creatureTemplateSize){ - return false; - } - if(currentStreamLength < 18 + creatureTemplateSize){ - return false; - } - if(currentStreamLength < 26 + creatureTemplateSize){ - return false; - } - if(currentStreamLength < 34 + creatureTemplateSize){ - return false; - } - if(currentStreamLength < 42 + creatureTemplateSize){ - return false; - } - if(currentStreamLength < 50 + creatureTemplateSize){ - return false; - } - if(currentStreamLength < 58 + creatureTemplateSize){ - return false; - } - if(currentStreamLength < 66 + creatureTemplateSize){ - return false; - } - return true; - } - - public static EntityMessage parseSpawnItemMessage(CircularByteBuffer byteBuffer){ - EntityMessage rVal = new EntityMessage(EntityMessageType.SPAWNITEM); - stripPacketHeader(byteBuffer); - rVal.setentityID(ByteStreamUtils.popIntFromByteQueue(byteBuffer)); - rVal.setcreatureTemplate(ByteStreamUtils.popStringFromByteQueue(byteBuffer)); - rVal.setpositionX(ByteStreamUtils.popDoubleFromByteQueue(byteBuffer)); - rVal.setpositionY(ByteStreamUtils.popDoubleFromByteQueue(byteBuffer)); - rVal.setpositionZ(ByteStreamUtils.popDoubleFromByteQueue(byteBuffer)); - rVal.setrotationX(ByteStreamUtils.popDoubleFromByteQueue(byteBuffer)); - rVal.setrotationY(ByteStreamUtils.popDoubleFromByteQueue(byteBuffer)); - rVal.setrotationZ(ByteStreamUtils.popDoubleFromByteQueue(byteBuffer)); - rVal.setrotationW(ByteStreamUtils.popDoubleFromByteQueue(byteBuffer)); - return rVal; - } - - public static EntityMessage constructSpawnItemMessage(int entityID,String creatureTemplate,double positionX,double positionY,double positionZ,double rotationX,double rotationY,double rotationZ,double rotationW){ - EntityMessage rVal = new EntityMessage(EntityMessageType.SPAWNITEM); - rVal.setentityID(entityID); - rVal.setcreatureTemplate(creatureTemplate); - rVal.setpositionX(positionX); - rVal.setpositionY(positionY); - rVal.setpositionZ(positionZ); - rVal.setrotationX(rotationX); - rVal.setrotationY(rotationY); - rVal.setrotationZ(rotationZ); - rVal.setrotationW(rotationW); - rVal.serialize(); - return rVal; - } - - public static boolean canParseSpawnObjectMessage(CircularByteBuffer byteBuffer){ - int currentStreamLength = byteBuffer.getRemaining(); - List temporaryByteQueue = new LinkedList(); - if(currentStreamLength < 6){ - return false; - } - int creatureTemplateSize = 0; - if(currentStreamLength < 10){ - return false; - } else { - temporaryByteQueue.add(byteBuffer.peek(6 + 0)); - temporaryByteQueue.add(byteBuffer.peek(6 + 1)); - temporaryByteQueue.add(byteBuffer.peek(6 + 2)); - temporaryByteQueue.add(byteBuffer.peek(6 + 3)); - creatureTemplateSize = ByteStreamUtils.popIntFromByteQueue(temporaryByteQueue); - } - if(currentStreamLength < 10 + creatureTemplateSize){ - return false; - } - if(currentStreamLength < 18 + creatureTemplateSize){ - return false; - } - if(currentStreamLength < 26 + creatureTemplateSize){ - return false; - } - if(currentStreamLength < 34 + creatureTemplateSize){ - return false; - } - if(currentStreamLength < 42 + creatureTemplateSize){ - return false; - } - if(currentStreamLength < 50 + creatureTemplateSize){ - return false; - } - if(currentStreamLength < 58 + creatureTemplateSize){ - return false; - } - if(currentStreamLength < 66 + creatureTemplateSize){ - return false; - } - return true; - } - - public static EntityMessage parseSpawnObjectMessage(CircularByteBuffer byteBuffer){ - EntityMessage rVal = new EntityMessage(EntityMessageType.SPAWNOBJECT); - stripPacketHeader(byteBuffer); - rVal.setentityID(ByteStreamUtils.popIntFromByteQueue(byteBuffer)); - rVal.setcreatureTemplate(ByteStreamUtils.popStringFromByteQueue(byteBuffer)); - rVal.setpositionX(ByteStreamUtils.popDoubleFromByteQueue(byteBuffer)); - rVal.setpositionY(ByteStreamUtils.popDoubleFromByteQueue(byteBuffer)); - rVal.setpositionZ(ByteStreamUtils.popDoubleFromByteQueue(byteBuffer)); - rVal.setrotationX(ByteStreamUtils.popDoubleFromByteQueue(byteBuffer)); - rVal.setrotationY(ByteStreamUtils.popDoubleFromByteQueue(byteBuffer)); - rVal.setrotationZ(ByteStreamUtils.popDoubleFromByteQueue(byteBuffer)); - rVal.setrotationW(ByteStreamUtils.popDoubleFromByteQueue(byteBuffer)); - return rVal; - } - - public static EntityMessage constructSpawnObjectMessage(int entityID,String creatureTemplate,double positionX,double positionY,double positionZ,double rotationX,double rotationY,double rotationZ,double rotationW){ - EntityMessage rVal = new EntityMessage(EntityMessageType.SPAWNOBJECT); - rVal.setentityID(entityID); rVal.setcreatureTemplate(creatureTemplate); rVal.setpositionX(positionX); rVal.setpositionY(positionY); @@ -924,84 +665,6 @@ public class EntityMessage extends NetworkMessage { return rVal; } - public static boolean canParseSpawnFoliageSeedMessage(CircularByteBuffer byteBuffer){ - int currentStreamLength = byteBuffer.getRemaining(); - List temporaryByteQueue = new LinkedList(); - if(currentStreamLength < 6){ - return false; - } - int creatureTemplateSize = 0; - if(currentStreamLength < 10){ - return false; - } else { - temporaryByteQueue.add(byteBuffer.peek(6 + 0)); - temporaryByteQueue.add(byteBuffer.peek(6 + 1)); - temporaryByteQueue.add(byteBuffer.peek(6 + 2)); - temporaryByteQueue.add(byteBuffer.peek(6 + 3)); - creatureTemplateSize = ByteStreamUtils.popIntFromByteQueue(temporaryByteQueue); - } - if(currentStreamLength < 10 + creatureTemplateSize){ - return false; - } - if(currentStreamLength < 18 + creatureTemplateSize){ - return false; - } - if(currentStreamLength < 26 + creatureTemplateSize){ - return false; - } - if(currentStreamLength < 34 + creatureTemplateSize){ - return false; - } - if(currentStreamLength < 42 + creatureTemplateSize){ - return false; - } - if(currentStreamLength < 50 + creatureTemplateSize){ - return false; - } - if(currentStreamLength < 58 + creatureTemplateSize){ - return false; - } - if(currentStreamLength < 66 + creatureTemplateSize){ - return false; - } - if(currentStreamLength < 74 + creatureTemplateSize){ - return false; - } - return true; - } - - public static EntityMessage parseSpawnFoliageSeedMessage(CircularByteBuffer byteBuffer){ - EntityMessage rVal = new EntityMessage(EntityMessageType.SPAWNFOLIAGESEED); - stripPacketHeader(byteBuffer); - rVal.setentityID(ByteStreamUtils.popIntFromByteQueue(byteBuffer)); - rVal.setcreatureTemplate(ByteStreamUtils.popStringFromByteQueue(byteBuffer)); - rVal.setfoliageSeed(ByteStreamUtils.popLongFromByteQueue(byteBuffer)); - rVal.setpositionX(ByteStreamUtils.popDoubleFromByteQueue(byteBuffer)); - rVal.setpositionY(ByteStreamUtils.popDoubleFromByteQueue(byteBuffer)); - rVal.setpositionZ(ByteStreamUtils.popDoubleFromByteQueue(byteBuffer)); - rVal.setrotationX(ByteStreamUtils.popDoubleFromByteQueue(byteBuffer)); - rVal.setrotationY(ByteStreamUtils.popDoubleFromByteQueue(byteBuffer)); - rVal.setrotationZ(ByteStreamUtils.popDoubleFromByteQueue(byteBuffer)); - rVal.setrotationW(ByteStreamUtils.popDoubleFromByteQueue(byteBuffer)); - return rVal; - } - - public static EntityMessage constructSpawnFoliageSeedMessage(int entityID,String creatureTemplate,long foliageSeed,double positionX,double positionY,double positionZ,double rotationX,double rotationY,double rotationZ,double rotationW){ - EntityMessage rVal = new EntityMessage(EntityMessageType.SPAWNFOLIAGESEED); - rVal.setentityID(entityID); - rVal.setcreatureTemplate(creatureTemplate); - rVal.setfoliageSeed(foliageSeed); - rVal.setpositionX(positionX); - rVal.setpositionY(positionY); - rVal.setpositionZ(positionZ); - rVal.setrotationX(rotationX); - rVal.setrotationY(rotationY); - rVal.setrotationZ(rotationZ); - rVal.setrotationW(rotationW); - rVal.serialize(); - return rVal; - } - public static EntityMessage parseupdateEntityViewDirMessage(CircularByteBuffer byteBuffer){ EntityMessage rVal = new EntityMessage(EntityMessageType.UPDATEENTITYVIEWDIR); stripPacketHeader(byteBuffer); @@ -1084,7 +747,7 @@ public class EntityMessage extends NetworkMessage { byte[] stringBytes; switch(this.messageType){ case CREATE: - rawBytes = new byte[2+4+4+4+entitySubtype.length()+8+8+8]; + rawBytes = new byte[2+4+4+4+entitySubtype.length()+4+creatureTemplate.length()+8+8+8+8+8+8+8]; //message header rawBytes[0] = TypeBytes.MESSAGE_TYPE_ENTITY; //entity messaage header @@ -1105,158 +768,41 @@ public class EntityMessage extends NetworkMessage { for(int i = 0; i < entitySubtype.length(); i++){ rawBytes[14+i] = stringBytes[i]; } - intValues = ByteStreamUtils.serializeDoubleToBytes(positionX); - for(int i = 0; i < 8; i++){ + intValues = ByteStreamUtils.serializeIntToBytes(creatureTemplate.length()); + for(int i = 0; i < 4; i++){ rawBytes[14+entitySubtype.length()+i] = intValues[i]; } - intValues = ByteStreamUtils.serializeDoubleToBytes(positionY); - for(int i = 0; i < 8; i++){ - rawBytes[22+entitySubtype.length()+i] = intValues[i]; - } - intValues = ByteStreamUtils.serializeDoubleToBytes(positionZ); - for(int i = 0; i < 8; i++){ - rawBytes[30+entitySubtype.length()+i] = intValues[i]; - } - break; - case SPAWNCREATURE: - rawBytes = new byte[2+4+4+creatureTemplate.length()+8+8+8+8+8+8+8]; - //message header - rawBytes[0] = TypeBytes.MESSAGE_TYPE_ENTITY; - //entity messaage header - rawBytes[1] = TypeBytes.ENTITY_MESSAGE_TYPE_SPAWNCREATURE; - intValues = ByteStreamUtils.serializeIntToBytes(entityID); - for(int i = 0; i < 4; i++){ - rawBytes[2+i] = intValues[i]; - } - intValues = ByteStreamUtils.serializeIntToBytes(creatureTemplate.length()); - for(int i = 0; i < 4; i++){ - rawBytes[6+i] = intValues[i]; - } stringBytes = creatureTemplate.getBytes(); for(int i = 0; i < creatureTemplate.length(); i++){ - rawBytes[10+i] = stringBytes[i]; + rawBytes[18+entitySubtype.length()+i] = stringBytes[i]; } intValues = ByteStreamUtils.serializeDoubleToBytes(positionX); for(int i = 0; i < 8; i++){ - rawBytes[10+creatureTemplate.length()+i] = intValues[i]; + rawBytes[18+entitySubtype.length()+creatureTemplate.length()+i] = intValues[i]; } intValues = ByteStreamUtils.serializeDoubleToBytes(positionY); for(int i = 0; i < 8; i++){ - rawBytes[18+creatureTemplate.length()+i] = intValues[i]; + rawBytes[26+entitySubtype.length()+creatureTemplate.length()+i] = intValues[i]; } intValues = ByteStreamUtils.serializeDoubleToBytes(positionZ); for(int i = 0; i < 8; i++){ - rawBytes[26+creatureTemplate.length()+i] = intValues[i]; + rawBytes[34+entitySubtype.length()+creatureTemplate.length()+i] = intValues[i]; } intValues = ByteStreamUtils.serializeDoubleToBytes(rotationX); for(int i = 0; i < 8; i++){ - rawBytes[34+creatureTemplate.length()+i] = intValues[i]; + rawBytes[42+entitySubtype.length()+creatureTemplate.length()+i] = intValues[i]; } intValues = ByteStreamUtils.serializeDoubleToBytes(rotationY); for(int i = 0; i < 8; i++){ - rawBytes[42+creatureTemplate.length()+i] = intValues[i]; + rawBytes[50+entitySubtype.length()+creatureTemplate.length()+i] = intValues[i]; } intValues = ByteStreamUtils.serializeDoubleToBytes(rotationZ); for(int i = 0; i < 8; i++){ - rawBytes[50+creatureTemplate.length()+i] = intValues[i]; + rawBytes[58+entitySubtype.length()+creatureTemplate.length()+i] = intValues[i]; } intValues = ByteStreamUtils.serializeDoubleToBytes(rotationW); for(int i = 0; i < 8; i++){ - rawBytes[58+creatureTemplate.length()+i] = intValues[i]; - } - break; - case SPAWNITEM: - rawBytes = new byte[2+4+4+creatureTemplate.length()+8+8+8+8+8+8+8]; - //message header - rawBytes[0] = TypeBytes.MESSAGE_TYPE_ENTITY; - //entity messaage header - rawBytes[1] = TypeBytes.ENTITY_MESSAGE_TYPE_SPAWNITEM; - intValues = ByteStreamUtils.serializeIntToBytes(entityID); - for(int i = 0; i < 4; i++){ - rawBytes[2+i] = intValues[i]; - } - intValues = ByteStreamUtils.serializeIntToBytes(creatureTemplate.length()); - for(int i = 0; i < 4; i++){ - rawBytes[6+i] = intValues[i]; - } - stringBytes = creatureTemplate.getBytes(); - for(int i = 0; i < creatureTemplate.length(); i++){ - rawBytes[10+i] = stringBytes[i]; - } - intValues = ByteStreamUtils.serializeDoubleToBytes(positionX); - for(int i = 0; i < 8; i++){ - rawBytes[10+creatureTemplate.length()+i] = intValues[i]; - } - intValues = ByteStreamUtils.serializeDoubleToBytes(positionY); - for(int i = 0; i < 8; i++){ - rawBytes[18+creatureTemplate.length()+i] = intValues[i]; - } - intValues = ByteStreamUtils.serializeDoubleToBytes(positionZ); - for(int i = 0; i < 8; i++){ - rawBytes[26+creatureTemplate.length()+i] = intValues[i]; - } - intValues = ByteStreamUtils.serializeDoubleToBytes(rotationX); - for(int i = 0; i < 8; i++){ - rawBytes[34+creatureTemplate.length()+i] = intValues[i]; - } - intValues = ByteStreamUtils.serializeDoubleToBytes(rotationY); - for(int i = 0; i < 8; i++){ - rawBytes[42+creatureTemplate.length()+i] = intValues[i]; - } - intValues = ByteStreamUtils.serializeDoubleToBytes(rotationZ); - for(int i = 0; i < 8; i++){ - rawBytes[50+creatureTemplate.length()+i] = intValues[i]; - } - intValues = ByteStreamUtils.serializeDoubleToBytes(rotationW); - for(int i = 0; i < 8; i++){ - rawBytes[58+creatureTemplate.length()+i] = intValues[i]; - } - break; - case SPAWNOBJECT: - rawBytes = new byte[2+4+4+creatureTemplate.length()+8+8+8+8+8+8+8]; - //message header - rawBytes[0] = TypeBytes.MESSAGE_TYPE_ENTITY; - //entity messaage header - rawBytes[1] = TypeBytes.ENTITY_MESSAGE_TYPE_SPAWNOBJECT; - intValues = ByteStreamUtils.serializeIntToBytes(entityID); - for(int i = 0; i < 4; i++){ - rawBytes[2+i] = intValues[i]; - } - intValues = ByteStreamUtils.serializeIntToBytes(creatureTemplate.length()); - for(int i = 0; i < 4; i++){ - rawBytes[6+i] = intValues[i]; - } - stringBytes = creatureTemplate.getBytes(); - for(int i = 0; i < creatureTemplate.length(); i++){ - rawBytes[10+i] = stringBytes[i]; - } - intValues = ByteStreamUtils.serializeDoubleToBytes(positionX); - for(int i = 0; i < 8; i++){ - rawBytes[10+creatureTemplate.length()+i] = intValues[i]; - } - intValues = ByteStreamUtils.serializeDoubleToBytes(positionY); - for(int i = 0; i < 8; i++){ - rawBytes[18+creatureTemplate.length()+i] = intValues[i]; - } - intValues = ByteStreamUtils.serializeDoubleToBytes(positionZ); - for(int i = 0; i < 8; i++){ - rawBytes[26+creatureTemplate.length()+i] = intValues[i]; - } - intValues = ByteStreamUtils.serializeDoubleToBytes(rotationX); - for(int i = 0; i < 8; i++){ - rawBytes[34+creatureTemplate.length()+i] = intValues[i]; - } - intValues = ByteStreamUtils.serializeDoubleToBytes(rotationY); - for(int i = 0; i < 8; i++){ - rawBytes[42+creatureTemplate.length()+i] = intValues[i]; - } - intValues = ByteStreamUtils.serializeDoubleToBytes(rotationZ); - for(int i = 0; i < 8; i++){ - rawBytes[50+creatureTemplate.length()+i] = intValues[i]; - } - intValues = ByteStreamUtils.serializeDoubleToBytes(rotationW); - for(int i = 0; i < 8; i++){ - rawBytes[58+creatureTemplate.length()+i] = intValues[i]; + rawBytes[66+entitySubtype.length()+creatureTemplate.length()+i] = intValues[i]; } break; case MOVEUPDATE: @@ -1440,57 +986,6 @@ public class EntityMessage extends NetworkMessage { rawBytes[10+bone.length()+i] = intValues[i]; } break; - case SPAWNFOLIAGESEED: - rawBytes = new byte[2+4+4+creatureTemplate.length()+8+8+8+8+8+8+8+8]; - //message header - rawBytes[0] = TypeBytes.MESSAGE_TYPE_ENTITY; - //entity messaage header - rawBytes[1] = TypeBytes.ENTITY_MESSAGE_TYPE_SPAWNFOLIAGESEED; - intValues = ByteStreamUtils.serializeIntToBytes(entityID); - for(int i = 0; i < 4; i++){ - rawBytes[2+i] = intValues[i]; - } - intValues = ByteStreamUtils.serializeIntToBytes(creatureTemplate.length()); - for(int i = 0; i < 4; i++){ - rawBytes[6+i] = intValues[i]; - } - stringBytes = creatureTemplate.getBytes(); - for(int i = 0; i < creatureTemplate.length(); i++){ - rawBytes[10+i] = stringBytes[i]; - } - intValues = ByteStreamUtils.serializeLongToBytes(foliageSeed); - for(int i = 0; i < 8; i++){ - rawBytes[10+creatureTemplate.length()+i] = intValues[i]; - } - intValues = ByteStreamUtils.serializeDoubleToBytes(positionX); - for(int i = 0; i < 8; i++){ - rawBytes[18+creatureTemplate.length()+i] = intValues[i]; - } - intValues = ByteStreamUtils.serializeDoubleToBytes(positionY); - for(int i = 0; i < 8; i++){ - rawBytes[26+creatureTemplate.length()+i] = intValues[i]; - } - intValues = ByteStreamUtils.serializeDoubleToBytes(positionZ); - for(int i = 0; i < 8; i++){ - rawBytes[34+creatureTemplate.length()+i] = intValues[i]; - } - intValues = ByteStreamUtils.serializeDoubleToBytes(rotationX); - for(int i = 0; i < 8; i++){ - rawBytes[42+creatureTemplate.length()+i] = intValues[i]; - } - intValues = ByteStreamUtils.serializeDoubleToBytes(rotationY); - for(int i = 0; i < 8; i++){ - rawBytes[50+creatureTemplate.length()+i] = intValues[i]; - } - intValues = ByteStreamUtils.serializeDoubleToBytes(rotationZ); - for(int i = 0; i < 8; i++){ - rawBytes[58+creatureTemplate.length()+i] = intValues[i]; - } - intValues = ByteStreamUtils.serializeDoubleToBytes(rotationW); - for(int i = 0; i < 8; i++){ - rawBytes[66+creatureTemplate.length()+i] = intValues[i]; - } - break; case UPDATEENTITYVIEWDIR: rawBytes = new byte[2+4+8+4+8+8]; //message header diff --git a/src/main/java/electrosphere/net/parser/net/message/NetworkMessage.java b/src/main/java/electrosphere/net/parser/net/message/NetworkMessage.java index a39f6c26..5350c316 100644 --- a/src/main/java/electrosphere/net/parser/net/message/NetworkMessage.java +++ b/src/main/java/electrosphere/net/parser/net/message/NetworkMessage.java @@ -47,21 +47,6 @@ COMBAT_MESSAGE, rVal = EntityMessage.parseCreateMessage(byteBuffer); } break; - case TypeBytes.ENTITY_MESSAGE_TYPE_SPAWNCREATURE: - if(EntityMessage.canParseMessage(byteBuffer,secondByte)){ - rVal = EntityMessage.parseSpawnCreatureMessage(byteBuffer); - } - break; - case TypeBytes.ENTITY_MESSAGE_TYPE_SPAWNITEM: - if(EntityMessage.canParseMessage(byteBuffer,secondByte)){ - rVal = EntityMessage.parseSpawnItemMessage(byteBuffer); - } - break; - case TypeBytes.ENTITY_MESSAGE_TYPE_SPAWNOBJECT: - if(EntityMessage.canParseMessage(byteBuffer,secondByte)){ - rVal = EntityMessage.parseSpawnObjectMessage(byteBuffer); - } - break; case TypeBytes.ENTITY_MESSAGE_TYPE_MOVEUPDATE: if(EntityMessage.canParseMessage(byteBuffer,secondByte)){ rVal = EntityMessage.parsemoveUpdateMessage(byteBuffer); @@ -97,11 +82,6 @@ COMBAT_MESSAGE, rVal = EntityMessage.parseattachEntityToEntityMessage(byteBuffer); } break; - case TypeBytes.ENTITY_MESSAGE_TYPE_SPAWNFOLIAGESEED: - if(EntityMessage.canParseMessage(byteBuffer,secondByte)){ - rVal = EntityMessage.parseSpawnFoliageSeedMessage(byteBuffer); - } - break; case TypeBytes.ENTITY_MESSAGE_TYPE_UPDATEENTITYVIEWDIR: if(EntityMessage.canParseMessage(byteBuffer,secondByte)){ rVal = EntityMessage.parseupdateEntityViewDirMessage(byteBuffer); diff --git a/src/main/java/electrosphere/net/parser/net/message/TypeBytes.java b/src/main/java/electrosphere/net/parser/net/message/TypeBytes.java index 8112ac86..6b08b092 100644 --- a/src/main/java/electrosphere/net/parser/net/message/TypeBytes.java +++ b/src/main/java/electrosphere/net/parser/net/message/TypeBytes.java @@ -19,19 +19,15 @@ Message categories Entity subcategories */ public static final byte ENTITY_MESSAGE_TYPE_CREATE = 0; - public static final byte ENTITY_MESSAGE_TYPE_SPAWNCREATURE = 1; - public static final byte ENTITY_MESSAGE_TYPE_SPAWNITEM = 2; - public static final byte ENTITY_MESSAGE_TYPE_SPAWNOBJECT = 3; - public static final byte ENTITY_MESSAGE_TYPE_MOVEUPDATE = 4; - public static final byte ENTITY_MESSAGE_TYPE_ATTACKUPDATE = 5; - public static final byte ENTITY_MESSAGE_TYPE_STARTATTACK = 6; - public static final byte ENTITY_MESSAGE_TYPE_KILL = 7; - public static final byte ENTITY_MESSAGE_TYPE_DESTROY = 8; - public static final byte ENTITY_MESSAGE_TYPE_SETPROPERTY = 9; - public static final byte ENTITY_MESSAGE_TYPE_ATTACHENTITYTOENTITY = 10; - public static final byte ENTITY_MESSAGE_TYPE_SPAWNFOLIAGESEED = 11; - public static final byte ENTITY_MESSAGE_TYPE_UPDATEENTITYVIEWDIR = 12; - public static final byte ENTITY_MESSAGE_TYPE_SYNCPHYSICS = 13; + public static final byte ENTITY_MESSAGE_TYPE_MOVEUPDATE = 1; + public static final byte ENTITY_MESSAGE_TYPE_ATTACKUPDATE = 2; + public static final byte ENTITY_MESSAGE_TYPE_STARTATTACK = 3; + public static final byte ENTITY_MESSAGE_TYPE_KILL = 4; + public static final byte ENTITY_MESSAGE_TYPE_DESTROY = 5; + public static final byte ENTITY_MESSAGE_TYPE_SETPROPERTY = 6; + public static final byte ENTITY_MESSAGE_TYPE_ATTACHENTITYTOENTITY = 7; + public static final byte ENTITY_MESSAGE_TYPE_UPDATEENTITYVIEWDIR = 8; + public static final byte ENTITY_MESSAGE_TYPE_SYNCPHYSICS = 9; /* Entity packet sizes */ diff --git a/src/main/java/electrosphere/net/server/protocol/EntityProtocol.java b/src/main/java/electrosphere/net/server/protocol/EntityProtocol.java index 9510e9b0..03be1aa7 100644 --- a/src/main/java/electrosphere/net/server/protocol/EntityProtocol.java +++ b/src/main/java/electrosphere/net/server/protocol/EntityProtocol.java @@ -57,14 +57,10 @@ public class EntityProtocol implements ServerProtocolTemplate { } break; //ignore stack case KILL: - case SPAWNCREATURE: case DESTROY: case CREATE: case ATTACHENTITYTOENTITY: case SETPROPERTY: - case SPAWNFOLIAGESEED: - case SPAWNITEM: - case SPAWNOBJECT: case SYNCPHYSICS: //silently ignore break; diff --git a/src/main/java/electrosphere/renderer/actor/Actor.java b/src/main/java/electrosphere/renderer/actor/Actor.java index 322bf25a..4106bbd3 100644 --- a/src/main/java/electrosphere/renderer/actor/Actor.java +++ b/src/main/java/electrosphere/renderer/actor/Actor.java @@ -2,7 +2,7 @@ package electrosphere.renderer.actor; import electrosphere.engine.Globals; import electrosphere.entity.state.AnimationPriorities; -import electrosphere.game.data.common.TreeDataAnimation; +import electrosphere.game.data.common.treedata.TreeDataAnimation; import electrosphere.game.data.creature.type.bonegroups.BoneGroup; import electrosphere.logger.LoggerInterface; import electrosphere.renderer.OpenGLState; diff --git a/src/main/java/electrosphere/renderer/light/LightManager.java b/src/main/java/electrosphere/renderer/light/LightManager.java index 23c35df5..090fe300 100644 --- a/src/main/java/electrosphere/renderer/light/LightManager.java +++ b/src/main/java/electrosphere/renderer/light/LightManager.java @@ -10,8 +10,8 @@ import org.lwjgl.BufferUtils; import org.lwjgl.opengl.GL30; import org.lwjgl.opengl.GL31; +import electrosphere.client.entity.camera.CameraEntityUtils; import electrosphere.engine.Globals; -import electrosphere.entity.types.camera.CameraEntityUtils; import electrosphere.logger.LoggerInterface; import electrosphere.renderer.OpenGLState; import electrosphere.renderer.RenderingEngine; diff --git a/src/main/java/electrosphere/renderer/model/Mesh.java b/src/main/java/electrosphere/renderer/model/Mesh.java index dab6f8f7..143be93e 100644 --- a/src/main/java/electrosphere/renderer/model/Mesh.java +++ b/src/main/java/electrosphere/renderer/model/Mesh.java @@ -1,7 +1,7 @@ package electrosphere.renderer.model; +import electrosphere.client.entity.camera.CameraEntityUtils; import electrosphere.engine.Globals; -import electrosphere.entity.types.camera.CameraEntityUtils; import electrosphere.renderer.OpenGLState; import electrosphere.renderer.RenderPipelineState; import electrosphere.renderer.RenderingEngine; diff --git a/src/main/java/electrosphere/renderer/pipelines/FirstPersonItemsPipeline.java b/src/main/java/electrosphere/renderer/pipelines/FirstPersonItemsPipeline.java index f899c692..8cf148d8 100644 --- a/src/main/java/electrosphere/renderer/pipelines/FirstPersonItemsPipeline.java +++ b/src/main/java/electrosphere/renderer/pipelines/FirstPersonItemsPipeline.java @@ -7,13 +7,13 @@ import org.joml.Vector3f; import org.joml.Vector4d; import org.lwjgl.opengl.GL40; +import electrosphere.client.entity.camera.CameraEntityUtils; import electrosphere.engine.Globals; import electrosphere.entity.Entity; import electrosphere.entity.EntityUtils; import electrosphere.entity.state.client.firstPerson.FirstPersonTree; import electrosphere.entity.state.equip.ClientEquipState; import electrosphere.entity.types.attach.AttachUtils; -import electrosphere.entity.types.camera.CameraEntityUtils; import electrosphere.renderer.OpenGLState; import electrosphere.renderer.RenderPipelineState; import electrosphere.renderer.actor.Actor; diff --git a/src/main/java/electrosphere/renderer/pipelines/MainContentNoOITPipeline.java b/src/main/java/electrosphere/renderer/pipelines/MainContentNoOITPipeline.java index c24e2302..f0f4b86a 100644 --- a/src/main/java/electrosphere/renderer/pipelines/MainContentNoOITPipeline.java +++ b/src/main/java/electrosphere/renderer/pipelines/MainContentNoOITPipeline.java @@ -4,12 +4,12 @@ import org.joml.Vector3d; import org.joml.Vector3f; import org.lwjgl.opengl.GL40; +import electrosphere.client.entity.camera.CameraEntityUtils; import electrosphere.engine.Globals; import electrosphere.entity.Entity; import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityTags; import electrosphere.entity.EntityUtils; -import electrosphere.entity.types.camera.CameraEntityUtils; import electrosphere.renderer.OpenGLState; import electrosphere.renderer.RenderPipelineState; import electrosphere.renderer.RenderingEngine; diff --git a/src/main/java/electrosphere/renderer/pipelines/MainContentPipeline.java b/src/main/java/electrosphere/renderer/pipelines/MainContentPipeline.java index b323f350..c85d999f 100644 --- a/src/main/java/electrosphere/renderer/pipelines/MainContentPipeline.java +++ b/src/main/java/electrosphere/renderer/pipelines/MainContentPipeline.java @@ -8,13 +8,13 @@ import org.joml.Vector3d; import org.joml.Vector3f; import org.lwjgl.opengl.GL40; +import electrosphere.client.entity.camera.CameraEntityUtils; import electrosphere.engine.Globals; import electrosphere.entity.Entity; import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityTags; import electrosphere.entity.EntityUtils; import electrosphere.entity.types.attach.AttachUtils; -import electrosphere.entity.types.camera.CameraEntityUtils; import electrosphere.renderer.OpenGLState; import electrosphere.renderer.RenderPipelineState; import electrosphere.renderer.RenderingEngine; diff --git a/src/main/java/electrosphere/renderer/pipelines/NormalsForOutlinePipeline.java b/src/main/java/electrosphere/renderer/pipelines/NormalsForOutlinePipeline.java index ff3f9dfa..f2421f3d 100644 --- a/src/main/java/electrosphere/renderer/pipelines/NormalsForOutlinePipeline.java +++ b/src/main/java/electrosphere/renderer/pipelines/NormalsForOutlinePipeline.java @@ -5,12 +5,12 @@ import org.joml.Vector3d; import org.joml.Vector3f; import org.lwjgl.opengl.GL40; +import electrosphere.client.entity.camera.CameraEntityUtils; import electrosphere.engine.Globals; import electrosphere.entity.Entity; import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityTags; import electrosphere.entity.EntityUtils; -import electrosphere.entity.types.camera.CameraEntityUtils; import electrosphere.renderer.OpenGLState; import electrosphere.renderer.RenderPipelineState; import electrosphere.renderer.RenderingEngine; diff --git a/src/main/java/electrosphere/renderer/pipelines/ShadowMapPipeline.java b/src/main/java/electrosphere/renderer/pipelines/ShadowMapPipeline.java index cc8b6a53..d45c98ec 100644 --- a/src/main/java/electrosphere/renderer/pipelines/ShadowMapPipeline.java +++ b/src/main/java/electrosphere/renderer/pipelines/ShadowMapPipeline.java @@ -6,12 +6,12 @@ import org.joml.Vector3d; import org.joml.Vector3f; import org.lwjgl.opengl.GL40; +import electrosphere.client.entity.camera.CameraEntityUtils; import electrosphere.engine.Globals; import electrosphere.entity.Entity; import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityTags; import electrosphere.entity.EntityUtils; -import electrosphere.entity.types.camera.CameraEntityUtils; import electrosphere.renderer.OpenGLState; import electrosphere.renderer.RenderPipelineState; import electrosphere.renderer.RenderingEngine; diff --git a/src/main/java/electrosphere/renderer/pipelines/VolumeBufferPipeline.java b/src/main/java/electrosphere/renderer/pipelines/VolumeBufferPipeline.java index 97d13da8..65da66c5 100644 --- a/src/main/java/electrosphere/renderer/pipelines/VolumeBufferPipeline.java +++ b/src/main/java/electrosphere/renderer/pipelines/VolumeBufferPipeline.java @@ -5,12 +5,12 @@ import org.joml.Vector3d; import org.joml.Vector3f; import org.lwjgl.opengl.GL40; +import electrosphere.client.entity.camera.CameraEntityUtils; import electrosphere.engine.Globals; import electrosphere.entity.Entity; import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityTags; import electrosphere.entity.EntityUtils; -import electrosphere.entity.types.camera.CameraEntityUtils; import electrosphere.renderer.OpenGLState; import electrosphere.renderer.RenderPipelineState; import electrosphere.renderer.RenderingEngine; diff --git a/src/main/java/electrosphere/renderer/pipelines/debug/DebugBonesPipeline.java b/src/main/java/electrosphere/renderer/pipelines/debug/DebugBonesPipeline.java index 0ea79ff9..1ee7219e 100644 --- a/src/main/java/electrosphere/renderer/pipelines/debug/DebugBonesPipeline.java +++ b/src/main/java/electrosphere/renderer/pipelines/debug/DebugBonesPipeline.java @@ -6,11 +6,11 @@ import org.joml.Vector3d; import org.joml.Vector3f; import org.lwjgl.opengl.GL40; +import electrosphere.client.entity.camera.CameraEntityUtils; import electrosphere.engine.Globals; import electrosphere.engine.assetmanager.AssetDataStrings; import electrosphere.entity.Entity; import electrosphere.entity.EntityUtils; -import electrosphere.entity.types.camera.CameraEntityUtils; import electrosphere.renderer.OpenGLState; import electrosphere.renderer.RenderPipelineState; import electrosphere.renderer.RenderingEngine; diff --git a/src/main/java/electrosphere/renderer/pipelines/debug/DebugContentPipeline.java b/src/main/java/electrosphere/renderer/pipelines/debug/DebugContentPipeline.java index c0ab8724..9e9b182b 100644 --- a/src/main/java/electrosphere/renderer/pipelines/debug/DebugContentPipeline.java +++ b/src/main/java/electrosphere/renderer/pipelines/debug/DebugContentPipeline.java @@ -10,6 +10,7 @@ import org.ode4j.ode.DCapsule; import org.ode4j.ode.DGeom; import org.ode4j.ode.DSphere; +import electrosphere.client.entity.camera.CameraEntityUtils; import electrosphere.collision.PhysicsUtils; import electrosphere.collision.collidable.Collidable; import electrosphere.engine.Globals; @@ -19,7 +20,6 @@ import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityUtils; import electrosphere.entity.state.hitbox.HitboxCollectionState; import electrosphere.entity.state.hitbox.HitboxCollectionState.HitboxState; -import electrosphere.entity.types.camera.CameraEntityUtils; import electrosphere.game.data.collidable.CollidableTemplate; import electrosphere.game.data.collidable.HitboxData; import electrosphere.renderer.OpenGLState; diff --git a/src/main/java/electrosphere/server/ai/nodes/actions/move/FaceTargetNode.java b/src/main/java/electrosphere/server/ai/nodes/actions/move/FaceTargetNode.java index 9d7dcb86..2285ccf6 100644 --- a/src/main/java/electrosphere/server/ai/nodes/actions/move/FaceTargetNode.java +++ b/src/main/java/electrosphere/server/ai/nodes/actions/move/FaceTargetNode.java @@ -3,9 +3,9 @@ package electrosphere.server.ai.nodes.actions.move; import org.joml.Quaterniond; import org.joml.Vector3d; +import electrosphere.client.entity.camera.CameraEntityUtils; import electrosphere.entity.Entity; import electrosphere.entity.EntityUtils; -import electrosphere.entity.types.camera.CameraEntityUtils; import electrosphere.entity.types.creature.CreatureUtils; import electrosphere.server.ai.blackboard.Blackboard; import electrosphere.server.ai.nodes.AITreeNode; diff --git a/src/main/java/electrosphere/server/content/serialization/ContentSerialization.java b/src/main/java/electrosphere/server/content/serialization/ContentSerialization.java index 65c7c55f..19f60da1 100644 --- a/src/main/java/electrosphere/server/content/serialization/ContentSerialization.java +++ b/src/main/java/electrosphere/server/content/serialization/ContentSerialization.java @@ -7,13 +7,14 @@ import electrosphere.entity.Entity; import electrosphere.entity.EntityUtils; import electrosphere.entity.state.equip.ServerEquipState; import electrosphere.entity.state.inventory.InventoryUtils; +import electrosphere.entity.types.EntityTypes; +import electrosphere.entity.types.EntityTypes.EntityType; +import electrosphere.entity.types.common.CommonEntityUtils; import electrosphere.entity.types.creature.CreatureEquipData.EquippedItem; import electrosphere.entity.types.creature.CreatureTemplate; import electrosphere.entity.types.creature.CreatureUtils; import electrosphere.entity.types.foliage.FoliageUtils; import electrosphere.entity.types.item.ItemUtils; -import electrosphere.entity.types.object.ObjectUtils; -import electrosphere.entity.types.structure.StructureUtils; import electrosphere.server.datacell.Realm; import electrosphere.server.datacell.ServerDataCell; import electrosphere.server.datacell.utils.EntityLookupUtils; @@ -37,48 +38,44 @@ public class ContentSerialization { ContentSerialization rVal = new ContentSerialization(); for(Entity entity : entities){ if(!CreatureUtils.hasControllerPlayerId(entity)){ - if(CreatureUtils.isCreature(entity)){ - EntitySerialization serializedEntity = new EntitySerialization(); - serializedEntity.setPosition(EntityUtils.getPosition(entity)); - serializedEntity.setRotation(EntityUtils.getRotation(entity)); - serializedEntity.setType(CreatureUtils.ENTITY_TYPE_CREATURE); - serializedEntity.setSubtype(CreatureUtils.getType(entity)); - if(CreatureUtils.getCreatureTemplate(entity) != null){ - serializedEntity.setTemplate(Utilities.stringify(CreatureUtils.getCreatureTemplate(entity))); - } - rVal.serializedEntities.add(serializedEntity); - } - if(ItemUtils.isItem(entity) && ItemUtils.itemShouldBeSerialized(entity)){ - EntitySerialization serializedEntity = new EntitySerialization(); - serializedEntity.setPosition(EntityUtils.getPosition(entity)); - serializedEntity.setRotation(EntityUtils.getRotation(entity)); - serializedEntity.setType(ItemUtils.ENTITY_TYPE_ITEM); - serializedEntity.setSubtype(ItemUtils.getType(entity)); - rVal.serializedEntities.add(serializedEntity); - } - if(ObjectUtils.isObject(entity)){ - EntitySerialization serializedEntity = new EntitySerialization(); - serializedEntity.setPosition(EntityUtils.getPosition(entity)); - serializedEntity.setRotation(EntityUtils.getRotation(entity)); - serializedEntity.setType(ObjectUtils.ENTITY_TYPE_OBJECT); - serializedEntity.setSubtype(ObjectUtils.getType(entity)); - rVal.serializedEntities.add(serializedEntity); - } - if(StructureUtils.isStructure(entity)){ - throw new UnsupportedOperationException("Not implemented"); - } - if(FoliageUtils.isFoliage(entity)){ - if(FoliageUtils.hasSeed(entity)){ + EntityType type = CommonEntityUtils.getEntityType(entity); + switch(type){ + case CREATURE: { EntitySerialization serializedEntity = new EntitySerialization(); serializedEntity.setPosition(EntityUtils.getPosition(entity)); serializedEntity.setRotation(EntityUtils.getRotation(entity)); - serializedEntity.setType(FoliageUtils.ENTITY_TYPE_FOLIAGE); - serializedEntity.setSubtype(FoliageUtils.getFoliageType(entity).getName()); + serializedEntity.setType(EntityType.CREATURE.getValue()); + serializedEntity.setSubtype(CommonEntityUtils.getEntitySubtype(entity)); + if(CreatureUtils.getCreatureTemplate(entity) != null){ + serializedEntity.setTemplate(Utilities.stringify(CreatureUtils.getCreatureTemplate(entity))); + } + rVal.serializedEntities.add(serializedEntity); + } break; + case ITEM: { + EntitySerialization serializedEntity = new EntitySerialization(); + serializedEntity.setPosition(EntityUtils.getPosition(entity)); + serializedEntity.setRotation(EntityUtils.getRotation(entity)); + serializedEntity.setType(EntityType.ITEM.getValue()); + serializedEntity.setSubtype(CommonEntityUtils.getEntitySubtype(entity)); + rVal.serializedEntities.add(serializedEntity); + } break; + case FOLIAGE: { + EntitySerialization serializedEntity = new EntitySerialization(); + serializedEntity.setPosition(EntityUtils.getPosition(entity)); + serializedEntity.setRotation(EntityUtils.getRotation(entity)); + serializedEntity.setType(EntityType.FOLIAGE.getValue()); + serializedEntity.setSubtype(CommonEntityUtils.getEntitySubtype(entity)); serializedEntity.setTemplate(FoliageUtils.getFoliageSeed(entity) + ""); rVal.serializedEntities.add(serializedEntity); - } else { - throw new UnsupportedOperationException("Not implemented"); - } + } break; + case COMMON: { + EntitySerialization serializedEntity = new EntitySerialization(); + serializedEntity.setPosition(EntityUtils.getPosition(entity)); + serializedEntity.setRotation(EntityUtils.getRotation(entity)); + serializedEntity.setType(EntityType.COMMON.getValue()); + serializedEntity.setSubtype(CommonEntityUtils.getEntitySubtype(entity)); + rVal.serializedEntities.add(serializedEntity); + } break; } } } @@ -92,8 +89,8 @@ public class ContentSerialization { public void hydrateRawContent(Realm realm, ServerDataCell serverDataCell){ List serializedEntities = this.getSerializedEntities(); for(EntitySerialization serializedEntity : serializedEntities){ - switch(serializedEntity.getType()){ - case CreatureUtils.ENTITY_TYPE_CREATURE: { + switch(EntityTypes.fromInt(serializedEntity.getType())){ + case CREATURE: { CreatureTemplate template = null; if(serializedEntity.getTemplate() != null){ template = Utilities.deserialize(serializedEntity.getTemplate(), CreatureTemplate.class); @@ -122,15 +119,15 @@ public class ContentSerialization { } } } break; - case ItemUtils.ENTITY_TYPE_ITEM: { + case ITEM: { Entity item = ItemUtils.serverSpawnBasicItem(realm, serializedEntity.getPosition(), serializedEntity.getSubtype()); EntityUtils.getRotation(item).set(serializedEntity.getRotation()); } break; - case ObjectUtils.ENTITY_TYPE_OBJECT: { - Entity object = ObjectUtils.serverSpawnBasicObject(realm, serializedEntity.getPosition(), serializedEntity.getSubtype()); + case COMMON: { + Entity object = CommonEntityUtils.serverSpawnBasicObject(realm, serializedEntity.getPosition(), serializedEntity.getSubtype()); EntityUtils.getRotation(object).set(serializedEntity.getRotation()); } break; - case FoliageUtils.ENTITY_TYPE_FOLIAGE: { + case FOLIAGE: { long seed = Long.parseLong(serializedEntity.getTemplate()); Entity foliage = FoliageUtils.serverSpawnTreeFoliage(realm, serializedEntity.getPosition(), serializedEntity.getSubtype(), seed); EntityUtils.getRotation(foliage).set(serializedEntity.getRotation()); diff --git a/src/main/java/electrosphere/server/datacell/ServerDataCell.java b/src/main/java/electrosphere/server/datacell/ServerDataCell.java index ee163e5b..ed10f96d 100644 --- a/src/main/java/electrosphere/server/datacell/ServerDataCell.java +++ b/src/main/java/electrosphere/server/datacell/ServerDataCell.java @@ -3,11 +3,11 @@ package electrosphere.server.datacell; import electrosphere.engine.Globals; import electrosphere.entity.Entity; import electrosphere.entity.Scene; +import electrosphere.entity.types.EntityTypes.EntityType; +import electrosphere.entity.types.common.CommonEntityUtils; import electrosphere.entity.types.creature.CreatureUtils; import electrosphere.entity.types.foliage.FoliageUtils; import electrosphere.entity.types.item.ItemUtils; -import electrosphere.entity.types.object.ObjectUtils; -import electrosphere.entity.types.structure.StructureUtils; import electrosphere.game.server.character.Character; import electrosphere.net.parser.net.message.EntityMessage; import electrosphere.net.parser.net.message.NetworkMessage; @@ -144,20 +144,22 @@ public class ServerDataCell { * @param player The player to send the entity to */ void serializeEntityToPlayer(Entity entity, Player player){ - if(CreatureUtils.isCreature(entity)){ - CreatureUtils.sendEntityToPlayer(player, entity); - } - if(ItemUtils.isItem(entity) && ItemUtils.itemShouldBeSentToClient(entity)){ - ItemUtils.sendEntityToPlayer(player, entity); - } - if(ObjectUtils.isObject(entity)){ - ObjectUtils.sendEntityToPlayer(player,entity); - } - if(StructureUtils.isStructure(entity)){ - StructureUtils.sendStructureToPlayer(player, entity); - } - if(FoliageUtils.isFoliage(entity)){ - FoliageUtils.sendFoliageToPlayer(player, entity); + EntityType type = CommonEntityUtils.getEntityType(entity); + if(type != null){ + switch(type){ + case CREATURE: { + CreatureUtils.sendEntityToPlayer(player, entity); + } break; + case ITEM: { + ItemUtils.sendEntityToPlayer(player, entity); + } break; + case FOLIAGE: { + FoliageUtils.sendFoliageToPlayer(player, entity); + } break; + case COMMON: { + CommonEntityUtils.sendEntityToPlayer(player, entity); + } break; + } } } diff --git a/src/main/java/electrosphere/server/poseactor/PoseActor.java b/src/main/java/electrosphere/server/poseactor/PoseActor.java index 38d40883..258a6117 100644 --- a/src/main/java/electrosphere/server/poseactor/PoseActor.java +++ b/src/main/java/electrosphere/server/poseactor/PoseActor.java @@ -16,7 +16,7 @@ import org.joml.Vector4d; import electrosphere.engine.Globals; import electrosphere.entity.state.AnimationPriorities; -import electrosphere.game.data.common.TreeDataAnimation; +import electrosphere.game.data.common.treedata.TreeDataAnimation; import electrosphere.game.data.creature.type.bonegroups.BoneGroup; import electrosphere.logger.LoggerInterface; import electrosphere.renderer.actor.ActorAnimationMask; diff --git a/src/main/java/electrosphere/util/ds/octree/ChunkTree.java b/src/main/java/electrosphere/util/ds/octree/ChunkTree.java index 06c22115..0f9f5354 100644 --- a/src/main/java/electrosphere/util/ds/octree/ChunkTree.java +++ b/src/main/java/electrosphere/util/ds/octree/ChunkTree.java @@ -4,7 +4,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.LinkedList; import java.util.List; -import java.util.stream.Collectors; import org.joml.Vector3i; diff --git a/src/test/java/electrosphere/entity/types/camera/CameraEntityUtilsUnitTests.java b/src/test/java/electrosphere/entity/types/camera/CameraEntityUtilsUnitTests.java index b5062605..efd9159e 100644 --- a/src/test/java/electrosphere/entity/types/camera/CameraEntityUtilsUnitTests.java +++ b/src/test/java/electrosphere/entity/types/camera/CameraEntityUtilsUnitTests.java @@ -2,6 +2,7 @@ package electrosphere.entity.types.camera; import org.junit.jupiter.api.Assertions; +import electrosphere.client.entity.camera.CameraEntityUtils; import electrosphere.test.annotations.FastTest; import electrosphere.test.annotations.UnitTest;