Cinematic, fixed time seeking when having several SpatialAnimation with a speed > 1

fixed an issue in soundTrack crashing when time was < 0
properly implemented GuiTrack stop() method

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9239 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
rem..om 13 years ago
parent 191bd21b40
commit 8eae2cfd8a
  1. 14
      engine/src/core/com/jme3/animation/AnimChannel.java
  2. 128
      engine/src/core/com/jme3/cinematic/Cinematic.java
  3. 8
      engine/src/core/com/jme3/cinematic/events/AbstractCinematicEvent.java
  4. 14
      engine/src/core/com/jme3/cinematic/events/AnimationTrack.java
  5. 5
      engine/src/core/com/jme3/cinematic/events/SoundTrack.java
  6. 11
      engine/src/niftygui/com/jme3/cinematic/events/GuiTrack.java
  7. 2
      engine/test-data/Interface/Nifty/CinematicTest.xml

@ -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)

@ -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<String, CameraNode> cameras = new HashMap<String, CameraNode>();
private CameraNode currentCam;
private boolean initialized = false;
private Map<String, Map<String, Object>> eventsData;
private Map<String, Map<String, Object>> 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<String, CameraNode>) 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<String, Map<String, Object>> getEventsData() {
if (eventsData == null) {
eventsData = new HashMap<String, Map<String, Object>>();
}
return eventsData;
}
public void putEventData(String type, String name, Object object) {
Map<String, Map<String, Object>> data = getEventsData();
Map<String, Object> 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<String, Object> 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<String, Object> row = eventsData.get(type);
@ -374,7 +378,7 @@ public class Cinematic extends AbstractCinematicEvent implements AppState {
}
return null;
}
public Node getScene() {
return scene;
}

@ -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() {

@ -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

@ -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

@ -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

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<nifty>
<screen id="start" controller="jme3test.niftygui.TestNiftyGui">
<screen id="start" >
<layer id="layer" backgroundColor="#0000" childLayout="center">
<panel id="panel" width="100%" height="100%" backgroundColor="#0000" childLayout="center" visibleToMouse="true" >
<text id="text" font="aurulent-sans-16.fnt" color="#000f" text="" align="center" valign="bottom" />

Loading…
Cancel
Save