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   
  Show Posts
Pages: [1] 2 3 ... 7
1  Game Development / Newbie & Debugging Questions / Re: NIO for networking on: 2010-11-03 23:37:12
Thanks!
Confirms my doubts, with that out of the way, does anyone know a good networking (p2p) library? Ironically most of them seem to be build around NIO (and client/server for that matter). I know about JXTA, but it's way too bloated and over-engineered for my taste.

Edit: Just found this lib (http://code.google.com/p/ice4j/) which should take care of most p2p NAT traversal issues.
2  Game Development / Newbie & Debugging Questions / NIO for networking on: 2010-11-03 09:48:19
Hi,

I'm about to start work on a simulation which sends its updates p2p. Depending available bandwidth a peer will have between 6 - 20 active connections.

I haven't done any tests yet, but would NIO be helpfull here? I've read mixed stories; That NIO is overly complex, that a thread per socket performs better for a small number of connections than NIO, and conversely that the memory footprint of a thread per socket adds up quickly...

Thanks!

Matthijs
3  Game Development / Newbie & Debugging Questions / Re: Floating Point Determinism in Java on: 2010-10-14 07:12:52
As i understand you should only have to add strictfp to the class. Not the fields or methods etc...  

Yes, I thought so too.

I may try that out just to see for sure that it works, the question comes up a lot (though not enough to use strictfp in the library by default).

It would be cool if jbox2d supported deterministic simulation as an option, fx like Riven suggest through an manipulation framework like ASM (http://asm.ow2.org/)
Please keep us updated on your findings.. Im particularly interested as I'll have a go on a p2p networked physics simulation in the near future.
4  Game Development / Newbie & Debugging Questions / Re: Floating Point Determinism in Java on: 2010-10-12 05:54:04
I remember this guy having setup a deterministic jbox2d simulation:
http://zetsgames.com/deterministic-physics/

Basically he added strictfp to all classes
5  Games Center / Archived Projects / Re: Virtual Ocean Races II (Beta test .... soon...) on: 2010-09-10 07:37:22
Nice one Bruno, good to see all that hard work payed off!
6  Java Game APIs & Engines / Java 2D / Re: Vectorization of image in Java (triangles on top of image) on: 2009-07-20 09:01:54
Additionally, you could have a look at http://www.vividsolutions.com/jts/JTSHome.htm


It implements many polygon operations (including the ones you asked about like simplifying polygons), its open-source so you could take a peek how they tackled it...
7  Games Center / Archived Projects / Re: 3DzzD - tests of realtime sea rendering (software Java 1.1) on: 2009-07-09 20:40:30
You just cant stop spitting out one nifty demo after another cant you? Wink

Can't wait for the fake subsurface scattering and wave splashes btw...  Roll Eyes
8  Java Game APIs & Engines / Java 2D / Re: Vectorization of image in Java (triangles on top of image) on: 2009-07-08 10:45:22
About the multiple image issue:
Can't you split them in a seperate images? You can identify an mask color for transparant pixels (fx black) in the image, which you can use as empty space for the marching squares algorithm or "cut" out seperate images from your map.

About the holes:
You could repeat the process for the marching squares from within the first transparant pixel you find within the bounds of the already vectorized outline in the image. That will give the vector outline for the hole.

About the triangles:
Once you have created the concave polygon for your image you can use a tesselator to split the concave polygon into triangles which the gpu can render. JOGL has a nice tesselator in the glu package, if you dont want to stick to jogl, there are plenty of others around. But be aware that the quality of these tesselators can vary a great deal, some cant deal with concave polys, other cant handle holes in polys etcetc. I know the opengl version is very robust and I believe Slick also has a good one for tesselating SVG shapes.

Good luck!

Thijs
9  Java Game APIs & Engines / Java 2D / Re: Vectorization of image in Java (triangles on top of image) on: 2009-06-30 07:14:17
You should lookup the marching squares algorithm:
http://en.wikipedia.org/wiki/Marching_squares

It does exactly what you want, and the wiki entry links to a Java implementation.
10  Games Center / Archived Projects / Re: Test my platformer engine (WIP) Mac-testers appreciated! on: 2009-04-27 18:42:08
Ran flawlessly (50fps without bloom, +- 42fps with bloom) on IE & FF (jre 1.6.0_11) on winxp, core2dua 2.4Ghz, geforce 8600GT
11  Game Development / Newbie & Debugging Questions / Re: URL.openStream() very slow.... on: 2009-04-16 08:26:26
URL.openStream() is deadly slow... like if it was loading the whole file somewhere before returning the stream.

the problem is that for a big file >1MB my progressbar is stuck at 0 percent then suddently goes 100% and I dont find that is very user friendly.

I know this was the case with all versions of the sun plugin when urlconnection.setusecache is set to true (the ms jvm didnt have this problem if I recall correctly):

http://www.java-gaming.org/topics/reading-files-from-an-applet/11472/msg/90709/view.html#msg90709
http://www.java-gaming.org/topics/jogl-applet-security/11269/msg/90225/view.html#msg90225
http://www.java-gaming.org/topics/java-cache/19400/msg/155096/view.html#msg155096

Maybe they screwed up even more in the latest release which makes this behaviour always present?  Undecided

edit:
Maybe a workaround could be what you suggested, by doing it yourself... the only problem is that the jvm wont cache files that way (not without signing the applet and doing that yourself too), something you clearly want for big files and applets. Maybe you can trick the jvm in downloading the file yourself in memory (showing progress), and then establishing an urlconnection to a file in memory with setusecache(true) or something like that...
12  Discussions / General Discussions / Re: What happened to java.com? on: 2009-03-17 19:47:27
Thank you for your feedback. Sun's professional translator and reviewers disagree with you and consider the Dutch translation on that page correct.

Dmitri



Argh!
I'm also Dutch, and though I'm no Dutch linguist, I know for fact that the Dutch translation is horrible!

edit: and like Riven said, it isnt anything like "Belgium Dutch" neither, its more like broken English-Dutch translated by an chief Indian alike  Undecided
13  Discussions / General Discussions / Re: Applet VS Webstart , what do you prefer as a end user ? on: 2009-03-08 19:09:42
Definatly applets; They're all way backward compatible to java 1.1 (if you'd want and stick to the 1.1 syntax), their deployment is simple enough (require as few scary popups as possible) and run transparantly from within the browser like people are accustomed too with webapps.
14  Discussions / Business and Project Management Discussions / Re: Skill games on: 2009-02-01 09:10:59
Me and some fellow java delopers tried this once, with a games portal (see sig). You could compete in cash competitions in return for a micro payment (sms, pay phone or paypal). This is legal in most countries / states, as long as you make sure no chance / luck is involved. For example, in an arkanoid type of game, the powerups that you get after destroying a brick should be the same for all payers competing in that same competition, so I ended up calculating all random events based on an random seed, which could be feed to a competition. Still, there are some states where this is illegal, this is a snippet from the conditions and terms we made back then:

"Player's that reside in one of the following US states are not eligible to participate in prize competitions: Alaska, Iowa, Arizona, Louisiana, Arkansas, Maryland, Connecticut, Missouri, Delaware, South Dakota, Florida, Tennessee, Illinois, Vermont"

But note this list is probably not up to date, you should get some legal advice first, or only open it for countries you do know it's legal.
15  Game Development / Performance Tuning / Re: java cache on: 2008-12-11 18:04:36
You can also manually cache by storing the file at user.home + .whatever/ and you basically have your own resource folder on their HD.

Thats only possible with webstart and signed applets I'm afraid. If they use the JOGLAppletLauncher they wont have those rights from their own classes
16  Game Development / Performance Tuning / Re: java cache on: 2008-12-11 13:02:47
Yup,

Rename your resource files to .jar, download them over an urlconnection with setUseCache set to true (or false if you dont want to cache). Read in the byte[] and feed it to a zipstream and your done. If you try to load it with cache set to true, it will load the resource jar from the applet cache if its there. The only downside is that during the download (with caching on) the urlconnection wont tell you the nr of bytes it downloaded. This is because of some stupid implementation detail, if setUseCache is enabled, it's downloaded in an private stream somewhere deep in Suns classes. That stream is passed until the whole jar is downloaded and cached to disc... so no progress monitoring is possible :/

EDIT: .jar should read .class  Lips Sealed
17  Java Game APIs & Engines / Java 2D / Re: Weird symbol on java applet windows on: 2008-12-11 09:47:33
<edit> Just 1 further point you might want to chew on: you lot are all geeks. Proper, high-order grand wizard pointy propeller head geeks. You know about this stuff and even more strangely, you care. You are fundamentally interested in how things work and what they're doing. But the rest of the world does not give 2 shits. They just want stuff to work (which is largely why they click yes on nearly any dialog - "Do you want to grant permission to DodgyCorp.ru to access your computer so you can play Craptris?") Given that, they don't care about files being written to their hard drive any more than they care about how much heap the VM allocates on startup. They don't care, they don't understand, they don't even want to understand. All that matters to a normal person, a non-geek, is that the machine does what it is asked!

Cas Smiley

True, true... And (I assume) we're all good geeks here, but we know there are evil geeks too. The problem with the web is that you can easily stumble upon a website you didnt want to (redirect, wrong click etc). And if such a page contains an evil applet that screws the computer without notice, the user probably wants to disable all applets, and asociates applets==bad, and then we're all back in 1997 again :/

A popup doesnt have to be bad, can be userfriendly and maybe popup only once per author (signer) if you tell it so, it can simply say something like: "Yes i want to play games from this author". The notice must be clear (the flash way), and prefably be skinnable in some way, because Sun's own look&feel doesnt look/feel too good.
18  Java Game APIs & Engines / Java 2D / Re: Weird symbol on java applet windows on: 2008-12-10 22:18:24
Nice.  How does it do that? Reload a signed version of the applet or something?

It works like this:
An additional jar is added to the applet archive list, which is signed containing a loader class and a custom classloader. When this loader class is called it replaces the loaded securitymanager with its own (after the user has accepted the security question), which basically allows everything. Now you can tell the loader class to load a jar, it will load its classes through the custom classloader which has the original classloader as a parent. The beauty of this, is that the security popup is deferred until the unsigned applet loads the loader class from the signed jar.

The question is, why you need signed application? I bet it's because of 3D acceleration. If that would be handled gracefully (as outlined in my previous post here), it would leave signed applications only for special purpose things, where I find current security dialog a very proper solution. I agree with Matzon that signed code shouldn't be allowed to run by default.

I agree the current way it works (security popup) is fine for privileged actions, the user can accept it or not. And we developers can detect if the user accepted or not and act accordingly. Instead of using an "extensionloader" like I outlined above it would be nice if the JVM did this for us, check if an privileged action is invoked, check if the user accepted the security popup or not. Of course with this security popup it should have an option "reject", "accept once" and "always accept (for this applet)".
19  Games Center / Showcase / Re: Mini 3D FPS in an Applet Update 9 on: 2008-12-10 14:21:05
+! for cross-hair with the new mouse-look.

By the way, how did you do mouse capture without using Robot and all permissions? (or did you use Robot?)

Cross-hair is on the way, together with some menu's to help the user tune all settings.

The mouse capture is done using the Robot class, but I ask for permission before doing so, using the extensionloader I posted some while back. This means the applet can start within the sandbox, and ask for special rights at runtime when the user request a special feature like hw rendering or mouselook etc. The user only has to trust the applet once, from then on the applet is granted all privileged rights just like a normal signed applet.

Now you need to make some interesting levels Cheesy

Amazing, amazing work, the graphics are phenomenal. You guys just need some artists to help you out with models and you can churn out flash-style 3d games.

Well if you happen to know an artist who's willing to work for free we'd be glad to hear Wink
20  Java Game APIs & Engines / JavaFX / Re: JavaFX 1.0 released on: 2008-12-05 08:56:44
I've downloaded the SDK too, while the examples look very nice, I too had the problem that it took up to 2 minutes(!) until they showed something, in the console it displayed loading & validating the resource jars... Now i noticed it happens only the very first time that you try to load an fx applet. It would be nice if it at least displayed something in the applet (what it is exactly doing / progress)
21  Games Center / Showcase / Re: Mini 3D FPS in an Applet Update 8 on: 2008-11-28 12:21:01
I remind you that I worked on the Java Game Tome some months ago at the beginning of the project and I tested lots of games successfully (hundreds). My sound driver is fine, it works fine with TUER (webstart) and Tesseract (applet) that are both open source and use both AudioClip.
I don't have to place it, it is up to the author to do it and I see that he copied some jars on my machine when I activate the hardware rendering.

Well, something seems to break down with the AudioClip, especially since you say it happens when you try to walk; Thats when the footstep audioclip is played. We'll put a nosound version online to test.

I don't have to place it, it is up to the author to do it and I see that he copied some jars on my machine when I activate the hardware rendering.

I never said you'd have to, I said we forgot  Huh

The controlling is indeed bad and when i was trying to make a FPS-like game in Flash i had the same issue. I solved it by using WASD to move and turn around and using the mouse to aim. Here is an -unfinished- example of what i'm talking about.

Nice game! I just love these oldskool raycasted type of games. Those controls work very well for that type of game indeed, but I guess it'd work less intuitive in full 3d where 6dof mouselook is important. I'm working on a option that uses the robot class for mouselook, but it will require the user to accept a certificate when they chose that option. I guess it's the same dilema as console gamers vs pc gamers. Maybe we can give the non robot-mouselook players a slight advantage using limited auto-aiming or something.
22  Games Center / Showcase / Re: Mini 3D FPS in an Applet Update 8 on: 2008-11-27 22:53:54
I watch this in JConsole:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
Name: Thread-58
State: BLOCKED on java.lang.Object@1b94ea2 owned by: Direct Clip
Total blocked: 1  Total waited: 0

Stack trace:
com.sun.media.sound.DirectAudioDevice$DirectDL.flush(DirectAudioDevice.java:672)
com.sun.media.sound.JavaSoundAudioClip.stop(JavaSoundAudioClip.java:205)
   - locked com.sun.media.sound.JavaSoundAudioClip@13dc4d5
sun.plugin.viewer.context.AppletAudioClip.stop(AppletAudioClipFactory.java:340)
   - locked sun.plugin.viewer.context.AppletAudioClip@161def0
sun.plugin.viewer.context.PluginAudioClip.stop(AppletAudioClipFactory.java:181)
game.spiderExperiment.FPSSampleMain.playerControl(FPSSampleMain.java:789)
game.spiderExperiment.FPSSampleMain.doGameLogic(FPSSampleMain.java:521)
game.spiderExperiment.FPSSampleMain.render3DWorldSpace(FPSSampleMain.java:435)
net.dzzd.core.ap.render(Unknown Source)
net.dzzd.core.ap.run(Unknown Source)
java.lang.Thread.run(Thread.java:619)


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
Name: AWT-EventQueue-2
State: WAITING on java.awt.EventQueue@90ed81
Total blocked: 2  Total waited: 1 391

Stack trace:
java.lang.Object.wait(Native Method)
java.lang.Object.wait(Object.java:485)
java.awt.EventQueue.getNextEvent(EventQueue.java:479)
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:245)
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
java.awt.EventDispatchThread.run(EventDispatchThread.java:121)


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
java.io.FileNotFoundException: http://demo.dzzd.net/FPSSample8//LIB/gluegen-rt-natives-linux-i586.jar
   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
   at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
   at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
   at sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1296)
   at java.security.AccessController.doPrivileged(Native Method)
   at sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1290)
   at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:944)
   at net.dzzd.extension.jogl.JOGLLoader.a(Unknown Source)
   at net.dzzd.extension.jogl.JOGLLoader.load(Unknown Source)
   at net.dzzd.extension.loader.ExtensionLoader.loadExtension(Unknown Source)
   at net.dzzd.DzzD.newRender3D(Unknown Source)
   at net.dzzd.core.r.run(Unknown Source)
   at java.lang.Thread.run(Thread.java:619)
