 |
Crossfire JXClient, Trunk
|
Go to the documentation of this file.
23 package com.realtime.crossfire.jxclient.map;
33 import java.util.ArrayList;
34 import java.util.Collection;
35 import java.util.HashMap;
36 import java.util.HashSet;
38 import java.util.Random;
39 import java.util.random.RandomGenerator;
40 import org.jetbrains.annotations.NotNull;
41 import org.jetbrains.annotations.Nullable;
53 private static final Object
SYNC =
new Object();
84 private final RandomGenerator
random =
new Random();
90 @SuppressWarnings(
"FieldCanBeLocal")
94 public void playerChanged(@Nullable
final CfItem player) {
95 if (!
tags.isEmpty()) {
96 System.err.println(
"Warning: player inventory is not empty when changing players");
97 for (
final int tag :
tags.values()) {
106 playerTag = player ==
null ? -1 : player.getTag();
113 public void openContainerChanged(
final int tag) {
122 @SuppressWarnings(
"FieldAccessedSynchronizedAndUnsynchronized")
127 public Object mapBegin() {
132 public void mapFace(@NotNull
final Location location,
final int faceNum) {
136 public void mapEnd() {
190 public void itemChanged(
final int tag) {
194 public void itemRemoved(
final int tag) {
198 public void inventoryAdded(
final int tag,
final int index, @NotNull
final CfItem item) {
199 final int itemTag = item.getTag();
200 final int anim = item.getAnim();
201 final int animSpeed = item.getAnimSpeed();
204 if (animation ==
null) {
206 System.err.println(
"Unknown animation id "+(anim&
Map2.
ANIM_MASK)+
", ignoring");
211 final Integer prevTag =
tags.put(index, itemTag);
212 if (prevTag !=
null) {
221 public void inventoryRemoved(
final int tag,
final int index) {
222 final Integer prevTag =
tags.remove(index);
223 if (prevTag ==
null) {
236 private final Map<Integer, Integer>
tags =
new HashMap<>();
273 animationState.freeAllLocations();
342 public void tick(
final int tickNo) {
344 animationState.setTickNo(tickNo);
347 final Iterable<AnimationState> animationStatesToUpdate =
new ArrayList<>(
animationStates);
350 animationState.updateTickNo(tickNo);
362 private void tagAdd(
final int tag, @NotNull
final Animation animation,
final int type) {
382 assert 0 <= type && type < 4;
385 final boolean addToPendingTickUpdates;
390 addToPendingTickUpdates =
true;
395 addToPendingTickUpdates =
true;
399 final int animationId = animation.getAnimationId();
404 addToPendingTickUpdates =
true;
406 animationState = tmp;
407 addToPendingTickUpdates =
false;
413 if (addToPendingTickUpdates) {
417 return animationState;
final ItemSet itemSet
The ItemSet to notify of changes.
Maintains a mapping of face numbers to face data.
void addInventoryListener(final int tag, @NotNull final ItemListener listener)
Adds an ItemListener to be notified about changes.
final Collection< AnimationState > pendingTickUpdates
The AnimationState instances that have been added but not yet received a "tick" value.
void remove(@NotNull final Location location)
Clears a Location.
Model class maintaining the CfItems known to the player.
CfAnimations(@NotNull final ItemSet itemSet, @NotNull final FacesManager facesManager, @NotNull final Animations animations)
Creates a new instance.
final Collection< Integer > unknownAnimations
The animation IDs for which a warning has been printed.
Animation get(final int animationId)
Returns the animation for an animation id.
CfAnimationsMapListener mapListener
The CfAnimationsMapListener that is notified of changes.
int ANIM_RANDOM
Animation type: randomized animation.
final FacesManager facesManager
The FacesManager to track for updated faces.
final AnimationSet tagAnimations
The animations in the player's inventory.
Interface for listeners for changes of item locations.
void mapRemove(@NotNull final Location location)
Removes a visible map animation.
Manages animations received from the server.
final AnimationMap mapAnimations
The animations in the visible map area.
int ANIM_SYNC
Animation type: synchronized animation.
Manages animations received from the server.
Manages image information ("faces") needed to display the map view, items, and spell icons.
int mapWidth
The width of the visible map area.
void mapSetSize(final int mapWidth, final int mapHeight)
Updates the map size.
void mapEnd()
Parsing of "map2" has been finished.
int ANIM_MASK
The mask for extracting the animation ID.
static final Object SYNC
Dummy synchronization object if no map listener has been set.
final Map< Integer, Integer > tags
Maps inventory index to item tag.
void tagAdd(final int tag, @NotNull final Animation animation, final int type)
Adds a visible animation for an item tag.
int ANIM_NORMAL
Animation type: normal animation.
void setMapListener(@NotNull final CfAnimationsMapListener mapListener)
Sets the CfAnimationsMapListener to notify of changes.
void mapScroll(final int dx, final int dy)
Scrolls the map animations.
final Collection< AnimationState > animationStates
All AnimationState instances referenced by mapAnimations or tagAnimations.
void mapUpdateSpeed(@NotNull final Location location, final int speed)
Updates the map animation speed value.
void add(final int tag, @NotNull final AnimationState animationState)
Adds a new AnimationState for an item tag.
The representation of a Crossfire Item, client-side.
int ANIM_TYPE_SHIFT
The lowest bit of the animation type.
Collection< AnimationState > getAllAnimationStates()
Returns all AnimationState instances.
void tagRemove(final int tag)
Removes a visible animation for an item tag.
AnimationState add(@NotNull final Animation animation, final int type)
Adds a visible animation.
void clear()
Forgets all state.
final RandomGenerator random
The random number generator for Map2#ANIM_RANDOM type animations.
Interface defining constants for the "map2" Crossfire protocol message.
void updateSpeed(final int tag, final int speed)
Updates the animation speed value of an item tag.
void scroll(final int dx, final int dy, final int width, final int height)
Scrolls all locations.
int playerTag
The tag of the player object or.
Manages a set of animated faces.
void addItemSetListener(@NotNull final ItemSetListener listener)
Adds an ItemSetListener to be notified about changes.
void tick(final int tickNo)
Processes a tick command.
void remove(final int tag)
Clears an item tag.
void mapRemove(final int x, final int y)
Removes all visible map animations for a tile.
int mapHeight
The height of the visible map area.
final Map< Integer, AnimationState > syncAnimationStates
All AnimationState for Map2#ANIM_SYNC animations.
Maintains AnimationState instances for item tag values.
Object mapBegin()
Parsing of a "map2" command has been started.
int NUM_LAYERS
The total number of map layers to display.
void mapAdd(@NotNull final Location location, @NotNull final Animation animation, final int type)
Adds a visible map animation.
The state of an Animation on a map.
Interface for listeners in ItemSet related events.
void add(@NotNull final Location location, @NotNull final AnimationState animationState)
Adds a new AnimationState to a Location.
int ANIM_TYPE_MASK
The mask for extracting the animation type.
void mapClear()
Forgets all map animations.
Maintains AnimationState instances for map locations.
final ItemListener playerInventoryListener
Listener added to all items in itemSet.
void updateSpeed(@NotNull final Location location, final int speed)
Updates the animation speed value of a Location.
final ItemSetListener itemSetListener
The listener added to itemSet.
void removeInventoryListener(final int tag, @NotNull final ItemListener listener)
Removes an ItemListener to be notified about changes.
final Animations animations
The global Animations instance.