-
Notifications
You must be signed in to change notification settings - Fork 176
feat(options): Implement game options for texture filter mode, anisotropy and MSAA selection #2482
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,8 +44,20 @@ class OptionPreferences : public UserPreferences | |
| OptionPreferences(); | ||
| virtual ~OptionPreferences() override; | ||
|
|
||
| enum AliasingMode CPP_11(: Int) | ||
| { | ||
| OFF = 0, | ||
| X2, | ||
| X4, | ||
| X8, | ||
| NUM_ALIASING_MODES | ||
| }; | ||
|
|
||
| Bool loadFromIniFile(); | ||
|
|
||
| UnsignedInt getAntiAliasing(); | ||
| UnsignedInt getTextureFilterMode(); | ||
| UnsignedInt getTextureAnisotropyLevel(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better be const. |
||
| UnsignedInt getLANIPAddress(); | ||
| UnsignedInt getOnlineIPAddress(); | ||
| void setLANIPAddress(AsciiString IP); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,9 @@ | |
| // INCLUDES /////////////////////////////////////////////////////////////////////////////////////// | ||
| #include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine | ||
|
|
||
| #include "ww3d.h" | ||
| #include "texturefilter.h" | ||
|
|
||
| #include "Common/AudioSettings.h" | ||
| #include "Common/GameAudio.h" | ||
| #include "Common/GameLOD.h" | ||
|
|
@@ -66,6 +69,71 @@ Bool OptionPreferences::loadFromIniFile() | |
| return load("Options.ini"); | ||
| } | ||
|
|
||
| UnsignedInt OptionPreferences::getAntiAliasing() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this return the enum type instead?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was avoiding adding ww3d and texturefilter headers to the globaldata header There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you move the enums out of |
||
| { | ||
| OptionPreferences::const_iterator it = find("AntiAliasing"); | ||
| if (it == end()) | ||
| return WW3D::MultiSampleModeEnum::MULTISAMPLE_MODE_NONE; | ||
|
|
||
| UnsignedInt level = atoi(it->second.str()); | ||
| if (level == WW3D::MultiSampleModeEnum::MULTISAMPLE_MODE_NONE) | ||
| level = WW3D::MultiSampleModeEnum::MULTISAMPLE_MODE_NONE; | ||
| else if (level <= WW3D::MultiSampleModeEnum::MULTISAMPLE_MODE_2X) | ||
| level = WW3D::MultiSampleModeEnum::MULTISAMPLE_MODE_2X; | ||
| else if (level <= WW3D::MultiSampleModeEnum::MULTISAMPLE_MODE_4X) | ||
| level = WW3D::MultiSampleModeEnum::MULTISAMPLE_MODE_4X; | ||
| else if (level <= WW3D::MultiSampleModeEnum::MULTISAMPLE_MODE_8X) | ||
| level = WW3D::MultiSampleModeEnum::MULTISAMPLE_MODE_8X; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is a bit odd that Value 5 would become 8. I would expect 7 becomes 4. Can be simplified and improved by doing Int level = atoi(it->second.str());
level = clamp(WW3D::MULTISAMPLE_MODE_FIRST, level, WW3D::MULTISAMPLE_MODE_LAST);
level = highestBit(level);Then add in BaseType.h or so template <typename T>
T highestBit(T v)
{
static_assert(sizeof(T) <= 8, "T must be smaller equal 8");
UnsignedInt64 i = static_cast<UnsignedInt64>(v);
i |= i >> 1;
i |= i >> 2;
i |= i >> 4;
i |= i >> 8;
i |= i >> 16;
i |= i >> 32;
return static_cast<T>(i - (i >> 1));
}This will work for as long as the values are expected to be power of 2, which I think is always the case. Same for |
||
|
|
||
| if (level > WW3D::MultiSampleModeEnum::MULTISAMPLE_MODE_8X) | ||
| level = WW3D::MultiSampleModeEnum::MULTISAMPLE_MODE_8X; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. enums are unscoped, so |
||
|
|
||
| return level; | ||
| } | ||
|
|
||
| UnsignedInt OptionPreferences::getTextureFilterMode() | ||
| { | ||
| OptionPreferences::const_iterator it = find("TextureFilter"); | ||
| if (it == end()) | ||
| return TextureFilterClass::TextureFilterMode::TEXTURE_FILTER_BILINEAR; | ||
|
|
||
| UnsignedInt filter = TextureFilterClass::TextureFilterMode::TEXTURE_FILTER_NONE; | ||
| if(stricmp(it->second.str(), "None") == 0) | ||
| filter = TextureFilterClass::TextureFilterMode::TEXTURE_FILTER_NONE; | ||
| else if(stricmp(it->second.str(), "Point") == 0) | ||
| filter = TextureFilterClass::TextureFilterMode::TEXTURE_FILTER_POINT; | ||
| else if (stricmp(it->second.str(), "Bilinear") == 0) | ||
| filter = TextureFilterClass::TextureFilterMode::TEXTURE_FILTER_BILINEAR; | ||
| else if (stricmp(it->second.str(), "Trilinear") == 0) | ||
| filter = TextureFilterClass::TextureFilterMode::TEXTURE_FILTER_TRILINEAR; | ||
| else if (stricmp(it->second.str(), "Anisotropic") == 0) | ||
| filter = TextureFilterClass::TextureFilterMode::TEXTURE_FILTER_ANISOTROPIC; | ||
|
|
||
| return filter; | ||
| } | ||
|
|
||
| UnsignedInt OptionPreferences::getTextureAnisotropyLevel() | ||
| { | ||
| OptionPreferences::const_iterator it = find("AnisotropyLevel"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this an intuitive term for players? If I am not mistaken NVIDIA and AMD drivers call this Anisotropic.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's often hidden by having the user facing texture filter mode option showing |
||
| if (it == end()) | ||
| return TextureFilterClass::AnisotropicFilterMode::TEXTURE_FILTER_ANISOTROPIC_2X; | ||
|
|
||
| UnsignedInt level = atoi(it->second.str()); | ||
| if (level <= TextureFilterClass::AnisotropicFilterMode::TEXTURE_FILTER_ANISOTROPIC_2X) | ||
| level = TextureFilterClass::AnisotropicFilterMode::TEXTURE_FILTER_ANISOTROPIC_2X; | ||
| else if (level <= TextureFilterClass::AnisotropicFilterMode::TEXTURE_FILTER_ANISOTROPIC_4X) | ||
| level = TextureFilterClass::AnisotropicFilterMode::TEXTURE_FILTER_ANISOTROPIC_4X; | ||
| else if (level <= TextureFilterClass::AnisotropicFilterMode::TEXTURE_FILTER_ANISOTROPIC_8X) | ||
| level = TextureFilterClass::AnisotropicFilterMode::TEXTURE_FILTER_ANISOTROPIC_8X; | ||
| else if (level <= TextureFilterClass::AnisotropicFilterMode::TEXTURE_FILTER_ANISOTROPIC_16X) | ||
| level = TextureFilterClass::AnisotropicFilterMode::TEXTURE_FILTER_ANISOTROPIC_16X; | ||
|
|
||
| if (level > TextureFilterClass::AnisotropicFilterMode::TEXTURE_FILTER_ANISOTROPIC_16X) | ||
| level = TextureFilterClass::AnisotropicFilterMode::TEXTURE_FILTER_ANISOTROPIC_16X; | ||
|
|
||
| return level; | ||
| } | ||
|
|
||
| Int OptionPreferences::getCampaignDifficulty() | ||
| { | ||
| OptionPreferences::const_iterator it = find("CampaignDifficulty"); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,9 @@ | |
| // INCLUDES /////////////////////////////////////////////////////////////////////////////////////// | ||
| #include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine | ||
|
|
||
| #include "ww3d.h" | ||
| #include "texturefilter.h" | ||
|
|
||
| #include "Common/GlobalData.h" | ||
|
|
||
| #define DEFINE_TERRAIN_LOD_NAMES | ||
|
|
@@ -930,7 +933,9 @@ GlobalData::GlobalData() | |
|
|
||
| m_standardPublicBones.clear(); | ||
|
|
||
| m_antiAliasBoxValue = 0; | ||
| m_antiAliasLevel = WW3D::MultiSampleModeEnum::MULTISAMPLE_MODE_NONE; | ||
| m_textureFilteringMode = TextureFilterClass::TextureFilterMode::TEXTURE_FILTER_BILINEAR; | ||
| m_textureAnisotropyLevel = TextureFilterClass::AnisotropicFilterMode::TEXTURE_FILTER_ANISOTROPIC_2X; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do these need to be in GlobalData or is there a better place for them?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's not really a nice place to centralise them apart from global data, Texture Class is mostly handled by static functions and MSAA is handled inside dx8wrapper through ww3d. |
||
|
|
||
| // m_languageFilterPref = false; | ||
| m_languageFilterPref = true; | ||
|
|
@@ -1229,6 +1234,10 @@ void GlobalData::parseGameDataDefinition( INI* ini ) | |
| TheWritableGlobalData->m_playerInfoListFontSize = optionPref.getPlayerInfoListFontSize(); | ||
| TheWritableGlobalData->m_showMoneyPerMinute = optionPref.getShowMoneyPerMinute(); | ||
|
|
||
| TheWritableGlobalData->m_antiAliasLevel = optionPref.getAntiAliasing(); | ||
| TheWritableGlobalData->m_textureFilteringMode = optionPref.getTextureFilterMode(); | ||
| TheWritableGlobalData->m_textureAnisotropyLevel = optionPref.getTextureAnisotropyLevel(); | ||
|
|
||
| Int val=optionPref.getGammaValue(); | ||
| //generate a value between 0.6 and 2.0. | ||
| if (val < 50) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,6 +75,7 @@ | |
| #include "GameClient/MessageBox.h" | ||
|
|
||
| #include "ww3d.h" | ||
| #include "texturefilter.h" | ||
|
|
||
| // This is for non-RC builds only!!! | ||
| #define VERBOSE_VERSION L"Release" | ||
|
|
@@ -552,14 +553,73 @@ static void saveOptions() | |
| //------------------------------------------------------------------------------------------------- | ||
| // antialiasing | ||
| GadgetComboBoxGetSelectedPos(comboBoxAntiAliasing, &index); | ||
| if( index >= 0 && TheGlobalData->m_antiAliasBoxValue != index ) | ||
| if( index >= 0 && TheGlobalData ) | ||
| { | ||
| TheWritableGlobalData->m_antiAliasBoxValue = index; | ||
| Int mode = WW3D::MultiSampleModeEnum::MULTISAMPLE_MODE_NONE; | ||
|
|
||
| // TheSuperHackers @info We are converting comboBox entry position to human readable value | ||
| switch (index) { | ||
| default: | ||
| case OptionPreferences::AliasingMode::OFF: | ||
| mode = WW3D::MultiSampleModeEnum::MULTISAMPLE_MODE_NONE; | ||
| break; | ||
| case OptionPreferences::AliasingMode::X2: | ||
| mode = WW3D::MultiSampleModeEnum::MULTISAMPLE_MODE_2X; | ||
| break; | ||
| case OptionPreferences::AliasingMode::X4: | ||
| mode = WW3D::MultiSampleModeEnum::MULTISAMPLE_MODE_4X; | ||
| break; | ||
| case OptionPreferences::AliasingMode::X8: | ||
| mode = WW3D::MultiSampleModeEnum::MULTISAMPLE_MODE_8X; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can also be simplified by using bit shift mode = (index > 0) ? 1 << index : 0; |
||
| break; | ||
| } | ||
|
|
||
| TheWritableGlobalData->m_antiAliasLevel = mode; | ||
| AsciiString prefString; | ||
| prefString.format("%d", index); | ||
| prefString.format("%d", mode); | ||
| (*pref)["AntiAliasing"] = prefString; | ||
| } | ||
|
|
||
| //------------------------------------------------------------------------------------------------- | ||
| // texture filter mode | ||
| val = pref->getTextureFilterMode(); | ||
| if (val >= 0 && TheGlobalData) | ||
| { | ||
| TheWritableGlobalData->m_textureFilteringMode = val; | ||
|
|
||
| AsciiString prefString; | ||
|
|
||
| switch (val) { | ||
| case TextureFilterClass::TextureFilterMode::TEXTURE_FILTER_NONE: | ||
| prefString = "None"; | ||
| break; | ||
| case TextureFilterClass::TextureFilterMode::TEXTURE_FILTER_POINT: | ||
| prefString = "Point"; | ||
| break; | ||
| case TextureFilterClass::TextureFilterMode::TEXTURE_FILTER_BILINEAR: | ||
| prefString = "Bilinear"; | ||
| break; | ||
| case TextureFilterClass::TextureFilterMode::TEXTURE_FILTER_TRILINEAR: | ||
| prefString = "Trilinear"; | ||
| break; | ||
| case TextureFilterClass::TextureFilterMode::TEXTURE_FILTER_ANISOTROPIC: | ||
| prefString = "Anisotropic"; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest provide an enum to string array or function near the enum declaration instead so that the string mapping could be reused elsewhere too and is closer to the enum declaration, which reduces maintenance mistakes. |
||
| break; | ||
| } | ||
|
|
||
| (*pref)["TextureFilter"] = prefString; | ||
| } | ||
|
|
||
| //------------------------------------------------------------------------------------------------- | ||
| // anisotropy level | ||
| val = pref->getTextureAnisotropyLevel(); | ||
| if (val >= 0 && TheGlobalData) | ||
| { | ||
| TheWritableGlobalData->m_textureAnisotropyLevel = val; | ||
| AsciiString prefString; | ||
| prefString.format("%d", val); | ||
| (*pref)["AnisotropyLevel"] = prefString; | ||
| } | ||
|
|
||
| //------------------------------------------------------------------------------------------------- | ||
| // mouse mode | ||
|
|
@@ -1024,14 +1084,6 @@ void OptionsMenuInit( WindowLayout *layout, void *userData ) | |
|
|
||
| Color color = GameMakeColor(255,255,255,255); | ||
|
|
||
| enum AliasingMode CPP_11(: Int) | ||
| { | ||
| OFF = 0, | ||
| LOW, | ||
| HIGH, | ||
| NUM_ALIASING_MODES | ||
| }; | ||
|
|
||
| initLabelVersion(); | ||
|
|
||
| // Choose an IP address, then initialize the IP combo box | ||
|
|
@@ -1135,18 +1187,30 @@ void OptionsMenuInit( WindowLayout *layout, void *userData ) | |
| GadgetComboBoxReset(comboBoxAntiAliasing); | ||
| AsciiString temp; | ||
| Int i=0; | ||
| for (; i < NUM_ALIASING_MODES; ++i) | ||
| for (; i < OptionPreferences::AliasingMode::NUM_ALIASING_MODES; ++i) | ||
| { | ||
| temp.format("GUI:AntiAliasing%d", i); | ||
| str = TheGameText->fetch( temp ); | ||
| index = GadgetComboBoxAddEntry(comboBoxAntiAliasing, str, color); | ||
| } | ||
| Int val = atoi(selectedAliasingMode.str()); | ||
| if( val < 0 || val > NUM_ALIASING_MODES ) | ||
| Int pos = 0; | ||
|
|
||
| // TheSuperHackers @info We are converting from human readable value to comboBox entry position | ||
| if (val <= WW3D::MultiSampleModeEnum::MULTISAMPLE_MODE_NONE) | ||
| pos = OptionPreferences::AliasingMode::OFF; | ||
| else if (val <= WW3D::MultiSampleModeEnum::MULTISAMPLE_MODE_2X) | ||
| pos = OptionPreferences::AliasingMode::X2; | ||
| else if (val <= WW3D::MultiSampleModeEnum::MULTISAMPLE_MODE_4X) | ||
| pos = OptionPreferences::AliasingMode::X4; | ||
| else if (val <= WW3D::MultiSampleModeEnum::MULTISAMPLE_MODE_8X) | ||
| pos = OptionPreferences::AliasingMode::X8; | ||
|
|
||
| if( val < 0 || val > WW3D::MultiSampleModeEnum::MULTISAMPLE_MODE_8X) | ||
| { | ||
| TheWritableGlobalData->m_antiAliasBoxValue = val = 0; | ||
| TheWritableGlobalData->m_antiAliasLevel = pos = 0; | ||
| } | ||
| GadgetComboBoxSetSelectedPos(comboBoxAntiAliasing, val); | ||
| GadgetComboBoxSetSelectedPos(comboBoxAntiAliasing, pos); | ||
|
|
||
| // get resolution from saved preferences file | ||
| AsciiString selectedResolution = (*pref) ["Resolution"]; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please put more into the name to avoid shadowing or macro conflicts.