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 };
|
enum BLOCK_TYPE { BTYPE_AIR, BTYPE_DIRT, BTYPE_GRASS, BTYPE_METAL, BTYPE_ICE, BTYPE_LAST };
|
||||||
typedef uint64_t Timestamp;
|
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
|
#ifdef _WIN32
|
||||||
|
|
||||||
#pragma comment(lib,"wsock32.lib") // Pour pouvoir faire fonctionner le linker sans le vcxproject
|
#pragma comment(lib,"wsock32.lib") // Pour pouvoir faire fonctionner le linker sans le vcxproject
|
||||||
#pragma comment(lib,"ws2_32.lib")
|
#pragma comment(lib,"ws2_32.lib")
|
||||||
|
|
||||||
#include <ws2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
@ -1,67 +1,145 @@
|
|||||||
#include "parameters.h"
|
#include "parameters.h"
|
||||||
|
|
||||||
Parameters::Parameters() {}
|
Parameters::Parameters()
|
||||||
|
: m_mainVolume(0.5f),
|
||||||
Parameters::~Parameters() {}
|
m_musicVolume(0.5f),
|
||||||
|
m_sfxVolume(0.5f),
|
||||||
void Parameters::SaveAudioParameters() {
|
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) {
|
void Parameters::SetMusicVolume(float volume) {
|
||||||
m_audioSettings[key] = value;
|
m_musicVolume = volume;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Parameters::SetGraphicParameter(const std::string& key, const ParameterValue& value) {
|
float Parameters::GetSfxVolume() const {
|
||||||
m_graphicSettings[key] = value;
|
return m_sfxVolume;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Parameters::SetGameParameter(const std::string& key, const ParameterValue& value) {
|
void Parameters::SetSfxVolume(float volume) {
|
||||||
m_gameplaySettings[key] = value;
|
m_sfxVolume = volume;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<ParameterValue> Parameters::GetAudioParameter(const std::string& key) const {
|
float Parameters::GetBrightness() const {
|
||||||
auto it = m_audioSettings.find(key);
|
return m_brightness;
|
||||||
if (it != m_audioSettings.end()) {
|
}
|
||||||
return it->second;
|
|
||||||
|
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
|
#ifndef PARAMETERS_H
|
||||||
#define PARAMETERS_H
|
#define PARAMETERS_H
|
||||||
|
|
||||||
#include <optional>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <variant>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
using ParameterValue = std::variant<float, int, bool, std::string>;
|
#include "define.h"
|
||||||
|
|
||||||
class Parameters {
|
class Parameters {
|
||||||
public:
|
public:
|
||||||
Parameters();
|
Parameters();
|
||||||
~Parameters();
|
|
||||||
|
|
||||||
void SaveAudioParameters();
|
void SaveFile(const std::string& filename);
|
||||||
void SaveGraphicParameters();
|
void LoadFile(const std::string& filename);
|
||||||
void SaveGameParameters();
|
|
||||||
|
|
||||||
void LoadAudioParameters();
|
// Audio
|
||||||
void LoadGraphicParameters();
|
float GetMainVolume() const;
|
||||||
void LoadGameParameters();
|
void SetMainVolume(float volume);
|
||||||
|
|
||||||
void SetAudioParameter(const std::string& key, const ParameterValue& value);
|
float GetMusicVolume() const;
|
||||||
void SetGraphicParameter(const std::string& key, const ParameterValue& value);
|
void SetMusicVolume(float volume);
|
||||||
void SetGameParameter(const std::string& key, const ParameterValue& value);
|
|
||||||
|
|
||||||
std::optional<ParameterValue> GetAudioParameter(const std::string& key) const;
|
float GetSfxVolume() const;
|
||||||
std::optional<ParameterValue> GetGraphicParameter(const std::string& key) const;
|
void SetSfxVolume(float volume);
|
||||||
std::optional<ParameterValue> GetGameParameter(const std::string& key) const;
|
|
||||||
|
// 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:
|
private:
|
||||||
std::map<std::string, ParameterValue> m_audioSettings;
|
|
||||||
std::map<std::string, ParameterValue> m_graphicSettings;
|
|
||||||
std::map<std::string, ParameterValue> m_gameplaySettings;
|
|
||||||
|
|
||||||
// Audio
|
// Audio
|
||||||
float m_mainVolume;
|
float m_mainVolume;
|
||||||
float m_musicVolume;
|
float m_musicVolume;
|
||||||
float m_sfxVolume;
|
float m_sfxVolume;
|
||||||
|
|
||||||
// Graphic
|
// Graphic
|
||||||
float m_resolutionX;
|
Resolution m_resolution;
|
||||||
float m_resolutionY;
|
|
||||||
bool m_fullscreen;
|
bool m_fullscreen;
|
||||||
|
int m_rezWidth;
|
||||||
|
int m_rezHeight;
|
||||||
|
float m_brightness;
|
||||||
|
float m_contrast;
|
||||||
|
|
||||||
// Gameplay
|
// Gameplay
|
||||||
float m_mouseSensitivity;
|
float m_mouseSensitivity;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PARAMETERS_H
|
#endif // PARAMETERS_H
|
@ -25,7 +25,6 @@
|
|||||||
<ClInclude Include="engine.h" />
|
<ClInclude Include="engine.h" />
|
||||||
<ClInclude Include="mesh.h" />
|
<ClInclude Include="mesh.h" />
|
||||||
<ClInclude Include="openglcontext.h" />
|
<ClInclude Include="openglcontext.h" />
|
||||||
<ClInclude Include="parameters.h" />
|
|
||||||
<ClInclude Include="remoteplayer.h" />
|
<ClInclude Include="remoteplayer.h" />
|
||||||
<ClInclude Include="shader.h" />
|
<ClInclude Include="shader.h" />
|
||||||
<ClInclude Include="skybox.h" />
|
<ClInclude Include="skybox.h" />
|
||||||
@ -42,7 +41,6 @@
|
|||||||
<ClCompile Include="main.cpp" />
|
<ClCompile Include="main.cpp" />
|
||||||
<ClCompile Include="mesh.cpp" />
|
<ClCompile Include="mesh.cpp" />
|
||||||
<ClCompile Include="openglcontext.cpp" />
|
<ClCompile Include="openglcontext.cpp" />
|
||||||
<ClCompile Include="parameters.cpp" />
|
|
||||||
<ClCompile Include="remoteplayer.cpp" />
|
<ClCompile Include="remoteplayer.cpp" />
|
||||||
<ClCompile Include="shader.cpp" />
|
<ClCompile Include="shader.cpp" />
|
||||||
<ClCompile Include="skybox.cpp" />
|
<ClCompile Include="skybox.cpp" />
|
||||||
|
@ -53,9 +53,6 @@
|
|||||||
<ClInclude Include="remoteplayer.h">
|
<ClInclude Include="remoteplayer.h">
|
||||||
<Filter>Fichiers d%27en-tête</Filter>
|
<Filter>Fichiers d%27en-tête</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="parameters.h">
|
|
||||||
<Filter>Fichiers d%27en-tête</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="engine.cpp">
|
<ClCompile Include="engine.cpp">
|
||||||
@ -100,8 +97,5 @@
|
|||||||
<ClCompile Include="remoteplayer.cpp">
|
<ClCompile Include="remoteplayer.cpp">
|
||||||
<Filter>Fichiers sources</Filter>
|
<Filter>Fichiers sources</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="parameters.cpp">
|
|
||||||
<Filter>Fichiers sources</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
Loading…
x
Reference in New Issue
Block a user