Push premiere esquisse des parametres de sauvegarde
This commit is contained in:
parent
6bb3ee9667
commit
8e041a314d
@ -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 <ws2tcpip.h>
|
||||
#include <Windows.h>
|
||||
#include <cstdio>
|
||||
|
@ -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<int>(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<Resolution>(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<ParameterValue> 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<ParameterValue> 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<ParameterValue> Parameters::GetGameParameter(const std::string& key) const {
|
||||
auto it = m_gameplaySettings.find(key);
|
||||
if (it != m_gameplaySettings.end()) {
|
||||
return it->second;
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,55 +1,66 @@
|
||||
#ifndef PARAMETERS_H
|
||||
#define PARAMETERS_H
|
||||
|
||||
#include <optional>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <variant>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
using ParameterValue = std::variant<float, int, bool, std::string>;
|
||||
#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<ParameterValue> GetAudioParameter(const std::string& key) const;
|
||||
std::optional<ParameterValue> GetGraphicParameter(const std::string& key) const;
|
||||
std::optional<ParameterValue> 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<std::string, ParameterValue> m_audioSettings;
|
||||
std::map<std::string, ParameterValue> m_graphicSettings;
|
||||
std::map<std::string, ParameterValue> 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
|
@ -25,7 +25,6 @@
|
||||
<ClInclude Include="engine.h" />
|
||||
<ClInclude Include="mesh.h" />
|
||||
<ClInclude Include="openglcontext.h" />
|
||||
<ClInclude Include="parameters.h" />
|
||||
<ClInclude Include="remoteplayer.h" />
|
||||
<ClInclude Include="shader.h" />
|
||||
<ClInclude Include="skybox.h" />
|
||||
@ -42,7 +41,6 @@
|
||||
<ClCompile Include="main.cpp" />
|
||||
<ClCompile Include="mesh.cpp" />
|
||||
<ClCompile Include="openglcontext.cpp" />
|
||||
<ClCompile Include="parameters.cpp" />
|
||||
<ClCompile Include="remoteplayer.cpp" />
|
||||
<ClCompile Include="shader.cpp" />
|
||||
<ClCompile Include="skybox.cpp" />
|
||||
|
@ -53,9 +53,6 @@
|
||||
<ClInclude Include="remoteplayer.h">
|
||||
<Filter>Fichiers d%27en-tête</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="parameters.h">
|
||||
<Filter>Fichiers d%27en-tête</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="engine.cpp">
|
||||
@ -100,8 +97,5 @@
|
||||
<ClCompile Include="remoteplayer.cpp">
|
||||
<Filter>Fichiers sources</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="parameters.cpp">
|
||||
<Filter>Fichiers sources</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
Loading…
Reference in New Issue
Block a user