server.framework.threads
Class GameThread

java.lang.Object
  extended by server.framework.threads.GameThread
All Implemented Interfaces:
java.lang.Runnable

public class GameThread
extends java.lang.Object
implements java.lang.Runnable

This thread is responsible for bundling player positions into one big position message, instead of transmitting many small position messages.

Author:
Martin Jarrett, Eivind Sorteberg

Field Summary
static int POSITION_INTERVAL
           
 
Constructor Summary
GameThread(AbstractSession session)
          Initiates the GameThread's lists and assigns the thread's session.
 
Method Summary
 void addPosition(AbstractPlayer sender, java.lang.Object[] position)
          Adds a position to the position list.
 void freezePlayer(AbstractPlayer player, int duration)
          "Freezes" a player to a position for a given duration.
static void main(java.lang.String[] args)
          Test method used to test the performance of the bundle generation method.
 void run()
          The loop that is responsible for creating and sending position bundles with regular intervals.
 void stop()
          Called when the game is over.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

POSITION_INTERVAL

public static final int POSITION_INTERVAL
See Also:
Constant Field Values
Constructor Detail

GameThread

public GameThread(AbstractSession session)
Initiates the GameThread's lists and assigns the thread's session.

Parameters:
session - The session owning the game thread.
Method Detail

run

public void run()
The loop that is responsible for creating and sending position bundles with regular intervals. The frequency of these message transmissions is determined by the POSITION_INTERVAL variable.

Specified by:
run in interface java.lang.Runnable

stop

public void stop()
Called when the game is over. Stops the position bundle generation.


addPosition

public void addPosition(AbstractPlayer sender,
                        java.lang.Object[] position)
Adds a position to the position list.

Parameters:
sender - The player.
position - The position.

freezePlayer

public void freezePlayer(AbstractPlayer player,
                         int duration)
"Freezes" a player to a position for a given duration. Position updates are not forwarded from the player for the next milliseconds. Used when a player dies, to ensure that the next received position (near the trap) is not forwarded.

Parameters:
player - The player to freeze in place.
duration - The duration of the freeze.

main

public static void main(java.lang.String[] args)
Test method used to test the performance of the bundle generation method. Runs 1 000 000 tests with 50 player positions, and calculates the maximum and average time the method uses to complete.

Parameters:
args - Empty.