From 2446756c544904c83c9f08469ac9b17ebeab1fa3 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Thu, 21 Mar 2019 08:12:27 -0400 Subject: [PATCH] Make settings a namespace instead of a global class. --- include/settings.hpp | 73 +++++++++++++++++------------------- src/app.cpp | 2 +- src/app/CableWidget.cpp | 4 +- src/app/ModuleBrowser.cpp | 18 ++++----- src/app/ModuleWidget.cpp | 4 +- src/app/ParamWidget.cpp | 2 +- src/app/RackScrollWidget.cpp | 8 ++-- src/app/Scene.cpp | 4 +- src/app/Toolbar.cpp | 28 +++++++------- src/asset.cpp | 4 +- src/engine/Engine.cpp | 8 ++-- src/logger.cpp | 2 +- src/main.cpp | 22 +++++------ src/patch.cpp | 12 +++--- src/plugin.cpp | 14 +++---- src/settings.cpp | 40 +++++++++++++++----- src/window.cpp | 28 +++++++------- 17 files changed, 146 insertions(+), 127 deletions(-) diff --git a/include/settings.hpp b/include/settings.hpp index f69f82e9..0d37d644 100644 --- a/include/settings.hpp +++ b/include/settings.hpp @@ -6,42 +6,39 @@ namespace rack { - - -struct Settings { - /** Runtime state, not serialized. */ - bool devMode = false; - bool headless = false; - - /** Persistent state, serialized to settings.json. */ - std::string token; - math::Vec windowSize; - math::Vec windowPos; - float zoom = 1.0; - bool invertZoom = false; - float cableOpacity = 0.5; - float cableTension = 0.5; - bool allowCursorLock = true; - float sampleRate = 44100.0; - int threadCount = 1; - bool paramTooltip = false; - bool cpuMeter = false; - bool lockModules = false; - bool checkVersion = true; - float frameRateLimit = 70.0; - bool frameRateSync = true; - bool skipLoadOnLaunch = false; - std::string patchPath; - std::set favoriteModels; - - json_t *toJson(); - void fromJson(json_t *rootJ); - void save(const std::string &path); - void load(const std::string &path); -}; - - -extern Settings settings; - - +namespace settings { + + +/** Runtime state, not serialized. */ +extern bool devMode; +extern bool headless; + +/** Persistent state, serialized to settings.json. */ +extern std::string token; +extern math::Vec windowSize; +extern math::Vec windowPos; +extern float zoom; +extern bool invertZoom; +extern float cableOpacity; +extern float cableTension; +extern bool allowCursorLock; +extern float sampleRate; +extern int threadCount; +extern bool paramTooltip; +extern bool cpuMeter; +extern bool lockModules; +extern bool checkVersion; +extern float frameRateLimit; +extern bool frameRateSync; +extern bool skipLoadOnLaunch; +extern std::string patchPath; +extern std::set favoriteModels; + +json_t *toJson(); +void fromJson(json_t *rootJ); +void save(const std::string &path); +void load(const std::string &path); + + +} // namespace settings } // namespace rack diff --git a/src/app.cpp b/src/app.cpp index ccb1ac60..0c75ad02 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -13,7 +13,7 @@ namespace rack { void App::init() { engine = new engine::Engine; - if (!settings.headless) { + if (!settings::headless) { event = new widget::EventState; history = new history::State; window = new Window; diff --git a/src/app/CableWidget.cpp b/src/app/CableWidget.cpp index 8b3f31ee..05cb9062 100644 --- a/src/app/CableWidget.cpp +++ b/src/app/CableWidget.cpp @@ -214,8 +214,8 @@ void CableWidget::fromJson(json_t *rootJ) { } void CableWidget::draw(const DrawArgs &args) { - float opacity = settings.cableOpacity; - float tension = settings.cableTension; + float opacity = settings::cableOpacity; + float tension = settings::cableTension; float thickness = 5; if (isComplete()) { diff --git a/src/app/ModuleBrowser.cpp b/src/app/ModuleBrowser.cpp index 1c8f9635..0c7e92a0 100644 --- a/src/app/ModuleBrowser.cpp +++ b/src/app/ModuleBrowser.cpp @@ -126,17 +126,17 @@ struct ModelFavoriteQuantity : ui::Quantity { std::string getLabel() override {return "★";} void setValue(float value) override { if (value) { - settings.favoriteModels.insert(model); + settings::favoriteModels.insert(model); } else { - auto it = settings.favoriteModels.find(model); - if (it != settings.favoriteModels.end()) - settings.favoriteModels.erase(it); + auto it = settings::favoriteModels.find(model); + if (it != settings::favoriteModels.end()) + settings::favoriteModels.erase(it); } } float getValue() override { - auto it = settings.favoriteModels.find(model); - return (it != settings.favoriteModels.end()); + auto it = settings::favoriteModels.find(model); + return (it != settings::favoriteModels.end()); } }; @@ -304,7 +304,7 @@ struct BrowserSearchField : ui::TextField { struct ShowFavoritesQuantity : ui::Quantity { widget::Widget *widget; std::string getLabel() override { - int favoritesLen = settings.favoriteModels.size(); + int favoritesLen = settings::favoriteModels.size(); return string::f("Only show favorites (%d)", favoritesLen); } void setValue(float value) override; @@ -477,8 +477,8 @@ struct ModuleBrowser : widget::OpaqueWidget { for (Widget *w : modelContainer->children) { if (favorites) { ModelBox *m = dynamic_cast(w); - auto it = settings.favoriteModels.find(m->model); - w->visible = (it != settings.favoriteModels.end()); + auto it = settings::favoriteModels.find(m->model); + w->visible = (it != settings::favoriteModels.end()); } else { w->visible = true; diff --git a/src/app/ModuleWidget.cpp b/src/app/ModuleWidget.cpp index da94e349..339398d7 100644 --- a/src/app/ModuleWidget.cpp +++ b/src/app/ModuleWidget.cpp @@ -228,7 +228,7 @@ void ModuleWidget::draw(const DrawArgs &args) { Widget::draw(args); // Power meter - if (module && settings.cpuMeter) { + if (module && settings::cpuMeter) { nvgBeginPath(args.vg); nvgRect(args.vg, 0, box.size.y - 20, @@ -368,7 +368,7 @@ void ModuleWidget::onDragEnd(const widget::DragEndEvent &e) { } void ModuleWidget::onDragMove(const widget::DragMoveEvent &e) { - if (!settings.lockModules) { + if (!settings::lockModules) { math::Rect newBox = box; newBox.pos = APP->scene->rack->mousePos.minus(dragPos); APP->scene->rack->requestModuleBoxNearest(this, newBox); diff --git a/src/app/ParamWidget.cpp b/src/app/ParamWidget.cpp index 5a5d5757..ff1e1198 100644 --- a/src/app/ParamWidget.cpp +++ b/src/app/ParamWidget.cpp @@ -168,7 +168,7 @@ void ParamWidget::onDoubleClick(const widget::DoubleClickEvent &e) { } void ParamWidget::onEnter(const widget::EnterEvent &e) { - if (settings.paramTooltip && !tooltip && paramQuantity) { + if (settings::paramTooltip && !tooltip && paramQuantity) { ParamTooltip *paramTooltip = new ParamTooltip; paramTooltip->paramWidget = this; APP->scene->addChild(paramTooltip); diff --git a/src/app/RackScrollWidget.cpp b/src/app/RackScrollWidget.cpp index 43b99534..94a6b64b 100644 --- a/src/app/RackScrollWidget.cpp +++ b/src/app/RackScrollWidget.cpp @@ -21,7 +21,7 @@ RackScrollWidget::RackScrollWidget() { } void RackScrollWidget::step() { - float zoom = std::round(settings.zoom / 0.01) * 0.01; + float zoom = std::round(settings::zoom / 0.01) * 0.01; if (zoom != zoomWidget->zoom) { // Set offset based on zoomPos offset = offset.plus(zoomPos).div(zoomWidget->zoom).mult(zoom).minus(zoomPos); @@ -99,10 +99,10 @@ void RackScrollWidget::onHoverScroll(const widget::HoverScrollEvent &e) { if ((APP->window->getMods() & WINDOW_MOD_MASK) == WINDOW_MOD_CTRL) { // Increase zoom float zoomDelta = e.scrollDelta.y / 50 / 4; - if (settings.invertZoom) + if (settings::invertZoom) zoomDelta *= -1; - settings.zoom *= std::pow(2, zoomDelta); - settings.zoom = math::clamp(settings.zoom, 0.25f, 2.f); + settings::zoom *= std::pow(2, zoomDelta); + settings::zoom = math::clamp(settings::zoom, 0.25f, 2.f); zoomPos = e.pos; e.consume(this); return; diff --git a/src/app/Scene.cpp b/src/app/Scene.cpp index 8e645c1b..6d9cb11d 100644 --- a/src/app/Scene.cpp +++ b/src/app/Scene.cpp @@ -43,11 +43,11 @@ void Scene::step() { if (time - lastAutoSaveTime >= 15.0) { lastAutoSaveTime = time; APP->patch->save(asset::user("autosave.vcv")); - settings.save(asset::user("settings.json")); + settings::save(asset::user("settings.json")); } // Request latest version from server - if (!settings.devMode && checkVersion && !checkedVersion) { + if (!settings::devMode && checkVersion && !checkedVersion) { std::thread t(&Scene::runCheckVersion, this); t.detach(); checkedVersion = true; diff --git a/src/app/Toolbar.cpp b/src/app/Toolbar.cpp index 0cdc7139..b04db7cc 100644 --- a/src/app/Toolbar.cpp +++ b/src/app/Toolbar.cpp @@ -172,10 +172,10 @@ struct EditButton : MenuButton { struct ZoomQuantity : ui::Quantity { void setValue(float value) override { - settings.zoom = math::clamp(value, getMinValue(), getMaxValue()); + settings::zoom = math::clamp(value, getMinValue(), getMaxValue()); } float getValue() override { - return settings.zoom; + return settings::zoom; } float getMinValue() override {return 0.25;} float getMaxValue() override {return 2.0;} @@ -189,10 +189,10 @@ struct ZoomQuantity : ui::Quantity { struct CableOpacityQuantity : ui::Quantity { void setValue(float value) override { - settings.cableOpacity = math::clamp(value, getMinValue(), getMaxValue()); + settings::cableOpacity = math::clamp(value, getMinValue(), getMaxValue()); } float getValue() override { - return settings.cableOpacity; + return settings::cableOpacity; } float getDefaultValue() override {return 0.5;} float getDisplayValue() override {return getValue() * 100;} @@ -205,10 +205,10 @@ struct CableOpacityQuantity : ui::Quantity { struct CableTensionQuantity : ui::Quantity { void setValue(float value) override { - settings.cableTension = math::clamp(value, getMinValue(), getMaxValue()); + settings::cableTension = math::clamp(value, getMinValue(), getMaxValue()); } float getValue() override { - return settings.cableTension; + return settings::cableTension; } float getDefaultValue() override {return 0.5;} std::string getLabel() override {return "Cable tension";} @@ -218,21 +218,21 @@ struct CableTensionQuantity : ui::Quantity { struct CpuMeterItem : ui::MenuItem { void onAction(const widget::ActionEvent &e) override { - settings.cpuMeter ^= true; + settings::cpuMeter ^= true; } }; struct ParamTooltipItem : ui::MenuItem { void onAction(const widget::ActionEvent &e) override { - settings.paramTooltip ^= true; + settings::paramTooltip ^= true; } }; struct LockModulesItem : ui::MenuItem { void onAction(const widget::ActionEvent &e) override { - settings.lockModules ^= true; + settings::lockModules ^= true; } }; @@ -329,17 +329,17 @@ struct SettingsButton : MenuButton { ParamTooltipItem *paramTooltipItem = new ParamTooltipItem; paramTooltipItem->text = "Parameter tooltips"; - paramTooltipItem->rightText = CHECKMARK(settings.paramTooltip); + paramTooltipItem->rightText = CHECKMARK(settings::paramTooltip); menu->addChild(paramTooltipItem); CpuMeterItem *cpuMeterItem = new CpuMeterItem; cpuMeterItem->text = "CPU meter"; - cpuMeterItem->rightText = CHECKMARK(settings.cpuMeter); + cpuMeterItem->rightText = CHECKMARK(settings::cpuMeter); menu->addChild(cpuMeterItem); LockModulesItem *lockModulesItem = new LockModulesItem; lockModulesItem->text = "Lock modules"; - lockModulesItem->rightText = CHECKMARK(settings.lockModules); + lockModulesItem->rightText = CHECKMARK(settings::lockModules); menu->addChild(lockModulesItem); SampleRateItem *sampleRateItem = new SampleRateItem; @@ -593,7 +593,7 @@ struct WebsiteItem : ui::MenuItem { struct CheckVersionItem : ui::MenuItem { void onAction(const widget::ActionEvent &e) override { - settings.checkVersion ^= true; + settings::checkVersion ^= true; } }; @@ -623,7 +623,7 @@ struct HelpButton : MenuButton { CheckVersionItem *checkVersionItem = new CheckVersionItem; checkVersionItem->text = "Check version on launch"; - checkVersionItem->rightText = CHECKMARK(settings.checkVersion); + checkVersionItem->rightText = CHECKMARK(settings::checkVersion); menu->addChild(checkVersionItem); UserFolderItem *folderItem = new UserFolderItem; diff --git a/src/asset.cpp b/src/asset.cpp index b4da6494..f2bbaa01 100644 --- a/src/asset.cpp +++ b/src/asset.cpp @@ -28,7 +28,7 @@ namespace asset { void init() { // Get system dir if (systemDir.empty()) { - if (settings.devMode) { + if (settings::devMode) { systemDir = "."; } else { @@ -58,7 +58,7 @@ void init() { // Get user dir if (userDir.empty()) { - if (settings.devMode) { + if (settings::devMode) { userDir = "."; } else { diff --git a/src/engine/Engine.cpp b/src/engine/Engine.cpp index 28d6768f..95a427df 100644 --- a/src/engine/Engine.cpp +++ b/src/engine/Engine.cpp @@ -166,12 +166,12 @@ Engine::Engine() { internal->workerBarrier.total = 1; setSampleRate(44100.f); - setThreadCount(settings.threadCount); + setThreadCount(settings::threadCount); } Engine::~Engine() { - settings.sampleRate = internal->sampleRate; - settings.threadCount = internal->threadCount; + settings::sampleRate = internal->sampleRate; + settings::threadCount = internal->threadCount; // Stop worker threads setThreadCount(1); @@ -207,7 +207,7 @@ static void Engine_stepModules(Engine *that, int threadId) { Module *module = internal->modules[i]; if (!module->bypass) { // Step module - if (settings.cpuMeter) { + if (settings::cpuMeter) { auto startTime = std::chrono::high_resolution_clock::now(); module->process(processCtx); diff --git a/src/logger.cpp b/src/logger.cpp index e8921800..16f86340 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -16,7 +16,7 @@ static std::mutex logMutex; void init() { startTime = std::chrono::high_resolution_clock::now(); - if (settings.devMode) { + if (settings::devMode) { outputFile = stderr; } else { diff --git a/src/main.cpp b/src/main.cpp index 74549115..35f7b508 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -64,10 +64,10 @@ int main(int argc, char *argv[]) { while ((c = getopt(argc, argv, "ds:u:")) != -1) { switch (c) { case 'd': { - settings.devMode = true; + settings::devMode = true; } break; case 'h': { - settings.headless = true; + settings::headless = true; } break; case 's': { asset::systemDir = optarg; @@ -89,7 +89,7 @@ int main(int argc, char *argv[]) { // We can now install a signal handler and log the output // Mac has its own decent crash handler #if 0 - if (!settings.devMode) { + if (!settings::devMode) { signal(SIGABRT, fatalSignalHandler); signal(SIGFPE, fatalSignalHandler); signal(SIGILL, fatalSignalHandler); @@ -100,7 +100,7 @@ int main(int argc, char *argv[]) { // Log environment INFO("%s v%s", app::APP_NAME, app::APP_VERSION); - if (settings.devMode) + if (settings::devMode) INFO("Development mode"); INFO("System directory: %s", asset::systemDir.c_str()); INFO("User directory: %s", asset::userDir.c_str()); @@ -113,14 +113,14 @@ int main(int argc, char *argv[]) { keyboard::init(); gamepad::init(); plugin::init(); - if (!settings.headless) { + if (!settings::headless) { ui::init(); windowInit(); } // Initialize app INFO("Initializing app"); - settings.load(asset::user("settings.json")); + settings::load(asset::user("settings.json")); appInit(); const char *openedFilename = glfwGetOpenedFilename(); @@ -128,14 +128,14 @@ int main(int argc, char *argv[]) { patchPath = openedFilename; } - if (!settings.headless) { + if (!settings::headless) { APP->patch->init(patchPath); } INFO("Starting engine"); APP->engine->start(); - if (!settings.headless) { + if (!settings::headless) { INFO("Running window"); APP->window->run(); INFO("Stopped window"); @@ -148,16 +148,16 @@ int main(int argc, char *argv[]) { APP->engine->stop(); // Destroy app - if (!settings.headless) { + if (!settings::headless) { APP->patch->save(asset::user("autosave.vcv")); } INFO("Destroying app"); appDestroy(); - settings.save(asset::user("settings.json")); + settings::save(asset::user("settings.json")); // Destroy environment INFO("Destroying environment"); - if (!settings.headless) { + if (!settings::headless) { windowDestroy(); ui::destroy(); } diff --git a/src/patch.cpp b/src/patch.cpp index 8abf4883..cba230be 100644 --- a/src/patch.cpp +++ b/src/patch.cpp @@ -17,11 +17,11 @@ static const char PATCH_FILTERS[] = "VCV Rack patch (.vcv):vcv"; PatchManager::PatchManager() { - path = settings.patchPath; + path = settings::patchPath; } PatchManager::~PatchManager() { - settings.patchPath = path; + settings::patchPath = path; } void PatchManager::init(std::string path) { @@ -33,10 +33,10 @@ void PatchManager::init(std::string path) { } // To prevent launch crashes, if Rack crashes between now and 15 seconds from now, the "skipAutosaveOnLaunch" property will remain in settings.json, so that in the next launch, the broken autosave will not be loaded. - bool oldSkipLoadOnLaunch = settings.skipLoadOnLaunch; - settings.skipLoadOnLaunch = true; - settings.save(asset::user("settings.json")); - settings.skipLoadOnLaunch = false; + bool oldSkipLoadOnLaunch = settings::skipLoadOnLaunch; + settings::skipLoadOnLaunch = true; + settings::save(asset::user("settings.json")); + settings::skipLoadOnLaunch = false; if (oldSkipLoadOnLaunch && osdialog_message(OSDIALOG_INFO, OSDIALOG_YES_NO, "Rack has recovered from a crash, possibly caused by a faulty module in your patch. Clear your patch and start over?")) { this->path = ""; return; diff --git a/src/plugin.cpp b/src/plugin.cpp index d8bc5b03..158539d2 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -206,7 +206,7 @@ static bool syncPlugin(std::string slug, json_t *manifestJ, bool dryRun) { if (dryRun) { downloadUrl += "/available"; } - downloadUrl += "?token=" + network::encodeUrl(settings.token); + downloadUrl += "?token=" + network::encodeUrl(settings::token); downloadUrl += "&slug=" + network::encodeUrl(slug); downloadUrl += "&version=" + network::encodeUrl(latestVersion); downloadUrl += "&arch=" + network::encodeUrl(arch); @@ -366,7 +366,7 @@ void init() { // Copy Fundamental package to plugins directory if Fundamental is not loaded std::string fundamentalSrc = asset::system("Fundamental.zip"); std::string fundamentalDir = asset::user("plugins/Fundamental"); - if (!settings.devMode && !getPlugin("Fundamental") && system::isFile(fundamentalSrc)) { + if (!settings::devMode && !getPlugin("Fundamental") && system::isFile(fundamentalSrc)) { extractZip(fundamentalSrc.c_str(), pluginsDir.c_str()); loadPlugin(fundamentalDir); } @@ -409,7 +409,7 @@ void logIn(const std::string &email, const std::string &password) { json_t *tokenJ = json_object_get(resJ, "token"); if (tokenJ) { const char *tokenStr = json_string_value(tokenJ); - settings.token = tokenStr; + settings::token = tokenStr; loginStatus = ""; } } @@ -418,11 +418,11 @@ void logIn(const std::string &email, const std::string &password) { } void logOut() { - settings.token = ""; + settings::token = ""; } bool sync(bool dryRun) { - if (settings.token.empty()) + if (settings::token.empty()) return false; bool available = false; @@ -438,7 +438,7 @@ bool sync(bool dryRun) { // Get user's plugins list json_t *pluginsReqJ = json_object(); - json_object_set(pluginsReqJ, "token", json_string(settings.token.c_str())); + json_object_set(pluginsReqJ, "token", json_string(settings::token.c_str())); std::string pluginsUrl = app::API_URL; pluginsUrl += "/plugins"; json_t *pluginsResJ = network::requestJson(network::METHOD_GET, pluginsUrl, pluginsReqJ); @@ -509,7 +509,7 @@ void cancelDownload() { } bool isLoggedIn() { - return settings.token != ""; + return settings::token != ""; } Plugin *getPlugin(const std::string &pluginSlug) { diff --git a/src/settings.cpp b/src/settings.cpp index 3447a4ad..52a2c840 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -10,9 +10,33 @@ namespace rack { - - -json_t *Settings::toJson() { +namespace settings { + + +bool devMode = false; +bool headless = false; +std::string token; +math::Vec windowSize; +math::Vec windowPos; +float zoom = 1.0; +bool invertZoom = false; +float cableOpacity = 0.5; +float cableTension = 0.5; +bool allowCursorLock = true; +float sampleRate = 44100.0; +int threadCount = 1; +bool paramTooltip = false; +bool cpuMeter = false; +bool lockModules = false; +bool checkVersion = true; +float frameRateLimit = 70.0; +bool frameRateSync = true; +bool skipLoadOnLaunch = false; +std::string patchPath; +std::set favoriteModels; + + +json_t *toJson() { json_t *rootJ = json_object(); json_object_set_new(rootJ, "token", json_string(token.c_str())); @@ -67,7 +91,7 @@ json_t *Settings::toJson() { return rootJ; } -void Settings::fromJson(json_t *rootJ) { +void fromJson(json_t *rootJ) { json_t *tokenJ = json_object_get(rootJ, "token"); if (tokenJ) token = json_string_value(tokenJ); @@ -172,7 +196,7 @@ void Settings::fromJson(json_t *rootJ) { } } -void Settings::save(const std::string &path) { +void save(const std::string &path) { INFO("Saving settings %s", path.c_str()); json_t *rootJ = toJson(); if (rootJ) { @@ -186,7 +210,7 @@ void Settings::save(const std::string &path) { } } -void Settings::load(const std::string &path) { +void load(const std::string &path) { INFO("Loading settings %s", path.c_str()); FILE *file = std::fopen(path.c_str(), "r"); if (!file) @@ -206,7 +230,5 @@ void Settings::load(const std::string &path) { } -Settings settings; - - +} // namespace settings } // namespace rack diff --git a/src/window.cpp b/src/window.cpp index a7f57916..27b2ec95 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -215,12 +215,12 @@ Window::Window() { INFO("Window content scale: %f", contentScale); glfwSetWindowSizeLimits(win, 800, 600, GLFW_DONT_CARE, GLFW_DONT_CARE); - if (settings.windowSize.isZero()) { + if (settings::windowSize.isZero()) { glfwMaximizeWindow(win); } else { - glfwSetWindowPos(win, settings.windowPos.x, settings.windowPos.y); - glfwSetWindowSize(win, settings.windowSize.x, settings.windowSize.y); + glfwSetWindowPos(win, settings::windowPos.x, settings::windowPos.y); + glfwSetWindowSize(win, settings::windowSize.x, settings::windowSize.y); } glfwShowWindow(win); @@ -229,7 +229,7 @@ Window::Window() { glfwMakeContextCurrent(win); // Enable v-sync - glfwSwapInterval(settings.frameRateSync ? 1 : 0); + glfwSwapInterval(settings::frameRateSync ? 1 : 0); // Set window callbacks glfwSetWindowSizeCallback(win, windowSizeCallback); @@ -275,16 +275,16 @@ Window::Window() { Window::~Window() { if (glfwGetWindowAttrib(win, GLFW_MAXIMIZED)) { - settings.windowSize = math::Vec(); - settings.windowPos = math::Vec(); + settings::windowSize = math::Vec(); + settings::windowPos = math::Vec(); } else { int winWidth, winHeight; glfwGetWindowSize(win, &winWidth, &winHeight); int winX, winY; glfwGetWindowPos(win, &winX, &winY); - settings.windowSize = math::Vec(winWidth, winHeight); - settings.windowPos = math::Vec(winX, winY); + settings::windowSize = math::Vec(winWidth, winHeight); + settings::windowPos = math::Vec(winX, winY); } #if defined NANOVG_GL2 @@ -380,9 +380,9 @@ void Window::run() { // Limit frame rate double frameTimeEnd = glfwGetTime(); - if (settings.frameRateLimit > 0.0) { + if (settings::frameRateLimit > 0.0) { double frameDuration = frameTimeEnd - frameTimeStart; - double waitDuration = 1.0 / settings.frameRateLimit - frameDuration; + double waitDuration = 1.0 / settings::frameRateLimit - frameDuration; if (waitDuration > 0.0) { std::this_thread::sleep_for(std::chrono::duration(waitDuration)); } @@ -400,7 +400,7 @@ void Window::close() { } void Window::cursorLock() { - if (settings.allowCursorLock) { + if (settings::allowCursorLock) { #if defined ARCH_MAC glfwSetInputMode(win, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); #else @@ -410,7 +410,7 @@ void Window::cursorLock() { } void Window::cursorUnlock() { - if (settings.allowCursorLock) { + if (settings::allowCursorLock) { glfwSetInputMode(win, GLFW_CURSOR, GLFW_CURSOR_NORMAL); } } @@ -447,10 +447,10 @@ bool Window::isFullScreen() { } bool Window::isFrameOverdue() { - if (settings.frameRateLimit == 0.0) + if (settings::frameRateLimit == 0.0) return false; double frameDuration = glfwGetTime() - frameTimeStart; - return frameDuration > 1.0 / settings.frameRateLimit; + return frameDuration > 1.0 / settings::frameRateLimit; } std::shared_ptr Window::loadFont(const std::string &filename) {