Speed up game start by not loading map layers

* This can be done by making the assumption that all tiles from the maps tilesets will be used.
This commit is contained in:
Oskar Wiksten
2013-06-15 19:17:35 +02:00
parent cab1185f14
commit b455bf2dbe
4 changed files with 18 additions and 26 deletions

View File

@@ -30,8 +30,6 @@ public final class TMXMapFileParser {
try {
// Map format: http://sourceforge.net/apps/mediawiki/tiled/index.php?title=Examining_the_map_format
int eventType;
final ArrayList<TMXLayer> layers = new ArrayList<TMXLayer>();
final ArrayList<TMXTileSet> tileSets = new ArrayList<TMXTileSet>();
while ((eventType = xrp.next()) != XmlResourceParser.END_DOCUMENT) {
if (eventType == XmlResourceParser.START_TAG) {
String s = xrp.getName();
@@ -44,12 +42,8 @@ public final class TMXMapFileParser {
map.tileheight = xrp.getAttributeIntValue(null, "tileheight", -1);
XmlResourceParserUtils.readCurrentTagUntilEnd(xrp, new XmlResourceParserUtils.TagHandler() {
public void handleTag(XmlResourceParser xrp, String tagName) throws XmlPullParserException, IOException {
if (tagName.equals("tileset")) {
tileSets.add(readTMXTileSet(xrp));
} else if (tagName.equals("objectgroup")) {
if (tagName.equals("objectgroup")) {
map.objectGroups.add(readTMXObjectGroup(xrp));
} else if (tagName.equals("layer")) {
layers.add(readTMXMapLayer(xrp));
} else if (tagName.equals("property")) {
map.properties.add(readTMXProperty(xrp));
}
@@ -59,8 +53,6 @@ public final class TMXMapFileParser {
}
}
xrp.close();
map.layers = layers.toArray(new TMXLayer[layers.size()]);
map.tileSets = tileSets.toArray(new TMXTileSet[tileSets.size()]);
} catch (XmlPullParserException e) {
L.log("Error reading map \"" + name + "\": XmlPullParserException : " + e.toString());
} catch (IOException e) {

View File

@@ -39,10 +39,10 @@ public final class TMXMapTranslator {
return transformMap(resultMap, tileCache, map.name);
}
public ArrayList<PredefinedMap> transformMaps(DynamicTileLoader tileLoader, MonsterTypeCollection monsterTypes, DropListCollection dropLists) {
return transformMaps(maps, tileLoader, monsterTypes, dropLists);
public ArrayList<PredefinedMap> transformMaps(MonsterTypeCollection monsterTypes, DropListCollection dropLists) {
return transformMaps(maps, monsterTypes, dropLists);
}
public ArrayList<PredefinedMap> transformMaps(Collection<TMXMap> maps, DynamicTileLoader tileLoader, MonsterTypeCollection monsterTypes, DropListCollection dropLists) {
public ArrayList<PredefinedMap> transformMaps(Collection<TMXMap> maps, MonsterTypeCollection monsterTypes, DropListCollection dropLists) {
ArrayList<PredefinedMap> result = new ArrayList<PredefinedMap>();
Tile tile = new Tile();
@@ -59,18 +59,6 @@ public final class TMXMapTranslator {
}
final Size mapSize = new Size(m.width, m.height);
for (TMXLayer layer : m.layers) {
for (int y = 0; y < layer.height; ++y) {
for (int x = 0; x < layer.width; ++x) {
int gid = layer.gids[x][y];
if (gid <= 0) continue;
if (!getTile(m, gid, tile)) continue;
tileLoader.prepareTileID(tile.tilesetName, tile.localId);
}
}
}
ArrayList<MapObject> mapObjects = new ArrayList<MapObject>();
ArrayList<MonsterSpawnArea> spawnAreas = new ArrayList<MonsterSpawnArea>();

View File

@@ -1,6 +1,7 @@
package com.gpl.rpg.AndorsTrail.resource;
import java.util.HashMap;
import java.util.Map;
import android.util.SparseArray;
import android.util.SparseIntArray;
@@ -85,7 +86,17 @@ public final class DynamicTileLoader {
}
return tileID;
}
public void prepareAllMapTiles() {
for (Map.Entry<String, ResourceFileTilesetLoadList> tileset : preparedTilesetsByResourceName.entrySet()) {
if (!tileset.getKey().startsWith("map_")) continue;
ResourceFileTilesetLoadList b = tileset.getValue();
int numTiles = b.tileset.numTiles.width * b.tileset.numTiles.height;
for(int i = 0; i < numTiles; ++i) {
prepareTileID(b, i);
}
}
}
public void flush() {
tileCache.allocateMaxTileID(currentTileStoreIndex);

View File

@@ -159,7 +159,8 @@ public final class ResourceLoader {
mapReader.read(r, mapResourceId, mapName);
}
if (AndorsTrailApplication.DEVELOPMENT_DEBUGMESSAGES) timingCheckpoint("TMXMapReader");
world.maps.addAll(mapReader.transformMaps(loader, world.monsterTypes, world.dropLists));
world.maps.addAll(mapReader.transformMaps(world.monsterTypes, world.dropLists));
loader.prepareAllMapTiles();
mapReader = null;
if (AndorsTrailApplication.DEVELOPMENT_DEBUGMESSAGES) timingCheckpoint("mapReader.transformMaps");