mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-11-18 03:25:17 +00:00
Compare commits
27
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
063b2242e8 | ||
|
|
577f905dc5 | ||
|
|
071d2d4a39 | ||
|
|
891715b113 | ||
|
|
30a35ef25e | ||
|
|
33453b3b8c | ||
|
|
62e699f6d0 | ||
|
|
f107d173b7 | ||
|
|
d0948b36f3 | ||
|
|
ae1211f280 | ||
|
|
3d76cb3073 | ||
|
|
45fb120223 | ||
|
|
d7a196eb5c | ||
|
|
4d53e2af9b | ||
|
|
cb6336a365 | ||
|
|
5095021e0e | ||
|
|
f88ecbf68d | ||
|
|
7da9b9eb1c | ||
|
|
02c394108f | ||
|
|
720aaca1b7 | ||
|
|
1e71b1c4d8 | ||
|
|
df4c423e93 | ||
|
|
78e0074e5a | ||
|
|
0350ea2cb6 | ||
|
|
bed724ba59 | ||
|
|
6fa973dbc8 | ||
|
|
c4ad460f34 |
No files matched your search
@@ -15,7 +15,7 @@
|
||||
|
||||
# Required Dependencies
|
||||
* [UniMixins](https://github.com/LegacyModdingMC/UniMixins/releases) >= 0.1.19
|
||||
* [GTNHLib](https://github.com/GTNewHorizons/GTNHLib/releases) >= 0.6.6
|
||||
* [GTNHLib](https://github.com/GTNewHorizons/GTNHLib/releases) >= 0.6.20
|
||||
* NOTE: Some mods are not required, but a specific version is required if present - see: `Permanent Incompatibilities` below.
|
||||
|
||||
# Known (temporary) Incompatibilities
|
||||
@@ -29,13 +29,14 @@
|
||||
* FalseTweaks - Not currently planned (Looking for volunteers) [Might work if you effectively disable most of the mod]
|
||||
* SmoothFont - Not currently planned (Looking for volunteers)
|
||||
* RPLE - Not currently planned (Looking for volunteers)
|
||||
* LiteLoader - Install [LiteloaderLoader](https://github.com/Midnight145/LiteloaderLoader)
|
||||
|
||||
# Permanent Incompatibilities
|
||||
* OptiFine [Disabled, won't fix]
|
||||
* FastCraft [Disabled, won't fix]
|
||||
* BetterFPS [Disabled, won't fix]
|
||||
* OptimizationsAndTweaks [Disabled, won't fix]
|
||||
* [Amazing Trophies 1.2.1 and below](https://github.com/GTNewHorizons/Amazing-Trophies/releases) - use 1.2.2+
|
||||
* [Amazing Trophies 1.2.1 and below](https://github.com/GTNewHorizons/Amazing-Trophies/releases) - Use 1.2.2+
|
||||
* [LWJGL3ify 1.5.4 and below](https://github.com/GTNewHorizons/lwjgl3ify/releases/) - Use the latest version available, 1.5.7+
|
||||
* [ArchaicFix 0.6.2 and below](https://www.curseforge.com/minecraft/mc-mods/archaicfix/files/all?page=1&pageSize=20) - Use 0.7.0 or above
|
||||
* [Hodgepodge 2.4.3 and below](https://github.com/GTNewHorizons/Hodgepodge/releases) - Use 0.4.5 or above
|
||||
@@ -64,7 +65,7 @@
|
||||
* Makamys for [Neodymium](https://github.com/makamys/Neodymium) - Various Tessellator -> Quad functionality taken under the LGPL 3
|
||||
* MCPatcherForge
|
||||
* Original [MCPatcher](https://bitbucket.org/prupe/mcpatcher/src/master/): Paul Rupe
|
||||
* [Forge version](https://bitbucket.org/prupe/mcpatcher/src/master/): Mist475 under LGPL 3.0 with default ctm textures for glass and bookshelves by DarkBum under CC-BY-SA
|
||||
* [Forge version](https://github.com/mist475/MCPatcherForge): Mist475 under LGPL 3.0 with default ctm textures for glass and bookshelves by DarkBum under CC-BY-SA
|
||||
* HUDCaching
|
||||
* Created by [Moulberry](https://github.com/Moulberry/MCHUDCaching), backported from [Patcher](https://github.com/Sk1erLLC/Patcher) mod by Alexdoru under the CC-BY-SA-NC 4.0 license
|
||||
* Angelica
|
||||
|
||||
+8
-8
@@ -49,7 +49,7 @@ configurations {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly("com.github.GTNewHorizons:Hodgepodge:2.6.27")
|
||||
compileOnly("com.github.GTNewHorizons:Hodgepodge:2.6.30")
|
||||
|
||||
compileOnly("com.gtnewhorizons.retrofuturabootstrap:RetroFuturaBootstrap:1.0.7") { transitive = false }
|
||||
|
||||
@@ -57,11 +57,11 @@ dependencies {
|
||||
annotationProcessor("org.projectlombok:lombok:1.18.34")
|
||||
|
||||
// Use modern models+textures to inject QuadProviders
|
||||
devOnlyNonPublishable('com.github.GTNewHorizons:TX-Loader:1.8.0:dev')
|
||||
devOnlyNonPublishable('com.github.GTNewHorizons:TX-Loader:1.8.2:dev')
|
||||
|
||||
// Iris Shaders
|
||||
compileOnly('org.jetbrains:annotations:26.0.2')
|
||||
api("com.github.GTNewHorizons:GTNHLib:0.6.11:dev")
|
||||
api("com.github.GTNewHorizons:GTNHLib:0.6.20:dev")
|
||||
shadowImplementation("org.anarres:jcpp:1.4.14") // Apache 2.0
|
||||
shadowImplementation("org.taumc:glsl-transformation-lib:0.2.0-4.g6b42bca") {
|
||||
exclude module: "antlr4" // we only want to shadow the runtime module
|
||||
@@ -75,16 +75,15 @@ dependencies {
|
||||
|
||||
// Notfine Deps
|
||||
compileOnly("thaumcraft:Thaumcraft:1.7.10-4.2.3.5:dev")
|
||||
devOnlyNonPublishable("com.github.GTNewHorizons:Baubles:1.0.4:dev")
|
||||
devOnlyNonPublishable("com.github.GTNewHorizons:Baubles-Expanded:2.1.7-GTNH:dev")
|
||||
compileOnly("com.github.GTNewHorizons:twilightforest:2.7.5:dev") { transitive = false }
|
||||
compileOnly(rfg.deobf('curse.maven:witchery-69673:2234410'))
|
||||
compileOnly("com.github.GTNewHorizons:TinkersConstruct:1.13.9-GTNH:dev") { transitive = false }
|
||||
compileOnly("com.github.GTNewHorizons:TinkersConstruct:1.13.10-GTNH:dev") { transitive = false }
|
||||
compileOnly("com.github.GTNewHorizons:Natura:2.8.2:dev")
|
||||
|
||||
compileOnly("com.github.GTNewHorizons:ThaumicHorizons:1.7.1:dev")
|
||||
|
||||
compileOnly("com.github.GTNewHorizons:Battlegear2:1.4.2:dev") { transitive = false }
|
||||
compileOnly('com.github.GTNewHorizons:Backhand:1.6.11') { transitive = false }
|
||||
|
||||
compileOnly("com.falsepattern:chunkapi-mc1.7.10:0.5.1:api") { transitive = false }
|
||||
compileOnly("com.falsepattern:endlessids-mc1.7.10:1.5-beta0003:dev") { transitive = false }
|
||||
@@ -99,8 +98,7 @@ dependencies {
|
||||
|
||||
compileOnly(rfg.deobf("curse.maven:campfirebackport-387444:4611675"))
|
||||
compileOnly(rfg.deobf("curse.maven:xaeros-minimap-263420:5060684"))
|
||||
|
||||
compileOnly("com.github.GTNewHorizons:HoloInventory:2.5.0-GTNH:dev")
|
||||
compileOnly(rfg.deobf("curse.maven:security-craft-64760:2818228"))
|
||||
|
||||
runtimeOnlyNonPublishable(rfg.deobf("CoreTweaks:CoreTweaks:0.3.3.2"))
|
||||
|
||||
@@ -115,4 +113,6 @@ dependencies {
|
||||
testImplementation('org.junit.jupiter:junit-jupiter')
|
||||
testImplementation("org.mockito:mockito-core:3.+")
|
||||
testImplementation("org.lwjgl.lwjgl:lwjgl:2.9.4-nightly-20150209")
|
||||
|
||||
compileOnly("mega:fluidlogged-mc1.7.10:0.1.2")
|
||||
}
|
||||
Vendored
BIN
Binary file not shown.
@@ -205,7 +205,7 @@ fi
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command:
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
|
||||
@@ -8,6 +8,13 @@ repositories {
|
||||
includeGroup 'com.falsepattern'
|
||||
}
|
||||
}
|
||||
maven {
|
||||
name = 'mega'
|
||||
url = 'https://mvn.falsepattern.com/gtmega_releases/'
|
||||
content {
|
||||
includeGroup 'mega'
|
||||
}
|
||||
}
|
||||
exclusiveContent {
|
||||
forRepository {
|
||||
ivy {
|
||||
|
||||
+1
-1
@@ -16,5 +16,5 @@ pluginManagement {
|
||||
}
|
||||
|
||||
plugins {
|
||||
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.36'
|
||||
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.37'
|
||||
}
|
||||
@@ -15,8 +15,13 @@ import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
modid = "angelica",
|
||||
name = "Angelica",
|
||||
version = Tags.VERSION,
|
||||
dependencies = " before:lwjgl3ify@[1.5.3,);" + " after:hodgepodge@[2.4.4,);" + " after:CodeChickenCore@[1.2.0,);"
|
||||
+ " after:archaicfix@[0.7.0,);" + " required-after:gtnhlib@[0.6.6,);",
|
||||
dependencies = """
|
||||
required-after:gtnhlib@[0.6.6,);\
|
||||
before:lwjgl3ify@[1.5.3,);\
|
||||
after:hodgepodge@[2.4.4,);\
|
||||
after:CodeChickenCore@[1.2.0,);\
|
||||
after:archaicfix@[0.7.0,);\
|
||||
""",
|
||||
acceptedMinecraftVersions = "[1.7.10]",
|
||||
acceptableRemoteVersions = "*",
|
||||
guiFactory = "com.gtnewhorizons.angelica.config.AngelicaGuiConfigFactory")
|
||||
|
||||
@@ -7,8 +7,9 @@ import com.gtnewhorizons.angelica.mixins.interfaces.FontRendererAccessor;
|
||||
import it.unimi.dsi.fastutil.chars.Char2ShortOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import jss.util.RandomXoshiro256StarStar;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
@@ -150,7 +151,7 @@ public class BatchingFontRenderer {
|
||||
return idx;
|
||||
}
|
||||
|
||||
private void pushDrawCmd(int startIdx, int idxCount, ResourceLocation texture) {
|
||||
private void pushDrawCmd(int startIdx, int idxCount, ResourceLocation texture, boolean isUnicode) {
|
||||
if (!batchCommands.isEmpty()) {
|
||||
final FontDrawCmd lastCmd = batchCommands.get(batchCommands.size() - 1);
|
||||
final int prevEndVtx = lastCmd.startVtx + lastCmd.idxCount;
|
||||
@@ -166,7 +167,7 @@ public class BatchingFontRenderer {
|
||||
}
|
||||
}
|
||||
final FontDrawCmd cmd = batchCommandPool.pop();
|
||||
cmd.reset(startIdx, idxCount, texture);
|
||||
cmd.reset(startIdx, idxCount, texture, isUnicode);
|
||||
batchCommands.add(cmd);
|
||||
}
|
||||
|
||||
@@ -174,12 +175,14 @@ public class BatchingFontRenderer {
|
||||
|
||||
public int startVtx;
|
||||
public int idxCount;
|
||||
public boolean isUnicode;
|
||||
public ResourceLocation texture;
|
||||
|
||||
public void reset(int startVtx, int vtxCount, ResourceLocation texture) {
|
||||
public void reset(int startVtx, int vtxCount, ResourceLocation texture, boolean isUnicode) {
|
||||
this.startVtx = startVtx;
|
||||
this.idxCount = vtxCount;
|
||||
this.texture = texture;
|
||||
this.isUnicode = isUnicode;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -280,7 +283,21 @@ public class BatchingFontRenderer {
|
||||
}
|
||||
batchIndices.limit(cmd.startVtx + cmd.idxCount);
|
||||
batchIndices.position(cmd.startVtx);
|
||||
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
int scaleFactor = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight).getScaleFactor();
|
||||
boolean shouldApplyFilter = cmd.isUnicode && scaleFactor % 2 != 0;
|
||||
|
||||
if (shouldApplyFilter) {
|
||||
GLStateManager.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
|
||||
GLStateManager.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
|
||||
}
|
||||
GL11.glDrawElements(GL11.GL_TRIANGLES, batchIndices);
|
||||
|
||||
if (shouldApplyFilter) {
|
||||
GLStateManager.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
|
||||
GLStateManager.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
|
||||
}
|
||||
}
|
||||
|
||||
GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
|
||||
@@ -367,7 +384,7 @@ public class BatchingFontRenderer {
|
||||
if (curUnderline && underlineStartX != underlineEndX) {
|
||||
final int ulIdx = idxWriterIndex;
|
||||
pushUntexRect(underlineStartX, underlineY, underlineEndX - underlineStartX, 1.0f, curColor);
|
||||
pushDrawCmd(ulIdx, 6, null);
|
||||
pushDrawCmd(ulIdx, 6, null, false);
|
||||
underlineStartX = underlineEndX;
|
||||
}
|
||||
if (curStrikethrough && strikethroughStartX != strikethroughEndX) {
|
||||
@@ -378,7 +395,7 @@ public class BatchingFontRenderer {
|
||||
strikethroughEndX - strikethroughStartX,
|
||||
1.0f,
|
||||
curColor);
|
||||
pushDrawCmd(ulIdx, 6, null);
|
||||
pushDrawCmd(ulIdx, 6, null, false);
|
||||
strikethroughStartX = strikethroughEndX;
|
||||
}
|
||||
|
||||
@@ -462,13 +479,13 @@ public class BatchingFontRenderer {
|
||||
final int endColumn = this.glyphWidth[chr] & 15;
|
||||
final float startColumnF = (float) startColumn;
|
||||
final float endColumnF = (float) (endColumn + 1);
|
||||
uStart = ((float) (chr % 16 * 16) + startColumnF) / 256.0f;
|
||||
vStart = ((float) ((chr & 255) / 16 * 16)) / 256.0f;
|
||||
uStart = ((float) (chr % 16 * 16) + startColumnF + 0.21f) / 256.0f;
|
||||
vStart = ((float) ((chr & 255) / 16 * 16) + 0.21f) / 256.0f;
|
||||
final float chrWidth = endColumnF - startColumnF - 0.02F;
|
||||
glyphW = chrWidth / 2.0f + 1.0f;
|
||||
xAdvance = (endColumnF - startColumnF) / 2.0F + 1.0F;
|
||||
uSz = chrWidth / 256.0f;
|
||||
vSz = 15.98f / 256.0f;
|
||||
uSz = (chrWidth - 0.42f) / 256.0f;
|
||||
vSz = (16.0f - 0.42f) / 256.0f;
|
||||
|
||||
} else {
|
||||
// Draw "ASCII" char
|
||||
@@ -556,7 +573,7 @@ public class BatchingFontRenderer {
|
||||
vtxCount += 4;
|
||||
}
|
||||
|
||||
pushDrawCmd(idxId, vtxCount / 2 * 3, texture);
|
||||
pushDrawCmd(idxId, vtxCount / 2 * 3, texture, chr > 255);
|
||||
curX += xAdvance + (curBold ? shadowOffset : 0.0f);
|
||||
underlineEndX = curX;
|
||||
strikethroughEndX = curX;
|
||||
@@ -565,7 +582,7 @@ public class BatchingFontRenderer {
|
||||
if (curUnderline && underlineStartX != underlineEndX) {
|
||||
final int ulIdx = idxWriterIndex;
|
||||
pushUntexRect(underlineStartX, underlineY, underlineEndX - underlineStartX, 1.0f, curColor);
|
||||
pushDrawCmd(ulIdx, 6, null);
|
||||
pushDrawCmd(ulIdx, 6, null, false);
|
||||
}
|
||||
if (curStrikethrough && strikethroughStartX != strikethroughEndX) {
|
||||
final int ulIdx = idxWriterIndex;
|
||||
@@ -575,7 +592,7 @@ public class BatchingFontRenderer {
|
||||
strikethroughEndX - strikethroughStartX,
|
||||
1.0f,
|
||||
curColor);
|
||||
pushDrawCmd(ulIdx, 6, null);
|
||||
pushDrawCmd(ulIdx, 6, null, false);
|
||||
}
|
||||
|
||||
} finally {
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
package com.gtnewhorizons.angelica.compat;
|
||||
|
||||
import com.gtnewhorizons.angelica.compat.backhand.BackhandReflectionCompat;
|
||||
import com.gtnewhorizons.angelica.helpers.LoadControllerHelper;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.versioning.DefaultArtifactVersion;
|
||||
import mods.battlegear2.Battlegear;
|
||||
import net.dries007.holoInventory.HoloInventory;
|
||||
import xonin.backhand.Backhand;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class ModStatus {
|
||||
public static final Logger LOGGER = LogManager.getLogger("ModCompat");
|
||||
|
||||
public static BackhandReflectionCompat backhandCompat;
|
||||
/**
|
||||
* Mixin Version
|
||||
*/
|
||||
@@ -16,7 +20,6 @@ public class ModStatus {
|
||||
* ASM Version
|
||||
*/
|
||||
public static boolean isOldNEIDLoaded;
|
||||
|
||||
public static boolean isBetterCrashesLoaded;
|
||||
public static boolean isNEIDMetadataExtended;
|
||||
public static boolean isLotrLoaded;
|
||||
@@ -29,8 +32,14 @@ public class ModStatus {
|
||||
public static boolean isThaumcraftLoaded;
|
||||
public static boolean isThaumicHorizonsLoaded;
|
||||
public static boolean isBaublesLoaded;
|
||||
public static boolean isFluidLoggedLoaded;
|
||||
|
||||
public static void preInit(){
|
||||
isBackhandLoaded = Loader.isModLoaded("backhand");
|
||||
if(isBackhandLoaded) {
|
||||
isBackhandLoaded = BackhandReflectionCompat.isBackhandLoaded();
|
||||
}
|
||||
|
||||
isBetterCrashesLoaded = Loader.isModLoaded("bettercrashes");
|
||||
isNEIDLoaded = Loader.isModLoaded("neid");
|
||||
isOldNEIDLoaded = Loader.isModLoaded("notenoughIDs");
|
||||
@@ -40,17 +49,12 @@ public class ModStatus {
|
||||
isXaerosMinimapLoaded = Loader.isModLoaded("XaeroMinimap");
|
||||
isHoloInventoryLoaded = Loader.isModLoaded("holoinventory");
|
||||
isBattlegearLoaded = Loader.isModLoaded("battlegear2");
|
||||
isBackhandLoaded = Loader.isModLoaded("backhand");
|
||||
isThaumcraftLoaded = Loader.isModLoaded("Thaumcraft");
|
||||
isThaumicHorizonsLoaded = Loader.isModLoaded("ThaumicHorizons");
|
||||
isBaublesLoaded = Loader.isModLoaded("Baubles");
|
||||
isFluidLoggedLoaded = Loader.isModLoaded("fluidlogged");
|
||||
|
||||
if (isHoloInventoryLoaded){
|
||||
isHoloInventoryLoaded = new DefaultArtifactVersion("2.4.4-GTNH")
|
||||
.compareTo(
|
||||
LoadControllerHelper.getOwningMod(HoloInventory.class).getProcessedVersion()
|
||||
) <= 0;
|
||||
}
|
||||
isHoloInventoryLoaded = Loader.isModLoaded("holoinventory");
|
||||
|
||||
// remove compat with original release of BG2
|
||||
if (isBattlegearLoaded){
|
||||
@@ -60,17 +64,9 @@ public class ModStatus {
|
||||
) <= 0;
|
||||
}
|
||||
|
||||
if (isBackhandLoaded){
|
||||
isBackhandLoaded = new DefaultArtifactVersion("1.6.9")
|
||||
.compareTo(
|
||||
LoadControllerHelper.getOwningMod(Backhand.class).getProcessedVersion()
|
||||
) <= 0;
|
||||
}
|
||||
|
||||
|
||||
isNEIDMetadataExtended = false;
|
||||
if (isNEIDLoaded) {
|
||||
int majorVersion = Integer.parseInt(Loader.instance().getIndexedModList().get("neid").getVersion().split("\\.")[0]);
|
||||
final int majorVersion = Integer.parseInt(Loader.instance().getIndexedModList().get("neid").getVersion().split("\\.")[0]);
|
||||
if (majorVersion >= 2) {
|
||||
isNEIDMetadataExtended = true;
|
||||
}
|
||||
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
package com.gtnewhorizons.angelica.compat.backhand;
|
||||
|
||||
import com.gtnewhorizons.angelica.helpers.LoadControllerHelper;
|
||||
import cpw.mods.fml.common.versioning.DefaultArtifactVersion;
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.MethodType;
|
||||
|
||||
import static com.gtnewhorizons.angelica.compat.ModStatus.LOGGER;
|
||||
|
||||
public class BackhandReflectionCompat {
|
||||
private static final String BACKHAND_CLASS = "xonin.backhand.Backhand";
|
||||
private static final String ITEM_RENDERER_HOOKS_CLASS = "xonin.backhand.client.hooks.ItemRendererHooks";
|
||||
private static final String BACKHAND_UTILS_CLASS = "xonin.backhand.api.core.BackhandUtils";
|
||||
|
||||
private static boolean isLoaded;
|
||||
private static final MethodHandle renderOffhandReturn;
|
||||
private static final MethodHandle getOffhandItem;
|
||||
|
||||
static {
|
||||
MethodHandle renderOffhandReturnTemp = null;
|
||||
MethodHandle getOffhandItemTemp = null;
|
||||
|
||||
try {
|
||||
final Class<?> backhandClass = ReflectionHelper.getClass(BackhandReflectionCompat.class.getClassLoader(), BACKHAND_CLASS);
|
||||
final boolean versionCheck = new DefaultArtifactVersion("1.6.9").compareTo(LoadControllerHelper.getOwningMod(backhandClass).getProcessedVersion()) <= 0;
|
||||
|
||||
if (versionCheck) {
|
||||
final MethodHandles.Lookup lookup = MethodHandles.lookup();
|
||||
final Class<?> itemRendererHooksClass = ReflectionHelper.getClass(BackhandReflectionCompat.class.getClassLoader(), ITEM_RENDERER_HOOKS_CLASS);
|
||||
final Class<?> backhandUtilsClass = ReflectionHelper.getClass(BackhandReflectionCompat.class.getClassLoader(), BACKHAND_UTILS_CLASS);
|
||||
|
||||
renderOffhandReturnTemp = lookup.findStatic(itemRendererHooksClass, "renderOffhandReturn", MethodType.methodType(void.class, float.class));
|
||||
getOffhandItemTemp = lookup.findStatic(backhandUtilsClass, "getOffhandItem", MethodType.methodType(ItemStack.class, EntityPlayer.class));
|
||||
isLoaded = true;
|
||||
LOGGER.info("Backhand compat loaded");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Failed to load Backhand compat", e);
|
||||
isLoaded = false;
|
||||
}
|
||||
|
||||
renderOffhandReturn = renderOffhandReturnTemp;
|
||||
getOffhandItem = getOffhandItemTemp;
|
||||
}
|
||||
|
||||
public static boolean isBackhandLoaded() {
|
||||
return isLoaded;
|
||||
}
|
||||
|
||||
public static void renderOffhand(float partialTicks) {
|
||||
if (isLoaded && renderOffhandReturn != null) {
|
||||
try {
|
||||
renderOffhandReturn.invokeExact(partialTicks);
|
||||
} catch (Throwable e) {
|
||||
LOGGER.error("Failed to invoke Backhand renderOffhandReturn", e);
|
||||
isLoaded = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack getOffhandItem(EntityPlayer player) {
|
||||
if (isLoaded && getOffhandItem != null) {
|
||||
try {
|
||||
return (ItemStack) getOffhandItem.invokeExact(player);
|
||||
} catch (Throwable e) {
|
||||
LOGGER.error("Failed to invoke Backhand getOffhandItem", e);
|
||||
isLoaded = false;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.gtnewhorizons.angelica.compat.battlegear2;
|
||||
|
||||
import mods.battlegear2.api.core.IInventoryPlayerBattle;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* This class exists to isolate classes that exist in Battlegear 2 but not
|
||||
* in Battlegear 2 for Backhand in order to avoid class loading exceptions.
|
||||
*/
|
||||
public class Battlegear2Compat {
|
||||
public static ItemStack getBattlegear2Offhand(EntityPlayer player) {
|
||||
return ((IInventoryPlayerBattle) player.inventory).battlegear2$getCurrentOffhandWeapon();
|
||||
}
|
||||
}
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
package com.gtnewhorizons.angelica.compat.holoinventory;
|
||||
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.MethodType;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static com.gtnewhorizons.angelica.compat.ModStatus.LOGGER;
|
||||
|
||||
public class HoloInventoryReflectionCompat {
|
||||
private static final String RENDERER_CLASS = "net.dries007.holoInventory.client.Renderer";
|
||||
|
||||
private static boolean isLoaded;
|
||||
private static final MethodHandle renderEventPostMethod;
|
||||
private static final MethodHandle renderEventMethod;
|
||||
private static final MethodHandle angelicaOverrideSetter;
|
||||
|
||||
static {
|
||||
MethodHandle renderEventPostMethodTemp = null;
|
||||
MethodHandle renderEventMethodTemp = null;
|
||||
MethodHandle angelicaOverrideSetterTemp = null;
|
||||
final Object rendererInstance;
|
||||
final Class<?> rendererClass;
|
||||
|
||||
try {
|
||||
rendererClass = Class.forName(RENDERER_CLASS);
|
||||
|
||||
// Get and cache the Renderer.INSTANCE
|
||||
final Field instanceField = rendererClass.getDeclaredField("INSTANCE");
|
||||
instanceField.setAccessible(true);
|
||||
rendererInstance = instanceField.get(null);
|
||||
|
||||
final MethodHandles.Lookup lookup = MethodHandles.lookup();
|
||||
try {
|
||||
renderEventPostMethodTemp = lookup.findVirtual(rendererClass, "renderEvent", MethodType.methodType(void.class, RenderGameOverlayEvent.Post.class));
|
||||
} catch (NoSuchMethodException e) {
|
||||
// Fallback for 2.5.0-GTNH and earlier
|
||||
renderEventMethodTemp = lookup.findVirtual(rendererClass, "renderEvent", MethodType.methodType(void.class, RenderGameOverlayEvent.class));
|
||||
}
|
||||
|
||||
final Field angelicaOverrideField = rendererClass.getDeclaredField("angelicaOverride");
|
||||
angelicaOverrideField.setAccessible(true);
|
||||
angelicaOverrideSetterTemp = lookup.unreflectSetter(angelicaOverrideField);
|
||||
|
||||
// Bind the method handles to the instance
|
||||
if (rendererInstance != null) {
|
||||
if (renderEventPostMethodTemp != null) {
|
||||
renderEventPostMethodTemp = renderEventPostMethodTemp.bindTo(rendererInstance);
|
||||
}
|
||||
if (renderEventMethodTemp != null) {
|
||||
renderEventMethodTemp = renderEventMethodTemp.bindTo(rendererInstance);
|
||||
}
|
||||
angelicaOverrideSetterTemp = angelicaOverrideSetterTemp.bindTo(rendererInstance);
|
||||
}
|
||||
|
||||
isLoaded = true;
|
||||
LOGGER.info("Successfully initialized HoloInventory compatibility layer");
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn("Failed to initialize HoloInventory compatibility layer", e);
|
||||
isLoaded = false;
|
||||
}
|
||||
|
||||
renderEventPostMethod = renderEventPostMethodTemp;
|
||||
renderEventMethod = renderEventMethodTemp;
|
||||
angelicaOverrideSetter = angelicaOverrideSetterTemp;
|
||||
}
|
||||
|
||||
public static void renderEvent(RenderGameOverlayEvent event) {
|
||||
if (!isLoaded) return;
|
||||
try {
|
||||
if (event instanceof RenderGameOverlayEvent.Post && renderEventPostMethod != null) {
|
||||
renderEventPostMethod.invokeExact((RenderGameOverlayEvent.Post) event);
|
||||
} else {
|
||||
renderEventMethod.invokeExact(event);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
LOGGER.error("Failed to invoke HoloInventory renderEvent", e);
|
||||
isLoaded = false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void setAngelicaOverride(boolean value) {
|
||||
if (!isLoaded) return;
|
||||
try {
|
||||
angelicaOverrideSetter.invokeExact(value);
|
||||
} catch (Throwable e) {
|
||||
LOGGER.error("Failed to set HoloInventory angelicaOverride", e);
|
||||
isLoaded = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ package com.gtnewhorizons.angelica.compat.mojang;
|
||||
import com.gtnewhorizons.angelica.compat.ModStatus;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import xonin.backhand.api.core.BackhandUtils;
|
||||
|
||||
public enum InteractionHand {
|
||||
MAIN_HAND,
|
||||
@@ -15,7 +14,7 @@ public enum InteractionHand {
|
||||
|
||||
public ItemStack getItemInHand(EntityPlayer player){
|
||||
if (ModStatus.isBackhandLoaded && this == InteractionHand.OFF_HAND){ // off hand (requires backhand)
|
||||
return BackhandUtils.getOffhandItem(player);
|
||||
return ModStatus.backhandCompat.getOffhandItem(player);
|
||||
}
|
||||
else { // main hand
|
||||
return player.getHeldItem();
|
||||
|
||||
@@ -38,7 +38,7 @@ public class AngelicaConfig {
|
||||
public static boolean enableIris;
|
||||
|
||||
@Config.Comment("Enable MCPatcherForge features, still in Alpha. Individual features are toggled in mcpatcher.json")
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean enableMCPatcherForgeFeatures;
|
||||
|
||||
|
||||
@@ -39,4 +39,9 @@ public class CompatConfig {
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean fixImmersiveEngineering;
|
||||
|
||||
@Config.Comment("Apply fixes to Security Craft")
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean fixSecurityCraft;
|
||||
}
|
||||
@@ -6,12 +6,12 @@ import com.gtnewhorizon.gtnhlib.blockpos.IBlockPos;
|
||||
import com.gtnewhorizon.gtnhlib.util.CoordinatePacker;
|
||||
import com.gtnewhorizons.angelica.api.IDynamicLightProducer;
|
||||
import com.gtnewhorizons.angelica.compat.ModStatus;
|
||||
import com.gtnewhorizons.angelica.compat.battlegear2.Battlegear2Compat;
|
||||
import com.gtnewhorizons.angelica.config.AngelicaConfig;
|
||||
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
||||
import me.jellysquid.mods.sodium.client.render.SodiumWorldRenderer;
|
||||
import mods.battlegear2.api.core.IBattlePlayer;
|
||||
import mods.battlegear2.api.core.IInventoryPlayerBattle;
|
||||
import net.irisshaders.iris.api.v0.IrisApi;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
@@ -27,7 +27,6 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import xonin.backhand.api.core.BackhandUtils;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
@@ -377,13 +376,13 @@ public class DynamicLights {
|
||||
player instanceof IBattlePlayer battlePlayer &&
|
||||
battlePlayer.battlegear2$isBattlemode()
|
||||
) {
|
||||
ItemStack offhand = ((IInventoryPlayerBattle) player.inventory).battlegear2$getCurrentOffhandWeapon();
|
||||
ItemStack offhand = Battlegear2Compat.getBattlegear2Offhand(player);
|
||||
if (offhand != null) {
|
||||
luminance = Math.max(luminance, getLuminanceFromItemStack(offhand, inWater));
|
||||
}
|
||||
}
|
||||
else if (ModStatus.isBackhandLoaded && living instanceof EntityPlayer player){
|
||||
ItemStack offhand = BackhandUtils.getOffhandItem(player);
|
||||
ItemStack offhand = ModStatus.backhandCompat.getOffhandItem(player);
|
||||
if (offhand != null) {
|
||||
luminance = Math.max(luminance, getLuminanceFromItemStack(offhand, inWater));
|
||||
}
|
||||
|
||||
@@ -863,6 +863,16 @@ public class GLStateManager {
|
||||
GL11.glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels);
|
||||
}
|
||||
|
||||
public static void glTexImage2D(int target, int level, int internalformat, int width, int height, int border, int format, int type, FloatBuffer pixels) {
|
||||
TextureInfoCache.INSTANCE.onTexImage2D(target, level, internalformat, width, height, border, format, type, pixels);
|
||||
GL11.glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels);
|
||||
}
|
||||
|
||||
public static void glTexImage2D(int target, int level, int internalformat, int width, int height, int border, int format, int type, DoubleBuffer pixels) {
|
||||
TextureInfoCache.INSTANCE.onTexImage2D(target, level, internalformat, width, height, border, format, type, pixels);
|
||||
GL11.glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels);
|
||||
}
|
||||
|
||||
public static void glTexImage2D(int target, int level, int internalformat, int width, int height, int border, int format, int type, ByteBuffer pixels) {
|
||||
TextureInfoCache.INSTANCE.onTexImage2D(target, level, internalformat, width, height, border, format, type, pixels != null ? pixels.asIntBuffer() : (IntBuffer) null);
|
||||
GL11.glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels);
|
||||
|
||||
@@ -97,6 +97,8 @@ public class RenderSystem {
|
||||
GL20.glUniform3f(location, v0, v1, v2);
|
||||
}
|
||||
|
||||
public static void uniform3i(int location, int v0, int v1, int v2) { GL20.glUniform3i(location, v0, v1, v2); }
|
||||
|
||||
public static void uniform4f(int location, float v0, float v1, float v2, float v3) {
|
||||
GL20.glUniform4f(location, v0, v1, v2, v3);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.Buffer;
|
||||
|
||||
public class TextureInfoCache {
|
||||
/**
|
||||
@@ -25,7 +25,7 @@ public class TextureInfoCache {
|
||||
return cache.computeIfAbsent(id, TextureInfo::new);
|
||||
}
|
||||
|
||||
public void onTexImage2D(int target, int level, int internalformat, int width, int height, int border, int format, int type, @Nullable IntBuffer pixels) {
|
||||
public void onTexImage2D(int target, int level, int internalformat, int width, int height, int border, int format, int type, @Nullable Buffer pixels) {
|
||||
if (target == GL11.GL_TEXTURE_2D && level == 0) {
|
||||
final TextureInfo info = getInfo(GLStateManager.getBoundTexture());
|
||||
if(info == null) return;
|
||||
|
||||
@@ -2,13 +2,13 @@ package com.gtnewhorizons.angelica.hudcaching;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.TessellatorManager;
|
||||
import com.gtnewhorizons.angelica.compat.ModStatus;
|
||||
import com.gtnewhorizons.angelica.compat.holoinventory.HoloInventoryReflectionCompat;
|
||||
import com.gtnewhorizons.angelica.config.AngelicaConfig;
|
||||
import com.gtnewhorizons.angelica.mixins.interfaces.GuiIngameAccessor;
|
||||
import com.gtnewhorizons.angelica.mixins.interfaces.GuiIngameForgeAccessor;
|
||||
import com.gtnewhorizons.angelica.mixins.interfaces.RenderGameOverlayEventAccessor;
|
||||
import com.kentington.thaumichorizons.common.ThaumicHorizons;
|
||||
import cpw.mods.fml.common.eventhandler.EventPriority;
|
||||
import net.dries007.holoInventory.client.Renderer;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
@@ -60,7 +60,6 @@ public class HUDCaching {
|
||||
|
||||
public static final HUDCaching INSTANCE = new HUDCaching();
|
||||
|
||||
|
||||
private HUDCaching() {}
|
||||
|
||||
// highest so it runs before the GLSM load event
|
||||
@@ -99,7 +98,7 @@ public class HUDCaching {
|
||||
renderingCacheOverride = false;
|
||||
mc.getFramebuffer().bindFramebuffer(false);
|
||||
} else {
|
||||
renderer.setupOverlayRendering();
|
||||
renderer.setupOverlayRendering();
|
||||
}
|
||||
|
||||
ScaledResolution resolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||
@@ -112,52 +111,50 @@ public class HUDCaching {
|
||||
|
||||
// render bits that were captured when rendering into cache
|
||||
GuiIngameAccessor gui = (GuiIngameAccessor) ingame;
|
||||
if (renderVignetteCaptured)
|
||||
{
|
||||
if (renderVignetteCaptured) {
|
||||
gui.callRenderVignette(mc.thePlayer.getBrightness(partialTicks), width, height);
|
||||
} else {
|
||||
GLStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
|
||||
GLStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
|
||||
}
|
||||
|
||||
if (ingame instanceof GuiIngameForge) {
|
||||
GuiIngameForgeAccessor guiForge = ((GuiIngameForgeAccessor) ingame);
|
||||
if (renderHelmetCaptured) {
|
||||
guiForge.callRenderHelmet(resolution, partialTicks, hasScreen, mouseX, mouseY);
|
||||
GuiIngameForgeAccessor guiForge = ((GuiIngameForgeAccessor) ingame);
|
||||
if (renderHelmetCaptured) {
|
||||
guiForge.callRenderHelmet(resolution, partialTicks, hasScreen, mouseX, mouseY);
|
||||
if (ModStatus.isHoloInventoryLoaded) {
|
||||
Renderer.INSTANCE.angelicaOverride = false;
|
||||
HoloInventoryReflectionCompat.setAngelicaOverride(false);
|
||||
// only settings the partial ticks as mouseX and mouseY are not used in renderEvent
|
||||
((RenderGameOverlayEventAccessor) fakePostEvent).setPartialTicks(partialTicks);
|
||||
Renderer.INSTANCE.renderEvent(fakePostEvent);
|
||||
HoloInventoryReflectionCompat.renderEvent(fakePostEvent);
|
||||
}
|
||||
}
|
||||
if (renderPortalCapturedTicks > 0) {
|
||||
guiForge.callRenderPortal(width, height, partialTicks);
|
||||
}
|
||||
if (renderCrosshairsCaptured) {
|
||||
if (ModStatus.isXaerosMinimapLoaded){
|
||||
}
|
||||
if (renderPortalCapturedTicks > 0) {
|
||||
guiForge.callRenderPortal(width, height, partialTicks);
|
||||
}
|
||||
if (renderCrosshairsCaptured) {
|
||||
if (ModStatus.isXaerosMinimapLoaded) {
|
||||
// this fixes the crosshair going invisible when no lines are being drawn under the minimap
|
||||
GLStateManager.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
}
|
||||
guiForge.callRenderCrosshairs(width, height);
|
||||
}
|
||||
if (ModStatus.isThaumcraftLoaded || ModStatus.isThaumicHorizonsLoaded){
|
||||
guiForge.callRenderCrosshairs(width, height);
|
||||
}
|
||||
if (ModStatus.isThaumcraftLoaded || ModStatus.isThaumicHorizonsLoaded) {
|
||||
((RenderGameOverlayEventAccessor) fakeTextEvent).setPartialTicks(partialTicks);
|
||||
((RenderGameOverlayEventAccessor) fakeTextEvent).setResolution(resolution);
|
||||
((RenderGameOverlayEventAccessor) fakeTextEvent).setMouseX(mouseX);
|
||||
((RenderGameOverlayEventAccessor) fakeTextEvent).setMouseY(mouseY);
|
||||
if (ModStatus.isThaumcraftLoaded){
|
||||
if (ModStatus.isThaumcraftLoaded) {
|
||||
Thaumcraft.instance.renderEventHandler.renderOverlay(fakeTextEvent);
|
||||
}
|
||||
if (ModStatus.isThaumicHorizonsLoaded){
|
||||
if (ModStatus.isThaumicHorizonsLoaded) {
|
||||
ThaumicHorizons.instance.renderEventHandler.renderOverlay(fakeTextEvent);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (renderHelmetCaptured)
|
||||
{
|
||||
if (renderHelmetCaptured) {
|
||||
gui.callRenderPumpkinBlur(width, height);
|
||||
}
|
||||
if (renderPortalCapturedTicks > 0)
|
||||
{
|
||||
if (renderPortalCapturedTicks > 0) {
|
||||
gui.callRenderPortal(renderPortalCapturedTicks, width, height);
|
||||
}
|
||||
}
|
||||
@@ -180,19 +177,19 @@ public class HUDCaching {
|
||||
* the state before we start rendering
|
||||
*/
|
||||
public static void fixGLStateBeforeRenderingCache() {
|
||||
GLStateManager.glDepthMask(true);
|
||||
GLStateManager.enableDepthTest();
|
||||
GLStateManager.enableAlphaTest();
|
||||
GLStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO);
|
||||
GLStateManager.disableBlend();
|
||||
GLStateManager.glDepthMask(true);
|
||||
GLStateManager.enableDepthTest();
|
||||
GLStateManager.enableAlphaTest();
|
||||
GLStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO);
|
||||
GLStateManager.disableBlend();
|
||||
}
|
||||
|
||||
private static void resetFramebuffer(int width, int height) {
|
||||
if (framebuffer.framebufferWidth != width || framebuffer.framebufferHeight != height) {
|
||||
framebuffer.createBindFramebuffer(width, height);
|
||||
framebuffer.createBindFramebuffer(width, height);
|
||||
framebuffer.setFramebufferFilter(GL11.GL_NEAREST);
|
||||
} else {
|
||||
framebuffer.framebufferClear();
|
||||
framebuffer.framebufferClear();
|
||||
}
|
||||
// copy depth buffer from MC
|
||||
OpenGlHelper.func_153171_g(GL30.GL_READ_FRAMEBUFFER, mc.getFramebuffer().framebufferObject);
|
||||
@@ -214,10 +211,9 @@ public class HUDCaching {
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
|
||||
}
|
||||
|
||||
// moved to here due to the method being called from a mixin
|
||||
public static void disableHoloInventory() {
|
||||
if (ModStatus.isHoloInventoryLoaded) {
|
||||
Renderer.INSTANCE.angelicaOverride = true;
|
||||
HoloInventoryReflectionCompat.setAngelicaOverride(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ public enum Mixins {
|
||||
// Not compatible with the lwjgl debug callbacks, so disable if that's enabled
|
||||
ARCHAIC_SPLASH(new Builder("ArchaicFix Splash").addTargetedMod(TargetedMod.VANILLA).setSide(Side.CLIENT)
|
||||
.setPhase(Phase.EARLY).setApplyIf(() -> AngelicaConfig.showSplashMemoryBar && !AngelicaMod.lwjglDebug).addMixinClasses(
|
||||
"angelica.archaic.MixinSplashProgress"
|
||||
"angelica.archaic.MixinSplashProgress$3"
|
||||
,"angelica.archaic.AccessorSplashProgress"
|
||||
)
|
||||
),
|
||||
@@ -104,7 +104,7 @@ public enum Mixins {
|
||||
IRIS_STARTUP(new Builder("Start Iris").addTargetedMod(TargetedMod.VANILLA).setSide(Side.CLIENT)
|
||||
.setPhase(Phase.EARLY).setApplyIf(() -> AngelicaConfig.enableIris).addMixinClasses(
|
||||
"shaders.startup.MixinGameSettings"
|
||||
,"shaders.startup.MixinGuiMainMenu"
|
||||
,"shaders.startup.MixinMinecraft"
|
||||
,"shaders.startup.MixinInitRenderer"
|
||||
,"shaders.startup.MixinAbstractTexture"
|
||||
,"shaders.startup.MixinTextureAtlasSprite"
|
||||
@@ -226,6 +226,14 @@ public enum Mixins {
|
||||
.setApplyIf(() -> AngelicaConfig.removeUnicodeEvenScaling)
|
||||
.addMixinClasses("angelica.bugfixes.MixinScaledResolution_UnicodeFix")),
|
||||
|
||||
SECURITYCRAFT_COMPAT(new Builder("Fix reflection in SecurityCraft for compat with Angelica").setPhase(Phase.LATE)
|
||||
.addTargetedMod(TargetedMod.SECURITYCRAFT).setSide(Side.CLIENT)
|
||||
.setApplyIf(() -> CompatConfig.fixSecurityCraft)
|
||||
.addMixinClasses(
|
||||
"client.securitycraft.MixinBlockReinforcedFenceGate",
|
||||
"client.securitycraft.MixinBlockReinforcedIronBars"
|
||||
)),
|
||||
|
||||
EXTRA_UTILITIES_THREAD_SAFETY(new Builder("Enable thread safety fixes in Extra Utilities").setPhase(Phase.LATE)
|
||||
.addTargetedMod(TargetedMod.EXTRAUTILS).setSide(Side.CLIENT)
|
||||
.setApplyIf(() -> CompatConfig.fixExtraUtils)
|
||||
|
||||
@@ -25,6 +25,7 @@ public enum TargetedMod {
|
||||
, MRTJPCORE("MrTJPCore", null, "MrTJPCoreMod")
|
||||
, NATURA("Natura", null, "Natura")
|
||||
, PROJECTRED_ILLUMINATION("ProjectRed Illumination", null, "ProjRed|Illumination")
|
||||
, SECURITYCRAFT("SecurityCraft", null, "securitycraft")
|
||||
, SMART_RENDER("Smart Render", null, "SmartRender")
|
||||
, THAUMCRAFT("Thaumcraft", null, "Thaumcraft")
|
||||
, TINKERS_CONSTRUCT("Tinker's Construct", null, "TConstruct")
|
||||
|
||||
@@ -11,7 +11,7 @@ public class MCPatcherForgeConfig {
|
||||
@Config(modid = "mcpatcherforge", category = "custom_colors")
|
||||
public static class CustomColors {
|
||||
@Config.Comment("Enable the custom colors module")
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean enabled;
|
||||
|
||||
@@ -32,31 +32,31 @@ public class MCPatcherForgeConfig {
|
||||
@Config.RequiresMcRestart
|
||||
public static int fogBlendRadius;
|
||||
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean swampColors;
|
||||
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean water;
|
||||
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean tree;
|
||||
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean redstone;
|
||||
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean stem;
|
||||
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean otherBlocks;
|
||||
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean smoothBiomes;
|
||||
|
||||
@@ -64,43 +64,43 @@ public class MCPatcherForgeConfig {
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean testColorSmoothing;
|
||||
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean potion;
|
||||
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean particle;
|
||||
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean fog;
|
||||
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean clouds;
|
||||
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean map;
|
||||
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean dye;
|
||||
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean text;
|
||||
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean xporb;
|
||||
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean egg;
|
||||
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean lightmaps;
|
||||
}
|
||||
@@ -108,7 +108,7 @@ public class MCPatcherForgeConfig {
|
||||
@Config(modid = "mcpatcherforge", category = "custom_item_textures")
|
||||
public static class CustomItemTextures {
|
||||
@Config.Comment("Enable the custom item textures module")
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean enabled;
|
||||
|
||||
@@ -117,15 +117,15 @@ public class MCPatcherForgeConfig {
|
||||
@Config.RequiresMcRestart
|
||||
public static LogLevel logging;
|
||||
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean items;
|
||||
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean enchantments;
|
||||
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean armor;
|
||||
}
|
||||
@@ -164,7 +164,7 @@ public class MCPatcherForgeConfig {
|
||||
@Config(modid = "mcpatcherforge", category = "extended_hd")
|
||||
public static class ExtendedHD {
|
||||
@Config.Comment("Enable the extended hd module")
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean enabled;
|
||||
|
||||
@@ -186,27 +186,27 @@ public class MCPatcherForgeConfig {
|
||||
@Config.Name("lod bias")
|
||||
public static int lodBias;
|
||||
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean animations;
|
||||
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean fancyCompass;
|
||||
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean fancyClock;
|
||||
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean useGL13;
|
||||
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean useScratchTexture;
|
||||
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
@Config.Name("HDFont")
|
||||
public static boolean hdFont;
|
||||
@@ -223,7 +223,7 @@ public class MCPatcherForgeConfig {
|
||||
@Config(modid = "mcpatcherforge", category = "random_mobs")
|
||||
public static class RandomMobs {
|
||||
@Config.Comment("Enable the random mobs module")
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean enabled;
|
||||
|
||||
@@ -232,7 +232,7 @@ public class MCPatcherForgeConfig {
|
||||
@Config.RequiresMcRestart
|
||||
public static LogLevel logging;
|
||||
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean leashLine;
|
||||
}
|
||||
@@ -240,7 +240,7 @@ public class MCPatcherForgeConfig {
|
||||
@Config(modid = "mcpatcherforge", category = "better_skies")
|
||||
public static class BetterSkies {
|
||||
@Config.Comment("Enable the better skies module")
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean enabled;
|
||||
|
||||
@@ -253,15 +253,15 @@ public class MCPatcherForgeConfig {
|
||||
@Config.RequiresMcRestart
|
||||
public static int horizon;
|
||||
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean brightenFireworks;
|
||||
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean skybox;
|
||||
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean unloadTextures;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class VideoSettings {
|
||||
private final File optionsFile;
|
||||
@@ -19,11 +21,12 @@ public class VideoSettings {
|
||||
|
||||
public void loadSettings() {
|
||||
try {
|
||||
if (!optionsFile.exists()) {
|
||||
if (!optionsFile.exists() && !optionsFile.createNewFile()) {
|
||||
return;
|
||||
}
|
||||
BufferedReader bufferedreader = new BufferedReader(new FileReader(optionsFile));
|
||||
String settingString;
|
||||
Set<Settings> loadedSettings = EnumSet.noneOf(Settings.class);
|
||||
|
||||
while((settingString = bufferedreader.readLine()) != null) {
|
||||
try {
|
||||
@@ -31,12 +34,19 @@ public class VideoSettings {
|
||||
Settings setting = Settings.valueOf(fragments[0]);
|
||||
setting.option.deserialize(fragments[1]);
|
||||
setting.applyChanges();
|
||||
loadedSettings.add(setting);
|
||||
} catch (Exception exception) {
|
||||
NotFine.logger.warn("Skipping bad option: " + settingString);
|
||||
}
|
||||
|
||||
}
|
||||
bufferedreader.close();
|
||||
|
||||
for (Settings setting : Settings.values()) {
|
||||
if (!loadedSettings.contains(setting)) {
|
||||
setting.applyChanges();
|
||||
}
|
||||
}
|
||||
} catch (Exception exception) {
|
||||
NotFine.logger.error("Failed to load options", exception);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package kroppeb.stareval;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class Util {
|
||||
public static <T> T make(T item, Consumer<T> init) {
|
||||
init.accept(item);
|
||||
return item;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,23 +1,12 @@
|
||||
package kroppeb.stareval.element.tree;
|
||||
|
||||
import com.github.bsideup.jabel.Desugar;
|
||||
import kroppeb.stareval.element.AccessibleExpressionElement;
|
||||
|
||||
public class AccessExpressionElement implements AccessibleExpressionElement {
|
||||
private final AccessibleExpressionElement base;
|
||||
private final String index;
|
||||
@Desugar
|
||||
public record AccessExpressionElement(AccessibleExpressionElement base,
|
||||
String index) implements AccessibleExpressionElement {
|
||||
|
||||
public AccessExpressionElement(AccessibleExpressionElement base, String index) {
|
||||
this.base = base;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public AccessibleExpressionElement getBase() {
|
||||
return this.base;
|
||||
}
|
||||
|
||||
public String getIndex() {
|
||||
return this.index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
@@ -1,30 +1,13 @@
|
||||
package kroppeb.stareval.element.tree;
|
||||
|
||||
import com.github.bsideup.jabel.Desugar;
|
||||
import kroppeb.stareval.element.ExpressionElement;
|
||||
import kroppeb.stareval.parser.BinaryOp;
|
||||
|
||||
public class BinaryExpressionElement implements ExpressionElement {
|
||||
private final BinaryOp op;
|
||||
private final ExpressionElement left;
|
||||
private final ExpressionElement right;
|
||||
@Desugar
|
||||
public record BinaryExpressionElement(BinaryOp op, ExpressionElement left,
|
||||
ExpressionElement right) implements ExpressionElement {
|
||||
|
||||
public BinaryExpressionElement(BinaryOp op, ExpressionElement left, ExpressionElement right) {
|
||||
this.op = op;
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
public BinaryOp getOp() {
|
||||
return this.op;
|
||||
}
|
||||
|
||||
public ExpressionElement getLeft() {
|
||||
return this.left;
|
||||
}
|
||||
|
||||
public ExpressionElement getRight() {
|
||||
return this.right;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
@@ -1,25 +1,13 @@
|
||||
package kroppeb.stareval.element.tree;
|
||||
|
||||
import com.github.bsideup.jabel.Desugar;
|
||||
import kroppeb.stareval.element.ExpressionElement;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class FunctionCall implements ExpressionElement {
|
||||
private final String id;
|
||||
private final List<? extends ExpressionElement> args;
|
||||
@Desugar
|
||||
public record FunctionCall(String id, List<? extends ExpressionElement> args) implements ExpressionElement {
|
||||
|
||||
public FunctionCall(String id, List<? extends ExpressionElement> args) {
|
||||
this.id = id;
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public List<? extends ExpressionElement> getArgs() {
|
||||
return this.args;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
@@ -1,24 +1,12 @@
|
||||
package kroppeb.stareval.element.tree;
|
||||
|
||||
import com.github.bsideup.jabel.Desugar;
|
||||
import kroppeb.stareval.element.ExpressionElement;
|
||||
import kroppeb.stareval.parser.UnaryOp;
|
||||
|
||||
public class UnaryExpressionElement implements ExpressionElement {
|
||||
private final UnaryOp op;
|
||||
private final ExpressionElement inner;
|
||||
@Desugar
|
||||
public record UnaryExpressionElement(UnaryOp op, ExpressionElement inner) implements ExpressionElement {
|
||||
|
||||
public UnaryExpressionElement(UnaryOp op, ExpressionElement inner) {
|
||||
this.op = op;
|
||||
this.inner = inner;
|
||||
}
|
||||
|
||||
public UnaryOp getOp() {
|
||||
return op;
|
||||
}
|
||||
|
||||
public ExpressionElement getInner() {
|
||||
return inner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
@@ -21,7 +21,7 @@ public class PartialBinaryExpression extends PartialExpression implements Priori
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return this.op.getPriority();
|
||||
return this.op.priority();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
package kroppeb.stareval.exception;
|
||||
|
||||
public class MissingTokenException extends ParseException {
|
||||
|
||||
private static final long serialVersionUID = -2096321911994168858L;
|
||||
|
||||
public MissingTokenException(String message, int index) {
|
||||
public MissingTokenException(String message, int index) {
|
||||
super(message + " at index " + index);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,7 @@
|
||||
package kroppeb.stareval.exception;
|
||||
|
||||
public abstract class ParseException extends Exception{
|
||||
|
||||
private static final long serialVersionUID = -5014053641238717471L;
|
||||
|
||||
public ParseException() {
|
||||
public abstract class ParseException extends Exception {
|
||||
public ParseException() {
|
||||
}
|
||||
|
||||
public ParseException(String message) {
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
package kroppeb.stareval.exception;
|
||||
|
||||
public class UnexpectedCharacterException extends ParseException {
|
||||
|
||||
private static final long serialVersionUID = -3886198952263126846L;
|
||||
|
||||
public UnexpectedCharacterException(char expected, char actual, int index) {
|
||||
public UnexpectedCharacterException(char expected, char actual, int index) {
|
||||
this("Expected to read '" + expected + "' but got '" + actual + "' at index " + index);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
package kroppeb.stareval.exception;
|
||||
|
||||
public class UnexpectedEndingException extends ParseException {
|
||||
|
||||
private static final long serialVersionUID = -3704913315979481520L;
|
||||
|
||||
public UnexpectedEndingException() {
|
||||
public UnexpectedEndingException() {
|
||||
this("Expected to read more text, but the string has ended");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
package kroppeb.stareval.exception;
|
||||
|
||||
public class UnexpectedTokenException extends ParseException {
|
||||
|
||||
private static final long serialVersionUID = 689385399380177588L;
|
||||
|
||||
public UnexpectedTokenException(String message, int index) {
|
||||
public UnexpectedTokenException(String message, int index) {
|
||||
super(message + " at index " + index);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package kroppeb.stareval.expression;
|
||||
|
||||
import kroppeb.stareval.function.FunctionContext;
|
||||
import kroppeb.stareval.function.FunctionReturn;
|
||||
import kroppeb.stareval.function.Type;
|
||||
|
||||
public class BasicVariableExpression implements VariableExpression {
|
||||
final private String name;
|
||||
final private Type type;
|
||||
|
||||
public BasicVariableExpression(String name, Type type) {
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evaluateTo(FunctionContext c, FunctionReturn r) {
|
||||
c.getVariable(name).evaluateTo(c, r);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression partialEval(FunctionContext context, FunctionReturn functionReturn) {
|
||||
if (context.hasVariable(this.name)) {
|
||||
context.getVariable(this.name).evaluateTo(context, functionReturn);
|
||||
return type.createConstant(functionReturn);
|
||||
} else {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package kroppeb.stareval.expression;
|
||||
|
||||
import kroppeb.stareval.function.FunctionContext;
|
||||
import kroppeb.stareval.function.FunctionReturn;
|
||||
import kroppeb.stareval.function.TypedFunction;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class CallExpression implements Expression {
|
||||
private final TypedFunction function;
|
||||
private final Expression[] arguments;
|
||||
|
||||
public CallExpression(TypedFunction function, Expression[] arguments) {
|
||||
this.function = function;
|
||||
this.arguments = arguments;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evaluateTo(FunctionContext context, FunctionReturn functionReturn) {
|
||||
this.function.evaluateTo(this.arguments, context, functionReturn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void listVariables(Collection<? super VariableExpression> variables) {
|
||||
for (Expression argument : this.arguments) {
|
||||
argument.listVariables(variables);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isConstant() {
|
||||
for (Expression i : arguments) {
|
||||
if (!(i instanceof ConstantExpression)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression partialEval(FunctionContext context, FunctionReturn functionReturn) {
|
||||
// the dirty way would be this
|
||||
/*
|
||||
try{
|
||||
this.evaluateTo(context, functionReturn);
|
||||
return this.function.getReturnType().createConstant(functionReturn);
|
||||
}catch(Exception e){
|
||||
return this;
|
||||
}
|
||||
*/
|
||||
|
||||
if (this.function.isPure() && isConstant()) {
|
||||
this.evaluateTo(context, functionReturn);
|
||||
return function.getReturnType().createConstant(functionReturn);
|
||||
}
|
||||
|
||||
Expression[] partialEvaluatedParams = new Expression[this.arguments.length];
|
||||
boolean allFullySimplified = true;
|
||||
boolean noneSimplified = true;
|
||||
for (int i = 0; i < this.arguments.length; i++) {
|
||||
Expression simplified = this.arguments[i].partialEval(context, functionReturn);
|
||||
if (simplified instanceof ConstantExpression) {
|
||||
noneSimplified = false;
|
||||
} else {
|
||||
allFullySimplified = false;
|
||||
if (simplified != this.arguments[i]) {
|
||||
noneSimplified = false;
|
||||
}
|
||||
}
|
||||
partialEvaluatedParams[i] = simplified;
|
||||
}
|
||||
|
||||
if (this.function.isPure() && allFullySimplified) {
|
||||
this.function.evaluateTo(partialEvaluatedParams, context, functionReturn);
|
||||
return this.function.getReturnType().createConstant(functionReturn);
|
||||
}
|
||||
|
||||
if (noneSimplified) {
|
||||
return this;
|
||||
}
|
||||
|
||||
return new CallExpression(this.function, partialEvaluatedParams);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package kroppeb.stareval.expression;
|
||||
|
||||
import kroppeb.stareval.function.Type;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public abstract class ConstantExpression implements Expression {
|
||||
private final Type type;
|
||||
|
||||
protected ConstantExpression(Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void listVariables(Collection<? super VariableExpression> variables) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package kroppeb.stareval.expression;
|
||||
|
||||
import kroppeb.stareval.function.FunctionContext;
|
||||
import kroppeb.stareval.function.FunctionReturn;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface Expression {
|
||||
void evaluateTo(FunctionContext context, FunctionReturn functionReturn);
|
||||
|
||||
default Expression partialEval(FunctionContext context, FunctionReturn functionReturn) {
|
||||
return this;
|
||||
}
|
||||
|
||||
void listVariables(Collection<? super VariableExpression> variables);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package kroppeb.stareval.expression;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface VariableExpression extends Expression {
|
||||
@Override
|
||||
default void listVariables(Collection<? super VariableExpression> variables) {
|
||||
variables.add(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package kroppeb.stareval.function;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
public abstract class AbstractTypedFunction implements TypedFunction {
|
||||
private final Type returnType;
|
||||
private final Parameter[] parameters;
|
||||
private final int priority;
|
||||
private final boolean isPure;
|
||||
|
||||
public AbstractTypedFunction(Type returnType, Parameter[] parameters, int priority, boolean isPure) {
|
||||
this.returnType = returnType;
|
||||
this.parameters = parameters;
|
||||
this.priority = priority;
|
||||
this.isPure = isPure;
|
||||
}
|
||||
|
||||
public AbstractTypedFunction(Type returnType, Type[] parameterType) {
|
||||
this.returnType = returnType;
|
||||
this.parameters = Arrays.stream(parameterType).map(Parameter::new).toArray(Parameter[]::new);
|
||||
this.priority = 0;
|
||||
this.isPure = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getReturnType() {
|
||||
return this.returnType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Parameter[] getParameters() {
|
||||
return this.parameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPure() {
|
||||
return this.isPure;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int priority() {
|
||||
return this.priority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof AbstractTypedFunction func) {
|
||||
return Objects.equals(returnType, func.returnType) &&
|
||||
Arrays.equals(parameters, func.parameters) &&
|
||||
priority == func.priority &&
|
||||
isPure == func.isPure;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(returnType, Arrays.hashCode(parameters), priority, isPure);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return TypedFunction.format(this, "unknown");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package kroppeb.stareval.function;
|
||||
|
||||
import kroppeb.stareval.expression.Expression;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface B2BFunction extends TypedFunction {
|
||||
boolean eval(boolean a);
|
||||
|
||||
@Override
|
||||
default void evaluateTo(Expression[] params, FunctionContext context, FunctionReturn functionReturn) {
|
||||
params[0].evaluateTo(context, functionReturn);
|
||||
boolean a = functionReturn.booleanReturn;
|
||||
|
||||
functionReturn.booleanReturn = this.eval(a);
|
||||
}
|
||||
|
||||
@Override
|
||||
default Type getReturnType() {
|
||||
return Type.Boolean;
|
||||
}
|
||||
|
||||
@Override
|
||||
default Parameter[] getParameters() {
|
||||
return new Parameter[]{Type.BooleanParameter};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package kroppeb.stareval.function;
|
||||
|
||||
import kroppeb.stareval.expression.Expression;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface BB2BFunction extends TypedFunction {
|
||||
boolean eval(boolean a, boolean b);
|
||||
|
||||
@Override
|
||||
default void evaluateTo(Expression[] params, FunctionContext context, FunctionReturn functionReturn) {
|
||||
params[0].evaluateTo(context, functionReturn);
|
||||
boolean a = functionReturn.booleanReturn;
|
||||
|
||||
params[1].evaluateTo(context, functionReturn);
|
||||
boolean b = functionReturn.booleanReturn;
|
||||
|
||||
functionReturn.booleanReturn = this.eval(a, b);
|
||||
}
|
||||
|
||||
@Override
|
||||
default Type getReturnType() {
|
||||
return Type.Boolean;
|
||||
}
|
||||
|
||||
@Override
|
||||
default Parameter[] getParameters() {
|
||||
return new Parameter[]{Type.BooleanParameter, Type.BooleanParameter};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package kroppeb.stareval.function;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||
import kroppeb.stareval.expression.Expression;
|
||||
import kroppeb.stareval.expression.VariableExpression;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class BasicFunctionContext implements FunctionContext {
|
||||
final private Map<String, Expression> variables = new Object2ObjectOpenHashMap<>();
|
||||
|
||||
public void setVariable(String name, Expression value) {
|
||||
variables.put(name, value);
|
||||
}
|
||||
|
||||
public void setIntVariable(String name, int value) {
|
||||
setVariable(name, (VariableExpression) (c, r) -> r.intReturn = value);
|
||||
}
|
||||
|
||||
public void setFloatVariable(String name, float value) {
|
||||
setVariable(name, (VariableExpression) (c, r) -> r.floatReturn = value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression getVariable(String name) {
|
||||
Expression expression = variables.get(name);
|
||||
if (expression == null)
|
||||
throw new RuntimeException("Variable hasn't been set: " + name);
|
||||
return expression;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasVariable(String name) {
|
||||
return variables.containsKey(name);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package kroppeb.stareval.function;
|
||||
|
||||
import kroppeb.stareval.expression.Expression;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface F2FFunction extends TypedFunction {
|
||||
float eval(float a);
|
||||
|
||||
@Override
|
||||
default void evaluateTo(Expression[] params, FunctionContext context, FunctionReturn functionReturn) {
|
||||
params[0].evaluateTo(context, functionReturn);
|
||||
functionReturn.floatReturn = this.eval(functionReturn.floatReturn);
|
||||
}
|
||||
|
||||
@Override
|
||||
default Type getReturnType() {
|
||||
return Type.Float;
|
||||
}
|
||||
|
||||
@Override
|
||||
default Parameter[] getParameters() {
|
||||
return new Parameter[]{Type.FloatParameter};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package kroppeb.stareval.function;
|
||||
|
||||
import kroppeb.stareval.expression.Expression;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface F2IFunction extends TypedFunction {
|
||||
int eval(float a);
|
||||
|
||||
@Override
|
||||
default void evaluateTo(Expression[] params, FunctionContext context, FunctionReturn functionReturn) {
|
||||
params[0].evaluateTo(context, functionReturn);
|
||||
functionReturn.intReturn = this.eval(functionReturn.floatReturn);
|
||||
}
|
||||
|
||||
@Override
|
||||
default Type getReturnType() {
|
||||
return Type.Int;
|
||||
}
|
||||
|
||||
@Override
|
||||
default Parameter[] getParameters() {
|
||||
return new Parameter[]{Type.FloatParameter};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package kroppeb.stareval.function;
|
||||
|
||||
import kroppeb.stareval.expression.Expression;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface FF2BFunction extends TypedFunction {
|
||||
boolean eval(float a, float b);
|
||||
|
||||
@Override
|
||||
default void evaluateTo(Expression[] params, FunctionContext context, FunctionReturn functionReturn) {
|
||||
params[0].evaluateTo(context, functionReturn);
|
||||
float a = functionReturn.floatReturn;
|
||||
|
||||
params[1].evaluateTo(context, functionReturn);
|
||||
float b = functionReturn.floatReturn;
|
||||
|
||||
functionReturn.booleanReturn = this.eval(a, b);
|
||||
}
|
||||
|
||||
@Override
|
||||
default Type getReturnType() {
|
||||
return Type.Boolean;
|
||||
}
|
||||
|
||||
@Override
|
||||
default Parameter[] getParameters() {
|
||||
return new Parameter[]{Type.FloatParameter, Type.FloatParameter};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package kroppeb.stareval.function;
|
||||
|
||||
import kroppeb.stareval.expression.Expression;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface FF2FFunction extends TypedFunction {
|
||||
float eval(float a, float b);
|
||||
|
||||
@Override
|
||||
default void evaluateTo(Expression[] params, FunctionContext context, FunctionReturn functionReturn) {
|
||||
params[0].evaluateTo(context, functionReturn);
|
||||
float a = functionReturn.floatReturn;
|
||||
|
||||
params[1].evaluateTo(context, functionReturn);
|
||||
float b = functionReturn.floatReturn;
|
||||
|
||||
functionReturn.floatReturn = this.eval(a, b);
|
||||
}
|
||||
|
||||
@Override
|
||||
default Type getReturnType() {
|
||||
return Type.Float;
|
||||
}
|
||||
|
||||
@Override
|
||||
default Parameter[] getParameters() {
|
||||
return new Parameter[]{Type.FloatParameter, Type.FloatParameter};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package kroppeb.stareval.function;
|
||||
|
||||
import kroppeb.stareval.expression.Expression;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface FFF2BFunction extends TypedFunction {
|
||||
boolean eval(float a, float b, float c);
|
||||
|
||||
@Override
|
||||
default void evaluateTo(Expression[] params, FunctionContext context, FunctionReturn functionReturn) {
|
||||
params[0].evaluateTo(context, functionReturn);
|
||||
float a = functionReturn.floatReturn;
|
||||
|
||||
params[1].evaluateTo(context, functionReturn);
|
||||
float b = functionReturn.floatReturn;
|
||||
|
||||
params[2].evaluateTo(context, functionReturn);
|
||||
float c = functionReturn.floatReturn;
|
||||
|
||||
functionReturn.booleanReturn = this.eval(a, b, c);
|
||||
}
|
||||
|
||||
@Override
|
||||
default Type getReturnType() {
|
||||
return Type.Boolean;
|
||||
}
|
||||
|
||||
@Override
|
||||
default Parameter[] getParameters() {
|
||||
return new Parameter[]{Type.FloatParameter, Type.FloatParameter, Type.FloatParameter};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package kroppeb.stareval.function;
|
||||
|
||||
import kroppeb.stareval.expression.Expression;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface FFF2FFunction extends TypedFunction {
|
||||
float eval(float a, float b, float c);
|
||||
|
||||
@Override
|
||||
default void evaluateTo(Expression[] params, FunctionContext context, FunctionReturn functionReturn) {
|
||||
params[0].evaluateTo(context, functionReturn);
|
||||
float a = functionReturn.floatReturn;
|
||||
|
||||
params[1].evaluateTo(context, functionReturn);
|
||||
float b = functionReturn.floatReturn;
|
||||
|
||||
params[2].evaluateTo(context, functionReturn);
|
||||
float c = functionReturn.floatReturn;
|
||||
|
||||
functionReturn.floatReturn = this.eval(a, b, c);
|
||||
}
|
||||
|
||||
@Override
|
||||
default Type getReturnType() {
|
||||
return Type.Float;
|
||||
}
|
||||
|
||||
@Override
|
||||
default Parameter[] getParameters() {
|
||||
return new Parameter[]{Type.FloatParameter, Type.FloatParameter, Type.FloatParameter};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package kroppeb.stareval.function;
|
||||
|
||||
import kroppeb.stareval.expression.Expression;
|
||||
|
||||
public interface FunctionContext {
|
||||
Expression getVariable(String name);
|
||||
|
||||
boolean hasVariable(String name);
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
package kroppeb.stareval.function;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class FunctionResolver {
|
||||
private final Map<String, Map<Type, List<TypedFunction>>> functions;
|
||||
// TODO: instead of a suplier we could use an int->function to make varargs
|
||||
private final Map<String, Map<Type, List<Supplier<? extends TypedFunction>>>> dynamicFunctions;
|
||||
|
||||
public FunctionResolver(
|
||||
Map<String, Map<Type, List<TypedFunction>>> functions,
|
||||
Map<String, Map<Type, List<Supplier<? extends TypedFunction>>>> dynamicFunctions) {
|
||||
this.functions = functions;
|
||||
this.dynamicFunctions = dynamicFunctions;
|
||||
}
|
||||
|
||||
public List<? extends TypedFunction> resolve(String name, Type returnType) {
|
||||
Map<Type, List<TypedFunction>> normal = this.functions.get(name);
|
||||
Map<Type, List<Supplier<? extends TypedFunction>>> dynamic = this.dynamicFunctions.get(name);
|
||||
List<? extends TypedFunction> u = null;
|
||||
|
||||
if (normal == null && dynamic == null)
|
||||
throw new RuntimeException("No such function: " + name);
|
||||
if (normal != null)
|
||||
u = normal.get(returnType);
|
||||
if (dynamic != null) {
|
||||
List<Supplier<? extends TypedFunction>> p = dynamic.get(returnType);
|
||||
if (p != null) {
|
||||
List<? extends TypedFunction> uDynamic = p.stream().map(Supplier::get).collect(Collectors.toList());
|
||||
if (u == null) {
|
||||
u = uDynamic;
|
||||
} else {
|
||||
List<TypedFunction> newU = new ArrayList<>(u.size() + uDynamic.size());
|
||||
newU.addAll(u);
|
||||
newU.addAll(uDynamic);
|
||||
u = newU;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (u == null)
|
||||
return Collections.emptyList();
|
||||
return u;
|
||||
}
|
||||
|
||||
public void logAllFunctions() {
|
||||
final Set<String> names = new LinkedHashSet<>();
|
||||
names.addAll(this.functions.keySet());
|
||||
names.addAll(this.dynamicFunctions.keySet());
|
||||
for (final String name : names) {
|
||||
final Map<Type, List<TypedFunction>> overloads = new Object2ObjectLinkedOpenHashMap<>();
|
||||
Map<Type, List<TypedFunction>> normal = this.functions.get(name);
|
||||
if (normal != null)
|
||||
overloads.putAll(normal);
|
||||
|
||||
Map<Type, List<Supplier<? extends TypedFunction>>> dynamic = this.dynamicFunctions.get(name);
|
||||
if (dynamic != null)
|
||||
overloads.putAll(
|
||||
dynamic
|
||||
.entrySet()
|
||||
.stream()
|
||||
.collect(Collectors.toMap(
|
||||
Map.Entry::getKey,
|
||||
entry -> entry.getValue()
|
||||
.stream()
|
||||
.map(Supplier::get)
|
||||
.collect(Collectors.toList())
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
for (Map.Entry<Type, List<TypedFunction>> returnTypeOverloads : overloads.entrySet()) {
|
||||
for (TypedFunction typedFunction : returnTypeOverloads.getValue()) {
|
||||
System.out.println(TypedFunction.format(typedFunction, name));
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private final Map<String, List<TypedFunction>> functions = new Object2ObjectLinkedOpenHashMap<>();
|
||||
private final Map<String, Map<Type, List<Supplier<? extends TypedFunction>>>> dynamicFunctions = new Object2ObjectLinkedOpenHashMap<>();
|
||||
|
||||
public <T extends TypedFunction> void add(String name, T function) {
|
||||
this.addFunction(name, function);
|
||||
}
|
||||
|
||||
public <T extends TypedFunction> void addDynamic(String name, Type returnType, Supplier<T> function) {
|
||||
this.addDynamicFunction(name, returnType, function);
|
||||
}
|
||||
|
||||
public void addDynamicFunction(String name, Type returnType, Supplier<? extends TypedFunction> function) {
|
||||
this.dynamicFunctions
|
||||
.computeIfAbsent(name, (n) -> new Object2ObjectLinkedOpenHashMap<>())
|
||||
.computeIfAbsent(returnType, (n) -> new ObjectArrayList<>())
|
||||
.add(function);
|
||||
}
|
||||
|
||||
public void addFunction(String name, TypedFunction function) {
|
||||
this.functions.computeIfAbsent(name, (n) -> new ObjectArrayList<>()).add(function);
|
||||
}
|
||||
|
||||
public FunctionResolver build() {
|
||||
Map<String, Map<Type, List<TypedFunction>>> functions = new Object2ObjectLinkedOpenHashMap<>();
|
||||
for (Map.Entry<String, List<TypedFunction>> entry : this.functions.entrySet()) {
|
||||
Map<Type, List<TypedFunction>> typeMap = new Object2ObjectLinkedOpenHashMap<>();
|
||||
for (TypedFunction function : entry.getValue()) {
|
||||
typeMap.computeIfAbsent(function.getReturnType(), i -> new ObjectArrayList<>())
|
||||
.add(function);
|
||||
}
|
||||
functions.put(entry.getKey(), typeMap);
|
||||
}
|
||||
|
||||
return new FunctionResolver(functions, this.dynamicFunctions);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package kroppeb.stareval.function;
|
||||
|
||||
public class FunctionReturn {
|
||||
public boolean booleanReturn;
|
||||
public byte byteReturn;
|
||||
public short shortReturn;
|
||||
public int intReturn;
|
||||
public long longReturn;
|
||||
public float floatReturn;
|
||||
public double doubleReturn;
|
||||
public Object objectReturn;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package kroppeb.stareval.function;
|
||||
|
||||
import kroppeb.stareval.expression.Expression;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface I2FFunction extends TypedFunction {
|
||||
float eval(int a);
|
||||
|
||||
@Override
|
||||
default void evaluateTo(Expression[] params, FunctionContext context, FunctionReturn functionReturn) {
|
||||
params[0].evaluateTo(context, functionReturn);
|
||||
functionReturn.floatReturn = this.eval(functionReturn.intReturn);
|
||||
}
|
||||
|
||||
@Override
|
||||
default Type getReturnType() {
|
||||
return Type.Float;
|
||||
}
|
||||
|
||||
@Override
|
||||
default Parameter[] getParameters() {
|
||||
return new Parameter[]{Type.IntParameter};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package kroppeb.stareval.function;
|
||||
|
||||
import kroppeb.stareval.expression.Expression;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface I2IFunction extends TypedFunction {
|
||||
int eval(int a);
|
||||
|
||||
@Override
|
||||
default void evaluateTo(Expression[] params, FunctionContext context, FunctionReturn functionReturn) {
|
||||
params[0].evaluateTo(context, functionReturn);
|
||||
functionReturn.intReturn = this.eval(functionReturn.intReturn);
|
||||
}
|
||||
|
||||
@Override
|
||||
default Type getReturnType() {
|
||||
return Type.Int;
|
||||
}
|
||||
|
||||
@Override
|
||||
default Parameter[] getParameters() {
|
||||
return new Parameter[]{Type.IntParameter};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package kroppeb.stareval.function;
|
||||
|
||||
import kroppeb.stareval.expression.Expression;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface II2BFunction extends TypedFunction {
|
||||
boolean eval(int a, int b);
|
||||
|
||||
@Override
|
||||
default void evaluateTo(Expression[] params, FunctionContext context, FunctionReturn functionReturn) {
|
||||
params[0].evaluateTo(context, functionReturn);
|
||||
int a = functionReturn.intReturn;
|
||||
|
||||
params[1].evaluateTo(context, functionReturn);
|
||||
int b = functionReturn.intReturn;
|
||||
|
||||
functionReturn.booleanReturn = this.eval(a, b);
|
||||
}
|
||||
|
||||
@Override
|
||||
default Type getReturnType() {
|
||||
return Type.Boolean;
|
||||
}
|
||||
|
||||
@Override
|
||||
default Parameter[] getParameters() {
|
||||
return new Parameter[]{Type.IntParameter, Type.IntParameter};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package kroppeb.stareval.function;
|
||||
|
||||
import kroppeb.stareval.expression.Expression;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface II2IFunction extends TypedFunction {
|
||||
int eval(int a, int b);
|
||||
|
||||
@Override
|
||||
default void evaluateTo(Expression[] params, FunctionContext context, FunctionReturn functionReturn) {
|
||||
params[0].evaluateTo(context, functionReturn);
|
||||
int a = functionReturn.intReturn;
|
||||
|
||||
params[1].evaluateTo(context, functionReturn);
|
||||
int b = functionReturn.intReturn;
|
||||
|
||||
functionReturn.intReturn = this.eval(a, b);
|
||||
}
|
||||
|
||||
@Override
|
||||
default Type getReturnType() {
|
||||
return Type.Int;
|
||||
}
|
||||
|
||||
@Override
|
||||
default Parameter[] getParameters() {
|
||||
return new Parameter[]{Type.IntParameter, Type.IntParameter};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package kroppeb.stareval.function;
|
||||
|
||||
import kroppeb.stareval.expression.Expression;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface III2BFunction extends TypedFunction {
|
||||
boolean eval(int a, int b, int c);
|
||||
|
||||
@Override
|
||||
default void evaluateTo(Expression[] params, FunctionContext context, FunctionReturn functionReturn) {
|
||||
params[0].evaluateTo(context, functionReturn);
|
||||
int a = functionReturn.intReturn;
|
||||
|
||||
params[1].evaluateTo(context, functionReturn);
|
||||
int b = functionReturn.intReturn;
|
||||
|
||||
params[2].evaluateTo(context, functionReturn);
|
||||
int c = functionReturn.intReturn;
|
||||
|
||||
functionReturn.booleanReturn = this.eval(a, b, c);
|
||||
}
|
||||
|
||||
@Override
|
||||
default Type getReturnType() {
|
||||
return Type.Boolean;
|
||||
}
|
||||
|
||||
@Override
|
||||
default Parameter[] getParameters() {
|
||||
return new Parameter[]{Type.IntParameter, Type.IntParameter, Type.IntParameter};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package kroppeb.stareval.function;
|
||||
|
||||
import kroppeb.stareval.expression.Expression;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface III2IFunction extends TypedFunction {
|
||||
int eval(int a, int b, int c);
|
||||
|
||||
@Override
|
||||
default void evaluateTo(Expression[] params, FunctionContext context, FunctionReturn functionReturn) {
|
||||
params[0].evaluateTo(context, functionReturn);
|
||||
int a = functionReturn.intReturn;
|
||||
|
||||
params[1].evaluateTo(context, functionReturn);
|
||||
int b = functionReturn.intReturn;
|
||||
|
||||
params[2].evaluateTo(context, functionReturn);
|
||||
int c = functionReturn.intReturn;
|
||||
|
||||
functionReturn.intReturn = this.eval(a, b, c);
|
||||
}
|
||||
|
||||
@Override
|
||||
default Type getReturnType() {
|
||||
return Type.Int;
|
||||
}
|
||||
|
||||
@Override
|
||||
default Parameter[] getParameters() {
|
||||
return new Parameter[]{Type.IntParameter, Type.IntParameter, Type.IntParameter};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
package kroppeb.stareval.function;
|
||||
|
||||
import kroppeb.stareval.expression.ConstantExpression;
|
||||
import kroppeb.stareval.function.TypedFunction.Parameter;
|
||||
import net.coderbot.iris.gl.uniform.UniformType;
|
||||
import net.coderbot.iris.parsing.MatrixType;
|
||||
import net.coderbot.iris.parsing.VectorType;
|
||||
|
||||
public abstract class Type {
|
||||
public static final Boolean Boolean = new Boolean();
|
||||
public static final Int Int = new Int();
|
||||
public static final Float Float = new Float();
|
||||
public static final Parameter BooleanParameter = new Parameter(Boolean);
|
||||
public static final Parameter IntParameter = new Parameter(Int);
|
||||
public static final Parameter FloatParameter = new Parameter(Float);
|
||||
public static final Primitive[] AllPrimitives = {Type.Boolean, Type.Int, Type.Float};
|
||||
|
||||
public static UniformType convert(Type type) {
|
||||
if (type == Type.Int || type == Type.Boolean) return UniformType.INT;
|
||||
else if (type == Type.Float) return UniformType.FLOAT;
|
||||
else if (type == VectorType.VEC2) return UniformType.VEC2;
|
||||
else if (type == VectorType.VEC3) return UniformType.VEC3;
|
||||
else if (type == VectorType.VEC4) return UniformType.VEC4;
|
||||
else if (type == VectorType.I_VEC2) return UniformType.VEC2I;
|
||||
else if (type == VectorType.I_VEC3) return UniformType.VEC3I;
|
||||
else if (type == MatrixType.MAT4) return UniformType.MAT4;
|
||||
else throw new IllegalArgumentException("Unsupported custom uniform type: " + type);
|
||||
}
|
||||
|
||||
public abstract ConstantExpression createConstant(FunctionReturn functionReturn);
|
||||
|
||||
public abstract Object createArray(int length);
|
||||
|
||||
public abstract void setValueFromReturn(Object array, int index, FunctionReturn value);
|
||||
|
||||
public abstract void getValueFromArray(Object array, int index, FunctionReturn value);
|
||||
|
||||
public abstract String toString();
|
||||
|
||||
public abstract static class Primitive extends Type {
|
||||
}
|
||||
|
||||
public static class ObjectType extends Type {
|
||||
@Override
|
||||
public ConstantExpression createConstant(FunctionReturn functionReturn) {
|
||||
Object object = functionReturn.objectReturn;
|
||||
return new ConstantExpression(this) {
|
||||
@Override
|
||||
public void evaluateTo(FunctionContext context, FunctionReturn functionReturn) {
|
||||
functionReturn.objectReturn = object;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object createArray(int length) {
|
||||
return new Object[length];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValueFromReturn(Object array, int index, FunctionReturn value) {
|
||||
Object[] arr = (Object[]) array;
|
||||
arr[index] = value.objectReturn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getValueFromArray(Object array, int index, FunctionReturn value) {
|
||||
Object[] arr = (Object[]) array;
|
||||
value.objectReturn = arr[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Object";
|
||||
}
|
||||
}
|
||||
|
||||
public static class Boolean extends Primitive {
|
||||
@Override
|
||||
public ConstantExpression createConstant(FunctionReturn functionReturn) {
|
||||
boolean value = functionReturn.booleanReturn;
|
||||
return new ConstantExpression(this) {
|
||||
@Override
|
||||
public void evaluateTo(FunctionContext context, FunctionReturn functionReturn) {
|
||||
functionReturn.booleanReturn = value;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object createArray(int length) {
|
||||
return new boolean[length];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValueFromReturn(Object array, int index, FunctionReturn value) {
|
||||
boolean[] arr = (boolean[]) array;
|
||||
arr[index] = value.booleanReturn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getValueFromArray(Object array, int index, FunctionReturn value) {
|
||||
boolean[] arr = (boolean[]) array;
|
||||
value.booleanReturn = arr[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "bool";
|
||||
}
|
||||
}
|
||||
|
||||
public static class Int extends Primitive {
|
||||
@Override
|
||||
public ConstantExpression createConstant(FunctionReturn functionReturn) {
|
||||
int value = functionReturn.intReturn;
|
||||
return new ConstantExpression(this) {
|
||||
@Override
|
||||
public void evaluateTo(FunctionContext context, FunctionReturn functionReturn) {
|
||||
functionReturn.intReturn = value;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object createArray(int length) {
|
||||
return new int[length];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValueFromReturn(Object array, int index, FunctionReturn value) {
|
||||
int[] arr = (int[]) array;
|
||||
arr[index] = value.intReturn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getValueFromArray(Object array, int index, FunctionReturn value) {
|
||||
int[] arr = (int[]) array;
|
||||
value.intReturn = arr[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "int";
|
||||
}
|
||||
}
|
||||
|
||||
public static class Float extends Primitive {
|
||||
@Override
|
||||
public ConstantExpression createConstant(FunctionReturn functionReturn) {
|
||||
float value = functionReturn.floatReturn;
|
||||
return new ConstantExpression(this) {
|
||||
@Override
|
||||
public void evaluateTo(FunctionContext context, FunctionReturn functionReturn) {
|
||||
functionReturn.floatReturn = value;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object createArray(int length) {
|
||||
return new float[length];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValueFromReturn(Object array, int index, FunctionReturn value) {
|
||||
float[] arr = (float[]) array;
|
||||
arr[index] = value.floatReturn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getValueFromArray(Object array, int index, FunctionReturn value) {
|
||||
float[] arr = (float[]) array;
|
||||
value.floatReturn = arr[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "float";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package kroppeb.stareval.function;
|
||||
|
||||
import kroppeb.stareval.expression.Expression;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public interface TypedFunction {
|
||||
|
||||
static String format(TypedFunction function, String name) {
|
||||
return String.format("%s %s(%s) (priority: %d, pure:%s)",
|
||||
function.getReturnType().toString(),
|
||||
name,
|
||||
Arrays.stream(function.getParameters())
|
||||
.map(param -> param.constant() ? "const " + param.type() : param.type().toString())
|
||||
.collect(Collectors.joining(", ")),
|
||||
function.priority(),
|
||||
function.isPure() ? "yes" : "no"
|
||||
);
|
||||
}
|
||||
|
||||
Type getReturnType();
|
||||
|
||||
Parameter[] getParameters();
|
||||
|
||||
void evaluateTo(Expression[] params, FunctionContext context, FunctionReturn functionReturn);
|
||||
|
||||
default boolean isPure() {
|
||||
return true;
|
||||
}
|
||||
|
||||
default int priority() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
class Parameter {
|
||||
private final Type type;
|
||||
private final boolean isConstant;
|
||||
|
||||
public Parameter(Type type, boolean isConstant) {
|
||||
this.type = type;
|
||||
this.isConstant = isConstant;
|
||||
}
|
||||
|
||||
public Parameter(Type type) {
|
||||
this(type, false);
|
||||
}
|
||||
|
||||
public Type type() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public boolean constant() {
|
||||
return this.isConstant;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof Parameter p) {
|
||||
return Objects.equals(type, p.type) && Objects.equals(isConstant, p.isConstant);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(type) + 3192 + Objects.hashCode(isConstant);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package kroppeb.stareval.function;
|
||||
|
||||
import kroppeb.stareval.expression.Expression;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface V2FFunction extends TypedFunction {
|
||||
float eval();
|
||||
|
||||
@Override
|
||||
default void evaluateTo(Expression[] params, FunctionContext context, FunctionReturn functionReturn) {
|
||||
functionReturn.floatReturn = this.eval();
|
||||
}
|
||||
|
||||
@Override
|
||||
default Type getReturnType() {
|
||||
return Type.Float;
|
||||
}
|
||||
|
||||
@Override
|
||||
default Parameter[] getParameters() {
|
||||
return new Parameter[]{};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package kroppeb.stareval.function;
|
||||
|
||||
import kroppeb.stareval.expression.Expression;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface V2IFunction extends TypedFunction {
|
||||
int eval();
|
||||
|
||||
@Override
|
||||
default void evaluateTo(Expression[] params, FunctionContext context, FunctionReturn functionReturn) {
|
||||
functionReturn.intReturn = this.eval();
|
||||
}
|
||||
|
||||
@Override
|
||||
default Type getReturnType() {
|
||||
return Type.Int;
|
||||
}
|
||||
|
||||
@Override
|
||||
default Parameter[] getParameters() {
|
||||
return new Parameter[]{};
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,15 @@
|
||||
package kroppeb.stareval.parser;
|
||||
|
||||
public class BinaryOp {
|
||||
private final String name;
|
||||
private final int priority;
|
||||
import com.github.bsideup.jabel.Desugar;
|
||||
|
||||
@Desugar
|
||||
public record BinaryOp(String name, int priority) {
|
||||
|
||||
public BinaryOp(String name, int priority) {
|
||||
this.name = name;
|
||||
this.priority = priority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.name + "{" + this.priority + "}";
|
||||
}
|
||||
|
||||
public int getPriority() {
|
||||
return this.priority;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import java.util.Map;
|
||||
|
||||
/**
|
||||
* OpResolver maps the trailing characters identifying an operator to an actual operator.
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
abstract class OpResolver<T> {
|
||||
@@ -27,7 +28,7 @@ abstract class OpResolver<T> {
|
||||
* Adds a new multi-character operator. Calling this with an empty string is equivalent to calling singleChar.
|
||||
*
|
||||
* @param trailing every character after the first character of the operator.
|
||||
* @param op the operator
|
||||
* @param op the operator
|
||||
*/
|
||||
public void multiChar(String trailing, T op) {
|
||||
T previous = map.put(trailing, op);
|
||||
@@ -40,14 +41,14 @@ abstract class OpResolver<T> {
|
||||
public OpResolver<T> build() {
|
||||
if (map.size() > 2) {
|
||||
throw new RuntimeException("unimplemented: Cannot currently build an optimized operator resolver " +
|
||||
"tree when more than two operators start with the same character");
|
||||
"tree when more than two operators start with the same character");
|
||||
}
|
||||
|
||||
T singleChar = map.get("");
|
||||
|
||||
if (singleChar != null) {
|
||||
if (map.size() == 1) {
|
||||
return new SingleChar<>(singleChar);
|
||||
return new OpResolver.SingleChar<>(singleChar);
|
||||
} else {
|
||||
for (Map.Entry<String, T> subEntry : map.entrySet()) {
|
||||
if ("".equals(subEntry.getKey())) {
|
||||
@@ -57,33 +58,33 @@ abstract class OpResolver<T> {
|
||||
|
||||
if (subEntry.getKey().length() != 1) {
|
||||
throw new RuntimeException("unimplemented: Optimized operator resolver trees can " +
|
||||
"currently only be built of operators that contain one or two characters.");
|
||||
"currently only be built of operators that contain one or two characters.");
|
||||
}
|
||||
|
||||
// We can assume that this is the only other entry in the map due to the size check above
|
||||
return new SingleDualChar<>(
|
||||
singleChar,
|
||||
subEntry.getValue(),
|
||||
subEntry.getKey().charAt(0)
|
||||
return new OpResolver.SingleDualChar<>(
|
||||
singleChar,
|
||||
subEntry.getValue(),
|
||||
subEntry.getKey().charAt(0)
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (map.size() > 1) {
|
||||
throw new RuntimeException("unimplemented: Optimized operator resolver trees can currently only " +
|
||||
"handle two operators starting with the same character if one operator is a single character");
|
||||
"handle two operators starting with the same character if one operator is a single character");
|
||||
}
|
||||
|
||||
for (Map.Entry<String, T> subEntry : map.entrySet()) {
|
||||
if (subEntry.getKey().length() != 1) {
|
||||
throw new RuntimeException("unimplemented: Optimized operator resolver trees can " +
|
||||
"currently only be built of operators that contain one or two characters.");
|
||||
"currently only be built of operators that contain one or two characters.");
|
||||
}
|
||||
|
||||
// We can assume that this is the only entry in the map due to the size check above.
|
||||
return new DualChar<>(
|
||||
subEntry.getValue(),
|
||||
subEntry.getKey().charAt(0)
|
||||
return new OpResolver.DualChar<>(
|
||||
subEntry.getValue(),
|
||||
subEntry.getKey().charAt(0)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,9 +60,13 @@ public class Parser {
|
||||
Parser() {
|
||||
}
|
||||
|
||||
public static ExpressionElement parse(String input, ParserOptions options) throws ParseException {
|
||||
return Tokenizer.parse(input, options);
|
||||
}
|
||||
|
||||
private Element peek() {
|
||||
if (!this.stack.isEmpty()) {
|
||||
return this.stack.get(this.stack.size() - 1);
|
||||
return this.stack.get(this.stack.size() - 1);
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -115,6 +119,8 @@ public class Parser {
|
||||
return token;
|
||||
}
|
||||
|
||||
// visitor methods
|
||||
|
||||
/**
|
||||
* Executes following reduce step:
|
||||
* <ul>
|
||||
@@ -134,8 +140,8 @@ public class Parser {
|
||||
|
||||
if (args == null) {
|
||||
throw new MissingTokenException(
|
||||
"Expected an opening bracket '(' before seeing a comma ',' or closing bracket ')'",
|
||||
index
|
||||
"Expected an opening bracket '(' before seeing a comma ',' or closing bracket ')'",
|
||||
index
|
||||
);
|
||||
}
|
||||
|
||||
@@ -143,13 +149,11 @@ public class Parser {
|
||||
((UnfinishedArgsExpression) args).tokens.add(expr);
|
||||
} else {
|
||||
throw new UnexpectedTokenException(
|
||||
"Expected to see an opening bracket '(' or a comma ',' right before an expression followed by a " +
|
||||
"closing bracket ')' or a comma ','", index);
|
||||
"Expected to see an opening bracket '(' or a comma ',' right before an expression followed by a " +
|
||||
"closing bracket ')' or a comma ','", index);
|
||||
}
|
||||
}
|
||||
|
||||
// visitor methods
|
||||
|
||||
void visitId(String id) {
|
||||
this.push(new IdToken(id));
|
||||
}
|
||||
@@ -213,8 +217,8 @@ public class Parser {
|
||||
|
||||
if (!(pop instanceof UnfinishedArgsExpression)) {
|
||||
throw new UnexpectedTokenException(
|
||||
"Expected to see an opening bracket '(' or a comma ',' right before an expression followed by a " +
|
||||
"closing bracket ')' or a comma ','", index);
|
||||
"Expected to see an opening bracket '(' or a comma ',' right before an expression followed by a " +
|
||||
"closing bracket ')' or a comma ','", index);
|
||||
}
|
||||
args = (UnfinishedArgsExpression) pop;
|
||||
}
|
||||
@@ -256,7 +260,7 @@ public class Parser {
|
||||
*/
|
||||
void visitBinaryOperator(BinaryOp binaryOp) {
|
||||
// reduce the expressions to the needed priority level
|
||||
ExpressionElement left = this.expressionReducePop(binaryOp.getPriority());
|
||||
ExpressionElement left = this.expressionReducePop(binaryOp.priority());
|
||||
// stack[ {'a', '*'}, 'b'], token = '+' -> stack[], left = {'a', '*', 'b'}
|
||||
// -> stack[{{'a', '*', 'b'}, '+'}]
|
||||
// stack[ {'a', '+'}, 'b'], token = '+' -> stack[], left = {'a', '+', 'b'}
|
||||
@@ -287,8 +291,8 @@ public class Parser {
|
||||
throw new MissingTokenException("Expected a closing bracket", endIndex);
|
||||
} else {
|
||||
throw new UnexpectedTokenException(
|
||||
"The stack of tokens isn't empty at the end of the expression: " + this.stack +
|
||||
" top: " + result, endIndex);
|
||||
"The stack of tokens isn't empty at the end of the expression: " + this.stack +
|
||||
" top: " + result, endIndex);
|
||||
}
|
||||
} else {
|
||||
Element top = this.peek();
|
||||
@@ -296,20 +300,16 @@ public class Parser {
|
||||
throw new MissingTokenException("Expected a closing bracket", endIndex);
|
||||
} else if (top instanceof PriorityOperatorElement) {
|
||||
throw new MissingTokenException(
|
||||
"Expected a identifier, constant or subexpression on the right side of the operator",
|
||||
endIndex);
|
||||
"Expected a identifier, constant or subexpression on the right side of the operator",
|
||||
endIndex);
|
||||
} else {
|
||||
throw new UnexpectedTokenException(
|
||||
"The stack of tokens contains an unexpected token at the top: " + this.stack,
|
||||
endIndex);
|
||||
"The stack of tokens contains an unexpected token at the top: " + this.stack,
|
||||
endIndex);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new MissingTokenException("The input seems to be empty", endIndex);
|
||||
}
|
||||
}
|
||||
|
||||
public static ExpressionElement parse(String input, ParserOptions options) throws ParseException {
|
||||
return Tokenizer.parse(input, options);
|
||||
}
|
||||
}
|
||||
@@ -9,9 +9,9 @@ public final class ParserOptions {
|
||||
private final TokenRules tokenRules;
|
||||
|
||||
private ParserOptions(
|
||||
Char2ObjectMap<? extends OpResolver<? extends UnaryOp>> unaryOpResolvers,
|
||||
Char2ObjectMap<? extends OpResolver<? extends BinaryOp>> binaryOpResolvers,
|
||||
TokenRules tokenRules) {
|
||||
Char2ObjectMap<? extends OpResolver<? extends UnaryOp>> unaryOpResolvers,
|
||||
Char2ObjectMap<? extends OpResolver<? extends BinaryOp>> binaryOpResolvers,
|
||||
TokenRules tokenRules) {
|
||||
this.unaryOpResolvers = unaryOpResolvers;
|
||||
this.binaryOpResolvers = binaryOpResolvers;
|
||||
this.tokenRules = tokenRules;
|
||||
@@ -29,52 +29,12 @@ public final class ParserOptions {
|
||||
return this.binaryOpResolvers.get(c);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private final Char2ObjectMap<OpResolver.Builder<UnaryOp>> unaryOpResolvers = new Char2ObjectOpenHashMap<>();
|
||||
private final Char2ObjectMap<OpResolver.Builder<BinaryOp>> binaryOpResolvers = new Char2ObjectOpenHashMap<>();
|
||||
private TokenRules tokenRules = TokenRules.DEFAULT;
|
||||
|
||||
public void addUnaryOp(String s, UnaryOp op) {
|
||||
char first = s.charAt(0);
|
||||
String trailing = s.substring(1);
|
||||
|
||||
this.unaryOpResolvers.computeIfAbsent(first, (c) -> new OpResolver.Builder<>()).multiChar(trailing, op);
|
||||
}
|
||||
|
||||
public void addBinaryOp(String s, BinaryOp op) {
|
||||
char first = s.charAt(0);
|
||||
String trailing = s.substring(1);
|
||||
|
||||
this.binaryOpResolvers.computeIfAbsent(first, (c) -> new OpResolver.Builder<>()).multiChar(trailing, op);
|
||||
}
|
||||
|
||||
public void setTokenRules(TokenRules tokenRules) {
|
||||
this.tokenRules = tokenRules;
|
||||
}
|
||||
|
||||
private static <T> Char2ObjectMap<? extends OpResolver<? extends T>> buildOpResolvers(
|
||||
Char2ObjectMap<OpResolver.Builder<T>> ops) {
|
||||
Char2ObjectMap<OpResolver<T>> result = new Char2ObjectOpenHashMap<>();
|
||||
|
||||
ops.char2ObjectEntrySet().forEach(
|
||||
entry -> result.put(entry.getCharKey(), entry.getValue().build()));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public ParserOptions build() {
|
||||
return new ParserOptions(
|
||||
buildOpResolvers(this.unaryOpResolvers),
|
||||
buildOpResolvers(this.binaryOpResolvers),
|
||||
this.tokenRules);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines a set of rules that allows the tokenizer to identify tokens within a string.
|
||||
*/
|
||||
public interface TokenRules {
|
||||
TokenRules DEFAULT = new TokenRules() {};
|
||||
TokenRules DEFAULT = new TokenRules() {
|
||||
};
|
||||
|
||||
static boolean isNumber(final char c) {
|
||||
return c >= '0' && c <= '9';
|
||||
@@ -116,4 +76,45 @@ public final class ParserOptions {
|
||||
return this.isAccessStart(c);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private final Char2ObjectMap<OpResolver.Builder<UnaryOp>> unaryOpResolvers = new Char2ObjectOpenHashMap<>();
|
||||
private final Char2ObjectMap<OpResolver.Builder<BinaryOp>> binaryOpResolvers = new Char2ObjectOpenHashMap<>();
|
||||
private TokenRules tokenRules = TokenRules.DEFAULT;
|
||||
|
||||
private static <T> Char2ObjectMap<? extends OpResolver<? extends T>> buildOpResolvers(
|
||||
Char2ObjectMap<OpResolver.Builder<T>> ops) {
|
||||
Char2ObjectMap<OpResolver<T>> result = new Char2ObjectOpenHashMap<>();
|
||||
|
||||
ops.char2ObjectEntrySet().forEach(
|
||||
entry -> result.put(entry.getCharKey(), entry.getValue().build()));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void addUnaryOp(String s, UnaryOp op) {
|
||||
char first = s.charAt(0);
|
||||
String trailing = s.substring(1);
|
||||
|
||||
this.unaryOpResolvers.computeIfAbsent(first, (c) -> new OpResolver.Builder<>()).multiChar(trailing, op);
|
||||
}
|
||||
|
||||
public void addBinaryOp(String s, BinaryOp op) {
|
||||
char first = s.charAt(0);
|
||||
String trailing = s.substring(1);
|
||||
|
||||
this.binaryOpResolvers.computeIfAbsent(first, (c) -> new OpResolver.Builder<>()).multiChar(trailing, op);
|
||||
}
|
||||
|
||||
public void setTokenRules(TokenRules tokenRules) {
|
||||
this.tokenRules = tokenRules;
|
||||
}
|
||||
|
||||
public ParserOptions build() {
|
||||
return new ParserOptions(
|
||||
buildOpResolvers(this.unaryOpResolvers),
|
||||
buildOpResolvers(this.binaryOpResolvers),
|
||||
this.tokenRules);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
package kroppeb.stareval.parser;
|
||||
|
||||
public class UnaryOp {
|
||||
private final String name;
|
||||
import com.github.bsideup.jabel.Desugar;
|
||||
|
||||
@Desugar
|
||||
public record UnaryOp(String name) {
|
||||
|
||||
public UnaryOp(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
@@ -0,0 +1,320 @@
|
||||
package kroppeb.stareval.resolver;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||
import kroppeb.stareval.element.ExpressionElement;
|
||||
import kroppeb.stareval.element.token.IdToken;
|
||||
import kroppeb.stareval.element.token.NumberToken;
|
||||
import kroppeb.stareval.element.tree.AccessExpressionElement;
|
||||
import kroppeb.stareval.element.tree.BinaryExpressionElement;
|
||||
import kroppeb.stareval.element.tree.FunctionCall;
|
||||
import kroppeb.stareval.element.tree.UnaryExpressionElement;
|
||||
import kroppeb.stareval.expression.CallExpression;
|
||||
import kroppeb.stareval.expression.ConstantExpression;
|
||||
import kroppeb.stareval.expression.Expression;
|
||||
import kroppeb.stareval.expression.VariableExpression;
|
||||
import kroppeb.stareval.function.FunctionContext;
|
||||
import kroppeb.stareval.function.FunctionResolver;
|
||||
import kroppeb.stareval.function.FunctionReturn;
|
||||
import kroppeb.stareval.function.Type;
|
||||
import kroppeb.stareval.function.TypedFunction;
|
||||
import kroppeb.stareval.function.TypedFunction.Parameter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class ExpressionResolver {
|
||||
private final FunctionResolver functionResolver;
|
||||
private final Function<String, Type> variableTypeMap;
|
||||
private final boolean enableDebugging;
|
||||
private final Map<String, ConstantExpression> numbers = new Object2ObjectOpenHashMap<>();
|
||||
private List<String> logs;
|
||||
|
||||
public ExpressionResolver(FunctionResolver functionResolver, Function<String, Type> variableTypeMap) {
|
||||
this(functionResolver, variableTypeMap, false);
|
||||
}
|
||||
|
||||
|
||||
public ExpressionResolver(FunctionResolver functionResolver, Function<String, Type> variableTypeMap, boolean enableDebugging) {
|
||||
this.functionResolver = functionResolver;
|
||||
this.variableTypeMap = variableTypeMap;
|
||||
this.enableDebugging = enableDebugging;
|
||||
}
|
||||
|
||||
public Expression resolveExpression(Type targetType, ExpressionElement expression) {
|
||||
this.clearLogs();
|
||||
Expression result = this.resolveExpressionInternal(targetType, expression, true, true);
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
throw new RuntimeException("Couldn't resolve: \n" + String.join("\n", this.extractLogs()));
|
||||
}
|
||||
|
||||
Expression resolveCallExpressionInternal(
|
||||
Type targetType,
|
||||
String name,
|
||||
List<? extends ExpressionElement> inner,
|
||||
boolean implicit
|
||||
) {
|
||||
int innerLength = inner.size();
|
||||
Expression result = null;
|
||||
TypedFunction resultFunction = null;
|
||||
functions:
|
||||
for (TypedFunction f : this.functionResolver.resolve(name, targetType)) {
|
||||
Parameter[] paramTypes = f.getParameters();
|
||||
if (paramTypes.length != innerLength)
|
||||
continue;
|
||||
|
||||
Expression[] params = new Expression[innerLength];
|
||||
for (int i = 0; i < innerLength; i++) {
|
||||
ExpressionElement paramExpression = inner.get(i);
|
||||
Parameter param = paramTypes[i];
|
||||
if (param.constant() && !(paramExpression instanceof NumberToken)) {
|
||||
// not a constant
|
||||
continue functions;
|
||||
}
|
||||
|
||||
Expression expression = this.resolveExpressionInternal(param.type(), paramExpression,
|
||||
!implicit || innerLength > 1, implicit);
|
||||
if (expression == null)
|
||||
continue functions;
|
||||
params[i] = expression;
|
||||
}
|
||||
// FIXME
|
||||
if (result != null && f.priority() == resultFunction.priority()) {
|
||||
throw new RuntimeException("Ambiguity, \n\told: " + TypedFunction.format(resultFunction, "") + "\n\tnew: " + TypedFunction.format(f, ""));
|
||||
} else if (resultFunction == null || f.priority() >= resultFunction.priority()) {
|
||||
result = new CallExpression(f, params);
|
||||
resultFunction = f;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Expression resolveCallExpression(
|
||||
Type targetType,
|
||||
String name,
|
||||
List<? extends ExpressionElement> inner,
|
||||
boolean allowNonImplicit,
|
||||
boolean allowImplicit) {
|
||||
|
||||
this.log("[DEBUG] resolving function %s with args %s to type %s",
|
||||
name, inner, targetType);
|
||||
|
||||
Expression result = null;
|
||||
|
||||
if (allowNonImplicit) {
|
||||
result = this.resolveCallExpressionInternal(targetType, name, inner, false);
|
||||
}
|
||||
|
||||
if (result != null) {
|
||||
this.log("[DEBUG] resolved function %s with args %s to type %s directly",
|
||||
name, inner, targetType);
|
||||
return result;
|
||||
} else if (!allowImplicit) {
|
||||
this.log("[DEBUG] Failed to resolve function %s with args %s to type %s directly",
|
||||
name, inner, targetType);
|
||||
return null;
|
||||
}
|
||||
|
||||
List<? extends TypedFunction> casts = this.functionResolver.resolve("<cast>", targetType);
|
||||
|
||||
for (TypedFunction f : casts) {
|
||||
Expression u = this.resolveCallExpression(f.getParameters()[0].type(), name, inner, true, true);
|
||||
if (u == null)
|
||||
continue;
|
||||
if (result != null)
|
||||
throw new RuntimeException("Ambiguity");
|
||||
result = new CallExpression(f, new Expression[]{u});
|
||||
}
|
||||
if (result != null) {
|
||||
this.log("[DEBUG] resolved function %s with args %s to type %s using only final cast",
|
||||
name, inner, targetType);
|
||||
return result;
|
||||
}
|
||||
|
||||
result = this.resolveCallExpressionInternal(targetType, name, inner, true);
|
||||
if (result != null) {
|
||||
this.log("[DEBUG] resolved function %s with args %s to type %s using implicit inner casts",
|
||||
name, inner, targetType);
|
||||
} else {
|
||||
this.log("[DEBUG] failed to resolve function %s with args %s to type %s",
|
||||
name, inner, targetType);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<String> extractLogs() {
|
||||
List<String> old = this.logs;
|
||||
this.clearLogs();
|
||||
return old;
|
||||
}
|
||||
|
||||
public void clearLogs() {
|
||||
this.logs = new ArrayList<>();
|
||||
}
|
||||
|
||||
private void log(String str) {
|
||||
if (this.enableDebugging)
|
||||
this.logs.add(str);
|
||||
}
|
||||
|
||||
private void log(String str, Object... args) {
|
||||
if (this.enableDebugging)
|
||||
this.logs.add(String.format(str, args));
|
||||
}
|
||||
|
||||
private void log(Supplier<String> str) {
|
||||
if (this.enableDebugging)
|
||||
this.log(str.get());
|
||||
}
|
||||
|
||||
private Expression resolveExpressionInternal(
|
||||
Type targetType,
|
||||
ExpressionElement expression,
|
||||
boolean allowNonImplicit,
|
||||
boolean allowImplicit) {
|
||||
Expression castable;
|
||||
Type innerType;
|
||||
|
||||
this.log("[DEBUG] resolving %s to type %s (%d%d)",
|
||||
expression, targetType, allowNonImplicit ? 1 : 0, allowImplicit ? 1 : 0);
|
||||
|
||||
if (expression instanceof UnaryExpressionElement token) {
|
||||
return this.resolveCallExpression(targetType, token.op().name(), Collections.singletonList(token.inner()),
|
||||
allowNonImplicit, allowImplicit);
|
||||
} else if (expression instanceof BinaryExpressionElement token) {
|
||||
return this.resolveCallExpression(targetType, token.op().name(), Arrays.asList(token.left(), token.right()),
|
||||
allowNonImplicit, allowImplicit);
|
||||
} else if (expression instanceof FunctionCall token) {
|
||||
return this.resolveCallExpression(targetType, token.id(), token.args(),
|
||||
allowNonImplicit, allowImplicit);
|
||||
} else if (expression instanceof AccessExpressionElement token) {
|
||||
return this.resolveCallExpression(targetType, "<access$" + token.index() + ">",
|
||||
Collections.singletonList(token.base()),
|
||||
allowNonImplicit, allowImplicit);
|
||||
} else if (expression instanceof NumberToken token) {
|
||||
ConstantExpression exp = this.resolveNumber(token.getNumber());
|
||||
if (exp.getType().equals(targetType)) {
|
||||
this.log("[DEBUG] resolved constant %s to type %s", token.getNumber(), targetType);
|
||||
return exp;
|
||||
}
|
||||
// TODO: implicit casting is split up too much
|
||||
if (!allowImplicit) {
|
||||
this.log("[DEBUG] failed to resolve constant %s (of type %s) to type %s without implicit casts",
|
||||
token.getNumber(), exp.getType(), targetType);
|
||||
return null;
|
||||
}
|
||||
this.log("[DEBUG] trying implicit casts to resolve constant %s (of type %s) to type %s",
|
||||
token.getNumber(), exp.getType(), targetType);
|
||||
castable = exp;
|
||||
innerType = exp.getType();
|
||||
} else if (expression instanceof IdToken token) {
|
||||
final String name = token.getId();
|
||||
Type type = this.variableTypeMap.apply(name);
|
||||
if (type == null)
|
||||
throw new RuntimeException("Unknown variable: " + name);
|
||||
if (type.equals(targetType)) {
|
||||
log("[DEBUG] resolved variable %s to type %s", name, targetType);
|
||||
// TODO: We should add a variable provider (and have this as default)
|
||||
// doing so would remove the need for a FunctionContext.
|
||||
return new VariableExpression() {
|
||||
@Override
|
||||
public void evaluateTo(FunctionContext c, FunctionReturn r) {
|
||||
c.getVariable(name).evaluateTo(c, r);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression partialEval(FunctionContext context, FunctionReturn functionReturn) {
|
||||
return context.hasVariable(name) ? context.getVariable(name) : this;
|
||||
}
|
||||
};
|
||||
}
|
||||
if (!allowImplicit) {
|
||||
log("[DEBUG] failed to resolve variable %s (of type %s) to type %s without implicit casts",
|
||||
name, type, targetType);
|
||||
return null;
|
||||
}
|
||||
// TODO duplicate of above
|
||||
castable = new VariableExpression() {
|
||||
@Override
|
||||
public void evaluateTo(FunctionContext c, FunctionReturn r) {
|
||||
c.getVariable(name).evaluateTo(c, r);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression partialEval(FunctionContext context, FunctionReturn functionReturn) {
|
||||
return context.hasVariable(name) ? context.getVariable(name) : this;
|
||||
}
|
||||
};
|
||||
innerType = type;
|
||||
} else {
|
||||
throw new RuntimeException("unexpected token: " + expression.toString());
|
||||
}
|
||||
|
||||
List<? extends TypedFunction> casts = this.functionResolver.resolve("<cast>", targetType);
|
||||
|
||||
for (TypedFunction f : casts) {
|
||||
if (f.getParameters()[0].type().equals(innerType)) {
|
||||
this.log("[DEBUG] resolved %s to type %s using implicit casts",
|
||||
expression, targetType);
|
||||
return new CallExpression(f, new Expression[]{castable});
|
||||
}
|
||||
}
|
||||
this.log("[DEBUG] failed to resolved %s to type %s, even using implicit casts", expression, targetType);
|
||||
return null;
|
||||
}
|
||||
|
||||
private ConstantExpression resolveNumber(String s) {
|
||||
return this.numbers.computeIfAbsent(s, str -> {
|
||||
NumberFormatException p;
|
||||
try {
|
||||
final int val;
|
||||
if (str.length() >= 2 && str.charAt(0) == '0') {
|
||||
switch (str.charAt(1)) {
|
||||
case 'b': {
|
||||
val = Integer.parseInt(str.substring(2), 2);
|
||||
break;
|
||||
}
|
||||
case 'x': {
|
||||
val = Integer.parseInt(str.substring(2), 16);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
val = Integer.parseInt(str.substring(1), 8);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else
|
||||
val = Integer.parseInt(str);
|
||||
|
||||
return new ConstantExpression(Type.Int) {
|
||||
@Override
|
||||
public void evaluateTo(FunctionContext context, FunctionReturn functionReturn) {
|
||||
functionReturn.intReturn = val;
|
||||
}
|
||||
};
|
||||
} catch (NumberFormatException ex) {
|
||||
p = ex;
|
||||
}
|
||||
|
||||
try {
|
||||
final float res = Float.parseFloat(str);
|
||||
return new ConstantExpression(Type.Float) {
|
||||
@Override
|
||||
public void evaluateTo(FunctionContext context, FunctionReturn functionReturn) {
|
||||
functionReturn.floatReturn = res;
|
||||
}
|
||||
};
|
||||
} catch (NumberFormatException ex) {
|
||||
RuntimeException exception = new RuntimeException("Illegal number: " + str, ex);
|
||||
exception.addSuppressed(p);
|
||||
throw exception;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -17,7 +17,7 @@ public class ChunkModelVertexTransformer extends AbstractVertexTransformer<Model
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeQuad(float x, float y, float z, int color, float u, float v, int light) {
|
||||
this.delegate.writeQuad(x + this.offset.x, y + this.offset.y, z + this.offset.z, color, u, v, light);
|
||||
public void writeQuad(float x, float y, float z, int color, float u, float v, int light, int shaderBlockId) {
|
||||
this.delegate.writeQuad(x + this.offset.x, y + this.offset.y, z + this.offset.z, color, u, v, light, shaderBlockId);
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -12,6 +12,7 @@ public interface ModelVertexSink extends VertexSink {
|
||||
* @param u The u-texture of the vertex
|
||||
* @param v The y-texture of the vertex
|
||||
* @param light The packed light-map coordinates of the vertex
|
||||
* @param shaderBlockId The blockId to be passed to the shader
|
||||
*/
|
||||
void writeQuad(float x, float y, float z, int color, float u, float v, int light);
|
||||
void writeQuad(float x, float y, float z, int color, float u, float v, int light, int shaderBlockId);
|
||||
}
|
||||
+1
-1
@@ -14,7 +14,7 @@ public class HFPModelVertexBufferWriterNio extends VertexBufferWriterNio impleme
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeQuad(float x, float y, float z, int color, float u, float v, int light) {
|
||||
public void writeQuad(float x, float y, float z, int color, float u, float v, int light, int shaderBlockId) {
|
||||
this.writeQuadInternal(
|
||||
ModelVertexUtil.denormalizeVertexPositionFloatAsShort(x),
|
||||
ModelVertexUtil.denormalizeVertexPositionFloatAsShort(y),
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ public class HFPModelVertexBufferWriterUnsafe extends VertexBufferWriterUnsafe i
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeQuad(float x, float y, float z, int color, float u, float v, int light) {
|
||||
public void writeQuad(float x, float y, float z, int color, float u, float v, int light, int shaderBlockId) {
|
||||
this.writeQuadInternal(
|
||||
ModelVertexUtil.denormalizeVertexPositionFloatAsShort(x),
|
||||
ModelVertexUtil.denormalizeVertexPositionFloatAsShort(y),
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ public class SFPModelVertexBufferWriterNio extends VertexBufferWriterNio impleme
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeQuad(float x, float y, float z, int color, float u, float v, int light) {
|
||||
public void writeQuad(float x, float y, float z, int color, float u, float v, int light, int shaderBlockId) {
|
||||
int i = this.writeOffset;
|
||||
|
||||
ByteBuffer buffer = this.byteBuffer;
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ public class SFPModelVertexBufferWriterUnsafe extends VertexBufferWriterUnsafe i
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeQuad(float x, float y, float z, int color, float u, float v, int light) {
|
||||
public void writeQuad(float x, float y, float z, int color, float u, float v, int light, int shaderBlockId) {
|
||||
long i = this.writePointer;
|
||||
|
||||
memPutFloat(i, x);
|
||||
|
||||
+18
-2
@@ -2,6 +2,7 @@ package me.jellysquid.mods.sodium.client.render.chunk.tasks;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.blockpos.BlockPos;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.util.WorldUtil;
|
||||
import com.gtnewhorizons.angelica.compat.ModStatus;
|
||||
import com.gtnewhorizons.angelica.compat.mojang.ChunkOcclusionDataBuilder;
|
||||
import com.gtnewhorizons.angelica.compat.toremove.RenderLayer;
|
||||
import com.gtnewhorizons.angelica.config.AngelicaConfig;
|
||||
@@ -36,6 +37,7 @@ import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import org.joml.Vector3d;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -155,6 +157,11 @@ public class ChunkRenderRebuildTask<T extends ChunkGraphicsState> extends ChunkR
|
||||
|
||||
for (int relZ = 0; relZ < 16; relZ++) {
|
||||
for (int relX = 0; relX < 16; relX++) {
|
||||
Fluid fluid = null;
|
||||
if (ModStatus.isFluidLoggedLoaded) {
|
||||
fluid = slice.getFluidRelative(relX + 16, relY + 16, relZ + 16);
|
||||
}
|
||||
|
||||
final Block block = slice.getBlockRelative(relX + 16, relY + 16, relZ + 16);
|
||||
|
||||
// If the block is vanilla air, assume it renders nothing. Don't use isAir because mods
|
||||
@@ -172,10 +179,18 @@ public class ChunkRenderRebuildTask<T extends ChunkGraphicsState> extends ChunkR
|
||||
|
||||
if (rendersOffThread(block)) {
|
||||
// Do regular block rendering
|
||||
final long seed = MathUtil.hashPos(pos.x, pos.y, pos.z);
|
||||
for (BlockRenderPass pass : BlockRenderPass.VALUES) {
|
||||
if (ModStatus.isFluidLoggedLoaded) {
|
||||
if (fluid != null && canRenderInPass(fluid.getBlock(), pass)) {
|
||||
ChunkRenderManager.setWorldRenderPass(pass);
|
||||
if(AngelicaConfig.enableIris) buffers.iris$setMaterialId(fluid.getBlock(), ExtendedDataHelper.FLUID_RENDER_TYPE);
|
||||
|
||||
cache.getBlockRenderer().renderFluidLogged(fluid, renderBlocks, pos, buffers.get(pass), seed);
|
||||
}
|
||||
}
|
||||
if (canRenderInPass(block, pass) && !shouldUseSodiumFluidRendering(block)) {
|
||||
ChunkRenderManager.setWorldRenderPass(pass);
|
||||
final long seed = MathUtil.hashPos(pos.x, pos.y, pos.z);
|
||||
if(AngelicaConfig.enableIris) buffers.iris$setMaterialId(block, ExtendedDataHelper.BLOCK_RENDER_TYPE);
|
||||
|
||||
if (cache.getBlockRenderer().renderModel(cache.getWorldSlice(), renderBlocks, block, meta, pos, buffers.get(pass), true, seed)) {
|
||||
@@ -183,6 +198,7 @@ public class ChunkRenderRebuildTask<T extends ChunkGraphicsState> extends ChunkR
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
mainThreadBlocks.enqueue(pos.asLong());
|
||||
hasMainThreadBlocks = true;
|
||||
@@ -339,6 +355,6 @@ public class ChunkRenderRebuildTask<T extends ChunkGraphicsState> extends ChunkR
|
||||
}
|
||||
|
||||
private static boolean shouldUseSodiumFluidRendering(Block block) {
|
||||
return AngelicaConfig.enableSodiumFluidRendering && WorldUtil.isFluidBlock(block);
|
||||
return AngelicaConfig.enableSodiumFluidRendering && WorldUtil.isFluidBlock(block) && !ModStatus.isFluidLoggedLoaded;
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,7 @@ import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
@@ -62,13 +63,54 @@ public class BlockRenderer {
|
||||
this.occlusionCache = new BlockOcclusionCache();
|
||||
}
|
||||
|
||||
public boolean renderFluidLogged(Fluid fluid, RenderBlocks renderBlocks, BlockPos pos, ChunkModelBuffers buffers, long seed) {
|
||||
if (fluid == null) {
|
||||
return false;
|
||||
}
|
||||
Block block = fluid.getBlock();
|
||||
if (block == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean rendered = false;
|
||||
|
||||
try {
|
||||
final LightMode mode = LightMode.SMOOTH; // TODO: this.getLightingMode(block); is what was previously used. The flat pipeline is busted and was only an optimization for very few blocks.
|
||||
final LightPipeline lighter = this.lighters.getLighter(mode);
|
||||
|
||||
TessellatorManager.startCapturing();
|
||||
final CapturingTessellator tess = (CapturingTessellator) TessellatorManager.get();
|
||||
tess.startDrawingQuads();
|
||||
// Use setTranslation rather than setOffset so that the float data written to the internal buffer
|
||||
// is done in subchunk-relative coordinates
|
||||
tess.setOffset(POS_ZERO);
|
||||
tess.setTranslation(-pos.x, -pos.y, -pos.z);
|
||||
renderBlocks.renderBlockByRenderType(block, pos.x, pos.y, pos.z);
|
||||
final List<QuadView> quads = TessellatorManager.stopCapturingToPooledQuads();
|
||||
tess.resetOffset();
|
||||
|
||||
for (ModelQuadFacing facing : ModelQuadFacing.VALUES) {
|
||||
this.random.setSeed(seed);
|
||||
this.renderQuadList(pos, lighter, buffers, quads, facing, (this.useAmbientOcclusion && this.useSodiumAO));
|
||||
}
|
||||
|
||||
if (!quads.isEmpty()) rendered = true;
|
||||
} finally {
|
||||
TessellatorManager.cleanup();
|
||||
}
|
||||
|
||||
return rendered;
|
||||
|
||||
}
|
||||
|
||||
public boolean renderModel(IBlockAccess world, RenderBlocks renderBlocks, Block block, int meta, BlockPos pos, ChunkModelBuffers buffers, boolean cull, long seed) {
|
||||
final LightMode mode = LightMode.SMOOTH; // TODO: this.getLightingMode(block); is what was previously used. The flat pipeline is busted and was only an optimization for very few blocks.
|
||||
final LightPipeline lighter = this.lighters.getLighter(mode);
|
||||
|
||||
boolean rendered = false;
|
||||
|
||||
this.useSeparateAo = AngelicaConfig.enableIris && BlockRenderingSettings.INSTANCE.shouldUseSeparateAo();
|
||||
|
||||
boolean rendered = false;
|
||||
final QuadProvider model = ((ModeledBlock) block).getModel();
|
||||
|
||||
if (model != null) {
|
||||
@@ -150,6 +192,7 @@ public class BlockRenderer {
|
||||
|
||||
final ModelQuadOrientation order = (useSodiumLight || this.useSeparateAo) ? ModelQuadOrientation.orient(light.br) : ModelQuadOrientation.NORMAL;
|
||||
|
||||
int shaderBlockId = quad.getShaderBlockId();
|
||||
for (int dstIndex = 0; dstIndex < 4; dstIndex++) {
|
||||
final int srcIndex = order.getVertexIndex(dstIndex);
|
||||
|
||||
@@ -173,7 +216,7 @@ public class BlockRenderer {
|
||||
final int lm = (useSeparateAo) ? ModelQuadUtil.mergeBakedLight(quad.getLight(srcIndex), light.lm[srcIndex]) :
|
||||
(useSodiumLight) ? light.lm[srcIndex] : quad.getLight(srcIndex);
|
||||
|
||||
sink.writeQuad(x, y, z, color, u, v, lm);
|
||||
sink.writeQuad(x, y, z, color, u, v, lm, shaderBlockId);
|
||||
}
|
||||
|
||||
final TextureAtlasSprite sprite = quad.rubidium$getSprite();
|
||||
|
||||
@@ -405,7 +405,7 @@ public class FluidRenderer {
|
||||
|
||||
int light = this.quadLightData.lm[vertexIdx];
|
||||
|
||||
sink.writeQuad(x, y, z, color, u, v, light);
|
||||
sink.writeQuad(x, y, z, color, u, v, light, -1);
|
||||
|
||||
vertexIdx += lightOrder;
|
||||
}
|
||||
|
||||
@@ -3,13 +3,16 @@ package me.jellysquid.mods.sodium.client.world;
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.gtnewhorizons.angelica.api.IBlockAccessExtended;
|
||||
import com.gtnewhorizons.angelica.compat.ModStatus;
|
||||
import com.gtnewhorizons.angelica.compat.mojang.ChunkSectionPos;
|
||||
import com.gtnewhorizons.angelica.compat.mojang.CompatMathHelper;
|
||||
import com.gtnewhorizons.angelica.dynamiclights.DynamicLights;
|
||||
import cpw.mods.fml.common.Optional;
|
||||
import lombok.Getter;
|
||||
import me.jellysquid.mods.sodium.client.world.cloned.ChunkRenderContext;
|
||||
import me.jellysquid.mods.sodium.client.world.cloned.ClonedChunkSection;
|
||||
import me.jellysquid.mods.sodium.client.world.cloned.ClonedChunkSectionCache;
|
||||
import mega.fluidlogged.api.FLBlockAccess;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.multiplayer.WorldClient;
|
||||
import net.minecraft.init.Blocks;
|
||||
@@ -24,6 +27,8 @@ import net.minecraft.world.chunk.NibbleArray;
|
||||
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
|
||||
import net.minecraft.world.gen.structure.StructureBoundingBox;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Takes a slice of world state (block states, biome and light data arrays) and copies the data for use in off-thread
|
||||
@@ -35,7 +40,8 @@ import net.minecraftforge.common.util.ForgeDirection;
|
||||
*
|
||||
* Object pooling should be used to avoid huge allocations as this class contains many large arrays.
|
||||
*/
|
||||
public class WorldSlice implements IBlockAccessExtended {
|
||||
@Optional.Interface(iface = "mega.fluidlogged.api.FLBlockAccess", modid = "fluidlogged")
|
||||
public class WorldSlice implements IBlockAccessExtended, FLBlockAccess {
|
||||
private static final EnumSkyBlock[] LIGHT_TYPES = EnumSkyBlock.values();
|
||||
|
||||
// The number of blocks on each axis in a section.
|
||||
@@ -68,6 +74,7 @@ public class WorldSlice implements IBlockAccessExtended {
|
||||
|
||||
// Local Section->BlockState table.
|
||||
private final Block[][] blockArrays;
|
||||
private final Fluid[][] fluidArrays;
|
||||
private final int[][] metadataArrays;
|
||||
|
||||
// Local Section->Light table
|
||||
@@ -145,6 +152,12 @@ public class WorldSlice implements IBlockAccessExtended {
|
||||
this.biomeData = new BiomeGenBase[SECTION_TABLE_ARRAY_SIZE][];
|
||||
this.lightArrays = new NibbleArray[SECTION_TABLE_ARRAY_SIZE][LIGHT_TYPES.length];
|
||||
|
||||
if (ModStatus.isFluidLoggedLoaded) {
|
||||
this.fluidArrays = new Fluid[SECTION_TABLE_ARRAY_SIZE][];
|
||||
} else {
|
||||
this.fluidArrays = null;
|
||||
}
|
||||
|
||||
for (int x = 0; x < SECTION_LENGTH; x++) {
|
||||
for (int y = 0; y < SECTION_LENGTH; y++) {
|
||||
for (int z = 0; z < SECTION_LENGTH; z++) {
|
||||
@@ -152,6 +165,10 @@ public class WorldSlice implements IBlockAccessExtended {
|
||||
this.blockArrays[i] = new Block[SECTION_BLOCK_COUNT];
|
||||
Arrays.fill(this.blockArrays[i], Blocks.air);
|
||||
this.metadataArrays[i] = new int[SECTION_BLOCK_COUNT];
|
||||
|
||||
if (ModStatus.isFluidLoggedLoaded && this.fluidArrays != null) {
|
||||
this.fluidArrays[i] = new Fluid[SECTION_BLOCK_COUNT];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -175,6 +192,11 @@ public class WorldSlice implements IBlockAccessExtended {
|
||||
final ClonedChunkSection section = this.sections[idx];
|
||||
|
||||
this.unpackBlockData(this.blockArrays[idx], this.metadataArrays[idx], section, context.getVolume());
|
||||
|
||||
if (ModStatus.isFluidLoggedLoaded) {
|
||||
this.unpackFluidLoggedData(this.fluidArrays[idx], section, context.getVolume());
|
||||
}
|
||||
|
||||
this.biomeData[idx] = section.getBiomeData();
|
||||
|
||||
this.lightArrays[idx][EnumSkyBlock.Block.ordinal()] = section.getLightArray(EnumSkyBlock.Block);
|
||||
@@ -191,8 +213,8 @@ public class WorldSlice implements IBlockAccessExtended {
|
||||
return (15 << 20) | (min << 4);
|
||||
}
|
||||
|
||||
final int skyBrightness = this.getSkyBlockTypeBrightness(net.minecraft.world.EnumSkyBlock.Sky, x, y, z);
|
||||
int blockBrightness = this.getSkyBlockTypeBrightness(net.minecraft.world.EnumSkyBlock.Block, x, y, z);
|
||||
final int skyBrightness = this.getSkyBlockTypeBrightness(EnumSkyBlock.Sky, x, y, z);
|
||||
int blockBrightness = this.getSkyBlockTypeBrightness(EnumSkyBlock.Block, x, y, z);
|
||||
|
||||
if (blockBrightness < min) {
|
||||
blockBrightness = min;
|
||||
@@ -265,6 +287,14 @@ public class WorldSlice implements IBlockAccessExtended {
|
||||
return getBlock(x, y, z).isSideSolid(this, x, y, z, side);
|
||||
}
|
||||
|
||||
private void unpackFluidLoggedData(Fluid[] fluids, ClonedChunkSection section, StructureBoundingBox box) {
|
||||
if (this.origin.equals(section.getPosition())) {
|
||||
this.unpackFluidLoggedDataZ(fluids, section);
|
||||
} else {
|
||||
this.unpackFluidLoggedDataR(fluids, section, box);
|
||||
}
|
||||
}
|
||||
|
||||
private void unpackBlockData(Block[] blocks, int[] metas, ClonedChunkSection section, StructureBoundingBox box) {
|
||||
if (this.origin.equals(section.getPosition())) {
|
||||
this.unpackBlockDataZ(blocks, metas, section);
|
||||
@@ -273,6 +303,48 @@ public class WorldSlice implements IBlockAccessExtended {
|
||||
}
|
||||
}
|
||||
|
||||
private void unpackFluidLoggedDataR(Fluid[] fluids, ClonedChunkSection section, StructureBoundingBox box) {
|
||||
final ChunkSectionPos pos = section.getPosition();
|
||||
|
||||
final int minBlockX = Math.max(box.minX, pos.getMinX());
|
||||
final int maxBlockX = Math.min(box.maxX, pos.getMaxX());
|
||||
|
||||
final int minBlockY = Math.max(box.minY, pos.getMinY());
|
||||
final int maxBlockY = Math.min(box.maxY, pos.getMaxY());
|
||||
|
||||
final int minBlockZ = Math.max(box.minZ, pos.getMinZ());
|
||||
final int maxBlockZ = Math.min(box.maxZ, pos.getMaxZ());
|
||||
|
||||
copyFluids(fluids, section, minBlockY, maxBlockY, minBlockZ, maxBlockZ, minBlockX, maxBlockX);
|
||||
}
|
||||
|
||||
private void unpackFluidLoggedDataZ(Fluid[] fluids, ClonedChunkSection section) {
|
||||
// TODO: Look into a faster copy for this?
|
||||
final ChunkSectionPos pos = section.getPosition();
|
||||
|
||||
final int minBlockX = pos.getMinX();
|
||||
final int maxBlockX = pos.getMaxX();
|
||||
|
||||
final int minBlockY = pos.getMinY();
|
||||
final int maxBlockY = pos.getMaxY();
|
||||
|
||||
final int minBlockZ = pos.getMinZ();
|
||||
final int maxBlockZ = pos.getMaxZ();
|
||||
|
||||
// TODO: Can this be optimized?
|
||||
copyFluids(fluids, section, minBlockY, maxBlockY, minBlockZ, maxBlockZ, minBlockX, maxBlockX);
|
||||
}
|
||||
|
||||
private static void copyFluids(Fluid[] fluids, ClonedChunkSection section, int minBlockY, int maxBlockY, int minBlockZ, int maxBlockZ, int minBlockX, int maxBlockX) {
|
||||
for (int y = minBlockY; y <= maxBlockY; y++) {
|
||||
for (int z = minBlockZ; z <= maxBlockZ; z++) {
|
||||
for (int x = minBlockX; x <= maxBlockX; x++) {
|
||||
final int blockIdx = getLocalBlockIndex(x & 15, y & 15, z & 15);
|
||||
fluids[blockIdx] = section.getFluid(x & 15, y & 15, z & 15);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void copyBlocks(Block[] blocks, int[] metas, ClonedChunkSection section, int minBlockY, int maxBlockY, int minBlockZ, int maxBlockZ, int minBlockX, int maxBlockX) {
|
||||
for (int y = minBlockY; y <= maxBlockY; y++) {
|
||||
@@ -419,4 +491,23 @@ public class WorldSlice implements IBlockAccessExtended {
|
||||
z >= box.minZ &&
|
||||
z <= box.maxZ;
|
||||
}
|
||||
|
||||
public @Nullable Fluid fl$getFluid(int x, int y, int z) {
|
||||
if (!blockBoxContains(this.volume, x, y, z)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final int relX = x - this.baseX;
|
||||
final int relY = y - this.baseY;
|
||||
final int relZ = z - this.baseZ;
|
||||
return this.fluidArrays[getLocalSectionIndex(relX >> 4, relY >> 4, relZ >> 4)][getLocalBlockIndex(relX & 15, relY & 15, relZ & 15)];
|
||||
}
|
||||
|
||||
public Fluid getFluidRelative(int x, int y, int z) {
|
||||
return this.fluidArrays[getLocalSectionIndex(x >> 4, y >> 4, z >> 4)][getLocalBlockIndex(x & 15, y & 15, z & 15)];
|
||||
}
|
||||
|
||||
public void fl$setFluid(int x, int y, int z, @Nullable Fluid fluid) {
|
||||
throw new UnsupportedOperationException("Cannot set fluids in a world slice. WorldSlice is read-only");
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import com.gtnewhorizons.angelica.compat.mojang.ChunkSectionPos;
|
||||
import it.unimi.dsi.fastutil.shorts.Short2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.shorts.Short2ObjectOpenHashMap;
|
||||
import lombok.Getter;
|
||||
import mega.fluidlogged.internal.mixin.hook.FLSubChunk;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.EnumSkyBlock;
|
||||
@@ -15,6 +16,7 @@ import net.minecraft.world.biome.BiomeGenBase;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.chunk.NibbleArray;
|
||||
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@@ -102,6 +104,14 @@ public class ClonedChunkSection {
|
||||
return data.getBlockByExtId(x, y, z);
|
||||
}
|
||||
|
||||
public Fluid getFluid(int x, int y, int z) {
|
||||
if (ModStatus.isFluidLoggedLoaded) {
|
||||
return ((FLSubChunk) data).fl$getFluid(x, y, z);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getBlockMetadata(int x, int y, int z) {
|
||||
return data.getExtBlockMetadata(x, y, z);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
package net.coderbot.iris;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.CapturingTessellator;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.TessellatorManager;
|
||||
import com.gtnewhorizons.angelica.AngelicaMod;
|
||||
import com.gtnewhorizons.angelica.Tags;
|
||||
import com.gtnewhorizons.angelica.config.AngelicaConfig;
|
||||
import com.mojang.realmsclient.gui.ChatFormatting;
|
||||
import cpw.mods.fml.client.registry.ClientRegistry;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.InputEvent;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||
import lombok.Getter;
|
||||
import net.coderbot.iris.block_rendering.BlockRenderingSettings;
|
||||
import net.coderbot.iris.config.IrisConfig;
|
||||
import net.coderbot.iris.gl.shader.StandardMacros;
|
||||
import net.coderbot.iris.gui.screen.ShaderPackScreen;
|
||||
@@ -24,7 +29,9 @@ import net.coderbot.iris.shaderpack.option.OptionSet;
|
||||
import net.coderbot.iris.shaderpack.option.Profile;
|
||||
import net.coderbot.iris.shaderpack.option.values.MutableOptionValues;
|
||||
import net.coderbot.iris.shaderpack.option.values.OptionValues;
|
||||
import net.coderbot.iris.sodium.block_context.BlockContextHolder;
|
||||
import net.coderbot.iris.texture.pbr.PBRTextureManager;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.multiplayer.WorldClient;
|
||||
@@ -639,4 +646,36 @@ public class Iris {
|
||||
ClientRegistry.registerKeyBinding(toggleShadersKeybind);
|
||||
ClientRegistry.registerKeyBinding(shaderpackScreenKeybind);
|
||||
}
|
||||
|
||||
static BlockContextHolder contextHolder;
|
||||
|
||||
private static int getShaderMaterialOverrideId(Block block, int meta) {
|
||||
if (contextHolder == null) {
|
||||
final Object2IntMap<Block> blockMatches = BlockRenderingSettings.INSTANCE.getBlockMatches();
|
||||
if (blockMatches == null) {
|
||||
return -1;
|
||||
}
|
||||
contextHolder = new BlockContextHolder(blockMatches);
|
||||
|
||||
}
|
||||
contextHolder.set(block, (short) block.getRenderType());
|
||||
return contextHolder.blockId;
|
||||
}
|
||||
|
||||
public static void setShaderMaterialOverride(Block block, int meta) {
|
||||
if (!AngelicaConfig.enableIris)
|
||||
return;
|
||||
|
||||
int blockId = getShaderMaterialOverrideId(block, meta);
|
||||
|
||||
if (TessellatorManager.get() instanceof CapturingTessellator tess)
|
||||
tess.setShaderBlockId(blockId);
|
||||
}
|
||||
|
||||
public static void resetShaderMaterialOverride() {
|
||||
if (!AngelicaConfig.enableIris)
|
||||
return;
|
||||
if (TessellatorManager.get() instanceof CapturingTessellator tess)
|
||||
tess.setShaderBlockId(-1);
|
||||
}
|
||||
}
|
||||
@@ -57,12 +57,15 @@ public final class ComputeProgram extends GlResource {
|
||||
return cachedWorkGroups;
|
||||
}
|
||||
|
||||
public void dispatch(float width, float height) {
|
||||
GL20.glUseProgram(getGlId());
|
||||
uniforms.update();
|
||||
samplers.update();
|
||||
images.update();
|
||||
public void use() {
|
||||
GL20.glUseProgram(getGlId());
|
||||
|
||||
uniforms.update();
|
||||
samplers.update();
|
||||
images.update();
|
||||
}
|
||||
|
||||
public void dispatch(float width, float height) {
|
||||
if (!Iris.getPipelineManager().getPipeline().map(WorldRenderingPipeline::allowConcurrentCompute).orElse(false)) {
|
||||
RenderSystem.memoryBarrier(40);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.OptionalInt;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.coderbot.iris.Iris;
|
||||
import net.coderbot.iris.gl.state.ValueUpdateNotifier;
|
||||
import net.coderbot.iris.gl.uniform.DynamicLocationalUniformHolder;
|
||||
@@ -20,6 +22,7 @@ import net.coderbot.iris.gl.uniform.UniformUpdateFrequency;
|
||||
import net.coderbot.iris.uniforms.SystemTimeUniforms;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.WorldClient;
|
||||
import org.joml.Vector3i;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.ARBShaderImageLoadStore;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
@@ -172,8 +175,7 @@ public class ProgramUniforms {
|
||||
return OptionalInt.empty();
|
||||
}
|
||||
|
||||
// TODO: Temporary hack until custom uniforms are merged.
|
||||
if ((!locations.containsKey(id) && !uniformNames.containsKey(name)) || name.equals("framemod8")) {
|
||||
if ((!locations.containsKey(id) && !uniformNames.containsKey(name))) {
|
||||
locations.put(id, name);
|
||||
uniformNames.put(name, type);
|
||||
} else {
|
||||
@@ -240,12 +242,6 @@ public class ProgramUniforms {
|
||||
continue;
|
||||
}
|
||||
|
||||
// TODO: This is an absolutely horrific hack, but is needed until custom uniforms work.
|
||||
if ("framemod8".equals(name) && expected == UniformType.FLOAT && provided == UniformType.INT) {
|
||||
SystemTimeUniforms.addFloatFrameMod8Uniform(this);
|
||||
provided = UniformType.FLOAT;
|
||||
}
|
||||
|
||||
if (provided != null && provided != expected) {
|
||||
String expectedName;
|
||||
|
||||
@@ -283,7 +279,7 @@ public class ProgramUniforms {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public UniformHolder externallyManagedUniform(String name, UniformType type) {
|
||||
externalUniformNames.put(name, type);
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package net.coderbot.iris.gl.uniform;
|
||||
|
||||
import net.coderbot.iris.gl.state.ValueUpdateNotifier;
|
||||
import org.joml.Vector2i;
|
||||
import org.joml.Vector3i;
|
||||
import org.joml.Vector4f;
|
||||
import org.joml.Vector4i;
|
||||
|
||||
@@ -42,12 +43,23 @@ public interface DynamicLocationalUniformHolder extends LocationalUniformHolder,
|
||||
return this;
|
||||
}
|
||||
|
||||
default DynamicUniformHolder uniform3i(String name, Supplier<Vector3i> value, ValueUpdateNotifier notifier) {
|
||||
location(name, UniformType.VEC3I).ifPresent(id -> addDynamicUniform(new Vector3IntegerJomlUniform(id, value, notifier), notifier));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
default DynamicUniformHolder uniform4f(String name, Supplier<Vector4f> value, ValueUpdateNotifier notifier) {
|
||||
location(name, UniformType.VEC4).ifPresent(id -> addDynamicUniform(new Vector4Uniform(id, value, notifier), notifier));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
default DynamicUniformHolder uniform4fArray(String name, Supplier<float[]> value, ValueUpdateNotifier notifier) {
|
||||
location(name, UniformType.VEC4).ifPresent(id -> addDynamicUniform(new Vector4ArrayUniform(id, value, notifier), notifier));
|
||||
return this;
|
||||
}
|
||||
|
||||
default DynamicUniformHolder uniform4i(String name, Supplier<Vector4i> value, ValueUpdateNotifier notifier) {
|
||||
location(name, UniformType.VEC4I).ifPresent(id -> addDynamicUniform(new Vector4IntegerJomlUniform(id, value, notifier), notifier));
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package net.coderbot.iris.gl.uniform;
|
||||
|
||||
import net.coderbot.iris.gl.state.ValueUpdateNotifier;
|
||||
import org.joml.Vector2i;
|
||||
import org.joml.Vector3i;
|
||||
import org.joml.Vector4f;
|
||||
import org.joml.Vector4i;
|
||||
|
||||
@@ -15,6 +16,8 @@ public interface DynamicUniformHolder extends UniformHolder {
|
||||
DynamicUniformHolder uniform1f(String name, DoubleSupplier value, ValueUpdateNotifier notifier);
|
||||
DynamicUniformHolder uniform1i(String name, IntSupplier value, ValueUpdateNotifier notifier);
|
||||
DynamicUniformHolder uniform2i(String name, Supplier<Vector2i> value, ValueUpdateNotifier notifier);
|
||||
DynamicUniformHolder uniform3i(String name, Supplier<Vector3i> value, ValueUpdateNotifier notifier);
|
||||
DynamicUniformHolder uniform4f(String name, Supplier<Vector4f> value, ValueUpdateNotifier notifier);
|
||||
DynamicUniformHolder uniform4fArray(String name, Supplier<float[]> value, ValueUpdateNotifier notifier);
|
||||
DynamicUniformHolder uniform4i(String name, Supplier<Vector4i> value, ValueUpdateNotifier notifier);
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import org.joml.Vector2f;
|
||||
import org.joml.Vector2i;
|
||||
import org.joml.Vector3d;
|
||||
import org.joml.Vector3f;
|
||||
import org.joml.Vector3i;
|
||||
import org.joml.Vector4f;
|
||||
|
||||
import java.util.OptionalInt;
|
||||
@@ -75,6 +76,13 @@ public interface LocationalUniformHolder extends UniformHolder {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
default LocationalUniformHolder uniform3i(UniformUpdateFrequency updateFrequency, String name, Supplier<Vector3i> value) {
|
||||
location(name, UniformType.VEC3I).ifPresent(id -> addUniform(updateFrequency, new Vector3IntegerJomlUniform(id, value)));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
default LocationalUniformHolder uniformVanilla3f(UniformUpdateFrequency updateFrequency, String name, Supplier<Vec3> value) {
|
||||
location(name, UniformType.VEC3).ifPresent(id -> addUniform(updateFrequency, new VanillaVector3Uniform(id, value)));
|
||||
@@ -103,6 +111,13 @@ public interface LocationalUniformHolder extends UniformHolder {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
default LocationalUniformHolder uniform4fArray(UniformUpdateFrequency updateFrequency, String name, Supplier<float[]> value) {
|
||||
location(name, UniformType.VEC4).ifPresent(id -> addUniform(updateFrequency, new Vector4ArrayUniform(id, value)));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
default LocationalUniformHolder uniformMatrix(UniformUpdateFrequency updateFrequency, String name, Supplier<Matrix4f> value) {
|
||||
location(name, UniformType.MAT4).ifPresent(id -> addUniform(updateFrequency, new MatrixUniform(id, value)));
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.joml.Vector2f;
|
||||
import org.joml.Vector2i;
|
||||
import org.joml.Vector3d;
|
||||
import org.joml.Vector3f;
|
||||
import org.joml.Vector3i;
|
||||
import org.joml.Vector4f;
|
||||
|
||||
import java.util.function.BooleanSupplier;
|
||||
@@ -30,6 +31,8 @@ public interface UniformHolder {
|
||||
|
||||
UniformHolder uniform3f(UniformUpdateFrequency updateFrequency, String name, Supplier<Vector3f> value);
|
||||
|
||||
UniformHolder uniform3i(UniformUpdateFrequency updateFrequency, String name, Supplier<Vector3i> value);
|
||||
|
||||
UniformHolder uniformVanilla3f(UniformUpdateFrequency updateFrequency, String name, Supplier<Vec3> value);
|
||||
|
||||
UniformHolder uniformTruncated3f(UniformUpdateFrequency updateFrequency, String name, Supplier<Vector4f> value);
|
||||
@@ -38,6 +41,8 @@ public interface UniformHolder {
|
||||
|
||||
UniformHolder uniform4f(UniformUpdateFrequency updateFrequency, String name, Supplier<Vector4f> value);
|
||||
|
||||
UniformHolder uniform4fArray(UniformUpdateFrequency updateFrequency, String name, Supplier<float[]> value);
|
||||
|
||||
UniformHolder uniformMatrix(UniformUpdateFrequency updateFrequency, String name, Supplier<Matrix4f> value);
|
||||
|
||||
UniformHolder uniformMatrixFromArray(UniformUpdateFrequency updateFrequency, String name, Supplier<float[]> value);
|
||||
|
||||
@@ -7,6 +7,7 @@ public enum UniformType {
|
||||
VEC2,
|
||||
VEC2I,
|
||||
VEC3,
|
||||
VEC3I,
|
||||
VEC4,
|
||||
VEC4I
|
||||
}
|
||||
@@ -3,5 +3,6 @@ package net.coderbot.iris.gl.uniform;
|
||||
public enum UniformUpdateFrequency {
|
||||
ONCE,
|
||||
PER_TICK,
|
||||
PER_FRAME
|
||||
PER_FRAME,
|
||||
CUSTOM
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package net.coderbot.iris.gl.uniform;
|
||||
|
||||
import com.gtnewhorizons.angelica.glsm.RenderSystem;
|
||||
import net.coderbot.iris.gl.state.ValueUpdateNotifier;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class Vector3IntegerJomlUniform extends Uniform {
|
||||
private Vector3i cachedValue;
|
||||
private final Supplier<Vector3i> value;
|
||||
|
||||
Vector3IntegerJomlUniform(int location, Supplier<Vector3i> value) {
|
||||
this(location, value, null);
|
||||
}
|
||||
|
||||
Vector3IntegerJomlUniform(int location, Supplier<Vector3i> value, ValueUpdateNotifier notifier) {
|
||||
super(location, notifier);
|
||||
|
||||
this.cachedValue = null;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
updateValue();
|
||||
|
||||
if (notifier != null) {
|
||||
notifier.setListener(this::updateValue);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateValue() {
|
||||
Vector3i newValue = value.get();
|
||||
|
||||
if (cachedValue == null || !newValue.equals(cachedValue)) {
|
||||
cachedValue = newValue;
|
||||
RenderSystem.uniform3i(this.location, newValue.x, newValue.y, newValue.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package net.coderbot.iris.gl.uniform;
|
||||
|
||||
import com.gtnewhorizons.angelica.glsm.RenderSystem;
|
||||
import net.coderbot.iris.gl.state.ValueUpdateNotifier;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class Vector4ArrayUniform extends Uniform {
|
||||
private final Supplier<float[]> value;
|
||||
private float[] cachedValue;
|
||||
|
||||
Vector4ArrayUniform(int location, Supplier<float[]> value) {
|
||||
this(location, value, null);
|
||||
}
|
||||
|
||||
Vector4ArrayUniform(int location, Supplier<float[]> value, ValueUpdateNotifier notifier) {
|
||||
super(location, notifier);
|
||||
|
||||
this.cachedValue = new float[4];
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
updateValue();
|
||||
|
||||
if (notifier != null) {
|
||||
notifier.setListener(this::updateValue);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateValue() {
|
||||
float[] newValue = value.get();
|
||||
|
||||
if (!Arrays.equals(newValue, cachedValue)) {
|
||||
cachedValue = newValue;
|
||||
RenderSystem.uniform4f(location, cachedValue[0], cachedValue[1], cachedValue[2], cachedValue[3]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.coderbot.iris.gui.screen;
|
||||
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import com.gtnewhorizons.angelica.loading.AngelicaTweaker;
|
||||
import net.coderbot.iris.Iris;
|
||||
import net.coderbot.iris.gui.GuiUtil;
|
||||
@@ -21,6 +22,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.lwjgl.Sys;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
@@ -90,6 +92,8 @@ public class ShaderPackScreen extends GuiScreen implements HudHideable {
|
||||
}
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float delta) {
|
||||
GLStateManager.glPushAttrib(GL11.GL_COLOR_BUFFER_BIT);
|
||||
|
||||
if(dirty) {
|
||||
dirty = false;
|
||||
this.initGui();
|
||||
@@ -167,6 +171,8 @@ public class ShaderPackScreen extends GuiScreen implements HudHideable {
|
||||
} else {
|
||||
this.fontRendererObj.drawStringWithShadow(irisTextComponent, 2, this.height - 10, 0xFFFFFF);
|
||||
}
|
||||
|
||||
GLStateManager.glPopAttrib();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package net.coderbot.iris.parsing;
|
||||
|
||||
public enum BiomeCategories {
|
||||
NONE,
|
||||
TAIGA,
|
||||
EXTREME_HILLS,
|
||||
JUNGLE,
|
||||
MESA,
|
||||
PLAINS,
|
||||
SAVANNA,
|
||||
ICY,
|
||||
THE_END,
|
||||
BEACH,
|
||||
FOREST,
|
||||
OCEAN,
|
||||
DESERT,
|
||||
RIVER,
|
||||
SWAMP,
|
||||
MUSHROOM,
|
||||
NETHER,
|
||||
|
||||
// TODO: This is in Optifine, but undocumented...
|
||||
MOUNTAIN,
|
||||
UNDERGROUND
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package net.coderbot.iris.parsing;
|
||||
|
||||
import kroppeb.stareval.expression.Expression;
|
||||
import kroppeb.stareval.expression.VariableExpression;
|
||||
import kroppeb.stareval.function.FunctionContext;
|
||||
import kroppeb.stareval.function.FunctionReturn;
|
||||
import kroppeb.stareval.function.Type;
|
||||
import kroppeb.stareval.function.TypedFunction;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class BooleanVectorizedFunction implements TypedFunction {
|
||||
final TypedFunction inner;
|
||||
final int size;
|
||||
final Parameter[] parameters;
|
||||
|
||||
private final ElementAccessExpression[] vectorAccessors;
|
||||
private int index;
|
||||
|
||||
public BooleanVectorizedFunction(TypedFunction inner, int size) {
|
||||
this.inner = inner;
|
||||
this.size = size;
|
||||
|
||||
Parameter[] innerTypes = inner.getParameters();
|
||||
this.parameters = new Parameter[innerTypes.length];
|
||||
this.vectorAccessors = new ElementAccessExpression[innerTypes.length];
|
||||
|
||||
for (int i = 0; i < innerTypes.length; i++) {
|
||||
this.parameters[i] = new Parameter(VectorType.of((Type.Primitive) innerTypes[i].type(), size));
|
||||
this.vectorAccessors[i] = new ElementAccessExpression(innerTypes[i].type());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getReturnType() {
|
||||
return Type.Boolean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Parameter[] getParameters() {
|
||||
return this.parameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evaluateTo(Expression[] params, FunctionContext context, FunctionReturn functionReturn) {
|
||||
for (int p = 0; p < params.length; p++) {
|
||||
final Expression param = params[p];
|
||||
param.evaluateTo(context, functionReturn);
|
||||
this.vectorAccessors[p].vector = functionReturn.objectReturn;
|
||||
}
|
||||
|
||||
for (int i = 0; i < this.size; i++) {
|
||||
this.index = i;
|
||||
this.inner.evaluateTo(this.vectorAccessors, context, functionReturn);
|
||||
if (!functionReturn.booleanReturn)
|
||||
return; // if false -> return false
|
||||
}
|
||||
|
||||
// if all true (and thus the last one was true) -> return true
|
||||
}
|
||||
|
||||
class ElementAccessExpression implements Expression {
|
||||
final Type parameterType;
|
||||
Object vector;
|
||||
|
||||
|
||||
ElementAccessExpression(Type parameterType) {
|
||||
this.parameterType = parameterType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evaluateTo(FunctionContext context, FunctionReturn functionReturn) {
|
||||
parameterType.getValueFromArray(vector, index, functionReturn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void listVariables(Collection<? super VariableExpression> variables) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,53 @@
|
||||
package net.coderbot.iris.parsing;
|
||||
|
||||
import kroppeb.stareval.parser.BinaryOp;
|
||||
import kroppeb.stareval.parser.ParserOptions;
|
||||
import kroppeb.stareval.parser.UnaryOp;
|
||||
|
||||
public class IrisOptions {
|
||||
public static final ParserOptions options;
|
||||
static final BinaryOp Multiply = new BinaryOp("multiply", 0);
|
||||
static final BinaryOp Divide = new BinaryOp("divide", 0);
|
||||
static final BinaryOp Remainder = new BinaryOp("remainder", 0);
|
||||
static final BinaryOp Add = new BinaryOp("add", 1);
|
||||
static final BinaryOp Subtract = new BinaryOp("subtract", 1);
|
||||
static final BinaryOp Equals = new BinaryOp("equals", 2);
|
||||
static final BinaryOp NotEquals = new BinaryOp("notEquals", 2);
|
||||
static final BinaryOp LessThan = new BinaryOp("lessThan", 2);
|
||||
static final BinaryOp MoreThan = new BinaryOp("moreThan", 2);
|
||||
static final BinaryOp LessThanOrEquals = new BinaryOp("lessThanOrEquals", 2);
|
||||
static final BinaryOp MoreThanOrEquals = new BinaryOp("moreThanOrEquals", 2);
|
||||
static final BinaryOp And = new BinaryOp("and", 3);
|
||||
static final BinaryOp Or = new BinaryOp("or", 3);
|
||||
static final UnaryOp Not = new UnaryOp("not");
|
||||
static final UnaryOp Negate = new UnaryOp("negate");
|
||||
|
||||
static {
|
||||
final ParserOptions.Builder builder = new ParserOptions.Builder();
|
||||
builder.addBinaryOp("*", Multiply);
|
||||
builder.addBinaryOp("/", Divide);
|
||||
builder.addBinaryOp("%", Remainder);
|
||||
|
||||
builder.addBinaryOp("+", Add);
|
||||
builder.addBinaryOp("-", Subtract);
|
||||
|
||||
builder.addBinaryOp("==", Equals);
|
||||
builder.addBinaryOp("!=", NotEquals);
|
||||
builder.addBinaryOp("<", LessThan);
|
||||
builder.addBinaryOp(">", MoreThan);
|
||||
builder.addBinaryOp("<=", LessThanOrEquals);
|
||||
builder.addBinaryOp(">=", MoreThanOrEquals);
|
||||
|
||||
builder.addBinaryOp("≠", NotEquals);
|
||||
builder.addBinaryOp("≤", LessThanOrEquals);
|
||||
builder.addBinaryOp("≥", MoreThanOrEquals);
|
||||
|
||||
builder.addBinaryOp("&&", And);
|
||||
builder.addBinaryOp("||", Or);
|
||||
|
||||
builder.addUnaryOp("!", Not);
|
||||
builder.addUnaryOp("-", Negate);
|
||||
|
||||
options = builder.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package net.coderbot.iris.parsing;
|
||||
|
||||
import kroppeb.stareval.function.Type;
|
||||
import org.joml.Matrix2f;
|
||||
import org.joml.Matrix3f;
|
||||
import org.joml.Matrix4f;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class MatrixType<T> extends Type.ObjectType {
|
||||
public static final MatrixType<Matrix4f> MAT4 = new MatrixType<>("mat4", Matrix4f::new);
|
||||
public static MatrixType<Matrix2f> MAT2 = new MatrixType<>("mat2", Matrix2f::new);
|
||||
public static MatrixType<Matrix3f> MAT3 = new MatrixType<>("mat3", Matrix3f::new);
|
||||
final String name;
|
||||
|
||||
public MatrixType(String name, Supplier<T> supplier) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
package net.coderbot.iris.parsing;
|
||||
|
||||
import net.coderbot.iris.uniforms.SystemTimeUniforms;
|
||||
|
||||
/**
|
||||
* An implementation of basic exponential smoothing that converts a sequence of unsmoothed values into a sequence of
|
||||
* smoothed values.
|
||||
*
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Exponential_smoothing#Basic_(simple)_exponential_smoothing_(Holt_linear)">
|
||||
* Wikipedia: Basic (simple) exponential smoothing (Holt linear)</a>
|
||||
*/
|
||||
public class SmoothFloat {
|
||||
/**
|
||||
* Natural logarithm of 2, ie. {@code ln(2)}
|
||||
*/
|
||||
private static final double LN_OF_2 = Math.log(2.0);
|
||||
|
||||
/**
|
||||
* An accumulator for smoothed values.
|
||||
*/
|
||||
private float accumulator;
|
||||
|
||||
/**
|
||||
* Tracks whether an initial value has already been generated, because otherwise there will be nothing to smooth
|
||||
* with.
|
||||
*/
|
||||
private boolean hasInitialValue;
|
||||
private float cachedHalfLifeUp;
|
||||
private float cachedDecayUp;
|
||||
private float cachedHalfLifeDown;
|
||||
private float cachedDecayDown;
|
||||
|
||||
/**
|
||||
* Computes an exponential decay factor based on the given decay constant and time value
|
||||
*
|
||||
* @param k the decay constant, derived from the half life
|
||||
* @param t the time that has passed since the decay started
|
||||
*/
|
||||
private static float exponentialDecayFactor(float k, float t) {
|
||||
// https://en.wikipedia.org/wiki/Exponential_decay
|
||||
// e^(-kt)
|
||||
return (float) Math.exp(-k * t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes a linearly interpolated value between v0 and v1
|
||||
*
|
||||
* @param v0 the starting value (t = 0)
|
||||
* @param v1 the ending value (t = 1)
|
||||
* @param t the time/progress value - should be in the range of 0.0 to 1.0
|
||||
*/
|
||||
private static float lerp(float v0, float v1, float t) {
|
||||
// https://en.wikipedia.org/wiki/Linear_interpolation
|
||||
return (1 - t) * v0 + t * v1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes one value from the unsmoothed value sequence, and smooths it into our accumulator
|
||||
*/
|
||||
public float updateAndGet(float value, float halfLifeUp, float halfLifeDown) {
|
||||
if (halfLifeUp != cachedHalfLifeUp) {
|
||||
cachedHalfLifeUp = halfLifeUp;
|
||||
if (halfLifeUp == 0.0f) {
|
||||
cachedDecayUp = 0;
|
||||
} else {
|
||||
cachedDecayUp = computeDecay(halfLifeUp * 0.1F);
|
||||
}
|
||||
}
|
||||
|
||||
if (halfLifeDown != cachedHalfLifeDown) {
|
||||
cachedHalfLifeDown = halfLifeDown;
|
||||
if (halfLifeDown == 0.0f) {
|
||||
cachedDecayDown = 0;
|
||||
} else {
|
||||
cachedDecayDown = computeDecay(halfLifeDown * 0.1F);
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasInitialValue) {
|
||||
// There is no smoothing on the first value.
|
||||
// This is not an optimal approach to choosing the initial value:
|
||||
// https://en.wikipedia.org/wiki/Exponential_smoothing#Choosing_the_initial_smoothed_value
|
||||
//
|
||||
// However, it works well enough for now.
|
||||
accumulator = value;
|
||||
hasInitialValue = true;
|
||||
|
||||
return accumulator;
|
||||
}
|
||||
|
||||
// Implements the basic variant of exponential smoothing
|
||||
// https://en.wikipedia.org/wiki/Exponential_smoothing#Basic_(simple)_exponential_smoothing_(Holt_linear)
|
||||
|
||||
// 𝚫t
|
||||
float lastFrameTime = SystemTimeUniforms.TIMER.getLastFrameTime();
|
||||
|
||||
float decay = value > this.accumulator ? cachedDecayUp : cachedDecayDown;
|
||||
|
||||
if (decay == 0.0f) {
|
||||
accumulator = value;
|
||||
return accumulator;
|
||||
}
|
||||
|
||||
// Compute the smoothing factor based on our
|
||||
// α = 1 - e^(-𝚫t/τ) = 1 - e^(-k𝚫t)
|
||||
float smoothingFactor = 1.0f - exponentialDecayFactor(decay, lastFrameTime);
|
||||
|
||||
// sₜ = αxₜ + (1 - α)sₜ₋₁
|
||||
accumulator = lerp(accumulator, value, smoothingFactor);
|
||||
|
||||
return accumulator;
|
||||
}
|
||||
|
||||
private float computeDecay(float halfLife) {
|
||||
// Compute the decay constant from the half life
|
||||
// https://en.wikipedia.org/wiki/Exponential_decay#Measuring_rates_of_decay
|
||||
// https://en.wikipedia.org/wiki/Exponential_smoothing#Time_constant
|
||||
// k = 1 / τ
|
||||
return (float) (1.0f / (halfLife / LN_OF_2));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package net.coderbot.iris.parsing;
|
||||
|
||||
import kroppeb.stareval.Util;
|
||||
import kroppeb.stareval.expression.Expression;
|
||||
import kroppeb.stareval.function.AbstractTypedFunction;
|
||||
import kroppeb.stareval.function.FunctionContext;
|
||||
import kroppeb.stareval.function.FunctionReturn;
|
||||
import kroppeb.stareval.function.Type;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class VectorConstructor extends AbstractTypedFunction {
|
||||
|
||||
public VectorConstructor(Type inner, int size) {
|
||||
super(
|
||||
new VectorType.ArrayVector(inner, size),
|
||||
Util.make(new Type[size], params -> Arrays.fill(params, inner))
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VectorType.ArrayVector getReturnType() {
|
||||
return (VectorType.ArrayVector) super.getReturnType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evaluateTo(Expression[] params, FunctionContext context, FunctionReturn
|
||||
functionReturn) {
|
||||
VectorType.ArrayVector vectorType = this.getReturnType();
|
||||
vectorType.map(params, context, functionReturn, (i, p, ctx, fr) -> p[i].evaluateTo(ctx, fr));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
package net.coderbot.iris.parsing;
|
||||
|
||||
import kroppeb.stareval.function.FunctionReturn;
|
||||
import kroppeb.stareval.function.Type;
|
||||
import org.joml.Vector2f;
|
||||
import org.joml.Vector2i;
|
||||
import org.joml.Vector3f;
|
||||
import org.joml.Vector3i;
|
||||
import org.joml.Vector4f;
|
||||
import org.joml.Vector4i;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
abstract public class VectorType extends Type.ObjectType {
|
||||
public static final JOMLVector<Vector2f> VEC2 = new JOMLVector<>("vec2", Vector2f::new);
|
||||
public static final JOMLVector<Vector3f> VEC3 = new JOMLVector<>("vec3", Vector3f::new);
|
||||
public static final JOMLVector<Vector4f> VEC4 = new JOMLVector<>("vec4", Vector4f::new);
|
||||
public static final JOMLVector<Vector2i> I_VEC2 = new JOMLVector<>("ivec2", Vector2i::new);
|
||||
public static final JOMLVector<Vector3i> I_VEC3 = new JOMLVector<>("ivec3", Vector3i::new);
|
||||
public static final JOMLVector<Vector4i> I_VEC4 = new JOMLVector<>("ivec4", Vector4i::new);
|
||||
public static final VectorType B_VEC2 = new ArrayVector(Type.Boolean, 2);
|
||||
public static final VectorType B_VEC3 = new ArrayVector(Type.Boolean, 3);
|
||||
public static final VectorType B_VEC4 = new ArrayVector(Type.Boolean, 4);
|
||||
public static final ArrayVector[] AllArrayVectorTypes = Stream.of(Type.Int, Type.Boolean)
|
||||
.flatMap(type ->
|
||||
IntStream
|
||||
.rangeClosed(2, 4)
|
||||
.mapToObj(i -> new ArrayVector(type, i))
|
||||
).toArray(ArrayVector[]::new);
|
||||
public static final VectorType[] AllVectorTypes = Arrays.stream(Type.AllPrimitives)
|
||||
.flatMap(type ->
|
||||
IntStream
|
||||
.rangeClosed(2, 4)
|
||||
.mapToObj(i -> VectorType.of(type, i))
|
||||
).toArray(VectorType[]::new);
|
||||
|
||||
public static VectorType of(Type.Primitive primitive, int size) {
|
||||
if (primitive.equals(Type.Float)) {
|
||||
return switch (size) {
|
||||
case 2 -> VEC2;
|
||||
case 3 -> VEC3;
|
||||
case 4 -> VEC4;
|
||||
default -> throw new IllegalArgumentException("not a valid vector");
|
||||
};
|
||||
} else {
|
||||
return new ArrayVector(primitive, size);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ArrayVector extends VectorType {
|
||||
private final Type inner;
|
||||
private final int size;
|
||||
|
||||
public ArrayVector(Type inner, int size) {
|
||||
this.inner = inner;
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public Object createObject() {
|
||||
return this.inner.createArray(this.size);
|
||||
}
|
||||
|
||||
public void setValue(Object vector, int index, FunctionReturn functionReturn) {
|
||||
this.inner.setValueFromReturn(vector, index, functionReturn);
|
||||
}
|
||||
|
||||
public void getValue(Object vector, int index, FunctionReturn functionReturn) {
|
||||
this.inner.getValueFromArray(vector, index, functionReturn);
|
||||
}
|
||||
|
||||
public <T1, T2> void map(T1 item1, T2 item2, FunctionReturn functionReturn, IntObjectObjectObjectConsumer<T1, T2, FunctionReturn> mapper) {
|
||||
Object array = this.createObject();
|
||||
for (int i = 0; i < this.size; i++) {
|
||||
mapper.accept(i, item1, item2, functionReturn);
|
||||
this.setValue(array, i, functionReturn);
|
||||
}
|
||||
functionReturn.objectReturn = array;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof ArrayVector that)) return false;
|
||||
return size == that.size && inner.equals(that.inner);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(inner, size);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String base = this.inner.equals(Type.Float) ? "" : this.inner.toString().substring(0, 1);
|
||||
return "__" + base + "vec" + this.size;
|
||||
}
|
||||
|
||||
public interface IntObjectObjectObjectConsumer<TB, TC, TD> {
|
||||
void accept(int a, TB b, TC c, TD d);
|
||||
}
|
||||
}
|
||||
|
||||
public static class JOMLVector<T> extends VectorType {
|
||||
private final String name;
|
||||
private final Supplier<T> supplier;
|
||||
|
||||
public JOMLVector(String name, Supplier<T> supplier) {
|
||||
this.name = name;
|
||||
this.supplier = supplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public T create() {
|
||||
return this.supplier.get();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loaded 100 of 143 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user