You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
838 B
Plaintext
36 lines
838 B
Plaintext
// Small script that prints the FPS to screen with regular intervals.
|
|
import frames;
|
|
|
|
// 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!");
|
|
|
|
// Sleep until rendering begins. This just prevents the first printed
|
|
// value from being 'nan'
|
|
fsleep(0);
|
|
|
|
// counter and totalTime (in the 'frames' module) are updated
|
|
// automatically by the system.
|
|
ulong lastFrame = counter;
|
|
float lastTime = totalTime;
|
|
|
|
float delay = 1.5;
|
|
|
|
while(true)
|
|
{
|
|
sleep(delay);
|
|
|
|
// Calculate differences since last frame
|
|
ulong fdiff = counter-lastFrame;
|
|
float tdiff = totalTime-lastTime;
|
|
|
|
txt.setCaption("fps: ", fdiff/tdiff);
|
|
|
|
lastFrame = counter;
|
|
lastTime = totalTime;
|
|
}
|