summaryrefslogtreecommitdiff
path: root/src/mg_schematic.h
diff options
context:
space:
mode:
authorkwolekr <kwolekr@minetest.net>2015-04-12 16:40:50 -0400
committerkwolekr <kwolekr@minetest.net>2015-04-13 03:10:52 -0400
commitb2a89c04b22d51a9ec541c75cf530897dbbce8d9 (patch)
treed10614fa15c71fbd4110b3e2430208a332a82b40 /src/mg_schematic.h
parent39fd4da7a00e59fabe9b328842033901c15eeb70 (diff)
downloadminetest-b2a89c04b22d51a9ec541c75cf530897dbbce8d9.tar.gz
minetest-b2a89c04b22d51a9ec541c75cf530897dbbce8d9.tar.bz2
minetest-b2a89c04b22d51a9ec541c75cf530897dbbce8d9.zip
Schematics: Reorganize (de)serialization and add Lua serialization API
Diffstat (limited to 'src/mg_schematic.h')
-rw-r--r--src/mg_schematic.h48
1 files changed, 46 insertions, 2 deletions
diff --git a/src/mg_schematic.h b/src/mg_schematic.h
index 30bd0e4fd..50d48b1f1 100644
--- a/src/mg_schematic.h
+++ b/src/mg_schematic.h
@@ -30,10 +30,40 @@ class MMVManip;
class PseudoRandom;
class NodeResolver;
+/*
+ Minetest Schematic File Format
+
+ All values are stored in big-endian byte order.
+ [u32] signature: 'MTSM'
+ [u16] version: 3
+ [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] probability of occurance (param1)
+ 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
+*/
+
/////////////////// Schematic flags
#define SCHEM_CIDS_UPDATED 0x08
-
#define MTSCHEM_FILE_SIGNATURE 0x4d54534d // 'MTSM'
#define MTSCHEM_FILE_VER_HIGHEST_READ 3
#define MTSCHEM_FILE_VER_HIGHEST_WRITE 3
@@ -46,6 +76,11 @@ enum SchematicType
SCHEMATIC_NORMAL,
};
+enum SchematicFormatType {
+ SCHEM_FMT_HANDLE,
+ SCHEM_FMT_MTS,
+ SCHEM_FMT_LUA,
+};
class Schematic : public ObjDef, public NodeResolver {
public:
@@ -68,14 +103,23 @@ public:
bool loadSchematicFromFile(const char *filename, INodeDefManager *ndef,
StringMap *replace_names);
- void saveSchematicToFile(const char *filename, INodeDefManager *ndef);
+ bool saveSchematicToFile(const char *filename, INodeDefManager *ndef);
bool getSchematicFromMap(Map *map, v3s16 p1, v3s16 p2);
+ bool deserializeFromMts(std::istream *is, INodeDefManager *ndef,
+ std::vector<std::string> *names);
+ bool serializeToMts(std::ostream *os, INodeDefManager *ndef);
+ bool serializeToLua(std::ostream *os,
+ INodeDefManager *ndef, bool use_comments);
+
+
void placeStructure(Map *map, v3s16 p, u32 flags,
Rotation rot, bool force_placement, INodeDefManager *nef);
void applyProbabilities(v3s16 p0,
std::vector<std::pair<v3s16, u8> > *plist,
std::vector<std::pair<s16, u8> > *splist);
+
+ std::string getAsLuaTable(INodeDefManager *ndef, bool use_comments);
};
class SchematicManager : public ObjDefManager {