Skip to content

Commit 8396275

Browse files
committed
Implemented rendering of names.
1 parent 3349bee commit 8396275

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ find_package_handle_standard_args(LibSqlite3 DEFAULT_MSG LIBSQLITE3_LIBRARY LIB
2525

2626
mark_as_advanced(LIBSQLITE3_INCLUDE_DIR LIBSQLITE3_LIBRARY )
2727

28-
28+
find_package(Boost COMPONENTS filesystem)
2929

3030
include_directories(
3131
"${PROJECT_BINARY_DIR}"
3232
"${CMAKE_CURRENT_SOURCE_DIR}"
3333
"${CMAKE_CURRENT_BINARY_DIR}"
3434
${LIBSQLITE3_INCLUDE_DIRS}
35+
${Boost_INCLUDE_DIRS}
3536
)
3637

3738
set(mapper_HDRS
@@ -53,6 +54,7 @@ add_executable(minetest_mapper
5354
target_link_libraries(
5455
minetest_mapper
5556
${LIBSQLITE3_LIBRARIES}
57+
${Boost_LIBRARIES}
5658
gd
5759
z
5860
)

TileGenerator.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <iostream>
1515
#include <sstream>
1616
#include <zlib.h>
17+
#include <boost/filesystem.hpp>
1718
#include "TileGenerator.h"
1819

1920
using namespace std;
@@ -241,6 +242,9 @@ void TileGenerator::generate(const std::string &input, const std::string &output
241242
if (m_drawOrigin) {
242243
renderOrigin();
243244
}
245+
if (m_drawPlayers) {
246+
renderPlayers(input);
247+
}
244248
writeImage(output);
245249
}
246250

@@ -540,6 +544,48 @@ void TileGenerator::renderOrigin()
540544
gdImageArc(m_image, imageX, imageY, 12, 12, 0, 360, rgb2int(m_originColor.r, m_originColor.g, m_originColor.b));
541545
}
542546

547+
void TileGenerator::renderPlayers(const std::string &inputPath)
548+
{
549+
int color = rgb2int(m_playerColor.r, m_playerColor.g, m_playerColor.b);
550+
551+
string playersPath = inputPath + "players";
552+
boost::filesystem::path path(playersPath.c_str());
553+
boost::filesystem::directory_iterator end_iter;
554+
boost::filesystem::directory_iterator iter(path);
555+
for (; iter != end_iter; ++iter) {
556+
if (!boost::filesystem::is_directory(iter->status())) {
557+
string path = iter->path().string();
558+
559+
ifstream in;
560+
in.open(path.c_str(), ifstream::in);
561+
string buffer;
562+
string name;
563+
string position;
564+
while (getline(in, buffer)) {
565+
if (buffer.find("name = ") == 0) {
566+
name = buffer.substr(7);
567+
}
568+
else if (buffer.find("position = ") == 0) {
569+
position = buffer.substr(12, buffer.length() - 13);
570+
}
571+
}
572+
double x, y, z;
573+
char comma;
574+
istringstream positionStream(position, istringstream::in);
575+
positionStream >> x;
576+
positionStream >> comma;
577+
positionStream >> y;
578+
positionStream >> comma;
579+
positionStream >> z;
580+
int imageX = x / 10 - m_xMin * 16 + m_border;
581+
int imageY = m_mapHeight - (z / 10 - m_zMin * 16) + m_border;
582+
583+
gdImageArc(m_image, imageX, imageY, 5, 5, 0, 360, color);
584+
gdImageString(m_image, gdFontGetMediumBold(), imageX + 2, imageY + 2, reinterpret_cast<unsigned char *>(const_cast<char *>(name.c_str())), color);
585+
}
586+
}
587+
}
588+
543589
inline std::list<int> TileGenerator::getZValueList() const
544590
{
545591
std::list<int> zlist;

TileGenerator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ class TileGenerator
9999
void renderShading(int zPos);
100100
void renderScale();
101101
void renderOrigin();
102+
void renderPlayers(const std::string &inputPath);
102103
void writeImage(const std::string &output);
103104
int getImageX(int val) const;
104105
int getImageY(int val) const;

0 commit comments

Comments
 (0)