summaryrefslogtreecommitdiff
path: root/plugins/mapexport
diff options
context:
space:
mode:
authorMike Stewart2012-01-28 23:55:42 -0800
committerMike Stewart2012-01-28 23:55:42 -0800
commit05c37af4c9dc9724b31ffdc28fe7374923b6cd03 (patch)
treecac7f6cad5847dac62019b0ed818f5b7d66f841f /plugins/mapexport
parentbd26c54259461b632023c5f655fad514f6e536e3 (diff)
downloaddfhack-05c37af4c9dc9724b31ffdc28fe7374923b6cd03.tar.gz
dfhack-05c37af4c9dc9724b31ffdc28fe7374923b6cd03.tar.bz2
dfhack-05c37af4c9dc9724b31ffdc28fe7374923b6cd03.tar.xz
Mapexport now puts stuff out to a binary file compressed with zlib. Added liquid type and flow size to output as well.
Diffstat (limited to 'plugins/mapexport')
-rw-r--r--plugins/mapexport/CMakeLists.txt9
-rw-r--r--plugins/mapexport/mapexport.cpp55
-rw-r--r--plugins/mapexport/proto/Block.proto2
-rw-r--r--plugins/mapexport/proto/Map.proto4
-rw-r--r--plugins/mapexport/proto/Tile.proto7
5 files changed, 43 insertions, 34 deletions
diff --git a/plugins/mapexport/CMakeLists.txt b/plugins/mapexport/CMakeLists.txt
index 68422f5b..dcb0bd77 100644
--- a/plugins/mapexport/CMakeLists.txt
+++ b/plugins/mapexport/CMakeLists.txt
@@ -1,8 +1,13 @@
PROJECT(mapexport)
-include_directories (
+INCLUDE_DIRECTORIES (
${CMAKE_CURRENT_SOURCE_DIR}
${dfhack_SOURCE_DIR}/library/depends/protobuf/
+ ${dfhack_SOURCE_DIR}/library/depends/zlib/
+)
+
+LINK_DIRECTORIES(
+ ${dfhack_SOURCE_DIR}/library/depends/zlib/
)
#The protobuf sources we generate will require these headers
@@ -43,4 +48,4 @@ COMMAND protoc-bin -I=${CMAKE_CURRENT_SOURCE_DIR}/proto/ --cpp_out=${CMAKE_CURRE
DEPENDS protoc-bin ${PROJECT_PROTOS}
)
-DFHACK_PLUGIN(mapexport ${PROJECT_SRCS} ${PROJECT_HDRS} LINK_LIBRARIES protobuf)
+DFHACK_PLUGIN(mapexport ${PROJECT_SRCS} ${PROJECT_HDRS} LINK_LIBRARIES protobuf zlib)
diff --git a/plugins/mapexport/mapexport.cpp b/plugins/mapexport/mapexport.cpp
index b828eb23..6d82735f 100644
--- a/plugins/mapexport/mapexport.cpp
+++ b/plugins/mapexport/mapexport.cpp
@@ -8,12 +8,14 @@ using namespace DFHack;
#include <fstream>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
+#include <google/protobuf/io/gzip_stream.h>
using namespace google::protobuf::io;
#include "DataDefs.h"
#include "df/world.h"
#include "proto/Map.pb.h"
+#include "proto/Block.pb.h"
using namespace DFHack::Simple;
@@ -50,13 +52,6 @@ DFhackCExport command_result mapexport (Core * c, std::vector <std::string> & pa
return CR_OK;
}
}
- std::string filename;
- if (parameters.size() < 1)
- {
- c->con.printerr("Please supply a filename.\n");
- return CR_OK;
- }
- filename = parameters[0];
bool showHidden = true;
@@ -69,6 +64,15 @@ DFhackCExport command_result mapexport (Core * c, std::vector <std::string> & pa
return CR_FAILURE;
}
+ if (parameters.size() < 1)
+ {
+ c->con.printerr("Please supply a filename.\n");
+ c->Resume();
+ return CR_FAILURE;
+ }
+
+ std::string filename = parameters[0];
+
std::ofstream output_file(filename, std::ios::out | std::ios::trunc | std::ios::binary);
if (!output_file.is_open())
{
@@ -77,8 +81,10 @@ DFhackCExport command_result mapexport (Core * c, std::vector <std::string> & pa
return CR_FAILURE;
}
ZeroCopyOutputStream *raw_output = new OstreamOutputStream(&output_file);
- CodedOutputStream *coded_output = new CodedOutputStream(raw_output);
- coded_output->WriteLittleEndian32(0x50414DDF);
+ GzipOutputStream *zip_output = new GzipOutputStream(raw_output);
+ CodedOutputStream *coded_output = new CodedOutputStream(zip_output);
+
+ coded_output->WriteLittleEndian32(0x50414DDF); //Write our file header
Maps::getSize(x_max, y_max, z_max);
MapExtras::MapCache map;
@@ -89,8 +95,8 @@ DFhackCExport command_result mapexport (Core * c, std::vector <std::string> & pa
protomap.set_y_size(y_max);
protomap.set_z_size(z_max);
- //coded_output->WriteVarint32(protomap.ByteSize());
- //protomap.SerializeToCodedStream(coded_output);
+ coded_output->WriteVarint32(protomap.ByteSize());
+ protomap.SerializeToCodedStream(coded_output);
DFHack::t_feature blockFeatureGlobal;
DFHack::t_feature blockFeatureLocal;
@@ -109,10 +115,10 @@ DFhackCExport command_result mapexport (Core * c, std::vector <std::string> & pa
continue;
}
- dfproto::Block *protoblock = new dfproto::Block;
- protoblock->set_x(b_x);
- protoblock->set_y(b_y);
- protoblock->set_z(z);
+ dfproto::Block protoblock;
+ protoblock.set_x(b_x);
+ protoblock.set_y(b_y);
+ protoblock.set_z(z);
{ // Find features
uint32_t index = b->raw.global_feature;
@@ -141,39 +147,32 @@ DFhackCExport command_result mapexport (Core * c, std::vector <std::string> & pa
continue;
}
- dfproto::Tile *prototile = protoblock->add_tile();
+ dfproto::Tile *prototile = protoblock.add_tile();
prototile->set_x(x);
prototile->set_y(y);
// Check for liquid
if (des.bits.flow_size)
{
- //if (des.bits.liquid_type == df::tile_liquid::Magma)
-
- //else
+ prototile->set_liquid_type((dfproto::Tile::LiquidType)des.bits.liquid_type);
+ prototile->set_flow_size(des.bits.flow_size);
}
uint16_t type = b->TileTypeAt(coord);
const DFHack::TileRow *info = DFHack::getTileRow(type);
prototile->set_type((dfproto::Tile::TileType)info->shape);
- /*switch (info->shape)
- {
- case DFHack::WALL:
- prototile->set_type(dfproto::Tile::WALL);
- break;
- default:
- break;
- }*/
}
}
+ coded_output->WriteVarint32(protoblock.ByteSize());
+ protoblock.SerializeToCodedStream(coded_output);
} // block x
-
// Clean uneeded memory
map.trash();
} // block y
} // z
delete coded_output;
+ delete zip_output;
delete raw_output;
c->con.print("Map succesfully exported.\n");
diff --git a/plugins/mapexport/proto/Block.proto b/plugins/mapexport/proto/Block.proto
index 2403764b..cba809b5 100644
--- a/plugins/mapexport/proto/Block.proto
+++ b/plugins/mapexport/proto/Block.proto
@@ -9,4 +9,4 @@ message Block
required uint32 y = 2;
required uint32 z = 3;
repeated Tile tile = 4;
-}
+} \ No newline at end of file
diff --git a/plugins/mapexport/proto/Map.proto b/plugins/mapexport/proto/Map.proto
index eca5d2e2..e73dab5c 100644
--- a/plugins/mapexport/proto/Map.proto
+++ b/plugins/mapexport/proto/Map.proto
@@ -1,11 +1,9 @@
package dfproto;
option optimize_for = LITE_RUNTIME;
-import "Block.proto";
-
message Map
{
required uint32 x_size = 1;
required uint32 y_size = 2;
required uint32 z_size = 3;
-}
+} \ No newline at end of file
diff --git a/plugins/mapexport/proto/Tile.proto b/plugins/mapexport/proto/Tile.proto
index 75a117d8..b2de1c3a 100644
--- a/plugins/mapexport/proto/Tile.proto
+++ b/plugins/mapexport/proto/Tile.proto
@@ -29,8 +29,15 @@ message Tile
PEBLLES = 21;
ENDLESS_PIT = 22;
}
+ enum LiquidType
+ {
+ WATER = 0;
+ MAGMA = 1;
+ }
required uint32 x = 1;
required uint32 y = 2;
required TileType type = 3;
optional uint32 material = 4;
+ optional LiquidType liquid_type = 5;
+ optional uint32 flow_size = 6;
}