Esempio n. 1
0
        /// <summary>
        /// 初始化Mod
        /// </summary>
        /// <param name="mode"></param>
        /// <param name="args"></param>
        public void InitializeMod(string mod, Arguments args)
        {
            if (ModData != null)
            {
                ModData = null;
            }

            if (worldRenderer != null)
            {
                worldRenderer.Dispose();
            }
            worldRenderer = null;

            if (orderManager != null)
            {
                orderManager.Dispose();
            }

            if (ModData != null)
            {
                ModData.ModFiles.UnmountAll();
                ModData.Dispose();
            }

            if (mod == null)
            {
                throw new InvalidOperationException("Game.Mod argument missing.");
            }

            if (!Mods.ContainsKey(mod))
            {
                throw new InvalidOperationException("Unknown or invalid mod '{0}'.".F(mod));
            }

            Renderer = new Renderer(Settings.Graphics, GraphicsDevice);
            Sound    = new Sound(Settings.Sound);
            Sound.StopVideo();
            ModData = new ModData(Mods[mod], Mods, true);

            using (new Support.PerfTimer("LoadMaps"))
                ModData.MapCache.LoadMaps();

            ModData.InitializeLoaders(ModData.DefaultFileSystem);
            Renderer.InitializeFont(ModData);
            var grid = ModData.Manifest.Contains <MapGrid>() ? ModData.Manifest.Get <MapGrid>() : null;

            Renderer.InitializeDepthBuffer(grid);


            PerfHistory.Items["render"].HasNormalTick         = false;
            PerfHistory.Items["batches"].HasNormalTick        = false;
            PerfHistory.Items["render_widgets"].HasNormalTick = false;
            PerfHistory.Items["render_flip"].HasNormalTick    = false;

            JoinLocal();

            ModData.LoadScreen.StartGame(args);
        }
Esempio n. 2
0
        internal static void StartGame(string mapUID, WorldType type)
        {
            // Dispose of the old world before creating a new one.
            worldRenderer?.Dispose();

            Cursor.SetCursor(null);
            BeforeGameStart();

            Map map;

            using (new PerfTimer("PrepareMap"))
                map = ModData.PrepareMap(mapUID);

            using (new PerfTimer("NewWorld"))
            {
                OrderManager.World       = new World(ModData, map, OrderManager, type);
                OrderManager.FramesAhead = OrderManager.World.OrderLatency;
            }

            OrderManager.World.GameOver += FinishBenchmark;

            worldRenderer = new WorldRenderer(ModData, OrderManager.World);

            // Proactively collect memory during loading to reduce peak memory.
            GC.Collect();

            using (new PerfTimer("LoadComplete"))
                OrderManager.World.LoadComplete(worldRenderer);

            // Proactively collect memory during loading to reduce peak memory.
            GC.Collect();

            if (OrderManager.GameStarted)
            {
                return;
            }

            Ui.MouseFocusWidget    = null;
            Ui.KeyboardFocusWidget = null;

            OrderManager.LocalFrameNumber = 0;
            OrderManager.LastTickTime     = RunTime;
            OrderManager.StartGame();
            worldRenderer.RefreshPalette();
            Cursor.SetCursor(ChromeMetrics.Get <string>("DefaultCursor"));

            // Now loading is completed, now is the ideal time to run a GC and compact the LOH.
            // - All the temporary garbage created during loading can be collected.
            // - Live objects are likely to live for the length of the game or longer,
            //   thus promoting them into a higher generation is not an issue.
            // - We can remove any fragmentation in the LOH caused by temporary loading garbage.
            // - A loading screen is visible, so a delay won't matter to the user.
            //   Much better to clean up now then to drop frames during gameplay for GC pauses.
            GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
            GC.Collect();
        }
Esempio n. 3
0
        internal static void StartGame(string mapUID, WorldType type)
        {
            // Dispose of the old world before creating a new one.
            if (worldRenderer != null)
            {
                worldRenderer.Dispose();
            }

            Cursor.SetCursor(null);
            BeforeGameStart();

            Map map;

            using (new PerfTimer("PrepareMap"))
                map = ModData.PrepareMap(mapUID);
            using (new PerfTimer("NewWorld"))
                OrderManager.World = new World(ModData, map, OrderManager, type);

            OrderManager.World.GameOver += FinishBenchmark;

            worldRenderer = new WorldRenderer(ModData, OrderManager.World);

            GC.Collect();

            using (new PerfTimer("LoadComplete"))
                OrderManager.World.LoadComplete(worldRenderer);

            // Create a Http server and start listening for incoming connections
            // Handle requests
            if (OrderManager.World.LocalPlayer != null && HttpServer.Listener == null)
            {
                HttpServer.Listener = new HttpListener();
                HttpServer.Listener.Prefixes.Add(HttpServer.Url);
                HttpServer.Listener.Start();
                Console.WriteLine("Listening for connections on {0}", HttpServer.Url);
                HttpServer.HandleIncomingConnections();
            }

            GC.Collect();

            if (OrderManager.GameStarted)
            {
                return;
            }

            Ui.MouseFocusWidget    = null;
            Ui.KeyboardFocusWidget = null;

            OrderManager.LocalFrameNumber = 0;
            OrderManager.LastTickTime     = RunTime;
            OrderManager.StartGame();
            worldRenderer.RefreshPalette();
            Cursor.SetCursor("default");

            GC.Collect();
        }
