- make SceneExplorerProperty use mutex less often

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10086 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
nor..67 2013-01-17 03:04:27 +00:00
parent 08212605bc
commit e84105307c

View File

@ -118,32 +118,44 @@ public class SceneExplorerProperty<T> extends PropertySupport.Reflection<T> {
if (!editable) {
return;
}
final T realValue = getSuperValue();
if ((objectLocal == null) && !inited) {
mutex.postWriteRequest(new Runnable() {
public void run() {
T realValue = getSuperValue();
if ((objectLocal == null) && !inited) {
inited = true;
T newObject = duplicateObject(realValue);
notifyListeners(PROP_INIT_CHANGE, null, newObject);
objectLocal = duplicateObject(realValue);
}
});
} else if ((objectLocal != null) && !objectLocal.equals(realValue)) {
mutex.postWriteRequest(new Runnable() {
public void run() {
T oldObject = objectLocal;
T newObject = duplicateObject(realValue);
notifyListeners(PROP_SCENE_CHANGE, oldObject, newObject);
objectLocal = newObject;
}
});
} else if ((objectLocal == null) && (realValue != null)) {
mutex.postWriteRequest(new Runnable() {
public void run() {
T newObject = duplicateObject(realValue);
notifyListeners(PROP_SCENE_CHANGE, null, newObject);
objectLocal = duplicateObject(realValue);
}
}
});
}
}
@Override
public T getValue() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
return mutex.readAccess(new Mutex.Action<T>() {
public T run() {
return objectLocal;
}
});
}
@Override
public void setValue(final T val) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
@ -218,10 +230,11 @@ public class SceneExplorerProperty<T> extends PropertySupport.Reflection<T> {
}
private T duplicateObject(T a) {
T obj = a;
if (primitive) {
return obj;
} else if (cloneable) {
return a;
}
T obj = null;
if (cloneable) {
try {
obj = (T) a.getClass().getMethod("clone").invoke(a);
} catch (IllegalAccessException ex) {
@ -252,6 +265,9 @@ public class SceneExplorerProperty<T> extends PropertySupport.Reflection<T> {
Exceptions.printStackTrace(ex);
}
}
if (obj == null) {
return a;
}
return obj;
}