com.threerings.puzzle.drop.client
Class DropControllerDelegate

java.lang.Object
  extended by com.threerings.crowd.client.PlaceControllerDelegate
      extended by com.threerings.parlor.game.client.GameControllerDelegate
          extended by com.threerings.puzzle.client.PuzzleControllerDelegate
              extended by com.threerings.puzzle.drop.client.DropControllerDelegate
All Implemented Interfaces:
com.threerings.media.FrameParticipant, InvocationCodes, PuzzleCodes, PuzzleGameCodes, DropCodes, DropPieceCodes, DirectionCodes

public abstract class DropControllerDelegate
extends PuzzleControllerDelegate
implements DropCodes, DropPieceCodes, com.threerings.media.FrameParticipant

Games that wish to make use of the drop puzzle services will need to create an extension of this delegate class, customizing it for their particular game and then adding it via PlaceController.addDelegate(com.threerings.crowd.client.PlaceControllerDelegate).

It handles logical actions for a puzzle game that generally consists of a two-dimensional board containing pieces, with new pieces either falling into the board as a "drop block", or rising into the bottom of the board in new piece rows.

Derived classes must implement getPieceVelocity(boolean) and evolveBoard().

Block-dropping puzzles will likely want to override createNextBlock(), blockDidLand(), and getPieceDropLogic().

Board-rising puzzles will likely want to override getRiseVelocity(), getRiseDistance(), getPieceDropLogic(), and boardDidRise().


Field Summary
protected  int _bhei
          The board dimensions in pieces.
protected  DropBlockSprite _blocksprite
          The drop block sprite associated with the landing block, if any.
protected  long _blockStamp
          The timestamp used to keep track of when the drop block was removed so that we can fast-forward it when restored.
protected  int _bounceInterval
          The duration of the bounce interval.
protected  int _bounceRow
          The row at which we last bounced, or Integer.MIN_VALUE.
protected  long _bounceStamp
          The time at which we last started bouncing, or 0.
protected  int _bwid
          The board dimensions in pieces.
protected  PuzzleController _ctrl
          Our puzzle controller.
protected  PuzzleContext _ctx
          The puzzle context.
protected  DropBoard _dboard
          The drop board.
protected  DropPanel _dpanel
          The drop panel.
protected  DropSpriteObserver _dropMovedHandler
          Used to listen to drop sprites and react to their move events.
protected  PieceDropper _dropper
          The piece dropper used to drop pieces in the board if the puzzle chooses to make use of piece dropping functionality.
protected  DropBoardView _dview
          The drop board view.
protected  com.threerings.media.animation.AnimationAdapter _evolveObserver
          Used to evolve the board following the completion of animations.
protected  boolean _fastDrop
          Whether the drop blocks are currently dropping quickly.
protected  int _risedist
          The distance the board row travels in pixels.
protected  long _risesent
          The time at which we last fired off a board rising event.
protected  long _risestamp
          The time at which the last board rise began.
protected  float _risevel
          The speed with which the board rises in pixels per millisecond.
protected  long _rpstamp
          The time at which the board rise was paused.
protected  boolean _stable
          Whether or not the board is currently stable.
protected  DropBoard.PieceOperation _updateBoardOp
          A piece operation that will update piece sprites as board positions are updated.
protected  boolean _usedrop
          Whether the game is using drop block functionality.
protected  boolean _userise
          Whether the game is using board rising functionality.
protected  long _zipstamp
          The time at which we were requested to start zipping.
protected static float BOUNCE_FRACTION
          Defines the distance of a piece that we allow to bounce before we land it.
protected static int DEFAULT_RISE_DISTANCE
          The default board row rising distance.
protected static float DEFAULT_RISE_VELOCITY
          The default board row rising velocity.
static String END_DROP_BLOCK
          The action command for ending dropping the block.
static String MOVE_BLOCK_LEFT
          The action command for moving the block to the left.
static String MOVE_BLOCK_RIGHT
          The action command for moving the block to the right.
static String RAISE_ROW
          The action command for raising the next rising row.
protected static long RISE_INTERVAL
          The delay in milliseconds between board rising intervals.
static String ROTATE_BLOCK_CCW
          The action command for rotating the block counter-clockwise.
static String ROTATE_BLOCK_CW
          The action command for rotating the block clockwise.
static String START_DROP_BLOCK
          The action command for starting to dropping the block.
 
Fields inherited from class com.threerings.puzzle.client.PuzzleControllerDelegate
_puzobj
 
Fields inherited from class com.threerings.crowd.client.PlaceControllerDelegate
_controller
 
