Jump to content
  • Advertisement
Sign in to follow this  
KaptainKomunist

[.net] doing things the hard way...

This topic is 4440 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 in love with C#, it's a realy neat language to work with, especialy how it handles messages and stuff like that with delegates. My only problem is that I want to poll instead of waiting, so I can write some games. My first though, sadly enough was to use the DLL attribute thing, and abstract a bunch of win32 elements, such as window creation and the message pump. But I'm figuring there is probably already an easier way. I have several ideas, some of which I like even less... 1) Multi threading: create a seperate thread for the game and use the delegates to pass around variables and stuff. 2) Invalidating the rectangle immediately after every call to the paint delegate from within the paint function, and also have the game logic in that. I think that's prety sloppy myself. 3) set a timer to go off every 10ms and then just do the game logic and reseed the timer event. this seems like the best one, but it's still realy sloppy, and the timer won't always be as accurate as it should be. 4) there must be a default case, one where no other events are called, and i could handle my game logic and force a repaint in that. Are there any I'm missing? I think just calling the win32 stuff is still just the best option. I want to use OpenGL for the rendering, and that will be easy enough. (No, I'm not going to use TAO or MDX) Thanks

Share this post


Link to post
Share on other sites
Advertisement
Option 3 is a fairly good one, although not quite the way I'd go about it.

There are a few other timers available on the system, not just the stopwatch component in the drag-and-drop list of controls. It might take some p/invoke, but you should be able to access the high resolution timer on the system.

You can use this high-resolution timer to create your own scheduler that is specific to your game. Lots of games do this or something similar. Run events at intervals using your own scheduler. There is an example in one of the game programming gems books (2 or 3?) that backfills the time slices based on the previous execution time, the task priority, and other factors.

Some advantages of this are that you are building in your own in-game profiler, you can pause the game for whatever purpose you want including debugging, you can adjust the game speed at a single point, you can record everything that goes through the scheduler for instant replays or recordings, and so on.

Share this post


Link to post
Share on other sites
Quote:
Original post by frob
Option 3 is a fairly good one, although not quite the way I'd go about it.

There are a few other timers available on the system, not just the stopwatch component in the drag-and-drop list of controls. It might take some p/invoke, but you should be able to access the high resolution timer on the system.

You can use this high-resolution timer to create your own scheduler that is specific to your game. Lots of games do this or something similar. Run events at intervals using your own scheduler. There is an example in one of the game programming gems books (2 or 3?) that backfills the time slices based on the previous execution time, the task priority, and other factors.

Some advantages of this are that you are building in your own in-game profiler, you can pause the game for whatever purpose you want including debugging, you can adjust the game speed at a single point, you can record everything that goes through the scheduler for instant replays or recordings, and so on.


So, basicly using the .NET version of WM_TIMER, and then just correcting by using a performance timer?

System.Timers.ElapsedEventHandler
as a replacement for WM_TIMER?


Share this post


Link to post
Share on other sites
Not sure what you are trying to accomplish.

My engine employs a messaging system that allows a message to be sent via a delegate. Systems can listen to that event and get the message. The other way I approached this was to use a stack of messages that each system could poll every frame, but the coupling of system to system this required was a bit too much.

Hope this helps,
Krisc

Share this post


Link to post
Share on other sites
Quote:
Original post by Telastyn
Poll what, instead of waiting for what? You never actually describe your problem.

Maybe this is what you're looking for?


Yes, that is just about what I was looking for.
And by polling or waiting, i mean for system messages such as key presses, windows being closed, the usual kind of stuff. Essentialy waiting for a no event message. Thanks for the help though. I'll figure it out when I start coding.

I'm still prety used to the old Win32 way.

Share this post


Link to post
Share on other sites
One of the more common things to do is, is to use the OnPaint event.

Basicly, you perform all your game logic in the OnPaint event, and at the end of the OnPaint, you call this.Invalidate();


public void OnPaint(PaintEventArgs a)
{
// Game logic here

this.Invalidate();
}


Toolmaker

Share this post


Link to post
Share on other sites
You might use a loadbalancing technique that works like this for threads.
This might be applied to your message pump if you are doing this in a game.


duration = calculateDuration(lastTime, DateTime.Now);
//process everything and do message pump stuff here.
System.Threading.Thread.Sleep(duration);



* Calculate duration should make duration longer if you ended up with extra free time after processing.

* Calculate duration should make the duration shorter if processing took a long time.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!