Caused by: java.io.FileNotFoundException: http://demo.dzzd.net/FPSSample8//LIB/gluegen-rt-natives-linux-i586.jar
   at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1239)
   at sun.net.www.protocol.http.HttpURLConnection.getHeaderField(HttpURLConnection.java:2052)
   at java.net.URLConnection.getHeaderFieldInt(URLConnection.java:579)
   at java.net.URLConnection.getContentLength(URLConnection.java:474)
   ... 6 more



After some minutes, the game is no more frozen but when I try to walk again, it gets frozen Sad

I succeed in going forward when I press the right button on the mouse without releasing it. When I touch the floor, it gets frozen again.

Looks like the cause is the first exception; its a problem with the sounddriver... or your sounddriver and jvm not liking eachother. Can you play sound (using AudioClip) with other Java apps/applets on that config?

I'm not sure about the second, the stacktrace doesnt seem to trace back to the applet, it seems related to the first exception.

The last exception is because you tried to switch to hardware rendering, but we havent placed the necesary jar online for your jvm (gluegen-rt-natives-linux-i586.jar)  Lips Sealed
23  Game Development / Newbie & Debugging Questions / Re: Noob on Networking and Game creating on: 2008-11-24 14:23:37
This online book is not yet complete, but promises to become a good online resource for writing multiplayer games:
http://gafferongames.wordpress.com/networking-for-game-programmers/

