Inheritance: System.Windows.Forms.Form
示例#1
0
		// --------------------------------

		internal static void StartLoopEx(formMain.MainDialogResult result) {
			Screen.Show();
			jobs = new Queue<ThreadStart>(10);
			locks = new Queue<object>(10);
			Renderer.Initialize();
			Renderer.InitializeLighting();
			MainLoop.UpdateViewport(MainLoop.ViewPortChangeMode.NoChange);
			MainLoop.InitializeMotionBlur();
			ProcessEvents();
			Timers.Initialize();
			Loading.LoadAsynchronously(result.RouteFile, result.RouteEncoding, result.TrainFolder, result.TrainEncoding);
			// --- loading screen code ---
			LoadingScreenLoop();
			Renderer.InitializeLighting();
			Timetable.CreateTimetable();
			foreach (var message in Debug.Messages) {
				if (message.Type == Debug.MessageType.Critical) {
					MessageBox.Show("A critical error has occured:\n\n" + message.Text + "\n\nPlease inspect the error log file for further information.", "Load", MessageBoxButtons.OK, MessageBoxIcon.Hand);
					return;
				}
			}
			Game.LogRouteName = System.IO.Path.GetFileName(result.RouteFile);
			Game.LogTrainName = System.IO.Path.GetFileName(result.TrainFolder);
			Game.LogDateTime = DateTime.Now;
			StartLoop();
		}
示例#2
0
		internal static MainDialogResult ShowMainDialog(MainDialogResult initial) {
			formMain Dialog = new formMain();
			Dialog.Result = initial;
			Dialog.ShowDialog();
			MainDialogResult result = Dialog.Result;
			Dialog.Dispose();
			return result;
		}
示例#3
0
		internal static MainDialogResult ShowMainDialog(MainDialogResult initial)
		{
			using (formMain Dialog = new formMain())
			{
				Dialog.Result = initial;
				Dialog.ShowDialog();
				MainDialogResult result = Dialog.Result;
				//Dispose of the worker thread when closing the form
				//If it's still running, it attempts to update a non-existant form and crashes nastily
				Dialog.routeWorkerThread.Dispose();
				Dialog.trainWatcher.Dispose();
				Dialog.routeWatcher.Dispose();
				Dialog.Dispose();
				return result;
			}
		}
示例#4
0
 // --------------------------------
 internal static void StartLoopEx(formMain.MainDialogResult result)
 {
     Renderer.Initialize();
     Renderer.InitializeLighting();
     Sdl.SDL_GL_SwapBuffers();
     MainLoop.UpdateViewport(MainLoop.ViewPortChangeMode.NoChange);
     MainLoop.InitializeMotionBlur();
     ProcessEvents();
     Gl.glDisable(Gl.GL_FOG);
     Gl.glMatrixMode(Gl.GL_PROJECTION);
     Gl.glPushMatrix();
     Gl.glLoadIdentity();
     Gl.glOrtho(0.0, (double)Screen.Width, (double)Screen.Height, 0.0, -1.0, 1.0);
     Gl.glMatrixMode(Gl.GL_MODELVIEW);
     Gl.glPushMatrix();
     Gl.glLoadIdentity();
     Renderer.DrawLoadingScreen();
     Gl.glPopMatrix();
     Gl.glMatrixMode(Gl.GL_PROJECTION);
     Gl.glPopMatrix();
     Gl.glMatrixMode(Gl.GL_MODELVIEW);
     Sdl.SDL_GL_SwapBuffers();
     Loading.LoadSynchronously(result.RouteFile, result.RouteEncoding, result.TrainFolder, result.TrainEncoding);
     Timetable.CreateTimetable();
     for (int i = 0; i < Interface.MessageCount; i++) {
         if (Interface.Messages[i].Type == Interface.MessageType.Critical) {
             MessageBox.Show("A critical error has occured:\n\n" + Interface.Messages[i].Text + "\n\nPlease inspect the error log file for further information.", "Load", MessageBoxButtons.OK, MessageBoxIcon.Hand);
             return;
         }
     }
     Renderer.InitializeLighting();
     Game.LogRouteName = System.IO.Path.GetFileName(result.RouteFile);
     Game.LogTrainName = System.IO.Path.GetFileName(result.TrainFolder);
     Game.LogDateTime = DateTime.Now;
     StartLoop();
 }
