Mapexport now puts stuff out to a binary file compressed with zlib. Added liquid type and flow size to output as well.

develop
Mike Stewart 2012-01-28 23:55:42 -08:00
parent bd26c54259
commit 05c37af4c9
7 changed files with 45 additions and 35 deletions

@ -199,6 +199,7 @@ google/protobuf/compiler/zip_writer.cc
LIST(APPEND LIBPROTOBUF_FULL_SRCS ${LIBPROTOBUF_LITE_SRCS}) LIST(APPEND LIBPROTOBUF_FULL_SRCS ${LIBPROTOBUF_LITE_SRCS})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
INCLUDE_DIRECTORIES(${dfhack_SOURCE_DIR}/library/depends/zlib)
ADD_LIBRARY(protobuf-lite ${LIBPROTOBUF_LITE_SRCS} ${LIBPROTOBUF_LITE_HDRS}) ADD_LIBRARY(protobuf-lite ${LIBPROTOBUF_LITE_SRCS} ${LIBPROTOBUF_LITE_HDRS})
ADD_LIBRARY(protobuf ${LIBPROTOBUF_FULL_SRCS} ${LIBPROTOBUF_FULL_HDRS}) ADD_LIBRARY(protobuf ${LIBPROTOBUF_FULL_SRCS} ${LIBPROTOBUF_FULL_HDRS})

@ -9,4 +9,4 @@
/* define if you want to use zlib. See readme.txt for additional /* define if you want to use zlib. See readme.txt for additional
* requirements. */ * requirements. */
// #define HAVE_ZLIB 1 #define HAVE_ZLIB 1

@ -1,8 +1,13 @@
PROJECT(mapexport) PROJECT(mapexport)
include_directories ( INCLUDE_DIRECTORIES (
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
${dfhack_SOURCE_DIR}/library/depends/protobuf/ ${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 #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} 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)

@ -8,12 +8,14 @@ using namespace DFHack;
#include <fstream> #include <fstream>
#include <google/protobuf/io/coded_stream.h> #include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl.h> #include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/io/gzip_stream.h>
using namespace google::protobuf::io; using namespace google::protobuf::io;
#include "DataDefs.h" #include "DataDefs.h"
#include "df/world.h" #include "df/world.h"
#include "proto/Map.pb.h" #include "proto/Map.pb.h"
#include "proto/Block.pb.h"
using namespace DFHack::Simple; using namespace DFHack::Simple;
@ -50,13 +52,6 @@ DFhackCExport command_result mapexport (Core * c, std::vector <std::string> & pa
return CR_OK; 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; bool showHidden = true;
@ -69,6 +64,15 @@ DFhackCExport command_result mapexport (Core * c, std::vector <std::string> & pa
return CR_FAILURE; 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); std::ofstream output_file(filename, std::ios::out | std::ios::trunc | std::ios::binary);
if (!output_file.is_open()) if (!output_file.is_open())
{ {
@ -77,8 +81,10 @@ DFhackCExport command_result mapexport (Core * c, std::vector <std::string> & pa
return CR_FAILURE; return CR_FAILURE;
} }
ZeroCopyOutputStream *raw_output = new OstreamOutputStream(&output_file); ZeroCopyOutputStream *raw_output = new OstreamOutputStream(&output_file);
CodedOutputStream *coded_output = new CodedOutputStream(raw_output); GzipOutputStream *zip_output = new GzipOutputStream(raw_output);
coded_output->WriteLittleEndian32(0x50414DDF); CodedOutputStream *coded_output = new CodedOutputStream(zip_output);
coded_output->WriteLittleEndian32(0x50414DDF); //Write our file header
Maps::getSize(x_max, y_max, z_max); Maps::getSize(x_max, y_max, z_max);
MapExtras::MapCache map; 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_y_size(y_max);
protomap.set_z_size(z_max); protomap.set_z_size(z_max);
//coded_output->WriteVarint32(protomap.ByteSize()); coded_output->WriteVarint32(protomap.ByteSize());
//protomap.SerializeToCodedStream(coded_output); protomap.SerializeToCodedStream(coded_output);
DFHack::t_feature blockFeatureGlobal; DFHack::t_feature blockFeatureGlobal;
DFHack::t_feature blockFeatureLocal; DFHack::t_feature blockFeatureLocal;
@ -109,10 +115,10 @@ DFhackCExport command_result mapexport (Core * c, std::vector <std::string> & pa
continue; continue;
} }
dfproto::Block *protoblock = new dfproto::Block; dfproto::Block protoblock;
protoblock->set_x(b_x); protoblock.set_x(b_x);
protoblock->set_y(b_y); protoblock.set_y(b_y);
protoblock->set_z(z); protoblock.set_z(z);
{ // Find features { // Find features
uint32_t index = b->raw.global_feature; uint32_t index = b->raw.global_feature;
@ -141,39 +147,32 @@ DFhackCExport command_result mapexport (Core * c, std::vector <std::string> & pa
continue; continue;
} }
dfproto::Tile *prototile = protoblock->add_tile(); dfproto::Tile *prototile = protoblock.add_tile();
prototile->set_x(x); prototile->set_x(x);
prototile->set_y(y); prototile->set_y(y);
// Check for liquid // Check for liquid
if (des.bits.flow_size) if (des.bits.flow_size)
{ {
//if (des.bits.liquid_type == df::tile_liquid::Magma) prototile->set_liquid_type((dfproto::Tile::LiquidType)des.bits.liquid_type);
prototile->set_flow_size(des.bits.flow_size);
//else
} }
uint16_t type = b->TileTypeAt(coord); uint16_t type = b->TileTypeAt(coord);
const DFHack::TileRow *info = DFHack::getTileRow(type); const DFHack::TileRow *info = DFHack::getTileRow(type);
prototile->set_type((dfproto::Tile::TileType)info->shape); 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 } // block x
// Clean uneeded memory // Clean uneeded memory
map.trash(); map.trash();
} // block y } // block y
} // z } // z
delete coded_output; delete coded_output;
delete zip_output;
delete raw_output; delete raw_output;
c->con.print("Map succesfully exported.\n"); c->con.print("Map succesfully exported.\n");

@ -9,4 +9,4 @@ message Block
required uint32 y = 2; required uint32 y = 2;
required uint32 z = 3; required uint32 z = 3;
repeated Tile tile = 4; repeated Tile tile = 4;
} }

@ -1,11 +1,9 @@
package dfproto; package dfproto;
option optimize_for = LITE_RUNTIME; option optimize_for = LITE_RUNTIME;
import "Block.proto";
message Map message Map
{ {
required uint32 x_size = 1; required uint32 x_size = 1;
required uint32 y_size = 2; required uint32 y_size = 2;
required uint32 z_size = 3; required uint32 z_size = 3;
} }

@ -29,8 +29,15 @@ message Tile
PEBLLES = 21; PEBLLES = 21;
ENDLESS_PIT = 22; ENDLESS_PIT = 22;
} }
enum LiquidType
{
WATER = 0;
MAGMA = 1;
}
required uint32 x = 1; required uint32 x = 1;
required uint32 y = 2; required uint32 y = 2;
required TileType type = 3; required TileType type = 3;
optional uint32 material = 4; optional uint32 material = 4;
optional LiquidType liquid_type = 5;
optional uint32 flow_size = 6;
} }