public class MapUpdaterState extends java.lang.Object implements CrossfireTickListener, CrossfireUpdateMapListener, FacesManagerListener
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
.
Modifier and Type | Field and Description |
---|---|
private Animations |
animations
The defined animations.
|
private FacesManager |
facesManager
The
FacesManager to track for updated faces. |
private CfMap |
map
The current
CfMap instance. |
private int |
mapHeight
The height of the visible map area.
|
private EventListenerList2<MapListener> |
mapListeners
The listeners to notify about changed map squares.
|
private EventListenerList2<MapScrollListener> |
mapScrollListeners
The listeners to notify about scrolled maps.
|
private EventListenerList2<MapSizeListener> |
mapSizeListeners
The
MapSizeListeners to be notified. |
private int |
mapWidth
The width of the visible map area.
|
private EventListenerList2<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.
|
Constructor and Description |
---|
MapUpdaterState(FacesManager facesManager,
GuiStateManager guiStateManager)
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
void |
addAnimation(int animation,
int flags,
int[] faces)
An "addanim" command has been received.
|
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.
|
void |
faceUpdated(Face face)
Called when a
Face has been updated. |
CfMap |
getMap()
Returns the current map instance.
|
int |
getMapHeight()
Returns the height of the visible map area.
|
int |
getMapWidth()
Returns the width of the visible map area.
|
void |
magicMap(int x,
int y,
byte[][] data)
Part of "magicmap" parsing: set the magic map color.
|
void |
mapAnimation(Location location,
int animationNum,
int animationType)
Part of "map2" parsing: set the animation of a cell.
|
void |
mapAnimationSpeed(Location location,
int animationSpeed)
Part of "map2" parsing: set the animation speed.
|
java.lang.Object |
mapBegin()
Parsing of a "map2" command has been started.
|
void |
mapClear(int x,
int y)
Part of "map2" parsing: clear a cell.
|
void |
mapDarkness(int x,
int y,
int darkness)
Part of "map2" parsing: change the darkness of a cell.
|
void |
mapEnd()
Parsing of "map2" has been finished.
|
void |
mapEnd(boolean alwaysProcess)
Finishes processing of a set of map square changes.
|
void |
mapFace(Location location,
int faceNum)
Part of "map2" parsing: set the face of a cell.
|
void |
mapFace(Location location,
int faceNum,
boolean clearAnimation)
Updates a map square by changing a face.
|
void |
mapScroll(int dx,
int dy)
Part of "map2" parsing: scroll the map view.
|
void |
mapSmooth(Location location,
int smooth)
Part of "map2" parsing: set the smooth level.
|
void |
newMap(int mapWidth,
int mapHeight)
A "newmap" command has been received.
|
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.
|
void |
reset()
Resets the animation state.
|
void |
tick(int tickNo)
A "tick" command has been received.
|
@NotNull private final Animations animations
@NotNull private final FacesManager facesManager
FacesManager
to track for updated faces.private int mapHeight
@NotNull private final EventListenerList2<MapListener> mapListeners
@NotNull private final EventListenerList2<MapScrollListener> mapScrollListeners
@NotNull private final EventListenerList2<MapSizeListener> mapSizeListeners
MapSizeListeners
to be notified.private int mapWidth
@NotNull private final EventListenerList2<NewmapListener> newmapListeners
@NotNull private final java.util.Collection<Location> outOfViewMultiFaces
@NotNull private final java.lang.Object sync
@NotNull private final CfMapAnimations visibleAnimations
public MapUpdaterState(@NotNull FacesManager facesManager, @Nullable GuiStateManager guiStateManager)
facesManager
- the faces manager to track for updated facesguiStateManager
- the gui state manager to watch or null
public void addAnimation(int animation, int flags, @NotNull int[] faces)
addAnimation
in interface CrossfireUpdateMapListener
animation
- the animation IDflags
- the animation flagsfaces
- the faces list; must not be modifiedpublic void addCrossfireMapListener(@NotNull MapListener listener)
listener
- the listener to addpublic void addCrossfireMapScrollListener(@NotNull MapScrollListener listener)
listener
- the listener to addpublic void addCrossfireNewmapListener(@NotNull NewmapListener listener)
listener
- the listener to addpublic void addMapSizeListener(@NotNull MapSizeListener listener)
listener
- the listener to addpublic void faceUpdated(@NotNull Face face)
Face
has been updated.faceUpdated
in interface FacesManagerListener
face
- the face@NotNull public CfMap getMap()
public int getMapHeight()
public int getMapWidth()
public void magicMap(int x, int y, byte[][] data)
magicMap
in interface CrossfireUpdateMapListener
x
- the x-coordinatey
- the y-coordinatedata
- the magic map data (y, x); must not be changedpublic void mapAnimation(@NotNull Location location, int animationNum, int animationType)
mapAnimation
in interface CrossfireUpdateMapListener
location
- the locationanimationNum
- the animation IDanimationType
- the animation typepublic void mapAnimationSpeed(@NotNull Location location, int animationSpeed)
mapAnimationSpeed
in interface CrossfireUpdateMapListener
location
- the locationanimationSpeed
- the animation speed@NotNull public java.lang.Object mapBegin()
mapBegin
in interface CrossfireUpdateMapListener
synchronized
while calling any other function (except newMap()
)public void mapClear(int x, int y)
mapClear
in interface CrossfireUpdateMapListener
x
- the x-coordinatey
- the y-coordinatepublic void mapDarkness(int x, int y, int darkness)
mapDarkness
in interface CrossfireUpdateMapListener
x
- the x-coordinatey
- the y-coordinatedarkness
- the darkness valuepublic void mapEnd()
mapEnd
in interface CrossfireUpdateMapListener
public void mapEnd(boolean alwaysProcess)
alwaysProcess
- if set, notify listeners even if no changes are
presentpublic void mapFace(@NotNull Location location, int faceNum)
mapFace
in interface CrossfireUpdateMapListener
location
- the locationfaceNum
- the face IDpublic void mapFace(@NotNull Location location, int faceNum, boolean clearAnimation)
location
- the location to updatefaceNum
- the face to set; 0
clears the squareclearAnimation
- whether an animation should be clearedpublic void mapScroll(int dx, int dy)
mapScroll
in interface CrossfireUpdateMapListener
dx
- the x-distancedy
- the y-distancepublic void mapSmooth(@NotNull Location location, int smooth)
mapSmooth
in interface CrossfireUpdateMapListener
location
- the locationsmooth
- the smooth valuepublic void newMap(int mapWidth, int mapHeight)
newMap
in interface CrossfireUpdateMapListener
mapWidth
- the map widthmapHeight
- the map heightpublic void removeCrossfireMapListener(@NotNull MapListener listener)
listener
- the listener to removepublic void removeCrossfireMapScrollListener(@NotNull MapScrollListener listener)
listener
- the listener to removepublic void removeCrossfireNewmapListener(@NotNull NewmapListener listener)
listener
- the listener to removepublic void removeMapSizeListener(@NotNull MapSizeListener listener)
listener
- the listener to removepublic void reset()
public void tick(int tickNo)
tick
in interface CrossfireTickListener
tickNo
- the current tick