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/buffer_span.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#include "mc/world/level/chunk/ChunkState.h"
13#include "mc/world/level/chunk/LevelChunkGridAreaElement.h"
14
15// auto generated forward declare list
16// clang-format off
18class BlockPos;
19class BlockSource;
20class BoundingBox;
21class ChunkKey;
22class ChunkPos;
23class ChunkViewSource;
24class Dimension;
26class Level;
27class LevelChunk;
30class LevelStorage;
31class Random;
32class TaskResult;
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&);
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&);
87
88 virtual bool decorationPostProcessChunk(::ChunkViewSource&);
89
90 virtual void checkAndReplaceChunk(::ChunkViewSource&, ::LevelChunk&);
91
92 virtual bool verifyChunkNeedsNeighborAwareUpgrade(::LevelChunk&);
93
94 virtual void neighborAwareChunkUpgrade(::LevelChunk&, ::ChunkViewSource&);
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 bool saveLiveChunk(::LevelChunk& lc);
103
104 virtual void writeEntityChunkTransfer(::LevelChunk& levelChunk);
105
106 virtual void writeEntityChunkTransfersToUnloadedChunk(
107 ::ChunkKey const& chunkKey,
108 ::std::vector<::ActorUnloadedChunkTransferEntry> const& transfers
109 );
110
111 virtual void deserializeActorStorageToLevelChunk(::LevelChunk& levelChunk);
112
113 virtual void hintDiscardBatchBegin();
114
115 virtual void hintDiscardBatchEnd();
116
117 virtual void acquireDiscarded(::std::unique_ptr<::LevelChunk, ::LevelChunkFinalDeleter> ptr);
118
119 virtual void compact();
120
121 virtual void flushPendingDiscardedChunkWrites();
122
123 virtual void flushThreadBatch();
124
125 virtual bool isWithinWorldLimit(::ChunkPos const& cp) const;
126
127 virtual ::std::unordered_map<::ChunkPos, ::std::weak_ptr<::LevelChunk>> const* getChunkMap();
128
129 virtual ::std::unordered_map<::ChunkPos, ::std::weak_ptr<::LevelChunk>> const& getStorage() const;
130
131 virtual void clearDeletedEntities();
132
133 virtual bool canCreateViews() const;
134
135 virtual ::std::unique_ptr<::BlendingDataProvider> tryGetBlendingDataProvider();
136
137 virtual ::std::shared_ptr<::LevelChunkMetaDataDictionary> loadLevelChunkMetaDataDictionary();
138
139 virtual void setLevelChunk(::std::shared_ptr<::LevelChunk>);
140
141 virtual bool canLaunchTasks() const;
142
143 virtual bool chunkPosNeedsBlending(::ChunkPos const& cp);
144 // NOLINTEND
145
146public:
147 // member functions
148 // NOLINTBEGIN
149 MCAPI explicit ChunkSource(::std::unique_ptr<::ChunkSource> parent);
150
151 MCAPI bool _checkAndDispatchTaskForLevelChunk(
152 ::std::pair<::ChunkPos, ::ChunkState> const& chunkPosAndExpectedState,
153 bool areInTask
154 );
155
156 MCAPI void _checkForReplacementDataTask(::LevelChunk& lc, ::ChunkViewSource& chunks);
157
158 MCAPI void _checkForUnblockingChunks(::LevelChunk const& lc);
159
160 MCAPI void _checkLevelChunkForNextStage(
161 ::LevelChunk const& lc,
162 ::LevelChunkGridAreaElement<::std::weak_ptr<::LevelChunk>>& grid,
163 ::ChunkState stateToCheck
164 );
165
166 MCAPI void _checkSpecificLevelChunkForUnblocking(
167 ::LevelChunk const& lc,
168 ::LevelChunkGridAreaElement<::std::weak_ptr<::LevelChunk>>& grid
169 );
170
171 MCAPI bool _chunkAtStage(::std::weak_ptr<::LevelChunk> lcwp, ::ChunkState stateToCheck);
172
173 MCAPI void _createOrReplaceGridAreaMap(::std::shared_ptr<::LevelChunk> lc, bool createNeighbourGridsIfMissing);
174
175 MCAPI void _decorationPostProcessingTask(::LevelChunk& lc, ::ChunkViewSource& chunks);
176
177 MCAPI void _dispatchTaskForLevelChunk(
178 ::std::shared_ptr<::LevelChunk> const& lc,
179 ::std::shared_ptr<::ChunkViewSource> const& chunks,
180 bool areInTask
181 );
182
183 MCAPI void _freeChunkGenerationGridMap(::ChunkPos const& cp, bool isLevelChunkDeletion);
184
185 MCAPI void _handleTaskFailure(::LevelChunk& levelChunk, ::ChunkState currentState, ::ChunkState previousState);
186
187 MCAPI void _launchChunkTask(
188 ::std::string_view taskName,
189 ::ChunkPos const& chunkPos,
190 bool areInTask,
192 );
193
194 MCAPI void _launchDecorationPostProcessingTask(
195 ::std::shared_ptr<::LevelChunk> const& lc,
196 ::std::shared_ptr<::ChunkViewSource> const& chunks,
197 bool areInTask
198 );
199
200 MCAPI void _launchLightingTask(
201 ::std::shared_ptr<::LevelChunk> const& lc,
202 ::std::shared_ptr<::ChunkViewSource> const& chunks,
203 bool areInTask
204 );
205
206 MCAPI void _launchNeighborAwareUpgradeTask(
207 ::std::shared_ptr<::LevelChunk> const& lc,
208 ::std::shared_ptr<::ChunkViewSource> const& chunks,
209 bool areInTask
210 );
211
212 MCAPI void _launchReplacementDataTask(
213 ::std::shared_ptr<::LevelChunk> const& lc,
214 ::std::shared_ptr<::ChunkViewSource> const& chunks,
215 bool areInTask
216 );
217
218 MCAPI void _launchStructurePostProcessingTask(
219 ::std::shared_ptr<::LevelChunk> const& lc,
220 ::std::shared_ptr<::ChunkViewSource> const& chunks,
221 bool areInTask
222 );
223
224 MCAPI void _lightingTask(::std::shared_ptr<::LevelChunk> const& lc, ::ChunkViewSource& chunks);
225
226 MCAPI void _loadChunkTask(::LevelChunk& lc);
227
228 MCAPI void _neighborAwareUpgradeTask(::LevelChunk& lc, ::ChunkViewSource& chunks);
229
230 MCAPI void _saveDirtyChunks(::LevelStorage&);
231
232 MCAPI void _spawnChunkGenerationTasks(int numTasks, bool calledFromTask);
233
234 MCAPI_C void addEmptyChunkPosForProcessingNeighbours(::std::shared_ptr<::LevelChunk> lc);
235
236 MCAPI void checkAndLaunchChunkGenerationTasks(bool calledFromTask);
237
238 MCAPI ::GridArea<::std::shared_ptr<::LevelChunk>> createEmptyView(
239 ::ChunkSource::LoadMode lm,
240 bool circle,
241 ::std::function<void(::buffer_span_mut<::std::shared_ptr<::LevelChunk>>, ::buffer_span<uint>)> add,
242 ::ChunkSourceViewGenerateMode chunkViewGenerateMode,
243 float const* serverBuildRatio
244 );
245
246 MCAPI ::std::shared_ptr<::LevelChunk> getAvailableChunk(::ChunkPos const& cp);
247
248 MCAPI_C ::std::shared_ptr<::LevelChunk> getAvailableChunkAt(::BlockPos const& pos);
249
250 MCAPI void
251 initializeWithLevelStorageManagerConnector(::ILevelStorageManagerConnector& levelStorageManagerConnector);
252
253 MCAPI bool shouldServerGeneratePos(::ChunkPos const& chunkPos, float serverBuildRatio, int viewRadius);
254 // NOLINTEND
255
256public:
257 // static variables
258 // NOLINTBEGIN
259 MCAPI static bool& gPerfIsClientSide();
260 // NOLINTEND
261
262public:
263 // constructor thunks
264 // NOLINTBEGIN
265 MCAPI void* $ctor(::std::unique_ptr<::ChunkSource> parent);
266 // NOLINTEND
267
268public:
269 // destructor thunk
270 // NOLINTBEGIN
271 MCAPI void $dtor();
272 // NOLINTEND
273
274public:
275 // virtual function thunks
276 // NOLINTBEGIN
277 MCAPI void $shutdown();
278
279 MCAPI bool $isShutdownDone();
280
281 MCFOLD ::std::shared_ptr<::LevelChunk> $getExistingChunk(::ChunkPos const&);
282
283 MCFOLD ::std::shared_ptr<::LevelChunk> $getRandomChunk(::Random& random);
284
285 MCAPI bool $isChunkKnown(::ChunkPos const& chunkPos);
286
287 MCAPI bool $isChunkSaved(::ChunkPos const& chunkPos);
288
289 MCAPI ::std::shared_ptr<::LevelChunk>
290 $createNewChunk(::ChunkPos const& cp, ::ChunkSource::LoadMode lm, bool readOnly);
291
292 MCAPI ::std::shared_ptr<::LevelChunk>
293 $getOrLoadChunk(::ChunkPos const& cp, ::ChunkSource::LoadMode lm, bool readOnly);
294
295 MCFOLD bool $structurePostProcessChunk(::ChunkViewSource&);
296
297 MCFOLD bool $decorationPostProcessChunk(::ChunkViewSource&);
298
299 MCFOLD void $checkAndReplaceChunk(::ChunkViewSource&, ::LevelChunk&);
300
301 MCFOLD bool $verifyChunkNeedsNeighborAwareUpgrade(::LevelChunk&);
302
303 MCFOLD void $neighborAwareChunkUpgrade(::LevelChunk&, ::ChunkViewSource&);
304
305 MCAPI void $loadChunk(::LevelChunk& lc, bool forceImmediateReplacementDataLoad);
306
307 MCAPI void $postProcessMobsAt(::BlockSource& region, int chunkWestBlock, int chunkNorthBlock, ::Random& random);
308
309 MCAPI void $postProcessMobsAt(::BlockSource& region, ::BoundingBox const& chunkBB) const;
310
311 MCAPI bool $saveLiveChunk(::LevelChunk& lc);
312
313 MCAPI void $writeEntityChunkTransfer(::LevelChunk& levelChunk);
314
315 MCAPI void $writeEntityChunkTransfersToUnloadedChunk(
316 ::ChunkKey const& chunkKey,
317 ::std::vector<::ActorUnloadedChunkTransferEntry> const& transfers
318 );
319
320 MCAPI void $deserializeActorStorageToLevelChunk(::LevelChunk& levelChunk);
321
322 MCAPI void $hintDiscardBatchBegin();
323
324 MCAPI void $hintDiscardBatchEnd();
325
326 MCAPI void $acquireDiscarded(::std::unique_ptr<::LevelChunk, ::LevelChunkFinalDeleter> ptr);
327
328 MCAPI void $compact();
329
330 MCAPI void $flushPendingDiscardedChunkWrites();
331
332 MCAPI void $flushThreadBatch();
333
334 MCFOLD bool $isWithinWorldLimit(::ChunkPos const& cp) const;
335
336 MCFOLD ::std::unordered_map<::ChunkPos, ::std::weak_ptr<::LevelChunk>> const* $getChunkMap();
337
338 MCAPI ::std::unordered_map<::ChunkPos, ::std::weak_ptr<::LevelChunk>> const& $getStorage() const;
339
340 MCFOLD void $clearDeletedEntities();
341
342 MCFOLD bool $canCreateViews() const;
343
344 MCAPI ::std::unique_ptr<::BlendingDataProvider> $tryGetBlendingDataProvider();
345
346 MCAPI ::std::shared_ptr<::LevelChunkMetaDataDictionary> $loadLevelChunkMetaDataDictionary();
347
348 MCFOLD void $setLevelChunk(::std::shared_ptr<::LevelChunk>);
349
350 MCAPI bool $canLaunchTasks() const;
351
352 MCAPI bool $chunkPosNeedsBlending(::ChunkPos const& cp);
353
354
355 // NOLINTEND
356
357public:
358 // vftables
359 // NOLINTBEGIN
360 MCAPI static void** $vftable();
361 // NOLINTEND
362};
Definition EnableNonOwnerReferences.h:7
static MCAPI void ** $vftable()
Definition BlendingDataProvider.h:5
Definition BlockPos.h:19
Definition BlockSource.h:68
Definition BoundingBox.h:13
Definition ChunkKey.h:14
Definition ChunkPos.h:11
Definition ChunkViewSource.h:22
Definition Dimension.h:85
Definition ILevelStorageManagerConnector.h:13
Definition LevelChunkBuilderData.h:16
Definition LevelChunkGridAreaElement.h:6
Definition LevelChunkMetaDataDictionary.h:11
Definition LevelChunk.h:79
Definition LevelStorage.h:25
Definition Level.h:249
Definition Random.h:10
Definition TaskResult.h:5
Definition move_only_function.h:9
Definition _HeaderOutputPredefine.h:237
Definition buffer_span.h:6
Definition ActorUnloadedChunkTransferEntry.h:13
Definition LevelChunkFinalDeleter.h:5