com.realtime.crossfire.jxclient.queue
Class CommandQueue

java.lang.Object
  extended by com.realtime.crossfire.jxclient.queue.CommandQueue

public class CommandQueue
extends java.lang.Object

Maintains the pending (ncom) commands sent to the server.


Field Summary
private  CrossfireComcListener crossfireComcListener
          The listener to track comc commands.
private  CrossfireServerConnection crossfireServerConnection
          The server connection for sending ncom commands.
private  GuiStateListener guiStateListener
          The GuiStateListener for detecting established or dropped connections.
private  boolean isRunning
          Whether a "run" command has been sent without a following "run_stop" command.
private static int MAX_PENDING_COMMANDS
          Maximum number of pending commands sent to the server.
private  java.util.List<java.lang.Integer> pendingCommands
          Records command ids of commands sent to the server for which no comc commands has been received.
private  int repeatCount
          The default repeat counter for ncom commands.
 
Constructor Summary
CommandQueue(CrossfireServerConnection crossfireServerConnection, GuiStateManager guiStateManager)
          Create a new instance.
 
Method Summary
 void addToRepeatCount(int digit)
          Add a digit to the current repeat count.
 boolean checkFire()
          Returns whether the character is firing.
 boolean checkRun()
          Returns whether the character is running.
private  void clear()
          Forget about sent commands.
private  int getRepeatCount()
          Return the current repeat count and reset it to zero.
 void resetRepeatCount()
          Reset the current repeat count to zero.
 void sendMove(int to, int tag)
          Sends a "move" command to the server.
 void sendNcom(boolean mustSend, int repeat, java.lang.String command)
          Send a "ncom" command to the server.
 void sendNcom(boolean mustSend, java.lang.String command)
          Send a "ncom" command to the server.
 boolean stopRunning()
          Tell the server to stop running.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

crossfireComcListener

@NotNull
private final CrossfireComcListener crossfireComcListener
The listener to track comc commands.


crossfireServerConnection

@NotNull
private final CrossfireServerConnection crossfireServerConnection
The server connection for sending ncom commands.


guiStateListener

@NotNull
private final GuiStateListener guiStateListener
The GuiStateListener for detecting established or dropped connections.


isRunning

private boolean isRunning
Whether a "run" command has been sent without a following "run_stop" command.


MAX_PENDING_COMMANDS

private static final int MAX_PENDING_COMMANDS
Maximum number of pending commands sent to the server. Excess commands will be dropped.

See Also:
Constant Field Values

pendingCommands

@NotNull
private final java.util.List<java.lang.Integer> pendingCommands
Records command ids of commands sent to the server for which no comc commands has been received. Note that the size may be larger than MAX_PENDING_COMMANDS due to "must send" commands.


repeatCount

private int repeatCount
The default repeat counter for ncom commands.

Constructor Detail

CommandQueue

public CommandQueue(@NotNull
                    CrossfireServerConnection crossfireServerConnection,
                    @NotNull
                    GuiStateManager guiStateManager)
Create a new instance.

Parameters:
crossfireServerConnection - The server connection for sending ncom commands.
guiStateManager - the gui state manager to watch
Method Detail

addToRepeatCount

public void addToRepeatCount(int digit)
Add a digit to the current repeat count.

Parameters:
digit - The digit (0-9) to add.

checkFire

public boolean checkFire()
Returns whether the character is firing.

Returns:
whether the character is firing

checkRun

public boolean checkRun()
Returns whether the character is running.

Returns:
whether the character is running

clear

private void clear()
Forget about sent commands.


getRepeatCount

private int getRepeatCount()
Return the current repeat count and reset it to zero.

Returns:
The current repeat count.

resetRepeatCount

public void resetRepeatCount()
Reset the current repeat count to zero.


sendMove

public void sendMove(int to,
                     int tag)
Sends a "move" command to the server. The repeat count value is the client's current repeat count.

Parameters:
to - the destination location
tag - the item to move

sendNcom

public void sendNcom(boolean mustSend,
                     int repeat,
                     @NotNull
                     java.lang.String command)
Send a "ncom" command to the server.

Parameters:
mustSend - If set, always send the command; if unset, drop the command if the command queue is full.
repeat - The repeat count.
command - The command to send.
See Also:
sendNcom(boolean, String)

sendNcom

public void sendNcom(boolean mustSend,
                     @NotNull
                     java.lang.String command)
Send a "ncom" command to the server. This function uses the default repeat count.

Parameters:
mustSend - If set, always send the command; if unset, drop the command if the command queue is full.
command - The command to send.
See Also:
sendNcom(boolean, int, String)

stopRunning

public boolean stopRunning()
Tell the server to stop running. If the character is not running, do nothing.

Returns:
whether running was active