diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index 2608cfe2..82c5e5c7 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -543,6 +543,7 @@ Block override concept for hitboxes Block sfx Fix server hitboxes freaking out at animation end Fix hitcapsule misalignment +Always upright tree # TODO @@ -572,6 +573,7 @@ Transvoxel implementation Terrain Interface Positional Access Interface - Ability to get terrain at point for interactions with game world eg placing grass/water collision +Fix hitbox placement does not scale with entity scale on server Fix not all grass tiles update when updating a nearby voxel (ie it doesn't go into negative coordinates to scan for foliage updates) diff --git a/src/main/java/electrosphere/entity/EntityDataStrings.java b/src/main/java/electrosphere/entity/EntityDataStrings.java index b9bf2071..8f0933c1 100644 --- a/src/main/java/electrosphere/entity/EntityDataStrings.java +++ b/src/main/java/electrosphere/entity/EntityDataStrings.java @@ -305,6 +305,12 @@ public class EntityDataStrings { */ public static final String TREE_SERVERPHYSICSSYNCTREE = "treeServerPhysicsSyncTree"; public static final String TREE_CLIENTPHYSICSSYNCTREE = "treeClientPhysicsSyncTree"; + + /** + * Always upright tree + */ + public static final String TREE_CLIENTALWAYSUPRIGHTTREE = "treeClientAlwaysUprightTree"; + public static final String TREE_SERVERALWAYSUPRIGHTTREE = "treeServerAlwaysUprightTree"; /* Entity categories diff --git a/src/main/java/electrosphere/entity/ServerEntityUtils.java b/src/main/java/electrosphere/entity/ServerEntityUtils.java index a3d0b384..dec1b0f3 100644 --- a/src/main/java/electrosphere/entity/ServerEntityUtils.java +++ b/src/main/java/electrosphere/entity/ServerEntityUtils.java @@ -11,7 +11,6 @@ import electrosphere.server.datacell.ServerDataCell; import electrosphere.server.datacell.utils.DataCellSearchUtils; import electrosphere.server.datacell.utils.EntityLookupUtils; import electrosphere.server.datacell.utils.ServerBehaviorTreeUtils; -import electrosphere.server.datacell.utils.ServerEntityTagUtils; /** * Entity utilities specifically for the server side diff --git a/src/main/java/electrosphere/entity/state/physicssync/upright/ClientAlwaysUprightTree.java b/src/main/java/electrosphere/entity/state/physicssync/upright/ClientAlwaysUprightTree.java new file mode 100644 index 00000000..a68b9f2f --- /dev/null +++ b/src/main/java/electrosphere/entity/state/physicssync/upright/ClientAlwaysUprightTree.java @@ -0,0 +1,97 @@ +package electrosphere.entity.state.physicssync.upright; + +import org.joml.Quaterniond; +import org.joml.Vector3d; +import org.ode4j.ode.DBody; + +import electrosphere.collision.PhysicsEntityUtils; +import electrosphere.collision.PhysicsUtils; +import electrosphere.engine.Globals; +import electrosphere.entity.Entity; +import electrosphere.entity.EntityDataStrings; +import electrosphere.entity.EntityUtils; +import electrosphere.entity.btree.BehaviorTree; +import electrosphere.entity.state.physicssync.ClientPhysicsSyncTree; + +public class ClientAlwaysUprightTree implements BehaviorTree { + + //The parent entity for the tree + Entity parent; + + /** + * Constructor + * @param parent + * @param params + */ + private ClientAlwaysUprightTree(Entity parent, Object ... params){ + this.parent = parent; + } + + @Override + public void simulate(float deltaTime) { + DBody body = PhysicsEntityUtils.getDBody(parent); + if(body != null){ + Vector3d position = EntityUtils.getPosition(parent); + Quaterniond sourceRotation = new Quaterniond(EntityUtils.getRotation(parent)); + Vector3d linearVelocity = new Vector3d(); + Vector3d angularVelocity = new Vector3d(); + Vector3d linearForce = new Vector3d(); + Vector3d angularForce = new Vector3d(); + + //make sure rotation is vertical + // sourceRotation = sourceRotation.mul(0.001, 1, 0.001, 1).normalize(); + + EntityUtils.getPosition(parent).set(position); + EntityUtils.getRotation(parent).set(sourceRotation); + PhysicsUtils.synchronizeData(Globals.clientSceneWrapper.getCollisionEngine(), body, position, sourceRotation, linearVelocity, angularVelocity, linearForce, angularForce); + } + } + + /** + *

(initially) Automatically generated

+ *

+ * Attaches this tree to the entity. + *

