From f3ec768dfbad65e269da9c43f1ca982d0fb7234d Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 21 Dec 2020 14:31:44 +0000 Subject: unique_ptr to plain member --- src/Chunk.cpp | 4 +- src/Chunk.h | 8 +-- src/ChunkMap.cpp | 34 ++++++--- src/ChunkMap.h | 25 ++++--- src/World.cpp | 211 ++++++++++++++++++++++++------------------------------- src/World.h | 28 ++++---- 6 files changed, 144 insertions(+), 166 deletions(-) diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 7bf7f0567..eb44828e2 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -270,7 +270,7 @@ void cChunk::MarkLoadFailed(void) -void cChunk::GetAllData(cChunkDataCallback & a_Callback) +void cChunk::GetAllData(cChunkDataCallback & a_Callback) const { ASSERT(m_Presence == cpPresent); @@ -2027,7 +2027,7 @@ void cChunk::GetBlockTypeMeta(Vector3i a_RelPos, BLOCKTYPE & a_BlockType, NIBBLE -void cChunk::GetBlockInfo(Vector3i a_RelPos, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_Meta, NIBBLETYPE & a_SkyLight, NIBBLETYPE & a_BlockLight) +void cChunk::GetBlockInfo(Vector3i a_RelPos, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_Meta, NIBBLETYPE & a_SkyLight, NIBBLETYPE & a_BlockLight) const { a_BlockType = GetBlock(a_RelPos); a_Meta = m_ChunkData.GetMeta(a_RelPos); diff --git a/src/Chunk.h b/src/Chunk.h index bfd860b1c..28f7b0bec 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -111,7 +111,7 @@ public: void MarkLoadFailed(void); /** Gets all chunk data, calls the a_Callback's methods for each data type */ - void GetAllData(cChunkDataCallback & a_Callback); + void GetAllData(cChunkDataCallback & a_Callback) const; /** Sets all chunk data as either loaded from the storage or generated. BlockLight and BlockSkyLight are optional, if not present, chunk will be marked as unlighted. @@ -172,11 +172,7 @@ public: GetBlockTypeMeta({ a_RelX, a_RelY, a_RelZ }, a_BlockType, a_BlockMeta); } - void GetBlockInfo(Vector3i a_RelPos, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_Meta, NIBBLETYPE & a_SkyLight, NIBBLETYPE & a_BlockLight); - void GetBlockInfo(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_Meta, NIBBLETYPE & a_SkyLight, NIBBLETYPE & a_BlockLight) - { - GetBlockInfo({ a_RelX, a_RelY, a_RelZ }, a_BlockType, a_Meta, a_SkyLight, a_BlockLight); - } + void GetBlockInfo(Vector3i a_RelPos, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_Meta, NIBBLETYPE & a_SkyLight, NIBBLETYPE & a_BlockLight) const; /** Convert absolute coordinates into relative coordinates. Returns false on failure to obtain a valid chunk. Returns true otherwise. diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index aaa8cc0b1..facfe8a31 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -101,6 +101,18 @@ cChunk * cChunkMap::FindChunk(int a_ChunkX, int a_ChunkZ) +const cChunk * cChunkMap::FindChunk(int a_ChunkX, int a_ChunkZ) const +{ + ASSERT(m_CSChunks.IsLockedByCurrentThread()); + + const auto Chunk = m_Chunks.find({ a_ChunkX, a_ChunkZ }); + return (Chunk == m_Chunks.end()) ? nullptr : &Chunk->second; +} + + + + + void cChunkMap::SendBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cClientHandle & a_Client) { cCSLock Lock(m_CSChunks); @@ -285,7 +297,7 @@ void cChunkMap::ChunkLighted( -bool cChunkMap::GetChunkData(cChunkCoords a_Coords, cChunkDataCallback & a_Callback) +bool cChunkMap::GetChunkData(cChunkCoords a_Coords, cChunkDataCallback & a_Callback) const { if (!a_Callback.Coords(a_Coords.m_ChunkX, a_Coords.m_ChunkZ)) { @@ -323,7 +335,7 @@ bool cChunkMap::GetChunkBlockTypes(int a_ChunkX, int a_ChunkZ, BLOCKTYPE * a_Blo -bool cChunkMap::IsChunkQueued(int a_ChunkX, int a_ChunkZ) +bool cChunkMap::IsChunkQueued(int a_ChunkX, int a_ChunkZ) const { cCSLock Lock(m_CSChunks); const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ); @@ -334,7 +346,7 @@ bool cChunkMap::IsChunkQueued(int a_ChunkX, int a_ChunkZ) -bool cChunkMap::IsChunkValid(int a_ChunkX, int a_ChunkZ) +bool cChunkMap::IsChunkValid(int a_ChunkX, int a_ChunkZ) const { cCSLock Lock(m_CSChunks); const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ); @@ -345,7 +357,7 @@ bool cChunkMap::IsChunkValid(int a_ChunkX, int a_ChunkZ) -bool cChunkMap::HasChunkAnyClients(int a_ChunkX, int a_ChunkZ) +bool cChunkMap::HasChunkAnyClients(int a_ChunkX, int a_ChunkZ) const { cCSLock Lock(m_CSChunks); const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ); @@ -448,7 +460,7 @@ void cChunkMap::CollectPickupsByPlayer(cPlayer & a_Player) -BLOCKTYPE cChunkMap::GetBlock(Vector3i a_BlockPos) +BLOCKTYPE cChunkMap::GetBlock(Vector3i a_BlockPos) const { auto chunkPos = cChunkDef::BlockToChunk(a_BlockPos); auto relPos = cChunkDef::AbsoluteToRelative(a_BlockPos, chunkPos); @@ -467,7 +479,7 @@ BLOCKTYPE cChunkMap::GetBlock(Vector3i a_BlockPos) -NIBBLETYPE cChunkMap::GetBlockMeta(Vector3i a_BlockPos) +NIBBLETYPE cChunkMap::GetBlockMeta(Vector3i a_BlockPos) const { auto chunkPos = cChunkDef::BlockToChunk(a_BlockPos); auto relPos = cChunkDef::AbsoluteToRelative(a_BlockPos, chunkPos); @@ -486,7 +498,7 @@ NIBBLETYPE cChunkMap::GetBlockMeta(Vector3i a_BlockPos) -NIBBLETYPE cChunkMap::GetBlockSkyLight(Vector3i a_BlockPos) +NIBBLETYPE cChunkMap::GetBlockSkyLight(Vector3i a_BlockPos) const { auto chunkPos = cChunkDef::BlockToChunk(a_BlockPos); auto relPos = cChunkDef::AbsoluteToRelative(a_BlockPos, chunkPos); @@ -505,7 +517,7 @@ NIBBLETYPE cChunkMap::GetBlockSkyLight(Vector3i a_BlockPos) -NIBBLETYPE cChunkMap::GetBlockBlockLight(Vector3i a_BlockPos) +NIBBLETYPE cChunkMap::GetBlockBlockLight(Vector3i a_BlockPos) const { auto chunkPos = cChunkDef::BlockToChunk(a_BlockPos); auto relPos = cChunkDef::AbsoluteToRelative(a_BlockPos, chunkPos); @@ -559,7 +571,7 @@ void cChunkMap::SetBlock(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE -bool cChunkMap::GetBlockTypeMeta(Vector3i a_BlockPos, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) +bool cChunkMap::GetBlockTypeMeta(Vector3i a_BlockPos, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) const { auto chunkCoord = cChunkDef::BlockToChunk(a_BlockPos); auto relPos = cChunkDef::AbsoluteToRelative(a_BlockPos, chunkCoord); @@ -578,7 +590,7 @@ bool cChunkMap::GetBlockTypeMeta(Vector3i a_BlockPos, BLOCKTYPE & a_BlockType, N -bool cChunkMap::GetBlockInfo(Vector3i a_BlockPos, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_Meta, NIBBLETYPE & a_SkyLight, NIBBLETYPE & a_BlockLight) +bool cChunkMap::GetBlockInfo(Vector3i a_BlockPos, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_Meta, NIBBLETYPE & a_SkyLight, NIBBLETYPE & a_BlockLight) const { auto chunkPos = cChunkDef::BlockToChunk(a_BlockPos); auto relPos = cChunkDef::AbsoluteToRelative(a_BlockPos, chunkPos); @@ -633,7 +645,7 @@ void cChunkMap::ReplaceTreeBlocks(const sSetBlockVector & a_Blocks) -EMCSBiome cChunkMap::GetBiomeAt (int a_BlockX, int a_BlockZ) +EMCSBiome cChunkMap::GetBiomeAt(int a_BlockX, int a_BlockZ) const { int ChunkX, ChunkZ, X = a_BlockX, Y = 0, Z = a_BlockZ; cChunkDef::AbsoluteToRelative(X, Y, Z, ChunkX, ChunkZ); diff --git a/src/ChunkMap.h b/src/ChunkMap.h index 4a7e952b5..38f03255a 100644 --- a/src/ChunkMap.h +++ b/src/ChunkMap.h @@ -112,16 +112,16 @@ public: /** Calls the callback with the chunk's data, if available (with ChunkCS locked). Returns true if the chunk was reported successfully, false if not (chunk not present or callback failed). */ - bool GetChunkData(cChunkCoords a_Coords, cChunkDataCallback & a_Callback); + bool GetChunkData(cChunkCoords a_Coords, cChunkDataCallback & a_Callback) const; /** Copies the chunk's blocktypes into a_Blocks; returns true if successful */ bool GetChunkBlockTypes (int a_ChunkX, int a_ChunkZ, BLOCKTYPE * a_Blocks); /** Returns true iff the chunk is in the loader / generator queue. */ - bool IsChunkQueued(int a_ChunkX, int a_ChunkZ); + bool IsChunkQueued(int a_ChunkX, int a_ChunkZ) const; - bool IsChunkValid (int a_ChunkX, int a_ChunkZ); - bool HasChunkAnyClients (int a_ChunkX, int a_ChunkZ); + bool IsChunkValid (int a_ChunkX, int a_ChunkZ) const; + bool HasChunkAnyClients (int a_ChunkX, int a_ChunkZ) const; int GetHeight (int a_BlockX, int a_BlockZ); // Waits for the chunk to get loaded / generated bool TryGetHeight (int a_BlockX, int a_BlockZ, int & a_Height); // Returns false if chunk not loaded / generated @@ -134,24 +134,24 @@ public: /** Makes the specified player collect all the pickups around them. */ void CollectPickupsByPlayer(cPlayer & a_Player); - BLOCKTYPE GetBlock (Vector3i a_BlockPos); - NIBBLETYPE GetBlockMeta (Vector3i a_BlockPos); - NIBBLETYPE GetBlockSkyLight (Vector3i a_BlockPos); - NIBBLETYPE GetBlockBlockLight(Vector3i a_BlockPos); + BLOCKTYPE GetBlock (Vector3i a_BlockPos) const; + NIBBLETYPE GetBlockMeta (Vector3i a_BlockPos) const; + NIBBLETYPE GetBlockSkyLight (Vector3i a_BlockPos) const; + NIBBLETYPE GetBlockBlockLight(Vector3i a_BlockPos) const; /** Sets the meta for the specified block, while keeping the blocktype. Ignored if the chunk is invalid. */ void SetBlockMeta(Vector3i a_BlockPos, NIBBLETYPE a_BlockMeta); void SetBlock (Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); - bool GetBlockTypeMeta (Vector3i a_BlockPos, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta); - bool GetBlockInfo (Vector3i, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_Meta, NIBBLETYPE & a_SkyLight, NIBBLETYPE & a_BlockLight); + bool GetBlockTypeMeta (Vector3i a_BlockPos, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) const; + bool GetBlockInfo (Vector3i, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_Meta, NIBBLETYPE & a_SkyLight, NIBBLETYPE & a_BlockLight) const; /** Special function used for growing trees, replaces only blocks that tree may overwrite */ void ReplaceTreeBlocks(const sSetBlockVector & a_Blocks); /** Returns the biome at the specified coords. Reads the biome from the chunk, if loaded, otherwise uses the world generator to provide the biome value */ - EMCSBiome GetBiomeAt (int a_BlockX, int a_BlockZ); + EMCSBiome GetBiomeAt (int a_BlockX, int a_BlockZ) const; /** Sets the biome at the specified coords. Returns true if successful, false if not (chunk not loaded). Doesn't resend the chunk to clients. */ @@ -462,6 +462,9 @@ private: /** Locates a chunk ptr in the chunkmap; doesn't create it when not found; assumes m_CSChunks is locked. To be called only from cChunkMap. */ cChunk * FindChunk(int a_ChunkX, int a_ChunkZ); + /** Locates a chunk ptr in the chunkmap; doesn't create it when not found; assumes m_CSChunks is locked. To be called only from cChunkMap. */ + const cChunk * FindChunk(int a_ChunkX, int a_ChunkZ) const; + /** Adds a new cChunkStay descendant to the internal list of ChunkStays; loads its chunks. To be used only by cChunkStay; others should use cChunkStay::Enable() instead */ void AddChunkStay(cChunkStay & a_ChunkStay); diff --git a/src/World.cpp b/src/World.cpp index ba2f159a0..9aa31a14d 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -92,7 +92,7 @@ namespace World // cWorld::cLock: cWorld::cLock::cLock(cWorld & a_World) : - Super(&(a_World.m_ChunkMap->GetCS())) + Super(&(a_World.m_ChunkMap.GetCS())) { } @@ -184,7 +184,7 @@ cWorld::cWorld( m_FireSimulator(), m_RedstoneSimulator(nullptr), m_MaxPlayers(10), - m_ChunkMap(), + m_ChunkMap(this), m_bAnimals(true), m_Weather(eWeather_Sunny), m_WeatherInterval(24000), // Guaranteed 1 game-day of sunshine at server start :) @@ -227,9 +227,7 @@ cWorld::cWorld( cFile::CreateFolderRecursive(m_DataPath); - // TODO: unique ptr unnecessary - m_ChunkMap = std::make_unique(this); - m_ChunkMap->TrackInDeadlockDetect(a_DeadlockDetect, m_WorldName); + m_ChunkMap.TrackInDeadlockDetect(a_DeadlockDetect, m_WorldName); // Load the scoreboard cScoreboardSerializer Serializer(m_DataPath, &m_Scoreboard); @@ -581,7 +579,7 @@ bool cWorld::IsWeatherWetAtXYZ(Vector3i a_Pos) void cWorld::SetNextBlockToTick(const Vector3i a_BlockPos) { - return m_ChunkMap->SetNextBlockToTick(a_BlockPos); + return m_ChunkMap.SetNextBlockToTick(a_BlockPos); } @@ -957,7 +955,7 @@ void cWorld::Stop(cDeadlockDetect & a_DeadlockDetect) a_DeadlockDetect.UntrackCriticalSection(m_CSClients); a_DeadlockDetect.UntrackCriticalSection(m_CSTasks); - m_ChunkMap->UntrackInDeadlockDetect(a_DeadlockDetect); + m_ChunkMap.UntrackInDeadlockDetect(a_DeadlockDetect); if (IsSavingEnabled()) { @@ -1022,7 +1020,7 @@ void cWorld::Tick(std::chrono::milliseconds a_Dt, std::chrono::milliseconds a_La } for (auto & Entity : EntitiesToAdd) { - m_ChunkMap->AddEntity(std::move(Entity)); + m_ChunkMap.AddEntity(std::move(Entity)); } EntitiesToAdd.clear(); @@ -1031,7 +1029,7 @@ void cWorld::Tick(std::chrono::milliseconds a_Dt, std::chrono::milliseconds a_La TickClients(static_cast(a_Dt.count())); TickQueuedBlocks(); - m_ChunkMap->Tick(a_Dt); // Tick chunk after clients to apply at least one round of queued ticks (e.g. cBlockHandler::Check) this tick + m_ChunkMap.Tick(a_Dt); // Tick chunk after clients to apply at least one round of queued ticks (e.g. cBlockHandler::Check) this tick TickMobs(a_Dt); m_MapManager.TickMaps(); TickQueuedTasks(); @@ -1103,7 +1101,7 @@ void cWorld::TickMobs(std::chrono::milliseconds a_Dt) // before every Mob action, we have to count them depending on the distance to players, on their family ... cMobCensus MobCensus; - m_ChunkMap->CollectMobCensus(MobCensus); + m_ChunkMap.CollectMobCensus(MobCensus); if (m_bAnimals) { // Spawning is enabled, spawn now: @@ -1129,7 +1127,7 @@ void cWorld::TickMobs(std::chrono::milliseconds a_Dt) cMobSpawner Spawner(Family, m_AllowedMobs); if (Spawner.CanSpawnAnything()) { - m_ChunkMap->SpawnMobs(Spawner); + m_ChunkMap.SpawnMobs(Spawner); // do the spawn for (auto & Mob : Spawner.getSpawned()) { @@ -1300,7 +1298,7 @@ void cWorld::UpdateSkyDarkness(void) void cWorld::WakeUpSimulators(Vector3i a_Block) { - return m_ChunkMap->WakeUpSimulators(a_Block); + return m_ChunkMap.WakeUpSimulators(a_Block); } @@ -1328,7 +1326,7 @@ void cWorld::WakeUpSimulatorsInArea(const cCuboid & a_Area) bool cWorld::ForEachBlockEntityInChunk(int a_ChunkX, int a_ChunkZ, cBlockEntityCallback a_Callback) { - return m_ChunkMap->ForEachBlockEntityInChunk(a_ChunkX, a_ChunkZ, a_Callback); + return m_ChunkMap.ForEachBlockEntityInChunk(a_ChunkX, a_ChunkZ, a_Callback); } @@ -1337,7 +1335,7 @@ bool cWorld::ForEachBlockEntityInChunk(int a_ChunkX, int a_ChunkZ, cBlockEntityC bool cWorld::ForEachBrewingstandInChunk(int a_ChunkX, int a_ChunkZ, cBrewingstandCallback a_Callback) { - return m_ChunkMap->ForEachBrewingstandInChunk(a_ChunkX, a_ChunkZ, a_Callback); + return m_ChunkMap.ForEachBrewingstandInChunk(a_ChunkX, a_ChunkZ, a_Callback); } @@ -1346,7 +1344,7 @@ bool cWorld::ForEachBrewingstandInChunk(int a_ChunkX, int a_ChunkZ, cBrewingstan bool cWorld::ForEachChestInChunk(int a_ChunkX, int a_ChunkZ, cChestCallback a_Callback) { - return m_ChunkMap->ForEachChestInChunk(a_ChunkX, a_ChunkZ, a_Callback); + return m_ChunkMap.ForEachChestInChunk(a_ChunkX, a_ChunkZ, a_Callback); } @@ -1355,7 +1353,7 @@ bool cWorld::ForEachChestInChunk(int a_ChunkX, int a_ChunkZ, cChestCallback a_Ca bool cWorld::ForEachDispenserInChunk(int a_ChunkX, int a_ChunkZ, cDispenserCallback a_Callback) { - return m_ChunkMap->ForEachDispenserInChunk(a_ChunkX, a_ChunkZ, a_Callback); + return m_ChunkMap.ForEachDispenserInChunk(a_ChunkX, a_ChunkZ, a_Callback); } @@ -1364,7 +1362,7 @@ bool cWorld::ForEachDispenserInChunk(int a_ChunkX, int a_ChunkZ, cDispenserCallb bool cWorld::ForEachDropperInChunk(int a_ChunkX, int a_ChunkZ, cDropperCallback a_Callback) { - return m_ChunkMap->ForEachDropperInChunk(a_ChunkX, a_ChunkZ, a_Callback); + return m_ChunkMap.ForEachDropperInChunk(a_ChunkX, a_ChunkZ, a_Callback); } @@ -1373,7 +1371,7 @@ bool cWorld::ForEachDropperInChunk(int a_ChunkX, int a_ChunkZ, cDropperCallback bool cWorld::ForEachDropSpenserInChunk(int a_ChunkX, int a_ChunkZ, cDropSpenserCallback a_Callback) { - return m_ChunkMap->ForEachDropSpenserInChunk(a_ChunkX, a_ChunkZ, a_Callback); + return m_ChunkMap.ForEachDropSpenserInChunk(a_ChunkX, a_ChunkZ, a_Callback); } @@ -1382,7 +1380,7 @@ bool cWorld::ForEachDropSpenserInChunk(int a_ChunkX, int a_ChunkZ, cDropSpenserC bool cWorld::ForEachFurnaceInChunk(int a_ChunkX, int a_ChunkZ, cFurnaceCallback a_Callback) { - return m_ChunkMap->ForEachFurnaceInChunk(a_ChunkX, a_ChunkZ, a_Callback); + return m_ChunkMap.ForEachFurnaceInChunk(a_ChunkX, a_ChunkZ, a_Callback); } @@ -1426,7 +1424,7 @@ void cWorld::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_Blo bool cWorld::DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBlockEntityCallback a_Callback) { - return m_ChunkMap->DoWithBlockEntityAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); + return m_ChunkMap.DoWithBlockEntityAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); } @@ -1435,7 +1433,7 @@ bool cWorld::DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBloc bool cWorld::DoWithBeaconAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBeaconCallback a_Callback) { - return m_ChunkMap->DoWithBeaconAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); + return m_ChunkMap.DoWithBeaconAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); } @@ -1444,7 +1442,7 @@ bool cWorld::DoWithBeaconAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBeaconCal bool cWorld::DoWithBedAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBedCallback a_Callback) { - return m_ChunkMap->DoWithBedAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); + return m_ChunkMap.DoWithBedAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); } @@ -1453,7 +1451,7 @@ bool cWorld::DoWithBedAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBedCallback bool cWorld::DoWithBrewingstandAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBrewingstandCallback a_Callback) { - return m_ChunkMap->DoWithBrewingstandAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); + return m_ChunkMap.DoWithBrewingstandAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); } @@ -1462,7 +1460,7 @@ bool cWorld::DoWithBrewingstandAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBre bool cWorld::DoWithChestAt(int a_BlockX, int a_BlockY, int a_BlockZ, cChestCallback a_Callback) { - return m_ChunkMap->DoWithChestAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); + return m_ChunkMap.DoWithChestAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); } @@ -1471,7 +1469,7 @@ bool cWorld::DoWithChestAt(int a_BlockX, int a_BlockY, int a_BlockZ, cChestCallb bool cWorld::DoWithDispenserAt(int a_BlockX, int a_BlockY, int a_BlockZ, cDispenserCallback a_Callback) { - return m_ChunkMap->DoWithDispenserAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); + return m_ChunkMap.DoWithDispenserAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); } @@ -1480,7 +1478,7 @@ bool cWorld::DoWithDispenserAt(int a_BlockX, int a_BlockY, int a_BlockZ, cDispen bool cWorld::DoWithDropperAt(int a_BlockX, int a_BlockY, int a_BlockZ, cDropperCallback a_Callback) { - return m_ChunkMap->DoWithDropperAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); + return m_ChunkMap.DoWithDropperAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); } @@ -1489,7 +1487,7 @@ bool cWorld::DoWithDropperAt(int a_BlockX, int a_BlockY, int a_BlockZ, cDropperC bool cWorld::DoWithDropSpenserAt(int a_BlockX, int a_BlockY, int a_BlockZ, cDropSpenserCallback a_Callback) { - return m_ChunkMap->DoWithDropSpenserAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); + return m_ChunkMap.DoWithDropSpenserAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); } @@ -1498,7 +1496,7 @@ bool cWorld::DoWithDropSpenserAt(int a_BlockX, int a_BlockY, int a_BlockZ, cDrop bool cWorld::DoWithFurnaceAt(int a_BlockX, int a_BlockY, int a_BlockZ, cFurnaceCallback a_Callback) { - return m_ChunkMap->DoWithFurnaceAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); + return m_ChunkMap.DoWithFurnaceAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); } @@ -1507,7 +1505,7 @@ bool cWorld::DoWithFurnaceAt(int a_BlockX, int a_BlockY, int a_BlockZ, cFurnaceC bool cWorld::DoWithHopperAt(int a_BlockX, int a_BlockY, int a_BlockZ, cHopperCallback a_Callback) { - return m_ChunkMap->DoWithHopperAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); + return m_ChunkMap.DoWithHopperAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); } @@ -1516,7 +1514,7 @@ bool cWorld::DoWithHopperAt(int a_BlockX, int a_BlockY, int a_BlockZ, cHopperCal bool cWorld::DoWithNoteBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cNoteBlockCallback a_Callback) { - return m_ChunkMap->DoWithNoteBlockAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); + return m_ChunkMap.DoWithNoteBlockAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); } @@ -1525,7 +1523,7 @@ bool cWorld::DoWithNoteBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cNoteBl bool cWorld::DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCommandBlockCallback a_Callback) { - return m_ChunkMap->DoWithCommandBlockAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); + return m_ChunkMap.DoWithCommandBlockAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); } @@ -1534,7 +1532,7 @@ bool cWorld::DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCom bool cWorld::DoWithMobHeadAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadCallback a_Callback) { - return m_ChunkMap->DoWithMobHeadAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); + return m_ChunkMap.DoWithMobHeadAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); } @@ -1543,7 +1541,7 @@ bool cWorld::DoWithMobHeadAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadC bool cWorld::DoWithFlowerPotAt(int a_BlockX, int a_BlockY, int a_BlockZ, cFlowerPotCallback a_Callback) { - return m_ChunkMap->DoWithFlowerPotAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); + return m_ChunkMap.DoWithFlowerPotAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); } @@ -1552,7 +1550,7 @@ bool cWorld::DoWithFlowerPotAt(int a_BlockX, int a_BlockY, int a_BlockZ, cFlower bool cWorld::GetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4) { - return m_ChunkMap->GetSignLines(a_BlockX, a_BlockY, a_BlockZ, a_Line1, a_Line2, a_Line3, a_Line4); + return m_ChunkMap.GetSignLines(a_BlockX, a_BlockY, a_BlockZ, a_Line1, a_Line2, a_Line3, a_Line4); } @@ -1561,7 +1559,7 @@ bool cWorld::GetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_ bool cWorld::DoWithChunk(int a_ChunkX, int a_ChunkZ, cChunkCallback a_Callback) { - return m_ChunkMap->DoWithChunk(a_ChunkX, a_ChunkZ, a_Callback); + return m_ChunkMap.DoWithChunk(a_ChunkX, a_ChunkZ, a_Callback); } @@ -1570,7 +1568,7 @@ bool cWorld::DoWithChunk(int a_ChunkX, int a_ChunkZ, cChunkCallback a_Callback) bool cWorld::DoWithChunkAt(Vector3i a_BlockPos, cChunkCallback a_Callback) { - return m_ChunkMap->DoWithChunkAt(a_BlockPos, a_Callback); + return m_ChunkMap.DoWithChunkAt(a_BlockPos, a_Callback); } @@ -1776,7 +1774,7 @@ bool cWorld::GrowTreeImage(const sSetBlockVector & a_Blocks) } // for itr - b2[] // All ok, replace blocks with the tree image: - m_ChunkMap->ReplaceTreeBlocks(a_Blocks); + m_ChunkMap.ReplaceTreeBlocks(a_Blocks); return true; } @@ -1786,7 +1784,7 @@ bool cWorld::GrowTreeImage(const sSetBlockVector & a_Blocks) int cWorld::GrowPlantAt(Vector3i a_BlockPos, int a_NumStages) { - return m_ChunkMap->GrowPlantAt(a_BlockPos, a_NumStages); + return m_ChunkMap.GrowPlantAt(a_BlockPos, a_NumStages); } @@ -1804,7 +1802,7 @@ bool cWorld::GrowRipePlant(Vector3i a_BlockPos) EMCSBiome cWorld::GetBiomeAt (int a_BlockX, int a_BlockZ) { - return m_ChunkMap->GetBiomeAt(a_BlockX, a_BlockZ); + return m_ChunkMap.GetBiomeAt(a_BlockX, a_BlockZ); } @@ -1813,7 +1811,7 @@ EMCSBiome cWorld::GetBiomeAt (int a_BlockX, int a_BlockZ) bool cWorld::SetBiomeAt(int a_BlockX, int a_BlockZ, EMCSBiome a_Biome) { - return m_ChunkMap->SetBiomeAt(a_BlockX, a_BlockZ, a_Biome); + return m_ChunkMap.SetBiomeAt(a_BlockX, a_BlockZ, a_Biome); } @@ -1822,7 +1820,7 @@ bool cWorld::SetBiomeAt(int a_BlockX, int a_BlockZ, EMCSBiome a_Biome) bool cWorld::SetAreaBiome(int a_MinX, int a_MaxX, int a_MinZ, int a_MaxZ, EMCSBiome a_Biome) { - return m_ChunkMap->SetAreaBiome(a_MinX, a_MaxX, a_MinZ, a_MaxZ, a_Biome); + return m_ChunkMap.SetAreaBiome(a_MinX, a_MaxX, a_MinZ, a_MaxZ, a_Biome); } @@ -1853,7 +1851,7 @@ void cWorld::SetMaxViewDistance(unsigned a_MaxViewDistance) void cWorld::SetBlock(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) { - m_ChunkMap->SetBlock(a_BlockPos, a_BlockType, a_BlockMeta); + m_ChunkMap.SetBlock(a_BlockPos, a_BlockType, a_BlockMeta); } @@ -1862,7 +1860,7 @@ void cWorld::SetBlock(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_B void cWorld::SetBlockMeta(Vector3i a_BlockPos, NIBBLETYPE a_MetaData) { - m_ChunkMap->SetBlockMeta(a_BlockPos, a_MetaData); + m_ChunkMap.SetBlockMeta(a_BlockPos, a_MetaData); } @@ -1871,7 +1869,7 @@ void cWorld::SetBlockMeta(Vector3i a_BlockPos, NIBBLETYPE a_MetaData) NIBBLETYPE cWorld::GetBlockSkyLight(Vector3i a_BlockPos) { - return m_ChunkMap->GetBlockSkyLight(a_BlockPos); + return m_ChunkMap.GetBlockSkyLight(a_BlockPos); } @@ -1880,7 +1878,7 @@ NIBBLETYPE cWorld::GetBlockSkyLight(Vector3i a_BlockPos) NIBBLETYPE cWorld::GetBlockBlockLight(Vector3i a_BlockPos) { - return m_ChunkMap->GetBlockBlockLight(a_BlockPos); + return m_ChunkMap.GetBlockBlockLight(a_BlockPos); } @@ -1889,7 +1887,7 @@ NIBBLETYPE cWorld::GetBlockBlockLight(Vector3i a_BlockPos) bool cWorld::GetBlockTypeMeta(Vector3i a_BlockPos, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) { - return m_ChunkMap->GetBlockTypeMeta(a_BlockPos, a_BlockType, a_BlockMeta); + return m_ChunkMap.GetBlockTypeMeta(a_BlockPos, a_BlockType, a_BlockMeta); } @@ -1898,7 +1896,7 @@ bool cWorld::GetBlockTypeMeta(Vector3i a_BlockPos, BLOCKTYPE & a_BlockType, NIBB bool cWorld::GetBlockInfo(Vector3i a_BlockPos, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_Meta, NIBBLETYPE & a_SkyLight, NIBBLETYPE & a_BlockLight) { - return m_ChunkMap->GetBlockInfo(a_BlockPos, a_BlockType, a_Meta, a_SkyLight, a_BlockLight); + return m_ChunkMap.GetBlockInfo(a_BlockPos, a_BlockType, a_Meta, a_SkyLight, a_BlockLight); } @@ -1907,7 +1905,7 @@ bool cWorld::GetBlockInfo(Vector3i a_BlockPos, BLOCKTYPE & a_BlockType, NIBBLETY bool cWorld::WriteBlockArea(cBlockArea & a_Area, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes) { - return m_ChunkMap->WriteBlockArea(a_Area, a_MinBlockX, a_MinBlockY, a_MinBlockZ, a_DataTypes); + return m_ChunkMap.WriteBlockArea(a_Area, a_MinBlockX, a_MinBlockY, a_MinBlockZ, a_DataTypes); } @@ -2165,7 +2163,7 @@ void cWorld::PlaceBlock(const Vector3i a_Position, const BLOCKTYPE a_BlockType, bool cWorld::GetBlocks(sSetBlockVector & a_Blocks, bool a_ContinueOnFailure) { - return m_ChunkMap->GetBlocks(a_Blocks, a_ContinueOnFailure); + return m_ChunkMap.GetBlocks(a_Blocks, a_ContinueOnFailure); } @@ -2178,7 +2176,7 @@ bool cWorld::DigBlock(Vector3i a_BlockPos, const cEntity * a_Digger) NIBBLETYPE BlockMeta; GetBlockTypeMeta(a_BlockPos, BlockType, BlockMeta); - if (!m_ChunkMap->DigBlock(a_BlockPos)) + if (!m_ChunkMap.DigBlock(a_BlockPos)) { return false; } @@ -2210,7 +2208,7 @@ bool cWorld::DropBlockAsPickups(Vector3i a_BlockPos, const cEntity * a_Digger, c cItems cWorld::PickupsFromBlock(Vector3i a_BlockPos, const cEntity * a_Digger, const cItem * a_Tool) { - return m_ChunkMap->PickupsFromBlock(a_BlockPos, a_Digger, a_Tool); + return m_ChunkMap.PickupsFromBlock(a_BlockPos, a_Digger, a_Tool); } @@ -2219,7 +2217,7 @@ cItems cWorld::PickupsFromBlock(Vector3i a_BlockPos, const cEntity * a_Digger, c void cWorld::SendBlockTo(int a_X, int a_Y, int a_Z, cPlayer & a_Player) { - m_ChunkMap->SendBlockTo(a_X, a_Y, a_Z, a_Player); + m_ChunkMap.SendBlockTo(a_X, a_Y, a_Z, a_Player); } @@ -2228,7 +2226,7 @@ void cWorld::SendBlockTo(int a_X, int a_Y, int a_Z, cPlayer & a_Player) int cWorld::GetHeight(int a_X, int a_Z) { - return m_ChunkMap->GetHeight(a_X, a_Z); + return m_ChunkMap.GetHeight(a_X, a_Z); } @@ -2237,7 +2235,7 @@ int cWorld::GetHeight(int a_X, int a_Z) bool cWorld::TryGetHeight(int a_BlockX, int a_BlockZ, int & a_Height) { - return m_ChunkMap->TryGetHeight(a_BlockX, a_BlockZ, a_Height); + return m_ChunkMap.TryGetHeight(a_BlockX, a_BlockZ, a_Height); } @@ -2246,7 +2244,7 @@ bool cWorld::TryGetHeight(int a_BlockX, int a_BlockZ, int & a_Height) void cWorld::SendBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cClientHandle & a_Client) { - m_ChunkMap->SendBlockEntity(a_BlockX, a_BlockY, a_BlockZ, a_Client); + m_ChunkMap.SendBlockEntity(a_BlockX, a_BlockY, a_BlockZ, a_Client); } @@ -2255,7 +2253,7 @@ void cWorld::SendBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cClientHa void cWorld::MarkChunkDirty(int a_ChunkX, int a_ChunkZ) { - m_ChunkMap->MarkChunkDirty(a_ChunkX, a_ChunkZ); + m_ChunkMap.MarkChunkDirty(a_ChunkX, a_ChunkZ); } @@ -2264,7 +2262,7 @@ void cWorld::MarkChunkDirty(int a_ChunkX, int a_ChunkZ) void cWorld::MarkChunkSaving(int a_ChunkX, int a_ChunkZ) { - m_ChunkMap->MarkChunkSaving(a_ChunkX, a_ChunkZ); + m_ChunkMap.MarkChunkSaving(a_ChunkX, a_ChunkZ); } @@ -2273,7 +2271,7 @@ void cWorld::MarkChunkSaving(int a_ChunkX, int a_ChunkZ) void cWorld::MarkChunkSaved (int a_ChunkX, int a_ChunkZ) { - m_ChunkMap->MarkChunkSaved (a_ChunkX, a_ChunkZ); + m_ChunkMap.MarkChunkSaved (a_ChunkX, a_ChunkZ); } @@ -2311,7 +2309,7 @@ void cWorld::SetChunkData(cSetChunkData & a_SetChunkData) ASSERT(a_SetChunkData.AreBiomesValid()); ASSERT(a_SetChunkData.IsHeightMapValid()); - m_ChunkMap->SetChunkData(a_SetChunkData); + m_ChunkMap.SetChunkData(a_SetChunkData); // Initialize the entities (outside the m_ChunkMap's CS, to fix FS #347): for (auto & Entity : a_SetChunkData.GetEntities()) @@ -2360,7 +2358,7 @@ void cWorld::ChunkLighted( const cChunkDef::BlockNibbles & a_SkyLight ) { - m_ChunkMap->ChunkLighted(a_ChunkX, a_ChunkZ, a_BlockLight, a_SkyLight); + m_ChunkMap.ChunkLighted(a_ChunkX, a_ChunkZ, a_BlockLight, a_SkyLight); } @@ -2369,7 +2367,7 @@ void cWorld::ChunkLighted( bool cWorld::GetChunkData(cChunkCoords a_Coords, cChunkDataCallback & a_Callback) const { - return m_ChunkMap->GetChunkData(a_Coords, a_Callback); + return m_ChunkMap.GetChunkData(a_Coords, a_Callback); } @@ -2378,7 +2376,7 @@ bool cWorld::GetChunkData(cChunkCoords a_Coords, cChunkDataCallback & a_Callback bool cWorld::GetChunkBlockTypes(int a_ChunkX, int a_ChunkZ, BLOCKTYPE * a_BlockTypes) { - return m_ChunkMap->GetChunkBlockTypes(a_ChunkX, a_ChunkZ, a_BlockTypes); + return m_ChunkMap.GetChunkBlockTypes(a_ChunkX, a_ChunkZ, a_BlockTypes); } @@ -2387,7 +2385,7 @@ bool cWorld::GetChunkBlockTypes(int a_ChunkX, int a_ChunkZ, BLOCKTYPE * a_BlockT bool cWorld::IsChunkQueued(int a_ChunkX, int a_ChunkZ) const { - return m_ChunkMap->IsChunkQueued(a_ChunkX, a_ChunkZ); + return m_ChunkMap.IsChunkQueued(a_ChunkX, a_ChunkZ); } @@ -2396,7 +2394,7 @@ bool cWorld::IsChunkQueued(int a_ChunkX, int a_ChunkZ) const bool cWorld::IsChunkValid(int a_ChunkX, int a_ChunkZ) const { - return m_ChunkMap->IsChunkValid(a_ChunkX, a_ChunkZ); + return m_ChunkMap.IsChunkValid(a_ChunkX, a_ChunkZ); } @@ -2405,7 +2403,7 @@ bool cWorld::IsChunkValid(int a_ChunkX, int a_ChunkZ) const bool cWorld::HasChunkAnyClients(int a_ChunkX, int a_ChunkZ) const { - return m_ChunkMap->HasChunkAnyClients(a_ChunkX, a_ChunkZ); + return m_ChunkMap.HasChunkAnyClients(a_ChunkX, a_ChunkZ); } @@ -2415,7 +2413,7 @@ bool cWorld::HasChunkAnyClients(int a_ChunkX, int a_ChunkZ) const void cWorld::UnloadUnusedChunks(void) { m_LastChunkCheck = std::chrono::duration_cast(m_WorldAge); - m_ChunkMap->UnloadUnusedChunks(); + m_ChunkMap.UnloadUnusedChunks(); } @@ -2433,7 +2431,7 @@ void cWorld::QueueUnloadUnusedChunks(void) void cWorld::CollectPickupsByPlayer(cPlayer & a_Player) { - m_ChunkMap->CollectPickupsByPlayer(a_Player); + m_ChunkMap.CollectPickupsByPlayer(a_Player); } @@ -2453,7 +2451,7 @@ void cWorld::AddPlayer(std::unique_ptr a_Player, cWorld * a_OldWorld) std::unique_ptr cWorld::RemovePlayer(cPlayer & a_Player) { // Check the chunkmap - std::unique_ptr PlayerPtr(static_cast(m_ChunkMap->RemoveEntity(a_Player).release())); + std::unique_ptr PlayerPtr(static_cast(m_ChunkMap.RemoveEntity(a_Player).release())); if (PlayerPtr != nullptr) { @@ -2489,7 +2487,7 @@ std::unique_ptr cWorld::RemovePlayer(cPlayer & a_Player) if (Client != nullptr) { Client->RemoveFromWorld(); - m_ChunkMap->RemoveClientFromChunks(Client); + m_ChunkMap.RemoveClientFromChunks(Client); cCSLock Lock(m_CSClients); m_ClientsToRemove.push_back(Client); } @@ -2721,7 +2719,7 @@ void cWorld::SendPlayerList(cPlayer * a_DestPlayer) bool cWorld::ForEachEntity(cEntityCallback a_Callback) { - return m_ChunkMap->ForEachEntity(a_Callback); + return m_ChunkMap.ForEachEntity(a_Callback); } @@ -2730,7 +2728,7 @@ bool cWorld::ForEachEntity(cEntityCallback a_Callback) bool cWorld::ForEachEntityInChunk(int a_ChunkX, int a_ChunkZ, cEntityCallback a_Callback) { - return m_ChunkMap->ForEachEntityInChunk(a_ChunkX, a_ChunkZ, a_Callback); + return m_ChunkMap.ForEachEntityInChunk(a_ChunkX, a_ChunkZ, a_Callback); } @@ -2739,7 +2737,7 @@ bool cWorld::ForEachEntityInChunk(int a_ChunkX, int a_ChunkZ, cEntityCallback a_ bool cWorld::ForEachEntityInBox(const cBoundingBox & a_Box, cEntityCallback a_Callback) { - return m_ChunkMap->ForEachEntityInBox(a_Box, a_Callback); + return m_ChunkMap.ForEachEntityInBox(a_Box, a_Callback); } @@ -2762,7 +2760,7 @@ bool cWorld::DoWithEntityByID(UInt32 a_UniqueID, cEntityCallback a_Callback) } // Then check the chunkmap: - return m_ChunkMap->DoWithEntityByID(a_UniqueID, a_Callback); + return m_ChunkMap.DoWithEntityByID(a_UniqueID, a_Callback); } @@ -2771,7 +2769,7 @@ bool cWorld::DoWithEntityByID(UInt32 a_UniqueID, cEntityCallback a_Callback) void cWorld::CompareChunkClients(int a_ChunkX1, int a_ChunkZ1, int a_ChunkX2, int a_ChunkZ2, cClientDiffCallback & a_Callback) { - m_ChunkMap->CompareChunkClients(a_ChunkX1, a_ChunkZ1, a_ChunkX2, a_ChunkZ2, a_Callback); + m_ChunkMap.CompareChunkClients(a_ChunkX1, a_ChunkZ1, a_ChunkX2, a_ChunkZ2, a_Callback); } @@ -2780,7 +2778,7 @@ void cWorld::CompareChunkClients(int a_ChunkX1, int a_ChunkZ1, int a_ChunkX2, in bool cWorld::AddChunkClient(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Client) { - return m_ChunkMap->AddChunkClient(a_ChunkX, a_ChunkZ, a_Client); + return m_ChunkMap.AddChunkClient(a_ChunkX, a_ChunkZ, a_Client); } @@ -2789,7 +2787,7 @@ bool cWorld::AddChunkClient(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Client void cWorld::RemoveChunkClient(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Client) { - m_ChunkMap->RemoveChunkClient(a_ChunkX, a_ChunkZ, a_Client); + m_ChunkMap.RemoveChunkClient(a_ChunkX, a_ChunkZ, a_Client); } @@ -2798,7 +2796,7 @@ void cWorld::RemoveChunkClient(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Cli void cWorld::RemoveClientFromChunks(cClientHandle * a_Client) { - m_ChunkMap->RemoveClientFromChunks(a_Client); + m_ChunkMap.RemoveClientFromChunks(a_Client); } @@ -2835,7 +2833,7 @@ void cWorld::RemoveClientFromChunkSender(cClientHandle * a_Client) void cWorld::PrepareChunk(int a_ChunkX, int a_ChunkZ, std::unique_ptr a_CallAfter) { - m_ChunkMap->PrepareChunk(a_ChunkX, a_ChunkZ, std::move(a_CallAfter)); + m_ChunkMap.PrepareChunk(a_ChunkX, a_ChunkZ, std::move(a_CallAfter)); } @@ -2844,7 +2842,7 @@ void cWorld::PrepareChunk(int a_ChunkX, int a_ChunkZ, std::unique_ptrChunkLoadFailed(a_ChunkX, a_ChunkZ); + m_ChunkMap.ChunkLoadFailed(a_ChunkX, a_ChunkZ); } @@ -2863,7 +2861,7 @@ bool cWorld::SetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, const AStrin return false; } - if (m_ChunkMap->SetSignLines(a_BlockX, a_BlockY, a_BlockZ, Line1, Line2, Line3, Line4)) + if (m_ChunkMap.SetSignLines(a_BlockX, a_BlockY, a_BlockZ, Line1, Line2, Line3, Line4)) { cRoot::Get()->GetPluginManager()->CallHookUpdatedSign(*this, a_BlockX, a_BlockY, a_BlockZ, Line1, Line2, Line3, Line4, a_Player); return true; @@ -2933,7 +2931,7 @@ bool cWorld::SetTrapdoorOpen(int a_BlockX, int a_BlockY, int a_BlockZ, bool a_Op void cWorld::RegenerateChunk(int a_ChunkX, int a_ChunkZ) { - m_ChunkMap->MarkChunkRegenerating(a_ChunkX, a_ChunkZ); + m_ChunkMap.MarkChunkRegenerating(a_ChunkX, a_ChunkZ); m_Generator.QueueGenerateChunk({a_ChunkX, a_ChunkZ}, true); } @@ -2943,7 +2941,7 @@ void cWorld::RegenerateChunk(int a_ChunkX, int a_ChunkZ) void cWorld::GenerateChunk(int a_ChunkX, int a_ChunkZ) { - m_ChunkMap->GenerateChunk(a_ChunkX, a_ChunkZ); + m_ChunkMap.GenerateChunk(a_ChunkX, a_ChunkZ); } @@ -2961,7 +2959,7 @@ void cWorld::QueueLightChunk(int a_ChunkX, int a_ChunkZ, std::unique_ptrIsChunkLighted(a_ChunkX, a_ChunkZ); + return m_ChunkMap.IsChunkLighted(a_ChunkX, a_ChunkZ); } @@ -2970,7 +2968,7 @@ bool cWorld::IsChunkLighted(int a_ChunkX, int a_ChunkZ) bool cWorld::ForEachChunkInRect(int a_MinChunkX, int a_MaxChunkX, int a_MinChunkZ, int a_MaxChunkZ, cChunkDataCallback & a_Callback) { - return m_ChunkMap->ForEachChunkInRect(a_MinChunkX, a_MaxChunkX, a_MinChunkZ, a_MaxChunkZ, a_Callback); + return m_ChunkMap.ForEachChunkInRect(a_MinChunkX, a_MaxChunkX, a_MinChunkZ, a_MaxChunkZ, a_Callback); } @@ -2979,7 +2977,7 @@ bool cWorld::ForEachChunkInRect(int a_MinChunkX, int a_MaxChunkX, int a_MinChunk bool cWorld::ForEachLoadedChunk(cFunctionRef a_Callback) { - return m_ChunkMap->ForEachLoadedChunk(a_Callback); + return m_ChunkMap.ForEachLoadedChunk(a_Callback); } @@ -2991,7 +2989,7 @@ void cWorld::SaveAllChunks(void) if (IsSavingEnabled()) { m_LastSave = std::chrono::duration_cast(m_WorldAge); - m_ChunkMap->SaveAllChunks(); + m_ChunkMap.SaveAllChunks(); } } @@ -3043,37 +3041,10 @@ void cWorld::AddEntity(OwnedEntity a_Entity) -bool cWorld::HasEntity(UInt32 a_UniqueID) -{ - // Check if the entity is in the queue to be added to the world: - { - cCSLock Lock(m_CSEntitiesToAdd); - for (cEntityList::const_iterator itr = m_EntitiesToAdd.begin(), end = m_EntitiesToAdd.end(); itr != end; ++itr) - { - if ((*itr)->GetUniqueID() == a_UniqueID) - { - return true; - } - } // for itr - m_EntitiesToAdd[] - } - - // Check if the entity is in the chunkmap: - if (m_ChunkMap.get() == nullptr) - { - // Chunkmap has already been destroyed, there are no entities anymore. - return false; - } - return m_ChunkMap->HasEntity(a_UniqueID); -} - - - - - OwnedEntity cWorld::RemoveEntity(cEntity & a_Entity) { // Check if the entity is in the chunkmap: - auto Entity = m_ChunkMap->RemoveEntity(a_Entity); + auto Entity = m_ChunkMap.RemoveEntity(a_Entity); if (Entity != nullptr) { Entity->OnRemoveFromWorld(*this); @@ -3103,7 +3074,7 @@ OwnedEntity cWorld::RemoveEntity(cEntity & a_Entity) size_t cWorld::GetNumChunks(void) const { - return m_ChunkMap->GetNumChunks(); + return m_ChunkMap.GetNumChunks(); } @@ -3112,7 +3083,7 @@ size_t cWorld::GetNumChunks(void) const size_t cWorld::GetNumUnusedDirtyChunks(void) const { - return m_ChunkMap->GetNumUnusedDirtyChunks(); + return m_ChunkMap.GetNumUnusedDirtyChunks(); } @@ -3121,7 +3092,7 @@ size_t cWorld::GetNumUnusedDirtyChunks(void) const void cWorld::GetChunkStats(int & a_NumValid, int & a_NumDirty, int & a_NumInLightingQueue) { - m_ChunkMap->GetChunkStats(a_NumValid, a_NumDirty); + m_ChunkMap.GetChunkStats(a_NumValid, a_NumDirty); a_NumInLightingQueue = static_cast(m_Lighting.GetQueueLength()); } @@ -3145,7 +3116,7 @@ void cWorld::TickQueuedBlocks(void) if (Block->TicksToWait <= 0) { // TODO: Handle the case when the chunk is already unloaded - m_ChunkMap->TickBlock({Block->X, Block->Y, Block->Z}); + m_ChunkMap.TickBlock({Block->X, Block->Y, Block->Z}); delete Block; // We don't have to remove it from the vector, this will happen automatically on the next tick } else @@ -3334,7 +3305,7 @@ void cWorld::TabCompleteUserName(const AString & a_Text, AStringVector & a_Resul void cWorld::SetChunkAlwaysTicked(int a_ChunkX, int a_ChunkZ, bool a_AlwaysTicked) { - m_ChunkMap->SetChunkAlwaysTicked(a_ChunkX, a_ChunkZ, a_AlwaysTicked); + m_ChunkMap.SetChunkAlwaysTicked(a_ChunkX, a_ChunkZ, a_AlwaysTicked); } @@ -3475,7 +3446,7 @@ void cWorld::AddQueuedPlayers(void) // Add to chunkmap, if not already there (Spawn vs MoveToWorld): auto PlayerPtr = Player.get(); - m_ChunkMap->AddPlayer(std::move(Player)); + m_ChunkMap.AddPlayer(std::move(Player)); PlayerPtr->OnAddToWorld(*this); ASSERT(!PlayerPtr->IsTicking()); PlayerPtr->SetIsTicking(true); diff --git a/src/World.h b/src/World.h index fb2bdfacc..b2d996870 100644 --- a/src/World.h +++ b/src/World.h @@ -307,10 +307,6 @@ public: The entity is added lazily - this function only puts it in a queue that is then processed by the Tick thread. */ void AddEntity(OwnedEntity a_Entity); - /** Returns true if an entity with the specified UniqueID exists in the world. - Note: Only loaded chunks are considered. */ - bool HasEntity(UInt32 a_UniqueID); - /** Removes the entity from the world. Returns an owning reference to the found entity. */ OwnedEntity RemoveEntity(cEntity & a_Entity); @@ -410,7 +406,7 @@ public: The replaced blocks aren't checked for block entities (block entity is leaked if it exists at this block) */ void FastSetBlock(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) { - m_ChunkMap->FastSetBlock(a_BlockPos, a_BlockType, a_BlockMeta); + m_ChunkMap.FastSetBlock(a_BlockPos, a_BlockType, a_BlockMeta); } /** OBSOLETE, use the Vector3-based overload instead. @@ -424,32 +420,32 @@ public: /** Returns the block type at the specified position. Returns 0 if the chunk is not valid. */ - BLOCKTYPE GetBlock(Vector3i a_BlockPos) + BLOCKTYPE GetBlock(Vector3i a_BlockPos) const { - return m_ChunkMap->GetBlock(a_BlockPos); + return m_ChunkMap.GetBlock(a_BlockPos); } /** OBSOLETE, use the Vector3-based overload instead. Returns the block type at the specified position. Returns 0 if the chunk is not valid. */ - BLOCKTYPE GetBlock(int a_BlockX, int a_BlockY, int a_BlockZ) + BLOCKTYPE GetBlock(int a_BlockX, int a_BlockY, int a_BlockZ) const { - return m_ChunkMap->GetBlock({a_BlockX, a_BlockY, a_BlockZ}); + return m_ChunkMap.GetBlock({a_BlockX, a_BlockY, a_BlockZ}); } /** Returns the block meta at the specified position. Returns 0 if the chunk is not valid. */ - NIBBLETYPE GetBlockMeta(Vector3i a_BlockPos) + NIBBLETYPE GetBlockMeta(Vector3i a_BlockPos) const { - return m_ChunkMap->GetBlockMeta(a_BlockPos); + return m_ChunkMap.GetBlockMeta(a_BlockPos); } /** OBSOLETE, use the Vector3-based overload instead. Returns the block meta at the specified position. Returns 0 if the chunk is not valid. */ - NIBBLETYPE GetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ) + NIBBLETYPE GetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ) const { - return m_ChunkMap->GetBlockMeta({a_BlockX, a_BlockY, a_BlockZ}); + return m_ChunkMap.GetBlockMeta({a_BlockX, a_BlockY, a_BlockZ}); } /** Sets the meta for the specified block, while keeping the blocktype. @@ -808,7 +804,7 @@ public: bool GetSignLines (int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4); // Exported in ManualBindings.cpp /** a_Player is using block entity at [x, y, z], handle that: */ - void UseBlockEntity(cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) {m_ChunkMap->UseBlockEntity(a_Player, a_BlockX, a_BlockY, a_BlockZ); } // tolua_export + void UseBlockEntity(cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) { m_ChunkMap.UseBlockEntity(a_Player, a_BlockX, a_BlockY, a_BlockZ); } // tolua_export /** Calls the callback for the chunk specified, with ChunkMapCS locked. Returns false if the chunk doesn't exist, otherwise returns the same value as the callback */ @@ -1048,7 +1044,7 @@ public: cChunkGeneratorThread & GetGenerator(void) { return m_Generator; } cWorldStorage & GetStorage (void) { return m_Storage; } - cChunkMap * GetChunkMap (void) { return m_ChunkMap.get(); } + cChunkMap * GetChunkMap (void) { return &m_ChunkMap; } /** Causes the specified block to be ticked on the next Tick() call. Only one block coord per chunk may be set, a second call overwrites the first call */ @@ -1211,7 +1207,7 @@ private: unsigned int m_MaxPlayers; - std::unique_ptr m_ChunkMap; + cChunkMap m_ChunkMap; bool m_bAnimals; std::set m_AllowedMobs; -- cgit v1.2.3