Fields inherited from interface com.threerings.puzzle.drop.data.DropCodes
DROP_MESSAGE_BUNDLE, DROP_STREAM, RISE_STREAM
 
Fields inherited from interface com.threerings.puzzle.drop.data.DropPieceCodes
DROP_BLOCK_PIECE_COUNT, PIECE_NONE
 
Fields inherited from interface com.threerings.util.DirectionCodes
CARDINAL_DIRECTIONS, CCW, CW, DIRECTION_COUNT, DOWN, EAST, EASTNORTHEAST, EASTSOUTHEAST, FINE_DIRECTION_COUNT, HORIZONTAL, LEFT, NONE, NORTH, NORTHEAST, NORTHNORTHEAST, NORTHNORTHWEST, NORTHWEST, RIGHT, SOUTH, SOUTHEAST, SOUTHSOUTHEAST, SOUTHSOUTHWEST, SOUTHWEST, UP, VERTICAL, WEST, WESTNORTHWEST, WESTSOUTHWEST
 
Fields inherited from interface com.threerings.puzzle.data.PuzzleCodes
DEBUG_PUZZLE, DEFAULT_DIFFICULTY, PUZZLE_MESSAGE_BUNDLE
 
Fields inherited from interface com.threerings.presents.data.InvocationCodes
ACCESS_DENIED, E_ACCESS_DENIED, E_INTERNAL_ERROR, GLOBAL_GROUP, INTERNAL_ERROR
 
Constructor Summary
DropControllerDelegate(PuzzleController ctrl, DropLogic logic)
          Creates a delegate with the specified drop game logic and controller.
 
Method Summary
protected  void animationDidFinish(com.threerings.media.animation.Animation anim)
          Called when an animation finishes doing its business.
protected  void applyDropSprite(DropSprite sprite, int col, int row)
          Applies the pieces in the given sprite to the specified column and row in the board.
protected  void blockDidLand()
          Called only for block-dropping puzzles when the drop block lands on something.
protected  void blockDidRotate(int dir)
          Called when the drop block has rotated in the specified direction to allow derived classes to engage in any game-specific antics.
protected  void blockWillLand()
          Called only for block-dropping puzzles when the drop block is about to land on something.
protected  void boardDidRise()
          Called only for board-rising puzzles when the board has finished rising one row.
protected  void boardDidStabilize()
          Called when the board has been fully evolved and is once again stable.
protected  void boardWillRise()
          Called only for board-rising puzzles before effecting the rising of the board by one row.
protected  void bounceTimerExpired()
          Called when the bounce timer expires.
protected  boolean canClearAction()
          Delegates that wish to postpone action clearing can override this method to return false until such time as the action can be cleared.
protected  boolean canEvolveBoard()
          Called to determine whether it is safe to evolve the board.
protected  boolean checkBlockLanded(String source, boolean commit, boolean atTop)
          Checks whether the drop block can continue dropping and lands its pieces if not.
protected  boolean checkCanRise()
          Called to determine whether or not rising a new row into the board is legal.
protected  boolean checkDropEndsGame()
          Called by dropNextBlock() to determine whether the game should be ended rather than dropping the next block because the board is filled and a new block cannot enter.
protected  void clearAction()
          Clears out all of the action in the board; removes any drop block sprites, any pieces rising in the board, and resets the animation timestamps.
protected  DropBlockSprite createNextBlock()
          Called only for block-dropping puzzles when it's time to create the next drop block.
protected  void dropNextBlock()
          Handles creation and dropping of the next dropping block.
protected  boolean dropPieces()
          Drops any pieces that need dropping and returns whether any pieces were dropped.
protected abstract  boolean evolveBoard()
          Evolves the board to an unchanging state.
 void gameDidEnd()
          Called when the game transitions to the GAME_OVER state.
 Component getComponent()
           
protected  PieceDropLogic getPieceDropLogic()
          Returns the piece drop logic used to drop any pieces that need dropping in the board.
protected  PieceDropper getPieceDropper(PieceDropLogic logic)
          Returns the piece dropper used to drop any pieces that need dropping in the board.
protected abstract  float getPieceVelocity(boolean fast)
          Returns the drop sprite velocity to assign to a new drop sprite.
protected  int getRiseDistance()
          Returns the distance in pixels that each board row will traverse when rising into place.
protected  float getRiseVelocity()
          Returns the speed with which the next board row should rise into place, in pixels per millisecond.
protected  int getRotationType()
          Returns the rotation type used by this drop game.
 boolean handleAction(ActionEvent action)
           
protected  boolean handleBlockAction(ActionEvent action)
           
protected  void handleDropBlock(boolean fast)
          Handles drop block events.
