diff --git a/engine/src/core/com/jme3/animation/AnimChannel.java b/engine/src/core/com/jme3/animation/AnimChannel.java index a2fae7ccc..cce6aeeea 100644 --- a/engine/src/core/com/jme3/animation/AnimChannel.java +++ b/engine/src/core/com/jme3/animation/AnimChannel.java @@ -316,6 +316,20 @@ public final class AnimChannel { BitSet getAffectedBones(){ return affectedBones; } + + public void reset(boolean rewind){ + if(rewind){ + setTime(0); + if(control.getSkeleton()!=null){ + control.getSkeleton().resetAndUpdate(); + }else{ + TempVars vars = TempVars.get(); + update(0, vars); + vars.release(); + } + } + animation = null; + } void update(float tpf, TempVars vars) { if (animation == null) diff --git a/engine/src/core/com/jme3/cinematic/Cinematic.java b/engine/src/core/com/jme3/cinematic/Cinematic.java index 3477c221f..70d23704e 100644 --- a/engine/src/core/com/jme3/cinematic/Cinematic.java +++ b/engine/src/core/com/jme3/cinematic/Cinematic.java @@ -59,7 +59,7 @@ import java.util.logging.Logger; * @author Nehon */ public class Cinematic extends AbstractCinematicEvent implements AppState { - + private static final Logger logger = Logger.getLogger(Application.class.getName()); private Node scene; protected TimeLine timeLine = new TimeLine(); @@ -68,30 +68,30 @@ public class Cinematic extends AbstractCinematicEvent implements AppState { private Map cameras = new HashMap(); private CameraNode currentCam; private boolean initialized = false; - private Map> eventsData; - + private Map> eventsData; + public Cinematic() { } - + public Cinematic(Node scene) { this.scene = scene; } - + public Cinematic(Node scene, float initialDuration) { super(initialDuration); this.scene = scene; } - + public Cinematic(Node scene, LoopMode loopMode) { super(loopMode); this.scene = scene; } - + public Cinematic(Node scene, float initialDuration, LoopMode loopMode) { super(initialDuration, loopMode); this.scene = scene; } - + @Override public void onPlay() { if (isInitialized()) { @@ -105,7 +105,7 @@ public class Cinematic extends AbstractCinematicEvent implements AppState { } } } - + @Override public void onStop() { time = 0; @@ -116,7 +116,7 @@ public class Cinematic extends AbstractCinematicEvent implements AppState { } enableCurrentCam(false); } - + @Override public void onPause() { for (int i = 0; i < cinematicEvents.size(); i++) { @@ -126,28 +126,28 @@ public class Cinematic extends AbstractCinematicEvent implements AppState { } } } - + @Override public void write(JmeExporter ex) throws IOException { super.write(ex); OutputCapsule oc = ex.getCapsule(this); - + oc.writeSavableArrayList((ArrayList) cinematicEvents, "cinematicEvents", null); oc.writeStringSavableMap(cameras, "cameras", null); oc.write(timeLine, "timeLine", null); - + } - + @Override public void read(JmeImporter im) throws IOException { super.read(im); InputCapsule ic = im.getCapsule(this); - + cinematicEvents = ic.readSavableArrayList("cinematicEvents", null); cameras = (Map) ic.readStringSavableMap("cameras", null); timeLine = (TimeLine) ic.readSavable("timeLine", null); } - + @Override public void setSpeed(float speed) { super.setSpeed(speed); @@ -155,53 +155,53 @@ public class Cinematic extends AbstractCinematicEvent implements AppState { CinematicEvent ce = cinematicEvents.get(i); ce.setSpeed(speed); } - - + + } - + public void initialize(AppStateManager stateManager, Application app) { initEvent(app, this); for (CinematicEvent cinematicEvent : cinematicEvents) { cinematicEvent.initEvent(app, this); } - + initialized = true; } - + public boolean isInitialized() { return initialized; } - + public void setEnabled(boolean enabled) { if (enabled) { play(); } } - + public boolean isEnabled() { return playState == PlayState.Playing; } - + public void stateAttached(AppStateManager stateManager) { } - + public void stateDetached(AppStateManager stateManager) { stop(); } - + public void update(float tpf) { if (isInitialized()) { internalUpdate(tpf); } } - + @Override - public void onUpdate(float tpf) { + public void onUpdate(float tpf) { for (int i = 0; i < cinematicEvents.size(); i++) { CinematicEvent ce = cinematicEvents.get(i); ce.internalUpdate(tpf); } - + int keyFrameIndex = timeLine.getKeyFrameIndexFromTime(time); //iterate to make sure every key frame is triggered @@ -211,33 +211,37 @@ public class Cinematic extends AbstractCinematicEvent implements AppState { keyFrame.trigger(); } } - + lastFetchedKeyFrame = keyFrameIndex; } - + @Override public void setTime(float time) { - super.setTime(time); - int keyFrameIndex = timeLine.getKeyFrameIndexFromTime(time); + super.setTime(time); + //stopping all events + for (CinematicEvent ce : cinematicEvents) { + ce.stop(); + } //triggering all the event from start to "time" - //then computing timeOffset for each event - for (int i = 0; i <= keyFrameIndex; i++) { - KeyFrame keyFrame = timeLine.get(i); + //then computing timeOffset for each event + for (KeyFrame keyFrame : timeLine.values()) { + //KeyFrame keyFrame = timeLine.get(timeLine.keySet()); if (keyFrame != null) { for (CinematicEvent ce : keyFrame.getCinematicEvents()) { - ce.play(); - ce.setTime(time - timeLine.getKeyFrameTime(keyFrame)); + float t = this.time - timeLine.getKeyFrameTime(keyFrame); + if (t >= 0 && (t <= ce.getInitialDuration() || ce.getLoopMode() != LoopMode.DontLoop)) { + ce.play(); + ce.setTime(t); + } } } } if (playState != PlayState.Playing) { pause(); } - - // step(); } - + public KeyFrame addCinematicEvent(float timeStamp, CinematicEvent cinematicEvent) { KeyFrame keyFrame = timeLine.getKeyFrameAtTime(timeStamp); if (keyFrame == null) { @@ -248,13 +252,13 @@ public class Cinematic extends AbstractCinematicEvent implements AppState { cinematicEvents.add(cinematicEvent); return keyFrame; } - + public void render(RenderManager rm) { } - + public void postRender() { } - + public void cleanup() { } @@ -270,10 +274,10 @@ public class Cinematic extends AbstractCinematicEvent implements AppState { d = (ce.getDuration() * ce.getSpeed()); } } - + initialDuration = d; } - + public CameraNode bindCamera(String cameraName, Camera cam) { CameraNode node = new CameraNode(cameraName, cam); node.setControlDir(ControlDirection.SpatialToCamera); @@ -282,17 +286,17 @@ public class Cinematic extends AbstractCinematicEvent implements AppState { scene.attachChild(node); return node; } - + public CameraNode getCamera(String cameraName) { return cameras.get(cameraName); } - + private void enableCurrentCam(boolean enabled) { if (currentCam != null) { currentCam.getControl(CameraControl.class).setEnabled(enabled); } } - + public void setActiveCamera(String cameraName) { enableCurrentCam(false); currentCam = cameras.get(cameraName); @@ -301,51 +305,51 @@ public class Cinematic extends AbstractCinematicEvent implements AppState { } enableCurrentCam(true); } - + public void activateCamera(final float timeStamp, final String cameraName) { addCinematicEvent(timeStamp, new AbstractCinematicEvent() { - + @Override public void play() { super.play(); stop(); } - + @Override public void onPlay() { setActiveCamera(cameraName); } - + @Override public void onUpdate(float tpf) { } - + @Override public void onStop() { } - + @Override public void onPause() { } - + @Override public void setTime(float time) { play(); } }); } - + public void setScene(Node scene) { this.scene = scene; } - + private Map> getEventsData() { if (eventsData == null) { eventsData = new HashMap>(); } return eventsData; } - + public void putEventData(String type, String name, Object object) { Map> data = getEventsData(); Map row = data.get(type); @@ -354,7 +358,7 @@ public class Cinematic extends AbstractCinematicEvent implements AppState { } row.put(name, object); } - + public Object getEventData(String type, String name) { if (eventsData != null) { Map row = eventsData.get(type); @@ -364,7 +368,7 @@ public class Cinematic extends AbstractCinematicEvent implements AppState { } return null; } - + public Savable removeEventData(String type, String name) { if (eventsData != null) { Map row = eventsData.get(type); @@ -374,7 +378,7 @@ public class Cinematic extends AbstractCinematicEvent implements AppState { } return null; } - + public Node getScene() { return scene; } diff --git a/engine/src/core/com/jme3/cinematic/events/AbstractCinematicEvent.java b/engine/src/core/com/jme3/cinematic/events/AbstractCinematicEvent.java index ea2d13215..386cdb191 100644 --- a/engine/src/core/com/jme3/cinematic/events/AbstractCinematicEvent.java +++ b/engine/src/core/com/jme3/cinematic/events/AbstractCinematicEvent.java @@ -100,7 +100,7 @@ public abstract class AbstractCinematicEvent implements CinematicEvent { * Play this event */ public void play() { - onPlay(); + onPlay(); playState = PlayState.Playing; if (listeners != null) { for (int i = 0; i < listeners.size(); i++) { @@ -121,9 +121,7 @@ public abstract class AbstractCinematicEvent implements CinematicEvent { */ public void internalUpdate(float tpf) { if (playState == PlayState.Playing) { - time = time + (tpf * speed); - //time = elapsedTimePause + (timer.getTimeInSeconds() - start) * speed; - + time = time + (tpf * speed); onUpdate(tpf); if (time >= initialDuration && loopMode == loopMode.DontLoop) { stop(); @@ -311,7 +309,7 @@ public abstract class AbstractCinematicEvent implements CinematicEvent { * @param time the time to fast forward to */ public void setTime(float time) { - this.time = time / speed; + this.time = time ; } public float getTime() { diff --git a/engine/src/core/com/jme3/cinematic/events/AnimationTrack.java b/engine/src/core/com/jme3/cinematic/events/AnimationTrack.java index e857706c5..ab86fcfa8 100644 --- a/engine/src/core/com/jme3/cinematic/events/AnimationTrack.java +++ b/engine/src/core/com/jme3/cinematic/events/AnimationTrack.java @@ -109,17 +109,17 @@ public class AnimationTrack extends AbstractCinematicEvent { public void setTime(float time) { super.setTime(time); float t = time; - if(loopMode == loopMode.Loop){ + if (loopMode == loopMode.Loop) { t = t % channel.getAnimMaxTime(); } - if(loopMode == loopMode.Cycle){ - float parity = (float)Math.ceil(time / channel.getAnimMaxTime()); - if(parity >0 && parity%2 ==0){ + if (loopMode == loopMode.Cycle) { + float parity = (float) Math.ceil(time / channel.getAnimMaxTime()); + if (parity > 0 && parity % 2 == 0) { t = channel.getAnimMaxTime() - t % channel.getAnimMaxTime(); - }else{ + } else { t = t % channel.getAnimMaxTime(); } - + } channel.setTime(t); channel.getControl().update(0); @@ -142,8 +142,8 @@ public class AnimationTrack extends AbstractCinematicEvent { @Override public void onStop() { - channel.getControl().setEnabled(false); channel.setTime(0); + channel.reset(false); } @Override diff --git a/engine/src/core/com/jme3/cinematic/events/SoundTrack.java b/engine/src/core/com/jme3/cinematic/events/SoundTrack.java index 77aae312b..44838effd 100644 --- a/engine/src/core/com/jme3/cinematic/events/SoundTrack.java +++ b/engine/src/core/com/jme3/cinematic/events/SoundTrack.java @@ -116,10 +116,11 @@ public class SoundTrack extends AbstractCinematicEvent { public void setTime(float time) { super.setTime(time); //can occur on rewind - if (time < 0) { + if (time < 0f) { stop(); + }else{ + audioNode.setTimeOffset(time); } - audioNode.setTimeOffset(time); } @Override diff --git a/engine/src/niftygui/com/jme3/cinematic/events/GuiTrack.java b/engine/src/niftygui/com/jme3/cinematic/events/GuiTrack.java index 281c4507b..e4ed8dc35 100644 --- a/engine/src/niftygui/com/jme3/cinematic/events/GuiTrack.java +++ b/engine/src/niftygui/com/jme3/cinematic/events/GuiTrack.java @@ -32,13 +32,13 @@ package com.jme3.cinematic.events; import com.jme3.animation.LoopMode; -import com.jme3.app.Application; -import com.jme3.cinematic.Cinematic; import com.jme3.export.InputCapsule; import com.jme3.export.JmeExporter; import com.jme3.export.JmeImporter; import com.jme3.export.OutputCapsule; import de.lessvoid.nifty.Nifty; +import de.lessvoid.nifty.screen.NullScreen; +import de.lessvoid.nifty.screen.Screen; import java.io.IOException; /** @@ -78,13 +78,14 @@ public class GuiTrack extends AbstractCinematicEvent { @Override public void onPlay() { - System.out.println("screen should be "+screen); + System.out.println("screen should be " + screen); nifty.gotoScreen(screen); } @Override - public void onStop() { - nifty.gotoScreen(""); + public void onStop() { if (!(nifty.getCurrentScreen() instanceof NullScreen)) { + nifty.getCurrentScreen().endScreen(null); + } } @Override diff --git a/engine/test-data/Interface/Nifty/CinematicTest.xml b/engine/test-data/Interface/Nifty/CinematicTest.xml index a4aaeaf5b..5d8648207 100644 --- a/engine/test-data/Interface/Nifty/CinematicTest.xml +++ b/engine/test-data/Interface/Nifty/CinematicTest.xml @@ -1,6 +1,6 @@ - +