Paste Code
Paste Blends
Paste Images
Index: source/gameengine/Ketsji/KX_KetsjiEngine.cpp
===================================================================
--- source/gameengine/Ketsji/KX_KetsjiEngine.cpp (revision 32932)
+++ source/gameengine/Ketsji/KX_KetsjiEngine.cpp (working copy)
@@ -164,7 +164,13 @@
m_overrideFrameColorG(0.0),
m_overrideFrameColorB(0.0),

- m_usedome(false)
+ m_usedome(false),
+
+ // Frames Count and FPS AVG
+ m_frameCount(0),
+ m_fpsAvg(0),
+ m_fpsMax(0.0),
+ m_fpsMin(999.9)
{
// Initialize the time logger
m_logger = new KX_TimeCategoryLogger (25);
@@ -1395,14 +1401,29 @@
void KX_KetsjiEngine::RenderDebugProperties()
{
STR_String debugtxt;
+ STR_String fpsDetail;
+
int xcoord = 10; // mmmm, these constants were taken from blender source
int ycoord = 14; // to 'mimic' behaviour
-
+
float tottime = m_logger->GetAverage();
if (tottime < 1e-6f) {
tottime = 1e-6f;
}

+ // Update Frames Count
+ m_frameCount += 1;
+
+ // Clip Wrong Values for FPS AVG ( for mostly of causes )
+ if (1/tottime > 0.01 && 1/tottime < 999.9){
+ m_fpsAvg += (1/tottime);
+ if (m_fpsMax < (1/tottime)) // FPS Max
+ m_fpsMax = (1/tottime);
+ if (m_fpsMin > (1/tottime)) // FPS Min
+ m_fpsMin = (1/tottime);
+ }
+
+
// Set viewport to entire canvas
RAS_Rect viewport;
m_canvas->SetViewPort(0, 0, int(m_canvas->GetWidth()), int(m_canvas->GetHeight()));
@@ -1416,6 +1437,32 @@
ycoord,
m_canvas->GetWidth() /* RdV, TODO ?? */,
m_canvas->GetHeight() /* RdV, TODO ?? */);
+
+ // FPS AVG
+ fpsDetail.Format("FPS AVG: %.3f",m_fpsAvg/m_frameCount);
+ m_rendertools->RenderText2D(RAS_IRenderTools::RAS_TEXT_PADDED,
+ fpsDetail.Ptr(),
+ m_canvas->GetWidth() - 100, // Right side of Canvas - 100 pixels
+ ycoord,
+ m_canvas->GetWidth(),
+ m_canvas->GetHeight());
+ // FPS Max
+ fpsDetail.Format("FPS Max %.3f",m_fpsMax);
+ m_rendertools->RenderText2D(RAS_IRenderTools::RAS_TEXT_PADDED,
+ fpsDetail.Ptr(),
+ m_canvas->GetWidth() - 100,
+ ycoord + 14,
+ m_canvas->GetWidth(),
+ m_canvas->GetHeight());
+ // FPS Min
+ fpsDetail.Format("FPS Min %.3f",m_fpsMin);
+ m_rendertools->RenderText2D(RAS_IRenderTools::RAS_TEXT_PADDED,
+ fpsDetail.Ptr(),
+ m_canvas->GetWidth() - 100,
+ ycoord + 28,
+ m_canvas->GetWidth(),
+ m_canvas->GetHeight());
+
ycoord += 14;
}

Index: source/gameengine/Ketsji/KX_KetsjiEngine.h
===================================================================
--- source/gameengine/Ketsji/KX_KetsjiEngine.h (revision 32932)
+++ source/gameengine/Ketsji/KX_KetsjiEngine.h (working copy)
@@ -99,7 +99,7 @@

bool m_firstframe;
int m_currentFrame;
-
+
double m_frameTime;//discrete timestamp of the 'game logic frame'
double m_clockTime;//current time
double m_previousClockTime;//previous clock time
@@ -223,6 +223,12 @@
void RenderDome();
bool m_usedome;

