mirror of
https://github.com/izzy2lost/2ship2harkinian-Android.git
synced 2026-06-19 01:20:08 -07:00
Eliminate Graphics Menu Lag (#733)
* Moved non-dynamic window backend data to external variables and update function called on init and combobox change. * clang
This commit is contained in:
@@ -56,6 +56,25 @@ static const std::unordered_map<int32_t, const char*> alwaysWinDoggyraceOptions
|
||||
};
|
||||
|
||||
namespace BenGui {
|
||||
std::shared_ptr<std::vector<Ship::WindowBackend>> availableWindowBackends;
|
||||
std::unordered_map<Ship::WindowBackend, const char*> availableWindowBackendsMap;
|
||||
Ship::WindowBackend configWindowBackend;
|
||||
|
||||
void UpdateWindowBackendObjects() {
|
||||
Ship::WindowBackend runningWindowBackend = Ship::Context::GetInstance()->GetWindow()->GetWindowBackend();
|
||||
Ship::WindowBackend configWindowBackend;
|
||||
int32_t configWindowBackendId = Ship::Context::GetInstance()->GetConfig()->GetInt("Window.Backend.Id", -1);
|
||||
if (configWindowBackendId != -1 && configWindowBackendId < static_cast<int>(Ship::WindowBackend::BACKEND_COUNT)) {
|
||||
configWindowBackend = static_cast<Ship::WindowBackend>(configWindowBackendId);
|
||||
} else {
|
||||
configWindowBackend = runningWindowBackend;
|
||||
}
|
||||
|
||||
availableWindowBackends = Ship::Context::GetInstance()->GetWindow()->GetAvailableWindowBackends();
|
||||
for (auto& backend : *availableWindowBackends) {
|
||||
availableWindowBackendsMap[backend] = windowBackendsMap[backend];
|
||||
}
|
||||
}
|
||||
|
||||
void DrawMenuBarIcon() {
|
||||
static bool gameIconLoaded = false;
|
||||
@@ -244,32 +263,17 @@ void DrawSettingsMenu() {
|
||||
// UIWidgets::PaddedSeparator(true, true, 3.0f, 3.0f);
|
||||
// #endregion */
|
||||
|
||||
Ship::WindowBackend runningWindowBackend = Ship::Context::GetInstance()->GetWindow()->GetWindowBackend();
|
||||
Ship::WindowBackend configWindowBackend;
|
||||
int32_t configWindowBackendId = Ship::Context::GetInstance()->GetConfig()->GetInt("Window.Backend.Id", -1);
|
||||
if (configWindowBackendId != -1 &&
|
||||
configWindowBackendId < static_cast<int>(Ship::WindowBackend::BACKEND_COUNT)) {
|
||||
configWindowBackend = static_cast<Ship::WindowBackend>(configWindowBackendId);
|
||||
} else {
|
||||
configWindowBackend = runningWindowBackend;
|
||||
}
|
||||
|
||||
auto availableWindowBackends = Ship::Context::GetInstance()->GetWindow()->GetAvailableWindowBackends();
|
||||
std::unordered_map<Ship::WindowBackend, const char*> availableWindowBackendsMap;
|
||||
for (auto& backend : *availableWindowBackends) {
|
||||
availableWindowBackendsMap[backend] = windowBackendsMap[backend];
|
||||
}
|
||||
|
||||
if (UIWidgets::Combobox(
|
||||
"Renderer API (Needs reload)", &configWindowBackend, availableWindowBackendsMap,
|
||||
{ .tooltip = "Sets the renderer API used by the game. Requires a relaunch to take effect.",
|
||||
.disabled = Ship::Context::GetInstance()->GetWindow()->GetAvailableWindowBackends()->size() <= 1,
|
||||
.disabled = availableWindowBackends->size() <= 1,
|
||||
.disabledTooltip = "Only one renderer API is available on this platform." })) {
|
||||
Ship::Context::GetInstance()->GetConfig()->SetInt("Window.Backend.Id",
|
||||
static_cast<int32_t>(configWindowBackend));
|
||||
Ship::Context::GetInstance()->GetConfig()->SetString("Window.Backend.Name",
|
||||
windowBackendsMap.at(configWindowBackend));
|
||||
Ship::Context::GetInstance()->GetConfig()->Save();
|
||||
UpdateWindowBackendObjects();
|
||||
}
|
||||
|
||||
if (Ship::Context::GetInstance()->GetWindow()->CanDisableVerticalSync()) {
|
||||
@@ -738,6 +742,10 @@ void DrawDeveloperToolsMenu() {
|
||||
}
|
||||
}
|
||||
|
||||
void BenMenuBar::InitElement() {
|
||||
UpdateWindowBackendObjects();
|
||||
}
|
||||
|
||||
void BenMenuBar::DrawElement() {
|
||||
if (ImGui::BeginMenuBar()) {
|
||||
DrawMenuBarIcon();
|
||||
|
||||
@@ -15,7 +15,7 @@ class BenMenuBar : public Ship::GuiMenuBar {
|
||||
|
||||
protected:
|
||||
void DrawElement() override;
|
||||
void InitElement() override{};
|
||||
void InitElement() override;
|
||||
void UpdateElement() override{};
|
||||
};
|
||||
} // namespace BenGui
|
||||
|
||||
Reference in New Issue
Block a user