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