Work on path caching

This commit is contained in:
Aidan C. Brady 2014-08-20 15:54:05 -04:00
parent 275c7840cc
commit 80021dd4c7
12 changed files with 55 additions and 28 deletions

View file

@ -1,11 +1,12 @@
package mekanism.common;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -14,7 +15,7 @@ import mekanism.api.EnumColor;
import mekanism.api.transmitters.DynamicNetwork;
import mekanism.api.transmitters.IGridTransmitter;
import mekanism.api.transmitters.TransmissionType;
import mekanism.common.content.transporter.ILogisticalTransporter;
import mekanism.common.base.ILogisticalTransporter;
import mekanism.common.content.transporter.TransporterManager;
import mekanism.common.util.TransporterUtils;
import net.minecraft.inventory.IInventory;
@ -51,9 +52,9 @@ public class InventoryNetwork extends DynamicNetwork<IInventory, InventoryNetwor
register();
}
public Map<Coord4D, ItemStack> calculateAcceptors(ItemStack stack, EnumColor color)
public List<AcceptorData> calculateAcceptors(ItemStack stack, EnumColor color)
{
Map<Coord4D, ItemStack> toReturn = new HashMap<Coord4D, ItemStack>();
List<AcceptorData> toReturn = new ArrayList<AcceptorData>();
for(Coord4D coord : ((Map<Coord4D, IInventory>)possibleAcceptors.clone()).keySet())
{
@ -65,20 +66,46 @@ public class InventoryNetwork extends DynamicNetwork<IInventory, InventoryNetwor
continue;
}
AcceptorData data = null;
for(ForgeDirection side : sides)
{
ItemStack returned = TransporterManager.getPredictedInsert((TileEntity)acceptor, color, stack, side.ordinal());
if(TransporterManager.didEmit(stack, returned))
{
toReturn.put(coord, returned);
break;
if(data == null)
{
data = new AcceptorData(coord, returned, side);
}
else {
data.sides.add(side);
}
}
}
if(data != null)
{
toReturn.add(data);
}
}
return toReturn;
}
public static class AcceptorData
{
public Coord4D location;
public ItemStack rejected;
public EnumSet<ForgeDirection> sides = EnumSet.noneOf(ForgeDirection.class);
public AcceptorData(Coord4D coord, ItemStack stack, ForgeDirection side)
{
location = coord;
rejected = stack;
sides.add(side);
}
}
@Override
public void onUpdate()

View file

@ -1,10 +1,11 @@
package mekanism.common.content.transporter;
package mekanism.common.base;
import mekanism.api.Coord4D;
import mekanism.api.EnumColor;
import mekanism.api.transmitters.IBlockableConnection;
import mekanism.api.transmitters.IGridTransmitter;
import mekanism.common.InventoryNetwork;
import mekanism.common.content.transporter.TransporterStack;
import mekanism.common.tile.TileEntityLogisticalSorter;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;

View file

