more precise timing

renamed Time::elapsed -> Time::seconds, change type to double
updated game to store ticks (microseconds) instead of milliseconds for better update precision
This commit is contained in:
Noel Berry
2021-02-06 00:13:50 -08:00
parent 2c2d668927
commit ac58379de8
13 changed files with 101 additions and 87 deletions

View File

@ -21,8 +21,8 @@ namespace Blah
// Called during shutdown
void shutdown();
// The time, in milliseconds, since the Application was started
uint64_t time();
// The time, in ticks (microseconds) since the Application was started
uint64_t ticks();
// Called every frame
void frame();

View File

@ -7,6 +7,7 @@
#include <blah/core/app.h>
#include <blah/core/filesystem.h>
#include <blah/core/log.h>
#include <blah/core/time.h>
#include <SDL.h>
#include <SDL_vulkan.h>
@ -170,9 +171,11 @@ void PlatformBackend::shutdown()
SDL_Quit();
}
uint64_t PlatformBackend::time()
uint64_t PlatformBackend::ticks()
{
return (uint64_t)SDL_GetTicks();
auto counter = SDL_GetPerformanceCounter();
auto per_second = (double)SDL_GetPerformanceFrequency();
return (uint64_t)(counter * (Time::ticks_per_second / per_second));
}
// Macro defined by X11 conflicts with MouseButton enum