mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-25 20:55:38 +00:00
Cleaned up warnings. Updated documentation. Cleaned up some functions.
This commit is contained in:
parent
db6b583030
commit
210122454c
|
@ -119,46 +119,6 @@ namespace OpenTK
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region --- Functions ---
|
|
||||||
|
|
||||||
#region public void CreateWindow(DisplayMode mode, string title)
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a render window for the calling GameWindow, with the specified DisplayMode and Title.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="mode">The DisplayMode of the render window.</param>
|
|
||||||
/// <param name="title">The Title of the render window.</param>
|
|
||||||
/// <remarks>
|
|
||||||
/// It is an error to call this function when a render window already exists.
|
|
||||||
/// <para>Call DestroyWindow to close the render window.</para>
|
|
||||||
/// </remarks>
|
|
||||||
/// <exception cref="ApplicationException">Occurs when a render window already exists.</exception>
|
|
||||||
private void CreateWindow(DisplayMode mode, string title)
|
|
||||||
{
|
|
||||||
if (!Exists)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
glWindow.CreateWindow(mode);
|
|
||||||
this.Title = title;
|
|
||||||
input_driver = new InputDriver(this);
|
|
||||||
}
|
|
||||||
catch (ApplicationException expt)
|
|
||||||
{
|
|
||||||
Debug.Print(expt.ToString());
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException("A render window already exists for this GameWindow.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region --- INativeGLWindow Members ---
|
#region --- INativeGLWindow Members ---
|
||||||
|
|
||||||
#region public void Exit()
|
#region public void Exit()
|
||||||
|
@ -172,6 +132,7 @@ namespace OpenTK
|
||||||
public virtual void Exit()
|
public virtual void Exit()
|
||||||
{
|
{
|
||||||
isExiting = true;
|
isExiting = true;
|
||||||
|
//throw new GameWindowExitException();
|
||||||
//glWindow.Exit();
|
//glWindow.Exit();
|
||||||
//this.Dispose();
|
//this.Dispose();
|
||||||
}
|
}
|
||||||
|
@ -406,6 +367,42 @@ namespace OpenTK
|
||||||
|
|
||||||
#region --- GameWindow Methods ---
|
#region --- GameWindow Methods ---
|
||||||
|
|
||||||
|
#region public void CreateWindow(DisplayMode mode, string title)
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a render window for the calling GameWindow, with the specified DisplayMode and Title.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="mode">The DisplayMode of the render window.</param>
|
||||||
|
/// <param name="title">The Title of the render window.</param>
|
||||||
|
/// <remarks>
|
||||||
|
/// It is an error to call this function when a render window already exists.
|
||||||
|
/// <para>Call DestroyWindow to close the render window.</para>
|
||||||
|
/// </remarks>
|
||||||
|
/// <exception cref="ApplicationException">Occurs when a render window already exists.</exception>
|
||||||
|
private void CreateWindow(DisplayMode mode, string title)
|
||||||
|
{
|
||||||
|
if (!Exists)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
glWindow.CreateWindow(mode);
|
||||||
|
this.Title = title;
|
||||||
|
input_driver = new InputDriver(this);
|
||||||
|
}
|
||||||
|
catch (ApplicationException expt)
|
||||||
|
{
|
||||||
|
Debug.Print(expt.ToString());
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("A render window already exists for this GameWindow.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region void Run()
|
#region void Run()
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -450,7 +447,7 @@ namespace OpenTK
|
||||||
UpdateFrameEventArgs update_args = new UpdateFrameEventArgs();
|
UpdateFrameEventArgs update_args = new UpdateFrameEventArgs();
|
||||||
RenderFrameEventArgs render_args = new RenderFrameEventArgs();
|
RenderFrameEventArgs render_args = new RenderFrameEventArgs();
|
||||||
|
|
||||||
double sleep_granularity; // In seconds.
|
//double sleep_granularity; // In seconds.
|
||||||
|
|
||||||
//GC.Collect(2);
|
//GC.Collect(2);
|
||||||
//GC.WaitForPendingFinalizers();
|
//GC.WaitForPendingFinalizers();
|
||||||
|
@ -482,6 +479,8 @@ namespace OpenTK
|
||||||
while (next_update - time <= 0.0)
|
while (next_update - time <= 0.0)
|
||||||
{
|
{
|
||||||
next_update = next_update - time + TargetUpdatePeriod;
|
next_update = next_update - time + TargetUpdatePeriod;
|
||||||
|
if (next_update < -1.0) // Cap the maximum time drift, to avoid lengthy catch-up games.
|
||||||
|
next_update = -1.0;
|
||||||
|
|
||||||
update_time_counter += time;
|
update_time_counter += time;
|
||||||
++num_updates;
|
++num_updates;
|
||||||
|
@ -491,6 +490,7 @@ namespace OpenTK
|
||||||
|
|
||||||
update_args.Time = time;
|
update_args.Time = time;
|
||||||
OnUpdateFrameInternal(update_args);
|
OnUpdateFrameInternal(update_args);
|
||||||
|
update_time = update_watch.Elapsed.TotalSeconds;
|
||||||
|
|
||||||
if (TargetUpdateFrequency == 0.0)
|
if (TargetUpdateFrequency == 0.0)
|
||||||
break;
|
break;
|
||||||
|
@ -499,8 +499,8 @@ namespace OpenTK
|
||||||
next_update -= time;
|
next_update -= time;
|
||||||
update_time_counter += time;
|
update_time_counter += time;
|
||||||
|
|
||||||
// Allow up to 10 frames to be dropped.
|
// Allow up to 10 frames to be dropped. Prevents the application from hanging
|
||||||
// Prevent the application from hanging with very high update frequencies.
|
// with very high update frequencies.
|
||||||
if (num_updates >= 10)
|
if (num_updates >= 10)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -511,6 +511,9 @@ namespace OpenTK
|
||||||
update_time_counter = 0.0;
|
update_time_counter = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isExiting)
|
||||||
|
break;
|
||||||
|
|
||||||
// Raise RenderFrame event
|
// Raise RenderFrame event
|
||||||
time = render_watch.Elapsed.TotalSeconds;
|
time = render_watch.Elapsed.TotalSeconds;
|
||||||
if (time > 1.0)
|
if (time > 1.0)
|
||||||
|
@ -519,7 +522,7 @@ namespace OpenTK
|
||||||
if (VSync == VSyncMode.Adaptive)
|
if (VSync == VSyncMode.Adaptive)
|
||||||
{
|
{
|
||||||
// Check if we have enough time for a vsync
|
// Check if we have enough time for a vsync
|
||||||
if (time_left <= 0.5 * TargetRenderFrequency)
|
if (RenderTime > 2.0 * TargetRenderPeriod)
|
||||||
Context.VSync = false;
|
Context.VSync = false;
|
||||||
else
|
else
|
||||||
Context.VSync = true;
|
Context.VSync = true;
|
||||||
|
@ -528,12 +531,16 @@ namespace OpenTK
|
||||||
if (time_left <= 0.0)
|
if (time_left <= 0.0)
|
||||||
{
|
{
|
||||||
next_render = time_left + TargetRenderPeriod;
|
next_render = time_left + TargetRenderPeriod;
|
||||||
|
if (next_render < -1.0) // Cap the maximum time drift, to avoid lengthy catch-up games.
|
||||||
|
next_render = -1.0;
|
||||||
|
|
||||||
render_watch.Reset();
|
render_watch.Reset();
|
||||||
render_watch.Start();
|
render_watch.Start();
|
||||||
|
|
||||||
render_period = render_args.Time = time;
|
render_period = render_args.Time = time;
|
||||||
render_args.ScaleFactor = RenderPeriod / UpdatePeriod;
|
render_args.ScaleFactor = RenderPeriod / UpdatePeriod;
|
||||||
OnRenderFrameInternal(render_args);
|
OnRenderFrameInternal(render_args);
|
||||||
|
render_time = render_watch.Elapsed.TotalSeconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Yield CPU time, if the Thread.Sleep() granularity allows it.
|
// Yield CPU time, if the Thread.Sleep() granularity allows it.
|
||||||
|
@ -545,10 +552,10 @@ namespace OpenTK
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (GameWindowExitException e)
|
//catch (GameWindowExitException e)
|
||||||
{
|
//{
|
||||||
|
|
||||||
}
|
//}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
Thread.CurrentThread.Priority = ThreadPriority.Normal;
|
Thread.CurrentThread.Priority = ThreadPriority.Normal;
|
||||||
|
@ -858,7 +865,7 @@ namespace OpenTK
|
||||||
#region public double TargetRenderPeriod
|
#region public double TargetRenderPeriod
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the target render period in seconds.
|
/// Gets or sets a double representing the target render period, in seconds.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <para>A value of 0.0 indicates that RenderFrame events are generated at the maximum possible frequency (i.e. only limited by the hardware's capabilities).</para>
|
/// <para>A value of 0.0 indicates that RenderFrame events are generated at the maximum possible frequency (i.e. only limited by the hardware's capabilities).</para>
|
||||||
/// <para>Values lower than 0.005 seconds (200Hz) are clamped to 0.0. Values higher than 1.0 seconds (1Hz) are clamped to 1.0.</para>
|
/// <para>Values lower than 0.005 seconds (200Hz) are clamped to 0.0. Values higher than 1.0 seconds (1Hz) are clamped to 1.0.</para>
|
||||||
|
@ -889,7 +896,7 @@ namespace OpenTK
|
||||||
#region public double TargetRenderFrequency
|
#region public double TargetRenderFrequency
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the target render frequency in Herz.
|
/// Gets or sets a double representing the target render frequency, in Herz.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// <para>A value of 0.0 indicates that RenderFrame events are generated at the maximum possible frequency (i.e. only limited by the hardware's capabilities).</para>
|
/// <para>A value of 0.0 indicates that RenderFrame events are generated at the maximum possible frequency (i.e. only limited by the hardware's capabilities).</para>
|
||||||
|
@ -922,7 +929,7 @@ namespace OpenTK
|
||||||
#region public double TargetUpdatePeriod
|
#region public double TargetUpdatePeriod
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the target update period in seconds.
|
/// Gets or sets a double representing the target update period, in seconds.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// <para>A value of 0.0 indicates that UpdateFrame events are generated at the maximum possible frequency (i.e. only limited by the hardware's capabilities).</para>
|
/// <para>A value of 0.0 indicates that UpdateFrame events are generated at the maximum possible frequency (i.e. only limited by the hardware's capabilities).</para>
|
||||||
|
@ -953,7 +960,7 @@ namespace OpenTK
|
||||||
#region public double TargetUpdateFrequency
|
#region public double TargetUpdateFrequency
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the target update frequency in Herz.
|
/// Gets or sets a double representing the target update frequency, in Herz.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// <para>A value of 0.0 indicates that UpdateFrame events are generated at the maximum possible frequency (i.e. only limited by the hardware's capabilities).</para>
|
/// <para>A value of 0.0 indicates that UpdateFrame events are generated at the maximum possible frequency (i.e. only limited by the hardware's capabilities).</para>
|
||||||
|
@ -986,7 +993,7 @@ namespace OpenTK
|
||||||
#region public double RenderFrequency
|
#region public double RenderFrequency
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the actual frequency of RenderFrame events in Herz (i.e. FPS or Frames Per Second).
|
/// Gets a double representing the actual frequency of RenderFrame events, in Herz (i.e. FPS or Frames Per Second).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double RenderFrequency
|
public double RenderFrequency
|
||||||
{
|
{
|
||||||
|
@ -1003,7 +1010,7 @@ namespace OpenTK
|
||||||
#region public double RenderPeriod
|
#region public double RenderPeriod
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the period of RenderFrame events in seconds.
|
/// Gets a double representing the period of RenderFrame events, in seconds.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double RenderPeriod
|
public double RenderPeriod
|
||||||
{
|
{
|
||||||
|
@ -1018,7 +1025,7 @@ namespace OpenTK
|
||||||
#region public double UpdateFrequency
|
#region public double UpdateFrequency
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the frequency of UpdateFrame events in Herz.
|
/// Gets a double representing the frequency of UpdateFrame events, in Herz.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double UpdateFrequency
|
public double UpdateFrequency
|
||||||
{
|
{
|
||||||
|
@ -1035,7 +1042,7 @@ namespace OpenTK
|
||||||
#region public double UpdatePeriod
|
#region public double UpdatePeriod
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the period of UpdateFrame events in seconds.
|
/// Gets a double representing the period of UpdateFrame events, in seconds.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double UpdatePeriod
|
public double UpdatePeriod
|
||||||
{
|
{
|
||||||
|
@ -1047,6 +1054,31 @@ namespace OpenTK
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region public double RenderTime
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a double representing the time spent in the RenderFrame function, in seconds.
|
||||||
|
/// </summary>
|
||||||
|
public double RenderTime
|
||||||
|
{
|
||||||
|
get { return render_time; }
|
||||||
|
protected set { render_time = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region public double RenderTime
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a double representing the time spent in the UpdateFrame function, in seconds.
|
||||||
|
/// </summary>
|
||||||
|
public double UpdateTime
|
||||||
|
{
|
||||||
|
get { return update_time; }
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region --- IResizable Members ---
|
#region --- IResizable Members ---
|
||||||
|
@ -1193,7 +1225,7 @@ namespace OpenTK
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void Dispose()
|
public virtual void Dispose()
|
||||||
{
|
{
|
||||||
Dispose(true); // Real Dispose method.
|
Dispose(true);
|
||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1201,9 +1233,6 @@ namespace OpenTK
|
||||||
{
|
{
|
||||||
if (!disposed)
|
if (!disposed)
|
||||||
{
|
{
|
||||||
// Is this safe? Maybe 'Debug' has been disposed, too...
|
|
||||||
//Debug.Print("{0} disposing GameWindow.", manual ? "Manually" : "Automatically");
|
|
||||||
|
|
||||||
if (manual)
|
if (manual)
|
||||||
{
|
{
|
||||||
if (glWindow != null)
|
if (glWindow != null)
|
||||||
|
@ -1218,7 +1247,7 @@ namespace OpenTK
|
||||||
|
|
||||||
~GameWindow()
|
~GameWindow()
|
||||||
{
|
{
|
||||||
this.Dispose(false);
|
Dispose(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
Loading…
Reference in a new issue