示例#1
0
        private void GameTick(object source, ElapsedEventArgs e)
        {
            _sw.Start();

            DayTick();

            WeatherTick();

            foreach (var blockEvent in BlockWithTicks.ToArray())
            {
                if (blockEvent.Value <= CurrentWorldTime)
                {
                    var d = GetBlock(blockEvent.Key);
                    d.OnTick(this);
                    BlockWithTicks.Remove(blockEvent.Key);
                }
            }

            foreach (var player in OnlinePlayers.Values.ToArray())
            {
                player.OnTick();
            }

            foreach (var entity in Entities)
            {
                entity.OnTick();
            }

            /*if (_saveTick == 3000)
             * {
             *      _saveTick = 0;
             *      ConsoleFunctions.WriteInfoLine("Saving chunks");
             *      var sw = new Stopwatch();
             *      sw.Start();
             *      SaveChunks();
             *      sw.Stop();
             *      ConsoleFunctions.WriteInfoLine("Saving chunks took: " + sw.ElapsedMilliseconds + "MS");
             *
             *      GC.Collect(); //Collect garbage
             * }
             */

            if (_saveTick == 750)
            {
                GC.Collect();
                _saveTick = 0;
            }
            else
            {
                _saveTick++;
            }

            _sw.Stop();
            _lastCalc = _sw.ElapsedMilliseconds;
            _sw.Reset();
        }
示例#2
0
        private void GameTick(object source, ElapsedEventArgs e)
        {
            _sw.Start();

            DayTick();

            foreach (var blockEvent in BlockWithTicks.ToArray())
            {
                if (blockEvent.Value <= CurrentWorldTime)
                {
                    GetBlock(blockEvent.Key).OnTick(this);
                    int value;
                    BlockWithTicks.TryRemove(blockEvent.Key, out value);
                }
            }

            foreach (var player in OnlinePlayers.ToArray())
            {
                player.OnTick();
            }

            foreach (var entity in Entities.ToArray())
            {
                entity.OnTick();
            }

            if (_saveTick == 1500)
            {
                _saveTick = 0;
                ConsoleFunctions.WriteInfoLine("Saving chunks");
                var sw = new Stopwatch();
                sw.Start();
                SaveChunks();
                sw.Stop();
                ConsoleFunctions.WriteInfoLine("Saving chunks took: " + sw.ElapsedMilliseconds + "MS");

                ConsoleFunctions.WriteInfoLine("Clearing chunk cache...");
                Generator.ClearCache();       //Clear chunk cache
                GC.Collect();                 //Collect garbage
            }
            else
            {
                _saveTick++;
            }

            if (_saveTick == 750)
            {
                GC.Collect();
            }

            _sw.Stop();
            _lastCalc = _sw.ElapsedMilliseconds;
            _sw.Reset();
        }
示例#3
0
文件: Level.cs 项目: wgaox/MiNET
        private void WorldTick(object sender)
        {
            if (!Monitor.TryEnter(_tickSync))
            {
                return;
            }

            _tickTimer.Restart();
            try
            {
                TickTime++;

                Player[] players = GetSpawnedPlayers();

                if (IsWorldTimeStarted)
                {
                    CurrentWorldTime += 1.25;
                }
                if (CurrentWorldTime > _worldDayCycleTime)
                {
                    CurrentWorldTime = 0;
                }
                if (TickTime % 100 == 0)
                {
                    //McpeSetTime message = McpeSetTime.CreateObject();
                    //message.time = (int) CurrentWorldTime;
                    //message.started = (byte) (IsWorldTimeStarted ? 0x80 : 0x00);

                    //RelayBroadcast(players, message);
                }

                // Block updates
                foreach (KeyValuePair <BlockCoordinates, long> blockEvent in BlockWithTicks.ToArray())
                {
                    if (blockEvent.Value <= TickTime)
                    {
                        GetBlock(blockEvent.Key).OnTick(this);
                        long value;
                        BlockWithTicks.TryRemove(blockEvent.Key, out value);
                    }
                }

                // Block entity updates
                foreach (BlockEntity blockEntity in BlockEntities.ToArray())
                {
                    blockEntity.OnTick(this);
                }

                // Entity updates
                foreach (Entity entity in Entities.ToArray())
                {
                    entity.OnTick();
                }

                // Player tick
                foreach (Player player in players)
                {
                    player.OnTick();
                }

                // Send player movements
                Player[] updatedPlayers = GetUpdatedPlayers(players);
                BroadCastMovement(players, updatedPlayers);
            }
            finally
            {
                LastTickProcessingTime = _tickTimer.ElapsedMilliseconds;
                Monitor.Exit(_tickSync);
            }
        }