diff --git a/src/bedrock/forward.h b/src/bedrock/forward.h index a1c5ccfdb..052ccfcbe 100644 --- a/src/bedrock/forward.h +++ b/src/bedrock/forward.h @@ -49,21 +49,23 @@ class BaseLightTextureImageBuilder; class BehaviorFactory; class BiomeComponentFactory; class BiomeManager; +class BlendingDataProvider; class BlockClimberDefinition; class BlockComponentFactory; class BlockDefinitionGroup; +class BlockEventDispatcher; class BlockGraphicsModeChangeContext; class BlockItem; class BlockReducer; class BlockState; class BodyControl; class BossEventSubscriptionManager; +class BoundingBox; class Bounds; class CameraPresets; class ChalkboardBlockActor; class ChangeDimensionPacket; class ChunkKey; -class ChunkSource; class ChunkTickRangeManager; class ChunkViewSource; class ClientNetworkSystem; @@ -111,7 +113,9 @@ class ItemComponent; class ItemComponentPacket; class ItemData; class JigsawStructureRegistry; +class LevelChunkBuilderData; class LevelChunkMetaData; +class LevelChunkMetaDataDictionary; class LevelData; class LevelSoundManager; class LevelStorageObserver; @@ -138,6 +142,7 @@ class PlayerMovementSettings; class PortalForcer; class PositionTrackingDBClient; class PositionTrackingDBServer; +class PostprocessingManager; class PrivateKeyManager; class PropertyGroupManager; class PropertiesSettings; @@ -166,6 +171,7 @@ class SpawnConditions; class Spawner; class StorageVersion; class StructureManager; +class SubChunkInterlocker; class SubChunkPacket; class SubChunkPos; class SurfaceBuilderRegistry; @@ -176,6 +182,7 @@ class TaskGroup; class TickingAreaList; class TickingAreasManager; class TrackedPacketDataContainer; +class TrackedUniqueChunkPtr; class TrimMaterialRegistry; class TrimPatternRegistry; class UpdateEntityAfterFallOnInterface; diff --git a/src/bedrock/world/level/chunk/chunk_source.h b/src/bedrock/world/level/chunk/chunk_source.h new file mode 100644 index 000000000..dd16e6f3d --- /dev/null +++ b/src/bedrock/world/level/chunk/chunk_source.h @@ -0,0 +1,78 @@ +// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include "bedrock/core/utility/enable_non_owner_references.h" +#include "bedrock/core/utility/pub_sub/subscription.h" +#include "bedrock/world/level/block_source.h" +#include "bedrock/world/level/chunk/chunk_source_lookup_map.h" +#include "bedrock/world/scores/identity_dictionary.h" + +class ChunkSource : public Bedrock::EnableNonOwnerReferences { +public: + enum class LoadMode : int { + None = 0, + Deferred = 1, + }; + + ChunkSource(Dimension *, int); + + virtual ~ChunkSource() = 0; + virtual void shutdown() = 0; + virtual bool isShutdownDone() = 0; + virtual std::shared_ptr getExistingChunk(const ChunkPos &) = 0; + virtual std::shared_ptr getRandomChunk(Random &) = 0; + virtual bool isChunkKnown(const ChunkPos &) = 0; + virtual bool isChunkSaved(const ChunkPos &) = 0; + virtual std::shared_ptr createNewChunk(const ChunkPos &, LoadMode, bool) = 0; + virtual std::shared_ptr getOrLoadChunk(const ChunkPos &, LoadMode, bool) = 0; + virtual bool postProcess(ChunkViewSource &) = 0; + virtual void checkAndReplaceChunk(ChunkViewSource &, LevelChunk &) = 0; + virtual void loadChunk(LevelChunk &, bool) = 0; + virtual void postProcessMobsAt(BlockSource &, int, int, Random &) = 0; + virtual void postProcessMobsAt(BlockSource &, const BoundingBox &) const = 0; + virtual bool saveLiveChunk(LevelChunk &) = 0; + virtual void writeEntityChunkTransfer(LevelChunk &) = 0; + virtual void writeEntityChunkTransfersToUnloadedChunk(const ChunkKey &, + const std::vector &) = 0; + virtual void deserializeActorStorageToLevelChunk(LevelChunk &) = 0; + virtual void hintDiscardBatchBegin() = 0; + virtual void hintDiscardBatchEnd() = 0; + virtual void acquireDiscarded(TrackedUniqueChunkPtr) = 0; + virtual void compact() = 0; + virtual void flushPendingDiscardedChunkWrites() = 0; + virtual void flushThreadBatch() = 0; + virtual bool isWithinWorldLimit(const ChunkPos &) const = 0; + virtual const ChunkSourceLookupMap *getChunkMap() = 0; + virtual const ChunkSourceLookupMap &getStorage() const = 0; + virtual void clearDeletedEntities() = 0; + virtual bool canCreateViews() const = 0; + virtual std::unique_ptr tryGetBlendingDataProvider() = 0; + virtual std::shared_ptr loadLevelChunkMetaDataDictionary() = 0; + virtual void setLevelChunk(std::shared_ptr) = 0; + virtual bool canLaunchTasks() const = 0; + virtual bool chunkPosNeedsBlending(const ChunkPos &) = 0; + +private: + int chunk_side_; + Level *level_; + Dimension *dimension_; + ChunkSource *parent_; + std::unique_ptr owned_parent_; + LevelChunkBuilderData *level_chunk_builder_data_; + std::atomic shutting_down_; + Bedrock::PubSub::Subscription on_save_subscription_; + Bedrock::PubSub::Subscription on_level_storage_app_suspend_subscription_; +}; diff --git a/src/bedrock/world/level/chunk/chunk_source_lookup_map.h b/src/bedrock/world/level/chunk/chunk_source_lookup_map.h new file mode 100644 index 000000000..1cabedcdf --- /dev/null +++ b/src/bedrock/world/level/chunk/chunk_source_lookup_map.h @@ -0,0 +1,22 @@ +// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include + +#include "bedrock/world/level/chunk/level_chunk.h" +#include "bedrock/world/level/chunk_pos.h" + +using ChunkSourceLookupMap = std::unordered_map>; diff --git a/src/bedrock/world/level/chunk/level_chunk.h b/src/bedrock/world/level/chunk/level_chunk.h index c808cded4..fd47020f6 100644 --- a/src/bedrock/world/level/chunk/level_chunk.h +++ b/src/bedrock/world/level/chunk/level_chunk.h @@ -16,11 +16,13 @@ #include "bedrock/platform/threading/mutex_details.h" #include "bedrock/platform/threading/spin_lock.h" +#include "bedrock/world/level/block_pos.h" #include "bedrock/world/level/chunk_pos.h" #include "bedrock/world/level/tick.h" class Level; class Dimension; +class ChunkSource; class LevelChunk { public: diff --git a/src/bedrock/world/level/dimension/dimension.cpp b/src/bedrock/world/level/dimension/dimension.cpp index aa32dca33..21112f87e 100644 --- a/src/bedrock/world/level/dimension/dimension.cpp +++ b/src/bedrock/world/level/dimension/dimension.cpp @@ -19,6 +19,11 @@ Level &Dimension::getLevel() const return *level_; } +ChunkSource &Dimension::getChunkSource() const +{ + return *chunk_source_; +} + const std::string &Dimension::getName() const { return name_; diff --git a/src/bedrock/world/level/dimension/dimension.h b/src/bedrock/world/level/dimension/dimension.h index 06d3cc2dd..8bc742153 100644 --- a/src/bedrock/world/level/dimension/dimension.h +++ b/src/bedrock/world/level/dimension/dimension.h @@ -26,6 +26,7 @@ #include "bedrock/world/actor/actor_unique_id.h" #include "bedrock/world/level/biome/registry/biome_registry.h" #include "bedrock/world/level/block_source.h" +#include "bedrock/world/level/chunk/chunk_source.h" #include "bedrock/world/level/dimension/dimension_height_range.h" #include "bedrock/world/level/level_listener.h" #include "bedrock/world/level/levelgen/v2/providers/int_provider.h" @@ -56,7 +57,10 @@ class Dimension : public IDimension, public EnableGetWeakRef, public std::enable_shared_from_this { public: + Dimension(ILevel &, DimensionType, DimensionHeightRange, Scheduler &, std::string); + [[nodiscard]] Level &getLevel() const; + [[nodiscard]] ChunkSource &getChunkSource() const; BlockSource &getBlockSourceFromMainChunkSource() const; [[nodiscard]] const std::string &getName() const; // Endstone @@ -81,5 +85,15 @@ class Dimension : public IDimension, std::unique_ptr runtime_lighting_manager_; // +352 std::string name_; // +360 DimensionType id_; // +392 - // ... + bool ultra_warm_; // +356 + bool has_ceiling_; // +357 + bool has_weather_; // +358 + bool has_skylight_; // +359 + Brightness sky_darken_; // +360 + std::unique_ptr dispatcher_; // +368 + std::unique_ptr task_group_; // +376 + std::unique_ptr chunk_gen_task_group_; // +384 + std::unique_ptr post_processing_manager_; // +392 + std::unique_ptr sub_chunk_interlocker_; // +400 + std::unique_ptr chunk_source_; // +408 }; diff --git a/src/bedrock/world/level/storage/level_storage.h b/src/bedrock/world/level/storage/level_storage.h index fe3a75d45..7cb7321a5 100644 --- a/src/bedrock/world/level/storage/level_storage.h +++ b/src/bedrock/world/level/storage/level_storage.h @@ -23,6 +23,7 @@ #include "bedrock/core/threading/async.h" #include "bedrock/forward.h" #include "bedrock/nbt/compound_tag.h" +#include "bedrock/world/level/chunk/chunk_source.h" #include "bedrock/world/level/storage/db_storage_performance_data.h" struct PlayerStorageIds {