Example #1
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();
        }