Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualCC Ricers

Posted 16 January 2013 - 11:34 AM

My loading screen is a static class with a static function, because I won't need to display more than one screen at a time. So, similar to Milcho's setup. It also stores a list of the resources to load in a queue, to send to special content loader made for this type.

 

Here is some of my code in the loading screen. I've generalized the loader class to be any type of file you may want. I'm not familiar with Allegro or what ALLEGRO_BITMAP supports, but the trick is to go through each item frame by frame.

 

BitmapLoader Bitmaps;

LoadingState::LoadingState()
{
	Bitmaps.addToQueue("dragon.bmp");
        Bitmaps.addToQueue("tiles.bmp");
        Bitmaps.addToQueue("background.bmp");
}

void LoadState::update()
{

	if (!Bitmaps.queueEmpty()) {

		if (!Bitmaps.fileLoaded())
			Bitmaps.loadNext();

if (!Bitmaps.doneProcessing()) {

// Add to the data buffer

Bitmaps.Process();

}

else {


/// Add the bitmap to the scene and then clear buffer
Assets->addBitmap(Bitmaps.dataBuffer());
Bitmaps.clearData();
}
}
else
{
// Move on
Game->pushState(PlayingState::Instance());
}
}

 

 

 

Granted, I only needed to do this with 3D meshes, as it sometimes took more than a few seconds to load files in one go. For more complex assets such as meshes, I broke it down into smaller discrete parts of data, process a certain number of those at a time and treating that as one complete "item". One pass of processing is done per frame. Textures didn't need a lot of attention yet, but I didn't use too many of them so they were loaded in just one frame.

 

If individual files don't take too long, you can perhaps make your object loader more generic to read everything from map files to sounds or bitmaps. Then choose a certain number of files to load each frame, take that number and divide by the total of files on your list to determine the loading progress.


#1CC Ricers

Posted 16 January 2013 - 11:27 AM

My loading screen is a static class with a static function, because I won't need to display more than one screen at a time. So, similar to Milcho's setup. It also stores a list of the resources to load in a queue, to send to special content loader made for this type.

 

Here is some of my code in the loading screen. I've generalized the loader class to be any type of file you may want. I'm not familiar with Allegro or what ALLEGRO_BITMAP supports, but the trick is to go through each item frame by frame.

 

BitmapLoader Bitmaps;

LoadingState::LoadingState()
{
	Bitmaps.addToQueue("dragon.obj");
}

void LoadState::update()
{

	if (!Meshes.queueEmpty()) {

		if (!Meshes.fileLoaded())
			Meshes.loadNext();

		if (!Meshes.doneProcessing()) {
// Here the file is read/decoded and stored in a buffer.  // Depending on file it could be any reasonable discrete unit of data.  // Files that take longer to decode can be read in chunks here, for instance  Meshes.processInfo();

} if (Bitmaps.doneProcessing()) { // Add the bitmap to the scene Assets->addBitmap(Bitmaps.dataBuffer());
// Clears buffer data, resets fileLoaded and doneProcessing flags Bitmaps.clearData(); } } else { // All is loaded, queue up the Playing state Game->pushState(PlayingState::Instance()); }

 

 

 

Granted, I only needed to do this with 3D meshes, as it sometimes took more than a few seconds to load files in one go. For more complex assets such as meshes, I broke it down into smaller discrete parts of data, process a certain number of those at a time and treating that as one complete "item". One pass of processing is done per frame. Textures didn't need a lot of attention yet, but I didn't use too many of them so they were loaded in just one frame.

 

If individual files don't take too long, you can perhaps make your object loader more generic to read everything from map files to sounds or bitmaps. Then choose a certain number of files to load each frame, take that number and divide by the total of files on your list to determine the loading progress.


PARTNERS