@@ -301,6 +301,29 @@ void SpoolAllAreaDatas()
301301 MsgError (" Unable to spool area datas!\n " );
302302}
303303
304+ // -------------------------------------------------------------
305+ // Updates frames per second counter and returns a number
306+ // -------------------------------------------------------------
307+ int UpdateFPSCounter (float deltaTime)
308+ {
309+ // Engine frames status
310+ static float accumTime = 0 .1f ;
311+ static int framesPerSecond = 0 ;
312+ static int numFrames = 0 ;
313+
314+ if (accumTime > 0 .1f )
315+ {
316+ framesPerSecond = (int )((float )numFrames / accumTime + 0 .5f );
317+ numFrames = 0 ;
318+ accumTime = 0 ;
319+ }
320+
321+ accumTime += deltaTime;
322+ numFrames++;
323+
324+ return framesPerSecond;
325+ }
326+
304327// -------------------------------------------------------------
305328
306329char g_modelSearchNameBuffer[64 ];
@@ -418,7 +441,7 @@ extern int g_drawnPolygons;
418441// -------------------------------------------------------------
419442// Displays Main menu bar, stats and child windows
420443// -------------------------------------------------------------
421- void DisplayUI ()
444+ void DisplayUI (float deltaTime )
422445{
423446 if (ImGui::BeginMainMenuBar ())
424447 {
@@ -515,6 +538,8 @@ void DisplayUI()
515538 {
516539 ImGui::SetWindowPos (ImVec2 (0 , 24 ));
517540
541+ ImGui::TextColored (ImVec4 (1 .0f , 1 .0f , 1 .0f , 0 .5f ), " FPS: %d" , UpdateFPSCounter (deltaTime));
542+
518543 if (g_viewerMode == 0 )
519544 {
520545 ImGui::SetWindowSize (ImVec2 (400 , 120 ));
@@ -535,7 +560,7 @@ void DisplayUI()
535560 MODEL* model = ref->model ;
536561
537562 ImGui::TextColored (ImVec4 (1 .0f , 1 .0f , 0 .0f , 1 .5f ), " Use arrows to change models" );
538-
563+
539564 if (model)
540565 {
541566 ImGui::TextColored (ImVec4 (1 .0f , 1 .0f , 1 .0f , 0 .5f ), " Polygons: %d" , model->num_polys );
@@ -767,11 +792,11 @@ void ViewerMainLoop()
767792 do
768793 {
769794 // compute time
770- const float ticks_to_ms = 1 .0f / 10000 . 0f ;
795+ const double ticks_to_ms = 1.0 / 1000000.0 ;
771796 int64 curTicks = Time::microTicks ();
772797
773798 float deltaTime = double (curTicks - oldTicks) * ticks_to_ms;
774-
799+
775800 oldTicks = curTicks;
776801
777802 ImGui_ImplOpenGL3_NewFrame ();
@@ -808,7 +833,7 @@ void ViewerMainLoop()
808833 DebugOverlay_Draw ();
809834
810835 // Do ImGUI interface
811- DisplayUI ();
836+ DisplayUI (deltaTime );
812837
813838 // draw stuff
814839 ImGui::Render ();
0 commit comments