com.threerings.tudey.client
Class TudeySceneController

java.lang.Object
  extended by com.samskivert.swing.Controller
      extended by com.threerings.crowd.client.PlaceController
          extended by com.threerings.whirled.client.SceneController
              extended by com.threerings.tudey.client.TudeySceneController
All Implemented Interfaces:
ComponentListener, MouseListener, MouseMotionListener, MouseWheelListener, PseudoKeys.Observer, Tickable, ChangeListener, MessageListener, SceneDeltaListener, ActionListener, EventListener
Direct Known Subclasses:
ToolSceneController

public class TudeySceneController
extends SceneController
implements SceneDeltaListener, MessageListener, PseudoKeys.Observer, MouseListener, MouseMotionListener, MouseWheelListener, Tickable

The basic Tudey scene controller class.


Nested Class Summary
protected static class TudeySceneController.PawnState
          Records the state of the controlled pawn at the time of an input frame (along with the frame itself).
 
Nested classes/interfaces inherited from class com.threerings.crowd.client.PlaceController
PlaceController.DelegateOp
 
Nested classes/interfaces inherited from class com.samskivert.swing.Controller
Controller.ActionInvoker
 
Field Summary
protected  float[] _absoluteMoveAmounts
          The absolute move command amounts in each direction.
protected  IntMap<Float>[] _absoluteMovePresses
          Pseudo-key presses for each absolute direction.
protected  PawnAdvancer _advancer
          The advancer we use to update the controlled pawn state.
protected  int _controlledId
          The id of the actor being controlled.
protected  com.google.common.collect.Multimap<Integer,Integer> _flagPresses
          Maps flags to corresponding presses pseudo-keys.
protected  int _flags
          The current value of the input flags.
protected  boolean _holdHover
          When true, we hold the hover state.
protected  Sprite _hsprite
          The current hover sprite, if any.
protected  List<InputFrame> _input
          The list of outgoing input frames.
protected  Vector3f _isect
          Contains the result of the intersection test.
protected  IntMap<ObserverList<PseudoKeys.Observer>> _keyObservers
          Maps pseudo-key codes to observers for individual keys.
protected  int _lastDelta
          The timestamp of the last delta received from the server.
protected  float _lastDirection
          The last direction we transmitted.
protected  int _lastFlags
          The last flags we transmitted.
protected  InputFrame _lastFrame
          The last input frame added.
protected  float _lastRotation
          The last rotation we transmitted.
protected  long _lastTransmit
          The time at which we last transmitted our input.
protected  long _nextInput
          The latest time at which we should enqueue an input frame.
protected  MouseOrbiter _orbiter
          The orbiter used to control the camera, if any.
protected  Ray3D _pick
          Used for picking.
protected  float[] _relativeMoveAmounts
          The relative move command amounts in each direction.
protected  IntMap<Float>[] _relativeMovePresses
          Pseudo-key presses for each relative direction.
protected  List<TudeySceneController.PawnState> _states
          States recorded for input frames.
protected  HashIntSet _strafePresses
          The set of keys pressed mapped to the strafe function.
protected  int _targetId
          The id of the actor that the camera should track.
protected  TudeyContext _tctx
          A casted reference to the context.
protected  int _tickCount
          Incremented on each tick.
protected  Plane _tplane
          Contains the target plane for intersecting testing.
protected  Vector2f _translation
          Holds averaged translation.
protected  TudeySceneObject _tsobj
          A casted reference to the scene object.
protected  TudeySceneView _tsview
          A casted reference to the scene view.
protected  PseudoKeys.Unifier _unifier
          Translates various events into pseudo-key events.
protected static float CONVERGENCE_RATE
          The exponential rate at which we converge upon the server-corrected translation.
protected static com.google.common.base.Predicate<SceneElement> HOVER_FILTER
          Selects hoverable sprites.
protected static int UPSTREAM_RATE_LIMIT
          A rate limit (in bytes per second) for upstream traffic.
 
Fields inherited from class com.threerings.whirled.client.SceneController
_updateListener, _wctx
 
Fields inherited from class com.threerings.crowd.client.PlaceController
_config, _ctx, _delegates, _plobj, _view
 
