public Texture2D GetTexture()
        {
            int         xSize      = 16;
            int         zSize      = 16;
            int         chunkWidth = picWidth / 16;
            int         chunkDepth = picHeight / 16;
            Texture2D   tex        = new Texture2D(chunkWidth * xSize, chunkDepth * zSize);
            ArraysCache cache      = ArraysCacheManager.GetCache();

            for (int x = 0; x < chunkWidth; x++)
            {
                for (int z = 0; z < chunkDepth; z++)
                {
                    int[] result = mainLayer.getInts(cache, x * xSize, z * zSize, xSize, zSize);
                    cache.release();
                    for (int i = 0; i < result.Length; i++)
                    {
                        int   tempX = i % xSize;
                        int   tempZ = i / xSize;
                        Color c;
                        int   biomeId = ((result[i] & BiomeBits));

                        BiomeConfig biomeConfig = WorldConfig.Instance.GetBiomeConfigById(biomeId);
                        c = biomeConfig.color;
                        tex.SetPixel(x * xSize + tempX, z * zSize + tempZ, c);
                    }
                }
            }
            tex.Apply();
            return(tex);
        }
 public static void ReleaseCache(ArraysCache cache)
 {
     lock (ARRAYS_CACHES)
     {
         cache.release();
     }
 }
示例#3
0
        public override int[] getInts(ArraysCache cache, int x, int z, int xSize, int zSize)
        {
            int[] childInts = this.child.getInts(cache, x, z, xSize, zSize);
            int[] thisInts  = cache.getArray(xSize * zSize);

            for (int zi = 0; zi < zSize; zi++)
            {
                for (int xi = 0; xi < xSize; xi++)
                {
                    initChunkSeed(zi + z, xi + x);                               // reversed
                    int currentPiece = childInts[(xi + zi * xSize)];
//					if (nextInt(2) == 0)
//						currentPiece |= RiverBitOne;
//					else
//						currentPiece |= RiverBitTwo;
                    if (nextInt(2) == 0)
                    {
                        currentPiece |= RiverBits;
                    }

                    thisInts[(xi + zi * xSize)] = currentPiece;
                }
            }
            return(thisInts);
        }
示例#4
0
        public override int[] getInts(ArraysCache cache, int x, int z, int xSize, int zSize)
        {
            int[] childInts = this.child.getInts(cache, x, z, xSize, zSize);
            int[] thisInts  = cache.getArray(xSize * zSize);

            for (int zi = 0; zi < zSize; zi++)
            {
                for (int xi = 0; xi < xSize; xi++)
                {
                    initChunkSeed(x + xi, z + zi);
                    int currentPiece = childInts[(xi + zi * xSize)];

                    if ((currentPiece & LandBit) != 0 && (currentPiece & BiomeBits) == 0)
                    {
                        if (nextInt(2) == 0)
                        {
                            thisInts[(xi + zi * xSize)] = (currentPiece | 1);
                        }
                        else
                        {
                            thisInts[(xi + zi * xSize)] = (currentPiece | 2);
                        }
                    }
                    else
                    {
                        thisInts[(xi + zi * xSize)] = currentPiece;
                    }
                }
            }
            return(thisInts);
        }
示例#5
0
        public override int[] getInts(ArraysCache arraysCache, int x, int z, int x_size, int z_size)
        {
            int[] childInts = this.child.getInts(arraysCache, x, z, x_size, z_size);
            int[] thisInts  = arraysCache.getArray(x_size * z_size);

            for (int i = 0; i < z_size; i++)
            {
                for (int j = 0; j < x_size; j++)
                {
                    initGroupSeed(j + x, i + z);
                    int currentPiece = childInts[(j + i * x_size)];

                    if ((currentPiece & LandBit) != 0 && (currentPiece & BiomeGroupBits) == 0)
                    {
                        Dictionary <int, BiomeGroupConfig> possibleGroups = WorldConfig.Instance.GetBiomeGroupRarityMap(depth);
                        int newGroupRarity = nextGroupInt(WorldConfig.Instance.GetMaxRarity());
                        foreach (var item in possibleGroups)
                        {
                            if (newGroupRarity < item.Key)
                            {
                                if (item.Value != null)
                                {
                                    currentPiece |= (item.Value.groupId << BiomeGroupShift);
                                }
                                break;
                            }
                        }
                    }
                    thisInts[(j + i * x_size)] = currentPiece;
                }
            }

            return(thisInts);
        }
 private static ArraysCache[] InitCache()
 {
     ArraysCache[] temp = new ArraysCache[4];
     for (int i = 0; i < temp.Length; i++)
     {
         temp[i] = new ArraysCache();
     }
     return(temp);
 }
