From ef1f371dab95522343b27c5bed65ffe655666294 Mon Sep 17 00:00:00 2001 From: peterbell10 Date: Tue, 5 Sep 2017 15:11:35 +0100 Subject: Add cWorld::RemoveEntity and use in cEntity (#4003) * Add cWorld::RemoveEntity and use in cEntity * cEntity: Remove uneeded asserts from Destroy and DoMoveToWorld --- src/World.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/World.cpp') diff --git a/src/World.cpp b/src/World.cpp index acec3049e..0ecf9a274 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -3709,6 +3709,36 @@ bool cWorld::HasEntity(UInt32 a_UniqueID) +OwnedEntity cWorld::RemoveEntity(cEntity & a_Entity) +{ + // Check if the entity is in the chunkmap: + auto Entity = m_ChunkMap->RemoveEntity(a_Entity); + if (Entity != nullptr) + { + return Entity; + } + + // Check if the entity is in the queue to be added to the world: + cCSLock Lock(m_CSEntitiesToAdd); + auto itr = std::find_if(m_EntitiesToAdd.begin(), m_EntitiesToAdd.end(), + [&a_Entity](const OwnedEntity & a_OwnedEntity) + { + return (a_OwnedEntity.get() == &a_Entity); + } + ); + + if (itr != m_EntitiesToAdd.end()) + { + Entity = std::move(*itr); + m_EntitiesToAdd.erase(itr); + } + return Entity; +} + + + + + /* unsigned int cWorld::GetNumPlayers(void) { -- cgit v1.2.3 From 104f9e127b259731836c2b88d74a8d731f3ad535 Mon Sep 17 00:00:00 2001 From: Bond-009 Date: Thu, 7 Sep 2017 10:25:34 +0200 Subject: Changed some int parameters to vector parameters (#3937) --- src/World.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/World.cpp') diff --git a/src/World.cpp b/src/World.cpp index 0ecf9a274..f610d4d2e 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -2306,9 +2306,9 @@ UInt32 cWorld::SpawnMinecart(double a_X, double a_Y, double a_Z, int a_MinecartT -UInt32 cWorld::SpawnBoat(double a_X, double a_Y, double a_Z, cBoat::eMaterial a_Material) +UInt32 cWorld::SpawnBoat(Vector3d a_Pos, cBoat::eMaterial a_Material) { - auto Boat = cpp14::make_unique(a_X, a_Y, a_Z, a_Material); + auto Boat = cpp14::make_unique(a_Pos, a_Material); auto BoatPtr = Boat.get(); if (!BoatPtr->Initialize(std::move(Boat), *this)) { @@ -2320,9 +2320,9 @@ UInt32 cWorld::SpawnBoat(double a_X, double a_Y, double a_Z, cBoat::eMaterial a_ -UInt32 cWorld::SpawnPrimedTNT(double a_X, double a_Y, double a_Z, int a_FuseTicks, double a_InitialVelocityCoeff) +UInt32 cWorld::SpawnPrimedTNT(Vector3d a_Pos, int a_FuseTicks, double a_InitialVelocityCoeff) { - auto TNT = cpp14::make_unique(a_X, a_Y, a_Z, a_FuseTicks); + auto TNT = cpp14::make_unique(a_Pos, a_FuseTicks); auto TNTPtr = TNT.get(); if (!TNTPtr->Initialize(std::move(TNT), *this)) { -- cgit v1.2.3 From b12f4ef7d58cfe4d815feb2db1f88f223c7f2a61 Mon Sep 17 00:00:00 2001 From: Lane Kolbly Date: Thu, 7 Sep 2017 07:41:16 -0500 Subject: Made world data paths adjustable, and added API to temporarily disable saving chunks to disk. (#3912) --- src/World.cpp | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'src/World.cpp') diff --git a/src/World.cpp b/src/World.cpp index f610d4d2e..e2ac24e71 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -120,16 +120,18 @@ void cWorld::cTickThread::Execute(void) //////////////////////////////////////////////////////////////////////////////// // cWorld: -cWorld::cWorld(const AString & a_WorldName, eDimension a_Dimension, const AString & a_LinkedOverworldName) : +cWorld::cWorld(const AString & a_WorldName, const AString & a_DataPath, eDimension a_Dimension, const AString & a_LinkedOverworldName) : m_WorldName(a_WorldName), + m_DataPath(a_DataPath), m_LinkedOverworldName(a_LinkedOverworldName), - m_IniFileName(m_WorldName + "/world.ini"), + m_IniFileName(m_DataPath + "/world.ini"), m_StorageSchema("Default"), #ifdef __arm__ m_StorageCompressionFactor(0), #else m_StorageCompressionFactor(6), #endif + m_IsSavingEnabled(true), m_Dimension(a_Dimension), m_IsSpawnExplicitlySet(false), m_SpawnX(0), @@ -194,10 +196,10 @@ cWorld::cWorld(const AString & a_WorldName, eDimension a_Dimension, const AStrin { LOGD("cWorld::cWorld(\"%s\")", a_WorldName.c_str()); - cFile::CreateFolder(FILE_IO_PREFIX + m_WorldName); + cFile::CreateFolderRecursive(FILE_IO_PREFIX + m_DataPath); // Load the scoreboard - cScoreboardSerializer Serializer(m_WorldName, &m_Scoreboard); + cScoreboardSerializer Serializer(m_DataPath, &m_Scoreboard); Serializer.Load(); } @@ -213,11 +215,14 @@ cWorld::~cWorld() m_Storage.WaitForFinish(); - // Unload the scoreboard - cScoreboardSerializer Serializer(m_WorldName, &m_Scoreboard); - Serializer.Save(); + if (IsSavingEnabled()) + { + // Unload the scoreboard + cScoreboardSerializer Serializer(m_DataPath, &m_Scoreboard); + Serializer.Save(); - m_MapManager.SaveMapData(); + m_MapManager.SaveMapData(); + } // Explicitly destroy the chunkmap, so that it's guaranteed to be destroyed before the other internals // This fixes crashes on stopping the server, because chunk destructor deletes entities and those access the world. @@ -2965,7 +2970,9 @@ void cWorld::SetChunkData(cSetChunkData & a_SetChunkData) ); // Save the chunk right after generating, so that we don't have to generate it again on next run - if (a_SetChunkData.ShouldMarkDirty()) + // If saving is disabled, then the chunk was marked dirty so it will get + // saved if saving is later enabled. + if (a_SetChunkData.ShouldMarkDirty() && IsSavingEnabled()) { m_Storage.QueueSaveChunk(ChunkX, ChunkZ); } @@ -3629,8 +3636,11 @@ bool cWorld::ForEachLoadedChunk(std::function a_Callback) void cWorld::SaveAllChunks(void) { - m_LastSave = std::chrono::duration_cast(m_WorldAge); - m_ChunkMap->SaveAllChunks(); + if (IsSavingEnabled()) + { + m_LastSave = std::chrono::duration_cast(m_WorldAge); + m_ChunkMap->SaveAllChunks(); + } } -- cgit v1.2.3