Class Spill

java.lang.Object
com.github.yellowstonegames.grid.Spill

public class Spill extends Object
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 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
    Modifier and Type
    Field
    Description
    protected Region
     
    protected com.github.tommyettinger.random.EnhancedRandom
     
    protected Region
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Calls Spill(Region) with a new empty 32x32 Region.
    Spill(char[][] passable)
    Calls Spill(Region) by creating a Region from passable with Region(char[][], char) and a "yes" char of '.'.
    Spill(char[][] passable, char floorChar)
    Calls Spill(Region) by creating a Region from passable with Region(char[][], char) and a "yes" char of floorChar.
    Spill(char[][] passable, char floorChar, com.github.tommyettinger.random.EnhancedRandom random)
    Calls Spill(Region) by creating a Region from passable with Region(char[][], char) and a "yes" char of floorChar.
    Spill(char[][] passable, com.github.tommyettinger.random.EnhancedRandom random)
    Calls Spill(Region) by creating a Region from passable with Region(char[][], char) and a "yes" char of '.'.
    Spill(Region passable)
    Constructs a Spill from the given Region, where "on" cells represent passable areas that the spill can move through and occupy.
    Spill(Region passable, com.github.tommyettinger.random.EnhancedRandom random)
    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 Type
    Method
    Description
     
    com.github.tommyettinger.random.EnhancedRandom
     
    Gets the last spillMap produced by run(Coord, int).
    run(Coord entrance, int volume)
    Runs a spill outwards from one entrance point, until volume cells are present in the result, or until no more cells can be added.
    run(Region entrances, int volume)
    Runs a spill outwards from one or more entrances, until volume cells are present in the result, or until no more cells can be added.
    void
    setPassable(Region passable)
     
    void
    setRandom(com.github.tommyettinger.random.EnhancedRandom random)
     
    void
    setSpillMap(Region spillMap)
    This probably won't be used often, but you can change the spillMap this uses here.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • spillMap

      protected Region spillMap
    • passable

      protected Region passable
    • random

      protected com.github.tommyettinger.random.EnhancedRandom random
  • Constructor Details

    • Spill

      public Spill()
      Calls Spill(Region) with a new empty 32x32 Region.
    • Spill

      public Spill(char[][] passable)
      Calls Spill(Region) by creating a Region from passable with Region(char[][], char) and a "yes" char of '.'. Uses a randomly-seeded WhiskerRandom.
      Parameters:
      passable - a rectangular 2D char array where '.' represents a walkable cell
    • Spill

      public Spill(char[][] passable, char floorChar)
      Calls Spill(Region) by creating a Region from passable with Region(char[][], char) and a "yes" char of floorChar. Uses a randomly-seeded WhiskerRandom.
      Parameters:
      passable - a rectangular 2D char array where floorChar represents a walkable cell
      floorChar - the char that is considered walkable in passable
    • Spill

      public Spill(char[][] passable, com.github.tommyettinger.random.EnhancedRandom random)
      Calls Spill(Region) by creating a Region from passable with Region(char[][], char) and a "yes" char of '.'. Uses the given EnhancedRandom, or a randomly-seeded WhiskerRandom if it is null.
      Parameters:
      passable - a rectangular 2D char array where '.' represents a walkable cell
      random - 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)
      Calls Spill(Region) by creating a Region from passable with Region(char[][], char) and a "yes" char of floorChar. Uses the given EnhancedRandom, or a randomly-seeded WhiskerRandom if it is null.
      Parameters:
      passable - a rectangular 2D char array where floorChar represents a walkable cell
      floorChar - the char that is considered walkable in passable
      random - the random number generator to use; if null, this will use a random seed
    • Spill

      public Spill(Region passable)
      Constructs a Spill from the given Region, where "on" cells represent passable areas that the spill can move through and occupy. Uses a randomly-seeded WhiskerRandom.
      Parameters:
      passable - a Region where "on" cells can be moved through; will be referenced but not modified
    • Spill

      public Spill(Region passable, com.github.tommyettinger.random.EnhancedRandom random)
      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-seeded WhiskerRandom if it is null.
      Parameters:
      passable - a Region where "on" cells can be moved through; will be referenced but not modified
      random - the random number generator to use; if null, this will use a random seed
  • Method Details

    • run

      public Region run(Coord entrance, int volume)
      Runs a spill outwards from one entrance point, until volume cells are present in the result, or until no more cells can be added. You should usually call Region.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 from
      volume - how many "on" cells the result can hold at most before returning
      Returns:
      the spillMap, which this can reuse; call Region.copy() to avoid losing this
    • run

      public Region run(Region entrances, int volume)
      Runs a spill outwards from one or more entrances, until volume cells are present in the result, or until no more cells can be added. You should usually call Region.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 in entrances do not need to be contiguous.
      Parameters:
      entrances - a Region holding typically one or more initial cells the spill will move out from
      volume - how many "on" cells the result can hold at most before returning
      Returns:
      the spillMap, which this can reuse; call Region.copy() to avoid losing this
    • getSpillMap

      public Region getSpillMap()
      Gets the last spillMap produced by run(Coord, int).
      Returns:
      the last spillMap, a Region, produced by one of the run methods
    • setSpillMap

      public void setSpillMap(Region spillMap)
      This probably won't be used often, but you can change the spillMap this uses here. This is returned by run(Coord, int).
      Parameters:
      spillMap - a non-null Region that should be the same size as getPassable()
    • getPassable

      public Region getPassable()
    • setPassable

      public void setPassable(Region passable)
    • getRandom

      public com.github.tommyettinger.random.EnhancedRandom getRandom()
    • setRandom

      public void setRandom(com.github.tommyettinger.random.EnhancedRandom random)