示例#5
0
		/// <summary>Parses any command-line arguments passed to the main program</summary>
		/// <param name="Arguments">A string array of arguments</param>
		/// <param name="Result">The main dialog result (Used to launch)</param>
		internal static void ParseArguments(string[] Arguments, ref formMain.MainDialogResult Result)
		{
			if (Arguments.Length == 0)
			{
				return;
			}
			for (int i = 0; i < Arguments.Length; i++)
			{
				int equals = Arguments[i].IndexOf('=');
				if (@equals >= 0)
				{
					string key = Arguments[i].Substring(0, @equals).Trim().ToLowerInvariant();
					string value = Arguments[i].Substring(@equals + 1).Trim();
					switch (key)
					{
						case "/route":
							Result.RouteFile = value;
							switch (TextEncoding.GetEncodingFromFile(Result.RouteFile))
							{
								case TextEncoding.Encoding.Utf7:
									Result.RouteEncoding = System.Text.Encoding.UTF7;
									break;
								case TextEncoding.Encoding.Utf8:
									Result.RouteEncoding = System.Text.Encoding.UTF8;
									break;
								case TextEncoding.Encoding.Utf16Le:
									Result.RouteEncoding = System.Text.Encoding.Unicode;
									break;
								case TextEncoding.Encoding.Utf16Be:
									Result.RouteEncoding = System.Text.Encoding.BigEndianUnicode;
									break;
								case TextEncoding.Encoding.Utf32Le:
									Result.RouteEncoding = System.Text.Encoding.UTF32;
									break;
								case TextEncoding.Encoding.Utf32Be:
									Result.RouteEncoding = System.Text.Encoding.GetEncoding(12001);
									break;
								case TextEncoding.Encoding.Shift_JIS:
									Result.RouteEncoding = System.Text.Encoding.GetEncoding(932);
									break;
								default:
									Result.RouteEncoding = Encoding.Default;
									break;
							}
							break;
						case "/train":
							Result.TrainFolder = value;
							switch (TextEncoding.GetEncodingFromFile(Result.TrainFolder, "train.txt"))
							{
								case TextEncoding.Encoding.Utf8:
									Result.TrainEncoding = System.Text.Encoding.UTF8;
									break;
								case TextEncoding.Encoding.Utf16Le:
									Result.TrainEncoding = System.Text.Encoding.Unicode;
									break;
								case TextEncoding.Encoding.Utf16Be:
									Result.TrainEncoding = System.Text.Encoding.BigEndianUnicode;
									break;
								case TextEncoding.Encoding.Utf32Le:
									Result.TrainEncoding = System.Text.Encoding.UTF32;
									break;
								case TextEncoding.Encoding.Utf32Be:
									Result.TrainEncoding = System.Text.Encoding.GetEncoding(12001);
									break;
								case TextEncoding.Encoding.Shift_JIS:
									Result.TrainEncoding = System.Text.Encoding.GetEncoding(932);
									break;
								default:
									Result.TrainEncoding = Encoding.Default;
									break;
							}
							break;
						case "/station":
							Result.InitialStation = value;
							break;
						case "/time":
							Interface.TryParseTime(value, out Result.StartTime);
							break;
						case "/ai":
							if (value.ToLowerInvariant() == "true" || value.ToLowerInvariant() == "1")
							{
								Result.AIDriver = true;
							}
							break;
						case "/fullscreen":
							if (value.ToLowerInvariant() == "true" || value.ToLowerInvariant() == "1")
							{
								Result.FullScreen = true;
							}
							break;
						case "/width":
							Interface.TryParseIntVb6(value, out Result.Width);
							break;
						case "/height":
							Interface.TryParseIntVb6(value, out Result.Height);
							break;
					}
				}
			}
		}
示例#6
0
//		internal static formRouteInformation RouteInformationForm;
//		internal static Thread RouteInfoThread;
//		internal static bool RouteInfoActive
//		{
//			get
//			{
//				return RouteInformationForm != null && RouteInformationForm.IsHandleCreated && RouteInformationForm.Visible;
//			}
//		}