示例#7
0
 public override int[] getInts(ArraysCache cache, int x, int z, int xSize, int zSize)
 {
     int[] thisInts = cache.getArray(xSize * zSize);
     for (int i = 0; i < thisInts.Length; i++)
     {
         thisInts[i] = 0;
     }
     return(thisInts);
 }
示例#8
0
        public override int[] getInts(ArraysCache cache, int x, int z, int xSize, int zSize)
        {
            int x0     = x - 1;
            int z0     = z - 1;
            int xSize0 = xSize + 2;
            int zSize0 = zSize + 2;

            int[] childInts = this.child.getInts(cache, x0, z0, xSize0, zSize0);
            int[] thisInts  = cache.getArray(xSize * zSize);

            for (int zi = 0; zi < zSize; ++zi)
            {
                for (int xi = 0; xi < xSize; ++xi)
                {
                    int northCheck  = childInts[xi + 1 + (zi + 0) * xSize0];
                    int southCheck  = childInts[xi + 1 + (zi + 2) * xSize0];
                    int eastCheck   = childInts[xi + 2 + (zi + 1) * xSize0];
                    int westCheck   = childInts[xi + 0 + (zi + 1) * xSize0];
                    int centerCheck = childInts[xi + 1 + (zi + 1) * xSize0];

                    if (westCheck == eastCheck && northCheck == southCheck)
                    {
                        this.initChunkSeed((long)(xi + x), (long)(zi + z));

                        if (this.nextInt(2) == 0)
                        {
                            centerCheck = westCheck;
                        }
                        else
                        {
                            centerCheck = northCheck;
                        }
                    }
                    else
                    {
                        if (westCheck == eastCheck)
                        {
                            centerCheck = westCheck;
                        }

                        if (northCheck == southCheck)
                        {
                            centerCheck = northCheck;
                        }
                    }

                    thisInts[xi + zi * xSize] = centerCheck;
                }
            }

            return(thisInts);
        }
示例#9
0
        public override int[] getInts(ArraysCache cache, int x, int z, int xSize, int zSize)
        {
            int x0     = x - 1;
            int z0     = z - 1;
            int xSize0 = xSize + 2;
            int zSize0 = zSize + 2;

            int[] childInts = this.child.getInts(cache, x0, z0, xSize0, zSize0);
            int[] thisInts  = cache.getArray(xSize * zSize);

            for (int zi = 0; zi < zSize; zi++)
            {
                for (int xi = 0; xi < xSize; xi++)
                {
                    initChunkSeed(xi + x, zi + z);
                    int selection = childInts[(xi + 1 + (zi + 1) * xSize0)];

                    bool spawn = false;
                    if (inOcean)
                    {
                        int nwCheck = childInts[(xi + 0 + (zi) * xSize0)] & LandBit;
                        int neCheck = childInts[(xi + 2 + (zi) * xSize0)] & LandBit;
                        int swCheck = childInts[(xi + 0 + (zi + 2) * xSize0)] & LandBit;
                        int seCheck = childInts[(xi + 2 + (zi + 2) * xSize0)] & LandBit;


                        if (((selection & LandBit) == 0) && (nwCheck == 0) && (neCheck == 0) && (swCheck == 0) && (seCheck == 0) && nextInt(100) < chance)
                        {
                            selection = (selection & IceBit) | (selection & RiverBits) | LandBit | biomeConfig.biomeId | IslandBit;
                            spawn     = true;
                        }
                    }
                    if (!spawn)
                    {
                        int nwCheck = childInts[(xi + 0 + (zi) * xSize0)] & BiomeBits;
                        int neCheck = childInts[(xi + 2 + (zi) * xSize0)] & BiomeBits;
                        int swCheck = childInts[(xi + 0 + (zi + 2) * xSize0)] & BiomeBits;
                        int seCheck = childInts[(xi + 2 + (zi + 2) * xSize0)] & BiomeBits;

                        if (biomeIsles[(selection & BiomeBits)] && biomeIsles[nwCheck] && biomeIsles[neCheck] && biomeIsles[swCheck] && biomeIsles[seCheck] && nextInt(100) < chance)
                        {
                            selection = (selection & LandBit) | (selection & IceBit) | (selection & RiverBits) | biomeConfig.biomeId | IslandBit;
                        }
                    }
                    thisInts[(xi + zi * xSize)] = selection;
                }
            }
            return(thisInts);
        }
