Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Layer {
- int64 baseSeed; // Generator seed (depends only on hierarchy of generator)
- int64 worldSeed; // based on the seed of the world
- int64 chunkSeed; // randomiser seed
- int scale; // map scale of this layer (map entry = scale x scale blocks)
- void (*getMap)(Layer *uniform l, uniform int out[], uniform int areaX, uniform int areaZ, uniform int areaWidth, uniform int areaHeight);
- Layer *p, *p2;
- };
- static inline void setChunkSeed(Layer *layer, int64 chunkX, int64 chunkZ)
- {
- layer->chunkSeed = layer->worldSeed;
- layer->chunkSeed *= layer->chunkSeed * 6364136223846793005L + 1442695040888963407L;
- layer->chunkSeed += chunkX;
- layer->chunkSeed *= layer->chunkSeed * 6364136223846793005L + 1442695040888963407L;
- layer->chunkSeed += chunkZ;
- layer->chunkSeed *= layer->chunkSeed * 6364136223846793005L + 1442695040888963407L;
- layer->chunkSeed += chunkX;
- layer->chunkSeed *= layer->chunkSeed * 6364136223846793005L + 1442695040888963407L;
- layer->chunkSeed += chunkZ;
- }
- static inline int mcNextInt(Layer *layer, int mod)
- {
- int ret = (int)((layer->chunkSeed >> 24) & (int64)mod);
- if (ret < 0)
- {
- ret += mod;
- }
- layer->chunkSeed *= layer->chunkSeed * 6364136223846793005L + 1442695040888963407L;
- layer->chunkSeed += layer->worldSeed;
- return ret;
- }
- static inline int selectRandom2(Layer *l, int a1, int a2)
- {
- int i = mcNextInt(l, 0x1);
- return i == 0 ? a1 : a2;
- }
- static inline int selectRandom4(Layer *l, int a1, int a2, int a3, int a4)
- {
- int i = mcNextInt(l, 0x3);
- return i == 0 ? a1 : i == 1 ? a2 : i == 2 ? a3 : a4;
- }
- static inline int selectModeOrRandom(Layer *l, int a1, int a2, int a3, int a4)
- {
- int rndarg = selectRandom4(l, a1, a2, a3, a4);
- if(a2 == a3 && a3 == a4) return a2;
- if(a1 == a2 && a1 == a3) return a1;
- if(a1 == a2 && a1 == a4) return a1;
- if(a1 == a3 && a1 == a4) return a1;
- if(a1 == a2 && a3 != a4) return a1;
- if(a1 == a3 && a2 != a4) return a1;
- if(a1 == a4 && a2 != a3) return a1;
- if(a2 == a3 && a1 != a4) return a2;
- if(a2 == a4 && a1 != a3) return a2;
- if(a3 == a4 && a1 != a2) return a3;
- return rndarg;
- }
- extern "C" void mapIsland(Layer *uniform l, uniform int out[], uniform int areaX, uniform int areaZ, uniform int areaWidth, uniform int areaHeight);
- export void mapZoom(Layer *uniform l, uniform int out[], uniform int areaX, uniform int areaZ, uniform int areaWidth, uniform int areaHeight) {
- uniform int pX = areaX >> 1;
- uniform int pZ = areaZ >> 1;
- uniform int pWidth = (areaWidth >> 1) + 2;
- uniform int pHeight = (areaHeight >> 1) + 2;
- uniform int z;
- Layer* pre = l->p;
- pre->getMap(l->p, out, pX, pZ, pWidth, pHeight);
- int (*selectRand)(Layer *l, int a1, int a2, int a3, int a4) = ((void*)pre->getMap == (void*)mapIsland) ? selectRandom4 : selectModeOrRandom;
- uniform int newWidth = (pWidth-1) << 1;
- uniform int newHeight = (pHeight-1) << 1;
- int idx, a, b, a1, b1;
- uniform int *buf = new int[(newWidth+1)*(newHeight+1)*sizeof(int)];
- for(z = 0; z < pHeight - 1; z++)
- {
- idx = (z << 1) * newWidth;
- a = out[(z+0)*pWidth];
- b = out[(z+1)*pWidth];
- foreach (x = 0 ... pWidth-1)
- {
- setChunkSeed(l, (int64)((x + pX) << 1), (int64)((z + pZ) << 1));
- a1 = out[x+1 + (z+0)*pWidth];
- b1 = out[x+1 + (z+1)*pWidth];
- buf[idx] = a;
- buf[idx + newWidth] = selectRandom2(l, a, b);
- idx++;
- buf[idx] = selectRandom2(l, a, a1);
- buf[idx + newWidth] = selectRand(l, a, a1, b, b1);
- idx++;
- a = a1;
- b = b1;
- }
- }
- for(z = 0; z < areaHeight; z++)
- {
- memcpy(&out[z*areaWidth], &buf[(z + (areaZ & 1))*newWidth + (areaX & 1)], areaWidth*sizeof(int));
- }
- delete[] buf;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement