#include <iostream>
#include <time.h>
#include <sys/time.h>
class timer {
public:
timer();
double show_delta();
void update();
private:
struct timeval t1, t2;
double dt;
};
void eat_time()
{
int x;
for(x=0;x<5000000;++x)
x+x/x+x*x+x/x;
return;
}
int main()
{
int x;
timer *T;
T=new timer();
while(1)
{
eat_time();
T->update();
cout << "delta time: " << T->show_delta() << " FPS: " << 1/T->show_delta() << " \r";
cout.flush();
}
return 0;
}
timer::timer()
{
gettimeofday(&t1,NULL);
gettimeofday(&t2,NULL);
dt=.00001;
}
double
timer::show_delta()
{
return dt;
}
void
timer::update()
{
gettimeofday(&t1,NULL);
dt=(t1.tv_sec-t2.tv_sec)+(t1.tv_usec-t2.tv_usec)/1000000.0;
gettimeofday(&t2,NULL);
}
WWWOFFLE - Sat, 11 Dec 1999 18:22:04 CET (vor 15 Minuten) - [Löschen| Neu abrufen: Optionen| regelm. abrufen| Index] - WWWOFFLE