@ -38,16 +38,14 @@ public class PathfinderCache
public static class PathData
{
public Coord4D start;
public ForgeDirection startSide;
public Coord4D startTransporter;
public Coord4D end;
public ForgeDirection endSide;
public PathData(Coord4D s, ForgeDirection ss, Coord4D e, ForgeDirection es)
public PathData(Coord4D s, Coord4D e, ForgeDirection es)
{
start = s;
startSide = ss;
startTransporter = s;
end = e;
endSide = es;
@ -57,8 +55,7 @@ public class PathfinderCache
public boolean equals(Object obj)
{
return obj instanceof PathData &&
((PathData)obj).start.equals(start) &&
((PathData)obj).startSide.equals(startSide) &&
((PathData)obj).startTransporter.equals(startTransporter) &&
((PathData)obj).end.equals(end) &&
((PathData)obj).endSide.equals(endSide);
}
@ -67,8 +64,7 @@ public class PathfinderCache
public int hashCode()
{
int code = 1;
code = 31 * code + start.hashCode();
code = 31 * code + startSide.hashCode();
code = 31 * code + startTransporter.hashCode();
code = 31 * code + end.hashCode();
code = 31 * code + endSide.hashCode();
return code;

View file

@ -11,6 +11,8 @@ import java.util.Set;
import mekanism.api.Coord4D;
import mekanism.common.InventoryNetwork;
import mekanism.common.InventoryNetwork.AcceptorData;
import mekanism.common.base.ILogisticalTransporter;
import mekanism.common.content.transporter.TransporterPathfinder.Pathfinder.DestChecker;
import mekanism.common.content.transporter.TransporterStack.Path;
import mekanism.common.tile.TileEntityLogisticalSorter;
@ -214,18 +216,18 @@ public final class TransporterPathfinder
};
InventoryNetwork network = start.getTransmitterNetwork();
Map<Coord4D, ItemStack> acceptors = network.calculateAcceptors(stack.itemStack, stack.color);
List<AcceptorData> acceptors = network.calculateAcceptors(stack.itemStack, stack.color);
List<Destination> paths = new ArrayList<Destination>();
for(Map.Entry<Coord4D, ItemStack> entry : acceptors.entrySet())
for(AcceptorData entry : acceptors)
{
Pathfinder p = new Pathfinder(checker, start.getTile().getWorldObj(), entry.getKey(), Coord4D.get(start.getTile()), stack);
Pathfinder p = new Pathfinder(checker, start.getTile().getWorldObj(), entry.location, Coord4D.get(start.getTile()), stack);
if(p.getPath().size() >= 2)
{
if(TransporterManager.getToUse(stack.itemStack, entry.getValue()).stackSize >= min)
if(TransporterManager.getToUse(stack.itemStack, entry.rejected).stackSize >= min)
{
paths.add(new Destination(p.getPath(), p.finalScore, false, entry.getValue()));
paths.add(new Destination(p.getPath(), p.finalScore, false, entry.rejected));
}
}
}

View file

@ -7,6 +7,7 @@ import java.util.List;
import mekanism.api.Coord4D;
import mekanism.api.EnumColor;
import mekanism.common.base.ILogisticalTransporter;
import mekanism.common.content.transporter.TransporterPathfinder.Destination;
import mekanism.common.tile.TileEntityLogisticalSorter;
import mekanism.common.util.MekanismUtils;

View file

@ -33,7 +33,7 @@ public class MultipartMekanism implements IPartFactory
MultipartGenerator.registerPassThroughInterface("mekanism.api.transmitters.ITransmitter");
MultipartGenerator.registerPassThroughInterface("mekanism.api.energy.IStrictEnergyAcceptor");
MultipartGenerator.registerPassThroughInterface("mekanism.api.transmitters.IGridTransmitter");
MultipartGenerator.registerPassThroughInterface("mekanism.common.transporter.ILogisticalTransporter");
MultipartGenerator.registerPassThroughInterface("mekanism.common.base.ILogisticalTransporter");
MultipartGenerator.registerPassThroughInterface("buildcraft.api.power.IPowerReceptor");
MultipartGenerator.registerPassThroughInterface("cofh.api.energy.IEnergyHandler");
MultipartGenerator.registerPassThroughInterface("mekanism.api.IConfigurable");

View file

@ -15,7 +15,7 @@ import mekanism.client.render.RenderPartTransmitter;
import mekanism.common.HashList;
import mekanism.common.InventoryNetwork;
import mekanism.common.Mekanism;
import mekanism.common.content.transporter.ILogisticalTransporter;
import mekanism.common.base.ILogisticalTransporter;
import mekanism.common.content.transporter.InvStack;
import mekanism.common.content.transporter.TransporterManager;
import mekanism.common.content.transporter.TransporterStack;

View file

@ -11,7 +11,7 @@ import mekanism.api.util.StackUtils;
import mekanism.common.Mekanism;
import mekanism.common.PacketHandler;
import mekanism.common.base.IActiveState;
import mekanism.common.content.transporter.ILogisticalTransporter;
import mekanism.common.base.ILogisticalTransporter;
import mekanism.common.content.transporter.TransporterManager;
import mekanism.common.item.ItemBlockBasic;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;

View file

@ -20,6 +20,7 @@ import mekanism.common.Mekanism;
import mekanism.common.MekanismBlocks;
import mekanism.common.base.IActiveState;
import mekanism.common.base.IAdvancedBoundingBlock;
import mekanism.common.base.ILogisticalTransporter;
import mekanism.common.base.IRedstoneControl;
import mekanism.common.base.ISustainedData;
import mekanism.common.base.IUpgradeTile;
@ -29,7 +30,6 @@ import mekanism.common.content.miner.MOreDictFilter;
import mekanism.common.content.miner.MinerFilter;
import mekanism.common.content.miner.ThreadMinerSearch;
import mekanism.common.content.miner.ThreadMinerSearch.State;
import mekanism.common.content.transporter.ILogisticalTransporter;
import mekanism.common.content.transporter.InvStack;
import mekanism.common.content.transporter.TransporterManager;
import mekanism.common.inventory.container.ContainerFilter;

View file

@ -12,10 +12,10 @@ import mekanism.api.Range4D;
import mekanism.common.HashList;
import mekanism.common.Mekanism;
import mekanism.common.base.IActiveState;
import mekanism.common.base.ILogisticalTransporter;
import mekanism.common.base.IRedstoneControl;
import mekanism.common.base.ISustainedData;
import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.content.transporter.ILogisticalTransporter;
import mekanism.common.content.transporter.InvStack;
import mekanism.common.content.transporter.TItemStackFilter;
import mekanism.common.content.transporter.TransporterFilter;

View file

@ -10,8 +10,8 @@ import mekanism.api.EnumColor;
import mekanism.common.SideData;
import mekanism.common.base.IEjector;
import mekanism.common.base.IInvConfiguration;
import mekanism.common.base.ILogisticalTransporter;
import mekanism.common.base.ITileComponent;
import mekanism.common.content.transporter.ILogisticalTransporter;
import mekanism.common.content.transporter.TransporterManager;
import mekanism.common.tile.TileEntityContainerBlock;
import mekanism.common.util.InventoryUtils;

View file

@ -7,7 +7,7 @@ import mekanism.api.Coord4D;
import mekanism.api.EnumColor;
import mekanism.api.util.ListUtils;
import mekanism.api.transmitters.IGridTransmitter;
import mekanism.common.content.transporter.ILogisticalTransporter;
import mekanism.common.base.ILogisticalTransporter;
import mekanism.common.content.transporter.TransporterManager;
import mekanism.common.content.transporter.TransporterStack;
import mekanism.common.tile.TileEntityLogisticalSorter;