diff options
| author | Mike Stewart | 2012-01-27 17:32:52 -0800 |
|---|---|---|
| committer | Mike Stewart | 2012-01-27 17:32:52 -0800 |
| commit | b89cd43b85e7c51ccaa8dca3c61c85615e76b1fc (patch) | |
| tree | 4e483a160ac81d52d13c7771281aecd9a3968a7d /plugins/mapexport | |
| parent | e68cdee95bdd2c09c475293c19c12a68e9bec546 (diff) | |
| download | dfhack-b89cd43b85e7c51ccaa8dca3c61c85615e76b1fc.tar.gz dfhack-b89cd43b85e7c51ccaa8dca3c61c85615e76b1fc.tar.bz2 dfhack-b89cd43b85e7c51ccaa8dca3c61c85615e76b1fc.tar.xz | |
More work on getting the map exporter up to speed.
Diffstat (limited to 'plugins/mapexport')
| -rw-r--r-- | plugins/mapexport/mapexport.cpp | 42 | ||||
| -rw-r--r-- | plugins/mapexport/proto/Block.proto | 2 | ||||
| -rw-r--r-- | plugins/mapexport/proto/Map.proto | 3 | ||||
| -rw-r--r-- | plugins/mapexport/proto/Tile.proto | 58 |
4 files changed, 52 insertions, 53 deletions
diff --git a/plugins/mapexport/mapexport.cpp b/plugins/mapexport/mapexport.cpp index 576a6f98..219e02ce 100644 --- a/plugins/mapexport/mapexport.cpp +++ b/plugins/mapexport/mapexport.cpp @@ -6,6 +6,9 @@ using namespace DFHack; #include <fstream> +#include <google/protobuf/io/coded_stream.h> +#include <google/protobuf/io/zero_copy_stream_impl.h> +using namespace google::protobuf::io; #include "DataDefs.h" #include "df/world.h" @@ -63,21 +66,30 @@ DFhackCExport command_result mapexport (Core * c, std::vector <std::string> & pa c->Resume(); return CR_FAILURE; } - Maps::getSize(x_max, y_max, z_max); - MapExtras::MapCache map; - DFHack::Materials *mats = c->getMaterials(); - DFHack::Vegetation *veg = c->getVegetation(); - if (veg->Start()) + std::ofstream output_file(filename, std::ios::out | std::ios::trunc | std::ios::binary); + if (!output_file.is_open()) { - c->con.printerr("Unable to read vegetation; plants won't be listed!\n" ); + c->con.printerr("Couldn't open the output file.\n"); + c->Resume(); + return CR_FAILURE; } + ZeroCopyOutputStream *raw_output = new OstreamOutputStream(&output_file); + CodedOutputStream *coded_output = new CodedOutputStream(raw_output); + coded_output->WriteLittleEndian32(0x50414DDF); + + Maps::getSize(x_max, y_max, z_max); + MapExtras::MapCache map; + DFHack::Materials *mats = c->getMaterials(); dfproto::Map protomap; protomap.set_x_size(x_max); protomap.set_y_size(y_max); protomap.set_z_size(z_max); + //coded_output->WriteVarint32(protomap.ByteSize()); + //protomap.SerializeToCodedStream(coded_output); + DFHack::t_feature blockFeatureGlobal; DFHack::t_feature blockFeatureLocal; @@ -95,7 +107,7 @@ DFhackCExport command_result mapexport (Core * c, std::vector <std::string> & pa continue; } - dfproto::Block *protoblock = protomap.add_block(); + dfproto::Block *protoblock = new dfproto::Block; protoblock->set_x(b_x); protoblock->set_y(b_y); protoblock->set_z(z); @@ -159,19 +171,9 @@ DFhackCExport command_result mapexport (Core * c, std::vector <std::string> & pa } // block y } // z - std::ofstream output(filename, std::ios::out | std::ios::trunc | std::ios::binary); - if (!output.is_open()) - { - c->con.printerr("Couldn't open the output file.\n"); - c->Resume(); - return CR_FAILURE; - } - if (!protomap.SerializeToOstream(&output)) - { - c->con.printerr("Failed to save map file.\n"); - c->Resume(); - return CR_FAILURE; - } + delete coded_output; + delete raw_output; + c->con.print("Map succesfully exported.\n"); c->Resume(); return CR_OK; diff --git a/plugins/mapexport/proto/Block.proto b/plugins/mapexport/proto/Block.proto index 7a73d33b..2403764b 100644 --- a/plugins/mapexport/proto/Block.proto +++ b/plugins/mapexport/proto/Block.proto @@ -1,5 +1,5 @@ package dfproto; -//option optimize_for = LITE_RUNTIME; +option optimize_for = LITE_RUNTIME; import "Tile.proto"; diff --git a/plugins/mapexport/proto/Map.proto b/plugins/mapexport/proto/Map.proto index 8801dafa..eca5d2e2 100644 --- a/plugins/mapexport/proto/Map.proto +++ b/plugins/mapexport/proto/Map.proto @@ -1,5 +1,5 @@ package dfproto; -//option optimize_for = LITE_RUNTIME; +option optimize_for = LITE_RUNTIME; import "Block.proto"; @@ -8,5 +8,4 @@ message Map required uint32 x_size = 1; required uint32 y_size = 2; required uint32 z_size = 3; - repeated Block block = 4; } diff --git a/plugins/mapexport/proto/Tile.proto b/plugins/mapexport/proto/Tile.proto index ecf8c2e5..75a117d8 100644 --- a/plugins/mapexport/proto/Tile.proto +++ b/plugins/mapexport/proto/Tile.proto @@ -1,38 +1,36 @@ package dfproto; -//option optimize_for = LITE_RUNTIME; +option optimize_for = LITE_RUNTIME; message Tile { + enum TileType + { + EMPTY = 0; + WALL = 1; + PILLAR = 2; + BROOK_BED = 3; + FORTIFICATION = 4; + STAIR_UP = 5; + STAIR_DOWN = 6; + STAIR_UPDOWN = 7; + RAMP = 8; + RAMP_TOP = 9; + FLOOR = 10; + BROOK_TOP = 11; + RIVER_BED = 12; + POOL = 13; + TREE_DEAD = 14; + TREE_OK = 15; + SAPLING_DEAD = 16; + SAPLING_OK = 17; + SHRUB_DEAD = 18; + SHRUB_OK = 19; + BOULDER = 20; + PEBLLES = 21; + ENDLESS_PIT = 22; + } required uint32 x = 1; required uint32 y = 2; - - enum TileType - { - EMPTY = 0; - WALL = 1; - PILLAR = 2; - BROOK_BED = 3; - FORTIFICATION = 4; - STAIR_UP = 5; - STAIR_DOWN = 6; - STAIR_UPDOWN = 7; - RAMP = 8; - RAMP_TOP = 9; - FLOOR = 10; - BROOK_TOP = 11; - RIVER_BED = 12; - POOL = 13; - TREE_DEAD = 14; - TREE_OK = 15; - SAPLING_DEAD = 16; - SAPLING_OK = 17; - SHRUB_DEAD = 18; - SHRUB_OK = 19; - BOULDER = 20; - PEBLLES = 21; - ENDLESS_PIT = 22; - } - required TileType type = 3; - + required TileType type = 3; optional uint32 material = 4; } |
