static private Update ( double TimeElapsed ) : void | ||
TimeElapsed | double | |
Résultat | void |
//This renders the frame protected override void OnRenderFrame(FrameEventArgs e) { Game.InfoFrameRate = RenderFrequency; GL.ClearColor(0.75f, 0.75f, 0.75f, 1.0f); //Do not do anything whilst loading if (currentlyLoading) { System.Threading.Thread.Sleep(10); return; } ProcessEvents(); double TimeElapsed = CPreciseTimer.GetElapsedTime(); if (Program.CpuReducedMode) { System.Threading.Thread.Sleep(250); } else { System.Threading.Thread.Sleep(1); if (ReducedModeEnteringTime == 0) { ReducedModeEnteringTime = 2500; } if (World.CameraAlignmentDirection.Position.X != 0.0 | World.CameraAlignmentDirection.Position.Y != 0.0 | World.CameraAlignmentDirection.Position.Z != 0.0 | World.CameraAlignmentDirection.Pitch != 0.0 | World.CameraAlignmentDirection.Yaw != 0.0 | World.CameraAlignmentDirection.Roll != 0.0 | World.CameraAlignmentDirection.TrackPosition != 0.0 | World.CameraAlignmentDirection.Zoom != 0.0) { ReducedModeEnteringTime = 2500; } //Automatically enter reduced CPU mode if appropriate if (Program.CpuAutomaticMode && Program.CpuReducedMode == false) { ReducedModeEnteringTime -= TimeElapsed; if (ReducedModeEnteringTime <= 0) { Program.CpuReducedMode = true; ReducedModeEnteringTime = 0; } } } DateTime d = DateTime.Now; Game.SecondsSinceMidnight = (double)(3600 * d.Hour + 60 * d.Minute + d.Second) + 0.001 * (double)d.Millisecond; ObjectManager.UpdateAnimatedWorldObjects(TimeElapsed, false); World.UpdateAbsoluteCamera(TimeElapsed); ObjectManager.UpdateVisibility(World.CameraTrackFollower.TrackPosition + World.CameraCurrentAlignment.Position.Z); TextureManager.Update(TimeElapsed); SoundManager.Update(TimeElapsed); Renderer.RenderScene(TimeElapsed); SwapBuffers(); }
internal static void Main(string[] args) { Interface.CurrentOptions.UseSound = true; Interface.CurrentOptions.ObjectOptimizationBasicThreshold = 1000; Interface.CurrentOptions.ObjectOptimizationFullThreshold = 250; // platform and mono int p = (int)Environment.OSVersion.Platform; if (p == 4 | p == 128) { // general Unix CurrentPlatform = Platform.Linux; } else if (p == 6) { // Mac CurrentPlatform = Platform.Mac; } else { // non-Unix CurrentPlatform = Platform.Windows; } CurrentlyRunOnMono = Type.GetType("Mono.Runtime") != null; // file system FileSystem = FileSystem.FromCommandLineArgs(args); FileSystem.CreateFileSystem(); SetPackageLookupDirectories(); // command line arguments bool[] SkipArgs = new bool[args.Length]; if (args.Length != 0) { string File = System.IO.Path.Combine(Application.StartupPath, "ObjectViewer.exe"); if (System.IO.File.Exists(File)) { int Skips = 0; System.Text.StringBuilder NewArgs = new System.Text.StringBuilder(); for (int i = 0; i < args.Length; i++) { if (System.IO.File.Exists(args[i])) { if (System.IO.Path.GetExtension(args[i]).Equals(".csv", StringComparison.OrdinalIgnoreCase)) { string Text = System.IO.File.ReadAllText(args[i], System.Text.Encoding.UTF8); if (Text.Length == 0 || Text.IndexOf("CreateMeshBuilder", StringComparison.OrdinalIgnoreCase) >= 0) { if (NewArgs.Length != 0) { NewArgs.Append(" "); } NewArgs.Append("\"" + args[i] + "\""); SkipArgs[i] = true; Skips++; } } } else { SkipArgs[i] = true; Skips++; } } if (NewArgs.Length != 0) { System.Diagnostics.Process.Start(File, NewArgs.ToString()); } if (Skips == args.Length) { return; } } } // application Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); if (SDL.SDL_Init(SDL.SDL_INIT_VIDEO) != 0) { MessageBox.Show("SDL failed to initialize the video subsystem.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand); return; } // initialize sdl window SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_DOUBLEBUFFER, 1); SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_DEPTH_SIZE, 16); SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_RED_SIZE, 8); SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_GREEN_SIZE, 8); SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_BLUE_SIZE, 8); SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_ALPHA_SIZE, 8); SDL.SDL_ShowCursor(1); // initialize camera ResetCamera(); World.BackgroundImageDistance = 600.0; World.ForwardViewingDistance = 600.0; World.BackwardViewingDistance = 0.0; World.ExtraViewingDistance = 50.0; // create window Renderer.ScreenWidth = 960; Renderer.ScreenHeight = 600; //int Bits = 32; //IntPtr video = Sdl.SDL_SetVideoMode(Renderer.ScreenWidth, Renderer.ScreenHeight, Bits, Sdl.SDL_OPENGL | Sdl.SDL_DOUBLEBUF); Window = SDL.SDL_CreateWindow(Application.ProductName, SDL.SDL_WINDOWPOS_UNDEFINED, SDL.SDL_WINDOWPOS_UNDEFINED, Renderer.ScreenWidth, Renderer.ScreenHeight, SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL | SDL.SDL_WindowFlags.SDL_WINDOW_RESIZABLE); if (Window == IntPtr.Zero) { MessageBox.Show("SDL failed to create the window.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand); return; } // icon string iconFile = OpenBveApi.Path.CombineFile(Program.FileSystem.GetDataFolder(), "icon.png"); if (System.IO.File.Exists(iconFile)) { iconBmp = new Bitmap(iconFile); // load file iconData = iconBmp.LockBits(new Rectangle(0, 0, iconBmp.Width, iconBmp.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); // lock data iconSurface = SDL.SDL_CreateRGBSurfaceFrom(iconData.Scan0, iconBmp.Width, iconBmp.Height, 32, iconData.Stride, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000); // upload to sdl SDL.SDL_SetWindowIcon(Window, iconSurface); // use icon } GLContext = SDL.SDL_GL_CreateContext(Window); tkContext = new GraphicsContext(new ContextHandle(GLContext), SDL.SDL_GL_GetProcAddress, SDLGetCurrentContext); // anisotropic filtering string[] extensions = GL.GetString(StringName.Extensions).Split(new [] { ' ' }, StringSplitOptions.RemoveEmptyEntries); Interface.CurrentOptions.AnisotropicFilteringMaximum = 0; for (int i = 0; i < extensions.Length; i++) { if (extensions[i] == "GL_EXT_texture_filter_anisotropic") { float n; GL.GetFloat((GetPName)ExtTextureFilterAnisotropic.MaxTextureMaxAnisotropyExt, out n); Interface.CurrentOptions.AnisotropicFilteringMaximum = (int)Math.Round((double)n); break; } } if (Interface.CurrentOptions.AnisotropicFilteringMaximum <= 0) { Interface.CurrentOptions.AnisotropicFilteringMaximum = 0; Interface.CurrentOptions.AnisotropicFilteringLevel = 0; Interface.CurrentOptions.Interpolation = TextureManager.InterpolationMode.AnisotropicFiltering; } else { Interface.CurrentOptions.AnisotropicFilteringLevel = Interface.CurrentOptions.AnisotropicFilteringMaximum; Interface.CurrentOptions.Interpolation = TextureManager.InterpolationMode.TrilinearMipmapped; } Interface.CurrentOptions.TransparencyMode = Renderer.TransparencyMode.Sharp; // module initialization Renderer.Initialize(); Renderer.InitializeLighting(); SoundManager.Initialize(); GL.ClearColor(0.75f, 0.75f, 0.75f, 1.0f); SwapBuffers(); Fonts.Initialize(); UpdateViewport(); // loop bool processCommandLineArgs = true; timer = new System.Diagnostics.Stopwatch(); timer.Start(); while (!Quit) { ProcessEvents(); int a = (int)timer.ElapsedMilliseconds; double TimeElapsed = 0.001 * (double)(a - LastTicks); if (CpuReducedMode) { System.Threading.Thread.Sleep(250); } else { System.Threading.Thread.Sleep(1); if (ReducedModeEnteringTime == 0) { ReducedModeEnteringTime = a + 2500; } if (World.CameraAlignmentDirection.Position.X != 0.0 | World.CameraAlignmentDirection.Position.Y != 0.0 | World.CameraAlignmentDirection.Position.Z != 0.0 | World.CameraAlignmentDirection.Pitch != 0.0 | World.CameraAlignmentDirection.Yaw != 0.0 | World.CameraAlignmentDirection.Roll != 0.0 | World.CameraAlignmentDirection.TrackPosition != 0.0 | World.CameraAlignmentDirection.Zoom != 0.0) { ReducedModeEnteringTime = a + 2500; } else if (a > ReducedModeEnteringTime & CpuAutomaticMode) { ReducedModeEnteringTime = 0; CpuReducedMode = true; } } DateTime d = DateTime.Now; Game.SecondsSinceMidnight = (double)(3600 * d.Hour + 60 * d.Minute + d.Second) + 0.001 * (double)d.Millisecond; ObjectManager.UpdateAnimatedWorldObjects(TimeElapsed, false); World.UpdateAbsoluteCamera(TimeElapsed); ObjectManager.UpdateVisibility(World.CameraTrackFollower.TrackPosition + World.CameraCurrentAlignment.Position.Z); TextureManager.Update(TimeElapsed); SoundManager.Update(TimeElapsed); Renderer.RenderScene(TimeElapsed); SwapBuffers(); LastTicks = a; // command line arguments if (processCommandLineArgs) { processCommandLineArgs = false; for (int i = 0; i < args.Length; i++) { if (!SkipArgs[i] && System.IO.File.Exists(args[i])) { CurrentlyLoading = true; Renderer.RenderScene(0.0); SwapBuffers(); CurrentRoute = args[i]; LoadRoute(); CurrentlyLoading = false; UpdateCaption(); break; } } } } // quit TextureManager.UnuseAllTextures(); SoundManager.Deinitialize(); if (iconSurface != IntPtr.Zero) { SDL.SDL_FreeSurface(iconSurface); // free surface } if (iconBmp != null && iconData != null) { iconBmp.UnlockBits(iconData); // free pixels iconBmp.Dispose(); } SDL.SDL_GL_DeleteContext(GLContext); SDL.SDL_DestroyWindow(Window); SDL.SDL_Quit(); }
internal static void Main(string[] args) { Interface.CurrentOptions.UseSound = true; Interface.CurrentOptions.ObjectOptimizationBasicThreshold = 1000; Interface.CurrentOptions.ObjectOptimizationFullThreshold = 250; // platform and mono int p = (int)Environment.OSVersion.Platform; if (p == 4 | p == 128) { /// general Unix CurrentPlatform = Platform.Linux; } else if (p == 6) { /// Mac CurrentPlatform = Platform.Mac; } else { /// non-Unix CurrentPlatform = Platform.Windows; } CurrentlyRunOnMono = Type.GetType("Mono.Runtime") != null; // file system FileSystem = FileSystem.FromCommandLineArgs(args); FileSystem.CreateFileSystem(); SetPackageLookupDirectories(); // command line arguments bool[] SkipArgs = new bool[args.Length]; if (args.Length != 0) { string File = System.IO.Path.Combine(Application.StartupPath, "ObjectViewer.exe"); if (System.IO.File.Exists(File)) { int Skips = 0; System.Text.StringBuilder NewArgs = new System.Text.StringBuilder(); for (int i = 0; i < args.Length; i++) { if (System.IO.File.Exists(args[i])) { if (System.IO.Path.GetExtension(args[i]).Equals(".csv", StringComparison.OrdinalIgnoreCase)) { string Text = System.IO.File.ReadAllText(args[i], System.Text.Encoding.UTF8); if (Text.Length == 0 || Text.IndexOf("CreateMeshBuilder", StringComparison.OrdinalIgnoreCase) >= 0) { if (NewArgs.Length != 0) { NewArgs.Append(" "); } NewArgs.Append("\"" + args[i] + "\""); SkipArgs[i] = true; Skips++; } } } else { SkipArgs[i] = true; Skips++; } } if (NewArgs.Length != 0) { System.Diagnostics.Process.Start(File, NewArgs.ToString()); } if (Skips == args.Length) { return; } } } // application Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); if (Sdl.SDL_Init(Sdl.SDL_INIT_VIDEO) != 0) { MessageBox.Show("SDL failed to initialize the video subsystem.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand); return; } // initialize sdl window Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_DOUBLEBUFFER, 1); Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_DEPTH_SIZE, 16); Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_RED_SIZE, 8); Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_GREEN_SIZE, 8); Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_BLUE_SIZE, 8); Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_ALPHA_SIZE, 8); Sdl.SDL_ShowCursor(Sdl.SDL_ENABLE); // icon if (Program.CurrentPlatform == Platform.Windows) { string File = OpenBveApi.Path.CombineFile(Program.FileSystem.GetDataFolder(), "icon.bmp"); if (System.IO.File.Exists(File)) { IntPtr Bitmap = Sdl.SDL_LoadBMP(File); if (Bitmap != null) { Sdl.SDL_Surface Surface = (Sdl.SDL_Surface)System.Runtime.InteropServices.Marshal.PtrToStructure(Bitmap, typeof(Sdl.SDL_Surface)); int ColorKey = Sdl.SDL_MapRGB(Surface.format, 0, 0, 255); Sdl.SDL_SetColorKey(Bitmap, Sdl.SDL_SRCCOLORKEY, ColorKey); Sdl.SDL_WM_SetIcon(Bitmap, null); } } } // initialize camera ResetCamera(); World.BackgroundImageDistance = 600.0; World.ForwardViewingDistance = 600.0; World.BackwardViewingDistance = 0.0; World.ExtraViewingDistance = 50.0; // create window Renderer.ScreenWidth = 960; Renderer.ScreenHeight = 600; int Bits = 32; IntPtr video = Sdl.SDL_SetVideoMode(Renderer.ScreenWidth, Renderer.ScreenHeight, Bits, Sdl.SDL_OPENGL | Sdl.SDL_DOUBLEBUF); if (video != IntPtr.Zero) { // create window Sdl.SDL_WM_SetCaption(Application.ProductName, null); // anisotropic filtering string[] Extensions = Gl.glGetString(Gl.GL_EXTENSIONS).Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); Interface.CurrentOptions.AnisotropicFilteringMaximum = 0; for (int i = 0; i < Extensions.Length; i++) { if (string.Compare(Extensions[i], "GL_EXT_texture_filter_anisotropic", StringComparison.OrdinalIgnoreCase) == 0) { float n; Gl.glGetFloatv(Gl.GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, out n); Interface.CurrentOptions.AnisotropicFilteringMaximum = (int)Math.Round((double)n); break; } } if (Interface.CurrentOptions.AnisotropicFilteringMaximum <= 0) { Interface.CurrentOptions.AnisotropicFilteringMaximum = 0; Interface.CurrentOptions.AnisotropicFilteringLevel = 0; Interface.CurrentOptions.Interpolation = TextureManager.InterpolationMode.AnisotropicFiltering; } else { Interface.CurrentOptions.AnisotropicFilteringLevel = Interface.CurrentOptions.AnisotropicFilteringMaximum; Interface.CurrentOptions.Interpolation = TextureManager.InterpolationMode.TrilinearMipmapped; } Interface.CurrentOptions.TransparencyMode = Renderer.TransparencyMode.Sharp; // module initialization Renderer.Initialize(); Renderer.InitializeLighting(); SoundManager.Initialize(); Gl.glClearColor(0.75f, 0.75f, 0.75f, 1.0f); Sdl.SDL_GL_SwapBuffers(); Fonts.Initialize(); UpdateViewport(); // loop bool processCommandLineArgs = true; while (!Quit) { ProcessEvents(); int a = Sdl.SDL_GetTicks(); double TimeElapsed = 0.001 * (double)(a - LastTicks); if (CpuReducedMode) { System.Threading.Thread.Sleep(250); } else { System.Threading.Thread.Sleep(1); if (ReducedModeEnteringTime == 0) { ReducedModeEnteringTime = a + 2500; } if (World.CameraAlignmentDirection.Position.X != 0.0 | World.CameraAlignmentDirection.Position.Y != 0.0 | World.CameraAlignmentDirection.Position.Z != 0.0 | World.CameraAlignmentDirection.Pitch != 0.0 | World.CameraAlignmentDirection.Yaw != 0.0 | World.CameraAlignmentDirection.Roll != 0.0 | World.CameraAlignmentDirection.TrackPosition != 0.0 | World.CameraAlignmentDirection.Zoom != 0.0) { ReducedModeEnteringTime = a + 2500; } else if (a > ReducedModeEnteringTime & CpuAutomaticMode) { ReducedModeEnteringTime = 0; CpuReducedMode = true; } } DateTime d = DateTime.Now; Game.SecondsSinceMidnight = (double)(3600 * d.Hour + 60 * d.Minute + d.Second) + 0.001 * (double)d.Millisecond; ObjectManager.UpdateAnimatedWorldObjects(TimeElapsed, false); World.UpdateAbsoluteCamera(TimeElapsed); ObjectManager.UpdateVisibility(World.CameraTrackFollower.TrackPosition + World.CameraCurrentAlignment.Position.Z); TextureManager.Update(TimeElapsed); SoundManager.Update(TimeElapsed); Renderer.RenderScene(TimeElapsed); Sdl.SDL_GL_SwapBuffers(); LastTicks = a; // command line arguments if (processCommandLineArgs) { processCommandLineArgs = false; for (int i = 0; i < args.Length; i++) { if (!SkipArgs[i] && System.IO.File.Exists(args[i])) { CurrentlyLoading = true; Renderer.RenderScene(0.0); Sdl.SDL_GL_SwapBuffers(); CurrentRoute = args[i]; LoadRoute(); CurrentlyLoading = false; UpdateCaption(); break; } } } } // quit TextureManager.UnuseAllTextures(); SoundManager.Deinitialize(); Sdl.SDL_Quit(); } else { MessageBox.Show("SDL failed to create the window.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand); } }