Optimize static effect checks even more based on profiling.

This commit is contained in:
Myrd
2015-02-14 07:09:05 +00:00
parent 5d6f5912e3
commit 9f03746360
2 changed files with 15 additions and 5 deletions

View File

@@ -56,12 +56,17 @@ import java.util.Map;
public final class GameActionUtil {
// Cache these instead of generating them on the fly, to avoid excessive allocations every time
// static abilities are checked.
private static final String[] BASIC_LAND_ABILITIES = new String[MagicColor.WUBRG.length];
@SuppressWarnings("unchecked")
private static final Map<String, String>[] BASIC_LAND_ABILITIES_PARAMS = new Map[MagicColor.WUBRG.length];
private static final AbilityRecordType[] BASIC_LAND_ABILITIES_TYPES = new AbilityRecordType[MagicColor.WUBRG.length];
static {
for (int i = 0; i < MagicColor.WUBRG.length; i++ ) {
String color = MagicColor.toShortString(MagicColor.WUBRG[i]);
BASIC_LAND_ABILITIES[i] = "AB$ Mana | Cost$ T | Produced$ " + color +
String abString = "AB$ Mana | Cost$ T | Produced$ " + color +
" | SpellDescription$ Add {" + color + "} to your mana pool.";
Map<String, String> mapParams = AbilityFactory.getMapParams(abString);
BASIC_LAND_ABILITIES_PARAMS[i] = mapParams;
BASIC_LAND_ABILITIES_TYPES[i] = AbilityRecordType.getRecordType(mapParams);
}
}
@@ -139,10 +144,11 @@ public final class GameActionUtil {
// add all appropriate mana abilities based on current types
for (int i = 0; i < MagicColor.WUBRG.length; i++ ) {
String landType = MagicColor.Constant.BASIC_LANDS.get(i);
String abString = BASIC_LAND_ABILITIES[i];
Map<String, String> mapParams = BASIC_LAND_ABILITIES_PARAMS[i];
AbilityRecordType type = BASIC_LAND_ABILITIES_TYPES[i];
for (final Card land : lands) {
if (land.getType().hasSubtype(landType)) {
final SpellAbility sa = AbilityFactory.getAbility(abString, land);
final SpellAbility sa = AbilityFactory.getAbility(mapParams, type, land);
sa.setBasicLandAbility(true);
land.getCurrentState().addManaAbility(sa);
}

View File

@@ -99,16 +99,20 @@ public final class AbilityFactory {
catch (RuntimeException ex) {
throw new RuntimeException(hostCard.getName() + ": " + ex.getMessage());
}
// parse universal parameters
AbilityRecordType type = AbilityRecordType.getRecordType(mapParams);
if (null == type) {
String source = hostCard.getName().isEmpty() ? abString : hostCard.getName();
throw new RuntimeException("AbilityFactory : getAbility -- no API in " + source);
}
return getAbility(mapParams, type, hostCard);
}
public static final SpellAbility getAbility(final Map<String, String> mapParams, AbilityRecordType type, final Card hostCard) {
return getAbility(type, type.getApiTypeOf(mapParams), mapParams, parseAbilityCost(hostCard, mapParams, type), hostCard);
}
public static Cost parseAbilityCost(final Card hostCard, Map<String, String> mapParams, AbilityRecordType type) {
Cost abCost = null;
if (type != AbilityRecordType.SubAbility) {