com.threerings.opengl.scene
Class Scene

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

public abstract class Scene
extends DynamicScope
implements Tickable, Compositable

Base class for scenes.


Nested Class Summary
static class Scene.Transient
          Extends the normal model class to include an optional pre-tick updater.
 
Field Summary
protected  ArrayList<SceneElement> _alwaysTick
          The scene elements that we always tick.
protected  SoundClipManager _clipmgr
          A sound clip manager for the scene.
protected  GlContext _ctx
          The application context.
protected  boolean _disposed
          Set when we've been disposed.
protected  ViewerEffectSet _effects
          The effects currently acting on the viewer.
protected  SceneInfluenceSet _influences
          Holds the influences affecting an element.
protected  ViewerEffectSet _neffects
          Holds the new set of effects acting on the viewer.
protected  Vector3f _result
          Result vector for intersection testing.
protected  SoundGroup _soundGroup
          A sound group for the scene.
protected  ModelAdapter _transientObserver
          Removes transient models and returns them to the pool when they complete.
protected  HashMap<ConfigReference,ArrayList<SoftReference<Scene.Transient>>> _transientPool
          Pooled transient models.
protected  SceneElement[] _updateArray
          Holds the scene elements while we're updating their influences.
protected  HashSet<SceneElement> _updateInfluences
          The elements whose influence sets must be updated.
protected  int _updateInfluencesCount
          The last count of the influences set.
protected  Box _viewer
          The viewer volume.
protected  HashSet<SceneElement> _visible
          The visible elements to tick.
protected static int DEFAULT_SOURCES
          The default number of sound sources to allow.
 
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
Scene(GlContext ctx)
          Creates a new scene.
Scene(GlContext ctx, int sources)
          Creates a new scene.
 
Method Summary
 void add(SceneElement element)
          Adds an element to this scene.
 void add(SceneInfluence influence)
          Adds an influence to this scene.
 void add(ViewerEffect effect)
          Adds a viewer effect to this scene.
 void addAll(SceneElement[] elements)
          Adds all of the specified elements to the scene.
protected abstract  void addToSpatial(SceneElement element)
          Adds an element to the scene's spatial data structure.
protected abstract  void addToSpatial(SceneInfluence influence)
          Adds an influence to the scene's spatial data structure.
protected abstract  void addToSpatial(ViewerEffect effect)
          Adds an effect to the scene's spatial data structure.
protected  void addToTick(SceneElement element)
          Adds an element to the scene's tick data structure.
 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 clearEffects()
          Clears any viewer effects (when called outside the tick method).
protected  void composite(ArrayList<SceneElement> elements, Frustum frustum)
          Composites a list of elements for rendering.
protected  void composite(SceneElement element)
          Composites an element for rendering.
 void dispose()
          Releases the resources associated with this scope.
 void dumpViewerEffects()
          Writes the set of active viewer effects out to the log.
 int getAlwaysTickCount()
          Returns the size of the list of elements that we tick on every frame.
abstract  void getEffects(Box bounds, Collection<ViewerEffect> results)
          Retrieves all viewer effects whose bounds intersect the provided region.
abstract  void getElements(Box bounds, Collection<SceneElement> results)
          Retrieves all scene elements whose bounds intersect the provided region.
 Scene.Transient getFromTransientPool(ConfigReference<ModelConfig> ref)
          Returns an instance of the referenced model from the transient pool.
abstract  void getInfluences(Box bounds, Collection<SceneInfluence> results)
          Retrieves all scene influences whose bounds intersect the provided region.
protected static
<T extends SceneObject>
void
getIntersecting(ArrayList<T> objects, Box bounds, Collection<T> results)
          Adds all objects from the provided list that intersect the given bounds to the specified results list.
protected  SceneElement getIntersection(ArrayList<SceneElement> elements, Ray3D ray, Vector3f location, com.google.common.base.Predicate<? super SceneElement> filter)
          Searches for an intersection with the supplied elements.
 SceneElement getIntersection(Ray3D ray, Vector3f location)
          Checks for an intersection between the provided ray and the contents of the scene.
abstract  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.
 int getUpdateInfluencesCount()
          Returns the size of the set of elements whose influences must be updated.
 int getViewerEffectCount()
          Returns the number of effects acting upon the viewer.
 int getVisibleTickCount()
          Returns the size of the set of elements that we are going to tick because they're visible.
 void remove(SceneElement element)
          Removes an element from the scene.
 void remove(SceneElement element, boolean clearParentScope)
          Removes an element from the scene.
 void remove(SceneInfluence influence)
          Removes an influence from this scene.
 void remove(ViewerEffect effect)
          Removes a viewer effect from this scene.
 void removeAll(SceneElement[] elements)
          Removes all of the specified elements from the scene.
 void removeAll(SceneElement[] elements, boolean clearParentScopes)
          Removes all of the specified elements from the scene.
