More formatting changes.

This commit is contained in:
Cubitect 2018-07-28 16:36:41 +02:00
parent 5c9b46b701
commit a82ee1ccff
3 changed files with 57 additions and 49 deletions

View File

@ -23,7 +23,7 @@ void *searchCompactBiomesThread(void *data)
int64_t *seeds = (int64_t *) malloc(sizeof(*seeds)*SEED_BUF_LEN);
int64_t i, s, scnt;
LayerStack g = setupGenerator();
LayerStack g = setupGenerator(MC_1_7);
int *cache = allocCache(&g.layers[L_BIOME_256], 8, 8);
for(s = info.seedStart; s < info.seedEnd; s += SEED_BUF_LEN)

View File

@ -6,16 +6,6 @@
#include <string.h>
int *allocCache(Layer *layer, int sizeX, int sizeZ)
{
int size = calcRequiredBuf(layer, sizeX, sizeZ);
int *ret = (int*) malloc(sizeof(*ret)*size);
memset(ret, 0, sizeof(*ret)*size);
return ret;
}
void setupLayer(int scale, Layer *l, Layer *p, int s, void (*getMap)(Layer *layer, int *out, int x, int z, int w, int h))
{
setBaseSeed(l, s);
@ -37,15 +27,18 @@ void setupMultiLayer(int scale, Layer *l, Layer *p1, Layer *p2, int s, void (*ge
}
LayerStack setupGenerator()
LayerStack setupGenerator(const int mcversion)
{
return setupGeneratorMC17();
if (mcversion <= MC_1_12)
return setupGeneratorMC17();
else
return setupGeneratorMC113();
}
LayerStack setupGeneratorMC17()
{
if(biomes[plains].id == 0)
if (biomes[plains].id == 0)
{
fprintf(stderr, "Warning: The biomes have to be initialised first using initBiomes() before any generator can be used.\n");
}
@ -115,7 +108,7 @@ LayerStack setupGeneratorMC17()
LayerStack setupGeneratorMC113()
{
if(biomes[plains].id == 0)
if (biomes[plains].id == 0)
{
fprintf(stderr, "Warning: The biomes have to be initialised first using initBiomes() before any generator can be used.\n");
}
@ -123,7 +116,7 @@ LayerStack setupGeneratorMC113()
LayerStack g;
g.layerNum = 52;
g.layers = (Layer*) malloc(sizeof(Layer)*g.layerNum);
g.layers = (Layer *) malloc(sizeof(Layer) * g.layerNum);
// SCALE LAYER PARENT SEED LAYER_FUNCTION
setupLayer(4096, &g.layers[ 0], NULL, 1, mapIsland);
@ -196,30 +189,45 @@ LayerStack setupGeneratorMC113()
return g;
}
void freeGenerator(LayerStack g)
{
int i;
for(i = 0; i < g.layerNum; i++)
{
if (g.layers[i].oceanRnd != NULL)
free(g.layers[i].oceanRnd);
}
free(g.layers);
}
/* Recursively calculates the minimum buffer size required to generate an area
* of the specified size from the current layer onwards.
*/
static void getMaxArea(Layer *layer, int areaX, int areaZ, int *maxX, int *maxZ)
{
if(layer == NULL)
if (layer == NULL)
return;
if(layer->getMap == mapZoom)
if (layer->getMap == mapZoom)
{
areaX = (areaX >> 1) + 2;
areaZ = (areaZ >> 1) + 2;
}
else if(layer->getMap == mapVoronoiZoom)
else if (layer->getMap == mapVoronoiZoom)
{
areaX = (areaX >> 2) + 2;
areaZ = (areaZ >> 2) + 2;
}
else if(layer->getMap == mapOceanMix)
else if (layer->getMap == mapOceanMix)
{
areaX += 17;
areaZ += 17;
}
else
{
if( layer->getMap != mapNull &&
if (layer->getMap != mapNull &&
layer->getMap != mapSkip &&
layer->getMap != mapIsland &&
layer->getMap != mapSpecial &&
@ -233,14 +241,13 @@ static void getMaxArea(Layer *layer, int areaX, int areaZ, int *maxX, int *maxZ)
}
}
if(areaX > *maxX) *maxX = areaX;
if(areaZ > *maxZ) *maxZ = areaZ;
if (areaX > *maxX) *maxX = areaX;
if (areaZ > *maxZ) *maxZ = areaZ;
getMaxArea(layer->p, areaX, areaZ, maxX, maxZ);
getMaxArea(layer->p2, areaX, areaZ, maxX, maxZ);
}
int calcRequiredBuf(Layer *layer, int areaX, int areaZ)
{
int maxX = areaX, maxZ = areaZ;
@ -249,25 +256,23 @@ int calcRequiredBuf(Layer *layer, int areaX, int areaZ)
return maxX * maxZ;
}
void freeGenerator(LayerStack g)
int *allocCache(Layer *layer, int sizeX, int sizeZ)
{
int i;
for(i = 0; i < g.layerNum; i++)
{
if(g.layers[i].oceanRnd != NULL)
free(g.layers[i].oceanRnd);
}
int size = calcRequiredBuf(layer, sizeX, sizeZ);
free(g.layers);
int *ret = (int *) malloc(sizeof(*ret)*size);
memset(ret, 0, sizeof(*ret)*size);
return ret;
}
void applySeed(LayerStack *g, int64_t seed)
{
// the seed has to be applied recursively
setWorldSeed(&g->layers[g->layerNum-1], seed);
}
void genArea(Layer *layer, int *out, int areaX, int areaZ, int areaWidth, int areaHeight)
{
memset(out, 0, areaWidth*areaHeight*sizeof(*out));

View File

@ -80,36 +80,39 @@ STRUCT(LayerStack)
int layerNum;
};
// Initialise an instance of a generator
LayerStack setupGenerator();
/* Initialise an instance of a generator. */
LayerStack setupGenerator(const int mcversion);
LayerStack setupGeneratorMC17();
LayerStack setupGeneratorMC113();
// Cleans up and frees the generator layers
/* Cleans up and frees the generator layers */
void freeGenerator(LayerStack g);
// Allocates an amount of memory required to generate an area of dimensions
// 'sizeX' by 'sizeZ' for the magnification of the current top layer.
/* Calculates the minimum size of the buffers required to generate an area of
* dimensions 'sizeX' by 'sizeZ' at the specified layer.
*/
int calcRequiredBuf(Layer *layer, int areaX, int areaZ);
/* Allocates an amount of memory required to generate an area of dimensions
* 'sizeX' by 'sizeZ' for the magnification of the current top layer.
*/
int *allocCache(Layer *layer, int sizeX, int sizeZ);
// Set up custom layers
/* Set up custom layers. */
void setupLayer(int scale, Layer *l, Layer *p, int s, void (*getMap)(Layer *layer, int *out, int x, int z, int w, int h));
void setupMultiLayer(int scale, Layer *l, Layer *p1, Layer *p2, int s, void (*getMap)(Layer *layer, int *out, int x, int z, int w, int h));
// Calculates the minimum size of the buffers required to generate an area of dimensions
// 'sizeX' by 'sizeZ' at the specified layer.
int calcRequiredBuf(Layer *layer, int areaX, int areaZ);
// Sets the world seed for the generator
/* Sets the world seed for the generator */
void applySeed(LayerStack *g, int64_t seed);
/*
* genArea
* -------
* Generates the specified area using the current generator settings and stores the biomeIDs in 'out'.
/* 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.
* It is recommended that 'out' is allocated using allocCache() for the correct
* buffer size.
*/
void genArea(Layer *layer, int *out, int areaX, int areaZ, int areaWidth, int areaHeight);