com.threerings.opengl.scene
Class HashScene

java.lang.Object
  extended by com.threerings.expr.DynamicScope
      extended by com.threerings.opengl.scene.Scene
          extended by com.threerings.opengl.scene.HashScene
All Implemented Interfaces:
Scope, ScopeUpdateListener, Compositable, Tickable

public class HashScene
extends Scene

A scene that uses a hybrid spatial hashing/octree scheme to store scene elements.


Nested Class Summary
protected static class HashScene.Coord
          The coordinates of a hash cell.
protected  class HashScene.InternalNode<T extends SceneObject>
          An internal node with (up to) eight children.
protected  class HashScene.LeafNode<T extends SceneObject>
          A leaf node.
protected  class HashScene.Node<T extends SceneObject>
          Represents a node in an octree.
 
Nested classes/interfaces inherited from class com.threerings.opengl.scene.Scene
Scene.Transient
 
Field Summary
protected  Box _bounds
          The bounds of the roots (does not include the oversized objects).
protected  Box _box
          A reusable box.
protected  HashScene.Coord _coord
          A reusable coord object for queries.
protected  HashMap<HashScene.Coord,HashScene.Node<ViewerEffect>> _effects
          The top level effect nodes.
protected  HashMap<HashScene.Coord,HashScene.Node<SceneElement>> _elements
          The top level element nodes.
protected  float _granularity
          The size of the root nodes.
protected  HashMap<HashScene.Coord,HashScene.Node<SceneInfluence>> _influences
          The top level influence nodes.
protected  List<HashScene.InternalNode> _internalNodePool
          A pool of internal nodes to reuse.
protected  List<HashScene.LeafNode> _leafNodePool
          A pool of leaf nodes to reuse.
protected  int _levels
          The (maximum) number of tree levels.
protected  Vector3f[] _lresults
          Per-level result vectors.
protected  HashScene.Coord _maxCoord
          The maximum coordinate.
protected  HashScene.Coord _minCoord
          The minimum coordinate.
protected  ArrayList<ViewerEffect> _oversizedEffects
          Oversized effects.
protected  ArrayList<SceneElement> _oversizedElements
          Oversized elements.
protected  ArrayList<SceneInfluence> _oversizedInfluences
          Oversized influences.
protected  Vector3f _pt
          Reusable location vector.
protected  int _visit
          The visit counter.
 
Fields inherited from class com.threerings.opengl.scene.Scene
_alwaysTick, _clipmgr, _ctx, _disposed, _neffects, _result, _soundGroup, _transientObserver, _transientPool, _updateArray, _updateInfluences, _updateInfluencesCount, _viewer, _visible, DEFAULT_SOURCES
 
Fields inherited from class com.threerings.expr.DynamicScope
_compoundDepth, _listeners, _owner, _parentScope, _scopeName, _symbols, INVALID_SCOPE
 
Fields inherited from interface com.threerings.expr.Scope
EPOCH, NOW
 
Constructor Summary
HashScene(GlContext ctx, float granularity, int levels)
          Creates a new hash scene.
HashScene(GlContext ctx, float granularity, int levels, int sources)
          Creates a new hash scene.
 
Method Summary
protected
<T extends SceneObject>
void
add(HashMap<HashScene.Coord,HashScene.Node<T>> roots, ArrayList<T> oversized, T object)
          Adds the specified object to the provided map.
protected
<T extends SceneObject>
void
addBounds(HashMap<HashScene.Coord,HashScene.Node<T>> roots)
          Adds the bounds of the specified roots.
protected
<T extends SceneObject>
void
addBounds(HashScene.Coord coord, HashScene.Node<T> node)
          Adds the bounds of the specified coordinate/node mapping.
protected  void addToSpatial(SceneElement element)
          Adds an element to the scene's spatial data structure.
protected  void addToSpatial(SceneInfluence influence)
          Adds an influence to the scene's spatial data structure.
protected  void addToSpatial(ViewerEffect effect)
          Adds an effect to the scene's spatial data structure.
