mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 19:58:00 +00:00
Create the FaceDown card state lazily.
Profiling showed this was responsible for 3% of execution time when using Simulated AI and is also wasting memory.
This commit is contained in:
@@ -282,7 +282,6 @@ public class Card extends GameEntity implements Comparable<Card> {
|
|||||||
view = new CardView(id0, game == null ? null : game.getTracker());
|
view = new CardView(id0, game == null ? null : game.getTracker());
|
||||||
currentState = new CardState(view.getCurrentState(), this);
|
currentState = new CardState(view.getCurrentState(), this);
|
||||||
states.put(CardStateName.Original, currentState);
|
states.put(CardStateName.Original, currentState);
|
||||||
states.put(CardStateName.FaceDown, CardUtil.getFaceDownCharacteristic(this));
|
|
||||||
view.updateChangedColorWords(this);
|
view.updateChangedColorWords(this);
|
||||||
view.updateChangedTypes(this);
|
view.updateChangedTypes(this);
|
||||||
view.updateSickness(this);
|
view.updateSickness(this);
|
||||||
@@ -357,9 +356,14 @@ public class Card extends GameEntity implements Comparable<Card> {
|
|||||||
}
|
}
|
||||||
public boolean setState(final CardStateName state, boolean updateView) {
|
public boolean setState(final CardStateName state, boolean updateView) {
|
||||||
if (!states.containsKey(state)) {
|
if (!states.containsKey(state)) {
|
||||||
|
if (state == CardStateName.FaceDown) {
|
||||||
|
// The face-down state is created lazily only when needed.
|
||||||
|
states.put(CardStateName.FaceDown, CardUtil.getFaceDownCharacteristic(this));
|
||||||
|
} else {
|
||||||
System.out.println(getName() + " tried to switch to non-existant state \"" + state + "\"!");
|
System.out.println(getName() + " tried to switch to non-existant state \"" + state + "\"!");
|
||||||
return false; // Nonexistant state.
|
return false; // Nonexistant state.
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (state.equals(currentStateName)) {
|
if (state.equals(currentStateName)) {
|
||||||
return false;
|
return false;
|
||||||
@@ -6281,6 +6285,8 @@ public class Card extends GameEntity implements Comparable<Card> {
|
|||||||
public final void setManifested(final boolean manifested) {
|
public final void setManifested(final boolean manifested) {
|
||||||
this.manifested = manifested;
|
this.manifested = manifested;
|
||||||
final String image = manifested ? ImageKeys.MANIFEST_IMAGE : ImageKeys.MORPH_IMAGE;
|
final String image = manifested ? ImageKeys.MANIFEST_IMAGE : ImageKeys.MORPH_IMAGE;
|
||||||
|
// Note: This should only be called after state has been set to CardStateName.FaceDown,
|
||||||
|
// so the below call should be valid since the state should have been created already.
|
||||||
getState(CardStateName.FaceDown).setImageKey(ImageKeys.getTokenKey(image));
|
getState(CardStateName.FaceDown).setImageKey(ImageKeys.getTokenKey(image));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user