示例#1
0
        public static void Run()
        {
            VrManager.WaitGetPoses();
            double realTime = Time.RealTime;

            LastFrameTime               = (float)(realTime - m_frameBeginTime);
            LastCpuFrameTime            = (float)(m_cpuEndTime - m_frameBeginTime);
            m_frameBeginTime            = realTime;
            Window.PresentationInterval = ((!VrManager.IsVrStarted) ? SettingsManager.PresentationInterval : 0);
            try
            {
                if (ExceptionManager.Error == null)
                {
                    while (m_urisToHandle.Count > 0)
                    {
                        Uri obj = m_urisToHandle[0];
                        m_urisToHandle.RemoveAt(0);
                        Program.HandleUri?.Invoke(obj);
                    }
                    PerformanceManager.Update();
                    MotdManager.Update();
                    MusicManager.Update();
                    ScreensManager.Update();
                    DialogsManager.Update();
                }
                else
                {
                    ExceptionManager.UpdateExceptionScreen();
                }
            }
            catch (Exception e)
            {
                ExceptionManager.ReportExceptionToUser(null, e);
                ScreensManager.SwitchScreen("MainMenu");
            }
            try
            {
                Display.RenderTarget = null;
                if (ExceptionManager.Error == null)
                {
                    ScreensManager.Draw();
                    PerformanceManager.Draw();
                    ScreenCaptureManager.Run();
                }
                else
                {
                    ExceptionManager.DrawExceptionScreen();
                }
                m_cpuEndTime = Time.RealTime;
            }
            catch (Exception e2)
            {
                ExceptionManager.ReportExceptionToUser(null, e2);
                ScreensManager.SwitchScreen("MainMenu");
            }
        }
示例#2
0
 public static void Capture(int width, int height, string filename)
 {
     if (GameManager.Project != null)
     {
         using (RenderTarget2D renderTarget2D = new RenderTarget2D(width, height, 1, ColorFormat.Rgba8888, DepthFormat.Depth24Stencil8))
         {
             RenderTarget2D renderTarget = Display.RenderTarget;
             Dictionary <ComponentGui, bool> dictionary = new Dictionary <ComponentGui, bool>();
             ResolutionMode resolutionMode = ResolutionMode.High;
             try
             {
                 if (!SettingsManager.ShowGuiInScreenshots)
                 {
                     foreach (ComponentPlayer componentPlayer in GameManager.Project.FindSubsystem <SubsystemPlayers>(throwOnError: true).ComponentPlayers)
                     {
                         dictionary[componentPlayer.ComponentGui] = componentPlayer.ComponentGui.ControlsContainerWidget.IsVisible;
                         componentPlayer.ComponentGui.ControlsContainerWidget.IsVisible = false;
                     }
                 }
                 resolutionMode = SettingsManager.ResolutionMode;
                 SettingsManager.ResolutionMode = ResolutionMode.High;
                 Display.RenderTarget           = renderTarget2D;
                 ScreensManager.Draw();
                 if (SettingsManager.ShowLogoInScreenshots)
                 {
                     PrimitivesRenderer2D primitivesRenderer2D = new PrimitivesRenderer2D();
                     Texture2D            texture2D            = ContentManager.Get <Texture2D>("Textures/Gui/ScreenCaptureOverlay");
                     Vector2 vector = new Vector2((width - texture2D.Width) / 2, 0f);
                     Vector2 corner = vector + new Vector2(texture2D.Width, texture2D.Height);
                     primitivesRenderer2D.TexturedBatch(texture2D, useAlphaTest: false, 0, DepthStencilState.None).QueueQuad(vector, corner, 0f, new Vector2(0f, 0f), new Vector2(1f, 1f), Engine.Color.White);
                     primitivesRenderer2D.Flush();
                 }
             }
             finally
             {
                 Display.RenderTarget = renderTarget;
                 foreach (KeyValuePair <ComponentGui, bool> item in dictionary)
                 {
                     item.Key.ControlsContainerWidget.IsVisible = item.Value;
                 }
                 SettingsManager.ResolutionMode = resolutionMode;
             }
             if (!Storage.DirectoryExists(ModsManager.baseDir + "/ScreenCapture"))
             {
                 Storage.CreateDirectory(ModsManager.baseDir + "/ScreenCapture");
             }
             string path = Storage.CombinePaths(Storage.GetSystemPath(ModsManager.baseDir + "/ScreenCapture"), filename);
             using (FileStream stream = new FileStream(path, FileMode.Create))
             {
                 byte[] array = new byte[4 * renderTarget2D.Width * renderTarget2D.Height];
                 renderTarget2D.GetData(array, 0, new Rectangle(0, 0, renderTarget2D.Width, renderTarget2D.Height));
                 ByteBuffer src    = ByteBuffer.Wrap(array);
                 Bitmap     bitmap = Bitmap.CreateBitmap(renderTarget2D.Width, renderTarget2D.Height, Bitmap.Config.Argb8888);
                 bitmap.CopyPixelsFromBuffer(src);
                 bitmap.Compress(Bitmap.CompressFormat.Png, 100, stream);
             }
             Intent intent = new Intent("android.intent.action.MEDIA_SCANNER_SCAN_FILE");
             intent.SetData(Android.Net.Uri.FromFile(new Java.IO.File(path)));
             Window.Activity.SendBroadcast(intent);
         }
     }
 }