Created TimedPath to factor out code common to paths that effect
themselves in a fixed period of time. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1688 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: LinePath.java,v 1.9 2002/06/18 22:25:33 mdb Exp $
|
// $Id: LinePath.java,v 1.10 2002/09/17 03:59:05 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.media.util;
|
package com.threerings.media.util;
|
||||||
|
|
||||||
@@ -11,13 +11,12 @@ import java.awt.Point;
|
|||||||
import com.samskivert.util.StringUtil;
|
import com.samskivert.util.StringUtil;
|
||||||
|
|
||||||
import com.threerings.media.Log;
|
import com.threerings.media.Log;
|
||||||
import com.threerings.media.util.MathUtil;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The line path is used to cause a pathable to go from point A to point B
|
* The line path is used to cause a pathable to go from point A to point B
|
||||||
* in a certain number of milliseconds.
|
* in a certain number of milliseconds.
|
||||||
*/
|
*/
|
||||||
public class LinePath implements Path
|
public class LinePath extends TimedPath
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Constructs a line path between the two specified points that will
|
* Constructs a line path between the two specified points that will
|
||||||
@@ -34,29 +33,9 @@ public class LinePath implements Path
|
|||||||
*/
|
*/
|
||||||
public LinePath (Point source, Point dest, long duration)
|
public LinePath (Point source, Point dest, long duration)
|
||||||
{
|
{
|
||||||
// sanity check some things
|
super(duration);
|
||||||
if (duration <= 0) {
|
|
||||||
String errmsg = "Requested path with illegal duration (<=0) " +
|
|
||||||
"[duration=" + duration + "]";
|
|
||||||
throw new IllegalArgumentException(errmsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
_source = source;
|
_source = source;
|
||||||
_dest = dest;
|
_dest = dest;
|
||||||
_duration = duration;
|
|
||||||
}
|
|
||||||
|
|
||||||
// documentation inherited
|
|
||||||
public void init (Pathable pable, long timestamp)
|
|
||||||
{
|
|
||||||
// give the pable a chance to perform any starting antics
|
|
||||||
pable.pathBeginning();
|
|
||||||
|
|
||||||
// make a note of when we started
|
|
||||||
_startStamp = timestamp;
|
|
||||||
|
|
||||||
// update our position to the start of the path
|
|
||||||
tick(pable, timestamp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
@@ -83,12 +62,6 @@ public class LinePath implements Path
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited
|
|
||||||
public void fastForward (long timeDelta)
|
|
||||||
{
|
|
||||||
_startStamp += timeDelta;
|
|
||||||
}
|
|
||||||
|
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
public void paint (Graphics2D gfx)
|
public void paint (Graphics2D gfx)
|
||||||
{
|
{
|
||||||
@@ -97,11 +70,11 @@ public class LinePath implements Path
|
|||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
public String toString ()
|
protected void toString (StringBuffer buf)
|
||||||
{
|
{
|
||||||
return "[src=" + StringUtil.toString(_source) +
|
super.toString(buf);
|
||||||
", dest=" + StringUtil.toString(_dest) +
|
buf.append(", src=").append(StringUtil.toString(_source));
|
||||||
", duration=" + _duration + "ms]";
|
buf.append(", dest=").append(StringUtil.toString(_dest));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -125,10 +98,4 @@ public class LinePath implements Path
|
|||||||
/** A temporary point used when computing our position along the
|
/** A temporary point used when computing our position along the
|
||||||
* path. */
|
* path. */
|
||||||
protected Point _tpos = new Point();
|
protected Point _tpos = new Point();
|
||||||
|
|
||||||
/** The time at which we started along the path. */
|
|
||||||
protected long _startStamp;
|
|
||||||
|
|
||||||
/** The duration that we're to spend following the path. */
|
|
||||||
protected long _duration;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
//
|
||||||
|
// $Id: TimedPath.java,v 1.1 2002/09/17 03:59:05 mdb Exp $
|
||||||
|
|
||||||
|
package com.threerings.media.util;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A base class for path implementations that endeavor to move their
|
||||||
|
* pathables along a path in a specified number of milliseconds.
|
||||||
|
*/
|
||||||
|
public abstract class TimedPath implements Path
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Configures the timed path with the duration in which it must
|
||||||
|
* traverse its path.
|
||||||
|
*/
|
||||||
|
public TimedPath (long duration)
|
||||||
|
{
|
||||||
|
// sanity check some things
|
||||||
|
if (duration <= 0) {
|
||||||
|
String errmsg = "Requested path with illegal duration (<=0) " +
|
||||||
|
"[duration=" + duration + "]";
|
||||||
|
throw new IllegalArgumentException(errmsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
_duration = duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
// documentation inherited
|
||||||
|
public void init (Pathable pable, long timestamp)
|
||||||
|
{
|
||||||
|
// give the pable a chance to perform any starting antics
|
||||||
|
pable.pathBeginning();
|
||||||
|
|
||||||
|
// make a note of when we started
|
||||||
|
_startStamp = timestamp;
|
||||||
|
|
||||||
|
// update our position to the start of the path
|
||||||
|
tick(pable, timestamp);
|
||||||
|
}
|
||||||
|
|
||||||
|
// documentation inherited
|
||||||
|
public void fastForward (long timeDelta)
|
||||||
|
{
|
||||||
|
_startStamp += timeDelta;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a string representation of this instance.
|
||||||
|
*/
|
||||||
|
public String toString ()
|
||||||
|
{
|
||||||
|
StringBuffer buf = new StringBuffer("[");
|
||||||
|
toString(buf);
|
||||||
|
return buf.append("]").toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An extensible method for generating a string representation of this
|
||||||
|
* instance.
|
||||||
|
*/
|
||||||
|
protected void toString (StringBuffer buf)
|
||||||
|
{
|
||||||
|
buf.append("duration=").append(_duration).append("ms");
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The duration that we're to spend following the path. */
|
||||||
|
protected long _duration;
|
||||||
|
|
||||||
|
/** The time at which we started along the path. */
|
||||||
|
protected long _startStamp;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user