Luanti 5.10.0-dev
 
Loading...
Searching...
No Matches
servermap.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2010-2024 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5#pragma once
6
7#include <vector>
8#include <memory>
9
10#include "map.h"
11#include "util/container.h"
12#include "util/metricsbackend.h"
14
15class Settings;
16class MapDatabase;
18class EmergeManager;
20struct BlockMakeData;
21class MetricsBackend;
22
23// TODO: this could wrap all calls to MapDatabase, including locking
26 std::mutex mutex;
28 MapDatabase *dbase = nullptr;
31
34 void loadBlock(v3s16 blockpos, std::string &ret);
35};
36
37/*
38 ServerMap
39
40 This is the only map class that is able to generate map.
41*/
42
43class ServerMap : public Map
44{
45public:
46 /*
47 savedir: directory to which map data should be saved
48 */
49 ServerMap(const std::string &savedir, IGameDef *gamedef, EmergeManager *emerge, MetricsBackend *mb);
50 ~ServerMap();
51
52 /*
53 Get a sector from somewhere.
54 - Check memory
55 - Check disk (doesn't load blocks)
56 - Create blank one
57 */
59
60 /*
61 Blocks are generated by using these and makeBlock().
62 */
64 bool initBlockMake(v3s16 blockpos, BlockMakeData *data);
66 std::map<v3s16, MapBlock*> *changed_blocks);
67
68 /*
69 Get a block from somewhere.
70 - Memory
71 - Create blank
72 */
74
75 /*
76 Forcefully get a block from somewhere (blocking!).
77 - Memory
78 - Load from disk
79 - Create blank filled with CONTENT_IGNORE
80
81 */
82 MapBlock *emergeBlock(v3s16 p, bool create_blank=true) override;
83
84 /*
85 Try to get a block.
86 If it does not exist in memory, add it to the emerge queue.
87 - Memory
88 - Emerge Queue (deferred disk or generate)
89 */
90 MapBlock *getBlockOrEmerge(v3s16 p3d, bool generate);
91
92 bool isBlockInQueue(v3s16 pos);
93
95 std::map<v3s16, MapBlock*> &modified_blocks,
96 bool remove_metadata) override;
97
98 /*
99 Database functions
100 */
101 static MapDatabase *createDatabase(const std::string &name, const std::string &savedir, Settings &conf);
102
103 // Call these before and after saving of blocks
104 void beginSave() override;
105 void endSave() override;
106
107 void save(ModifiedState save_level) override;
108 void listAllLoadableBlocks(std::vector<v3s16> &dst);
109 void listAllLoadedBlocks(std::vector<v3s16> &dst);
110
112
113 bool saveBlock(MapBlock *block) override;
114 static bool saveBlock(MapBlock *block, MapDatabase *db, int compression_level = -1);
115
116 // Load block in a synchronous fashion
120 MapBlock *loadBlock(const std::string &blob, v3s16 p, bool save_after_load=false);
121
122 // Helper for deserializing blocks from disk
123 // @throws SerializationError
124 static void deSerializeBlock(MapBlock *block, std::istream &is);
125
126 // Blocks are removed from the map but not deleted from memory until
127 // deleteDetachedBlocks() is called, since pointers to them may still exist
128 // when deleteBlock() is called.
129 bool deleteBlock(v3s16 blockpos) override;
130
132
133 void step();
134
135 void updateVManip(v3s16 pos);
136
137 // For debug printing
138 void PrintInfo(std::ostream &out) override;
139
141
142 u64 getSeed();
143
151 bool repairBlockLight(v3s16 blockpos,
152 std::map<v3s16, MapBlock *> *modified_blocks);
153
154 void transformLiquids(std::map<v3s16, MapBlock*> & modified_blocks,
155 ServerEnvironment *env);
156
158
160
161protected:
162
163 void reportMetrics(u64 save_time_us, u32 saved_blocks, u32 all_blocks) override;
164
165private:
166 friend class ModApiMapgen; // for m_transforming_liquid
167
168 // Emerge manager
170
171 std::string m_savedir;
173
175
176 std::set<v3s16> m_chunks_in_progress;
177
178 // used by deleteBlock() and deleteDetachedBlocks()
179 std::vector<std::unique_ptr<MapBlock>> m_detached_blocks;
180
181 // Queued transforming water nodes
185 u64 m_inc_trending_up_start_time = 0; // milliseconds
187
188 /*
189 Metadata is re-written on disk only if this is true.
190 This is reset to false when written on disk.
191 */
193
195
196 // Map metrics
200};
Definition emerge.h:117
Definition gamedef.h:36
Definition rollback_interface.h:97
Definition mapblock.h:58
Definition database.h:23
Definition mapsector.h:25
Definition map_settings_manager.h:30
Definition map.h:101
Definition metricsbackend.h:39
Definition l_mapgen.h:18
Definition serverenvironment.h:219
Definition servermap.h:44
void updateVManip(v3s16 pos)
Definition servermap.cpp:453
MapSettingsManager settings_mgr
Definition servermap.h:159
MapBlock * emergeBlock(v3s16 p, bool create_blank=true) override
Definition servermap.cpp:390
u64 getSeed()
Definition servermap.cpp:182
void step()
Definition servermap.cpp:770
bool blockpos_over_mapgen_limit(v3s16 p)
Definition servermap.cpp:187
bool repairBlockLight(v3s16 blockpos, std::map< v3s16, MapBlock * > *modified_blocks)
Definition servermap.cpp:782
void finishBlockMake(BlockMakeData *data, std::map< v3s16, MapBlock * > *changed_blocks)
Definition servermap.cpp:265
~ServerMap()
Definition servermap.cpp:142
void endSave() override
Definition servermap.cpp:609
MapSector * createSector(v2s16 p)
Definition servermap.cpp:327
bool saveBlock(MapBlock *block) override
Definition servermap.cpp:615
std::set< v3s16 > m_chunks_in_progress
Definition servermap.h:176
MetricGaugePtr m_loaded_blocks_gauge
Definition servermap.h:197
static void deSerializeBlock(MapBlock *block, std::istream &is)
Definition servermap.cpp:646
static MapDatabase * createDatabase(const std::string &name, const std::string &savedir, Settings &conf)
Definition servermap.cpp:575
std::string m_savedir
Definition servermap.h:171
bool m_map_saving_enabled
Definition servermap.h:172
void listAllLoadedBlocks(std::vector< v3s16 > &dst)
Definition servermap.cpp:560
void PrintInfo(std::ostream &out) override
Definition servermap.cpp:777
std::vector< std::unique_ptr< MapBlock > > m_detached_blocks
Definition servermap.h:179
UniqueQueue< v3s16 > m_transforming_liquid
Definition servermap.h:182
void deleteDetachedBlocks()
Definition servermap.cpp:760
MetricCounterPtr m_save_count_counter
Definition servermap.h:199
void transformLiquids(std::map< v3s16, MapBlock * > &modified_blocks, ServerEnvironment *env)
Definition servermap.cpp:860
MapDatabaseAccessor m_db
Definition servermap.h:194
EmergeManager * m_emerge
Definition servermap.h:169
bool isBlockInQueue(v3s16 pos)
Definition servermap.cpp:423
void reportMetrics(u64 save_time_us, u32 saved_blocks, u32 all_blocks) override
Definition servermap.cpp:473
int m_map_compression_level
Definition servermap.h:174
bool m_map_metadata_changed
Definition servermap.h:192
bool initBlockMake(v3s16 blockpos, BlockMakeData *data)
Definition servermap.cpp:200
f32 m_transforming_liquid_loop_count_multiplier
Definition servermap.h:183
MapBlock * createBlock(v3s16 p)
Definition servermap.cpp:355
void save(ModifiedState save_level) override
Definition servermap.cpp:480
ServerMap(const std::string &savedir, IGameDef *gamedef, EmergeManager *emerge, MetricsBackend *mb)
Definition servermap.cpp:55
MetricCounterPtr m_save_time_counter
Definition servermap.h:198
MapBlock * getBlockOrEmerge(v3s16 p3d, bool generate)
Definition servermap.cpp:414
u32 m_unprocessed_count
Definition servermap.h:184
void beginSave() override
Definition servermap.cpp:603
void transforming_liquid_add(v3s16 p)
Definition servermap.cpp:855
MapgenParams * getMapgenParams()
Definition servermap.cpp:175
void listAllLoadableBlocks(std::vector< v3s16 > &dst)
Definition servermap.cpp:552
void addNodeAndUpdate(v3s16 p, MapNode n, std::map< v3s16, MapBlock * > &modified_blocks, bool remove_metadata) override
Definition servermap.cpp:428
bool m_queue_size_timer_started
Definition servermap.h:186
bool isSavingEnabled()
Definition servermap.h:140
MapBlock * loadBlock(v3s16 p)
Definition servermap.cpp:726
bool deleteBlock(v3s16 blockpos) override
Definition servermap.cpp:740
u64 m_inc_trending_up_start_time
Definition servermap.h:185
Definition settings.h:109
Definition container.h:26
core::vector2d< s16 > v2s16
Definition irr_v2d.h:12
core::vector3d< s16 > v3s16
Definition irr_v3d.h:13
std::shared_ptr< MetricCounter > MetricCounterPtr
Definition metricsbackend.h:22
std::shared_ptr< MetricGauge > MetricGaugePtr
Definition metricsbackend.h:36
ModifiedState
Definition modifiedstate.h:10
Definition emerge.h:37
Definition servermap.h:24
void loadBlock(v3s16 blockpos, std::string &ret)
Load a block, taking dbase_ro into account.
Definition servermap.cpp:43
MapDatabase * dbase
Main database.
Definition servermap.h:28
MapDatabase * dbase_ro
Fallback database for read operations.
Definition servermap.h:30
std::mutex mutex
Lock, to be taken for any operation.
Definition servermap.h:26
Definition mapnode.h:124
Definition mapgen.h:114
static std::string p(std::string path)
Definition test_filesys.cpp:53