netwar.game
Class SelfSortingMutualDistanceSquared

java.lang.Object
  |
  +--netwar.game.SelfSortingMutualDistanceSquared

public class SelfSortingMutualDistanceSquared
extends java.lang.Object

This class provides a high-RAM, low computation way to find a listing of all other GameObjects, sorted from closest to farthest. This also provides pre-calculated distance squared values. These are faster to calculate than distances, but can be compared as if they were distances to find longer or shorter.


Method Summary
 float getDistanceSquared()
          Get a pre-calculated distance squared between the two GameObjects.
 SelfSortingMutualDistanceSquared getNext(GameObject go)
          Get the next SSMDS in go's list.
 GameObject getOther(GameObject go)
          Get the other GameObject for this SSMDS.
 SelfSortingMutualDistanceSquared getTarget(GameObject go, GameObject target)
          Traverse go's list, and find the SSMDS that matches with target.
 Point3D getVector(GameObject go)
          Get a Point3D which is the vector from the passed GameObject to the other GameObject.
static void newSSMDS(GameObject younger, GameObject older)
          This calls the constructor for SSMDS to prevent the new object from being assigned to a reference, which would be improper usage.
 void remove(GameObject go)
          When called on the go.firstSSMDS, it will recursively remove all of the SSMDSs' which reference go.
 void update()
          When a GameObject moves, it should call this on each SSMDS in its list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

newSSMDS

public static void newSSMDS(GameObject younger,
                            GameObject older)
This calls the constructor for SSMDS to prevent the new object from being assigned to a reference, which would be improper usage. The constructor automatically integrates the SSMDS into both GameObjects' lists.
Parameters:
younger - the newly made GameObject.
older - the GameObject already included in the system.

remove

public void remove(GameObject go)
When called on the go.firstSSMDS, it will recursively remove all of the SSMDSs' which reference go.
Parameters:
go - The GameObject which is being invalidated.

update

public void update()
When a GameObject moves, it should call this on each SSMDS in its list. This is the responsibility of the GameObject, because the order of the list changes due to each update. This will adjust the sorting of all the lists.

getDistanceSquared

public float getDistanceSquared()
Get a pre-calculated distance squared between the two GameObjects.
Returns:
the distance squared between the two GameObjects.

getVector

public Point3D getVector(GameObject go)
Get a Point3D which is the vector from the passed GameObject to the other GameObject.
Parameters:
go - the GameObject to measure the vector from.
Returns:
the Point3D.

getOther

public GameObject getOther(GameObject go)
Get the other GameObject for this SSMDS.
Parameters:
go - The GameObject which is known.
Returns:
The other GameObject.

getTarget

public SelfSortingMutualDistanceSquared getTarget(GameObject go,
                                                  GameObject target)
Traverse go's list, and find the SSMDS that matches with target.
Parameters:
go - - the GameObject which you are searching with.
target - - the other GameObject for the desired SSMDS.
Returns:
The SSMDS relating go and target.

getNext

public SelfSortingMutualDistanceSquared getNext(GameObject go)
Get the next SSMDS in go's list.
Parameters:
go - The GameObject whose list you are traversing.
Returns:
The next SSMDS.