forked from Wirless/IdlersMapEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasemap.h
More file actions
173 lines (148 loc) · 4.72 KB
/
basemap.h
File metadata and controls
173 lines (148 loc) · 4.72 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
//////////////////////////////////////////////////////////////////////
// This file is part of Remere's Map Editor
//////////////////////////////////////////////////////////////////////
// Remere's Map Editor is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Remere's Map Editor is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//////////////////////////////////////////////////////////////////////
#ifndef RME_BASE_MAP_H_
#define RME_BASE_MAP_H_
#include "main.h"
#include "position.h"
#include "filehandle.h"
#include "map_allocator.h"
#include "tile.h"
// Class declarations
class QTreeNode;
class BaseMap;
class MapIterator;
class Floor;
class QTreeNode;
class TileLocation;
class MapIterator {
public:
MapIterator(BaseMap* _map = nullptr);
~MapIterator();
MapIterator(const MapIterator& other);
TileLocation* operator*();
TileLocation* operator->();
MapIterator& operator++();
MapIterator operator++(int);
bool operator==(const MapIterator& other) const {
if (other.local_z != local_z) {
return false;
}
if (other.local_i != local_i) {
return false;
}
if (other.nodestack == nodestack) {
return true;
}
if (other.current_tile == current_tile) {
return true;
}
return false;
}
bool operator!=(const MapIterator& other) const {
return !(other == *this);
}
struct NodeIndex {
NodeIndex(QTreeNode* _node) :
index(0), node(_node) { }
NodeIndex(const NodeIndex& other) :
index(other.index), node(other.node) { }
int index;
QTreeNode* node;
bool operator==(const NodeIndex& n) const {
return n.node == node && n.index == index;
}
};
private:
std::vector<NodeIndex> nodestack;
int local_i, local_z;
TileLocation* current_tile;
BaseMap* map;
friend class BaseMap;
};
class BaseMap {
public:
BaseMap();
virtual ~BaseMap();
// This doesn't destroy the map structure, just clears it, if param is true, delete all tiles too.
void clear(bool del = true);
MapIterator begin();
MapIterator end();
uint64_t size() const {
return tilecount;
}
// these functions take a position and returns a tile on the map
Tile* createTile(int x, int y, int z);
Tile* getTile(int x, int y, int z);
Tile* getTile(const Position& pos);
Tile* getOrCreateTile(const Position& pos);
const Tile* getTile(int x, int y, int z) const;
const Tile* getTile(const Position& pos) const;
TileLocation* getTileL(int x, int y, int z);
TileLocation* getTileL(const Position& pos);
TileLocation* createTileL(int x, int y, int z);
TileLocation* createTileL(const Position& pos);
const TileLocation* getTileL(int x, int y, int z) const;
const TileLocation* getTileL(const Position& pos) const;
// Get a Quad Tree Leaf from the map
QTreeNode* getLeaf(int x, int y) {
return root.getLeaf(x, y);
}
QTreeNode* createLeaf(int x, int y) {
return root.getLeafForce(x, y);
}
// Assigns a tile, it might seem pointless to provide position, but it is not, as the passed tile may be nullptr
void setTile(int _x, int _y, int _z, Tile* newtile, bool remove = false);
void setTile(const Position& pos, Tile* newtile, bool remove = false) {
setTile(pos.x, pos.y, pos.z, newtile, remove);
}
void setTile(Tile* newtile, bool remove = false) {
setTile(newtile->getX(), newtile->getY(), newtile->getZ(), newtile, remove);
}
// Replaces a tile and returns the old one
Tile* swapTile(int _x, int _y, int _z, Tile* newtile);
Tile* swapTile(const Position& pos, Tile* newtile) {
return swapTile(pos.x, pos.y, pos.z, newtile);
}
// Clears the visiblity according to the mask passed
void clearVisible(uint32_t mask);
uint64_t getTileCount() const {
return tilecount;
}
public:
MapAllocator allocator;
protected:
uint64_t tilecount;
QTreeNode root; // The Quad Tree root
friend class QTreeNode;
};
inline Tile* BaseMap::getTile(int x, int y, int z) {
TileLocation* l = getTileL(x, y, z);
return l ? l->get() : nullptr;
}
inline Tile* BaseMap::getTile(const Position& pos) {
TileLocation* l = getTileL(pos);
return l ? l->get() : nullptr;
}
inline const Tile* BaseMap::getTile(int x, int y, int z) const {
const TileLocation* l = getTileL(x, y, z);
return l ? l->get() : nullptr;
}
inline const Tile* BaseMap::getTile(const Position& pos) const {
const TileLocation* l = getTileL(pos);
return l ? l->get() : nullptr;
}
#endif