protected  void handleDropSpriteMoved(DropSprite sprite, long when, int col, int row)
          Called when a drop sprite posts a piece moved event.
protected  void handleMoveBlock(int dir)
          Handles block moved events.
protected  void handleRotateBlock(int dir)
          Handles block rotation events.
 void init(CrowdContext ctx, PlaceConfig config)
           
 boolean needsPaint()
           
protected  int[] peekNextPieces()
          Take a peek at the next pieces.
 void setBoard(Board board)
          Called when the puzzle controller sets up a new board for the player.
 void setRisingPaused(boolean paused)
          Sets whether the board rising is paused.
protected  void startAction()
          Starts up the action; tries evolving the board to get things going.
protected  void startBounceTimer(String source)
          Called when a block lands.
 void tick(long tickStamp)
           
protected  void unstabilizeBoard()
          Derived classes should call this method whenever they change some board state that will require board evolution to restabilize the board.
 void updateSelfSummary()
          Updates the player's own local board summary to reflect the local copy of the player's board which is likely to be more up to date than the server-side board from which all other player board summaries originate.
 void zipToNextRow()
          Causes the board to zip quickly to the next row.
 
Methods inherited from class com.threerings.puzzle.client.PuzzleControllerDelegate
canStartChatting, didLeavePlace, maybeClearAction, playerKnockedOut, setChatting, willEnterPlace
 
Methods inherited from class com.threerings.parlor.game.client.GameControllerDelegate
gameDidStart, gameWasCancelled, gameWillReset
 
Methods inherited from class com.threerings.crowd.client.PlaceControllerDelegate
mayLeavePlace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MOVE_BLOCK_LEFT

public static final String MOVE_BLOCK_LEFT
The action command for moving the block to the left.

See Also:
Constant Field Values

MOVE_BLOCK_RIGHT

public static final String MOVE_BLOCK_RIGHT
The action command for moving the block to the right.

See Also:
Constant Field Values

ROTATE_BLOCK_CCW

public static final String ROTATE_BLOCK_CCW
The action command for rotating the block counter-clockwise.

See Also:
Constant Field Values

ROTATE_BLOCK_CW

public static final String ROTATE_BLOCK_CW
The action command for rotating the block clockwise.

See Also:
Constant Field Values

START_DROP_BLOCK

public static final String START_DROP_BLOCK
The action command for starting to dropping the block.

See Also:
Constant Field Values

END_DROP_BLOCK

public static final String END_DROP_BLOCK
The action command for ending dropping the block.

See Also:
Constant Field Values

RAISE_ROW

public static final String RAISE_ROW
The action command for raising the next rising row.

See Also:
Constant Field Values

_ctx

protected PuzzleContext _ctx
The puzzle context.


_ctrl

protected PuzzleController _ctrl
Our puzzle controller.


_dpanel

protected DropPanel _dpanel
The drop panel.


_dview

protected DropBoardView _dview
The drop board view.


_dboard

protected DropBoard _dboard
The drop board.


_usedrop

protected boolean _usedrop
Whether the game is using drop block functionality.


_userise

protected boolean _userise
Whether the game is using board rising functionality.


_stable

protected boolean _stable
Whether or not the board is currently stable.


_bwid

protected int _bwid
The board dimensions in pieces.


_bhei

protected int _bhei
The board dimensions in pieces.


_risedist

protected int _risedist
The distance the board row travels in pixels.


_risevel

protected float _risevel
The speed with which the board rises in pixels per millisecond.


_blocksprite

protected DropBlockSprite _blocksprite
The drop block sprite associated with the landing block, if any.


_dropper

protected PieceDropper _dropper
The piece dropper used to drop pieces in the board if the puzzle chooses to make use of piece dropping functionality.


_rpstamp

protected long _rpstamp
The time at which the board rise was paused.


_risestamp

protected long _risestamp
The time at which the last board rise began.


_risesent

protected long _risesent
The time at which we last fired off a board rising event.


_zipstamp

protected long _zipstamp
The time at which we were requested to start zipping.


_bounceInterval

protected int _bounceInterval
The duration of the bounce interval.


_bounceStamp

protected long _bounceStamp
The time at which we last started bouncing, or 0.


_bounceRow

protected int _bounceRow
The row at which we last bounced, or Integer.MIN_VALUE.


_blockStamp

protected long _blockStamp
The timestamp used to keep track of when the drop block was removed so that we can fast-forward it when restored.


_fastDrop

protected boolean _fastDrop
Whether the drop blocks are currently dropping quickly.


_evolveObserver

protected com.threerings.media.animation.AnimationAdapter _evolveObserver
Used to evolve the board following the completion of animations.


