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