Ejemplo n.º 1
0
        void LoaderThread()
        {
            Profiler.SetThread();
            Game.SetThreadLanguage();

            while (true)
            {
                // Wait for a new Update() command
                State.WaitTillStarted();
                if (State.Terminated)
                {
                    break;
                }
                try
                {
                    if (!DoLoad())
                    {
                        return;
                    }
                }
                finally
                {
                    // Signal finished so RenderProcess can start drawing
                    State.SignalFinish();
                }
            }
        }
Ejemplo n.º 2
0
        public static float[] ShadowMapLimit;  // diameter of shadow map far edge from camera

        internal RenderProcess(Game game)
        {
            this.game = game;
            gameForm  = (Form)Control.FromHandle(game.Window.Handle);

            watchdogToken = new WatchdogToken(System.Threading.Thread.CurrentThread);

            Profiler = new Profiler("Render");
            Profiler.SetThread();
            game.SetThreadLanguage();

            game.Window.Title     = "Open Rails";
            GraphicsDeviceManager = new GraphicsDeviceManager(game);

            var windowSizeParts = game.Settings.WindowSize.Split(new[] { 'x' }, 2);

            gameWindowSize = new System.Drawing.Size(Convert.ToInt32(windowSizeParts[0]), Convert.ToInt32(windowSizeParts[1]));

            FrameRate         = new SmoothedData();
            FrameTime         = new SmoothedDataWithPercentiles();
            PrimitiveCount    = new int[(int)RenderPrimitiveSequence.Sentinel];
            PrimitivePerFrame = new int[(int)RenderPrimitiveSequence.Sentinel];

            // Run the game initially at 10FPS fixed-time-step. Do not change this! It affects the loading performance.
            game.IsFixedTimeStep   = true;
            game.TargetElapsedTime = TimeSpan.FromMilliseconds(100);
            game.InactiveSleepTime = TimeSpan.FromMilliseconds(100);

            // Set up the rest of the graphics according to the settings.
            GraphicsDeviceManager.SynchronizeWithVerticalRetrace = game.Settings.VerticalSync;
            GraphicsDeviceManager.PreferredBackBufferFormat      = SurfaceFormat.Color;
            GraphicsDeviceManager.PreferredDepthStencilFormat    = DepthFormat.Depth24Stencil8;
            GraphicsDeviceManager.IsFullScreen             = true;
            GraphicsDeviceManager.PreferMultiSampling      = game.Settings.MultisamplingCount > 0;
            GraphicsDeviceManager.PreparingDeviceSettings += new EventHandler <PreparingDeviceSettingsEventArgs>(GDM_PreparingDeviceSettings);

            currentScreen    = Screen.PrimaryScreen;
            gameWindowOrigin = new System.Drawing.Point((currentScreen.WorkingArea.Right - gameWindowSize.Width) / 2, (currentScreen.WorkingArea.Bottom - gameWindowSize.Height) / 2);
            System.Drawing.Point tempGameWindowOrigin = gameWindowOrigin;
            SynchronizeGraphicsDeviceManager(game.Settings.FullScreen ?
                                             game.Settings.NativeFullscreenResolution ? ScreenMode.FullscreenNativeResolution : ScreenMode.FullscreenPresetResolution
                : ScreenMode.WindowedPresetResolution);

            //restore gameWindowOrigin which will be overriden when game started in Fullscreen ()
            gameWindowOrigin = tempGameWindowOrigin;

            RenderPrimitive.SetGraphicsDevice(game.GraphicsDevice);

            UserInput.Initialize(game);
            gameForm.LocationChanged += GameForm_LocationChanged;
        }
Ejemplo n.º 3
0
        void WebServerThread()
        {
            Profiler.SetThread();
            Game.SetThreadLanguage();
            int port = Game.Settings.WebServerPort;

            var myWebContentPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(
                                                              System.Windows.Forms.Application.ExecutablePath), "Content\\Web");

            // 127.0.0.1 is a dummy, IPAddress.Any in WebServer.cs to accept any address
            // on the local Lan
            webServer = new WebServer("127.0.0.1", port, 1, myWebContentPath);
            webServer.Run();
        }
Ejemplo n.º 4
0
        private void WebServerThread()
        {
            Profiler.SetThread();
            Game.SetThreadLanguage();
            if (!Game.Settings.WebServer)
            {
                return;
            }

            string contentPath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Content\\Web");

            EndPointManager.UseIpv6 = true;
            using (EmbedIO.WebServer server = WebServer.CreateWebServer($"http://*:{Game.Settings.WebServerPort}", contentPath))
                server.RunAsync(StopServer.Token).Wait();
        }
Ejemplo n.º 5
0
        void WatchdogThread()
        {
            Profiler.SetThread();
            Game.SetThreadLanguage();

            while (true)
            {
                Thread.Sleep(1000);
                if (State.Terminated)
                {
                    break;
                }

                var tokens = Tokens;

                // Step each token first (which checks the state and captures stacks).
                foreach (var token in tokens)
                {
                    token.Step();
                }

                // Now see if any are waiting and any have hung.
                var waitTokens = new List <WatchdogToken>();
                var hungTokens = new List <WatchdogToken>();
                foreach (var token in tokens)
                {
                    if (token.IsWaiting)
                    {
                        waitTokens.Add(token);
                    }
                    else if (!token.IsResponding)
                    {
                        hungTokens.Add(token);
                    }
                }

                if (hungTokens.Count > 0)
                {
                    // Report every hung thread as a fatal error.
                    foreach (var token in hungTokens)
                    {
                        Trace.WriteLine(new FatalException(new ThreadHangException(token.Thread, token.Stacks)));
                    }

                    // Report every waiting thread as a warning (it might be relevant).
                    foreach (var token in waitTokens)
                    {
                        Trace.WriteLine(new ThreadWaitException(token.Thread, token.Stacks));
                    }

                    // Abandon ship!
                    if (Debugger.IsAttached)
                    {
                        Debugger.Break();
                    }
                    else
                    {
                        Environment.Exit(1);
                    }
                }
            }
        }