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();
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();
|