mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-25 09:15:31 +00:00
GameWindow.Exit() now throws an exception that is caught inside GameWindow.Run() to signal end of execution. Simplifies code and removes some ugly conditionals.
This commit is contained in:
parent
1fa4641781
commit
11015a9fc7
|
@ -105,6 +105,7 @@ namespace OpenTK
|
|||
glWindow.Destroy += new DestroyEvent(glWindow_Destroy);
|
||||
|
||||
CreateWindow(mode, title);
|
||||
this.vsync = VSyncMode.Adaptive;
|
||||
}
|
||||
|
||||
void glWindow_Destroy(object sender, EventArgs e)
|
||||
|
@ -432,6 +433,8 @@ namespace OpenTK
|
|||
/// <param name="updates_per_second">The frequency of UpdateFrame events.</param>
|
||||
/// <param name="frames_per_second">The frequency of RenderFrame events.</param>
|
||||
public void Run(double updates_per_second, double frames_per_second)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (updates_per_second < 0.0 || updates_per_second > 200.0)
|
||||
throw new ArgumentOutOfRangeException("updates_per_second", updates_per_second, "Parameter should be inside the range [0.0, 200.0]");
|
||||
|
@ -472,9 +475,6 @@ namespace OpenTK
|
|||
// Process events
|
||||
ProcessEvents();
|
||||
|
||||
if (isExiting)
|
||||
break;
|
||||
|
||||
// Raise UpdateFrame events
|
||||
time = update_watch.Elapsed.TotalSeconds;
|
||||
if (time > 1.0)
|
||||
|
@ -511,16 +511,23 @@ namespace OpenTK
|
|||
update_time_counter = 0.0;
|
||||
}
|
||||
|
||||
// Raise RenderFrame events
|
||||
if (isExiting)
|
||||
break;
|
||||
|
||||
// Raise RenderFrame event
|
||||
time = render_watch.Elapsed.TotalSeconds;
|
||||
if (time > 1.0)
|
||||
time = 1.0;
|
||||
if (next_render - time <= 0.0)
|
||||
double time_left = next_render - time;
|
||||
if (VSync == VSyncMode.Adaptive)
|
||||
{
|
||||
next_render = next_render - time + TargetRenderPeriod;
|
||||
// Check if we have enough time for a vsync
|
||||
if (time_left <= 0.5 * TargetRenderFrequency)
|
||||
Context.VSync = false;
|
||||
else
|
||||
Context.VSync = true;
|
||||
}
|
||||
|
||||
if (time_left <= 0.0)
|
||||
{
|
||||
next_render = time_left + TargetRenderPeriod;
|
||||
render_watch.Reset();
|
||||
render_watch.Start();
|
||||
|
||||
|
@ -537,7 +544,13 @@ namespace OpenTK
|
|||
// Thread.Sleep((int)(1000.0 * System.Math.Min(next_render - sleep_granularity, next_update - sleep_granularity)));
|
||||
//}
|
||||
}
|
||||
}
|
||||
catch (GameWindowExitException e)
|
||||
{
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
Thread.CurrentThread.Priority = ThreadPriority.Normal;
|
||||
|
||||
OnUnloadInternal(EventArgs.Empty);
|
||||
|
@ -551,6 +564,7 @@ namespace OpenTK
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
Loading…
Reference in a new issue