diff --git a/SQCSim-common/define.h b/SQCSim-common/define.h index 05d90da..a77aa5d 100644 --- a/SQCSim-common/define.h +++ b/SQCSim-common/define.h @@ -37,10 +37,18 @@ typedef uint8_t BlockType; enum BLOCK_TYPE { BTYPE_AIR, BTYPE_DIRT, BTYPE_GRASS, BTYPE_METAL, BTYPE_ICE, BTYPE_LAST }; typedef uint64_t Timestamp; +enum Resolution { + HD = 0, // 1280x720 (High Definition) + FHD, // 1920x1080 (Full HD) + QHD, // 2560x1440 (Quad HD) + UHD // 3840x2160 (Ultra HD) +}; + #ifdef _WIN32 #pragma comment(lib,"wsock32.lib") // Pour pouvoir faire fonctionner le linker sans le vcxproject #pragma comment(lib,"ws2_32.lib") + #include #include #include diff --git a/SQCSim-common/parameters.cpp b/SQCSim-common/parameters.cpp index 4fd9ff1..615d74e 100644 --- a/SQCSim-common/parameters.cpp +++ b/SQCSim-common/parameters.cpp @@ -1,67 +1,145 @@ #include "parameters.h" -Parameters::Parameters() {} - -Parameters::~Parameters() {} - -void Parameters::SaveAudioParameters() { - +Parameters::Parameters() + : m_mainVolume(0.5f), + m_musicVolume(0.5f), + m_sfxVolume(0.5f), + m_resolution(FHD), + m_fullscreen(false), + m_brightness(0.5f), + m_contrast(0.5f), + m_mouseSensitivity(0.5f) { + ApplyResolution(m_resolution); } -void Parameters::SaveGraphicParameters() { +void Parameters::SaveFile(const std::string& filename) { + std::ofstream file(filename); + if (!file.is_open()) { + std::cerr << "Failed to open file for saving parameters" << std::endl; + return; + } + file << m_mainVolume << '\n'; + file << m_musicVolume << '\n'; + file << m_sfxVolume << '\n'; + + file << static_cast(m_resolution) << '\n'; + file << m_fullscreen << '\n'; + file << m_brightness << '\n'; + file << m_contrast << '\n'; + + file << m_mouseSensitivity << '\n'; + + file.close(); } -void Parameters::SaveGameParameters() { +void Parameters::LoadFile(const std::string& filename) { + std::ifstream file(filename); + if (!file.is_open()) { + std::cerr << "Failed to open file for loading parameters" << std::endl; + return; + } + file >> m_mainVolume; + file >> m_musicVolume; + file >> m_sfxVolume; + + int resolutionValue; + file >> resolutionValue; + m_resolution = static_cast(resolutionValue); + + file >> m_fullscreen; + file >> m_brightness; + file >> m_contrast; + + file >> m_mouseSensitivity; + + file.close(); } -void Parameters::LoadAudioParameters() { - +float Parameters::GetMainVolume() const { + return m_mainVolume; } -void Parameters::LoadGraphicParameters() { - +void Parameters::SetMainVolume(float volume) { + m_mainVolume = volume; } -void Parameters::LoadGameParameters() { - +float Parameters::GetMusicVolume() const { + return m_musicVolume; } -void Parameters::SetAudioParameter(const std::string& key, const ParameterValue& value) { - m_audioSettings[key] = value; +void Parameters::SetMusicVolume(float volume) { + m_musicVolume = volume; } -void Parameters::SetGraphicParameter(const std::string& key, const ParameterValue& value) { - m_graphicSettings[key] = value; +float Parameters::GetSfxVolume() const { + return m_sfxVolume; } -void Parameters::SetGameParameter(const std::string& key, const ParameterValue& value) { - m_gameplaySettings[key] = value; +void Parameters::SetSfxVolume(float volume) { + m_sfxVolume = volume; } -std::optional Parameters::GetAudioParameter(const std::string& key) const { - auto it = m_audioSettings.find(key); - if (it != m_audioSettings.end()) { - return it->second; +float Parameters::GetBrightness() const { + return m_brightness; +} + +void Parameters::SetBrightness(float brightness) { + m_brightness = brightness; +} + +float Parameters::GetContrast() const { + return m_contrast; +} + +void Parameters::SetContrast(float contrast) { + m_contrast = contrast; +} + +bool Parameters::GetFullscreen() const { + return m_fullscreen; +} + +void Parameters::SetFullscreen(bool fullscreen) { + m_fullscreen = fullscreen; +} + +const Resolution& Parameters::GetResolution() const { + return m_resolution; +} + +void Parameters::SetResolution(const Resolution& resolution) { + m_resolution = resolution; +} + +float Parameters::GetMouseSensitivity() const { + return m_mouseSensitivity; +} + +void Parameters::SetMouseSensitivity(float sensitivity) { + m_mouseSensitivity = sensitivity; +} + +void Parameters::ApplyResolution(Resolution resolution) { + switch (resolution) { + case HD: + m_rezWidth = 1280; + m_rezHeight = 720; + break; + case FHD: + m_rezWidth = 1920; + m_rezHeight = 1080; + break; + case QHD: + m_rezWidth = 2560; + m_rezHeight = 1440; + break; + case UHD: + m_rezWidth = 3840; + m_rezHeight = 2160; + break; + default: + break; } - return std::nullopt; } - -std::optional Parameters::GetGraphicParameter(const std::string& key) const { - auto it = m_graphicSettings.find(key); - if (it != m_graphicSettings.end()) { - return it->second; - } - return std::nullopt; -} - -std::optional Parameters::GetGameParameter(const std::string& key) const { - auto it = m_gameplaySettings.find(key); - if (it != m_gameplaySettings.end()) { - return it->second; - } - return std::nullopt; -} - - diff --git a/SQCSim-common/parameters.h b/SQCSim-common/parameters.h index 3e2acea..a7bdaba 100644 --- a/SQCSim-common/parameters.h +++ b/SQCSim-common/parameters.h @@ -1,55 +1,66 @@ #ifndef PARAMETERS_H #define PARAMETERS_H -#include #include #include #include -#include #include #include -using ParameterValue = std::variant; +#include "define.h" class Parameters { public: Parameters(); - ~Parameters(); - void SaveAudioParameters(); - void SaveGraphicParameters(); - void SaveGameParameters(); + void SaveFile(const std::string& filename); + void LoadFile(const std::string& filename); - void LoadAudioParameters(); - void LoadGraphicParameters(); - void LoadGameParameters(); + // Audio + float GetMainVolume() const; + void SetMainVolume(float volume); - void SetAudioParameter(const std::string& key, const ParameterValue& value); - void SetGraphicParameter(const std::string& key, const ParameterValue& value); - void SetGameParameter(const std::string& key, const ParameterValue& value); + float GetMusicVolume() const; + void SetMusicVolume(float volume); - std::optional GetAudioParameter(const std::string& key) const; - std::optional GetGraphicParameter(const std::string& key) const; - std::optional GetGameParameter(const std::string& key) const; + float GetSfxVolume() const; + void SetSfxVolume(float volume); + + // Graphic + float GetBrightness() const; + void SetBrightness(float brightness); + + float GetContrast() const; + void SetContrast(float contrast); + + bool GetFullscreen() const; + void SetFullscreen(bool fullscreen); + + const Resolution& GetResolution() const; + void SetResolution(const Resolution& resolution); + + // Gameplay + float GetMouseSensitivity() const; + void SetMouseSensitivity(float sensitivity); + + void ApplyResolution(Resolution resolution); private: - std::map m_audioSettings; - std::map m_graphicSettings; - std::map m_gameplaySettings; - // Audio float m_mainVolume; float m_musicVolume; float m_sfxVolume; // Graphic - float m_resolutionX; - float m_resolutionY; + Resolution m_resolution; bool m_fullscreen; + int m_rezWidth; + int m_rezHeight; + float m_brightness; + float m_contrast; // Gameplay float m_mouseSensitivity; - }; #endif // PARAMETERS_H \ No newline at end of file diff --git a/SQCSim2021/SQCSim2021.vcxproj b/SQCSim2021/SQCSim2021.vcxproj index b306010..fc67c42 100644 --- a/SQCSim2021/SQCSim2021.vcxproj +++ b/SQCSim2021/SQCSim2021.vcxproj @@ -25,7 +25,6 @@ - @@ -42,7 +41,6 @@ - diff --git a/SQCSim2021/SQCSim2021.vcxproj.filters b/SQCSim2021/SQCSim2021.vcxproj.filters index 271ff00..5c8a864 100644 --- a/SQCSim2021/SQCSim2021.vcxproj.filters +++ b/SQCSim2021/SQCSim2021.vcxproj.filters @@ -53,9 +53,6 @@ Fichiers d%27en-tĂȘte - - Fichiers d%27en-tĂȘte - @@ -100,8 +97,5 @@ Fichiers sources - - Fichiers sources - \ No newline at end of file