com.realtime.crossfire.jxclient.mapupdater
Class CfMapUpdater

java.lang.Object
  extended by com.realtime.crossfire.jxclient.mapupdater.CfMapUpdater

public class CfMapUpdater
extends java.lang.Object

Utility class to update a CfMap model from protocol commands.

The map updater is called from two threads: the ClientSocket reading commands received from the Crossfire server, and FileCacheFaceQueue reading faces from the (file) cache. Synchronization is by sync and applies to the whole map model map.


Field Summary
private  Animations animations
          The defined animations.
private  CrossfireUpdateMapListener crossfireUpdateMapListener
          The listener to detect map model changes.
private  FacesManager facesManager
          The FacesManager to track for updated faces.
private  FacesManagerListener facesManagerListener
          The listener to detect updated faces.
private  GuiStateListener guiStateListener
          The GuiStateListener for detecting established or dropped connections.
private  int height
          The height of the visible map area.
private  CfMap map
          The current CfMap instance.
private  java.util.Collection<MapListener> mapListeners
          The listeners to notify about changed map squares.
private  java.util.Collection<MapScrollListener> mapScrollListeners
          The listeners to notify about scrolled maps.
private  java.util.Collection<MapSizeListener> mapSizeListeners
          The MapSizeListeners to be notified.
private  java.util.Collection<NewmapListener> newmapListeners
          The listeners to notify about cleared maps.
private  java.util.Collection<Location> outOfViewMultiFaces
          All multi-tiled faces with heads outside the visible map area.
private  java.lang.Object sync
          The object used for synchronization.
private  CfMapAnimations visibleAnimations
          The animations in the visible map area.
private  int width
          The width of the visible map area.
 
Constructor Summary
CfMapUpdater(CrossfireServerConnection crossfireServerConnection, FacesManager facesManager, GuiStateManager guiStateManager)
          Creates a new instance.
CfMapUpdater(FacesManager facesManager)
          Creates a new instance.
 
Method Summary
 void addCrossfireMapListener(MapListener listener)
          Adds a listener to notify about changed map squares.
 void addCrossfireMapScrollListener(MapScrollListener listener)
          Adds a listener to notify about scrolled maps.
 void addCrossfireNewmapListener(NewmapListener listener)
          Adds a listener to notify about cleared maps.
 void addMapSizeListener(MapSizeListener listener)
          Adds a listener to be notified about map size changes.
private  Face getFace(int faceNum)
          Returns the Face instance by face ID.
 int getHeight()
          Returns the height of the visible map area.
 CfMap getMap()
          Returns the current map instance.
 CfMapAnimations getMapAnimations()
          Returns the CfMapAnimations instance.
 int getWidth()
          Returns the width of the visible map area.
 void processMagicMap(int x, int y, int color)
          Finishes processing of a set of map square changes.
private  void processMapAnimation(int x, int y, int layer, Animation animation, int type)
          Updates a map square by changing an animation.
private  void processMapAnimationSpeed(int x, int y, int layer, int animationSpeed)
          Updates a map square by changing the animation speed.
 void processMapBegin()
          Starts processing of a set of map square changes.
 void processMapClear(int x, int y)
          Updates a map square by clearing it.
private  void processMapDarkness(int x, int y, int darkness)
          Updates a map square by changing the darkness value.
 void processMapEnd(boolean alwaysProcess)
          Finishes processing of a set of map square changes.
 void processMapFace(Location location, int faceNum, boolean clearAnimation)
          Updates a map square by changing a face.
 void processMapScroll(int dx, int dy)
          Processes a map scroll command.
 void processNewMap(int width, int height)
          Processes a newmap command.
 void removeCrossfireMapListener(MapListener listener)
          Removes a listener to notify about changed map squares.
 void removeCrossfireMapScrollListener(MapScrollListener listener)
          Removes a listener to notify about scrolled maps.
 void removeCrossfireNewmapListener(NewmapListener listener)
          Removes a listener to notify about cleared maps.
 void removeMapSizeListener(MapSizeListener listener)
          Removes a listener to be notified about map size changes.
private  void reset()
          Resets the animation state.
private  void updateFace(int faceNum)
          Processes an updated face image.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

animations

@NotNull
private final Animations animations
The defined animations.


crossfireUpdateMapListener

@NotNull
private final CrossfireUpdateMapListener crossfireUpdateMapListener
The listener to detect map model changes.


facesManager

@NotNull
private final FacesManager facesManager
The FacesManager to track for updated faces.


facesManagerListener

@NotNull
private final FacesManagerListener facesManagerListener
The listener to detect updated faces.


guiStateListener

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


height

private int height
The height of the visible map area.


map

@NotNull
private CfMap map
The current CfMap instance.


mapListeners

@NotNull
private final java.util.Collection<MapListener> mapListeners
The listeners to notify about changed map squares.


mapScrollListeners

@NotNull
private final java.util.Collection<MapScrollListener> mapScrollListeners
The listeners to notify about scrolled maps.


mapSizeListeners

@NotNull
private final java.util.Collection<MapSizeListener> mapSizeListeners
The MapSizeListeners to be notified.


newmapListeners

@NotNull
private final java.util.Collection<NewmapListener> newmapListeners
The listeners to notify about cleared maps.


outOfViewMultiFaces

@NotNull
private final java.util.Collection<Location> outOfViewMultiFaces
All multi-tiled faces with heads outside the visible map area.


sync

@NotNull
private final java.lang.Object sync
The object used for synchronization.


