Skip to content
LeviMC
English
AutoLightDark
LeviLamina
Loading...
Searching...
No Matches
ChunkSource.h
1#pragma once
2
3#include "mc/_HeaderOutputPredefine.h"
4
5// auto generated inclusion list
6#include "mc/deps/core/threading/SharedLockbox.h"
7#include "mc/deps/core/utility/EnableNonOwnerReferences.h"
8#include "mc/deps/core/utility/pub_sub/Subscription.h"
9#include "mc/platform/brstd/move_only_function.h"
10#include "mc/util/GridArea.h"
11#include "mc/world/level/chunk/ChunkSourceViewGenerateMode.h"
12
13// auto generated forward declare list
14// clang-format off
16class BlockSource;
17class BoundingBox;
18class ChunkKey;
19class ChunkPos;
20class ChunkViewSource;
21class Dimension;
23class Level;
24class LevelChunk;
27class LevelStorage;
28class Random;
29class TaskResult;
33namespace br::worldgen { class StructureInstance; }
34namespace br::worldgen { struct Structure; }
35// clang-format on
36
37class ChunkSource : public ::Bedrock::EnableNonOwnerReferences {
38public:
39 // ChunkSource inner types define
40 enum class LoadMode : int {
41 None = 0,
42 Deferred = 1,
43 };
44
45public:
46 // member variables
47 // NOLINTBEGIN
48 ::ll::TypedStorage<4, 4, int> mChunkSide;
49 ::ll::TypedStorage<8, 8, ::Level*> mLevel;
50 ::ll::TypedStorage<8, 8, ::Dimension*> mDimension;
51 ::ll::TypedStorage<8, 8, ::ChunkSource*> mParent;
52 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::ChunkSource>> mOwnedParent;
53 ::ll::TypedStorage<8, 8, ::LevelChunkBuilderData*> mLevelChunkBuilderData;
54 ::ll::TypedStorage<1, 1, ::std::atomic<bool>> mShuttingDown;
55 ::ll::TypedStorage<8, 16, ::Bedrock::PubSub::Subscription> mOnSaveSubscription;
56 ::ll::TypedStorage<8, 16, ::Bedrock::PubSub::Subscription> mOnLevelStorageAppSuspendSubscription;
57 // NOLINTEND
58
59public:
60 // prevent constructor by default
61 ChunkSource();
62
63public:
64 // virtual functions
65 // NOLINTBEGIN
66 virtual ~ChunkSource() /*override*/;
67
68 virtual void shutdown();
69
70 virtual bool isShutdownDone();
71
72 virtual ::std::shared_ptr<::LevelChunk> getExistingChunk(::ChunkPos const& pos);
73
74 virtual ::std::shared_ptr<::LevelChunk> getRandomChunk(::Random& random);
75
76 virtual bool isChunkKnown(::ChunkPos const& chunkPos);
77
78 virtual bool isChunkSaved(::ChunkPos const& chunkPos);
79
80 virtual ::std::shared_ptr<::LevelChunk>
81 createNewChunk(::ChunkPos const& cp, ::ChunkSource::LoadMode lm, bool readOnly);
82
83 virtual ::std::shared_ptr<::LevelChunk>
84 getOrLoadChunk(::ChunkPos const& cp, ::ChunkSource::LoadMode lm, bool readOnly);
85
86 virtual bool structurePostProcessChunk(::ChunkViewSource& neighborhood);
87
88 virtual bool decorationPostProcessChunk(::ChunkViewSource& neighborhood);
89
90 virtual void checkAndReplaceChunk(::ChunkViewSource& neighborhood, ::LevelChunk& lc);
91
92 virtual bool verifyChunkNeedsNeighborAwareUpgrade(::LevelChunk& lc);
93
94 virtual void neighborAwareChunkUpgrade(::LevelChunk& levelChunk, ::ChunkViewSource& neighborhood);
95
96 virtual void loadChunk(::LevelChunk& lc, bool forceImmediateReplacementDataLoad);
97
98 virtual void postProcessMobsAt(::BlockSource& region, int chunkWestBlock, int chunkNorthBlock, ::Random& random);
99
100 virtual void postProcessMobsAt(::BlockSource& region, ::BoundingBox const& chunkBB) const;
101
102 virtual void deleteAllChunkData(
103 ::std::unordered_set<::ChunkPos> chunksToDelete,
104 ::std::function<void()> completionCallback,
105 ::std::shared_ptr<::ChunkDeletionMetadata> metadata
106 );
107
108 virtual void deleteStoredChunkData(
109 ::std::unordered_set<::ChunkPos> chunksToDelete,
110 ::std::function<void()> completionCallback,
111 ::std::shared_ptr<::ChunkDeletionMetadata> metadata
112 );
113
114 virtual bool saveLiveChunk(::LevelChunk& lc);
115
116 virtual void writeEntityChunkTransfer(::LevelChunk& levelChunk);
117
118 virtual void writeEntityChunkTransfersToUnloadedChunk(
119 ::ChunkKey const& chunkKey,
120 ::std::vector<::ActorUnloadedChunkTransferEntry> const& transfers
121 );
122
123 virtual void deserializeActorStorageToLevelChunk(::LevelChunk& levelChunk);
124
125 virtual void hintDiscardBatchBegin();
126
127 virtual void hintDiscardBatchEnd();
128
129 virtual void acquireDiscarded(::std::unique_ptr<::LevelChunk, ::LevelChunkFinalDeleter> ptr);
130
131 virtual void compact();
132
133 virtual void flushPendingDiscardedChunkWrites();
134
135 virtual void flushThreadBatch();
136
137 virtual bool isWithinWorldLimit(::ChunkPos const& cp) const;
138
139 virtual ::std::unordered_map<::ChunkPos, ::std::weak_ptr<::LevelChunk>> const* getChunkMap() const;
140
141 virtual ::std::unordered_map<::ChunkPos, ::std::weak_ptr<::LevelChunk>> const& getStorage() const;
142
143 virtual void clearDeletedEntities();
144
145 virtual bool canCreateViews() const;
146
147 virtual ::std::unique_ptr<::BlendingDataProvider> tryGetBlendingDataProvider();
148
149 virtual ::std::shared_ptr<::LevelChunkMetaDataDictionary> loadLevelChunkMetaDataDictionary();
150
151 virtual void setLevelChunk(::std::shared_ptr<::LevelChunk> lc);
152
153 virtual bool canLaunchTasks() const;
154
155 virtual bool chunkPosNeedsBlending(::ChunkPos const& cp);
156
157 virtual void _clearBlendingCache();
158
159 virtual ::std::shared_ptr<::br::worldgen::StructureInstance>
160 _tryGetOrLoadStructureInstanceAt(::ChunkPos const& cp, ::br::worldgen::Structure const& structure);
161 // NOLINTEND
162
163public:
164 // member functions
165 // NOLINTBEGIN
166 MCNAPI explicit ChunkSource(::std::unique_ptr<::ChunkSource> parent);
167
168#ifdef LL_PLAT_C
169 MCNAPI void _checkForUnblockingChunks(::ChunkPos cp);
170#endif
171
172#ifdef LL_PLAT_S
173 MCNAPI void _checkForUnblockingChunks(::ChunkPos cp);
174#endif
175
176#ifdef LL_PLAT_C
177 MCNAPI void _createOrReplaceGridAreaMap(::std::shared_ptr<::LevelChunk> lc, bool createNeighbourGridsIfMissing);
178#endif
179
180 MCNAPI void _freeChunkGenerationGridMap(::ChunkPos const& cp, bool isLevelChunkDeletion);
181
182 MCNAPI void _launchChunkTask(
183 ::std::string_view taskName,
184 ::ChunkPos const& chunkPos,
185 bool areInTask,
187 );
188
190
191 MCNAPI void _spawnChunkGenerationTasks(int numTasks, bool calledFromTask);
192
193#ifdef LL_PLAT_C
194 MCNAPI void addEmptyChunkPosForProcessingNeighbours(::std::shared_ptr<::LevelChunk> lc);
195#endif
196
197 MCAPI void checkAndLaunchChunkGenerationTasks(bool calledFromTask);
198
199#ifdef LL_PLAT_C
200 MCNAPI ::GridArea<::std::shared_ptr<::LevelChunk>, ::Bedrock::Threading::SharedLockbox> createEmptyView(
201 ::ChunkSource::LoadMode lm,
202 bool circle,
203 ::std::function<void(::gsl::span<::std::shared_ptr<::LevelChunk>>)> add,
204 ::ChunkSourceViewGenerateMode chunkViewGenerateMode,
205 float const* serverBuildRatio
206 );
207#endif
208
209 // Unlike getExistingChunk, this one withholds any chunk that has not finished loading.
210 LLAPI ::std::shared_ptr<::LevelChunk> getAvailableChunk(::ChunkPos const& cp);
211
212 MCNAPI void
214 // NOLINTEND
215
216public:
217 // static variables
218 // NOLINTBEGIN
219 MCNAPI static bool& gPerfIsClientSide();
220 // NOLINTEND
221
222public:
223 // constructor thunks
224 // NOLINTBEGIN
225 MCNAPI void* $ctor(::std::unique_ptr<::ChunkSource> parent);
226 // NOLINTEND
227
228public:
229 // destructor thunk
230 // NOLINTBEGIN
231 MCAPI void $dtor();
232 // NOLINTEND
233
234public:
235 // virtual function thunks
236 // NOLINTBEGIN
237 MCAPI void $shutdown();
238
239 MCAPI bool $isShutdownDone();
240
241 MCFOLD ::std::shared_ptr<::LevelChunk> $getExistingChunk(::ChunkPos const& pos);
242
243 MCFOLD ::std::shared_ptr<::LevelChunk> $getRandomChunk(::Random& random);
244
245 MCAPI bool $isChunkKnown(::ChunkPos const& chunkPos);
246
247 MCAPI bool $isChunkSaved(::ChunkPos const& chunkPos);
248
249 MCAPI ::std::shared_ptr<::LevelChunk>
250 $createNewChunk(::ChunkPos const& cp, ::ChunkSource::LoadMode lm, bool readOnly);
251
252 MCAPI ::std::shared_ptr<::LevelChunk>
253 $getOrLoadChunk(::ChunkPos const& cp, ::ChunkSource::LoadMode lm, bool readOnly);
254
255 MCFOLD bool $structurePostProcessChunk(::ChunkViewSource& neighborhood);
256
257 MCFOLD bool $decorationPostProcessChunk(::ChunkViewSource& neighborhood);
258
259 MCFOLD void $checkAndReplaceChunk(::ChunkViewSource& neighborhood, ::LevelChunk& lc);
260
261 MCFOLD bool $verifyChunkNeedsNeighborAwareUpgrade(::LevelChunk& lc);
262
263 MCFOLD void $neighborAwareChunkUpgrade(::LevelChunk& levelChunk, ::ChunkViewSource& neighborhood);
264
265 MCAPI void $loadChunk(::LevelChunk& lc, bool forceImmediateReplacementDataLoad);
266
267 MCAPI void $postProcessMobsAt(::BlockSource& region, int chunkWestBlock, int chunkNorthBlock, ::Random& random);
268
269 MCAPI void $postProcessMobsAt(::BlockSource& region, ::BoundingBox const& chunkBB) const;
270
271 MCAPI void $deleteAllChunkData(
272 ::std::unordered_set<::ChunkPos> chunksToDelete,
273 ::std::function<void()> completionCallback,
274 ::std::shared_ptr<::ChunkDeletionMetadata> metadata
275 );
276
277 MCAPI void $deleteStoredChunkData(
278 ::std::unordered_set<::ChunkPos> chunksToDelete,
279 ::std::function<void()> completionCallback,
280 ::std::shared_ptr<::ChunkDeletionMetadata> metadata
281 );
282
283 MCAPI bool $saveLiveChunk(::LevelChunk& lc);
284
285 MCAPI void $writeEntityChunkTransfer(::LevelChunk& levelChunk);
286
287 MCAPI void $writeEntityChunkTransfersToUnloadedChunk(
288 ::ChunkKey const& chunkKey,
289 ::std::vector<::ActorUnloadedChunkTransferEntry> const& transfers
290 );
291
292 MCAPI void $deserializeActorStorageToLevelChunk(::LevelChunk& levelChunk);
293
294 MCAPI void $hintDiscardBatchBegin();
295
296 MCAPI void $hintDiscardBatchEnd();
297
298 MCAPI void $acquireDiscarded(::std::unique_ptr<::LevelChunk, ::LevelChunkFinalDeleter> ptr);
299
300 MCAPI void $compact();
301
302 MCAPI void $flushPendingDiscardedChunkWrites();
303
304 MCAPI void $flushThreadBatch();
305
306 MCFOLD bool $isWithinWorldLimit(::ChunkPos const& cp) const;
307
308 MCFOLD ::std::unordered_map<::ChunkPos, ::std::weak_ptr<::LevelChunk>> const* $getChunkMap() const;
309
310 MCAPI ::std::unordered_map<::ChunkPos, ::std::weak_ptr<::LevelChunk>> const& $getStorage() const;
311
312 MCFOLD void $clearDeletedEntities();
313
314 MCFOLD bool $canCreateViews() const;
315
316 MCAPI ::std::unique_ptr<::BlendingDataProvider> $tryGetBlendingDataProvider();
317
318 MCAPI ::std::shared_ptr<::LevelChunkMetaDataDictionary> $loadLevelChunkMetaDataDictionary();
319
320#ifdef LL_PLAT_S
321 MCAPI void $setLevelChunk(::std::shared_ptr<::LevelChunk> lc);
322#else // LL_PLAT_C
323 MCFOLD void $setLevelChunk(::std::shared_ptr<::LevelChunk> lc);
324#endif
325
326 MCAPI bool $canLaunchTasks() const;
327
328 MCAPI bool $chunkPosNeedsBlending(::ChunkPos const& cp);
329
330 MCAPI void $_clearBlendingCache();
331
332 MCAPI ::std::shared_ptr<::br::worldgen::StructureInstance>
333 $_tryGetOrLoadStructureInstanceAt(::ChunkPos const& cp, ::br::worldgen::Structure const& structure);
334
335
336 // NOLINTEND
337
338public:
339 // vftables
340 // NOLINTBEGIN
341 MCNAPI static void** $vftable();
342 // NOLINTEND
343};
Definition EnableNonOwnerReferences.h:7
Definition SharedLockbox.h:9
Definition BlendingDataProvider.h:5
Definition BlockSource.h:72
Definition BoundingBox.h:13
Definition ChunkKey.h:9
Definition ChunkPos.h:13
static MCAPI void ** $vftable()
MCAPI void _launchChunkTask(::std::string_view taskName, ::ChunkPos const &chunkPos, bool areInTask, ::brstd::move_only_function<::TaskResult()> taskFunc)
MCAPI void _saveDirtyChunks(::LevelStorage &)
MCAPI void * $ctor(::std::unique_ptr<::ChunkSource > parent)
MCAPI ChunkSource(::std::unique_ptr<::ChunkSource > parent)
MCAPI void initializeWithLevelStorageManagerConnector(::ILevelStorageManagerConnector &levelStorageManagerConnector)
MCAPI void _freeChunkGenerationGridMap(::ChunkPos const &cp, bool isLevelChunkDeletion)
MCAPI void _spawnChunkGenerationTasks(int numTasks, bool calledFromTask)
static MCAPI bool & gPerfIsClientSide()
Definition ChunkViewSource.h:23
Definition Dimension.h:86
Definition ILevelStorageManagerConnector.h:13
Definition LevelChunkBuilderData.h:16
Definition LevelChunkMetaDataDictionary.h:11
Definition LevelChunk.h:76
Definition LevelStorage.h:26
Definition Level.h:255
Definition Random.h:10
Definition TaskResult.h:5
Definition StructureInstance.h:20
Definition move_only_function.h:9
Definition ActorUnloadedChunkTransferEntry.h:13
Definition ChunkDeletionMetadata.h:5
Definition LevelChunkFinalDeleter.h:5
Definition Structure.h:24