Skip to content

Commit

Permalink
Added frame rate limiter UI and hooked it up.
Browse files Browse the repository at this point in the history
  • Loading branch information
luciusDXL committed Jan 17, 2023
1 parent 44dc832 commit 40af822
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 6 deletions.
30 changes: 30 additions & 0 deletions TheForceEngine/TFE_FrontEndUI/frontEndUi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <TFE_RenderBackend/renderBackend.h>
#include <TFE_System/system.h>
#include <TFE_System/parser.h>
#include <TFE_System/frameLimiter.h>
#include <TFE_Jedi/IMuse/imuse.h>
#include <TFE_FileSystem/fileutil.h>
#include <TFE_FileSystem/paths.h>
Expand Down Expand Up @@ -2074,6 +2075,35 @@ namespace TFE_FrontEndUI
ImGui::LabelText("##ConfigLabel", "Rendering");
ImGui::PopFont();

// Frame Rate Limiter.
s32 frameRateLimit = graphics->frameRateLimit;
bool limitEnable = frameRateLimit != 0;
ImGui::Checkbox("Frame Rate Limit Enable", &limitEnable);

if (limitEnable)
{
if (frameRateLimit < 30)
{
frameRateLimit = 74;
}
ImGui::LabelText("##ConfigLabel", "Maximum Framerate:"); ImGui::SameLine(150 * s_uiScale);
ImGui::SetNextItemWidth(196 * s_uiScale);
ImGui::SliderInt("##FPSLimitSlider", &frameRateLimit, 30, 360, "%d");
ImGui::SetNextItemWidth(128 * s_uiScale);
ImGui::InputInt("##FPSLimitEdit", &frameRateLimit, 1, 10);
}
else
{
frameRateLimit = 0;
}

if (frameRateLimit != graphics->frameRateLimit)
{
graphics->frameRateLimit = frameRateLimit;
TFE_System::frameLimiter_set(frameRateLimit);
}
ImGui::Separator();

ImGui::LabelText("##ConfigLabel", "Renderer:"); ImGui::SameLine(75 * s_uiScale);
ImGui::SetNextItemWidth(196 * s_uiScale);
ImGui::Combo("##Renderer", &graphics->rendererIndex, c_renderer, IM_ARRAYSIZE(c_renderer));
Expand Down
5 changes: 5 additions & 0 deletions TheForceEngine/TFE_Settings/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ namespace TFE_Settings
writeKeyValue_Bool(settings, "perspectiveCorrect3DO", s_graphicsSettings.perspectiveCorrectTexturing);
writeKeyValue_Bool(settings, "extendAjoinLimits", s_graphicsSettings.extendAjoinLimits);
writeKeyValue_Bool(settings, "vsync", s_graphicsSettings.vsync);
writeKeyValue_Int(settings, "frameRateLimit", s_graphicsSettings.frameRateLimit);
writeKeyValue_Float(settings, "brightness", s_graphicsSettings.brightness);
writeKeyValue_Float(settings, "contrast", s_graphicsSettings.contrast);
writeKeyValue_Float(settings, "saturation", s_graphicsSettings.saturation);
Expand Down Expand Up @@ -627,6 +628,10 @@ namespace TFE_Settings
{
s_graphicsSettings.vsync = parseBool(value);
}
else if (strcasecmp("frameRateLimit", key) == 0)
{
s_graphicsSettings.frameRateLimit = parseInt(value);
}
else if (strcasecmp("brightness", key) == 0)
{
s_graphicsSettings.brightness = parseFloat(value);
Expand Down
1 change: 1 addition & 0 deletions TheForceEngine/TFE_Settings/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct TFE_Settings_Graphics
bool perspectiveCorrectTexturing = false;
bool extendAjoinLimits = true;
bool vsync = true;
s32 frameRateLimit = 0;
f32 brightness = 1.0f;
f32 contrast = 1.0f;
f32 saturation = 1.0f;
Expand Down
2 changes: 1 addition & 1 deletion TheForceEngine/gitVersion.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const char c_gitVersion[] = R"(
v1.01.000-54-g48942f6e
v1.01.000-55-g44dc832f
)";
10 changes: 5 additions & 5 deletions TheForceEngine/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <TFE_Settings/settings.h>
#include <TFE_System/system.h>
#include <TFE_System/CrashHandler/crashHandler.h>
// #include <TFE_System/frameLimiter.h>
#include <TFE_System/frameLimiter.h>
#include <TFE_System/tfeMessage.h>
#include <TFE_Jedi/Task/task.h>
#include <TFE_RenderShared/texturePacker.h>
Expand Down Expand Up @@ -651,8 +651,8 @@ int main(int argc, char* argv[])
TFE_Game* gameInfo = TFE_Settings::getGame();
TFE_SaveSystem::setCurrentGame(gameInfo->id);

// Test
// TFE_System::frameLimiter_set(72.0);
// Setup the framelimiter.
TFE_System::frameLimiter_set(graphics->frameRateLimit);

// Game loop
u32 frame = 0u;
Expand All @@ -662,7 +662,7 @@ int main(int argc, char* argv[])
while (s_loop && !TFE_System::quitMessagePosted())
{
TFE_FRAME_BEGIN();
// TFE_System::frameLimiter_begin();
TFE_System::frameLimiter_begin();

bool enableRelative = TFE_Input::relativeModeEnabled();
if (enableRelative != relativeMode)
Expand Down Expand Up @@ -846,7 +846,7 @@ int main(int argc, char* argv[])
TFE_RenderBackend::swap(swap);

// Handle framerate limiter.
// TFE_System::frameLimiter_end();
TFE_System::frameLimiter_end();

// Clear transitory input state.
if (endInputFrame)
Expand Down

0 comments on commit 40af822

Please sign in to comment.