protected  boolean areOversized(Box bounds)
          Determines whether the specified bounds qualify as "oversized" with respect to the scene granularity.
 void boundsDidChange(SceneElement element)
          Notes that the specified scene element's bounds have changed.
 void boundsDidChange(SceneInfluence influence)
          Notes that the specified influence's bounds have changed.
 void boundsDidChange(ViewerEffect effect)
          Notes that the specified effect's bounds have changed.
 void boundsWillChange(SceneElement element)
          Notes that the specified scene element's bounds are about to change.
 void boundsWillChange(SceneInfluence influence)
          Notes that the specified influence's bounds are about to change.
 void boundsWillChange(ViewerEffect effect)
          Notes that the specified effect's bounds are about to change.
 void composite()
          Adds this object's Dependencys and Enqueueables to the compositor in preparation for rendering.
protected
<T extends SceneObject>
HashScene.Node<T>
createRoot(int x, int y, int z)
          Creates a root node for the specified coordinates.
 void getEffects(Box bounds, Collection<ViewerEffect> results)
          Retrieves all viewer effects whose bounds intersect the provided region.
 void getElements(Box bounds, Collection<SceneElement> results)
          Retrieves all scene elements whose bounds intersect the provided region.
protected
<T extends SceneObject>
HashScene.InternalNode<T>
getFromInternalNodePool(int levels)
          Obtains an internal node through the pool.
protected
<T extends SceneObject>
HashScene.LeafNode<T>
getFromLeafNodePool()
          Obtains a leaf node through the pool.
protected
<T extends SceneObject>
HashScene.Node<T>
getFromNodePool(int levels)
          Returns an internal or leaf node from the pool as appropriate for the number of remaining levels.
 void getInfluences(Box bounds, Collection<SceneInfluence> results)
          Retrieves all scene influences whose bounds intersect the provided region.
protected
<T extends SceneObject>
void
getIntersecting(HashMap<HashScene.Coord,HashScene.Node<T>> roots, ArrayList<T> oversized, Box bounds, Collection<T> results)
          Adds all objects from the provided map that intersect the given bounds to the specified results list.
 SceneElement getIntersection(Ray3D ray, Vector3f location, com.google.common.base.Predicate<? super SceneElement> filter)
          Checks for an intersection between the provided ray and the contents of the scene.
protected  int getLevel(Box bounds)
          Returns the level for the supplied bounds.
protected  void recomputeBounds()
          Recomputes the bounds of the roots.
protected
<T extends SceneObject>
void
remove(HashMap<HashScene.Coord,HashScene.Node<T>> roots, ArrayList<T> oversized, T object)
          Removes the specified object from the provided map.
protected  void removeFromSpatial(SceneElement element)
          Removes an element from the scene's spatial data structure.
protected  void removeFromSpatial(SceneInfluence influence)
          Removes an influence from the scene's spatial data structure.
protected  void removeFromSpatial(ViewerEffect effect)
          Removes an effect from the scene's spatial data structure.
 
Methods inherited from class com.threerings.opengl.scene.Scene
add, add, add, addAll, addToTick, clearEffects, composite, composite, dispose, dumpViewerEffects, getAlwaysTickCount, getFromTransientPool, getIntersecting, getIntersection, getIntersection, getUpdateInfluencesCount, getViewerEffectCount, getVisibleTickCount, remove, remove, remove, remove, removeAll, removeAll, removeFromTick, returnToTransientPool, setEffects, spawnTransient, tick, tickPolicyDidChange, tickPolicyWillChange
 
Methods inherited from class com.threerings.expr.DynamicScope
addListener, endCompoundUpdate, get, getParentScope, getScopeName, put, remove, removeListener, scopeUpdated, setParentScope, startCompoundUpdate, wasUpdated
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_granularity

protected float _granularity
The size of the root nodes.


_levels

protected int _levels
The (maximum) number of tree levels.


_elements

