public void MainLoop() private void OnApplicationIdle(object sender, EventArgs e) And the declarations for those two native methods members: [StructLayout(LayoutKind.Sequential)]public struct Message { public IntPtr hWnd; public WindowMessage msg; public IntPtr wParam; public IntPtr lParam; public uint time; public System.Drawing.Point p; } [System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously [DllImport("User32.dll", CharSet=CharSet.Auto)] public static extern bool PeekMessage(out Message msg, IntPtr hWnd, uint messageFilterMin, uint messageFilterMax, uint flags); |
Tom Miller's Render Loop
I am using vb.net 2003 an i am at a loss as to how to convert Tom Miller's render loop c# code sample into vb, could anyone help

Tom Miller's Render Loop
Rafe Wu
Debating managed DirectX render loops serves only one purpose - it prevents you from finishing your project.
If you are a beginner then start with the EmptyProject in the DirectX SDK and don't worry about it. If you like DoEvents/Paint then also don't worry about it. If you don't want to use those then use the one from Tom's blog. It really, really doesn't matter.... (for the record I switched in DoEvents/Paint on a big project - the difference wasn't even measurable). You will see much more perf by using smart code, proper algorithms and by simply drawing less on the screen.
Of course just move over to XNA and stop worrying about this forever....
Mr_Mojoman
zoso
Here is a basic convert using some tools on the web,
http://www.kamalpatel.net/ConvertCSharp2VB.aspx
I know that there are some errors there that are listed, but these should be easy to work out.
'Error: Converting Methods, Functions and Constructors
'Error: Converting While-Loops
Public void MainLoop()
{
' Hook the application's idle event
System.Windows.Forms.Application.Idle += New EventHandler(OnApplicationIdle)
System.Windows.Forms.Application.Run(myForm)
}
private void OnApplicationIdle(Object sender, EventArgs e)
{
while (AppStillIdle)
{
' Render a frame during idle time (no messages are waiting)
UpdateEnvironment()
Render3DEnvironment()
}
}
Private ReadOnly Property AppStillIdle() As Boolean
Get
Dim msg As NativeMethods.Message
Return Not NativeMethods.PeekMessage( msg, IntPtr.Zero, 0, 0, 0)
End Get
End Property
And the declarations for those two native methods members:
<StructLayout(LayoutKind.Sequential)> _
Public Structure Message
Public hWnd As IntPtr
Public msg As WindowMessage
Public wParam As IntPtr
Public lParam As IntPtr
Public time As System.UInt32
Public p As System.Drawing.Point
End Structure
<System.Security.SuppressUnmanagedCodeSecurity) ' We won't use this maliciously
(DllImport("User32.dll", CharSet=CharSet.Auto)> _
Public static extern Boolean PeekMessage( Message msg, IntPtr hWnd, System.UInt32 messageFilterMin, System.UInt32 messageFilterMax, System.UInt32 flags)
'----------------------------------------------------------------
' Converted from C# to VB .NET using CSharpToVBConverter(1.2).
' Developed by: Kamal Patel (http://www.KamalPatel.net)
'----------------------------------------------------------------
Mykre
www.ircomm.net
Managed DirectX and Game Programming Resources.
AndrewVos
I came across that discussion on Tom Miller's site and it seems quite an important topic for those writing games. And yet nearly all the game programming tutorials I'm finding online are using the Application.DoEvents() method, even though it appears to be plainly one of the worst possible ways to write a game according to Tom's blogs. I can't say it's reassuring to beginners to find they are being taught how to write games using a woefully bad method from the get-go.
Now Tom's effort at figuring out how to overcome this is a sterling one but his blog has the discussion split over multiple blog posts. There are also other blogs about Tom's render loop discussion with suggestions for alternatives that do not use something called P/Invoke (that cryptic bit of DLL importing code at the bottom of the listing apparently). Again though the discussions are split among multiple blog posts. Also, the explanations appear largely targetted at experienced coders.
I feel what's needed is for this whole topic of a suitable and efficient render loop to be put in one place and for that person to explain the why's of the concept, not just the how. And preferably not as stand-alone code pieces to plug in, but rather in the context of a full class definition, either starting from a C# (or VB) empty project template or the Windows Application project template. That way, you open up the concept to a much wider base of readers such as relative beginners, not just experienced code jockies. Then maybe we'll see the Application.DoEvents sample code that appear to dominate online tutorials banished once and for all :)
I'm also surprised that this important issue is not covered in any comprehensive manner on Microsoft's Coding4Fun website. There is a link to Tom's site in one of the tutorials, but this isn't really suitable because Tom's explanations and sparsely commented code examples appear to be for more experienced coders.
Anyone up to the challenge
questron
http://www.aisto.com/roeder/dotnet/
nabeelfarid
Pavel Sich