Luanti 5.10.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 <ostream>
11#include <map>
12#include <vector>
13
14class Map;
15class IGameDef;
16
17/*
18 This is an Y-wise stack of MapBlocks.
19*/
20
21#define MAPSECTOR_SERVER 0
22#define MAPSECTOR_CLIENT 1
23
25{
26public:
27
28 MapSector(Map *parent, v2s16 pos, IGameDef *gamedef);
29 virtual ~MapSector();
30
31 void deleteBlocks();
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 int size() const { return m_blocks.size(); }
63protected:
64
65 // The pile of MapBlocks
66 std::unordered_map<s16, std::unique_ptr<MapBlock>> m_blocks;
67
69 // Position on parent (in MapBlock widths)
71
73
74 // Last-used block is cached here for quicker access.
75 // Be sure to set this to nullptr when the cached block is deleted
78
79 /*
80 Private methods
81 */
83
84};
Definition gamedef.h:36
Definition mapblock.h:58
Definition mapsector.h:25
v2s16 m_pos
Definition mapsector.h:70
std::unique_ptr< MapBlock > detachBlock(MapBlock *block)
Definition mapsector.cpp:99
void insertBlock(std::unique_ptr< MapBlock > block)
Definition mapsector.cpp:77
MapBlock * getBlockNoCreateNoEx(s16 y)
Definition mapsector.cpp:50
const auto & getBlocks()=delete
MapBlock * getBlockBuffered(s16 y)
Definition mapsector.cpp:31
s16 m_block_cache_y
Definition mapsector.h:77
Map * m_parent
Definition mapsector.h:68
std::unordered_map< s16, std::unique_ptr< MapBlock > > m_blocks
Definition mapsector.h:66
const auto & getBlocks() const
Definition mapsector.h:57
int size() const
Definition mapsector.h:62
MapSector(Map *parent, v2s16 pos, IGameDef *gamedef)
Definition mapsector.cpp:10
IGameDef * m_gamedef
Definition mapsector.h:72
MapBlock * createBlankBlock(s16 y)
Definition mapsector.cpp:67
bool empty() const
Definition mapsector.h:60
MapBlock * m_block_cache
Definition mapsector.h:76
virtual ~MapSector()
Definition mapsector.cpp:17
void deleteBlocks()
Definition mapsector.cpp:22
v2s16 getPos() const
Definition mapsector.h:33
void deleteBlock(MapBlock *block)
Definition mapsector.cpp:93
std::unique_ptr< MapBlock > createBlankBlockNoInsert(s16 y)
Definition mapsector.cpp:55
Definition map.h:101
core::vector2d< s16 > v2s16
Definition irr_v2d.h:12
std::vector< MapBlock * > MapBlockVect
Definition mapblock.h:554