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

v3.2
Nehon 7 years ago committed by Stephen Gold
parent bbe8f01f0f
commit 26644c89f5
  1. 17
      jme3-core/src/plugins/java/com/jme3/material/plugins/ShaderNodeLoaderDelegate.java

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

Loading…
Cancel
Save