void timer_Tick(object sender, EventArgs e) { _timer.Stop(); // Stop timer, in case it ticks again before we finish work StringBuilder sbPerfInfo = new StringBuilder(); QueryPerfCounter perfTimer = new QueryPerfCounter(); double perfDur; // Unhook Positions collection from our mesh, for performance // (see http://blogs.msdn.com/timothyc/archive/2006/08/31/734308.aspx) meshMain.Positions = null; perfTimer.Start(); // Do the next iteration on the water grid, propagating waves _grid.ProcessWater(); perfTimer.Stop(); perfDur = perfTimer.Duration(1); sbPerfInfo.AppendFormat("ProcessWater took {0}. ", perfDur.ToString()); perfTimer.Start(); // Then update our mesh to use new Z values meshMain.Positions = _grid.Points; perfTimer.Stop(); perfDur = perfTimer.Duration(1); sbPerfInfo.AppendFormat("UpdateMeshZValues took {0}", perfDur.ToString()); // Write perf data to event log EventLog.WriteEntry(MyEventSource, sbPerfInfo.ToString(), EventLogEntryType.Information); _timer.Start(); // Restart timer that controls frequency of wave propagation }
void CompositionTarget_Rendering(object sender, EventArgs e) { RenderingEventArgs rargs = (RenderingEventArgs)e; if ((rargs.RenderingTime.TotalMilliseconds - _lastTimeRendered) > RenderPeriodInMS) { // Performans için, örgüden Positions koleksiyonunu çıkartın // (see http://blogs.msdn.com/timothyc/archive/2006/08/31/734308.aspx) meshMain.Positions = null; // grid de sonraki yinelemeyi yapılır, dalgaları yaymak double NumDropsThisTime = RenderPeriodInMS / _raindropPeriodInMS; // Bu noktada damla sayısı için bir sonuç gibi bir şey var. // 2.25. Tamsayı kısmı (ör. 2 damla), daha sonra üçüncü damla için% 25 şans vermeyi vereceğiz. int NumDrops = (int)NumDropsThisTime; // trunc for (int i = 0; i < NumDrops; i++) { _grid.SetRandomPeak(_splashAmplitude, _splashDelta, _dropSize); } if ((NumDropsThisTime - NumDrops) > 0) { double DropChance = NumDropsThisTime - NumDrops; if (_rnd.NextDouble() <= DropChance) { _grid.SetRandomPeak(_splashAmplitude, _splashDelta, _dropSize); } } _grid.ProcessWater(); // Ardından, yeni Z değerlerini kullanmak için ağımızı güncelleyin. meshMain.Positions = _grid.Points; _lastTimeRendered = rargs.RenderingTime.TotalMilliseconds; } }