CLR,How do I calculate FPS
-
I use Application::Idle to calculate FPS, but it seems to be unsuitable. Becuase the Application::Idle does not like the CWinApp::Idle in MFC. Application::Idle event is not called in every frame. Could somebody know how to calculate FPS in Visual C++ CLR project?
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);Form1^ form1=gcnew Form1();
Application::Idle += gcnew System::EventHandler(form1,&Form1::Form1_Idle);
Application::Run(form1);
return 0;
}public: System::Void Form1_Idle(System::Object^ sender, System::EventArgs^ e)
{
DWORD currentTime=GetTickCount();
DWORD deltaTime=currentTime-m_PlayCurrentTime;m\_PlayCurrentTime=currentTime; m\_FPS->FrameCnt++; m\_FPS->TimeElapsed+=deltaTime; if (m\_FPS->TimeElapsed >= 1000) { m\_FPS->CalculateFPS(); m\_FPS->TimeElapsed -= 1000; m\_FPS->FrameCnt = 0; FPStoolStripStatusLabel->Text=L"FPS=" + m\_FPS->dFPS.ToString(); }
}
-
I use Application::Idle to calculate FPS, but it seems to be unsuitable. Becuase the Application::Idle does not like the CWinApp::Idle in MFC. Application::Idle event is not called in every frame. Could somebody know how to calculate FPS in Visual C++ CLR project?
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);Form1^ form1=gcnew Form1();
Application::Idle += gcnew System::EventHandler(form1,&Form1::Form1_Idle);
Application::Run(form1);
return 0;
}public: System::Void Form1_Idle(System::Object^ sender, System::EventArgs^ e)
{
DWORD currentTime=GetTickCount();
DWORD deltaTime=currentTime-m_PlayCurrentTime;m\_PlayCurrentTime=currentTime; m\_FPS->FrameCnt++; m\_FPS->TimeElapsed+=deltaTime; if (m\_FPS->TimeElapsed >= 1000) { m\_FPS->CalculateFPS(); m\_FPS->TimeElapsed -= 1000; m\_FPS->FrameCnt = 0; FPStoolStripStatusLabel->Text=L"FPS=" + m\_FPS->dFPS.ToString(); }
}
akira32 wrote:
Could somebody know how to calculate FPS in Visual C++ CLR
FPS of what? What frames?
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
akira32 wrote:
Could somebody know how to calculate FPS in Visual C++ CLR
FPS of what? What frames?
Mark Salsbery Microsoft MVP - Visual C++ :java:
FPS is frame per second. Sorry! m_FPS is customized strcut as below: ref struct sFPS { sFPS() { Init(); } void Init() { FrameCnt=0; TimeElapsed=0; dFPS=0; } void CalculateFPS() { dFPS = (Double)FrameCnt / (TimeElapsed/1000.0f); } DWORD FrameCnt; DWORD TimeElapsed; Double dFPS; }; In MFC project, I can use the CWinApp::Idle to count the frame number for FPS. But in CLR project. Application::Idle is not always called(must have some windows messages be triggerred), so I cannot use it to calculate FPS if the mouse does not focus on the winform. I want to find a event that will be called at any time.
modified on Tuesday, November 24, 2009 12:14 AM
-
FPS is frame per second. Sorry! m_FPS is customized strcut as below: ref struct sFPS { sFPS() { Init(); } void Init() { FrameCnt=0; TimeElapsed=0; dFPS=0; } void CalculateFPS() { dFPS = (Double)FrameCnt / (TimeElapsed/1000.0f); } DWORD FrameCnt; DWORD TimeElapsed; Double dFPS; }; In MFC project, I can use the CWinApp::Idle to count the frame number for FPS. But in CLR project. Application::Idle is not always called(must have some windows messages be triggerred), so I cannot use it to calculate FPS if the mouse does not focus on the winform. I want to find a event that will be called at any time.
modified on Tuesday, November 24, 2009 12:14 AM
-
-
I guess I'm missing what you're trying to do. It seems to me a FPS calculation should be done when each frame (or multiple of frames) is rendered, not during an idle event, unless the idle event is the only time a new frame is rendered.
Mark Salsbery Microsoft MVP - Visual C++ :java: