22 package com.realtime.crossfire.jxclient.map;
25 import java.util.Collection;
26 import java.util.Collections;
27 import java.util.HashSet;
28 import java.util.Iterator;
30 import org.jetbrains.annotations.NotNull;
69 private final Set<Location>
locations =
new HashSet<>();
78 this.index = index%animation.
getFaces();
88 if (this.speed == speed) {
91 final int tmpIndex = index/this.
speed;
92 final int tmpDelay = Math.min(index%this.speed, speed-1);
94 index = tmpIndex*speed+tmpDelay;
112 final int diff = tickNo-this.
tickNo;
113 if (tickNo < this.tickNo) {
114 System.err.println(
"Ignoring inconsistent tick value: current tick number is "+tickNo+
", previous tick number was "+this.tickNo+
".");
116 index = (index+diff)%(speed*animation.
getFaces());
127 final int face = animation.
getFace(index/speed);
128 if (face == lastFace) {
132 for (
final Location location : locations) {
133 mapUpdaterState.mapFace(location, face,
false);
143 if (!locations.add(location)) {
144 throw new IllegalArgumentException(
"duplicate location "+location);
146 if (lastFace != -1) {
147 mapUpdaterState.mapFace(location, lastFace,
false);
156 if (!locations.remove(location)) {
157 throw new IllegalArgumentException(
"undefined location "+location);
167 return Collections.unmodifiableSet(locations).iterator();
177 public void scroll(
final int dx,
final int dy,
final int width,
final int height) {
178 final Collection<Location> tmp =
new HashSet<>();
180 for (
final Location location : locations) {
181 if (0 <= location.getX() && location.getX() < width && 0 <= location.getY() && location.getY() < height) {
182 final int newX = location.getX()-dx;
183 final int newY = location.getY()-dy;
184 if (0 <= newX && newX < width && 0 <= newY && newY < height) {
186 tmp.add(newLocation);
191 locations.addAll(tmp);
final Set< Location > locations
All map locations this animation is displayed at.
int getFace(final int index)
Returns one face of this animation.
void allocate(@NotNull final MapUpdaterState mapUpdaterState, @NotNull final Location location)
Adds this animation state to a map Location.
AnimationState(@NotNull final Animation animation, final int index)
Creates a new instance.
int getFaces()
Returns the number of faces of this animation.
void updateTickNo(@NotNull final MapUpdaterState mapUpdaterState, final int tickNo)
Sets the tick number and update affected faces.
void setTickNo(final int tickNo)
Sets the tick number.
void free(@NotNull final Location location)
Removes this animation state from a map Location.
int lastFace
Records the last known face.
Iterator< Location > iterator()
The state of an Animation on a map.
Update a CfMap model from protocol commands.
int index
The face index currently shown.
int tickNo
The face was updated last in this tick number.
final Animation animation
The Animation to display.
Manages animations received from the server.
void updateFace(@NotNull final MapUpdaterState mapUpdaterState)
Updates the map face from the state.
void scroll(final int dx, final int dy, final int width, final int height)
Scrolls all map locations.
void setSpeed(@NotNull final MapUpdaterState mapUpdaterState, final int speed)
Sets the animation speed.
int speed
The animation speed.