Home » Community » Forums » DirectX and XNA » Best way to impliment a loading screen?
  Intel sponsors gamedev.net search:   
[Control Panel] [Register] [Bookmarks] [Who's Online] [Active Topics] [Stats] [FAQ] [Search]

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?
Post New Topic  Post Reply 
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.

 User Rating: 1036   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

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 )

 User Rating: 1712   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

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.


 User Rating: 1380   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

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.

 User Rating: 1517   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

What about just a fixed image without a loading bar. Do I need to continually redraw it or is once sufficient?

 User Rating: 1036   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Quote:
Original post by xegoth
What about just a fixed image without a loading bar. Do I need to continually redraw it or is once sufficient?


The back buffer can get trashed, I'm pretty sure.



 User Rating: 1079   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Quote:
Original post by xegoth
What about just a fixed image without a loading bar. Do I need to continually redraw it or is once sufficient?


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.

 User Rating: 1517   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

Quote:
Original post by Sr_Guapo
Quote:
Original post by xegoth
What about just a fixed image without a loading bar. Do I need to continually redraw it or is once sufficient?

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.

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.

 User Rating: 1712   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

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

 User Rating: 1457   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Quote:
Original post by RDragon1
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.


If you do this then how does the other thread get the loaded data?

ace



 User Rating: 1737   |  Rate This User  Send Private MessageView ProfileView JournalView GD Showcase Entries Report this Post to a Moderator | Link

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.

 User Rating: 1127   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Quote:
Original post by circlesoft
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 );
  }
}

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

 User Rating: 1823   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

Quote:
Original post by Coder
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

Maybe I should start compiling and testing all of my code before I post. That or do it in English++ pseudocode hehe

 User Rating: 1712   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

All times are ET (US)

Post Reply
 Last Thread Next Thread 
Forum Rules:
You may not post new threads
You may post replies
You may not edit your posts
You may not use HTML in your posts
Jump To:
Administrative Options: