Sign in to follow this  

[.net] What game loop are you using?

This topic is 4841 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm just curious which way people are going. I am going to switch over my base code tonight to use PInvoking, and wanted to know who else has done this? What do you think is the best way for setting up the message pump using PInvoke? Currently I just have my renderer demo using Application.DoEvents(), but I always planned to swap it out down the road, I just had it using DoEvents to whip up something quick. Now I want to find the best possible way to set this up.

Share this post


Link to post
Share on other sites
Until performance becomes an issue for me, I am using the OnPaint method and invalidating the form. Although in other projects with lower memory constraints I use the Application.DoEvents(). In the new engine I am creating though it will be using PInvoke.

Share this post


Link to post
Share on other sites
Quote:
Original post by bL0wF1sH
Until performance becomes an issue for me, I am using the OnPaint method and invalidating the form. Although in other projects with lower memory constraints I use the Application.DoEvents(). In the new engine I am creating though it will be using PInvoke.


hehe it sounds like you have/are doing the same thing I did. I have been invalidating the form with OnPaint but for smaller tools I just use DoEvents! :)

Right now I am basically going to re-write my rendering code from the ground up, which is why I wanted to check what people feel the best way of doing it is? Make a message pump class with PInvoke and catch events?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I use a multi-threaded loop so a simple while statement does it for me. This lets me tweak various loops independent of each other for example the animation system may run 20 times per second where the actual render loop runs much faster. Every iteration of the render loop it checks the various other loops to see if a update is available.

Share this post


Link to post
Share on other sites
I, myself, use the PInvoke method, have for a while now.

Is it better? Well, that's not really the question you should ask, since the WinForms is based on PInvoke (atleast till avalon). The performance gain for smaller applications will be negligable, if any. It's when you get into larger applications that you will notice it. Also, wrapping up your PInvoke calls can make it very easy to use it in place of DoEvents.

The best way? No such thing.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I'd recommend avoiding p/invoke as far as possible. It will become more and more common that people don't allow applications to run unsafe code, thus assemblies using p/invoke will get security exceptions and not start.

Until you see your application's bottleneck in app.doevents don't optimize that. It's also something likely to be improved in future framework versions.

Share this post


Link to post
Share on other sites
I'm going to keep using PInvoke (QPF/QPC) until Microsoft puts a Hi-res timer in the .Net framework. TickCount works fine (and hi-res) in Linux, but I don't want my timer to have 17 ms resolution on Windows.

For my actual game loop, I am using something a bit different (Tao.OpenGL and SDLDotNet) so my program should run on both Windows and Linux. My loop is quite simple:

[code]
while( MagmaEngine.IsRunning )
{
Timer.Update();
//uses QPC by default, switches to TickCount if there's an exception

MagmaEngine.Draw();
//uses various OpenGL calls through an abstracted interface
MagmaEngine.HandleEvents();
//uses SDL.Events.PollAndDelegate
GameWorld.Update();
//guess...
}

Share this post


Link to post
Share on other sites

This topic is 4841 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this