22 package com.realtime.crossfire.jxclient.map;
26 import java.util.ArrayList;
27 import java.util.Collection;
28 import java.util.HashMap;
30 import java.util.Random;
31 import java.util.WeakHashMap;
32 import org.jetbrains.annotations.NotNull;
45 private final Random
random =
new Random();
87 animationStates.clear();
88 syncAnimationStates.clear();
89 pendingTickUpdates.clear();
100 assert 0 <= location.getX();
101 assert 0 <= location.getY();
102 assert 0 <= type && type < 4;
105 final boolean addToPendingTickUpdates;
110 addToPendingTickUpdates =
true;
114 animationState =
new AnimationState(animation, random.nextInt(animation.getFaces()));
115 addToPendingTickUpdates =
true;
119 final int animationId = animation.getAnimationId();
123 syncAnimationStates.put(animationId, animationState);
124 addToPendingTickUpdates =
true;
126 animationState = tmp;
127 addToPendingTickUpdates =
false;
132 animationStates.put(animationState, null);
133 animations.
add(mapUpdaterState, location, animationState);
134 if (addToPendingTickUpdates) {
135 pendingTickUpdates.add(animationState);
144 public void remove(
final int x,
final int y) {
154 public void remove(@NotNull
final Location location) {
155 animations.
remove(location);
165 animations.
updateSpeed(mapUpdaterState, location, speed);
174 public void scroll(
final int dx,
final int dy) {
175 animations.
scroll(dx, dy, width, height);
185 animationState.setTickNo(tickNo);
187 pendingTickUpdates.clear();
188 final Iterable<AnimationState> animationStatesToUpdate =
new ArrayList<>(animationStates.keySet());
189 synchronized (mapUpdaterState.mapBegin()) {
190 for (
final AnimationState animationState : animationStatesToUpdate) {
191 animationState.updateTickNo(mapUpdaterState, tickNo);
193 mapUpdaterState.mapEnd(
false);
final Map< AnimationState, Void > animationStates
All AnimationState instances referenced by animations.
void updateSpeed(@NotNull final MapUpdaterState mapUpdaterState, @NotNull final Location location, final int speed)
Updates the animation speed value.
void clear()
Forgets all animations.
Maintains AnimationState instances for map locations.
void scroll(final int dx, final int dy, final int width, final int height)
Scrolls all locations.
void remove(@NotNull final Location location)
Clears a Location.
void add(@NotNull final MapUpdaterState mapUpdaterState, @NotNull final Location location, @NotNull final Animation animation, final int type)
Adds a visible animation.
int NUM_LAYERS
The total number of map layers to display.
void scroll(final int dx, final int dy)
Scrolls the animations.
final Map< Integer, AnimationState > syncAnimationStates
All AnimationState for Map2#ANIM_SYNC animations.
void clear()
Forgets all state.
Interface defining constants for the "map2" Crossfire protocol message.
Manages a set of animated map squares.
final Random random
The random number generator for Map2#ANIM_RANDOM type animations.
int height
The height of the visible map area.
The state of an Animation on a map.
Update a CfMap model from protocol commands.
void tick(@NotNull final MapUpdaterState mapUpdaterState, final int tickNo)
Processes a tick command.
void add(@NotNull final MapUpdaterState mapUpdaterState, @NotNull final Location location, @NotNull final AnimationState animationState)
Adds a new AnimationState to a Location.
int ANIM_SYNC
Animation type: synchronized animation.
int ANIM_RANDOM
Animation type: randomized animation.
void updateSpeed(@NotNull final MapUpdaterState mapUpdaterState, @NotNull final Location location, final int speed)
Updates the animation speed value of a Location.
Manages animations received from the server.
void setMapSize(final int width, final int height)
Updates the map size.
int width
The width of the visible map area.
final Collection< AnimationState > pendingTickUpdates
The AnimationState instances that have been added but not yet received a "tick" value.
final AnimationMap animations
The animations in the visible map area.
int ANIM_NORMAL
Animation type: normal animation.