org.globalse.arena.frag.objects
Class ObjectManager

java.lang.Object
  |
  +--org.globalse.arena.frag.objects.ObjectManager

public class ObjectManager
extends java.lang.Object
implements EventSource, EventSink

The ObjectManager handles all object associated events, such as state updates or controller changes. It is also responsible for checking which objects are in focus and therefore candidates to be controlled. It stores the objects in a HashTable with the object names as keys to speed up object lookup.


Constructor Summary
ObjectManager(java.lang.String gameName, java.lang.String playerName)
          Consturctor of the class.
 
Method Summary
 boolean addObject(FRAGObject object)
          Stores the data of an object in a {@ Hashtable}.
 MathVector checkMove(java.lang.String objName, MathVector newPosition, MathVector oldPosition)
          Called whenever an object changes its position.
 EventDistributor eventDistributor()
          Returns the eventDistributor for the class.
 java.lang.String getFocusCenter()
          Returns the focus center of the local peer.
 GameManager getGameManager()
          Returns the GameManager of the current game.
 java.lang.String getGameName()
           
 java.lang.String getPlayerName()
           
 void importObjects(java.util.Hashtable extern)
          Imports Hashtable with already created objects.
 boolean killObject(java.lang.String objName)
          deletets a object from the ObjectManager's table.
 FRAGObject lookupObject(java.lang.String objName)
          Returns the data of an object, which is stored in the class FRAGObject.
 void makeOwner(java.lang.String objName)
          makes the local peer the owner (and the controller) of the FRAGObject (keyname = objName), sends a ObjectUpdateEvent
 java.util.Hashtable objects()
          Returns a copy of the Hashtable with all objects (object data and object names as keys).
 void processEvent(Event event)
          Handles all types of incoming events: ObjectUpdateEvent, ObjectControllerEvent, ObjectActionEvent - looks for the data, matching the event.
 void releaseAndKillObjects(java.lang.String owner)
          Remove all objects, owned by a player, from the Hashtable, where the objects data is stored.
 void setFocusCenter(java.lang.String focusCenter)
          sets the focusCenter of the local peer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectManager

public ObjectManager(java.lang.String gameName,
                     java.lang.String playerName)
Consturctor of the class. The game name and the player name are are saved in class variables.
Parameters:
gameName - the name of the game
playerName - the name of the player
Method Detail

lookupObject

public FRAGObject lookupObject(java.lang.String objName)
Returns the data of an object, which is stored in the class FRAGObject.
Parameters:
objName - the name of the object, which is used for resolving the data of the object, using a hash table
Returns:
the data of the object, associated with the given name
See Also:
FRAGObject

addObject

public boolean addObject(FRAGObject object)
Stores the data of an object in a {@ Hashtable}. Each object has a corresponding name, which is stored as key, mapping the data of the object in the Hashtable.
Parameters:
object - the data of the object
Returns:
True if the object was stored, False if an object with the same name already exists
See Also:
FRAGObject

processEvent

public void processEvent(Event event)
Handles all types of incoming events: ObjectUpdateEvent, ObjectControllerEvent, ObjectActionEvent - looks for the data, matching the event. If the data already exists in the Hashtable and the version number of the data in the Hashtable is older, then the data is being updated. ObjectKilledEvent - in this case the object is deleted from the Hashtable
Specified by:
processEvent in interface EventSink
Parameters:
event - an event, bound to an object.

makeOwner

public void makeOwner(java.lang.String objName)
makes the local peer the owner (and the controller) of the FRAGObject (keyname = objName), sends a ObjectUpdateEvent
Parameters:
objName - name of the object

killObject

public boolean killObject(java.lang.String objName)
deletets a object from the ObjectManager's table. sends a ObjectKilledEvent to all peers
Parameters:
objName - the name of the object to be deleted returns boolean true, if succesful; false, if not succesful
Returns:
boolean returns true if kill was successfully.

checkMove

public MathVector checkMove(java.lang.String objName,
                            MathVector newPosition,
                            MathVector oldPosition)
Called whenever an object changes its position. Computes the distance to the other objects and changes the position of objName by calling the checkCollision methode of each object
Parameters:
objName - name of moved object
newPosition - position, the objName would like to move to
oldPosition - old position of objName
Returns:
MathVector position to which objName is allowed to move

releaseAndKillObjects

public void releaseAndKillObjects(java.lang.String owner)
Remove all objects, owned by a player, from the Hashtable, where the objects data is stored.
Parameters:
owner - Sring the owner of the object
Preconditions:
owner != ""

objects

public java.util.Hashtable objects()
Returns a copy of the Hashtable with all objects (object data and object names as keys).
Returns:
a Hashtable copy with the objects

importObjects

public void importObjects(java.util.Hashtable extern)
Imports Hashtable with already created objects.
Parameters:
extern - a Hashtable with objects

eventDistributor

public EventDistributor eventDistributor()
Returns the eventDistributor for the class.
Specified by:
eventDistributor in interface EventSource
Returns:
the eventDistributor

getGameName

public java.lang.String getGameName()

getPlayerName

public java.lang.String getPlayerName()

getFocusCenter

public java.lang.String getFocusCenter()
Returns the focus center of the local peer.
Returns:
string the focus center

setFocusCenter

public void setFocusCenter(java.lang.String focusCenter)
sets the focusCenter of the local peer
Parameters:
focusCenter - String sets the focus center

getGameManager

public GameManager getGameManager()
Returns the GameManager of the current game.
Returns:
the GameManager of the current game
See Also:
GameManager



This page is hosted by the Chair for Applied Software Engineering of the Technische Universität München.
Imprint (Impressum)