Modified the define list to only recompile if

values have changed.  Also, it returns a boolean
for set and remove on whether a change actually
occurred.  This will be used by my next commit
to give a performance boost.


git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9138 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
PSp..om 13 years ago
parent b0cff4343e
commit 1f0a77de26
  1. 49
      engine/src/core/com/jme3/shader/DefineList.java

@ -81,7 +81,9 @@ public class DefineList implements Savable {
} }
public String get(String key){ public String get(String key){
compiled = null; // I do not see the point of forcing a rebuild on get()
// so I'm commenting it out. -pspeed
//compiled = null;
return defines.get(key); return defines.get(key);
} }
@ -90,41 +92,62 @@ public class DefineList implements Savable {
// defines.put(key, val); // defines.put(key, val);
// } // }
public void set(String key, VarType type, Object val){ public boolean set(String key, VarType type, Object val){
compiled = null;
if (val == null){ if (val == null){
defines.remove(key); defines.remove(key);
return; compiled = null;
return true;
} }
switch (type){ switch (type){
case Boolean: case Boolean:
if ( ((Boolean) val).booleanValue() ) if ( ((Boolean) val).booleanValue() ) {
defines.put(key, "1"); // same literal, != should work
else if (defines.containsKey(key)) if( defines.put(key, "1") != "1" ) {
compiled = null;
return true;
}
} else if (defines.containsKey(key)) {
defines.remove(key); defines.remove(key);
compiled = null;
return true;
}
break; break;
case Float: case Float:
case Int: case Int:
defines.put(key, val.toString()); String original = defines.put(key, val.toString());
if (!val.equals(original)) {
compiled = null;
return true;
}
break; break;
default: default:
defines.put(key, "1"); // same literal, != should work
if (defines.put(key, "1") != "1") {
compiled = null;
return true;
}
break; break;
} }
return false;
} }
public void remove(String key){ public boolean remove(String key){
compiled = null; if (defines.remove(key) != null) {
defines.remove(key); compiled = null;
return true;
}
return false;
} }
public void addFrom(DefineList other){ public void addFrom(DefineList other){
compiled = null;
if (other == null) if (other == null)
return; return;
compiled = null;
defines.putAll(other.defines); defines.putAll(other.defines);
} }

Loading…
Cancel
Save