Esempio n. 1
0
        protected virtual void Dispose(bool disposing)
        {
            if (!IsDisposed)
            {
                if (disposing)
                {
                    XNAGameWrapper.Dispose();
                }

                IsRunning  = false;
                IsDisposed = true;
            }
        }
Esempio n. 2
0
        private void Setup(string title, int windowWidth, int windowHeight, float pixelScale, int targetFramerate, bool fullscreen, bool vsync)
        {
            Instance = this;

            // start core systems
            Logger.Initialize();

#if DEBUG
            Debug.Start();

            try {
                System.Console.Title = "Raccoon Debug";
            } catch {
            }
#endif

            System.AppDomain.CurrentDomain.UnhandledException += (object sender, System.UnhandledExceptionEventArgs args) => {
                Logger.ClearSubjects();
                System.Exception e = (System.Exception)args.ExceptionObject;

                using (StreamWriter logWriter = new StreamWriter($"crash-report.log", append: false)) {
                    logWriter.WriteLine($"Operating System: {System.Environment.OSVersion} ({(System.Environment.Is64BitOperatingSystem ? "x64" : "x86")})");
                    logWriter.WriteLine($"CLR Runtime Version: {System.Environment.Version}");
                    logWriter.WriteLine($"Command Line: {System.Environment.CommandLine}\n\n");
                    try {
                        OnCrash?.Invoke(logWriter);
                    } catch (System.Exception onCrashException) {
                        logWriter.WriteLine($"Game.OnCrash raised an exception: {onCrashException.Message}\n{onCrashException.StackTrace}\n\n");
                    }

                    logWriter.WriteLine($"\n{System.DateTime.Now.ToString()}  {e.Message}\n{e.StackTrace}\n");

                    while (e.InnerException != null)
                    {
                        e = e.InnerException;
                        logWriter.WriteLine($"{System.DateTime.Now.ToString()}  InnerException: {e.Message}\n{e.StackTrace}\n");
                    }

                    // include report.log
                    string reportLogFilepath = Path.Combine(System.Environment.CurrentDirectory, Debug.LogFileName);
                    logWriter.WriteLine($"\n\nreport.log\n-------------\n{reportLogFilepath}\n-------------\n");

                    if (File.Exists(reportLogFilepath))
                    {
                        logWriter.WriteLine(File.ReadAllText(reportLogFilepath));
                    }
                    else
                    {
                        logWriter.WriteLine($"  No 'report.log' file found. (At: {reportLogFilepath})");
                    }
                }

                switch (System.Environment.OSVersion.Platform)
                {
                case System.PlatformID.Win32NT:
                    System.Diagnostics.Process.Start("notepad.exe", "crash-report.log");
                    break;

                default:
                    break;
                }
            };

            // fps
            TargetFramerate = targetFramerate;

            // pixel
            _pixelScale = pixelScale < Math.Epsilon ? Math.Epsilon : pixelScale;

            // wrapper
            XNAGameWrapper = new XNAGameWrapper(windowWidth, windowHeight, TargetFramerate, fullscreen, vsync, InternalLoadContent, InternalUnloadContent, InternalUpdate, InternalDraw);
            XNAGameWrapper.Content.RootDirectory = Path.Combine(System.Environment.CurrentDirectory, "Content/");
            Title = title;

            // background
            BackgroundColor = Color.Black;

            // events
            XNAGameWrapper.Activated   += Activated;
            XNAGameWrapper.Deactivated += Deactivated;
            XNAGameWrapper.Disposed    += Disposed;
            XNAGameWrapper.Exiting     += Exiting;
            XNAGameWrapper.GraphicsDeviceManager.DeviceReset += GraphicsDeviceReset;

            // window and game internal size
            WindowSize   = new Size(windowWidth, windowHeight);
            WindowCenter = new Vector2(windowWidth / 2f, windowHeight / 2f);
            Size         = new Size(windowWidth, windowHeight) / PixelScale;
            Center       = (Size / 2f).ToVector2();

            OnBeforeUpdate = () => {
                if (NextScene == Scene)
                {
                    return;
                }

                UpdateCurrentScene();
            };

            // systems
            Input.Input.Initialize();
        }
Esempio n. 3
0
 public void Exit()
 {
     Debug.WriteLine("Exiting...");
     IsRunning = false;
     XNAGameWrapper.Exit();
 }
Esempio n. 4
0
 public void Start()
 {
     Logger.Info("| Raccoon Started |");
     IsRunning = true;
     XNAGameWrapper.Run();
 }