From a28962c38d57b581c650ba01193a134660944cc2 Mon Sep 17 00:00:00 2001 From: orfanidi Date: Tue, 18 May 2021 12:55:24 +0300 Subject: [PATCH 1/2] Bugfix when load the configuration. --- src/main.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 8dc458f3..268237f7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,15 +2,37 @@ #include #include #include +#include #include "colony.hpp" #include "config.hpp" #include "display_manager.hpp" +std::string getCurrentPath() +{ + std::string path; + static constexpr size_t PATH_SIZE = 1024; + path.resize(PATH_SIZE); +#if defined(__unix__) + size_t pos = readlink("/proc/self/exe", path.data(), PATH_SIZE); + path.resize(pos); + pos = path.rfind("/"); + path.resize(++pos); +#endif + +#if defined(_WIN32) + char currentPath[PATH_SIZE]; + _getcwd(currentPath, sizeof(currentPath)); + path = std::string(currentPath); + path += "\\"; +#endif + + return path; +} void loadUserConf() { - std::ifstream conf_file("conf.txt"); + std::ifstream conf_file(getCurrentPath() + "conf.txt"); if (conf_file) { conf_file >> Conf::WIN_WIDTH; conf_file >> Conf::WIN_HEIGHT; @@ -26,6 +48,7 @@ int main() { Conf::loadTextures(); loadUserConf(); + Conf::COLONY_POSITION = sf::Vector2f(Conf::WIN_WIDTH * 0.5f, Conf::WIN_HEIGHT * 0.5f); sf::ContextSettings settings; settings.antialiasingLevel = 4; From 41ade5cc23707555d4504f30539c81f7135f3a12 Mon Sep 17 00:00:00 2001 From: Ivan Orfanidi Date: Tue, 18 May 2021 23:59:26 +0300 Subject: [PATCH 2/2] fix for c++11 --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 268237f7..470f2849 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,7 +14,7 @@ std::string getCurrentPath() static constexpr size_t PATH_SIZE = 1024; path.resize(PATH_SIZE); #if defined(__unix__) - size_t pos = readlink("/proc/self/exe", path.data(), PATH_SIZE); + size_t pos = readlink("/proc/self/exe", &path[0], PATH_SIZE); path.resize(pos); pos = path.rfind("/"); path.resize(++pos); @@ -52,7 +52,7 @@ int main() sf::ContextSettings settings; settings.antialiasingLevel = 4; - sf::RenderWindow window(sf::VideoMode(Conf::WIN_WIDTH, Conf::WIN_HEIGHT), "AntSim", sf::Style::Fullscreen, settings); + sf::RenderWindow window(sf::VideoMode(Conf::WIN_WIDTH, Conf::WIN_HEIGHT), "AntSim", sf::Style::Default, settings); window.setFramerateLimit(60); World world(Conf::WORLD_WIDTH, Conf::WORLD_HEIGHT);