Add fps_limit param

pull/28/head
FlightlessMango 4 years ago
parent a99720f311
commit cd131e0c39

@ -2144,20 +2144,11 @@ static void overlay_DestroySwapchainKHR(
destroy_swapchain_data(swapchain_data);
}
void getFpsLimit(){
const char *fpsLimit = std::getenv("FPS");
if (fpsLimit != nullptr && !string(fpsLimit).empty()) {
double fps = stod(fpsLimit);
targetFrameTime = double(1000000000.0f / fps);
}
}
void FpsLimiter(){
int64_t now = os_time_get_nano();
sleepTime = targetFrameTime - (now - frameEnd);
this_thread::sleep_for(chrono::nanoseconds(sleepTime - frameOverhead));
frameOverhead = (now - frameStart);
cout << frameOverhead << endl;
}
static VkResult overlay_QueuePresentKHR(
@ -2576,8 +2567,6 @@ static VkResult overlay_CreateInstance(
if (engineName == "vkd3d")
engineName = "VKD3D";
getFpsLimit();
assert(chain_info->u.pLayerInfo);
PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr =
chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
@ -2600,7 +2589,9 @@ static VkResult overlay_CreateInstance(
instance_data_map_physical_devices(instance_data, true);
parse_overlay_env(&instance_data->params, getenv("MANGOHUD_CONFIG"));
if (instance_data->params.fps_limit > 0)
targetFrameTime = double(1000000000.0f / instance_data->params.fps_limit);
int font_size;
instance_data->params.font_size > 0 ? font_size = instance_data->params.font_size : font_size = 24;
instance_data->params.font_size > 0 ? font_size = instance_data->params.font_size : instance_data->params.font_size = 24;

@ -79,6 +79,12 @@ parse_fps_sampling_period(const char *str)
return strtol(str, NULL, 0) * 1000;
}
static uint32_t
parse_fps_limit(const char *str)
{
return strtol(str, NULL, 0);
}
static bool
parse_no_display(const char *str)
{
@ -183,6 +189,7 @@ parse_overlay_env(struct overlay_params *params,
params->width = 280;
params->height = 140;
params->control = -1;
params->fps_limit = 0;
if (!env)
return;

@ -52,6 +52,7 @@ extern "C" {
OVERLAY_PARAM_CUSTOM(height) \
OVERLAY_PARAM_CUSTOM(no_display) \
OVERLAY_PARAM_CUSTOM(control) \
OVERLAY_PARAM_CUSTOM(fps_limit) \
OVERLAY_PARAM_CUSTOM(font_size) \
OVERLAY_PARAM_CUSTOM(help)
@ -77,6 +78,7 @@ struct overlay_params {
FILE *output_file;
int control;
uint32_t fps_sampling_period; /* us */
uint32_t fps_limit;
bool help;
bool no_display;
unsigned width;

Loading…
Cancel
Save