Class BasicHashNoise

java.lang.Object
com.github.yellowstonegames.grid.BasicHashNoise
All Implemented Interfaces:
com.github.yellowstonegames.core.ISerializersNeeded, INoise, Externalizable, Serializable

public class BasicHashNoise extends Object implements INoise, com.github.yellowstonegames.core.ISerializersNeeded
Makes 2D through 6D value noise that simply preserves the behavior of an IPointHash, including intentional (or unintentional) artifacts that the point hash produces. This is more useful with intentionally-flawed point hashes from FlawedPointHash, such as FlawedPointHash.FlowerHash. Note that because this uses an arbitrary IPointHash (and that interface doesn't define any way to serialize itself), you can't serialize or deserialize a BasicHashNoise to or from a String. Binary serialization (such as using Kryo) still works.
See Also:
  • Field Details

  • Constructor Details

    • BasicHashNoise

      public BasicHashNoise()
    • BasicHashNoise

      public BasicHashNoise(int seed)
    • BasicHashNoise

      public BasicHashNoise(int seed, IPointHash hash)
  • Method Details

    • getMinDimension

      public int getMinDimension()
      Gets the minimum dimension supported by this generator, which is 2.
      Specified by:
      getMinDimension in interface INoise
      Returns:
      the minimum supported dimension, 2
    • getMaxDimension

      public int getMaxDimension()
      Gets the maximum dimension supported by this generator, which is 6.
      Specified by:
      getMaxDimension in interface INoise
      Returns:
      the maximum supported dimension, 6
    • hasEfficientSetSeed

      public boolean hasEfficientSetSeed()
      Returns true because this generator can be seeded with setSeed(long) and retrieved with getSeed().
      Specified by:
      hasEfficientSetSeed in interface INoise
      Returns:
      true
    • setSeed

      public void setSeed(long seed)
      Sets the seed to the given long, if long seeds are supported, or (int)seed if only int seeds are supported. If hasEfficientSetSeed() returns true, this must be implemented and must set the seed given a long input. If this generator cannot be seeded, this is permitted to either do nothing or throw an UnsupportedOperationException. If this operation allocates or is time-intensive, then that performance cost will be passed along to getNoiseWithSeed(float, float, long), since that calls this twice unless overridden. In the case where seeding is expensive to perform, setSeed() can still be implemented while hasEfficientSetSeed() returns false. This makes the getNoiseWithSeed(float, float, long) methods avoid reseeding, and instead move their inputs around in space.
      Specified by:
      setSeed in interface INoise
      Parameters:
      seed - a long or int seed, with no restrictions unless otherwise documented
    • getSeed

      public long getSeed()
      Gets the current seed of the generator, as a long.
      Specified by:
      getSeed in interface INoise
      Returns:
      the current seed, as a long
    • getTag

      public String getTag()
      Returns the constant String "BaHN" that identifies this in serialized Strings.
      Specified by:
      getTag in interface INoise
      Returns:
      a short String constant that identifies this INoise type, "BaHN"
    • stringSerialize

      public String stringSerialize()
      Because this needs to write an IPointHash, but that interface can't be serialized, this throws an UnsupportedOperationException only.
      Specified by:
      stringSerialize in interface INoise
      Returns:
      never returns normally
    • stringDeserialize

      public BasicHashNoise stringDeserialize(String data)
      Because this needs to read an IPointHash, but that interface can't be deserialized, this throws an UnsupportedOperationException only.
      Specified by:
      stringDeserialize in interface INoise
      Parameters:
      data - a serialized String, typically produced by stringSerialize()
      Returns:
      never returns normally
    • copy

      public BasicHashNoise copy()
      Creates a copy of this BasicHashNoise, which is a shallow copy here and assumes pointHash has no mutable state that could need a deep copy.
      Specified by:
      copy in interface INoise
      Returns:
      a copy of this BasicHashNoise
    • getNoise

      public float getNoise(float x, float y)
      Description copied from interface: INoise
      Gets 2D noise with a default or pre-set seed.
      Specified by:
      getNoise in interface INoise
      Parameters:
      x - x position; can be any finite float
      y - y position; can be any finite float
      Returns:
      a noise value between -1.0f and 1.0f, both inclusive
    • getNoiseWithSeed

      public float getNoiseWithSeed(float x, float y, long seed)
      Description copied from interface: INoise
      Gets 2D noise with a specific seed. If the seed cannot be retrieved or changed per-call, then this falls back to changing the position instead of the seed; you can check if this will happen with INoise.hasEfficientSetSeed().
      Specified by:
      getNoiseWithSeed in interface INoise
      Parameters:
      x - x position; can be any finite float
      y - y position; can be any finite float
      seed - can be any long
      Returns:
      a noise value between -1.0f and 1.0f, both inclusive
    • getNoise

      public float getNoise(float x, float y, float z)
      Description copied from interface: INoise
      Gets 3D noise with a default or pre-set seed.
      Specified by:
      getNoise in interface INoise
      Parameters:
      x - x position; can be any finite float
      y - y position; can be any finite float
      z - z position; can be any finite float
      Returns:
      a noise value between -1.0f and 1.0f, both inclusive
    • getNoiseWithSeed

      public float getNoiseWithSeed(float x, float y, float z, long seed)
      Description copied from interface: INoise
      Gets 3D noise with a specific seed. If the seed cannot be retrieved or changed per-call, then this falls back to changing the position instead of the seed; you can check if this will happen with INoise.hasEfficientSetSeed().
      Specified by:
      getNoiseWithSeed in interface INoise
      Parameters:
      x - x position; can be any finite float
      y - y position; can be any finite float
      z - z position; can be any finite float
      seed - can be any long
      Returns:
      a noise value between -1.0f and 1.0f, both inclusive
    • getNoise

      public float getNoise(float x, float y, float z, float w)
      Description copied from interface: INoise
      Gets 4D noise with a default or pre-set seed.
      Specified by:
      getNoise in interface INoise
      Parameters:
      x - x position; can be any finite float
      y - y position; can be any finite float
      z - z position; can be any finite float
      w - w position; can be any finite float
      Returns:
      a noise value between -1.0f and 1.0f, both inclusive
    • getNoiseWithSeed

      public float getNoiseWithSeed(float x, float y, float z, float w, long seed)
      Description copied from interface: INoise
      Gets 4D noise with a specific seed. If the seed cannot be retrieved or changed per-call, then this falls back to changing the position instead of the seed; you can check if this will happen with INoise.hasEfficientSetSeed().
      Specified by:
      getNoiseWithSeed in interface INoise
      Parameters:
      x - x position; can be any finite float
      y - y position; can be any finite float
      z - z position; can be any finite float
      w - w position; can be any finite float
      seed - can be any long
      Returns:
      a noise value between -1.0f and 1.0f, both inclusive
    • getNoise

      public float getNoise(float x, float y, float z, float w, float u)
      Description copied from interface: INoise
      Gets 5D noise with a default or pre-set seed.
      Specified by:
      getNoise in interface INoise
      Parameters:
      x - x position; can be any finite float
      y - y position; can be any finite float
      z - z position; can be any finite float
      w - w position; can be any finite float
      u - u position; can be any finite float
      Returns:
      a noise value between -1.0f and 1.0f, both inclusive
    • getNoiseWithSeed

      public float getNoiseWithSeed(float x, float y, float z, float w, float u, long seed)
      Description copied from interface: INoise
      Gets 5D noise with a specific seed. If the seed cannot be retrieved or changed per-call, then this falls back to changing the position instead of the seed; you can check if this will happen with INoise.hasEfficientSetSeed().
      Specified by:
      getNoiseWithSeed in interface INoise
      Parameters:
      x - x position; can be any finite float
      y - y position; can be any finite float
      z - z position; can be any finite float
      w - w position; can be any finite float
      u - u position; can be any finite float
      seed - can be any long
      Returns:
      a noise value between -1.0f and 1.0f, both inclusive
    • getNoise

      public float getNoise(float x, float y, float z, float w, float u, float v)
      Description copied from interface: INoise
      Gets 6D noise with a default or pre-set seed.
      Specified by:
      getNoise in interface INoise
      Parameters:
      x - x position; can be any finite float
      y - y position; can be any finite float
      z - z position; can be any finite float
      w - w position; can be any finite float
      u - u position; can be any finite float
      v - v position; can be any finite float
      Returns:
      a noise value between -1.0f and 1.0f, both inclusive
    • getNoiseWithSeed

      public float getNoiseWithSeed(float x, float y, float z, float w, float u, float v, long seed)
      Description copied from interface: INoise
      Gets 6D noise with a specific seed. If the seed cannot be retrieved or changed per-call, then this falls back to changing the position instead of the seed; you can check if this will happen with INoise.hasEfficientSetSeed().
      Specified by:
      getNoiseWithSeed in interface INoise
      Parameters:
      x - x position; can be any finite float
      y - y position; can be any finite float
      z - z position; can be any finite float
      w - w position; can be any finite float
      u - u position; can be any finite float
      v - v position; can be any finite float
      seed - can be any long
      Returns:
      a noise value between -1.0f and 1.0f, both inclusive
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Specified by:
      equals in interface INoise
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getSerializersNeeded

      public List<Class<?>> getSerializersNeeded()
      Specified by:
      getSerializersNeeded in interface com.github.yellowstonegames.core.ISerializersNeeded