mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-10-25 20:22:23 +00:00
Reduce allocation spam in capacitor banks (#155)
* reduce memory allocation * update dep * use public * wrong dep * spotlessApply (#156) Co-authored-by: GitHub GTNH Actions <> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
4 files changed
+49
-26
No files matched your search
+1
-1
@@ -1,7 +1,7 @@
|
||||
// Add your dependencies here
|
||||
|
||||
dependencies {
|
||||
api('com.github.GTNewHorizons:EnderCore:0.4.1:dev') {transitive = false}
|
||||
api('com.github.GTNewHorizons:EnderCore:0.4.4:dev') {transitive = false}
|
||||
compileOnly('com.github.GTNewHorizons:ForestryMC:4.8.4:dev')
|
||||
compileOnly('com.github.GTNewHorizons:NotEnoughItems:2.5.19-GTNH:dev')
|
||||
compileOnly("com.github.GTNewHorizons:GTNHLib:0.2.7:dev")
|
||||
|
||||
@@ -129,7 +129,7 @@ public class CapBankRenderer extends TileEntitySpecialRenderer implements ISimpl
|
||||
nw.setMaxEnergyStoredL(CapBankType.getTypeFromMeta(item.getItemDamage()).getMaxEnergyStored());
|
||||
nw.setEnergyStored(PowerHandlerUtil.getStoredEnergyForItem(item));
|
||||
|
||||
GaugeInfo gi = new GaugeInfo(1, 0);
|
||||
GaugeInfo gi = GaugeInfo.DEFAULT;
|
||||
GaugeKey key = new GaugeKey(ForgeDirection.SOUTH, FillGauge.Type.SINGLE);
|
||||
fillGaugeRenderer.doRender(nw, RenderUtil.BRIGHTNESS_MAX, gi, key);
|
||||
// key = new GaugeKey(ForgeDirection.EAST, FillGauge.Type.SINGLE);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package crazypants.enderio.machine.capbank.render;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -32,6 +31,7 @@ public class FillGauge implements IInfoRenderer, IResourceManagerReloadListener
|
||||
private static final double HEIGHT = 0.75;
|
||||
private static final double VERT_BORDER = (1 - HEIGHT) / 2;
|
||||
private static final double WIDTH = 0.25;
|
||||
private final Vertex[] newVerts = new Vertex[] { new Vertex(), new Vertex(), new Vertex(), new Vertex() };
|
||||
|
||||
enum Type {
|
||||
SINGLE,
|
||||
@@ -95,8 +95,8 @@ public class FillGauge implements IInfoRenderer, IResourceManagerReloadListener
|
||||
if (ratio <= 0) {
|
||||
return;
|
||||
}
|
||||
double maxY = ratio * info.height;
|
||||
if (maxY <= info.yPosition) {
|
||||
double maxY = ratio * info.getHeight();
|
||||
if (maxY <= info.getyPosition()) {
|
||||
// empty
|
||||
return;
|
||||
}
|
||||
@@ -105,26 +105,24 @@ public class FillGauge implements IInfoRenderer, IResourceManagerReloadListener
|
||||
Tessellator.instance.addTranslation((float) offset.x, (float) offset.y, (float) offset.z);
|
||||
|
||||
List<Vertex> verts = levelVertexCache.get(key);
|
||||
if (maxY >= info.yPosition + 1) {
|
||||
if (maxY >= info.getyPosition() + 1) {
|
||||
// full bar
|
||||
RenderUtil.addVerticesToTessellator(verts, Tessellator.instance);
|
||||
|
||||
} else {
|
||||
// need to render partial bar
|
||||
double myMaxY = maxY - info.yPosition;
|
||||
double myMaxY = maxY - info.getyPosition();
|
||||
|
||||
if (info.type == Type.BOTTOM || info.type == Type.SINGLE) {
|
||||
// If we have some power and we are the bottom bit of the display,
|
||||
// always show at least a little bit in the bar
|
||||
myMaxY = Math.max(0.2, myMaxY);
|
||||
}
|
||||
List<Vertex> newVerts = new ArrayList<Vertex>();
|
||||
for (Vertex v : verts) {
|
||||
v = new Vertex(v);
|
||||
newVerts.add(v);
|
||||
if (v.y() > myMaxY) {
|
||||
v.setXYZ(v.x(), myMaxY, v.z());
|
||||
v.setUV(v.u(), barMinV + (float) (myMaxY * barHeightV));
|
||||
for (int i = 0; i < verts.size(); i++) {
|
||||
newVerts[i].set(verts.get(i));
|
||||
if (newVerts[i].y() > myMaxY) {
|
||||
newVerts[i].setXYZ(newVerts[i].x(), myMaxY, newVerts[i].z());
|
||||
newVerts[i].setUV(newVerts[i].u(), barMinV + (float) (myMaxY * barHeightV));
|
||||
}
|
||||
}
|
||||
RenderUtil.addVerticesToTessellator(newVerts, Tessellator.instance);
|
||||
@@ -136,7 +134,7 @@ public class FillGauge implements IInfoRenderer, IResourceManagerReloadListener
|
||||
private GaugeInfo getGaugeInfo(TileCapBank cb, ForgeDirection dir) {
|
||||
|
||||
if (!cb.getType().isMultiblock()) {
|
||||
return new GaugeInfo(1, 0);
|
||||
return GaugeInfo.DEFAULT;
|
||||
}
|
||||
|
||||
int height = 1;
|
||||
@@ -240,8 +238,10 @@ public class FillGauge implements IInfoRenderer, IResourceManagerReloadListener
|
||||
|
||||
static class GaugeInfo {
|
||||
|
||||
int height;
|
||||
int yPosition;
|
||||
public static final GaugeInfo DEFAULT = new GaugeInfo(1, 0);
|
||||
|
||||
private int height;
|
||||
private int yPosition;
|
||||
Type type;
|
||||
|
||||
GaugeInfo(int height, int position) {
|
||||
@@ -262,6 +262,14 @@ public class FillGauge implements IInfoRenderer, IResourceManagerReloadListener
|
||||
}
|
||||
return Type.MIDDLE;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public int getyPosition() {
|
||||
return yPosition;
|
||||
}
|
||||
}
|
||||
|
||||
static class GaugeKey {
|
||||
|
||||
@@ -21,6 +21,14 @@ import crazypants.enderio.machine.power.PowerDisplayUtil;
|
||||
|
||||
public class IoDisplay implements IInfoRenderer {
|
||||
|
||||
private float previousAverageInput;
|
||||
private float previousAverageOutput;
|
||||
|
||||
String averageInputText = "0";
|
||||
String averageOutputText = "0";
|
||||
HeadingText heading1;
|
||||
HeadingText heading2;
|
||||
|
||||
@Override
|
||||
public void render(TileCapBank cb, ForgeDirection dir, double x, double y, double z, float partialTick) {
|
||||
if (dir.offsetY != 0) {
|
||||
@@ -137,10 +145,8 @@ public class IoDisplay implements IInfoRenderer {
|
||||
|
||||
nw.requestPowerUpdate(cb, 20);
|
||||
|
||||
HeadingText heading1 = HeadingText.STABLE;
|
||||
HeadingText heading2 = null;
|
||||
String text1;
|
||||
String text2 = "";
|
||||
heading1 = HeadingText.STABLE;
|
||||
heading2 = null;
|
||||
|
||||
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
|
||||
float size = 0.15f * Math.min(info.width, info.height);
|
||||
@@ -150,8 +156,14 @@ public class IoDisplay implements IInfoRenderer {
|
||||
if (info.height * 3 >= info.width * 4) {
|
||||
heading1 = HeadingText.INPUT;
|
||||
heading2 = HeadingText.OUTPUT;
|
||||
text1 = getChangeText(nw.getAverageInputPerTick(), fr);
|
||||
text2 = getChangeText(nw.getAverageOutputPerTick(), fr);
|
||||
if (previousAverageInput != nw.getAverageInputPerTick()) {
|
||||
averageInputText = getChangeText(nw.getAverageInputPerTick(), fr);
|
||||
previousAverageInput = nw.getAverageInputPerTick();
|
||||
}
|
||||
if (previousAverageOutput != nw.getAverageOutputPerTick()) {
|
||||
averageOutputText = getChangeText(nw.getAverageOutputPerTick(), fr);
|
||||
previousAverageOutput = nw.getAverageOutputPerTick();
|
||||
}
|
||||
offset = -size * 2.5f;
|
||||
} else {
|
||||
int change = Math.round(nw.getAverageChangePerTick());
|
||||
@@ -160,7 +172,10 @@ public class IoDisplay implements IInfoRenderer {
|
||||
} else if (change < 0) {
|
||||
heading1 = HeadingText.LOSS;
|
||||
}
|
||||
text1 = getChangeText(change, fr);
|
||||
if (change != previousAverageInput) {
|
||||
averageInputText = getChangeText(change, fr);
|
||||
previousAverageInput = change;
|
||||
}
|
||||
offset = -size;
|
||||
}
|
||||
|
||||
@@ -184,9 +199,9 @@ public class IoDisplay implements IInfoRenderer {
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO);
|
||||
|
||||
offset = drawText(heading1, text1, offset, scale, size, fr);
|
||||
offset = drawText(heading1, averageInputText, offset, scale, size, fr);
|
||||
if (heading2 != null) {
|
||||
drawText(heading2, text2, offset, scale, size, fr);
|
||||
drawText(heading2, averageOutputText, offset, scale, size, fr);
|
||||
}
|
||||
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
|
||||
Reference in new issue
Block a user