2022-12-31 20:52:01 +08:00

112 lines
2.1 KiB
C++

#include "precompile.h"
#include "entity.h"
#include "room.h"
#include "human.h"
#include "app.h"
#include "perfmonitor.h"
Entity::Entity()
{
entity_weak_ptr_chunk_.Set(this);
}
Entity::~Entity()
{
}
void Entity::Initialize()
{
}
void Entity::BroadcastFullState(Room* room)
{
std::set<GridCell*> tmp_grids;
room->grid_service->GetAllCells(room, grid_id_, tmp_grids);
room->grid_service->TraverseAllLayerHumanList
(
room->GetRoomIdx(),
tmp_grids,
[this] (Human* hum, bool& stop)
{
hum->AddToNewObjects(this);
});
}
void Entity::BroadcastDeleteState(Room* room)
{
#if 0
room->TraverseHumanList
(
[this] (Human* hum) -> bool
{
hum->RemoveObjects(this);
return true;
});
#else
std::set<GridCell*> tmp_grids;
room->grid_service->GetAllCells(room, grid_id_, tmp_grids);
room->grid_service->TraverseAllLayerHumanList
(
room->GetRoomIdx(),
tmp_grids,
[this] (Human* hum, bool& stop)
{
hum->RemoveObjects(this);
});
#endif
}
void Entity::RemoveFromAroundPlayers(Room* room)
{
#if 1
room->TraverseHumanList
(
[this] (Human* hum) -> bool
{
hum->RemovePartObjects(this);
return true;
});
#else
std::set<GridCell*> tmp_grids;
room->grid_service->GetAllCells(room, grid_id_, tmp_grids);
room->grid_service->TraverseAllLayerHumanList
(
room->GetRoomIdx(),
tmp_grids,
[this] (Human* hum, bool& stop)
{
hum->RemovePartObjects(this);
});
#endif
}
bool Entity::IsClientCached(Human* hum)
{
return false;
}
bool Entity::CanClientCache(Human* hum)
{
return false;
}
void Entity::AddClientCache(Human* hum)
{
}
EntityWeakPtr Entity::AllocEntityWeakPtr()
{
EntityWeakPtr ptr;
ptr.Attach(this);
return ptr;
}
EntityWeakPtr& Entity::GetEntityWeakPtrRef()
{
if (!entity_weak_ptr_.Get()) {
entity_weak_ptr_.Attach(this);
}
return entity_weak_ptr_;
}