track real and scaled time

This commit is contained in:
ktyl 2022-06-25 22:09:19 +01:00
parent 2fd7797e7d
commit b3c5440736
3 changed files with 17 additions and 10 deletions

View File

@ -1,6 +1,11 @@
#include "clock.h"
float now(struct Epoch t)
{
return t.speed * (float)SDL_GetTicks() / 1000.0;
float now()
{
return (float)SDL_GetTicks() / 1000.0;
}
float nowScaled(struct Epoch t)
{
return t.scale * now();
}

View File

@ -4,8 +4,10 @@
struct Epoch
{
float speed;
float scale;
};
// seconds since program start
float now(struct Epoch e);
// real seconds since program start
float now();
// simulation seconds since program start
float nowScaled(struct Epoch e);

View File

@ -41,7 +41,7 @@ void parseArgs(int argc, char* argv[], struct Epoch* e)
fprintf(stderr, "usage: oglc TIMESPEED\n");
}
sscanf(argv[1], "%f", &(e->speed));
sscanf(argv[1], "%f", &(e->scale));
}
int main(int argc, char* argv[])
@ -50,12 +50,12 @@ int main(int argc, char* argv[])
initialise();
float start = now(epoch);
float start = now();
int frames;
for (frames = 0; !checkQuit(); frames++)
{
GLuint shader;
float t = now(epoch);
float t = nowScaled(epoch);
// prepass
// TODO: write output to different texture than main output
@ -104,7 +104,7 @@ int main(int argc, char* argv[])
SDL_GL_SwapWindow(window);
}
float elapsed = now(epoch)-start;
float elapsed = now()-start;
printf("%d frames in %fs [%f fps]\n",
frames,
elapsed,