Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix when load the configuration. #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,37 @@
#include <vector>
#include <list>
#include <fstream>
#include <unistd.h>
#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[0], 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;
Expand All @@ -26,10 +48,11 @@ 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;
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);
Expand Down