Beispiel #1
0
        public void Close()
        {
            //_levelTicker.Change(Timeout.Infinite, Timeout.Infinite);
            //WaitHandle waitHandle = new AutoResetEvent(false);
            //_levelTicker.Dispose(waitHandle);
            //WaitHandle.WaitAll(new[] {waitHandle}, TimeSpan.FromMinutes(2));
            //_levelTicker = null;

            _tickerHighPrecisionTimer.Dispose();

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

            Entities.Clear();

            foreach (Player player in Players.Values.ToArray())
            {
                player.Disconnect("Unexpected player lingering on close of level: " + player.Username);
            }

            Players.Clear();

            BlockEntities.Clear();

            BlockWithTicks.Clear();
            BlockWithTicks = null;
            BlockEntities  = null;
            Players        = null;
            Entities       = null;

            AnvilWorldProvider provider = _worldProvider as AnvilWorldProvider;

            if (provider != null)
            {
                foreach (var chunk in provider._chunkCache)
                {
                    chunk.Value?.ClearCache();
                }
            }

            _worldProvider = null;

            Log.Info("Closed level: " + LevelId);
        }
Beispiel #2
0
        public override void Close()
        {
            try
            {
                GameLevelTick.Dispose();
            }
            catch (Exception e)
            {
                BugSnagUtil.ReportBug(e, this);
            }

            try
            {
                GameLevelTickThread.Abort();
            }
            catch (Exception e)
            {
                BugSnagUtil.ReportBug(e, this);
            }

            try
            {
                DoForAllPlayers(player =>
                {
                    ExternalGameHandler.AddPlayer(player, "hub");
                });
            }
            catch (Exception e)
            {
                BugSnagUtil.ReportBug(e, this);
            }

            try
            {
                if (CurrentState.GetEnumState(this) != StateType.Closing)
                {
                    UpdateGameState(new VoidGameState());
                }
            }
            catch (Exception e)
            {
                BugSnagUtil.ReportBug(e, this);
            }

            try
            {
                base.Close();
            }
            catch (Exception e)
            {
                BugSnagUtil.ReportBug(e, this);
            }

            try
            {
                Plugin.Server.LevelManager.Levels.Remove(this);
            }
            catch (Exception e)
            {
                BugSnagUtil.ReportBug(e, this);
            }
        }
Beispiel #3
0
        public static void Calculate(Level level)
        {
            var chunks = level.GetLoadedChunks().OrderBy(column => column.x).ThenBy(column => column.z);

            _chunkCount = chunks.Count();

            if (_chunkCount == 0)
            {
                return;
            }

            CheckIfSpawnIsMiddle(chunks, level.SpawnPoint.GetCoordinates3D());

            Stopwatch sw = new Stopwatch();

            sw.Start();
            foreach (var pair in chunks)
            {
                pair.RecalcHeight();
            }
            Log.Debug($"Recalc height for {_chunkCount} chunks, {_chunkCount*16*16*256} blocks. Time {sw.ElapsedMilliseconds}ms");


            SkyLightCalculations calculator = new SkyLightCalculations(Config.GetProperty("CalculateLights.MakeMovie", false));

            int midX  = calculator.GetMidX(chunks.ToArray());
            int width = calculator.GetWidth(chunks.ToArray());

            sw.Restart();

            var tickerHighPrecisionTimer = new HighPrecisionTimer(100, _ => calculator.SnapshotVisits());

            calculator.StartTimeInMilliseconds = Environment.TickCount;

            var t0 = Task.Run(() =>
            {
                var pairs = chunks.OrderBy(pair => pair.x).ThenBy(pair => pair.z).Where(chunk => chunk.x <= midX).OrderByDescending(pair => pair.x).ThenBy(pair => pair.z).ToArray();
                calculator.CalculateSkyLights(level, pairs);
            });

            var t5 = Task.Run(() =>
            {
                var pairs = chunks.OrderByDescending(pair => pair.x).ThenBy(pair => pair.z).Where(chunk => chunk.x > midX).OrderBy(pair => pair.x).ThenByDescending(pair => pair.z).ToArray();
                calculator.CalculateSkyLights(level, pairs);
            });

            var t1 = Task.Run(() =>
            {
                var pairs = chunks.OrderBy(pair => pair.x).ThenBy(pair => pair.z).ToArray();
                calculator.CalculateSkyLights(level, pairs);
            });

            var t2 = Task.Run(() =>
            {
                var pairs = chunks.OrderByDescending(pair => pair.x).ThenByDescending(pair => pair.z).ToArray();
                calculator.CalculateSkyLights(level, pairs);
            });

            var t3 = Task.Run(() =>
            {
                var pairs = chunks.OrderByDescending(pair => pair.x).ThenBy(pair => pair.z).ToArray();
                calculator.CalculateSkyLights(level, pairs);
            });

            var t4 = Task.Run(() =>
            {
                var pairs = chunks.OrderBy(pair => pair.x).ThenByDescending(pair => pair.z).ToArray();
                calculator.CalculateSkyLights(level, pairs);
            });

            Task.WaitAll(t0, t1, t2, t3, t4, t5);

            Log.Debug($"Recalc skylight for {_chunkCount}({_chunkCount}) chunks, {_chunkCount*16*16*256:N0} blocks. Time {sw.ElapsedMilliseconds}ms");

            Task.Run(() =>
            {
                tickerHighPrecisionTimer.Dispose();
                calculator.SnapshotVisits();
                calculator.SnapshotVisits();


                // Start with an end-frame (twitter thumbs)
                var last = calculator.RenderingTasks.Last();
                calculator.RenderingTasks.Remove(last);
                calculator.RenderingTasks.Insert(0, last);

                calculator.RenderVideo();

                Log.Debug($"Movie rendered.");
            });

            //foreach (var chunk in chunks)
            //{
            //	calculator.ShowHeights(chunk);
            //}

            //var chunkColumn = chunks.First(column => column.x == -1 && column.z == 0 );
            //if (chunkColumn != null)
            //{
            //	Log.Debug($"Heights:\n{Package.HexDump(chunkColumn.height)}");
            //	Log.Debug($"skylight.Data:\n{Package.HexDump(chunkColumn.skyLight.Data, 64)}");
            //}
        }
 public void Close()
 {
     GameTick.Dispose();
     GameTickThread.Abort();
 }