示例#10
0
        public override int[] getInts(ArraysCache cache, int x, int z, int xSize, int zSize)
        {
            int[] childInts = this.child.getInts(cache, x, z, xSize, zSize);
            int[] thisInts  = cache.getArray(xSize * zSize);

            for (int zi = 0; zi < zSize; zi++)
            {
                for (int xi = 0; xi < xSize; xi++)
                {
                    initChunkSeed(z + zi, x + xi);                          // reversed
                    thisInts[(xi + zi * xSize)] = (nextInt(rarity) == 0 ? (childInts[(xi + zi * xSize)] | IceBit) : childInts[(xi + zi * xSize)]);
                }
            }
            return(thisInts);
        }
示例#11
0
        public override int[] getInts(ArraysCache cache, int x, int z, int xSize, int zSize)
        {
            int x0     = x - 1;
            int z0     = z - 1;
            int xSize0 = xSize + 2;
            int zSize0 = zSize + 2;

            int[] childInts = this.child.getInts(cache, x0, z0, xSize0, zSize0);
            int[] thisInts  = cache.getArray(xSize * zSize);

            for (int zi = 0; zi < zSize; zi++)
            {
                for (int xi = 0; xi < xSize; xi++)
                {
                    int nwCheck     = childInts[(xi + 0 + (zi) * xSize0)] & LandBit;
                    int neCheck     = childInts[(xi + 2 + (zi) * xSize0)] & LandBit;
                    int swCheck     = childInts[(xi + 0 + (zi + 2) * xSize0)] & LandBit;
                    int seCheck     = childInts[(xi + 2 + (zi + 2) * xSize0)] & LandBit;
                    int centerCheck = childInts[(xi + 1 + (zi + 1) * xSize0)] & LandBit;
                    initChunkSeed(xi + x, zi + z);
                    initGroupSeed(xi + x, zi + z);
                    thisInts[(xi + zi * xSize)] = childInts[(xi + 1 + (zi + 1) * xSize0)] | LandBit;

                    //如果当前不是陆地而周围有陆地,那么有1/3几率将当前变为陆地
                    if ((centerCheck == 0) && ((nwCheck != 0) || (neCheck != 0) || (swCheck != 0) || (seCheck != 0)))
                    {
                        if (nextInt(3) != 0)
                        {
                            thisInts[(xi + zi * xSize)] ^= LandBit;
                        }
                        //如果当前是陆地,而周围有水,那么有4/5概率将当前陆地变为水
                    }
                    else if ((centerCheck > 0) && ((nwCheck == 0) || (neCheck == 0) || (swCheck == 0) || (seCheck == 0)))
                    {
                        if (nextInt(5) == 0)
                        {
                            thisInts[(xi + zi * xSize)] ^= LandBit;
                        }
                        //否则,什么都不做
                    }
                    else if (centerCheck == 0)
                    {
                        thisInts[(xi + zi * xSize)] ^= LandBit;
                    }
                }
            }
            return(thisInts);
        }
