Merge pull request #3105 from LogicParrot/chunkStability
Entities are never lost
This commit is contained in:
commit
0f2cebb786
@ -693,10 +693,9 @@ void cChunk::MoveEntityToNewChunk(cEntity * a_Entity)
|
|||||||
cChunk * Neighbor = GetNeighborChunk(a_Entity->GetChunkX() * cChunkDef::Width, a_Entity->GetChunkZ() * cChunkDef::Width);
|
cChunk * Neighbor = GetNeighborChunk(a_Entity->GetChunkX() * cChunkDef::Width, a_Entity->GetChunkZ() * cChunkDef::Width);
|
||||||
if (Neighbor == nullptr)
|
if (Neighbor == nullptr)
|
||||||
{
|
{
|
||||||
Neighbor = m_ChunkMap->GetChunkNoLoad(a_Entity->GetChunkX(), a_Entity->GetChunkZ());
|
Neighbor = m_ChunkMap->GetChunk(a_Entity->GetChunkX(), a_Entity->GetChunkZ());
|
||||||
if (Neighbor == nullptr)
|
if (Neighbor == nullptr) // This will assert inside GetChunk in debug builds
|
||||||
{
|
{
|
||||||
// TODO: What to do with this?
|
|
||||||
LOGWARNING("%s: Failed to move entity, destination chunk unreachable. Entity lost", __FUNCTION__);
|
LOGWARNING("%s: Failed to move entity, destination chunk unreachable. Entity lost", __FUNCTION__);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1623,11 +1623,8 @@ void cChunkMap::RemoveClientFromChunks(cClientHandle * a_Client)
|
|||||||
void cChunkMap::AddEntity(cEntity * a_Entity)
|
void cChunkMap::AddEntity(cEntity * a_Entity)
|
||||||
{
|
{
|
||||||
cCSLock Lock(m_CSLayers);
|
cCSLock Lock(m_CSLayers);
|
||||||
cChunkPtr Chunk = GetChunkNoGen(a_Entity->GetChunkX(), a_Entity->GetChunkZ());
|
cChunkPtr Chunk = GetChunk(a_Entity->GetChunkX(), a_Entity->GetChunkZ());
|
||||||
if (
|
if (Chunk == nullptr) // This will assert inside GetChunk in Debug builds
|
||||||
(Chunk == nullptr) || // Chunk not present at all
|
|
||||||
(!Chunk->IsValid() && !a_Entity->IsPlayer()) // Chunk present, but no valid data; players need to spawn in such chunks (#953)
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
LOGWARNING("Entity at %p (%s, ID %d) spawning in a non-existent chunk, the entity is lost.",
|
LOGWARNING("Entity at %p (%s, ID %d) spawning in a non-existent chunk, the entity is lost.",
|
||||||
static_cast<void *>(a_Entity), a_Entity->GetClass(), a_Entity->GetUniqueID()
|
static_cast<void *>(a_Entity), a_Entity->GetClass(), a_Entity->GetUniqueID()
|
||||||
@ -1644,11 +1641,8 @@ void cChunkMap::AddEntity(cEntity * a_Entity)
|
|||||||
void cChunkMap::AddEntityIfNotPresent(cEntity * a_Entity)
|
void cChunkMap::AddEntityIfNotPresent(cEntity * a_Entity)
|
||||||
{
|
{
|
||||||
cCSLock Lock(m_CSLayers);
|
cCSLock Lock(m_CSLayers);
|
||||||
cChunkPtr Chunk = GetChunkNoGen(a_Entity->GetChunkX(), a_Entity->GetChunkZ());
|
cChunkPtr Chunk = GetChunk(a_Entity->GetChunkX(), a_Entity->GetChunkZ());
|
||||||
if (
|
if (Chunk == nullptr) // This will assert inside GetChunk in Debug builds
|
||||||
(Chunk == nullptr) || // Chunk not present at all
|
|
||||||
(!Chunk->IsValid() && !a_Entity->IsPlayer()) // Chunk present, but no valid data; players need to spawn in such chunks (#953)
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
LOGWARNING("Entity at %p (%s, ID %d) spawning in a non-existent chunk, the entity is lost.",
|
LOGWARNING("Entity at %p (%s, ID %d) spawning in a non-existent chunk, the entity is lost.",
|
||||||
static_cast<void *>(a_Entity), a_Entity->GetClass(), a_Entity->GetUniqueID()
|
static_cast<void *>(a_Entity), a_Entity->GetClass(), a_Entity->GetUniqueID()
|
||||||
|
@ -1014,15 +1014,12 @@ void cWorld::Tick(std::chrono::milliseconds a_Dt, std::chrono::milliseconds a_La
|
|||||||
// Add entities waiting in the queue to be added:
|
// Add entities waiting in the queue to be added:
|
||||||
{
|
{
|
||||||
cCSLock Lock(m_CSEntitiesToAdd);
|
cCSLock Lock(m_CSEntitiesToAdd);
|
||||||
for (cEntityList::iterator itr = m_EntitiesToAdd.begin(), end = m_EntitiesToAdd.end(); itr != end; ++itr)
|
for (auto & Entity : m_EntitiesToAdd)
|
||||||
{
|
{
|
||||||
(*itr)->SetWorld(this);
|
Entity->SetWorld(this);
|
||||||
m_ChunkMap->AddEntity(*itr);
|
m_ChunkMap->AddEntity(Entity);
|
||||||
ASSERT(!(*itr)->IsTicking());
|
ASSERT(!Entity->IsTicking());
|
||||||
if (m_ChunkMap->HasEntity((*itr)->GetUniqueID()))
|
Entity->SetIsTicking(true);
|
||||||
{
|
|
||||||
(*itr)->SetIsTicking(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
m_EntitiesToAdd.clear();
|
m_EntitiesToAdd.clear();
|
||||||
}
|
}
|
||||||
@ -3820,21 +3817,18 @@ void cWorld::AddQueuedPlayers(void)
|
|||||||
// Add all the players in the grabbed list:
|
// Add all the players in the grabbed list:
|
||||||
{
|
{
|
||||||
cCSLock Lock(m_CSPlayers);
|
cCSLock Lock(m_CSPlayers);
|
||||||
for (cPlayerList::iterator itr = PlayersToAdd.begin(), end = PlayersToAdd.end(); itr != end; ++itr)
|
for (auto Player : m_Players)
|
||||||
{
|
{
|
||||||
ASSERT(std::find(m_Players.begin(), m_Players.end(), *itr) == m_Players.end()); // Is it already in the list? HOW?
|
ASSERT(std::find(m_Players.begin(), m_Players.end(), Player) == m_Players.end()); // Is it already in the list? HOW?
|
||||||
LOGD("Adding player %s to world \"%s\".", (*itr)->GetName().c_str(), m_WorldName.c_str());
|
LOGD("Adding player %s to world \"%s\".", Player->GetName().c_str(), m_WorldName.c_str());
|
||||||
|
|
||||||
m_Players.push_back(*itr);
|
m_Players.push_back(Player);
|
||||||
(*itr)->SetWorld(this);
|
Player->SetWorld(this);
|
||||||
|
|
||||||
// Add to chunkmap, if not already there (Spawn vs MoveToWorld):
|
// Add to chunkmap, if not already there (Spawn vs MoveToWorld):
|
||||||
m_ChunkMap->AddEntityIfNotPresent(*itr);
|
m_ChunkMap->AddEntityIfNotPresent(Player);
|
||||||
ASSERT(!(*itr)->IsTicking());
|
ASSERT(!Player->IsTicking());
|
||||||
if (m_ChunkMap->HasEntity((*itr)->GetUniqueID()))
|
Player->SetIsTicking(true);
|
||||||
{
|
|
||||||
(*itr)->SetIsTicking(true);
|
|
||||||
}
|
|
||||||
} // for itr - PlayersToAdd[]
|
} // for itr - PlayersToAdd[]
|
||||||
} // Lock(m_CSPlayers)
|
} // Lock(m_CSPlayers)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user