Luanti 5.15.0-dev
 
Loading...
Searching...
No Matches
mg_schematic.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2014-2018 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
4// Copyright (C) 2015-2018 paramat
5
6#pragma once
7
8#include "mg_decoration.h"
9#include "util/string.h"
10
11class Map;
12class ServerMap;
13class MMVManip;
14class NodeResolver;
15class Server;
16
17/*
18 Minetest Schematic File Format
19
20 All values are stored in big-endian byte order.
21 [u32] signature: 'MTSM'
22 [u16] version: 4
23 [u16] size X
24 [u16] size Y
25 [u16] size Z
26 For each Y:
27 [u8] slice probability value
28 [Name-ID table] Name ID Mapping Table
29 [u16] name-id count
30 For each name-id mapping:
31 [u16] name length
32 [u8[]] name
33 ZLib deflated {
34 For each node in schematic: (for z, y, x)
35 [u16] content
36 For each node in schematic:
37 [u8] param1
38 bit 0-6: probability
39 bit 7: specific node force placement
40 For each node in schematic:
41 [u8] param2
42 }
43
44 Version changes:
45 1 - Initial version
46 2 - Fixed messy never/always place; 0 probability is now never, 0xFF is always
47 3 - Added y-slice probabilities; this allows for variable height structures
48 4 - Compressed range of node occurrence prob., added per-node force placement bit
49*/
50
52#define MTSCHEM_FILE_SIGNATURE 0x4d54534d // 'MTSM'
53#define MTSCHEM_FILE_VER_HIGHEST_READ 4
54#define MTSCHEM_FILE_VER_HIGHEST_WRITE 4
55#define MTSCHEM_MAPNODE_SER_FMT_VER 28 // Fixed serialization version for schematics since these still need to use Zlib
56
57#define MTSCHEM_PROB_MASK 0x7F
58
59#define MTSCHEM_PROB_NEVER 0x00
60#define MTSCHEM_PROB_ALWAYS 0x7F
61#define MTSCHEM_PROB_ALWAYS_OLD 0xFF
62
63#define MTSCHEM_FORCE_PLACE 0x80
64
69
75
76class Schematic : public ObjDef, public NodeResolver {
77public:
78 Schematic() = default;
79 virtual ~Schematic();
80
81 ObjDef *clone() const;
82
83 virtual void resolveNodeNames();
84
85 bool loadSchematicFromFile(const std::string &filename,
86 const NodeDefManager *ndef, StringMap *replace_names = NULL);
87 bool saveSchematicToFile(const std::string &filename,
88 const NodeDefManager *ndef);
89 bool getSchematicFromMap(Map *map, v3s16 p1, v3s16 p2);
90
91 bool deserializeFromMts(std::istream *is);
92 bool serializeToMts(std::ostream *os) const;
93 bool serializeToLua(std::ostream *os, bool use_comments, u32 indent_spaces) const;
94
95 void blitToVManip(MMVManip *vm, v3s16 p, Rotation rot, bool force_place);
96 bool placeOnVManip(MMVManip *vm, v3s16 p, u32 flags, Rotation rot, bool force_place);
97 void placeOnMap(ServerMap *map, v3s16 p, u32 flags, Rotation rot, bool force_place);
98
100 std::vector<std::pair<v3s16, u8> > *plist,
101 std::vector<std::pair<s16, u8> > *splist);
102
103 std::vector<content_t> c_nodes;
104 u32 flags = 0;
106 MapNode *schemdata = nullptr;
107 u8 *slice_probs = nullptr;
108
109private:
110 // Counterpart to the node resolver: Condense content_t to a sequential "m_nodenames" list
111 void condenseContentIds();
112};
113
115public:
117 virtual ~SchematicManager() = default;
118
119 SchematicManager *clone() const;
120
121 virtual void clear();
122
123 const char *getObjectTitle() const
124 {
125 return "schematic";
126 }
127
129 {
130 return new Schematic;
131 }
132
133private:
135
137};
138
Definition map.h:301
Definition map.h:100
This class is for getting the actual properties of nodes from their content ID.
Definition nodedef.h:509
Definition nodedef.h:816
Definition objdef.h:57
Definition objdef.h:31
Definition mg_schematic.h:114
SchematicManager()
Definition mg_schematic.h:134
static Schematic * create(SchematicType type)
Definition mg_schematic.h:128
const char * getObjectTitle() const
Definition mg_schematic.h:123
virtual void clear()
Definition mg_schematic.cpp:41
Server * m_server
Definition mg_schematic.h:136
SchematicManager * clone() const
Definition mg_schematic.cpp:32
virtual ~SchematicManager()=default
Definition mg_schematic.h:76
bool serializeToLua(std::ostream *os, bool use_comments, u32 indent_spaces) const
Definition mg_schematic.cpp:382
bool saveSchematicToFile(const std::string &filename, const NodeDefManager *ndef)
Definition mg_schematic.cpp:502
void condenseContentIds()
Definition mg_schematic.cpp:593
bool getSchematicFromMap(Map *map, v3s16 p1, v3s16 p2)
Definition mg_schematic.cpp:533
bool deserializeFromMts(std::istream *is)
Definition mg_schematic.cpp:269
std::vector< content_t > c_nodes
Definition mg_schematic.h:103
bool loadSchematicFromFile(const std::string &filename, const NodeDefManager *ndef, StringMap *replace_names=NULL)
Definition mg_schematic.cpp:472
ObjDef * clone() const
Definition mg_schematic.cpp:73
void applyProbabilities(v3s16 p0, std::vector< std::pair< v3s16, u8 > > *plist, std::vector< std::pair< s16, u8 > > *splist)
Definition mg_schematic.cpp:568
bool placeOnVManip(MMVManip *vm, v3s16 p, u32 flags, Rotation rot, bool force_place)
Definition mg_schematic.cpp:195
u8 * slice_probs
Definition mg_schematic.h:107
MapNode * schemdata
Definition mg_schematic.h:106
void placeOnMap(ServerMap *map, v3s16 p, u32 flags, Rotation rot, bool force_place)
Definition mg_schematic.cpp:222
bool serializeToMts(std::ostream *os) const
Definition mg_schematic.cpp:354
virtual void resolveNodeNames()
Definition mg_schematic.cpp:93
virtual ~Schematic()
Definition mg_schematic.cpp:65
Schematic()=default
u32 flags
Definition mg_schematic.h:104
void blitToVManip(MMVManip *vm, v3s16 p, Rotation rot, bool force_place)
Definition mg_schematic.cpp:112
v3s16 size
Definition mg_schematic.h:105
Definition servermap.h:43
Definition server.h:178
core::vector3d< s16 > v3s16
Definition irr_v3d.h:13
Rotation
Definition mapnode.h:87
SchematicType
Definition mg_schematic.h:66
@ SCHEMATIC_NORMAL
Definition mg_schematic.h:67
SchematicFormatType
Definition mg_schematic.h:70
@ SCHEM_FMT_LUA
Definition mg_schematic.h:73
@ SCHEM_FMT_HANDLE
Definition mg_schematic.h:71
@ SCHEM_FMT_MTS
Definition mg_schematic.h:72
Definition activeobjectmgr.cpp:11
std::unordered_map< std::string, std::string > StringMap
Definition string.h:66
Definition mapnode.h:123
static std::string p(std::string path)
Definition test_filesys.cpp:64