Class Spill
java.lang.Object
com.github.yellowstonegames.grid.Spill
Performs randomized flood-fill operations on arbitrarily-shaped areas, until a volume is reached.
Randomized flood-fills are useful for generating areas as if they were produced by a fluid process, such as a cloud
of smoke or gas, or a literal spill of liquid over an uneven floor. The
This is commonly used by constructing a Spill (specifying at least the valid cells the spill can expand into) and calling
This is a simple wrapper around
passable Region this
uses allows limiting the "fluid" from spilling into walls or making other impossible movements.
This is commonly used by constructing a Spill (specifying at least the valid cells the spill can expand into) and calling
run(Coord, int) or run(Region, int) with the desired volume for the spill and its starting
location(s). You can get the resulting spillMap returned from run() or by a getter later;
it may need to be copied (using Region.copy(), or put into another Region using
Region.remake(Region)) to avoid getting the spillMap overwritten by a later run() call.
This is a simple wrapper around
Region.spill(Region, int, EnhancedRandom, Region, Region) to help handle its
several arguments more cleanly.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSpill()CallsSpill(Region)with a new empty 32x32 Region.Spill(char[][] passable) CallsSpill(Region)by creating a Region frompassablewithRegion(char[][], char)and a "yes" char of'.'.Spill(char[][] passable, char floorChar) CallsSpill(Region)by creating a Region frompassablewithRegion(char[][], char)and a "yes" char offloorChar.Spill(char[][] passable, char floorChar, com.github.tommyettinger.random.EnhancedRandom random) CallsSpill(Region)by creating a Region frompassablewithRegion(char[][], char)and a "yes" char offloorChar.Spill(char[][] passable, com.github.tommyettinger.random.EnhancedRandom random) CallsSpill(Region)by creating a Region frompassablewithRegion(char[][], char)and a "yes" char of'.'.Constructs a Spill from the given Region, where "on" cells represent passable areas that the spill can move through and occupy.Constructs a Spill from the given Region, where "on" cells represent passable areas that the spill can move through and occupy. -
Method Summary
Modifier and TypeMethodDescriptioncom.github.tommyettinger.random.EnhancedRandomGets the last spillMap produced byrun(Coord, int).Runs a spill outwards from oneentrancepoint, untilvolumecells are present in the result, or until no more cells can be added.Runs a spill outwards from one or moreentrances, untilvolumecells are present in the result, or until no more cells can be added.voidsetPassable(Region passable) voidsetRandom(com.github.tommyettinger.random.EnhancedRandom random) voidsetSpillMap(Region spillMap) This probably won't be used often, but you can change the spillMap this uses here.
-
Field Details
-
spillMap
-
passable
-
random
protected com.github.tommyettinger.random.EnhancedRandom random
-
-
Constructor Details
-
Spill
public Spill()CallsSpill(Region)with a new empty 32x32 Region. -
Spill
public Spill(char[][] passable) CallsSpill(Region)by creating a Region frompassablewithRegion(char[][], char)and a "yes" char of'.'. Uses a randomly-seededWhiskerRandom.- Parameters:
passable- a rectangular 2D char array where'.'represents a walkable cell
-
Spill
public Spill(char[][] passable, char floorChar) CallsSpill(Region)by creating a Region frompassablewithRegion(char[][], char)and a "yes" char offloorChar. Uses a randomly-seededWhiskerRandom.- Parameters:
passable- a rectangular 2D char array wherefloorCharrepresents a walkable cellfloorChar- the char that is considered walkable inpassable
-
Spill
public Spill(char[][] passable, com.github.tommyettinger.random.EnhancedRandom random) CallsSpill(Region)by creating a Region frompassablewithRegion(char[][], char)and a "yes" char of'.'. Uses the given EnhancedRandom, or a randomly-seededWhiskerRandomif it is null.- Parameters:
passable- a rectangular 2D char array where'.'represents a walkable cellrandom- the random number generator to use; if null, this will use a random seed
-
Spill
public Spill(char[][] passable, char floorChar, com.github.tommyettinger.random.EnhancedRandom random) CallsSpill(Region)by creating a Region frompassablewithRegion(char[][], char)and a "yes" char offloorChar. Uses the given EnhancedRandom, or a randomly-seededWhiskerRandomif it is null.- Parameters:
passable- a rectangular 2D char array wherefloorCharrepresents a walkable cellfloorChar- the char that is considered walkable inpassablerandom- the random number generator to use; if null, this will use a random seed
-
Spill
Constructs a Spill from the given Region, where "on" cells represent passable areas that the spill can move through and occupy. Uses a randomly-seededWhiskerRandom.- Parameters:
passable- a Region where "on" cells can be moved through; will be referenced but not modified
-
Spill
Constructs a Spill from the given Region, where "on" cells represent passable areas that the spill can move through and occupy. Uses the given EnhancedRandom, or a randomly-seededWhiskerRandomif it is null.- Parameters:
passable- a Region where "on" cells can be moved through; will be referenced but not modifiedrandom- the random number generator to use; if null, this will use a random seed
-
-
Method Details
-
run
Runs a spill outwards from oneentrancepoint, untilvolumecells are present in the result, or until no more cells can be added. You should usually callRegion.copy()on the result, unless you intend to discard it, because the result is a direct reference that will be reused in future calls to run().- Parameters:
entrance- the single initial cell the spill will move out fromvolume- how many "on" cells the result can hold at most before returning- Returns:
- the
spillMap, which this can reuse; callRegion.copy()to avoid losing this
-
run
Runs a spill outwards from one or moreentrances, untilvolumecells are present in the result, or until no more cells can be added. You should usually callRegion.copy()on the result, unless you intend to discard it, because the result is a direct reference that will be reused in future calls to run().
The "on" cells inentrancesdo not need to be contiguous.- Parameters:
entrances- a Region holding typically one or more initial cells the spill will move out fromvolume- how many "on" cells the result can hold at most before returning- Returns:
- the
spillMap, which this can reuse; callRegion.copy()to avoid losing this
-
getSpillMap
Gets the last spillMap produced byrun(Coord, int).- Returns:
- the last spillMap, a Region, produced by one of the run methods
-
setSpillMap
This probably won't be used often, but you can change the spillMap this uses here. This is returned byrun(Coord, int).- Parameters:
spillMap- a non-null Region that should be the same size asgetPassable()
-
getPassable
-
setPassable
-
getRandom
public com.github.tommyettinger.random.EnhancedRandom getRandom() -
setRandom
public void setRandom(com.github.tommyettinger.random.EnhancedRandom random)
-