Add option to fix the framerate to the native screen refresh rate

Useful on mobile devices where using non-standard framerates
looks absolutely horrible and screen refresh rates vary highly.
This commit is contained in:
Jonas Kulla 2015-01-03 18:48:09 +01:00
parent 4fb94aaf10
commit 146e0294b4
6 changed files with 44 additions and 6 deletions

View File

@ -88,6 +88,17 @@
# frameSkip=true # frameSkip=true
# Use a fixed framerate that is approx. equal to the
# native screen refresh rate. This is different from
# "fixedFramerate" because the actual frame rate is
# reported back to the game, ensuring correct timers.
# If the screen refresh rate cannot be determined,
# this option is force-disabled
# (default: disabled)
#
# syncToRefreshrate=false
# Don't use alpha blending when rendering text # Don't use alpha blending when rendering text
# (default: disabled) # (default: disabled)
# #

View File

@ -152,6 +152,7 @@ Config::Config()
defScreenH(0), defScreenH(0),
fixedFramerate(0), fixedFramerate(0),
frameSkip(true), frameSkip(true),
syncToRefreshrate(false),
solidFonts(false), solidFonts(false),
subImageFix(false), subImageFix(false),
gameFolder("."), gameFolder("."),
@ -181,6 +182,7 @@ void Config::read(int argc, char *argv[])
PO_DESC(defScreenH, int) \ PO_DESC(defScreenH, int) \
PO_DESC(fixedFramerate, int) \ PO_DESC(fixedFramerate, int) \
PO_DESC(frameSkip, bool) \ PO_DESC(frameSkip, bool) \
PO_DESC(syncToRefreshrate, bool) \
PO_DESC(solidFonts, bool) \ PO_DESC(solidFonts, bool) \
PO_DESC(subImageFix, bool) \ PO_DESC(subImageFix, bool) \
PO_DESC(gameFolder, std::string) \ PO_DESC(gameFolder, std::string) \

View File

@ -86,6 +86,7 @@ struct Config
int fixedFramerate; int fixedFramerate;
bool frameSkip; bool frameSkip;
bool syncToRefreshrate;
bool solidFonts; bool solidFonts;

View File

@ -187,6 +187,7 @@ struct RGSSThreadData
Vec2 sizeResoRatio; Vec2 sizeResoRatio;
Vec2i screenOffset; Vec2i screenOffset;
const int refreshRate;
Config config; Config config;
@ -196,12 +197,14 @@ struct RGSSThreadData
const char *argv0, const char *argv0,
SDL_Window *window, SDL_Window *window,
ALCdevice *alcDev, ALCdevice *alcDev,
int refreshRate,
const Config& newconf) const Config& newconf)
: ethread(ethread), : ethread(ethread),
argv0(argv0), argv0(argv0),
window(window), window(window),
alcDev(alcDev), alcDev(alcDev),
sizeResoRatio(1, 1), sizeResoRatio(1, 1),
refreshRate(refreshRate),
config(newconf) config(newconf)
{} {}
}; };

View File

@ -628,10 +628,19 @@ Graphics::Graphics(RGSSThreadData *data)
{ {
p = new GraphicsPrivate(data); p = new GraphicsPrivate(data);
if (data->config.fixedFramerate > 0) if (data->config.syncToRefreshrate)
p->fpsLimiter.setDesiredFPS(data->config.fixedFramerate); {
else if (data->config.fixedFramerate < 0) p->frameRate = data->refreshRate;
p->fpsLimiter.disabled = true; p->fpsLimiter.disabled = true;
}
else if (data->config.fixedFramerate > 0)
{
p->fpsLimiter.setDesiredFPS(data->config.fixedFramerate);
}
else if (data->config.fixedFramerate < 0)
{
p->fpsLimiter.disabled = true;
}
} }
Graphics::~Graphics() Graphics::~Graphics()
@ -798,6 +807,9 @@ void Graphics::setFrameRate(int value)
{ {
p->frameRate = clamp(value, 10, 120); p->frameRate = clamp(value, 10, 120);
if (p->threadData->config.syncToRefreshrate)
return;
if (p->threadData->config.fixedFramerate > 0) if (p->threadData->config.fixedFramerate > 0)
return; return;

View File

@ -68,13 +68,14 @@ printGLInfo()
int rgssThreadFun(void *userdata) int rgssThreadFun(void *userdata)
{ {
RGSSThreadData *threadData = static_cast<RGSSThreadData*>(userdata); RGSSThreadData *threadData = static_cast<RGSSThreadData*>(userdata);
const Config &conf = threadData->config;
SDL_Window *win = threadData->window; SDL_Window *win = threadData->window;
SDL_GLContext glCtx; SDL_GLContext glCtx;
/* Setup GL context */ /* Setup GL context */
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
if (threadData->config.debugMode) if (conf.debugMode)
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG); SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG);
glCtx = SDL_GL_CreateContext(win); glCtx = SDL_GL_CreateContext(win);
@ -103,7 +104,8 @@ int rgssThreadFun(void *userdata)
printGLInfo(); printGLInfo();
SDL_GL_SetSwapInterval(threadData->config.vsync ? 1 : 0); bool vsync = conf.vsync || conf.syncToRefreshrate;
SDL_GL_SetSwapInterval(vsync ? 1 : 0);
GLDebugLogger dLogger; GLDebugLogger dLogger;
@ -283,9 +285,16 @@ int main(int argc, char *argv[])
return 0; return 0;
} }
SDL_DisplayMode mode;
SDL_GetDisplayMode(0, 0, &mode);
/* Can't sync to display refresh rate if its value is unknown */
if (!mode.refresh_rate)
conf.syncToRefreshrate = false;
EventThread eventThread; EventThread eventThread;
RGSSThreadData rtData(&eventThread, argv[0], win, RGSSThreadData rtData(&eventThread, argv[0], win,
alcDev, conf); alcDev, mode.refresh_rate, conf);
int winW, winH; int winW, winH;
SDL_GetWindowSize(win, &winW, &winH); SDL_GetWindowSize(win, &winW, &winH);