This commit is contained in:
s809
2023-11-19 22:56:56 +05:00
11 changed files with 144 additions and 69 deletions
@@ -26,10 +26,12 @@ import com.seibel.distanthorizons.core.config.types.ConfigCategory;
import com.seibel.distanthorizons.core.config.types.ConfigEntry;
import com.seibel.distanthorizons.core.config.types.ConfigLinkedEntry;
import com.seibel.distanthorizons.core.wrapperInterfaces.config.ILangWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftSharedWrapper;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.lang.reflect.Field;
import java.nio.file.Path;
import java.util.*;
/**
@@ -69,7 +71,7 @@ public class ConfigBase
* <br> {@link String}
* <br>
* <br> // Below, "T" should be a value from above
* <br> // Note: This is not checked, so we trust that you are doing the right thing
* <br> // Note: This is not checked, so we trust that you are doing the right thing (TODO: Check it)
* <br> List<T>
* <br> ArrayList<T>
* <br> Map<String, T>
@@ -98,7 +100,20 @@ public class ConfigBase
public final List<AbstractConfigType<?, ?>> entries = new ArrayList<>();
public ConfigBase(String modID, String modName, Class<?> config)
{
this(modID, modName, config, getConfigPath(modName), -1);
}
public ConfigBase(String modID, String modName, Class<?> config, Path configPath)
{
this(modID, modName, config, configPath, -1);
}
public ConfigBase(String modID, String modName, Class<?> config, int configVersion)
{
this(modID, modName, config, getConfigPath(modName), configVersion);
}
public ConfigBase(String modID, String modName, Class<?> config, Path configPath, int configVersion)
{
this.LOGGER = LogManager.getLogger(this.getClass().getSimpleName() + ", " + modID);
@@ -110,7 +125,7 @@ public class ConfigBase
initNestedClass(config, ""); // Init root category
// File handling (load from file)
this.configFileINSTANCE = new ConfigFileHandling(this);
this.configFileINSTANCE = new ConfigFileHandling(this, configPath);
this.configFileINSTANCE.loadFromFile();
isLoaded = true;
@@ -171,6 +186,12 @@ public class ConfigBase
}
/** Gets the default config path given a mod name */
public static Path getConfigPath(String modName)
{
return SingletonInjector.INSTANCE.get(IMinecraftSharedWrapper.class)
.getInstallationDirectory().toPath().resolve("config").resolve(modName + ".toml");
}
/**
@@ -49,15 +49,13 @@ public class ConfigFileHandling
/** This is the object for night-config */
private final CommentedFileConfig nightConfig;
public ConfigFileHandling(ConfigBase configBase)
public ConfigFileHandling(ConfigBase configBase, Path configPath)
{
this.LOGGER = LogManager.getLogger(this.getClass().getSimpleName() + ", " + configBase.modID);
this.configBase = configBase;
this.configPath = configPath;
configPath = SingletonInjector.INSTANCE.get(IMinecraftSharedWrapper.class)
.getInstallationDirectory().toPath().resolve("config").resolve(this.configBase.modName + ".toml");
this.nightConfig = CommentedFileConfig.builder(configPath.toFile()).build();
this.nightConfig = CommentedFileConfig.builder(this.configPath.toFile()).build();
}
/** Saves the entire config to the file */
@@ -105,7 +103,38 @@ public class ConfigFileHandling
*/
public void loadFromFile()
{
int currentCfgVersion = configBase.configVersion;
try
{
// Dont load the real `this.nightConfig`, instead create a tempoary one
CommentedFileConfig tmpNightConfig = CommentedFileConfig.builder(this.configPath.toFile()).build();
tmpNightConfig.load();
// Attempt to get the version number
currentCfgVersion = (Integer) tmpNightConfig.get("_version");
tmpNightConfig.close();
} catch (Exception e) {e.printStackTrace();}
if (currentCfgVersion == configBase.configVersion)
{}
else if (currentCfgVersion > configBase.configVersion)
{
LOGGER.warn("Found config version [" + String.valueOf(currentCfgVersion) + "] which is newer than current mods config version of [" + String.valueOf(configBase.configVersion) + "]. You may have downgraded the mod and items may have been moved, you have been warned");
}
else // if (currentCfgVersion < configBase.configVersion)
{
LOGGER.warn(configBase.modName +" config is of an older version, currently there is no config updater... so resetting config");
try
{
Files.delete(configPath);
}
catch (Exception e)
{
LOGGER.error(e);
}
}
loadFromFile(nightConfig);
nightConfig.set("_version", configBase.configVersion);
}
/**
* Loads the entire config from the file
@@ -122,7 +151,6 @@ public class ConfigFileHandling
else
{
reCreateFile(configPath);
return;
}
@@ -39,7 +39,7 @@ public class GitlabGetter
public final String projectID;
/** Combines the {@link GitlabGetter#GitlabApi} and {@link GitlabGetter#projectID} into one var (Followed by a "/" at the end) */
public final String GitProjID;
public ArrayList<Config> projectPipelines;
public ArrayList<Config> projectPipelines = new ArrayList<>();
/** Commit sha; Commit info */
private static final Map<String, Config> commitInfo = new HashMap<>();
@@ -89,7 +89,7 @@ public class MarkdownFormatter
@Override
public String convertTo(String original)
{
original = original.replaceAll("<br>", "\n"); // New lines
original = original.replaceAll("<br>|<br/>", "\n"); // New lines
original = replaceRegex(original, "\\*\\*", "§l", "§r"); // Bold
original = replaceRegex(original, "~~", "§m", "§r"); // Striketrough
// original = replaceRegex(original, "_", "§n", "§r"); // Italic
@@ -80,15 +80,22 @@ public class SelfUpdater
}
boolean returnValue = false;
switch (Config.Client.Advanced.AutoUpdater.updateBranch.get())
try
{
case STABLE:
returnValue = onStableStart();
break;
case NIGHTLY:
returnValue = onNightlyStart();
break;
};
switch (Config.Client.Advanced.AutoUpdater.updateBranch.get())
{
case STABLE:
returnValue = onStableStart();
break;
case NIGHTLY:
returnValue = onNightlyStart();
break;
};
}
catch (Exception e) // Shouldn't be needed, but just in case
{
LOGGER.warn(e);
}
return returnValue;
}
@@ -373,7 +380,9 @@ public class SelfUpdater
}
catch (Exception e)
{
LOGGER.warn("Failed to delete previous " + ModInfo.READABLE_NAME + " file, please delete it manually at [" + JarUtils.jarFile + "]", e);
LOGGER.warn("Failed to delete old jar using bootstrap method, doing backup 'Files.deleteOnExit()' method", e);
JarUtils.jarFile.deleteOnExit();
LOGGER.warn("If the old DH file didnt delete, delete it manually at [" + JarUtils.jarFile + "]");
}
}
@@ -36,6 +36,9 @@ public class GLState
public int activeTextureNumber;
public int texture0;
public int texture1;
public int frameBufferTexture0;
public int frameBufferTexture1;
public int frameBufferDepthTexture;
public boolean blend;
public int blendEqRGB;
public int blendEqAlpha;
@@ -82,6 +85,10 @@ public class GLState
GL32.glActiveTexture(this.activeTextureNumber);
this.frameBufferTexture0 = GL32.glGetFramebufferAttachmentParameteri(GL32.GL_FRAMEBUFFER, GL32.GL_COLOR_ATTACHMENT0, GL32.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME);
this.frameBufferTexture1 = GL32.glGetFramebufferAttachmentParameteri(GL32.GL_FRAMEBUFFER, GL32.GL_COLOR_ATTACHMENT1, GL32.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME);
this.frameBufferDepthTexture = GL32.glGetFramebufferAttachmentParameteri(GL32.GL_FRAMEBUFFER, GL32.GL_DEPTH_ATTACHMENT, GL32.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME);
this.blend = GL32.glIsEnabled(GL32.GL_BLEND);
this.blendEqRGB = GL32.glGetInteger(GL32.GL_BLEND_EQUATION_RGB);
this.blendEqAlpha = GL32.glGetInteger(GL32.GL_BLEND_EQUATION_ALPHA);
@@ -109,6 +116,9 @@ public class GLState
return "GLState{" +
"program=" + this.program + ", vao=" + this.vao + ", vbo=" + this.vbo + ", ebo=" + this.ebo + ", fbo=" + this.fbo[0] +
", text=" + GLEnums.getString(this.texture2D) + "@" + this.activeTextureNumber + ", text0=" + GLEnums.getString(this.texture0) +
", FB text0=" + this.frameBufferTexture0 +
", FB text1=" + this.frameBufferTexture1 +
", FB depth=" + this.frameBufferDepthTexture +
", blend=" + this.blend + ", blendMode=" + GLEnums.getString(this.blendSrcColor) + "," + GLEnums.getString(this.blendDstColor) +
", depth=" + this.depth +
", depthFunc=" + GLEnums.getString(this.depthFunc) + ", stencil=" + this.stencil + ", stencilFunc=" +
@@ -155,6 +165,10 @@ public class GLState
GL32.glActiveTexture(this.activeTextureNumber);
GL32.glBindTexture(GL32.GL_TEXTURE_2D, GL32.glIsTexture(this.texture2D) ? this.texture2D : 0);
GL32.glFramebufferTexture2D(GL32.GL_FRAMEBUFFER, GL32.GL_COLOR_ATTACHMENT0, GL32.GL_TEXTURE_2D, this.frameBufferTexture0, 0);
GL32.glFramebufferTexture2D(GL32.GL_FRAMEBUFFER, GL32.GL_COLOR_ATTACHMENT1, GL32.GL_TEXTURE_2D, this.frameBufferTexture1, 0);
GL32.glFramebufferTexture2D(GL32.GL_FRAMEBUFFER, GL32.GL_DEPTH_ATTACHMENT, GL32.GL_TEXTURE_2D, this.frameBufferDepthTexture, 0);
GL32.glBindVertexArray(GL32.glIsVertexArray(this.vao) ? this.vao : 0);
GL32.glBindBuffer(GL32.GL_ARRAY_BUFFER, GL32.glIsBuffer(this.vbo) ? this.vbo : 0);
GL32.glBindBuffer(GL32.GL_ELEMENT_ARRAY_BUFFER, GL32.glIsBuffer(this.ebo) ? this.ebo: 0);
@@ -16,7 +16,8 @@ public class DhColorTexture
private int height;
private boolean isValid;
private final int texture;
/** AKA, the OpenGL name of this texture */
private final int id;
private static final ByteBuffer NULL_BUFFER = null;
@@ -37,10 +38,10 @@ public class DhColorTexture
this.width = builder.width;
this.height = builder.height;
this.texture = GL43C.glGenTextures();
this.id = GL43C.glGenTextures();
boolean isPixelFormatInteger = builder.internalFormat.getPixelFormat().isInteger();
setupTexture(texture, builder.width, builder.height, !isPixelFormatInteger);
this.setupTexture(this.id, builder.width, builder.height, !isPixelFormatInteger);
// Clean up after ourselves
// This is strictly defensive to ensure that other buggy code doesn't tamper with our textures
@@ -53,9 +54,9 @@ public class DhColorTexture
// methods //
//=========//
private void setupTexture(int texture, int width, int height, boolean allowsLinear)
private void setupTexture(int id, int width, int height, boolean allowsLinear)
{
resizeTexture(texture, width, height);
this.resizeTexture(id, width, height);
GL43C.glTexParameteri(GL11C.GL_TEXTURE_2D, GL11C.GL_TEXTURE_MIN_FILTER, allowsLinear ? GL11C.GL_LINEAR : GL11C.GL_NEAREST);
GL43C.glTexParameteri(GL11C.GL_TEXTURE_2D, GL11C.GL_TEXTURE_MAG_FILTER, allowsLinear ? GL11C.GL_LINEAR : GL11C.GL_NEAREST);
@@ -66,7 +67,7 @@ public class DhColorTexture
private void resizeTexture(int texture, int width, int height)
{
GL43C.glBindTexture(GL43C.GL_TEXTURE_2D, texture);
GL43C.glTexImage2D(GL11C.GL_TEXTURE_2D, 0, internalFormat.getGlFormat(), width, height, 0, format.getGlFormat(), type.getGlFormat(), NULL_BUFFER);
GL43C.glTexImage2D(GL11C.GL_TEXTURE_2D, 0, this.internalFormat.getGlFormat(), width, height, 0, this.format.getGlFormat(), this.type.getGlFormat(), NULL_BUFFER);
}
void resize(Vector2i textureScaleOverride) { this.resize(textureScaleOverride.x, textureScaleOverride.y); }
@@ -74,38 +75,38 @@ public class DhColorTexture
// Package private, call CompositeRenderTargets#resizeIfNeeded instead.
public void resize(int width, int height)
{
requireValid();
this.throwIfInvalid();
this.width = width;
this.height = height;
resizeTexture(texture, width, height);
this.resizeTexture(this.id, width, height);
}
public EDhInternalTextureFormat getInternalFormat() { return internalFormat; }
public EDhInternalTextureFormat getInternalFormat() { return this.internalFormat; }
public int getTexture()
public int getTextureId()
{
requireValid();
return texture;
this.throwIfInvalid();
return this.id;
}
public int getWidth() { return width; }
public int getWidth() { return this.width; }
public int getHeight() { return height; }
public int getHeight() { return this.height; }
public void destroy()
{
requireValid();
isValid = false;
this.throwIfInvalid();
this.isValid = false;
GL43C.glDeleteTextures(texture);
GL43C.glDeleteTextures(this.id);
}
private void requireValid()
/** @throws IllegalStateException if the texture isn't valid */
private void throwIfInvalid()
{
if (!isValid)
if (!this.isValid)
{
throw new IllegalStateException("Attempted to use a deleted composite render target");
}
@@ -2,8 +2,7 @@ package com.seibel.distanthorizons.core.render.glObject.texture;
import it.unimi.dsi.fastutil.ints.Int2IntArrayMap;
import it.unimi.dsi.fastutil.ints.Int2IntMap;
import org.lwjgl.opengl.GL30C;
import org.lwjgl.opengl.GL43C;
import org.lwjgl.opengl.GL32;
// TODO lowercase
public class DhFramebuffer
@@ -22,11 +21,11 @@ public class DhFramebuffer
public DhFramebuffer()
{
this.id = GL43C.glGenFramebuffers();
this.id = GL32.glGenFramebuffers();
this.attachments = new Int2IntArrayMap();
this.maxDrawBuffers = GL43C.glGetInteger(GL30C.GL_MAX_DRAW_BUFFERS);
this.maxColorAttachments = GL43C.glGetInteger(GL30C.GL_MAX_COLOR_ATTACHMENTS);
this.maxDrawBuffers = GL32.glGetInteger(GL32.GL_MAX_DRAW_BUFFERS);
this.maxColorAttachments = GL32.glGetInteger(GL32.GL_MAX_COLOR_ATTACHMENTS);
this.hasDepthAttachment = false;
}
@@ -36,8 +35,8 @@ public class DhFramebuffer
this.id = id;
this.attachments = new Int2IntArrayMap();
this.maxDrawBuffers = GL43C.glGetInteger(GL30C.GL_MAX_DRAW_BUFFERS);
this.maxColorAttachments = GL43C.glGetInteger(GL30C.GL_MAX_COLOR_ATTACHMENTS);
this.maxDrawBuffers = GL32.glGetInteger(GL32.GL_MAX_DRAW_BUFFERS);
this.maxColorAttachments = GL32.glGetInteger(GL32.GL_MAX_COLOR_ATTACHMENTS);
this.hasDepthAttachment = false;
}
@@ -53,11 +52,11 @@ public class DhFramebuffer
if (depthBufferFormat.isCombinedStencil())
{
GL43C.glFramebufferTexture2D(GL30C.GL_FRAMEBUFFER, GL30C.GL_DEPTH_STENCIL_ATTACHMENT, GL30C.GL_TEXTURE_2D, texture, 0);
GL32.glFramebufferTexture2D(GL32.GL_FRAMEBUFFER, GL32.GL_DEPTH_STENCIL_ATTACHMENT, GL32.GL_TEXTURE_2D, texture, 0);
}
else
{
GL43C.glFramebufferTexture2D(GL30C.GL_FRAMEBUFFER, GL30C.GL_DEPTH_ATTACHMENT, GL30C.GL_TEXTURE_2D, texture, 0);
GL32.glFramebufferTexture2D(GL32.GL_FRAMEBUFFER, GL32.GL_DEPTH_ATTACHMENT, GL32.GL_TEXTURE_2D, texture, 0);
}
this.hasDepthAttachment = true;
@@ -68,14 +67,14 @@ public class DhFramebuffer
int fb = id;
bind();
GL43C.glFramebufferTexture2D(GL30C.GL_FRAMEBUFFER, GL30C.GL_COLOR_ATTACHMENT0 + index, GL30C.GL_TEXTURE_2D, texture, 0);
GL32.glFramebufferTexture2D(GL32.GL_FRAMEBUFFER, GL32.GL_COLOR_ATTACHMENT0 + index, GL32.GL_TEXTURE_2D, texture, 0);
attachments.put(index, texture);
}
public void noDrawBuffers()
{
bind();
GL43C.glDrawBuffers(new int[]{GL30C.GL_NONE});
GL32.glDrawBuffers(new int[]{GL32.GL_NONE});
}
public void drawBuffers(int[] buffers)
@@ -94,17 +93,17 @@ public class DhFramebuffer
throw new IllegalArgumentException("Only " + maxColorAttachments + " color attachments are supported on this GPU, but an attempt was made to write to a color attachment with index " + buffer);
}
glBuffers[index++] = GL30C.GL_COLOR_ATTACHMENT0 + buffer;
glBuffers[index++] = GL32.GL_COLOR_ATTACHMENT0 + buffer;
}
bind();
GL43C.glDrawBuffers(new int[]{GL30C.GL_NONE});
GL32.glDrawBuffers(new int[]{GL32.GL_NONE});
}
public void readBuffer(int buffer)
{
bind();
GL43C.glReadBuffer(GL30C.GL_COLOR_ATTACHMENT0 + buffer);
GL32.glReadBuffer(GL32.GL_COLOR_ATTACHMENT0 + buffer);
}
public int getColorAttachment(int index) { return attachments.get(index); }
@@ -117,23 +116,23 @@ public class DhFramebuffer
{
throw new IllegalStateException("Framebuffer does not exist!");
}
GL43C.glBindFramebuffer(GL30C.GL_FRAMEBUFFER, id);
GL32.glBindFramebuffer(GL32.GL_FRAMEBUFFER, id);
}
public void bindAsReadBuffer() { GL43C.glBindFramebuffer(GL30C.GL_READ_FRAMEBUFFER, id); }
public void bindAsReadBuffer() { GL32.glBindFramebuffer(GL32.GL_READ_FRAMEBUFFER, id); }
public void bindAsDrawBuffer() { GL43C.glBindFramebuffer(GL30C.GL_DRAW_FRAMEBUFFER, id); }
public void bindAsDrawBuffer() { GL32.glBindFramebuffer(GL32.GL_DRAW_FRAMEBUFFER, id); }
public void destroyInternal()
{
GL43C.glDeleteFramebuffers(id);
GL32.glDeleteFramebuffers(id);
this.id = -1;
}
public int getStatus()
{
bind();
int status = GL43C.glCheckFramebufferStatus(GL30C.GL_FRAMEBUFFER);
int status = GL32.glCheckFramebufferStatus(GL32.GL_FRAMEBUFFER);
return status;
}
@@ -212,9 +212,10 @@ public class LodRenderer
}
}
public void resize(int width, int height) {
colorTexture.resize(width, height);
depthTexture.resize(width, height, EDhDepthBufferFormat.DEPTH32F);
public void resize(int width, int height)
{
this.colorTexture.resize(width, height);
this.depthTexture.resize(width, height, EDhDepthBufferFormat.DEPTH32F);
}
@@ -292,15 +293,16 @@ public class LodRenderer
}
}
if (MC_RENDER.getTargetFrameBufferViewportWidth() != cachedWidth || MC_RENDER.getTargetFrameBufferViewportHeight() != cachedHeight) {
if (MC_RENDER.getTargetFrameBufferViewportWidth() != this.cachedWidth || MC_RENDER.getTargetFrameBufferViewportHeight() != this.cachedHeight)
{
this.cachedWidth = MC_RENDER.getTargetFrameBufferViewportWidth();
this.cachedHeight = MC_RENDER.getTargetFrameBufferViewportHeight();
resize(cachedWidth, cachedHeight);
this.resize(this.cachedWidth, this.cachedHeight);
}
this.setActiveFramebufferId(framebuffer.getId());
this.setActiveDepthTextureId(depthTexture.getTextureId());
this.setActiveColorTextureId(colorTexture.getTexture());
this.setActiveColorTextureId(colorTexture.getTextureId());
// Bind LOD frame buffer
this.framebuffer.bind();
@@ -548,13 +550,13 @@ public class LodRenderer
.build();
this.depthTexture = new DHDepthTexture(MC_RENDER.getTargetFrameBufferViewportWidth(), MC_RENDER.getTargetFrameBufferViewportHeight(), EDhDepthBufferFormat.DEPTH32F);
this.framebuffer.addDepthAttachment(depthTexture.getTextureId(), EDhDepthBufferFormat.DEPTH32F);
this.framebuffer.addColorAttachment(0, colorTexture.getTexture());
this.framebuffer.addDepthAttachment(this.depthTexture.getTextureId(), EDhDepthBufferFormat.DEPTH32F);
this.framebuffer.addColorAttachment(0, this.colorTexture.getTextureId());
this.cachedWidth = MC_RENDER.getTargetFrameBufferViewportWidth();
this.cachedHeight = MC_RENDER.getTargetFrameBufferViewportHeight();
if(framebuffer.getStatus() != GL32.GL_FRAMEBUFFER_COMPLETE)
if(this.framebuffer.getStatus() != GL32.GL_FRAMEBUFFER_COMPLETE)
{
// This generally means something wasn't bound, IE missing either the color or depth texture
tickLogger.warn("FrameBuffer ["+this.framebuffer.getId()+"] isn't complete.");
@@ -76,7 +76,8 @@ public interface IMinecraftRenderWrapper extends IBindable
int getScreenHeight();
/** @return -1 if no valid framebuffer is available yet */
int getTargetFrameBuffer();
int getTargetFrameBuffer(); // Note: Iris is now hooking onto this for DH + Iris compat, try not to change (unless we wanna deal with some annoyances)
// Iris commit: https://github.com/IrisShaders/Iris/commit/a76a240527e93780bbcba57c09bef377419d47a7#diff-7b9ded0c79bbcdb130010373387756a28ee8d3640d522c0a5b7acd0abbfc20aeR16
int getDepthTextureId();
int getTargetFrameBufferViewportWidth();
int getTargetFrameBufferViewportHeight();