22 package com.realtime.crossfire.jxclient.map;
33 import java.util.Collection;
34 import java.util.HashSet;
36 import org.jetbrains.annotations.NotNull;
37 import org.jetbrains.annotations.Nullable;
56 private final Object
sync =
new Object();
137 mapListeners.
add(listener);
145 mapListeners.
remove(listener);
153 newmapListeners.
add(listener);
161 newmapListeners.
remove(listener);
169 mapScrollListeners.
add(listener);
177 mapScrollListeners.
remove(listener);
185 mapSizeListeners.
add(listener);
193 mapSizeListeners.
remove(listener);
200 synchronized (
sync) {
201 newMap(mapWidth, mapHeight);
219 assert Thread.holdsLock(sync);
220 visibleAnimations.
remove(x, y);
221 outOfViewMultiFaces.clear();
232 mapFace(location, faceNum,
true);
241 public void mapFace(@NotNull
final Location location,
final int faceNum,
final boolean clearAnimation) {
242 assert Thread.holdsLock(sync);
243 if (clearAnimation) {
244 visibleAnimations.
remove(location);
247 final int x = location.getX();
248 final int y = location.getY();
249 if (x >= mapWidth || y >= mapHeight) {
251 outOfViewMultiFaces.remove(location);
253 outOfViewMultiFaces.add(location);
257 map.
setFace(x, y, location.getLayer(), face);
266 assert Thread.holdsLock(sync);
267 final Animation animation = animations.
get(animationNum);
268 if (animation == null) {
269 System.err.println(
"unknown animation id "+animationNum+
", ignoring");
274 map.
setFace(location.getX(), location.getY(), location.getLayer(), null);
276 visibleAnimations.
add(
this, location, animation, animationType);
284 assert Thread.holdsLock(sync);
285 visibleAnimations.
updateSpeed(
this, location, animationSpeed);
293 assert Thread.holdsLock(sync);
295 map.
setSmooth(location.getX(), location.getY(), location.getLayer(), smooth);
303 public void mapDarkness(
final int x,
final int y,
final int darkness) {
304 assert Thread.holdsLock(sync);
314 public void magicMap(
final int x,
final int y,
final byte[][] data) {
315 assert Thread.holdsLock(sync);
335 public void mapEnd(
final boolean alwaysProcess) {
336 assert Thread.holdsLock(sync);
339 if (!alwaysProcess && squares.isEmpty()) {
344 listener.mapChanged(map, squares);
354 assert Thread.holdsLock(sync);
356 for (
final Location location : outOfViewMultiFaces) {
357 visibleAnimations.
remove(location);
358 map.
setFace(location.getX(), location.getY(), location.getLayer(), null);
360 outOfViewMultiFaces.clear();
363 visibleAnimations.
clear();
365 visibleAnimations.
scroll(dx, dy);
370 mapscrollListener.mapScrolled(dx, dy);
392 public void newMap(
final int mapWidth,
final int mapHeight) {
393 synchronized (
sync) {
394 final boolean changed = this.mapWidth != mapWidth || this.mapHeight !=
mapHeight;
399 map.
reset(mapWidth, mapHeight);
402 visibleAnimations.
setMapSize(mapWidth, mapHeight);
406 listener.mapSizeChanged(mapWidth, mapHeight);
411 listener.commandNewmapReceived();
445 public void addAnimation(
final int animation,
final int flags, @NotNull
final int[] faces) {
453 public void tick(
final int tickNo) {
454 synchronized (
sync) {
455 visibleAnimations.
tick(
this, tickNo);
void addAnimation(final int animation, final int flags, @NotNull final int[] faces)
An "addanim" command has been received.the animation ID the animation flags the faces list; must not ...
void removeMapSizeListener(@NotNull final MapSizeListener listener)
Removes a listener to be notified about map size changes.
Face getFace2(int faceNum)
Returns the Face instance for a given face ID.
void addMapSizeListener(@NotNull final MapSizeListener listener)
Adds a listener to be notified about map size changes.
final CfMap map
The current CfMap instance.
int getMapHeight()
Returns the height of the visible map area.
void setFace(final int x, final int y, final int layer, @Nullable final Face face)
Sets the face of one square.
Maintains the current GuiState.
int getMapWidth()
Returns the width of the visible map area.
final CfMapAnimations visibleAnimations
The animations in the visible map area.
void setDarkness(final int x, final int y, final int darkness)
Sets the darkness value of one square.
void addCrossfireNewmapListener(@NotNull final NewmapListener listener)
Adds a listener to notify about cleared maps.
void mapClear(final int x, final int y)
Part of "map2" parsing: clear a cell.the x-coordinate the y-coordinate
void addAnimation(final int animationId, final int flags, @NotNull final int[] faces)
Defines a new animation.
CfMap getMap()
Returns the current map instance.
Represents a map (as seen by the client).
final Animations animations
The defined animations.
int getTileHeight()
Returns the face height in tiles.
A list of event listeners.
void updateSpeed(@NotNull final MapUpdaterState mapUpdaterState, @NotNull final Location location, final int speed)
Updates the animation speed value.
final Object sync
The object used for synchronization.
void clear()
Forgets all animations.
void removeCrossfireNewmapListener(@NotNull final NewmapListener listener)
Removes a listener to notify about cleared maps.
final Collection< Location > outOfViewMultiFaces
All multi-tiled faces with heads outside the visible map area.
void clearSquare(final int x, final int y)
Clears the content of one square.
Interface for listeners interested in "tick" commands.
Set< CfMapSquare > getDirtyMapSquares()
Returns the dirty map squares.
void mapSmooth(@NotNull final Location location, final int smooth)
Part of "map2" parsing: set the smooth level.the location the smooth value
void mapDarkness(final int x, final int y, final int darkness)
Part of "map2" parsing: change the darkness of a cell.the x-coordinate the y-coordinate the darkness ...
void add(@NotNull final MapUpdaterState mapUpdaterState, @NotNull final Location location, @NotNull final Animation animation, final int type)
Adds a visible animation.
void removeCrossfireMapScrollListener(@NotNull final MapScrollListener listener)
Removes a listener to notify about scrolled maps.
Object mapBegin()
Parsing of a "map2" command has been started.the synchronization object which must besynchronized wh...
Manages image information ("faces") needed to display the map view, items, and spell icons...
final FacesManager facesManager
The FacesManager to track for updated faces.
final EventListenerList2< NewmapListener > newmapListeners
The listeners to notify about cleared maps.
final EventListenerList2< MapSizeListener > mapSizeListeners
The MapSizeListeners to be notified.
void addCrossfireMapScrollListener(@NotNull final MapScrollListener listener)
Adds a listener to notify about scrolled maps.
boolean processMapScroll(final int dx, final int dy, final int width, final int height)
Processes a map scroll command.
Listener for clients interested in map size changes.
void scroll(final int dx, final int dy)
Scrolls the animations.
void reset()
Resets the animation state.
void reset(final int mapWidth, final int mapHeight)
Clears the map contents.
void updateFace(final int faceNum, final int width, final int height)
Processes an updated face image.
MapUpdaterState(@NotNull final FacesManager facesManager, @Nullable final GuiStateManager guiStateManager)
Creates a new instance.
Manages a set of animated map squares.
void setMagicMap(final int x0, final int y0, final byte[][] data)
Sets the magic map color of one square.
void remove(final int x, final int y)
Removes all visible animations for a tile.
void mapFace(@NotNull final Location location, final int faceNum, final boolean clearAnimation)
Updates a map square by changing a face.
Interface for listeners interested in changes within CfMap instances.
void mapAnimationSpeed(@NotNull final Location location, final int animationSpeed)
Part of "map2" parsing: set the animation speed.the location the animation speed
Interface for listeners interested in FacesManager events.
void addCrossfireMapListener(@NotNull final MapListener listener)
Adds a listener to notify about changed map squares.
Update a CfMap model from protocol commands.
void add(@NotNull final T listener)
Adds a listener.
void mapAnimation(@NotNull final Location location, final int animationNum, final int animationType)
Part of "map2" parsing: set the animation of a cell.the location the animation ID the animation type ...
void magicMap(final int x, final int y, final byte[][] data)
Part of "magicmap" parsing: set the magic map color.the x-coordinate the y-coordinate the magic map d...
void tick(@NotNull final MapUpdaterState mapUpdaterState, final int tickNo)
Processes a tick command.
int getTileWidth()
Returns the face width in tiles.
Manages animations received from the server.
void faceUpdated(@NotNull final Face face)
Called when a Face has been updated.the face
void setMapSize(final int width, final int height)
Updates the map size.
int mapWidth
The width of the visible map area.
final EventListenerList2< MapListener > mapListeners
The listeners to notify about changed map squares.
void mapScroll(final int dx, final int dy)
Part of "map2" parsing: scroll the map view.the x-distance the y-distance
void mapEnd(final boolean alwaysProcess)
Finishes processing of a set of map square changes.
Interface for listeners interested in received "newmap" messages.
final EventListenerList2< MapScrollListener > mapScrollListeners
The listeners to notify about scrolled maps.
void removeCrossfireMapListener(@NotNull final MapListener listener)
Removes a listener to notify about changed map squares.
int mapHeight
The height of the visible map area.
Animation get(final int animationId)
Returns the animation for an animation id.
void remove(@NotNull final T listener)
Removes a listener.
void mapEnd()
Parsing of "map2" has been finished.
Manages animations received from the server.
Interface for listeners interested in map related commands.
void tick(final int tickNo)
A "tick" command has been received.the current tick
void newMap(final int mapWidth, final int mapHeight)
A "newmap" command has been received.the map width the map height
void mapFace(@NotNull final Location location, final int faceNum)
Part of "map2" parsing: set the face of a cell.the location the face ID
void setSmooth(final int x, final int y, final int layer, final int smooth)
Sets the smooth value of one square.
Maintains a mapping of face numbers to face data.