Exemplo n.º 1
0
        public void LoadWorld(string filename)
        {
            _loadTimer.Reset();
            _loadTimer.Start();
            _saveTimer.Stop();
            CurrentFile  = filename;
            CurrentWorld = null;
            GC.WaitForFullGCComplete();

            Task.Factory.StartNew(() => World.LoadWorld(filename))
            .ContinueWith(t => CurrentWorld = t.Result, TaskFactoryHelper.UiTaskScheduler)
            .ContinueWith(t => RenderEntireWorld())
            .ContinueWith(t =>
            {
                if (CurrentWorld != null)
                {
                    PixelMap = t.Result;
                    UpdateTitle();
                    Points.Clear();
                    Points.Add("Spawn");
                    Points.Add("Dungeon");
                    foreach (NPC npc in CurrentWorld.NPCs)
                    {
                        Points.Add(npc.Name);
                    }
                    MinimapImage = RenderMiniMap.Render(CurrentWorld);
                    _loadTimer.Stop();
                    OnProgressChanged(this, new ProgressChangedEventArgs(0,
                                                                         $"World loaded in {_loadTimer.Elapsed.TotalSeconds} seconds."));
                    _saveTimer.Start();
                }
                _loadTimer.Stop();
            }, TaskFactoryHelper.UiTaskScheduler);
        }
Exemplo n.º 2
0
 private void UpdateMinimap(object sender, EventArgs eventArgs)
 {
     if (CurrentWorld != null)
     {
         if (MinimapImage != null)
         {
             RenderMiniMap.UpdateMinimap(CurrentWorld, ref _minimapImage);
         }
     }
 }
Exemplo n.º 3
0
        private void NewWorld()
        {
            var nwDialog = new NewWorldView();

            if ((bool)nwDialog.ShowDialog())
            {
                _loadTimer.Reset();
                _loadTimer.Start();
                _saveTimer.Stop();
                Task.Factory.StartNew(() =>
                {
                    World w       = nwDialog.NewWorld;
                    w.SpawnX      = w.TilesWide / 2;
                    w.SpawnY      = (int)Math.Max(0, w.GroundLevel - 10);
                    w.GroundLevel = (int)w.GroundLevel;
                    w.RockLevel   = (int)w.RockLevel;
                    w.BottomWorld = w.TilesHigh * 16;
                    w.RightWorld  = w.TilesWide * 16;
                    w.Tiles       = new Tile[w.TilesWide, w.TilesHigh];
                    var cloneTile = new Tile();
                    for (int y = 0; y < w.TilesHigh; y++)
                    {
                        OnProgressChanged(w, new ProgressChangedEventArgs(Calc.ProgressPercentage(y, w.TilesHigh), "Generating World..."));

                        if (y == (int)w.GroundLevel - 10)
                        {
                            cloneTile = new Tile {
                                WireRed = false, IsActive = true, LiquidType = LiquidType.None, LiquidAmount = 0, Type = 2, U = -1, V = -1, Wall = 2
                            }
                        }
                        ;
                        if (y == (int)w.GroundLevel - 9)
                        {
                            cloneTile = new Tile {
                                WireRed = false, IsActive = true, LiquidType = LiquidType.None, LiquidAmount = 0, Type = 0, U = -1, V = -1, Wall = 2
                            }
                        }
                        ;
                        else if (y == (int)w.GroundLevel + 1)
                        {
                            cloneTile = new Tile {
                                WireRed = false, IsActive = true, LiquidType = LiquidType.None, LiquidAmount = 0, Type = 0, U = -1, V = -1, Wall = 0
                            }
                        }
                        ;
                        else if (y == (int)w.RockLevel)
                        {
                            cloneTile = new Tile {
                                WireRed = false, IsActive = true, LiquidType = LiquidType.None, LiquidAmount = 0, Type = 1, U = -1, V = -1, Wall = 0
                            }
                        }
                        ;
                        else if (y == w.TilesHigh - 182)
                        {
                            cloneTile = new Tile();
                        }
                        for (int x = 0; x < w.TilesWide; x++)
                        {
                            w.Tiles[x, y] = (Tile)cloneTile.Clone();
                        }
                    }
                    return(w);
                })
                .ContinueWith(t => CurrentWorld = t.Result, TaskFactoryHelper.UiTaskScheduler)
                .ContinueWith(t => RenderEntireWorld())
                .ContinueWith(t =>
                {
                    CurrentFile = null;
                    PixelMap    = t.Result;
                    UpdateTitle();
                    Points.Clear();
                    Points.Add("Spawn");
                    Points.Add("Dungeon");
                    foreach (NPC npc in CurrentWorld.NPCs)
                    {
                        Points.Add(npc.Name);
                    }
                    MinimapImage = RenderMiniMap.Render(CurrentWorld);
                    _loadTimer.Stop();
                    OnProgressChanged(this, new ProgressChangedEventArgs(0,
                                                                         $"World loaded in {_loadTimer.Elapsed.TotalSeconds} seconds."));
                    _saveTimer.Start();
                }, TaskFactoryHelper.UiTaskScheduler);
            }
        }