Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## gecco.server.clock
Class Clock

    java.lang.Object
      java.lang.Thread
          gecco.util.SignalThread
              gecco.server.clock.Clock

All Implemented Interfaces:
  Runnable, SignalRunnable

public class Clock
extends SignalThread

This is a virtual game clock. It keeps track of the game time and its relation to real time. At any moment, the relationship is linear, but seen over the course of a whole game, the function will be pieced together of many such linear functions.

Author:
  Karl Hasselström

Field Summary

Fields inherited from class java.lang.Thread
`MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY`

Fields inherited from interface gecco.util.SignalRunnable
`SIGKILL, SIGNONE, SIGPAUSE, SIGQUIT, SIGRESUME`

Constructor Summary
`Clock(double startTime, double speed, double normalSpeed, boolean isFrozen)` Create a game clock.

Method Summary
`void` | `freeze(boolean freeze)` Freezes or unfreezes the game.
`void` | `gameSleep(double time)` Sleep for the specified amount of game time.
`double` | `gameTime(double realTime)` Converts real time to game time.
`double` | `gameTimeNow()` Returns the current game time, in seconds.
`void` | `gameWait(Object obj, double time)` Wait on an object for (at most) the specified amount of game time.
`double` | `getNormalSpeed()` Returns the normal speed of the game time.
`double` | `getSpeed()` Gets the Speed attribute of the Clock object
`boolean` | `isFrozen()` Gets the Frozen attribute of the Clock object
`void` | `realSleep(double time)` Sleep for the specified amount of real time.
`double` | `realTime(double gameTime)` Converts game time to real time.
`double` | `realTimeNow()` Returns the current value of the real-time clock, in seconds.
`void` | `realWait(Object obj, double time)` Wait on the specified object for (at most) the specified amount of real time.
`void` | `run()` Wake up sleeping threads at the times they asked for.
`void` | `setNormalSpeed()` Sets the speed of the game to its default value.
`void` | `setSpeed(double speed)` Sets the speed of the game.

Methods inherited from class gecco.util.SignalThread
`clearSignal, current, pauseHandler, sendSignal, signalPending`

Methods inherited from class java.lang.Thread
`activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### Clock

    public Clock(double startTime,
                 double speed,
                 double normalSpeed,
                 boolean isFrozen)

  Create a game clock.

Parameters:
  `speed` - The speed of the game time.
  `normalSpeed` - The normal speed of the game time.
  `startTime` - The game time should start at this value.
  `isFrozen` - `true` if the game time is initially frozen, `false` otherwise.

Method Detail

### setNormalSpeed

    public void setNormalSpeed()

  Sets the speed of the game to its default value.

### setSpeed

    public void setSpeed(double speed)

  Sets the speed of the game.

  Parameters:
    `speed` - The new speed of the game time.

### getSpeed

    public double getSpeed()

  Gets the Speed attribute of the Clock object

  Returns:
    The Speed value

### getNormalSpeed

    public double getNormalSpeed()

  Returns the normal speed of the game time.

  Returns:
    The normal speed.

### isFrozen

    public boolean isFrozen()

  Gets the Frozen attribute of the Clock object

  Returns:
    The Frozen value

### realTime

    public double realTime(double gameTime)

  Converts game time to real time.

  Parameters:
    `gameTime` - A point in game time.
  Returns:
    The corresponding point in real time.

### realTimeNow

    public double realTimeNow()

  Returns the current value of the real-time clock, in seconds.

  Returns:
    The real time in seconds.

### gameTime

    public double gameTime(double realTime)

  Converts real time to game time.

  Parameters:
    `realTime` - A point in real time.
  Returns:
    The corresponding point in game time.

### gameTimeNow

    public double gameTimeNow()

  Returns the current game time, in seconds.

  Returns:
    The game time in seconds.

### realSleep

    public void realSleep(double time)
                   throws InterruptedException

  Sleep for the specified amount of real time.

  Parameters:
    `time` - The number of real seconds to sleep.
  Throws:
    `InterruptedException` - If the thread is interrupted.

### realWait

    public void realWait(Object obj,
                         double time)
                  throws InterruptedException

  Wait on the specified object for (at most) the specified amount of real time.

  Parameters:
    `obj` - The object to wait on.
    `time` - The number of real seconds to wait.
  Throws:
    `InterruptedException` - If the thread is interrupted.

### gameSleep

    public void gameSleep(double time)
                   throws InterruptedException

  Sleep for the specified amount of game time.

  Parameters:
    `time` - The number of game seconds to sleep.
  Throws:
    `InterruptedException` - If the thread is interrupted.

### gameWait

    public void gameWait(Object obj,
                         double time)
                  throws InterruptedException

  Wait on an object for (at most) the specified amount of game time.

  Parameters:
    `obj` - The object.
    `time` - The number of game seconds to wait.
  Throws:
    `InterruptedException` - If the thread is interrupted.

### freeze

    public void freeze(boolean freeze)

  Freezes or unfreezes the game.

  Parameters:
    `freeze` - true if the game should freeze, false if it should unfreeze.

### run

    public void run()

  Wake up sleeping threads at the times they asked for.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD