Class MutantNoiseWrapper
java.lang.Object
com.github.yellowstonegames.grid.MutantNoiseWrapper
- All Implemented Interfaces:
com.github.yellowstonegames.core.ISerializersNeeded, INoise, Externalizable, Serializable
public class MutantNoiseWrapper
extends Object
implements INoise, com.github.yellowstonegames.core.ISerializersNeeded
A wrapper around an
Internally this works by calling the same method you call here on an internal INoise,
This defaults to using a FoamNoise for its basis INoise, which allows dimensions 2 through 6 to be produced with a mutation value. Using a FoamNoise means this defaults to acting like
INoise that allows an extra degree of freedom to adjust the inputs by a small amount,
continuously rather than in jumps (as adjusting the seed would do). You can change the mutation by any
amount at a time, though usually it is a small change you can preview to see how each adjustment affects some result.
Internally this works by calling the same method you call here on an internal INoise,
basis, but using
a higher dimension and passing mutation in as that higher-dimensional input. This means if you call
getNoise(float, float), passing x and y, internally this calls
INoise.getNoise(float, float, float) and passes x, y, and mutation.
This defaults to using a FoamNoise for its basis INoise, which allows dimensions 2 through 6 to be produced with a mutation value. Using a FoamNoise means this defaults to acting like
Noise with Noise.MUTANT as its
NoiseType.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface INoise
INoise.Serializer -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionMakes a MutantNoise with aFoamNoisebasis (seeded with 1234567890L) and a mutation of 0.0f .MutantNoiseWrapper(long seed) Makes a MutantNoise with aFoamNoisebasis (seeded with the given seed) and a mutation of 0.0f.MutantNoiseWrapper(long seed, float mutation) Makes a MutantNoise with aFoamNoisebasis (seeded with the given seed) and the given mutation.MutantNoiseWrapper(INoise base) Makes a MutantNoise with the given basis INoise and a mutation of 0.0f.MutantNoiseWrapper(INoise base, float mutation) Makes a MutantNoise with the given basis INoise and mutation. -
Method Summary
Modifier and TypeMethodDescriptioncopy()Creates a copy of this INoise, which should be a deep copy for any mutable state but can be shallow for immutable types such as functions.final booleanintMaximum dimension is one less than the maximum dimension of the basis INoise.intMinimum dimension is 2, unless the basis INoise has a minimum dimension of 4 or greater.floatGets the mutation value.floatgetNoise(float x, float y) Gets 2D noise with a default or pre-set seed.floatgetNoise(float x, float y, float z) Gets 3D noise with a default or pre-set seed.floatgetNoise(float x, float y, float z, float w) Gets 4D noise with a default or pre-set seed.floatgetNoise(float x, float y, float z, float w, float u) Gets 5D noise with a default or pre-set seed.floatgetNoise(float x, float y, float z, float w, float u, float v) Gets 6D noise with a default or pre-set seed.floatgetNoiseWithSeed(float x, float y, float z, float w, float u, float v, long seed) Gets 6D noise with a specific seed.floatgetNoiseWithSeed(float x, float y, float z, float w, float u, long seed) Gets 5D noise with a specific seed.floatgetNoiseWithSeed(float x, float y, float z, float w, long seed) Gets 4D noise with a specific seed.floatgetNoiseWithSeed(float x, float y, float z, long seed) Gets 3D noise with a specific seed.floatgetNoiseWithSeed(float x, float y, long seed) Gets 2D noise with a specific seed.longgetSeed()Gets the current seed of the generator, as a long even if the seed is stored internally as an int.getTag()The String "Muta" .booleanSetting the seed is efficient here if and only if it is efficient for the basis INoise.inthashCode()static MutantNoiseWrapperrecreateFromString(String data) voidsetMutation(float mutation) Sets the mutation value.voidsetSeed(long seed) Sets the seed to the given long, if long seeds are supported, or(int)seedif only int seeds are supported.stringDeserialize(String data) Given a serialized String produced byINoise.stringSerialize(), reassigns this INoise to have the described state from the given String.Produces a String that describes everything needed to recreate this INoise in full.toString()Methods inherited from interface INoise
getNoise, getNoiseWithSeed, readExternal, writeExternal
-
Field Details
-
basis
The INoise this uses for all its internal noise generation. This defaults to a FoamNoise, but can be any INoise withINoise.getMaxDimension()greater than 2. -
mutation
public float mutationThe extra input that is passed tobasis, in addition to the inputs to each noise call. This typically changes only be a small amount at a time, to make minor continuous adjustments to a noise result, instead of usingsetSeed(long)to make a non-continuous adjustment that "jumps." This defaults to 0.
-
-
Constructor Details
-
MutantNoiseWrapper
public MutantNoiseWrapper()Makes a MutantNoise with aFoamNoisebasis (seeded with 1234567890L) and a mutation of 0.0f . -
MutantNoiseWrapper
public MutantNoiseWrapper(long seed) Makes a MutantNoise with aFoamNoisebasis (seeded with the given seed) and a mutation of 0.0f.- Parameters:
seed- the seed to use for any noise call that doesn't take a seed already
-
MutantNoiseWrapper
public MutantNoiseWrapper(long seed, float mutation) Makes a MutantNoise with aFoamNoisebasis (seeded with the given seed) and the given mutation.- Parameters:
seed- the seed to use for any noise call that doesn't take a seed alreadymutation- the initial value for the extra input to be passed in addition to the inputs to each noise call
-
MutantNoiseWrapper
Makes a MutantNoise with the given basis INoise and a mutation of 0.0f.- Parameters:
base- the INoise to use as a basis
-
MutantNoiseWrapper
Makes a MutantNoise with the given basis INoise and mutation.- Parameters:
base- the INoise to use as a basismutation- the initial value for the extra input to be passed in addition to the inputs to each noise call
-
-
Method Details
-
getMinDimension
public int getMinDimension()Minimum dimension is 2, unless the basis INoise has a minimum dimension of 4 or greater. With the default basis, a FoamNoise, this will be 2.- Specified by:
getMinDimensionin interfaceINoise- Returns:
- 2, in almost all cases
-
getMaxDimension
public int getMaxDimension()Maximum dimension is one less than the maximum dimension of the basis INoise. With the default basis, a FoamNoise, this will be 6.- Specified by:
getMaxDimensionin interfaceINoise- Returns:
- one less than
basis.getMaxDimension()
-
hasEfficientSetSeed
public boolean hasEfficientSetSeed()Setting the seed is efficient here if and only if it is efficient for the basis INoise.- Specified by:
hasEfficientSetSeedin interfaceINoise- Returns:
basis.hasEfficientSetSeed()
-
getNoise
public float getNoise(float x, float y) Description copied from interface:INoiseGets 2D noise with a default or pre-set seed. -
getNoise
public float getNoise(float x, float y, float z) Description copied from interface:INoiseGets 3D noise with a default or pre-set seed. -
getNoise
public float getNoise(float x, float y, float z, float w) Description copied from interface:INoiseGets 4D noise with a default or pre-set seed. -
getNoise
public float getNoise(float x, float y, float z, float w, float u) Description copied from interface:INoiseGets 5D noise with a default or pre-set seed.- Specified by:
getNoisein interfaceINoise- Parameters:
x- x position; can be any finite floaty- y position; can be any finite floatz- z position; can be any finite floatw- w position; can be any finite floatu- u position; can be any finite float- 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:INoiseGets 6D noise with a default or pre-set seed.- Specified by:
getNoisein interfaceINoise- Parameters:
x- x position; can be any finite floaty- y position; can be any finite floatz- z position; can be any finite floatw- w position; can be any finite floatu- u position; can be any finite floatv- v position; can be any finite float- Returns:
- a noise value between -1.0f and 1.0f, both inclusive
-
setSeed
public void setSeed(long seed) Description copied from interface:INoiseSets the seed to the given long, if long seeds are supported, or(int)seedif only int seeds are supported. If this generator cannot be seeded, this should do nothing, and should not throw an exception. If this operation allocates or is time-intensive, thenINoise.hasEfficientSetSeed()should return false. That method is checked inINoise.getNoiseWithSeed(float, float, long), and if it returns false, the noise call will avoid calling setSeed(). You can always at least try to set the seed, even if it does nothing or is heavy on performance, and doing it a few times each frame should typically be fine for any generator. In the case this is called thousands of times each frame, checkINoise.hasEfficientSetSeed(). -
getSeed
public long getSeed()Description copied from interface:INoiseGets the current seed of the generator, as a long even if the seed is stored internally as an int. This must be implemented, but if the generator doesn't have a seed that can be expressed as a long (potentially usingBitConversion.floatToIntBits(float)), this can just return0. -
getMutation
public float getMutation()Gets the mutation value. The mutation is an extra input that is passed tobasis, in addition to the inputs to each noise call. This typically changes only be a small amount at a time, to make minor continuous adjustments to a noise result, instead of usingsetSeed(long)to make a non-continuous adjustment that "jumps." -
setMutation
public void setMutation(float mutation) Sets the mutation value. The mutation is an extra input that is passed tobasis, in addition to the inputs to each noise call. This typically changes only be a small amount at a time, to make minor continuous adjustments to a noise result, instead of usingsetSeed(long)to make a non-continuous adjustment that "jumps."- Parameters:
mutation- the float value to use for the mutation
-
getTag
-
stringSerialize
Description copied from interface:INoiseProduces a String that describes everything needed to recreate this INoise in full. This String can be read back in byINoise.stringDeserialize(String)to reassign the described state to another INoise. The syntax here should always start and end with the`character, which is used byINoise.stringDeserialize(String)to identify the portion of a String that can be read back. The`character should not be otherwise used unless to serialize another INoise that this uses.
If you useBaseto produce String representations for numeric fields in an INoise,Base.BASE10is strongly recommended; in most cases, you can just use string concatenation with the fields separated by the tilde character,"~". For printing a floatfieldwith Base to a StringBuildersb, useBase.BASE10.appendGeneral(sb, field).
The default implementation throws anUnsupportedOperationExceptiononly. INoise classes do not have to implement any serialization methods, but they aren't serializable by the methods in this class or inINoise.Serializerunless they do implement this,INoise.getTag(),INoise.stringDeserialize(String), andINoise.copy().- Specified by:
stringSerializein interfaceINoise- Returns:
- a String that describes this INoise for serialization
-
stringDeserialize
Description copied from interface:INoiseGiven a serialized String produced byINoise.stringSerialize(), reassigns this INoise to have the described state from the given String. The serialized String must have been produced by the same class as this object is.
Any class that implementsINoise.stringSerialize()should also implement this method in a compatible way. Using base-10 is expected for most uses. UsingBase.BASE10.readFloat(data, start, end)may be useful to parse only the part of data between start and end.
The default implementation throws anUnsupportedOperationExceptiononly. INoise classes do not have to implement any serialization methods, but they aren't serializable by the methods in this class or inINoise.Serializerunless they do implement this,INoise.getTag(),INoise.stringSerialize(), andINoise.copy().- Specified by:
stringDeserializein interfaceINoise- Parameters:
data- a serialized String, typically produced byINoise.stringSerialize()- Returns:
- this INoise, after being modified (if possible)
-
recreateFromString
-
getSerializersNeeded
-
copy
Description copied from interface:INoiseCreates a copy of this INoise, which should be a deep copy for any mutable state but can be shallow for immutable types such as functions. This almost always just calls a copy constructor.
The default implementation throws anUnsupportedOperationExceptiononly. Implementors are strongly encouraged to implement this in general, and that is required to use an INoise class withINoise.Serializer. -
equals
-
hashCode
-
toString
-
getNoiseWithSeed
public float getNoiseWithSeed(float x, float y, long seed) Description copied from interface:INoiseGets 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 withINoise.hasEfficientSetSeed().- Specified by:
getNoiseWithSeedin interfaceINoise- Parameters:
x- x position; can be any finite floaty- y position; can be any finite floatseed- can be any long- 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:INoiseGets 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 withINoise.hasEfficientSetSeed().- Specified by:
getNoiseWithSeedin interfaceINoise- Parameters:
x- x position; can be any finite floaty- y position; can be any finite floatz- z position; can be any finite floatseed- can be any long- 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:INoiseGets 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 withINoise.hasEfficientSetSeed().- Specified by:
getNoiseWithSeedin interfaceINoise- Parameters:
x- x position; can be any finite floaty- y position; can be any finite floatz- z position; can be any finite floatw- w position; can be any finite floatseed- can be any long- 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:INoiseGets 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 withINoise.hasEfficientSetSeed().- Specified by:
getNoiseWithSeedin interfaceINoise- Parameters:
x- x position; can be any finite floaty- y position; can be any finite floatz- z position; can be any finite floatw- w position; can be any finite floatu- u position; can be any finite floatseed- can be any long- 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:INoiseGets 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 withINoise.hasEfficientSetSeed().- Specified by:
getNoiseWithSeedin interfaceINoise- Parameters:
x- x position; can be any finite floaty- y position; can be any finite floatz- z position; can be any finite floatw- w position; can be any finite floatu- u position; can be any finite floatv- v position; can be any finite floatseed- can be any long- Returns:
- a noise value between -1.0f and 1.0f, both inclusive
-