forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmapbuffer.h
82 lines (69 loc) · 2.67 KB
/
mapbuffer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#pragma once
#ifndef CATA_SRC_MAPBUFFER_H
#define CATA_SRC_MAPBUFFER_H
#include <iosfwd>
#include <list>
#include <map>
#include <memory>
#include "point.h"
class JsonIn;
class submap;
/**
* Store, buffer, save and load the entire world map.
*/
class mapbuffer
{
public:
mapbuffer();
~mapbuffer();
/** Store all submaps in this instance into savefiles.
* @param delete_after_save If true, the saved submaps are removed
* from the mapbuffer (and deleted).
**/
void save( bool delete_after_save = false );
/** Delete all buffered submaps. **/
void clear();
/** Add a new submap to the buffer.
*
* @param p The absolute world position in submap coordinates.
* Same as the ones in @ref lookup_submap.
* @param sm The submap. If the submap has been added, the unique_ptr
* is released (set to NULL).
* @return true if the submap has been stored here. False if there
* is already a submap with the specified coordinates. The submap
* is not stored and the given unique_ptr retains ownsership.
*/
bool add_submap( const tripoint &p, std::unique_ptr<submap> &sm );
// Old overload that we should stop using, but it's complicated
bool add_submap( const tripoint &p, submap *sm );
/** Get a submap stored in this buffer.
*
* @param p The absolute world position in submap coordinates.
* Same as the ones in @ref add_submap.
* @return NULL if the submap is not in the mapbuffer
* and could not be loaded. The mapbuffer takes care of the returned
* submap object, don't delete it on your own.
*/
submap *lookup_submap( const tripoint &p );
private:
using submap_map_t = std::map<tripoint, std::unique_ptr<submap>>;
public:
inline submap_map_t::iterator begin() {
return submaps.begin();
}
inline submap_map_t::iterator end() {
return submaps.end();
}
private:
// There's a very good reason this is private,
// if not handled carefully, this can erase in-use submaps and crash the game.
void remove_submap( tripoint addr );
submap *unserialize_submaps( const tripoint &p );
void deserialize( JsonIn &jsin );
void save_quad( const std::string &dirname, const std::string &filename,
const tripoint &om_addr, std::list<tripoint> &submaps_to_delete,
bool delete_after_save );
submap_map_t submaps; // NOLINT(cata-serialize)
};
extern mapbuffer MAPBUFFER;
#endif // CATA_SRC_MAPBUFFER_H