From 9e6a6c01e46fde9987974eef8a99333fd0b0a744 Mon Sep 17 00:00:00 2001
From: nightmareci <[EMAIL REDACTED]>
Date: Tue, 1 Jul 2025 09:12:18 -0700
Subject: [PATCH] Add support for floating point main callback rates
---
include/SDL3/SDL_hints.h | 4 ++++
src/main/generic/SDL_sysmain_callbacks.c | 6 +++---
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/include/SDL3/SDL_hints.h b/include/SDL3/SDL_hints.h
index 7961157ccf3dd..30a04c4da416d 100644
--- a/include/SDL3/SDL_hints.h
+++ b/include/SDL3/SDL_hints.h
@@ -2500,6 +2500,10 @@ extern "C" {
* This defaults to 0, and specifying NULL for the hint's value will restore
* the default.
*
+ * This doesn't have to be an integer value. For example, "59.94" won't be
+ * rounded to an integer rate; the digits after the decimal are actually
+ * respected.
+ *
* This hint can be set anytime.
*
* \since This hint is available since SDL 3.2.0.
diff --git a/src/main/generic/SDL_sysmain_callbacks.c b/src/main/generic/SDL_sysmain_callbacks.c
index afe5dbdef6c64..0b5f607c23711 100644
--- a/src/main/generic/SDL_sysmain_callbacks.c
+++ b/src/main/generic/SDL_sysmain_callbacks.c
@@ -34,9 +34,9 @@ static void SDLCALL MainCallbackRateHintChanged(void *userdata, const char *name
if (iterate_after_waitevent) {
callback_rate_increment = 0;
} else {
- const int callback_rate = newValue ? SDL_atoi(newValue) : 0;
- if (callback_rate > 0) {
- callback_rate_increment = ((Uint64) 1000000000) / ((Uint64) callback_rate);
+ const double callback_rate = newValue ? SDL_atof(newValue) : 0.0;
+ if (callback_rate > 0.0) {
+ callback_rate_increment = (Uint64) ((double) SDL_NS_PER_SECOND / callback_rate);
} else {
callback_rate_increment = 0;
}