Skip to content

Commit

Permalink
feat(filter2): added new filter, update lib
Browse files Browse the repository at this point in the history
Updated cubiomes to latest commit files, added externs to finders.h for
  • Loading branch information
BoySanic committed Oct 13, 2020
1 parent 4b3eaf7 commit cc2e0a7
Show file tree
Hide file tree
Showing 9 changed files with 559 additions and 39 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.txt
126 changes: 98 additions & 28 deletions cubiomes/finders.c
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ int areBiomesViable(
int height = z2 - z1 + 1;
int i;
int *map;
int viable;

if (l->scale != 4)
{
Expand All @@ -562,20 +563,23 @@ int areBiomesViable(
}

map = cache ? cache : allocCache(l, width, height);
if (genArea(l, map, x1, z1, width, height))
return 0;
viable = !genArea(l, map, x1, z1, width, height);

for (i = 0; i < width*height; i++)
if (viable)
{
if (!biomeExists(map[i]) || !isValid[ map[i] ])
for (i = 0; i < width*height; i++)
{
if (cache == NULL) free(map);
return 0;
if (!biomeExists(map[i]) || !isValid[ map[i] ])
{
viable = 0;
break;
}
}
}

if (cache == NULL) free(map);
return 1;
if (cache == NULL)
free(map);
return viable;
}


Expand Down Expand Up @@ -625,6 +629,61 @@ int getBiomeRadius(
//==============================================================================


void approxInnerStrongholdRing(Pos p[3], int mcversion, int64_t s48)
{
int64_t rnds = s48;
setSeed(&rnds);

double angle = 2.0 * PI * nextDouble(&rnds);
double acos = cos(angle);
double asin = sin(angle);
double tmp, distance;

const double r120c = cos(2.0 * PI / 3);
const double r120s = sin(2.0 * PI / 3);

if (mcversion >= MC_1_9)
{
distance = (4.0 * 32.0) + (nextDouble(&rnds) - 0.5) * 32 * 2.5;
p[0].x = (int)round(acos * distance);
p[0].z = (int)round(asin * distance);
// rotate 120 degrees
tmp = acos;
acos = tmp * r120c - asin * r120s;
asin = tmp * r120s + asin * r120c;
distance = (4.0 * 32.0) + (nextDouble(&rnds) - 0.5) * 32 * 2.5;
p[1].x = (int)round(acos * distance);
p[1].z = (int)round(asin * distance);
// rotate 120 degrees
tmp = acos;
acos = tmp * r120c - asin * r120s;
asin = tmp * r120s + asin * r120c;
distance = (4.0 * 32.0) + (nextDouble(&rnds) - 0.5) * 32 * 2.5;
p[2].x = (int)round(acos * distance);
p[2].z = (int)round(asin * distance);
}
else
{
distance = (1.25 + nextDouble(&rnds)) * 32.0;
p[0].x = (int)round(acos * distance);
p[0].z = (int)round(asin * distance);
// rotate 120 degrees
tmp = acos;
acos = tmp * r120c - asin * r120s;
asin = tmp * r120s + asin * r120c;
distance = (1.25 + nextDouble(&rnds)) * 32.0;
p[1].x = (int)round(acos * distance);
p[1].z = (int)round(asin * distance);
// rotate 120 degrees
tmp = acos;
acos = tmp * r120c - asin * r120s;
asin = tmp * r120s + asin * r120c;
distance = (1.25 + nextDouble(&rnds)) * 32.0;
p[2].x = (int)round(acos * distance);
p[2].z = (int)round(asin * distance);
}
}

const char* getValidStrongholdBiomes()
{
static char validStrongholdBiomes[256];
Expand All @@ -644,7 +703,7 @@ const char* getValidStrongholdBiomes()


int findStrongholds(const int mcversion, const LayerStack *g, int *cache,
Pos *locations, int64_t worldSeed, int maxSH, const int maxRadius)
Pos *locations, int64_t worldSeed, int maxSH, int maxRing)
{
const char *validStrongholdBiomes = getValidStrongholdBiomes();
int i, x, z;
Expand All @@ -654,7 +713,7 @@ int findStrongholds(const int mcversion, const LayerStack *g, int *cache,
int currentCount = 0;
int perRing = 3;

setSeed(&worldSeed);
setSeed(&worldSeed); // PRNG
double angle = nextDouble(&worldSeed) * PI * 2.0;

const Layer *l = &g->layers[L_RIVER_MIX_4];
Expand All @@ -668,9 +727,6 @@ int findStrongholds(const int mcversion, const LayerStack *g, int *cache,
distance = (4.0 * 32.0) + (6.0 * currentRing * 32.0) +
(nextDouble(&worldSeed) - 0.5) * 32 * 2.5;

if (maxRadius && distance*16 > maxRadius)
return i;

x = (int)round(cos(angle) * distance);
z = (int)round(sin(angle) * distance);

Expand All @@ -685,6 +741,12 @@ int findStrongholds(const int mcversion, const LayerStack *g, int *cache,
{
// Current ring is complete, move to next ring.
currentRing++;
if (currentRing == maxRing)
{
i++;
break;
}

currentCount = 0;
perRing = perRing + 2*perRing/(currentRing+1);
if (perRing > 128-i)
Expand All @@ -701,9 +763,6 @@ int findStrongholds(const int mcversion, const LayerStack *g, int *cache,
{
distance = (1.25 + nextDouble(&worldSeed)) * 32.0;

if (maxRadius && distance*16 > maxRadius)
return i;

x = (int)round(cos(angle) * distance);
z = (int)round(sin(angle) * distance);

Expand All @@ -715,7 +774,7 @@ int findStrongholds(const int mcversion, const LayerStack *g, int *cache,
}
}

return maxSH;
return i;
}


Expand Down Expand Up @@ -782,7 +841,7 @@ static int canCoordinateBeSpawn(const int64_t seed, const LayerStack *g, int *ca
}


static const char* getValidSpawnBiomes()
const char* getValidSpawnBiomes()
{
static const int biomesToSpawnIn[] = {forest, plains, taiga, taiga_hills, wooded_hills, jungle, jungle_hills};
static char isValid[256];
Expand Down Expand Up @@ -1192,22 +1251,34 @@ int isViableStructurePos(int structureType, int mcversion, LayerStack *g,
}

case Monument:
// Monuments require two viability checks with the ocean layer branch =>
// worth checking for potential deep ocean beforehand.
l = &g->layers[L_SHORE_16];
setWorldSeed(l, seed);
map = allocCache(l, 1, 1);
if (genArea(l, map, chunkX, chunkZ, 1, 1))
goto L_NOT_VIABLE;
if (mcversion >= MC_1_9)
{
// Monuments require two viability checks with the ocean layer
// branch => worth checking for potential deep ocean beforehand.
l = &g->layers[L_SHORE_16];
setWorldSeed(l, seed);
map = allocCache(l, 1, 1);
if (genArea(l, map, chunkX, chunkZ, 1, 1))
goto L_NOT_VIABLE;
}
else
{
// In 1.8 monuments require only a single deep ocean block.
l = g->entry_1;
setWorldSeed(l, seed);
map = allocCache(l, 1, 1);
if (genArea(l, map, blockX, blockZ, 1, 1))
goto L_NOT_VIABLE;
}
if (!isDeepOcean(map[0]))
goto L_NOT_VIABLE;
if (mcversion >= MC_1_13)
l = &g->layers[L13_OCEAN_MIX_4];
else
l = &g->layers[L_RIVER_MIX_4];
setWorldSeed(l, seed);
if (areBiomesViable(l, NULL, blockX, blockZ, 16, getValidMonumentBiomes1()))
if (areBiomesViable(l, NULL, blockX, blockZ, 29, getValidMonumentBiomes2()))
if (mcversion < MC_1_9 || areBiomesViable(l, NULL, blockX, blockZ, 16, getValidMonumentBiomes2()))
if (areBiomesViable(l, NULL, blockX, blockZ, 29, getValidMonumentBiomes1()))
goto L_VIABLE;
goto L_NOT_VIABLE;

Expand Down Expand Up @@ -2076,4 +2147,3 @@ int hasAllTemps(LayerStack *g, int64_t seed, int x1024, int z1024)




24 changes: 19 additions & 5 deletions cubiomes/finders.h
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,20 @@ int getBiomeRadius(
// Finding Strongholds and Spawn
//==============================================================================

/* The chunk locations of the 3 closest strongholds, from the inner ring, can
* be approximated without going through the full biome check. However, the
* accurate positions as well as the locations of the strongholds in the outer
* rings depend on a pseudo-random-number which requires the full biome check
* for all strongholds before them.
*
* Up to MC_1_8 this covers the approximate location for all strongholds as
* there is only one ring.
*
* Note that this function requires only the lower 48-bits of the seed, and the
* accuracy is within +/-112 blocks.
*/
void approxInnerStrongholdRing(Pos p[3], int mcversion, int64_t s48);

/* Finds the block positions of the strongholds in the world. Note that the
* number of strongholds was increased from 3 to 128 in MC 1.9.
* Warning: Slow!
Expand All @@ -464,8 +478,7 @@ int getBiomeRadius(
* @worldSeed : world seed of the generator
* @maxSH : Stop when this many strongholds have been found. A value of 0
* defaults to 3 for mcversion <= MC_1_8, and to 128 for >= MC_1_9.
* @maxRadius : Stop searching if the radius exceeds this value in meters.
* Set this to 0 to ignore this condition.
* @maxRing : Stop after this many rings.
*
* Returned is the number of strongholds found.
*/
Expand All @@ -476,7 +489,7 @@ int findStrongholds(
Pos * locations,
int64_t worldSeed,
int maxSH,
const int maxRadius
int maxRing
);

/* Finds the spawn point in the world.
Expand Down Expand Up @@ -935,7 +948,8 @@ float isQuadBaseFeature(const StructureConfig sconf, int64_t seed,
x0,z0,x1,z1,x2,z2,x3,z3,ax,ay,az,sconf.regionSize,radius);
return sqrad < radius ? sqrad : 0;
}

const char* getValidStrongholdBiomes();
const char* getValidSpawnBiomes();

static inline __attribute__((always_inline, const))
float isQuadBaseLarge(const StructureConfig sconf, int64_t seed,
Expand Down Expand Up @@ -1013,4 +1027,4 @@ float isQuadBaseLarge(const StructureConfig sconf, int64_t seed,
}
#endif

#endif /* FINDERS_H_ */
#endif /* FINDERS_H_ */
9 changes: 4 additions & 5 deletions cubiomes/generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ static void setupScale(Layer *l, int scale)

mapfunc_t map = l->getMap;

if (map == mapZoom)
if (map == mapZoom || map == mapZoomIsland)
{
m = 2;
e = 2; // from ((w>>1)+1)<<1
e = 3;
}
else if (map == mapVoronoiZoom)
{
m = 4;
e = 8; // from ((w>>2)+2)<<2
e = 7;
}
else if (map == mapOceanMix)
{
Expand Down Expand Up @@ -209,7 +209,7 @@ static void getMaxArea(const Layer *layer, int areaX, int areaZ, int *maxX, int
if (layer == NULL)
return;

if (layer->getMap == mapZoom)
if (layer->getMap == mapZoom || layer->getMap == mapZoomIsland)
{
areaX >>= 1;
areaZ >>= 1;
Expand Down Expand Up @@ -264,4 +264,3 @@ int genArea(const Layer *layer, int *out, int areaX, int areaZ, int areaWidth, i




Binary file added filter2
Binary file not shown.
Loading

0 comments on commit cc2e0a7

Please sign in to comment.