I am having some trouble with loading on android as it is taking for ever to load a 500x500 map
Okay first:
How do i make it load from another thread? I am using libgdx but I would like to know how to do it in pure java and libgdx Gdx.app.postRunnable() I want another thread so i can show the user that the game is loading with a little animation screen
second for a map size of 500 x 500 should i consider using the chunking system… if so how?
Here is my parser code
public static TileMap loadMap(FileHandle file) {
if (!file.extension().contains("hawk")) {
System.err.println("Wrong file");
return new TileMap(100, 100, TileType.GRASS);
}
TileMap map = null;
BufferedReader reader = new BufferedReader(new StringReader(file.readString()));
try {
String[] configString = reader.readLine().split(",");
int mapWidth = Integer.parseInt(configString[0]);
int mapHeight = Integer.parseInt(configString[1]);
String line = null;
int counterX = 0;
int counterY = 0;
MasterTile[][] tiles = new MasterTile[mapWidth][mapHeight];
while ((line = reader.readLine()) != null) {
String[] split = line.split(",");
int botTile = Integer.parseInt(split[0]);
int topTile = Integer.parseInt(split[1]);
float rotationBot = 90;
float rotationTop = 90;
boolean fXBot = false;
boolean fYBot = false;
boolean fXTop = false;
boolean fYTop = false;
if(split.length > 2){
rotationBot = Float.parseFloat(split[2]);
rotationTop = Float.parseFloat(split[3]);
if(split.length > 4){
fXBot = Boolean.parseBoolean(split[4]);
fYBot = Boolean.parseBoolean(split[5]);
fXTop = Boolean.parseBoolean(split[6]);
fYTop = Boolean.parseBoolean(split[7]);
}
}
Tile bot = TileUtils.createTile(botTile);
bot.setRotation(rotationBot);
bot.setFlipX(fXBot);
bot.setFlipY(fYBot);
Tile top = TileUtils.createTile(topTile);
top.setRotation(rotationTop);
top.setFlipX(fXTop);
top.setFlipY(fYTop);
tiles[counterX][counterY] = new MasterTile(counterX*MasterTile.TILE_WIDTH, counterY*MasterTile.TILE_HEIGHT, top, bot);
counterY++;
if(counterY > mapHeight-1){
counterY = 0;
counterX++;
}
if(counterX > mapWidth-1){
counterX = 0;
}
}
map = new TileMap(mapWidth, mapHeight, tiles);
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
return map;
}