X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fmg_schematic.h;h=1d46e6ac4fc7dfa78ead419b91efb215a5fc160c;hb=cdc538e0a242167cd7031d40670d2d4464b87f2c;hp=63cea21f697a012c004137258687c4fbc8feabfd;hpb=479f38973e13680d6a39d9c2a7f29fd330b67d41;p=minetest.git diff --git a/src/mg_schematic.h b/src/mg_schematic.h index 63cea21f6..1d46e6ac4 100644 --- a/src/mg_schematic.h +++ b/src/mg_schematic.h @@ -29,13 +29,14 @@ class Mapgen; class MMVManip; class PseudoRandom; class NodeResolver; +class Server; /* Minetest Schematic File Format All values are stored in big-endian byte order. [u32] signature: 'MTSM' - [u16] version: 3 + [u16] version: 4 [u16] size X [u16] size Y [u16] size Z @@ -50,7 +51,9 @@ class NodeResolver; For each node in schematic: (for z, y, x) [u16] content For each node in schematic: - [u8] probability of occurance (param1) + [u8] param1 + bit 0-6: probability + bit 7: specific node force placement For each node in schematic: [u8] param2 } @@ -59,17 +62,21 @@ class NodeResolver; 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 flags -#define SCHEM_CIDS_UPDATED 0x08 - +//// 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_MASK 0x7F + +#define MTSCHEM_PROB_NEVER 0x00 +#define MTSCHEM_PROB_ALWAYS 0x7F +#define MTSCHEM_PROB_ALWAYS_OLD 0xFF -#define MTSCHEM_PROB_NEVER 0x00 -#define MTSCHEM_PROB_ALWAYS 0xFF +#define MTSCHEM_FORCE_PLACE 0x80 enum SchematicType { @@ -84,44 +91,42 @@ enum SchematicFormatType { class Schematic : public ObjDef, public NodeResolver { public: - std::vector c_nodes; - - u32 flags; - v3s16 size; - MapNode *schemdata; - u8 *slice_probs; - Schematic(); virtual ~Schematic(); virtual void resolveNodeNames(); - void updateContentIds(); - - void blitToVManip(v3s16 p, MMVManip *vm, - Rotation rot, bool force_placement, INodeDefManager *ndef); - bool loadSchematicFromFile(const std::string &filename, INodeDefManager *ndef, - StringMap *replace_names, NodeResolveMethod resolve_method); - bool saveSchematicToFile(const std::string &filename); + StringMap *replace_names=NULL); + bool saveSchematicToFile(const std::string &filename, INodeDefManager *ndef); bool getSchematicFromMap(Map *map, v3s16 p1, v3s16 p2); - bool deserializeFromMts(std::istream *is, std::vector *names_out); - bool serializeToMts(std::ostream *os); - bool serializeToLua(std::ostream *os, bool use_comments); + 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(MMVManip *vm, v3s16 p, Rotation rot, bool force_place); + bool placeOnVManip(MMVManip *vm, v3s16 p, u32 flags, Rotation rot, bool force_place); + void placeOnMap(Map *map, v3s16 p, u32 flags, Rotation rot, bool force_place); - void placeStructure(Map *map, v3s16 p, u32 flags, - Rotation rot, bool force_placement, INodeDefManager *nef); void applyProbabilities(v3s16 p0, std::vector > *plist, std::vector > *splist); + + std::vector c_nodes; + u32 flags; + v3s16 size; + MapNode *schemdata; + u8 *slice_probs; }; class SchematicManager : public ObjDefManager { public: - SchematicManager(IGameDef *gamedef); - ~SchematicManager() {} + SchematicManager(Server *server); + virtual ~SchematicManager() {} + + virtual void clear(); const char *getObjectTitle() const { @@ -132,10 +137,12 @@ class SchematicManager : public ObjDefManager { { return new Schematic; } -}; -void build_nnlist_and_update_ids(MapNode *nodes, u32 nodecount, - std::vector *usednodes); +private: + Server *m_server; +}; +void generate_nodelist_and_update_ids(MapNode *nodes, size_t nodecount, + std::vector *usednodes, INodeDefManager *ndef); #endif