Skip to content

Commit

Permalink
reduce memory allocation in renderers
Browse files Browse the repository at this point in the history
  • Loading branch information
boubou19 committed May 2, 2024
1 parent 4cb896d commit fa590fa
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
public class EnderChestRenderer extends TileEntitySpecialRenderer {

private static ModelEnderChest model = new ModelEnderChest();
static Vector3 Y = new Vector3(0, 1, 0);

public EnderChestRenderer() {}

Expand Down Expand Up @@ -63,7 +64,7 @@ public static void renderChest(CCRenderState state, int rotation, int freq, bool
double time = ClientUtils.getRenderTime() + offset;
Matrix4 pearlMat = CCModelLibrary.getRenderMatrix(
new Vector3(x + 0.5, y + 0.2 + lidAngle * -0.5 + EnderStorageClientProxy.getPearlBob(time), z + 0.5),
new Rotation(time / 3, new Vector3(0, 1, 0)),
new Rotation(time / 3, Y),
0.04);

GL11.glDisable(GL11.GL_LIGHTING);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ public class EnderTankRenderer extends TileEntitySpecialRenderer {
static CCModel tankModel;
static CCModel valveModel;
static CCModel[] buttons;

static UVTranslation[] UVTranslationButtons = new UVTranslation[16];
static UVTranslation UVTvalveOwned = new UVTranslation(0, 13 / 64D);
static UVTranslation UVTvalveNotOwned = new UVTranslation(0, 0);
static Vector3 Y = new Vector3(0,1,0);
static Vector3 Z = new Vector3(0, 0, 1);
static Vector3 point = new Vector3(0, 0.4165, 0);

static Cuboid6 cuboidFLuid = new Cuboid6(0.22, 0.12, 0.22, 0.78, 0.121 + 0.63, 0.78);


static RenderCustomEndPortal renderEndPortal = new RenderCustomEndPortal(0.1205, 0.24, 0.76, 0.24, 0.76);

static {
Expand All @@ -62,6 +73,10 @@ public class EnderTankRenderer extends TileEntitySpecialRenderer {
buttons = new CCModel[3];
for (int i = 0; i < 3; i++) buttons[i] = RenderEnderStorage.button.copy()
.apply(TileEnderTank.buttonT[i].with(new Translation(-0.5, 0, -0.5)));

for (int colour=0;colour<16;colour++){
UVTranslationButtons[colour] = new UVTranslation(0.25 * (colour % 4), 0.25 * (colour / 4));
}
}

@Override
Expand Down Expand Up @@ -117,23 +132,23 @@ public static void renderTank(CCRenderState state, int rotation, float valve, in
state.startDrawing(7);
for (int i = 0; i < 3; i++) {
int colour = EnderStorageManager.getColourFromFreq(freq, i);
buttons[i].render(new UVTranslation(0.25 * (colour % 4), 0.25 * (colour / 4)));
buttons[i].render(UVTranslationButtons[colour]);
}
state.draw();

new Rotation(valve, new Vector3(0, 0, 1)).at(new Vector3(0, 0.4165, 0)).glApply();
new Rotation(valve, Z).at(point).glApply();

state.changeTexture("enderstorage:textures/endertank.png");
state.startDrawing(4);
valveModel.render(new UVTranslation(0, owned ? 13 / 64D : 0));
valveModel.render(owned ? UVTvalveOwned : UVTvalveNotOwned);
state.draw();
GL11.glPopMatrix();
GL11.glDisable(GL12.GL_RESCALE_NORMAL);

double time = ClientUtils.getRenderTime() + offset;
Matrix4 pearlMat = CCModelLibrary.getRenderMatrix(
new Vector3(x + 0.5, y + 0.45 + EnderStorageClientProxy.getPearlBob(time) * 2, z + 0.5),
new Rotation(time / 3, new Vector3(0, 1, 0)),
new Rotation(time / 3, Y),
0.04);

GL11.glDisable(GL11.GL_LIGHTING);
Expand All @@ -147,7 +162,7 @@ public static void renderTank(CCRenderState state, int rotation, float valve, in
public static void renderLiquid(FluidStack liquid, double x, double y, double z) {
RenderUtils.renderFluidCuboid(
liquid,
new Cuboid6(0.22, 0.12, 0.22, 0.78, 0.121 + 0.63, 0.78).add(new Vector3(x, y, z)),
cuboidFLuid.add(new Vector3(x, y, z)),
liquid.amount / ((double) EnderStorage.enderTankSize * FluidUtils.B),
0.75);
}
Expand Down

0 comments on commit fa590fa

Please sign in to comment.