From d41f3f2b1688d6232ccd6ccde0a015e7b7b04da5 Mon Sep 17 00:00:00 2001 From: austin Date: Fri, 16 Aug 2024 18:11:59 -0400 Subject: [PATCH] synchronization rotation fix --- buildNumber.properties | 4 +- docs/src/progress/currenttarget.md | 2 - docs/src/progress/renderertodo.md | 1 + net/entity.json | 26 ++- .../client/fluid/cells/FluidCell.java | 3 +- .../client/terrain/cells/DrawCell.java | 3 +- .../entity/ClientEntityUtils.java | 5 +- .../groundmove/ClientGroundMovementTree.java | 2 +- .../types/collision/CollisionObjUtils.java | 6 +- .../entity/types/creature/CreatureUtils.java | 9 +- .../entity/types/foliage/FoliageUtils.java | 8 +- .../entity/types/item/ItemUtils.java | 9 +- .../entity/types/object/ObjectUtils.java | 8 +- .../net/client/protocol/EntityProtocol.java | 24 ++- .../net/parser/net/message/EntityMessage.java | 160 +++++++++++++++++- .../net/parser/net/raw/NetworkParser.java | 8 +- 16 files changed, 241 insertions(+), 37 deletions(-) diff --git a/buildNumber.properties b/buildNumber.properties index 5f32d5a6..da501854 100644 --- a/buildNumber.properties +++ b/buildNumber.properties @@ -1,3 +1,3 @@ #maven.buildNumber.plugin properties file -#Fri Aug 16 16:31:44 EDT 2024 -buildNumber=256 +#Fri Aug 16 18:09:29 EDT 2024 +buildNumber=257 diff --git a/docs/src/progress/currenttarget.md b/docs/src/progress/currenttarget.md index 41d65334..22a94861 100644 --- a/docs/src/progress/currenttarget.md +++ b/docs/src/progress/currenttarget.md @@ -8,7 +8,6 @@ Script engine ability to spawn entities + rearchitecture - Netconf file that pre-populates address, ip, username, password Quad tree implementation to support grass placement and eventually chunk LOD management + fix the vibes @@ -21,7 +20,6 @@ Fix AI tracking deleted entity Fix server ground movement tree playing animation over falling animation Fix F2 menu not regaining controls when Xing menu instead of hitting F2 to close - Fix rotation not sending correctly on initialization of creatures on client Fix empty item slot not showing underneath dragged item Fix grass rendering distance diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index 0f09b727..2b0f4137 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -599,6 +599,7 @@ Fix AI components not resetting on turning off ai manager Fix broken rendering pipeline when creating new level Fix ui alignment for item panels in inventory menus (ie dont have to place in corner) Netconfig file support +Fix rotation not sending correctly on initialization of creatures on client # TODO diff --git a/net/entity.json b/net/entity.json index 7dfec583..db26d93e 100644 --- a/net/entity.json +++ b/net/entity.json @@ -191,7 +191,11 @@ "creatureTemplate", "positionX", "positionY", - "positionZ" + "positionZ", + "rotationX", + "rotationY", + "rotationZ", + "rotationW" ] }, { @@ -202,7 +206,11 @@ "creatureTemplate", "positionX", "positionY", - "positionZ" + "positionZ", + "rotationX", + "rotationY", + "rotationZ", + "rotationW" ] }, { @@ -213,7 +221,11 @@ "creatureTemplate", "positionX", "positionY", - "positionZ" + "positionZ", + "rotationX", + "rotationY", + "rotationZ", + "rotationW" ] }, { @@ -236,7 +248,7 @@ }, { "messageName" : "attackUpdate", - "description" : "Updates the client on the status of a given attack", + "description" : "(Deprecated) Updates the client on the status of a given attack", "data" : [ "entityID", "time", @@ -298,7 +310,11 @@ "foliageSeed", "positionX", "positionY", - "positionZ" + "positionZ", + "rotationX", + "rotationY", + "rotationZ", + "rotationW" ] }, { diff --git a/src/main/java/electrosphere/client/fluid/cells/FluidCell.java b/src/main/java/electrosphere/client/fluid/cells/FluidCell.java index 4147efe0..edf338c4 100644 --- a/src/main/java/electrosphere/client/fluid/cells/FluidCell.java +++ b/src/main/java/electrosphere/client/fluid/cells/FluidCell.java @@ -1,5 +1,6 @@ package electrosphere.client.fluid.cells; +import org.joml.Quaterniond; import org.joml.Vector3d; import org.joml.Vector3i; import org.ode4j.ode.DBody; @@ -68,7 +69,7 @@ public class FluidCell { modelEntity = FluidChunk.clientCreateFluidChunkEntity(weights); - ClientEntityUtils.initiallyPositionEntity(modelEntity, getRealPos()); + ClientEntityUtils.initiallyPositionEntity(modelEntity, getRealPos(), new Quaterniond()); } protected Vector3d getRealPos(){ diff --git a/src/main/java/electrosphere/client/terrain/cells/DrawCell.java b/src/main/java/electrosphere/client/terrain/cells/DrawCell.java index 2db4f0af..4c1069b7 100644 --- a/src/main/java/electrosphere/client/terrain/cells/DrawCell.java +++ b/src/main/java/electrosphere/client/terrain/cells/DrawCell.java @@ -1,5 +1,6 @@ package electrosphere.client.terrain.cells; +import org.joml.Quaterniond; import org.joml.Vector3d; import org.joml.Vector3i; import org.ode4j.ode.DBody; @@ -81,7 +82,7 @@ public class DrawCell { } modelEntity = TerrainChunk.clientCreateTerrainChunkEntity(chunkData, lod, atlas); - ClientEntityUtils.initiallyPositionEntity(modelEntity, getRealPos()); + ClientEntityUtils.initiallyPositionEntity(modelEntity, getRealPos(), new Quaterniond()); } /** diff --git a/src/main/java/electrosphere/entity/ClientEntityUtils.java b/src/main/java/electrosphere/entity/ClientEntityUtils.java index abdd1dd6..57f817fd 100644 --- a/src/main/java/electrosphere/entity/ClientEntityUtils.java +++ b/src/main/java/electrosphere/entity/ClientEntityUtils.java @@ -1,5 +1,6 @@ package electrosphere.entity; +import org.joml.Quaterniond; import org.joml.Vector3d; import electrosphere.entity.types.collision.CollisionObjUtils; @@ -16,9 +17,9 @@ public class ClientEntityUtils { * @param entity * @param position */ - public static void initiallyPositionEntity(Entity entity, Vector3d position){ + public static void initiallyPositionEntity(Entity entity, Vector3d position, Quaterniond rotation){ //reposition entity - CollisionObjUtils.clientPositionCharacter(entity, position); + CollisionObjUtils.clientPositionCharacter(entity, position, rotation); } /** diff --git a/src/main/java/electrosphere/entity/state/movement/groundmove/ClientGroundMovementTree.java b/src/main/java/electrosphere/entity/state/movement/groundmove/ClientGroundMovementTree.java index aeebf84c..18a69432 100644 --- a/src/main/java/electrosphere/entity/state/movement/groundmove/ClientGroundMovementTree.java +++ b/src/main/java/electrosphere/entity/state/movement/groundmove/ClientGroundMovementTree.java @@ -280,7 +280,7 @@ public class ClientGroundMovementTree implements BehaviorTree { } //we want to always update the server facing vector with where the client says they're facing EntityUtils.getRotation(parent).set(message.getrotationX(),message.getrotationY(),message.getrotationZ(),message.getrotationW()); - CollisionObjUtils.clientPositionCharacter(parent, position); + CollisionObjUtils.clientPositionCharacter(parent, position, rotation); // CreatureUtils.setFacingVector(parent, new Vector3d(message.getrotationX(),message.getrotationY(),message.getrotationZ())); break; } diff --git a/src/main/java/electrosphere/entity/types/collision/CollisionObjUtils.java b/src/main/java/electrosphere/entity/types/collision/CollisionObjUtils.java index eb4f3588..9bc35e72 100644 --- a/src/main/java/electrosphere/entity/types/collision/CollisionObjUtils.java +++ b/src/main/java/electrosphere/entity/types/collision/CollisionObjUtils.java @@ -232,6 +232,7 @@ 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); @@ -239,7 +240,7 @@ public class CollisionObjUtils { entity.putData(EntityDataStrings.PHYSICS_COLLISION_BODY, collisionObject); //update world transform of collision object - clientPositionCharacter(entity,position); + clientPositionCharacter(entity,position,rotation); entity.putData(EntityDataStrings.COLLISION_ENTITY_COLLISION_OBJECT, collisionObject); entity.putData(EntityDataStrings.COLLISION_ENTITY_COLLIDABLE, collidable); @@ -284,9 +285,8 @@ public class CollisionObjUtils { } } - public static void clientPositionCharacter(Entity e, Vector3d position){ + public static void clientPositionCharacter(Entity e, Vector3d position, Quaterniond rotation){ EntityUtils.getPosition(e).set(position); - Quaterniond rotation = EntityUtils.getRotation(e); DBody body = getCollisionBody(e); if(body != null){ PhysicsUtils.setRigidBodyTransform(Globals.clientSceneWrapper.getCollisionEngine(), position, rotation, body); diff --git a/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java b/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java index 8801c454..28c0b719 100644 --- a/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java +++ b/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java @@ -1,5 +1,6 @@ package electrosphere.entity.types.creature; +import org.joml.Quaterniond; import org.joml.Vector3d; import org.ode4j.ode.DBody; @@ -720,13 +721,19 @@ public class CreatureUtils { public static void sendEntityToPlayer(Player player, Entity creature){ int id = creature.getId(); Vector3d position = EntityUtils.getPosition(creature); + Quaterniond rotation = EntityUtils.getRotation(creature); String template = Utilities.stringify(CreatureUtils.getCreatureTemplate(creature)); NetworkMessage message = EntityMessage.constructSpawnCreatureMessage( id, template, position.x, position.y, - position.z); + position.z, + rotation.x, + rotation.y, + rotation.z, + rotation.w + ); player.addMessage(message); if(CreatureUtils.hasControllerPlayerId(creature)){ LoggerInterface.loggerNetworking.INFO("Sending controller packets"); diff --git a/src/main/java/electrosphere/entity/types/foliage/FoliageUtils.java b/src/main/java/electrosphere/entity/types/foliage/FoliageUtils.java index 67ee95f2..a602730c 100644 --- a/src/main/java/electrosphere/entity/types/foliage/FoliageUtils.java +++ b/src/main/java/electrosphere/entity/types/foliage/FoliageUtils.java @@ -18,6 +18,7 @@ import electrosphere.renderer.actor.ActorUtils; import electrosphere.server.datacell.Realm; import electrosphere.server.datacell.utils.ServerEntityTagUtils; +import org.joml.Quaterniond; import org.joml.Vector3d; /** @@ -153,6 +154,7 @@ public class FoliageUtils { int id = foliage.getId(); FoliageType type = FoliageUtils.getFoliageType(foliage); Vector3d position = EntityUtils.getPosition(foliage); + Quaterniond rotation = EntityUtils.getRotation(foliage); if(FoliageUtils.hasSeed(foliage)){ long seed = FoliageUtils.getFoliageSeed(foliage); NetworkMessage message = EntityMessage.constructSpawnFoliageSeedMessage( @@ -161,7 +163,11 @@ public class FoliageUtils { seed, position.x, position.y, - position.z + position.z, + rotation.x, + rotation.y, + rotation.z, + rotation.w ); player.addMessage(message); } else { diff --git a/src/main/java/electrosphere/entity/types/item/ItemUtils.java b/src/main/java/electrosphere/entity/types/item/ItemUtils.java index 7e95f337..5f351709 100644 --- a/src/main/java/electrosphere/entity/types/item/ItemUtils.java +++ b/src/main/java/electrosphere/entity/types/item/ItemUtils.java @@ -2,6 +2,7 @@ package electrosphere.entity.types.item; import java.util.List; +import org.joml.Quaterniond; import org.joml.Vector3d; import org.ode4j.ode.DBody; @@ -266,13 +267,19 @@ public class ItemUtils { 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); + position.z, + rotation.x, + rotation.y, + rotation.z, + rotation.w + ); player.addMessage(message); } diff --git a/src/main/java/electrosphere/entity/types/object/ObjectUtils.java b/src/main/java/electrosphere/entity/types/object/ObjectUtils.java index a206e3b4..60a32450 100644 --- a/src/main/java/electrosphere/entity/types/object/ObjectUtils.java +++ b/src/main/java/electrosphere/entity/types/object/ObjectUtils.java @@ -1,5 +1,6 @@ package electrosphere.entity.types.object; +import org.joml.Quaterniond; import org.joml.Vector3d; import org.ode4j.ode.DBody; @@ -245,13 +246,18 @@ public class ObjectUtils { 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 + position.z, + rotation.x, + rotation.y, + rotation.z, + rotation.w ); player.addMessage(message); } diff --git a/src/main/java/electrosphere/net/client/protocol/EntityProtocol.java b/src/main/java/electrosphere/net/client/protocol/EntityProtocol.java index 660b40b3..208303e6 100644 --- a/src/main/java/electrosphere/net/client/protocol/EntityProtocol.java +++ b/src/main/java/electrosphere/net/client/protocol/EntityProtocol.java @@ -94,7 +94,11 @@ public class EntityProtocol implements ClientProtocolTemplate { LoggerInterface.loggerNetworking.DEBUG("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())); + 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){ @@ -123,14 +127,22 @@ public class EntityProtocol implements ClientProtocolTemplate { String itemType = message.getcreatureTemplate(); newlySpawnedEntity = ItemUtils.clientSpawnBasicItem(itemType); //position - ClientEntityUtils.initiallyPositionEntity(newlySpawnedEntity, new Vector3d(message.getpositionX(),message.getpositionY(),message.getpositionZ())); + 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("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())); + 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: { @@ -139,7 +151,11 @@ public class EntityProtocol implements ClientProtocolTemplate { String objectType = message.getcreatureTemplate(); newlySpawnedEntity = ObjectUtils.clientSpawnBasicObject(objectType); //position - ClientEntityUtils.initiallyPositionEntity(newlySpawnedEntity, new Vector3d(message.getpositionX(),message.getpositionY(),message.getpositionZ())); + 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; 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 973797d3..fa1b6b91 100644 --- a/src/main/java/electrosphere/net/parser/net/message/EntityMessage.java +++ b/src/main/java/electrosphere/net/parser/net/message/EntityMessage.java @@ -560,6 +560,18 @@ public class EntityMessage extends NetworkMessage { 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; } @@ -571,16 +583,24 @@ public class EntityMessage extends NetworkMessage { 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){ + 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; } @@ -613,6 +633,18 @@ public class EntityMessage extends NetworkMessage { 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; } @@ -624,16 +656,24 @@ public class EntityMessage extends NetworkMessage { 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){ + 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; } @@ -666,6 +706,18 @@ public class EntityMessage extends NetworkMessage { 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; } @@ -677,16 +729,24 @@ public class EntityMessage extends NetworkMessage { 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){ + 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); rVal.setpositionZ(positionZ); + rVal.setrotationX(rotationX); + rVal.setrotationY(rotationY); + rVal.setrotationZ(rotationZ); + rVal.setrotationW(rotationW); rVal.serialize(); return rVal; } @@ -895,6 +955,18 @@ public class EntityMessage extends NetworkMessage { 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; } @@ -907,10 +979,14 @@ public class EntityMessage extends NetworkMessage { 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){ + 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); @@ -918,6 +994,10 @@ public class EntityMessage extends NetworkMessage { 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; } @@ -1039,7 +1119,7 @@ public class EntityMessage extends NetworkMessage { } break; case SPAWNCREATURE: - rawBytes = new byte[2+4+4+creatureTemplate.length()+8+8+8]; + 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 @@ -1068,9 +1148,25 @@ public class EntityMessage extends NetworkMessage { 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 SPAWNITEM: - rawBytes = new byte[2+4+4+creatureTemplate.length()+8+8+8]; + 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 @@ -1099,9 +1195,25 @@ public class EntityMessage extends NetworkMessage { 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]; + 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 @@ -1130,6 +1242,22 @@ public class EntityMessage extends NetworkMessage { 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 MOVEUPDATE: rawBytes = new byte[2+4+8+8+8+8+8+8+8+8+8+4+4]; @@ -1313,7 +1441,7 @@ public class EntityMessage extends NetworkMessage { } break; case SPAWNFOLIAGESEED: - rawBytes = new byte[2+4+4+creatureTemplate.length()+8+8+8+8]; + 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 @@ -1346,6 +1474,22 @@ public class EntityMessage extends NetworkMessage { 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]; diff --git a/src/main/java/electrosphere/net/parser/net/raw/NetworkParser.java b/src/main/java/electrosphere/net/parser/net/raw/NetworkParser.java index dcd156d7..f91afbb3 100644 --- a/src/main/java/electrosphere/net/parser/net/raw/NetworkParser.java +++ b/src/main/java/electrosphere/net/parser/net/raw/NetworkParser.java @@ -1,6 +1,6 @@ -package electrosphere.net.parser.net.raw; - -import electrosphere.net.parser.net.message.NetworkMessage; +package electrosphere.net.parser.net.raw; + +import electrosphere.net.parser.net.message.NetworkMessage; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -59,7 +59,7 @@ public class NetworkParser { for(NetworkMessage message : outgoingMessageQueue){ outgoingMessageQueue.remove(message); // System.out.println("Write message of type " + message.getType()); - outgoingStream.write(message.getRawBytes()); + outgoingStream.write(message.getRawBytes()); } }