Fields inherited from class com.samskivert.swing.Controller
DISPATCHER
 
Constructor Summary
TudeySceneController()
           
 
Method Summary
protected  void addKeyObserver(int key, PseudoKeys.Observer observer)
          Adds an observer for a single key.
protected  void addKeyObserver(int key, PseudoKeys.Observer observer, boolean hold)
          Adds an observer for a single key.
protected  void bindKeyCycle(int key, boolean forward)
          Binds a key to cycle between targets.
protected  void bindKeyFlag(int key, int flag)
          Binds a key to an input flag.
protected  void bindKeyMovement(int key, float[] amounts, IntMap<Float>[] presses, int idx)
          Binds a key to a movement direction.
protected  void bindKeys()
          Binds pseudo-keys to observers that act on key press and/or release events.
protected  void bindKeyStrafe(int key)
          Binds a key to the strafe flag.
protected  void clearDirection(float[] amounts, IntMap<Float>[] presses)
          Clears directional state.
protected  void clearInput()
          Clears the input state, since the input window is not hovered.
protected  float computeDirection(float dir)
          Computes the direction of movement based on the requested direction.
 void controlledActorAdded(int timestamp, Actor actor)
          Called by the view when we first add our controlled actor.
 void controlledActorUpdated(int timestamp, Actor actor)
          Called by the view when we receive an update for our controlled actor.
 void controlledSpriteRemoved(long timestamp)
          Called by the view when we remove our controlled sprite.
protected static IntMap<Float>[] createDirectionPresses()
          Creates a map array to store per-direction pseudo-key presses.
protected  InputFrame createInputFrame(int timestamp, float rotation, float direction, int flags)
          Creates an input frame.
protected  PlaceView createPlaceView(CrowdContext ctx)
           
protected  void cycleTarget(boolean forward)
          Switches to the next or previous potential target in the occupant list.
protected  void didInit()
           
 void didLeavePlace(PlaceObject plobj)
           
protected  Sprite findHoverSprite(Ray3D pick)
          Finds the hover sprite that the pick ray intersects, if any.
 int getControlledId()
          Returns the id of the actor that is being controlled.
 Sprite getHoverSprite()
          Returns a reference to the hover sprite, if any.
protected  int getInputMask()
          Returns the set of all flags corresponding to input controls (i.e., the flags that should be cleared when input is disabled).
protected  int getMouseCameraModifiers()
          Returns the combination of modifiers that activates the mouse camera, or 0 if the mouse camera is not enabled.
 int getTargetId()
          Returns the id of the actor that the camera should track.
 int getTransmitInterval()
          Returns the interval at which we transmit our input frames.
protected  boolean inputWindowFocused()
          Determines whether the input window is receiving/should receive keyboard/controller events.
protected  boolean inputWindowHovered()
          Determines whether we should process mouse events on the input window.
 boolean isControlledId(int actorId)
          Checks whether the specified actor id is that of the controlled target.
protected  boolean isPressed(float[] amounts)
          Checks whether the supplied amounts count as a "press" for movement purposes.
 void keyPressed(long when, int key, float amount)
          Called when a "key" (either a real key or a pseudo-key) is pressed.
 void keyReleased(long when, int key)
          Called when a "key" is released.
protected  void maybeDispatchToHoverSprite(Event event)
          Dispatches the given event to the hover sprite if we have one and the input window is hovered.
 void messageReceived(MessageEvent event)
           
protected  boolean mouseCameraEnabled()
          Determines whether the mouse camera is enabled.
 void mouseClicked(MouseEvent event)
          Dispatched when a button is clicked within the bounds of the target component.
 void mouseDragged(MouseEvent event)
          Dispatched when the mouse is moved after a button having been pressed within the bounds of the target component.
 void mouseEntered(MouseEvent event)
          Dispatched when the mouse enters the bounds of the target component.
 void mouseExited(MouseEvent event)
          Dispatched when the mouse exits the bounds of the target component.
 void mouseMoved(MouseEvent event)
          Dispatched when the mouse is moved within the bounds of the target component.
 void mousePressed(MouseEvent event)
          Dispatched when a button is pressed within the bounds of the target component.
 void mouseReleased(MouseEvent event)
          Dispatched when a button is released after having been pressed within the bounds of the target component.
 void mouseWheeled(MouseEvent event)
          Dispatched when the mouse wheel is rotated within the bounds of the target component.
 void sceneDeltaReceived(SceneDeltaEvent event)
          Called when a scene delta has been received.