_dropMovedHandler

protected DropSpriteObserver _dropMovedHandler
Used to listen to drop sprites and react to their move events.


_updateBoardOp

protected DropBoard.PieceOperation _updateBoardOp
A piece operation that will update piece sprites as board positions are updated.


DEFAULT_RISE_VELOCITY

protected static final float DEFAULT_RISE_VELOCITY
The default board row rising velocity.

See Also:
Constant Field Values

DEFAULT_RISE_DISTANCE

protected static final int DEFAULT_RISE_DISTANCE
The default board row rising distance.

See Also:
Constant Field Values

RISE_INTERVAL

protected static final long RISE_INTERVAL
The delay in milliseconds between board rising intervals.

See Also:
Constant Field Values

BOUNCE_FRACTION

protected static final float BOUNCE_FRACTION
Defines the distance of a piece that we allow to bounce before we land it.

See Also:
Constant Field Values
Constructor Detail

DropControllerDelegate

public DropControllerDelegate(PuzzleController ctrl,
                              DropLogic logic)
Creates a delegate with the specified drop game logic and controller.

Method Detail

init

public void init(CrowdContext ctx,
                 PlaceConfig config)
Overrides:
init in class PlaceControllerDelegate

getRiseVelocity

protected float getRiseVelocity()
Returns the speed with which the next board row should rise into place, in pixels per millisecond.


getRiseDistance

protected int getRiseDistance()
Returns the distance in pixels that each board row will traverse when rising into place.


startAction

protected void startAction()
Starts up the action; tries evolving the board to get things going.

Overrides:
startAction in class PuzzleControllerDelegate

canClearAction

protected boolean canClearAction()
Description copied from class: PuzzleControllerDelegate
Delegates that wish to postpone action clearing can override this method to return false until such time as the action can be cleared. They must, however, call PuzzleControllerDelegate.maybeClearAction() when conditions become such that they would once again allow action to be cleared.

Overrides:
canClearAction in class PuzzleControllerDelegate

clearAction

protected void clearAction()
Clears out all of the action in the board; removes any drop block sprites, any pieces rising in the board, and resets the animation timestamps.

Overrides:
clearAction in class PuzzleControllerDelegate

gameDidEnd

public void gameDidEnd()
Description copied from class: GameControllerDelegate
Called when the game transitions to the GAME_OVER state. This happens when the game reaches some end condition by normal means (is not cancelled or aborted).

Overrides:
gameDidEnd in class GameControllerDelegate

handleAction

public boolean handleAction(ActionEvent action)
Overrides:
handleAction in class PlaceControllerDelegate

setBoard

public void setBoard(Board board)
Description copied from class: PuzzleControllerDelegate
Called when the puzzle controller sets up a new board for the player.

Overrides:
setBoard in class PuzzleControllerDelegate
Parameters:
board - the newly initialized and ready-to-go board.

handleBlockAction

protected boolean handleBlockAction(ActionEvent action)

handleMoveBlock

protected void handleMoveBlock(int dir)
Handles block moved events.


handleRotateBlock

protected void handleRotateBlock(int dir)
Handles block rotation events.


blockDidRotate

protected void blockDidRotate(int dir)
Called when the drop block has rotated in the specified direction to allow derived classes to engage in any game-specific antics.


getRotationType

protected int getRotationType()
Returns the rotation type used by this drop game. Either DropBoard.RADIAL_ROTATION or DropBoard.INPLACE_ROTATION.


handleDropBlock

protected void handleDropBlock(boolean fast)
Handles drop block events.


getPieceVelocity

protected abstract float getPieceVelocity(boolean fast)
Returns the drop sprite velocity to assign to a new drop sprite.


dropNextBlock

protected void dropNextBlock()
Handles creation and dropping of the next dropping block.


checkDropEndsGame

protected boolean checkDropEndsGame()
Called by dropNextBlock() to determine whether the game should be ended rather than dropping the next block because the board is filled and a new block cannot enter. If true is returned, the drop controller assumes that the derived class will have ended or reset the game as appropriate and will simply abandon its attempt to drop the next block.


createNextBlock

protected DropBlockSprite createNextBlock()
Called only for block-dropping puzzles when it's time to create the next drop block. Returns the drop block sprite if it was successfully created, or null if it was not.


peekNextPieces

protected int[] peekNextPieces()
Take a peek at the next pieces.


handleDropSpriteMoved

protected void handleDropSpriteMoved(DropSprite sprite,
                                     long when,
                                     int col,
                                     int row)
Called when a drop sprite posts a piece moved event.


applyDropSprite

