X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fmg_schematic.h;h=5c732648edaadd561bf3451af186e08c243ac21f;hb=868a1a5c13a0c086aa1ff3414a1eb12076821c27;hp=8a495fef2e1fec2b011219c86b5935ccae3fe96d;hpb=9e811a92e7846b958e4bc84aeb30bad8b51e8e1d;p=dragonfireclient.git diff --git a/src/mg_schematic.h b/src/mg_schematic.h index 8a495fef2..5c732648e 100644 --- a/src/mg_schematic.h +++ b/src/mg_schematic.h @@ -26,62 +26,122 @@ with this program; if not, write to the Free Software Foundation, Inc., class Map; class Mapgen; -class ManualMapVoxelManipulator; +class MMVManip; class PseudoRandom; class NodeResolver; +class IGameDef; -/////////////////// Decoration flags -#define DECO_PLACE_CENTER_X 1 -#define DECO_PLACE_CENTER_Y 2 -#define DECO_PLACE_CENTER_Z 4 -#define DECO_SCHEM_CIDS_UPDATED 8 - +/* + Minetest Schematic File Format + + All values are stored in big-endian byte order. + [u32] signature: 'MTSM' + [u16] version: 4 + [u16] size X + [u16] size Y + [u16] size Z + For each Y: + [u8] slice probability value + [Name-ID table] Name ID Mapping Table + [u16] name-id count + For each name-id mapping: + [u16] name length + [u8[]] name + ZLib deflated { + For each node in schematic: (for z, y, x) + [u16] content + For each node in schematic: + [u8] param1 + bit 0-6: probability + bit 7: specific node force placement + For each node in schematic: + [u8] param2 + } + + Version changes: + 1 - Initial version + 2 - Fixed messy never/always place; 0 probability is now never, 0xFF is always + 3 - Added y-slice probabilities; this allows for variable height structures + 4 - Compressed range of node occurence prob., added per-node force placement bit +*/ +//// Schematic constants #define MTSCHEM_FILE_SIGNATURE 0x4d54534d // 'MTSM' -#define MTSCHEM_FILE_VER_HIGHEST_READ 3 -#define MTSCHEM_FILE_VER_HIGHEST_WRITE 3 +#define MTSCHEM_FILE_VER_HIGHEST_READ 4 +#define MTSCHEM_FILE_VER_HIGHEST_WRITE 4 -#define MTSCHEM_PROB_NEVER 0x00 -#define MTSCHEM_PROB_ALWAYS 0xFF +#define MTSCHEM_PROB_MASK 0x7F -extern FlagDesc flagdesc_deco_schematic[]; +#define MTSCHEM_PROB_NEVER 0x00 +#define MTSCHEM_PROB_ALWAYS 0x7F +#define MTSCHEM_PROB_ALWAYS_OLD 0xFF -class DecoSchematic : public Decoration { -public: - std::string filename; +#define MTSCHEM_FORCE_PLACE 0x80 - std::vector c_nodes; +enum SchematicType +{ + SCHEMATIC_NORMAL, +}; - u32 flags; - Rotation rotation; - v3s16 size; - MapNode *schematic; - u8 *slice_probs; +enum SchematicFormatType { + SCHEM_FMT_HANDLE, + SCHEM_FMT_MTS, + SCHEM_FMT_LUA, +}; - DecoSchematic(); - ~DecoSchematic(); +class Schematic : public ObjDef, public NodeResolver { +public: + Schematic(); + virtual ~Schematic(); - void updateContentIds(); - virtual void generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p); - virtual int getHeight(); - virtual std::string getName(); + virtual void resolveNodeNames(); - void blitToVManip(v3s16 p, ManualMapVoxelManipulator *vm, - Rotation rot, bool force_placement); + bool loadSchematicFromFile(const std::string &filename, INodeDefManager *ndef, + StringMap *replace_names=NULL); + bool saveSchematicToFile(const std::string &filename, INodeDefManager *ndef); + bool getSchematicFromMap(Map *map, v3s16 p1, v3s16 p2); - bool loadSchematicFile(NodeResolver *resolver, - std::map &replace_names); - void saveSchematicFile(INodeDefManager *ndef); + bool deserializeFromMts(std::istream *is, std::vector *names); + bool serializeToMts(std::ostream *os, const std::vector &names); + bool serializeToLua(std::ostream *os, const std::vector &names, + bool use_comments, u32 indent_spaces); + + void blitToVManip(v3s16 p, MMVManip *vm, Rotation rot, bool force_place); + void placeStructure(Map *map, v3s16 p, u32 flags, Rotation rot, bool force_place); - bool getSchematicFromMap(Map *map, v3s16 p1, v3s16 p2); - void placeStructure(Map *map, v3s16 p, bool force_placement); void applyProbabilities(v3s16 p0, std::vector > *plist, std::vector > *splist); + + std::vector c_nodes; + u32 flags; + v3s16 size; + MapNode *schemdata; + u8 *slice_probs; }; -void build_nnlist_and_update_ids(MapNode *nodes, u32 nodecount, - std::vector *usednodes); +class SchematicManager : public ObjDefManager { +public: + SchematicManager(IGameDef *gamedef); + virtual ~SchematicManager() {} + + virtual void clear(); + + const char *getObjectTitle() const + { + return "schematic"; + } + + static Schematic *create(SchematicType type) + { + return new Schematic; + } + +private: + IGameDef *m_gamedef; +}; +void generate_nodelist_and_update_ids(MapNode *nodes, size_t nodecount, + std::vector *usednodes, INodeDefManager *ndef); #endif