Slick Forums

Discuss the Slick 2D Library
It is currently Thu May 23, 2013 7:03 am

All times are UTC




Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: Input/Output help
PostPosted: Wed Jul 06, 2011 5:19 pm 
Offline

Joined: Wed Jul 06, 2011 5:14 pm
Posts: 33
Hey guys,

So how does one go about creating these I/O plugins? Im using a cache system which means I store all my files structurally in one file. How would I load my map and not get the "I can't file my tileset images" exception? By this I mean:

Code:
java.lang.RuntimeException: Resource not found: /../img/land.png


Am I able to use those images from an array? I have all my sprites loading to an array.

Thanks for your help, Mech


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 07, 2011 3:19 am 
Offline

Joined: Mon Jun 13, 2011 12:40 pm
Posts: 18
Have you tried writing the full path?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 07, 2011 7:16 pm 
Offline

Joined: Wed Jul 06, 2011 5:14 pm
Posts: 33
Shazer2 wrote:
Have you tried writing the full path?


Thats just it... There is no path to the images. They are stored in my cache. I was asking if there was a way to use images that are in my sprite array that i've already loaded from the cache.

Thanks for your reply.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 07, 2011 7:41 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1172
When you use URL to references resources you can provide your own URLStreamHandler to resolve them. You can take a look at the TWL Theme Editor sources.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 08, 2011 1:25 am 
Offline

Joined: Wed Jul 06, 2011 5:14 pm
Posts: 33
Is there a way I can load the tileset images later? Instead of the constructor automatically doing so?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 08, 2011 5:46 am 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1172
I have a library called TWLTiled which has separated model and rendering. It also has a tool to create a minimap. Using libGDX it can be used on Android. And of course all data loading is using URL.
You can check the (simple) demo.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 11, 2011 10:14 pm 
Offline

Joined: Wed Jul 06, 2011 5:14 pm
Posts: 33
MatthiasM wrote:
I have a library called TWLTiled which has separated model and rendering. It also has a tool to create a minimap. Using libGDX it can be used on Android. And of course all data loading is using URL.
You can check the (simple) demo.


Okay thanks. I'm looking for a way to load them from my cache... not a URL. As stated above, my cache is like a ZIP archive; storing files within in itself then using GZIP for compression. I can load my sprites, my entity files but I cannot load my Tiled maps because there is no option (i'm guessing) available. I'm doing so without extracting the cache. I noticed the TiledMap has a constructor for an InputStream so I'm using the DataInputStream to read a certain amount of bytes into a ByteArrayInputStream for storage then calling this:

'input' being my DataInputStream and my ZoneMap extends TiledMap and implements TileBasedMap for various pathfinding abilities...
Code:
               byte[] buffer = new byte[(int) length];
               input.readFully(buffer, 0, (int) length);

               ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
               // ZoneMap map = new ZoneMap(bais);

               // Game.getMaps().add(map);


I have them commented out for the obvious reason of them not loading the sprites used for the TileSets.

If I've missed something here or you need me to explain something a little more please don't hesitate to ask me.

Thanks for your help and kindness.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 11, 2011 10:17 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1172
You can do all that just fine with an URL - just provide your own URLStreamHandler.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 12, 2011 1:09 am 
Offline

Joined: Wed Jul 06, 2011 5:14 pm
Posts: 33
MatthiasM wrote:
You can do all that just fine with an URL - just provide your own URLStreamHandler.


What exactally would I use for a URL in this case?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 12, 2011 6:28 am 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1172
To allow code to access your "cache file" without the need for it to know about your file format.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 12, 2011 3:54 pm 
Offline

Joined: Wed Jul 06, 2011 5:14 pm
Posts: 33
MatthiasM wrote:
To allow code to access your "cache file" without the need for it to know about your file format.


Did I mention that I never extract the cache?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 12, 2011 4:16 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1172
That would defeat the purpose.

With URL + URLStreamHandler you can create a virtual file system (eg present data / folders etc which don't exist, or file formats normally not supported by the JVM) and let 3rd party code use it.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 12, 2011 5:14 pm 
Offline

Joined: Wed Jul 06, 2011 5:14 pm
Posts: 33
MatthiasM wrote:
That would defeat the purpose.

With URL + URLStreamHandler you can create a virtual file system (eg present data / folders etc which don't exist, or file formats normally not supported by the JVM) and let 3rd party code use it.


Oh okay, I will go and explore the URLStreamHandler docs. Thanks for all your help!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 19, 2011 1:16 am 
Offline

Joined: Wed Jul 06, 2011 5:14 pm
Posts: 33
Unfortuneatly, URLStreamHandler will not be an option for this.

My files are structured like this:
Code:
Parent directory as null terminated string
File name as null terminated string
File length as a long
File type as a byte
------------------------------------------------
String name = readString(input);
String parent = readString(input);
long length = input.readLong();
int fileType = input.readByte();


Then I parse them out like this:
Code:
            if (fileType == 0) {
               if (Cache.CURRENT_STATE != 1) {
                  Cache.CURRENT_STATE = 1;
               }

               byte[] buffer = new byte[(int) length];
               input.readFully(buffer, 0, (int) length);

               ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
               Sprite img = new Sprite(bais, name, false);

               Game.getSprites().add(img);
               System.out.println("Added sprite '" + name + "'");
            }


Can you see my issue now?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group