Ver Fonte

SDL platform: Use performance counter for increased time precision

Michael Ragazzon há 3 anos atrás
pai
commit
1b3111b5dc

+ 1 - 1
Backends/RmlUi_Backend_SDL_GL2.cpp

@@ -163,7 +163,7 @@ bool Backend::Initialize(const char* window_name, int width, int height, bool al
 {
 	RMLUI_ASSERT(!data);
 
-	if (SDL_Init(SDL_INIT_VIDEO) != 0)
+	if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_TIMER) != 0)
 		return false;
 
 	// Submit click events when focusing the window.

+ 1 - 1
Backends/RmlUi_Backend_SDL_GL3.cpp

@@ -123,7 +123,7 @@ bool Backend::Initialize(const char* window_name, int width, int height, bool al
 {
 	RMLUI_ASSERT(!data);
 
-	if (SDL_Init(SDL_INIT_VIDEO) != 0)
+	if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_TIMER) != 0)
 		return false;
 
 	// Submit click events when focusing the window.

+ 1 - 1
Backends/RmlUi_Backend_SDL_SDLrenderer.cpp

@@ -56,7 +56,7 @@ bool Backend::Initialize(const char* window_name, int width, int height, bool al
 {
 	RMLUI_ASSERT(!data);
 
-	if (SDL_Init(SDL_INIT_VIDEO) != 0)
+	if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_TIMER) != 0)
 		return false;
 
 	// Submit click events when focusing the window.

+ 3 - 1
Backends/RmlUi_Platform_SDL.cpp

@@ -62,7 +62,9 @@ void SystemInterface_SDL::SetWindow(SDL_Window* in_window)
 
 double SystemInterface_SDL::GetElapsedTime()
 {
-	return double(SDL_GetTicks()) / 1000.0;
+	static const Uint64 start = SDL_GetPerformanceCounter();
+	static const double frequency = double(SDL_GetPerformanceFrequency());
+	return double(SDL_GetPerformanceCounter() - start) / frequency;
 }
 
 void SystemInterface_SDL::SetMouseCursor(const Rml::String& cursor_name)