The guy has quite some expirience and has written an excellent tutorial on networked physics..
24  Discussions / General Discussions / Re: Applet Reliability: Test with me! (MSIE 7.0 please) on: 2008-11-20 10:25:03
It seemed to work fine in IE, though at some point it threw some exceptions

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
java.lang.InterruptedException
   at java.lang.Object.wait(Native Method)
   at java.lang.Thread.join(Unknown Source)
   at java.lang.Thread.join(Unknown Source)
   at main.SpookyApplet$1.run(SpookyApplet.java:49)
   at java.lang.Thread.run(Unknown Source)
SpookyApplet.run() -> stopped
java.lang.InterruptedException
   at java.lang.Object.wait(Native Method)
   at java.lang.Thread.join(Unknown Source)
   at java.lang.Thread.join(Unknown Source)
SpookyApplet.run() -> stopped
   at main.SpookyApplet$1.run(SpookyApplet.java:49)
   at java.lang.Thread.run(Unknown Source)
java.lang.InterruptedException
   at java.lang.Object.wait(Native Method)
   at java.lang.Thread.join(Unknown Source)
   at java.lang.Thread.join(Unknown Source)
   at main.SpookyApplet$1.run(SpookyApplet.java:49)
   at java.lang.Thread.run(Unknown Source)


