/** * Gets the size of this Region as measured in Coords stored. * Performs "cleanup" if the Region is "dirty," even though this doesn't specifically request a Coord. As such, it * may take longer than a call to size() might be expected to, but only just after a "dirtying" method was called. * @return the number of Coords stored in this Region. */ @Override public int size() { if(dirty) { coords = allPacked(raw); dirty = false; } return coords.length; }
/** * Gets the Coords contained in this as an array, a direct reference that does permit modifying the Coords in your * own code without altering "dirty/clean" status. This method does "cleanup" in itself if necessary, but once the * Coords are returned you can change them at-will. The Coords may not reflect changes made by this object if it * creates a new Coord array, as it often does. * @return the Coords contained in this Region as an array */ public Coord[] getCoords() { if(dirty) { coords = allPacked(raw); dirty = false; } return coords; }
/** * Gets the Coord stored at the given index in this Region, or null if index is out of bounds. * The ordering this class uses may seem unusual, but it is predictable, using the pattern a Hilbert Curve takes to * wind through a 256x256 space (at its maximum). Any two given Coords will always have the same before-after * relationship, regardless of other Coords in the Region. A Region is a dense data structure, like a List or array, * so valid indices shouldn't ever return null. * @param index the index into this Region to get a Coord at; should be less than size() and non-negative. * @return the Coord this Region holds at index, if index is valid; otherwise null */ @Override public Coord get(int index) { if(dirty) { coords = allPacked(raw); dirty = false; } if(index >= 0 && index < coords.length) return coords[index]; return null; }
/** * Returns an array containing all of the elements in this collection. * If this collection makes any guarantees as to what order its elements * are returned by its iterator, this method must return the elements in * the same order. * <p> * <p>The returned array will be "safe" in that no references to it are * maintained by this collection. (In other words, this method must * allocate a new array even if this collection is backed by an array). * The caller is thus free to modify the returned array. * <p> * <p>This method acts as bridge between array-based and collection-based * APIs. * * @return an array containing all of the elements in this collection */ @Override public Object[] toArray() { return CoordPacker.allPacked(shorts); }
@Override public List<Coord> getAll() { if (unpacked == null) { final Coord[] allPacked = CoordPacker.allPacked(shorts); unpacked = new ArrayList<Coord>(allPacked.length); Collections.addAll(unpacked, allPacked); } return unpacked; }
/** * A constructor for a Region that takes a specifically-formatted short array (packed data), as produced by * CoordPacker or sometimes other classes, like RegionMap or RoomFinder. If you don't have such data, the other * constructors are recommended instead. * <br> * Note: arrays of Hilbert indices are occasionally returned in CoordPacker as a different kind of short array, but * those methods are always noted as such and those short arrays won't make sense if passed to this constructor. * They may result in a technically-valid Region with random-seeming contents. In general, if a method in * CoordPacker returns a short array (most of them do), but the name contains Hilbert, it may return the wrong kind * (an array of Hilbert indices is wrong, packed data is right); check the documentation for that method. * @param packedData a short array as produced by CoordPacker (usually), or sometimes RoomFinder or RegionMap */ public Region(short[] packedData) { CoordPacker.init(); raw = new short[packedData.length]; System.arraycopy(packedData, 0, raw, 0, packedData.length); coords = allPacked(raw); dirty = false; }
/** * A constructor that copies another Region so this Region will have the same contents. If the other Region is * "dirty", this won't perform "cleanup" on it, but will ensure that this Region is "clean" at creation. * None of the reference types in other will be used directly in this Region, so changes made to this Region won't * be reflected in other. * @param other another Region to copy into this one */ public Region(Region other) { CoordPacker.init(); raw = new short[other.raw.length]; System.arraycopy(other.raw, 0, raw, 0, raw.length); if(other.dirty) { coords = allPacked(raw); } else { coords = new Coord[other.coords.length]; System.arraycopy(other.coords, 0, coords, 0, coords.length); } dirty = false; }
/** * A constructor for a Region that takes an array or vararg of Coord and encodes all of them in the Region. * @param points an array or vararg of Coord that will be stored in this Region, none can be null */ public Region(Coord... points) { CoordPacker.init(); raw = packSeveral(points); coords = allPacked(raw); dirty = false; } /**
/** * A constructor for a Region that takes a Collection of Coord, such as a List or Set, and encodes all of them in * the Region. * @param points a Collection of Coord that will be stored in this Region, none can be null */ public Region(Collection<Coord> points) { CoordPacker.init(); raw = packSeveral(points); coords = allPacked(raw); dirty = false; }
/** * A constructor for a Region that takes a 2D double array, usually the kind produced by FOV, and stores only Coord * positions that correspond to values greater than 0.0 (actually, greater than epsilon, which here is 0.0001). * This won't behave as-expected if you give it a double[][] that DijkstraMap produces; there's a different * constructor for that purpose. * @param fovMap a 2D double array as produced by FOV */ public Region(double[][] fovMap) { CoordPacker.init(); raw = pack(fovMap); coords = allPacked(raw); dirty = false; }
/** * A constructor for a Region that takes a 2D char array, the kind produced by most map/dungeon generators in this * library, and a vararg or array of char that will have their Coord positions used where those chars appear in map. * This is optimized for the common case of a single char in using if you only want to, for example, store '.' to * make a Region of floors, or '#' for walls. * @param map a 2D char array that is usually the kind returned by a dungeon or map generator * @param using an array or vararg of char that will have their Coords used where they appear in map */ public Region(char[][] map, char... using) { CoordPacker.init(); raw = pack(map, using); coords = allPacked(raw); dirty = false; }
/** * A constructor for a circular Region (possibly truncated at the edges) with a Coord center, an int radius, and a * maximum width and height that the Coords in this Region will not exceed. * @param center the center of the circular Region * @param circleRadius the radius as an int * @param mapWidth one more than the maximum x-position of any Coord this will contain * @param mapHeight one more than the maximum y-position of any Coord this will contain */ public Region(Coord center, int circleRadius, int mapWidth, int mapHeight) { CoordPacker.init(); raw = circle(center, circleRadius, mapWidth, mapHeight); coords = allPacked(raw); dirty = false; }
/** * A constructor for a Region that takes a 2D double array, usually produced by DijkstraMap, and a maximum value, * and stores only Coord positions that correspond to values no greater than maximum. * This won't behave as-expected if you give it a double[][] that FOV produces; there's a different * constructor for that purpose. * @param dijkstraMap a 2D double array as produced by DijkstraMap * @param maximum the highest value that a position can have in dijkstraMap and still be given a Coord in this */ public Region(double[][] dijkstraMap, double maximum) { CoordPacker.init(); raw = pack(dijkstraMap, maximum); coords = allPacked(raw); dirty = false; }
/** * A constructor for a rectangular Region that stores Coords for the area from (minX,minY) at the minimum corner to * (width + minX - 1, height + minY - 1) at the maximum corner. All parameters should be non-negative and less than * 256, and height and width will be reduced if a Coord in the rectangle would extend to 256 in either dimension. * This doesn't take two Coords as parameters because that would be confusing with the constructor that takes a * vararg or array of Coord for its parameters. * @param minX lowest x-coordinate in the rectangle; should be between 0 and 255 * @param minY lowest y-coordinate in the rectangle; should be between 0 and 255 * @param width total width of the rectangle; must be non-negative * @param height total height of the rectangle; must be non-negative */ public Region(int minX, int minY, int width, int height) { CoordPacker.init(); raw = rectangle(minX, minY, width, height); coords = allPacked(raw); dirty = false; } /**
return allPacked(packed); ShortVLA vla = new ShortVLA(64); boolean on = false;
return allPacked(packed); if(eightWay) return apartPacked(packed, minDistance);
return allPacked(packed); ShortVLA vla = new ShortVLA(64); boolean on = false;
short[] drs = CoordPacker.pack(this.map, doors); if(drs.length >= 2) validDoors = CoordPacker.allPacked(drs); else { validDoors = CoordPacker.fractionPacked(pk, 5);//CoordPacker.allPacked(pk);
short[] drs = CoordPacker.pack(map, doors); if(drs.length >= 2) validDoors = CoordPacker.allPacked(drs); else { validDoors = CoordPacker.fractionPacked(pk, 5);//CoordPacker.allPacked(pk);
return allPacked(packed); ShortVLA vla = new ShortVLA(64); boolean on = false;