Beispiel #1
0
    public override int GetHashCode()
    {
        int rlt = 0;

        foreach (var f in this.GetType().GetFields())
        {
            var val = f.GetValue(this);
            if (val != null)
            {
                if (f.FieldType.ToString() == "UnityEngine.AnimationCurve")
                {
                    AnimationCurve c = (AnimationCurve)val;
                    rlt ^= PerlinCache.getCurveHash(c);
                }
                rlt ^= val.GetHashCode();
            }
        }
        for (int i = 0; i < getInputNum(); i++)
        {
            if (getInputNode(i) != null)
            {
                rlt ^= getInputNode(i).GetHashCode();
            }
        }
        return(rlt);
    }
Beispiel #2
0
    public override float[,] update(int seed, int x, int y, int w, int h, float scaleX = 1.0f, float scaleY = 1.0f)
    {
        generator.Frequency   = 1.0 / size;
        generator.OctaveCount = 1;
        generator.Seed        = seed + localSeed;
        generator.Quality     = LibNoise.Unity.QualityMode.Low;
        //PerlinNoise perlin = new PerlinNoise(generator.Seed);

        string key = PerlinCache.makeKey("perlin", generator.Frequency, generator.Seed, octaveCount, x, y, w, h, scaleX, scaleY, curve);

        float[,] temp = null;
        if (PerlinCache.hasKey(key))
        {
            temp = PerlinCache.getCache(key);
        }
        else
        {
            temp = new float[w, h];
            for (int i = 0; i < w; i++)
            {
                for (int j = 0; j < h; j++)
                {
                    float tempX = x + i;
                    float tempY = y + j;
                    float val   = 0f;
                    float cp    = 0.5f;
                    for (int o = 0; o < octaveCount; o++)
                    {
                        float signal = (float)generator.GetValue(tempX * scaleX, tempY * scaleY, 0);
                        //float signal = (float)perlin.Noise(tempX * scaleX * generator.Frequency, tempY * scaleY * generator.Frequency, 0);
                        //float signal = 0.2f;
                        val   += (curve.Evaluate(signal * 0.4f + 0.5f) - 0.5f) * 2f * cp;
                        tempX *= 1.83456789f;
                        tempY *= 1.83456789f;
                        cp    *= 0.5f;
                    }
                    temp[i, j] = (val * 0.5f + 0.5f);
                }
            }
            PerlinCache.addCache(key, temp);
        }
        float[,] values = new float[w, h];
        for (int i = 0; i < w; i++)
        {
            for (int j = 0; j < h; j++)
            {
                values[i, j] = temp[i, j] * scale + bias;
            }
        }
        return(values);
    }
    //[HarmonyPrefix]
    public static bool Prefix(Segment s, PerlinCache cache)
    {
        long realCubeX = s.baseX;
        long realCubeZ = s.baseZ;

        long offsetX = realCubeX - WorldScript.mDefaultOffset;
        long offsetZ = realCubeZ - WorldScript.mDefaultOffset;

        if (Math.Abs(offsetX) < 17 && Math.Abs(offsetZ) < 17)
        {
            return(true);
        }
        return(false);
    }
    public static void Suffix(Segment s, PerlinCache cache, ushort[,]  ___SurfaceValCache)
    {
        for (int x = 0; x < WorldHelper.SegmentX + TerrainGenerator.doublePerlinBorder; x++)
        {
            for (int z = 0; z < WorldHelper.SegmentZ + TerrainGenerator.doublePerlinBorder; z++)
            {
                for (int y = 0; y < WorldHelper.SegmentY + TerrainGenerator.doublePerlinBorder; y++)
                {
                    long realCubeX = s.baseX + x - PerlinCache.STANDARD_PERLIN_BORDER;
                    long realCubeZ = s.baseZ + z - PerlinCache.STANDARD_PERLIN_BORDER;

                    long offsetX = realCubeX - WorldScript.mDefaultOffset;
                    long offsetZ = realCubeZ - WorldScript.mDefaultOffset;

                    // Pythag
                    float offsetSquared = Mathf.Pow(offsetX, 2) + Mathf.Pow(offsetZ, 2);

                    if (offsetSquared > 100)
                    {
                        cache.maCubes[x, y, z]      = eCubeTypes.Air;
                        cache.maCubeValues[x, y, z] = 0;
                    }
                    else
                    {
                        // Top layer is organic detritus with several meters of rock
                        if (y == WorldHelper.SegmentY + 1)
                        {
                            cache.maCubes[x, y, z]      = eCubeTypes.NewSurvivalSurface;
                            cache.maCubeValues[x, y, z] = ___SurfaceValCache[x, z];
                        }
                        else if (y > 8 && y < WorldHelper.SegmentY + 1)
                        {
                            cache.maCubes[x, y, z] = eCubeTypes.RoughHewnRock;
                        }
                        else
                        {
                            cache.maCubes[x, y, z] = eCubeTypes.Air;
                        }
                    }
                }
            }
        }
    }