|
||||||||||||||||||
Add Forum to Favorites | Send Topic To a Friend | View Forum FAQ | Track this topic |
Last Thread Next Thread ![]() |
| Best way to impliment a loading screen? |
|
![]() xegoth Member since: 12/4/2002 |
||||
|
|
||||
| I have a DirectX app that takes a bit of time to load. What I want to do, is display a fullscreen bitmap (think like loading counter strike), while the game loads. I know I have to display my image after DirectX is initialized, but what about rendering it? I won't be in a render loop because I'll be loading my level. Does anyone know of a really good way to impliment a bitmap being displayed at load time? I can think of a few ways to do it but none of them stand out as really clean and effective to me. As far as I'm concerned, I want a simple implimentation that is displayed quickly. |
||||
|
||||
![]() circlesoft Member since: 2/2/2003 From: Baltimore, MD, United States |
||||
|
|
||||
If you have an organized loading system, you could do it by calling a fairly simple drawing function every n percent. Kind like this:LoadResources()
{
for( int i = 0; i < numResourcesToLoad; i++ )
{
// Load the resource
LoadResource( i );
float percentDone = i / numResourcesToLoad;
// Only update every 5 percent
if( (percentDone * 100) % 5 == 0 )
DrawLoadingScreen( percentDone );
}
}Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL ) |
||||
|
||||
![]() RDragon1 Member since: 2/7/2001 From: redmond, WA, United States |
||||
|
|
||||
| Or throw the resource loading into it's own thread. Then you'll still have your render loop, etc. Have the resource loading thread update the 'percentage done', and then you'll be able to use that during each render loop to render your progress bar, or however else you want your loading screen to work. Best of luck. |
||||
|
||||
![]() Sr_Guapo Member since: 5/30/2004 From: Troy, NY, United States |
||||
|
|
||||
| Those are the two ways that you can implement the loading screen. Circlesoft's implementation is undoubtably easier and will look decent for most things. However, if you want a continuously updated progress bar or a cool animation, then you will have to implement a seperate thread. |
||||
|
||||
![]() xegoth Member since: 12/4/2002 |
||||
|
|
||||
| What about just a fixed image without a loading bar. Do I need to continually redraw it or is once sufficient? |
||||
|
||||
![]() Daniel Miller Member since: 12/19/2004 From: Austin, TX, United States |
||||
|
|
||||
Quote: The back buffer can get trashed, I'm pretty sure. |
||||
|
||||
![]() Sr_Guapo Member since: 5/30/2004 From: Troy, NY, United States |
||||
|
|
||||
Quote: It depends how you do it, I guess. I would think that stuff could happen to the window and it may get kinda messed up while loading. If it is a pretty short load time, you may be ok though. |
||||
|
||||
![]() circlesoft Member since: 2/2/2003 From: Baltimore, MD, United States |
||||
|
|
||||
Quote: If you decide to not use a loading bar, and are having problems with the window getting trashed, just redraw the same screen after loading x percent of the resources. Just like I mentioned above, but without the loading bar stuff. |
||||
|
||||
![]() DrunkenHyena Member since: 1/17/2001 From: Winnipeg, Canada |
||||
|
|
||||
| Strange things can also happen if you don't run the message pump for an extended period of time, so you'll want to keep that in mind as well. I would lean towards a separate thread for the load. It just seems more elegant and scalable. Stay Casual, Ken Drunken Hyena |
||||
|
||||
![]() Dave Member since: 3/22/2004 From: London, United Kingdom |
||||
|
|
||||
Quote: If you do this then how does the other thread get the loaded data? ace |
||||
|
||||
![]() chad_420 Member since: 2/22/2005 From: tacoma, WA, United States |
||||
|
|
||||
| or you could have your resource loader call a callback function and have the function do whatever you want for a loading screen. If you do this then how does the other thread get the loaded data? if your loading screen needs the data you're about to load methinks there is a problem. |
||||
|
||||
![]() Muhammad Haggag Moderator Member since: 9/22/2000 From: Redmond, WA, United States |
||||
|
|
||||
Quote: Just a couple of notes for people who might use this code as is: 1) percentDone will always be zero, because the integer division will always be zero. Do something like: float percentDone = static_cast<float>(i)/numResourcesToLoad; 2) (percentDone * 100) % 5 is an illegal operation, because the modulus operator only works on integer types. So you'd have to do "static_cast<int>(percentDone * 100) % 5" or something similar. EDIT: Of course I realize Dustin's code is just off-the-top-of-the-head pseudo-code, but I feared that someone would be tempted to copy/paste it, and then bang his head against the wall when it doesn't work ![]() Please read the DirectX FAQ, it answers a lot of common technical questions | NeXe | Journal #259850 |
||||
|
||||
![]() circlesoft Member since: 2/2/2003 From: Baltimore, MD, United States |
||||
|
|
||||
Quote: Maybe I should start compiling and testing all of my code before I post. That or do it in English++ pseudocode hehe |
||||
|
||||
All times are ET (US)![]() |
Last Thread Next Thread ![]() |
|