示例#12
0
        public override int[] getInts(ArraysCache cache, int x, int z, int xSize, int zSize)
        {
            int x0     = x >> 1;
            int z0     = z >> 1;
            int xSize0 = (xSize >> 1) + 3;
            int zSize0 = (zSize >> 1) + 3;

            int[] childInts = this.child.getInts(cache, x0, z0, xSize0, zSize0);
            int[] thisInts  = cache.getArray(xSize0 * 2 * (zSize0 * 2));

            int n = xSize0 << 1;

            for (int zi = 0; zi < zSize0 - 1; zi++)
            {
                int i2 = zi << 1;
                int i3 = i2 * n;
                int i4 = childInts[((zi) * xSize0)];
                int i5 = childInts[((zi + 1) * xSize0)];
                for (int xi = 0; xi < xSize0 - 1; xi++)
                {
                    initChunkSeed((long)(xi + x0 << 1), (long)(zi + z0 << 1));
                    int northCheck  = childInts[(xi + 1 + (zi) * xSize0)];
                    int centerCheck = childInts[(xi + 1 + (zi + 1) * xSize0)];

                    thisInts[i3]         = i4;
                    thisInts[(i3++ + n)] = RndParam(i4, i5);
                    thisInts[i3]         = RndParam(i4, northCheck);
                    thisInts[(i3++ + n)] = getRandomOf4(i4, northCheck, i5, centerCheck);

                    i4 = northCheck;
                    i5 = centerCheck;
                }
            }
            int[] ret = cache.getArray(xSize * zSize);
            for (int i2 = 0; i2 < zSize; i2++)
            {
                Array.Copy(thisInts, (i2 + (z & 0x1)) * (xSize0 << 1) + (x & 0x1), ret, i2 * xSize, xSize);
            }
            return(ret);
        }
示例#13
0
        public override int[] getInts(ArraysCache cache, int x, int z, int xSize, int zSize)
        {
            int x0     = x - 1;
            int z0     = z - 1;
            int xSize0 = xSize + 2;
            int zSize0 = zSize + 2;

            int[] childInts = this.child.getInts(cache, x0, z0, xSize0, zSize0);
            int[] thisInts  = cache.getArray(xSize * zSize);

            for (int zi = 0; zi < zSize; zi++)
            {
                for (int xi = 0; xi < xSize; xi++)
                {
                    int northCheck  = childInts[(xi + 1 + (zi) * xSize0)] & RiverBits;
                    int southCheck  = childInts[(xi + 1 + (zi + 2) * xSize0)] & RiverBits;
                    int eastCheck   = childInts[(xi + 2 + (zi + 1) * xSize0)] & RiverBits;
                    int westCheck   = childInts[(xi + 0 + (zi + 1) * xSize0)] & RiverBits;
                    int centerCheck = childInts[(xi + 1 + (zi + 1) * xSize0)] & RiverBits;

                    int currentPiece = childInts[(xi + 1 + (zi + 1) * xSize0)];
                    if ((centerCheck == 0) || (westCheck == 0) || (eastCheck == 0) || (northCheck == 0) || (southCheck == 0))
                    {
                        currentPiece |= RiverBits;
                    }
                    else if ((centerCheck != westCheck) || (centerCheck != northCheck) || (centerCheck != eastCheck) || (centerCheck != southCheck))
                    {
                        currentPiece ^= RiverBits;
                    }
                    else
                    {
                        currentPiece |= RiverBits;
                        currentPiece ^= RiverBits;
                    }
                    thisInts[(xi + zi * xSize)] = currentPiece;
                }
            }

            return(thisInts);
        }
        public int[] GetBiomes(int[] biomeArray, int x, int z, int x_size, int z_size)
        {
            if ((biomeArray == null) || biomeArray.Length < x_size * z_size)
            {
                biomeArray = new int[x_size * z_size];
            }

            ArraysCache cache = ArraysCacheManager.GetCache();

            int[] result = this._biomeLayer.getInts(cache, x, z, x_size, z_size);
            ArraysCacheManager.ReleaseCache(cache);

            Array.Copy(result, 0, biomeArray, 0, x_size * z_size);

//			for (int i = 0; i < result.Length; i++) {
//				int tempX = i % x_size;
//				int tempZ = i / x_size;
//
//				biomeArray[tempX,tempZ] = result[i];
//			}
            return(biomeArray);
        }
示例#15
0
        public override int[] getInts(ArraysCache cache, int x, int z, int xSize, int zSize)
        {
            int[] childInts = this.child.getInts(cache, x, z, xSize, zSize);
            int[] thisInts  = cache.getArray(xSize * zSize);

            for (int zi = 0; zi < zSize; zi++)
            {
                for (int xi = 0; xi < xSize; xi++)
                {
                    initChunkSeed(x + xi, z + zi);
                    if (nextInt(100) < rarity)
                    {
                        thisInts[(xi + zi * xSize)] = childInts[(xi + zi * xSize)] | LandBit;
                    }
                    else
                    {
                        thisInts[(xi + zi * xSize)] = childInts[(xi + zi * xSize)];
                    }
                }
            }
            return(thisInts);
        }
