From 428afd4ca0e08948b94386fb224446fd9a054dc8 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Sat, 4 Feb 2006 03:24:44 +0000 Subject: [PATCH] Add support for being notified when a camera path is complete. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3830 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../threerings/jme/camera/CameraHandler.java | 20 +++++++++++++++++++ .../com/threerings/jme/camera/CameraPath.java | 12 +++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/java/com/threerings/jme/camera/CameraHandler.java b/src/java/com/threerings/jme/camera/CameraHandler.java index bfc2dc6ee..75177b200 100644 --- a/src/java/com/threerings/jme/camera/CameraHandler.java +++ b/src/java/com/threerings/jme/camera/CameraHandler.java @@ -27,6 +27,8 @@ import com.jme.math.Plane; import com.jme.math.Vector3f; import com.jme.renderer.Camera; +import com.samskivert.util.ObserverList; + /** * Provides various useful mechanisms for manipulating the camera. */ @@ -125,6 +127,7 @@ public class CameraHandler { if (_campath != null) { _campath.abort(); + _campathobs.apply(new CompletedOp(_campath)); } _campath = path; } @@ -146,6 +149,7 @@ public class CameraHandler { if (_campath != null) { if (_campath.tick(frameTime)) { + _campathobs.apply(new CompletedOp(_campath)); _campath = null; } } @@ -317,8 +321,24 @@ public class CameraHandler } } + /** Used to dispatch {@link CameraPath.Observer#pathCompleted}. */ + protected static class CompletedOp implements ObserverList.ObserverOp + { + public CompletedOp (CameraPath path) { + _path = path; + } + public boolean apply (Object observer) { + ((CameraPath.Observer)observer).pathCompleted(_path); + return true; + } + protected CameraPath _path; + } + protected Camera _camera; protected CameraPath _campath; + protected ObserverList _campathobs = + new ObserverList(ObserverList.SAFE_IN_ORDER_NOTIFY); + protected Matrix3f _rotm = new Matrix3f(); protected Vector3f _temp = new Vector3f(); diff --git a/src/java/com/threerings/jme/camera/CameraPath.java b/src/java/com/threerings/jme/camera/CameraPath.java index 38d4ffae5..746561b84 100644 --- a/src/java/com/threerings/jme/camera/CameraPath.java +++ b/src/java/com/threerings/jme/camera/CameraPath.java @@ -28,6 +28,18 @@ import com.jme.renderer.Camera; */ public abstract class CameraPath { + /** Used to inform observers when a camera path is completed or aborted. */ + public interface Observer + { + /** + * Called when this path is finished (potentially early because another + * path was set before this path completed). + * + * @param path the path that was completed. + */ + public void pathCompleted (CameraPath path); + } + /** * This is called on every frame to allow the path to adjust the position * of the camera.