Getting close to the new EnergyValueRegistry implementation
This commit is contained in:
parent
c9e2cb4f0c
commit
209c18da21
4 changed files with 29 additions and 53 deletions
|
@ -118,7 +118,6 @@ public class EquivalentExchange3
|
||||||
{
|
{
|
||||||
CachedOreDictionary.getInstance();
|
CachedOreDictionary.getInstance();
|
||||||
Abilities.initNotLearnables();
|
Abilities.initNotLearnables();
|
||||||
NewEnergyValueRegistry.INSTANCE.compute();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
|
|
@ -20,8 +20,9 @@ public class DynamicEnergyValueInitThread implements Runnable
|
||||||
RecipeRegistry.getInstance().registerVanillaRecipes();
|
RecipeRegistry.getInstance().registerVanillaRecipes();
|
||||||
AludelRecipeManager.registerRecipes();
|
AludelRecipeManager.registerRecipes();
|
||||||
|
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.nanoTime();
|
||||||
EnergyValueRegistry.getInstance().init();
|
// EnergyValueRegistry.getInstance().init();
|
||||||
LogHelper.info(EnergyValueRegistry.ENERGY_VALUE_MARKER, "DynamicEMC system initialized after {} ms", System.currentTimeMillis() - startTime);
|
NewEnergyValueRegistry.INSTANCE.compute();
|
||||||
|
LogHelper.info(EnergyValueRegistry.ENERGY_VALUE_MARKER, "DynamicEMC system initialized after {} ms", System.nanoTime() - startTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -538,14 +538,13 @@ public class NewEnergyValueRegistry {
|
||||||
|
|
||||||
private Map<WrappedStack, EnergyValue> calculateStackValueMap(Map<WrappedStack, EnergyValue> stackValueMap) {
|
private Map<WrappedStack, EnergyValue> calculateStackValueMap(Map<WrappedStack, EnergyValue> stackValueMap) {
|
||||||
|
|
||||||
Map<WrappedStack, EnergyValue> computedMap = new TreeMap<>(stackValueMap);
|
|
||||||
|
|
||||||
Map<WrappedStack, EnergyValue> tempComputedMap = new TreeMap<>();
|
|
||||||
int passNumber = 0;
|
|
||||||
|
|
||||||
LogHelper.info(ENERGY_VALUE_MARKER, "Beginning energy value calculation");
|
LogHelper.info(ENERGY_VALUE_MARKER, "Beginning energy value calculation");
|
||||||
long startingTime = System.nanoTime();
|
long startingTime = System.nanoTime();
|
||||||
|
|
||||||
|
Map<WrappedStack, EnergyValue> computedMap = new TreeMap<>(stackValueMap);
|
||||||
|
Map<WrappedStack, EnergyValue> tempComputedMap = new TreeMap<>();
|
||||||
|
int passNumber = 0;
|
||||||
|
|
||||||
while ((passNumber == 0 || tempComputedMap.size() != computedMap.size()) && passNumber < 16) {
|
while ((passNumber == 0 || tempComputedMap.size() != computedMap.size()) && passNumber < 16) {
|
||||||
|
|
||||||
long passStartTime = System.nanoTime();
|
long passStartTime = System.nanoTime();
|
||||||
|
@ -560,7 +559,24 @@ public class NewEnergyValueRegistry {
|
||||||
// We won't attempt to recalculate values that already have a pre-calculation value assignment
|
// We won't attempt to recalculate values that already have a pre-calculation value assignment
|
||||||
if (!stackValueMap.containsKey(WrappedStack.wrap(recipeOutput, 1))) {
|
if (!stackValueMap.containsKey(WrappedStack.wrap(recipeOutput, 1))) {
|
||||||
for (List<WrappedStack> recipeInputs : RecipeRegistry.getInstance().getRecipeMappings().get(recipeOutput)) {
|
for (List<WrappedStack> recipeInputs : RecipeRegistry.getInstance().getRecipeMappings().get(recipeOutput)) {
|
||||||
// FIXME PRIORITY NUMBER 1
|
|
||||||
|
// FIXME PRIORITY NUMBER 1 - getting of values should use the same algo in getEnergyValue
|
||||||
|
EnergyValue currentOutputValue = tempComputedMap.get(WrappedStack.wrap(recipeOutput, 1));
|
||||||
|
EnergyValue computedOutputValue = computeFromInputs(tempComputedMap, recipeOutput, recipeInputs);
|
||||||
|
|
||||||
|
if (computedOutputValue != null && computedOutputValue.compareTo(currentOutputValue) < 0) {
|
||||||
|
|
||||||
|
uncomputedStacks.removeIf(wrappedStack -> uncomputedStacks.contains(WrappedStack.wrap(recipeOutput, 1)));
|
||||||
|
|
||||||
|
if (ConfigurationHandler.Settings.energyValueDebugLoggingEnabled) {
|
||||||
|
LogHelper.info(ENERGY_VALUE_MARKER, "Pass {}: Calculated value {} for object {}", passNumber, computedOutputValue, recipeOutput);
|
||||||
|
}
|
||||||
|
|
||||||
|
tempComputedMap.put(WrappedStack.wrap(recipeOutput), computedOutputValue);
|
||||||
|
}
|
||||||
|
else if (computedOutputValue != null) {
|
||||||
|
uncomputedStacks.add(WrappedStack.wrap(recipeOutput, 1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -578,43 +594,6 @@ public class NewEnergyValueRegistry {
|
||||||
return computedMap;
|
return computedMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<WrappedStack, EnergyValue> computeValuesFromRecipes(Map<WrappedStack, EnergyValue> stackValueMap) {
|
|
||||||
|
|
||||||
Map<WrappedStack, EnergyValue> tempStackValueMap = new TreeMap<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Algorithm
|
|
||||||
*
|
|
||||||
* For everything we know how to make in the RecipeRegistry
|
|
||||||
* Check to see if we have a value for it already
|
|
||||||
*/
|
|
||||||
for (WrappedStack recipeOutput : RecipeRegistry.getInstance().getRecipeMappings().keySet()) {
|
|
||||||
// TODO Review: possible fault in the logic here that is preventing some values from being assigned?
|
|
||||||
if (!hasEnergyValue(recipeOutput.getWrappedObject()) && !tempStackValueMap.containsKey(recipeOutput)) {
|
|
||||||
EnergyValue lowestValue = null;
|
|
||||||
|
|
||||||
for (List<WrappedStack> recipeInputs : RecipeRegistry.getInstance().getRecipeMappings().get(recipeOutput)) {
|
|
||||||
EnergyValue computedValue = computeFromInputs(stackValueMap, recipeOutput, recipeInputs);
|
|
||||||
|
|
||||||
if (computedValue != null) {
|
|
||||||
if (computedValue.compareTo(lowestValue) < 0) {
|
|
||||||
lowestValue = computedValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
uncomputedStacks.add(recipeOutput);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((lowestValue != null) && (lowestValue.getValue() > 0f)) {
|
|
||||||
tempStackValueMap.put(WrappedStack.wrap(recipeOutput.getWrappedObject()), lowestValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return tempStackValueMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void calculateValueStackMap() {
|
private void calculateValueStackMap() {
|
||||||
|
|
||||||
SortedMap<EnergyValue, List<WrappedStack>> tempValueMap = new TreeMap<>();
|
SortedMap<EnergyValue, List<WrappedStack>> tempValueMap = new TreeMap<>();
|
||||||
|
|
|
@ -33,11 +33,8 @@ public class Comparators
|
||||||
public int compare(ItemStack itemStack1, ItemStack itemStack2) {
|
public int compare(ItemStack itemStack1, ItemStack itemStack2) {
|
||||||
|
|
||||||
if (itemStack1 != null && itemStack2 != null) {
|
if (itemStack1 != null && itemStack2 != null) {
|
||||||
|
// Sort on id
|
||||||
String name1 = Item.itemRegistry.getNameForObject(itemStack1.getItem());
|
if (Item.getIdFromItem(itemStack1.getItem()) - Item.getIdFromItem(itemStack2.getItem()) == 0) {
|
||||||
String name2 = Item.itemRegistry.getNameForObject(itemStack2.getItem());
|
|
||||||
|
|
||||||
if (name1.equalsIgnoreCase(name2)) {
|
|
||||||
// Sort on item
|
// Sort on item
|
||||||
if (itemStack1.getItem() == itemStack2.getItem()) {
|
if (itemStack1.getItem() == itemStack2.getItem()) {
|
||||||
// Then sort on meta
|
// Then sort on meta
|
||||||
|
@ -71,7 +68,7 @@ public class Comparators
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return name1.compareToIgnoreCase(name2);
|
return Item.getIdFromItem(itemStack1.getItem()) - Item.getIdFromItem(itemStack2.getItem());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (itemStack1 != null) {
|
else if (itemStack1 != null) {
|
||||||
|
|
Loading…
Reference in a new issue