Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion glsl-relocated/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repositories {
}

dependencies {
implementation(shadow("io.github.douira:glsl-transformer:2.0.0-pre13")) {
implementation(shadow("io.github.douira:glsl-transformer:2.0.2")) {
exclude module: "antlr4" // we only want to shadow the runtime module
}
implementation shadow("org.antlr:antlr4-runtime:4.11.1")
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ loom.platform = forge
# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.20.1
forge_version=47.1.105
forge_version=47.1.106

# Mod Properties
mod_version = 1.8.0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package net.irisshaders.iris.gl.buffer;

public record BuiltShaderStorageInfo(long size, boolean relative, float scaleX, float scaleY, byte[] content) {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.irisshaders.iris.gl.buffer;

public record ShaderStorageInfo(int size, boolean relative, float scaleX, float scaleY) {
public record ShaderStorageInfo(int size, boolean relative, float scaleX, float scaleY, String name) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.irisshaders.iris.uniforms.BiomeUniforms;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.regex.Pattern;
Expand Down
713 changes: 318 additions & 395 deletions src/main/java/net/irisshaders/iris/shaderpack/ShaderPack.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
package net.irisshaders.iris.shaderpack.parsing;

import net.irisshaders.iris.Iris;
import net.irisshaders.iris.shaderpack.option.values.OptionValues;

import java.util.EmptyStackException;
import java.util.Stack;

public class BooleanParser {
private enum Operation {
AND {
@Override
boolean compute(boolean value, Stack<Boolean> valueStack) {
return valueStack.pop() && value;
}
}, OR {
@Override
boolean compute(boolean value, Stack<Boolean> valueStack) {
return valueStack.pop() || value;
}
}, NOT {
@Override
boolean compute(boolean value, Stack<Boolean> valueStack) {
return !value;
}
}, OPEN;

boolean compute(boolean value, Stack<Boolean> valueStack) {
return value;
}
}

/**
* parses the given expression
* @param expression expression to parse
* @param valueLookup lookup of shadow options
* @return result of the expression, or true if there was an error
*/
public static boolean parse(String expression, OptionValues valueLookup) {
try {
String option = "";
Stack<Operation> operationStack = new Stack<>();
Stack<Boolean> valueStack = new Stack<>();
for (int i = 0; i < expression.length(); i++) {
char c = expression.charAt(i);
switch (c) {
case '!' -> operationStack.push(Operation.NOT);
case '&' -> {
// add value first, because this checks for preceding NOTs
if (!option.isEmpty()) {
valueStack.push(processValue(option, valueLookup, operationStack));
option = "";
}
// AND operators have priority, so add a bracket if it's the first AND
if (operationStack.isEmpty() || !operationStack.peek().equals(Operation.AND)) {
operationStack.push(Operation.OPEN);
}
i++;
operationStack.push(Operation.AND);
}
case '|' -> {
// add value first, because this checks for preceding NOTs
if (!option.isEmpty()) {
valueStack.push(processValue(option, valueLookup, operationStack));
option = "";
}
// if there was an AND before, that needs to be evaluated because it takes priority
if (!operationStack.isEmpty() && operationStack.peek().equals(Operation.AND)) {
evaluate(operationStack, valueStack, true);
}
i++;
operationStack.push(Operation.OR);
}
case '(' -> operationStack.push(Operation.OPEN);
case ')' -> {
// add value first, because this checks for preceding NOTs
if (!option.isEmpty()) {
valueStack.push(processValue(option, valueLookup, operationStack));
option = "";
}
// if there was an AND before, that needs to be evaluated because it added its own bracket
if (!operationStack.isEmpty() && operationStack.peek().equals(Operation.AND)) {
evaluate(operationStack, valueStack, true);
}
evaluate(operationStack, valueStack, true);
}
case ' ' -> {}
default -> option += c;
}
}
if (!option.isEmpty()) {
valueStack.push(processValue(option, valueLookup, operationStack));
}
evaluate(operationStack, valueStack, false);
boolean result = valueStack.pop();
if (!valueStack.isEmpty() || !operationStack.isEmpty()) {
Iris.logger.warn(
"Failed to parse the following boolean operation correctly, stacks not empty, defaulting to true!: '{}'",
expression);
return true;
}
return result;
} catch (EmptyStackException emptyStackException) {
Iris.logger.warn(
"Failed to parse the following boolean operation correctly, stacks empty when it shouldn't, defaulting to true!: '{}'",
expression);
return true;
}
}

/**
* gets the value for the given string and negates it if there is a NOT in the operationStack
*/
private static boolean processValue(String value, OptionValues valueLookup, Stack<Operation> operationStack) {
boolean booleanValue = switch (value) {
case "true", "1" -> true;
case "false", "0" -> false;
default -> valueLookup != null && valueLookup.getBooleanValueOrDefault(value);
};
if (!operationStack.isEmpty() && operationStack.peek() == Operation.NOT) {
// if there is a NOT, that needs to be handled immediately
operationStack.pop();
return !booleanValue;
} else {
return booleanValue;
}
}

/**
* evaluates the operation stack backwards, to the next bracket, or the whole way
* @param operationStack Stack with operations
* @param valueStack Stack with values
* @param currentBracket only evaluates the current bracket
*/
private static void evaluate(Stack<Operation> operationStack, Stack<Boolean> valueStack, boolean currentBracket) {
boolean value = valueStack.pop();
while (!operationStack.isEmpty() && (!currentBracket || operationStack.peek() != Operation.OPEN)) {
value = operationStack.pop().compute(value, valueStack);
}

// if there is a bracket check if the whole bracket should be negated
if (!operationStack.isEmpty() && operationStack.peek() == Operation.OPEN) {
operationStack.pop();
if (!operationStack.isEmpty() && operationStack.peek() == Operation.NOT) {
value = operationStack.pop().compute(value, valueStack);
}
}
valueStack.push(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ public ShaderProperties(String contents, ShaderPackOptions shaderPackOptions, It
return;
}

bufferObjects.put(trueIndex, new ShaderStorageInfo(trueSize, false, 0, 0));
bufferObjects.put(trueIndex, new ShaderStorageInfo(trueSize, false, 0, 0, null));
} else {
// Assume it's a long one
try {
Expand All @@ -422,7 +422,7 @@ public ShaderProperties(String contents, ShaderPackOptions shaderPackOptions, It
return;
}

bufferObjects.put(trueIndex, new ShaderStorageInfo(trueSize, isRelative, scaleX, scaleY));
bufferObjects.put(trueIndex, new ShaderStorageInfo(trueSize, isRelative, scaleX, scaleY, null));
}
});

Expand Down Expand Up @@ -948,7 +948,7 @@ public CustomUniforms.Builder getCustomUniforms() {
return customUniforms;
}

public CloudSetting getDHCloudSetting() {
return dhCloudSetting;
}
public CloudSetting getDHCloudSetting() {
return dhCloudSetting;
}
}