Simplify ProcessEvents implementation
authorStefanos A. <stapostol@gmail.com>
Fri, 20 Dec 2013 07:42:36 +0000 (08:42 +0100)
committerStefanos A. <stapostol@gmail.com>
Fri, 20 Dec 2013 07:42:36 +0000 (08:42 +0100)
Instead of combining PeekMessage+GetMessage, we can simply call
PeekMessage(Remove) to achieve the same effect. This also allows us to
remove the IsIdle property, which is no longer used anywhere.

Source/OpenTK/Platform/Windows/API.cs
Source/OpenTK/Platform/Windows/WinGLNative.cs

index b9107d7..c05398e 100644 (file)
@@ -349,7 +349,7 @@ namespace OpenTK.Platform.Windows
         [System.Security.SuppressUnmanagedCodeSecurity]
         [DllImport("User32.dll"), CLSCompliant(false)]
         [return: MarshalAs(UnmanagedType.Bool)]
-        internal static extern bool PeekMessage(ref MSG msg, IntPtr hWnd, int messageFilterMin, int messageFilterMax, int flags);
+        internal static extern bool PeekMessage(ref MSG msg, IntPtr hWnd, int messageFilterMin, int messageFilterMax, PeekMessageFlags flags);
 
         #endregion
 
@@ -4028,6 +4028,18 @@ namespace OpenTK.Platform.Windows
 
     #endregion
 
+    #region PeekMessageFlags
+
+    [Flags]
+    enum PeekMessageFlags : uint
+    {
+        NoRemove = 0,
+        Remove = 1,
+        NoYield = 2
+    }
+
+    #endregion
+
     #region ShowWindowCommand
 
     /// <summary>
index aae5d10..ccdcbd3 100644 (file)
@@ -583,19 +583,6 @@ namespace OpenTK.Platform.Windows
 
         #endregion
 
-        #region IsIdle
-
-        bool IsIdle
-        {
-            get
-            {
-                MSG message = new MSG();
-                return !Functions.PeekMessage(ref message, window.Handle, 0, 0, 0);
-            }
-        }
-
-        #endregion
-
         #region CreateWindow
 
         IntPtr CreateWindow(int x, int y, int width, int height, string title, GameWindowFlags options, DisplayDevice device, IntPtr parentHandle)
@@ -1217,20 +1204,11 @@ namespace OpenTK.Platform.Windows
 
         #region public void ProcessEvents()
 
-        private int ret;
         MSG msg;
         public void ProcessEvents()
         {
-            while (!IsIdle)
+            while (Functions.PeekMessage(ref msg, window.Handle, 0, 0, PeekMessageFlags.Remove))
             {
-                ret = Functions.GetMessage(ref msg, window.Handle, 0, 0);
-                if (ret == -1)
-                {
-                    throw new PlatformException(String.Format(
-                        "An error happened while processing the message queue. Windows error: {0}",
-                        Marshal.GetLastWin32Error()));
-                }
-
                 Functions.TranslateMessage(ref msg);
                 Functions.DispatchMessage(ref msg);
             }