cubiomes/generator.h

145 lines
4.3 KiB
C
Raw Permalink Normal View History

2018-03-06 05:20:54 +08:00
#ifndef GENERATOR_H_
#define GENERATOR_H_
#include "layers.h"
#include "biomenoise.h"
2018-03-06 05:20:54 +08:00
// generator flags
enum
{
LARGE_BIOMES = 0x1,
Added Beta climate biome generation (no ocean gen yet) (biome_tree.c) - getOldBetaBiome: removed isWater argument. (finders.c) - getStructureConfig: now returns 0 for mineshafts and villages before B1.8. (layers.h) - Added SurfaceNoiseBeta struct: Very similar to SurfaceNoise. Since SurfaceNoiseBeta will only ever be used for the Overworld, the double values saved in SurfaceNoise will be hardcoded into the SurfaceNoiseBeta sampling function. octSurf and octDepth in surfaceNoise are replaced with new octA and octB OctaveNoises, used for precise terrain generation. These names are subject to change if I come up with more meaningful names in the future. The oct array contains six additional PerlinNoise structs compared to SurfaceNoise, as the 4-octave octSurf is replaced with the 10-octave octA. - Added BiomeNoiseBeta struct: Mostly a cut-down version of BiomeNoise. The climate array contains three OctaveNoise structs, corresponding to the 4-octave temperature and humidity noise generators, as well as an additional 2-octave generator that I'm calling "fuzz". The fuzz noise is high-frequency and low-amplitude, and is used as a factor applied to the raw output of both the temperature and humidity generators before these values are used. The PerlinNoise array oct contains 10 octaves -- 4 for temperature, 4 for humidity, and 2 for fuzz. nptype and mc are carried over from BiomeNoise. mc currently has no purpose, but I've heard of a bug in some early beta versions causing chunk biomes to generate rotated, so storing the version may eventually prove useful. - Added headers for 5 new functions in layers.c. - Changed header for getOldBetaBiome (defined in biome_tree.c) to reflect new signature. (layers.c) - Added initSurfaceNoiseBeta function: No-op placeholder for now. - Added setBetaBiomeSeed function: Initializes the three climate simplex noise generators and sets bnb->nptype to -1 by default. - Added sampleBiomeNoiseBeta function: sampleBiomeNoiseBeta samples climate noise at the given x and z coordinates (1:1 scale) and returns a biome ID corresponding to the biome at the generated temperature and humidity noise values. The behavior of zeroing out the array np when it is passed is copied from sampleBiomeNoise. I'm not sure about its function, so if it's not applicable, this argument and associated behavior can be removed. If bnb->nptype is set to NP_TEMPERATURE or NP_HUMIDITY, only that noise value is generated and the other is ignored. The noise value is multiplied by 10000 and returned as a signed long to match the behavior of sampleBiomeNoise. Note that Beta climate values range from 0 to 1, not -1 to 1, so the resulting ints will all be nonnegative. The argument nv (noise values) is a pointer to a 2-element array of doubles. If it is present, the noise values are placed in the array before the biome is determined. - Added genBetaBiomeNoiseScaled function: At 1:1 scale, every block in Range r is sampled and the return value of sampleBiomeNoiseBeta is placed in the cache. At higher scales, midpoints are sampled. When ocean support is added, this function will likely behave differently when NO_BETA_OCEAN is clear in order to maximize time and memory efficiency. (generator.h) - Flags enum: Bit 1 (0x2) is now the NO_BETA_OCEAN flag. - Generator struct: New union member for pre-B1.8: Includes BiomeNoiseBeta and SurfaceNoiseBeta structs now defined in layers.h (generator.c) - setupGenearator: New version so pre-B1.8 versions behave correctly. For mc <= MC_B1_7, setupGenerator simply sets g->bnb.mc, as all other setup for pre-B1.8 biome generation requires the seed to be known. - applySeed: When mc <= MC_B1_7, the new setBetaBiomeSeed function defined in layers.c is called. If the NO_BETA_OCEAN flag is not set, initSurfaceNoiseBeta is also called. initSurfaceNoiseBeta is currently just a no-op placeholder. - getMinCacheSize: New version check. Returns default size when mc <= MC_B1_7. Will likely be modified when ocean-finding functionality is added. - genBiomes: Calls genBetaBiomeNoiseScaled when mc <= MC_B1_7 Note: Compiling libcubiomes.a will will currently cause several warnings due to unused parameters related to not-yet-implemented ocean finding.
2023-01-24 05:51:54 +08:00
NO_BETA_OCEAN = 0x2,
FORCE_OCEAN_VARIANTS = 0x4,
};
2018-03-18 00:53:16 +08:00
STRUCT(Generator)
{
int mc;
int dim;
uint32_t flags;
uint64_t seed;
uint64_t sha;
union {
struct { // MC 1.0 - 1.17
LayerStack ls;
Layer xlayer[5]; // buffer for custom entry layers @{1,4,16,64,256}
Layer *entry;
};
struct { // MC 1.18
BiomeNoise bn;
};
Added Beta climate biome generation (no ocean gen yet) (biome_tree.c) - getOldBetaBiome: removed isWater argument. (finders.c) - getStructureConfig: now returns 0 for mineshafts and villages before B1.8. (layers.h) - Added SurfaceNoiseBeta struct: Very similar to SurfaceNoise. Since SurfaceNoiseBeta will only ever be used for the Overworld, the double values saved in SurfaceNoise will be hardcoded into the SurfaceNoiseBeta sampling function. octSurf and octDepth in surfaceNoise are replaced with new octA and octB OctaveNoises, used for precise terrain generation. These names are subject to change if I come up with more meaningful names in the future. The oct array contains six additional PerlinNoise structs compared to SurfaceNoise, as the 4-octave octSurf is replaced with the 10-octave octA. - Added BiomeNoiseBeta struct: Mostly a cut-down version of BiomeNoise. The climate array contains three OctaveNoise structs, corresponding to the 4-octave temperature and humidity noise generators, as well as an additional 2-octave generator that I'm calling "fuzz". The fuzz noise is high-frequency and low-amplitude, and is used as a factor applied to the raw output of both the temperature and humidity generators before these values are used. The PerlinNoise array oct contains 10 octaves -- 4 for temperature, 4 for humidity, and 2 for fuzz. nptype and mc are carried over from BiomeNoise. mc currently has no purpose, but I've heard of a bug in some early beta versions causing chunk biomes to generate rotated, so storing the version may eventually prove useful. - Added headers for 5 new functions in layers.c. - Changed header for getOldBetaBiome (defined in biome_tree.c) to reflect new signature. (layers.c) - Added initSurfaceNoiseBeta function: No-op placeholder for now. - Added setBetaBiomeSeed function: Initializes the three climate simplex noise generators and sets bnb->nptype to -1 by default. - Added sampleBiomeNoiseBeta function: sampleBiomeNoiseBeta samples climate noise at the given x and z coordinates (1:1 scale) and returns a biome ID corresponding to the biome at the generated temperature and humidity noise values. The behavior of zeroing out the array np when it is passed is copied from sampleBiomeNoise. I'm not sure about its function, so if it's not applicable, this argument and associated behavior can be removed. If bnb->nptype is set to NP_TEMPERATURE or NP_HUMIDITY, only that noise value is generated and the other is ignored. The noise value is multiplied by 10000 and returned as a signed long to match the behavior of sampleBiomeNoise. Note that Beta climate values range from 0 to 1, not -1 to 1, so the resulting ints will all be nonnegative. The argument nv (noise values) is a pointer to a 2-element array of doubles. If it is present, the noise values are placed in the array before the biome is determined. - Added genBetaBiomeNoiseScaled function: At 1:1 scale, every block in Range r is sampled and the return value of sampleBiomeNoiseBeta is placed in the cache. At higher scales, midpoints are sampled. When ocean support is added, this function will likely behave differently when NO_BETA_OCEAN is clear in order to maximize time and memory efficiency. (generator.h) - Flags enum: Bit 1 (0x2) is now the NO_BETA_OCEAN flag. - Generator struct: New union member for pre-B1.8: Includes BiomeNoiseBeta and SurfaceNoiseBeta structs now defined in layers.h (generator.c) - setupGenearator: New version so pre-B1.8 versions behave correctly. For mc <= MC_B1_7, setupGenerator simply sets g->bnb.mc, as all other setup for pre-B1.8 biome generation requires the seed to be known. - applySeed: When mc <= MC_B1_7, the new setBetaBiomeSeed function defined in layers.c is called. If the NO_BETA_OCEAN flag is not set, initSurfaceNoiseBeta is also called. initSurfaceNoiseBeta is currently just a no-op placeholder. - getMinCacheSize: New version check. Returns default size when mc <= MC_B1_7. Will likely be modified when ocean-finding functionality is added. - genBiomes: Calls genBetaBiomeNoiseScaled when mc <= MC_B1_7 Note: Compiling libcubiomes.a will will currently cause several warnings due to unused parameters related to not-yet-implemented ocean finding.
2023-01-24 05:51:54 +08:00
struct { // MC A1.2 - B1.7
BiomeNoiseBeta bnb;
//SurfaceNoiseBeta snb;
Added Beta climate biome generation (no ocean gen yet) (biome_tree.c) - getOldBetaBiome: removed isWater argument. (finders.c) - getStructureConfig: now returns 0 for mineshafts and villages before B1.8. (layers.h) - Added SurfaceNoiseBeta struct: Very similar to SurfaceNoise. Since SurfaceNoiseBeta will only ever be used for the Overworld, the double values saved in SurfaceNoise will be hardcoded into the SurfaceNoiseBeta sampling function. octSurf and octDepth in surfaceNoise are replaced with new octA and octB OctaveNoises, used for precise terrain generation. These names are subject to change if I come up with more meaningful names in the future. The oct array contains six additional PerlinNoise structs compared to SurfaceNoise, as the 4-octave octSurf is replaced with the 10-octave octA. - Added BiomeNoiseBeta struct: Mostly a cut-down version of BiomeNoise. The climate array contains three OctaveNoise structs, corresponding to the 4-octave temperature and humidity noise generators, as well as an additional 2-octave generator that I'm calling "fuzz". The fuzz noise is high-frequency and low-amplitude, and is used as a factor applied to the raw output of both the temperature and humidity generators before these values are used. The PerlinNoise array oct contains 10 octaves -- 4 for temperature, 4 for humidity, and 2 for fuzz. nptype and mc are carried over from BiomeNoise. mc currently has no purpose, but I've heard of a bug in some early beta versions causing chunk biomes to generate rotated, so storing the version may eventually prove useful. - Added headers for 5 new functions in layers.c. - Changed header for getOldBetaBiome (defined in biome_tree.c) to reflect new signature. (layers.c) - Added initSurfaceNoiseBeta function: No-op placeholder for now. - Added setBetaBiomeSeed function: Initializes the three climate simplex noise generators and sets bnb->nptype to -1 by default. - Added sampleBiomeNoiseBeta function: sampleBiomeNoiseBeta samples climate noise at the given x and z coordinates (1:1 scale) and returns a biome ID corresponding to the biome at the generated temperature and humidity noise values. The behavior of zeroing out the array np when it is passed is copied from sampleBiomeNoise. I'm not sure about its function, so if it's not applicable, this argument and associated behavior can be removed. If bnb->nptype is set to NP_TEMPERATURE or NP_HUMIDITY, only that noise value is generated and the other is ignored. The noise value is multiplied by 10000 and returned as a signed long to match the behavior of sampleBiomeNoise. Note that Beta climate values range from 0 to 1, not -1 to 1, so the resulting ints will all be nonnegative. The argument nv (noise values) is a pointer to a 2-element array of doubles. If it is present, the noise values are placed in the array before the biome is determined. - Added genBetaBiomeNoiseScaled function: At 1:1 scale, every block in Range r is sampled and the return value of sampleBiomeNoiseBeta is placed in the cache. At higher scales, midpoints are sampled. When ocean support is added, this function will likely behave differently when NO_BETA_OCEAN is clear in order to maximize time and memory efficiency. (generator.h) - Flags enum: Bit 1 (0x2) is now the NO_BETA_OCEAN flag. - Generator struct: New union member for pre-B1.8: Includes BiomeNoiseBeta and SurfaceNoiseBeta structs now defined in layers.h (generator.c) - setupGenearator: New version so pre-B1.8 versions behave correctly. For mc <= MC_B1_7, setupGenerator simply sets g->bnb.mc, as all other setup for pre-B1.8 biome generation requires the seed to be known. - applySeed: When mc <= MC_B1_7, the new setBetaBiomeSeed function defined in layers.c is called. If the NO_BETA_OCEAN flag is not set, initSurfaceNoiseBeta is also called. initSurfaceNoiseBeta is currently just a no-op placeholder. - getMinCacheSize: New version check. Returns default size when mc <= MC_B1_7. Will likely be modified when ocean-finding functionality is added. - genBiomes: Calls genBetaBiomeNoiseScaled when mc <= MC_B1_7 Note: Compiling libcubiomes.a will will currently cause several warnings due to unused parameters related to not-yet-implemented ocean finding.
2023-01-24 05:51:54 +08:00
};
};
NetherNoise nn; // MC 1.16
EndNoise en; // MC 1.9
};
#ifdef __cplusplus
extern "C"
{
#endif
///=============================================================================
/// Biome Generation
///=============================================================================
/**
* Sets up a biome generator for a given MC version. The 'flags' can be used to
* control LARGE_BIOMES or to FORCE_OCEAN_VARIANTS to enable ocean variants at
* scales higher than normal.
*/
void setupGenerator(Generator *g, int mc, uint32_t flags);
/**
* Initializes the generator for a given dimension and seed.
* dim=0: Overworld
* dim=-1: Nether
* dim=+1: End
*/
void applySeed(Generator *g, int dim, uint64_t seed);
/**
* Calculates the buffer size (number of ints) required to generate a cuboidal
* volume of size (sx, sy, sz). If 'sy' is zero the buffer is calculated for a
* 2D plane (which is equivalent to sy=1 here).
* The function allocCache() can be used to allocate the corresponding int
* buffer using malloc().
*/
size_t getMinCacheSize(const Generator *g, int scale, int sx, int sy, int sz);
int *allocCache(const Generator *g, Range r);
/**
* Generates the biomes for a cuboidal scaled range given by 'r'.
* (See description of Range for more detail.)
*
* The output is generated inside the cache. Upon success the biome ids can be
* accessed by indexing as:
* cache[ y*r.sx*r.sz + z*r.sx + x ]
* where (x,y,z) is an relative position inside the range cuboid.
*
* The required length of the cache can be determined with getMinCacheSize().
*
* The return value is zero upon success.
*/
int genBiomes(const Generator *g, int *cache, Range r);
/**
* Gets the biome for a specified scaled position. Note that the scale should
* be either 1 or 4, for block or biome coordinates respectively.
* Returns none (-1) upon failure.
*/
int getBiomeAt(const Generator *g, int scale, int x, int y, int z);
/**
* Returns the default layer that corresponds to the given scale.
* Supported scales are {0, 1, 4, 16, 64, 256}. A scale of zero indicates the
* custom entry layer 'g->entry'.
* (Overworld, MC <= 1.17)
*/
const Layer *getLayerForScale(const Generator *g, int scale);
///=============================================================================
/// Layered Biome Generation (old interface up to 1.17)
///=============================================================================
/* Initialize an instance of a layered generator. */
void setupLayerStack(LayerStack *g, int mc, int largeBiomes);
/* Calculates the minimum size of the buffers required to generate an area of
* dimensions 'sizeX' by 'sizeZ' at the specified layer.
*/
size_t getMinLayerCacheSize(const Layer *layer, int sizeX, int sizeZ);
/* Set up custom layers. */
Layer *setupLayer(Layer *l, mapfunc_t *map, int mc,
int8_t zoom, int8_t edge, uint64_t saltbase, Layer *p, Layer *p2);
/* Generates the specified area using the current generator settings and stores
* the biomeIDs in 'out'.
* The biomeIDs will be indexed in the form: out[x + z*areaWidth]
* It is recommended that 'out' is allocated using allocCache() for the correct
* buffer size.
*/
int genArea(const Layer *layer, int *out, int areaX, int areaZ, int areaWidth, int areaHeight);
/**
* Map an approximation of the Overworld surface height.
* The horizontal scaling is 1:4. If non-null, the ids are filled with the
* biomes of the area. The height (written to y) is in blocks.
*/
int mapApproxHeight(float *y, int *ids, const Generator *g,
const SurfaceNoise *sn, int x, int z, int w, int h);
#ifdef __cplusplus
}
#endif
2018-03-06 05:20:54 +08:00
#endif /* GENERATOR_H_ */