Minetest 5.9.0-dev
 
Loading...
Searching...
No Matches
mapsector.h
Go to the documentation of this file.
1/*
2Minetest
3Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5This program is free software; you can redistribute it and/or modify
6it under the terms of the GNU Lesser General Public License as published by
7the Free Software Foundation; either version 2.1 of the License, or
8(at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU Lesser General Public License for more details.
14
15You should have received a copy of the GNU Lesser General Public License along
16with this program; if not, write to the Free Software Foundation, Inc.,
1751 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18*/
19
20#pragma once
21
22#include "irrlichttypes.h"
23#include "irr_v2d.h"
24#include "mapblock.h"
25#include <ostream>
26#include <map>
27#include <vector>
28
29class Map;
30class IGameDef;
31
32/*
33 This is an Y-wise stack of MapBlocks.
34*/
35
36#define MAPSECTOR_SERVER 0
37#define MAPSECTOR_CLIENT 1
38
40{
41public:
42
43 MapSector(Map *parent, v2s16 pos, IGameDef *gamedef);
44 virtual ~MapSector();
45
46 void deleteBlocks();
47
48 v2s16 getPos() const
49 {
50 return m_pos;
51 }
52
54 std::unique_ptr<MapBlock> createBlankBlockNoInsert(s16 y);
56
57 void insertBlock(std::unique_ptr<MapBlock> block);
58
59 void deleteBlock(MapBlock *block);
60
61 // Remove a block from the map and the sector without deleting it
62 // Returns an owning ptr to block.
63 std::unique_ptr<MapBlock> detachBlock(MapBlock *block);
64
65 // This makes a copy of the internal collection.
66 // Prefer getBlocks() if possible.
67 void getBlocks(MapBlockVect &dest);
68
69 // Get access to the internal collection
70 // This is explicitly only allowed on a const object since modifying anything while iterating is unsafe.
71 // The caller needs to make sure that this does not happen.
72 const auto &getBlocks() const { return m_blocks; }
73 const auto &getBlocks() = delete;
74
75 bool empty() const { return m_blocks.empty(); }
76
77 int size() const { return m_blocks.size(); }
78protected:
79
80 // The pile of MapBlocks
81 std::unordered_map<s16, std::unique_ptr<MapBlock>> m_blocks;
82
84 // Position on parent (in MapBlock widths)
86
88
89 // Last-used block is cached here for quicker access.
90 // Be sure to set this to nullptr when the cached block is deleted
93
94 /*
95 Private methods
96 */
98
99};
Definition: gamedef.h:51
Definition: mapblock.h:73
Definition: mapsector.h:40
v2s16 m_pos
Definition: mapsector.h:85
std::unique_ptr< MapBlock > detachBlock(MapBlock *block)
Definition: mapsector.cpp:114
void insertBlock(std::unique_ptr< MapBlock > block)
Definition: mapsector.cpp:92
MapBlock * getBlockNoCreateNoEx(s16 y)
Definition: mapsector.cpp:65
const auto & getBlocks()=delete
MapBlock * getBlockBuffered(s16 y)
Definition: mapsector.cpp:46
s16 m_block_cache_y
Definition: mapsector.h:92
Map * m_parent
Definition: mapsector.h:83
std::unordered_map< s16, std::unique_ptr< MapBlock > > m_blocks
Definition: mapsector.h:81
const auto & getBlocks() const
Definition: mapsector.h:72
int size() const
Definition: mapsector.h:77
IGameDef * m_gamedef
Definition: mapsector.h:87
MapBlock * createBlankBlock(s16 y)
Definition: mapsector.cpp:82
bool empty() const
Definition: mapsector.h:75
MapBlock * m_block_cache
Definition: mapsector.h:91
virtual ~MapSector()
Definition: mapsector.cpp:32
void deleteBlocks()
Definition: mapsector.cpp:37
v2s16 getPos() const
Definition: mapsector.h:48
void deleteBlock(MapBlock *block)
Definition: mapsector.cpp:108
std::unique_ptr< MapBlock > createBlankBlockNoInsert(s16 y)
Definition: mapsector.cpp:70
Definition: map.h:116
core::vector2d< s16 > v2s16
Definition: irr_v2d.h:27
std::vector< MapBlock * > MapBlockVect
Definition: mapblock.h:569