Esempio n. 1
0
        public void ProcessUpdates()
        {
            if (World.IsLocked)
            {
                if (World.PendingUnload)
                {
                    World.UnloadMap(true);
                }
                return;
            }

            int         packetsSent         = 0;
            int         maxPacketsPerUpdate = Server.CalculateMaxPacketsPerUpdate(World);
            BlockUpdate update = new BlockUpdate();

            while (packetsSent < maxPacketsPerUpdate)
            {
                if (!updates.Dequeue(ref update))
                {
                    if (World.IsFlushing)
                    {
                        World.EndFlushMapBuffer();
                    }
                    break;
                }
                ChangedSinceSave = true;
                if (!InBounds(update.X, update.Y, update.H))
                {
                    continue;
                }
                int blockIndex = Index(update.X, update.Y, update.H);
                Blocks[blockIndex] = update.BlockType; // TODO: investigate IndexOutOfRangeException here

                if (!World.IsFlushing)
                {
                    World.SendToAllDelayed(PacketWriter.MakeSetBlock(update.X, update.Y, update.H, update.BlockType), update.Origin);
                }
                packetsSent++;
            }

            if (packetsSent == 0 && World.PendingUnload)
            {
                World.UnloadMap(true);
            }
        }
Esempio n. 2
0
        // Applies pending updates and sends them to players (if applicable).
        internal void ProcessUpdates()
        {
            if (World == null)
            {
                throw new InvalidOperationException("Map must be assigned to a world to process updates.");
            }

            if (World.IsLocked)
            {
                if (World.IsPendingMapUnload)
                {
                    World.UnloadMap(true);
                }
                return;
            }

            int         packetsSent         = 0;
            bool        canFlush            = false;
            int         maxPacketsPerUpdate = Server.CalculateMaxPacketsPerUpdate(World);
            BlockUpdate update = new BlockUpdate();

            while (packetsSent < maxPacketsPerUpdate)
            {
                if (!updates.Dequeue(ref update))
                {
                    if (World.IsFlushing)
                    {
                        canFlush = true;
                    }
                    break;
                }
                HasChangedSinceSave = true;
                compressedCopyCache = null;
                if (!InBounds(update.X, update.Y, update.Z))
                {
                    continue;
                }
                int blockIndex = Index(update.X, update.Y, update.Z);
                Blocks[blockIndex] = (byte)update.BlockType;

                if (!World.IsFlushing)
                {
                    Packet packet = PacketWriter.MakeSetBlock(update.X, update.Y, update.Z, update.BlockType);
                    World.Players.SendLowPriority(update.Origin, packet);
                }
                packetsSent++;
            }

            if (drawOps.Count > 0)
            {
                lock ( drawOpLock ) {
                    if (drawOps.Count > 0)
                    {
                        packetsSent += ProcessDrawOps(maxPacketsPerUpdate - packetsSent);
                    }
                }
            }
            else if (canFlush)
            {
                World.EndFlushMapBuffer();
            }

            if (packetsSent == 0 && World.IsPendingMapUnload)
            {
                World.UnloadMap(true);
            }
        }
Esempio n. 3
0
        // Applies pending updates and sends them to players (if applicable).
        internal void ProcessUpdates()
        {
            if (World == null)
            {
                throw new InvalidOperationException("Map must be assigned to a world to process updates.");
            }

            if (World.IsLocked)
            {
                if (World.IsPendingMapUnload)
                {
                    World.UnloadMap(true);
                }
                return;
            }

            int  packetsSent         = 0;
            bool canFlush            = false;
            int  maxPacketsPerUpdate = Server.CalculateMaxPacketsPerUpdate(World);

            while (packetsSent < maxPacketsPerUpdate)
            {
                BlockUpdate update;
                if (!updates.TryDequeue(out update))
                {
                    if (World.IsFlushing)
                    {
                        canFlush = true;
                    }
                    break;
                }
                if (!InBounds(update.X, update.Y, update.Z))
                {
                    continue;
                }
                int blockIndex = Index(update.X, update.Y, update.Z);
                Blocks[blockIndex] = (byte)update.BlockType;

                if (!World.IsFlushing)
                {
                    //non classicube players get fallbacks instead of the real blocks
                    Packet packet  = PacketWriter.MakeSetBlock(update.X, update.Y, update.Z, update.BlockType);
                    Packet packet2 = PacketWriter.MakeSetBlock(update.X, update.Y, update.Z, Map.GetFallbackBlock(update.BlockType));

                    World.Players.Where(p => p.usesCPE).SendLowPriority(update.Origin, packet);
                    World.Players.Where(p => !p.usesCPE).SendLowPriority(update.Origin, packet2);
                }
                packetsSent++;
            }

            if (drawOps.Count > 0)
            {
                lock ( drawOpLock ) {
                    if (drawOps.Count > 0)
                    {
                        packetsSent += ProcessDrawOps(maxPacketsPerUpdate - packetsSent);
                    }
                }
            }
            else if (canFlush)
            {
                World.EndFlushMapBuffer();
            }

            if (packetsSent == 0 && World.IsPendingMapUnload)
            {
                World.UnloadMap(true);
            }
        }
Esempio n. 4
0
        // Applies pending updates and sends them to players (if applicable).
        internal void ProcessUpdates()
        {
            if (World == null)
            {
                throw new InvalidOperationException("Map must be assigned to a world to process updates.");
            }

            if (World.IsLocked)
            {
                if (World.IsPendingMapUnload)
                {
                    World.UnloadMap(true);
                }
                return;
            }

            int         packetsSent         = 0;
            bool        canFlush            = false;
            int         maxPacketsPerUpdate = Server.CalculateMaxPacketsPerUpdate(World);
            BlockUpdate update = new BlockUpdate();

            while (packetsSent < maxPacketsPerUpdate)
            {
                if (!updates.TryDequeue(out update))
                {
                    if (World.IsFlushing)
                    {
                        canFlush = true;
                    }
                    break;
                }

                HasChangedSinceSave = true;
                if (!InBounds(update.X, update.Y, update.Z))
                {
                    continue;
                }
                int blockIndex = Index(update.X, update.Y, update.Z);
                Blocks[blockIndex] = (byte)update.BlockType;

                if (!World.IsFlushing)
                {
                    Player[] players = World.Players;
                    for (int i = 0; i < players.Length; i++)
                    {
                        Player p = players[i];
                        if (p == update.Origin)
                        {
                            continue;
                        }
                        p.SendBlock(new Vector3I(update.X, update.Y, update.Z), update.BlockType);
                    }
                }
                packetsSent++;
            }

            if (drawOps.Count > 0)
            {
                lock ( drawOpLock ) {
                    if (drawOps.Count > 0)
                    {
                        packetsSent += ProcessDrawOps(maxPacketsPerUpdate - packetsSent);
                    }
                }
            }
            else if (canFlush)
            {
                World.EndFlushMapBuffer();
            }

            if (packetsSent == 0 && World.IsPendingMapUnload)
            {
                World.UnloadMap(true);
            }
        }