PDA

View Full Version : Using DirectX to code a non-.NET game



MTsoul
December 29th, 2006, 03:19 PM
First on-topic thread in this forum! :love:

But anyway. I've been taught to use a while(1) loop for the main loop for a DirectX game on Windows. The game would be in a window (not full screen). All operations would be done one frame by one frame in that loop. I'm thinking this is a really dumb idea. Is there a way to use event callback handlers for this? I'd be using DirectInput and Direct3D as input and drawing methods. I can't find any event handlers for DirectX :(

// edit - I'd be doing this in C++.

freeskier89
December 30th, 2006, 04:32 AM
using a while(1) loop really isn't that dumb of an idea. Actionscript was the first language I ever learned, and using a while loop as an enterFrame like event just seemed plain bizarre at first when I started using C# with DirectX, but it is quite efficient.

You wouldn't necessarily need to have the rendering in a loop, but it is mandatory that your DirectInput is in a loop. It isn't set up for event handlers. I am pretty sure Microsoft did this because it is more efficient. Think... a DirectInput event handler would essentally be using while loop to look for changes in the the keyboard buffer... The programmer needs to have a custom render loop. So this makes two separate while loops. Wouldn't it be more efficient to use one by sticking the input testing in the render loop? In many cases the more convenient a language/library is the less efficient it is.

I am not totally sure about this, but that is my best guess :)

MTsoul
December 30th, 2006, 02:50 PM
Ah-ha. Thanks for that. I guess Input has to be in a loop for sure.

I guess multi-threading would come in handy when I want graphics and logic processed separately, but that would really complicate things. Graphics rendering should go in the same loop even though there are animations?

Al6200
January 9th, 2007, 07:54 PM
In managed DirectX, OnPaint() {} is your "render loop", and I'd imagine you'd want to put all your main code in there.

You can't just use a regular while loop if you want to make a game, because a game requires constant execution. A regular while loop will only get some time share. You NEED ALL THE TIME-SHARE!!!

BWAHAHAHAHAHAHA