Clean up pickup collection to use ForEachEntityInBox
This commit is contained in:
parent
167247328a
commit
071aee6c79
|
@ -1496,42 +1496,6 @@ void cChunk::SetAreaBiome(int a_MinRelX, int a_MaxRelX, int a_MinRelZ, int a_Max
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cChunk::CollectPickupsByPlayer(cPlayer & a_Player)
|
|
||||||
{
|
|
||||||
auto BoundingBox = a_Player.GetBoundingBox();
|
|
||||||
BoundingBox.Expand(1, 0.5, 1);
|
|
||||||
|
|
||||||
for (auto & Entity : m_Entities)
|
|
||||||
{
|
|
||||||
if ((!Entity->IsPickup()) && (!Entity->IsProjectile()))
|
|
||||||
{
|
|
||||||
continue; // Only pickups and projectiles can be picked up
|
|
||||||
}
|
|
||||||
|
|
||||||
if (BoundingBox.IsInside(Entity->GetPosition()))
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
LOG("Pickup %d being collected by player \"%s\", distance %f",
|
|
||||||
(*itr)->GetUniqueID(), a_Player->GetName().c_str(), SqrDist
|
|
||||||
);
|
|
||||||
*/
|
|
||||||
MarkDirty();
|
|
||||||
if (Entity->IsPickup())
|
|
||||||
{
|
|
||||||
static_cast<cPickup &>(*Entity).CollectedBy(a_Player);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
static_cast<cProjectileEntity &>(*Entity).CollectedBy(a_Player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool cChunk::SetSignLines(int a_PosX, int a_PosY, int a_PosZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4)
|
bool cChunk::SetSignLines(int a_PosX, int a_PosY, int a_PosZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4)
|
||||||
{
|
{
|
||||||
// Also sends update packets to all clients in the chunk
|
// Also sends update packets to all clients in the chunk
|
||||||
|
|
|
@ -218,8 +218,6 @@ public:
|
||||||
Sends the chunk to all relevant clients. */
|
Sends the chunk to all relevant clients. */
|
||||||
void SetAreaBiome(int a_MinRelX, int a_MaxRelX, int a_MinRelZ, int a_MaxRelZ, EMCSBiome a_Biome);
|
void SetAreaBiome(int a_MinRelX, int a_MaxRelX, int a_MinRelZ, int a_MaxRelZ, EMCSBiome a_Biome);
|
||||||
|
|
||||||
void CollectPickupsByPlayer(cPlayer & a_Player);
|
|
||||||
|
|
||||||
/** Sets the sign text. Returns true if successful. Also sends update packets to all clients in the chunk */
|
/** Sets the sign text. Returns true if successful. Also sends update packets to all clients in the chunk */
|
||||||
bool SetSignLines(int a_RelX, int a_RelY, int a_RelZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4);
|
bool SetSignLines(int a_RelX, int a_RelY, int a_RelZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4);
|
||||||
|
|
||||||
|
|
|
@ -418,25 +418,31 @@ void cChunkMap::FastSetBlock(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLET
|
||||||
|
|
||||||
void cChunkMap::CollectPickupsByPlayer(cPlayer & a_Player)
|
void cChunkMap::CollectPickupsByPlayer(cPlayer & a_Player)
|
||||||
{
|
{
|
||||||
int BlockX = static_cast<int>(a_Player.GetPosX()); // Truncating doesn't matter much; we're scanning entire chunks anyway
|
|
||||||
int BlockY = static_cast<int>(a_Player.GetPosY());
|
|
||||||
int BlockZ = static_cast<int>(a_Player.GetPosZ());
|
|
||||||
int ChunkX = 0, ChunkZ = 0;
|
|
||||||
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
|
|
||||||
int OtherChunkX = ChunkX + ((BlockX > 8) ? 1 : -1);
|
|
||||||
int OtherChunkZ = ChunkZ + ((BlockZ > 8) ? 1 : -1);
|
|
||||||
|
|
||||||
// We suppose that each player keeps their chunks in memory, therefore it makes little sense to try to re-load or even generate them.
|
|
||||||
// The only time the chunks are not valid is when the player is downloading the initial world and they should not call this at that moment
|
|
||||||
|
|
||||||
cCSLock Lock(m_CSChunks);
|
cCSLock Lock(m_CSChunks);
|
||||||
GetChunkNoLoad(ChunkX, ChunkZ)->CollectPickupsByPlayer(a_Player);
|
|
||||||
|
|
||||||
// Check the neighboring chunks as well:
|
auto BoundingBox = a_Player.GetBoundingBox();
|
||||||
GetChunkNoLoad(OtherChunkX, ChunkZ)->CollectPickupsByPlayer (a_Player);
|
BoundingBox.Expand(1, 0.5, 1);
|
||||||
GetChunkNoLoad(OtherChunkX, OtherChunkZ)->CollectPickupsByPlayer(a_Player);
|
|
||||||
GetChunkNoLoad(ChunkX, ChunkZ)->CollectPickupsByPlayer (a_Player);
|
ForEachEntityInBox(BoundingBox, [&a_Player](cEntity & Entity)
|
||||||
GetChunkNoLoad(ChunkX, OtherChunkZ)->CollectPickupsByPlayer(a_Player);
|
{
|
||||||
|
// Only pickups and projectiles can be picked up:
|
||||||
|
if (Entity.IsPickup())
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
LOG("Pickup %d being collected by player \"%s\", distance %f",
|
||||||
|
(*itr)->GetUniqueID(), a_Player->GetName().c_str(), SqrDist
|
||||||
|
);
|
||||||
|
*/
|
||||||
|
static_cast<cPickup &>(Entity).CollectedBy(a_Player);
|
||||||
|
}
|
||||||
|
else if (Entity.IsProjectile())
|
||||||
|
{
|
||||||
|
static_cast<cProjectileEntity &>(Entity).CollectedBy(a_Player);
|
||||||
|
}
|
||||||
|
|
||||||
|
// The entities will MarkDirty when they Destroy themselves
|
||||||
|
return false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user