From 8eceeb0226b87ae0e6764dd5b9248f2eb427c24b Mon Sep 17 00:00:00 2001 From: James Seibel Date: Thu, 11 Jul 2024 17:20:02 -0500 Subject: [PATCH] Add namespace/path to generic rendering (including F3 piechart) --- .../IDhApiCustomRenderObjectFactory.java | 46 +++++++++++++++++-- .../render/IDhApiRenderableBoxGroup.java | 29 +++++++++++- .../renderer/generic/BeaconRenderHandler.java | 3 +- .../generic/GenericObjectRenderer.java | 14 ++++-- .../generic/GenericRenderObjectFactory.java | 12 ++--- .../renderer/generic/RenderableBoxGroup.java | 22 ++++++++- 6 files changed, 111 insertions(+), 15 deletions(-) diff --git a/api/src/main/java/com/seibel/distanthorizons/api/interfaces/render/IDhApiCustomRenderObjectFactory.java b/api/src/main/java/com/seibel/distanthorizons/api/interfaces/render/IDhApiCustomRenderObjectFactory.java index 5b9b7ae66..334c3edd1 100644 --- a/api/src/main/java/com/seibel/distanthorizons/api/interfaces/render/IDhApiCustomRenderObjectFactory.java +++ b/api/src/main/java/com/seibel/distanthorizons/api/interfaces/render/IDhApiCustomRenderObjectFactory.java @@ -20,8 +20,48 @@ import java.util.List; */ public interface IDhApiCustomRenderObjectFactory { - IDhApiRenderableBoxGroup createForSingleBox(DhApiRenderableBox cube); - IDhApiRenderableBoxGroup createRelativePositionedGroup(DhApiVec3d originBlockPos, List cubeList); - IDhApiRenderableBoxGroup createAbsolutePositionedGroup(List cubeList); + /** + * Creates a {@link IDhApiRenderableBoxGroup} from for the given {@link DhApiRenderableBox} + * where the box is positioned relative to the level's origin. + * + * @param resourceLocation A colon separated Resource Location string, similar to vanilla Minecraft, for example: "DistantHorizons:Clouds" + * + * @see DhApiRenderableBox + * @see IDhApiRenderableBoxGroup#getResourceLocationNamespace() + * @see IDhApiRenderableBoxGroup#getResourceLocationPath() + * + * @throws IllegalArgumentException if resourceLocation is null, isn't separated by a colon, or has multiple colons. + */ + IDhApiRenderableBoxGroup createForSingleBox(String resourceLocation, DhApiRenderableBox cube) throws IllegalArgumentException; + + /** + * Creates a {@link IDhApiRenderableBoxGroup} from the given list of {@link DhApiRenderableBox} where each + * one is positioned relative to given originBlockPos, which in turn is relative to the level's origin. + * + * @param resourceLocation A colon separated Resource Location string, similar to vanilla Minecraft, for example: "DistantHorizons:Clouds" + * @param originBlockPos The starting position for this {@link IDhApiRenderableBoxGroup}, can be changed during runtime. + * + * + * @see DhApiRenderableBox + * @see IDhApiRenderableBoxGroup#getResourceLocationNamespace() + * @see IDhApiRenderableBoxGroup#getResourceLocationPath() + * + * @throws IllegalArgumentException if resourceLocation is null, isn't separated by a colon, or has multiple colons. + */ + IDhApiRenderableBoxGroup createRelativePositionedGroup(String resourceLocation, DhApiVec3d originBlockPos, List cubeList); + + /** + * Creates a {@link IDhApiRenderableBoxGroup} from the given list of {@link DhApiRenderableBox} where each + * one is positioned relative to the level's origin. + * + * @param resourceLocation A colon separated Resource Location string, similar to vanilla Minecraft, for example: "DistantHorizons:Clouds" + * + * @see DhApiRenderableBox + * @see IDhApiRenderableBoxGroup#getResourceLocationNamespace() + * @see IDhApiRenderableBoxGroup#getResourceLocationPath() + * + * @throws IllegalArgumentException if resourceLocation is null, isn't separated by a colon, or has multiple colons. + */ + IDhApiRenderableBoxGroup createAbsolutePositionedGroup(String resourceLocation, List cubeList); } diff --git a/api/src/main/java/com/seibel/distanthorizons/api/interfaces/render/IDhApiRenderableBoxGroup.java b/api/src/main/java/com/seibel/distanthorizons/api/interfaces/render/IDhApiRenderableBoxGroup.java index 5eda2969f..399ba1571 100644 --- a/api/src/main/java/com/seibel/distanthorizons/api/interfaces/render/IDhApiRenderableBoxGroup.java +++ b/api/src/main/java/com/seibel/distanthorizons/api/interfaces/render/IDhApiRenderableBoxGroup.java @@ -23,9 +23,36 @@ import java.util.function.Consumer; */ public interface IDhApiRenderableBoxGroup extends List { - /** @return the ID for this specific group */ + /** + * A unique numerical ID used by DH during rendering. + * This can also be used to bind/unbind specific {@link IDhApiRenderableBoxGroup}'s from the renderer. + * @return the ID for this specific group + */ long getId(); + /** + * Used to determine which mods have added what to the DH renderer. + * This can be used both by the F3 pie chart so you as a mod developer can profile your code + * or by shader developers who want to render your objects differently.

+ * + * Should be used the same as a vanilla Minecraft ResourceLocation. + * For example if your mod named "Heavy Thunder" adds additional clouds named "Storm Front", + * your Resource Location would be something like "HeavyThunder:StormFront" + * and this method would return "HeavyThunder". + */ + String getResourceLocationNamespace(); + /** + * Used to determine what type of object mods have added what to the DH renderer. + * This can be used both by the F3 pie chart so you as a mod developer can profile your code + * or by shader developers who want to render your objects differently.

+ * + * Should be used the same as a vanilla Minecraft ResourceLocation. + * For example if your mod named "Heavy Thunder" adds additional clouds named "Storm Front", + * your Resource Location would be something like "HeavyThunder:StormFront" + * and this method would return "StormFront". + */ + String getResourceLocationPath(); + /** Sets whether this group should render or not. */ void setActive(boolean active); /** @return if active this group will render. */ diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/BeaconRenderHandler.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/BeaconRenderHandler.java index dd4140b02..38eb0d470 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/BeaconRenderHandler.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/BeaconRenderHandler.java @@ -33,6 +33,7 @@ import com.seibel.distanthorizons.core.sql.dto.BeaconBeamDTO; import com.seibel.distanthorizons.core.sql.repo.BeaconBeamRepo; import com.seibel.distanthorizons.core.util.LodUtil; import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper; +import com.seibel.distanthorizons.coreapi.ModInfo; import org.apache.logging.log4j.Logger; import org.jetbrains.annotations.NotNull; @@ -66,7 +67,7 @@ public class BeaconRenderHandler { this.beaconBeamRepo = beaconBeamRepo; - this.beaconBoxGroup = GenericRenderObjectFactory.INSTANCE.createAbsolutePositionedGroup(new ArrayList<>(0)); + this.beaconBoxGroup = GenericRenderObjectFactory.INSTANCE.createAbsolutePositionedGroup(ModInfo.NAME+":Beacons", new ArrayList<>(0)); this.beaconBoxGroup.setBlockLight(LodUtil.MAX_MC_LIGHT); this.beaconBoxGroup.setSkyLight(LodUtil.MAX_MC_LIGHT); this.beaconBoxGroup.setShading(DhApiRenderableBoxGroupShading.getUnshaded()); diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/GenericObjectRenderer.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/GenericObjectRenderer.java index 2264cf1ac..0495a3609 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/GenericObjectRenderer.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/GenericObjectRenderer.java @@ -41,6 +41,7 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRen import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IProfilerWrapper; import com.seibel.distanthorizons.core.util.math.Vec3d; import com.seibel.distanthorizons.coreapi.DependencyInjection.OverrideInjector; +import com.seibel.distanthorizons.coreapi.ModInfo; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.lwjgl.opengl.ARBInstancedArrays; @@ -214,6 +215,7 @@ public class GenericObjectRenderer implements IDhApiCustomRenderRegister // single giant box IDhApiRenderableBoxGroup singleGiantBoxGroup = factory.createForSingleBox( + ModInfo.NAME + ":CyanChunkBox", new DhApiRenderableBox( new DhApiVec3d(0,0,0), new DhApiVec3d(16,190,16), new Color(Color.CYAN.getRed(), Color.CYAN.getGreen(), Color.CYAN.getBlue(), 125)) @@ -225,6 +227,7 @@ public class GenericObjectRenderer implements IDhApiCustomRenderRegister // single slender box IDhApiRenderableBoxGroup singleTallBoxGroup = factory.createForSingleBox( + ModInfo.NAME + ":GreenBeacon", new DhApiRenderableBox( new DhApiVec3d(16,0,31), new DhApiVec3d(17,2000,32), new Color(Color.GREEN.getRed(), Color.GREEN.getGreen(), Color.GREEN.getBlue(), 125)) @@ -242,7 +245,7 @@ public class GenericObjectRenderer implements IDhApiCustomRenderRegister new DhApiVec3d(i,150+i,24), new DhApiVec3d(1+i,151+i,25), new Color(Color.ORANGE.getRed(), Color.ORANGE.getGreen(), Color.ORANGE.getBlue()))); } - IDhApiRenderableBoxGroup absolutePosBoxGroup = factory.createAbsolutePositionedGroup(absBoxList); + IDhApiRenderableBoxGroup absolutePosBoxGroup = factory.createAbsolutePositionedGroup(ModInfo.NAME + ":OrangeStairs", absBoxList); this.add(absolutePosBoxGroup); @@ -255,6 +258,7 @@ public class GenericObjectRenderer implements IDhApiCustomRenderRegister new Color(Color.MAGENTA.getRed(), Color.MAGENTA.getGreen(), Color.MAGENTA.getBlue()))); } IDhApiRenderableBoxGroup relativePosBoxGroup = factory.createRelativePositionedGroup( + ModInfo.NAME + ":MovingMagentaGroup", new DhApiVec3d(24, 140, 24), relBoxList); relativePosBoxGroup.setPreRenderFunc((event) -> @@ -279,6 +283,7 @@ public class GenericObjectRenderer implements IDhApiCustomRenderRegister } } IDhApiRenderableBoxGroup massRelativePosBoxGroup = factory.createRelativePositionedGroup( + ModInfo.NAME + ":MassRedGroup", new DhApiVec3d(-25, 140, 0), massRelBoxList); massRelativePosBoxGroup.setPreRenderFunc((event) -> @@ -385,16 +390,19 @@ public class GenericObjectRenderer implements IDhApiCustomRenderRegister // ignore inactive groups if (boxGroup.active) { + profiler.popPush("rendering"); + profiler.push(boxGroup.getResourceLocationNamespace()); + profiler.push(boxGroup.getResourceLocationPath()); if (this.useInstancedRendering) { - profiler.popPush("rendering"); this.renderBoxGroupInstanced(shaderProgram, renderEventParam, boxGroup, camPos); } else { - profiler.popPush("rendering"); this.renderBoxGroupDirect(shaderProgram, renderEventParam, boxGroup, camPos); } + profiler.pop(); // resource path + profiler.pop(); // resource namespace boxGroup.postRender(renderEventParam); } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/GenericRenderObjectFactory.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/GenericRenderObjectFactory.java index 263b00ece..ca0590957 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/GenericRenderObjectFactory.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/GenericRenderObjectFactory.java @@ -60,19 +60,19 @@ public class GenericRenderObjectFactory implements IDhApiCustomRenderObjectFacto //================// @Override - public IDhApiRenderableBoxGroup createForSingleBox(DhApiRenderableBox box) + public IDhApiRenderableBoxGroup createForSingleBox(String resourceLocation, DhApiRenderableBox box) { ArrayList list = new ArrayList<>(); list.add(box); - return this.createAbsolutePositionedGroup(list); + return this.createAbsolutePositionedGroup(resourceLocation, list); } @Override - public IDhApiRenderableBoxGroup createRelativePositionedGroup(DhApiVec3d originBlockPos, List boxList) - { return new RenderableBoxGroup(new DhApiVec3d(originBlockPos.x, originBlockPos.y, originBlockPos.z), boxList, true); } + public IDhApiRenderableBoxGroup createRelativePositionedGroup(String resourceLocation, DhApiVec3d originBlockPos, List boxList) + { return new RenderableBoxGroup(resourceLocation, new DhApiVec3d(originBlockPos.x, originBlockPos.y, originBlockPos.z), boxList, true); } @Override - public IDhApiRenderableBoxGroup createAbsolutePositionedGroup(List boxList) - { return new RenderableBoxGroup(new DhApiVec3d(0, 0, 0), boxList, false); } + public IDhApiRenderableBoxGroup createAbsolutePositionedGroup(String resourceLocation, List boxList) + { return new RenderableBoxGroup(resourceLocation, new DhApiVec3d(0, 0, 0), boxList, false); } } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/RenderableBoxGroup.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/RenderableBoxGroup.java index 96fff73fa..214449ba2 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/RenderableBoxGroup.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/RenderableBoxGroup.java @@ -30,6 +30,9 @@ public class RenderableBoxGroup public final long id; + public final String resourceLocationNamespace; + public final String resourceLocationPath; + /** If false the boxes will be positioned relative to the level's origin */ public final boolean positionBoxesRelativeToGroupOrigin; @@ -65,6 +68,11 @@ public class RenderableBoxGroup @Override public long getId() { return this.id; } + @Override + public String getResourceLocationNamespace() { return this.resourceLocationNamespace; } + @Override + public String getResourceLocationPath() { return this.resourceLocationPath; } + @Override public void setOriginBlockPos(DhApiVec3d pos) { @@ -107,8 +115,20 @@ public class RenderableBoxGroup // constructor // //=============// - public RenderableBoxGroup(DhApiVec3d originBlockPos, List boxList, boolean positionBoxesRelativeToGroupOrigin) + public RenderableBoxGroup( + String resourceLocation, + DhApiVec3d originBlockPos, List boxList, + boolean positionBoxesRelativeToGroupOrigin) throws IllegalArgumentException { + String[] splitResourceLocation = resourceLocation.split(":"); + if (splitResourceLocation.length != 2) + { + throw new IllegalArgumentException("Resource Location must be a string that's separated by a single colon, for example: [DistantHorizons:Beacons], your namespace ["+resourceLocation+"], contains ["+(splitResourceLocation.length-1)+"] colons."); + } + + this.resourceLocationNamespace = splitResourceLocation[0]; + this.resourceLocationPath = splitResourceLocation[1]; + this.id = NEXT_ID_ATOMIC_INT.getAndIncrement(); this.boxList = new ArrayList<>(boxList);