From 4a9ad70d489ea859aa358321a79f5ebf75a1f931 Mon Sep 17 00:00:00 2001 From: mduval76 <9343789@etu.cegepsth.qc.ca> Date: Mon, 27 Nov 2023 16:03:06 -0500 Subject: [PATCH] Push changement pour Parametres -> Settings --- SQCSim-common/parameters.cpp | 145 ----------------- SQCSim2021/SQCSim2021.vcxproj | 4 +- SQCSim2021/SQCSim2021.vcxproj.filters | 4 +- SQCSim2021/audio.cpp | 4 + SQCSim2021/audio.h | 2 + SQCSim2021/engine.h | 3 +- SQCSim2021/settings.cpp | 146 ++++++++++++++++++ .../parameters.h => SQCSim2021/settings.h | 14 +- 8 files changed, 167 insertions(+), 155 deletions(-) delete mode 100644 SQCSim-common/parameters.cpp create mode 100644 SQCSim2021/settings.cpp rename SQCSim-common/parameters.h => SQCSim2021/settings.h (88%) diff --git a/SQCSim-common/parameters.cpp b/SQCSim-common/parameters.cpp deleted file mode 100644 index 615d74e..0000000 --- a/SQCSim-common/parameters.cpp +++ /dev/null @@ -1,145 +0,0 @@ -#include "parameters.h" - -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::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::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(); -} - -float Parameters::GetMainVolume() const { - return m_mainVolume; -} - -void Parameters::SetMainVolume(float volume) { - m_mainVolume = volume; -} - -float Parameters::GetMusicVolume() const { - return m_musicVolume; -} - -void Parameters::SetMusicVolume(float volume) { - m_musicVolume = volume; -} - -float Parameters::GetSfxVolume() const { - return m_sfxVolume; -} - -void Parameters::SetSfxVolume(float volume) { - m_sfxVolume = volume; -} - -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; - } -} diff --git a/SQCSim2021/SQCSim2021.vcxproj b/SQCSim2021/SQCSim2021.vcxproj index 8f2d6e3..31e1b8b 100644 --- a/SQCSim2021/SQCSim2021.vcxproj +++ b/SQCSim2021/SQCSim2021.vcxproj @@ -19,7 +19,6 @@ - @@ -28,6 +27,7 @@ + @@ -37,7 +37,6 @@ - @@ -46,6 +45,7 @@ + diff --git a/SQCSim2021/SQCSim2021.vcxproj.filters b/SQCSim2021/SQCSim2021.vcxproj.filters index 5b333aa..417ba37 100644 --- a/SQCSim2021/SQCSim2021.vcxproj.filters +++ b/SQCSim2021/SQCSim2021.vcxproj.filters @@ -56,7 +56,7 @@ Fichiers d%27en-tĂȘte - + Fichiers d%27en-tĂȘte @@ -106,7 +106,7 @@ Fichiers sources - + Fichiers sources diff --git a/SQCSim2021/audio.cpp b/SQCSim2021/audio.cpp index e849c6f..7691f88 100644 --- a/SQCSim2021/audio.cpp +++ b/SQCSim2021/audio.cpp @@ -48,3 +48,7 @@ void Audio::Render3DAudioObj(irrklang::ISound* sound, Vector3f& pos, Vector3f& v void Audio::ToggleMusicState() { m_music->setIsPaused(!m_music->getIsPaused()); } void Audio::PauseEngine() { m_engine->setAllSoundsPaused(); } + +float Audio::GetMusicVolume() const { + return m_music->getVolume(); +} diff --git a/SQCSim2021/audio.h b/SQCSim2021/audio.h index 775f316..f19682a 100644 --- a/SQCSim2021/audio.h +++ b/SQCSim2021/audio.h @@ -33,6 +33,8 @@ public: void ToggleMusicState(); void PauseEngine(); + + float GetMusicVolume() const; }; #endif // AUDIO_H__ diff --git a/SQCSim2021/engine.h b/SQCSim2021/engine.h index 57841b9..5351cc1 100644 --- a/SQCSim2021/engine.h +++ b/SQCSim2021/engine.h @@ -24,7 +24,7 @@ #include "renderer.h" #include "remoteplayer.h" #include "booster.h" - +#include "settings.h" class Engine : public OpenglContext { public: @@ -95,6 +95,7 @@ private: irrklang::ISound *m_whoosh[MAX_BULLETS]; Player m_player = Player(Vector3f(.5f, CHUNK_SIZE_Y + 1.8f, .5f)); + Settings m_parameters = Settings(m_audio); Bullet* m_bullets[MAX_BULLETS]; diff --git a/SQCSim2021/settings.cpp b/SQCSim2021/settings.cpp new file mode 100644 index 0000000..b84effc --- /dev/null +++ b/SQCSim2021/settings.cpp @@ -0,0 +1,146 @@ +#include "settings.h" + +Settings::Settings(Audio& audio) + : m_audio(audio), + 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 Settings::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 Settings::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(); +} + +float Settings::GetMainVolume() const { + return m_mainVolume; +} + +void Settings::SetMainVolume(float volume) { + m_mainVolume = volume; +} + +void Settings::GetMusicVolume() { + m_musicVolume = m_audio.GetMusicVolume(); +} + +void Settings::SetMusicVolume(float volume) { + m_musicVolume = volume; +} + +float Settings::GetSfxVolume() const { + return m_sfxVolume; +} + +void Settings::SetSfxVolume(float volume) { + m_sfxVolume = volume; +} + +float Settings::GetBrightness() const { + return m_brightness; +} + +void Settings::SetBrightness(float brightness) { + m_brightness = brightness; +} + +float Settings::GetContrast() const { + return m_contrast; +} + +void Settings::SetContrast(float contrast) { + m_contrast = contrast; +} + +bool Settings::GetFullscreen() const { + return m_fullscreen; +} + +void Settings::SetFullscreen(bool fullscreen) { + m_fullscreen = fullscreen; +} + +const Resolution& Settings::GetResolution() const { + return m_resolution; +} + +void Settings::SetResolution(const Resolution& resolution) { + m_resolution = resolution; +} + +float Settings::GetMouseSensitivity() const { + return m_mouseSensitivity; +} + +void Settings::SetMouseSensitivity(float sensitivity) { + m_mouseSensitivity = sensitivity; +} + +void Settings::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; + } +} diff --git a/SQCSim-common/parameters.h b/SQCSim2021/settings.h similarity index 88% rename from SQCSim-common/parameters.h rename to SQCSim2021/settings.h index a7bdaba..e871529 100644 --- a/SQCSim-common/parameters.h +++ b/SQCSim2021/settings.h @@ -1,5 +1,5 @@ -#ifndef PARAMETERS_H -#define PARAMETERS_H +#ifndef SETTINGS_H__ +#define SETTINGS_H__ #include #include @@ -8,10 +8,11 @@ #include #include "define.h" +#include "audio.h" -class Parameters { +class Settings { public: - Parameters(); + Settings(Audio& audio); void SaveFile(const std::string& filename); void LoadFile(const std::string& filename); @@ -20,7 +21,7 @@ public: float GetMainVolume() const; void SetMainVolume(float volume); - float GetMusicVolume() const; + void GetMusicVolume(); void SetMusicVolume(float volume); float GetSfxVolume() const; @@ -46,6 +47,8 @@ public: void ApplyResolution(Resolution resolution); private: + + Audio& m_audio; // Audio float m_mainVolume; float m_musicVolume; @@ -63,4 +66,5 @@ private: float m_mouseSensitivity; }; + #endif // PARAMETERS_H \ No newline at end of file