示例#16
0
        public override int[] getInts(ArraysCache cache, int x, int z, int xSize, int zSize)
        {
            int[] childInts = this.child.getInts(cache, x, z, xSize, zSize);
            int[] thisInts  = cache.getArray(xSize * zSize);

            int currentPiece;
            int cachedId;

            for (int zi = 0; zi < zSize; zi++)
            {
                for (int xi = 0; xi < xSize; xi++)
                {
                    currentPiece = childInts[(xi + zi * xSize)];

                    if ((currentPiece & LandBit) != 0)
                    {
                        cachedId = currentPiece & BiomeBits;
                    }
                    else
                    {
                        cachedId = DefaultBiome.Ocean.id;
                    }
                    currentPiece = cachedId;

//					if(riverBiomes[cachedId] != -1 && (currentPiece & RiverBits) != 0)
//					{
//						currentPiece = riverBiomes[cachedId];
//					}
//					else
//					{
//						currentPiece = cachedId;
//					}

                    thisInts[(xi + zi * xSize)] = currentPiece;
                }
            }
            return(thisInts);
        }
示例#17
0
        public override int[] getInts(ArraysCache cache, int x, int z, int xSize, int zSize)
        {
            int[] childInts = this.child.getInts(cache, x - 1, z - 1, xSize + 2, zSize + 2);
            int[] thisInts  = cache.getArray(xSize * zSize);

            for (int zi = 0; zi < zSize; zi++)
            {
                for (int xi = 0; xi < xSize; xi++)
                {
                    initChunkSeed(xi + x, zi + z);
                    int selection = childInts[(xi + 1 + (zi + 1) * (xSize + 2))];

                    int biomeId = GetBiomeFromLayer(selection);

                    if (bordersFrom[biomeId] != null)
                    {
                        int northCheck = GetBiomeFromLayer(childInts[(xi + 1 + (zi) * (xSize + 2))]);
                        int southCheck = GetBiomeFromLayer(childInts[(xi + 1 + (zi + 2) * (xSize + 2))]);
                        int eastCheck  = GetBiomeFromLayer(childInts[(xi + 2 + (zi + 1) * (xSize + 2))]);
                        int westCheck  = GetBiomeFromLayer(childInts[(xi + (zi + 1) * (xSize + 2))]);

                        bool[] biomeFrom = bordersFrom[biomeId];
                        if (biomeFrom[northCheck] && biomeFrom[eastCheck] && biomeFrom[westCheck] && biomeFrom[southCheck])
                        {
                            if ((northCheck != biomeId) || (eastCheck != biomeId) || (westCheck != biomeId) || (southCheck != biomeId))
                            {
                                selection = (selection & (IslandBit | RiverBits | IceBit)) | LandBit | bordersTo[biomeId];
                            }
                        }
                    }

                    thisInts[(xi + zi * xSize)] = selection;
                }
            }

            return(thisInts);
        }
示例#18
0
        public override int[] getInts(ArraysCache cache, int x, int z, int xSize, int zSize)
        {
            int[] childInts = this.child.getInts(cache, x, z, xSize, zSize);
            int[] thisInts  = cache.getArray(xSize * zSize);

            for (int i = 0; i < zSize; i++)
            {
                for (int j = 0; j < xSize; j++)
                {
                    initChunkSeed(j + x, i + z);
                    int currentPiece = childInts[(j + i * xSize)];

                    if ((currentPiece & BiomeGroupBits) != 0 && (currentPiece & BiomeBits) == 0)                        // has biomegroup bits but not biome bits
                    {
                        BiomeGroupConfig biomeGroupConfig            = WorldConfig.Instance.GetBiomeGroupConfigById((currentPiece & BiomeGroupBits) >> BiomeGroupShift);
                        Dictionary <int, BiomeConfig> possibleBiomes = biomeGroupConfig.GetBiomeRarityMap(depth);
                        if (possibleBiomes.Count > 0)
                        {
                            int newBiomeRarity = nextInt(biomeGroupConfig.getMaxRarity());
                            foreach (var item in possibleBiomes)
                            {
                                if (newBiomeRarity < item.Key)
                                {
                                    if (item.Value != null)
                                    {
                                        currentPiece |= item.Value.biomeId;
                                    }
                                    break;
                                }
                            }
                        }
                    }
                    thisInts[(j + i * xSize)] = currentPiece;
                }
            }
            return(thisInts);
        }