+ /// Max, Min and AVG FPS
+ int m_frameCount;
+ float m_fpsAvg;
+ float m_fpsMax;
+ float m_fpsMin;
+
///returns true if an update happened to indicate -> Render
bool NextFrame();
void Render();
  1. Index: source/gameengine/Ketsji/KX_KetsjiEngine.cpp
  2. ===================================================================
  3. --- source/gameengine/Ketsji/KX_KetsjiEngine.cpp        (revision 32932)
  4. +++ source/gameengine/Ketsji/KX_KetsjiEngine.cpp        (working copy)
  5. @@ -164,7 +164,13 @@
  6.         m_overrideFrameColorG(0.0),
  7.         m_overrideFrameColorB(0.0),
  8.  
  9. -       m_usedome(false)
  10. +       m_usedome(false),
  11. +       
  12. +       // Frames Count and FPS AVG
  13. +       m_frameCount(0),
  14. +       m_fpsAvg(0),
  15. +       m_fpsMax(0.0),
  16. +       m_fpsMin(999.9)
  17.  {
  18.         // Initialize the time logger
  19.         m_logger = new KX_TimeCategoryLogger (25);
  20. @@ -1395,14 +1401,29 @@
  21.  void KX_KetsjiEngine::RenderDebugProperties()
  22.  {
  23.         STR_String debugtxt;
  24. +       STR_String fpsDetail;
  25. +
  26.         int xcoord = 10;        // mmmm, these constants were taken from blender source
  27.         int ycoord = 14;        // to 'mimic' behaviour
  28. -
  29. +       
  30.         float tottime = m_logger->GetAverage();
  31.         if (tottime < 1e-6f) {
  32.                 tottime = 1e-6f;
  33.         }
  34.  
  35. +       // Update Frames Count
  36. +       m_frameCount += 1;
  37. +
  38. +       // Clip Wrong Values for FPS AVG ( for mostly of causes )
  39. +       if (1/tottime > 0.01 && 1/tottime < 999.9){
  40. +               m_fpsAvg += (1/tottime);
  41. +               if (m_fpsMax < (1/tottime)) // FPS Max
  42. +                       m_fpsMax = (1/tottime);
  43. +               if      (m_fpsMin > (1/tottime)) // FPS Min
  44. +                       m_fpsMin = (1/tottime);
  45. +       }
  46. +       
  47. +
  48.         // Set viewport to entire canvas
  49.         RAS_Rect viewport;
  50.         m_canvas->SetViewPort(0, 0, int(m_canvas->GetWidth()), int(m_canvas->GetHeight()));
  51. @@ -1416,6 +1437,32 @@
  52.                                                                         ycoord,
  53.                                                                         m_canvas->GetWidth() /* RdV, TODO ?? */,
  54.                                                                         m_canvas->GetHeight() /* RdV, TODO ?? */);
  55. +              
  56. +               // FPS AVG
  57. +               fpsDetail.Format("FPS AVG: %.3f",m_fpsAvg/m_frameCount);
  58. +               m_rendertools->RenderText2D(RAS_IRenderTools::RAS_TEXT_PADDED,
  59. +                                                                       fpsDetail.Ptr(),
  60. +                                                                       m_canvas->GetWidth() - 100, // Right side of Canvas - 100 pixels
  61. +                                                                       ycoord,
  62. +                                                                       m_canvas->GetWidth(),
  63. +                                                                       m_canvas->GetHeight());
  64. +               // FPS Max
  65. +               fpsDetail.Format("FPS Max %.3f",m_fpsMax);
  66. +               m_rendertools->RenderText2D(RAS_IRenderTools::RAS_TEXT_PADDED,
  67. +                                                                       fpsDetail.Ptr(),
  68. +                                                                       m_canvas->GetWidth() - 100,
  69. +                                                                       ycoord + 14,
  70. +                                                                       m_canvas->GetWidth(),
  71. +                                                                       m_canvas->GetHeight());
  72. +               // FPS Min
  73. +               fpsDetail.Format("FPS Min %.3f",m_fpsMin);
  74. +               m_rendertools->RenderText2D(RAS_IRenderTools::RAS_TEXT_PADDED,
  75. +                                                                       fpsDetail.Ptr(),
  76. +                                                                       m_canvas->GetWidth() - 100,
  77. +                                                                       ycoord + 28,
  78. +                                                                       m_canvas->GetWidth(),
  79. +                                                                       m_canvas->GetHeight());
  80. +
  81.                 ycoord += 14;
  82.         }
  83.  
  84. Index: source/gameengine/Ketsji/KX_KetsjiEngine.h
  85. ===================================================================
  86. --- source/gameengine/Ketsji/KX_KetsjiEngine.h  (revision 32932)
  87. +++ source/gameengine/Ketsji/KX_KetsjiEngine.h  (working copy)
  88. @@ -99,7 +99,7 @@
  89.         
  90.         bool                            m_firstframe;
  91.         int                                     m_currentFrame;
  92. -
  93. +       
  94.         double                          m_frameTime;//discrete timestamp of the 'game logic frame'
  95.         double                          m_clockTime;//current time
  96.         double                          m_previousClockTime;//previous clock time
  97. @@ -223,6 +223,12 @@
  98.         void                    RenderDome();
  99.         bool                    m_usedome;
  100.  
  101. +       /// Max, Min and AVG FPS
  102. +       int                             m_frameCount;
  103. +       float                   m_fpsAvg;
  104. +       float                   m_fpsMax;
  105. +       float                   m_fpsMin;
  106. +
  107.         ///returns true if an update happened to indicate -> Render
  108.         bool                    NextFrame();
  109.         void                    Render();
  110.  
go to heaven