diff options
| author | SND\weimingzhi_cp <SND\weimingzhi_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97> | 2009-04-16 06:22:51 +0000 |
|---|---|---|
| committer | SND\weimingzhi_cp <SND\weimingzhi_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97> | 2009-04-16 06:22:51 +0000 |
| commit | 8139fbf8204882663446bcb06f68789353597820 (patch) | |
| tree | 6ea1f39932b33faee84d603e956470e37f135804 /plugins/dfOpenGL/fps.c | |
| download | pcsxr-8139fbf8204882663446bcb06f68789353597820.tar.gz | |
git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@23061 e17a0e51-4ae3-4d35-97c3-1a29b211df97
Diffstat (limited to 'plugins/dfOpenGL/fps.c')
| -rw-r--r-- | plugins/dfOpenGL/fps.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/plugins/dfOpenGL/fps.c b/plugins/dfOpenGL/fps.c new file mode 100644 index 00000000..21f95c7f --- /dev/null +++ b/plugins/dfOpenGL/fps.c @@ -0,0 +1,41 @@ +#include <sys/time.h> +#include <unistd.h> +#include "gpu_i.h" + +static const double NTSC = 100000000/5994; +static const double PAL = 100000000/5000; + +static double lastvsync = 0; +#define FRAMESAMPLES 10 + +double GetTime() //in microseconds +{ + struct timeval tv; + gettimeofday(&tv, 0); // well, maybe there are better ways + return (double)tv.tv_sec * 1000000 + tv.tv_usec; // to do that, but at least it works +} + +void waitforrealtime() +{ + double currenttime,tickstogo; + double target; + + currenttime = GetTime(); + + if (currenttime < lastvsync + 1000000) + target = lastvsync + (psxDisp.pal ? PAL : NTSC); + else + target = currenttime; + + lastvsync = target; + + while (currenttime < target) + { + tickstogo = target - currenttime; + if (tickstogo >= 500.0f) + { + usleep((useconds_t)tickstogo-200); //usleep in microseconds + } + currenttime = GetTime(); + } +} |
