From 44b86cc6b1ecde84632f9cf4f06f5c35aa4d8b6d Mon Sep 17 00:00:00 2001 From: Brady Date: Thu, 25 Apr 2024 07:29:05 -0230 Subject: Backend: Improves performance of item backgrounds and borders (#1497) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Co-authored-by: Cal --- .../at/hannibal2/skyhanni/utils/CollectionUtils.kt | 11 ++++ .../at/hannibal2/skyhanni/utils/RenderUtils.kt | 60 +++++++++++++++++----- 2 files changed, 59 insertions(+), 12 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/utils') diff --git a/src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt index d33729ae3..f538f2d53 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt @@ -262,4 +262,15 @@ object CollectionUtils { addString("§a]") })) } + + inline fun Map.mapKeysNotNull(transform: (Map.Entry) -> R?): Map { + val destination = LinkedHashMap() + for (element in this) { + val newKey = transform(element) + if (newKey != null) { + destination[newKey] = element.value + } + } + return destination + } } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt index 0c8b2b694..0ea8b76eb 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt @@ -7,6 +7,7 @@ import at.hannibal2.skyhanni.data.GuiEditManager.Companion.getAbsY import at.hannibal2.skyhanni.data.GuiEditManager.Companion.getDummySize import at.hannibal2.skyhanni.events.GuiRenderItemEvent import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent +import at.hannibal2.skyhanni.events.RenderGuiItemOverlayEvent import at.hannibal2.skyhanni.features.misc.RoundedRectangleShader import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.renderables.Renderable @@ -66,22 +67,57 @@ object RenderUtils { } infix fun Slot.highlight(color: Color) { - GlStateManager.color(1f, 1f, 1f, 1f) - GlStateManager.pushAttrib() - GL11.glDisable(GL11.GL_LIGHTING) - GL11.glEnable(GL11.GL_DEPTH_TEST) + highlight(color, xDisplayPosition, yDisplayPosition) + } + + infix fun RenderGuiItemOverlayEvent.highlight(color: LorenzColor) { + highlight(color.toColor()) + } + + infix fun RenderGuiItemOverlayEvent.highlight(color: Color) { + highlight(color, x, y) + } + + fun highlight(color: Color, x: Int, y: Int) { + GlStateManager.disableLighting() + GlStateManager.disableDepth() GlStateManager.pushMatrix() // TODO don't use z GlStateManager.translate(0f, 0f, 110 + Minecraft.getMinecraft().renderItem.zLevel) - Gui.drawRect( - this.xDisplayPosition, - this.yDisplayPosition, - this.xDisplayPosition + 16, - this.yDisplayPosition + 16, - color.rgb - ) + Gui.drawRect(x, y, x + 16, y + 16, color.rgb) GlStateManager.popMatrix() - GlStateManager.popAttrib() + GlStateManager.enableDepth() + GlStateManager.enableLighting() + } + + infix fun Slot.drawBorder(color: LorenzColor) { + drawBorder(color.toColor()) + } + + infix fun Slot.drawBorder(color: Color) { + drawBorder(color, xDisplayPosition, yDisplayPosition) + } + + infix fun RenderGuiItemOverlayEvent.drawBorder(color: LorenzColor) { + drawBorder(color.toColor()) + } + + infix fun RenderGuiItemOverlayEvent.drawBorder(color: Color) { + drawBorder(color, x, y) + } + + fun drawBorder(color: Color, x: Int, y: Int) { + GlStateManager.disableLighting() + GlStateManager.disableDepth() + GlStateManager.pushMatrix() + GlStateManager.translate(0f, 0f, 110 + Minecraft.getMinecraft().renderItem.zLevel) + Gui.drawRect(x, y, x + 1, y + 16, color.rgb) + Gui.drawRect(x, y, x + 16, y + 1, color.rgb) + Gui.drawRect(x, y + 15, x + 16, y + 16, color.rgb) + Gui.drawRect(x + 15, y, x + 16, y + 16, color.rgb) + GlStateManager.popMatrix() + GlStateManager.enableDepth() + GlStateManager.enableLighting() } fun LorenzRenderWorldEvent.drawColor( -- cgit