public void Compute(WaterTileSpectrum targetSpectrum, float time, int outputBufferIndex) { this._TargetSpectrum = targetSpectrum; this._Time = time; Vector2[] directionalSpectrum; Vector2[] displacements; Vector4[] forceAndHeight; lock (targetSpectrum) { this._Resolution = targetSpectrum.ResolutionFFT; directionalSpectrum = targetSpectrum.DirectionalSpectrum; displacements = targetSpectrum.Displacements[outputBufferIndex]; forceAndHeight = targetSpectrum.ForceAndHeight[outputBufferIndex]; } CpuFFT.FFTBuffers fftbuffers; if (!CpuFFT._BuffersCache.TryGetValue(this._Resolution, out fftbuffers)) { fftbuffers = (CpuFFT._BuffersCache[this._Resolution] = new CpuFFT.FFTBuffers(this._Resolution)); } float tileSize = targetSpectrum.WindWaves.UnscaledTileSizes[targetSpectrum.TileIndex]; Vector3[] precomputedK = fftbuffers.GetPrecomputedK(tileSize); if (targetSpectrum.DirectionalSpectrumDirty > 0) { this.ComputeDirectionalSpectra(targetSpectrum.TileIndex, directionalSpectrum, precomputedK); targetSpectrum.DirectionalSpectrumDirty--; } this.ComputeTimedSpectra(directionalSpectrum, fftbuffers.Timed, precomputedK); this.ComputeFFT(fftbuffers.Timed, displacements, forceAndHeight, fftbuffers.Indices, fftbuffers.Weights, fftbuffers.PingPongA, fftbuffers.PingPongB); }
public void AddFFTComputations(WaterTileSpectrum scale) { object fftspectra = this._FFTSpectra; lock (fftspectra) { this._FFTSpectra.Add(scale); } }
public void RemoveFFTComputations(WaterTileSpectrum scale) { object fftspectra = this._FFTSpectra; lock (fftspectra) { int num = this._FFTSpectra.IndexOf(scale); if (num != -1) { if (num < this._FFTSpectrumIndex) { this._FFTSpectrumIndex--; } this._FFTSpectra.RemoveAt(num); } } }
private void RunFFTTask() { try { CpuFFT cpuFFT = new CpuFFT(); Stopwatch stopwatch = new Stopwatch(); bool flag = false; while (this._Run) { WaterTileSpectrum waterTileSpectrum = null; object fftspectra = this._FFTSpectra; lock (fftspectra) { if (this._FFTSpectra.Count != 0) { if (this._FFTSpectrumIndex >= this._FFTSpectra.Count) { this._FFTSpectrumIndex = 0; } if (this._FFTSpectrumIndex == 0) { if ((float)stopwatch.ElapsedMilliseconds > this._FFTTimeStep * 900f) { if (flag) { this._FFTTimeStep += 0.05f; } else { flag = true; } } else { flag = false; if (this._FFTTimeStep > 0.2f) { this._FFTTimeStep -= 0.001f; } } stopwatch.Reset(); stopwatch.Start(); } waterTileSpectrum = this._FFTSpectra[this._FFTSpectrumIndex++]; } } if (waterTileSpectrum == null) { stopwatch.Reset(); Thread.Sleep(6); } else { bool flag2 = false; SpectrumResolver spectrumResolver = waterTileSpectrum.WindWaves.SpectrumResolver; if (spectrumResolver != null) { int recentResultIndex = waterTileSpectrum.RecentResultIndex; int num = (recentResultIndex + 2) % waterTileSpectrum.ResultsTiming.Length; int num2 = (recentResultIndex + 1) % waterTileSpectrum.ResultsTiming.Length; float num3 = waterTileSpectrum.ResultsTiming[recentResultIndex]; float num4 = waterTileSpectrum.ResultsTiming[num]; float num5 = waterTileSpectrum.ResultsTiming[num2]; float lastFrameTime = spectrumResolver.LastFrameTime; if (num4 <= lastFrameTime || num5 > lastFrameTime) { float loopDuration = waterTileSpectrum.WindWaves.LoopDuration; float num6; if (loopDuration != 0f) { num6 = Mathf.Round((num3 % loopDuration + 0.2f) / 0.2f) * 0.2f; } else if (num5 > lastFrameTime) { num6 = lastFrameTime + this._FFTTimeStep; } else { num6 = Mathf.Max(num3, lastFrameTime) + this._FFTTimeStep; } if (num6 != num5) { cpuFFT.Compute(waterTileSpectrum, num6, num2); waterTileSpectrum.ResultsTiming[num2] = num6; flag2 = true; } waterTileSpectrum.RecentResultIndex = num2; } if (!flag2) { stopwatch.Reset(); Thread.Sleep(3); } } } } } catch (Exception threadException) { this._ThreadException = threadException; } }