-
Notifications
You must be signed in to change notification settings - Fork 137
feat: add feature constraints #1804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| #include "FeatureConstraints.h" | ||
| #include "Feature.h" | ||
|
|
||
| #include <unordered_set> | ||
|
|
||
| namespace FeatureConstraints | ||
| { | ||
| ConstraintResult GetConstraints(const SettingId& setting) | ||
| { | ||
| ConstraintResult result; | ||
|
|
||
| for (auto* feature : Feature::GetFeatureList()) { | ||
| if (!feature->loaded) | ||
| continue; | ||
|
|
||
| auto constraints = feature->GetActiveConstraints(); | ||
| for (const auto& constraint : constraints) { | ||
| if (constraint.targetSetting == setting) { | ||
| if (!result.isConstrained) { | ||
| result.isConstrained = true; | ||
| result.forcedValue = constraint.forcedValue; | ||
| } else if (constraint.forcedValue != result.forcedValue) { | ||
| // Two features disagree on the forced value; first one wins. | ||
| // Log once so it surfaces during development / testing. | ||
| logger::warn("[FeatureConstraints] Conflict on {}.{}: {} wants {}, but {} already forced {}", | ||
| setting.featureShortName, setting.settingPath, | ||
| feature->GetName(), FormatConstraintValue(constraint.forcedValue), | ||
| result.sources[0].featureName, FormatConstraintValue(result.forcedValue)); | ||
| } | ||
| result.sources.push_back({ feature->GetName(), | ||
| feature->GetShortName(), | ||
| constraint.reason, | ||
| constraint.recommendDisableAtBoot }); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| std::vector<std::pair<SettingId, ConstraintResult>> GetAllActiveConstraints() | ||
| { | ||
| std::vector<std::pair<SettingId, ConstraintResult>> allConstraints; | ||
| std::unordered_set<std::string> processedKeys; // featureShortName|settingPath for O(1) lookup | ||
|
|
||
| for (auto* feature : Feature::GetFeatureList()) { | ||
| if (!feature->loaded) | ||
| continue; | ||
|
|
||
| auto constraints = feature->GetActiveConstraints(); | ||
| for (const auto& constraint : constraints) { | ||
| std::string key = constraint.targetSetting.featureShortName + "|" + constraint.targetSetting.settingPath; | ||
| if (processedKeys.insert(key).second) { | ||
| auto result = GetConstraints(constraint.targetSetting); | ||
| if (result.isConstrained) { | ||
| allConstraints.push_back({ constraint.targetSetting, result }); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return allConstraints; | ||
| } | ||
|
|
||
| std::string BuildConstraintTooltip(const ConstraintResult& result) | ||
| { | ||
| if (!result.isConstrained || result.sources.empty()) | ||
| return ""; | ||
|
|
||
| std::string tooltip = "This setting is constrained by:\n"; | ||
| for (const auto& src : result.sources) { | ||
| tooltip += "\n- " + src.featureName + ":\n " + src.reason; | ||
| if (src.recommendDisableAtBoot) { | ||
| tooltip += "\n (Consider disabling this feature at boot for best compatibility)"; | ||
| } | ||
| } | ||
|
|
||
| tooltip += "\n\nForced value: " + FormatConstraintValue(result.forcedValue); | ||
|
|
||
| return tooltip; | ||
| } | ||
|
|
||
| std::string FormatConstraintValue(const std::variant<bool, int, float>& value) | ||
| { | ||
| if (std::holds_alternative<bool>(value)) { | ||
| return std::get<bool>(value) ? "Enabled" : "Disabled"; | ||
| } else if (std::holds_alternative<int>(value)) { | ||
| return std::to_string(std::get<int>(value)); | ||
| } else if (std::holds_alternative<float>(value)) { | ||
| char buf[32]; | ||
| snprintf(buf, sizeof(buf), "%.2f", std::get<float>(value)); | ||
| return buf; | ||
| } | ||
| return "Unknown"; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| #pragma once | ||
|
|
||
| #include <string> | ||
| #include <variant> | ||
| #include <vector> | ||
|
|
||
| namespace FeatureConstraints | ||
| { | ||
| /** | ||
| * @brief Identifies a specific setting that can be constrained | ||
| */ | ||
| struct SettingId | ||
| { | ||
| std::string featureShortName; // e.g., "VR" | ||
| std::string settingPath; // e.g., "EnableDepthBufferCullingExterior" | ||
|
|
||
| bool operator==(const SettingId& other) const | ||
| { | ||
| return featureShortName == other.featureShortName && settingPath == other.settingPath; | ||
| } | ||
| }; | ||
|
|
||
| /** | ||
| * @brief A constraint that one feature places on another feature's setting | ||
| */ | ||
| struct Constraint | ||
| { | ||
| SettingId targetSetting; // Which setting is affected | ||
| std::variant<bool, int, float> forcedValue; // Value to force | ||
| std::string reason; // UI tooltip explanation | ||
| bool recommendDisableAtBoot = false; // Suggest disabling the source feature entirely | ||
| }; | ||
|
|
||
| /** | ||
| * @brief Result of checking constraints on a setting | ||
| */ | ||
| struct ConstraintResult | ||
| { | ||
| bool isConstrained = false; | ||
| std::variant<bool, int, float> forcedValue; | ||
|
|
||
| struct Source | ||
| { | ||
| std::string featureName; // Display name (e.g. "Terrain Blending") | ||
| std::string featureShortName; // Menu navigation key (e.g. "TerrainBlending") | ||
| std::string reason; | ||
| bool recommendDisableAtBoot; | ||
| }; | ||
| std::vector<Source> sources; | ||
|
|
||
| /** | ||
| * @brief Check if any source recommends disabling at boot | ||
| */ | ||
| bool AnyRecommendDisableAtBoot() const | ||
| { | ||
| for (const auto& src : sources) { | ||
| if (src.recommendDisableAtBoot) | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| }; | ||
|
|
||
| /** | ||
| * @brief Query if a setting is constrained by any active feature | ||
| * @param setting The setting to check | ||
| * @return ConstraintResult with all sources causing the constraint | ||
| */ | ||
| ConstraintResult GetConstraints(const SettingId& setting); | ||
|
|
||
| /** | ||
| * @brief Get all active constraints across all features | ||
| * @return Vector of setting IDs and their constraint results | ||
| */ | ||
| std::vector<std::pair<SettingId, ConstraintResult>> GetAllActiveConstraints(); | ||
|
|
||
| /** | ||
| * @brief Build a formatted tooltip string for a constrained setting | ||
| * @param result The constraint result to format | ||
| * @return Formatted string suitable for ImGui tooltip | ||
| */ | ||
| std::string BuildConstraintTooltip(const ConstraintResult& result); | ||
|
|
||
| /** | ||
| * @brief Format a constraint value as a string for display | ||
| * @param value The variant value to format | ||
| * @return String representation of the value | ||
| */ | ||
| std::string FormatConstraintValue(const std::variant<bool, int, float>& value); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.