Uses a HashSet for variable names in ShaderNodeLoaderDelegate instead of a String

shader-nodes-enhancement
Nehon 7 years ago
parent c0cdf75603
commit 302e746a94
  1. 17
      jme3-core/src/plugins/java/com/jme3/material/plugins/ShaderNodeLoaderDelegate.java

@ -43,10 +43,7 @@ import com.jme3.shader.*;
import com.jme3.util.blockparser.Statement;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
* This class is here to be able to load shaderNodeDefinition from both the
@ -75,7 +72,7 @@ public class ShaderNodeLoaderDelegate {
protected MaterialDef materialDef;
protected String shaderLanguage;
protected String shaderName;
protected String varNames = "";
protected Set<String> varNames = new HashSet<>();
protected AssetManager assetManager;
protected ConditionParser conditionParser = new ConditionParser();
protected List<String> nulledConditions = new ArrayList<String>();
@ -177,7 +174,7 @@ public class ShaderNodeLoaderDelegate {
shaderNodeDefinition.setDocumentation(doc);
}
} else if (line.startsWith("Input")) {
varNames = "";
varNames.clear();
for (Statement statement1 : statement.getContents()) {
try {
shaderNodeDefinition.getInputs().add(readVariable(statement1));
@ -186,7 +183,7 @@ public class ShaderNodeLoaderDelegate {
}
}
} else if (line.startsWith("Output")) {
varNames = "";
varNames.clear();
for (Statement statement1 : statement.getContents()) {
try {
if (statement1.getLine().trim().equals("None")) {
@ -235,11 +232,11 @@ public class ShaderNodeLoaderDelegate {
multiplicity = arr[1].replaceAll("\\]", "").trim();
}
if (varNames.contains(varName + ";")) {
if (varNames.contains(varName)) {
throw new MatParseException("Duplicate variable name " + varName, statement);
}
varNames += varName + ";";
varNames.add(varName);
final ShaderNodeVariable variable = new ShaderNodeVariable(varType, "", varName, multiplicity);
variable.setDefaultValue(defaultValue);
@ -1139,7 +1136,7 @@ public class ShaderNodeLoaderDelegate {
materialDef = null;
shaderLanguage = "";
shaderName = "";
varNames = "";
varNames.clear();
assetManager = null;
nulledConditions.clear();
}

Loading…
Cancel
Save