Esempio n. 4
0
        internal static void StartGame(string mapUID, WorldType type)
        {
            // Dispose of the old world before creating a new one.
            if (worldRenderer != null)
            {
                worldRenderer.Dispose();
            }

            Cursor.SetCursor(null);
            BeforeGameStart();

            Map map;

            using (new PerfTimer("PrepareMap"))
                map = ModData.PrepareMap(mapUID);
            using (new PerfTimer("NewWorld"))
                OrderManager.World = new World(ModData, map, OrderManager, type);

            ChromeProvider.World = OrderManager.World;             // для доступа к текстурам из seq/*.yaml

            OrderManager.World.GameOver += FinishBenchmark;

            worldRenderer = new WorldRenderer(ModData, OrderManager.World);

            GC.Collect();

            using (new PerfTimer("LoadComplete"))
                OrderManager.World.LoadComplete(worldRenderer);

            GC.Collect();

            if (OrderManager.GameStarted)
            {
                return;
            }

            Ui.MouseFocusWidget    = null;
            Ui.KeyboardFocusWidget = null;

            OrderManager.LocalFrameNumber = 0;
            OrderManager.LastTickTime     = RunTime;
            OrderManager.StartGame();
            worldRenderer.RefreshPalette();
            Cursor.SetCursor("default");

            GC.Collect();
        }
Esempio n. 5
0
        internal static void StartGame(string mapUID, WorldType type)
        {
            // Dispose of the old world before creating a new one.
            if (worldRenderer != null)
            {
                worldRenderer.Dispose();
            }

            BeforeGameStart();

            Map map;

            using (new PerfTimer("PrepareMap"))
                map = ModData.PrepareMap(mapUID);
            using (new PerfTimer("NewWorld"))
                OrderManager.World = new World(ModData, map, OrderManager, type);

            worldRenderer = new WorldRenderer(ModData, OrderManager.World);

            GC.Collect();

            using (new PerfTimer("LoadComplete"))
                OrderManager.World.LoadComplete(worldRenderer);

            GC.Collect();

            if (OrderManager.GameStarted)
            {
                return;
            }

            Ui.MouseFocusWidget    = null;
            Ui.KeyboardFocusWidget = null;

            OrderManager.LocalFrameNumber = 0;
            OrderManager.LastTickTime     = RunTime;
            OrderManager.StartGame();
            worldRenderer.RefreshPalette();

            GC.Collect();
        }
Esempio n. 6
0
        internal static void StartGame(string mapUID, WorldType type)
        {
            Cursor.SetCursor(null);
            BeforeGameStart();

            Map map;

            using (new PerfTimer("PrepareMap"))
                map = ModData.PrepareMap(mapUID);
            using (new PerfTimer("NewWorld"))
            {
                OrderManager.World          = new World(map, OrderManager, type);
                OrderManager.World.Timestep = Timestep;
            }

            if (worldRenderer != null)
            {
                worldRenderer.Dispose();
            }

            worldRenderer = new WorldRenderer(OrderManager.World);

            using (new PerfTimer("LoadComplete"))
                OrderManager.World.LoadComplete(worldRenderer);

            if (OrderManager.GameStarted)
            {
                return;
            }

            Ui.MouseFocusWidget    = null;
            Ui.KeyboardFocusWidget = null;

            OrderManager.LocalFrameNumber = 0;
            OrderManager.LastTickTime     = RunTime;
            OrderManager.StartGame();
            worldRenderer.RefreshPalette();
            Cursor.SetCursor("default");

            GC.Collect();
        }
Esempio n. 7
0
        public void Dispose()
        {
            textRenderer?.Dispose();
            spriteBatch?.Dispose();

            (userInterface as IDisposable)?.Dispose();

            worldRenderer?.Dispose();

            worldProgram?.Dispose();
            blockTextureAtlas?.Dispose();

            window.Dispose();
        }
Esempio n. 8
0
 protected override void DisposeManaged()
 {
     base.DisposeManaged();
     buffers?.Dispose();
     renderer?.Dispose();
 }