示例#19
0
        public override int[] getInts(ArraysCache cache, int x, int z, int xSize, int zSize)
        {
            x -= 2;
            z -= 2;
            int i  = 2;
            int j  = 1 << i;
            int k  = x >> i;
            int m  = z >> i;
            int n  = (xSize >> i) + 3;
            int i1 = (zSize >> i) + 3;

            int[] childInts = this.child.getInts(cache, k, m, n, i1);

            int i2 = n << i;
            int i3 = i1 << i;

            int[] thisInts = cache.getArray(i2 * i3);
            for (int i4 = 0; i4 < i1 - 1; i4++)
            {
                int i5 = childInts[((i4) * n)];
                int i6 = childInts[((i4 + 1) * n)];
                for (int i7 = 0; i7 < n - 1; i7++)
                {
                    double d1 = j * 0.9D;
                    initChunkSeed(i7 + k << i, i4 + m << i);
                    double d2 = (nextInt(1024) / 1024.0D - 0.5D) * d1;
                    double d3 = (nextInt(1024) / 1024.0D - 0.5D) * d1;
                    initChunkSeed(i7 + k + 1 << i, i4 + m << i);
                    double d4 = (nextInt(1024) / 1024.0D - 0.5D) * d1 + j;
                    double d5 = (nextInt(1024) / 1024.0D - 0.5D) * d1;
                    initChunkSeed(i7 + k << i, i4 + m + 1 << i);
                    double d6 = (nextInt(1024) / 1024.0D - 0.5D) * d1;
                    double d7 = (nextInt(1024) / 1024.0D - 0.5D) * d1 + j;
                    initChunkSeed(i7 + k + 1 << i, i4 + m + 1 << i);
                    double d8 = (nextInt(1024) / 1024.0D - 0.5D) * d1 + j;
                    double d9 = (nextInt(1024) / 1024.0D - 0.5D) * d1 + j;

                    int i8 = childInts[(i7 + 1 + (i4) * n)];
                    int i9 = childInts[(i7 + 1 + (i4 + 1) * n)];

                    for (int i10 = 0; i10 < j; i10++)
                    {
                        int i11 = ((i4 << i) + i10) * i2 + (i7 << i);
                        for (int i12 = 0; i12 < j; i12++)
                        {
                            double d10 = (i10 - d3) * (i10 - d3) + (i12 - d2) * (i12 - d2);
                            double d11 = (i10 - d5) * (i10 - d5) + (i12 - d4) * (i12 - d4);
                            double d12 = (i10 - d7) * (i10 - d7) + (i12 - d6) * (i12 - d6);
                            double d13 = (i10 - d9) * (i10 - d9) + (i12 - d8) * (i12 - d8);

                            if ((d10 < d11) && (d10 < d12) && (d10 < d13))
                            {
                                thisInts[(i11++)] = i5;
                            }
                            else if ((d11 < d10) && (d11 < d12) && (d11 < d13))
                            {
                                thisInts[(i11++)] = i8;
                            }
                            else if ((d12 < d10) && (d12 < d11) && (d12 < d13))
                            {
                                thisInts[(i11++)] = i6;
                            }
                            else
                            {
                                thisInts[(i11++)] = i9;
                            }
                        }
                    }

                    i5 = i8;
                    i6 = i9;
                }
            }
            int[] outputInts = cache.getArray(xSize * zSize);
            for (int i5 = 0; i5 < zSize; i5++)
            {
                Array.Copy(thisInts, (i5 + (z & j - 1)) * (n << i) + (x & j - 1), outputInts, i5 * xSize, xSize);
            }
            return(outputInts);
        }
示例#20
0
 public abstract int[] getInts(ArraysCache cache, int x, int z, int xSize, int zSize);