Cached Orientations arrays for perf improvements
I was informed that a great deal of liquid calculations cpu time was spent cloning these arrays.
This commit is contained in:
parent
aa3fdfd5dc
commit
5130e27867
22
.gitattributes
vendored
Normal file
22
.gitattributes
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
# Auto detect text files and perform LF normalization
|
||||
*.java text
|
||||
|
||||
# Custom for Visual Studio
|
||||
*.cs diff=csharp
|
||||
*.sln merge=union
|
||||
*.csproj merge=union
|
||||
*.vbproj merge=union
|
||||
*.fsproj merge=union
|
||||
*.dbproj merge=union
|
||||
|
||||
# Standard to msysgit
|
||||
*.doc diff=astextplain
|
||||
*.DOC diff=astextplain
|
||||
*.docx diff=astextplain
|
||||
*.DOCX diff=astextplain
|
||||
*.dot diff=astextplain
|
||||
*.DOT diff=astextplain
|
||||
*.pdf diff=astextplain
|
||||
*.PDF diff=astextplain
|
||||
*.rtf diff=astextplain
|
||||
*.RTF diff=astextplain
|
|
@ -9,8 +9,6 @@
|
|||
|
||||
package buildcraft.transport;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import buildcraft.BuildCraftCore;
|
||||
import buildcraft.api.core.Orientations;
|
||||
import buildcraft.api.core.SafeTimeTracker;
|
||||
|
@ -47,8 +45,8 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
|
|||
|
||||
@Override
|
||||
public int fill(LiquidStack resource, boolean doFill) {
|
||||
if(resource == null)
|
||||
return 0;
|
||||
if(resource == null)
|
||||
return 0;
|
||||
|
||||
int maxToFill = Math.min(resource.amount, flowRate - incomming[currentTime]);
|
||||
if (maxToFill <= 0) return 0;
|
||||
|
@ -87,7 +85,6 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
|
|||
public void reset(){
|
||||
this.setLiquid(null);
|
||||
incomming = new short[travelDelay];
|
||||
|
||||
}
|
||||
|
||||
public int getAvailable(){
|
||||
|
@ -117,7 +114,6 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
|
|||
if (this.getLiquid() != null){
|
||||
this.getLiquid().writeToNBT(subTag);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -135,14 +131,17 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
|
|||
public static short OUTPUT_TTL = 80; //80
|
||||
public static short OUTPUT_COOLDOWN = 30; //30
|
||||
|
||||
private static final Orientations[] directions = Orientations.dirs();
|
||||
private static final Orientations[] orientations = Orientations.values();
|
||||
|
||||
|
||||
public short travelDelay = 12;
|
||||
public short flowRate = 20;
|
||||
public LiquidStack[] renderCache = new LiquidStack[Orientations.values().length];
|
||||
public LiquidStack[] renderCache = new LiquidStack[orientations.length];
|
||||
|
||||
private final PipeSection[] internalTanks = new PipeSection[Orientations.values().length];
|
||||
private final PipeSection[] internalTanks = new PipeSection[orientations.length];
|
||||
|
||||
private final TransferState[] transferState = new TransferState[Orientations.dirs().length];
|
||||
private final TransferState[] transferState = new TransferState[directions.length];
|
||||
|
||||
private final short[] inputTTL = new short[] { 0, 0, 0, 0, 0, 0 };
|
||||
private final short[] outputTTL = new short[] { OUTPUT_TTL, OUTPUT_TTL, OUTPUT_TTL, OUTPUT_TTL, OUTPUT_TTL, OUTPUT_TTL };
|
||||
|
@ -152,7 +151,7 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
|
|||
|
||||
|
||||
public PipeTransportLiquids() {
|
||||
for (Orientations direction : Orientations.values()) {
|
||||
for (Orientations direction : orientations) {
|
||||
internalTanks[direction.ordinal()] = new PipeSection();
|
||||
if (direction != Orientations.Unknown){
|
||||
transferState[direction.ordinal()] = TransferState.None;
|
||||
|
@ -186,7 +185,7 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
|
|||
return;
|
||||
|
||||
moveLiquids();
|
||||
for (Orientations direction : Orientations.values()) {
|
||||
for (Orientations direction : orientations) {
|
||||
LiquidStack liquid = internalTanks[direction.ordinal()].getLiquid();
|
||||
|
||||
if (liquid != null){
|
||||
|
@ -233,7 +232,7 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
|
|||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
super.readFromNBT(nbttagcompound);
|
||||
|
||||
for (Orientations direction : Orientations.values()) {
|
||||
for (Orientations direction : orientations) {
|
||||
if (nbttagcompound.hasKey("tank[" + direction.ordinal() + "]")){
|
||||
internalTanks[direction.ordinal()].readFromNBT(nbttagcompound.getCompoundTag("tank[" + direction.ordinal() + "]"));
|
||||
}
|
||||
|
@ -247,7 +246,7 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
|
|||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
super.writeToNBT(nbttagcompound);
|
||||
|
||||
for (Orientations direction : Orientations.values()) {
|
||||
for (Orientations direction : orientations) {
|
||||
NBTTagCompound subTag = new NBTTagCompound();
|
||||
internalTanks[direction.ordinal()].writeToNBT(subTag);
|
||||
nbttagcompound.setTag("tank[" + direction.ordinal() + "]", subTag);
|
||||
|
@ -269,7 +268,7 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
|
|||
private void moveFromPipe(short outputCount) {
|
||||
//Move liquid from the non-center to the connected output blocks
|
||||
if (outputCount > 0) {
|
||||
for (Orientations o : Orientations.dirs()){
|
||||
for (Orientations o : directions){
|
||||
if (transferState[o.ordinal()] == TransferState.Output){
|
||||
TileEntity target = this.container.getTile(o);
|
||||
if (!(target instanceof ITankContainer)) continue;
|
||||
|
@ -296,7 +295,7 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
|
|||
LiquidStack testStack = pushStack.copy();
|
||||
testStack.amount = flowRate;
|
||||
//Move liquid from the center to the output sides
|
||||
for (Orientations direction : Orientations.dirs()) {
|
||||
for (Orientations direction : directions) {
|
||||
if (transferState[direction.ordinal()] == TransferState.Output) {
|
||||
int available = internalTanks[direction.ordinal()].fill(testStack, false);
|
||||
int ammountToPush = (int) (available / (double) flowRate / (double) outputCount * (double) Math.min(flowRate, totalAvailable));
|
||||
|
@ -322,7 +321,7 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
|
|||
}
|
||||
|
||||
|
||||
for (Orientations direction : Orientations.dirs()){
|
||||
for (Orientations direction : directions){
|
||||
LiquidStack testStack = internalTanks[direction.ordinal()].drain(flowRate, false);
|
||||
if (testStack == null) continue;
|
||||
if (stackInCenter != null && !stackInCenter.isLiquidEqual(testStack)) continue;
|
||||
|
@ -330,7 +329,7 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
|
|||
transferInCount++;
|
||||
}
|
||||
|
||||
for (Orientations direction : Orientations.dirs()){
|
||||
for (Orientations direction : directions){
|
||||
//Move liquid from input sides to the center
|
||||
if (transferState[direction.ordinal()] != TransferState.Output && maxInput[direction.ordinal()] > 0){
|
||||
|
||||
|
@ -352,7 +351,7 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
|
|||
short outputCount = 0;
|
||||
|
||||
//Processes all internal tanks
|
||||
for (Orientations direction : Orientations.values()) {
|
||||
for (Orientations direction : orientations) {
|
||||
internalTanks[direction.ordinal()].setTime(newTimeSlot);
|
||||
internalTanks[direction.ordinal()].moveLiquids();
|
||||
// Input processing
|
||||
|
@ -393,8 +392,8 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
|
|||
public void onNeighborBlockChange(int blockId) {
|
||||
super.onNeighborBlockChange(blockId);
|
||||
|
||||
for (Orientations direction : Orientations.dirs()){
|
||||
if (!Utils.checkPipesConnections(container.getTile(Orientations.values()[direction.ordinal()]), container)) {
|
||||
for (Orientations direction : directions){
|
||||
if (!Utils.checkPipesConnections(container.getTile(orientations[direction.ordinal()]), container)) {
|
||||
internalTanks[direction.ordinal()].reset();
|
||||
transferState[direction.ordinal()] = TransferState.None;
|
||||
renderCache[direction.ordinal()] = null;
|
||||
|
@ -425,7 +424,6 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
|
|||
|
||||
public void handleLiquidPacket(PacketLiquidUpdate packetLiquid) {
|
||||
this.renderCache = packetLiquid.displayLiquid;
|
||||
|
||||
}
|
||||
|
||||
/** ITankContainer implementation **/
|
||||
|
@ -440,7 +438,7 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
|
|||
int filled;
|
||||
|
||||
if (this.container.pipe instanceof IPipeTransportLiquidsHook)
|
||||
filled = ((IPipeTransportLiquidsHook) this.container.pipe).fill(Orientations.values()[tankIndex], resource, doFill);
|
||||
filled = ((IPipeTransportLiquidsHook) this.container.pipe).fill(orientations[tankIndex], resource, doFill);
|
||||
else
|
||||
filled = internalTanks[tankIndex].fill(resource, doFill);
|
||||
|
||||
|
|
Loading…
Reference in a new issue