com.planeth.gtroids.environment
Class FieldedArea

java.lang.Object
  extended bycom.planeth.gtroids.environment.FieldedArea

public class FieldedArea
extends java.lang.Object

FieldedArea is an in quadrants splitted space to manage game objects

Author:
Andreas Grässer, gal@planet-h.com.
created 02.10.2005
See Also:
Quadrant, QuadrantIterator

Constructor Summary
FieldedArea()
           
 
Method Summary
 void addPhysicalObject(AbstractPhysicalObject physicalObject)
          Adds a AbstractPhysicalObject to the FieldedArea
 void deleteAllPhysicalObjects()
          Removes all Objects from the FieldedArea
 Quadrant findQuadrant(int X, int Y)
          Returns the Quadrant for the passed coordinates
 java.util.Iterator getCollisionObjectIterator(AbstractPhysicalObject physicalObject)
          Returns an Iterator with the objects of the following Quadrants:
The Quadrant of the passed PhysicalObject (only the Objects after the passed PysicalObject included)
The Quadrant at East
The Quadrant at South-East
The Quadrant at South
This Iterator is used to get the Objects for Collision checks.
 java.util.Iterator getObjectIterator()
          Returns an Iterator with the objects of all Quadrants
 java.util.Iterator getObjectSnapShotIterator()
          Returns an Iterator with the objects of all Quadrants.
 Vector2D getQuadrantCoordsForPos(Vector2D pos)
          Returns the quadrant coordinates for the passed position
 int getQuadrantCount()
          Returns the number of quadrants in the area
 java.util.Iterator getRangedObjectIterator(AbstractPhysicalObject physicalObject, int range)
          Returns an Iterator with the objects of the Quadrants within a defined range from the viewpoint of the passed PhysicalObject.
 void initQuadrants(int width, int height)
          Initializes the Quadrants
 void paint(java.awt.Graphics g)
          Paints the FieldedArea into the passed Graphics
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FieldedArea

public FieldedArea()
Method Detail

getQuadrantCount

public int getQuadrantCount()
Returns the number of quadrants in the area

Returns:
Returns the number of quadrants in the area

initQuadrants

public void initQuadrants(int width,
                          int height)
Initializes the Quadrants


getObjectIterator

public java.util.Iterator getObjectIterator()
Returns an Iterator with the objects of all Quadrants

Returns:
Returns an Iterator with the objects of all Quadrants

getObjectSnapShotIterator

public java.util.Iterator getObjectSnapShotIterator()
Returns an Iterator with the objects of all Quadrants.
In this special case the Iterator referencing a snapshot(copy) of the real Quadrants. This is needed for example to kill a lot of PysicalObjects at the same time. The snapshotIterator is not affected by deleted items.

Returns:
Returns an Iterator with the objects of all Quadrants (snapshot).

getRangedObjectIterator

public java.util.Iterator getRangedObjectIterator(AbstractPhysicalObject physicalObject,
                                                  int range)
Returns an Iterator with the objects of the Quadrants within a defined range from the viewpoint of the passed PhysicalObject.
This Iterator is useful, if you want Objects beeing affected by the Objects within a defined area.

Parameters:
physicalObject - the PhysicalObject which defines the startPoint for the range
range - the range of Quadrants from the viewPoint of the PhysicalObject
Returns:
Ranged Iterator with defined range and viewPoint

getCollisionObjectIterator

public java.util.Iterator getCollisionObjectIterator(AbstractPhysicalObject physicalObject)
Returns an Iterator with the objects of the following Quadrants:
The Quadrant of the passed PhysicalObject (only the Objects after the passed PysicalObject included)
The Quadrant at East
The Quadrant at South-East
The Quadrant at South
This Iterator is used to get the Objects for Collision checks. With this Iterator used every check (obj / obj) is done only once.

Parameters:
physicalObject -
Returns:
Returns the CollisionIterator (self, east, sout-east, south)

addPhysicalObject

public void addPhysicalObject(AbstractPhysicalObject physicalObject)
Adds a AbstractPhysicalObject to the FieldedArea

Parameters:
physicalObject - the Object to be added

getQuadrantCoordsForPos

public Vector2D getQuadrantCoordsForPos(Vector2D pos)
Returns the quadrant coordinates for the passed position

Parameters:
pos - position to get the quadrant coordinates for
Returns:
Returns the quadrant coordinates for the passed position

deleteAllPhysicalObjects

public void deleteAllPhysicalObjects()
Removes all Objects from the FieldedArea


findQuadrant

public Quadrant findQuadrant(int X,
                             int Y)
Returns the Quadrant for the passed coordinates

Parameters:
X - x-coordinate
Y - y-coordinate
Returns:
Returns the Quadrant for the passed coordinates

paint

public void paint(java.awt.Graphics g)
Paints the FieldedArea into the passed Graphics

Parameters:
g - the Graphics to paint into