parent
4f98149fa7
commit
6cba868e20
@ -46,9 +46,12 @@ namespace hex {
|
||||
|
||||
float m_globalScale = 1.0f, m_fontScale = 1.0f;
|
||||
bool m_fpsVisible = false;
|
||||
double m_targetFps;
|
||||
bool m_demoWindowOpen = false;
|
||||
bool m_layoutConfigured = false;
|
||||
|
||||
double m_lastFrameTime;
|
||||
|
||||
static inline std::tuple<int, int> s_currShortcut = { -1, -1 };
|
||||
|
||||
std::list<std::string> m_recentFiles;
|
||||
|
@ -61,6 +61,17 @@ namespace hex::plugin::builtin {
|
||||
return false;
|
||||
});
|
||||
|
||||
ContentRegistry::Settings::add("hex.builtin.setting.interface", "hex.builtin.setting.interface.fps", 60, [](auto name, nlohmann::json &setting) {
|
||||
static int fps = setting.is_number() ? static_cast<int>(setting) : 60;
|
||||
|
||||
if (ImGui::SliderInt(name.data(), &fps, 15, 60)) {
|
||||
setting = fps;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -463,6 +463,7 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.setting.interface.color.light", "Hell" },
|
||||
{ "hex.builtin.setting.interface.color.classic", "Klassisch" },
|
||||
{ "hex.builtin.setting.interface.language", "Sprache" },
|
||||
{ "hex.builtin.setting.interface.fps", "FPS Limite" },
|
||||
|
||||
{ "hex.builtin.provider.file.path", "Dateipfad" },
|
||||
{ "hex.builtin.provider.file.size", "Größe" },
|
||||
|
@ -463,6 +463,7 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.setting.interface.color.light", "Light" },
|
||||
{ "hex.builtin.setting.interface.color.classic", "Classic" },
|
||||
{ "hex.builtin.setting.interface.language", "Language" },
|
||||
{ "hex.builtin.setting.interface.fps", "FPS Limit" },
|
||||
|
||||
{ "hex.builtin.provider.file.path", "File path" },
|
||||
{ "hex.builtin.provider.file.size", "Size" },
|
||||
|
@ -463,6 +463,7 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.setting.interface.color.light", "Chiaro" },
|
||||
{ "hex.builtin.setting.interface.color.classic", "Classico" },
|
||||
{ "hex.builtin.setting.interface.language", "Lingua" },
|
||||
{ "hex.builtin.setting.interface.fps", "FPS limite" },
|
||||
|
||||
{ "hex.builtin.provider.file.path", "Percorso del File" },
|
||||
{ "hex.builtin.provider.file.size", "Dimensione" },
|
||||
|
@ -3,9 +3,11 @@
|
||||
#include <hex.hpp>
|
||||
#include <hex/api/content_registry.hpp>
|
||||
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <numeric>
|
||||
#include <typeinfo>
|
||||
#include <thread>
|
||||
|
||||
#include <imgui.h>
|
||||
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||
@ -26,6 +28,8 @@
|
||||
|
||||
namespace hex {
|
||||
|
||||
using namespace std::literals::chrono_literals;
|
||||
|
||||
void *ImHexSettingsHandler_ReadOpenFn(ImGuiContext *ctx, ImGuiSettingsHandler *, const char *) {
|
||||
return ctx; // Unused, but the return value has to be non-null
|
||||
}
|
||||
@ -57,7 +61,7 @@ namespace hex {
|
||||
this->initGLFW();
|
||||
this->initImGui();
|
||||
|
||||
EventManager::subscribe(Events::SettingsChanged, this, [](auto) -> std::any {
|
||||
EventManager::subscribe(Events::SettingsChanged, this, [this](auto) -> std::any {
|
||||
{
|
||||
auto theme = ContentRegistry::Settings::getSetting("hex.builtin.setting.interface", "hex.builtin.setting.interface.color");
|
||||
|
||||
@ -91,6 +95,13 @@ namespace hex {
|
||||
LangEntry::loadLanguage(static_cast<std::string>(language));
|
||||
}
|
||||
|
||||
{
|
||||
auto targetFps = ContentRegistry::Settings::getSetting("hex.builtin.setting.interface", "hex.builtin.setting.interface.fps");
|
||||
|
||||
if (targetFps.is_number())
|
||||
this->m_targetFps = targetFps;
|
||||
}
|
||||
|
||||
return { };
|
||||
});
|
||||
|
||||
@ -156,6 +167,7 @@ namespace hex {
|
||||
}
|
||||
|
||||
void Window::loop() {
|
||||
this->m_lastFrameTime = glfwGetTime();
|
||||
while (!glfwWindowShouldClose(this->m_window)) {
|
||||
this->frameBegin();
|
||||
|
||||
@ -245,6 +257,10 @@ namespace hex {
|
||||
}
|
||||
|
||||
void Window::frameBegin() {
|
||||
|
||||
if (!glfwGetWindowAttrib(this->m_window, GLFW_VISIBLE) || glfwGetWindowAttrib(this->m_window, GLFW_ICONIFIED))
|
||||
glfwWaitEvents();
|
||||
|
||||
glfwPollEvents();
|
||||
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
@ -373,6 +389,10 @@ namespace hex {
|
||||
glfwMakeContextCurrent(backup_current_context);
|
||||
|
||||
glfwSwapBuffers(this->m_window);
|
||||
|
||||
while (glfwGetTime() < this->m_lastFrameTime + (1 / this->m_targetFps))
|
||||
std::this_thread::sleep_for(500us);
|
||||
this->m_lastFrameTime = glfwGetTime();
|
||||
}
|
||||
|
||||
void Window::drawWelcomeScreen() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user