Added a default implementation of cloneForSpatial()

to AbstractControl.  It should work in 99% of regular
use cases and not require controls to implement
cloning if they don't need it.  And if they didn't
implement it then the error message will be pretty
clear when they try to reload a saved control that
doesn't implement Cloneable.


git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9849 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
PSp..om 12 years ago
parent c5c06ca10a
commit d6267527e8
  1. 23
      engine/src/core/com/jme3/scene/control/AbstractControl.java

@ -82,6 +82,29 @@ public abstract class AbstractControl implements Control {
*/ */
protected abstract void controlRender(RenderManager rm, ViewPort vp); protected abstract void controlRender(RenderManager rm, ViewPort vp);
/**
* Default implementation of cloneForSpatial() that
* simply clones the control and sets the spatial.
* <pre>
* AbstractControl c = clone();
* c.spatial = null;
* c.setSpatial(spatial);
* </pre>
*
* Controls that wish to be persisted must be Cloneable.
*/
@Override
public Control cloneForSpatial(Spatial spatial) {
try {
AbstractControl c = (AbstractControl)clone();
c.spatial = null; // to keep setSpatial() from throwing an exception
c.setSpatial(spatial);
return c;
} catch(CloneNotSupportedException e) {
throw new RuntimeException( "Can't clone control for spatial", e );
}
}
public void update(float tpf) { public void update(float tpf) {
if (!enabled) if (!enabled)
return; return;

Loading…
Cancel
Save