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 Summary
ConstructorsConstructorDescriptionMapUpdaterState(@NotNull FacesManager facesManager, @NotNull Animations animations, @NotNull CfAnimations cfAnimations) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCrossfireMapListener(@NotNull MapListener listener) Adds a listener to notify about changed map squares.voidaddCrossfireMapScrollListener(@NotNull MapScrollListener listener) Adds a listener to notify about scrolled maps.voidaddCrossfireNewmapListener(@NotNull NewmapListener listener) Adds a listener to notify about cleared maps.voidaddMapSizeListener(@NotNull MapSizeListener listener) Adds a listener to be notified about map size changes.voidfaceUpdated(@NotNull Face face) Called when aFacehas been updated.@NotNull CfMapgetMap()Returns the current map instance.intReturns the height of the visible map area.intReturns the width of the visible map area.voidmagicMap(int x, int y, byte @NotNull [] @NotNull [] data) Part of "magicmap" parsing: set the magic map color.voidmapAnimation(@NotNull Location location, int animationNum, int animationType) Part of "map2" parsing: set the animation of a cell.voidmapAnimationSpeed(@NotNull Location location, int animationSpeed) Part of "map2" parsing: set the animation speed.@NotNull ObjectmapBegin()Parsing of a "map2" command has been started.voidmapClear(int x, int y) Part of "map2" parsing: clear a cell.voidmapDarkness(int x, int y, int darkness) Part of "map2" parsing: change the darkness of a cell.voidmapEnd()Parsing of "map2" has been finished.voidmapEnd(boolean alwaysProcess) Finishes processing of a set of map square changes.voidPart of "map2" parsing: set the face of a cell.voidUpdates a map square by changing a face.voidmapScroll(int dx, int dy) Part of "map2" parsing: scroll the map view.voidPart of "map2" parsing: set the smooth level.voidnewMap(int mapWidth, int mapHeight) A "newmap" command has been received.voidremoveCrossfireMapListener(@NotNull MapListener listener) Removes a listener to notify about changed map squares.voidremoveCrossfireMapScrollListener(@NotNull MapScrollListener listener) Removes a listener to notify about scrolled maps.voidremoveCrossfireNewmapListener(@NotNull NewmapListener listener) Removes a listener to notify about cleared maps.voidremoveMapSizeListener(@NotNull MapSizeListener listener) Removes a listener to be notified about map size changes.voidreset()Resets the animation state.voidtick(int tickNo) A "tick" command has been received.
-
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 facesanimations- the known animationscfAnimations- the animations manager to use
-
-
Method Details
-
addCrossfireMapListener
Adds a listener to notify about changed map squares.- Parameters:
listener- the listener to add
-
removeCrossfireMapListener
Removes a listener to notify about changed map squares.- Parameters:
listener- the listener to remove
-
addCrossfireNewmapListener
Adds a listener to notify about cleared maps.- Parameters:
listener- the listener to add
-
removeCrossfireNewmapListener
Removes a listener to notify about cleared maps.- Parameters:
listener- the listener to remove
-
addCrossfireMapScrollListener
Adds a listener to notify about scrolled maps.- Parameters:
listener- the listener to add
-
removeCrossfireMapScrollListener
Removes a listener to notify about scrolled maps.- Parameters:
listener- the listener to remove
-
addMapSizeListener
Adds a listener to be notified about map size changes.- Parameters:
listener- the listener to add
-
removeMapSizeListener
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
Description copied from interface:CrossfireUpdateMapListenerParsing of a "map2" command has been started.- Specified by:
mapBeginin interfaceCrossfireUpdateMapListener- Returns:
- the synchronization object which must be
synchronizedwhile calling any other function (exceptnewMap())
-
mapClear
public void mapClear(int x, int y) Description copied from interface:CrossfireUpdateMapListenerPart of "map2" parsing: clear a cell.- Specified by:
mapClearin interfaceCrossfireUpdateMapListener- Parameters:
x- the x-coordinatey- the y-coordinate
-
mapFace
Description copied from interface:CrossfireUpdateMapListenerPart of "map2" parsing: set the face of a cell.- Specified by:
mapFacein interfaceCrossfireUpdateMapListener- Parameters:
location- the locationfaceNum- the face ID
-
mapFace
Updates a map square by changing a face.- Parameters:
location- the location to updatefaceNum- the face to set;0clears the squareclearAnimation- whether an animation should be cleared
-
mapAnimation
Description copied from interface:CrossfireUpdateMapListenerPart of "map2" parsing: set the animation of a cell.- Specified by:
mapAnimationin interfaceCrossfireUpdateMapListener- Parameters:
location- the locationanimationNum- the animation IDanimationType- the animation type
-
mapAnimationSpeed
Description copied from interface:CrossfireUpdateMapListenerPart of "map2" parsing: set the animation speed.- Specified by:
mapAnimationSpeedin interfaceCrossfireUpdateMapListener- Parameters:
location- the locationanimationSpeed- the animation speed
-
mapSmooth
Description copied from interface:CrossfireUpdateMapListenerPart of "map2" parsing: set the smooth level.- Specified by:
mapSmoothin interfaceCrossfireUpdateMapListener- Parameters:
location- the locationsmooth- the smooth value
-
mapDarkness
public void mapDarkness(int x, int y, int darkness) Description copied from interface:CrossfireUpdateMapListenerPart of "map2" parsing: change the darkness of a cell.- Specified by:
mapDarknessin interfaceCrossfireUpdateMapListener- Parameters:
x- the x-coordinatey- the y-coordinatedarkness- the darkness value
-
magicMap
public void magicMap(int x, int y, byte @NotNull [] @NotNull [] data) Description copied from interface:CrossfireUpdateMapListenerPart of "magicmap" parsing: set the magic map color.- Specified by:
magicMapin interfaceCrossfireUpdateMapListener- Parameters:
x- the x-coordinatey- the y-coordinatedata- the magic map data (y, x); must not be changed
-
mapEnd
public void mapEnd()Description copied from interface:CrossfireUpdateMapListenerParsing of "map2" has been finished.- Specified by:
mapEndin interfaceCrossfireUpdateMapListener
-
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:CrossfireUpdateMapListenerPart of "map2" parsing: scroll the map view.- Specified by:
mapScrollin interfaceCrossfireUpdateMapListener- Parameters:
dx- the x-distancedy- the y-distance
-
faceUpdated
Description copied from interface:FacesManagerListenerCalled when aFacehas been updated.- Specified by:
faceUpdatedin interfaceFacesManagerListener- Parameters:
face- the face
-
newMap
public void newMap(int mapWidth, int mapHeight) Description copied from interface:CrossfireUpdateMapListenerA "newmap" command has been received.- Specified by:
newMapin interfaceCrossfireUpdateMapListener- Parameters:
mapWidth- the map widthmapHeight- the map height
-
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:CrossfireTickListenerA "tick" command has been received.- Specified by:
tickin interfaceCrossfireTickListener- Parameters:
tickNo- the current tick
-