]> git.lizzy.rs Git - minetest.git/blob - src/serialization.h
Add chat HUD flag (#13189)
[minetest.git] / src / serialization.h
1 /*
2 Minetest
3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #pragma once
21
22 #include "irrlichttypes.h"
23 #include "exceptions.h"
24 #include <iostream>
25 #include "util/pointer.h"
26
27 /*
28         Map format serialization version
29         --------------------------------
30
31         For map data (blocks, nodes, sectors).
32
33         NOTE: The goal is to increment this so that saved maps will be
34               loadable by any version. Other compatibility is not
35                   maintained.
36
37         0: original networked test with 1-byte nodes
38         1: update with 2-byte nodes
39         2: lighting is transmitted in param
40         3: optional fetching of far blocks
41         4: block compression
42         5: sector objects NOTE: block compression was left accidentally out
43         6: failed attempt at switching block compression on again
44         7: block compression switched on again
45         8: server-initiated block transfers and all kinds of stuff
46         9: block objects
47         10: water pressure
48         11: zlib'd blocks, block flags
49         12: UnlimitedHeightmap now uses interpolated areas
50         13: Mapgen v2
51         14: NodeMetadata
52         15: StaticObjects
53         16: larger maximum size of node metadata, and compression
54         17: MapBlocks contain timestamp
55         18: new generator (not really necessary, but it's there)
56         19: new content type handling
57         20: many existing content types translated to extended ones
58         21: dynamic content type allocation
59         22: minerals removed, facedir & wallmounted changed
60         23: new node metadata format
61         24: 16-bit node ids and node timers (never released as stable)
62         25: Improved node timer format
63         26: Never written; read the same as 25
64         27: Added light spreading flags to blocks
65         28: Added "private" flag to NodeMetadata
66         29: Switched compression to zstd, a bit of reorganization
67 */
68 // This represents an uninitialized or invalid format
69 #define SER_FMT_VER_INVALID 255
70 // Highest supported serialization version
71 #define SER_FMT_VER_HIGHEST_READ 29
72 // Saved on disk version
73 #define SER_FMT_VER_HIGHEST_WRITE 29
74 // Lowest supported serialization version
75 #define SER_FMT_VER_LOWEST_READ 0
76 // Lowest serialization version for writing
77 // Can't do < 24 anymore; we have 16-bit dynamically allocated node IDs
78 // in memory; conversion just won't work in this direction.
79 #define SER_FMT_VER_LOWEST_WRITE 24
80
81 inline bool ser_ver_supported(s32 v) {
82         return v >= SER_FMT_VER_LOWEST_READ && v <= SER_FMT_VER_HIGHEST_READ;
83 }
84
85 /*
86         Misc. serialization functions
87 */
88
89 void compressZlib(const u8 *data, size_t data_size, std::ostream &os, int level = -1);
90 void compressZlib(const std::string &data, std::ostream &os, int level = -1);
91 void decompressZlib(std::istream &is, std::ostream &os, size_t limit = 0);
92
93 void compressZstd(const u8 *data, size_t data_size, std::ostream &os, int level = 0);
94 void compressZstd(const std::string &data, std::ostream &os, int level = 0);
95 void decompressZstd(std::istream &is, std::ostream &os);
96
97 // These choose between zlib and a self-made one according to version
98 void compress(const SharedBuffer<u8> &data, std::ostream &os, u8 version, int level = -1);
99 void compress(const std::string &data, std::ostream &os, u8 version, int level = -1);
100 void compress(u8 *data, u32 size, std::ostream &os, u8 version, int level = -1);
101 void decompress(std::istream &is, std::ostream &os, u8 version);