protected HashMap<HashScene.Coord,HashScene.Node<SceneElement>> _elements
The top level element nodes.


_oversizedElements

protected ArrayList<SceneElement> _oversizedElements
Oversized elements.


_influences

protected HashMap<HashScene.Coord,HashScene.Node<SceneInfluence>> _influences
The top level influence nodes.


_oversizedInfluences

protected ArrayList<SceneInfluence> _oversizedInfluences
Oversized influences.


_effects

protected HashMap<HashScene.Coord,HashScene.Node<ViewerEffect>> _effects
The top level effect nodes.


_oversizedEffects

protected ArrayList<ViewerEffect> _oversizedEffects
Oversized effects.


_bounds

protected Box _bounds
The bounds of the roots (does not include the oversized objects).


_minCoord

protected HashScene.Coord _minCoord
The minimum coordinate.


_maxCoord

protected HashScene.Coord _maxCoord
The maximum coordinate.


_visit

protected int _visit
The visit counter.


_coord

protected HashScene.Coord _coord
A reusable coord object for queries.


_box

protected Box _box
A reusable box.


_pt

protected Vector3f _pt
Reusable location vector.


_lresults

protected Vector3f[] _lresults
Per-level result vectors.


_internalNodePool

protected List<HashScene.InternalNode> _internalNodePool
A pool of internal nodes to reuse.


_leafNodePool

protected List<HashScene.LeafNode> _leafNodePool
A pool of leaf nodes to reuse.

Constructor Detail

HashScene

public HashScene(GlContext ctx,
                 float granularity,
                 int levels)
Creates a new hash scene.

Parameters:
granularity - the size of the top-level cells.
levels - the (maximum) number of octree levels.

HashScene

public HashScene(GlContext ctx,
                 float granularity,
                 int levels,
                 int sources)
Creates a new hash scene.

Parameters:
granularity - the size of the top-level cells.
levels - the (maximum) number of octree levels.
sources - the number of simultaneous sound sources to allow.
Method Detail

composite

public void composite()
Description copied from interface: Compositable
Adds this object's Dependencys and Enqueueables to the compositor in preparation for rendering.


getIntersection

public SceneElement getIntersection(Ray3D ray,
                                    Vector3f location,
                                    com.google.common.base.Predicate<? super SceneElement> filter)
Description copied from class: Scene
Checks for an intersection between the provided ray and the contents of the scene.

Specified by:
getIntersection in class Scene
location - a vector to populate with the location of the intersection, if any.
filter - a predicate to use in filtering the results of the test.
Returns:
a reference to the first element intersected by the ray, or null for none.

getElements

public void getElements(Box bounds,
                        Collection<SceneElement> results)
Description copied from class: Scene
Retrieves all scene elements whose bounds intersect the provided region.

Specified by:
getElements in class Scene
results - a list to hold the results of the search.

getInfluences

public void getInfluences(Box bounds,
                          Collection<SceneInfluence> results)
Description copied from class: Scene
Retrieves all scene influences whose bounds intersect the provided region.

Specified by:
getInfluences in class Scene

getEffects

public void getEffects(Box bounds,
                       Collection<ViewerEffect> results)
Description copied from class: Scene
Retrieves all viewer effects whose bounds intersect the provided region.

Specified by:
getEffects in class Scene

boundsWillChange

public void boundsWillChange(SceneElement element)
Description copied from class: Scene
Notes that the specified scene element's bounds are about to change. Will be followed by a call to Scene.boundsDidChange(SceneElement) when the change has been effected.

Overrides:
boundsWillChange in class Scene

boundsDidChange

public void boundsDidChange(SceneElement element)
Description copied from class: Scene
Notes that the specified scene element's bounds have changed.

Overrides:
boundsDidChange in class Scene

boundsWillChange

public void boundsWillChange(SceneInfluence influence)
Description copied from class: Scene
Notes that the specified influence's bounds are about to change. Will be followed by a call to Scene.boundsDidChange(SceneInfluence) when the change has been effected.

