Attempt to combat game memory leaks after game finishes.

- Make PLAY_LAND_SURROGATE a game field rather than static
- Remove games from cache more aggressively
- Remove targeting overlay from global view after game ends
This commit is contained in:
elcnesh
2015-04-02 14:35:42 +00:00
parent b7a47736bf
commit dc4559c577
10 changed files with 67 additions and 35 deletions

View File

@@ -44,6 +44,7 @@ import forge.game.card.CardLists;
import forge.game.card.CardPredicates;
import forge.game.card.CardView;
import forge.game.combat.Combat;
import forge.game.cost.Cost;
import forge.game.event.Event;
import forge.game.event.GameEventGameOutcome;
import forge.game.phase.Phase;
@@ -107,6 +108,19 @@ public class Game {
private final GameView view;
private final Tracker tracker = new Tracker();
public final Ability PLAY_LAND_SURROGATE = new Ability(null, (Cost) null) {
@Override
public boolean canPlay() {
return true; //if this ability is added anywhere, it can be assumed that land can be played
}
@Override
public void resolve() {
throw new RuntimeException("This ability is intended to indicate \"land to play\" choice only");
}
@Override
public String toUnsuppressedString() { return "Play land"; }
};
private final GameEntityCache<Player, PlayerView> playerCache = new GameEntityCache<>();
public Player getPlayer(PlayerView playerView) {
return playerCache.get(playerView);
@@ -140,7 +154,7 @@ public class Game {
rules = rules0;
match = match0;
spabCache.put(Ability.PLAY_LAND_SURROGATE.getId(), Ability.PLAY_LAND_SURROGATE);
spabCache.put(PLAY_LAND_SURROGATE.getId(), PLAY_LAND_SURROGATE);
int highestTeam = -1;
for (RegisteredPlayer psc : players0) {

View File

@@ -6427,8 +6427,8 @@ public class Card extends GameEntity implements Comparable<Card> {
}
if (getState(CardStateName.Original).getType().isLand() && player.canPlayLand(this)) {
Ability.PLAY_LAND_SURROGATE.setHostCard(this);
abilities.add(Ability.PLAY_LAND_SURROGATE);
game.PLAY_LAND_SURROGATE.setHostCard(this);
abilities.add(game.PLAY_LAND_SURROGATE);
}
return abilities;

View File

@@ -76,16 +76,4 @@ public abstract class Ability extends SpellAbility {
return this.getHostCard().isInPlay() && !this.getHostCard().isFaceDown();
}
public static final Ability PLAY_LAND_SURROGATE = new Ability(null, (Cost) null) {
@Override
public boolean canPlay() {
return true; //if this ability is added anywhere, it can be assumed that land can be played
}
@Override
public void resolve() {
throw new RuntimeException("This ability is intended to indicate \"land to play\" choice only");
}
@Override
public String toUnsuppressedString() { return "Play land"; }
};
}