mirror of
https://github.com/Cubitect/cubiomes.git
synced 2025-09-24 04:03:39 -04:00
Formatting for layers.
This commit is contained in:
parent
a82ee1ccff
commit
8d6dc1fce2
27
layers.c
27
layers.c
@ -180,7 +180,9 @@ void mapIsland(Layer *l, int * __restrict out, int areaX, int areaZ, int areaWid
|
||||
}
|
||||
|
||||
#if defined USE_SIMD && defined __AVX2__
|
||||
void mapZoom(Layer *l, int* __restrict out, int areaX, int areaZ, int areaWidth, int areaHeight) {
|
||||
|
||||
void mapZoom(Layer *l, int* __restrict out, int areaX, int areaZ, int areaWidth, int areaHeight)
|
||||
{
|
||||
int pWidth = (areaWidth>>1)+2, pHeight = (areaHeight>>1)+1;
|
||||
|
||||
l->p->getMap(l->p, out, areaX>>1, areaZ>>1, pWidth, pHeight+1);
|
||||
@ -198,11 +200,13 @@ void mapZoom(Layer *l, int* __restrict out, int areaX, int areaZ, int areaWidth,
|
||||
int* idx = buf;
|
||||
int* outIdx = out;
|
||||
//z first!
|
||||
for (x = 0; x < pWidth-1; x += 8) {
|
||||
for (x = 0; x < pWidth-1; x += 8)
|
||||
{
|
||||
a = _mm256_loadu_si256((__m256i*)(outIdx));//0, 0
|
||||
b = _mm256_loadu_si256((__m256i*)(outIdx+1));//1, 0
|
||||
zs = _mm256_set1_epi32(areaZ&0xFFFFFFFE);
|
||||
for (z = 0; z < pHeight; z++) {
|
||||
for (z = 0; z < pHeight; z++)
|
||||
{
|
||||
cs = set8ChunkSeeds(l->worldSeed, xs, zs);
|
||||
outIdx += pWidth;
|
||||
a1 = _mm256_loadu_si256((__m256i*)(outIdx));//0, 1
|
||||
@ -237,8 +241,11 @@ void mapZoom(Layer *l, int* __restrict out, int areaX, int areaZ, int areaWidth,
|
||||
|
||||
free(buf);
|
||||
}
|
||||
|
||||
#elif defined USE_SIMD && defined __SSE4_2__
|
||||
void mapZoom(Layer *l, int* __restrict out, int areaX, int areaZ, int areaWidth, int areaHeight) {
|
||||
|
||||
void mapZoom(Layer *l, int* __restrict out, int areaX, int areaZ, int areaWidth, int areaHeight)
|
||||
{
|
||||
int pWidth = (areaWidth>>1)+2, pHeight = (areaHeight>>1)+1;
|
||||
|
||||
l->p->getMap(l->p, out, areaX>>1, areaZ>>1, pWidth, pHeight+1);
|
||||
@ -255,11 +262,13 @@ void mapZoom(Layer *l, int* __restrict out, int areaX, int areaZ, int areaWidth,
|
||||
int* idx = buf;
|
||||
int* outIdx = out;
|
||||
//z first!
|
||||
for (x = 0; x < pWidth-1; x += 4) {
|
||||
for (x = 0; x < pWidth-1; x += 4)
|
||||
{
|
||||
a = _mm_loadu_si128((__m128i_u*)(outIdx));//0, 0
|
||||
b = _mm_loadu_si128((__m128i_u*)(outIdx+1));//1, 0
|
||||
zs = _mm_set1_epi32(areaZ&0xFFFFFFFE);
|
||||
for (z = 0; z < pHeight; z++) {
|
||||
for (z = 0; z < pHeight; z++)
|
||||
{
|
||||
cs = set4ChunkSeeds(l->worldSeed, xs, zs);
|
||||
outIdx += pWidth;
|
||||
a1 = _mm_loadu_si128((__m128i_u*)(outIdx));//0, 1
|
||||
@ -294,7 +303,9 @@ void mapZoom(Layer *l, int* __restrict out, int areaX, int areaZ, int areaWidth,
|
||||
|
||||
free(buf);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void mapZoom(Layer *l, int * __restrict out, int areaX, int areaZ, int areaWidth, int areaHeight)
|
||||
{
|
||||
int pX = areaX >> 1;
|
||||
@ -1420,9 +1431,7 @@ void mapRiverMix(Layer *l, int * __restrict out, int areaX, int areaZ, int areaW
|
||||
|
||||
|
||||
|
||||
/* oceanRndInit
|
||||
* ------------
|
||||
* Initialises data for the ocean temperature types using the world seed.
|
||||
/* Initialises data for the ocean temperature types using the world seed.
|
||||
* This function is called when the world seed is applied in setWorldSeed().
|
||||
*/
|
||||
static void oceanRndInit(OceanRnd *rnd, int64_t seed)
|
||||
|
63
layers.h
63
layers.h
@ -26,7 +26,8 @@
|
||||
#define OPT_O2 __attribute__((optimize("O2")))
|
||||
|
||||
|
||||
enum BiomeID {
|
||||
enum BiomeID
|
||||
{
|
||||
none = -1,
|
||||
ocean = 0, plains, desert, extremeHills, forest, taiga, swampland, river, hell, sky, // 0-9
|
||||
frozenOcean, frozenRiver, icePlains, iceMountains, mushroomIsland, mushroomIslandShore, beach, desertHills, forestHills, taigaHills, // 10-19
|
||||
@ -38,11 +39,13 @@ enum BiomeID {
|
||||
BIOME_NUM
|
||||
};
|
||||
|
||||
enum BiomeType {
|
||||
enum BiomeType
|
||||
{
|
||||
Ocean, Plains, Desert, Hills, Forest, Taiga, Swamp, River, Hell, Sky, Snow, MushroomIsland, Beach, Jungle, StoneBeach, Savanna, Mesa, BTYPE_NUM
|
||||
};
|
||||
|
||||
enum BiomeTempCategory {
|
||||
enum BiomeTempCategory
|
||||
{
|
||||
Oceanic, Warm, Lush, Cold, Freezing, Unknown
|
||||
};
|
||||
|
||||
@ -56,7 +59,6 @@ STRUCT(Biome)
|
||||
int tempCat;
|
||||
};
|
||||
|
||||
|
||||
STRUCT(OceanRnd)
|
||||
{
|
||||
int d[512];
|
||||
@ -80,19 +82,23 @@ STRUCT(Layer)
|
||||
};
|
||||
|
||||
|
||||
//==============================================================================
|
||||
// Essentials
|
||||
//==============================================================================
|
||||
|
||||
extern Biome biomes[256];
|
||||
|
||||
|
||||
/* initBiomes() has to be called before any of the generators can be used */
|
||||
void initBiomes();
|
||||
|
||||
/* setWorldSeed
|
||||
* ------------
|
||||
* Applies the given world seed to the layer and all dependent layers.
|
||||
*/
|
||||
/* Applies the given world seed to the layer and all dependent layers. */
|
||||
void setWorldSeed(Layer *layer, int64_t seed);
|
||||
|
||||
|
||||
//==============================================================================
|
||||
// Static Helpers
|
||||
//==============================================================================
|
||||
|
||||
static inline int getBiomeType(int id)
|
||||
{
|
||||
@ -208,7 +214,9 @@ static inline void setBaseSeed(Layer *layer, int64_t seed)
|
||||
}
|
||||
|
||||
#if defined USE_SIMD && __AVX2__
|
||||
static inline __m256i set8ChunkSeeds(int ws, __m256i xs, __m256i zs) {
|
||||
|
||||
static inline __m256i set8ChunkSeeds(int ws, __m256i xs, __m256i zs)
|
||||
{
|
||||
__m256i out = _mm256_set1_epi32(ws);
|
||||
__m256i mul = _mm256_set1_epi32(1284865837);
|
||||
__m256i add = _mm256_set1_epi32(4150755663);
|
||||
@ -218,19 +226,22 @@ static inline __m256i set8ChunkSeeds(int ws, __m256i xs, __m256i zs) {
|
||||
return _mm256_add_epi32(zs, _mm256_mullo_epi32(out, _mm256_add_epi32(add, _mm256_mullo_epi32(out, mul))));
|
||||
}
|
||||
|
||||
static inline __m256i mc8NextInt(__m256i* cs, int ws, int mask) {
|
||||
static inline __m256i mc8NextInt(__m256i* cs, int ws, int mask)
|
||||
{
|
||||
__m256i and = _mm256_set1_epi32(mask);
|
||||
__m256i ret = _mm256_and_si256(and, _mm256_srli_epi32(*cs, 24));
|
||||
*cs = _mm256_add_epi32(_mm256_set1_epi32(ws), _mm256_mullo_epi32(*cs, _mm256_add_epi32(_mm256_set1_epi32(4150755663), _mm256_mullo_epi32(*cs, _mm256_set1_epi32(1284865837)))));
|
||||
return _mm256_add_epi32(ret, _mm256_and_si256(and, _mm256_cmpgt_epi32(_mm256_set1_epi32(0), ret)));;
|
||||
}
|
||||
|
||||
static inline __m256i select8Random2(__m256i* cs, int ws, __m256i a1, __m256i a2) {
|
||||
static inline __m256i select8Random2(__m256i* cs, int ws, __m256i a1, __m256i a2)
|
||||
{
|
||||
__m256i cmp = _mm256_cmpeq_epi32(_mm256_set1_epi32(0), mc8NextInt(cs, ws, 0x1));
|
||||
return _mm256_or_si256(_mm256_and_si256(cmp, a1), _mm256_andnot_si256(cmp, a2));
|
||||
}
|
||||
|
||||
static inline __m256i select8Random4(__m256i* cs, int ws, __m256i a1, __m256i a2, __m256i a3, __m256i a4) {
|
||||
static inline __m256i select8Random4(__m256i* cs, int ws, __m256i a1, __m256i a2, __m256i a3, __m256i a4)
|
||||
{
|
||||
__m256i val = mc8NextInt(cs, ws, 0x3);
|
||||
__m256i v2 = _mm256_set1_epi32(2);
|
||||
__m256i cmp1 = _mm256_cmpeq_epi32(val, _mm256_set1_epi32(0));
|
||||
@ -242,7 +253,8 @@ static inline __m256i select8Random4(__m256i* cs, int ws, __m256i a1, __m256i a2
|
||||
);
|
||||
}
|
||||
|
||||
static inline __m256i select8ModeOrRandom(__m256i* cs, int ws, __m256i a1, __m256i a2, __m256i a3, __m256i a4) {
|
||||
static inline __m256i select8ModeOrRandom(__m256i* cs, int ws, __m256i a1, __m256i a2, __m256i a3, __m256i a4)
|
||||
{
|
||||
__m256i cmp1 = _mm256_cmpeq_epi32(a1, a2);
|
||||
__m256i cmp2 = _mm256_cmpeq_epi32(a1, a3);
|
||||
__m256i cmp3 = _mm256_cmpeq_epi32(a1, a4);
|
||||
@ -261,6 +273,7 @@ static inline __m256i select8ModeOrRandom(__m256i* cs, int ws, __m256i a1, __m25
|
||||
_mm256_andnot_si256(cmp2, cmp5)
|
||||
);
|
||||
__m256i isa3 = _mm256_andnot_si256(cmp1, cmp6);
|
||||
|
||||
return _mm256_or_si256(
|
||||
_mm256_andnot_si256(
|
||||
_mm256_or_si256(
|
||||
@ -278,8 +291,11 @@ static inline __m256i select8ModeOrRandom(__m256i* cs, int ws, __m256i a1, __m25
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#elif defined USE_SIMD && defined __SSE4_2__
|
||||
static inline __m128i set4ChunkSeeds(int ws, __m128i xs, __m128i zs) {
|
||||
|
||||
static inline __m128i set4ChunkSeeds(int ws, __m128i xs, __m128i zs)
|
||||
{
|
||||
__m128i out = _mm_set1_epi32(ws);
|
||||
__m128i mul = _mm_set1_epi32(1284865837);
|
||||
__m128i add = _mm_set1_epi32(4150755663);
|
||||
@ -289,19 +305,22 @@ static inline __m128i set4ChunkSeeds(int ws, __m128i xs, __m128i zs) {
|
||||
return _mm_add_epi32(zs, _mm_mullo_epi32(out, _mm_add_epi32(add, _mm_mullo_epi32(out, mul))));
|
||||
}
|
||||
|
||||
static inline __m128i mc4NextInt(__m128i* cs, int ws, int mask) {
|
||||
static inline __m128i mc4NextInt(__m128i* cs, int ws, int mask)
|
||||
{
|
||||
__m128i and = _mm_set1_epi32(mask);
|
||||
__m128i ret = _mm_and_si128(and, _mm_srli_epi32(*cs, 24));
|
||||
*cs = _mm_add_epi32( _mm_set1_epi32(ws), _mm_mullo_epi32(*cs, _mm_add_epi32(_mm_set1_epi32(4150755663), _mm_mullo_epi32(*cs, _mm_set1_epi32(1284865837)))));
|
||||
return _mm_add_epi32(ret, _mm_and_si128(and, _mm_cmplt_epi32(ret, _mm_set1_epi32(0))));;
|
||||
}
|
||||
|
||||
static inline __m128i select4Random2(__m128i* cs, int ws, __m128i a1, __m128i a2) {
|
||||
static inline __m128i select4Random2(__m128i* cs, int ws, __m128i a1, __m128i a2)
|
||||
{
|
||||
__m128i cmp = _mm_cmpeq_epi32(_mm_set1_epi32(0), mc4NextInt(cs, ws, 0x1));
|
||||
return _mm_or_si128(_mm_and_si128(cmp, a1), _mm_andnot_si128(cmp, a2));
|
||||
}
|
||||
|
||||
static inline __m128i select4Random4(__m128i* cs, int ws, __m128i a1, __m128i a2, __m128i a3, __m128i a4) {
|
||||
static inline __m128i select4Random4(__m128i* cs, int ws, __m128i a1, __m128i a2, __m128i a3, __m128i a4)
|
||||
{
|
||||
__m128i val = mc4NextInt(cs, ws, 0x3);
|
||||
__m128i v2 = _mm_set1_epi32(2);
|
||||
__m128i cmp1 = _mm_cmpeq_epi32(val, _mm_set1_epi32(0));
|
||||
@ -313,7 +332,8 @@ static inline __m128i select4Random4(__m128i* cs, int ws, __m128i a1, __m128i a2
|
||||
);
|
||||
}
|
||||
|
||||
static inline __m128i select4ModeOrRandom(__m128i* cs, int ws, __m128i a1, __m128i a2, __m128i a3, __m128i a4) {
|
||||
static inline __m128i select4ModeOrRandom(__m128i* cs, int ws, __m128i a1, __m128i a2, __m128i a3, __m128i a4)
|
||||
{
|
||||
//((a == b)&(c != d) | (a == c)&(b != d) | (a == d)&(b != c))&a | ((b == c)&(a != d) | (b == d)&(a != c))&b | ((c == d)&(a != b))&c
|
||||
__m128i cmp1 = _mm_cmpeq_epi32(a1, a2);
|
||||
__m128i cmp2 = _mm_cmpeq_epi32(a1, a3);
|
||||
@ -350,7 +370,9 @@ static inline __m128i select4ModeOrRandom(__m128i* cs, int ws, __m128i a1, __m12
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static inline int selectRandom2(Layer *l, int a1, int a2)
|
||||
{
|
||||
int i = mcNextInt(l, 2);
|
||||
@ -380,8 +402,13 @@ static inline int selectModeOrRandom(Layer *l, int a1, int a2, int a3, int a4)
|
||||
|
||||
return rndarg;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//==============================================================================
|
||||
// Layers
|
||||
//==============================================================================
|
||||
|
||||
// A null layer does nothing, and can be used to apply a layer to existing data.
|
||||
void mapNull(Layer *l, int * __restrict out, int x, int z, int w, int h);
|
||||
// A skip layer simply calls its first parent without modification.
|
||||
|
Loading…
x
Reference in New Issue
Block a user