Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Features/LinearLighting.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "LinearLighting.h"

#include "State.h"

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(
LinearLighting::Settings,
enableLinearLighting,
Expand Down Expand Up @@ -105,7 +107,7 @@ void LinearLighting::SetupResources()

void LinearLighting::Prepass()
{
bool isMainLoadingMenu = globals::game::ui && (globals::game::ui->IsMenuOpen(RE::MainMenu::MENU_NAME) || globals::game::ui->IsMenuOpen(RE::LoadingMenu::MENU_NAME));
bool isMainLoadingMenu = globals::state->isMainMenuOpen || globals::state->isLoadingMenuOpen;
dirLightMult = 1.0f;
if (!settings.enableLinearLighting || isMainLoadingMenu)
return;
Expand Down Expand Up @@ -148,7 +150,7 @@ LinearLighting::PerFrameData LinearLighting::GetCommonBufferData()
data.enableLinearLighting = false;
return data;
}
bool isMainLoadingMenu = globals::game::ui && (globals::game::ui->IsMenuOpen(RE::MainMenu::MENU_NAME) || globals::game::ui->IsMenuOpen(RE::LoadingMenu::MENU_NAME));
bool isMainLoadingMenu = globals::state->isMainMenuOpen || globals::state->isLoadingMenuOpen;
auto data = PerFrameData{};
data.enableLinearLighting = settings.enableLinearLighting && !isMainLoadingMenu;
data.enableGammaCorrection = settings.enableGammaCorrection;
Expand Down
10 changes: 4 additions & 6 deletions src/Features/Skylighting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,8 @@ Skylighting::SkylightingCB Skylighting::GetCommonBufferData(bool a_inWorld)
if (!a_inWorld)
return Skylighting::SkylightingCB{};

if (auto ui = globals::game::ui)
if (ui->IsMenuOpen(RE::MapMenu::MENU_NAME))
return Skylighting::SkylightingCB{};
if (globals::state->isMapMenuOpen)
return Skylighting::SkylightingCB{};

static float3 prevCellID = { 0, 0, 0 };

Expand Down Expand Up @@ -206,9 +205,8 @@ Skylighting::SkylightingCB Skylighting::GetCommonBufferData(bool a_inWorld)

void Skylighting::Prepass()
{
if (auto ui = globals::game::ui)
if (ui->IsMenuOpen(RE::MapMenu::MENU_NAME))
return;
if (globals::state->isMapMenuOpen)
return;

bool interior = true;

Expand Down
5 changes: 3 additions & 2 deletions src/Features/VR/Input.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "Features/VR.h"
#include "Menu.h"
#include "State.h"
#include "Utils/PerfUtils.h"
#include "Utils/VRUtils.h"

Expand Down Expand Up @@ -28,8 +29,8 @@ void VR::UpdateOverlayMenuStateFromInput()
return;
}

bool uiMenusOpen = globals::game::ui &&
(globals::game::ui->IsMenuOpen(RE::MainMenu::MENU_NAME) || globals::game::ui->IsMenuOpen(RE::TweenMenu::MENU_NAME));
bool uiMenusOpen = globals::state->isMainMenuOpen ||
(globals::game::ui && globals::game::ui->IsMenuOpen(RE::TweenMenu::MENU_NAME));

bool inValidMenuState = uiMenusOpen || (globals::game::ui && (isEnabled || overlayEnabled));

Expand Down
2 changes: 1 addition & 1 deletion src/Features/VR/SettingsUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void VR::DrawOverlay()
static LARGE_INTEGER overlayShowStart = { 0 };
static LARGE_INTEGER freq = { 0 };

bool shouldShow = settings.kAutoHideSeconds > 0 && globals::game::ui && globals::game::ui->IsMenuOpen(RE::MainMenu::MENU_NAME) && globals::menu && !globals::menu->IsEnabled;
bool shouldShow = settings.kAutoHideSeconds > 0 && globals::state->isMainMenuOpen && globals::menu && !globals::menu->IsEnabled;

if (!shouldShow) {
overlayShowStart.QuadPart = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/Menu/BackgroundBlur.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "../Features/Upscaling.h"
#include "../Globals.h"
#include "../ShaderCache.h"
#include "../State.h"
#include "../Util.h"

#include <algorithm>
Expand Down Expand Up @@ -505,8 +506,7 @@ namespace BackgroundBlur

// Back buffer is black on main/loading menu during shader compilation without upscaling
if (!useUpscalingBackbuffer && !(upscaling.loaded && upscaling.IsUpscalingActive())) {
auto ui = globals::game::ui;
bool isMainOrLoading = ui && (ui->IsMenuOpen(RE::MainMenu::MENU_NAME) || ui->IsMenuOpen(RE::LoadingMenu::MENU_NAME));
bool isMainOrLoading = globals::state->isMainMenuOpen || globals::state->isLoadingMenuOpen;
auto shaderCache = globals::shaderCache;
if (isMainOrLoading && shaderCache && shaderCache->IsCompiling()) {
return;
Expand Down
4 changes: 2 additions & 2 deletions src/SceneSettingsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "Feature.h"
#include "Globals.h"
#include "State.h"
#include "Utils/FileSystem.h"
#include "Utils/Game.h"

Expand Down Expand Up @@ -303,8 +304,7 @@ void SceneSettingsManager::Update()
{
// Revert interior overrides on main/loading menu (same check as LinearLighting)
if (isCurrentlyApplied) {
bool isMainOrLoading = globals::game::ui &&
(globals::game::ui->IsMenuOpen(RE::MainMenu::MENU_NAME) || globals::game::ui->IsMenuOpen(RE::LoadingMenu::MENU_NAME));
bool isMainOrLoading = globals::state->isMainMenuOpen || globals::state->isLoadingMenuOpen;
if (isMainOrLoading) {
RevertToExteriorSettings();
isCurrentlyApplied = false;
Expand Down
18 changes: 14 additions & 4 deletions src/State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,19 @@ void State::Reset()
Feature::ForEachLoadedFeature("Reset", [](Feature* feature) { feature->Reset(); });
if (!globals::game::ui->GameIsPaused())
timer += RE::GetSecondsSinceLastFrame();

// Cache menu open states once per frame to avoid repeated IsMenuOpen calls
// (each call constructs a BSFixedString, which is expensive at scale).
if (auto ui = globals::game::ui) {
isMainMenuOpen = ui->IsMenuOpen(RE::MainMenu::MENU_NAME);
isLoadingMenuOpen = ui->IsMenuOpen(RE::LoadingMenu::MENU_NAME);
isMapMenuOpen = ui->IsMenuOpen(RE::MapMenu::MENU_NAME);
} else {
isMainMenuOpen = false;
isLoadingMenuOpen = false;
isMapMenuOpen = false;
}
Comment thread
doodlum marked this conversation as resolved.

lastModifiedPixelDescriptor = 0;
lastModifiedVertexDescriptor = 0;
lastPixelDescriptor = 0;
Expand Down Expand Up @@ -831,10 +844,7 @@ void State::UpdateSharedData([[maybe_unused]] bool a_inWorld, [[maybe_unused]] b
else
data.HideSky = false;

if (globals::game::ui)
data.InMapMenu = globals::game::ui->IsMenuOpen(RE::MapMenu::MENU_NAME);
else
data.InMapMenu = false;
data.InMapMenu = isMapMenuOpen;

auto& upscaling = globals::features::upscaling;

Expand Down
6 changes: 6 additions & 0 deletions src/State.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ class State
bool inWorld = false;
bool activeReflections = false;

// Cached menu open states, updated once per frame in Reset().
// Avoids repeated IsMenuOpen calls (each constructs a BSFixedString).
bool isMainMenuOpen = false;
bool isLoadingMenuOpen = false;
bool isMapMenuOpen = false;

void UpdateSharedData(bool a_inWorld, bool a_prepass);

struct PermutationCB
Expand Down
Loading