File colors.txt compiled into binary

This commit is contained in:
Miroslav Bendík 2012-09-01 15:51:02 +02:00
parent 4a8c041bc1
commit 112ccc5d08
3 changed files with 58 additions and 28 deletions

@ -25,6 +25,27 @@ find_package_handle_standard_args(LibSqlite3 DEFAULT_MSG LIBSQLITE3_LIBRARY LIB
mark_as_advanced(LIBSQLITE3_INCLUDE_DIR LIBSQLITE3_LIBRARY) mark_as_advanced(LIBSQLITE3_INCLUDE_DIR LIBSQLITE3_LIBRARY)
if (LIBSQLITE3_INCLUDE_DIR)
else (LIBSQLITE3_INCLUDE_DIR)
message(FATAL_ERROR "Could not find sqlite3")
endif (LIBSQLITE3_INCLUDE_DIR)
find_program(XXD_EXECUTABLE xxd)
if (XXD_EXECUTABLE)
message(STATUS "Found xxd")
else (XXD_EXECUTABLE)
message(FATAL_ERROR "Executable xxd not found")
endif (XXD_EXECUTABLE)
add_custom_command(
OUTPUT colors.h
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/colors.txt colors.txt
COMMAND xxd -i colors.txt colors.h
DEPENDS colors.txt
)
set_property(SOURCE TileGenerator.cpp APPEND PROPERTY OBJECT_DEPENDS colors.h)
include_directories( include_directories(
"${PROJECT_BINARY_DIR}" "${PROJECT_BINARY_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}"

@ -17,6 +17,7 @@
#include <dirent.h> #include <dirent.h>
#include "config.h" #include "config.h"
#include "TileGenerator.h" #include "TileGenerator.h"
#include "colors.h"
using namespace std; using namespace std;
@ -132,6 +133,9 @@ TileGenerator::TileGenerator():
m_zMin(0), m_zMin(0),
m_zMax(0) m_zMax(0)
{ {
string colors_txt_data(reinterpret_cast<char *>(colors_txt), colors_txt_len);
istringstream colors_stream(colors_txt_data);
parseColorsStream(colors_stream);
} }
TileGenerator::~TileGenerator() TileGenerator::~TileGenerator()
@ -203,32 +207,9 @@ void TileGenerator::parseColorsFile(const std::string &fileName)
ifstream in; ifstream in;
in.open(fileName.c_str(), ifstream::in); in.open(fileName.c_str(), ifstream::in);
if (!in.is_open()) { if (!in.is_open()) {
std::cerr << "File colors.txt does not exist" << std::endl; return;
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()) {
color.r = r;
color.g = g;
color.b = b;
m_colors[name] = color;
}
} }
parseColorsStream(in);
} }
void TileGenerator::generate(const std::string &input, const std::string &output) void TileGenerator::generate(const std::string &input, const std::string &output)
@ -255,6 +236,32 @@ void TileGenerator::generate(const std::string &input, const std::string &output
printUnknown(); printUnknown();
} }
void TileGenerator::parseColorsStream(std::istream &in)
{
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()) {
color.r = r;
color.g = g;
color.b = b;
m_colors[name] = color;
}
}
}
void TileGenerator::openDb(const std::string &input) void TileGenerator::openDb(const std::string &input)
{ {
string db_name = input + "map.sqlite"; string db_name = input + "map.sqlite";

@ -11,12 +11,13 @@
#define TILEGENERATOR_H_JJNUCARH #define TILEGENERATOR_H_JJNUCARH
#include <gd.h> #include <gd.h>
#include <iosfwd>
#include <list> #include <list>
#include <map> #include <map>
#include <set>
#include <sqlite3.h> #include <sqlite3.h>
#include <stdint.h> #include <stdint.h>
#include <string> #include <string>
#include <set>
#include "PixelAttributes.h" #include "PixelAttributes.h"
struct Color { struct Color {
@ -89,6 +90,7 @@ public:
void generate(const std::string &input, const std::string &output); void generate(const std::string &input, const std::string &output);
private: private:
void parseColorsStream(std::istream &in);
void openDb(const std::string &input); void openDb(const std::string &input);
void loadBlocks(); void loadBlocks();
BlockPos decodeBlockPos(sqlite3_int64 blockId) const; BlockPos decodeBlockPos(sqlite3_int64 blockId) const;