protected  void setHoverSprite(Sprite nhsprite)
          Sets the hover sprite.
protected  void setTarget(int pawnId)
          Targets the pawn with the specified id.
 void submitRequest(Sprite source, String name)
          Submits a named request to the server.
 void tick(float elapsed)
          Updates the state of this object based on the elapsed time in seconds.
protected  void transmitInput()
          Sends all enqueued input to the server.
protected  void updateFlag(int flag)
          Updates the state of the specified flag based on its presses.
protected  void updateInput(float elapsed)
          Updates the input for the current tick.
protected  void updateMoveFlag()
          Updates the move flag.
 void wasAdded()
           
 void wasRemoved()
           
 void willEnterPlace(PlaceObject plobj)
           
 
Methods inherited from class com.threerings.whirled.client.SceneController
init, sceneUpdated
 
Methods inherited from class com.threerings.crowd.client.PlaceController
addDelegate, applyToDelegates, createPlaceView, getPlaceConfig, getPlaceView, handleAction, mayLeavePlace
 
Methods inherited from class com.samskivert.swing.Controller
actionPerformed, configureAction, createActionButton, generateArguments, handleAction, handleAction, handleAction, postAction, postAction, postAction, setControlledPanel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_tctx

protected TudeyContext _tctx
A casted reference to the context.


_tsview

protected TudeySceneView _tsview
A casted reference to the scene view.


_tsobj

protected TudeySceneObject _tsobj
A casted reference to the scene object.


_orbiter

protected MouseOrbiter _orbiter
The orbiter used to control the camera, if any.


_targetId

protected int _targetId
The id of the actor that the camera should track.


_controlledId

protected int _controlledId
The id of the actor being controlled.


_hsprite

protected Sprite _hsprite
The current hover sprite, if any.


_holdHover

protected boolean _holdHover
When true, we hold the hover state.


_unifier

protected PseudoKeys.Unifier _unifier
Translates various events into pseudo-key events.


_keyObservers

protected IntMap<ObserverList<PseudoKeys.Observer>> _keyObservers
Maps pseudo-key codes to observers for individual keys.


_flags

protected int _flags
The current value of the input flags.


_flagPresses

protected com.google.common.collect.Multimap<Integer,Integer> _flagPresses
Maps flags to corresponding presses pseudo-keys.


_absoluteMoveAmounts

protected float[] _absoluteMoveAmounts
The absolute move command amounts in each direction.


_relativeMoveAmounts

protected float[] _relativeMoveAmounts
The relative move command amounts in each direction.


_absoluteMovePresses

protected IntMap<Float>[] _absoluteMovePresses
Pseudo-key presses for each absolute direction.


_relativeMovePresses

protected IntMap<Float>[] _relativeMovePresses
Pseudo-key presses for each relative direction.


_input

protected List<InputFrame> _input
The list of outgoing input frames.


_lastFrame

protected InputFrame _lastFrame
The last input frame added.


_states

protected List<TudeySceneController.PawnState> _states
States recorded for input frames.


_advancer

protected PawnAdvancer _advancer
The advancer we use to update the controlled pawn state.


_lastRotation

protected float _lastRotation
The last rotation we transmitted.


_lastDirection

protected float _lastDirection
The last direction we transmitted.


_lastFlags

protected int _lastFlags
The last flags we transmitted.


_nextInput

protected long _nextInput
The latest time at which we should enqueue an input frame.


_lastTransmit

protected long _lastTransmit
The time at which we last transmitted our input.


_lastDelta

protected int _lastDelta
The timestamp of the last delta received from the server.


_strafePresses

protected HashIntSet _strafePresses
The set of keys pressed mapped to the strafe function.


_tickCount

protected int _tickCount
Incremented on each tick.


_pick

