Some idle widening & vararg logging
git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@801 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
@@ -100,8 +100,7 @@ public class PlayerStatusView extends JPanel
|
||||
@Override
|
||||
public String toString ()
|
||||
{
|
||||
return "[user=" + _username + ", pidx=" + _pidx +
|
||||
", status=" + _status + "]";
|
||||
return "[user=" + _username + ", pidx=" + _pidx + ", status=" + _status + "]";
|
||||
}
|
||||
|
||||
/** The game object associated with this view. */
|
||||
|
||||
@@ -86,10 +86,9 @@ public abstract class PuzzleBoardView extends VirtualMediaPanel
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the board view with a reference to its controller so that
|
||||
* it may communicate directly rather than by posting actions up the
|
||||
* interface hierarchy which sometimes fails if the puzzle board view
|
||||
* is hidden before we get a chance to post our actions.
|
||||
* Provides the board view with a reference to its controller so that it may communicate
|
||||
* directly rather than by posting actions up the interface hierarchy which sometimes fails if
|
||||
* the puzzle board view is hidden before we get a chance to post our actions.
|
||||
*/
|
||||
public void setController (PuzzleController pctrl)
|
||||
{
|
||||
@@ -105,9 +104,8 @@ public abstract class PuzzleBoardView extends VirtualMediaPanel
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this puzzle is paused or not.
|
||||
* If paused, a label will be displayed with the component's font,
|
||||
* which may be set with setFont().
|
||||
* Set whether this puzzle is paused or not. If paused, a label will be displayed with the
|
||||
* component's font, which may be set with setFont().
|
||||
*/
|
||||
@Override
|
||||
public void setPaused (boolean paused)
|
||||
@@ -118,8 +116,7 @@ public abstract class PuzzleBoardView extends VirtualMediaPanel
|
||||
PuzzleCodes.PUZZLE_MESSAGE_BUNDLE).xlate(pmsg);
|
||||
// create a label using our component's standard font
|
||||
_pauseLabel = new Label(pmsg, Label.BOLD | Label.OUTLINE,
|
||||
Color.WHITE, Color.BLACK,
|
||||
getFont());
|
||||
Color.WHITE, Color.BLACK, getFont());
|
||||
_pauseLabel.setTargetWidth(_bounds.width);
|
||||
_pauseLabel.layout(this);
|
||||
} else {
|
||||
@@ -129,11 +126,10 @@ public abstract class PuzzleBoardView extends VirtualMediaPanel
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the given animation to the set of animations currently present
|
||||
* on the board. The animation will be added to a list of action
|
||||
* animations whose count can be queried with {@link
|
||||
* #getActionAnimationCount}. The animation will automatically be
|
||||
* removed from the action list when it completes.
|
||||
* Adds the given animation to the set of animations currently present on the board. The
|
||||
* animation will be added to a list of action animations whose count can be queried with
|
||||
* {@link #getActionAnimationCount}. The animation will automatically be removed from the
|
||||
* action list when it completes.
|
||||
*/
|
||||
public void addActionAnimation (Animation anim)
|
||||
{
|
||||
@@ -172,11 +168,10 @@ public abstract class PuzzleBoardView extends VirtualMediaPanel
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the given sprite to the set of sprites currently present on
|
||||
* the board. The sprite will be added to a list of action sprites
|
||||
* whose count can be queried with {@link #getActionSpriteCount}. Callers
|
||||
* should be sure to remove the sprite when their work with it is done
|
||||
* via {@link #removeSprite}.
|
||||
* Adds the given sprite to the set of sprites currently present on the board. The sprite will
|
||||
* be added to a list of action sprites whose count can be queried with
|
||||
* {@link #getActionSpriteCount}. Callers should be sure to remove the sprite when their work
|
||||
* with it is done via {@link #removeSprite}.
|
||||
*/
|
||||
public void addActionSprite (Sprite sprite)
|
||||
{
|
||||
@@ -253,15 +248,16 @@ public abstract class PuzzleBoardView extends VirtualMediaPanel
|
||||
return StringUtil.shortClassName(obj);
|
||||
}
|
||||
};
|
||||
log.info("Board contents [board=" + StringUtil.shortClassName(this) +
|
||||
", sprites=" + StringUtil.listToString(_actionSprites, fmt) +
|
||||
", anims=" + StringUtil.listToString(_actionAnims, fmt) +
|
||||
"].");
|
||||
log.info("Board contents",
|
||||
"board", StringUtil.shortClassName(this),
|
||||
"sprites", StringUtil.listToString(_actionSprites, fmt),
|
||||
"anims", StringUtil.listToString(_actionAnims, fmt));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns an animation displaying the given string with
|
||||
* the specified parameters, floating it a short distance up the view.
|
||||
* Creates and returns an animation displaying the given string with the specified parameters,
|
||||
* floating it a short distance up the view.
|
||||
*
|
||||
* @param score the score text to display.
|
||||
* @param color the color of the text.
|
||||
@@ -276,9 +272,8 @@ public abstract class PuzzleBoardView extends VirtualMediaPanel
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a score animation, allowing derived classes to use custom
|
||||
* animations that are customized following a call to
|
||||
* {@link #createScoreAnimation(String,Color,Font,int,int)}.
|
||||
* Creates a score animation, allowing derived classes to use custom animations that are
|
||||
* customized following a call to {@link #createScoreAnimation(String,Color,Font,int,int)}.
|
||||
*/
|
||||
protected ScoreAnimation createScoreAnimation (Label label, int x, int y)
|
||||
{
|
||||
@@ -286,10 +281,9 @@ public abstract class PuzzleBoardView extends VirtualMediaPanel
|
||||
}
|
||||
|
||||
/**
|
||||
* Positions the supplied animation so as to avoid any active
|
||||
* animations previously registered with this method, and adds the
|
||||
* animation to the list of animations to be avoided by any future
|
||||
* avoid animations.
|
||||
* Positions the supplied animation so as to avoid any active animations previously registered
|
||||
* with this method, and adds the animation to the list of animations to be avoided by any
|
||||
* future avoid animations.
|
||||
*/
|
||||
public void trackAvoidAnimation (Animation anim)
|
||||
{
|
||||
@@ -341,8 +335,8 @@ public abstract class PuzzleBoardView extends VirtualMediaPanel
|
||||
}
|
||||
|
||||
/**
|
||||
* Fires a {@link #ACTION_CLEARED} command iff we have no remaining
|
||||
* interesting sprites or animations.
|
||||
* Fires a {@link #ACTION_CLEARED} command if we have no remaining interesting sprites or
|
||||
* animations.
|
||||
*/
|
||||
protected void maybeFireCleared ()
|
||||
{
|
||||
@@ -351,10 +345,9 @@ public abstract class PuzzleBoardView extends VirtualMediaPanel
|
||||
getActionCount() + ":" + isShowing());
|
||||
}
|
||||
if (getActionCount() == 0) {
|
||||
// we're probably in the middle of a tick() in an
|
||||
// animationDidFinish() call and we want everyone to finish
|
||||
// processing their business before we go clearing the action,
|
||||
// so we queue this up to be run after the tick is complete
|
||||
// we're probably in the middle of a tick() in an animationDidFinish() call and we want
|
||||
// everyone to finish processing their business before we go clearing the action, so we
|
||||
// queue this up to be run after the tick is complete
|
||||
_ctx.getClient().getRunQueue().postRunnable(new Runnable() {
|
||||
public void run () {
|
||||
_pctrl.boardActionCleared();
|
||||
@@ -364,9 +357,8 @@ public abstract class PuzzleBoardView extends VirtualMediaPanel
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the board contents to the given graphics context.
|
||||
* Sub-classes should implement this method to draw all of their
|
||||
* game-specific business.
|
||||
* Renders the board contents to the given graphics context. Sub-classes should implement this
|
||||
* method to draw all of their game-specific business.
|
||||
*/
|
||||
protected abstract void renderBoard (Graphics2D gfx, Rectangle dirty);
|
||||
|
||||
|
||||
@@ -130,16 +130,14 @@ public abstract class PuzzleController extends GameController
|
||||
{
|
||||
super.setGameOver(gameOver);
|
||||
|
||||
// clear the action if we're informed that the game is over early
|
||||
// by the client
|
||||
// clear the action if we're informed that the game is over early by the client
|
||||
if (gameOver) {
|
||||
clearAction();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the puzzle has action, false if the action is
|
||||
* cleared or it is suspended.
|
||||
* Returns true if the puzzle has action, false if the action is cleared or it is suspended.
|
||||
*/
|
||||
public boolean hasAction ()
|
||||
{
|
||||
@@ -209,9 +207,8 @@ public abstract class PuzzleController extends GameController
|
||||
}
|
||||
|
||||
/**
|
||||
* Derived classes should override this and return false if their
|
||||
* action should not be paused when the user switches control to the
|
||||
* chat area.
|
||||
* Derived classes should override this and return false if their action should not be paused
|
||||
* when the user switches control to the chat area.
|
||||
*/
|
||||
protected boolean supportsActionPause ()
|
||||
{
|
||||
@@ -297,9 +294,9 @@ public abstract class PuzzleController extends GameController
|
||||
}
|
||||
|
||||
/**
|
||||
* Puzzles that do not have "action" that starts and stops (via {@link
|
||||
* #startAction} and {@link #clearAction}) when the puzzle starts and
|
||||
* stops can override this method and return false.
|
||||
* Puzzles that do not have "action" that starts and stops (via {@link #startAction} and
|
||||
* {@link #clearAction}) when the puzzle starts and stops can override this method and return
|
||||
* false.
|
||||
*/
|
||||
protected boolean isActionPuzzle ()
|
||||
{
|
||||
@@ -307,11 +304,10 @@ public abstract class PuzzleController extends GameController
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether the action should start immediately as a result
|
||||
* of {@link GameController#gameDidStart} being called. If a puzzle wishes to do
|
||||
* some beginning of the game fun stuff, like display a tutorial
|
||||
* screen, they can veto the action start and then start it themselves
|
||||
* later.
|
||||
* Indicates whether the action should start immediately as a result of
|
||||
* {@link GameController#gameDidStart} being called. If a puzzle wishes to do some beginning
|
||||
* of the game fun stuff, like display a tutorial screen, they can veto the action start and
|
||||
* then start it themselves later.
|
||||
*/
|
||||
protected boolean startActionImmediately ()
|
||||
{
|
||||
@@ -327,28 +323,25 @@ public abstract class PuzzleController extends GameController
|
||||
if (name.equals(PuzzleObject.STATE)) {
|
||||
switch (event.getIntValue()) {
|
||||
case PuzzleObject.IN_PLAY:
|
||||
// we have to postpone all game starting activity until the
|
||||
// current action has ended; only after all the animations have
|
||||
// been completed will everything be in a state fit for
|
||||
// starting back up again
|
||||
// we have to postpone all game starting activity until the current action has
|
||||
// ended; only after all the animations have been completed will everything be in a
|
||||
// state fit for starting back up again
|
||||
fireWhenActionCleared(new ClearPender() {
|
||||
public int actionCleared () {
|
||||
// do the standard game did start business
|
||||
gameDidStart();
|
||||
// we don't always start the action immediately
|
||||
return startActionImmediately() ?
|
||||
RESTART_ACTION : CARE_NOT;
|
||||
return startActionImmediately() ? RESTART_ACTION : CARE_NOT;
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
||||
case PuzzleObject.GAME_OVER:
|
||||
// similarly we haev to postpone game ending activity until
|
||||
// the current action has ended
|
||||
// clean up and clear out
|
||||
// similarly we haev to postpone game ending activity until the current action has
|
||||
// ended clean up and clear out
|
||||
clearAction();
|
||||
// wait until the action is cleared before we roll down to our
|
||||
// delegates and do all that business
|
||||
// wait until the action is cleared before we roll down to our delegates and do all
|
||||
// that business
|
||||
fireWhenActionCleared(new ClearPender() {
|
||||
public int actionCleared () {
|
||||
gameDidEnd();
|
||||
@@ -390,12 +383,10 @@ public abstract class PuzzleController extends GameController
|
||||
}
|
||||
|
||||
/**
|
||||
* Derived classes should override this method and do whatever is
|
||||
* necessary to start up the action for their puzzle. This could be
|
||||
* called when the user is already in the "room" and the game starts,
|
||||
* or immediately upon entering the room if the game is already
|
||||
* started (for example if they disconnected and reconnected to a game
|
||||
* already in progress).
|
||||
* Derived classes should override this method and do whatever is necessary to start up the
|
||||
* action for their puzzle. This could be called when the user is already in the "room" and
|
||||
* the game starts, or immediately upon entering the room if the game is already started (for
|
||||
* example if they disconnected and reconnected to a game already in progress).
|
||||
*/
|
||||
protected void startAction ()
|
||||
{
|
||||
@@ -413,23 +404,22 @@ public abstract class PuzzleController extends GameController
|
||||
|
||||
// refuse to start the action if it's already going
|
||||
if (_astate != ACTION_CLEARED) {
|
||||
log.warning("Action state inappropriate for startAction() " +
|
||||
"[astate=" + _astate + "].");
|
||||
log.warning("Action state inappropriate for startAction()", "astate", _astate);
|
||||
Thread.dumpStack();
|
||||
return;
|
||||
}
|
||||
|
||||
if (isChatting() && supportsActionPause()) {
|
||||
log.info("Not starting action, player is chatting in a puzzle " +
|
||||
"that supports pausing the action.");
|
||||
log.info(
|
||||
"Not starting action, player is chatting in a puzzle that supports pausing the action.");
|
||||
return;
|
||||
}
|
||||
|
||||
log.debug("Starting puzzle action.");
|
||||
|
||||
// register the game progress updater; it may already be updated
|
||||
// because we can cycle through clearing the action and starting
|
||||
// it again before the updater gets a chance to unregister itself
|
||||
// register the game progress updater; it may already be updated because we can cycle
|
||||
// through clearing the action and starting it again before the updater gets a chance to
|
||||
// unregister itself
|
||||
if (!_pctx.getFrameManager().isRegisteredFrameParticipant(_updater)) {
|
||||
_pctx.getFrameManager().registerFrameParticipant(_updater);
|
||||
}
|
||||
@@ -440,8 +430,8 @@ public abstract class PuzzleController extends GameController
|
||||
// let our panel know what's up
|
||||
_panel.startAction();
|
||||
|
||||
// and if we're not currently chatting, set the puzzle to grab
|
||||
// keys and for the chatbox to look disabled
|
||||
// and if we're not currently chatting, set the puzzle to grab keys and for the chatbox to
|
||||
// look disabled
|
||||
if (!isChatting()) {
|
||||
_panel.setPuzzleGrabsKeys(true);
|
||||
}
|
||||
@@ -456,11 +446,10 @@ public abstract class PuzzleController extends GameController
|
||||
}
|
||||
|
||||
/**
|
||||
* If it is not known whether the puzzle board view has finished
|
||||
* animating its final bits after a previous call to {@link
|
||||
* #clearAction}, this method should be used instead of {@link
|
||||
* #startAction} as it will wait until the action is confirmedly over
|
||||
* before starting it anew.
|
||||
* If it is not known whether the puzzle board view has finished animating its final bits
|
||||
* after a previous call to {@link #clearAction}, this method should be used instead of
|
||||
* {@link #startAction} as it will wait until the action is confirmedly over before starting
|
||||
* it anew.
|
||||
*/
|
||||
protected void safeStartAction ()
|
||||
{
|
||||
@@ -477,14 +466,12 @@ public abstract class PuzzleController extends GameController
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the game has ended or when it is going to reset and
|
||||
* when the client leaves the game "room". This method does not always
|
||||
* immediately clear the action, but may mark the clear as pending if
|
||||
* the action cannot yet be cleared (as indicated by {@link
|
||||
* #canClearAction}). The action will eventually be cleared which will
|
||||
* result in a call to {@link #actuallyClearAction} which is what
|
||||
* derived classes should override to do their action clearing
|
||||
* business.
|
||||
* Called when the game has ended or when it is going to reset and when the client leaves the
|
||||
* game "room". This method does not always immediately clear the action, but may mark the
|
||||
* clear as pending if the action cannot yet be cleared (as indicated by
|
||||
* {@link #canClearAction}). The action will eventually be cleared which will result in a call
|
||||
* to {@link #actuallyClearAction} which is what derived classes should override to do their
|
||||
* action clearing business.
|
||||
*/
|
||||
protected void clearAction ()
|
||||
{
|
||||
@@ -500,35 +487,31 @@ public abstract class PuzzleController extends GameController
|
||||
|
||||
log.debug("Attempting to clear puzzle action.");
|
||||
|
||||
// put ourselves into a pending clear state and attempt to clear
|
||||
// the action
|
||||
// put ourselves into a pending clear state and attempt to clear the action
|
||||
_astate = CLEAR_PENDING;
|
||||
maybeClearAction();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called by the {@link PuzzleBoardView} when all
|
||||
* action on the board has finished.
|
||||
* This method is called by the {@link PuzzleBoardView} when all action on the board has
|
||||
* finished.
|
||||
*/
|
||||
protected void boardActionCleared ()
|
||||
{
|
||||
// if we have a clear pending, this could be the trigger that
|
||||
// allows us to clear our action
|
||||
// if we have a clear pending, this could be the trigger that allows us to clear our action
|
||||
maybeClearAction();
|
||||
}
|
||||
|
||||
/**
|
||||
* Queues up code to be invoked when the action is completely cleared
|
||||
* (including all remaining interesting sprites and animations on the
|
||||
* puzzle board).
|
||||
* Queues up code to be invoked when the action is completely cleared (including all remaining
|
||||
* interesting sprites and animations on the puzzle board).
|
||||
*/
|
||||
protected void fireWhenActionCleared (ClearPender pender)
|
||||
{
|
||||
// if the action is already ended, fire this pender immediately
|
||||
if (_astate == ACTION_CLEARED) {
|
||||
if (pender.actionCleared() == ClearPender.RESTART_ACTION) {
|
||||
log.debug("Restarting action at behest of pender " +
|
||||
pender + ".");
|
||||
log.debug("Restarting action at behest of pender " + pender + ".");
|
||||
startAction();
|
||||
}
|
||||
|
||||
@@ -539,14 +522,12 @@ public abstract class PuzzleController extends GameController
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not it is safe to clear the action. The default
|
||||
* behavior is to not allow the action to be cleared until all
|
||||
* interesting sprites and animations in the board view have finished.
|
||||
* If derived classes or delegates wish to postpone the clearing of
|
||||
* the action, they can return false from this method, but they must
|
||||
* then be sure to call {@link #maybeClearAction} when whatever
|
||||
* condition that caused them to desire to postpone action clearing
|
||||
* has finally been satisfied.
|
||||
* Returns whether or not it is safe to clear the action. The default behavior is to not allow
|
||||
* the action to be cleared until all interesting sprites and animations in the board view
|
||||
* have finished. If derived classes or delegates wish to postpone the clearing of the action,
|
||||
* they can return false from this method, but they must then be sure to call
|
||||
* {@link #maybeClearAction} when whatever condition that caused them to desire to postpone
|
||||
* action clearing has finally been satisfied.
|
||||
*/
|
||||
protected boolean canClearAction ()
|
||||
{
|
||||
@@ -561,8 +542,7 @@ public abstract class PuzzleController extends GameController
|
||||
applyToDelegates(new DelegateOp(PuzzleControllerDelegate.class) {
|
||||
@Override
|
||||
public void apply (PlaceControllerDelegate delegate) {
|
||||
canClear[0] = canClear[0] &&
|
||||
((PuzzleControllerDelegate)delegate).canClearAction();
|
||||
canClear[0] = canClear[0] && ((PuzzleControllerDelegate)delegate).canClearAction();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -570,27 +550,23 @@ public abstract class PuzzleController extends GameController
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to effect the actual clearing of our action if we've
|
||||
* received some asynchronous trigger that indicates that it may well
|
||||
* be safe now to clear the action.
|
||||
* Called to effect the actual clearing of our action if we've received some asynchronous
|
||||
* trigger that indicates that it may well be safe now to clear the action.
|
||||
*/
|
||||
protected void maybeClearAction ()
|
||||
{
|
||||
if (_astate == CLEAR_PENDING && canClearAction()) {
|
||||
actuallyClearAction();
|
||||
// } else {
|
||||
// Log.info("Not clearing action [astate=" + _astate +
|
||||
// ", canClear=" + canClearAction() + "].");
|
||||
// } else {
|
||||
// log.info("Not clearing action", "astate", _astate, "canClear", canClearAction());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the actual process of clearing the action for this puzzle.
|
||||
* This is only called after it is known to be safe to clear the
|
||||
* action. Derived classes can override this method and clear out
|
||||
* anything that is not needed while the puzzle's "action" is not
|
||||
* going (timers, etc.). Anything that is cleared out here should be
|
||||
* recreated in {@link #startAction}.
|
||||
* Performs the actual process of clearing the action for this puzzle. This is only called
|
||||
* after it is known to be safe to clear the action. Derived classes can override this method
|
||||
* and clear out anything that is not needed while the puzzle's "action" is not going (timers,
|
||||
* etc.). Anything that is cleared out here should be recreated in {@link #startAction}.
|
||||
*/
|
||||
protected void actuallyClearAction ()
|
||||
{
|
||||
@@ -635,16 +611,15 @@ public abstract class PuzzleController extends GameController
|
||||
});
|
||||
_clearPenders.clear();
|
||||
|
||||
// if there are no refusals and at least one restart request, go
|
||||
// ahead and restart the action now
|
||||
// if there are no refusals and at least one restart request, go ahead and restart the
|
||||
// action now
|
||||
if (results[1] == 0 && results[0] > 0) {
|
||||
startAction();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the action was actually cleared, but before the action
|
||||
* obsevers are notified.
|
||||
* Called when the action was actually cleared, but before the action observers are notified.
|
||||
*/
|
||||
protected void actionWasCleared ()
|
||||
{
|
||||
@@ -665,10 +640,9 @@ public abstract class PuzzleController extends GameController
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the delay in milliseconds between sending each progress
|
||||
* update event to the server. Derived classes may wish to override
|
||||
* this to send their progress updates more or less frequently than
|
||||
* the default.
|
||||
* Returns the delay in milliseconds between sending each progress update event to the server.
|
||||
* Derived classes may wish to override this to send their progress updates more or less
|
||||
* frequently than the default.
|
||||
*/
|
||||
protected long getProgressInterval ()
|
||||
{
|
||||
@@ -680,8 +654,8 @@ public abstract class PuzzleController extends GameController
|
||||
*/
|
||||
protected void generateNewBoard ()
|
||||
{
|
||||
// wait for any animations or sprites in the board to finish their
|
||||
// business before setting the board into place
|
||||
// wait for any animations or sprites in the board to finish their business before setting
|
||||
// the board into place
|
||||
fireWhenActionCleared(new ClearPender() {
|
||||
public int actionCleared () {
|
||||
// update the player board
|
||||
@@ -709,8 +683,8 @@ public abstract class PuzzleController extends GameController
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of progress events currently queued up for
|
||||
* sending to the server with the next progress update.
|
||||
* Returns the number of progress events currently queued up for sending to the server with
|
||||
* the next progress update.
|
||||
*/
|
||||
public int getEventCount ()
|
||||
{
|
||||
@@ -718,8 +692,8 @@ public abstract class PuzzleController extends GameController
|
||||
}
|
||||
|
||||
/**
|
||||
* Are we syncing boards for this puzzle?
|
||||
* By default, we defer to the PuzzlePanel and its runtime config.
|
||||
* Are we syncing boards for this puzzle? By default, we defer to the PuzzlePanel and its
|
||||
* runtime config.
|
||||
*/
|
||||
protected boolean isSyncingBoards ()
|
||||
{
|
||||
@@ -727,17 +701,15 @@ public abstract class PuzzleController extends GameController
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the given progress event and a snapshot of the supplied board
|
||||
* state to the set of progress events and associated board states for
|
||||
* later transmission to the server.
|
||||
* Adds the given progress event and a snapshot of the supplied board state to the set of
|
||||
* progress events and associated board states for later transmission to the server.
|
||||
*/
|
||||
public void addProgressEvent (int event, Board board)
|
||||
{
|
||||
// make sure they don't queue things up at strange times
|
||||
if (_puzobj.state != PuzzleObject.IN_PLAY) {
|
||||
log.warning("Rejecting progress event; game not in play " +
|
||||
"[puzobj=" + _puzobj.which() +
|
||||
", event=" + event + "].");
|
||||
log.warning("Rejecting progress event; game not in play",
|
||||
"puzobj", _puzobj.which(), "event", event);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -745,16 +717,16 @@ public abstract class PuzzleController extends GameController
|
||||
if (isSyncingBoards()) {
|
||||
_states.add((board == null) ? null : (Board)board.clone());
|
||||
if (board == null) {
|
||||
log.warning("Added progress event with no associated board " +
|
||||
"state, server will not be able to ensure " +
|
||||
"board state synchronization.");
|
||||
log.warning(
|
||||
"Added progress event with no associated board state, " +
|
||||
"server will not be able to ensure board state synchronization.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the server a game progress update with the list of events, as
|
||||
* well as board states if {@link PuzzlePanel#isSyncingBoards} is true.
|
||||
* Sends the server a game progress update with the list of events, as well as board states if
|
||||
* {@link PuzzlePanel#isSyncingBoards} is true.
|
||||
*/
|
||||
public void sendProgressUpdate ()
|
||||
{
|
||||
@@ -768,11 +740,11 @@ public abstract class PuzzleController extends GameController
|
||||
int[] events = CollectionUtil.toIntArray(_events);
|
||||
_events.clear();
|
||||
|
||||
// Log.info("Sending progress [session=" + _puzobj.sessionId +
|
||||
// ", events=" + StringUtil.toString(events) + "].");
|
||||
// log.info("Sending progress", "session", _puzobj.sessionId,
|
||||
// "events", StringUtil.toString(events));
|
||||
|
||||
// create an array of the board states that correspond with those
|
||||
// events (if state syncing is enabled)
|
||||
// create an array of the board states that correspond with those events (if state syncing
|
||||
// is enabled)
|
||||
int numStates = _states.size();
|
||||
if (numStates == size) { // ie, if we have a board to match every event
|
||||
Board[] states = new Board[numStates];
|
||||
@@ -812,8 +784,7 @@ public abstract class PuzzleController extends GameController
|
||||
*/
|
||||
class Unpauser extends MouseHijacker
|
||||
{
|
||||
public Unpauser (PuzzlePanel panel)
|
||||
{
|
||||
public Unpauser (PuzzlePanel panel) {
|
||||
super(panel.getBoardView());
|
||||
_panel = panel;
|
||||
panel.addMouseListener(_clicker);
|
||||
@@ -821,8 +792,7 @@ public abstract class PuzzleController extends GameController
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component release ()
|
||||
{
|
||||
public Component release () {
|
||||
_panel.removeMouseListener(_clicker);
|
||||
_panel.getBoardView().removeMouseListener(_clicker);
|
||||
return super.release();
|
||||
@@ -838,22 +808,21 @@ public abstract class PuzzleController extends GameController
|
||||
protected PuzzlePanel _panel;
|
||||
}
|
||||
|
||||
/** A special frame participant that handles the sending of puzzle
|
||||
* progress updates. We can't just
|
||||
* register an interval for this because sometimes the clock goes
|
||||
* backwards in time in windows and our intervals don't get called for
|
||||
* a long period of time which causes the server to think the client
|
||||
* is disconnected or cheating and resign them from the puzzle. God
|
||||
* bless you, Microsoft. */
|
||||
/**
|
||||
* A special frame participant that handles the sending of puzzle progress updates. We can't
|
||||
* just register an interval for this because sometimes the clock goes backwards in time in
|
||||
* windows and our intervals don't get called for a long period of time which causes the
|
||||
* server to think the client is disconnected or cheating and resign them from the puzzle. God
|
||||
* bless you, Microsoft.
|
||||
*/
|
||||
protected class Updater implements FrameParticipant
|
||||
{
|
||||
public void tick (long tickStamp) {
|
||||
if (_astate == ACTION_CLEARED) {
|
||||
// remove ourselves as the action is now cleared; we can't
|
||||
// do this in actuallyClearAction() because that might get
|
||||
// called during the PuzzlePanel's frame tick and it's
|
||||
// only safe to remove yourself during a tick(), not
|
||||
// another frame participant
|
||||
// remove ourselves as the action is now cleared; we can't do this in
|
||||
// actuallyClearAction() because that might get called during the PuzzlePanel's
|
||||
// frame tick and it's only safe to remove yourself during a tick(), not another
|
||||
// frame participant
|
||||
_pctx.getFrameManager().removeFrameParticipant(_updater);
|
||||
|
||||
} else if (tickStamp - _lastProgressTick > getProgressInterval()) {
|
||||
@@ -952,8 +921,7 @@ public abstract class PuzzleController extends GameController
|
||||
if (keycode == KeyEvent.VK_ESCAPE || keycode == KeyEvent.VK_PAUSE) {
|
||||
setChatting(!isChatting());
|
||||
|
||||
// pressing P also to pause (but not unpause),
|
||||
// and only if it has not been reassigned
|
||||
// pressing P also to pause (but not unpause), and only if it has not been reassigned
|
||||
} else if (keycode == KeyEvent.VK_P && !isChatting() &&
|
||||
!_panel._xlate.hasCommand(KeyEvent.VK_P)) {
|
||||
setChatting(true);
|
||||
|
||||
@@ -31,10 +31,9 @@ import com.threerings.puzzle.data.PuzzleGameCodes;
|
||||
import com.threerings.puzzle.data.PuzzleObject;
|
||||
|
||||
/**
|
||||
* A base class for puzzle controller delegates. Provides access to some
|
||||
* delegated puzzle controller methods ({@link #startAction}, {@link
|
||||
* #clearAction}, etc.) and provides a casted reference to the puzzle
|
||||
* object.
|
||||
* A base class for puzzle controller delegates. Provides access to some delegated puzzle
|
||||
* controller methods ({@link #startAction}, {@link #clearAction}, etc.) and provides a casted
|
||||
* reference to the puzzle object.
|
||||
*/
|
||||
public class PuzzleControllerDelegate extends GameControllerDelegate
|
||||
implements PuzzleCodes, PuzzleGameCodes
|
||||
@@ -90,23 +89,20 @@ public class PuzzleControllerDelegate extends GameControllerDelegate
|
||||
}
|
||||
|
||||
/**
|
||||
* Derived classes should override this method and do whatever is
|
||||
* necessary to start up the action for their puzzle. This could be
|
||||
* called when the user is already in the "room" and the game starts,
|
||||
* or immediately upon entering the room if the game is already
|
||||
* started (for example if they disconnected and reconnected to a game
|
||||
* already in progress).
|
||||
* Derived classes should override this method and do whatever is necessary to start up the
|
||||
* action for their puzzle. This could be called when the user is already in the "room" and
|
||||
* the game starts, or immediately upon entering the room if the game is already started (for
|
||||
* example if they disconnected and reconnected to a game already in progress).
|
||||
*/
|
||||
protected void startAction ()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {@link #maybeClearAction} when
|
||||
* conditions become such that they would once again allow action to
|
||||
* be cleared.
|
||||
* 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
|
||||
* {@link #maybeClearAction} when conditions become such that they would once again allow
|
||||
* action to be cleared.
|
||||
*/
|
||||
protected boolean canClearAction ()
|
||||
{
|
||||
@@ -114,9 +110,8 @@ public class PuzzleControllerDelegate extends GameControllerDelegate
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@link PuzzleController#maybeClearAction}, preserving its
|
||||
* protected access but making the method available to all
|
||||
* PuzzleControllerDelegate derivations.
|
||||
* Calls {@link PuzzleController#maybeClearAction}, preserving its protected access but making
|
||||
* the method available to all PuzzleControllerDelegate derivations.
|
||||
*/
|
||||
protected void maybeClearAction ()
|
||||
{
|
||||
@@ -124,20 +119,17 @@ public class PuzzleControllerDelegate extends GameControllerDelegate
|
||||
}
|
||||
|
||||
/**
|
||||
* Puzzles should override this method and clear out any action on the
|
||||
* board and generally clean up anything that was going on because the
|
||||
* game was in play. This is called when the game has ended or when it
|
||||
* is going to reset and when the client leaves the game "room".
|
||||
* Anything that is cleared out here should be recreated in {@link
|
||||
* #startAction}.
|
||||
* Puzzles should override this method and clear out any action on the board and generally
|
||||
* clean up anything that was going on because the game was in play. This is called when the
|
||||
* game has ended or when it is going to reset and when the client leaves the game "room".
|
||||
* Anything that is cleared out here should be recreated in {@link #startAction}.
|
||||
*/
|
||||
protected void clearAction ()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the puzzle controller sets up a new board for the
|
||||
* player.
|
||||
* Called when the puzzle controller sets up a new board for the player.
|
||||
*
|
||||
* @param board the newly initialized and ready-to-go board.
|
||||
*/
|
||||
|
||||
@@ -45,10 +45,9 @@ import com.threerings.puzzle.util.PuzzleContext;
|
||||
import static com.threerings.puzzle.Log.log;
|
||||
|
||||
/**
|
||||
* The puzzle panel class should be extended by classes that provide a
|
||||
* view for a puzzle game. The {@link PuzzleController} calls these
|
||||
* methods as necessary to perform its duties in managing the logical
|
||||
* actions of a puzzle game.
|
||||
* The puzzle panel class should be extended by classes that provide a view for a puzzle game. The
|
||||
* {@link PuzzleController} calls these methods as necessary to perform its duties in managing the
|
||||
* logical actions of a puzzle game.
|
||||
*/
|
||||
public abstract class PuzzlePanel extends JPanel
|
||||
implements PlaceView, ControllerProvider, PuzzleCodes, PuzzleGameCodes
|
||||
@@ -83,8 +82,7 @@ public abstract class PuzzlePanel extends JPanel
|
||||
{
|
||||
super.addNotify();
|
||||
|
||||
// leave the keyboard manager disabled to start, and set things up
|
||||
// for chatting
|
||||
// leave the keyboard manager disabled to start, and set things up for chatting
|
||||
setPuzzleGrabsKeys(false);
|
||||
}
|
||||
|
||||
@@ -98,20 +96,18 @@ public abstract class PuzzlePanel extends JPanel
|
||||
}
|
||||
|
||||
/**
|
||||
* Temporarily replaces the puzzle board display with the supplied
|
||||
* overlay panel. The panel can be removed and the board display
|
||||
* restored by calling {@link #popOverlayPanel}.
|
||||
* Temporarily replaces the puzzle board display with the supplied overlay panel. The panel
|
||||
* can be removed and the board display restored by calling {@link #popOverlayPanel}.
|
||||
*
|
||||
* @return true if the specified panel will be displayed, false if it
|
||||
* was not able to be pushed because another overlay panel is already
|
||||
* pushed onto the primary panel.
|
||||
* @return true if the specified panel will be displayed, false if it was not able to be
|
||||
* pushed because another overlay panel is already pushed onto the primary panel.
|
||||
*/
|
||||
public boolean pushOverlayPanel (JPanel opanel)
|
||||
{
|
||||
// bail if we've already got an overlay
|
||||
if (_opanel != null) {
|
||||
log.info("Refusing to push overlay panel, we've already got one " +
|
||||
"[opanel=" + _opanel + ", npanel=" + opanel + "].");
|
||||
log.info("Refusing to push overlay panel, we've already got one",
|
||||
"opanel", _opanel, "npanel", opanel);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -150,8 +146,8 @@ public abstract class PuzzlePanel extends JPanel
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the puzzle panel with the puzzle config of the puzzle
|
||||
* whose user interface is being displayed by the panel
|
||||
* Initializes the puzzle panel with the puzzle config of the puzzle whose user interface is
|
||||
* being displayed by the panel
|
||||
*/
|
||||
public void init (GameConfig config)
|
||||
{
|
||||
@@ -160,8 +156,7 @@ public abstract class PuzzlePanel extends JPanel
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether this panel receives events periodically from a robot
|
||||
* player.
|
||||
* Sets whether this panel receives events periodically from a robot player.
|
||||
*/
|
||||
public void setRobotPlayer (boolean isrobot)
|
||||
{
|
||||
@@ -175,8 +170,7 @@ public abstract class PuzzlePanel extends JPanel
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether the puzzle grabs keys or if they should go to the chat
|
||||
* window.
|
||||
* Sets whether the puzzle grabs keys or if they should go to the chat window.
|
||||
*/
|
||||
public void setPuzzleGrabsKeys (boolean puzgrabs)
|
||||
{
|
||||
@@ -211,9 +205,8 @@ public abstract class PuzzlePanel extends JPanel
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a robot player using the default RobotPlayer. Derived
|
||||
* classes can override to make use of more advanced robots adapted to
|
||||
* specific puzzles.
|
||||
* Creates a robot player using the default RobotPlayer. Derived classes can override to make
|
||||
* use of more advanced robots adapted to specific puzzles.
|
||||
*/
|
||||
protected RobotPlayer createRobotPlayer ()
|
||||
{
|
||||
@@ -221,25 +214,23 @@ public abstract class PuzzlePanel extends JPanel
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the puzzle board view that will be used to display the main
|
||||
* puzzle interface. This is called when the puzzle panel is
|
||||
* constructed. The derived panel will still be responsible for adding
|
||||
* the board to the interface hierarchy.
|
||||
* Creates the puzzle board view that will be used to display the main puzzle interface. This
|
||||
* is called when the puzzle panel is constructed. The derived panel will still be responsible
|
||||
* for adding the board to the interface hierarchy.
|
||||
*/
|
||||
protected abstract PuzzleBoardView createBoardView (PuzzleContext ctx);
|
||||
|
||||
/**
|
||||
* Creates the main panel used to display the puzzle and its various
|
||||
* in-game accoutrements (next block views, player status displays,
|
||||
* etc.) This is called when the puzzle panel is constructed. The
|
||||
* derived panel is responsible for making sure that the board view is
|
||||
* Creates the main panel used to display the puzzle and its various in-game accoutrements
|
||||
* (next block views, player status displays, etc.) This is called when the puzzle panel is
|
||||
* constructed. The derived panel is responsible for making sure that the board view is
|
||||
* present in the board panel.
|
||||
*/
|
||||
protected abstract JPanel createBoardPanel (PuzzleContext ctx);
|
||||
|
||||
/**
|
||||
* Returns a key translator with the desired key to controller command
|
||||
* mappings desired for this puzzle.
|
||||
* Returns a key translator with the desired key to controller command mappings desired for
|
||||
* this puzzle.
|
||||
*/
|
||||
protected abstract KeyTranslator getKeyTranslator ();
|
||||
|
||||
|
||||
@@ -37,8 +37,8 @@ public abstract class Board
|
||||
public abstract void dump ();
|
||||
|
||||
/**
|
||||
* Outputs a string representation of the board contents, interlaced
|
||||
* with the supplied comparison board.
|
||||
* Outputs a string representation of the board contents, interlaced with the supplied
|
||||
* comparison board.
|
||||
*/
|
||||
public abstract void dumpAndCompare (Board other);
|
||||
|
||||
@@ -60,8 +60,7 @@ public abstract class Board
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the seed in the board's random number generator and calls
|
||||
* {@link #populate}.
|
||||
* Sets the seed in the board's random number generator and calls {@link #populate}.
|
||||
*/
|
||||
public void initializeSeed (long seed)
|
||||
{
|
||||
@@ -70,8 +69,8 @@ public abstract class Board
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the random number generator used by the board to generate
|
||||
* random numbers for our puzzles.
|
||||
* Returns the random number generator used by the board to generate random numbers for our
|
||||
* puzzles.
|
||||
*/
|
||||
public Random getRandom ()
|
||||
{
|
||||
@@ -79,8 +78,8 @@ public abstract class Board
|
||||
}
|
||||
|
||||
/**
|
||||
* Called after the seed is set in the board to give derived classes a
|
||||
* chance to do things like populating the board with random pieces.
|
||||
* Called after the seed is set in the board to give derived classes a chance to do things
|
||||
* like populating the board with random pieces.
|
||||
*/
|
||||
protected void populate ()
|
||||
{
|
||||
@@ -90,29 +89,25 @@ public abstract class Board
|
||||
protected static class BoardRandom extends Random
|
||||
implements Cloneable
|
||||
{
|
||||
public BoardRandom (long seed)
|
||||
{
|
||||
public BoardRandom (long seed) {
|
||||
super(0L);
|
||||
setSeed(seed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void setSeed (long seed)
|
||||
{
|
||||
public synchronized void setSeed (long seed) {
|
||||
_seed = (seed ^ multiplier) & mask;
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized protected int next (int bits)
|
||||
{
|
||||
synchronized protected int next (int bits) {
|
||||
long nextseed = (_seed * multiplier + addend) & mask;
|
||||
_seed = nextseed;
|
||||
return (int)(nextseed >>> (48 - bits));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void nextBytes (byte[] bytes)
|
||||
{
|
||||
public void nextBytes (byte[] bytes) {
|
||||
unimplemented();
|
||||
}
|
||||
|
||||
@@ -123,8 +118,7 @@ public abstract class Board
|
||||
// nextFloat()
|
||||
|
||||
@Override
|
||||
public int nextInt (int n)
|
||||
{
|
||||
public int nextInt (int n) {
|
||||
if (n <= 0) {
|
||||
throw new IllegalArgumentException("n must be positive");
|
||||
}
|
||||
@@ -142,15 +136,13 @@ public abstract class Board
|
||||
}
|
||||
|
||||
@Override
|
||||
public double nextDouble ()
|
||||
{
|
||||
public double nextDouble () {
|
||||
long l = ((long)(next(26)) << 27) + next(27);
|
||||
return l / (double)(1L << 53);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized double nextGaussian ()
|
||||
{
|
||||
public synchronized double nextGaussian () {
|
||||
if (_haveNextNextGaussian) {
|
||||
_haveNextNextGaussian = false;
|
||||
return _nextNextGaussian;
|
||||
@@ -170,8 +162,7 @@ public abstract class Board
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object clone ()
|
||||
{
|
||||
public Object clone () {
|
||||
try {
|
||||
return super.clone();
|
||||
} catch (CloneNotSupportedException cnse) {
|
||||
@@ -180,14 +171,12 @@ public abstract class Board
|
||||
}
|
||||
|
||||
/**
|
||||
* I suppose I could copy all the methods from Random, then we
|
||||
* wouldn't need this..
|
||||
* I suppose I could copy all the methods from Random, then we wouldn't need this..
|
||||
*/
|
||||
private final void unimplemented ()
|
||||
{
|
||||
throw new RuntimeException(
|
||||
"The Random method you attempted to call " +
|
||||
"has not been implemented by BoardRandom.");
|
||||
"The Random method you attempted to call has not been implemented by BoardRandom.");
|
||||
}
|
||||
|
||||
/** The internal state related to generating random numbers. */
|
||||
|
||||
@@ -24,15 +24,14 @@ package com.threerings.puzzle.data;
|
||||
import com.threerings.io.SimpleStreamableObject;
|
||||
|
||||
/**
|
||||
* Provides summarized data representing a player's board in a puzzle
|
||||
* game. Board summaries are maintained by the puzzle server and are
|
||||
* periodically sent to the clients to give them a view into how well
|
||||
* their opponent(s) are doing. The data required to marshal a board
|
||||
* summary object should be notably smaller in size than what would be
|
||||
* required to marshal the entire associated {@link Board}.
|
||||
* Provides summarized data representing a player's board in a puzzle game. Board summaries are
|
||||
* maintained by the puzzle server and are periodically sent to the clients to give them a view
|
||||
* into how well their opponent(s) are doing. The data required to marshal a board summary object
|
||||
* should be notably smaller in size than what would be required to marshal the entire associated
|
||||
* {@link Board}.
|
||||
*
|
||||
* <p> Note all non-transient members of this and derived classes will
|
||||
* automatically be serialized when the summary is sent over the wire.
|
||||
* <p> Note all non-transient members of this and derived classes will automatically be serialized
|
||||
* when the summary is sent over the wire.
|
||||
*/
|
||||
public abstract class BoardSummary extends SimpleStreamableObject
|
||||
{
|
||||
@@ -45,8 +44,8 @@ public abstract class BoardSummary extends SimpleStreamableObject
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a board summary that retrieves full board information
|
||||
* from the supplied board when summarizing.
|
||||
* Constructs a board summary that retrieves full board information from the supplied board
|
||||
* when summarizing.
|
||||
*/
|
||||
public BoardSummary (Board board)
|
||||
{
|
||||
@@ -54,8 +53,8 @@ public abstract class BoardSummary extends SimpleStreamableObject
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the board associated with this board summary, causing
|
||||
* an immediate update to this summary.
|
||||
* Sets the board associated with this board summary, causing an immediate update to this
|
||||
* summary.
|
||||
*/
|
||||
public void setBoard (Board board)
|
||||
{
|
||||
@@ -64,14 +63,12 @@ public abstract class BoardSummary extends SimpleStreamableObject
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the {@link
|
||||
* com.threerings.puzzle.server.PuzzleManager} to refresh the
|
||||
* board summary information by studying the associated board
|
||||
* contents.
|
||||
* Called by the {@link com.threerings.puzzle.server.PuzzleManager} to refresh the board
|
||||
* summary information by studying the associated board contents.
|
||||
*/
|
||||
public abstract void summarize ();
|
||||
|
||||
/** The board that we're summarizing. This is only valid on the
|
||||
* server, and on the client only for the actual player's board. */
|
||||
/** The board that we're summarizing. This is only valid on the server, and on the client only
|
||||
* for the actual player's board. */
|
||||
protected transient Board _board;
|
||||
}
|
||||
|
||||
@@ -34,10 +34,9 @@ public interface PuzzleCodes extends InvocationCodes
|
||||
/** The default puzzle difficulty level. */
|
||||
public static final int DEFAULT_DIFFICULTY = 2;
|
||||
|
||||
/** Whether to enable debug logging and assertions for puzzles. Note
|
||||
* that enabling this may result in the server or client exiting
|
||||
* unexpectedly if certain error conditions arise in order to
|
||||
* facilitate debugging, and so this should never be enabled in any
|
||||
* environment even remotely resembling production. */
|
||||
/** Whether to enable debug logging and assertions for puzzles. Note that enabling this may
|
||||
* result in the server or client exiting unexpectedly if certain error conditions arise in
|
||||
* order to facilitate debugging, and so this should never be enabled in any environment even
|
||||
* remotely resembling production. */
|
||||
public static final boolean DEBUG_PUZZLE = false;
|
||||
}
|
||||
|
||||
@@ -22,9 +22,9 @@
|
||||
package com.threerings.puzzle.data;
|
||||
|
||||
/**
|
||||
* Contains codes used by the puzzle game client implementations. This
|
||||
* differs from {@link PuzzleCodes} as that is related to the puzzle
|
||||
* services which span the client and the server.
|
||||
* Contains codes used by the puzzle game client implementations. This differs from
|
||||
* {@link PuzzleCodes} as that is related to the puzzle services which span the client and the
|
||||
* server.
|
||||
*/
|
||||
public interface PuzzleGameCodes
|
||||
{
|
||||
|
||||
@@ -24,10 +24,9 @@ package com.threerings.puzzle.data;
|
||||
import com.threerings.parlor.game.data.GameObject;
|
||||
|
||||
/**
|
||||
* Extends the basic {@link GameObject} to add individual player
|
||||
* status. Puzzle games typically contain numerous players that may be
|
||||
* knocked out of the game while the overall game continues on, thereby
|
||||
* necessitating this second level of game status.
|
||||
* Extends the basic {@link GameObject} to add individual player status. Puzzle games typically
|
||||
* contain numerous players that may be knocked out of the game while the overall game continues
|
||||
* on, thereby necessitating this second level of game status.
|
||||
*/
|
||||
public class PuzzleObject extends GameObject
|
||||
implements PuzzleCodes
|
||||
@@ -52,8 +51,8 @@ public class PuzzleObject extends GameObject
|
||||
/** The puzzle difficulty level. */
|
||||
public int difficulty;
|
||||
|
||||
/** Summaries of the boards of all players in this puzzle (may be null
|
||||
* if the puzzle doesn't support individual player boards). */
|
||||
/** Summaries of the boards of all players in this puzzle (may be null if the puzzle doesn't
|
||||
* support individual player boards). */
|
||||
public BoardSummary[] summaries;
|
||||
|
||||
/** The seed used to germinate the boards. */
|
||||
|
||||
@@ -24,11 +24,10 @@ package com.threerings.puzzle.drop.client;
|
||||
import java.awt.Rectangle;
|
||||
|
||||
/**
|
||||
* The drop block sprite represents a block of multiple pieces that can be
|
||||
* rotated to any of the four cardinal compass directions. As such, it
|
||||
* may span multiple columns or rows depending on its orientation. The
|
||||
* block has a "central" piece around which it rotates, with the other
|
||||
* pieces referred to as "external" pieces.
|
||||
* The drop block sprite represents a block of multiple pieces that can be rotated to any of the
|
||||
* four cardinal compass directions. As such, it may span multiple columns or rows depending on
|
||||
* its orientation. The block has a "central" piece around which it rotates, with the other pieces
|
||||
* referred to as "external" pieces.
|
||||
*/
|
||||
public class DropBlockSprite extends DropSprite
|
||||
{
|
||||
@@ -41,8 +40,7 @@ public class DropBlockSprite extends DropSprite
|
||||
* @param orient the orientation of the sprite.
|
||||
* @param pieces the pieces displayed by the sprite.
|
||||
*/
|
||||
public DropBlockSprite (
|
||||
DropBoardView view, int col, int row, int orient, int[] pieces)
|
||||
public DropBlockSprite (DropBoardView view, int col, int row, int orient, int[] pieces)
|
||||
{
|
||||
super(view, col, row, pieces, 0);
|
||||
|
||||
@@ -60,8 +58,7 @@ public class DropBlockSprite extends DropSprite
|
||||
* @param renderOrder the rendering order of the sprite.
|
||||
*/
|
||||
public DropBlockSprite (
|
||||
DropBoardView view, int col, int row, int orient, int[] pieces,
|
||||
int renderOrder)
|
||||
DropBoardView view, int col, int row, int orient, int[] pieces, int renderOrder)
|
||||
{
|
||||
super(view, col, row, pieces, 0, renderOrder);
|
||||
|
||||
@@ -77,10 +74,9 @@ public class DropBlockSprite extends DropSprite
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of the row numbers containing the block pieces.
|
||||
* The first index is the row of the central piece. The array is
|
||||
* cached and re-used internally and so the caller should make their
|
||||
* own copy if they care to modify it.
|
||||
* Returns an array of the row numbers containing the block pieces. The first index is the row
|
||||
* of the central piece. The array is cached and re-used internally and so the caller should
|
||||
* make their own copy if they care to modify it.
|
||||
*/
|
||||
public int[] getRows ()
|
||||
{
|
||||
@@ -88,10 +84,9 @@ public class DropBlockSprite extends DropSprite
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of the column numbers containing the block pieces.
|
||||
* The first index is the column of the central piece. The array is
|
||||
* cached and re-used internally and so the caller should make their
|
||||
* own copy if they care to modify it.
|
||||
* Returns an array of the column numbers containing the block pieces. The first index is the
|
||||
* column of the central piece. The array is cached and re-used internally and so the caller
|
||||
* should make their own copy if they care to modify it.
|
||||
*/
|
||||
public int[] getColumns ()
|
||||
{
|
||||
@@ -99,9 +94,9 @@ public class DropBlockSprite extends DropSprite
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the bounds of the block in board piece coordinates. The
|
||||
* bounds rectangle is cached and re-used internally and so the caller
|
||||
* should make their own copy if they care to modify it.
|
||||
* Returns the bounds of the block in board piece coordinates. The bounds rectangle is cached
|
||||
* and re-used internally and so the caller should make their own copy if they care to modify
|
||||
* it.
|
||||
*/
|
||||
public Rectangle getBoardBounds ()
|
||||
{
|
||||
@@ -146,8 +141,8 @@ public class DropBlockSprite extends DropSprite
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the sprite image offset to reflect the direction in which
|
||||
* the external piece is hanging.
|
||||
* Updates the sprite image offset to reflect the direction in which the external piece is
|
||||
* hanging.
|
||||
*/
|
||||
@Override
|
||||
public void setOrientation (int orient)
|
||||
@@ -194,8 +189,7 @@ public class DropBlockSprite extends DropSprite
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-calculates the external piece position and bounds of the drop
|
||||
* block.
|
||||
* Re-calculates the external piece position and bounds of the drop block.
|
||||
*/
|
||||
protected void updateDropInfo ()
|
||||
{
|
||||
@@ -227,8 +221,8 @@ public class DropBlockSprite extends DropSprite
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the row the external piece is located in based on the
|
||||
* current central piece location and sprite orientation.
|
||||
* Returns the row the external piece is located in based on the current central piece
|
||||
* location and sprite orientation.
|
||||
*/
|
||||
protected int calculateExternalRow ()
|
||||
{
|
||||
@@ -242,8 +236,8 @@ public class DropBlockSprite extends DropSprite
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the column the external piece is located in based on the
|
||||
* current central piece location and sprite orientation.
|
||||
* Returns the column the external piece is located in based on the current central piece
|
||||
* location and sprite orientation.
|
||||
*/
|
||||
protected int calculateExternalColumn ()
|
||||
{
|
||||
@@ -256,8 +250,7 @@ public class DropBlockSprite extends DropSprite
|
||||
}
|
||||
}
|
||||
|
||||
/** How many times this sprite can be popped-up a row in a forgiving
|
||||
* rotation. */
|
||||
/** How many times this sprite can be popped-up a row in a forgiving rotation. */
|
||||
protected byte _popups = 2;
|
||||
|
||||
/** The drop block bounds in board coordinates. */
|
||||
|
||||
@@ -108,11 +108,9 @@ public abstract class DropBoardView extends PuzzleBoardView
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the {@link DropSprite} to populate <code>pos</code> with
|
||||
* the screen coordinates in pixels at which a piece at <code>(col,
|
||||
* row)</code> in the board should be drawn. Derived classes may wish
|
||||
* to override this method to allow specialised positioning of
|
||||
* sprites.
|
||||
* Called by the {@link DropSprite} to populate <code>pos</code> with the screen coordinates
|
||||
* in pixels at which a piece at <code>(col, row)</code> in the board should be drawn. Derived
|
||||
* classes may wish to override this method to allow specialised positioning of sprites.
|
||||
*/
|
||||
public void getPiecePosition (int col, int row, Point pos)
|
||||
{
|
||||
@@ -120,10 +118,9 @@ public abstract class DropBoardView extends PuzzleBoardView
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the {@link DropSprite} to get the dimensions of the area
|
||||
* that will be occupied by rendering a piece segment of the given
|
||||
* orientation and length whose bottom-leftmost corner is at
|
||||
* <code>(col, row)</code>.
|
||||
* Called by the {@link DropSprite} to get the dimensions of the area that will be occupied by
|
||||
* rendering a piece segment of the given orientation and length whose bottom-leftmost corner
|
||||
* is at <code>(col, row)</code>.
|
||||
*/
|
||||
public Dimension getPieceSegmentSize (int col, int row, int orient, int len)
|
||||
{
|
||||
@@ -141,8 +138,7 @@ public abstract class DropBoardView extends PuzzleBoardView
|
||||
public void createPiece (int piece, int sx, int sy)
|
||||
{
|
||||
if (sx < 0 || sy < 0 || sx >= _bwid || sy >= _bhei) {
|
||||
log.warning("Requested to create piece in invalid location " +
|
||||
"[sx=" + sx + ", sy=" + sy + "].");
|
||||
log.warning("Requested to create piece in invalid location", "sx", sx, "sy", sy);
|
||||
Thread.dumpStack();
|
||||
return;
|
||||
}
|
||||
@@ -150,11 +146,10 @@ public abstract class DropBoardView extends PuzzleBoardView
|
||||
}
|
||||
|
||||
/**
|
||||
* Refreshes the piece sprite at the specified location, if no sprite
|
||||
* exists at the location, one will be created. <em>Note:</em> this
|
||||
* method assumes the default {@link ImageSprite} is being used to
|
||||
* display pieces. If {@link #createPieceSprite} is overridden to
|
||||
* return a non-ImageSprite, this method must also be customized.
|
||||
* Refreshes the piece sprite at the specified location, if no sprite exists at the location,
|
||||
* one will be created. <em>Note:</em> this method assumes the default {@link ImageSprite} is
|
||||
* being used to display pieces. If {@link #createPieceSprite} is overridden to return a
|
||||
* non-ImageSprite, this method must also be customized.
|
||||
*/
|
||||
public void updatePiece (int sx, int sy)
|
||||
{
|
||||
@@ -162,17 +157,15 @@ public abstract class DropBoardView extends PuzzleBoardView
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the piece sprite at the specified location, if no sprite
|
||||
* exists at the location, one will be created. <em>Note:</em> this
|
||||
* method assumes the default {@link ImageSprite} is being used to
|
||||
* display pieces. If {@link #createPieceSprite} is overridden to
|
||||
* return a non-ImageSprite, this method must also be customized.
|
||||
* Updates the piece sprite at the specified location, if no sprite exists at the location,
|
||||
* one will be created. <em>Note:</em> this method assumes the default {@link ImageSprite} is
|
||||
* being used to display pieces. If {@link #createPieceSprite} is overridden to return a
|
||||
* non-ImageSprite, this method must also be customized.
|
||||
*/
|
||||
public void updatePiece (int piece, int sx, int sy)
|
||||
{
|
||||
if (sx < 0 || sy < 0 || sx >= _bwid || sy >= _bhei) {
|
||||
log.warning("Requested to update piece in invalid location " +
|
||||
"[sx=" + sx + ", sy=" + sy + "].");
|
||||
log.warning("Requested to update piece in invalid location", "sx", sx, "sy", sy);
|
||||
Thread.dumpStack();
|
||||
return;
|
||||
}
|
||||
@@ -192,8 +185,8 @@ public abstract class DropBoardView extends PuzzleBoardView
|
||||
long duration)
|
||||
{
|
||||
if (tx < 0 || ty < 0 || tx >= _bwid || ty >= _bhei) {
|
||||
log.warning("Requested to create and move piece to invalid " +
|
||||
"location [tx=" + tx + ", ty=" + ty + "].");
|
||||
log.warning("Requested to create and move piece to invalid location",
|
||||
"tx", tx, "ty", ty);
|
||||
Thread.dumpStack();
|
||||
return;
|
||||
}
|
||||
@@ -211,11 +204,10 @@ public abstract class DropBoardView extends PuzzleBoardView
|
||||
}
|
||||
|
||||
/**
|
||||
* Instructs the view to move the piece at the specified starting
|
||||
* position to the specified destination position. There must be a
|
||||
* sprite at the starting position, if there is a sprite at the
|
||||
* destination position, it must also be moved immediately following
|
||||
* this call (as in the case of a swap) to avoid badness.
|
||||
* Instructs the view to move the piece at the specified starting position to the specified
|
||||
* destination position. There must be a sprite at the starting position, if there is a sprite
|
||||
* at the destination position, it must also be moved immediately following this call (as in
|
||||
* the case of a swap) to avoid badness.
|
||||
*
|
||||
* @return the piece sprite that is being moved.
|
||||
*/
|
||||
@@ -224,8 +216,7 @@ public abstract class DropBoardView extends PuzzleBoardView
|
||||
int spos = sy * _bwid + sx;
|
||||
Sprite piece = _pieces[spos];
|
||||
if (piece == null) {
|
||||
log.warning("Missing source sprite for drop [sx=" + sx +
|
||||
", sy=" + sy + ", tx=" + tx + ", ty=" + ty + "].");
|
||||
log.warning("Missing source sprite for drop", "sx", sx, "sy", sy, "tx", tx, "ty", ty);
|
||||
return null;
|
||||
}
|
||||
_pieces[spos] = null;
|
||||
@@ -236,8 +227,8 @@ public abstract class DropBoardView extends PuzzleBoardView
|
||||
/**
|
||||
* A helper function for moving pieces into place.
|
||||
*/
|
||||
protected void movePiece (Sprite piece, final int sx, final int sy,
|
||||
final int tx, final int ty, long duration)
|
||||
protected void movePiece (
|
||||
Sprite piece, final int sx, final int sy, final int tx, final int ty, long duration)
|
||||
{
|
||||
final Exception where = new Exception();
|
||||
|
||||
@@ -247,9 +238,8 @@ public abstract class DropBoardView extends PuzzleBoardView
|
||||
if (sx == tx && sy == ty) {
|
||||
int tpos = ty * _bwid + tx;
|
||||
if (_pieces[tpos] != null) {
|
||||
log.warning("Zoiks! Asked to add a piece where we already " +
|
||||
"have one [sx=" + sx + ", sy=" + sy +
|
||||
", tx=" + tx + ", ty=" + ty + "].", where);
|
||||
log.warning("Zoiks! Asked to add a piece where we already have one",
|
||||
"sx", sx, "sy", sy, "tx", tx, "ty", ty, where);
|
||||
}
|
||||
_pieces[tpos] = piece;
|
||||
piece.setLocation(start.x, start.y);
|
||||
@@ -268,9 +258,8 @@ public abstract class DropBoardView extends PuzzleBoardView
|
||||
public void pathCompleted (Sprite sprite, Path path, long when) {
|
||||
sprite.removeSpriteObserver(this);
|
||||
if (_pieces[tpos] != null) {
|
||||
log.warning("Oh god, we're dropping onto another piece " +
|
||||
"[sx=" + sx + ", sy=" + sy +
|
||||
", tx=" + tx + ", ty=" + ty + "].", where);
|
||||
log.warning("Oh god, we're dropping onto another piece",
|
||||
"sx", sx, "sy", sy, "tx", tx + "ty", ty, where);
|
||||
return;
|
||||
}
|
||||
_pieces[tpos] = sprite;
|
||||
@@ -285,9 +274,8 @@ public abstract class DropBoardView extends PuzzleBoardView
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a piece is finished moving into its requested position.
|
||||
* Derived classes may wish to take this opportunity to play a sound
|
||||
* or whatnot.
|
||||
* Called when a piece is finished moving into its requested position. Derived classes may
|
||||
* wish to take this opportunity to play a sound or whatnot.
|
||||
*/
|
||||
protected void pieceArrived (long tickStamp, Sprite sprite, int px, int py)
|
||||
{
|
||||
@@ -295,9 +283,9 @@ public abstract class DropBoardView extends PuzzleBoardView
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the piece that is supposed to be at the specified
|
||||
* coordinates is not yet there but is actually en route to that
|
||||
* location (due to a call to {@link #movePiece(Sprite,int,int,int,int,long)}).
|
||||
* Returns true if the piece that is supposed to be at the specified coordinates is not yet
|
||||
* there but is actually en route to that location (due to a call to
|
||||
* {@link #movePiece(Sprite,int,int,int,int,long)}).
|
||||
*/
|
||||
protected boolean isMoving (int px, int py)
|
||||
{
|
||||
@@ -305,10 +293,9 @@ public abstract class DropBoardView extends PuzzleBoardView
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the image used to display the given piece at coordinates
|
||||
* <code>(0, 0)</code> with an orientation of {@link #NORTH}. This
|
||||
* serves as a convenience routine for those puzzles that don't bother
|
||||
* rendering their pieces differently when placed at different board
|
||||
* Returns the image used to display the given piece at coordinates <code>(0, 0)</code> with
|
||||
* an orientation of {@link #NORTH}. This serves as a convenience routine for those puzzles
|
||||
* that don't bother rendering their pieces differently when placed at different board
|
||||
* coordinates or in different orientations.
|
||||
*/
|
||||
public Mirage getPieceImage (int piece)
|
||||
@@ -317,11 +304,10 @@ public abstract class DropBoardView extends PuzzleBoardView
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the image used to display the given piece at the specified
|
||||
* column and row with the given orientation.
|
||||
* Returns the image used to display the given piece at the specified column and row with the
|
||||
* given orientation.
|
||||
*/
|
||||
public abstract Mirage getPieceImage (
|
||||
int piece, int col, int row, int orient);
|
||||
public abstract Mirage getPieceImage (int piece, int col, int row, int orient);
|
||||
|
||||
@Override
|
||||
public void setBoard (Board board)
|
||||
@@ -356,8 +342,7 @@ public abstract class DropBoardView extends PuzzleBoardView
|
||||
_pieces = new Sprite[width * height];
|
||||
for (int yy = 0; yy < height; yy++) {
|
||||
for (int xx = 0; xx < width; xx++) {
|
||||
Sprite piece = createPieceSprite(
|
||||
_dboard.getPiece(xx, yy), xx, yy);
|
||||
Sprite piece = createPieceSprite(_dboard.getPiece(xx, yy), xx, yy);
|
||||
if (piece != null) {
|
||||
int ppos = yy * width + xx;
|
||||
getPiecePosition(xx, yy, spos);
|
||||
@@ -403,8 +388,7 @@ public abstract class DropBoardView extends PuzzleBoardView
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new drop sprite used to animate the given pieces falling
|
||||
* in the specified column.
|
||||
* Creates a new drop sprite used to animate the given pieces falling in the specified column.
|
||||
*/
|
||||
public DropSprite createPieces (int col, int row, int[] pieces, int dist)
|
||||
{
|
||||
@@ -412,9 +396,8 @@ public abstract class DropBoardView extends PuzzleBoardView
|
||||
}
|
||||
|
||||
/**
|
||||
* Dirties the rectangle encompassing the segment with the given
|
||||
* direction and length whose bottom-leftmost corner is at <code>(col,
|
||||
* row)</code>.
|
||||
* Dirties the rectangle encompassing the segment with the given direction and length whose
|
||||
* bottom-leftmost corner is at <code>(col, row)</code>.
|
||||
*/
|
||||
public void dirtySegment (int dir, int col, int row, int len)
|
||||
{
|
||||
@@ -425,9 +408,8 @@ public abstract class DropBoardView extends PuzzleBoardView
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns an animation showing the specified score
|
||||
* floating up the view, with the label initially centered within the
|
||||
* view.
|
||||
* Creates and returns an animation showing the specified score floating up the view, with the
|
||||
* label initially centered within the view.
|
||||
*
|
||||
* @param score the score text to display.
|
||||
* @param color the color of the text.
|
||||
@@ -436,63 +418,57 @@ public abstract class DropBoardView extends PuzzleBoardView
|
||||
public ScoreAnimation createScoreAnimation (
|
||||
String score, Color color, Font font)
|
||||
{
|
||||
return createScoreAnimation(
|
||||
score, color, font, 0, _bhei - 1, _bwid, _bhei);
|
||||
return createScoreAnimation(score, color, font, 0, _bhei - 1, _bwid, _bhei);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns an animation showing the specified score
|
||||
* floating up the view.
|
||||
* Creates and returns an animation showing the specified score floating up the view.
|
||||
*
|
||||
* @param score the score text to display.
|
||||
* @param color the color of the text.
|
||||
* @param font the font to use.
|
||||
* @param x the left coordinate in board coordinates of the rectangle
|
||||
* within which the score is to be centered.
|
||||
* @param y the bottom coordinate in board coordinates of the
|
||||
* rectangle within which the score is to be centered.
|
||||
* @param width the width in board coordinates of the rectangle within
|
||||
* which the score is to be centered.
|
||||
* @param height the height in board coordinates of the rectangle
|
||||
* within which the score is to be centered.
|
||||
* @param x the left coordinate in board coordinates of the rectangle within which the score
|
||||
* is to be centered.
|
||||
* @param y the bottom coordinate in board coordinates of the rectangle within which the score
|
||||
* is to be centered.
|
||||
* @param width the width in board coordinates of the rectangle within which the score is to
|
||||
* be centered.
|
||||
* @param height the height in board coordinates of the rectangle within which the score is to
|
||||
* be centered.
|
||||
*/
|
||||
public ScoreAnimation createScoreAnimation (String score, Color color,
|
||||
Font font, int x, int y,
|
||||
int width, int height)
|
||||
public ScoreAnimation createScoreAnimation (
|
||||
String score, Color color, Font font, int x, int y, int width, int height)
|
||||
{
|
||||
// create the score animation
|
||||
ScoreAnimation anim =
|
||||
createScoreAnimation(score, color, font, x, y);
|
||||
ScoreAnimation anim = createScoreAnimation(score, color, font, x, y);
|
||||
|
||||
// position the label within the specified rectangle
|
||||
Dimension lsize = anim.getLabel().getSize();
|
||||
Point pos = new Point();
|
||||
centerRectInBoardRect(
|
||||
x, y, width, height, lsize.width, lsize.height, pos);
|
||||
centerRectInBoardRect(x, y, width, height, lsize.width, lsize.height, pos);
|
||||
anim.setLocation(pos.x, pos.y);
|
||||
|
||||
return anim;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the sprite that is used to display the specified piece. If
|
||||
* the piece represents no piece, this method should return null.
|
||||
* Creates the sprite that is used to display the specified piece. If the piece represents no
|
||||
* piece, this method should return null.
|
||||
*/
|
||||
protected Sprite createPieceSprite (int piece, int px, int py)
|
||||
{
|
||||
if (piece == PIECE_NONE) {
|
||||
return null;
|
||||
}
|
||||
ImageSprite sprite = new ImageSprite(
|
||||
getPieceImage(piece, px, py, NORTH));
|
||||
ImageSprite sprite = new ImageSprite(getPieceImage(piece, px, py, NORTH));
|
||||
sprite.setRenderOrder(-1);
|
||||
return sprite;
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates <code>pos</code> with the most appropriate screen
|
||||
* coordinates to center a rectangle of the given width and height (in
|
||||
* pixels) within the specified rectangle (in board coordinates).
|
||||
* Populates <code>pos</code> with the most appropriate screen coordinates to center a
|
||||
* rectangle of the given width and height (in pixels) within the specified rectangle (in
|
||||
* board coordinates).
|
||||
*
|
||||
* @param bx the bounding rectangle's left board coordinate.
|
||||
* @param by the bounding rectangle's bottom board coordinate.
|
||||
@@ -500,8 +476,7 @@ public abstract class DropBoardView extends PuzzleBoardView
|
||||
* @param bhei the bounding rectangle's height in board coordinates.
|
||||
* @param rwid the width of the rectangle to position in pixels.
|
||||
* @param rhei the height of the rectangle to position in pixels.
|
||||
* @param pos the point to populate with the rectangle's final
|
||||
* position.
|
||||
* @param pos the point to populate with the rectangle's final position.
|
||||
*/
|
||||
protected void centerRectInBoardRect (
|
||||
int bx, int by, int bwid, int bhei, int rwid, int rhei, Point pos)
|
||||
@@ -515,10 +490,9 @@ public abstract class DropBoardView extends PuzzleBoardView
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates the given drop block sprite to the specified orientation,
|
||||
* updating the image as necessary. Derived classes that make use of
|
||||
* block dropping functionality should override this method to do the
|
||||
* right thing.
|
||||
* Rotates the given drop block sprite to the specified orientation, updating the image as
|
||||
* necessary. Derived classes that make use of block dropping functionality should override
|
||||
* this method to do the right thing.
|
||||
*/
|
||||
public void rotateDropBlock (DropBlockSprite sprite, int orient)
|
||||
{
|
||||
@@ -543,9 +517,8 @@ public abstract class DropBoardView extends PuzzleBoardView
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the row of rising pieces to the given graphics context.
|
||||
* Sub-classes that make use of board rising functionality should
|
||||
* override this method to draw the rising piece row.
|
||||
* Renders the row of rising pieces to the given graphics context. Sub-classes that make use
|
||||
* of board rising functionality should override this method to draw the rising piece row.
|
||||
*/
|
||||
protected void renderRisingPieces (Graphics2D gfx, Rectangle dirtyRect)
|
||||
{
|
||||
|
||||
@@ -53,14 +53,13 @@ import com.threerings.puzzle.util.PuzzleContext;
|
||||
import static com.threerings.puzzle.Log.log;
|
||||
|
||||
/**
|
||||
* 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 {@link PlaceController#addDelegate}.
|
||||
* 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
|
||||
* {@link PlaceController#addDelegate}.
|
||||
*
|
||||
* <p> 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.
|
||||
* <p> 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.
|
||||
*
|
||||
* <p> Derived classes must implement {@link #getPieceVelocity} and {@link #evolveBoard}.
|
||||
*
|
||||
@@ -95,8 +94,7 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
public static final String RAISE_ROW = "raise_row";
|
||||
|
||||
/**
|
||||
* Creates a delegate with the specified drop game logic and
|
||||
* controller.
|
||||
* Creates a delegate with the specified drop game logic and controller.
|
||||
*/
|
||||
public DropControllerDelegate (PuzzleController ctrl, DropLogic logic)
|
||||
{
|
||||
@@ -141,8 +139,8 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the speed with which the next board row should rise into
|
||||
* place, in pixels per millisecond.
|
||||
* Returns the speed with which the next board row should rise into place, in pixels per
|
||||
* millisecond.
|
||||
*/
|
||||
protected float getRiseVelocity ()
|
||||
{
|
||||
@@ -166,7 +164,7 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
{
|
||||
super.startAction();
|
||||
|
||||
// Log.info("Starting drop action");
|
||||
// log.info("Starting drop action");
|
||||
|
||||
// add ourselves as a frame participant
|
||||
_ctx.getFrameManager().registerFrameParticipant(this);
|
||||
@@ -181,17 +179,15 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
// it on its merry way once more
|
||||
if (_blocksprite != null) {
|
||||
long delta = _dview.getTimeStamp() - _blockStamp;
|
||||
log.info("Restarting drop sprite [delta=" + delta + "].");
|
||||
log.info("Restarting drop sprite", "delta", delta);
|
||||
_blocksprite.fastForward(delta);
|
||||
_blockStamp = 0L;
|
||||
_dview.addSprite(_blocksprite);
|
||||
|
||||
// if we cleared the action while the drop sprite was
|
||||
// bouncing, we need to land the block to get things going
|
||||
// again
|
||||
// if we cleared the action while the drop sprite was bouncing, we need to land the
|
||||
// block to get things going again
|
||||
if (_blocksprite.isBouncing()) {
|
||||
log.info("Ended on a bounce, landing the block and " +
|
||||
"starting things up.");
|
||||
log.info("Ended on a bounce, landing the block and starting things up.");
|
||||
checkBlockLanded("bounced", true, true);
|
||||
}
|
||||
}
|
||||
@@ -210,16 +206,15 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
@Override
|
||||
protected void clearAction ()
|
||||
{
|
||||
super.clearAction();
|
||||
|
||||
// Log.info("Clearing drop action.");
|
||||
// log.info("Clearing drop action.");
|
||||
|
||||
// do away with the bounce interval
|
||||
_bounceStamp = 0;
|
||||
@@ -310,8 +305,8 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
}
|
||||
|
||||
if (handled && _blocksprite != null) {
|
||||
// land the block if it's been placed on something solid as a
|
||||
// result of one of the above actions
|
||||
// land the block if it's been placed on something solid as a result of one of the
|
||||
// above actions
|
||||
String source = "fiddled [cmd=" + cmd + "]";
|
||||
if (checkBlockLanded(source, false, false)) {
|
||||
startBounceTimer(source);
|
||||
@@ -335,19 +330,17 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
int row = _blocksprite.getRow(), col = _blocksprite.getColumn();
|
||||
int dx = (dir == LEFT) ? -1 : 1;
|
||||
|
||||
// if the sprite has made it to the bottom of the board then we
|
||||
// don't want to allow it to "virtually" fall any further because
|
||||
// of the bounce interval
|
||||
// if the sprite has made it to the bottom of the board then we don't want to allow it to
|
||||
// "virtually" fall any further because of the bounce interval
|
||||
float pctdone = (row >= (_bhei - 1)) ? 0 :
|
||||
_blocksprite.getPercentDone(_dview.getTimeStamp());
|
||||
|
||||
// get the drop block position resulting from the move
|
||||
Point pos = _dboard.getForgivingMove(
|
||||
bb.x, bb.y, bb.width, bb.height, dx, 0, pctdone);
|
||||
Point pos = _dboard.getForgivingMove(bb.x, bb.y, bb.width, bb.height, dx, 0, pctdone);
|
||||
if (pos != null) {
|
||||
int frow = row + (pos.y - bb.y);
|
||||
int fcol = col + (pos.x - bb.x);
|
||||
// Log.info("Valid move [row=" + frow + ", col=" + col + "].");
|
||||
// log.info("Valid move", "row", frow, "col", col);
|
||||
_blocksprite.setBoardLocation(frow, fcol);
|
||||
}
|
||||
}
|
||||
@@ -364,9 +357,8 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
// gather information regarding the attempted rotation
|
||||
int[] rows = _blocksprite.getRows();
|
||||
int[] cols = _blocksprite.getColumns();
|
||||
// if the sprite has made it to the bottom of the board then we
|
||||
// don't want to allow it to "virtually" fall any further because
|
||||
// of the bounce interval
|
||||
// if the sprite has made it to the bottom of the board then we don't want to allow it to
|
||||
// "virtually" fall any further because of the bounce interval
|
||||
float pctdone = (rows[0] >= (_bhei - 1)) ? 0 :
|
||||
_blocksprite.getPercentDone(_dview.getTimeStamp());
|
||||
|
||||
@@ -375,10 +367,9 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
rows, cols, _blocksprite.getOrientation(), dir,
|
||||
getRotationType(), pctdone, _blocksprite.canPopup());
|
||||
if (info != null) {
|
||||
// Log.info("Found valid rotation " +
|
||||
// "[orient=" + DirectionUtil.toShortString(info[0]) +
|
||||
// ", col=" + info[1] + ", row=" + info[2] +
|
||||
// ", blocksprite=" + _blocksprite + "].");
|
||||
// log.info("Found valid rotation",
|
||||
// "orient", DirectionUtil.toShortString(info[0]), "col", info[1], "row", info[2],
|
||||
// "blocksprite", _blocksprite);
|
||||
|
||||
// update the piece image
|
||||
_dview.rotateDropBlock(_blocksprite, info[0]);
|
||||
@@ -396,16 +387,16 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the drop block has rotated in the specified direction
|
||||
* to allow derived classes to engage in any game-specific antics.
|
||||
* Called when the drop block has rotated in the specified direction to allow derived classes
|
||||
* to engage in any game-specific antics.
|
||||
*/
|
||||
protected void blockDidRotate (int dir)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the rotation type used by this drop game. Either {@link
|
||||
* DropBoard#RADIAL_ROTATION} or {@link DropBoard#INPLACE_ROTATION}.
|
||||
* Returns the rotation type used by this drop game. Either {@link DropBoard#RADIAL_ROTATION}
|
||||
* or {@link DropBoard#INPLACE_ROTATION}.
|
||||
*/
|
||||
protected int getRotationType ()
|
||||
{
|
||||
@@ -421,7 +412,7 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
|
||||
// only allow changing the piece velocity if we're not bouncing
|
||||
if (_blocksprite != null && _bounceStamp == 0) {
|
||||
// Log.info("Updating drop block velocity [fast=" + fast + "].");
|
||||
// log.info("Updating drop block velocity", "fast", fast);
|
||||
_blocksprite.setVelocity(getPieceVelocity(fast));
|
||||
}
|
||||
}
|
||||
@@ -437,13 +428,11 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
protected void dropNextBlock ()
|
||||
{
|
||||
if (_blocksprite != null || !_ctrl.hasAction()) {
|
||||
log.info("Not dropping block [bs=" + (_blocksprite != null) +
|
||||
", action=" + _ctrl.hasAction() + "].");
|
||||
log.info("Not dropping block", "bs", _blocksprite != null, "action", _ctrl.hasAction());
|
||||
return;
|
||||
}
|
||||
|
||||
// determine whether or not the game should be ended because we
|
||||
// can't drop the next block
|
||||
// determine whether or not the game should be ended because we can't drop the next block
|
||||
if (checkDropEndsGame()) {
|
||||
return;
|
||||
}
|
||||
@@ -476,12 +465,10 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by {@link #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.
|
||||
* Called by {@link #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.
|
||||
*/
|
||||
protected boolean checkDropEndsGame ()
|
||||
{
|
||||
@@ -489,9 +476,9 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 <code>null</code> if it was not.
|
||||
* 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 <code>null</code> if it
|
||||
* was not.
|
||||
*/
|
||||
protected DropBlockSprite createNextBlock ()
|
||||
{
|
||||
@@ -510,8 +497,7 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
/**
|
||||
* Called when a drop sprite posts a piece moved event.
|
||||
*/
|
||||
protected void handleDropSpriteMoved (
|
||||
DropSprite sprite, long when, int col, int row)
|
||||
protected void handleDropSpriteMoved (DropSprite sprite, long when, int col, int row)
|
||||
{
|
||||
if (sprite instanceof DropBlockSprite) {
|
||||
if (checkBlockLanded("piece-moved", false, true)) {
|
||||
@@ -538,9 +524,8 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
protected void applyDropSprite (DropSprite sprite, int col, int row)
|
||||
{
|
||||
@@ -551,17 +536,16 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
for (int dy = 0; dy < pieces.length; dy++) {
|
||||
// pieces outside the board are discarded
|
||||
if (row - dy >= 0) {
|
||||
// note: vertical segments are applied counting downwards
|
||||
// from the starting row toward row zero
|
||||
// note: vertical segments are applied counting downwards from the starting row
|
||||
// toward row zero
|
||||
_dview.createPiece(pieces[dy], col, row - dy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
protected boolean canEvolveBoard ()
|
||||
{
|
||||
@@ -569,24 +553,21 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {@link #dropPieces},
|
||||
* piece destruction, and/or piece joining), this is where that
|
||||
* process should be effected.
|
||||
* 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
|
||||
* {@link #dropPieces}, piece destruction, and/or piece joining), this is where that process
|
||||
* should be effected.
|
||||
*
|
||||
* <p> 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
|
||||
* {@link #boardDidStabilize} (assuming that the action was not
|
||||
* cleared prior to the final stabilization of the board).
|
||||
* <p> 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 {@link #boardDidStabilize} (assuming that the action was not cleared prior to the
|
||||
* final stabilization of the board).
|
||||
*/
|
||||
protected abstract boolean evolveBoard ();
|
||||
|
||||
/**
|
||||
* Derived classes should call this method whenever they change some
|
||||
* board state that will require board evolution to restabilize the
|
||||
* board.
|
||||
* Derived classes should call this method whenever they change some board state that will
|
||||
* require board evolution to restabilize the board.
|
||||
*/
|
||||
protected void unstabilizeBoard ()
|
||||
{
|
||||
@@ -594,11 +575,10 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
protected void boardDidStabilize ()
|
||||
{
|
||||
@@ -607,10 +587,9 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
public void updateSelfSummary ()
|
||||
{
|
||||
@@ -624,9 +603,8 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when an animation finishes doing its business. Derived
|
||||
* classes may wish to override this method but should be sure to call
|
||||
* <code>super.animationDidFinish()</code>.
|
||||
* Called when an animation finishes doing its business. Derived classes may wish to override
|
||||
* this method but should be sure to call <code>super.animationDidFinish()</code>.
|
||||
*/
|
||||
protected void animationDidFinish (Animation anim)
|
||||
{
|
||||
@@ -634,17 +612,16 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* 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.
|
||||
*
|
||||
* @param commit if true, the block landing is committed, if false, it
|
||||
* is only checked, not committed.
|
||||
* @param atTop whether the block sprite is to be treated as being at
|
||||
* the top of its current row.
|
||||
* @param commit if true, the block landing is committed, if false, it is only checked, not
|
||||
* committed.
|
||||
* @param atTop whether the block sprite is to be treated as being at the top of its current
|
||||
* row.
|
||||
*/
|
||||
protected boolean checkBlockLanded (
|
||||
String source, boolean commit, boolean atTop)
|
||||
protected boolean checkBlockLanded (String source, boolean commit, boolean atTop)
|
||||
{
|
||||
if (_blocksprite == null) {
|
||||
return true;
|
||||
@@ -659,25 +636,20 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
float pctdone = (atTop) ? 0.0f :
|
||||
_blocksprite.getPercentDone(_dview.getTimeStamp());
|
||||
|
||||
// Log.info("Checking landed [source=" + source +
|
||||
// ", bounceRow=" + _bounceRow +
|
||||
// ", rows=" + StringUtil.toString(rows) +
|
||||
// ", cols=" + StringUtil.toString(cols) +
|
||||
// ", orient=" + DirectionUtil.toShortString(
|
||||
// _blocksprite.getOrientation()) +
|
||||
// ", commit=" + commit + ", pctdone=" + pctdone + "].");
|
||||
// log.info("Checking landed",
|
||||
// "source", source, "bounceRow", _bounceRow, "rows", rows, "cols", cols,
|
||||
// "orient", DirectionUtil.toShortString(_blocksprite.getOrientation()),
|
||||
// "commit", commit, "pctdone", pctdone);
|
||||
|
||||
if (_dboard.isValidDrop(rows, cols, pctdone)) {
|
||||
if (commit) {
|
||||
log.info("Not valid drop [source=" + source +
|
||||
", commit=" + commit + ", atTop=" + atTop +
|
||||
", pctdone=" + pctdone + "].");
|
||||
log.info("Not valid drop",
|
||||
"source", source, "commit", commit, "atTop", atTop, "pctdone", pctdone);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// if we're committing the landing, remove the sprite and update
|
||||
// the board and all that
|
||||
// if we're committing the landing, remove the sprite and update the board and all that
|
||||
if (commit) {
|
||||
// give sub-classes a chance to do any pre-landing business
|
||||
blockWillLand();
|
||||
@@ -689,23 +661,18 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
if (rows[ii] >= 0) {
|
||||
int col = cols[ii], row = rows[ii];
|
||||
|
||||
// sanity-check the block to make sure it's located in
|
||||
// a valid position, and that we aren't somehow
|
||||
// overwriting an existing piece
|
||||
// sanity-check the block to make sure it's located in a valid position, and
|
||||
// that we aren't somehow overwriting an existing piece
|
||||
if (col < 0 || col >= _bwid || row >= _bhei) {
|
||||
log.warning("Placing drop block piece outside board " +
|
||||
"bounds!? [x=" + col + ", y=" + row +
|
||||
", pidx=" + ii +
|
||||
", blocksprite=" + _blocksprite + "].");
|
||||
log.warning("Placing drop block piece outside board bounds!?",
|
||||
"x", col, "y", row, "pidx", ii, "blocksprite", _blocksprite);
|
||||
error = true;
|
||||
|
||||
} else {
|
||||
int cpiece = _dboard.getPiece(col, row);
|
||||
if (cpiece != PIECE_NONE) {
|
||||
log.warning("Placing drop block piece onto " +
|
||||
"occupied board position!? [x=" + col +
|
||||
", y=" + row + ", pidx=" + ii +
|
||||
", blocksprite=" + _blocksprite + "].");
|
||||
log.warning("Placing drop block piece onto occupied board position!?",
|
||||
"x", col, "y", row, "pidx", ii, "blocksprite", _blocksprite);
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
@@ -736,10 +703,9 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
protected void blockWillLand ()
|
||||
{
|
||||
@@ -747,9 +713,8 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
protected void blockDidLand ()
|
||||
{
|
||||
@@ -757,19 +722,16 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
protected void startBounceTimer (String source)
|
||||
{
|
||||
int bounceRow = IntListUtil.getMaxValue(_blocksprite.getRows());
|
||||
// Log.info("startBounceTimer [source=" + source +
|
||||
// ", bounceStamp=" + _bounceStamp +
|
||||
// ", time=" + _dview.getTimeStamp() +
|
||||
// ", bounceRow=" + _bounceRow +
|
||||
// ", nbounceRow=" + bounceRow + "].");
|
||||
// log.info("startBounceTimer",
|
||||
// "source", source, "bounceStamp", _bounceStamp, "time", _dview.getTimeStamp(),
|
||||
// "bounceRow", _bounceRow, "nbounceRow", bounceRow);
|
||||
|
||||
// forcibly land the block if we bounce twice at the same row
|
||||
if (_bounceStamp == 0 && _bounceRow == bounceRow) {
|
||||
@@ -779,26 +741,23 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
return;
|
||||
}
|
||||
|
||||
// if the bounce "timer" is already started, the user probably did
|
||||
// something like rotate the piece while it was bouncing (which is
|
||||
// why we give them the bounce interval), so we don't reset
|
||||
// if the bounce "timer" is already started, the user probably did something like rotate
|
||||
// the piece while it was bouncing (which is why we give them the bounce interval), so we
|
||||
// don't reset
|
||||
if (_bounceStamp == 0) {
|
||||
// slow the piece down so that it doesn't fly past the
|
||||
// coordinates at which it's potentially landing; we have to
|
||||
// do this before we tell the sprite that it's bouncing
|
||||
// because changing the velocity fiddles with the rowstamp and
|
||||
// we're going to reset the rowstamp when we tell the sprite
|
||||
// that it's bouncing
|
||||
// slow the piece down so that it doesn't fly past the coordinates at which it's
|
||||
// potentially landing; we have to do this before we tell the sprite that it's bouncing
|
||||
// because changing the velocity fiddles with the rowstamp and we're going to reset the
|
||||
// rowstamp when we tell the sprite that it's bouncing
|
||||
_blocksprite.setVelocity(getPieceVelocity(false));
|
||||
|
||||
// set up our bounce interval (it depends on the current piece
|
||||
// velocity and so must be set at the time we bounce)
|
||||
// set up our bounce interval (it depends on the current piece velocity and so must be
|
||||
// set at the time we bounce)
|
||||
_bounceInterval = (int)
|
||||
((_dview.getPieceHeight() * BOUNCE_FRACTION) /
|
||||
getPieceVelocity(false));
|
||||
// Log.info("bounceInterval=" + _bounceInterval +
|
||||
// ", phei=" + _dview.getPieceHeight() +
|
||||
// ", vel=" + getPieceVelocity(false));
|
||||
// log.info("bounce", "bounceInterval", _bounceInterval,
|
||||
// "phei", _dview.getPieceHeight(), "vel", getPieceVelocity(false));
|
||||
|
||||
// make a note of the time we started bouncing
|
||||
_bounceStamp = _dview.getTimeStamp();
|
||||
@@ -812,15 +771,13 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
* 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.
|
||||
*/
|
||||
protected void bounceTimerExpired ()
|
||||
{
|
||||
// Log.info("bounceTimerExpired [bounceStamp=" + _bounceStamp +
|
||||
// ", time=" + _dview.getTimeStamp() +
|
||||
// ", bounceRow=" + _bounceRow + "].");
|
||||
// log.info("bounceTimerExpired",
|
||||
// "bounceStamp", _bounceStamp, "time", _dview.getTimeStamp(), "bounceRow", _bounceRow);
|
||||
|
||||
// make sure we weren't cancelled for some reason
|
||||
if (_bounceStamp != 0) {
|
||||
@@ -836,11 +793,10 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {@link #evolveBoard}
|
||||
* implementation, and must also override {@link #getPieceDropLogic}
|
||||
* to provide their game-specific piece dropper implementation.
|
||||
* 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
|
||||
* {@link #evolveBoard} implementation, and must also override {@link #getPieceDropLogic} to
|
||||
* provide their game-specific piece dropper implementation.
|
||||
*/
|
||||
protected boolean dropPieces ()
|
||||
{
|
||||
@@ -848,8 +804,7 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
public void pieceDropped (
|
||||
int piece, int sx, int sy, int dx, int dy) {
|
||||
float vel = getPieceVelocity(true) * 1.5f;
|
||||
long duration = (long)(_dview.getPieceHeight() *
|
||||
Math.abs(dy-sy) / vel);
|
||||
long duration = (long)(_dview.getPieceHeight() * Math.abs(dy-sy) / vel);
|
||||
if (sy < 0) {
|
||||
_dview.createPiece(piece, sx, sy, dx, dy, duration);
|
||||
} else {
|
||||
@@ -861,10 +816,9 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the piece drop logic used to drop any pieces that need
|
||||
* dropping in the board. Derived classes that intend to make use of
|
||||
* {@link #dropPieces} must implement this method and return a
|
||||
* reference to their game-specific piece dropper implementation.
|
||||
* Returns the piece drop logic used to drop any pieces that need dropping in the board.
|
||||
* Derived classes that intend to make use of {@link #dropPieces} must implement this method
|
||||
* and return a reference to their game-specific piece dropper implementation.
|
||||
*/
|
||||
protected PieceDropLogic getPieceDropLogic ()
|
||||
{
|
||||
@@ -893,24 +847,24 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
bounceTimerExpired();
|
||||
}
|
||||
|
||||
// if we can't evolve the board because it doesn't need evolving
|
||||
// or things are going on, we stop here
|
||||
// if we can't evolve the board because it doesn't need evolving or things are going on,
|
||||
// we stop here
|
||||
if (_stable || !canEvolveBoard()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// if we do not evolve the board in any way, let the derived class
|
||||
// know that the board stabilized so that they can drop in a new
|
||||
// piece if they like or take whatever other action is appropriate
|
||||
// if we do not evolve the board in any way, let the derived class know that the board
|
||||
// stabilized so that they can drop in a new piece if they like or take whatever other
|
||||
// action is appropriate
|
||||
boolean evolving = evolveBoard();
|
||||
boolean debug = false;
|
||||
if (debug) {
|
||||
log.info("Evolved board [evolving=" + evolving + "].");
|
||||
log.info("Evolved board", "evolving", evolving);
|
||||
}
|
||||
|
||||
// if we're no longer evolving and the action has not ended, go
|
||||
// ahead and let our derived class know that the board has
|
||||
// stabilized so that it can drop in the next piece or somesuch
|
||||
// if we're no longer evolving and the action has not ended, go ahead and let our derived
|
||||
// class know that the board has stabilized so that it can drop in the next piece or
|
||||
// somesuch
|
||||
if (!evolving) {
|
||||
// no evolving again until someone destabilizes the board
|
||||
_stable = true;
|
||||
@@ -921,8 +875,8 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
}
|
||||
boardDidStabilize();
|
||||
|
||||
// ensure that if we have been postponing action due to board
|
||||
// evolution, that it will now be cleared
|
||||
// ensure that if we have been postponing action due to board evolution, that it will
|
||||
// now be cleared
|
||||
if (!_ctrl.hasAction()) {
|
||||
if (debug) {
|
||||
log.info("Maybe clearing action.");
|
||||
@@ -971,8 +925,7 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
{
|
||||
// don't overwrite an existing zip
|
||||
if (_zipstamp == 0) {
|
||||
// if we're paused, inherit the pause time, otherwise use the
|
||||
// current time
|
||||
// if we're paused, inherit the pause time, otherwise use the current time
|
||||
if (_rpstamp != 0) {
|
||||
_zipstamp = _rpstamp;
|
||||
} else {
|
||||
@@ -982,8 +935,8 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
}
|
||||
|
||||
/**
|
||||
* Called periodically on the frame tick. Raises the board row based
|
||||
* on the time since the current row traversal began.
|
||||
* Called periodically on the frame tick. Raises the board row based on the time since the
|
||||
* current row traversal began.
|
||||
*/
|
||||
/*
|
||||
protected void raiseBoard (long tickStamp)
|
||||
@@ -1040,10 +993,9 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
_dview.setRiseOffset(ypos);
|
||||
|
||||
if (rose) {
|
||||
// check to see if this means doom and defeat (even though the
|
||||
// game might be over, we still want to advance the piece
|
||||
// packet one last time and do the last rise so that the
|
||||
// server can tell that we kicked the proverbial bucket)
|
||||
// check to see if this means doom and defeat (even though the game might be over, we
|
||||
// still want to advance the piece packet one last time and do the last rise so that
|
||||
// the server can tell that we kicked the proverbial bucket)
|
||||
boolean canRise = checkCanRise();
|
||||
|
||||
// apply the rising row pieces to the board
|
||||
@@ -1062,23 +1014,21 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
unstabilizeBoard();
|
||||
|
||||
} else {
|
||||
log.debug("Sticking fork in it [risers=" +
|
||||
StringUtil.toString(pieces) + ".");
|
||||
log.debug("Sticking fork in it", "risers", pieces);
|
||||
|
||||
// let the controller know that we're done for
|
||||
_ctrl.resetGame();
|
||||
}
|
||||
}
|
||||
|
||||
// Log.info("Board rise [msecs=" + msecs + ", roff=" + ypos +
|
||||
// ", pctdone=" + pctdone + ", zipsecs=" + zipsecs + "].");
|
||||
// log.info("Board rise",
|
||||
// "msecs", msecs, "roff", ypos, "pctdone", pctdone, "zipsecs", zipsecs);
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
protected boolean checkCanRise ()
|
||||
{
|
||||
@@ -1086,10 +1036,9 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* <code>super.boardWillRise()</code>.
|
||||
* 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 <code>super.boardWillRise()</code>.
|
||||
*/
|
||||
protected void boardWillRise ()
|
||||
{
|
||||
@@ -1097,17 +1046,16 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* <code>super.boardDidRise()</code>.
|
||||
* 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 <code>super.boardDidRise()</code>.
|
||||
*/
|
||||
protected void boardDidRise ()
|
||||
{
|
||||
// nothing for now
|
||||
}
|
||||
|
||||
/** The yohoho context. */
|
||||
/** The puzzle context. */
|
||||
protected PuzzleContext _ctx;
|
||||
|
||||
/** Our puzzle controller. */
|
||||
@@ -1143,8 +1091,8 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
/** The drop block sprite associated with the landing block, if any. */
|
||||
protected DropBlockSprite _blocksprite;
|
||||
|
||||
/** The piece dropper used to drop pieces in the board if the puzzle
|
||||
* chooses to make use of piece dropping functionality. */
|
||||
/** The piece dropper used to drop pieces in the board if the puzzle chooses to make use of
|
||||
* piece dropping functionality. */
|
||||
protected PieceDropper _dropper;
|
||||
|
||||
/** The time at which the board rise was paused. */
|
||||
@@ -1168,8 +1116,8 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
/** The row at which we last bounced, or {@link Integer#MIN_VALUE}. */
|
||||
protected int _bounceRow;
|
||||
|
||||
/** The timestamp used to keep track of when the drop block was
|
||||
* removed so that we can fast-forward it when restored. */
|
||||
/** The timestamp used to keep track of when the drop block was removed so that we can
|
||||
* fast-forward it when restored. */
|
||||
protected long _blockStamp;
|
||||
|
||||
/** Whether the drop blocks are currently dropping quickly. */
|
||||
@@ -1191,8 +1139,7 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
}
|
||||
};
|
||||
|
||||
/** A piece operation that will update piece sprites as board
|
||||
* positions are updated. */
|
||||
/** A piece operation that will update piece sprites as board positions are updated. */
|
||||
protected DropBoard.PieceOperation _updateBoardOp =
|
||||
new DropBoard.PieceOperation() {
|
||||
public boolean execute (DropBoard board, int col, int row) {
|
||||
@@ -1210,7 +1157,6 @@ public abstract class DropControllerDelegate extends PuzzleControllerDelegate
|
||||
/** The delay in milliseconds between board rising intervals. */
|
||||
protected static final long RISE_INTERVAL = 50L;
|
||||
|
||||
/** Defines the distance of a piece that we allow to bounce before we
|
||||
* land it. */
|
||||
/** Defines the distance of a piece that we allow to bounce before we land it. */
|
||||
protected static final float BOUNCE_FRACTION = 0.125f;
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ package com.threerings.puzzle.drop.client;
|
||||
import com.threerings.puzzle.data.BoardSummary;
|
||||
|
||||
/**
|
||||
* Puzzles using the drop services need implement this interface to
|
||||
* display drop puzzle related information.
|
||||
* Puzzles using the drop services need implement this interface to display drop puzzle related
|
||||
* information.
|
||||
*/
|
||||
public interface DropPanel
|
||||
{
|
||||
|
||||
@@ -34,8 +34,8 @@ import com.threerings.media.image.Mirage;
|
||||
import com.threerings.media.sprite.Sprite;
|
||||
|
||||
/**
|
||||
* The drop sprite is a sprite that displays one or more pieces falling
|
||||
* toward the bottom of the board.
|
||||
* The drop sprite is a sprite that displays one or more pieces falling toward the bottom of the
|
||||
* board.
|
||||
*/
|
||||
public class DropSprite extends Sprite
|
||||
{
|
||||
@@ -48,8 +48,7 @@ public class DropSprite extends Sprite
|
||||
* @param pieces the pieces displayed by the sprite.
|
||||
* @param dist the distance the sprite is to drop in rows.
|
||||
*/
|
||||
public DropSprite (
|
||||
DropBoardView view, int col, int row, int[] pieces, int dist)
|
||||
public DropSprite (DropBoardView view, int col, int row, int[] pieces, int dist)
|
||||
{
|
||||
this(view, col, row, pieces, dist, -1);
|
||||
}
|
||||
@@ -65,8 +64,7 @@ public class DropSprite extends Sprite
|
||||
* @param renderOrder the render order.
|
||||
*/
|
||||
public DropSprite (
|
||||
DropBoardView view, int col, int row, int[] pieces, int dist,
|
||||
int renderOrder)
|
||||
DropBoardView view, int col, int row, int[] pieces, int dist, int renderOrder)
|
||||
{
|
||||
_view = view;
|
||||
_col = col;
|
||||
@@ -188,11 +186,9 @@ public class DropSprite extends Sprite
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the velocity of this sprite. The time at which the current
|
||||
* row was entered is modified so that the sprite position will remain
|
||||
* the same when calculated using the new velocity since the piece
|
||||
* sprite may have its velocity modified in the middle of a row
|
||||
* traversal.
|
||||
* Sets the velocity of this sprite. The time at which the current row was entered is modified
|
||||
* so that the sprite position will remain the same when calculated using the new velocity
|
||||
* since the piece sprite may have its velocity modified in the middle of a row traversal.
|
||||
*/
|
||||
public void setVelocity (float velocity)
|
||||
{
|
||||
@@ -235,15 +231,14 @@ public class DropSprite extends Sprite
|
||||
_stopstamp = 0;
|
||||
|
||||
} else {
|
||||
// we're continuing a previous drop, so make use of any
|
||||
// previously existing time
|
||||
// we're continuing a previous drop, so make use of any previously existing time
|
||||
_rowstamp = _endstamp;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this drop sprite is dropping, false if it has been
|
||||
* {@link #stop}ped or has not yet been {@link #drop}ped.
|
||||
* Returns true if this drop sprite is dropping, false if it has been {@link #stop}ped or has
|
||||
* not yet been {@link #drop}ped.
|
||||
*/
|
||||
public boolean isDropping ()
|
||||
{
|
||||
@@ -257,33 +252,29 @@ public class DropSprite extends Sprite
|
||||
{
|
||||
if (_stopstamp == 0) {
|
||||
_stopstamp = _view.getTimeStamp();
|
||||
// Log.info("Stopped piece [piece=" + this + "].");
|
||||
// log.info("Stopped piece", "piece", this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts the drop sprite into (or takes it out of) bouncing
|
||||
* mode. Bouncing mode is used to put the sprite into limbo after it
|
||||
* lands but before we commit the landing, giving the user a last
|
||||
* moment change move or rotate the piece. While the sprite is
|
||||
* "bouncing" it will be rendered one pixel below it's at rest state.
|
||||
* Puts the drop sprite into (or takes it out of) bouncing mode. Bouncing mode is used to put
|
||||
* the sprite into limbo after it lands but before we commit the landing, giving the user a
|
||||
* last moment change move or rotate the piece. While the sprite is "bouncing" it will be
|
||||
* rendered one pixel below it's at rest state.
|
||||
*/
|
||||
public void setBouncing (boolean bouncing)
|
||||
{
|
||||
_bouncing = bouncing;
|
||||
if (_bouncing) {
|
||||
// if we've activated bouncing, shift the sprite slightly to
|
||||
// illustrate its new state
|
||||
// if we've activated bouncing, shift the sprite slightly to illustrate its new state
|
||||
shiftForBounce();
|
||||
|
||||
// to prevent funny business in the event that we were a long
|
||||
// ways past the end of the row when we landed, we warp the
|
||||
// sprite back to the exact point of landing for the purposes
|
||||
// of the bounce and any subsequent antics
|
||||
// to prevent funny business in the event that we were a long ways past the end of the
|
||||
// row when we landed, we warp the sprite back to the exact point of landing for the
|
||||
// purposes of the bounce and any subsequent antics
|
||||
_endstamp = _rowstamp = _view.getTimeStamp();
|
||||
|
||||
// Log.info("Adjusted rowstap due to bounce " +
|
||||
// "[time=" + _endstamp + "].");
|
||||
// log.info("Adjusted rowstap due to bounce", "time", _endstamp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -296,8 +287,7 @@ public class DropSprite extends Sprite
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the sprite's location to illustrate that it is currently in
|
||||
* the "bouncing" state.
|
||||
* Updates the sprite's location to illustrate that it is currently in the "bouncing" state.
|
||||
*/
|
||||
protected void shiftForBounce ()
|
||||
{
|
||||
@@ -311,15 +301,13 @@ public class DropSprite extends Sprite
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a value between <code>0.0</code> and <code>1.0</code>
|
||||
* representing how far the piece has moved toward the next row
|
||||
* as of the given time stamp.
|
||||
* Returns a value between <code>0.0</code> and <code>1.0</code> representing how far the
|
||||
* piece has moved toward the next row as of the given time stamp.
|
||||
*/
|
||||
public float getPercentDone (long timestamp)
|
||||
{
|
||||
// if we've never been ticked and so haven't yet initialized our
|
||||
// row start timestamp, just let the caller know that we've not
|
||||
// traversed our row at all
|
||||
// if we've never been ticked and so haven't yet initialized our row start timestamp, just
|
||||
// let the caller know that we've not traversed our row at all
|
||||
if (_rowstamp == 0) {
|
||||
return 0.0f;
|
||||
}
|
||||
@@ -328,10 +316,9 @@ public class DropSprite extends Sprite
|
||||
float travpix = msecs * _vel;
|
||||
float pctdone = (travpix / _unit);
|
||||
|
||||
// Log.info("getPercentDone [timestamp=" + timestamp +
|
||||
// ", rowstamp=" + _rowstamp + ", msecs=" + msecs +
|
||||
// ", travpix=" + travpix + ", pctdone=" + pctdone +
|
||||
// ", vel=" + _vel + "].");
|
||||
// log.info("getPercentDone",
|
||||
// "timestamp", timestamp, "rowstamp", _rowstamp, "msecs", msecs, "travpix", travpix,
|
||||
// "pctdone", pctdone, "vel", _vel);
|
||||
|
||||
return pctdone;
|
||||
}
|
||||
@@ -352,8 +339,7 @@ public class DropSprite extends Sprite
|
||||
// ask the board for the render position of this piece
|
||||
_view.getPiecePosition(pcol, prow, _renderPos);
|
||||
// draw the piece image
|
||||
paintPieceImage(gfx, ii, pcol, prow, _orient,
|
||||
_renderPos.x + dx, _renderPos.y + dy);
|
||||
paintPieceImage(gfx, ii, pcol, prow, _orient, _renderPos.x + dx, _renderPos.y + dy);
|
||||
// increment the target column and row
|
||||
pcol += incx;
|
||||
prow += incy;
|
||||
@@ -363,8 +349,8 @@ public class DropSprite extends Sprite
|
||||
/**
|
||||
* Paints the specified piece with the supplied parameters.
|
||||
*/
|
||||
protected void paintPieceImage (Graphics2D gfx, int pieceidx,
|
||||
int col, int row, int orient, int x, int y)
|
||||
protected void paintPieceImage (
|
||||
Graphics2D gfx, int pieceidx, int col, int row, int orient, int x, int y)
|
||||
{
|
||||
Mirage image = _view.getPieceImage(_pieces[pieceidx], col, row, orient);
|
||||
image.paint(gfx, x, y);
|
||||
@@ -415,9 +401,8 @@ public class DropSprite extends Sprite
|
||||
int nx = _srcPos.x + (int)((_destPos.x - _srcPos.x) * pctdone);
|
||||
int ny = _srcPos.y + (int)((_destPos.y - _srcPos.y) * pctdone);
|
||||
|
||||
// Log.info("Drop sprite tick [dist=" + _dist + ", pctdone=" + pctdone +
|
||||
// ", row=" + _row + ", col=" + _col +
|
||||
// ", nx=" + nx + ", ny=" + ny + "].");
|
||||
// log.info("Drop sprite tick",
|
||||
// "dist", _dist, "pctdone", pctdone, "row", _row, "col", _col, "nx", nx, "ny", ny);
|
||||
|
||||
// only update the sprite's location if it actually moved
|
||||
if (_ox != nx || _oy != ny) {
|
||||
@@ -431,8 +416,8 @@ public class DropSprite extends Sprite
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the sprite has finished traversing its current row to
|
||||
* advance its board coordinates to the next row.
|
||||
* Called when the sprite has finished traversing its current row to advance its board
|
||||
* coordinates to the next row.
|
||||
*/
|
||||
protected void advancePosition ()
|
||||
{
|
||||
@@ -480,21 +465,18 @@ public class DropSprite extends Sprite
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the bounds for this sprite based on the sprite display
|
||||
* dimensions in the view.
|
||||
* Updates the bounds for this sprite based on the sprite display dimensions in the view.
|
||||
*/
|
||||
protected void updateBounds ()
|
||||
{
|
||||
Dimension size = _view.getPieceSegmentSize(
|
||||
_col, _row, _orient, _pieces.length);
|
||||
Dimension size = _view.getPieceSegmentSize(_col, _row, _orient, _pieces.length);
|
||||
_bounds.width = size.width;
|
||||
_bounds.height = size.height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjusts our render origin such that our location is not in the
|
||||
* upper left of the sprite's rendered image but is in fact offset by
|
||||
* some number of rows and columns.
|
||||
* Adjusts our render origin such that our location is not in the upper left of the sprite's
|
||||
* rendered image but is in fact offset by some number of rows and columns.
|
||||
*/
|
||||
protected void updateRenderOffset ()
|
||||
{
|
||||
@@ -505,19 +487,16 @@ public class DropSprite extends Sprite
|
||||
/** Used to dispatch {@link DropSpriteObserver#pieceMoved}. */
|
||||
protected static class PieceMovedOp implements ObserverList.ObserverOp<Object>
|
||||
{
|
||||
public PieceMovedOp (DropSprite sprite, long when, int col, int row)
|
||||
{
|
||||
public PieceMovedOp (DropSprite sprite, long when, int col, int row) {
|
||||
_sprite = sprite;
|
||||
_when = when;
|
||||
_col = col;
|
||||
_row = row;
|
||||
}
|
||||
|
||||
public boolean apply (Object observer)
|
||||
{
|
||||
public boolean apply (Object observer) {
|
||||
if (observer instanceof DropSpriteObserver) {
|
||||
((DropSpriteObserver)observer).pieceMoved(
|
||||
_sprite, _when, _col, _row);
|
||||
((DropSpriteObserver)observer).pieceMoved(_sprite, _when, _col, _row);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -545,16 +524,14 @@ public class DropSprite extends Sprite
|
||||
/** The unit distance the sprite moves to reach the next row. */
|
||||
protected int _unit;
|
||||
|
||||
/** The screen coordinates of the top-left of the row currently
|
||||
* occupied by the sprite. */
|
||||
/** The screen coordinates of the top-left of the row currently occupied by the sprite. */
|
||||
protected Point _srcPos = new Point();
|
||||
|
||||
/** The screen coordinates of the top-left of the row toward which the
|
||||
* sprite is falling. */
|
||||
/** The screen coordinates of the top-left of the row toward which the sprite is falling. */
|
||||
protected Point _destPos = new Point();
|
||||
|
||||
/** The piece render position; used as working data when determining
|
||||
* where to render each piece in the sprite. */
|
||||
/** The piece render position; used as working data when determining where to render each piece
|
||||
* in the sprite. */
|
||||
protected Point _renderPos = new Point();
|
||||
|
||||
/** The number of rows remaining to drop. */
|
||||
@@ -572,8 +549,7 @@ public class DropSprite extends Sprite
|
||||
/** The pieces this sprite is displaying. */
|
||||
protected int[] _pieces;
|
||||
|
||||
/** Indicates that the drop sprite is bouncing; see {@link
|
||||
* #setBouncing}. */
|
||||
/** Indicates that the drop sprite is bouncing; see {@link #setBouncing}. */
|
||||
protected boolean _bouncing;
|
||||
|
||||
// used to compute the column and row increment while rendering the
|
||||
|
||||
@@ -27,8 +27,7 @@ package com.threerings.puzzle.drop.client;
|
||||
public interface DropSpriteObserver
|
||||
{
|
||||
/**
|
||||
* Called when the drop sprite has moved completely to the specified
|
||||
* board coordinates.
|
||||
* Called when the drop sprite has moved completely to the specified board coordinates.
|
||||
*/
|
||||
public void pieceMoved (DropSprite sprite, long when, int col, int row);
|
||||
}
|
||||
|
||||
@@ -32,8 +32,7 @@ import com.threerings.util.DirectionCodes;
|
||||
import com.threerings.media.image.Mirage;
|
||||
|
||||
/**
|
||||
* The next block view displays an image representing the next drop block
|
||||
* to appear in the game.
|
||||
* The next block view displays an image representing the next drop block to appear in the game.
|
||||
*/
|
||||
public class NextBlockView extends JComponent
|
||||
implements DirectionCodes
|
||||
@@ -74,8 +73,8 @@ public class NextBlockView extends JComponent
|
||||
int xpos = (_orient == VERTICAL) ? 0 : (size.width - _pwid);
|
||||
int ypos = (_orient == VERTICAL) ? (size.height - _phei) : 0;
|
||||
|
||||
for (int ii = 0; ii < _pieces.length; ii++) {
|
||||
Mirage image = _view.getPieceImage(_pieces[ii]);
|
||||
for (int _piece : _pieces) {
|
||||
Mirage image = _view.getPieceImage(_piece);
|
||||
image.paint(gfx, xpos, ypos);
|
||||
if (_orient == VERTICAL) {
|
||||
ypos -= _phei;
|
||||
@@ -103,7 +102,6 @@ public class NextBlockView extends JComponent
|
||||
/** The piece dimensions in pixels. */
|
||||
protected int _pwid, _phei;
|
||||
|
||||
/** The view orientation; one of {@link #HORIZONTAL} or {@link
|
||||
* #VERTICAL}. */
|
||||
/** The view orientation; one of {@link #HORIZONTAL} or {@link #VERTICAL}. */
|
||||
protected int _orient;
|
||||
}
|
||||
|
||||
@@ -34,8 +34,8 @@ import com.threerings.media.util.Path;
|
||||
import com.threerings.puzzle.drop.data.DropBoard;
|
||||
|
||||
/**
|
||||
* Animates all the pieces on a puzzle board doing some sort of global
|
||||
* effect like all flying into place or out into the ether.
|
||||
* Animates all the pieces on a puzzle board doing some sort of global effect like all flying into
|
||||
* place or out into the ether.
|
||||
*/
|
||||
public abstract class PieceGroupAnimation extends Animation
|
||||
implements PathObserver
|
||||
@@ -80,8 +80,7 @@ public abstract class PieceGroupAnimation extends Animation
|
||||
{
|
||||
super.willStart(tickStamp);
|
||||
|
||||
// create an image sprite for every piece on the board and set
|
||||
// them on their paths
|
||||
// create an image sprite for every piece on the board and set them on their paths
|
||||
int width = _board.getWidth(), height = _board.getHeight();
|
||||
_sprites = new Sprite[width * height];
|
||||
for (int yy = 0; yy < height; yy++) {
|
||||
@@ -98,9 +97,8 @@ public abstract class PieceGroupAnimation extends Animation
|
||||
}
|
||||
|
||||
/**
|
||||
* An animation must override this method to configure each sprite
|
||||
* with a path, potentially a render order, and whatever other
|
||||
* configurations are needed.
|
||||
* An animation must override this method to configure each sprite with a path, potentially a
|
||||
* render order, and whatever other configurations are needed.
|
||||
*/
|
||||
protected abstract void configureSprite (Sprite sprite, int xx, int yy);
|
||||
|
||||
|
||||
@@ -257,8 +257,7 @@ public class DropBoard extends Board
|
||||
{
|
||||
int px = cols[0], py = rows[0];
|
||||
|
||||
// Log.info("Starting rotation [px=" + px + ", py=" + py +
|
||||
// ", orient=" + orient + ", pctdone=" + pctdone + "].");
|
||||
// log.info("Starting rotation", "px", px, "py", py, "orient", orient, "pctdone", pctdone);
|
||||
|
||||
// try rotating the block in the given direction through all four possible orientations
|
||||
for (int ii = 0; ii < 4; ii++) {
|
||||
@@ -285,16 +284,12 @@ public class DropBoard extends Board
|
||||
}
|
||||
|
||||
// try each of three coercions: nothing, one left, one right
|
||||
for (int c = 0; c < COERCE_DX.length; c++) {
|
||||
int cx = COERCE_DX[c];
|
||||
for (int cx : COERCE_DX) {
|
||||
// check if our hypothetical new coordinates are empty
|
||||
if (isBlockEmpty(ox + cx, oy, ORIENT_WIDTHS[oidx], ORIENT_HEIGHTS[oidx])) {
|
||||
// Log.info(
|
||||
// "Block is empty [ox=" + ox + ", cx=" + cx +
|
||||
// ", oy=" + oy + ", oidx=" + oidx +
|
||||
// ", orient=" + DirectionUtil.toShortString(orient) +
|
||||
// ", owid=" + ORIENT_WIDTHS[oidx] +
|
||||
// ", ohei=" + ORIENT_HEIGHTS[oidx] + "].");
|
||||
// log.info("Block is empty", "ox", ox + "cx", cx, "oy", oy, "oidx", oidx,
|
||||
// "orient", DirectionUtil.toShortString(orient), "owid", ORIENT_WIDTHS[oidx],
|
||||
// "ohei", ORIENT_HEIGHTS[oidx]);
|
||||
return new int[] { orient, px + cx, py, 0 };
|
||||
}
|
||||
}
|
||||
@@ -304,13 +299,10 @@ public class DropBoard extends Board
|
||||
if (canPopup && rtype == RADIAL_ROTATION && orient == SOUTH) {
|
||||
// check if our hypothetical new coordinates are empty
|
||||
if (isBlockEmpty(ox, oy - 1, ORIENT_WIDTHS[oidx], ORIENT_HEIGHTS[oidx])) {
|
||||
// Log.info(
|
||||
// "Popped-up block is empty [ox=" + ox +
|
||||
// ", oy=" + (oy - 1) + ", oidx=" + oidx +
|
||||
// ", orient=" + DirectionUtil.toShortString(orient) +
|
||||
// ", owid=" + ORIENT_WIDTHS[oidx] +
|
||||
// ", ohei=" + ORIENT_HEIGHTS[oidx] +
|
||||
// ", bhei=" + _bhei + "].");
|
||||
// log.info("Popped-up block is empty",
|
||||
// "ox", ox, "oy", (oy - 1), "oidx", oidx,
|
||||
// "orient", DirectionUtil.toShortString(orient), "owid", ORIENT_WIDTHS[oidx],
|
||||
// "ohei", ORIENT_HEIGHTS[oidx], "bhei", _bhei);
|
||||
return new int[] { orient, px, py - 1, 1 };
|
||||
}
|
||||
}
|
||||
@@ -325,8 +317,9 @@ public class DropBoard extends Board
|
||||
|
||||
/**
|
||||
* Returns a {@link Point} object containing the coordinates to place the bottom-left of the
|
||||
* given block at after moving it the given distance on the x- and y-axes, or <code>null</code>
|
||||
* if the move is not valid. Note that only the final block position is checked.
|
||||
* given block at after moving it the given distance on the x- and y-axes, or
|
||||
* <code>null</code> if the move is not valid. Note that only the final block position is
|
||||
* checked.
|
||||
*
|
||||
* @param col the leftmost column of the block.
|
||||
* @param row the bottommost row of the block.
|
||||
@@ -424,8 +417,8 @@ public class DropBoard extends Board
|
||||
return true;
|
||||
|
||||
} else {
|
||||
log.warning("Attempt to set piece outside board bounds " +
|
||||
"[col=" + col + ", row=" + row + ", p=" + piece + "].");
|
||||
log.warning("Attempt to set piece outside board bounds",
|
||||
"col", col, "row", row, "p", piece);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -451,8 +444,8 @@ public class DropBoard extends Board
|
||||
* @param len the length of the segment in pieces.
|
||||
* @param piece the piece to set in the segment.
|
||||
*
|
||||
* @return false if the segment was only partially applied because some pieces were outside the
|
||||
* bounds of the board, true if it was completely applied.
|
||||
* @return false if the segment was only partially applied because some pieces were outside
|
||||
* the bounds of the board, true if it was completely applied.
|
||||
*/
|
||||
public boolean setSegment (int dir, int col, int row, int len, int piece)
|
||||
{
|
||||
@@ -492,8 +485,8 @@ public class DropBoard extends Board
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies a specified {@link PieceOperation} to all pieces in a row or column segment starting
|
||||
* at the specified coordinates and of the specified length in the board.
|
||||
* Applies a specified {@link PieceOperation} to all pieces in a row or column segment
|
||||
* starting at the specified coordinates and of the specified length in the board.
|
||||
*
|
||||
* @param dir the direction to iterate in; one of {@link #HORIZONTAL} or {@link #VERTICAL}.
|
||||
* @param col the starting leftmost column of the segment.
|
||||
@@ -685,8 +678,8 @@ public class DropBoard extends Board
|
||||
{
|
||||
int size = (_bwid*_bhei);
|
||||
if (board.length < size) {
|
||||
log.warning("Attempt to set board with invalid data size " +
|
||||
"[len=" + board.length + ", expected=" + size + "].");
|
||||
log.warning("Attempt to set board with invalid data size",
|
||||
"len", board.length, "expected", size);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -724,16 +717,14 @@ public class DropBoard extends Board
|
||||
/**
|
||||
* Sets the array of pieces to be placed in the board segment.
|
||||
*/
|
||||
public void init (int dir, int[] pieces)
|
||||
{
|
||||
public void init (int dir, int[] pieces) {
|
||||
_dir = dir;
|
||||
_pieces = pieces;
|
||||
_idx = (dir == HORIZONTAL) ? _pieces.length - 1 : 0;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public boolean execute (DropBoard board, int col, int row)
|
||||
{
|
||||
public boolean execute (DropBoard board, int col, int row) {
|
||||
if (_dir == HORIZONTAL) {
|
||||
board.setPiece(col, row, _pieces[_idx--]);
|
||||
} else {
|
||||
@@ -758,8 +749,7 @@ public class DropBoard extends Board
|
||||
/**
|
||||
* Sets the piece to be placed in the board segment.
|
||||
*/
|
||||
public void init (int piece)
|
||||
{
|
||||
public void init (int piece) {
|
||||
_piece = piece;
|
||||
_error = false;
|
||||
}
|
||||
@@ -768,14 +758,12 @@ public class DropBoard extends Board
|
||||
* Returns true if we attempted to set a piece outside the bounds of the board during the
|
||||
* course of our operation.
|
||||
*/
|
||||
public boolean getError ()
|
||||
{
|
||||
public boolean getError () {
|
||||
return _error;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public boolean execute (DropBoard board, int col, int row)
|
||||
{
|
||||
public boolean execute (DropBoard board, int col, int row) {
|
||||
if (!board.setPiece(col, row, _piece)) {
|
||||
_error = true;
|
||||
}
|
||||
|
||||
@@ -41,8 +41,8 @@ public class DropBoardSummary extends BoardSummary
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a drop board summary that retrieves board information
|
||||
* from the supplied board when summarizing.
|
||||
* Constructs a drop board summary that retrieves board information from the supplied board
|
||||
* when summarizing.
|
||||
*/
|
||||
public DropBoardSummary (Board board)
|
||||
{
|
||||
@@ -50,8 +50,8 @@ public class DropBoardSummary extends BoardSummary
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the column number of the column within the given column
|
||||
* range that contains the most pieces.
|
||||
* Returns the column number of the column within the given column range that contains the
|
||||
* most pieces.
|
||||
*/
|
||||
public int getHighestColumn (int startx, int endx)
|
||||
{
|
||||
|
||||
@@ -22,8 +22,7 @@
|
||||
package com.threerings.puzzle.drop.data;
|
||||
|
||||
/**
|
||||
* Provides access to the configuration information for a drop puzzle
|
||||
* game.
|
||||
* Provides access to the configuration information for a drop puzzle game.
|
||||
*/
|
||||
public interface DropConfig
|
||||
{
|
||||
|
||||
@@ -22,20 +22,18 @@
|
||||
package com.threerings.puzzle.drop.data;
|
||||
|
||||
/**
|
||||
* Describes the features and configuration desired for a given drop
|
||||
* puzzle game.
|
||||
* Describes the features and configuration desired for a given drop puzzle game.
|
||||
*/
|
||||
public interface DropLogic
|
||||
{
|
||||
/**
|
||||
* Returns whether the puzzle game would like to make use of the
|
||||
* manipulable block dropping functionality.
|
||||
* Returns whether the puzzle game would like to make use of the manipulable block dropping
|
||||
* functionality.
|
||||
*/
|
||||
public boolean useBlockDropping ();
|
||||
|
||||
/**
|
||||
* Returns whether the puzzle game would like to make use of the
|
||||
* rising board functionality.
|
||||
* Returns whether the puzzle game would like to make use of the rising board functionality.
|
||||
*/
|
||||
public boolean useBoardRising ();
|
||||
}
|
||||
|
||||
@@ -24,8 +24,7 @@ package com.threerings.puzzle.drop.data;
|
||||
import com.threerings.util.DirectionCodes;
|
||||
|
||||
/**
|
||||
* The drop piece codes interface contains constants common to the drop
|
||||
* game package.
|
||||
* The drop piece codes interface contains constants common to the drop game package.
|
||||
*/
|
||||
public interface DropPieceCodes extends DirectionCodes
|
||||
{
|
||||
|
||||
@@ -39,25 +39,21 @@ import com.threerings.puzzle.server.PuzzleManagerDelegate;
|
||||
import static com.threerings.puzzle.Log.log;
|
||||
|
||||
/**
|
||||
* Provides the necessary support for a puzzle game that involves 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, groups of blocks can be "broken" and garbage
|
||||
* can be sent to other players' boards as a result. This is implemented
|
||||
* as a delegate so that the natural hierarchy need not be twisted to
|
||||
* differentiate between puzzles that use piece dropping and those that
|
||||
* don't. Because we have need to structure our hierarchy around things
|
||||
* like whether a puzzle is a duty puzzle, this becomes necessary.
|
||||
* Provides the necessary support for a puzzle game that involves 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, groups of blocks can be "broken" and garbage
|
||||
* can be sent to other players' boards as a result. This is implemented as a delegate so that the
|
||||
* natural hierarchy need not be twisted to differentiate between puzzles that use piece dropping
|
||||
* and those that don't. Because we have need to structure our hierarchy around things like
|
||||
* whether a puzzle is a duty puzzle, this becomes necessary.
|
||||
*
|
||||
* <p> A puzzle game using these services will then need to extend this
|
||||
* delegate, implementing the necessary methods to customize it for the
|
||||
* particulars of their game and then register it with their game manager
|
||||
* via {@link PlaceManager#addDelegate}.
|
||||
* <p> A puzzle game using these services will then need to extend this delegate, implementing the
|
||||
* necessary methods to customize it for the particulars of their game and then register it with
|
||||
* their game manager via {@link PlaceManager#addDelegate}.
|
||||
*
|
||||
* <p> It also keeps track of, for each player, board level information,
|
||||
* and player game status. Miscellaneous utility routines are provided
|
||||
* for checking things like whether the game is over, whether a player is
|
||||
* still active in the game, and so forth.
|
||||
* <p> It also keeps track of, for each player, board level information, and player game status.
|
||||
* Miscellaneous utility routines are provided for checking things like whether the game is over,
|
||||
* whether a player is still active in the game, and so forth.
|
||||
*
|
||||
* <p> Derived classes are likely to want to override {@link #getPieceDropLogic}.
|
||||
*/
|
||||
@@ -82,9 +78,8 @@ public abstract class DropManagerDelegate extends PuzzleManagerDelegate
|
||||
_usedrop = logic.useBlockDropping();
|
||||
_userise = logic.useBoardRising();
|
||||
if (_usedrop && _userise) {
|
||||
log.warning("Can't use dropping blocks and board rising "+
|
||||
"functionality simultaneously in a drop puzzle game! " +
|
||||
"Falling back to straight dropping.");
|
||||
log.warning("Can't use dropping blocks and board rising functionality simultaneously " +
|
||||
"in a drop puzzle game! Falling back to straight dropping.");
|
||||
_userise = false;
|
||||
}
|
||||
}
|
||||
@@ -129,8 +124,8 @@ public abstract class DropManagerDelegate extends PuzzleManagerDelegate
|
||||
}
|
||||
|
||||
/**
|
||||
* Drops any pieces that need dropping on the given player's board and
|
||||
* returns whether any pieces were dropped.
|
||||
* Drops any pieces that need dropping on the given player's board and returns whether any
|
||||
* pieces were dropped.
|
||||
*/
|
||||
protected boolean dropPieces (DropBoard board)
|
||||
{
|
||||
@@ -153,10 +148,9 @@ public abstract class DropManagerDelegate extends PuzzleManagerDelegate
|
||||
return new PieceDropper(logic);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method should be called by derived classes whenever the player
|
||||
* successfully places a drop block.
|
||||
* This method should be called by derived classes whenever the player successfully places a
|
||||
* drop block.
|
||||
*/
|
||||
protected void placedBlock (int pidx)
|
||||
{
|
||||
@@ -177,11 +171,11 @@ public abstract class DropManagerDelegate extends PuzzleManagerDelegate
|
||||
/** The board dimensions in pieces. */
|
||||
protected int _bwid, _bhei;
|
||||
|
||||
/** The piece dropper used to drop pieces in the board if the puzzle
|
||||
* chooses to make use of piece dropping functionality. */
|
||||
/** The piece dropper used to drop pieces in the board if the puzzle chooses to make use of
|
||||
* piece dropping functionality. */
|
||||
protected PieceDropper _dropper;
|
||||
|
||||
/** Used to limit the maximum number of board update loops permitted
|
||||
* before assuming something's gone horribly awry and aborting. */
|
||||
/** Used to limit the maximum number of board update loops permitted before assuming something's
|
||||
* gone horribly awry and aborting. */
|
||||
protected static final int MAX_UPDATE_LOOPS = 100;
|
||||
}
|
||||
|
||||
@@ -27,12 +27,11 @@ public class DropBoardUtil
|
||||
implements DirectionCodes
|
||||
{
|
||||
/**
|
||||
* Returns the orientation resulting from rotating the block in the
|
||||
* given direction the specified number of times.
|
||||
* Returns the orientation resulting from rotating the block in the given direction the
|
||||
* specified number of times.
|
||||
*
|
||||
* @param orient the current orientation.
|
||||
* @param dir the direction to rotate in; one of <code>CW</code> or
|
||||
* <code>CCW</code>.
|
||||
* @param dir the direction to rotate in; one of <code>CW</code> or <code>CCW</code>.
|
||||
* @param count the number of rotations to perform.
|
||||
*
|
||||
* @return the rotated orientation.
|
||||
@@ -46,12 +45,10 @@ public class DropBoardUtil
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the orientation resulting from rotating the block in
|
||||
* the given direction.
|
||||
* Returns the orientation resulting from rotating the block in the given direction.
|
||||
*
|
||||
* @param orient the current orientation.
|
||||
* @param dir the direction to rotate in; one of <code>CW</code> or
|
||||
* <code>CCW</code>.
|
||||
* @param dir the direction to rotate in; one of <code>CW</code> or <code>CCW</code>.
|
||||
*
|
||||
* @return the rotated orientation.
|
||||
*/
|
||||
|
||||
@@ -34,8 +34,7 @@ import com.threerings.puzzle.util.PuzzleGameUtil;
|
||||
public class DropGameUtil
|
||||
{
|
||||
/**
|
||||
* Returns a key translator configured with mappings suitable for a
|
||||
* drop puzzle game.
|
||||
* Returns a key translator configured with mappings suitable for a drop puzzle game.
|
||||
*/
|
||||
public static KeyTranslatorImpl getKeyTranslator ()
|
||||
{
|
||||
@@ -44,21 +43,15 @@ public class DropGameUtil
|
||||
|
||||
// add all press key mappings
|
||||
xlate.addPressCommand(KeyEvent.VK_LEFT,
|
||||
DropControllerDelegate.MOVE_BLOCK_LEFT,
|
||||
MOVE_RATE, MOVE_DELAY);
|
||||
DropControllerDelegate.MOVE_BLOCK_LEFT, MOVE_RATE, MOVE_DELAY);
|
||||
xlate.addPressCommand(KeyEvent.VK_RIGHT,
|
||||
DropControllerDelegate.MOVE_BLOCK_RIGHT,
|
||||
MOVE_RATE, MOVE_DELAY);
|
||||
xlate.addPressCommand(KeyEvent.VK_UP,
|
||||
DropControllerDelegate.ROTATE_BLOCK_CCW, 0);
|
||||
xlate.addPressCommand(KeyEvent.VK_DOWN,
|
||||
DropControllerDelegate.ROTATE_BLOCK_CW, 0);
|
||||
xlate.addPressCommand(KeyEvent.VK_SPACE,
|
||||
DropControllerDelegate.START_DROP_BLOCK, 0);
|
||||
DropControllerDelegate.MOVE_BLOCK_RIGHT, MOVE_RATE, MOVE_DELAY);
|
||||
xlate.addPressCommand(KeyEvent.VK_UP, DropControllerDelegate.ROTATE_BLOCK_CCW, 0);
|
||||
xlate.addPressCommand(KeyEvent.VK_DOWN, DropControllerDelegate.ROTATE_BLOCK_CW, 0);
|
||||
xlate.addPressCommand(KeyEvent.VK_SPACE, DropControllerDelegate.START_DROP_BLOCK, 0);
|
||||
|
||||
// add all release key mappings
|
||||
xlate.addReleaseCommand(KeyEvent.VK_SPACE,
|
||||
DropControllerDelegate.END_DROP_BLOCK);
|
||||
xlate.addReleaseCommand(KeyEvent.VK_SPACE, DropControllerDelegate.END_DROP_BLOCK);
|
||||
|
||||
return xlate;
|
||||
}
|
||||
|
||||
@@ -37,29 +37,26 @@ public class PieceDestroyer
|
||||
implements DropPieceCodes
|
||||
{
|
||||
/**
|
||||
* An interface to be implemented by specific puzzles to detail the
|
||||
* parameters and methodology by which pieces are destroyed in the
|
||||
* puzzle board.
|
||||
* An interface to be implemented by specific puzzles to detail the parameters and methodology
|
||||
* by which pieces are destroyed in the puzzle board.
|
||||
*/
|
||||
public interface DestroyLogic
|
||||
{
|
||||
/**
|
||||
* Returns the minimum length of a contiguously piece segment that
|
||||
* should be destroyed.
|
||||
* Returns the minimum length of a contiguously piece segment that should be destroyed.
|
||||
*/
|
||||
public int getMinimumLength ();
|
||||
|
||||
/**
|
||||
* Returns whether piece <code>a</code> is equivalent to piece
|
||||
* <code>b</code> for the purposes of including it in a contiguous
|
||||
* piece segment to be destroyed.
|
||||
* Returns whether piece <code>a</code> is equivalent to piece <code>b</code> for the
|
||||
* purposes of including it in a contiguous piece segment to be destroyed.
|
||||
*/
|
||||
public boolean isEquivalent (int a, int b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a piece destroyer that destroys pieces as specified by
|
||||
* the supplied destroy logic.
|
||||
* Constructs a piece destroyer that destroys pieces as specified by the supplied destroy
|
||||
* logic.
|
||||
*/
|
||||
public PieceDestroyer (DestroyLogic logic)
|
||||
{
|
||||
@@ -67,13 +64,11 @@ public class PieceDestroyer
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys all pieces in the given board that are in contiguous rows
|
||||
* or columns of pieces, returning a list of {@link SegmentInfo}
|
||||
* objects detailing the destroyed piece segments. Note that a single
|
||||
* list is used internally to gather the segment info, and so callers
|
||||
* that care to modify the list should create their own copy; also,
|
||||
* the pieces in the segments may overlap, i.e., two segments may
|
||||
* contain the same piece.
|
||||
* Destroys all pieces in the given board that are in contiguous rows or columns of pieces,
|
||||
* returning a list of {@link SegmentInfo} objects detailing the destroyed piece segments.
|
||||
* Note that a single list is used internally to gather the segment info, and so callers that
|
||||
* care to modify the list should create their own copy; also, the pieces in the segments may
|
||||
* overlap, i.e., two segments may contain the same piece.
|
||||
*/
|
||||
public List<SegmentInfo> destroyPieces (DropBoard board, PieceOperation destroyOp)
|
||||
{
|
||||
@@ -108,9 +103,8 @@ public class PieceDestroyer
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for a contiguously colored piece segment with the
|
||||
* specified orientation and root coordinates in the supplied board
|
||||
* and returns the length of the segment traversed.
|
||||
* Searches for a contiguously colored piece segment with the specified orientation and root
|
||||
* coordinates in the supplied board and returns the length of the segment traversed.
|
||||
*/
|
||||
protected int findSegment (DropBoard board, int dir, int x, int y)
|
||||
{
|
||||
@@ -124,8 +118,8 @@ public class PieceDestroyer
|
||||
}
|
||||
|
||||
/**
|
||||
* A piece operation that calculates the length of the contiguous
|
||||
* piece segment to which it is applied.
|
||||
* A piece operation that calculates the length of the contiguous piece segment to which it is
|
||||
* applied.
|
||||
*/
|
||||
protected class SegmentLengthOperation
|
||||
implements PieceOperation
|
||||
@@ -133,22 +127,19 @@ public class PieceDestroyer
|
||||
/**
|
||||
* Resets the operation for application to a new piece segment.
|
||||
*/
|
||||
public void reset ()
|
||||
{
|
||||
public void reset () {
|
||||
_len = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the length of the contiguous piece segment.
|
||||
*/
|
||||
public int getLength ()
|
||||
{
|
||||
public int getLength () {
|
||||
return _len;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public boolean execute (DropBoard board, int col, int row)
|
||||
{
|
||||
public boolean execute (DropBoard board, int col, int row) {
|
||||
int piece = board.getPiece(col, row);
|
||||
if (_len == 0) {
|
||||
_len = 1;
|
||||
|
||||
@@ -26,8 +26,8 @@ import com.threerings.util.DirectionCodes;
|
||||
import com.threerings.puzzle.drop.data.DropBoard;
|
||||
|
||||
/**
|
||||
* An interface to be implemented by games that would like to be able to
|
||||
* drop their pieces during game play.
|
||||
* An interface to be implemented by games that would like to be able to drop their pieces during
|
||||
* game play.
|
||||
*/
|
||||
public interface PieceDropLogic
|
||||
{
|
||||
@@ -49,28 +49,28 @@ public interface PieceDropLogic
|
||||
public boolean isConstrainedPiece (int piece);
|
||||
|
||||
/**
|
||||
* Returns whether the given piece terminates a column climb when
|
||||
* determining the height of a piece column to be dropped.
|
||||
* Returns whether the given piece terminates a column climb when determining the height of a
|
||||
* piece column to be dropped.
|
||||
*
|
||||
* @param allowConst whether to allow dropping constrained pieces
|
||||
* (though only in the first encountered constrained block.)
|
||||
* @param allowConst whether to allow dropping constrained pieces (though only in the first
|
||||
* encountered constrained block.)
|
||||
* @param piece the piece to consider.
|
||||
* @param pre whether the climbability check is being performed
|
||||
* before the height is incremented, or after.
|
||||
* @param pre whether the climbability check is being performed before the height is
|
||||
* incremented, or after.
|
||||
*/
|
||||
public boolean isClimbablePiece (boolean allowConst, int piece, boolean pre);
|
||||
|
||||
/**
|
||||
* Returns the x-axis coordinate of the specified edge of the given constrained piece.
|
||||
*
|
||||
* <p> TODO: This should go away once the sword and sail games have standardized on
|
||||
* WEST/EAST or BLOCK_LEFT/BLOCK_RIGHT to reference block edges.
|
||||
* <p> TODO: This should go away once the sword and sail games have standardized on WEST/EAST
|
||||
* or BLOCK_LEFT/BLOCK_RIGHT to reference block edges.
|
||||
*
|
||||
* @param board the board to search.
|
||||
* @param col the column of the constrained piece.
|
||||
* @param row the row of the constrained piece.
|
||||
* @param dir the edge direction to find; one of {@link
|
||||
* DirectionCodes#LEFT} or {@link DirectionCodes#RIGHT}.
|
||||
* @param dir the edge direction to find; one of {@link DirectionCodes#LEFT} or
|
||||
* {@link DirectionCodes#RIGHT}.
|
||||
*/
|
||||
public int getConstrainedEdge (DropBoard board, int col, int row, int dir);
|
||||
}
|
||||
|
||||
@@ -54,16 +54,14 @@ public class PieceDropper
|
||||
/**
|
||||
* Constructs a piece drop info object.
|
||||
*/
|
||||
public PieceDropInfo (int col, int row, int dist)
|
||||
{
|
||||
public PieceDropInfo (int col, int row, int dist) {
|
||||
this.col = col;
|
||||
this.row = row;
|
||||
this.dist = dist;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString ()
|
||||
{
|
||||
public String toString () {
|
||||
return StringUtil.fieldsToString(this);
|
||||
}
|
||||
}
|
||||
@@ -78,8 +76,8 @@ public class PieceDropper
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a piece dropper that uses the supplied piece drop logic
|
||||
* to specialise itself for a particular puzzle.
|
||||
* Constructs a piece dropper that uses the supplied piece drop logic to specialize itself for
|
||||
* a particular puzzle.
|
||||
*/
|
||||
public PieceDropper (PieceDropLogic logic)
|
||||
{
|
||||
@@ -87,8 +85,8 @@ public class PieceDropper
|
||||
}
|
||||
|
||||
/**
|
||||
* Effects any drops possible on the supplied board (modifying the
|
||||
* board in the progress) and notifying the supplied drop observer of those drops.
|
||||
* Effects any drops possible on the supplied board (modifying the board in the progress) and
|
||||
* notifying the supplied drop observer of those drops.
|
||||
*
|
||||
* @return the number of pieces dropped.
|
||||
*/
|
||||
@@ -135,8 +133,8 @@ public class PieceDropper
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes and effects the drop for the specified piece and any
|
||||
* associated attached pieces. The supplied observer is notified of all drops.
|
||||
* Computes and effects the drop for the specified piece and any associated attached pieces.
|
||||
* The supplied observer is notified of all drops.
|
||||
*/
|
||||
protected int dropPieces (DropBoard board, int xx, int yy, DropObserver drobs)
|
||||
{
|
||||
@@ -153,8 +151,8 @@ public class PieceDropper
|
||||
int end = _logic.getConstrainedEdge(board, xx, yy, RIGHT);
|
||||
int bwid = board.getWidth();
|
||||
if (start < 0 || end >= bwid) {
|
||||
log.warning("Board reported bogus constrained edge " +
|
||||
"[x=" + xx + ", y=" + yy + ", start=" + start + ", end=" + end + "].");
|
||||
log.warning("Board reported bogus constrained edge",
|
||||
"x", xx, "y", yy, "start", start, "end", end);
|
||||
board.dump();
|
||||
start = Math.max(start, 0);
|
||||
end = Math.min(end, bwid);
|
||||
@@ -169,8 +167,7 @@ public class PieceDropper
|
||||
return 0;
|
||||
}
|
||||
|
||||
// scoot along the bottom edge of the block, noting the drop
|
||||
// for each column
|
||||
// scoot along the bottom edge of the block, noting the drop for each column
|
||||
for (int xpos = start; xpos <= end; xpos++) {
|
||||
piece = board.getPiece(xpos, yy);
|
||||
drop(board, piece, xpos, yy, yy + dist, drobs);
|
||||
@@ -191,8 +188,8 @@ public class PieceDropper
|
||||
}
|
||||
|
||||
/** Helpy helper function. */
|
||||
protected final void drop (DropBoard board, int piece,
|
||||
int xx, int yy, int ty, DropObserver drobs)
|
||||
protected final void drop (
|
||||
DropBoard board, int piece, int xx, int yy, int ty, DropObserver drobs)
|
||||
{
|
||||
// don't try to clear things out if we're filling in from off-board
|
||||
if (yy >= 0) {
|
||||
|
||||
@@ -57,13 +57,12 @@ public abstract class PuzzleManager extends GameManager
|
||||
*/
|
||||
public BoardSummary getBoardSummary (int pidx)
|
||||
{
|
||||
return (_puzobj == null || _puzobj.summaries == null) ? null :
|
||||
_puzobj.summaries[pidx];
|
||||
return (_puzobj == null || _puzobj.summaries == null) ? null : _puzobj.summaries[pidx];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this puzzle cares to make use of per-player board summaries that are sent
|
||||
* periodically to all users in the puzzle via {@link #sendStatusUpdate}. The default
|
||||
* periodically to all users in the puzzle via {@link #sendStatusUpdate}. The default
|
||||
* implementation returns <code>false</code>.
|
||||
*/
|
||||
public boolean needsBoardSummaries ()
|
||||
@@ -81,7 +80,7 @@ public abstract class PuzzleManager extends GameManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the server and client states being out of sync when in debug mode. The default
|
||||
* Handles the server and client states being out of sync when in debug mode. The default
|
||||
* implementation halts the server.
|
||||
*/
|
||||
protected void handleBoardNotEqual ()
|
||||
@@ -104,7 +103,7 @@ public abstract class PuzzleManager extends GameManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies updateBoardSummary on all the players' boards. AI board summaries should be updated
|
||||
* Applies updateBoardSummary on all the players' boards. AI board summaries should be updated
|
||||
* by the AI logic.
|
||||
*/
|
||||
public void updateBoardSummaries ()
|
||||
@@ -207,9 +206,10 @@ public abstract class PuzzleManager extends GameManager
|
||||
|
||||
/**
|
||||
* Returns the frequency with which puzzle status updates are broadcast to the players (which
|
||||
* is accomplished via a call to {@link #sendStatusUpdate} which in turn calls {@link
|
||||
* #updateStatus} wherein derived classes can participate in the status update). Returning
|
||||
* <code>O</code> (the default) indicates that a periodic status update is not desired.
|
||||
* is accomplished via a call to {@link #sendStatusUpdate} which in turn calls
|
||||
* {@link #updateStatus} wherein derived classes can participate in the status update).
|
||||
* Returning <code>O</code> (the default) indicates that a periodic status update is not
|
||||
* desired.
|
||||
*/
|
||||
protected long getStatusInterval ()
|
||||
{
|
||||
@@ -246,7 +246,7 @@ public abstract class PuzzleManager extends GameManager
|
||||
{
|
||||
_puzobj.startTransaction();
|
||||
try {
|
||||
// Log.info("Updating status [game=" + _puzobj.which() + "].");
|
||||
// log.info("Updating status", "game", _puzobj.which());
|
||||
updateStatus();
|
||||
} finally {
|
||||
_puzobj.commitTransaction();
|
||||
@@ -255,9 +255,9 @@ public abstract class PuzzleManager extends GameManager
|
||||
|
||||
/**
|
||||
* A puzzle periodically (default of once every 5 seconds but configurable by puzzle) updates
|
||||
* status information that is visible to the user. Derived classes can override this method and
|
||||
* effect their updates by generating events on the puzzle object and they will be packaged
|
||||
* into the update transaction.
|
||||
* status information that is visible to the user. Derived classes can override this method
|
||||
* and effect their updates by generating events on the puzzle object and they will be
|
||||
* packaged into the update transaction.
|
||||
*/
|
||||
protected void updateStatus ()
|
||||
{
|
||||
@@ -289,8 +289,8 @@ public abstract class PuzzleManager extends GameManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and initializes boards and board summaries (if desired per {@link
|
||||
* #needsBoardSummaries}) for each player.
|
||||
* Creates and initializes boards and board summaries (if desired per
|
||||
* {@link #needsBoardSummaries}) for each player.
|
||||
*/
|
||||
protected void initBoards ()
|
||||
{
|
||||
@@ -314,8 +314,8 @@ public abstract class PuzzleManager extends GameManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this puzzle needs a board for the given player index. The default
|
||||
* implementation only creates boards for occupied player slots. Derived classes may wish to
|
||||
* Returns whether this puzzle needs a board for the given player index. The default
|
||||
* implementation only creates boards for occupied player slots. Derived classes may wish to
|
||||
* override this method if they have specialized board needs, e.g., they need only a single
|
||||
* board for all players.
|
||||
*/
|
||||
@@ -356,8 +356,8 @@ public abstract class PuzzleManager extends GameManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies progress updates received from the client. If puzzle debugging is enabled, this also
|
||||
* compares the client board dumps provided along with each puzzle event.
|
||||
* Applies progress updates received from the client. If puzzle debugging is enabled, this
|
||||
* also compares the client board dumps provided along with each puzzle event.
|
||||
*/
|
||||
protected void applyProgressEvents (int pidx, int[] gevents, Board[] states)
|
||||
{
|
||||
@@ -376,8 +376,7 @@ public abstract class PuzzleManager extends GameManager
|
||||
|
||||
// apply the event to the player's board
|
||||
if (!applyProgressEvent(pidx, gevent, cboard)) {
|
||||
log.warning("Unknown event [puzzle=" + where() + ", pidx=" + pidx +
|
||||
", event=" + gevent + "].");
|
||||
log.warning("Unknown event", "puzzle", where(), "pidx", pidx, "event", gevent);
|
||||
}
|
||||
|
||||
// maybe we are comparing boards afterwards
|
||||
@@ -393,8 +392,8 @@ public abstract class PuzzleManager extends GameManager
|
||||
protected void compareBoards (int pidx, Board boardstate, int gevent, boolean before)
|
||||
{
|
||||
if (DEBUG_PUZZLE) {
|
||||
log.info((before ? "About to apply " : "Just applied ") + "[game=" + _puzobj.which() +
|
||||
", pidx=" + pidx + ", event=" + gevent + "].");
|
||||
log.info((before ? "About to apply " : "Just applied "),
|
||||
"game", _puzobj.which(), "pidx", pidx, "event", gevent);
|
||||
}
|
||||
if (boardstate == null) {
|
||||
if (DEBUG_PUZZLE) {
|
||||
@@ -404,8 +403,8 @@ public abstract class PuzzleManager extends GameManager
|
||||
}
|
||||
boolean equal = _boards[pidx].equals(boardstate);
|
||||
if (!equal) {
|
||||
log.warning("Client and server board states not equal! [game=" + _puzobj.which() +
|
||||
", type=" + _puzobj.getClass().getName() + "].");
|
||||
log.warning("Client and server board states not equal!",
|
||||
"game", _puzobj.which(), "type", _puzobj.getClass().getName());
|
||||
}
|
||||
if (DEBUG_PUZZLE) {
|
||||
// if we're debugging, dump the board state every time we're about to apply an event
|
||||
@@ -424,14 +423,14 @@ public abstract class PuzzleManager extends GameManager
|
||||
/**
|
||||
* Called by {@link #updateProgress} to give the server a chance to apply each game event
|
||||
* received from the client to the respective player's server-side board and, someday, confirm
|
||||
* their validity. Derived classes that make use of the progress updating functionality should
|
||||
* be sure to override this method to perform their game-specific event application
|
||||
* antics. They should first perform a call to super() to see if the event is handled there.
|
||||
* their validity. Derived classes that make use of the progress updating functionality should
|
||||
* be sure to override this method to perform their game-specific event application antics.
|
||||
* They should first perform a call to super() to see if the event is handled there.
|
||||
*
|
||||
* @param pidx the player index that submitted the progress event.
|
||||
* @param gevent the progress event itself.
|
||||
* @param cboard a snapshot of the board on the client iff the client has board syncing enabled
|
||||
* (which is only enabled when debugging).
|
||||
* @param cboard a snapshot of the board on the client iff the client has board syncing
|
||||
* enabled (which is only enabled when debugging).
|
||||
*
|
||||
* @return true to indicate that the event was handled.
|
||||
*/
|
||||
@@ -441,7 +440,7 @@ public abstract class PuzzleManager extends GameManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides the game manager implementation to mark all active players as winners. Derived
|
||||
* Overrides the game manager implementation to mark all active players as winners. Derived
|
||||
* classes may wish to override this method in order to customize the winning conditions.
|
||||
*/
|
||||
@Override
|
||||
@@ -458,7 +457,7 @@ public abstract class PuzzleManager extends GameManager
|
||||
protected abstract Board newBoard (int pidx);
|
||||
|
||||
/**
|
||||
* Creates and returns a new board summary for the given board. Puzzles that do not make use
|
||||
* Creates and returns a new board summary for the given board. Puzzles that do not make use
|
||||
* of board summaries should implement this method and return <code>null</code>.
|
||||
*/
|
||||
protected abstract BoardSummary newBoardSummary (Board board);
|
||||
@@ -480,31 +479,30 @@ public abstract class PuzzleManager extends GameManager
|
||||
if (sessionId != _puzobj.sessionId) {
|
||||
// only warn if this isn't a straggling update from the previous session
|
||||
if (sessionId != _puzobj.sessionId-1) {
|
||||
log.warning("Received progress update for invalid session, not applying " +
|
||||
"[game=" + _puzobj.which() + ", invalidSessionId=" + sessionId +
|
||||
", sessionId=" + _puzobj.sessionId + "].");
|
||||
log.warning("Received progress update for invalid session, not applying",
|
||||
"game", _puzobj.which(), "invalidSessionId", sessionId,
|
||||
"sessionId", _puzobj.sessionId);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// if the game is over, we wing straggling updates
|
||||
if (!_puzobj.isInPlay()) {
|
||||
log.debug("Ignoring straggling events", "game", _puzobj.which(), "who", caller.who(),
|
||||
"events", events);
|
||||
log.debug("Ignoring straggling events",
|
||||
"game", _puzobj.which(), "who", caller.who(), "events", events);
|
||||
return;
|
||||
}
|
||||
|
||||
// determine the caller's player index in the game
|
||||
int pidx = IntListUtil.indexOf(_playerOids, caller.getOid());
|
||||
if (pidx == -1) {
|
||||
log.warning("Received progress update for non-player?!", "game", _puzobj.which(),
|
||||
"who", caller.who(), "ploids", _playerOids);
|
||||
log.warning("Received progress update for non-player?!",
|
||||
"game", _puzobj.which(), "who", caller.who(), "ploids", _playerOids);
|
||||
return;
|
||||
}
|
||||
|
||||
// Log.info("Handling progress events [game=" + _puzobj.which() +
|
||||
// ", pidx=" + pidx + ", sessionId=" + sessionId +
|
||||
// ", count=" + events.length + "].");
|
||||
// log.info("Handling progress events", "game", _puzobj.which(),
|
||||
// "pidx", pidx + "sessionId", sessionId, "count", events.length);
|
||||
|
||||
// note that we received a progress update from this player
|
||||
_lastProgress[pidx] = System.currentTimeMillis();
|
||||
@@ -530,8 +528,8 @@ public abstract class PuzzleManager extends GameManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether {@link #checkPlayerActivity} should be called periodically while the game is
|
||||
* in play to make sure players are still active.
|
||||
* Returns whether {@link #checkPlayerActivity} should be called periodically while the game
|
||||
* is in play to make sure players are still active.
|
||||
*/
|
||||
protected boolean checkForInactivity ()
|
||||
{
|
||||
@@ -540,7 +538,7 @@ public abstract class PuzzleManager extends GameManager
|
||||
|
||||
/**
|
||||
* Called periodically for each human player to give puzzles a chance to make sure all such
|
||||
* players are engaging in reasonable levels of activity. The default implementation does
|
||||
* players are engaging in reasonable levels of activity. The default implementation does
|
||||
* naught.
|
||||
*/
|
||||
protected void checkPlayerActivity (long tickStamp, int pidx)
|
||||
|
||||
@@ -26,8 +26,8 @@ import com.threerings.crowd.data.PlaceConfig;
|
||||
import com.threerings.parlor.game.server.GameManagerDelegate;
|
||||
|
||||
/**
|
||||
* Extends the {@link GameManagerDelegate} mechanism with puzzle manager specific methods (of which
|
||||
* there are currently none).
|
||||
* Extends the {@link GameManagerDelegate} mechanism with puzzle manager specific methods (of
|
||||
* which there are currently none).
|
||||
*/
|
||||
public class PuzzleManagerDelegate extends GameManagerDelegate
|
||||
{
|
||||
|
||||
@@ -28,14 +28,13 @@ import java.awt.Point;
|
||||
import static com.threerings.puzzle.Log.log;
|
||||
|
||||
/**
|
||||
* The point set class provides an efficient implementation of a set
|
||||
* containing two-dimensional point values as <code>(x, y)</code>.
|
||||
* The point set class provides an efficient implementation of a set containing two-dimensional
|
||||
* point values as <code>(x, y)</code>.
|
||||
*/
|
||||
public class PointSet
|
||||
{
|
||||
/**
|
||||
* Creates a point set that can contain points within the given range
|
||||
* of values.
|
||||
* Creates a point set that can contain points within the given range of values.
|
||||
*
|
||||
* @param rangeX the maximum x-axis range.
|
||||
* @param rangeY the maximum y-axis range.
|
||||
@@ -48,8 +47,7 @@ public class PointSet
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a point to the set and returns whether the point was already
|
||||
* present in the set.
|
||||
* Adds a point to the set and returns whether the point was already present in the set.
|
||||
*
|
||||
* @param x the point x-coordinate.
|
||||
* @param y the point y-coordinate.
|
||||
@@ -122,10 +120,9 @@ public class PointSet
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator that iterates over the points in this set,
|
||||
* returning them as {@link Point} objects. Note that the iterator
|
||||
* uses a single point object internally, and so callers should create
|
||||
* their own copy of the point if they plan to do something fancy with
|
||||
* Returns an iterator that iterates over the points in this set, returning them as
|
||||
* {@link Point} objects. Note that the iterator uses a single point object internally, and so
|
||||
* callers should create their own copy of the point if they plan to do something fancy with
|
||||
* it.
|
||||
*
|
||||
* @return the iterator over the set's points.
|
||||
@@ -136,8 +133,7 @@ public class PointSet
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the given point from the set and returns whether the point
|
||||
* was present in the set.
|
||||
* Removes the given point from the set and returns whether the point was present in the set.
|
||||
*
|
||||
* @param x the point x-coordinate.
|
||||
* @param y the point y-coordinate.
|
||||
|
||||
Reference in New Issue
Block a user