Simple question: Managing alt-tabbing

Started by
14 comments, last by Zedix 18 years, 8 months ago
Quote:Original post by intrest86
Quote:Original post by Daggett
Managed resources are copied to memory, thus wasting several megabytes of space. If at all possible, you should use D3DPOOL_DEFAULT, as it's faster. And resetting the device is rather easy, my game does it in like 30 lines of code.

On the other hand the SDK clearly says that the managed pool should be the preffered pool for storage. Sure, everything has a copy in system memory, but unless the device is constantly being reset most of the data will simply be swapped out to the hard drive and not occupy memory. Since this is the common scenario, you aren't going to be facing actual memory consumption problems all that much. When the device is lost all of the managed resources get swapped back into memory, sent to the device, and then swapped back out. Sounds like an ideal solution to me, since setting the managed flag is always going to be less code then manually resetting everything.

I don't think there's managed ressources in DX7, is there?
Advertisement
Sorry Zedix; I totally overlooked the DX7 specification. This is totally different as in DX7 more needs to be done manually (I believe, for example, in windowed mode you had to recreate the back buffer and such). I do have some code (in a book) but no time as of yet to seek it out. Please let me know what you have and what exactly you want to know (which code parts).

Then: why still use DX7? I know it is not always so easy to switch so I'm just curious for your reasons. I also know DirectDraw got lost but you can do quite the same on a full-screen quad isn't it? (probably not)

Greetz,

Illco
Quote:Original post by intrest86
Quote:Original post by Daggett
Managed resources are copied to memory, thus wasting several megabytes of space. If at all possible, you should use D3DPOOL_DEFAULT, as it's faster. And resetting the device is rather easy, my game does it in like 30 lines of code.

On the other hand the SDK clearly says that the managed pool should be the preffered pool for storage. Sure, everything has a copy in system memory, but unless the device is constantly being reset most of the data will simply be swapped out to the hard drive and not occupy memory. Since this is the common scenario, you aren't going to be facing actual memory consumption problems all that much. When the device is lost all of the managed resources get swapped back into memory, sent to the device, and then swapped back out. Sounds like an ideal solution to me, since setting the managed flag is always going to be less code then manually resetting everything.

On the third hand.. both ATI and nVidia say you should use D3DPOOL_DEFAULT in their tech docs.
hi all
Great discussion but is there a method to stop windows from loosing focus on a application?
Is there a way to stop alt+tab?

for example in max paine 2 is impossible to alt+tab and if you somehow do it the computer is gets "Not Responding" :D
Quote:Original post by Illco
(...)Please let me know what you have and what exactly you want to know (which code parts).

Then: why still use DX7? I know it is not always so easy to switch so I'm just curious for your reasons. I also know DirectDraw got lost but you can do quite the same on a full-screen quad isn't it? (probably not)

That's no problem at all, it's been an informative discussion anyways :) First, the reason I used DX7: I'm new to this stuff, extremely new. I have a background coding in C, Java and a host of other web languages, but I've never touched graphics stuff. I've been reading on different graphical APIs trying to find a good tutorial for tileset RPGs, and I read a lot. It seems tutorials are somewhat hard to find for making 2d in DX9, and slightly harder to understand. Simply put, I found the concept of making a 2d RPG in 2d a lot simpler (DirectDraw), than playing with vertexes in a 3d space (Direct3d). On top of that, I found an excellent tutorial on gamedev that really contained everything I needed to get me started, and it was using DirectX7, so I decided to go with that. I understand it's outdated, but for a 2d RPG, it seems quite enough.

Now for the actual question at hand: I did find the DirectX7/DD7 SDK online and I'm using that as a base of reference. I'm using strictly Fullscreen mode, so all I need to check is if the program looses Fullscreen mode. IDirectDraw7::TestCooperativeLevel returns DDERR_NOEXCLUSIVEMODE if it does, or DD_OK if it's fine. (I don't need to check in windowed mode). It then looks like you have to pause your application. The SDK kinda gets vague after that, but says to restore it you need to call IDirectDraw7::RestoreAllSurfaces and reload the bitmaps on the surfaces etc.. This seems quite simple, and I'm afraid I'm missing something. I did try that code briefly yesterday, and when I alt-tabbed, I simply couldn't get back in my program, so I'm guessing I did something wrong. I'll try playing again with it this morning, if it doesn't work I'll try to post my code. Thanks for your help!

P.S: I know my partner will kill me for posting this. I tend to talk in terms of RPG, but in fact it's more like an adventure game a la Zelda. If you're reading this, sorry! Hehe!

Sorry for the double post, I finally got it working :) It's quite simple really, I just patched up a bunch of code I found on various threads on gamedev.net.

For future reference, if anyone needs it-

In your WindowProc:

    case WM_ACTIVATEAPP:       //Window is initialized for the first time       if(bInit == true)       {          bInit = false;          break;       }       //Window is being being restored from lost state       else if((bool)wparam == true)       {          lpdd7->RestoreAllSurfaces();          // Code to reload bitmaps on surfaces here       }      


The only problem with this code is that your game is still running in the background - it's not Paused. If you want to pause your game, you'll have to add code in your render loop to check for lost exclusive mode using TestCooperativeLevel().

Edit: Found a better way to Pause the game. Check if (bool)wparam == false, if yes just set a flag to false. Have your rendering code only execute if that flag is true. When wparam == true, simply set that flag back to true. (Make sure your PeekMessage and GetMessage code is being executed even if that flag is false, or else you'll never get the message that your window is being reactived... Oops!)

Thanks for all your help!

This topic is closed to new replies.

Advertisement