Esempio n. 1
0
 public bool SetResolveMode(bool resolveByFFT, int resolution)
 {
     if (this.ResolveByFFT != resolveByFFT || (this.ResolveByFFT && this._ResolutionFFT != resolution))
     {
         if (resolveByFFT)
         {
             lock (this)
             {
                 bool flag = this.WindWaves.LoopDuration != 0f;
                 int  num  = (!flag) ? 4 : ((int)(this.WindWaves.LoopDuration * 5f + 0.6f));
                 this._ResolutionFFT = resolution;
                 this._MipIndexFFT   = WaterWavesSpectrumDataBase.GetMipIndex(resolution);
                 int num2 = resolution * resolution;
                 this.DirectionalSpectrum = new Vector2[num2];
                 this.Displacements       = new Vector2[num][];
                 this.ForceAndHeight      = new Vector4[num][];
                 this.ResultsTiming       = new float[num];
                 this.SetDirty();
                 this._CachedTime = float.NegativeInfinity;
                 for (int i = 0; i < num; i++)
                 {
                     this.Displacements[i]  = new Vector2[num2];
                     this.ForceAndHeight[i] = new Vector4[num2];
                 }
                 if (!this.ResolveByFFT)
                 {
                     WaterAsynchronousTasks.Instance.AddFFTComputations(this);
                     this.ResolveByFFT = true;
                 }
             }
         }
         else
         {
             WaterAsynchronousTasks.Instance.RemoveFFTComputations(this);
             this.ResolveByFFT = false;
         }
         return(true);
     }
     return(false);
 }
        private void AnalyzeSpectrum()
        {
            int finalResolution    = this._WindWaves.FinalResolution;
            int num                = finalResolution >> 1;
            int num2               = Mathf.RoundToInt(Mathf.Log((float)(finalResolution >> 1), 2f)) - 4;
            Heap <WaterWave> heap  = new Heap <WaterWave>();
            Heap <WaterWave> heap2 = new Heap <WaterWave>();

            this._StdDev = 0f;
            for (byte b = 0; b < 4; b += 1)
            {
                Vector3[] array   = this.SpectrumValues[(int)b];
                float[]   array2  = this._StandardDeviationData[(int)b] = new float[num2 + 1];
                float     num3    = 6.28318548f / this._TileSize;
                float     offsetX = this._TileSize + 0.5f / (float)finalResolution * this._TileSize;
                float     offsetZ = -this._TileSize + 0.5f / (float)finalResolution * this._TileSize;
                for (int i = 0; i < finalResolution; i++)
                {
                    float  num4 = num3 * (float)(i - num);
                    ushort num5 = (ushort)((i + num) % finalResolution);
                    ushort num6 = (ushort)((int)num5 * finalResolution);
                    for (int j = 0; j < finalResolution; j++)
                    {
                        float   num7   = num3 * (float)(j - num);
                        ushort  num8   = (ushort)((j + num) % finalResolution);
                        Vector3 vector = array[(int)(num6 + num8)];
                        float   num9   = vector.x * vector.x + vector.y * vector.y;
                        float   num10  = Mathf.Sqrt(num9);
                        float   num11  = Mathf.Sqrt(num4 * num4 + num7 * num7);
                        float   w      = Mathf.Sqrt(this._Gravity * num11);
                        if (num10 >= 0.0025f)
                        {
                            heap2.Insert(new WaterWave(b, offsetX, offsetZ, num5, num8, num4, num7, num11, w, num10));
                            if (heap2.Count > 100)
                            {
                                heap2.ExtractMax();
                            }
                        }
                        if (num10 > 0.025f)
                        {
                            heap.Insert(new WaterWave(b, offsetX, offsetZ, num5, num8, num4, num7, num11, w, num10));
                            if (heap.Count > 200)
                            {
                                heap.ExtractMax();
                            }
                        }
                        int mipIndex = WaterWavesSpectrumDataBase.GetMipIndex(Mathf.Max(Mathf.Min((int)num5, finalResolution - (int)num5 - 1), Mathf.Min((int)num8, finalResolution - (int)num8 - 1)));
                        array2[mipIndex] += num9;
                    }
                }
                for (int k = 0; k < array2.Length; k++)
                {
                    array2[k]     = Mathf.Sqrt(2f * array2[k]);
                    this._StdDev += array2[k];
                }
            }
            this.CpuWaves = heap2.ToArray <WaterWave>();
            WaterWavesSpectrumDataBase.SortCpuWaves(this.CpuWaves, false);
            this.ShorelineCandidates = heap.ToArray <WaterWave>();
            Array.Sort <WaterWave>(this.ShorelineCandidates);
        }