protected abstract  void removeFromSpatial(SceneElement element)
          Removes an element from the scene's spatial data structure.
protected abstract  void removeFromSpatial(SceneInfluence influence)
          Removes an influence from the scene's spatial data structure.
protected abstract  void removeFromSpatial(ViewerEffect effect)
          Removes an effect from the scene's spatial data structure.
protected  void removeFromTick(SceneElement element)
          Removes an element from the scene's tick data structure.
 void returnToTransientPool(Scene.Transient model)
          Returns a model to the transient pool.
protected  void setEffects(ViewerEffectSet effects)
          Sets the effects acting on the viewer.
 Scene.Transient spawnTransient(ConfigReference<ModelConfig> ref, Transform3D transform)
          Spawns a transient model.
 void tick(float elapsed)
          Updates the state of this object based on the elapsed time in seconds.
 void tickPolicyDidChange(SceneElement element)
          Notes that the specified scene element's tick policy has changed.
 void tickPolicyWillChange(SceneElement element)
          Notes that the specified scene element's tick policy is about to change.
 
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
 
Methods inherited from interface com.threerings.opengl.compositor.Compositable
composite
 

Field Detail

_ctx

protected GlContext _ctx
The application context.


_alwaysTick

protected ArrayList<SceneElement> _alwaysTick
The scene elements that we always tick.


_visible

protected HashSet<SceneElement> _visible
The visible elements to tick.


_updateInfluences

protected HashSet<SceneElement> _updateInfluences
The elements whose influence sets must be updated.


_updateInfluencesCount

protected int _updateInfluencesCount
The last count of the influences set.


_updateArray

protected SceneElement[] _updateArray
Holds the scene elements while we're updating their influences.


_effects

protected ViewerEffectSet _effects
The effects currently acting on the viewer.


_transientPool

protected HashMap<ConfigReference,ArrayList<SoftReference<Scene.Transient>>> _transientPool
Pooled transient models.


_transientObserver

protected ModelAdapter _transientObserver
Removes transient models and returns them to the pool when they complete.


_soundGroup

@Scoped
protected SoundGroup _soundGroup
A sound group for the scene.


_clipmgr

@Scoped
protected SoundClipManager _clipmgr
A sound clip manager for the scene.


_disposed

protected boolean _disposed
Set when we've been disposed.


_viewer

protected Box _viewer
The viewer volume.


_influences

protected SceneInfluenceSet _influences
Holds the influences affecting an element.


_result

protected Vector3f _result
Result vector for intersection testing.


_neffects

protected ViewerEffectSet _neffects
Holds the new set of effects acting on the viewer.


DEFAULT_SOURCES

protected static final int DEFAULT_SOURCES
The default number of sound sources to allow.

See Also:
Constant Field Values
Constructor Detail

Scene

public Scene(GlContext ctx)
Creates a new scene.


Scene

public Scene(GlContext ctx,
             int sources)
Creates a new scene.

Parameters:
sources - the number of simultaneous sound sources to allow.
Method Detail

spawnTransient

@Scoped
public Scene.Transient spawnTransient(ConfigReference<ModelConfig> ref,
                                             Transform3D transform)
Spawns a transient model.


getFromTransientPool

@Scoped
public Scene.Transient getFromTransientPool(ConfigReference<ModelConfig> ref)
Returns an instance of the referenced model from the transient pool.


returnToTransientPool

@Scoped
public void returnToTransientPool(Scene.Transient model)
Returns a model to the transient pool.


addAll

public void addAll(SceneElement[] elements)
Adds all of the specified elements to the scene.


add

public void add(SceneElement element)
Adds an element to this scene.


removeAll

public void removeAll(SceneElement[] elements)
Removes all of the specified elements from the scene.


removeAll

public void removeAll(SceneElement[] elements,
                      boolean clearParentScopes)
Removes all of the specified elements from the scene.

Parameters:
clearParentScopes - if true and the element is an instance of DynamicScope, set the element's parent scope to null.

remove

public void remove(SceneElement element)
Removes an element from the scene.


remove

public void remove(SceneElement element,
                   boolean clearParentScope)
Removes an element from the scene.

Parameters:
clearParentScope - if true and the element is an instance of DynamicScope, set the element's parent scope to null.

add

public void add(SceneInfluence influence)
Adds an influence to this scene.


remove