Overrides:
boundsWillChange in class Scene

boundsDidChange

public void boundsDidChange(SceneInfluence influence)
Description copied from class: Scene
Notes that the specified influence's bounds have changed.

Overrides:
boundsDidChange in class Scene

boundsWillChange

public void boundsWillChange(ViewerEffect effect)
Description copied from class: Scene
Notes that the specified effect's bounds are about to change. Will be followed by a call to Scene.boundsDidChange(ViewerEffect) when the change has been effected.

Overrides:
boundsWillChange in class Scene

boundsDidChange

public void boundsDidChange(ViewerEffect effect)
Description copied from class: Scene
Notes that the specified effect's bounds have changed.

Overrides:
boundsDidChange in class Scene

addToSpatial

protected void addToSpatial(SceneElement element)
Description copied from class: Scene
Adds an element to the scene's spatial data structure.

Specified by:
addToSpatial in class Scene

removeFromSpatial

protected void removeFromSpatial(SceneElement element)
Description copied from class: Scene
Removes an element from the scene's spatial data structure.

Specified by:
removeFromSpatial in class Scene

addToSpatial

protected void addToSpatial(SceneInfluence influence)
Description copied from class: Scene
Adds an influence to the scene's spatial data structure.

Specified by:
addToSpatial in class Scene

removeFromSpatial

protected void removeFromSpatial(SceneInfluence influence)
Description copied from class: Scene
Removes an influence from the scene's spatial data structure.

Specified by:
removeFromSpatial in class Scene

addToSpatial

protected void addToSpatial(ViewerEffect effect)
Description copied from class: Scene
Adds an effect to the scene's spatial data structure.

Specified by:
addToSpatial in class Scene

removeFromSpatial

protected void removeFromSpatial(ViewerEffect effect)
Description copied from class: Scene
Removes an effect from the scene's spatial data structure.

Specified by:
removeFromSpatial in class Scene

add

protected <T extends SceneObject> void add(HashMap<HashScene.Coord,HashScene.Node<T>> roots,
                                           ArrayList<T> oversized,
                                           T object)
Adds the specified object to the provided map.


remove

protected <T extends SceneObject> void remove(HashMap<HashScene.Coord,HashScene.Node<T>> roots,
                                              ArrayList<T> oversized,
                                              T object)
Removes the specified object from the provided map.


areOversized

protected boolean areOversized(Box bounds)
Determines whether the specified bounds qualify as "oversized" with respect to the scene granularity.


getIntersecting

protected <T extends SceneObject> void getIntersecting(HashMap<HashScene.Coord,HashScene.Node<T>> roots,
                                                       ArrayList<T> oversized,
                                                       Box bounds,
                                                       Collection<T> results)
Adds all objects from the provided map that intersect the given bounds to the specified results list.


getLevel

protected int getLevel(Box bounds)
Returns the level for the supplied bounds.


createRoot

protected <T extends SceneObject> HashScene.Node<T> createRoot(int x,
                                                               int y,
                                                               int z)
Creates a root node for the specified coordinates.


recomputeBounds

protected void recomputeBounds()
Recomputes the bounds of the roots.


addBounds

protected <T extends SceneObject> void addBounds(HashMap<HashScene.Coord,HashScene.Node<T>> roots)
Adds the bounds of the specified roots.


addBounds

protected <T extends SceneObject> void addBounds(HashScene.Coord coord,
                                                 HashScene.Node<T> node)
Adds the bounds of the specified coordinate/node mapping.


getFromNodePool

protected <T extends SceneObject> HashScene.Node<T> getFromNodePool(int levels)
Returns an internal or leaf node from the pool as appropriate for the number of remaining levels.


getFromInternalNodePool

protected <T extends SceneObject> HashScene.InternalNode<T> getFromInternalNodePool(int levels)
Obtains an internal node through the pool.


getFromLeafNodePool

protected <T extends SceneObject> HashScene.LeafNode<T> getFromLeafNodePool()
Obtains a leaf node through the pool.