summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLaG1924 <12997935+LaG1924@users.noreply.github.com>2018-08-07 01:19:20 +0200
committerLaG1924 <12997935+LaG1924@users.noreply.github.com>2018-08-07 01:19:20 +0200
commite20289f53325036629870b257aee1728157a548e (patch)
tree46e549df2406bf1e958b6ff5c2787cdae49e974c /src
parentTextureAtlas padding small textures (diff)
downloadAltCraft-e20289f53325036629870b257aee1728157a548e.tar
AltCraft-e20289f53325036629870b257aee1728157a548e.tar.gz
AltCraft-e20289f53325036629870b257aee1728157a548e.tar.bz2
AltCraft-e20289f53325036629870b257aee1728157a548e.tar.lz
AltCraft-e20289f53325036629870b257aee1728157a548e.tar.xz
AltCraft-e20289f53325036629870b257aee1728157a548e.tar.zst
AltCraft-e20289f53325036629870b257aee1728157a548e.zip
Diffstat (limited to '')
-rw-r--r--src/Render.cpp59
-rw-r--r--src/Render.hpp5
-rw-r--r--src/Settings.hpp25
3 files changed, 69 insertions, 20 deletions
diff --git a/src/Render.cpp b/src/Render.cpp
index d5a4b6a..7e770fc 100644
--- a/src/Render.cpp
+++ b/src/Render.cpp
@@ -30,9 +30,27 @@ Render::Render(unsigned int windowWidth, unsigned int windowHeight,
PrepareToRendering();
glCheckError();
+ //Read settings
strcpy(fieldUsername, Settings::Read("username", "HelloOne").c_str());
strcpy(fieldServerAddr, Settings::Read("serverAddr", "127.0.0.1").c_str());
- fieldServerPort = std::stoi(Settings::Read("serverPort", "25565"));
+ fieldServerPort = Settings::ReadInt("serverPort", 25565);
+ fieldDistance = Settings::ReadDouble("renderDistance", 2.0);
+ fieldTargetFps = Settings::ReadDouble("targetFps", 60.0);
+ fieldSensetivity = Settings::ReadDouble("mouseSensetivity", 0.1);
+ fieldVsync = Settings::ReadBool("vsync", false);
+ fieldWireframe = Settings::ReadBool("wireframe", false);
+
+ //Apply settings
+ if (fieldSensetivity != sensetivity)
+ sensetivity = fieldSensetivity;
+ isWireframe = fieldWireframe;
+ timer.SetDelayLength(std::chrono::duration<double, std::milli>(1.0 / fieldTargetFps * 1000.0));
+ if (fieldVsync) {
+ timer.SetDelayLength(std::chrono::milliseconds(0));
+ SDL_GL_SetSwapInterval(1);
+ }
+ else
+ SDL_GL_SetSwapInterval(0);
LOG(INFO) << "Supported threads: " << std::thread::hardware_concurrency();
}
@@ -40,7 +58,12 @@ Render::Render(unsigned int windowWidth, unsigned int windowHeight,
Render::~Render() {
Settings::Write("username", fieldUsername);
Settings::Write("serverAddr", fieldServerAddr);
- Settings::Write("serverPort", std::to_string(fieldServerPort));
+ Settings::WriteInt("serverPort", fieldServerPort);
+ Settings::WriteDouble("renderDistance", fieldDistance);
+ Settings::WriteDouble("targetFps", fieldTargetFps);
+ Settings::WriteDouble("mouseSensetivity", fieldSensetivity);
+ Settings::WriteBool("vsync", fieldVsync);
+ Settings::WriteBool("wireframe", fieldWireframe);
Settings::Save();
ImGui_ImplSdlGL3_Shutdown();
@@ -528,35 +551,29 @@ void Render::RenderGui() {
GlobalState::SetState(State::Playing);
}
ImGui::Separator();
- static float distance = world->MaxRenderingDistance;
- ImGui::SliderFloat("Render distance", &distance, 1.0f, 16.0f);
- static float sense = sensetivity;
- ImGui::SliderFloat("Sensetivity", &sense, 0.01f, 1.0f);
+ ImGui::SliderFloat("Render distance", &fieldDistance, 1.0f, 16.0f);
- static float targetFps = 60.0f;
- ImGui::SliderFloat("Target FPS", &targetFps, 1.0f, 300.0f);
+ ImGui::SliderFloat("Sensetivity", &fieldSensetivity, 0.01f, 1.0f);
- static bool wireframe = isWireframe;
+ ImGui::SliderFloat("Target FPS", &fieldTargetFps, 1.0f, 300.0f);
- ImGui::Checkbox("Wireframe", &wireframe);
+ ImGui::Checkbox("Wireframe", &fieldWireframe);
- static bool vsync = false;
-
- ImGui::Checkbox("VSync", &vsync);
+ ImGui::Checkbox("VSync", &fieldVsync);
if (ImGui::Button("Apply settings")) {
- if (distance != world->MaxRenderingDistance) {
- world->MaxRenderingDistance = distance;
+ if (fieldDistance != world->MaxRenderingDistance) {
+ world->MaxRenderingDistance = fieldDistance;
PUSH_EVENT("UpdateSectionsRender", 0);
}
- if (sense != sensetivity)
- sensetivity = sense;
+ if (fieldSensetivity != sensetivity)
+ sensetivity = fieldSensetivity;
- isWireframe = wireframe;
- timer.SetDelayLength(std::chrono::duration<double, std::milli>(1.0 / targetFps * 1000.0));
- if (vsync) {
+ isWireframe = fieldWireframe;
+ timer.SetDelayLength(std::chrono::duration<double, std::milli>(1.0 / fieldTargetFps * 1000.0));
+ if (fieldVsync) {
timer.SetDelayLength(std::chrono::milliseconds(0));
SDL_GL_SetSwapInterval(1);
} else
@@ -594,6 +611,8 @@ void Render::InitEvents() {
listener.RegisterHandler("PlayerConnected", [this](const Event&) {
stateString = "Loading terrain...";
world = std::make_unique<RendererWorld>(GlobalState::GetGameState());
+ world->MaxRenderingDistance = fieldDistance;
+ PUSH_EVENT("UpdateSectionsRender", 0);
});
listener.RegisterHandler("RemoveLoadingScreen", [this](const Event&) {
diff --git a/src/Render.hpp b/src/Render.hpp
index f4523a1..b0058b7 100644
--- a/src/Render.hpp
+++ b/src/Render.hpp
@@ -35,6 +35,11 @@ class Render {
char fieldUsername[512];
char fieldServerAddr[512];
int fieldServerPort;
+ float fieldDistance;
+ float fieldSensetivity;
+ float fieldTargetFps;
+ bool fieldWireframe;
+ bool fieldVsync;
void SetMouseCapture(bool IsCaptured);
diff --git a/src/Settings.hpp b/src/Settings.hpp
index 194e736..9132161 100644
--- a/src/Settings.hpp
+++ b/src/Settings.hpp
@@ -10,4 +10,29 @@ namespace Settings {
std::string Read(const std::string &key, const std::string &defaultValue);
void Write(const std::string &key, const std::string &value);
+
+ inline bool ReadBool(const std::string &key, bool defaultValue) {
+ return Read(key, std::to_string(defaultValue)) == "true";
+ }
+
+ inline void WriteBool(const std::string &key, bool value) {
+ Write(key, value ? "true" : "false");
+ }
+
+ inline int ReadInt(const std::string &key, int defaultValue) {
+ return std::stoi(Read(key, std::to_string(defaultValue)));
+ }
+
+ inline void WriteInt(const std::string &key, int value) {
+ Write(key, std::to_string(value));
+ }
+
+ inline double ReadDouble(const std::string &key, double defaultValue) {
+ return std::stod(Read(key, std::to_string(defaultValue)));
+ }
+
+ inline void WriteDouble(const std::string &key, double value) {
+ Write(key, std::to_string(value));
+ }
+
} \ No newline at end of file