MultiplayerSampleUserSettings.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzCore/EBus/EBus.h>
  10. #include <AzCore/IO/Path/Path.h>
  11. #include <Atom/Bootstrap/BootstrapNotificationBus.h>
  12. namespace AZ
  13. {
  14. class SettingsRegistryInterface;
  15. }
  16. namespace MultiplayerSample
  17. {
  18. enum VolumeChannel : uint8_t
  19. {
  20. MasterVolume,
  21. MusicVolume,
  22. SfxVolume,
  23. Max
  24. };
  25. enum class SpecularReflections : uint8_t
  26. {
  27. None,
  28. ScreenSpace,
  29. ScreenSpaceAndRaytracing
  30. };
  31. enum class Msaa : uint8_t
  32. {
  33. X1,
  34. X2,
  35. X4
  36. };
  37. // This provides a way to get/set every user setting that MultiplayerSample supports, and to save the user settings file.
  38. // Getting the values pulls them out of the saved user settings data, and setting the values both sets them in the user
  39. // settings and communicates the change to the appropriate part of the game engine to make the change take effect.
  40. class MultiplayerSampleUserSettingsRequests
  41. : public AZ::EBusTraits
  42. {
  43. public:
  44. static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
  45. virtual ~MultiplayerSampleUserSettingsRequests() = default;
  46. // Load the user settings and refresh the game engine based on the settings. They automatically get loaded and applied
  47. // on launcher startup, but this might need to be called to refresh the settings after connecting to the server and loading
  48. // the level in case any engine systems get reset by server cvars and level data.
  49. virtual void Load() = 0;
  50. // Save the user settings file out to disk.
  51. virtual void Save() = 0;
  52. // Change the default graphics API between dx12/vulkan/metal/null on the next restart of the game.
  53. virtual AZStd::string GetGraphicsApi() = 0;
  54. virtual void SetGraphicsApi(const AZStd::string& apiName) = 0;
  55. // Change the texture quality. 0 = highest quality (highest mipmap), N = lowest quality (lowest mipmap).
  56. // There's no well-defined value for lowest quality so we'll just arbitrarily cap it at 6 (64x64 if mip 0 is 4096x4096).
  57. // Anything lower doesn't really provide any benefit.
  58. virtual int16_t GetTextureQuality() = 0;
  59. virtual void SetTextureQuality(int16_t textureQuality) = 0;
  60. // Change between fullscreen and windowed.
  61. virtual bool GetFullscreen() = 0;
  62. virtual void SetFullscreen(bool fullscreen) = 0;
  63. // Change the rendering resolution (width, height)
  64. virtual AZStd::pair<uint32_t, uint32_t> GetResolution() = 0;
  65. virtual void SetResolution(AZStd::pair<uint32_t, uint32_t> resolution) = 0;
  66. // Change the type of screen space reflections
  67. virtual SpecularReflections GetReflectionSetting() = 0;
  68. virtual void SetReflectionSetting(SpecularReflections reflectionType) = 0;
  69. // Change the MSAA setting
  70. virtual Msaa GetMsaa() = 0;
  71. virtual void SetMsaa(Msaa msaa) = 0;
  72. // This is a workaround. The MSAA setting can currently only be applied at boot time or else
  73. // it has the potential to lead to a graphics crash.
  74. virtual void ApplyMsaaSetting() = 0;
  75. // Enable/Disable TAA
  76. virtual bool GetTaa() = 0;
  77. virtual void SetTaa(bool enable) = 0;
  78. // Change the volume setting from 0 - 100 for the given channel
  79. virtual uint8_t GetVolume(VolumeChannel volumeChannel) = 0;
  80. virtual void SetVolume(VolumeChannel volumeChannel, uint8_t volume) = 0;
  81. };
  82. using MultiplayerSampleUserSettingsRequestBus = AZ::EBus<MultiplayerSampleUserSettingsRequests>;
  83. // This implements the bus provided above. The user settings get auto-loaded at construction and auto-saved at destruction,
  84. // though saves can also be triggered at other times as well. Because one of the settings is the default graphics API, these
  85. // settings need to be loaded before system components are initialized because the Atom system components load the graphics
  86. // API. All of the other settings are changeable at any time and would have allowed this class to get created later in the
  87. // boot process.
  88. class MultiplayerSampleUserSettings
  89. : public MultiplayerSampleUserSettingsRequestBus::Handler
  90. , public AZ::Render::Bootstrap::NotificationBus::Handler
  91. {
  92. public:
  93. MultiplayerSampleUserSettings();
  94. ~MultiplayerSampleUserSettings() override;
  95. // AZ::Render::Bootstrap::NotificationBus overrides...
  96. void OnBootstrapSceneReady(AZ::RPI::Scene* bootstrapScene) override;
  97. // MultiplayerSampleUserSettingsRequestBus overrides...
  98. void Load() override;
  99. void Save() override;
  100. AZStd::string GetGraphicsApi() override;
  101. void SetGraphicsApi(const AZStd::string& apiName) override;
  102. int16_t GetTextureQuality() override;
  103. void SetTextureQuality(int16_t textureQuality) override;
  104. bool GetFullscreen() override;
  105. void SetFullscreen(bool fullscreen) override;
  106. SpecularReflections GetReflectionSetting() override;
  107. void SetReflectionSetting(SpecularReflections reflectionType) override;
  108. Msaa GetMsaa() override;
  109. void SetMsaa(Msaa msaa) override;
  110. void ApplyMsaaSetting() override;
  111. bool GetTaa() override;
  112. void SetTaa(bool enable) override;
  113. uint8_t GetVolume(VolumeChannel volumeChannel) override;
  114. void SetVolume(VolumeChannel volumeChannel, uint8_t volume) override;
  115. AZStd::pair<uint32_t, uint32_t> GetResolution() override;
  116. void SetResolution(AZStd::pair<uint32_t, uint32_t> resolution) override;
  117. private:
  118. void SetMsaaInRenderer(Msaa msaa);
  119. AZStd::pair<uint32_t, uint32_t> GetMaxResolution();
  120. // Cached pointer to the settings registry so that we don't have to fetch it for every setting.
  121. AZ::SettingsRegistryInterface* m_registry = nullptr;
  122. // The path to the user settings file.
  123. AZ::IO::FixedMaxPath m_userSettingsPath;
  124. bool m_changingResolution = false;
  125. };
  126. } // namespace MultiplayerSample