Wednesday, November 20, 2013

How do i display the units of the timer as frames per second ?

If you want to know the actual FPS, I just wrote a FPS counter.



using System;
using System.Collections.Generic;

namespace FPS_Counter
{
class FPS_Counter
{
List<DateTime> FrameCounter = new List<DateTime>();

public void countFrame(){
FrameCounter.Add(DateTime.Now);
}

private void clearOld()
{
bool continueLoop;
DateTime decayLimit = DateTime.Now.AddSeconds(-1);

do
{
continueLoop = false;
if (FrameCounter.Count > 0 && FrameCounter[0] < decayLimit)
{
FrameCounter.RemoveAt(0);
//If you removed one, the one after might be too old too.
continueLoop = true;
}
}while (continueLoop);
}

public int FPS
{
get
{
clearOld();
return FrameCounter.Count;
}
}
}
}

Even in my test app a WindowsForms.Timer calling countFrame every 40 ms and a second one polling FPS every 10 ms I never reached full 25 FPS. I got to 21/22 FPS.



Let's talk about MVVM: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2 Please mark post as helpfull and answers respectively.


No comments:

Post a Comment