protected Ray3D _pick
Used for picking.


_tplane

protected Plane _tplane
Contains the target plane for intersecting testing.


_isect

protected Vector3f _isect
Contains the result of the intersection test.


_translation

protected Vector2f _translation
Holds averaged translation.


CONVERGENCE_RATE

protected static final float CONVERGENCE_RATE
The exponential rate at which we converge upon the server-corrected translation.


UPSTREAM_RATE_LIMIT

protected static final int UPSTREAM_RATE_LIMIT
A rate limit (in bytes per second) for upstream traffic.

See Also:
Constant Field Values

HOVER_FILTER

protected static final com.google.common.base.Predicate<SceneElement> HOVER_FILTER
Selects hoverable sprites.

Constructor Detail

TudeySceneController

public TudeySceneController()
Method Detail

getTransmitInterval

public int getTransmitInterval()
Returns the interval at which we transmit our input frames.


getTargetId

public int getTargetId()
Returns the id of the actor that the camera should track.


getControlledId

public int getControlledId()
Returns the id of the actor that is being controlled.


isControlledId

public boolean isControlledId(int actorId)
Checks whether the specified actor id is that of the controlled target.


getHoverSprite

public Sprite getHoverSprite()
Returns a reference to the hover sprite, if any.


controlledActorAdded

public void controlledActorAdded(int timestamp,
                                 Actor actor)
Called by the view when we first add our controlled actor.


controlledActorUpdated

public void controlledActorUpdated(int timestamp,
                                   Actor actor)
Called by the view when we receive an update for our controlled actor.


controlledSpriteRemoved

public void controlledSpriteRemoved(long timestamp)
Called by the view when we remove our controlled sprite.


submitRequest

public void submitRequest(Sprite source,
                          String name)
Submits a named request to the server.


sceneDeltaReceived

public void sceneDeltaReceived(SceneDeltaEvent event)
Description copied from interface: SceneDeltaListener
Called when a scene delta has been received.

Specified by:
sceneDeltaReceived in interface SceneDeltaListener

messageReceived

public void messageReceived(MessageEvent event)
Specified by:
messageReceived in interface MessageListener

keyPressed

public void keyPressed(long when,
                       int key,
                       float amount)
Description copied from interface: PseudoKeys.Observer
Called when a "key" (either a real key or a pseudo-key) is pressed.

Specified by:
keyPressed in interface PseudoKeys.Observer

keyReleased

public void keyReleased(long when,
                        int key)
Description copied from interface: PseudoKeys.Observer
Called when a "key" is released.

Specified by:
keyReleased in interface PseudoKeys.Observer

mousePressed

public void mousePressed(MouseEvent event)
Description copied from interface: MouseListener
Dispatched when a button is pressed within the bounds of the target component.

Specified by:
mousePressed in interface MouseListener

mouseReleased

public void mouseReleased(MouseEvent event)
Description copied from interface: MouseListener
Dispatched when a button is released after having been pressed within the bounds of the target component.

Specified by:
mouseReleased in interface MouseListener

mouseClicked

public void mouseClicked(MouseEvent event)
Description copied from interface: MouseListener
Dispatched when a button is clicked within the bounds of the target component.

Specified by:
mouseClicked in interface MouseListener

mouseEntered

public void mouseEntered(MouseEvent event)
Description copied from interface: MouseListener
Dispatched when the mouse enters the bounds of the target component.

Specified by:
mouseEntered in interface MouseListener

mouseExited

public void mouseExited(MouseEvent event)
Description copied from interface: MouseListener
Dispatched when the mouse exits the bounds of the target component.

Specified by:
mouseExited in interface MouseListener

mouseMoved

public void mouseMoved(MouseEvent event)
Description copied from interface: MouseMotionListener
Dispatched when the mouse is moved within the bounds of the target component.

Specified by:
mouseMoved in interface MouseMotionListener

mouseDragged

public void mouseDragged(MouseEvent event)
Description copied from interface: MouseMotionListener
Dispatched when the mouse is moved after a button having been pressed within the bounds of the target component.

Specified by:
mouseDragged in interface MouseMotionListener

mouseWheeled

