void UpdaterThread() { Profiler.SetThread(); Game.SetThreadLanguage(); while (true) { // Wait for a new Update() command State.WaitTillStarted(); if (State.Terminated) { break; } try { if (!DoUpdate()) { return; } } finally { // Signal finished so RenderProcess can start drawing State.SignalFinish(); } } }
void WebServerThread() { Profiler.SetThread(); Game.SetThreadLanguage(); string myWebContentPath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Content\\Web"); EndPointManager.UseIpv6 = true; try { using (EmbedIO.WebServer server = WebServer.CreateWebServer($"http://*:{Game.Settings.WebServerPort}", myWebContentPath)) server.RunAsync(StopServer.Token).Wait(); } catch (AggregateException ex) { if (ex.InnerException is SocketException) { Trace.TraceWarning($"Port {Game.Settings.WebServerPort} is already in use. Continuing without webserver"); } else { throw ex; } } }
public static float[] ShadowMapLimit; // diameter of shadow map far edge from camera internal RenderProcess(Game game) { 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 Point(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 = false; GraphicsDeviceManager.PreferMultiSampling = Game.Settings.EnableMultisampling; GraphicsDeviceManager.PreparingDeviceSettings += new EventHandler <PreparingDeviceSettingsEventArgs>(GDM_PreparingDeviceSettings); var screen = Game.Settings.FastFullScreenAltTab ? Screen.FromControl(GameForm) : Screen.PrimaryScreen; if (screen.Primary) { var wa = Screen.PrimaryScreen.WorkingArea; GameForm.Location = new System.Drawing.Point((wa.Right - GameWindowSize.X) / 2, (wa.Bottom - GameWindowSize.Y) / 2); } else { GameForm.Location = new System.Drawing.Point((screen.Bounds.Width - GameWindowSize.X) / 2, (screen.Bounds.Height - GameWindowSize.Y) / 2); } GameWindowOrigin = GameForm.Location; if (Game.Settings.FullScreen) { ToggleFullScreen(); } SynchronizeGraphicsDeviceManager(); }
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(); }
void WebServerThread() { Profiler.SetThread(); Game.SetThreadLanguage(); if (!Game.Settings.WebServer) { return; } string myWebContentPath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Content\\Web"); EndPointManager.UseIpv6 = true; using (EmbedIO.WebServer server = WebServer.CreateWebServer($"http://*:{Game.Settings.WebServerPort}", myWebContentPath)) server.RunAsync(StopServer.Token).Wait(); }
public static float[] ShadowMapLimit; // diameter of shadow map far edge from camera internal RenderProcess(Game game) { 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 Point(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 = Game.Settings.FullScreen; GraphicsDeviceManager.PreferMultiSampling = (AntiAliasingMethod)Game.Settings.AntiAliasing != AntiAliasingMethod.None; GraphicsDeviceManager.HardwareModeSwitch = false; // for fast full-screen Alt-Tab switching GraphicsDeviceManager.PreparingDeviceSettings += new EventHandler <PreparingDeviceSettingsEventArgs>(GDM_PreparingDeviceSettings); }
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); } } } }