mirror of
https://github.com/NoelFB/blah.git
synced 2025-07-01 19:45:26 +08:00
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:
@ -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();
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user