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