Transmitter network efficiency overhaul! Transmitter networks now only refresh acceptors on the transmitter that initiated the refresh instead of resetting the entire grid.
This commit is contained in:
parent
fba83a3634
commit
d9658a16bd
7 changed files with 116 additions and 70 deletions
|
@ -8,6 +8,7 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.ListUtils;
|
||||
import mekanism.api.transmitters.DynamicNetwork;
|
||||
import mekanism.api.transmitters.IGridTransmitter;
|
||||
|
@ -282,7 +283,7 @@ public class GasNetwork extends DynamicNetwork<IGasHandler, GasNetwork>
|
|||
Gas type = (Gas)data[0];
|
||||
Set<IGasHandler> toReturn = new HashSet<IGasHandler>();
|
||||
|
||||
for(IGasHandler acceptor : possibleAcceptors)
|
||||
for(IGasHandler acceptor : possibleAcceptors.values())
|
||||
{
|
||||
if(acceptorDirections.get(acceptor) == null)
|
||||
{
|
||||
|
@ -305,9 +306,6 @@ public class GasNetwork extends DynamicNetwork<IGasHandler, GasNetwork>
|
|||
Iterator<IGridTransmitter<GasNetwork>> it = iterTubes.iterator();
|
||||
boolean networkChanged = false;
|
||||
|
||||
possibleAcceptors.clear();
|
||||
acceptorDirections.clear();
|
||||
|
||||
while(it.hasNext())
|
||||
{
|
||||
IGridTransmitter<GasNetwork> conductor = (IGridTransmitter<GasNetwork>)it.next();
|
||||
|
@ -323,26 +321,30 @@ public class GasNetwork extends DynamicNetwork<IGasHandler, GasNetwork>
|
|||
}
|
||||
}
|
||||
|
||||
for(IGridTransmitter<GasNetwork> transmitter : transmitters)
|
||||
if(networkChanged)
|
||||
{
|
||||
IGasHandler[] acceptors = GasTransmission.getConnectedAcceptors((TileEntity)transmitter);
|
||||
|
||||
for(IGasHandler acceptor : acceptors)
|
||||
{
|
||||
ForgeDirection side = ForgeDirection.getOrientation(Arrays.asList(acceptors).indexOf(acceptor));
|
||||
|
||||
if(side != null && acceptor != null && !(acceptor instanceof IGridTransmitter) && transmitter.canConnectToAcceptor(side, true))
|
||||
{
|
||||
possibleAcceptors.add(acceptor);
|
||||
acceptorDirections.put(acceptor, ForgeDirection.getOrientation(Arrays.asList(acceptors).indexOf(acceptor)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (networkChanged) {
|
||||
updateCapacity();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void refresh(IGridTransmitter<GasNetwork> transmitter)
|
||||
{
|
||||
IGasHandler[] acceptors = GasTransmission.getConnectedAcceptors((TileEntity)transmitter);
|
||||
|
||||
clearAround(transmitter);
|
||||
|
||||
for(IGasHandler acceptor : acceptors)
|
||||
{
|
||||
ForgeDirection side = ForgeDirection.getOrientation(Arrays.asList(acceptors).indexOf(acceptor));
|
||||
|
||||
if(side != null && acceptor != null && !(acceptor instanceof IGridTransmitter) && transmitter.canConnectToAcceptor(side, true))
|
||||
{
|
||||
possibleAcceptors.put(Coord4D.get((TileEntity)acceptor), acceptor);
|
||||
acceptorDirections.put(acceptor, ForgeDirection.getOrientation(Arrays.asList(acceptors).indexOf(acceptor)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void merge(GasNetwork network)
|
||||
|
|
|
@ -16,16 +16,16 @@ import net.minecraft.entity.player.EntityPlayer;
|
|||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
|
||||
public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implements ITransmitterNetwork<A, N>, IClientTicker
|
||||
{
|
||||
public LinkedHashSet<IGridTransmitter<N>> transmitters = new LinkedHashSet<IGridTransmitter<N>>();
|
||||
|
||||
public HashSet<A> possibleAcceptors = new HashSet<A>();
|
||||
public HashMap<Coord4D, A> possibleAcceptors = new HashMap<Coord4D, A>();
|
||||
public HashMap<A, ForgeDirection> acceptorDirections = new HashMap<A, ForgeDirection>();
|
||||
|
||||
private List<DelayQueue> updateQueue = new ArrayList<DelayQueue>();
|
||||
|
@ -46,6 +46,16 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
|
|||
protected abstract ITransmitterNetwork<A, N> create(Collection<IGridTransmitter<N>> collection);
|
||||
|
||||
protected abstract ITransmitterNetwork<A, N> create(Set<N> networks);
|
||||
|
||||
protected void clearAround(IGridTransmitter<N> transmitter)
|
||||
{
|
||||
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
Coord4D coord = Coord4D.get((TileEntity)transmitter).getFromSide(side);
|
||||
possibleAcceptors.remove(coord);
|
||||
acceptorDirections.remove(coord.getTileEntity(transmitter.getWorld()));
|
||||
}
|
||||
}
|
||||
|
||||
public void addAllTransmitters(Set<IGridTransmitter<N>> newTransmitters)
|
||||
{
|
||||
|
@ -58,6 +68,20 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
|
|||
return transmitters.iterator().next().equals(transmitter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fullRefresh()
|
||||
{
|
||||
possibleAcceptors.clear();
|
||||
acceptorDirections.clear();
|
||||
|
||||
for(IGridTransmitter<N> transmitter : transmitters)
|
||||
{
|
||||
refresh(transmitter);
|
||||
}
|
||||
|
||||
refresh();
|
||||
}
|
||||
|
||||
public AxisAlignedBB getPacketRange()
|
||||
{
|
||||
if(packetRange == null)
|
||||
|
@ -183,10 +207,13 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
|
|||
* Override this if things can have variable capacity along the network.
|
||||
* @return An 'average' value of capacity. Calculate it how you will.
|
||||
*/
|
||||
protected synchronized void updateMeanCapacity() {
|
||||
if (transmitters.size() > 0) {
|
||||
protected synchronized void updateMeanCapacity()
|
||||
{
|
||||
if(transmitters.size() > 0)
|
||||
{
|
||||
meanCapacity = transmitters.iterator().next().getCapacity();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
meanCapacity = 0;
|
||||
}
|
||||
}
|
||||
|
@ -275,7 +302,7 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
|
|||
}
|
||||
|
||||
ITransmitterNetwork<A, N> newNetwork = create(newTransporters);
|
||||
newNetwork.refresh();
|
||||
newNetwork.fullRefresh();
|
||||
newNetwork.setFixed(true);
|
||||
deregister();
|
||||
}
|
||||
|
@ -354,7 +381,7 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
|
|||
|
||||
for(ITransmitterNetwork<A, N> network : newNetworks)
|
||||
{
|
||||
network.refresh();
|
||||
network.fullRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package mekanism.api.transmitters;
|
|||
|
||||
import mekanism.api.Coord4D;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public interface IGridTransmitter<N extends DynamicNetwork<?, N>> extends ITransmitter
|
||||
|
@ -63,4 +64,6 @@ public interface IGridTransmitter<N extends DynamicNetwork<?, N>> extends ITrans
|
|||
public int getCapacity();
|
||||
|
||||
public Coord4D getLocation();
|
||||
|
||||
public World getWorld();
|
||||
}
|
||||
|
|
|
@ -22,6 +22,10 @@ public interface ITransmitterNetwork<A, N extends DynamicNetwork<A, N>>
|
|||
public void removeTransmitter(IGridTransmitter<N> transmitter);
|
||||
|
||||
public void refresh();
|
||||
|
||||
public void fullRefresh();
|
||||
|
||||
public void refresh(IGridTransmitter<N> transmitter);
|
||||
|
||||
public void split(IGridTransmitter<N> splitPoint);
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.ListUtils;
|
||||
import mekanism.api.energy.IStrictEnergyAcceptor;
|
||||
import mekanism.api.transmitters.DynamicNetwork;
|
||||
|
@ -240,9 +241,7 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
|
|||
return toReturn;
|
||||
}
|
||||
|
||||
Set<TileEntity> copy = (Set<TileEntity>)possibleAcceptors.clone();
|
||||
|
||||
for(TileEntity acceptor : copy)
|
||||
for(TileEntity acceptor : possibleAcceptors.values())
|
||||
{
|
||||
ForgeDirection side = acceptorDirections.get(acceptor);
|
||||
|
||||
|
@ -315,9 +314,6 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
|
|||
Set<IGridTransmitter<EnergyNetwork>> iterCables = (Set<IGridTransmitter<EnergyNetwork>>)transmitters.clone();
|
||||
Iterator<IGridTransmitter<EnergyNetwork>> it = iterCables.iterator();
|
||||
boolean networkChanged = false;
|
||||
|
||||
possibleAcceptors.clear();
|
||||
acceptorDirections.clear();
|
||||
|
||||
while(it.hasNext())
|
||||
{
|
||||
|
@ -334,22 +330,6 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
|
|||
}
|
||||
}
|
||||
|
||||
for(IGridTransmitter<EnergyNetwork> transmitter : iterCables)
|
||||
{
|
||||
TileEntity[] acceptors = CableUtils.getConnectedEnergyAcceptors((TileEntity)transmitter);
|
||||
|
||||
for(TileEntity acceptor : acceptors)
|
||||
{
|
||||
ForgeDirection side = ForgeDirection.getOrientation(Arrays.asList(acceptors).indexOf(acceptor));
|
||||
|
||||
if(side != null && acceptor != null && !(acceptor instanceof IGridTransmitter) && transmitter.canConnectToAcceptor(side, true))
|
||||
{
|
||||
possibleAcceptors.add(acceptor);
|
||||
acceptorDirections.put(acceptor, ForgeDirection.getOrientation(Arrays.asList(acceptors).indexOf(acceptor)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(networkChanged)
|
||||
{
|
||||
updateCapacity();
|
||||
|
@ -357,6 +337,25 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
|
|||
|
||||
needsUpdate = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void refresh(IGridTransmitter<EnergyNetwork> transmitter)
|
||||
{
|
||||
TileEntity[] acceptors = CableUtils.getConnectedEnergyAcceptors((TileEntity)transmitter);
|
||||
|
||||
clearAround(transmitter);
|
||||
|
||||
for(TileEntity acceptor : acceptors)
|
||||
{
|
||||
ForgeDirection side = ForgeDirection.getOrientation(Arrays.asList(acceptors).indexOf(acceptor));
|
||||
|
||||
if(side != null && acceptor != null && !(acceptor instanceof IGridTransmitter) && transmitter.canConnectToAcceptor(side, true))
|
||||
{
|
||||
possibleAcceptors.put(Coord4D.get(acceptor), acceptor);
|
||||
acceptorDirections.put(acceptor, ForgeDirection.getOrientation(Arrays.asList(acceptors).indexOf(acceptor)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void merge(EnergyNetwork network)
|
||||
|
|
|
@ -8,11 +8,13 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.ListUtils;
|
||||
import mekanism.api.transmitters.DynamicNetwork;
|
||||
import mekanism.api.transmitters.IGridTransmitter;
|
||||
import mekanism.api.transmitters.ITransmitterNetwork;
|
||||
import mekanism.api.transmitters.TransmissionType;
|
||||
import mekanism.common.util.CableUtils;
|
||||
import mekanism.common.util.PipeUtils;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
@ -295,7 +297,7 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork>
|
|||
FluidStack fluidToSend = (FluidStack)data[0];
|
||||
Set<IFluidHandler> toReturn = new HashSet<IFluidHandler>();
|
||||
|
||||
for(IFluidHandler acceptor : possibleAcceptors)
|
||||
for(IFluidHandler acceptor : possibleAcceptors.values())
|
||||
{
|
||||
if(acceptorDirections.get(acceptor) == null)
|
||||
{
|
||||
|
@ -317,9 +319,6 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork>
|
|||
Set<IGridTransmitter<FluidNetwork>> iterPipes = (Set<IGridTransmitter<FluidNetwork>>)transmitters.clone();
|
||||
Iterator it = iterPipes.iterator();
|
||||
boolean networkChanged = false;
|
||||
|
||||
possibleAcceptors.clear();
|
||||
acceptorDirections.clear();
|
||||
|
||||
while(it.hasNext())
|
||||
{
|
||||
|
@ -336,26 +335,30 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork>
|
|||
}
|
||||
}
|
||||
|
||||
for(IGridTransmitter<FluidNetwork> transmitter : iterPipes)
|
||||
if(networkChanged)
|
||||
{
|
||||
IFluidHandler[] acceptors = PipeUtils.getConnectedAcceptors((TileEntity)transmitter);
|
||||
|
||||
for(IFluidHandler acceptor : acceptors)
|
||||
{
|
||||
ForgeDirection side = ForgeDirection.getOrientation(Arrays.asList(acceptors).indexOf(acceptor));
|
||||
|
||||
if(side != null && acceptor != null && !(acceptor instanceof IGridTransmitter) && transmitter.canConnectToAcceptor(side, true))
|
||||
{
|
||||
possibleAcceptors.add(acceptor);
|
||||
acceptorDirections.put(acceptor, ForgeDirection.getOrientation(Arrays.asList(acceptors).indexOf(acceptor)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(networkChanged) {
|
||||
updateCapacity();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void refresh(IGridTransmitter<FluidNetwork> transmitter)
|
||||
{
|
||||
IFluidHandler[] acceptors = PipeUtils.getConnectedAcceptors((TileEntity)transmitter);
|
||||
|
||||
clearAround(transmitter);
|
||||
|
||||
for(IFluidHandler acceptor : acceptors)
|
||||
{
|
||||
ForgeDirection side = ForgeDirection.getOrientation(Arrays.asList(acceptors).indexOf(acceptor));
|
||||
|
||||
if(side != null && acceptor != null && !(acceptor instanceof IGridTransmitter) && transmitter.canConnectToAcceptor(side, true))
|
||||
{
|
||||
possibleAcceptors.put(Coord4D.get((TileEntity)acceptor), acceptor);
|
||||
acceptorDirections.put(acceptor, ForgeDirection.getOrientation(Arrays.asList(acceptors).indexOf(acceptor)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void merge(FluidNetwork network)
|
||||
|
|
|
@ -14,6 +14,7 @@ import mekanism.common.Mekanism;
|
|||
import mekanism.common.network.PacketTransmitterUpdate.PacketType;
|
||||
import mekanism.common.network.PacketTransmitterUpdate.TransmitterUpdateMessage;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import codechicken.multipart.TileMultipart;
|
||||
|
||||
|
@ -54,6 +55,7 @@ public abstract class PartTransmitter<N extends DynamicNetwork<?, N>> extends Pa
|
|||
}
|
||||
}
|
||||
|
||||
((DynamicNetwork<?,N>)getTransmitterNetwork()).refresh(this);
|
||||
((DynamicNetwork<?,N>)getTransmitterNetwork()).refresh();
|
||||
}
|
||||
|
||||
|
@ -222,6 +224,12 @@ public abstract class PartTransmitter<N extends DynamicNetwork<?, N>> extends Pa
|
|||
{
|
||||
return Coord4D.get(tile());
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld()
|
||||
{
|
||||
return world();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void chunkLoad() {}
|
||||
|
|
Loading…
Reference in a new issue