diff --git a/src/main/java/electrosphere/entity/EntityDataStrings.java b/src/main/java/electrosphere/entity/EntityDataStrings.java index 32b000b7..d9db05f2 100644 --- a/src/main/java/electrosphere/entity/EntityDataStrings.java +++ b/src/main/java/electrosphere/entity/EntityDataStrings.java @@ -75,10 +75,27 @@ public class EntityDataStrings { public static final String DATA_STRING_COLLISION_ENTITY_TYPE_SPHERE = "collisionSphere"; public static final String COLLISION_ENTITY_DATA_TYPE = "collisionDataType"; + public static final String COLLISION_ENTITY_DATA_TYPE_HIT = "collisionDataTypeHit"; + public static final String COLLISION_ENTITY_DATA_TYPE_HURT = "collisionDataTypeHurt"; public static final String COLLISION_ENTITY_DATA_PARENT = "collisionDataParent"; public static final String COLLISION_ENTITY_DATA_BONE = "collisionDataBone"; + public static final String COLLISION_ENTITY_DATA_SIZE = "collisionSphereSize"; + + + /* + Attach Entity + */ + public static final String ATTACH_ENTITY_IS_ATTACHED = "attachIsAttached"; + public static final String ATTACH_PARENT = "attachParent"; + public static final String ATTACH_TARGET_BONE = "attachTargetBone"; + + /* + Item Entity + */ + public static final String ITEM_IS_ITEM = "itemIsItem"; + public static final String ITEM_TYPE = "itemType"; } diff --git a/src/main/java/electrosphere/entity/EntityManager.java b/src/main/java/electrosphere/entity/EntityManager.java index 839af30b..d7b2b6d3 100644 --- a/src/main/java/electrosphere/entity/EntityManager.java +++ b/src/main/java/electrosphere/entity/EntityManager.java @@ -17,6 +17,8 @@ public class EntityManager { static CopyOnWriteArrayList moveableList = new CopyOnWriteArrayList(); static CopyOnWriteArrayList lightList = new CopyOnWriteArrayList(); static CopyOnWriteArrayList uiList = new CopyOnWriteArrayList(); + static CopyOnWriteArrayList itemList = new CopyOnWriteArrayList(); + static CopyOnWriteArrayList attachList = new CopyOnWriteArrayList(); public EntityManager(){ @@ -59,6 +61,22 @@ public class EntityManager { return uiList; } + public void registerItemEntity(Entity e){ + itemList.add(e); + } + + public CopyOnWriteArrayList getItemEntities(){ + return itemList; + } + + public void registerAttachedEntity(Entity e){ + attachList.add(e); + } + + public CopyOnWriteArrayList getAttachedEntities(){ + return attachList; + } + public void deregisterEntity(Entity e){ if(lightList.contains(e)){ lightList.remove(e); @@ -76,6 +94,9 @@ public class EntityManager { if(uiList.contains(e)){ uiList.remove(e); } + if(itemList.contains(e)){ + itemList.remove(e); + } } public void overrideEntityId(Entity e, int id){ diff --git a/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java b/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java index f06934f3..60e4bfa3 100644 --- a/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java +++ b/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java @@ -44,7 +44,7 @@ public class CreatureUtils { CreatureType rawType = Globals.entityTypeMap.get(creatureId); Entity rVal = EntityUtils.spawnDrawableEntity(rawType.getModelPath()); for(HitboxData hitboxdata : rawType.getHitboxes()){ - Globals.hitboxManager.registerHitbox(HitboxUtils.spawnRegularHitbox(rVal, hitboxdata.getBone())); + Globals.hitboxManager.registerHitbox(HitboxUtils.spawnRegularHitbox(rVal, hitboxdata.getBone(), hitboxdata.getSize())); } rVal.putData(EntityDataStrings.DATA_STRING_CREATURE_IS_CREATURE, true); rVal.putData(EntityDataStrings.DATA_STRING_CREATURE_TYPE, creatureId); diff --git a/src/main/java/electrosphere/entity/types/creature/creaturemap/HitboxData.java b/src/main/java/electrosphere/entity/types/creature/creaturemap/HitboxData.java index 41a3c374..6b574e5d 100644 --- a/src/main/java/electrosphere/entity/types/creature/creaturemap/HitboxData.java +++ b/src/main/java/electrosphere/entity/types/creature/creaturemap/HitboxData.java @@ -7,6 +7,7 @@ package electrosphere.entity.types.creature.creaturemap; public class HitboxData { String type; String bone; + float size; public String getType() { return type; @@ -16,5 +17,9 @@ public class HitboxData { return bone; } + public float getSize() { + return size; + } + } diff --git a/src/main/java/electrosphere/entity/types/hitbox/HitboxUtils.java b/src/main/java/electrosphere/entity/types/hitbox/HitboxUtils.java index 63c586b8..fb0967a6 100644 --- a/src/main/java/electrosphere/entity/types/hitbox/HitboxUtils.java +++ b/src/main/java/electrosphere/entity/types/hitbox/HitboxUtils.java @@ -15,10 +15,20 @@ import org.joml.Vector4f; public class HitboxUtils { - public static Entity spawnRegularHitbox(Entity parent, String bone){ + public static Entity spawnRegularHitbox(Entity parent, String bone, float size){ Entity rVal = new Entity(); rVal.putData(EntityDataStrings.COLLISION_ENTITY_DATA_PARENT, parent); rVal.putData(EntityDataStrings.COLLISION_ENTITY_DATA_BONE, bone); + rVal.putData(EntityDataStrings.COLLISION_ENTITY_DATA_SIZE,size); + rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3f(0,0,0)); + return rVal; + } + + public static Entity spawnRegularHurtbox(Entity parent, String bone, float size){ + Entity rVal = new Entity(); + rVal.putData(EntityDataStrings.COLLISION_ENTITY_DATA_PARENT, parent); + rVal.putData(EntityDataStrings.COLLISION_ENTITY_DATA_BONE, bone); + rVal.putData(EntityDataStrings.COLLISION_ENTITY_DATA_SIZE,size); rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3f(0,0,0)); return rVal; } diff --git a/src/main/java/electrosphere/entity/types/item/ItemUtils.java b/src/main/java/electrosphere/entity/types/item/ItemUtils.java new file mode 100644 index 00000000..5c42501e --- /dev/null +++ b/src/main/java/electrosphere/entity/types/item/ItemUtils.java @@ -0,0 +1,45 @@ +package electrosphere.entity.types.item; + +import electrosphere.entity.Entity; +import electrosphere.entity.EntityDataStrings; +import electrosphere.entity.EntityUtils; +import electrosphere.entity.state.MovementTree; +import electrosphere.entity.types.creature.creaturemap.CreatureType; +import electrosphere.entity.types.creature.creaturemap.HitboxData; +import electrosphere.entity.types.hitbox.HitboxUtils; +import electrosphere.main.Globals; +import electrosphere.renderer.Actor; +import electrosphere.renderer.Model; +import org.joml.Quaternionf; +import org.joml.Vector3f; + +/** + * + * @author amaterasu + */ +public class ItemUtils { + public static Entity spawnBasicItem(int itemId){ + CreatureType rawType = Globals.entityTypeMap.get(itemId); + Entity rVal = EntityUtils.spawnDrawableEntity(rawType.getModelPath()); + for(HitboxData hitboxdata : rawType.getHitboxes()){ + Globals.hitboxManager.registerHitbox(HitboxUtils.spawnRegularHitbox(rVal, hitboxdata.getBone(), hitboxdata.getSize())); + } + rVal.putData(EntityDataStrings.ITEM_IS_ITEM, true); + rVal.putData(EntityDataStrings.ITEM_TYPE, itemId); + 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.entityManager.registerItemEntity(rVal); + return rVal; + } + + public static void updateItemActorAnimation(Entity item){ + Actor actor = EntityUtils.getEntityActor(item); + if(actor.getCurrentAnimation() == null){ +// Model model; +// if((model = Globals.assetManager.fetchModel(actor.getModelPath()))!=null){ +// model.describeAllAnimations(); +// } + actor.playAnimation("Sword|Idle"); + } + } +} diff --git a/src/main/java/electrosphere/game/state/AliveManager.java b/src/main/java/electrosphere/game/state/AliveManager.java new file mode 100644 index 00000000..433a9101 --- /dev/null +++ b/src/main/java/electrosphere/game/state/AliveManager.java @@ -0,0 +1,33 @@ +package electrosphere.game.state; + +import electrosphere.entity.Entity; +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author amaterasu + */ +public class AliveManager { + List aliveList = new ArrayList(); + List deadList = new ArrayList(); + List invulnerableList = new ArrayList(); + + public List getAliveEntities(){ + return aliveList; + } + + public List getDeadEntities(){ + return deadList; + } + + public List getInvulnerableEntities(){ + return invulnerableList; + } + + + public void registerAliveEntity(Entity e){ + aliveList.add(e); + } + +} diff --git a/src/main/java/electrosphere/game/state/AttachUtils.java b/src/main/java/electrosphere/game/state/AttachUtils.java new file mode 100644 index 00000000..daeec331 --- /dev/null +++ b/src/main/java/electrosphere/game/state/AttachUtils.java @@ -0,0 +1,42 @@ +package electrosphere.game.state; + +import electrosphere.entity.Entity; +import electrosphere.entity.EntityDataStrings; +import electrosphere.entity.EntityUtils; +import electrosphere.main.Globals; +import electrosphere.renderer.Actor; +import org.joml.Quaternionf; +import org.joml.Vector3f; + +/** + * + * @author amaterasu + */ +public class AttachUtils { + + + public static void attachEntityToEntityAtBone(Entity parent, Entity toAttach, String boneName){ + Globals.entityManager.registerAttachedEntity(toAttach); + toAttach.putData(EntityDataStrings.ATTACH_ENTITY_IS_ATTACHED, true); + toAttach.putData(EntityDataStrings.ATTACH_PARENT, parent); + toAttach.putData(EntityDataStrings.ATTACH_TARGET_BONE, boneName); + } + + public static void updateAttachedEntityPositions(){ + for(Entity currentEntity : Globals.entityManager.getAttachedEntities()){ + Entity parent; + if((parent = (Entity)currentEntity.getData(EntityDataStrings.ATTACH_PARENT))!=null){ + String targetBone; + if((targetBone = (String)currentEntity.getData(EntityDataStrings.ATTACH_TARGET_BONE))!=null){ + Actor parentActor = EntityUtils.getEntityActor(parent); + Vector3f position = new Vector3f(parentActor.getBonePosition(targetBone)); + position = position.mul(((Vector3f)EntityUtils.getEntityScale(parent))); + position = position.rotate(((Quaternionf)EntityUtils.getEntityRotation(parent))); + position.add(new Vector3f(EntityUtils.getEntityPosition(parent))); + EntityUtils.getEntityPosition(currentEntity).set(position); + EntityUtils.getEntityRotation(currentEntity).add(EntityUtils.getEntityRotation(parent)).normalize(); + } + } + } + } +} diff --git a/src/main/java/electrosphere/game/state/LoadingThread.java b/src/main/java/electrosphere/game/state/LoadingThread.java index 7f779ac1..9f7d5d2f 100644 --- a/src/main/java/electrosphere/game/state/LoadingThread.java +++ b/src/main/java/electrosphere/game/state/LoadingThread.java @@ -6,6 +6,7 @@ import electrosphere.entity.Entity; import electrosphere.entity.EntityUtils; import electrosphere.entity.collision.CollisionEngine; import electrosphere.entity.types.creature.CreatureUtils; +import electrosphere.entity.types.item.ItemUtils; import electrosphere.game.cell.DrawCellManager; import electrosphere.game.state.SimulationState.SimulationStateMachine; import electrosphere.game.terrain.TerrainManager; @@ -379,6 +380,12 @@ public class LoadingThread extends Thread { // EntityUtils.getEntityPosition(creature).set(rand.nextFloat() * 10, rand.nextFloat() * 10, rand.nextFloat() * 10); // EntityUtils.getEntityScale(creature).set(0.01f); // } + + Entity sword = ItemUtils.spawnBasicItem(2); + Entity testHomie = CreatureUtils.spawnBasicCreature(0, 0.1f, 0.5f); + EntityUtils.getEntityScale(testHomie).set(0.005f); + EntityUtils.getEntityPosition(testHomie).set(2,0,2); + AttachUtils.attachEntityToEntityAtBone(testHomie, sword, "Bone.020"); } diff --git a/src/main/java/electrosphere/game/world/World.java b/src/main/java/electrosphere/game/world/World.java index 7e253426..ba33b916 100644 --- a/src/main/java/electrosphere/game/world/World.java +++ b/src/main/java/electrosphere/game/world/World.java @@ -57,7 +57,7 @@ public class World { rVal.type = WorldType.GAME_WORLD; rVal.terrainManager = terrainManager; rVal.worldMinPoint = new Vector3f(0,0,0); - int worldDim = rVal.terrainManager.getWorldDiscreteSize(); + int worldDim = rVal.terrainManager.getWorldDiscreteSize() * rVal.terrainManager.getChunkWidth(); rVal.worldMaxPoint = new Vector3f(worldDim,0,worldDim); return rVal; } diff --git a/src/main/java/electrosphere/main/Globals.java b/src/main/java/electrosphere/main/Globals.java index 4f1232e9..13c28cd5 100644 --- a/src/main/java/electrosphere/main/Globals.java +++ b/src/main/java/electrosphere/main/Globals.java @@ -18,6 +18,7 @@ import electrosphere.entity.types.creature.creaturemap.CreatureType; import electrosphere.entity.types.creature.creaturemap.CreatureTypeList; import electrosphere.entity.types.hitbox.HitboxManager; import electrosphere.game.cell.DrawCellManager; +import electrosphere.game.state.AliveManager; import electrosphere.game.state.LoadingThread; import electrosphere.game.terrain.TerrainManager; import electrosphere.game.world.World; @@ -185,6 +186,9 @@ public class Globals { //ui text box for loading text public static TextBox loadingBox; + //life status entity manager + public static AliveManager aliveManager; + //the player camera entity public static Entity playerCamera; @@ -225,6 +229,8 @@ public class Globals { widgetManager = new WidgetManager(); //hitbox manager hitboxManager = new HitboxManager(); + //alive manager + aliveManager = new AliveManager(); } public static void initDefaultGraphicalResources(){ diff --git a/src/main/java/electrosphere/main/Main.java b/src/main/java/electrosphere/main/Main.java index 599065f3..cf4f343a 100644 --- a/src/main/java/electrosphere/main/Main.java +++ b/src/main/java/electrosphere/main/Main.java @@ -16,7 +16,9 @@ import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityUtils; import electrosphere.entity.state.MovementTree; import electrosphere.entity.types.hitbox.HitboxUtils; +import electrosphere.entity.types.item.ItemUtils; import electrosphere.game.cell.DrawCellManager; +import electrosphere.game.state.AttachUtils; import electrosphere.game.state.LoadingThread; import electrosphere.game.state.SimulationState; import electrosphere.game.state.SimulationState.SimulationStateMachine; @@ -210,6 +212,12 @@ public class Main { /// C L I E N T S I M U L A T I O N S T U F F /// if(SimulationState.simulationState == SimulationStateMachine.MAIN_SIMULATION || SimulationState.simulationState == SimulationStateMachine.ARENA_SIMULATION){ + //make items play idle animation + for(Entity item : Globals.entityManager.getItemEntities()){ + ItemUtils.updateItemActorAnimation(item); + } + //update attached entity positions + AttachUtils.updateAttachedEntityPositions(); //simulate creature behavior trees for(Entity currentMoveable : Globals.entityManager.getMoveable()){ MovementTree behaviorTree = CreatureUtils.getEntityMovementTree(currentMoveable); diff --git a/src/main/java/electrosphere/net/server/ServerConnectionHandler.java b/src/main/java/electrosphere/net/server/ServerConnectionHandler.java index e0165f6a..ed89669f 100644 --- a/src/main/java/electrosphere/net/server/ServerConnectionHandler.java +++ b/src/main/java/electrosphere/net/server/ServerConnectionHandler.java @@ -3,6 +3,8 @@ package electrosphere.net.server; import electrosphere.entity.types.creature.CreatureUtils; import electrosphere.entity.Entity; import electrosphere.entity.EntityUtils; +import electrosphere.entity.types.item.ItemUtils; +import electrosphere.game.state.AttachUtils; import electrosphere.main.Globals; import electrosphere.main.Main; import electrosphere.net.NetUtils; @@ -88,6 +90,10 @@ public class ServerConnectionHandler implements Runnable { Entity newPlayerCharacter = CreatureUtils.spawnBasicCreature(0, 0.001f, 0.05f); EntityUtils.getEntityScale(newPlayerCharacter).set(0.005f); EntityUtils.getEntityPosition(newPlayerCharacter).set(Globals.spawnPoint.x,Globals.drawCellManager.getElevationAtRealPoint(Globals.spawnPoint.x, Globals.spawnPoint.z),Globals.spawnPoint.z); + //spawn player sword + Entity sword = ItemUtils.spawnBasicItem(2); + AttachUtils.attachEntityToEntityAtBone(newPlayerCharacter, sword, "Bone.020"); + //set controller id CreatureUtils.setControllerPlayerId(newPlayerCharacter, playerID); if(Globals.mainConfig.runServer && Main.playerId == -1){ Globals.playerCharacter = newPlayerCharacter; diff --git a/src/main/java/electrosphere/renderer/Actor.java b/src/main/java/electrosphere/renderer/Actor.java index 21fbf746..1c852330 100644 --- a/src/main/java/electrosphere/renderer/Actor.java +++ b/src/main/java/electrosphere/renderer/Actor.java @@ -111,9 +111,7 @@ public class Actor { model.playAnimation(animation); model.incrementTime(0.001); model.incrementTime(animationTime); - if(model.currentAnimation == null){ - playingAnimation = false; - } + model.update_node_transform(model.root_anim_node); Bone currentBone = model.boneMap.get(boneName); if(currentBone != null){ Vector4f result = currentBone.final_transform.transform(new Matrix4f(currentBone.inverseBindPoseMatrix).invert().transform(new Vector4f(rVal.x,rVal.y,rVal.z,1))); diff --git a/src/main/java/electrosphere/renderer/RenderUtils.java b/src/main/java/electrosphere/renderer/RenderUtils.java index 3ebe36fc..35e0e450 100644 --- a/src/main/java/electrosphere/renderer/RenderUtils.java +++ b/src/main/java/electrosphere/renderer/RenderUtils.java @@ -1,8 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package electrosphere.renderer; import electrosphere.entity.CameraEntityUtils; @@ -685,7 +680,7 @@ public class RenderUtils { modelTransformMatrix.identity(); modelTransformMatrix.translate(new Vector3f(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)).sub(new Vector3f(0,1,0))); // modelTransformMatrix.translate(-0.25f, 0.0f, 0.5f); //center sphere - modelTransformMatrix.scale(0.1f); + modelTransformMatrix.scale((Float)currentHitbox.getData(EntityDataStrings.COLLISION_ENTITY_DATA_SIZE)); hitboxModel.modelMatrix = modelTransformMatrix; hitboxModel.draw(); } diff --git a/src/main/resources/Data/entity_map.json b/src/main/resources/Data/entity_map.json index e9052728..58d435e9 100644 --- a/src/main/resources/Data/entity_map.json +++ b/src/main/resources/Data/entity_map.json @@ -5,7 +5,36 @@ "modelPath" : "Models/person1walkanim.fbx", "hitboxes" : [ { - "bone": "Bone.031" + "bone": "Bone.031", + "size": 0.08 + }, + { + "bone": "Bone.017", + "size": 0.08 + }, + { + "bone": "Bone.012", + "size": 0.08 + }, + { + "bone": "Bone.003", + "size": 0.08 + }, + { + "bone": "Bone.010", + "size": 0.11 + }, + { + "bone": "Bone.001", + "size": 0.11 + }, + { + "bone": "Bone", + "size": 0.15 + }, + { + "bone": "Bone.014", + "size": 0.12 } ] }, @@ -13,6 +42,24 @@ "id" : 1, "modelPath" : "", "hitboxes" : [] + }, + { + "id" : 2, + "modelPath" : "Models/katana1alt.fbx", + "hitboxes" : [ + { + "bone": "Blade1", + "size": 0.08 + }, + { + "bone": "Blade2", + "size": 0.08 + }, + { + "bone": "Blade3", + "size": 0.08 + } + ] } ] } diff --git a/src/main/resources/Models/katana1.fbx b/src/main/resources/Models/katana1.fbx new file mode 100644 index 00000000..f1a3f522 Binary files /dev/null and b/src/main/resources/Models/katana1.fbx differ diff --git a/src/main/resources/Models/katana1alt.fbx b/src/main/resources/Models/katana1alt.fbx new file mode 100644 index 00000000..43202aed Binary files /dev/null and b/src/main/resources/Models/katana1alt.fbx differ diff --git a/src/main/resources/Textures/default_texture_map.json b/src/main/resources/Textures/default_texture_map.json index a6093c1c..c40ca4b3 100644 --- a/src/main/resources/Textures/default_texture_map.json +++ b/src/main/resources/Textures/default_texture_map.json @@ -23,6 +23,12 @@ "Textures/transparent_blue.png", "Textures/transparent_blue.png" ] + }, + "Models/katana1.fbx": { + "SwordMesh": [ + "Textures/katana1.png", + "Textures/katana1.png" + ] } } } \ No newline at end of file diff --git a/src/main/resources/Textures/katana1.png b/src/main/resources/Textures/katana1.png new file mode 100644 index 00000000..82774c70 Binary files /dev/null and b/src/main/resources/Textures/katana1.png differ