net.jinx.action
Class Clock

java.lang.Object
  extended by net.jinx.action.Actor
      extended by net.jinx.action.Clock
All Implemented Interfaces:
OwnerListener, SceneListener
Direct Known Subclasses:
RealTimeClock, SteppingClock

public abstract class Clock
extends Actor
implements OwnerListener

Clock keeps track of time for a Scene and then activates other Actors by sending them ClockEvent and IdleEvent objects.

API Stability: Beta.


Field Summary
protected  java.lang.Object sync
          The synchronization object.
 
Constructor Summary
protected Clock(java.lang.String name, float deltaTime)
          Constructs a new Clock.
 
Method Summary
 void actorAdded(Actor actor, Scene scene)
          Notifies this Clock that an Actor has been added to it's owner.
 void actorRemoved(Actor actor, Scene scene)
          Notifies this Clock that an Actor has been removed from it's owner.
 float getDeltaTime()
          Provides the current change in time value.
protected  void processEvent(ActorEvent event)
          Does nothing.
protected  void sendClockEvent(float dt)
          Sends ClockEvents to all ClockSensitive Actors.
protected  void sendClockStateEvent(int state)
          Sends a ClockStateEvent to all ClockSensitive and IdleSensitive Actors.
protected  void sendIdleEvent(float dt, float i)
          Sends an IdleEvent to all the current IdleSensitive Actors.
 void setDeltaTime(float deltaTime)
          Sets the change in time calue for this Clock.
 
Methods inherited from class net.jinx.action.Actor
checkAllowAdd, getName, getOwner, hashCode, ownerChanged, sendEvent, sendEvent, sendEvent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sync

protected final java.lang.Object sync
The synchronization object.

Constructor Detail

Clock

protected Clock(java.lang.String name,
                float deltaTime)
Constructs a new Clock.

Parameters:
name - the name of the Clock.
deltaTime - the change in time value for this clock.
Throws:
java.lang.IllegalArgumentException - if deltaTime is less than or equal to zero.
Method Detail

setDeltaTime

public void setDeltaTime(float deltaTime)
Sets the change in time calue for this Clock. This is the amount of time in seconds to wait between sending ClockEvents. This is synchronized, so it can be called at any time.

Parameters:
deltaTime - the change in time value.
Throws:
java.lang.IllegalArgumentException - if the value is less than or equal to zero.

getDeltaTime

public float getDeltaTime()
Provides the current change in time value.

Returns:
the value.

sendClockStateEvent

protected void sendClockStateEvent(int state)
Sends a ClockStateEvent to all ClockSensitive and IdleSensitive Actors.

Parameters:
state - the state constant to use.

sendClockEvent

protected void sendClockEvent(float dt)
Sends ClockEvents to all ClockSensitive Actors.

Parameters:
dt - the change in time value.

sendIdleEvent

protected void sendIdleEvent(float dt,
                             float i)
Sends an IdleEvent to all the current IdleSensitive Actors.

Parameters:
dt - the current change in time for this TimeSource.
i - the interpolation value. Zero means that no time has passed since the most recent ClockEvent. One means that dt seconds have passed. Larger values have proportionate meaning.

actorAdded

public void actorAdded(Actor actor,
                       Scene scene)
Notifies this Clock that an Actor has been added to it's owner. If it is either ClockSensitive or IdleSensitive, it will be used. Otherwise, it's ignored.

Specified by:
actorAdded in interface SceneListener
Parameters:
actor - the Actor to check and then possibly use.
scene - the Scene that actor came from. If this is not the same as the results of the getOwner() method, then the actor is ignored.

actorRemoved

public void actorRemoved(Actor actor,
                         Scene scene)
Notifies this Clock that an Actor has been removed from it's owner.

Specified by:
actorRemoved in interface SceneListener
Parameters:
actor - the Actor that has been removed from scene.
scene - the scene that actor came from.

processEvent

protected void processEvent(ActorEvent event)
Does nothing. Clocks are meant to send events, not receive them.

Specified by:
processEvent in class Actor
Parameters:
event - the ActorEvent to process.