protected void applyDropSprite(DropSprite sprite,
                               int col,
                               int row)
Applies the pieces in the given sprite to the specified column and row in the board. Called when a drop sprite has finished traversing its entire distance.


canEvolveBoard

protected boolean canEvolveBoard()
Called to determine whether it is safe to evolve the board. The default implementation does not allow board evolution if there are sprites or animations active on the board.


evolveBoard

protected abstract boolean evolveBoard()
Evolves the board to an unchanging state. If the board is in a state where pieces should react with one another to cause changes to the board state (such as piece dropping via dropPieces(), piece destruction, and/or piece joining), this is where that process should be effected.

When no further evolution is possible and the board has stabilized this method should return false to indicate that such action should be taken. That will result in a follow-up call to boardDidStabilize() (assuming that the action was not cleared prior to the final stabilization of the board).


unstabilizeBoard

protected void unstabilizeBoard()
Derived classes should call this method whenever they change some board state that will require board evolution to restabilize the board.


boardDidStabilize

protected void boardDidStabilize()
Called when the board has been fully evolved and is once again stable. The default implementation updates the player's local board summary and drops the next block into the board, but derived classes may wish to perform custom actions if they don't use drop blocks or have other requirements.


updateSelfSummary

public void updateSelfSummary()
Updates the player's own local board summary to reflect the local copy of the player's board which is likely to be more up to date than the server-side board from which all other player board summaries originate.


animationDidFinish

protected void animationDidFinish(com.threerings.media.animation.Animation anim)
Called when an animation finishes doing its business. Derived classes may wish to override this method but should be sure to call super.animationDidFinish().


checkBlockLanded

protected boolean checkBlockLanded(String source,
                                   boolean commit,
                                   boolean atTop)
Checks whether the drop block can continue dropping and lands its pieces if not. Returns whether at least one piece of the block has landed; note that the other piece may need subsequent dropping.

Parameters:
commit - if true, the block landing is committed, if false, it is only checked, not committed.
atTop - whether the block sprite is to be treated as being at the top of its current row.

blockWillLand

protected void blockWillLand()
Called only for block-dropping puzzles when the drop block is about to land on something. Derived classes may wish to override this method to perform game-specific actions such as queueing up a "block placed" progress event.


blockDidLand

protected void blockDidLand()
Called only for block-dropping puzzles when the drop block lands on something. Derived classes may wish to override this method to perform any game-specific actions.


startBounceTimer

protected void startBounceTimer(String source)
Called when a block lands. We give the user a smidgen of time to continue to fiddle with the block before we actually land it. If the block is still landed when the bounce timer expires, we commit the landing, otherwise we let the block keep falling.


bounceTimerExpired

protected void bounceTimerExpired()
Called when the bounce timer expires. Herein we either commit the landing of a block if it is still landed or let it keep falling if it is no longer landed.


dropPieces

protected boolean dropPieces()
Drops any pieces that need dropping and returns whether any pieces were dropped. Derived classes that would like to drop their pieces should include a call to this method in their evolveBoard() implementation, and must also override getPieceDropLogic() to provide their game-specific piece dropper implementation.


getPieceDropLogic

protected PieceDropLogic getPieceDropLogic()
Returns the piece drop logic used to drop any pieces that need dropping in the board. Derived classes that intend to make use of dropPieces() must implement this method and return a reference to their game-specific piece dropper implementation.


getPieceDropper

protected PieceDropper getPieceDropper(PieceDropLogic logic)
Returns the piece dropper used to drop any pieces that need dropping in the board.


tick

public void tick(long tickStamp)
Specified by:
tick in interface com.threerings.media.FrameParticipant

getComponent

public Component getComponent()
Specified by:
getComponent in interface com.threerings.media.FrameParticipant

needsPaint

public boolean needsPaint()
Specified by:
needsPaint in interface com.threerings.media.FrameParticipant

setRisingPaused

public void setRisingPaused(boolean paused)
Sets whether the board rising is paused.


zipToNextRow

public void zipToNextRow()
Causes the board to zip quickly to the next row.


checkCanRise

protected boolean checkCanRise()
Called to determine whether or not rising a new row into the board is legal. The default implementation will return false if the top row of the board contains any pieces.


boardWillRise

protected void boardWillRise()
Called only for board-rising puzzles before effecting the rising of the board by one row. Derived classes may wish to override this method to add any desired behaviour, but should be sure to call super.boardWillRise().


boardDidRise

protected void boardDidRise()
Called only for board-rising puzzles when the board has finished rising one row. Derived classes may wish to override this method to add any desired behaviour, but should be sure to call super.boardDidRise().