Esempio n. 1
0
        /// <summary>
        /// Create a new piece of GameData from a byte array representation.
        /// </summary>
        /// <param name="byteArray">A byte array to create a GameData packet from.</param>
        public GameData(byte[] byteArray)
        {
            using (MemoryStream memoryStream = new MemoryStream(byteArray))
            {
                using (BinaryReader binaryReader = new BinaryReader(memoryStream))
                {
                    Type = (GameDataType)binaryReader.ReadByte();
                    PlayerID = (int)binaryReader.ReadByte();
                    EventDetail = (int)binaryReader.ReadByte();

                    byte[] subData  = new byte[byteArray.Length - 3];
                    Array.ConstrainedCopy(byteArray, 3, subData, 0, byteArray.Length - 3);

                    if (Type == GameDataType.Movement)
                    {
                        TransformData = new TransformData(subData);
                    }
                    else if (Type == GameDataType.NewEntity)
                    {
                        EntityData = new EntityData(subData);
                    }
                    else if (Type == GameDataType.EntityStateChange)
                    {
                        EntityStateData = new EntityStateData(subData);
                    }
                }
            }

            return;
        }
Esempio n. 2
0
 /// <summary>
 /// Create a new GameData packet.
 /// </summary>
 /// <param name="gameDataType">The type associated with this packet.</param>
 /// <param name="playerId">The id of the player that performed the action.</param>
 /// <param name="eventDetail">The extra detail associated with this event.</param>
 public GameData(GameDataType gameDataType, int playerId = 0, int eventDetail = 0, TransformData transformData = null, EntityData entityData = null)
 {
     Type = gameDataType;
     PlayerID = playerId;
     EventDetail = eventDetail;
     TransformData = transformData;
     EntityData = entityData;
     return;
 }
Esempio n. 3
0
 /// <summary>
 /// Reconstruct the Class from Network
 /// </summary>
 /// <param name="data"></param>
 public EntityData(byte[] data)
 {
     using (MemoryStream memoryStream = new MemoryStream(data))
     {
         using (BinaryReader binaryReader = new BinaryReader(memoryStream))
         {
             type = (EntityType)binaryReader.ReadInt32();
             int entityID = (int)binaryReader.ReadInt32();
             float[] matrix = new float[16];
             Matrix Matrix;
             for (int i = 0; i < 16; i++)
             {
                 matrix[i] = (float)binaryReader.ReadDouble();
             }
             Matrix = new Matrix(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5], matrix[6], matrix[7], matrix[8], matrix[9], matrix[10], matrix[11], matrix[12], matrix[13], matrix[14], matrix[15]);
             transformData = new TransformData(entityID, Matrix);
         }
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Update an entity based on a transform.
        /// </summary>
        /// <param name="entity">The entity to update.</param>
        public virtual void OnTransformChange(Entity entity)
        {
            // Generate a transform change packet, put it on stack
            TransformData transformData = new TransformData(entity.id, entity.transform);

            // TODO: This likely doesn't work. This neeeds to be fixed (the player ID and event detail might need changing, or we may simply need a new constructor).
            GameData gameData = new GameData(GameData.GameDataType.Movement, LocalPlayer.PlayerID, 0, transformData);

            lock (gameStatesToSend)
            {
                gameStatesToSend.Add(gameData);
            }
            return;
        }
Esempio n. 5
0
 /// <summary>
 /// Convinience Constructor to Marshal Matrix
 /// </summary>
 /// <param name="ID"></param>
 /// <param name="matrix"></param>
 public EntityData(EntityType type, int id, Matrix matrix)
 {
     this.type = type;
     this.transformData = new TransformData(id, matrix);
 }