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
15 changes: 15 additions & 0 deletions UnleashedRecomp/gpu/video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1736,6 +1736,21 @@ bool Video::CreateHostDevice(const char *sdlVideoDriver)
ApplyLowEndDefaults();
}

const RenderSampleCounts colourSampleCount = g_device->getSampleCountsSupported(RenderFormat::R16G16B16A16_FLOAT);
const RenderSampleCounts depthSampleCount = g_device->getSampleCountsSupported(RenderFormat::D32_FLOAT);
const RenderSampleCounts commonSampleCount = colourSampleCount & depthSampleCount;

// Disable specific MSAA levels if they are not supported.
if ((commonSampleCount & RenderSampleCount::COUNT_2) == 0)
Config::AntiAliasing.InaccessibleValues.emplace(EAntiAliasing::MSAA2x);
if ((commonSampleCount & RenderSampleCount::COUNT_4) == 0)
Config::AntiAliasing.InaccessibleValues.emplace(EAntiAliasing::MSAA4x);
if ((commonSampleCount & RenderSampleCount::COUNT_8) == 0)
Config::AntiAliasing.InaccessibleValues.emplace(EAntiAliasing::MSAA8x);

// Set Anti-Aliasing to nearest supported level.
Config::AntiAliasing.SnapToNearestAccessibleValue(false);

g_queue = g_device->createCommandQueue(RenderCommandListType::DIRECT);

for (auto& commandList : g_commandLists)
Expand Down
3 changes: 2 additions & 1 deletion UnleashedRecomp/ui/options_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,7 @@ static void DrawConfigOption(int32_t rowIndex, float yOffset, ConfigDef<T>* conf
}

config->Value = it->first;
config->SnapToNearestAccessibleValue(rightTapped);

if (increment || decrement)
Game_PlaySound("sys_actstg_pausecursor");
Expand Down Expand Up @@ -1271,7 +1272,7 @@ static void DrawConfigOptions()
DrawConfigOption(rowCount++, yOffset, &Config::VSync, true);
DrawConfigOption(rowCount++, yOffset, &Config::FPS, true, nullptr, FPS_MIN, 120, FPS_MAX);
DrawConfigOption(rowCount++, yOffset, &Config::Brightness, true);
DrawConfigOption(rowCount++, yOffset, &Config::AntiAliasing, true);
DrawConfigOption(rowCount++, yOffset, &Config::AntiAliasing, Config::AntiAliasing.InaccessibleValues.size() != 3, &Localise("Options_Desc_NotAvailableHardware"));
DrawConfigOption(rowCount++, yOffset, &Config::TransparencyAntiAliasing, Config::AntiAliasing != EAntiAliasing::None, &Localise("Options_Desc_NotAvailableMSAA"));
DrawConfigOption(rowCount++, yOffset, &Config::ShadowResolution, true);
DrawConfigOption(rowCount++, yOffset, &Config::GITextureFiltering, true);
Expand Down
48 changes: 48 additions & 0 deletions UnleashedRecomp/user/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,9 @@ template<typename T, bool isHidden>
void ConfigDef<T, isHidden>::MakeDefault()
{
Value = DefaultValue;

if constexpr (std::is_enum_v<T>)
SnapToNearestAccessibleValue(false);
}

template<typename T, bool isHidden>
Expand Down Expand Up @@ -696,6 +699,51 @@ void ConfigDef<T, isHidden>::GetLocaleStrings(std::vector<std::string_view>& loc
}
}

template<typename T, bool isHidden>
void ConfigDef<T, isHidden>::SnapToNearestAccessibleValue(bool searchUp)
{
if constexpr (std::is_enum_v<T>)
{
if (EnumTemplateReverse.empty() || InaccessibleValues.empty())
return;

if (EnumTemplateReverse.size() == InaccessibleValues.size())
{
assert(false && "All enum values are marked inaccessible and the nearest accessible value cannot be determined.");
return;
}

auto it = EnumTemplateReverse.find(Value);

if (it == EnumTemplateReverse.end())
{
assert(false && "Enum value does not exist in the template.");
return;
}

// Skip the enum value if it's marked as inaccessible.
while (InaccessibleValues.find(it->first) != InaccessibleValues.end())
{
if (searchUp)
{
++it;

if (it == EnumTemplateReverse.end())
it = EnumTemplateReverse.begin();
}
else
{
if (it == EnumTemplateReverse.begin())
it = EnumTemplateReverse.end();

--it;
}
}

Value = it->first;
}
}

std::filesystem::path Config::GetConfigPath()
{
return GetUserPath() / "config.toml";
Expand Down
11 changes: 4 additions & 7 deletions UnleashedRecomp/user/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class IConfigDef
virtual std::string GetDefinition(bool withSection = false) const = 0;
virtual std::string ToString(bool strWithQuotes = true) const = 0;
virtual void GetLocaleStrings(std::vector<std::string_view>& localeStrings) const = 0;
virtual void SnapToNearestAccessibleValue(bool searchUp) = 0;
};

#define CONFIG_LOCALE std::unordered_map<ELanguage, std::tuple<std::string, std::string>>
Expand Down Expand Up @@ -158,7 +159,8 @@ class ConfigDef final : public IConfigDef
CONFIG_LOCALE* Locale{};
T DefaultValue{};
T Value{ DefaultValue };
std::unordered_map<std::string, T>* EnumTemplate;
std::set<T> InaccessibleValues{};
std::unordered_map<std::string, T>* EnumTemplate{};
std::map<T, std::string> EnumTemplateReverse{};
CONFIG_ENUM_LOCALE(T)* EnumLocale{};
std::function<void(ConfigDef<T, isHidden>*)> Callback;
Expand All @@ -183,25 +185,20 @@ class ConfigDef final : public IConfigDef
~ConfigDef();

bool IsHidden() override;

void ReadValue(toml::v3::ex::parse_result& toml) override;
void MakeDefault() override;

std::string_view GetSection() const override;
std::string_view GetName() const override;
std::string GetNameLocalised(ELanguage language) const override;
std::string GetDescription(ELanguage language) const override;

bool IsDefaultValue() const override;
const void* GetValue() const override;

std::string GetValueLocalised(ELanguage language) const override;
std::string GetValueDescription(ELanguage language) const override;

std::string GetDefinition(bool withSection = false) const override;
std::string ToString(bool strWithQuotes = true) const override;

void GetLocaleStrings(std::vector<std::string_view>& localeStrings) const override;
void SnapToNearestAccessibleValue(bool searchUp) override;

operator T() const
{
Expand Down