From 957a72e2b4344398fadd63b89042bc02606e2942 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bend=C3=ADk?= Date: Thu, 23 Aug 2012 12:55:31 +0200 Subject: [PATCH] Parsing of colors moved to TileGenerator. --- CMakeLists.txt | 6 ++++++ TileGenerator.cpp | 38 +++++++++++++++++++++++++++++++++++ TileGenerator.h | 13 ++++++++++++ mapper.cpp | 50 +---------------------------------------------- 4 files changed, 58 insertions(+), 49 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f677200..d526723 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,12 @@ cmake_minimum_required(VERSION 2.6) cmake_policy(SET CMP0003 NEW) set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) +if(CMAKE_COMPILER_IS_GNUCXX) + set(CMAKE_CXX_FLAGS_RELEASE "-std=c++0x -Wall -DNDEBUG") + set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -std=c++0x -Wall -Wextra -DDEBUG") +endif(CMAKE_COMPILER_IS_GNUCXX) + + find_package(PkgConfig) pkg_check_modules(PC_LIBSQLITE QUIET sqlite3) set(LIBSQLITE3_DEFINITIONS ${PC_LIBSQLITE_CFLAGS_OTHER}) diff --git a/TileGenerator.cpp b/TileGenerator.cpp index 030d1e1..cd8b14d 100644 --- a/TileGenerator.cpp +++ b/TileGenerator.cpp @@ -7,8 +7,13 @@ * ===================================================================== */ +#include +#include +#include #include "TileGenerator.h" +using namespace std; + TileGenerator::TileGenerator(): m_bgColor("#ffffff"), m_scaleColor("#000000"), @@ -70,3 +75,36 @@ void TileGenerator::generate(const std::string &/*input*/, const std::string &/* { } +void TileGenerator::parseColorsFile(const std::string &fileName) +{ + ifstream in; + in.open(fileName.c_str(), ifstream::in); + if (!in.is_open()) { + std::cerr << "File colors.txt does not exist" << std::endl; + exit(-2); + } + + while (in.good()) { + string name; + Color color; + in >> name; + if (name[0] == '#') { + in.ignore(65536, '\n'); + in >> name; + } + while (name == "\n" && in.good()) { + in >> name; + } + int r, g, b; + in >> r; + in >> g; + in >> b; + if (in.good()) { + m_colors[name] = color; + color.r = r; + color.g = g; + color.b = b; + } + } +} + diff --git a/TileGenerator.h b/TileGenerator.h index 047db31..346feb8 100644 --- a/TileGenerator.h +++ b/TileGenerator.h @@ -10,10 +10,21 @@ #ifndef TILEGENERATOR_H_JJNUCARH #define TILEGENERATOR_H_JJNUCARH +#include #include +#include + +struct Color { + uint8_t r; + uint8_t g; + uint8_t b; +}; class TileGenerator { +private: + typedef std::map ColorMap; + public: TileGenerator(); ~TileGenerator(); @@ -26,6 +37,7 @@ public: void setDrawScale(bool drawScale); void setDrawUnderground(bool drawUnderground); void generate(const std::string &input, const std::string &output); + void parseColorsFile(const std::string &fileName); private: std::string m_bgColor; @@ -36,6 +48,7 @@ private: bool m_drawPlayers; bool m_drawScale; bool m_drawUnderground; + ColorMap m_colors; }; /* ----- end of class TileGenerator ----- */ #endif /* end of include guard: TILEGENERATOR_H_JJNUCARH */ diff --git a/mapper.cpp b/mapper.cpp index 1721671..848cb5d 100644 --- a/mapper.cpp +++ b/mapper.cpp @@ -8,61 +8,14 @@ */ #include -#include #include #include #include -#include #include #include "TileGenerator.h" using namespace std; -struct Color { - uint8_t r; - uint8_t g; - uint8_t b; -}; - -typedef map ColorMap; - -ColorMap parse_colors() -{ - ColorMap parsed; - - ifstream in; - in.open("colors.txt", ifstream::in); - if (!in.is_open()) { - std::cerr << "File colors.txt does not exist" << std::endl; - exit(-2); - } - - while (in.good()) { - string name; - Color color; - in >> name; - if (name[0] == '#') { - in.ignore(65536, '\n'); - in >> name; - } - while (name == "\n" && in.good()) { - in >> name; - } - int r, g, b; - in >> r; - in >> g; - in >> b; - if (in.good()) { - parsed[name] = color; - color.r = r; - color.g = g; - color.b = b; - } - } - - return parsed; -} - void usage() { const char *usage_text = "minetestmapper.py [options]\n\ @@ -101,6 +54,7 @@ int main(int argc, char *argv[]) string output; TileGenerator generator; + generator.parseColorsFile("colors.txt"); int option_index = 0; int c = 0; while (1) { @@ -151,6 +105,4 @@ int main(int argc, char *argv[]) abort(); } } - - ColorMap colors = parse_colors(); }