diff --git a/src/config.cpp b/src/config.cpp index 69fc670..5ee49f0 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -6,7 +6,7 @@ namespace config { unsigned int seed = 0; double resolution = 0.08; std::string outfileExt = ".png"; -std::string outfile = "output" + outfileExt; +std::string outfile = "output"; double erosionAmount = -1.0; int erosionIterations = 3; int numCities = -1; @@ -23,6 +23,8 @@ bool enableCities = true; bool enableTowns = true; bool enableLabels = true; bool enableAreaLabels = true; +bool withSvgOutput = false; +bool enableSvgColors = false; bool verbose = false; void print(std::string msg) { @@ -55,6 +57,8 @@ bool parseOptions(int argc, char **argv) { opts.nolabels = arg_litn(NULL, "no-labels", 0, 1, "disable label drawing"), opts.noarealabels = arg_litn(NULL, "no-arealabels", 0, 1, "disable area label drawing"), opts.drawinfo = arg_litn(NULL, "drawing-supported", 0, 1, "display whether drawing is supported and exit"), + opts.withsvg = arg_litn(NULL, "with-svg", 0, 1, "additional output in svg format"), + opts.svgcolors = arg_litn(NULL, "svg-colors", 0, 1, "enable colors in svg output"), opts.verbose = arg_litn("v", "verbose", 0, 1, "output additional information to stdout"), opts.end = arg_end(20) }; @@ -138,6 +142,8 @@ bool _setOptions(OptionArgs opts) { if (!_disableTowns(opts.notowns)) { return false; } if (!_disableLabels(opts.nolabels)) { return false; } if (!_disableAreaLabels(opts.noarealabels)) { return false; } + if (!_enableWithSvg(opts.withsvg)) { return false; } + if (!_enableSvgColors(opts.svgcolors)) { return false; } if (!_setVerbosity(opts.verbose)) { return false; } return true; @@ -377,6 +383,22 @@ bool _disableAreaLabels(arg_lit *noarealabels) { return true; } +bool _enableWithSvg(arg_lit *withsvg) { + if (withsvg->count > 0) { + gen::config::withSvgOutput = true; + } + + return true; +} + +bool _enableSvgColors(arg_lit *svgcolors) { + if (svgcolors->count > 0) { + gen::config::enableSvgColors = true; + } + + return true; +} + bool _setVerbosity(arg_lit *verbose) { if (verbose->count > 0) { gen::config::verbose = true; @@ -386,4 +408,4 @@ bool _setVerbosity(arg_lit *verbose) { } } -} \ No newline at end of file +} diff --git a/src/config.h b/src/config.h index d723419..a947f3b 100644 --- a/src/config.h +++ b/src/config.h @@ -32,6 +32,8 @@ struct OptionArgs { struct arg_lit *nolabels; struct arg_lit *noarealabels; struct arg_lit *drawinfo; + struct arg_lit *withsvg; + struct arg_lit *svgcolors; struct arg_lit *verbose; struct arg_end *end; }; @@ -56,6 +58,8 @@ extern bool enableCities; extern bool enableTowns; extern bool enableLabels; extern bool enableAreaLabels; +extern bool withSvgOutput; +extern bool enableSvgColors; extern bool verbose; template @@ -88,9 +92,11 @@ bool _disableCities(arg_lit *nocities); bool _disableTowns(arg_lit *notowns); bool _disableLabels(arg_lit *nolabels); bool _disableAreaLabels(arg_lit *noarealabels); +bool _enableWithSvg(arg_lit *withsvg); +bool _enableSvgColors(arg_lit *svgcolors); bool _setVerbosity(arg_lit *verbose); } } -#endif \ No newline at end of file +#endif diff --git a/src/main.cpp b/src/main.cpp index 37edde3..c9d8a7a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -36,22 +36,30 @@ void outputMap(gen::MapGenerator &map) { gen::config::print("Finished Generating map draw data in " + gen::config::toString(timer.getTime()) + " seconds.\n"); - std::string outfile = gen::config::outfile; - std::string outfileExt = gen::config::outfileExt; + if (gen::config::withSvgOutput) + { + std::string svg_outfile = gen::config::outfile + ".svg"; + timer.reset(); + timer.start(); + gen::config::print("Exporting map as svg..."); + map.outputSvgData(svg_outfile); + timer.stop(); + gen::config::print("Finished exporting to svg in " + + gen::config::toString(timer.getTime()) + " seconds.\n"); + + gen::config::print("Wrote svg to file: " + svg_outfile); + } #ifdef PYTHON_RENDERING_SUPPORTED - if (outfileExt != std::string(".png")) { - outfile += ".png"; - } - + std::string png_outfile = gen::config::outfile + ".png"; timer.reset(); timer.start(); gen::config::print("Drawing map..."); - gen::render::drawMap(drawdata, outfile); + gen::render::drawMap(drawdata, png_outfile); timer.stop(); gen::config::print("Finished drawing map in " + gen::config::toString(timer.getTime()) + " seconds.\n"); - gen::config::print("Wrote map to image: " + outfile); + gen::config::print("Wrote map to image: " + png_outfile); #else if (outfileExt != std::string(".json")) { outfile += ".json"; diff --git a/src/mapgenerator.cpp b/src/mapgenerator.cpp index 9728d99..cce06dc 100644 --- a/src/mapgenerator.cpp +++ b/src/mapgenerator.cpp @@ -364,6 +364,204 @@ std::vector gen::MapGenerator::getDrawData() { return charvect; } +void gen::MapGenerator::outputSvgData(std::string filename) { + if (!_isInitialized) { + throw std::runtime_error("MapGenerator must be initialized."); + } + + if (!_isHeightMapEroded) { + erode(0.0); + } + + std::vector > contourData; + if (_isContourEnabled) { + _getContourDrawData(contourData); + _contourData = contourData; + } + + std::vector > riverData; + if (_isRiversEnabled) { + _getRiverDrawData(riverData); + _riverData = riverData; + } + + std::vector slopeData; + if (_isSlopesEnabled) { + _getSlopeDrawData(slopeData); + } + + std::vector cityData; + if (_isCitiesEnabled) { + _getCityDrawData(cityData); + } + + std::vector townData; + if (_isTownsEnabled) { + _getTownDrawData(townData); + } + + std::vector > territoryData; + _getTerritoryDrawData(territoryData); + _borderData = territoryData; + if (!_isBordersEnabled) { + territoryData.clear(); + } + + std::vector