From 6935c266503605b50e23b8017848892651c46855 Mon Sep 17 00:00:00 2001 From: Gonk Date: Tue, 25 Feb 2020 23:01:19 +0100 Subject: [PATCH] The different parts of the currently active map are now switched in one step. This should avoid a lot of dumps from race conditions. Highly experimental! --- .../src/com/gpl/rpg/AndorsTrail/Dialogs.java | 2 +- .../activity/ConversationActivity.java | 9 ++-- .../activity/DisplayWorldMapActivity.java | 2 +- .../activity/MonsterEncounterActivity.java | 2 +- .../activity/MonsterInfoActivity.java | 2 +- .../controller/CombatController.java | 24 +++++----- .../controller/ConversationController.java | 16 +++---- .../controller/GameRoundController.java | 14 +++--- .../controller/ItemController.java | 6 +-- .../AndorsTrail/controller/MapController.java | 10 ++--- .../controller/MonsterMovementController.java | 10 ++--- .../controller/MovementController.java | 44 +++++++++---------- .../controller/WorldMapController.java | 4 +- .../gpl/rpg/AndorsTrail/model/MapBundle.java | 11 +++++ .../rpg/AndorsTrail/model/ModelContainer.java | 12 ++--- .../AndorsTrail/model/map/PredefinedMap.java | 2 +- .../resource/tiles/TileManager.java | 9 ++-- .../LegacySavegamesContentAdaptations.java | 2 +- .../rpg/AndorsTrail/savegames/Savegames.java | 2 +- .../gpl/rpg/AndorsTrail/view/CombatView.java | 2 +- .../gpl/rpg/AndorsTrail/view/MainView.java | 8 ++-- 21 files changed, 103 insertions(+), 90 deletions(-) create mode 100644 AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/MapBundle.java diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/Dialogs.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/Dialogs.java index 19293b26a..12c0b68e1 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/Dialogs.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/Dialogs.java @@ -111,7 +111,7 @@ public final class Dialogs { if (!params.containsKey("x")) return null; int x = params.getInt("x"); int y = params.getInt("y"); - return world.model.currentMap.getMonsterAt(x, y); + return world.model.currentMaps.map.getMonsterAt(x, y); } public static void showMonsterEncounter(final MainActivity currentActivity, final ControllerContext context, final Monster monster) { diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/ConversationActivity.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/ConversationActivity.java index 98fbc7506..0aaee3fdf 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/ConversationActivity.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/ConversationActivity.java @@ -43,6 +43,7 @@ import com.gpl.rpg.AndorsTrail.model.item.Loot; import com.gpl.rpg.AndorsTrail.model.quest.Quest; import com.gpl.rpg.AndorsTrail.model.quest.QuestLogEntry; import com.gpl.rpg.AndorsTrail.model.quest.QuestProgress; +import com.gpl.rpg.AndorsTrail.resource.tiles.TileCollection; import com.gpl.rpg.AndorsTrail.resource.tiles.TileManager; import com.gpl.rpg.AndorsTrail.util.ThemeHelper; @@ -85,7 +86,7 @@ public final class ConversationActivity replyGroup.setLayoutParams(new ListView.LayoutParams(ListView.LayoutParams.MATCH_PARENT, ListView.LayoutParams.WRAP_CONTENT)); statementList = (ListView) findViewById(R.id.conversation_statements); statementList.addFooterView(replyGroup); - listAdapter = new StatementContainerAdapter(this, conversationHistory, world.tileManager); + listAdapter = new StatementContainerAdapter(this, conversationHistory, world.tileManager, world.model.currentMaps.tiles); statementList.setAdapter(listAdapter); nextButton = (Button) findViewById(R.id.conversation_next); @@ -349,10 +350,12 @@ public final class ConversationActivity private static final class StatementContainerAdapter extends ArrayAdapter { private final TileManager tileManager; + private final TileCollection tiles; - public StatementContainerAdapter(Context context, ArrayList items, TileManager tileManager) { + public StatementContainerAdapter(Context context, ArrayList items, TileManager tileManager, TileCollection tiles) { super(context, 0, items); this.tileManager = tileManager; + this.tiles = tiles; } @Override @@ -367,7 +370,7 @@ public final class ConversationActivity if (statement.hasActor()) { final Resources res = getContext().getResources(); if (statement.isPlayerActor) tileManager.setImageViewTileForPlayer(res, tv, statement.iconID); - else tileManager.setImageViewTileForMonster(res, tv, statement.iconID); + else tileManager.setImageViewTileForMonster(res, tv, statement.iconID, tiles); tv.setText(statement.actorName + ": " + statement.text, BufferType.SPANNABLE); Spannable sp = (Spannable) tv.getText(); diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/DisplayWorldMapActivity.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/DisplayWorldMapActivity.java index 50410e5d8..4c0904ec0 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/DisplayWorldMapActivity.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/DisplayWorldMapActivity.java @@ -93,7 +93,7 @@ public final class DisplayWorldMapActivity extends AndorsTrailBaseActivity { } WorldMapSegment segment = world.maps.worldMapSegments.get(worldMapSegmentName); - map = segment.maps.get(world.model.currentMap.name); + map = segment.maps.get(world.model.currentMaps.map.name); if (map == null) { this.finish(); return; diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/MonsterEncounterActivity.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/MonsterEncounterActivity.java index bdf69ce31..846669365 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/MonsterEncounterActivity.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/MonsterEncounterActivity.java @@ -41,7 +41,7 @@ public final class MonsterEncounterActivity extends AndorsTrailBaseActivity { TextView tv = (TextView) findViewById(R.id.monsterencounter_title); tv.setText(monster.getName()); - world.tileManager.setImageViewTile(getResources(), tv, monster); + world.tileManager.setImageViewTile(getResources(), tv, monster, world.model.currentMaps.tiles); tv = (TextView) findViewById(R.id.monsterencounter_description); tv.setText(getString(R.string.dialog_monsterencounter_message, difficulty)); diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/MonsterInfoActivity.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/MonsterInfoActivity.java index 16764b2a3..5de716a9b 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/MonsterInfoActivity.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/MonsterInfoActivity.java @@ -79,7 +79,7 @@ public final class MonsterInfoActivity extends AndorsTrailBaseActivity { private void updateTitle(Monster monster) { monsterinfo_title.setText(monster.getName()); - world.tileManager.setImageViewTile(getResources(), monsterinfo_title, monster); + world.tileManager.setImageViewTile(getResources(), monsterinfo_title, monster, world.model.currentMaps.tiles); monsterinfo_difficulty.setText(getMonsterDifficultyResource(controllers, monster)); } diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/CombatController.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/CombatController.java index 1045e889a..75706b472 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/CombatController.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/CombatController.java @@ -111,10 +111,10 @@ public final class CombatController implements VisualEffectCompletedCallback { } public void setCombatSelection(Coord p) { - Monster m = world.model.currentMap.getMonsterAt(p); + Monster m = world.model.currentMaps.map.getMonsterAt(p); if (m != null) { setCombatSelection(m, p); - } else if (world.model.currentTileMap.isWalkable(p)) { + } else if (world.model.currentMaps.tileMap.isWalkable(p)) { setCombatSelection(null, p); } } @@ -130,7 +130,7 @@ public final class CombatController implements VisualEffectCompletedCallback { public boolean canExitCombat() { return getAdjacentAggressiveMonster() == null; } private Monster getAdjacentAggressiveMonster() { - return MovementController.getAdjacentAggressiveMonster(world.model.currentMap, world.model.player); + return MovementController.getAdjacentAggressiveMonster(world.model.currentMaps.map, world.model.player); } public void executeMoveAttack(int dx, int dy) { @@ -157,7 +157,7 @@ public final class CombatController implements VisualEffectCompletedCallback { private void executeFlee(int dx, int dy) { // avoid monster fields when fleeing if (!controllers.movementController.findWalkablePosition(dx, dy, AndorsTrailPreferences.MOVEMENTAGGRESSIVENESS_DEFENSIVE)) return; - Monster m = world.model.currentMap.getMonsterAt(world.model.player.nextPosition); + Monster m = world.model.currentMaps.map.getMonsterAt(world.model.player.nextPosition); if (m != null) return; executeCombatMove(world.model.player.nextPosition); } @@ -200,11 +200,11 @@ public final class CombatController implements VisualEffectCompletedCallback { public void playerKilledMonster(Monster killedMonster) { final Player player = world.model.player; - Loot loot = world.model.currentMap.getBagOrCreateAt(killedMonster.position); + Loot loot = world.model.currentMaps.map.getBagOrCreateAt(killedMonster.position); killedMonster.createLoot(loot, player); - controllers.monsterSpawnController.remove(world.model.currentMap, killedMonster); - controllers.effectController.addSplatter(world.model.currentMap, killedMonster); + controllers.monsterSpawnController.remove(world.model.currentMaps.map, killedMonster); + controllers.effectController.addSplatter(world.model.currentMaps.map, killedMonster); controllers.actorStatsController.addActorAP(player, player.getSkillLevel(SkillCollection.SkillID.cleave) * SkillCollection.PER_SKILLPOINT_INCREASE_CLEAVE_AP); controllers.actorStatsController.addActorHealth(player, player.getSkillLevel(SkillCollection.SkillID.eater) * SkillCollection.PER_SKILLPOINT_INCREASE_EATER_HEALTH); @@ -218,7 +218,7 @@ public final class CombatController implements VisualEffectCompletedCallback { controllers.actorStatsController.applyOnDeathEffectsToPlayer(player, killedMonster); if (!loot.hasItemsOrGold()) { - world.model.currentMap.removeGroundLoot(loot); + world.model.currentMaps.map.removeGroundLoot(loot); } else if (world.model.uiSelections.isInCombat) { killedMonsterBags.add(loot); } @@ -307,7 +307,7 @@ public final class CombatController implements VisualEffectCompletedCallback { private void beginMonsterTurn(boolean isFirstRound) { controllers.actorStatsController.setActorMinAP(world.model.player); world.model.uiSelections.isPlayersCombatTurn = false; - for (MonsterSpawnArea a : world.model.currentMap.spawnAreas) { + for (MonsterSpawnArea a : world.model.currentMaps.map.spawnAreas) { for (Monster m : a.monsters) { controllers.actorStatsController.setActorMaxAP(m); } @@ -325,7 +325,7 @@ public final class CombatController implements VisualEffectCompletedCallback { if (shouldAttackWithMonsterInCombat(currentActiveMonster, playerPosition)) return MonsterAction.attack; } - for (MonsterSpawnArea a : world.model.currentMap.spawnAreas) { + for (MonsterSpawnArea a : world.model.currentMaps.map.spawnAreas) { for (Monster m : a.monsters) { if (!m.isAgressive(world.model.player)) continue; @@ -389,7 +389,7 @@ public final class CombatController implements VisualEffectCompletedCallback { } final Monster movingMonster = currentActiveMonster; - controllers.monsterMovementController.moveMonsterToNextPositionDuringCombat(currentActiveMonster, world.model.currentMap, new VisualEffectController.VisualEffectCompletedCallback(){ + controllers.monsterMovementController.moveMonsterToNextPositionDuringCombat(currentActiveMonster, world.model.currentMaps.map, new VisualEffectController.VisualEffectCompletedCallback(){ @Override public void onVisualEffectCompleted(int callbackValue) { combatActionListeners.onMonsterMovedDuringCombat(movingMonster); @@ -595,7 +595,7 @@ public final class CombatController implements VisualEffectCompletedCallback { world.model.worldData.tickWorldTime(); controllers.gameRoundController.resetRoundTimers(); controllers.actorStatsController.applyConditionsToPlayer(world.model.player, false); - controllers.actorStatsController.applyConditionsToMonsters(world.model.currentMap, true); + controllers.actorStatsController.applyConditionsToMonsters(world.model.currentMaps.map, true); } public void monsterSteppedOnPlayer(Monster m) { diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/ConversationController.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/ConversationController.java index 66c9dae58..55c3322c2 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/ConversationController.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/ConversationController.java @@ -130,7 +130,7 @@ public final class ConversationController { private void changeMapFilter(Resources res, String mapName, String effectID) { PredefinedMap map = findMapForScriptEffect(mapName); map.currentColorFilter = effectID; - if (world.model.currentMap == map) { + if (world.model.currentMaps.map == map) { controllers.mapController.applyCurrentMapReplacements(res, true); } } @@ -141,7 +141,7 @@ public final class ConversationController { } private PredefinedMap findMapForScriptEffect(String mapName) { - if (mapName == null) return world.model.currentMap; + if (mapName == null) return world.model.currentMaps.map; return world.maps.findPredefinedMap(mapName); } @@ -153,8 +153,8 @@ public final class ConversationController { private void spawnAll(String mapName, String areaId) { PredefinedMap map = findMapForScriptEffect(mapName); LayeredTileMap tileMap = null; - if (map == world.model.currentMap) { - tileMap = world.model.currentTileMap; + if (map == world.model.currentMaps.map) { + tileMap = world.model.currentMaps.tileMap; } for (MonsterSpawnArea area : map.spawnAreas) { if (!area.areaID.equals(areaId)) continue; @@ -174,12 +174,12 @@ public final class ConversationController { private void addAlignmentReward(Player player, String faction, int delta) { player.addAlignment(faction, delta); - MovementController.refreshMonsterAggressiveness(world.model.currentMap, world.model.player); + MovementController.refreshMonsterAggressiveness(world.model.currentMaps.map, world.model.player); } private void setAlignmentReward(Player player, String faction, int delta) { player.setAlignment(faction, delta); - MovementController.refreshMonsterAggressiveness(world.model.currentMap, world.model.player); + MovementController.refreshMonsterAggressiveness(world.model.currentMaps.map, world.model.player); } private void addQuestProgressReward(Player player, String questID, int questProgress, ScriptEffectResult result) { @@ -388,7 +388,7 @@ public final class ConversationController { if (currentPhrase == null) currentPhrase = new Phrase("(phrase \"" + phraseID + "\" not implemented yet)", null, null, null); } if (this.currentPhrase.switchToNPC != null) { - setCurrentNPC(world.model.currentMap.findSpawnedMonster(this.currentPhrase.switchToNPC)); + setCurrentNPC(world.model.currentMaps.map.findSpawnedMonster(this.currentPhrase.switchToNPC)); } } @@ -445,7 +445,7 @@ public final class ConversationController { listener.onConversationEnded(); return; } - controllers.monsterSpawnController.remove(world.model.currentMap, npc); + controllers.monsterSpawnController.remove(world.model.currentMaps.map, npc); listener.onConversationEndedWithRemoval(npc); } diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/GameRoundController.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/GameRoundController.java index b1681c61a..698b64307 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/GameRoundController.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/GameRoundController.java @@ -74,7 +74,7 @@ public final class GameRoundController implements TimedMessageTask.Callback { public void onNewFullRound() { controllers.mapController.resetMapsNotRecentlyVisited(); - controllers.actorStatsController.applyConditionsToMonsters(world.model.currentMap, true); + controllers.actorStatsController.applyConditionsToMonsters(world.model.currentMaps.map, true); controllers.actorStatsController.applyConditionsToPlayer(world.model.player, true); gameRoundListeners.onNewFullRound(); } @@ -87,19 +87,19 @@ public final class GameRoundController implements TimedMessageTask.Callback { public void onNewPlayerRound() { world.model.worldData.tickWorldTime(); controllers.actorStatsController.applyConditionsToPlayer(world.model.player, false); - controllers.actorStatsController.applySkillEffectsForNewRound(world.model.player, world.model.currentMap); - controllers.mapController.handleMapEvents(world.model.currentMap, world.model.player.position, MapObject.MapObjectEvaluationType.afterEveryRound); + controllers.actorStatsController.applySkillEffectsForNewRound(world.model.player, world.model.currentMaps.map); + controllers.mapController.handleMapEvents(world.model.currentMaps.map, world.model.player.position, MapObject.MapObjectEvaluationType.afterEveryRound); } public void onNewMonsterRound() { - controllers.actorStatsController.applyConditionsToMonsters(world.model.currentMap, false); + controllers.actorStatsController.applyConditionsToMonsters(world.model.currentMaps.map, false); } private void onNewTick() { controllers.monsterMovementController.moveMonsters(); - controllers.monsterSpawnController.maybeSpawn(world.model.currentMap, world.model.currentTileMap); + controllers.monsterSpawnController.maybeSpawn(world.model.currentMaps.map, world.model.currentMaps.tileMap); controllers.monsterMovementController.attackWithAgressiveMonsters(); - controllers.effectController.updateSplatters(world.model.currentMap); - controllers.mapController.handleMapEvents(world.model.currentMap, world.model.player.position, MapObject.MapObjectEvaluationType.continuously); + controllers.effectController.updateSplatters(world.model.currentMaps.map); + controllers.mapController.handleMapEvents(world.model.currentMaps.map, world.model.player.position, MapObject.MapObjectEvaluationType.continuously); gameRoundListeners.onNewTick(); } } diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/ItemController.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/ItemController.java index 7c822c6db..a1336d2a9 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/ItemController.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/ItemController.java @@ -35,7 +35,7 @@ public final class ItemController { public void dropItem(ItemType type, int quantity) { if (world.model.player.inventory.getItemQuantity(type.id) < quantity) return; world.model.player.inventory.removeItem(type.id, quantity); - world.model.currentMap.itemDropped(type, quantity, world.model.player.position); + world.model.currentMaps.map.itemDropped(type, quantity, world.model.player.position); } public void equipItem(ItemType type, Inventory.WearSlot slot) { @@ -245,8 +245,8 @@ public final class ItemController { public boolean removeLootBagIfEmpty(final Loot loot) { if (loot.hasItemsOrGold()) return false; - world.model.currentMap.removeGroundLoot(loot); - controllers.mapController.mapLayoutListeners.onLootBagRemoved(world.model.currentMap, loot.position); + world.model.currentMaps.map.removeGroundLoot(loot); + controllers.mapController.mapLayoutListeners.onLootBagRemoved(world.model.currentMaps.map, loot.position); return true; // The bag was removed. } diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/MapController.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/MapController.java index 2f9c12e4f..1bcb30ae1 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/MapController.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/MapController.java @@ -146,14 +146,14 @@ public final class MapController { for (PredefinedMap m : world.maps.getAllMaps()) { m.resetTemporaryData(); } - controllers.monsterSpawnController.spawnAll(world.model.currentMap, world.model.currentTileMap); + controllers.monsterSpawnController.spawnAll(world.model.currentMaps.map, world.model.currentMaps.tileMap); world.model.worldData.tickWorldTime(20); controllers.gameRoundController.resetRoundTimers(); } public void rest(MapObject area) { lotsOfTimePassed(); - world.model.player.setSpawnPlace(world.model.currentMap.name, area.id); + world.model.player.setSpawnPlace(world.model.currentMaps.map.name, area.id); worldEventListeners.onPlayerRested(); } @@ -168,7 +168,7 @@ public final class MapController { public void resetMapsNotRecentlyVisited() { for (PredefinedMap m : world.maps.getAllMaps()) { - if (m == world.model.currentMap) continue; + if (m == world.model.currentMaps.map) continue; if (m.isRecentlyVisited()) continue; if (m.hasResetTemporaryData()) continue; m.resetTemporaryData(); @@ -176,12 +176,12 @@ public final class MapController { } public void applyCurrentMapReplacements(final Resources res, boolean updateWorldmap) { - if (!applyReplacements(world.model.currentMap, world.model.currentTileMap)) return; + if (!applyReplacements(world.model.currentMaps.map, world.model.currentMaps.tileMap)) return; world.maps.worldMapRequiresUpdate = true; if (!updateWorldmap) return; WorldMapController.updateWorldMap(world, res); - mapLayoutListeners.onMapTilesChanged(world.model.currentMap, world.model.currentTileMap); + mapLayoutListeners.onMapTilesChanged(world.model.currentMaps.map, world.model.currentMaps.tileMap); } private boolean applyReplacements(PredefinedMap map, LayeredTileMap tileMap) { diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/MonsterMovementController.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/MonsterMovementController.java index b9e6be9f7..0a352aadd 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/MonsterMovementController.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/MonsterMovementController.java @@ -27,7 +27,7 @@ public final class MonsterMovementController implements EvaluateWalkable { public void moveMonsters() { long currentTime = System.currentTimeMillis(); - for (MonsterSpawnArea a : world.model.currentMap.spawnAreas) { + for (MonsterSpawnArea a : world.model.currentMaps.map.spawnAreas) { for (Monster m : a.monsters) { if (m.nextActionTime <= currentTime) { moveMonster(m, a); @@ -37,7 +37,7 @@ public final class MonsterMovementController implements EvaluateWalkable { } public void attackWithAgressiveMonsters() { - for (MonsterSpawnArea a : world.model.currentMap.spawnAreas) { + for (MonsterSpawnArea a : world.model.currentMaps.map.spawnAreas) { for (Monster m : a.monsters) { if (!m.isAgressive(world.model.player)) continue; if (!m.isAdjacentTo(world.model.player)) continue; @@ -75,8 +75,8 @@ public final class MonsterMovementController implements EvaluateWalkable { } private void moveMonster(final Monster m, final MonsterSpawnArea area) { - PredefinedMap map = world.model.currentMap; - LayeredTileMap tileMap = world.model.currentTileMap; + PredefinedMap map = world.model.currentMaps.map; + LayeredTileMap tileMap = world.model.currentMaps.tileMap; m.nextActionTime = System.currentTimeMillis() + getMillisecondsPerMove(m); if (m.movementDestination != null && m.position.equals(m.movementDestination)) { // Monster has been moving and arrived at the destination. @@ -159,7 +159,7 @@ public final class MonsterMovementController implements EvaluateWalkable { @Override public boolean isWalkable(CoordRect r, Monster m) { - return monsterCanMoveTo(null, world.model.currentMap, world.model.currentTileMap, r, m.area.ignoreAreas); + return monsterCanMoveTo(null, world.model.currentMaps.map, world.model.currentMaps.tileMap, r, m.area.ignoreAreas); } public void moveMonsterToNextPosition(final Monster m, final PredefinedMap map) { diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/MovementController.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/MovementController.java index a7d1e67c6..0646080f2 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/MovementController.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/MovementController.java @@ -7,6 +7,7 @@ import com.gpl.rpg.AndorsTrail.AndorsTrailPreferences; import com.gpl.rpg.AndorsTrail.context.ControllerContext; import com.gpl.rpg.AndorsTrail.context.WorldContext; import com.gpl.rpg.AndorsTrail.controller.listeners.PlayerMovementListeners; +import com.gpl.rpg.AndorsTrail.model.MapBundle; import com.gpl.rpg.AndorsTrail.model.ModelContainer; import com.gpl.rpg.AndorsTrail.model.actor.Monster; import com.gpl.rpg.AndorsTrail.model.actor.Player; @@ -56,7 +57,7 @@ public final class MovementController implements TimedMessageTask.Callback { protected void onPostExecute(Void result) { super.onPostExecute(result); stopMovement(); - playerMovementListeners.onPlayerEnteredNewMap(world.model.currentMap, world.model.player.position); + playerMovementListeners.onPlayerEnteredNewMap(world.model.currentMaps.map, world.model.player.position); controllers.gameRoundController.resume(); } @@ -83,7 +84,7 @@ public final class MovementController implements TimedMessageTask.Callback { } final ModelContainer model = world.model; - if (model.currentMap != null) model.currentMap.updateLastVisitTime(); + if (model.currentMaps.map != null) model.currentMaps.map.updateLastVisitTime(); model.player.position.set(place.position.topLeft); model.player.position.x += Math.min(offset_x, place.position.size.width-1); model.player.position.y += Math.min(offset_y, place.position.size.height-1); @@ -103,19 +104,28 @@ public final class MovementController implements TimedMessageTask.Callback { public void prepareMapAsCurrentMap(PredefinedMap newMap, Resources res, boolean spawnMonsters) { final ModelContainer model = world.model; - model.currentMap = newMap; - cacheCurrentMapData(res, newMap); + MapBundle newMaps = new MapBundle(); + newMaps.map = newMap; + + LayeredTileMap mapTiles = TMXMapTranslator.readLayeredTileMap(res, world.tileManager.tileCache, newMaps.map); + mapTiles.changeColorFilter(newMaps.map.currentColorFilter); + TileCollection cachedTiles = world.tileManager.loadTilesFor(newMaps.map, mapTiles, world, res); + newMaps.tileMap = mapTiles; + newMaps.tiles = cachedTiles; + world.tileManager.cacheAdjacentMaps(res, world, newMaps.map); + world.model.currentMaps = newMaps; + //Apply replacements before spawning, so that MonsterSpawnArea's isActive variable is up to date. controllers.mapController.applyCurrentMapReplacements(res, false); if (spawnMonsters) { if (!newMap.isRecentlyVisited()) { - controllers.monsterSpawnController.spawnAll(newMap, model.currentTileMap); + controllers.monsterSpawnController.spawnAll(newMap, model.currentMaps.tileMap); } } controllers.mapController.prepareScriptsOnCurrentMap(); newMap.visited = true; newMap.updateLastVisitTime(); - moveBlockedActors(newMap, model.currentTileMap); + moveBlockedActors(newMap, model.currentMaps.tileMap); refreshMonsterAggressiveness(newMap, model.player); controllers.effectController.updateSplatters(newMap); WorldMapController.updateWorldMap(world, res); @@ -131,7 +141,7 @@ public final class MovementController implements TimedMessageTask.Callback { if (!findWalkablePosition(dx, dy)) return; - Monster m = world.model.currentMap.getMonsterAt(world.model.player.nextPosition); + Monster m = world.model.currentMaps.map.getMonsterAt(world.model.player.nextPosition); if (m != null) { controllers.mapController.steppedOnMonster(m, world.model.player.nextPosition); return; @@ -196,14 +206,14 @@ public final class MovementController implements TimedMessageTask.Callback { ,player.position.y + dy ); - if (!world.model.currentTileMap.isWalkable(player.nextPosition)) return false; + if (!world.model.currentMaps.tileMap.isWalkable(player.nextPosition)) return false; // allow player to enter every field when he is NORMAL // prevent player from entering "non-monster-fields" when he is AGGRESSIVE // prevent player from entering "monster-fields" when he is DEFENSIVE if (aggressiveness == AndorsTrailPreferences.MOVEMENTAGGRESSIVENESS_NORMAL) return true; - Monster m = world.model.currentMap.getMonsterAt(player.nextPosition); + Monster m = world.model.currentMaps.map.getMonsterAt(player.nextPosition); if (m != null && !m.isAgressive(player)) return true; // avoid MOVEMENTAGGRESSIVENESS settings for NPCs if (aggressiveness == AndorsTrailPreferences.MOVEMENTAGGRESSIVENESS_AGGRESSIVE && m == null) return false; @@ -225,7 +235,7 @@ public final class MovementController implements TimedMessageTask.Callback { public void moveToNextIfPossible() { final Player player = world.model.player; - final PredefinedMap currentMap = world.model.currentMap; + final PredefinedMap currentMap = world.model.currentMaps.map; final Coord newPosition = player.nextPosition; for (MapObject o : currentMap.eventObjects) { @@ -251,7 +261,7 @@ public final class MovementController implements TimedMessageTask.Callback { if (!world.model.uiSelections.isInCombat) { //currentMap can be outdated due to mapchange events processed above. - Loot loot = world.model.currentMap.getBagAt(newPosition); + Loot loot = world.model.currentMaps.map.getBagAt(newPosition); if (loot != null) controllers.itemController.playerSteppedOnLootBag(loot); } } @@ -262,7 +272,7 @@ public final class MovementController implements TimedMessageTask.Callback { public void respawnPlayer(Resources res) { placePlayerAt(res, MapObject.MapObjectType.rest, world.model.player.getSpawnMap(), world.model.player.getSpawnPlace(), 0, 0); - playerMovementListeners.onPlayerEnteredNewMap(world.model.currentMap, world.model.player.position); + playerMovementListeners.onPlayerEnteredNewMap(world.model.currentMaps.map, world.model.player.position); } public void respawnPlayerAsync() { placePlayerAsyncAt(MapObject.MapObjectType.rest, world.model.player.getSpawnMap(), world.model.player.getSpawnPlace(), 0, 0); @@ -311,16 +321,6 @@ public final class MovementController implements TimedMessageTask.Callback { return null; } - private void cacheCurrentMapData(final Resources res, final PredefinedMap nextMap) { - LayeredTileMap mapTiles = TMXMapTranslator.readLayeredTileMap(res, world.tileManager.tileCache, nextMap); - mapTiles.changeColorFilter(nextMap.currentColorFilter); - TileCollection cachedTiles = world.tileManager.loadTilesFor(nextMap, mapTiles, world, res); - world.model.currentTileMap = mapTiles; - world.tileManager.currentMapTiles = cachedTiles; - world.tileManager.cacheAdjacentMaps(res, world, nextMap); - } - - private int movementDx; private int movementDy; public void startMovement(int dx, int dy, Coord destination) { diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/WorldMapController.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/WorldMapController.java index 74ef5dcfd..d1e31f6b5 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/WorldMapController.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/WorldMapController.java @@ -41,7 +41,7 @@ public final class WorldMapController { public static final int WORLDMAP_DISPLAY_TILESIZE = WORLDMAP_SCREENSHOT_TILESIZE; public static void updateWorldMap(final WorldContext world, final Resources res) { - updateWorldMap(world, world.model.currentMap, world.model.currentTileMap, world.tileManager.currentMapTiles, res); + updateWorldMap(world, world.model.currentMaps.map, world.model.currentMaps.tileMap, world.model.currentMaps.tiles, res); } private static void updateWorldMap( @@ -303,7 +303,7 @@ public final class WorldMapController { } public static boolean displayWorldMap(Context context, WorldContext world) { - String worldMapSegmentName = world.maps.getWorldMapSegmentNameForMap(world.model.currentMap.name); + String worldMapSegmentName = world.maps.getWorldMapSegmentNameForMap(world.model.currentMaps.map.name); if (worldMapSegmentName == null) { Toast.makeText(context, context.getResources().getString(R.string.display_worldmap_not_available), Toast.LENGTH_LONG).show(); return false; diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/MapBundle.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/MapBundle.java new file mode 100644 index 000000000..fa102330f --- /dev/null +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/MapBundle.java @@ -0,0 +1,11 @@ +package com.gpl.rpg.AndorsTrail.model; + +import com.gpl.rpg.AndorsTrail.model.map.LayeredTileMap; +import com.gpl.rpg.AndorsTrail.model.map.PredefinedMap; +import com.gpl.rpg.AndorsTrail.resource.tiles.TileCollection; + +public final class MapBundle { + public PredefinedMap map; + public LayeredTileMap tileMap; + public TileCollection tiles; +} diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/ModelContainer.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/ModelContainer.java index 4a768bf80..e4d942d28 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/ModelContainer.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/ModelContainer.java @@ -9,6 +9,7 @@ import com.gpl.rpg.AndorsTrail.context.WorldContext; import com.gpl.rpg.AndorsTrail.model.actor.Player; import com.gpl.rpg.AndorsTrail.model.map.LayeredTileMap; import com.gpl.rpg.AndorsTrail.model.map.PredefinedMap; +import com.gpl.rpg.AndorsTrail.resource.tiles.TileCollection; public final class ModelContainer { @@ -17,8 +18,7 @@ public final class ModelContainer { public final CombatLog combatLog = new CombatLog(); public final GameStatistics statistics; public final WorldData worldData; - public PredefinedMap currentMap; - public LayeredTileMap currentTileMap; + public MapBundle currentMaps = new MapBundle();; public ModelContainer(int startLives, boolean unlimitedSaves) { player = new Player(); @@ -31,13 +31,13 @@ public final class ModelContainer { public ModelContainer(DataInputStream src, WorldContext world, ControllerContext controllers, int fileversion) throws IOException { this.player = Player.newFromParcel(src, world, controllers, fileversion); - this.currentMap = world.maps.findPredefinedMap(src.readUTF()); + this.currentMaps.map = world.maps.findPredefinedMap(src.readUTF()); this.uiSelections = new InterfaceData(src, fileversion); if (uiSelections.selectedPosition != null) { - this.uiSelections.selectedMonster = currentMap.getMonsterAt(uiSelections.selectedPosition); + this.uiSelections.selectedMonster = currentMaps.map.getMonsterAt(uiSelections.selectedPosition); } this.statistics = new GameStatistics(src, world, fileversion); - this.currentTileMap = null; + this.currentMaps.tileMap = null; if (fileversion >= 40) { this.worldData = new WorldData(src, fileversion); } else { @@ -47,7 +47,7 @@ public final class ModelContainer { public void writeToParcel(DataOutputStream dest) throws IOException { player.writeToParcel(dest); - dest.writeUTF(currentMap.name); + dest.writeUTF(currentMaps.map.name); uiSelections.writeToParcel(dest); statistics.writeToParcel(dest); worldData.writeToParcel(dest); diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/PredefinedMap.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/PredefinedMap.java index f3bb09e85..20b383bd2 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/PredefinedMap.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/PredefinedMap.java @@ -361,7 +361,7 @@ public final class PredefinedMap { public boolean shouldSaveMapData(WorldContext world) { if (!hasResetTemporaryData()) return true; - if (this == world.model.currentMap) return true; + if (this == world.model.currentMaps.map) return true; if (!groundBags.isEmpty()) return true; for (MonsterSpawnArea a : spawnAreas) { if (this.visited && a.isUnique) return true; diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/resource/tiles/TileManager.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/resource/tiles/TileManager.java index 9ff2bf9d0..b56026ec0 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/resource/tiles/TileManager.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/resource/tiles/TileManager.java @@ -98,7 +98,6 @@ public final class TileManager { public final TileCache tileCache = new TileCache(); public TileCollection preloadedTiles;// = new TileCollection(116); - public TileCollection currentMapTiles; public TileCollection adjacentMapTiles; private final HashSet preloadedTileIDs = new HashSet(); @@ -177,9 +176,9 @@ public final class TileManager { - public void setImageViewTile(Resources res, TextView textView, Monster monster) { setImageViewTileForMonster(res, textView, monster.iconID); } + public void setImageViewTile(Resources res, TextView textView, Monster monster, TileCollection tiles) { setImageViewTileForMonster(res, textView, monster.iconID, tiles); } public void setImageViewTile(Resources res, TextView textView, Player player) { setImageViewTileForPlayer(res, textView, player.iconID); } - public void setImageViewTileForMonster(Resources res, TextView textView, int iconID) { setImageViewTile(res, textView, currentMapTiles.getBitmap(iconID)); } + public void setImageViewTileForMonster(Resources res, TextView textView, int iconID, TileCollection tiles) { setImageViewTile(res, textView, tiles.getBitmap(iconID)); } public void setImageViewTileForPlayer(Resources res, TextView textView, int iconID) { setImageViewTile(res, textView, preloadedTiles.getBitmap(iconID)); } public void setImageViewTile(Resources res, TextView textView, ActorConditionType conditionType) { setImageViewTile(res, textView, preloadedTiles.getBitmap(conditionType.iconID)); } public void setImageViewTile(Resources res, TextView textView, ActorConditionType conditionType, boolean immunityOverlay) { setImageViewTile(res, textView, preloadedTiles.getBitmap(conditionType.iconID), immunityOverlay); } @@ -249,9 +248,9 @@ public final class TileManager { } } - public void setImageViewTile(Resources res, ImageView imageView, Monster monster) { setImageViewTileForMonster(res, imageView, monster.iconID); } + public void setImageViewTile(Resources res, ImageView imageView, Monster monster, TileCollection tiles) { setImageViewTileForMonster(res, imageView, monster.iconID, tiles); } public void setImageViewTile(Resources res, ImageView imageView, Player player) { setImageViewTileForPlayer(res, imageView, player.iconID); } - public void setImageViewTileForMonster(Resources res, ImageView imageView, int iconID) { setImageViewTile(res, imageView, currentMapTiles.getBitmap(iconID)); } + public void setImageViewTileForMonster(Resources res, ImageView imageView, int iconID, TileCollection tiles) { setImageViewTile(res, imageView, tiles.getBitmap(iconID)); } public void setImageViewTileForPlayer(Resources res, ImageView imageView, int iconID) { setImageViewTile(res, imageView, preloadedTiles.getBitmap(iconID)); } // public void setImageViewTile(Resources res, ImageView imageView, ActorConditionType conditionType) { setImageViewTile(res, imageView, preloadedTiles.getBitmap(conditionType.iconID)); } public void setImageViewTile(Context ctx, ImageView imageView, ActorConditionType conditionType, boolean immunityOverlay) { setImageViewTile(ctx, imageView, preloadedTiles.getBitmap(conditionType.iconID), immunityOverlay); } diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/savegames/LegacySavegamesContentAdaptations.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/savegames/LegacySavegamesContentAdaptations.java index dd413f982..60d403a4f 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/savegames/LegacySavegamesContentAdaptations.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/savegames/LegacySavegamesContentAdaptations.java @@ -29,7 +29,7 @@ public class LegacySavegamesContentAdaptations { for (MonsterSpawnArea newarea : fields5Map.spawnAreas) { if (newarea.areaID.equals("guynmart_robber1")) { controllers.monsterSpawnController.spawnAllInArea(fields5Map, - (world.model.currentMap == fields5Map ? world.model.currentTileMap : null), + (world.model.currentMaps.map == fields5Map ? world.model.currentMaps.tileMap : null), newarea, true); break; } diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/savegames/Savegames.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/savegames/Savegames.java index 7a3aead4f..928b49f9a 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/savegames/Savegames.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/savegames/Savegames.java @@ -233,7 +233,7 @@ public final class Savegames { private static void onWorldLoaded(Resources res, WorldContext world, ControllerContext controllers) { controllers.actorStatsController.recalculatePlayerStats(world.model.player); controllers.mapController.resetMapsNotRecentlyVisited(); - controllers.movementController.prepareMapAsCurrentMap(world.model.currentMap, res, false); + controllers.movementController.prepareMapAsCurrentMap(world.model.currentMaps.map, res, false); controllers.gameRoundController.resetRoundTimers(); } diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/view/CombatView.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/view/CombatView.java index 105589936..2088625cb 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/view/CombatView.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/view/CombatView.java @@ -197,7 +197,7 @@ public final class CombatView extends RelativeLayout implements CombatSelectionL currentMonster = null; if (selectedMonster != null) { monsterBar.setVisibility(View.VISIBLE); - world.tileManager.setImageViewTile(res, monsterInfo, selectedMonster); + world.tileManager.setImageViewTile(res, monsterInfo, selectedMonster, world.model.currentMaps.tiles); updateMonsterHealth(selectedMonster); currentMonster = selectedMonster; } diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/view/MainView.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/view/MainView.java index d1f2684b4..b7e52ee4e 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/view/MainView.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/view/MainView.java @@ -167,8 +167,8 @@ public final class MainView extends SurfaceView sh.setFixedSize(surfaceSize.width, surfaceSize.height); } - if (model.currentMap != null) { - onPlayerEnteredNewMap(model.currentMap, model.player.position); + if (model.currentMaps.map != null) { + onPlayerEnteredNewMap(model.currentMaps.map, model.player.position); } else { redrawAll(RedrawAllDebugReason.SurfaceChanged); } @@ -506,8 +506,8 @@ public final class MainView extends SurfaceView movingSpritesRedrawTick.start(); synchronized (holder) { currentMap = map; - currentTileMap = model.currentTileMap; - tiles = world.tileManager.currentMapTiles; + currentTileMap = model.currentMaps.tileMap; + tiles = world.model.currentMaps.tiles; movingSprites = 0; Size visibleNumberOfTiles = new Size( Math.min(screenSizeTileCount.width, currentMap.size.width)