Post by jimmarlowe on May 25, 2015 19:44:45 GMT 1
Since there is no stock FPS display currently in Urho3D 1.32.0, a simple one can be constructed. There are algorithms to do averaging and other things, but this is as simple as it gets, and it coorelates with the fps shown in Debug HUD. "Every complex thing is made up of simple little parts".
in C++
And Angelscript
in C++
class Application
{
public:
...
void FpsDisplay(StringHash eventType, VariantMap& eventData); // event handler to calc fps
private:
...
Timer myTimer_; // timer for FPS display
unsigned int startFrame; // starting frame number
};
Application:: Start()
{
...
myTimer_.Reset();
startFrame = 0;
SubscribeToEvent(E_BEGINFRAME, HANDLER(Application, FpsDisplay));
...
}
// event handler to calculate the fps, it literally counts the frames
// and at the end of a second, it does a subtraction, and you have a
// number of frames per second. Reset the timer, get the starting frame
// and were off to the races again.
void Application::FpsDisplay(StringHash eventType, VariantMap &eventData)
{
if ( myTimer_.GetMSec(false) >= 1000 ) // have we got to a second yet?
{
unsigned int framex = eventData["FrameNumber"].GetUInt(); // get the current frame number
GetSubsystem<Graphics>()->SetWindowTitle("Application FPS:" + String( framex - startFrame ));
startFrame = framex; // make a new starting frame number
myTimer_.Reset(); // reset the timer
}
}
And Angelscript
Timer myTimer_;
uint startFrame = 0;
void Start()
{
...
SubscribeToEvent("BeginFrame","FpsDisplay");
...
}
void FpsDisplay(StringHash eventType, VariantMap& eventData)
{
if ( myTimer_.GetMSec(false) >= 1000 ) // have we got to a second yet
{
int framex = eventData["FrameNumber"].GetUInt();
graphics.windowTitle = "Application FPS:" + String( framex - startFrame );
startFrame = framex;
myTimer_.Reset();
}
}