Handle tile invalidates better for bigger-than-one-block cases (chunks)

This commit is contained in:
Mike Primm 2011-08-15 03:16:33 +08:00 committed by mikeprimm
parent 042544f22e
commit 0c9cfedb6e
8 changed files with 155 additions and 21 deletions

View file

@ -106,6 +106,11 @@ public class HDMap extends MapType {
return perspective.getTiles(loc);
}
@Override
public MapTile[] getTiles(Location loc0, Location loc1) {
return perspective.getTiles(loc0, loc1);
}
@Override
public MapTile[] getAdjecentTiles(MapTile tile) {
return perspective.getAdjecentTiles(tile);

View file

@ -13,6 +13,8 @@ public interface HDPerspective {
String getName();
/* Get tiles invalidated by change at given location */
MapTile[] getTiles(Location loc);
/* Get tiles invalidated by change at given volume, defined by 2 opposite corner locations */
MapTile[] getTiles(Location loc0, Location loc1);
/* Get tiles adjacent to given tile */
MapTile[] getAdjecentTiles(MapTile tile);
/* Get chunks needed for given tile */

View file

@ -726,6 +726,68 @@ public class IsoHDPerspective implements HDPerspective {
return tiles.toArray(new MapTile[tiles.size()]);
}
@Override
public MapTile[] getTiles(Location loc0, Location loc1) {
DynmapWorld world = MapManager.mapman.getWorld(loc0.getWorld().getName());
HashSet<MapTile> tiles = new HashSet<MapTile>();
Vector3D blocks[] = new Vector3D[] { new Vector3D(), new Vector3D() };
/* Get ordered point - 0=minX,Y,Z, 1=maxX,Y,Z */
if(loc0.getBlockX() < loc1.getBlockX()) {
blocks[0].x = loc0.getBlockX();
blocks[1].x = loc1.getBlockX() + 1;
}
else {
blocks[0].x = loc1.getBlockX();
blocks[1].x = loc0.getBlockX() + 1;
}
if(loc0.getBlockY() < loc1.getBlockY()) {
blocks[0].y = loc0.getBlockY();
blocks[1].y = loc1.getBlockY() + 1;
}
else {
blocks[0].y = loc1.getBlockY();
blocks[1].y = loc0.getBlockY() + 1;
}
if(loc0.getBlockZ() < loc1.getBlockZ()) {
blocks[0].z = loc0.getBlockZ();
blocks[1].z = loc1.getBlockZ() + 1;
}
else {
blocks[0].z = loc1.getBlockZ();
blocks[1].z = loc0.getBlockZ() + 1;
}
Vector3D corner = new Vector3D();
Vector3D tcorner = new Vector3D();
int mintilex = Integer.MAX_VALUE;
int maxtilex = Integer.MIN_VALUE;
int mintiley = Integer.MAX_VALUE;
int maxtiley = Integer.MIN_VALUE;
/* Loop through corners of the prism */
for(int i = 0; i < 2; i++) {
corner.x = blocks[i].x;
for(int j = 0; j < 2; j++) {
corner.y = blocks[j].y;
for(int k = 0; k < 2; k++) {
corner.z = blocks[k].z;
world_to_map.transform(corner, tcorner); /* Get map coordinate of corner */
int tx = (int)Math.floor(tcorner.x/tileWidth);
int ty = (int)Math.floor(tcorner.y/tileWidth);
if(mintilex > tx) mintilex = tx;
if(maxtilex < tx) maxtilex = tx;
if(mintiley > ty) mintiley = ty;
if(maxtiley < ty) maxtiley = ty;
}
}
}
/* Now, add the tiles for the ranges - not perfect, but it works (some extra tiles on corners possible) */
for(int i = mintilex; i <= maxtilex; i++) {
for(int j = mintiley; j < maxtiley; j++) {
addTile(tiles, world, i, j);
}
}
return tiles.toArray(new MapTile[tiles.size()]);
}
@Override
public MapTile[] getAdjecentTiles(MapTile tile) {
HDMapTile t = (HDMapTile) tile;