Skip to content

Commit db23bd6

Browse files
committed
AnimEvent: solve bug where onStop() kills prior event on the same layer (#1537)
* AnimEvent: solve bug where onStop() kills prior event on the same layer * AnimEvent: for clarity, use getAction() instead of action() * AnimComposer: keep track of the manager for each layer * AnimEvent: keep track of which event is managing each layer * TestJaime: reset the model position each time the cinematic starts
1 parent bc973a5 commit db23bd6

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

jme3-core/src/main/java/com/jme3/anim/AnimComposer.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,37 @@ public void setGlobalSpeed(float globalSpeed) {
456456
this.globalSpeed = globalSpeed;
457457
}
458458

459+
/**
460+
* Access the manager of the named layer.
461+
*
462+
* @param layerName the name of the layer to access
463+
* @return the current manager (typically an AnimEvent) or null for none
464+
*/
465+
public Object getLayerManager(String layerName) {
466+
Layer layer = layers.get(layerName);
467+
if (layer == null) {
468+
throw new IllegalArgumentException("Unknown layer " + layerName);
469+
}
470+
471+
return layer.manager;
472+
}
473+
474+
/**
475+
* Assign a manager to the named layer.
476+
*
477+
* @param layerName the name of the layer to modify
478+
* @param manager the desired manager (typically an AnimEvent) or null for
479+
* none
480+
*/
481+
public void setLayerManager(String layerName, Object manager) {
482+
Layer layer = layers.get(layerName);
483+
if (layer == null) {
484+
throw new IllegalArgumentException("Unknown layer " + layerName);
485+
}
486+
487+
layer.manager = manager;
488+
}
489+
459490
/**
460491
* Create a shallow clone for the JME cloner.
461492
*
@@ -539,6 +570,7 @@ private static class Layer implements JmeCloneable {
539570
private Action currentAction;
540571
private AnimationMask mask;
541572
private double time;
573+
private Object manager;
542574

543575
public Layer(AnimComposer ac) {
544576
this.ac = ac;

jme3-core/src/main/java/com/jme3/cinematic/events/AnimEvent.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,11 @@ public void initEvent(Application app, Cinematic cinematic) {
123123
public void onPause() {
124124
logger.log(Level.SEVERE, "");
125125

126-
Action eventAction = composer.action(actionName);
127-
eventAction.setSpeed(0f);
126+
Object layerManager = composer.getLayerManager(layerName);
127+
if (layerManager == this) {
128+
Action eventAction = composer.action(actionName);
129+
eventAction.setSpeed(0f);
130+
}
128131
}
129132

130133
/**
@@ -149,6 +152,7 @@ public void onPlay() {
149152
composer.setTime(layerName, 0.0);
150153
}
151154
eventAction.setSpeed(speed);
155+
composer.setLayerManager(layerName, this);
152156
}
153157

154158
/**
@@ -157,7 +161,12 @@ public void onPlay() {
157161
@Override
158162
public void onStop() {
159163
logger.log(Level.INFO, "");
160-
composer.removeCurrentAction(layerName);
164+
165+
Object layerManager = composer.getLayerManager(layerName);
166+
if (layerManager == this) {
167+
composer.removeCurrentAction(layerName);
168+
composer.setLayerManager(layerName, null);
169+
}
161170
}
162171

163172
/**

jme3-examples/src/main/java/jme3test/animation/TestJaime.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,19 @@ public void setupCinematic(final Node jaime) {
159159
AnimClip forwardClip = af.buildAnimation(jaime);
160160
AnimComposer composer = jaime.getControl(AnimComposer.class);
161161
composer.addAnimClip(forwardClip);
162+
/*
163+
* Add a clip that warps the model to its starting position.
164+
*/
165+
AnimFactory af2 = new AnimFactory(0.01f, "StartingPosition", 30f);
166+
af2.addTimeTranslation(0f, new Vector3f(0f, 0f, -3f));
167+
AnimClip startClip = af2.buildAnimation(jaime);
168+
composer.addAnimClip(startClip);
162169

163170
composer.makeLayer("SpatialLayer", null);
164171
String boneLayer = AnimComposer.DEFAULT_LAYER;
165172

173+
cinematic.addCinematicEvent(0f,
174+
new AnimEvent(composer, "StartingPosition", "SpatialLayer"));
166175
cinematic.enqueueCinematicEvent(
167176
new AnimEvent(composer, "Idle", boneLayer));
168177
float jumpStart = cinematic.enqueueCinematicEvent(

0 commit comments

Comments
 (0)