Sorry for the double post but I just had a thought on how the caching could be implemented better.
Since TileSet is basically a Wrapper for a SpriteSheet it may be better to add a constructor to TiledMap that takes a SpriteSheet as a parameter. Somthing like:
Code:
public SpriteSheet(String ref, SpriteSheet tileset) throws SlickException{
//read data from ref
//creates TileSet from tileset SpriteSheet
//throws SlickException if tile dimensions disagree with xml doc
}
Then you could have your caching mechanism elsewhere instead of embedded in the TileMap Class. For example you can use the typical Singleton approach and do something like
Code:
SpriteSheet ss = ResourceLoader.getInstance().getTileSetA();
TileMap tm1 = new TileMap(fileLocation1, ss);
TileMap tm2 = new TileMap(fileLocation2, ss);
The down side to this is that there isn't much protection that the SpriteSheet will have the correct number of tiles or the right tile dimensions. So you will either need some magic numbers in the code, ugly and bad, or you will need to load the XML for the tileset when the SpriteSheet is created and then again when you create the tileMap; a little redundant.
I've been thinking of proposing a patch for some of the RFEs regarding TileMap that have been floating around so I figured I'd post to see what you thought of the approach.