More work on getting the map exporter up to speed.

develop
Mike Stewart 2012-01-27 17:32:52 -08:00
parent e68cdee95b
commit b89cd43b85
5 changed files with 53 additions and 54 deletions

@ -1 +1 @@
Subproject commit 867e7de022af7a5cc623b360ae2b864df395316f Subproject commit 3da91078d44282fa096f71f3f1e44809f9699e3d

@ -6,6 +6,9 @@
using namespace DFHack; using namespace DFHack;
#include <fstream> #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 "DataDefs.h"
#include "df/world.h" #include "df/world.h"
@ -63,21 +66,30 @@ DFhackCExport command_result mapexport (Core * c, std::vector <std::string> & pa
c->Resume(); c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
Maps::getSize(x_max, y_max, z_max);
MapExtras::MapCache map;
DFHack::Materials *mats = c->getMaterials();
DFHack::Vegetation *veg = c->getVegetation(); std::ofstream output_file(filename, std::ios::out | std::ios::trunc | std::ios::binary);
if (veg->Start()) 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; dfproto::Map protomap;
protomap.set_x_size(x_max); protomap.set_x_size(x_max);
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());
//protomap.SerializeToCodedStream(coded_output);
DFHack::t_feature blockFeatureGlobal; DFHack::t_feature blockFeatureGlobal;
DFHack::t_feature blockFeatureLocal; DFHack::t_feature blockFeatureLocal;
@ -95,7 +107,7 @@ DFhackCExport command_result mapexport (Core * c, std::vector <std::string> & pa
continue; continue;
} }
dfproto::Block *protoblock = protomap.add_block(); dfproto::Block *protoblock = new dfproto::Block;
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);
@ -159,19 +171,9 @@ DFhackCExport command_result mapexport (Core * c, std::vector <std::string> & pa
} // block y } // block y
} // z } // z
std::ofstream output(filename, std::ios::out | std::ios::trunc | std::ios::binary); delete coded_output;
if (!output.is_open()) delete raw_output;
{
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;
}
c->con.print("Map succesfully exported.\n"); c->con.print("Map succesfully exported.\n");
c->Resume(); c->Resume();
return CR_OK; return CR_OK;

@ -1,5 +1,5 @@
package dfproto; package dfproto;
//option optimize_for = LITE_RUNTIME; option optimize_for = LITE_RUNTIME;
import "Tile.proto"; import "Tile.proto";

@ -1,5 +1,5 @@
package dfproto; package dfproto;
//option optimize_for = LITE_RUNTIME; option optimize_for = LITE_RUNTIME;
import "Block.proto"; import "Block.proto";
@ -8,5 +8,4 @@ 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;
repeated Block block = 4;
} }

@ -1,38 +1,36 @@
package dfproto; package dfproto;
//option optimize_for = LITE_RUNTIME; option optimize_for = LITE_RUNTIME;
message Tile 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 x = 1;
required uint32 y = 2; required uint32 y = 2;
required TileType type = 3;
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;
optional uint32 material = 4; optional uint32 material = 4;
} }