Argh, I just had an exception after many page refreshes and a click on the remove button, but appearantly the whole JVM died, cant access console anymore..
25  Games Center / Showcase / Re: Battle tank 2 - a bird eye view shooter on: 2008-11-20 10:18:35
Yep that version works perfectly fine!
26  Games Center / Showcase / Re: Battle tank 2 - a bird eye view shooter on: 2008-11-18 13:26:14
i have download the latest java 1.6_10 vm, and i had the exactly the same problem as you described.

I suspect that the web server i am using has some issues with this update.  Now I have host the applet on my own tomcat server.
Could you try it again and see if this works:

http://130.216.39.215:8080/bt2/play.htm

Many thanks
(dont hack me plz)


Your server seems down atm...
27  Games Center / Showcase / Re: Battle tank 2 - a bird eye view shooter on: 2008-11-17 11:53:06
Damn! The applet failed me a couple of times too, it just  suddendly stopped showing anything.  Also the console shows nothing (unlike ur case).
I think it could be a flaw in my timer class, which cases the system to sleep forever.

May I ask what is your JVM version and what browser, operating system you are using?:

Ah sorry, forgot to post that:

Java Plug-in 1.6.0_10-beta
IE7.0
Windows XP

Also, with unresponsive browser window I meant the IE window didnt respond to anything (close, mini/maximize).. The applet kept updating, but couldnt get focus and my last key command was kept repeated (the turret kept rotating).  Actually the same thing happend just again while typing this message; I can play the game for a while but then it just stops responding to input. IE becomes unresponsive and the tab keeps "loading" (the IE page loading indicator keeps spinning). So the liveconnect exception could be related... I noticed you dont provide a mayscript (http://java.sun.com/javase/6/docs/technotes/guides/plugin/developer_guide/java_js.html) param to your applet? Not sure if you use js communication, but given the liveconnect bug in my console and the page that keeps loading...

PS: I just tested it in FF 3.03 and that works perfectly!
28  Discussions / General Discussions / Re: monitoring loading progress in Applet on: 2008-11-17 11:33:40
Thanks for posting the code, however I have a question:
Suppose now I have the raw data of a jpg image in the format of byte[],  how do I create an Image object from it?

Ah, thats the easy part Wink

Image = Toolkit.getDefaultToolkit().createImage( imagebyte[] );

Or

BufferedImage image = ImageIO.read ( new ByteArrayInputStream ( imagebyte[] ) );
29  Games Center / Showcase / Re: Battle tank 2 - a bird eye view shooter on: 2008-11-16 22:44:44
Cool game! Has lots of potential...

Unfortunatly it only worked ok for a minute or so, I had multiple tabs open and when I switched between them, the game became uncontrollable and the browser window became unresponsive. I could access the java console though, it displayed an exception (might be unrelated), but still:

Exception in thread "Applet 1 LiveConnect Worker Thread" java.lang.ClassFormatError: Incompatible magic value 1008813135 in class file netscape
   at java.lang.ClassLoader.defineClass1(Native Method)
   at java.lang.ClassLoader.defineClass(Unknown Source)
   at java.security.SecureClassLoader.defineClass(Unknown Source)
   at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   at java.lang.ClassLoader.loadClassInternal(Unknown Source)
   at java.lang.Class.forName0(Native Method)
   at java.lang.Class.forName(Unknown Source)
   at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo$JavaNameSpaceProxy.getJavaClass(Unknown Source)
   at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo$JavaNameSpaceProxy.getField(Unknown Source)
   at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo$2.run(Unknown Source)
   at java.security.AccessController.doPrivileged(Native Method)
   at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo.doObjectOp(Unknown Source)
   at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo$LiveConnectWorker.run(Unknown Source)
   at java.lang.Thread.run(Unknown Source)
30  Discussions / General Discussions / Re: monitoring loading progress in Applet on: 2008-11-11 08:59:55
Java 6 will cache it. I get 304 "Not Modified" responses in my apache logs all the time.

And if you're stuck with jre < 1.6 compatibility, you could always just zip your images and rename the zip to .class. f you download it over an urlconnection with the property useCache(true) it will cache your zip...

Below is an excerpt I copy pasted from my IO lib (some helper methods might be missing, but you get the point), the download method would return a byte[] of the zipped data in your case, which you can then feed to the decompress method:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
   public synchronized static byte[] downloadData(String resource, Class loader, ResourceInfo info, ProgressListener plistener, boolean cache)
   {
      try
      {
         InputStream is = openStream(resource, loader, info, cache);
         DataInputStream dis = new DataInputStream(is);
         
         if (dis==null) {
            Log.log(this, "Resource not found: " + resource);
            return null;
         }

         int length=dis.available();
         //read min blocks of 8kb to force frequent updates for plistener (=~1update/sec on a 56k modem)
         if (length <= 0) length = 8192;
         //read max blocks of 100kb to prevent downloading all data in one sweep
         if (length >= 10240) length = 10240;

         byte[] chunk=new byte[length];
         ByteArrayOutputStream bos = new ByteArrayOutputStream();

         //set the progresslistener if available
         //if (plistener != null) plistener.next(plistener.DOWNLOAD);

         //read in bytes from the stream & update the progresslistener if available
         int bytesRead = 0;
         while((bytesRead = dis.read(chunk,0,length)) != -1) {
            //System.out.println("bytes read from bis: "+bytesRead);
            bos.write(chunk,0,bytesRead);
            //if(plistener!=null) plistener.update(bytesRead);
         }

         bos.flush();
         closeStream(dis);
         closeStream(is);
         return bos.toByteArray();
      }
      catch(Exception e) {
         Log.log(this, e);
         return null;
      }
   }

   public synchronized static void decompress(byte[] data, ProgressListener plistener)
   {
      //check how many zipentries the data contains
      int size=getNrEntries(data),index=0;

      sizes = new String[size*2];

      //check if there are any entries to process and tell the progress listener
      if(size>0) {
         Log.log(this, "Decompressing: "+size+" zipentries found");
         //if(plistener!=null) plistener.init(size);
      }
      else
      {
         Log.log(this, "Decompressing: no zip entries in data");
         return;
      }

      try
      {
         ZipEntry ze;
         ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(data));

         while ((ze=zis.getNextEntry())!=null)
         {
            if (ze.isDirectory()) {
               continue;
            }
           
            size=(int)ze.getSize();
           
            sizes[index++]=ze.getName();
            sizes[index++]=""+size;
           
            Log.log(this, "Decompressing: zip entry: "+ze.getName()+","+"size="+size);
             
            //if this is a valid entry, decompress it
            if (size>-1)
            {
               //set the progresslistener for this entry
               //if(plistener!=null) plistener.next(plistener.DECOMP);

               byte[] decompData = new byte[(int)size];
               int bytesRead=0;
               int chunk=0;
               while ((size - bytesRead) > 0)
               {
                  chunk=zis.read(decompData,bytesRead,(int)size - bytesRead);
                  if (chunk==-1) {
                     break;
                  }
                  bytesRead+=chunk;
                 
                  //if(plistener!=null) plistener.update(chunk);
               }
           
               //cache the entry in the game cache
               GameContext.addObject(ze.getName(),decompData);
               Log.log(this, "Decompressing: zip entry: "+ze.getName()+"  bytes read="+bytesRead+",size="+size+",compressed size="+ze.getCompressedSize());
            }
            else
            {
               Log.log(this, "Decompressing: zip entry: "+ze.getName()+" has unknown size");
               continue;
            }
         }
      }
      catch (NullPointerException e) {
         Log.log(this, e);
      }
      catch (FileNotFoundException e)   {
         Log.log(this, e);
      }
      catch (IOException e) {
         Log.log(this, e);
      }
   }
Pages: [1] 2 3 ... 7
 

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 (23 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 (59 views)
2014-12-03 16:27:13

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

toopeicgaming1999 (123 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!