Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Jar Indexing progress bar  (Read 2093 times)
0 Members and 1 Guest are viewing this topic.
Offline Jesse_Attard

Senior Newbie





« Posted 2009-11-26 04:37:54 »

Hello,

I am using Jar Indexing to load certain parts of the game at opportune times for the end user.

For example, most of the source (1mb worth or so) is in one JAR, whereas sfx and music are in another (27mb or so).

So they are able to download the basic 1mb app and show an in-game load screen.  The problem is, there doesn't seem to be any callback for when elements inside a jar are loaded from indexing.

Does anyone know a way around this? I'm referencing the audio in a separate thread, but that thread just blocks until the whole 27mb is downloaded. Best I can do right now is a spinner, but some indication of progress would be great.

Thanks for any help,

Jesse
Offline i30817

Junior Devvie





« Reply #1 - Posted 2009-11-26 08:05:40 »

If you know the downloaded size and can wrap the stream you can derive the download speed and indeed a progress bar.
I already did it (in the most inefficient possible way i think).
Offline Jesse_Attard

Senior Newbie





« Reply #2 - Posted 2009-11-26 14:41:46 »

How do you wrap the stream? Would you mind sharing your code?

Jesse
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 841
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #3 - Posted 2009-11-26 14:54:45 »

extend InputStream and overwrite the 3 read(..) methods, then pass the original InputStream in the constructor and delegate the all method invocations to it. Now you can hook some feedback interface onto the InputStream and get notified of read(...) invocations.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
Offline Jesse_Attard

Senior Newbie





« Reply #4 - Posted 2009-11-26 19:03:22 »

Okay, I follow what you are saying. I can do this no problem - however in my calling code, I am not actually "reading" the data into memory. I am simply "touching" it so Jar Indexing decides to download the JAR.

My code looks like:

1  
GetClass().getResourceAsStream(filename);


This is the function that blocks until the JAR is finished downloading.  Now I could wrap this in a subclass like you suggest, such as

1  
new WrappedInputStream(getClass().getResourceAsStream(filename));


but this will just block in the same way as before. My overloaded read methods would never be executed.

Jesse
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 841
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #5 - Posted 2009-11-26 19:14:50 »

It's not clear to me why you want to access your resources through a classloader. You can write a custom ClassLoader, that monitors its download progress, but why make it so hard for yourself? Put all the small resources in a JAR, and download the big stuff like music seperately, using URLConnection.getInputStream() and enable caching.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
Offline broumbroum

Junior Devvie





« Reply #6 - Posted 2009-11-26 19:50:50 »

I'm not sure if this is what you're seeking for, you're supposed to put the whole input stream in a BufferedInputStream.
I used to dowload .jar in this way :
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
        final URLConnection connection = src instanceof URL ? ((URL) src).openConnection() : null;
        final BufferedInputStream JXAextensionStream = connection instanceof URLConnection ? new BufferedInputStream(connection.getInputStream()) : src instanceof BufferedInputStream ? (BufferedInputStream) src : src instanceof InputStream ? new BufferedInputStream((InputStream) src) : null;
(...)
while ((r = inputStream.read(b)) != -1) {
                        JXAtmpPath.write(b, 0, r);
                        rBytes += r;
                        if (progressBar) {
                            if (!(src instanceof File)) {
                                UIMessage.getProgressBar(id).setString("downloaded " + Math.rint(rBytes * 10 / 1024) / 10.0 + " Kbytes");
                            }
                            UIMessage.updateProgress(id, rBytes, (int) connection.getContentLength();
                        }
                        /*** ERASED, hangs the SYSTEM.OUT if (_debug) {
                        System.out.print(".");
                        }*/

                    }        


you can find this in JXAenvUtils._fileCopy() of sf3jswing-jxakernel below at sf.net. Cheesy

::::... :..... :::::: ;;;:::™ b23:production 2006 GNU/GPL @ http://b23prodtm.webhop.info
on sf.net: /projects/sf3jswing
Java (1.6u10 plz) Web Start pool
dev' VODcast[/ur
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 841
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #7 - Posted 2009-11-26 19:56:02 »

Woa! The worst code I've seen. Ever.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
Offline Jesse_Attard

Senior Newbie





« Reply #8 - Posted 2009-11-27 14:53:27 »

There's no particular reason I'm using the class loader - other than that it works and caches in the way I want it to.  Just has this problem with the progress bar. 

I have not used the URLConnection before, but I will definitely give that a shot.  I am concerned however that the caching it would use sounds like it is not as persistent as the JAR caching.  (for example, it mentions circumventing the cache if the user hits refresh on their browser)  With Jar Caching, the file is cached until the user manually deletes it or it is updated server-side.

Jesse
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 841
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #9 - Posted 2009-11-27 16:23:08 »

Then put every big resource in its own JAR.


It seems you do not have a signed application, so you can't use custom ClassLoaders to monitor progress.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Jesse_Attard

Senior Newbie





« Reply #10 - Posted 2009-11-27 16:38:03 »

Yes that's what I'm currently debating. It seems like that will work fine.  But it makes me cry on the inside
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (33 views)
2014-12-15 09:26:44

Mr.CodeIt (24 views)
2014-12-14 19:50:38

BurntPizza (51 views)
2014-12-09 22:41:13

BurntPizza (84 views)
2014-12-08 04:46:31

JscottyBieshaar (46 views)
2014-12-05 12:39:02

SHC (60 views)
2014-12-03 16:27:13

CopyableCougar4 (62 views)
2014-11-29 21:32:03

toopeicgaming1999 (124 views)
2014-11-26 15:22:04

toopeicgaming1999 (114 views)
2014-11-26 15:20:36

toopeicgaming1999 (32 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!