L.log("onResume");
if (!AndorsTrailApplication.getApplicationFromActivity(this).setup.isSceneReady) return;
+ if (world.model.uiSelections.isInCombat) {
+ view.combatController.setCombatSelection(world.model.uiSelections.selectedMonster, world.model.uiSelections.selectedPosition);
+ view.combatController.enterCombat(CombatController.BEGIN_TURN_CONTINUE);
+ }
view.gameRoundController.resume();
-
- if (world.model.uiSelections.isInCombat) {
- view.combatController.setCombatSelection(world.model.uiSelections.selectedMonster, world.model.uiSelections.selectedPosition);
- view.combatController.enterCombat(CombatController.BEGIN_TURN_CONTINUE);
- }
}
@Override
HashSet<Integer> iconIDs = world.tileManager.getTileIDsFor(container_buy);
iconIDs.addAll(world.tileManager.getTileIDsFor(player.inventory));
- TileCollection tiles = world.tileManager.tileCache.loadTilesFor(iconIDs, res);
+ TileCollection tiles = world.tileManager.loadTilesFor(iconIDs, res);
buyListAdapter = new ShopItemContainerAdapter(this, tiles, world.tileManager, player, container_buy, this, false);
sellListAdapter = new ShopItemContainerAdapter(this, tiles, world.tileManager, player, player.inventory, this, true);
shoplist_buy.setAdapter(buyListAdapter);
}
public static void cacheCurrentMapData(final Resources res, final WorldContext world, final PredefinedMap nextMap) {
+ L.log("-> cacheCurrentMapData");
+ long start = System.currentTimeMillis();
LayeredTileMap mapTiles = TMXMapTranslator.readLayeredTileMap(res, world.tileManager.tileCache, nextMap);
TileCollection cachedTiles = world.tileManager.loadTilesFor(nextMap, mapTiles, world, res);
world.model.currentTileMap = mapTiles;
world.tileManager.currentMapTiles = cachedTiles;
world.tileManager.cacheAdjacentMaps(res, world, nextMap);
+ long duration = System.currentTimeMillis() - start;
+ L.log(" <- cacheCurrentMapData " + duration + "ms");
}
public TileCollection loadTilesFor(Collection<Integer> iconIDs, Resources r) { return loadTilesFor(iconIDs, r, null); }
public TileCollection loadTilesFor(Collection<Integer> iconIDs, Resources r, TileCollection result) {
- cleanQueue();
+ if (AndorsTrailApplication.DEVELOPMENT_DEBUGMESSAGES) L.log("TileCache::loadTilesFor({" + iconIDs.size() + " items})");
int maxTileID = 0;
HashMap<ResourceFileTileset, HashMap<Integer, ResourceFileTile>> tilesToLoadPerSourceFile = new HashMap<ResourceFileTileset, HashMap<Integer, ResourceFileTile>>();
for(int tileID : iconIDs) {
maxTileID = Math.max(maxTileID, tileID);
}
+ boolean hasLoadedTiles = false;
if (result == null) result = new TileCollection(maxTileID);
for(Entry<ResourceFileTileset, HashMap<Integer, ResourceFileTile>> e : tilesToLoadPerSourceFile.entrySet()) {
TileCutter cutter = null;
if (AndorsTrailApplication.DEVELOPMENT_DEBUGMESSAGES) {
L.log("Loading tiles from tileset " + e.getKey().tilesetName);
}
+ if (!hasLoadedTiles) cleanQueue();
cutter = new TileCutter(e.getKey(), r);
+ hasLoadedTiles = true;
}
bitmap = cutter.createTile(tile.localID);
if (cutter != null) cutter.recycle();
}
- cleanQueue();
+ if (hasLoadedTiles) cleanQueue();
return result;
}
package com.gpl.rpg.AndorsTrail.resource.tiles;
+import java.util.HashMap;
import java.util.HashSet;
import android.content.res.Resources;
import com.gpl.rpg.AndorsTrail.model.map.MonsterSpawnArea;
import com.gpl.rpg.AndorsTrail.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail.model.map.TMXMapTranslator;
+import com.gpl.rpg.AndorsTrail.util.L;
public final class TileManager {
public static final int CHAR_HERO = 1;
public float scale;
- public final TileCache tileCache = new TileCache();
+ public final TileCache tileCache = new TileCache();
public final TileCollection preloadedTiles = new TileCollection(72);
public TileCollection currentMapTiles;
public TileCollection adjacentMapTiles;
private final HashSet<Integer> preloadedTileIDs = new HashSet<Integer>();
+ public TileCollection loadTilesFor(HashSet<Integer> tileIDs, Resources r) {
+ return tileCache.loadTilesFor(tileIDs, r);
+ }
+
public TileCollection loadTilesFor(ItemContainer container, Resources r) {
return tileCache.loadTilesFor(getTileIDsFor(container), r);
}
tileCache.loadTilesFor(preloadedTileIDs, r, preloadedTiles);
}
+ private HashMap<String, HashSet<Integer>> tileIDsPerMap = new HashMap<String, HashSet<Integer>>();
+ private void addTileIDsFor(HashSet<Integer> dest, String mapName, final Resources res, final WorldContext world) {
+ HashSet<Integer> cachedTileIDs = tileIDsPerMap.get(mapName);
+ if (cachedTileIDs == null) {
+ PredefinedMap adjacentMap = world.maps.findPredefinedMap(mapName);
+ if (adjacentMap == null) return;
+ LayeredTileMap adjacentMapTiles = TMXMapTranslator.readLayeredTileMap(res, tileCache, adjacentMap);
+ cachedTileIDs = getTileIDsFor(adjacentMap, adjacentMapTiles, world);
+ tileIDsPerMap.put(mapName, cachedTileIDs);
+ }
+ dest.addAll(cachedTileIDs);
+ }
public void cacheAdjacentMaps(final Resources res, final WorldContext world, final PredefinedMap nextMap) {
(new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... arg0) {
+ L.log("-> cacheAdjacentMaps");
+ long start = System.currentTimeMillis();
adjacentMapTiles = null;
HashSet<String> adjacentMapNames = new HashSet<String>();
HashSet<Integer> tileIDs = new HashSet<Integer>();
for (String mapName : adjacentMapNames) {
- PredefinedMap adjacentMap = world.maps.findPredefinedMap(mapName);
- if (adjacentMap == null) continue;
- LayeredTileMap adjacentMapTiles = TMXMapTranslator.readLayeredTileMap(res, tileCache, adjacentMap);
- tileIDs.addAll(getTileIDsFor(adjacentMap, adjacentMapTiles, world));
+ addTileIDsFor(tileIDs, mapName, res, world);
}
+ long duration = System.currentTimeMillis() - start;
+ L.log(" -- cacheAdjacentMaps " + duration + "ms");
adjacentMapTiles = tileCache.loadTilesFor(tileIDs, res);
+ duration = System.currentTimeMillis() - start;
+ L.log(" <- cacheAdjacentMaps " + duration + "ms");
return null;
}
}).execute();
if (!isAlive) return;
if (!hasQueuedTick) return;
hasQueuedTick = false;
- if (tick()) queueAnotherTick();
+ tick();
}
- private boolean tick() {
+ private void tick() {
nextTickTime = System.currentTimeMillis() + interval;
- return callback.onTick(this);
+ boolean continueTicking = callback.onTick(this);
+ if (continueTicking) queueAnotherTick();
}
private void sleep(long delayMillis) {
public void start() {
isAlive = true;
if (shouldCauseTickOnStart()) tick();
- queueAnotherTick();
+ else queueAnotherTick();
}
public void stop() {
package com.gpl.rpg.AndorsTrail.view;
+import java.util.HashSet;
+
import android.R.color;
import android.content.Context;
import android.content.res.Resources;
import com.gpl.rpg.AndorsTrail.context.ViewContext;
import com.gpl.rpg.AndorsTrail.context.WorldContext;
import com.gpl.rpg.AndorsTrail.model.item.ItemType;
+import com.gpl.rpg.AndorsTrail.resource.tiles.TileCollection;
import com.gpl.rpg.AndorsTrail.resource.tiles.TileManager;
public class QuickitemView extends LinearLayout implements OnClickListener {
private final WorldContext world;
private final ViewContext view;
- private final QuickButton[] items = new QuickButton[NUM_QUICK_SLOTS];
+ private final QuickButton[] buttons = new QuickButton[NUM_QUICK_SLOTS];
+ private final HashSet<Integer> loadedTileIDs = new HashSet<Integer>();
+ private TileCollection tiles = null;
public QuickitemView(Context context, AttributeSet attrs) {
super(context, attrs);
this.setBackgroundColor(res.getColor(color.transparent));
TypedArray quickButtons = res.obtainTypedArray(R.array.quick_buttons);
- for(int i = 0; i <items.length ; ++i) {
- items[i] = (QuickButton)findViewById(quickButtons.getResourceId(i, -1));
- QuickButton item = items[i];
+ for(int i = 0; i < buttons.length; ++i) {
+ buttons[i] = (QuickButton)findViewById(quickButtons.getResourceId(i, -1));
+ QuickButton item = buttons[i];
item.setIndex(i);
world.tileManager.setImageViewTileForUIIcon(item, TileManager.iconID_shop);
item.setOnClickListener(this);
}
public boolean isQuickButtonId(int id){
- for(QuickButton item: items){
+ for(QuickButton item: buttons){
if(item.getId()==id)
return true;
}
}
public void refreshQuickitems() {
+ loadItemTypeImages();
+
for (int i = 0; i < NUM_QUICK_SLOTS; ++i){
- QuickButton item = items[i];
+ QuickButton item = buttons[i];
ItemType type = world.model.player.inventory.quickitem[i];
- if(type==null) {
+ if (type == null) {
world.tileManager.setImageViewTileForUIIcon(item, TileManager.iconID_shop);
item.setEmpty(true);
} else {
- world.tileManager.setImageViewTileForSingleItemType(item, type, getResources());
+ world.tileManager.setImageViewTile(item, type, tiles);
item.setEmpty(!world.model.player.inventory.hasItem(type.id));
}
}
}
+ private void loadItemTypeImages() {
+ boolean shouldLoadImages = false;
+ for (ItemType type : world.model.player.inventory.quickitem) {
+ if (type == null) continue;
+ if (!loadedTileIDs.contains(type.iconID)) {
+ shouldLoadImages = true;
+ break;
+ }
+ }
+ if (!shouldLoadImages) return;
+
+ HashSet<Integer> iconIDs = new HashSet<Integer>();
+
+ for (ItemType type : world.model.player.inventory.quickitem) {
+ if (type == null) continue;
+ iconIDs.add(type.iconID);
+ }
+
+ loadedTileIDs.clear();
+ loadedTileIDs.addAll(iconIDs);
+ tiles = world.tileManager.loadTilesFor(iconIDs, getResources());
+ }
+
public void registerForContextMenu(MainActivity mainActivity) {
- for(QuickButton item: items)
+ for(QuickButton item: buttons)
mainActivity.registerForContextMenu(item);
}
}