Ejemplo n.º 1
0
        public override void ReadPacket()
        {
            SequenceNumber = ReadUShort();

            // Read the byte flag representing update types and reconstruct it
            var updateTypeFlag = ReadByte();
            // Keep track of value of current bit
            var currentTypeValue = 1;

            for (var i = 0; i < (int)UpdateType.Count; i++)
            {
                // If this bit was set in our flag, we add the type to the list
                if ((updateTypeFlag & currentTypeValue) != 0)
                {
                    UpdateTypes.Add((UpdateType)currentTypeValue);
                }

                // Increase the value of current bit
                currentTypeValue *= 2;
            }

            // Based on the update types, we read the corresponding values
            if (UpdateTypes.Contains(UpdateType.PlayerUpdate))
            {
                // First we read the length of the player update list
                var numPlayerUpdates = ReadByte();

                // Then we read all the values into PlayerUpdate instances
                for (var i = 0; i < numPlayerUpdates; i++)
                {
                    // We create a new instance
                    var playerUpdate = new PlayerUpdate();

                    // Read the information into the new instance
                    ReadPlayerUpdate(playerUpdate);

                    // Add the instance to the list
                    PlayerUpdates.Add(playerUpdate);
                }
            }

            if (UpdateTypes.Contains(UpdateType.EntityUpdate))
            {
                // First we read the length of the entity update list
                var numEntityUpdates = ReadByte();

                // Then we read all the values into the EntityUpdates dictionary
                for (var i = 0; i < numEntityUpdates; i++)
                {
                    // Create a new EntityUpdate instance
                    var entityUpdate = new EntityUpdate();

                    // Read the values into the instance
                    ReadEntityUpdate(entityUpdate);

                    // Add it to the list
                    EntityUpdates.Add(entityUpdate);
                }
            }
        }
Ejemplo n.º 2
0
    public bool Register(myUpdate update)
    {
        switch (update.GetUpdateType())
        {
        case myUpdate.UpdateType.GUI:
            GUIUpdates.Add(update.GetPriorityInType(), update);
            return(true);

        case myUpdate.UpdateType.Map:
            MapUpdates.Add(update.GetPriorityInType(), update);
            return(true);

        case myUpdate.UpdateType.PoolThing:
            //储存引用
            SortedList <int, myUpdate> temp;
            //看看有没有这个id
            if (PoolThingUpdates.TryGetValue(update.gameObject.GetInstanceID(), out temp))
            {
                //如果有,则将这个组件加入到对应敌人的更新队列中去
                temp.Add(update.GetPriorityInType(), update);
            }
            else
            {
                //如果没有,增加这个敌人的队列,并且把这个组件加入进去
                temp = new SortedList <int, myUpdate>();
                temp.Add(update.GetPriorityInType(), update);
                PoolThingUpdates.Add(update.gameObject.GetInstanceID(), temp);
            }

            return(true);

        case myUpdate.UpdateType.Player:
            PlayerUpdates.Add(update.GetPriorityInType(), update);
            return(true);

        case myUpdate.UpdateType.Enemy:
            //储存引用
            SortedList <int, myUpdate> temp1;
            //看看有没有这个id
            if (EnemyUpdates.TryGetValue(update.gameObject.GetInstanceID(), out temp1))
            {
                //如果有,则将这个组件加入到对应敌人的更新队列中去
                temp1.Add(update.GetPriorityInType(), update);
            }
            else
            {
                //如果没有,增加这个敌人的队列,并且把这个组件加入进去
                temp1 = new SortedList <int, myUpdate>();
                temp1.Add(update.GetPriorityInType(), update);
                EnemyUpdates.Add(update.gameObject.GetInstanceID(), temp1);
            }

            return(true);
        }
        return(false);
    }