From: Oskar Wiksten Date: Tue, 7 Aug 2012 07:55:54 +0000 (+0200) Subject: Bugfix: reset spawns on maps that have not been visited recently. This will shrink... X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=c50b9f43cce494a6d02e4237e80f01c995ff03c1;p=users%2Fmchehab%2Fandors-trail.git Bugfix: reset spawns on maps that have not been visited recently. This will shrink the savegame size to about a fifth of the previous sizes. --- diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/Savegames.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/Savegames.java index ea91a53..7516e44 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/Savegames.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/Savegames.java @@ -24,6 +24,7 @@ import android.os.Environment; import com.gpl.rpg.AndorsTrail.context.WorldContext; import com.gpl.rpg.AndorsTrail.controller.ActorStatsController; import com.gpl.rpg.AndorsTrail.controller.Constants; +import com.gpl.rpg.AndorsTrail.controller.Controller; import com.gpl.rpg.AndorsTrail.controller.MovementController; import com.gpl.rpg.AndorsTrail.model.ModelContainer; import com.gpl.rpg.AndorsTrail.util.L; @@ -110,7 +111,8 @@ public final class Savegames { world.model.writeToParcel(dest, flags); dest.close(); } - public static int loadWorld(WorldContext world, InputStream inState) throws IOException { + + public static int loadWorld(WorldContext world, InputStream inState) throws IOException { DataInputStream src = new DataInputStream(inState); final FileHeader header = new FileHeader(src); if (header.fileversion > AndorsTrailApplication.CURRENT_VERSION) return LOAD_RESULT_FUTURE_VERSION; @@ -119,12 +121,17 @@ public final class Savegames { world.model = new ModelContainer(src, world, header.fileversion); src.close(); - ActorStatsController.recalculatePlayerCombatTraits(world.model.player); - MovementController.moveBlockedActors(world); + onWorldLoaded(world); return LOAD_RESULT_SUCCESS; } + private static void onWorldLoaded(WorldContext world) { + ActorStatsController.recalculatePlayerCombatTraits(world.model.player); + Controller.resetMaps(world, true, true); + MovementController.moveBlockedActors(world); + } + public static FileHeader quickload(Context androidContext, int slot) { try { if (slot != SLOT_QUICKSAVE) { diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/DebugInterface.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/DebugInterface.java index b373457..21e57f6 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/DebugInterface.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/DebugInterface.java @@ -120,7 +120,7 @@ public final class DebugInterface { public void onClick(View arg0) { for(PredefinedMap map : world.maps.predefinedMaps) { map.lastVisitTime = 1; - map.resetIfNotRecentlyVisited(); + map.resetIfNotRecentlyVisited(true); } mainActivity.showToast("DEBUG: maps respawned", Toast.LENGTH_SHORT); } diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/Controller.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/Controller.java index e4dc66c..3caefd6 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/Controller.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/Controller.java @@ -85,9 +85,7 @@ public final class Controller { player.spawnPlace = area.id; player.spawnMap = world.model.currentMap.name; } - for (PredefinedMap m : world.maps.predefinedMaps) { - if (m.visited) m.spawnAll(world); - } + resetMaps(world, false, true); } public static void ui_playerRested(final Activity currentActivity, final ViewContext viewContext, MapObject area) { @@ -102,10 +100,12 @@ public final class Controller { return false; } - public void resetMaps() { + public static void resetMaps(final WorldContext world, boolean excludeCurrentMap, boolean resetEvenIfMapIsAlreadyReset) { for (PredefinedMap m : world.maps.predefinedMaps) { - if (m == model.currentMap) continue; - m.resetIfNotRecentlyVisited(); + if (excludeCurrentMap) { + if (m == world.model.currentMap) continue; + } + m.resetIfNotRecentlyVisited(resetEvenIfMapIsAlreadyReset); } } diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/GameRoundController.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/GameRoundController.java index df94d67..5f1c460 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/GameRoundController.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/GameRoundController.java @@ -54,7 +54,7 @@ public final class GameRoundController implements TimedMessageTask.Callback { } private void onNewFullRound() { - view.controller.resetMaps(); + Controller.resetMaps(world, true, false); view.actorStatsController.applyConditionsToMonsters(model.currentMap, true); view.actorStatsController.applyConditionsToPlayer(model.player, true); } 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 5a1a5bc..57ab6f7 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/PredefinedMap.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/PredefinedMap.java @@ -159,7 +159,7 @@ public final class PredefinedMap { spawnAllInArea(world, a, respawnUniqueMonsters); } } - public void spawnAllInArea(WorldContext world, MonsterSpawnArea area, boolean respawnUniqueMonsters) { + private void spawnAllInArea(WorldContext world, MonsterSpawnArea area, boolean respawnUniqueMonsters) { while (area.isSpawnable(respawnUniqueMonsters)) { final boolean wasAbleToSpawn = spawnInArea(area, world, null); if (!wasAbleToSpawn) break; @@ -226,8 +226,10 @@ public final class PredefinedMap { public void updateLastVisitTime() { lastVisitTime = System.currentTimeMillis(); } - public void resetIfNotRecentlyVisited() { - if (lastVisitTime == VISIT_RESET) return; + public void resetIfNotRecentlyVisited(boolean resetEvenIfMapIsAlreadyReset) { + if (!resetEvenIfMapIsAlreadyReset) { + if (lastVisitTime == VISIT_RESET) return; + } if (isRecentlyVisited()) return; // We reset all non-unique spawn areas. This keeps the savegame file smaller, thus reducing load and save times. Also keeps the running memory usage slightly lower.