From 91743bf742c790b34e7dd435bfa7171396d384c0 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Mon, 9 Jun 2025 07:50:21 -0500 Subject: [PATCH] Add Api Before/After Text Create events Deprecate DhApiColorDepthTextureCreatedEvent since it is less obvious when it fires --- ...ApiAfterColorDepthTextureCreatedEvent.java | 48 +++++++++++++ ...piBeforeColorDepthTextureCreatedEvent.java | 49 +++++++++++++ .../DhApiColorDepthTextureCreatedEvent.java | 14 +++- .../DhApiTextureCreatedParam.java | 68 +++++++++++++++++++ .../distanthorizons/coreapi/ModInfo.java | 2 +- .../core/render/renderer/LodRenderer.java | 17 +++-- 6 files changed, 191 insertions(+), 7 deletions(-) create mode 100644 api/src/main/java/com/seibel/distanthorizons/api/methods/events/abstractEvents/DhApiAfterColorDepthTextureCreatedEvent.java create mode 100644 api/src/main/java/com/seibel/distanthorizons/api/methods/events/abstractEvents/DhApiBeforeColorDepthTextureCreatedEvent.java create mode 100644 api/src/main/java/com/seibel/distanthorizons/api/methods/events/sharedParameterObjects/DhApiTextureCreatedParam.java diff --git a/api/src/main/java/com/seibel/distanthorizons/api/methods/events/abstractEvents/DhApiAfterColorDepthTextureCreatedEvent.java b/api/src/main/java/com/seibel/distanthorizons/api/methods/events/abstractEvents/DhApiAfterColorDepthTextureCreatedEvent.java new file mode 100644 index 000000000..a787fc5b9 --- /dev/null +++ b/api/src/main/java/com/seibel/distanthorizons/api/methods/events/abstractEvents/DhApiAfterColorDepthTextureCreatedEvent.java @@ -0,0 +1,48 @@ +/* + * This file is part of the Distant Horizons mod + * licensed under the GNU LGPL v3 License. + * + * Copyright (C) 2020 James Seibel + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.seibel.distanthorizons.api.methods.events.abstractEvents; + +import com.seibel.distanthorizons.api.methods.events.interfaces.IDhApiEvent; +import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiEventParam; +import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiTextureCreatedParam; + +/** + * Called after Distant Horizons (re)creates + * the color and depth textures it renders to.
+ * + * @author James Seibel + * @version 2025-6-9 + * @since API 4.1.0 + */ +public abstract class DhApiAfterColorDepthTextureCreatedEvent implements IDhApiEvent +{ + /** Fired before Distant Horizons creates. */ + public abstract void onResize(DhApiEventParam event); + + + //=========================// + // internal DH API methods // + //=========================// + + @Override + public final void fireEvent(DhApiEventParam event) { this.onResize(event); } + + +} \ No newline at end of file diff --git a/api/src/main/java/com/seibel/distanthorizons/api/methods/events/abstractEvents/DhApiBeforeColorDepthTextureCreatedEvent.java b/api/src/main/java/com/seibel/distanthorizons/api/methods/events/abstractEvents/DhApiBeforeColorDepthTextureCreatedEvent.java new file mode 100644 index 000000000..780423aa5 --- /dev/null +++ b/api/src/main/java/com/seibel/distanthorizons/api/methods/events/abstractEvents/DhApiBeforeColorDepthTextureCreatedEvent.java @@ -0,0 +1,49 @@ +/* + * This file is part of the Distant Horizons mod + * licensed under the GNU LGPL v3 License. + * + * Copyright (C) 2020 James Seibel + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.seibel.distanthorizons.api.methods.events.abstractEvents; + +import com.seibel.distanthorizons.api.methods.events.interfaces.IDhApiEvent; +import com.seibel.distanthorizons.api.methods.events.interfaces.IDhApiEventParam; +import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiEventParam; +import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiTextureCreatedParam; + +/** + * Called before Distant Horizons (re)creates + * the color and depth textures it renders to.
+ * + * @author James Seibel + * @version 2025-6-9 + * @since API 4.1.0 + */ +public abstract class DhApiBeforeColorDepthTextureCreatedEvent implements IDhApiEvent +{ + /** Fired before Distant Horizons creates. */ + public abstract void onResize(DhApiEventParam event); + + + //=========================// + // internal DH API methods // + //=========================// + + @Override + public final void fireEvent(DhApiEventParam event) { this.onResize(event); } + + +} \ No newline at end of file diff --git a/api/src/main/java/com/seibel/distanthorizons/api/methods/events/abstractEvents/DhApiColorDepthTextureCreatedEvent.java b/api/src/main/java/com/seibel/distanthorizons/api/methods/events/abstractEvents/DhApiColorDepthTextureCreatedEvent.java index 1de7b1a08..c362fdc54 100644 --- a/api/src/main/java/com/seibel/distanthorizons/api/methods/events/abstractEvents/DhApiColorDepthTextureCreatedEvent.java +++ b/api/src/main/java/com/seibel/distanthorizons/api/methods/events/abstractEvents/DhApiColorDepthTextureCreatedEvent.java @@ -22,15 +22,18 @@ package com.seibel.distanthorizons.api.methods.events.abstractEvents; import com.seibel.distanthorizons.api.methods.events.interfaces.IDhApiEvent; import com.seibel.distanthorizons.api.methods.events.interfaces.IDhApiEventParam; import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiEventParam; +import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiTextureCreatedParam; /** - * Called whenever Distant Horizons (re)creates + * Called before Distant Horizons (re)creates * the color and depth textures it renders to.
* * @author James Seibel * @version 2024-3-2 * @since API 2.0.0 + * @deprecated Replaced by {@link DhApiBeforeColorDepthTextureCreatedEvent} since this event's name isn't obvious when it fires. */ +@Deprecated public abstract class DhApiColorDepthTextureCreatedEvent implements IDhApiEvent { /** Fired before Distant Horizons creates. */ @@ -73,6 +76,15 @@ public abstract class DhApiColorDepthTextureCreatedEvent implements IDhApiEvent< this.newHeight = newHeight; } + public EventParam(DhApiTextureCreatedParam textureCreatedParam) + { + this.previousWidth = textureCreatedParam.previousWidth; + this.previousHeight = textureCreatedParam.previousHeight; + + this.newWidth = textureCreatedParam.newWidth; + this.newHeight = textureCreatedParam.newHeight; + + } @Override diff --git a/api/src/main/java/com/seibel/distanthorizons/api/methods/events/sharedParameterObjects/DhApiTextureCreatedParam.java b/api/src/main/java/com/seibel/distanthorizons/api/methods/events/sharedParameterObjects/DhApiTextureCreatedParam.java new file mode 100644 index 000000000..e9f49f86a --- /dev/null +++ b/api/src/main/java/com/seibel/distanthorizons/api/methods/events/sharedParameterObjects/DhApiTextureCreatedParam.java @@ -0,0 +1,68 @@ +/* + * This file is part of the Distant Horizons mod + * licensed under the GNU LGPL v3 License. + * + * Copyright (C) 2020 James Seibel + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.seibel.distanthorizons.api.methods.events.sharedParameterObjects; + +import com.seibel.distanthorizons.api.enums.rendering.EDhApiRenderPass; +import com.seibel.distanthorizons.api.methods.events.interfaces.IDhApiEventParam; +import com.seibel.distanthorizons.api.objects.math.DhApiMat4f; + +/** + * Contains information relevant to when Distant Horizons (re)creates + * depth/color textures for rendering. + * + * @author James Seibel + * @version 2025-6-9 + * @since API 4.1.0 + */ +public class DhApiTextureCreatedParam implements IDhApiEventParam +{ + /** Measured in pixels */ + public final int previousWidth; + /** Measured in pixels */ + public final int previousHeight; + + /** Measured in pixels */ + public final int newWidth; + /** Measured in pixels */ + public final int newHeight; + + + public DhApiTextureCreatedParam( + int previousWidth, int previousHeight, + int newWidth, int newHeight) + { + this.previousWidth = previousWidth; + this.previousHeight = previousHeight; + + this.newWidth = newWidth; + this.newHeight = newHeight; + + } + + + @Override + public DhApiTextureCreatedParam copy() + { + return new DhApiTextureCreatedParam( + this.previousWidth, this.previousHeight, + this.newWidth, this.newHeight + ); + } +} diff --git a/api/src/main/java/com/seibel/distanthorizons/coreapi/ModInfo.java b/api/src/main/java/com/seibel/distanthorizons/coreapi/ModInfo.java index 2243e10d7..c0c109076 100644 --- a/api/src/main/java/com/seibel/distanthorizons/coreapi/ModInfo.java +++ b/api/src/main/java/com/seibel/distanthorizons/coreapi/ModInfo.java @@ -45,7 +45,7 @@ public final class ModInfo /** This version should only be updated when breaking changes are introduced to the DH API */ public static final int API_MAJOR_VERSION = 4; /** This version should be updated whenever new methods are added to the DH API */ - public static final int API_MINOR_VERSION = 0; + public static final int API_MINOR_VERSION = 1; /** This version should be updated whenever non-breaking fixes are added to the DH API */ public static final int API_PATCH_VERSION = 0; diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/LodRenderer.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/LodRenderer.java index 1b7392e0a..dd4eee5c7 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/LodRenderer.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/LodRenderer.java @@ -23,6 +23,7 @@ import com.seibel.distanthorizons.api.interfaces.override.rendering.IDhApiFrameb import com.seibel.distanthorizons.api.interfaces.override.rendering.IDhApiShaderProgram; import com.seibel.distanthorizons.api.methods.events.abstractEvents.*; import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiRenderParam; +import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiTextureCreatedParam; import com.seibel.distanthorizons.core.config.Config; import com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding.ColumnRenderBuffer; import com.seibel.distanthorizons.core.dependencyInjection.ModAccessorInjector; @@ -692,12 +693,15 @@ public class LodRenderer this.cachedWidth = MC_RENDER.getTargetFrameBufferViewportWidth(); this.cachedHeight = MC_RENDER.getTargetFrameBufferViewportHeight(); + DhApiTextureCreatedParam textureCreatedParam = new DhApiTextureCreatedParam( + oldWidth, oldHeight, + this.cachedWidth, this.cachedHeight + ); - ApiEventInjector.INSTANCE.fireAllEvents(DhApiColorDepthTextureCreatedEvent.class, - new DhApiColorDepthTextureCreatedEvent.EventParam( - oldWidth, oldHeight, - this.cachedWidth, this.cachedHeight - )); + + + ApiEventInjector.INSTANCE.fireAllEvents(DhApiColorDepthTextureCreatedEvent.class, new DhApiColorDepthTextureCreatedEvent.EventParam(textureCreatedParam)); + ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeColorDepthTextureCreatedEvent.class, textureCreatedParam); // also update the override if present @@ -729,6 +733,9 @@ public class LodRenderer { this.nullableColorTexture = null; } + + + ApiEventInjector.INSTANCE.fireAllEvents(DhApiAfterColorDepthTextureCreatedEvent.class, textureCreatedParam); }