public void remove(SceneInfluence influence)
Removes an influence from this scene.


add

public void add(ViewerEffect effect)
Adds a viewer effect to this scene.


remove

public void remove(ViewerEffect effect)
Removes a viewer effect from this scene.


getIntersection

public SceneElement getIntersection(Ray3D ray,
                                    Vector3f location)
Checks for an intersection between the provided ray and the contents of the scene.

Parameters:
location - a vector to populate with the location of the intersection, if any.
Returns:
a reference to the first element intersected by the ray, or null for none.

getIntersection

public abstract 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.

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

getElements

public abstract void getElements(Box bounds,
                                 Collection<SceneElement> results)
Retrieves all scene elements whose bounds intersect the provided region.

Parameters:
results - a list to hold the results of the search.

getInfluences

public abstract void getInfluences(Box bounds,
                                   Collection<SceneInfluence> results)
Retrieves all scene influences whose bounds intersect the provided region.


getEffects

public abstract void getEffects(Box bounds,
                                Collection<ViewerEffect> results)
Retrieves all viewer effects whose bounds intersect the provided region.


getAlwaysTickCount

public int getAlwaysTickCount()
Returns the size of the list of elements that we tick on every frame.


getVisibleTickCount

public int getVisibleTickCount()
Returns the size of the set of elements that we are going to tick because they're visible.


getUpdateInfluencesCount

public int getUpdateInfluencesCount()
Returns the size of the set of elements whose influences must be updated.


getViewerEffectCount

public int getViewerEffectCount()
Returns the number of effects acting upon the viewer.


dumpViewerEffects

public void dumpViewerEffects()
Writes the set of active viewer effects out to the log.


tickPolicyWillChange

public void tickPolicyWillChange(SceneElement element)
Notes that the specified scene element's tick policy is about to change. Will be followed by a call to tickPolicyDidChange(com.threerings.opengl.scene.SceneElement) when the change has been effected.


tickPolicyDidChange

public void tickPolicyDidChange(SceneElement element)
Notes that the specified scene element's tick policy has changed.


boundsWillChange

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


boundsDidChange

public void boundsDidChange(SceneElement element)
Notes that the specified scene element's bounds have changed.


boundsWillChange

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


boundsDidChange

public void boundsDidChange(SceneInfluence influence)
Notes that the specified influence's bounds have changed.


boundsWillChange

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


boundsDidChange

public void boundsDidChange(ViewerEffect effect)
Notes that the specified effect's bounds have changed.


clearEffects

public void clearEffects()
Clears any viewer effects (when called outside the tick method).


tick

public void tick(float elapsed)
Description copied from interface: Tickable
Updates the state of this object based on the elapsed time in seconds.

Specified by:
tick in interface Tickable

dispose

public void dispose()
Description copied from class: DynamicScope
Releases the resources associated with this scope.

Overrides:
dispose in class DynamicScope

setEffects

protected void setEffects(ViewerEffectSet effects)
Sets the effects acting on the viewer.


addToTick

protected void addToTick(SceneElement element)
Adds an element to the scene's tick data structure.


removeFromTick

protected void removeFromTick(SceneElement element)
Removes an element from the scene's tick data structure.


addToSpatial

protected abstract void addToSpatial(SceneElement element)
Adds an element to the scene's spatial data structure.


removeFromSpatial

protected abstract void removeFromSpatial(SceneElement element)
Removes an element from the scene's spatial data structure.


addToSpatial

protected abstract void addToSpatial(SceneInfluence influence)
Adds an influence to the scene's spatial data structure.


removeFromSpatial

protected abstract void removeFromSpatial(SceneInfluence influence)
Removes an influence from the scene's spatial data structure.


addToSpatial

protected abstract void addToSpatial(ViewerEffect effect)
Adds an effect to the scene's spatial data structure.


removeFromSpatial

protected abstract void removeFromSpatial(ViewerEffect effect)
Removes an effect from the scene's spatial data structure.


composite

protected void composite(ArrayList<SceneElement> elements,
                         Frustum frustum)
Composites a list of elements for rendering.


composite

protected final void composite(SceneElement element)
Composites an element for rendering.


getIntersection

protected SceneElement getIntersection(ArrayList<SceneElement> elements,
                                       Ray3D ray,
                                       Vector3f location,
                                       com.google.common.base.Predicate<? super SceneElement> filter)
Searches for an intersection with the supplied elements.


getIntersecting

protected static <T extends SceneObject> void getIntersecting(ArrayList<T> objects,
                                                              Box bounds,
                                                              Collection<T> results)
Adds all objects from the provided list that intersect the given bounds to the specified results list.