visibleAnimations

@NotNull
private final CfMapAnimations visibleAnimations
The animations in the visible map area.


width

private int width
The width of the visible map area.

Constructor Detail

CfMapUpdater

public CfMapUpdater(@NotNull
                    CrossfireServerConnection crossfireServerConnection,
                    @NotNull
                    FacesManager facesManager,
                    @NotNull
                    GuiStateManager guiStateManager)
Creates a new instance.

Parameters:
crossfireServerConnection - the connection to monitor
facesManager - the faces manager to track for updated faces
guiStateManager - the gui state manager to watch

CfMapUpdater

public CfMapUpdater(@NotNull
                    FacesManager facesManager)
Creates a new instance.

Parameters:
facesManager - the faces manager to track for updated faces
Method Detail

addCrossfireMapListener

public void addCrossfireMapListener(@NotNull
                                    MapListener listener)
Adds a listener to notify about changed map squares.

Parameters:
listener - the listener to add

addCrossfireMapScrollListener

public void addCrossfireMapScrollListener(@NotNull
                                          MapScrollListener listener)
Adds a listener to notify about scrolled maps.

Parameters:
listener - the listener to add

addCrossfireNewmapListener

public void addCrossfireNewmapListener(@NotNull
                                       NewmapListener listener)
Adds a listener to notify about cleared maps.

Parameters:
listener - the listener to add

addMapSizeListener

public void addMapSizeListener(@NotNull
                               MapSizeListener listener)
Adds a listener to be notified about map size changes.

Parameters:
listener - the listener to add

getFace

@Nullable
private Face getFace(int faceNum)
Returns the Face instance by face ID.

Parameters:
faceNum - the face ID
Returns:
return the face instance, or null if faceNum==0

getHeight

public int getHeight()
Returns the height of the visible map area.

Returns:
the height of the visible map area

getMap

@NotNull
public CfMap getMap()
Returns the current map instance.

Returns:
the current map instance

getMapAnimations

@NotNull
public CfMapAnimations getMapAnimations()
Returns the CfMapAnimations instance.

Returns:
the instance

getWidth

public int getWidth()
Returns the width of the visible map area.

Returns:
the width of the visible map area

processMagicMap

public void processMagicMap(int x,
                            int y,
                            int color)
Finishes processing of a set of map square changes. Notifies listeners about changes. present

Parameters:
x - the x-coordinate of the square
y - the y-coordinate of the square
color - the magic map color to set

processMapAnimation

private void processMapAnimation(int x,
                                 int y,
                                 int layer,
                                 @NotNull
                                 Animation animation,
                                 int type)
Updates a map square by changing an animation.

Parameters:
x - the x-coordinate of the square
y - the y-coordinate of the square
layer - the layer to update
animation - the animation to set
type - the animation type

processMapAnimationSpeed

private void processMapAnimationSpeed(int x,
                                      int y,
                                      int layer,
                                      int animationSpeed)
Updates a map square by changing the animation speed.

Parameters:
x - the x-coordinate of the square
y - the y-coordinate of the square
layer - the layer to update
animationSpeed - the animation speed to set

processMapBegin

public void processMapBegin()
Starts processing of a set of map square changes.


processMapClear

public void processMapClear(int x,
                            int y)
Updates a map square by clearing it.

Parameters:
x - the x-coordinate of the square
y - the y-coordinate of the square

processMapDarkness

private void processMapDarkness(int x,
                                int y,
                                int darkness)
Updates a map square by changing the darkness value.

Parameters:
x - the x-coordinate of the square
y - the y-coordinate of the square
darkness - the darkness value to set

processMapEnd

public void processMapEnd(boolean alwaysProcess)
Finishes processing of a set of map square changes. Notifies listeners about changes.

Parameters:
alwaysProcess - if set, notify listeners even if no changes are present

processMapFace

public void processMapFace(@NotNull
                           Location location,
                           int faceNum,
                           boolean clearAnimation)
Updates a map square by changing a face.

Parameters:
location - the location to update
faceNum - the face to set. 0 clears the square
clearAnimation - whether an animation should be cleared

processMapScroll

public void processMapScroll(int dx,
                             int dy)
Processes a map scroll command.

Parameters:
dx - the distance to scroll in x-direction in squares
dy - the distance to scroll in y-direction in squares

processNewMap

public void processNewMap(int width,
                          int height)
Processes a newmap command. This clears the map state.

Parameters:
width - the width of the visible map area
height - the height of the visible map area

removeCrossfireMapListener

public void removeCrossfireMapListener(@NotNull
                                       MapListener listener)
Removes a listener to notify about changed map squares.

Parameters:
listener - the listener to remove

removeCrossfireMapScrollListener

public void removeCrossfireMapScrollListener(@NotNull
                                             MapScrollListener listener)
Removes a listener to notify about scrolled maps.

Parameters:
listener - the listener to remove

removeCrossfireNewmapListener

public void removeCrossfireNewmapListener(@NotNull
                                          NewmapListener listener)
Removes a listener to notify about cleared maps.

Parameters:
listener - the listener to remove

removeMapSizeListener

public void removeMapSizeListener(@NotNull
                                  MapSizeListener listener)
Removes a listener to be notified about map size changes.

Parameters:
listener - the listener to remove

reset

private void reset()
Resets the animation state.


updateFace

private void updateFace(int faceNum)
Processes an updated face image.

Parameters:
faceNum - the face that has changed