Skip to main content
GameDev.net gamedev.net
🔒 Locked

Best way to impliment a loading screen?

Started by xegoth Aug 5, 2005 at 12:06 AM 11 replies 2.3k views
Original Post
xegoth
xegoth
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
circlesoft
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 );  }}
RDragon1
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.
Sr_Guapo
Sr_Guapo
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.
Sean Henley [C++ Tutor]Rensselaer Polytechnic Institute
xegoth
xegoth
What about just a fixed image without a loading bar. Do I need to continually redraw it or is once sufficient?
Daniel Miller
Daniel Miller
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.
Sr_Guapo
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.
Sean Henley [C++ Tutor]Rensselaer Polytechnic Institute
circlesoft
circlesoft
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.
DrunkenHyena
DrunkenHyena
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,KenDrunken Hyena</FON
dave
dave
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
chad_420
chad_420
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
Muhammad Haggag
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(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(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 [smile]

circlesoft
circlesoft
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 [smile]

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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.