+ * @param entity The entity to attach to + * @param tree The behavior tree to attach + * @param params Optional parameters that will be provided to the constructor + */ + public static ClientAlwaysUprightTree attachTree(Entity parent, Object ... params){ + ClientAlwaysUprightTree rVal = new ClientAlwaysUprightTree(parent,params); + //!!WARNING!! from here below should not be touched + //This was generated automatically to properly alert various systems that the btree exists and should be tracked + parent.putData(EntityDataStrings.TREE_CLIENTALWAYSUPRIGHTTREE, rVal); + Globals.clientSceneWrapper.getScene().registerBehaviorTree(rVal); + return rVal; + } + + /** + *

Automatically generated

+ *

+ * Detatches this tree from the entity. + *

+ * @param entity The entity to detach to + * @param tree The behavior tree to detach + */ + public static void detachTree(Entity entity, BehaviorTree tree){ + } + + /** + * Returns whether the entity has a physics sync tree + * @param entity The entity to check + * @return True if the entity contains a physics sync tree, false otherwise + */ + public static boolean hasTree(Entity entity){ + return entity.containsKey(EntityDataStrings.TREE_CLIENTALWAYSUPRIGHTTREE); + } + + /** + * Gets the client physics sync tree on the entity + * @param entity The entity + * @return The tree if it exists, null otherwise + */ + public static ClientPhysicsSyncTree getTree(Entity entity){ + return (ClientPhysicsSyncTree)entity.getData(EntityDataStrings.TREE_CLIENTALWAYSUPRIGHTTREE); + } + +} diff --git a/src/main/java/electrosphere/entity/state/physicssync/upright/ServerAlwaysUprightTree.java b/src/main/java/electrosphere/entity/state/physicssync/upright/ServerAlwaysUprightTree.java new file mode 100644 index 00000000..f4b3455b --- /dev/null +++ b/src/main/java/electrosphere/entity/state/physicssync/upright/ServerAlwaysUprightTree.java @@ -0,0 +1,98 @@ +package electrosphere.entity.state.physicssync.upright; + +import org.joml.Quaterniond; +import org.joml.Vector3d; +import org.ode4j.ode.DBody; + +import electrosphere.collision.PhysicsEntityUtils; +import electrosphere.collision.PhysicsUtils; +import electrosphere.engine.Globals; +import electrosphere.entity.Entity; +import electrosphere.entity.EntityDataStrings; +import electrosphere.entity.EntityUtils; +import electrosphere.entity.btree.BehaviorTree; +import electrosphere.entity.state.physicssync.ServerPhysicsSyncTree; +import electrosphere.server.datacell.Realm; +import electrosphere.server.datacell.utils.ServerBehaviorTreeUtils; + +public class ServerAlwaysUprightTree implements BehaviorTree { + + //The parent entity for the tree + Entity parent; + + /** + * Constructor + * @param parent + * @param params + */ + private ServerAlwaysUprightTree(Entity parent, Object ... params){ + this.parent = parent; + } + + @Override + public void simulate(float deltaTime) { + DBody body = PhysicsEntityUtils.getDBody(parent); + if(body != null){ + Realm realm = Globals.realmManager.getEntityRealm(parent); + Vector3d position = EntityUtils.getPosition(parent); + Quaterniond sourceRotation = new Quaterniond(EntityUtils.getRotation(parent)); + Vector3d linearVelocity = new Vector3d(); + Vector3d angularVelocity = new Vector3d(); + Vector3d linearForce = new Vector3d(); + Vector3d angularForce = new Vector3d(); + + //make sure rotation is vertical + // sourceRotation = sourceRotation.mul(0.001, 1, 0.001, 1).normalize(); + + EntityUtils.getPosition(parent).set(position); + EntityUtils.getRotation(parent).set(sourceRotation); + PhysicsUtils.synchronizeData(realm.getCollisionEngine(), body, position, sourceRotation, linearVelocity, angularVelocity, linearForce, angularForce); + } + } + + /** + *

+ * Attaches this tree to the entity. + *

+ * @param entity The entity to attach to + * @param tree The behavior tree to attach + * @param params Optional parameters that will be provided to the constructor + */ + public static ServerAlwaysUprightTree attachTree(Entity parent, Object ... params){ + ServerAlwaysUprightTree rVal = new ServerAlwaysUprightTree(parent,params); + //!!WARNING!! from here below should not be touched + //This was generated automatically to properly alert various systems that the btree exists and should be tracked + ServerBehaviorTreeUtils.attachBTreeToEntity(parent, rVal); + parent.putData(EntityDataStrings.TREE_SERVERALWAYSUPRIGHTTREE, rVal); + return rVal; + } + + /** + *

+ * Detatches this tree from the entity. + *

+ * @param entity The entity to detach to + * @param tree The behavior tree to detach + */ + public static void detachTree(Entity entity, BehaviorTree tree){ + } + + /** + * Returns whether the entity has a physics sync tree + * @param entity The entity to check + * @return True if the entity contains a physics sync tree, false otherwise + */ + public static boolean hasTree(Entity entity){ + return entity.containsKey(EntityDataStrings.TREE_SERVERALWAYSUPRIGHTTREE); + } + + /** + * Gets the server physics sync tree on the entity + * @param entity The entity + * @return The tree if it exists, null otherwise + */ + public static ServerPhysicsSyncTree getTree(Entity entity){ + return (ServerPhysicsSyncTree)entity.getData(EntityDataStrings.TREE_SERVERALWAYSUPRIGHTTREE); + } + +} diff --git a/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java b/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java index 00d14092..ce121496 100644 --- a/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java +++ b/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java @@ -41,6 +41,8 @@ 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.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; @@ -115,6 +117,7 @@ public class CreatureUtils { if(rawType.getCollidable() != null){ CollidableTemplate physicsTemplate = rawType.getCollidable(); PhysicsEntityUtils.clientAttachCollidableTemplate(rVal, physicsTemplate); + ClientAlwaysUprightTree.attachTree(rVal); } // @@ -384,6 +387,7 @@ public class CreatureUtils { if(rawType.getCollidable() != null){ CollidableTemplate physicsTemplate = rawType.getCollidable(); PhysicsEntityUtils.serverAttachCollidableTemplate(realm, rVal, physicsTemplate); + ServerAlwaysUprightTree.attachTree(rVal); } // //