Skip to content

Commit 9fb61d5

Browse files
committed
path
1 parent f25bcc6 commit 9fb61d5

3 files changed

Lines changed: 27 additions & 6 deletions

File tree

include/mapgen/Painter.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

src/MapGenerator.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -732,13 +732,11 @@ void MapGenerator::makeRiver(Region *r) {
732732
rvr->regions.push_back(r);
733733
r->humidity = 1;
734734

735-
if (end != nullptr) {
736735
for (auto n : end->getNeighbors()) {
737736
r = _cells[n];
738737
r->biom = biom::LAKE;
739738
r->humidity = 1;
740739
}
741-
}
742740
break;
743741
}
744742
if (r->getHeight(r->site) < 0.0625) {

src/Painter.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,14 @@ class Painter {
3636
// TODO: use map instead mapgen
3737
Painter(sf::RenderWindow *w, MapGenerator *m, std::string v)
3838
: window(w), mapgen(m), VERSION(v) {
39+
40+
auto dir = get_selfpath();
41+
char path[100];
42+
sprintf(path, "%s/font.ttf", dir.c_str());
43+
mg::info("Loading font:", path);
44+
sffont.loadFromFile(path);
3945
loadIcons();
4046
initProgressBar();
41-
// TODO: use whereami
42-
sffont.loadFromFile("./font.ttf");
4347

4448
sf::Vector2u windowSize = window->getSize();
4549
cachedMap.create(windowSize.x, windowSize.y);
@@ -66,6 +70,20 @@ class Painter {
6670
sf::Clock clock;
6771
std::vector<Walker*> walkers;
6872

73+
std::string get_selfpath() {
74+
char buff[PATH_MAX];
75+
#ifdef _WIN32
76+
GetModuleFileName(NULL,buff,sizeof(buff));
77+
#else
78+
ssize_t len = ::readlink("/proc/self/exe", buff, sizeof(buff)-1);
79+
if (len != -1) {
80+
buff[len] = '\0';
81+
}
82+
#endif
83+
auto path = std::string(buff);
84+
return path.substr(0, path.size()-7);
85+
}
86+
6987
void initProgressBar() {
7088
progressBar.setShowBackgroundAndFrame(true);
7189
progressBar.setSize(sf::Vector2f(400, 10));
@@ -80,10 +98,14 @@ class Painter {
8098
{TRADE, "images/trade.png"}, {LIGHTHOUSE, "images/lighthouse.png"},
8199
{CAVE, "images/cave.png"}, {FORT, "images/fort.png"}};
82100

101+
auto dir = get_selfpath();
102+
char path[100];
103+
83104
for (auto pair : iconMap) {
84105
sf::Texture *icon = new sf::Texture();
85-
mg::info("Loading icon:", pair.second);
86-
icon->loadFromFile(pair.second);
106+
sprintf(path, "%s/%s", dir.c_str(), pair.second.c_str());
107+
mg::info("Loading icon:", path);
108+
icon->loadFromFile(path);
87109
icon->setSmooth(true);
88110
icons.insert(std::make_pair(pair.first, icon));
89111
}

0 commit comments

Comments
 (0)