public class CfMap
extends java.lang.Object
CfMapSquares
can be stored.
The map will be automatically enlarged by accesses to new squares. Not yet set squares are considered dark.
All accesses must be synchronized on the map instance.
Modifier and Type | Field and Description |
---|---|
private java.util.Set<CfMapSquare> |
dirtyMapSquares
The "dirty" map squares that have been modified.
|
private int |
maxPx
The right edge of the defined patches in
patch . |
private int |
maxPy
The bottom edge of the defined patches in
patch . |
private int |
maxX
The right edge of the defined tiles.
|
private int |
maxY
The bottom edge of the defined tiles.
|
private int |
minPx
The left edge of the defined patches in
patch . |
private int |
minPy
The top edge of the defined patches in
patch . |
private int |
minX
The left edge of the defined tiles.
|
private int |
minY
The top edge of the defined tiles.
|
private int |
ox
Result values for
getMapPatch(int, int) and expandTo(int, int) . |
private int |
oy
Result values for
getMapPatch(int, int) and expandTo(int, int) . |
private CfMapPatch[][] |
patch
Array of (possibly) defined squares.
|
private int |
patchX
Left edge of viewable area.
|
private int |
patchY
Top edge of viewable area.
|
private java.util.Map<java.lang.Integer,java.util.Collection<CfMapSquare>> |
pendingFaceSquares
The map squares containing pending faces.
|
Constructor and Description |
---|
CfMap() |
Modifier and Type | Method and Description |
---|---|
void |
clearSquare(int x,
int y)
Clears the content of one square.
|
private CfMapPatch[][] |
copyPatches(int newWidth,
int newHeight,
int offsetX,
int offsetY,
int height,
int width)
Returns a copy of a rectangular area of
patch . |
void |
dirty(int x,
int y)
Marks a single square as dirty.
|
private void |
dirtyFace(int x,
int y,
int layer,
Face face)
Marks one face as "dirty".
|
private void |
expandFace(int x,
int y,
int layer,
Face face,
CfMapSquare oldMapSquare,
CfMapSquare newMapSquare)
Adds or removes "head" pointer to/from tail-parts of a face.
|
private CfMapPatch |
expandTo(int x,
int y)
(Possibly) expands the defined area of the map to a given position.
|
int |
getColor(int x,
int y)
Returns the magic map color value of one square.
|
int |
getDarkness(int x,
int y)
Returns the darkness value of one square.
|
java.util.Set<CfMapSquare> |
getDirtyMapSquares()
Returns the dirty map squares.
|
Face |
getFace(int x,
int y,
int layer)
Determines the face of one square.
|
CfMapSquare |
getHeadMapSquare(int x,
int y,
int layer)
Returns the map square of the head of a multi-square object.
|
private CfMapPatch |
getMapPatch(int x,
int y)
Checks if a given position is within the defined map area.
|
CfMapSquare |
getMapSquare(int x,
int y)
Returns a map square.
|
CfMapSquare |
getMapSquareUnlessDirty(int x,
int y)
Returns a map square.
|
int |
getOffsetX()
Returns the offset to convert an absolute x-coordinate of a map square
(
CfMapSquare.getX() to a relative x-coordinate. |
int |
getOffsetY()
Returns the offset to convert an absolute y-coordinate of a map square
(
CfMapSquare.getY() to a relative y-coordinate. |
int |
getSmooth(int x,
int y,
int layer)
Returns the smooth value of one square.
|
private void |
increase(int dx,
int dy)
Increases the defined area of the map.
|
boolean |
isFogOfWar(int x,
int y)
Determines if the tile is not up-to-date.
|
boolean |
processMapScroll(int dx,
int dy,
int width,
int height)
Processes a map scroll command.
|
void |
reset(int mapWidth,
int mapHeight)
Clears the map contents.
|
private void |
scroll(int dx,
int dy)
Scrolls the map.
|
void |
setDarkness(int x,
int y,
int darkness)
Sets the darkness value of one square.
|
void |
setFace(int x,
int y,
int layer,
Face face)
Sets the face of one square.
|
private void |
setFaceInternal(int x,
int y,
int layer,
Face face)
Sets the face of one square.
|
private void |
setHeadMapSquare(int x,
int y,
int layer,
CfMapSquare mapSquare,
boolean setAlways)
Sets the map square containing the head face for a layer.
|
void |
setMagicMap(int x0,
int y0,
byte[][] data)
Sets the magic map color of one square.
|
void |
setSmooth(int x,
int y,
int layer,
int smooth)
Sets the smooth value of one square.
|
private static int |
size(int min,
int max)
Calculates the number of patches needed to hold tiles between two patch
coordinates.
|
void |
squareModified(CfMapSquare mapSquare)
Marks a
CfMapSquare as dirty. |
void |
squarePendingFace(int x,
int y,
int faceNum)
Marks a
CfMapSquare as containing a pending face. |
void |
updateFace(int faceNum,
int width,
int height)
Processes an updated face image.
|
@NotNull private final java.util.Set<CfMapSquare> dirtyMapSquares
private int maxPx
patch
.private int maxPy
patch
.private int maxX
private int maxY
private int minPx
patch
.private int minPy
patch
.private int minX
private int minY
private int ox
getMapPatch(int, int)
and expandTo(int, int)
.private int oy
getMapPatch(int, int)
and expandTo(int, int)
.@Nullable private CfMapPatch[][] patch
private int patchX
private int patchY
@NotNull private final java.util.Map<java.lang.Integer,java.util.Collection<CfMapSquare>> pendingFaceSquares
public void clearSquare(int x, int y)
x
- the x-coordinate of the squarey
- the y-coordinate of the square@NotNull private CfMapPatch[][] copyPatches(int newWidth, int newHeight, int offsetX, int offsetY, int height, int width)
patch
.newWidth
- the width of the new areanewHeight
- the height of the new areaoffsetX
- the x-offset into the new areaoffsetY
- the y-offset into the new areaheight
- the height of the area to copywidth
- the width of the area to copypublic void dirty(int x, int y)
x
- the x-coordinate of the squarey
- the y-coordinate of the squareprivate void dirtyFace(int x, int y, int layer, @NotNull Face face)
x
- the x-coordinate of the tail part of the facey
- the y-coordinate of the tail part of the facelayer
- the layer of the faceface
- the face to mark dirtyprivate void expandFace(int x, int y, int layer, @NotNull Face face, @NotNull CfMapSquare oldMapSquare, @Nullable CfMapSquare newMapSquare)
x
- the x-coordinate of the tail part to expandy
- the y-coordinate of the tail part to expandlayer
- the layer to expandface
- the face to expandoldMapSquare
- the map square of the tail partnewMapSquare
- the map square of the tail part to add pointers, or
null
to remove pointers@NotNull private CfMapPatch expandTo(int x, int y)
x
- the x-coordinate to expand the defined area toy
- the y-coordinate to expand the defined area tonull
if the coordinates are out of map
boundspublic int getColor(int x, int y)
x
- the x-coordinate of the squarey
- the y-coordinate of the squarepublic int getDarkness(int x, int y)
x
- the x-coordinate of the squarey
- the y-coordinate of the square@NotNull public java.util.Set<CfMapSquare> getDirtyMapSquares()
@Nullable public Face getFace(int x, int y, int layer)
x
- the x-coordinate of the squarey
- the y-coordinate of the squarelayer
- the layer of the facenull
@Nullable public CfMapSquare getHeadMapSquare(int x, int y, int layer)
x
- the x-coordinate of the squarey
- the y-coordinate of the squarelayer
- the layer to return the head fornull
if this square does not
contain a multi-tail@Nullable private CfMapPatch getMapPatch(int x, int y)
x
- the x-coordinate to checky
- the y-coordinate to checknull
if the coordinates are out of map
bounds@NotNull public CfMapSquare getMapSquare(int x, int y)
x
- the x-coordinatey
- the y-coordinate@Nullable public CfMapSquare getMapSquareUnlessDirty(int x, int y)
x
- the x-coordinatey
- the y-coordinatenull
if it would be dirtypublic int getOffsetX()
CfMapSquare.getX()
to a relative x-coordinate.public int getOffsetY()
CfMapSquare.getY()
to a relative y-coordinate.public int getSmooth(int x, int y, int layer)
x
- the x-coordinate of the squarey
- the y-coordinate of the squarelayer
- the layer of the squareprivate void increase(int dx, int dy)
dx
- the increase in x-direction; dx<0 means "expand (-dx) tiles
to the left", dx>0 means "expand (dx) tiles to the right"dy
- the increase in y-direction; dy<0 means "expand (-dy) tiles
to the top", dy>0 means "expand (dy) tiles to the bottom"public boolean isFogOfWar(int x, int y)
x
- the x-coordinate of the squarey
- the y-coordinate of the squarepublic boolean processMapScroll(int dx, int dy, int width, int height)
dx
- the distance to scroll in x-direction in squaresdy
- the distance to scroll in y-direction in squareswidth
- the width of the visible map area in map squaresheight
- the height of the visible map area in map squarespublic void reset(int mapWidth, int mapHeight)
mapWidth
- the width of the visible map areamapHeight
- the height of the visible map areaprivate void scroll(int dx, int dy)
dx
- the x-difference to scrolldy
- the y-difference to scrollpublic void setDarkness(int x, int y, int darkness)
x
- the x-coordinate of the squarey
- the y-coordinate of the squaredarkness
- the darkness value to set; 0=dark, 255=full brightpublic void setFace(int x, int y, int layer, @Nullable Face face)
x
- the x-coordinate of the squarey
- the y-coordinate of the squarelayer
- the layer to setface
- the face to set; may be null
to remove the faceprivate void setFaceInternal(int x, int y, int layer, @Nullable Face face)
x
- the x-coordinate of the squarey
- the y-coordinate of the squarelayer
- the layer to setface
- the face to set; may be null
to remove the faceprivate void setHeadMapSquare(int x, int y, int layer, @Nullable CfMapSquare mapSquare, boolean setAlways)
x
- the x-coordinate of the squarey
- the y-coordinate of the squarelayer
- the layer for the new head face between 0
and LAYERS-1
mapSquare
- the map square containing the head face; may be null
setAlways
- if set, always update the face; if unset, only update
when fog-of-warpublic void setMagicMap(int x0, int y0, byte[][] data)
x0
- the x-coordinate of the squarey0
- the y-coordinate of the squaredata
- the magic map data (y, x); will not be changedpublic void setSmooth(int x, int y, int layer, int smooth)
x
- the x-coordinate of the squarey
- the y-coordinate of the squarelayer
- the layer to setsmooth
- the smooth value to setprivate static int size(int min, int max)
min
- the minimum coordinatemax
- the maximum coordinatepublic void squareModified(@NotNull CfMapSquare mapSquare)
CfMapSquare
as dirty.mapSquare
- the map squarepublic void squarePendingFace(int x, int y, int faceNum)
CfMapSquare
as containing a pending face.x
- the x coordinate of the map squarey
- the y coordinate of the map squarefaceNum
- the pending facepublic void updateFace(int faceNum, int width, int height)
faceNum
- the face that has changedwidth
- the width of the visible map areaheight
- the height of the visible map area