how to monitor loading of ressources

hello,

in my game i have a lot of ressources (textures, sounds, maps, models, etc…) which all need to be loaded before the main window should show up.

what is the best way to monitor and visualize the loading progress? should i run a separate thread and constantly check for changed variables?
thanks!

Is there any problem with the ‘obvious’ solution of simply printing to standard out or updating some text component every time something has happened? For example, you could increment a counter for every resource loaded. It might not portray the time it is going to take very realistically, but when the user has run the application once or twice it’ll be easy to see approximately how far it is into the loading process.

i am sorry, i forgot to mention that i want to watch the loading process from another part of the program. preferably in another thread, so i can display a nice progressbar.

Use a implementation of MediaTracker for your image loading, when MediaTracker notifies that its done loading, then show the game.

here’s a forum link for it
http://www.java-gaming.org/forums/index.php?topic=13420.0

api
http://java.sun.com/j2se/1.5.0/docs/api/index.html

tutorials
http://www.google.com/search?q=mediatracker%20tutorials&svnum=100&hl=en&lr=&safe=off&sa=N&tab=iw

is the media tracker actually tracking madia yet and not just images?

I haven’t tried it yet, but NIO offers loading file data through buffers and such… maybe you should try that? It gives you insieght how much data was loaded, and you know from the start how much data needs to be loaded so you can create fine progress bar.

Yes, I think MediaTracker wouldn’t work with all files?

How about using URLConnection? With a thread, you can easy load data from the net and store it in a file + track progress. Something similar to:


 // where to store the data
OutputStream out = new FileOutputStream(localFilePath);   

 // where the file is located we want to download
URLConnection urlConnection = new URL(remoteFileURL).openConnection();     
InputStream in = urlConnection.getInputStream();

// globals
totalSize = urlConnection.getContentLength();
currentSize = 0;
byte buffer[1024];
boolean finished = false;

while (!finished) {
    int size = in.read(buffer);
    if (size == -1) {
       finished = true;
    }
    else {
      out.write(buffer, 0, size);
      currentSize += size;
    }
}

It won’t compile. There is also some stuff missing. However, that’s what I basically use. With the class variables “currentSize”/“totalSize” you can track the download progress from a separate class. I can send you my “FileDownloader” class if you are interested…