Some work-in-progress in hp and mobs and a frightening amount of random fixes.
[oweals/minetest.git] / src / serialization.h
1 /*
2 Minetest-c55
3 Copyright (C) 2010 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 General Public License as published by
7 the Free Software Foundation; either version 2 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 General Public License for more details.
14
15 You should have received a copy of the GNU 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 #ifndef SERIALIZATION_HEADER
21 #define SERIALIZATION_HEADER
22
23 #include "common_irrlicht.h"
24 #include "exceptions.h"
25 #include <iostream>
26 #include "utility.h"
27
28 /*
29         NOTE: The goal is to increment this so that saved maps will be
30               loadable by any version. Other compatibility is not
31                   maintained.
32         Serialization format versions (for raw map data (blocks, nodes, sectors)):
33         == Unsupported ==
34         0: original networked test with 1-byte nodes
35         1: update with 2-byte nodes
36         == Supported ==
37         2: lighting is transmitted in param
38         3: optional fetching of far blocks
39         4: block compression
40         5: sector objects NOTE: block compression was left accidentally out
41         6: failed attempt at switching block compression on again
42         7: block compression switched on again
43         8: (dev) server-initiated block transfers and all kinds of stuff
44         9: (dev) block objects
45         10: (dev) water pressure
46         11: (dev) zlib'd blocks, block flags
47         12: (dev) UnlimitedHeightmap now uses interpolated areas
48         13: (dev) Mapgen v2
49         14: (dev) NodeMetadata
50         15: (dev) StaticObjects
51         16: (dev) larger maximum size of node metadata, and compression
52 */
53 // This represents an uninitialized or invalid format
54 #define SER_FMT_VER_INVALID 255
55 // Highest supported serialization version
56 #define SER_FMT_VER_HIGHEST 16
57 // Lowest supported serialization version
58 #define SER_FMT_VER_LOWEST 0
59
60 #define ser_ver_supported(v) (v >= SER_FMT_VER_LOWEST && v <= SER_FMT_VER_HIGHEST)
61
62 void compressZlib(SharedBuffer<u8> data, std::ostream &os);
63 void compressZlib(const std::string &data, std::ostream &os);
64 void decompressZlib(std::istream &is, std::ostream &os);
65
66 void compress(SharedBuffer<u8> data, std::ostream &os, u8 version);
67 //void compress(const std::string &data, std::ostream &os, u8 version);
68 void decompress(std::istream &is, std::ostream &os, u8 version);
69
70 /*class Serializable
71 {
72 public:
73         void serialize(std::ostream &os, u8 version) = 0;
74         void deSerialize(std::istream &istr);
75 };*/
76
77 #endif
78