2009-01-14 20:51:17 +00:00
|
|
|
// Small script that prints the FPS to screen with regular intervals.
|
2009-01-22 20:36:36 +00:00
|
|
|
import frames;
|
2009-01-14 20:51:17 +00:00
|
|
|
|
2009-02-08 18:41:03 +00:00
|
|
|
// Set up the text widget
|
|
|
|
Widget txt = gui.text("StaticText",
|
|
|
|
gui.getWidth()-90, 10, 120, 30,
|
|
|
|
"Statistic");
|
|
|
|
txt.setNeedMouseFocus(false);
|
|
|
|
txt.setTextColor(1,1,1);
|
|
|
|
txt.setCaption("hello!");
|
2009-01-14 20:51:17 +00:00
|
|
|
|
2009-02-22 18:58:17 +00:00
|
|
|
// Sleep until rendering begins. This just prevents the first printed
|
|
|
|
// value from being 'nan'
|
|
|
|
fsleep(0);
|
2009-01-14 20:51:17 +00:00
|
|
|
|
2009-02-08 18:41:03 +00:00
|
|
|
// counter and totalTime (in the 'frames' module) are updated
|
|
|
|
// automatically by the system.
|
|
|
|
ulong lastFrame = counter;
|
|
|
|
float lastTime = totalTime;
|
2009-02-01 02:21:08 +00:00
|
|
|
|
2009-02-08 18:41:03 +00:00
|
|
|
float delay = 1.5;
|
2009-02-01 02:21:08 +00:00
|
|
|
|
2009-02-08 18:41:03 +00:00
|
|
|
while(true)
|
|
|
|
{
|
|
|
|
sleep(delay);
|
2009-01-20 08:29:15 +00:00
|
|
|
|
2009-02-08 18:41:03 +00:00
|
|
|
// Calculate differences since last frame
|
|
|
|
ulong fdiff = counter-lastFrame;
|
|
|
|
float tdiff = totalTime-lastTime;
|
2009-01-20 08:29:15 +00:00
|
|
|
|
2009-02-08 18:41:03 +00:00
|
|
|
txt.setCaption("fps: ", fdiff/tdiff);
|
2009-01-20 08:29:15 +00:00
|
|
|
|
2009-02-08 18:41:03 +00:00
|
|
|
lastFrame = counter;
|
|
|
|
lastTime = totalTime;
|
2009-01-14 20:51:17 +00:00
|
|
|
}
|