If an application passes an input value to the
get(double, double, double)
method that differs from the
previously passed-in input value, this noise module instructs the source
module to calculate the output value. This value, as well as the
(x, y, z)
coordinates of the input value, are stored (cached) in this
noise module.
If the application passes an input value to the
get(double, double, double)
method that is equal to the
previously passed-in input values, this noise module returns the cached
output value without having the source module recalculate the output value.
If an application passes a new source module to the
setSourceModule(int, NoiseModule)
method, the cache is invalidated.
Caching a noise module is useful if it is used as a source module for multiple noise modules. If a source module is not cached, the source module will redundantly calculate the same output value once for each noise module in which it is included.
This noise module requires one source module.
-
Field Summary
Fields inherited from class org.spongepowered.noise.module.NoiseModule
sourceModule
-
Constructor Summary
ConstructorDescriptionCache()
Cache
(NoiseModule source) Create a new Cache module with the source module pre-configured. -
Method Summary
Modifier and TypeMethodDescriptiondouble
get
(double x, double y, double z) Generates an output value given the coordinates of the specified input value.void
setSourceModule
(int index, NoiseModule sourceModule) Connects a source module to this noise module.Methods inherited from class org.spongepowered.noise.module.NoiseModule
sourceModule, sourceModuleCount
-
Constructor Details
-
Cache
public Cache() -
Cache
Create a new Cache module with the source module pre-configured.- Parameters:
source
- the module to cache
-
-
Method Details
-
setSourceModule
Description copied from class:NoiseModule
Connects a source module to this noise module.A noise module mathematically combines the output values from the source modules to generate the value returned by
NoiseModule.get(double, double, double)
.The
index
value to assign a source module is a unique identifier for that source module. If an index value has already been assigned to a source module, this noise module replaces the old source module with the new source module.Before an application can call the
NoiseModule.get(double, double, double)
method, it must first connect all the required source modules. To determine the number of source modules required by the noise module, call theNoiseModule.sourceModuleCount()
method.A noise module does not modify a souce module, it only modifies its output values.
- Overrides:
setSourceModule
in classNoiseModule
- Parameters:
index
- an index value to assign to this source module, must be in the range [0,NoiseModule.sourceModuleCount()
)sourceModule
- the source module to attach
-
get
public double get(double x, double y, double z) Description copied from class:NoiseModule
Generates an output value given the coordinates of the specified input value.All source modules required by this module must have been connected with the
NoiseModule.setSourceModule(int, NoiseModule)
method. If these source modules are not connected, this method will throw aNoModuleException
.To determine the number of source modules required by this noise module, call the
NoiseModule.sourceModuleCount()
method.- Specified by:
get
in classNoiseModule
- Parameters:
x
- thex
coordinate of the input valuey
- they
coordinate of the input valuez
- thez
coordinate of the input value- Returns:
- the output value
-