public void mouseWheeled(MouseEvent event)
Description copied from interface: MouseWheelListener
Dispatched when the mouse wheel is rotated within the bounds of the target component.

Specified by:
mouseWheeled in interface MouseWheelListener

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

wasAdded

public void wasAdded()
Overrides:
wasAdded in class Controller

wasRemoved

public void wasRemoved()
Overrides:
wasRemoved in class Controller

willEnterPlace

public void willEnterPlace(PlaceObject plobj)
Overrides:
willEnterPlace in class SceneController

didLeavePlace

public void didLeavePlace(PlaceObject plobj)
Overrides:
didLeavePlace in class SceneController

createPlaceView

protected PlaceView createPlaceView(CrowdContext ctx)
Overrides:
createPlaceView in class PlaceController

didInit

protected void didInit()
Overrides:
didInit in class PlaceController

bindKeys

protected void bindKeys()
Binds pseudo-keys to observers that act on key press and/or release events.


bindKeyFlag

protected void bindKeyFlag(int key,
                           int flag)
Binds a key to an input flag.


updateFlag

protected void updateFlag(int flag)
Updates the state of the specified flag based on its presses.


updateMoveFlag

protected void updateMoveFlag()
Updates the move flag.


isPressed

protected boolean isPressed(float[] amounts)
Checks whether the supplied amounts count as a "press" for movement purposes.


bindKeyCycle

protected void bindKeyCycle(int key,
                            boolean forward)
Binds a key to cycle between targets.


bindKeyMovement

protected void bindKeyMovement(int key,
                               float[] amounts,
                               IntMap<Float>[] presses,
                               int idx)
Binds a key to a movement direction.


bindKeyStrafe

protected void bindKeyStrafe(int key)
Binds a key to the strafe flag.


addKeyObserver

protected void addKeyObserver(int key,
                              PseudoKeys.Observer observer)
Adds an observer for a single key.


addKeyObserver

protected void addKeyObserver(int key,
                              PseudoKeys.Observer observer,
                              boolean hold)
Adds an observer for a single key.

Parameters:
hold - if true and the key is pressed and released in the same frame, hold the release event until the next frame so that we have a chance to process the press.

maybeDispatchToHoverSprite

protected void maybeDispatchToHoverSprite(Event event)
Dispatches the given event to the hover sprite if we have one and the input window is hovered.


inputWindowHovered

protected boolean inputWindowHovered()
Determines whether we should process mouse events on the input window.


inputWindowFocused

protected boolean inputWindowFocused()
Determines whether the input window is receiving/should receive keyboard/controller events.


mouseCameraEnabled

protected boolean mouseCameraEnabled()
Determines whether the mouse camera is enabled.


getMouseCameraModifiers

protected int getMouseCameraModifiers()
Returns the combination of modifiers that activates the mouse camera, or 0 if the mouse camera is not enabled.


updateInput

protected void updateInput(float elapsed)
Updates the input for the current tick.


findHoverSprite

protected Sprite findHoverSprite(Ray3D pick)
Finds the hover sprite that the pick ray intersects, if any.


computeDirection

protected float computeDirection(float dir)
Computes the direction of movement based on the requested direction.


clearInput

protected void clearInput()
Clears the input state, since the input window is not hovered.


getInputMask

protected int getInputMask()
Returns the set of all flags corresponding to input controls (i.e., the flags that should be cleared when input is disabled).


clearDirection

protected void clearDirection(float[] amounts,
                              IntMap<Float>[] presses)
Clears directional state.


createInputFrame

protected InputFrame createInputFrame(int timestamp,
                                      float rotation,
                                      float direction,
                                      int flags)
Creates an input frame.


setHoverSprite

protected void setHoverSprite(Sprite nhsprite)
Sets the hover sprite.


transmitInput

protected void transmitInput()
Sends all enqueued input to the server.


cycleTarget

protected void cycleTarget(boolean forward)
Switches to the next or previous potential target in the occupant list.


setTarget

protected void setTarget(int pawnId)
Targets the pawn with the specified id.


createDirectionPresses

protected static IntMap<Float>[] createDirectionPresses()
Creates a map array to store per-direction pseudo-key presses.