| 82 | |
| 83 | |
| 84 | TriStepResult TriStepRenderFps::Execute( Be::Time realTime, Be::Time simTime, Tr2RenderContext& renderContext ) |
| 85 | { |
| 86 | // these values are static for this implementation, but it should be considered |
| 87 | // to change this in a follwing sprint |
| 88 | const float fpsCalculationTime = 0.25f; |
| 89 | |
| 90 | // position of the fps, left top corner |
| 91 | Tr2Rect screenFPSPos; |
| 92 | const TriViewport& vp = renderContext.m_esm.GetViewport(); |
| 93 | screenFPSPos.left = vp.x + m_displayX; |
| 94 | screenFPSPos.top = vp.y + m_displayY; |
| 95 | screenFPSPos.right = vp.x + vp.width - m_displayX; |
| 96 | screenFPSPos.bottom = vp.y + vp.height - m_displayY; |
| 97 | |
| 98 | // this enables access to the fps |
| 99 | BeInfo* beOSInfo = BeOS->GetInfo(); |
| 100 | |
| 101 | uint32_t textColor; |
| 102 | // TimeAsDouble is formating the time from a int64 in nanoseconds to |
| 103 | // a double where seconds are the first digit before the . |
| 104 | double nowTime = TimeAsDouble( beOSInfo->mRealTime ); |
| 105 | |
| 106 | // to calculate the average the fps of every frame gets collected |
| 107 | m_FPSValuesCount += 1; |
| 108 | m_sumFPSValues += beOSInfo->mFps; |
| 109 | |
| 110 | // This is not the best timing functionality but it is simple and correct enough |
| 111 | // for these purposes (the timing is most likely a few nanoseconds off, due to the |
| 112 | // fact that this doesn't check for the exact time) |
| 113 | if( nowTime >= m_nextFPSCalculationTime ) |
| 114 | { |
| 115 | //timer control |
| 116 | m_nextFPSCalculationTime = ( nowTime + fpsCalculationTime ); |
| 117 | |
| 118 | // calculate the avarege fps and ms |
| 119 | m_averageFPS = m_sumFPSValues / m_FPSValuesCount; |
| 120 | if( m_averageFPS < 1e-5f ) |
| 121 | { |
| 122 | m_averageMSPerFrame = 0.0f; |
| 123 | } |
| 124 | else |
| 125 | { |
| 126 | m_averageMSPerFrame = 1.0f / m_averageFPS * 1000; |
| 127 | } |
| 128 | |
| 129 | // clean up for the new average calculation |
| 130 | m_sumFPSValues = 0.0f; |
| 131 | m_FPSValuesCount = 0; |
| 132 | } |
| 133 | |
| 134 | // Set the print color |
| 135 | // over 60fps green |
| 136 | // between 60 and 30 fps orange |
| 137 | // under 30 fps red |
| 138 | // rgb color calculator http://www.drpeterjones.com/colorcalc/ |
| 139 | if( m_averageFPS > 59.9f ) |
| 140 | { |
| 141 | textColor = 0xff00ff00; |
nothing calls this directly
no test coverage detected