Luanti 5.15.0-dev
 
Loading...
Searching...
No Matches
mapsector.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5#pragma once
6
7#include "irrlichttypes.h"
8#include "irr_v2d.h"
9#include "mapblock.h"
10#include <memory>
11
12class Map;
13class IGameDef;
14
15/*
16 This is an Y-wise stack of MapBlocks.
17*/
18
19#define MAPSECTOR_SERVER 0
20#define MAPSECTOR_CLIENT 1
21
23{
24public:
25
26 MapSector(Map *parent, v2s16 pos, IGameDef *gamedef);
27 virtual ~MapSector();
28
31 void deleteBlocks(size_t *used_count = nullptr);
32
33 v2s16 getPos() const
34 {
35 return m_pos;
36 }
37
39 std::unique_ptr<MapBlock> createBlankBlockNoInsert(s16 y);
41
42 void insertBlock(std::unique_ptr<MapBlock> block);
43
44 void deleteBlock(MapBlock *block);
45
46 // Remove a block from the map and the sector without deleting it
47 // Returns an owning ptr to block.
48 std::unique_ptr<MapBlock> detachBlock(MapBlock *block);
49
50 // This makes a copy of the internal collection.
51 // Prefer getBlocks() if possible.
52 void getBlocks(MapBlockVect &dest);
53
54 // Get access to the internal collection
55 // This is explicitly only allowed on a const object since modifying anything while iterating is unsafe.
56 // The caller needs to make sure that this does not happen.
57 const auto &getBlocks() const { return m_blocks; }
58 const auto &getBlocks() = delete;
59
60 bool empty() const { return m_blocks.empty(); }
61
62 size_t size() const { return m_blocks.size(); }
63
64protected:
65
66 // The pile of MapBlocks
67 std::unordered_map<s16, std::unique_ptr<MapBlock>> m_blocks;
68
70 // Position on parent (in MapBlock widths)
72
74
75 // Last-used block is cached here for quicker access.
76 // Be sure to set this to nullptr when the cached block is deleted
79
80 /*
81 Private methods
82 */
84
85};
Definition gamedef.h:26
Definition mapblock.h:58
Definition mapsector.h:23
v2s16 m_pos
Definition mapsector.h:71
std::unique_ptr< MapBlock > detachBlock(MapBlock *block)
Definition mapsector.cpp:104
void insertBlock(std::unique_ptr< MapBlock > block)
Definition mapsector.cpp:82
MapBlock * getBlockNoCreateNoEx(s16 y)
Definition mapsector.cpp:55
const auto & getBlocks()=delete
MapBlock * getBlockBuffered(s16 y)
Definition mapsector.cpp:36
s16 m_block_cache_y
Definition mapsector.h:78
size_t size() const
Definition mapsector.h:62
Map * m_parent
Definition mapsector.h:69
std::unordered_map< s16, std::unique_ptr< MapBlock > > m_blocks
Definition mapsector.h:67
const auto & getBlocks() const
Definition mapsector.h:57
MapSector(Map *parent, v2s16 pos, IGameDef *gamedef)
Definition mapsector.cpp:9
IGameDef * m_gamedef
Definition mapsector.h:73
MapBlock * createBlankBlock(s16 y)
Definition mapsector.cpp:72
bool empty() const
Definition mapsector.h:60
MapBlock * m_block_cache
Definition mapsector.h:77
virtual ~MapSector()
Definition mapsector.cpp:16
v2s16 getPos() const
Definition mapsector.h:33
void deleteBlock(MapBlock *block)
Definition mapsector.cpp:98
std::unique_ptr< MapBlock > createBlankBlockNoInsert(s16 y)
Definition mapsector.cpp:60
void deleteBlocks(size_t *used_count=nullptr)
Deletes all blocks (regardless of reference count).
Definition mapsector.cpp:21
Definition map.h:100
core::vector2d< s16 > v2s16
Definition irr_v2d.h:12
std::vector< MapBlock * > MapBlockVect
Definition mapblock.h:565
constexpr v3f y
Definition test_irr_matrix4.cpp:19