Class MapUpdaterState

java.lang.Object
com.realtime.crossfire.jxclient.map.MapUpdaterState
All Implemented Interfaces:
FacesManagerListener, CrossfireTickListener, CrossfireUpdateMapListener, EventListener

public class MapUpdaterState extends Object implements CrossfireTickListener, CrossfireUpdateMapListener, FacesManagerListener
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.

  • Constructor Details

    • MapUpdaterState

      public MapUpdaterState(@NotNull @NotNull FacesManager facesManager, @NotNull @NotNull Animations animations, @NotNull @NotNull CfAnimations cfAnimations)
      Creates a new instance.
      Parameters:
      facesManager - the faces manager to track for updated faces
      animations - the known animations
      cfAnimations - the animations manager to use
  • Method Details

    • addCrossfireMapListener

      public void addCrossfireMapListener(@NotNull @NotNull MapListener listener)
      Adds a listener to notify about changed map squares.
      Parameters:
      listener - the listener to add
    • removeCrossfireMapListener

      public void removeCrossfireMapListener(@NotNull @NotNull MapListener listener)
      Removes a listener to notify about changed map squares.
      Parameters:
      listener - the listener to remove
    • addCrossfireNewmapListener

      public void addCrossfireNewmapListener(@NotNull @NotNull NewmapListener listener)
      Adds a listener to notify about cleared maps.
      Parameters:
      listener - the listener to add
    • removeCrossfireNewmapListener

      public void removeCrossfireNewmapListener(@NotNull @NotNull NewmapListener listener)
      Removes a listener to notify about cleared maps.
      Parameters:
      listener - the listener to remove
    • addCrossfireMapScrollListener

      public void addCrossfireMapScrollListener(@NotNull @NotNull MapScrollListener listener)
      Adds a listener to notify about scrolled maps.
      Parameters:
      listener - the listener to add
    • removeCrossfireMapScrollListener

      public void removeCrossfireMapScrollListener(@NotNull @NotNull MapScrollListener listener)
      Removes a listener to notify about scrolled maps.
      Parameters:
      listener - the listener to remove
    • addMapSizeListener

      public void addMapSizeListener(@NotNull @NotNull MapSizeListener listener)
      Adds a listener to be notified about map size changes.
      Parameters:
      listener - the listener to add
    • removeMapSizeListener

      public void removeMapSizeListener(@NotNull @NotNull MapSizeListener listener)
      Removes a listener to be notified about map size changes.
      Parameters:
      listener - the listener to remove
    • reset

      public void reset()
      Resets the animation state.
    • mapBegin

      @NotNull public @NotNull Object mapBegin()
      Description copied from interface: CrossfireUpdateMapListener
      Parsing of a "map2" command has been started.
      Specified by:
      mapBegin in interface CrossfireUpdateMapListener
      Returns:
      the synchronization object which must be synchronized while calling any other function (except newMap())
    • mapClear

      public void mapClear(int x, int y)
      Description copied from interface: CrossfireUpdateMapListener
      Part of "map2" parsing: clear a cell.
      Specified by:
      mapClear in interface CrossfireUpdateMapListener
      Parameters:
      x - the x-coordinate
      y - the y-coordinate
    • mapFace

      public void mapFace(@NotNull @NotNull Location location, int faceNum)
      Description copied from interface: CrossfireUpdateMapListener
      Part of "map2" parsing: set the face of a cell.
      Specified by:
      mapFace in interface CrossfireUpdateMapListener
      Parameters:
      location - the location
      faceNum - the face ID
    • mapFace

      public void mapFace(@NotNull @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
    • mapAnimation

      public void mapAnimation(@NotNull @NotNull Location location, int animationNum, int animationType)
      Description copied from interface: CrossfireUpdateMapListener
      Part of "map2" parsing: set the animation of a cell.
      Specified by:
      mapAnimation in interface CrossfireUpdateMapListener
      Parameters:
      location - the location
      animationNum - the animation ID
      animationType - the animation type
    • mapAnimationSpeed

      public void mapAnimationSpeed(@NotNull @NotNull Location location, int animationSpeed)
      Description copied from interface: CrossfireUpdateMapListener
      Part of "map2" parsing: set the animation speed.
      Specified by:
      mapAnimationSpeed in interface CrossfireUpdateMapListener
      Parameters:
      location - the location
      animationSpeed - the animation speed
    • mapSmooth

      public void mapSmooth(@NotNull @NotNull Location location, int smooth)
      Description copied from interface: CrossfireUpdateMapListener
      Part of "map2" parsing: set the smooth level.
      Specified by:
      mapSmooth in interface CrossfireUpdateMapListener
      Parameters:
      location - the location
      smooth - the smooth value
    • mapDarkness

      public void mapDarkness(int x, int y, int darkness)
      Description copied from interface: CrossfireUpdateMapListener
      Part of "map2" parsing: change the darkness of a cell.
      Specified by:
      mapDarkness in interface CrossfireUpdateMapListener
      Parameters:
      x - the x-coordinate
      y - the y-coordinate
      darkness - the darkness value
    • magicMap

      public void magicMap(int x, int y, byte @NotNull [] @NotNull [] data)
      Description copied from interface: CrossfireUpdateMapListener
      Part of "magicmap" parsing: set the magic map color.
      Specified by:
      magicMap in interface CrossfireUpdateMapListener
      Parameters:
      x - the x-coordinate
      y - the y-coordinate
      data - the magic map data (y, x); must not be changed
    • mapEnd

      public void mapEnd()
      Description copied from interface: CrossfireUpdateMapListener
      Parsing of "map2" has been finished.
      Specified by:
      mapEnd in interface CrossfireUpdateMapListener
    • mapEnd

      public void mapEnd(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
    • mapScroll

      public void mapScroll(int dx, int dy)
      Description copied from interface: CrossfireUpdateMapListener
      Part of "map2" parsing: scroll the map view.
      Specified by:
      mapScroll in interface CrossfireUpdateMapListener
      Parameters:
      dx - the x-distance
      dy - the y-distance
    • faceUpdated

      public void faceUpdated(@NotNull @NotNull Face face)
      Description copied from interface: FacesManagerListener
      Called when a Face has been updated.
      Specified by:
      faceUpdated in interface FacesManagerListener
      Parameters:
      face - the face
    • newMap

      public void newMap(int mapWidth, int mapHeight)
      Description copied from interface: CrossfireUpdateMapListener
      A "newmap" command has been received.
      Specified by:
      newMap in interface CrossfireUpdateMapListener
      Parameters:
      mapWidth - the map width
      mapHeight - the map height
    • getMap

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

      public int getMapWidth()
      Returns the width of the visible map area.
      Returns:
      the width of the visible map area
    • getMapHeight

      public int getMapHeight()
      Returns the height of the visible map area.
      Returns:
      the height of the visible map area
    • tick

      public void tick(int tickNo)
      Description copied from interface: CrossfireTickListener
      A "tick" command has been received.
      Specified by:
      tick in interface CrossfireTickListener
      Parameters:
      tickNo - the current tick