wyvern.lib.properties
Class SuspendableTimer

java.lang.Object
  extended bywyvern.lib.properties.SuspendableTimer
All Implemented Interfaces:
MethodHookCallback, Timed

public class SuspendableTimer
extends java.lang.Object
implements Timed, MethodHookCallback

A proxy for a repeating timer that knows how to stop when the target's map suspends (or unloads), and resume when the target's map resumes.

Version:
1.0, Jul 04, 2002
Author:
Steve Yegge

Constructor Summary
SuspendableTimer(Timed target, long period)
          Constructs a new SuspendableTimer for the specified target object.
 
Method Summary
protected  void addHooks(GameMap map)
          Adds the map hooks.
protected  void killTimer()
          Kills the timer.
 void methodCalled(java.lang.String hookName, MethodHookable target, java.lang.Object data)
          The map suspend/unload/resume method-hook was called.
protected  void removeHooks(GameMap map)
          Removes hooks
 void start(GameMap map)
          Starts the timer.
protected  void startTimer()
          Starts the timer up.
 void stop()
          Stops the timer and removes the hooks from the map.
 void timerExpired()
          Timer went off.
 java.lang.String toString()
          Prints debugging string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SuspendableTimer

public SuspendableTimer(Timed target,
                        long period)
Constructs a new SuspendableTimer for the specified target object.

Parameters:
period - the timer delay/period in millis
target - the object to call back when our timer goes off
Method Detail

start

public void start(GameMap map)
Starts the timer. Stops any old timer that might have been going, re-adds the hooks to the map, and starts the repeating timer.


stop

public void stop()
Stops the timer and removes the hooks from the map.


addHooks

protected void addHooks(GameMap map)
Adds the map hooks.


removeHooks

protected void removeHooks(GameMap map)
Removes hooks


methodCalled

public void methodCalled(java.lang.String hookName,
                         MethodHookable target,
                         java.lang.Object data)
The map suspend/unload/resume method-hook was called.

Specified by:
methodCalled in interface MethodHookCallback
Parameters:
hookName - the name of the hook being run
target - the object on which the method was invoked: a GameMap or GameObject.
data - a method-specific data object; can be null. Check the documentation for the method hook to see if any data is passed to the callbacks.

startTimer

protected void startTimer()
Starts the timer up. Don't call this directly; call start().


killTimer

protected void killTimer()
Kills the timer. Don't call it directly; use stop().


timerExpired

public void timerExpired()
Timer went off. Calls the target's timerExpired() method.

Specified by:
timerExpired in interface Timed

toString

public java.lang.String toString()
Prints debugging string.