Skip to content

Commit fe2ab03

Browse files
committed
add cinematic abstraction
1 parent 3a784d9 commit fe2ab03

File tree

9 files changed

+168
-19
lines changed

9 files changed

+168
-19
lines changed

jme3-core/src/main/java/com/jme3/cinematic/Cinematic.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
*
9595
* @author Nehon
9696
*/
97-
public class Cinematic extends AbstractCinematicEvent implements AppState {
97+
public class Cinematic extends AbstractCinematicEvent implements AppState, CinematicHandler {
9898

9999
private static final Logger logger = Logger.getLogger(Cinematic.class.getName());
100100
private static final String CINEMATIC_REF = "Cinematic:Refs";
@@ -544,6 +544,7 @@ public void setTime(float time) {
544544
* @param cinematicEvent the cinematic event
545545
* @return the keyFrame for that event.
546546
*/
547+
@Override
547548
public KeyFrame addCinematicEvent(float timeStamp, CinematicEvent cinematicEvent) {
548549
KeyFrame keyFrame = timeLine.getKeyFrameAtTime(timeStamp);
549550
if (keyFrame == null) {
@@ -565,6 +566,7 @@ public KeyFrame addCinematicEvent(float timeStamp, CinematicEvent cinematicEvent
565566
* @param cinematicEvent the cinematic event to enqueue
566567
* @return the timestamp the event was scheduled.
567568
*/
569+
@Override
568570
public float enqueueCinematicEvent(CinematicEvent cinematicEvent) {
569571
float scheduleTime = nextEnqueue;
570572
addCinematicEvent(scheduleTime, cinematicEvent);
@@ -578,6 +580,7 @@ public float enqueueCinematicEvent(CinematicEvent cinematicEvent) {
578580
* @param cinematicEvent the cinematicEvent to remove
579581
* @return true if the element has been removed
580582
*/
583+
@Override
581584
public boolean removeCinematicEvent(CinematicEvent cinematicEvent) {
582585
cinematicEvent.dispose();
583586
cinematicEvents.remove(cinematicEvent);
@@ -597,6 +600,7 @@ public boolean removeCinematicEvent(CinematicEvent cinematicEvent) {
597600
* @param cinematicEvent the cinematicEvent to remove
598601
* @return true if the element has been removed
599602
*/
603+
@Override
600604
public boolean removeCinematicEvent(float timeStamp, CinematicEvent cinematicEvent) {
601605
KeyFrame keyFrame = timeLine.getKeyFrameAtTime(timeStamp);
602606
return removeCinematicEvent(keyFrame, cinematicEvent);
@@ -610,6 +614,7 @@ public boolean removeCinematicEvent(float timeStamp, CinematicEvent cinematicEve
610614
* @param cinematicEvent the cinematicEvent to remove
611615
* @return true if the element has been removed
612616
*/
617+
@Override
613618
public boolean removeCinematicEvent(KeyFrame keyFrame, CinematicEvent cinematicEvent) {
614619
cinematicEvent.dispose();
615620
boolean ret = keyFrame.cinematicEvents.remove(cinematicEvent);
@@ -677,6 +682,7 @@ public void fitDuration() {
677682
* @param cam the scene camera.
678683
* @return the created CameraNode.
679684
*/
685+
@Override
680686
public CameraNode bindCamera(String cameraName, Camera cam) {
681687
if (cameras.containsKey(cameraName)) {
682688
throw new IllegalArgumentException("Camera " + cameraName + " is already bound to this cinematic");
@@ -696,6 +702,7 @@ public CameraNode bindCamera(String cameraName, Camera cam) {
696702
* Cinematic#bindCamera())
697703
* @return the cameraNode for this name
698704
*/
705+
@Override
699706
public CameraNode getCamera(String cameraName) {
700707
return cameras.get(cameraName);
701708
}
@@ -718,6 +725,7 @@ private void setEnableCurrentCam(boolean enabled) {
718725
* @param cameraName the camera name (as registered in
719726
* Cinematic#bindCamera())
720727
*/
728+
@Override
721729
public void setActiveCamera(String cameraName) {
722730
setEnableCurrentCam(false);
723731
currentCam = cameras.get(cameraName);
@@ -734,6 +742,7 @@ public void setActiveCamera(String cameraName) {
734742
* @param cameraName the camera name (as registered in
735743
* Cinematic#bindCamera())
736744
*/
745+
@Override
737746
public void activateCamera(final float timeStamp, final String cameraName) {
738747
addCinematicEvent(timeStamp, new CameraEvent(this, cameraName));
739748
}
@@ -757,6 +766,7 @@ private Map<String, Map<Object, Object>> getEventsData() {
757766
* @param key the key
758767
* @param object the data
759768
*/
769+
@Override
760770
public void putEventData(String type, Object key, Object object) {
761771
Map<String, Map<Object, Object>> data = getEventsData();
762772
Map<Object, Object> row = data.get(type);
@@ -774,6 +784,7 @@ public void putEventData(String type, Object key, Object object) {
774784
* @param key the key
775785
* @return the pre-existing object, or null
776786
*/
787+
@Override
777788
public Object getEventData(String type, Object key) {
778789
if (eventsData != null) {
779790
Map<Object, Object> row = eventsData.get(type);
@@ -790,6 +801,7 @@ public Object getEventData(String type, Object key) {
790801
* @param type the type of data
791802
* @param key the key of the data
792803
*/
804+
@Override
793805
public void removeEventData(String type, Object key) {
794806
if (eventsData != null) {
795807
Map<Object, Object> row = eventsData.get(type);
@@ -849,6 +861,7 @@ public void clear() {
849861
* This method removes all previously bound CameraNodes and clears the
850862
* internal camera map, effectively detaching all cameras from the scene.
851863
*/
864+
@Override
852865
public void clearCameras() {
853866
for (CameraNode cameraNode : cameras.values()) {
854867
scene.detachChild(cameraNode);
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
package com.jme3.cinematic;
2+
3+
import com.jme3.cinematic.events.CinematicEvent;
4+
import com.jme3.renderer.Camera;
5+
import com.jme3.scene.CameraNode;
6+
7+
public interface CinematicHandler {
8+
9+
/**
10+
* Adds a cinematic event to this cinematic at the given timestamp. This
11+
* operation returns a keyFrame
12+
*
13+
* @param timeStamp the time when the event will start after the beginning
14+
* of the cinematic
15+
* @param cinematicEvent the cinematic event
16+
* @return the keyFrame for that event.
17+
*/
18+
KeyFrame addCinematicEvent(float timeStamp, CinematicEvent cinematicEvent);
19+
20+
/**
21+
* Enqueue a cinematic event to a Cinematic. This is handy when you
22+
* want to chain events without knowing their durations.
23+
*
24+
* @param cinematicEvent the cinematic event to enqueue
25+
* @return the timestamp the event was scheduled.
26+
*/
27+
float enqueueCinematicEvent(CinematicEvent cinematicEvent);
28+
29+
/**
30+
* removes the first occurrence found of the given cinematicEvent.
31+
*
32+
* @param cinematicEvent the cinematicEvent to remove
33+
* @return true if the element has been removed
34+
*/
35+
boolean removeCinematicEvent(CinematicEvent cinematicEvent);
36+
37+
/**
38+
* removes the first occurrence found of the given cinematicEvent for the
39+
* given time stamp.
40+
*
41+
* @param timeStamp the timestamp when the cinematicEvent has been added
42+
* @param cinematicEvent the cinematicEvent to remove
43+
* @return true if the element has been removed
44+
*/
45+
boolean removeCinematicEvent(float timeStamp, CinematicEvent cinematicEvent);
46+
47+
/**
48+
* removes the first occurrence found of the given cinematicEvent for the
49+
* given keyFrame
50+
*
51+
* @param keyFrame the keyFrame returned by the addCinematicEvent method.
52+
* @param cinematicEvent the cinematicEvent to remove
53+
* @return true if the element has been removed
54+
*/
55+
boolean removeCinematicEvent(KeyFrame keyFrame, CinematicEvent cinematicEvent);
56+
57+
/**
58+
* Binds a camera to this Cinematic, tagged by a unique name. This method
59+
* creates and returns a CameraNode for the cam and attaches it to the scene.
60+
* The control direction is set to SpatialToCamera. This camera Node can
61+
* then be used in other events to handle the camera movements during
62+
* playback.
63+
*
64+
* @param cameraName the unique tag the camera should have
65+
* @param cam the scene camera.
66+
* @return the created CameraNode.
67+
*/
68+
CameraNode bindCamera(String cameraName, Camera cam);
69+
70+
/**
71+
* returns a cameraNode given its name
72+
*
73+
* @param cameraName the camera name (as registered in
74+
* Cinematic#bindCamera())
75+
* @return the cameraNode for this name
76+
*/
77+
CameraNode getCamera(String cameraName);
78+
79+
/**
80+
* Sets the active camera instantly (use activateCamera if you want to
81+
* schedule that event)
82+
*
83+
* @param cameraName the camera name (as registered in
84+
* Cinematic#bindCamera())
85+
*/
86+
void setActiveCamera(String cameraName);
87+
88+
/**
89+
* schedule an event that will activate the camera at the given time
90+
*
91+
* @param timeStamp the time to activate the cam
92+
* @param cameraName the camera name (as registered in
93+
* Cinematic#bindCamera())
94+
*/
95+
void activateCamera(float timeStamp, String cameraName);
96+
97+
/**
98+
* used internally put an eventdata in the cinematic
99+
*
100+
* @param type the type of data
101+
* @param key the key
102+
* @param object the data
103+
*/
104+
void putEventData(String type, Object key, Object object);
105+
106+
/**
107+
* used internally return and event data
108+
*
109+
* @param type the type of data
110+
* @param key the key
111+
* @return the pre-existing object, or null
112+
*/
113+
Object getEventData(String type, Object key);
114+
115+
/**
116+
* Used internally remove an eventData
117+
*
118+
* @param type the type of data
119+
* @param key the key of the data
120+
*/
121+
void removeEventData(String type, Object key);
122+
123+
/**
124+
* Clears all camera nodes bound to the cinematic from the scene node.
125+
* This method removes all previously bound CameraNodes and clears the
126+
* internal camera map, effectively detaching all cameras from the scene.
127+
*/
128+
void clearCameras();
129+
130+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import com.jme3.animation.AnimationUtils;
3535
import com.jme3.animation.LoopMode;
3636
import com.jme3.app.Application;
37-
import com.jme3.cinematic.Cinematic;
37+
import com.jme3.cinematic.CinematicHandler;
3838
import com.jme3.cinematic.PlayState;
3939
import com.jme3.export.InputCapsule;
4040
import com.jme3.export.JmeExporter;
@@ -317,7 +317,7 @@ public void read(JmeImporter im) throws IOException {
317317
* @param cinematic ignored
318318
*/
319319
@Override
320-
public void initEvent(Application app, Cinematic cinematic) {
320+
public void initEvent(Application app, CinematicHandler cinematic) {
321321
}
322322

323323
/**

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import com.jme3.animation.LoopMode;
3737
import com.jme3.app.Application;
3838
import com.jme3.cinematic.Cinematic;
39+
import com.jme3.cinematic.CinematicHandler;
3940
import com.jme3.cinematic.PlayState;
4041
import com.jme3.export.InputCapsule;
4142
import com.jme3.export.JmeExporter;
@@ -127,10 +128,14 @@ protected AnimEvent() {
127128
* @param cinematic the Cinematic that contains this event
128129
*/
129130
@Override
130-
public void initEvent(Application app, Cinematic cinematic) {
131+
public void initEvent(Application app, CinematicHandler cinematic) {
131132
super.initEvent(app, cinematic);
132133
}
133134

135+
@Deprecated
136+
public void initEvent(Application app, Cinematic cinematic) {
137+
initEvent(app, (CinematicHandler) cinematic);
138+
}
134139

135140
/**
136141
* Callback when the event is paused.

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import com.jme3.animation.*;
3535
import com.jme3.app.Application;
3636
import com.jme3.cinematic.Cinematic;
37+
import com.jme3.cinematic.CinematicHandler;
3738
import com.jme3.cinematic.PlayState;
3839
import com.jme3.export.*;
3940
import com.jme3.scene.Node;
@@ -287,9 +288,9 @@ public AnimationEvent(Spatial model, String animationName, float initialDuration
287288

288289
@Override
289290
@SuppressWarnings("unchecked")
290-
public void initEvent(Application app, Cinematic cinematic) {
291-
super.initEvent(app, cinematic);
292-
this.cinematic = cinematic;
291+
public void initEvent(Application app, CinematicHandler handler) {
292+
super.initEvent(app, handler);
293+
this.cinematic = (Cinematic) handler;
293294
if (channel == null) {
294295
Object s = cinematic.getEventData(MODEL_CHANNELS, model);
295296
if (s == null) {

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
package com.jme3.cinematic.events;
3333

3434
import com.jme3.app.Application;
35-
import com.jme3.cinematic.Cinematic;
35+
import com.jme3.cinematic.CinematicHandler;
3636
import com.jme3.export.InputCapsule;
3737
import com.jme3.export.JmeExporter;
3838
import com.jme3.export.JmeImporter;
@@ -55,7 +55,7 @@ public class CameraEvent extends AbstractCinematicEvent {
5555
* The `Cinematic` instance to which this event belongs and on which the
5656
* camera will be set.
5757
*/
58-
private Cinematic cinematic;
58+
private CinematicHandler cinematic;
5959

6060
/**
6161
* For serialization only. Do not use.
@@ -69,13 +69,13 @@ public CameraEvent() {
6969
* @param cinematic The `Cinematic` instance this event belongs to (cannot be null).
7070
* @param cameraName The name of the camera to be activated by this event (cannot be null or empty).
7171
*/
72-
public CameraEvent(Cinematic cinematic, String cameraName) {
72+
public CameraEvent(CinematicHandler cinematic, String cameraName) {
7373
this.cinematic = cinematic;
7474
this.cameraName = cameraName;
7575
}
7676

7777
@Override
78-
public void initEvent(Application app, Cinematic cinematic) {
78+
public void initEvent(Application app, CinematicHandler cinematic) {
7979
super.initEvent(app, cinematic);
8080
this.cinematic = cinematic;
8181
}
@@ -116,15 +116,15 @@ public void setTime(float time) {
116116
* Returns the `Cinematic` instance associated with this event.
117117
* @return The `Cinematic` instance.
118118
*/
119-
public Cinematic getCinematic() {
119+
public CinematicHandler getCinematic() {
120120
return cinematic;
121121
}
122122

123123
/**
124124
* Sets the `Cinematic` instance for this event.
125125
* @param cinematic The `Cinematic` instance to set (cannot be null).
126126
*/
127-
public void setCinematic(Cinematic cinematic) {
127+
public void setCinematic(CinematicHandler cinematic) {
128128
this.cinematic = cinematic;
129129
}
130130

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
import com.jme3.animation.LoopMode;
3535
import com.jme3.app.Application;
36-
import com.jme3.cinematic.Cinematic;
36+
import com.jme3.cinematic.CinematicHandler;
3737
import com.jme3.cinematic.PlayState;
3838
import com.jme3.export.Savable;
3939

@@ -135,7 +135,7 @@ public interface CinematicEvent extends Savable {
135135
* @param app the application
136136
* @param cinematic the cinematic
137137
*/
138-
public void initEvent(Application app, Cinematic cinematic);
138+
public void initEvent(Application app, CinematicHandler cinematic);
139139

140140
/**
141141
* Fast-forwards to the given time, where time=0 is the start of the event.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import com.jme3.animation.AnimationUtils;
3535
import com.jme3.animation.LoopMode;
3636
import com.jme3.app.Application;
37-
import com.jme3.cinematic.Cinematic;
37+
import com.jme3.cinematic.CinematicHandler;
3838
import com.jme3.cinematic.MotionPath;
3939
import com.jme3.cinematic.PlayState;
4040
import com.jme3.export.InputCapsule;
@@ -197,7 +197,7 @@ public void internalUpdate(float tpf) {
197197
}
198198

199199
@Override
200-
public void initEvent(Application app, Cinematic cinematic) {
200+
public void initEvent(Application app, CinematicHandler cinematic) {
201201
super.initEvent(app, cinematic);
202202
isControl = false;
203203
}

0 commit comments

Comments
 (0)