//		internal static AppDomain RouteInfoFormDomain;

		internal static void StartLoopEx(formMain.MainDialogResult result)
		{
			Sounds.Initialize();
			//Process extra command line arguments supplied
			if (result.InitialStation != null)
			{
				//We have supplied a station name or index to the loader
				Game.InitialStationName = result.InitialStation;
			}
			if (result.StartTime != default(double))
			{
				Game.InitialStationTime = result.StartTime;
			}
			if (result.AIDriver == true)
			{
				Game.InitialAIDriver = true;
			}
			if (result.FullScreen == true)
			{
				Interface.CurrentOptions.FullscreenMode = true;
			}
			if (result.Width != default(double) && result.Height != default(double))
			{
				if (Interface.CurrentOptions.FullscreenMode == true)
				{
					Interface.CurrentOptions.FullscreenWidth = result.Width;
					Interface.CurrentOptions.FullscreenHeight = result.Height;
					
				}
				else
				{
					Interface.CurrentOptions.WindowWidth = result.Width;
					Interface.CurrentOptions.WindowHeight = result.Height;
				}
			}
			Screen.Initialize();
			currentResult = result;
			GraphicsMode currentGraphicsMode = new GraphicsMode(new ColorFormat(8, 8, 8, 8), 24, 8,
				Interface.CurrentOptions.AntiAliasingLevel);

			/*
			 * TODO: This should be able to be moved back into the screen initialisation file
			 */
			if (Interface.CurrentOptions.FullscreenMode)
			{
				IList<DisplayResolution> resolutions = OpenTK.DisplayDevice.Default.AvailableResolutions;
				bool resolutionFound = false;
				for (int i = 0; i < resolutions.Count; i++)
				{

					//Test each resolution
					if (resolutions[i].Width == Interface.CurrentOptions.FullscreenWidth &&
					    resolutions[i].Height == Interface.CurrentOptions.FullscreenHeight &&
					    resolutions[i].BitsPerPixel == Interface.CurrentOptions.FullscreenBits)
					{
						try
						{
							OpenTK.DisplayDevice.Default.ChangeResolution(resolutions[i]);
							Program.currentGameWindow = new OpenBVEGame(resolutions[i].Width, resolutions[i].Height, currentGraphicsMode,
								GameWindowFlags.Default)
							{
								Visible = true,
								WindowState = WindowState.Fullscreen
							};
							resolutionFound = true;
						}
						catch
						{
							//Our resolution was in the list of available resolutions presented, but the graphics card driver failed to switch
							MessageBox.Show("Failed to change to the selected full-screen resolution:" + Environment.NewLine +
							                Interface.CurrentOptions.FullscreenWidth + " x " + Interface.CurrentOptions.FullscreenHeight +
							                " " + Interface.CurrentOptions.FullscreenBits + "bit color" + Environment.NewLine +
							                "Please check your resolution settings.", Application.ProductName, MessageBoxButtons.OK,
								MessageBoxIcon.Hand);
							Program.RestartArguments = " ";
							return;
						}
						break;
					}
				}
				if (resolutionFound == false)
				{
					//Our resolution was not found at all
					MessageBox.Show(
						"The graphics card driver reported that the selected resolution was not supported:" + Environment.NewLine +
						Interface.CurrentOptions.FullscreenWidth + " x " + Interface.CurrentOptions.FullscreenHeight + " " +
						Interface.CurrentOptions.FullscreenBits + "bit color" + Environment.NewLine +
						"Please check your resolution settings.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
					Program.RestartArguments = " ";
					return;
				}
			}
			else
			{

				try
				{
					Program.currentGameWindow = new OpenBVEGame(Interface.CurrentOptions.WindowWidth,
						Interface.CurrentOptions.WindowHeight, currentGraphicsMode, GameWindowFlags.Default)
					{
						Visible = true
					};
				}
				catch
				{
					//Windowed mode failed to launch
					MessageBox.Show("An error occured whilst tring to launch in windowed mode at resolution:" + Environment.NewLine +
					                Interface.CurrentOptions.WindowWidth + " x " + Interface.CurrentOptions.WindowHeight + " " +
					                Environment.NewLine +
					                "Please check your resolution settings.", Application.ProductName, MessageBoxButtons.OK,
						MessageBoxIcon.Hand);
					Program.RestartArguments = " ";
					return;
				}
			}
			if (Program.currentGameWindow == null)
			{
				//We should never really get an unspecified error here, but it's good manners to handle all cases
				MessageBox.Show("An unspecified error occured whilst attempting to launch the graphics subsystem.",
					Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
				Program.RestartArguments = " ";
				return;
			}

			Program.currentGameWindow.TargetUpdateFrequency = 0;
			Program.currentGameWindow.TargetRenderFrequency = 0;
			Program.currentGameWindow.VSync = Interface.CurrentOptions.VerticalSynchronization ? VSyncMode.On : VSyncMode.Off;
			Program.currentGameWindow.Closing += OpenTKQuit;
			Program.currentGameWindow.Run();
		}