Emitting logic overhaul (#5422)

* First pass improving performance of EnergyNetwork emitting
Only sends power once per tick per accept now. Lots of comments of design included so that I have a backup of my thought process/solutions if I run into some blocker.

* Optimized implementation slightly, still more to be done

* Cleanup some comments

* Move send energy to acceptor logic to CableUtils
Replace old emit logic in CableUtils with using the newer logic

* Inline getConnections to slightly cut down on number of operations ran

* Fix a couple bugs with targets that have multiple sides
Also improve performance reducing frequency at amountPerChanged needs to be ran

* Improve performance of CableUtils.emit by faking we have one 6 sided target as opposed to having 6 one sided targets

* Allow simulating insertion into the EnergyAcceptorWrapper for IC2

* Fix using wrong value for total acceptor count when acceptors have multiple sides

* Use an EnumMap instead of a HashMap for the Target

* First pass converting gas and fluid network emission to target system

* Improve general fluid and gas emitting using the utility method
Change a couple things to using Sets rather than lists for emitting so that we can ensure each side is only done once.

* Document and cleanup method/variable names of target classes

* Start deduplicating emitting code into a EmitUtils file
Logic for Gas and Fluid emitting fully generic now

* Partially extract how we keep track of the split to make it easier to deduplicate the common code

* Start moving shifting needed to given to the targets themselves

* Use generics to deduplicate a lot of the remaining duplication in the new emitting code

* Fix having broke energy emitting and also further cleanup some code

* Half the number of loops the HeatNetwork does onUpdate

* Fix potentially divide by zero errors

* Deprecate and remove implementations of getAcceptors as it is no longer needed

* Never round up from doubles for sending power stops energy networks going negative.

* Fix more spots where we were accidentally rounding upwards/clamping improperly for energy

* Cleanup impl to use less memory and adjust better as sending if
the possible amount changed/should be adjusted
Also removed the need for a specific IntegerTypeTarget intermediary class

* Cleanup the docs of some of the changed things

* Given tickEmit is private now we already know it is only being called serverside

* Improve documentation slightly and rename a method to be more accurate

* Remove limit on IC2 given it uses doubles as well now

* Rename amountPer to amountPerTarget
This commit is contained in:
Richard Freimer authored and GitHub committed 2019-04-30 10:25:23 -04:00
1 parent 445556fef7
commit b3663a37a9
37 files changed
+689 -641

No files matched your search

@@ -2,11 +2,14 @@ package mekanism.common.tile.component;
import io.netty.buffer.ByteBuf;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import mekanism.api.Coord4D;
import mekanism.api.EnumColor;
import mekanism.api.TileNetworkList;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.GasTank;
import mekanism.api.transmitters.TransmissionType;
@@ -14,7 +17,6 @@ import mekanism.common.SideData;
import mekanism.common.base.ISideConfiguration;
import mekanism.common.base.ITankManager;
import mekanism.common.base.ITileComponent;
import mekanism.api.TileNetworkList;
import mekanism.common.capabilities.Capabilities;
import mekanism.common.content.transporter.TransitRequest;
import mekanism.common.content.transporter.TransitRequest.TransitResponse;
@@ -65,7 +67,7 @@ public class TileComponentEjector implements ITileComponent {
sideData = ejector.sideData;
}
private List<EnumFacing> getTrackedOutputs(TransmissionType type, int index, List<EnumFacing> dirs) {
private List<EnumFacing> getTrackedOutputs(TransmissionType type, int index, Set<EnumFacing> dirs) {
List<EnumFacing> sides = new ArrayList<>();
for (int i = trackers.get(type)[index] + 1; i <= trackers.get(type)[index] + 6; i++) {
@@ -92,7 +94,7 @@ public class TileComponentEjector implements ITileComponent {
if (!tileEntity.getWorld().isRemote) {
if (sideData.get(TransmissionType.GAS) != null && getEjecting(TransmissionType.GAS)) {
SideData data = sideData.get(TransmissionType.GAS);
List<EnumFacing> outputSides = getOutputSides(TransmissionType.GAS, data);
Set<EnumFacing> outputSides = getOutputSides(TransmissionType.GAS, data);
if (((ITankManager) tileEntity).getTanks() != null) {
GasTank tank = (GasTank) ((ITankManager) tileEntity).getTanks()[data.availableSlots[0]];
@@ -107,7 +109,7 @@ public class TileComponentEjector implements ITileComponent {
if (sideData.get(TransmissionType.FLUID) != null && getEjecting(TransmissionType.FLUID)) {
SideData data = sideData.get(TransmissionType.FLUID);
List<EnumFacing> outputSides = getOutputSides(TransmissionType.FLUID, data);
Set<EnumFacing> outputSides = getOutputSides(TransmissionType.FLUID, data);
if (((ITankManager) tileEntity).getTanks() != null) {
FluidTank tank = (FluidTank) ((ITankManager) tileEntity).getTanks()[data.availableSlots[0]];
@@ -123,18 +125,15 @@ public class TileComponentEjector implements ITileComponent {
}
}
public List<EnumFacing> getOutputSides(TransmissionType type, SideData data) {
List<EnumFacing> outputSides = new ArrayList<>();
ISideConfiguration configurable = (ISideConfiguration) tileEntity;
SideConfig sideConfig = configurable.getConfig().getConfig(type);
ArrayList<SideData> outputs = configurable.getConfig().getOutputs(type);
public Set<EnumFacing> getOutputSides(TransmissionType type, SideData data) {
Set<EnumFacing> outputSides = EnumSet.noneOf(EnumFacing.class);
TileComponentConfig config = ((ISideConfiguration) tileEntity).getConfig();
SideConfig sideConfig = config.getConfig(type);
ArrayList<SideData> outputs = config.getOutputs(type);
EnumFacing[] facings = MekanismUtils.getBaseOrientations(tileEntity.facing);
for (int i = 0; i < EnumFacing.VALUES.length; i++) {
EnumFacing side = facings[i];
if (sideConfig.get(side) == outputs.indexOf(data)) {
outputSides.add(EnumFacing.VALUES[i]);
}
@@ -149,7 +148,7 @@ public class TileComponentEjector implements ITileComponent {
}
SideData data = sideData.get(TransmissionType.ITEM);
List<EnumFacing> outputSides = getOutputSides(TransmissionType.ITEM, data);
Set<EnumFacing> outputSides = getOutputSides(TransmissionType.ITEM, data);
for (int index = 0; index < sideData.get(TransmissionType.ITEM).availableSlots.length; index++) {
int slotID = sideData.get(TransmissionType.ITEM).availableSlots[index];