 |
Crossfire JXClient, Trunk
|
Go to the documentation of this file.
23 package com.realtime.crossfire.jxclient.map;
28 import java.util.Collection;
29 import java.util.HashMap;
30 import java.util.HashSet;
33 import org.jetbrains.annotations.NotNull;
34 import org.jetbrains.annotations.Nullable;
134 public void reset(
final int mapWidth,
final int mapHeight) {
160 public void setDarkness(
final int x,
final int y,
final int darkness) {
161 assert Thread.holdsLock(
this);
177 assert Thread.holdsLock(
this);
189 public void setSmooth(
final int x,
final int y,
final int layer,
final int smooth) {
191 if ((result&1) != 0) {
196 if ((result&2) != 0) {
197 for (
int dx = -1; dx <= +1; dx++) {
198 for (
int dy = -1; dy <= +1; dy++) {
212 public int getSmooth(
final int x,
final int y,
final int layer) {
223 public void setMagicMap(
final int x0,
final int y0,
final byte @NotNull [] @NotNull [] data) {
224 assert Thread.holdsLock(
this);
225 for (
int y = 0; y < data.length; y++) {
226 for (
int x = 0; x < data[y].length; x++) {
240 assert Thread.holdsLock(
this);
253 public void setFace(
final int x,
final int y,
final int layer, @Nullable
final Face face) {
254 assert Thread.holdsLock(
this);
277 if (oldFace !=
null) {
278 expandFace(x, y, layer, oldFace, headMapSquare,
null);
280 headMapSquare.
setFace(layer, face);
282 expandFace(x, y, layer, face, headMapSquare, headMapSquare);
297 final int sx = face.getTileWidth();
298 final int sy = face.getTileHeight();
299 for (
int dx = 0; dx < sx; dx++) {
300 for (
int dy = 0; dy < sy; dy++) {
301 if (dx > 0 || dy > 0) {
302 if (newMapSquare !=
null) {
320 private void dirtyFace(
final int x,
final int y,
final int layer, @NotNull
final Face face) {
321 final int sx = face.getTileWidth();
322 final int sy = face.getTileHeight();
323 for (
int dx = 0; dx < sx; dx++) {
324 for (
int dy = 0; dy < sy; dy++) {
325 if (dx > 0 || dy > 0) {
345 assert Thread.holdsLock(
this);
375 assert Thread.holdsLock(
this);
387 assert Thread.holdsLock(
this);
403 public void dirty(
final int x,
final int y) {
404 assert Thread.holdsLock(
this);
415 assert Thread.holdsLock(
this);
430 if (x < minX || x >
maxX || y < minY || y >
maxY) {
447 assert
patch !=
null;
448 assert
patch[px] !=
null;
450 if (mapPatch !=
null) {
455 assert
patch !=
null;
456 assert
patch[px] !=
null;
457 return patch[px][py];
465 private void scroll(
final int dx,
final int dy) {
466 assert Thread.holdsLock(
this);
467 if (dx == 0 && dy == 0) {
517 assert result !=
null;
528 private void increase(
final int dx,
final int dy) {
530 final int newMinX =
minX+dx;
532 final int diffPw =
minPx-newMinPx;
544 assert
patch !=
null;
545 final int oldPw =
patch.length;
546 final int oldPh =
patch[0].length;
549 assert newPw > oldPw;
550 assert newPw == oldPw+diffPw;
551 assert newPh == oldPh;
558 final int newMaxX =
maxX+dx;
560 final int diffPw = newMaxPx-
maxPx;
572 assert
patch !=
null;
573 final int oldPw =
patch.length;
574 final int oldPh =
patch[0].length;
577 assert newPw > oldPw;
578 assert newPw == oldPw+diffPw;
579 assert newPh == oldPh;
588 final int newMinY =
minY+dy;
590 final int diffPh =
minPy-newMinPy;
602 assert
patch !=
null;
603 final int oldPw =
patch.length;
604 final int oldPh =
patch[0].length;
607 assert newPh > oldPh;
608 assert newPh == oldPh+diffPh;
609 assert newPw == oldPw;
616 final int newMaxY =
maxY+dy;
618 final int diffPh = newMaxPy-
maxPy;
630 assert
patch !=
null;
631 final int oldPw =
patch.length;
632 final int oldPh =
patch[0].length;
635 assert newPh > oldPh;
636 assert newPh == oldPh+diffPh;
637 assert newPw == oldPw;
653 private static int size(
final int min,
final int max) {
665 assert Thread.holdsLock(
this);
677 assert Thread.holdsLock(
this);
688 assert Thread.holdsLock(
this);
698 assert Thread.holdsLock(
this);
713 private CfMapPatch @NotNull [] @NotNull []
copyPatches(
final int newWidth,
final int newHeight,
final int offsetX,
final int offsetY,
final int height,
final int width) {
714 assert
patch !=
null;
716 for (
int y = 0; y < width; y++) {
717 for (
int x = 0; x < height; x++) {
718 newPatch[offsetX+x][offsetY+y] =
patch[x][y];
729 assert Thread.holdsLock(
this);
740 assert Thread.holdsLock(
this);
750 assert Thread.holdsLock(
this);
762 public void updateFace(
final int faceNum,
final int width,
final int height) {
763 for (
int y = 0; y < height; y++) {
764 for (
int x = 0; x < width; x++) {
767 if (face !=
null && face.
getFaceNum() == faceNum) {
776 if (mapSquares !=
null) {
789 public boolean processMapScroll(
final int dx,
final int dy,
final int width,
final int height) {
790 if (Math.abs(dx) >= width || Math.abs(dy) >= height) {
792 for (
int y = 0; y < height; y++) {
793 for (
int x = 0; x < width; x++) {
804 for (
int y = 0; y < height; y++) {
812 for (
int y = 0; y < height; y++) {
822 for (
int x = 0; x < width; x++) {
830 for (
int x = 0; x <= width; x++) {
int getDarkness(final int x, final int y)
Determines the darkness value of one square.
int maxPy
The bottom edge of the defined patches in patch.
CfMapPatch expandTo(final int x, final int y)
(Possibly) expands the defined area of the map to a given position.
static final int SIZE
Size of patches in x- and y-direction.
void setFace(final int x, final int y, final int layer, @Nullable final Face face)
Sets the face of one square.
void setDarkness(final int x, final int y, final int darkness)
Sets the darkness value of one square.
boolean isFogOfWar(final int x, final int y)
Determines if the tile is not up-to-date.
int getSmooth(final int x, final int y, final int layer)
Determines the smooth value of one square.
CfMapSquare getHeadMapSquare(final int x, final int y, final int layer)
Returns the map square of the head of a multi-square object.
void expandFace(final int x, final int y, final int layer, @NotNull final Face face, @NotNull final CfMapSquare oldMapSquare, @Nullable final CfMapSquare newMapSquare)
Adds or removes "head" pointer to/from tail-parts of a face.
int maxY
The bottom edge of the defined tiles.
int getFaceNum()
Returns the unique face id.
Interface defining constants for the "magicmap" Crossfire protocol message.
Represents a square area of CfMapSquares.
static final int SIZE_LOG
Log2 of SIZE.
int ox
Result values for getMapPatch(int, int) and expandTo(int, int).
Represents a map (as seen by the client).
int minPy
The top edge of the defined patches in patch.
static final int DEFAULT_SMOOTH
The default smooth value for newly created squares.
int getSmooth(final int x, final int y, final int layer)
Returns the smooth value of one square.
Face getFace(final int x, final int y, final int layer)
Determines the face of one square.
void clearSquare(final int x, final int y)
Clears the content of one square.
Manages image information ("faces") needed to display the map view, items, and spell icons.
CfMapSquare getMapSquare(final int x, final int y)
Returns a map square.
CfMapPatch[][] patch
Array of (possibly) defined squares.
final Set< CfMapSquare > dirtyMapSquares
The "dirty" map squares that have been modified.
void setFace(final int layer, @Nullable final Face face)
Sets the face of a layer.
void setMagicMap(final int x0, final int y0, final byte @NotNull[] @NotNull[] data)
Sets the magic map color of one square.
int getOffsetX()
Returns the offset to convert an absolute x-coordinate of a map square (CfMapSquare#getX() to a relat...
int maxX
The right edge of the defined tiles.
final Map< Integer, Collection< CfMapSquare > > pendingFaceSquares
The map squares containing pending faces.
void setFaceInternal(final int x, final int y, final int layer, @Nullable final Face face)
Sets the face of one square.
void setSmooth(final int x, final int y, final int layer, final int smooth)
Sets the smooth value of one square.
CfMapPatch getMapPatch(final int x, final int y)
Checks if a given position is within the defined map area.
int minPx
The left edge of the defined patches in patch.
void updateFace(final int faceNum, final int width, final int height)
Processes an updated face image.
int oy
Result values for getMapPatch(int, int) and expandTo(int, int).
int getOffsetY()
Returns the offset to convert an absolute y-coordinate of a map square (CfMapSquare#getY() to a relat...
int FACE_COLOR_MASK
Bitmask in magic map information to extract the color information of a tile.
CfMapSquare getHeadMapSquare(final int x, final int y, final int layer)
Returns the map square of the head of a multi-square object.
Interface defining constants for the "map2" Crossfire protocol message.
Face getFace(final int layer)
Returns the face of a layer.
void increase(final int dx, final int dy)
Increases the defined area of the map.
static final Face DEFAULT_FACE
The default face value for newly creates squares.
void dirty(final int x, final int y)
Marks a single square as dirty.
int getColor(final int x, final int y)
Determines the magic map color value of one square.
static final int DEFAULT_COLOR
The default magic map color for newly created squares.
int getColor(final int x, final int y)
Returns the magic map color value of one square.
void dirty(final int x, final int y)
Marks a square as dirty.
int patchX
Left edge of viewable area.
CfMapSquare getSquare(final int x, final int y)
Returns one map square.
static final int DEFAULT_DARKNESS
The default darkness value for newly created squares.
void scroll(final int dx, final int dy)
Scrolls the map.
void setHeadMapSquare(final int x, final int y, final int layer, @Nullable final CfMapSquare mapSquare, final boolean setAlways)
Sets the map square containing the head face for a layer.
int NUM_LAYERS
The total number of map layers to display.
Set< CfMapSquare > getDirtyMapSquares()
Returns the dirty map squares.
int maxPx
The right edge of the defined patches in patch.
boolean processMapScroll(final int dx, final int dy, final int width, final int height)
Processes a map scroll command.
void dirtyFace(final int x, final int y, final int layer, @NotNull final Face face)
Marks one face as "dirty".
Represents a square in a CfMap.
int setSmooth(final int x, final int y, final int layer, final int smooth)
Sets the smooth value of one square.
static int size(final int min, final int max)
Calculates the number of patches needed to hold tiles between two patch coordinates.
void clearSquare(final int x, final int y)
Clears the content of one square.
void squarePendingFace(final int x, final int y, final int faceNum)
Marks a CfMapSquare as containing a pending face.
int minY
The top edge of the defined tiles.
void squareModified(@NotNull final CfMapSquare mapSquare)
Marks a CfMapSquare as dirty.
CfMapSquare getMapSquareUnlessDirty(final int x, final int y)
Returns a map square.
int patchY
Top edge of viewable area.
CfMapPatch[][] copyPatches(final int newWidth, final int newHeight, final int offsetX, final int offsetY, final int height, final int width)
Returns a copy of a rectangular area of patch.
void setColor(final int x, final int y, final int color)
Sets the magic map color of one square.
void reset(final int mapWidth, final int mapHeight)
Clears the map contents.
int getDarkness(final int x, final int y)
Returns the darkness value of one square.
void setHeadMapSquare(final int x, final int y, final int layer, @Nullable final CfMapSquare mapSquare, final boolean setAlways)
Sets the map square containing the head face for a layer.
boolean isFogOfWar(final int x, final int y)
Determines if a square is not up-to-date.
Face getFace(final int x, final int y, final int layer)
Determines the face of one square.
int minX
The left edge of the defined tiles.