remove beadded

This commit is contained in:
aozhiwei 2019-04-24 13:37:05 +08:00
parent 3ac23bdc69
commit 8368c6eeb5
9 changed files with 53 additions and 66 deletions

View File

@ -51,7 +51,7 @@ void Bullet::Update(int delta_time)
if (!objects.empty()) {
OnHit(objects);
}
room->AddDeletedObject(entity_uniid, true);
room->RemoveObjectLater(this);
}
}
}
@ -123,5 +123,5 @@ void Bullet::ProcBomb()
}
break;
}
room->AddDeletedObject(entity_uniid, true);
room->RemoveObjectLater(this);
}

View File

@ -109,3 +109,4 @@ const int SMOKE_SLOT = 4;
const int MAP_HEIGHT = 8192;
const int MAP_WIDTH = 8192;
const int MAP_CELL_WIDTH = 64 * 5;

View File

@ -93,3 +93,8 @@ void Entity::BroadcastFullState()
});
#endif
}
void Entity::BroadcastDeleteState()
{
}

View File

@ -66,5 +66,6 @@ class Entity
void ClearColliders();
void FindLocationWithTarget(Entity* target);
void BroadcastFullState();
void BroadcastDeleteState();
};

View File

@ -49,6 +49,11 @@ void GridService::UnInit()
}
}
bool GridService::BroderOverFlow(int x, int y)
{
return x <= min_x_ || x >= max_x_ || y <= min_y_ || y >= max_y_;
}
void GridService::Get123456789(int grid_id, std::set<GridCell*>& grid_list)
{
for (size_t i = 1; i <= 9; ++i) {

View File

@ -25,6 +25,7 @@ class GridService
void Init(int width, int height, int cell_width);
void UnInit();
bool BroderOverFlow(int x, int y);
void Get123456789(int grid_id, std::set<GridCell*>& grid_list);
void Get123(int grid_id, std::set<GridCell*>& grid_list);
void Get456(int grid_id, std::set<GridCell*>& grid_list);

View File

@ -694,7 +694,7 @@ void Player::LootInteraction(Loot* entity)
break;
}
entity->pickuped = true;
room->AddDeletedObject(entity->entity_uniid, false);
room->RemoveObjectLater(entity);
}
void Player::HumanInteraction(Human* hum)

View File

@ -43,6 +43,7 @@ void Room::Init()
{
xtimer.Init(RoomXGetTickCount, this, 100, 100);
xtimer_attacher.xtimer = &xtimer;
grid_service.Init(MAP_WIDTH, MAP_HEIGHT, MAP_CELL_WIDTH);
ShuaAndroid();
CreateThings();
@ -108,7 +109,6 @@ void Room::Update(int delta_time)
pair.second->SendUpdateMsg();
}
ClearDeletedObjects();
ProcAddedObjects();
#if 0
{
{
@ -274,7 +274,6 @@ void Room::AddPlayer(Player* hum)
unsigned short Room::AllocUniid()
{
while (GetEntityByUniId(++current_uniid) ||
be_added_hash_.find(current_uniid) != be_added_hash_.end() ||
current_uniid == 0) {}
return current_uniid;
}
@ -395,29 +394,6 @@ void Room::BuildingBoxBoundCollisionDetection(Entity* sender, std::vector<Entity
DestoryCollider(a_collider);
}
void Room::AddDeletedObject(unsigned short obj_uniid, bool soft_delete)
{
#if 0
std::set<unsigned short>* deleted_objects = nullptr;
if (soft_delete) {
auto itr = frame_data.softdeleted_objects_hash.find(frame_no);
if (itr == frame_data.softdeleted_objects_hash.end()) {
frame_data.softdeleted_objects_hash[frame_no] = std::set<unsigned short>();
itr = frame_data.softdeleted_objects_hash.find(frame_no);
}
deleted_objects = &itr->second;
} else {
auto itr = frame_data.deleted_objects_hash.find(frame_no);
if (itr == frame_data.deleted_objects_hash.end()) {
frame_data.deleted_objects_hash[frame_no] = std::set<unsigned short>();
itr = frame_data.deleted_objects_hash.find(frame_no);
}
deleted_objects = &itr->second;
}
deleted_objects->insert(obj_uniid);
#endif
}
void Room::FillSMJoinedNotify(Player* self_hum, cs::SMJoinedNotify& msg)
{
msg.set_team_mode(msg.team_mode());
@ -650,7 +626,41 @@ void Room::CreateBullet(Human* hum, MetaData::Equip* gun_meta,
bullet->fly_distance = fly_distance;
bullet->entity_uniid = AllocUniid();
bullet->Initialize();
#if 0
be_added_hash_[bullet->entity_uniid] = bullet;
#endif
}
void Room::RemoveObjectLater(Entity* entity)
{
auto remove_func = [] (const a8::XParams& param)
{
Entity* entity = (Entity*)param.sender.GetUserData();
entity->room->uniid_hash_.erase(entity->entity_uniid);
switch (entity->entity_type) {
case ET_Bullet:
{
entity->room->moveable_hash_.erase(entity->entity_uniid);
}
break;
case ET_Loot:
{
entity->BroadcastDeleteState();
}
break;
default:
{
}
break;
}
delete entity;
};
xtimer.AddDeadLineTimerAndAttach(0,
a8::XParams()
.SetSender(entity),
remove_func,
&entity->xtimer_attacher.timer_list_);
}
void Room::FetchBuilding(Human* hum)
@ -756,39 +766,6 @@ void Room::TouchEntityList(a8::XParams param,
}
}
void Room::ProcAddedObjects()
{
if (!be_added_hash_.empty()) {
for (auto& pair : be_added_hash_) {
uniid_hash_[pair.second->entity_uniid] = pair.second;
switch (pair.second->entity_type) {
case ET_Player:
case ET_Bullet:
{
moveable_hash_[pair.second->entity_uniid] = pair.second;
}
break;
case ET_Smoke:
{
for (auto& pair : human_hash_) {
pair.second->RemoveNewObjects(pair.second);
}
}
break;
default:
abort();
break;
}
}
be_added_hash_.clear();
}
}
void Room::BeAddedObject(Entity* entity)
{
be_added_hash_[entity->entity_uniid] = entity;
}
void Room::UpdateGas()
{
switch (gas_data.gas_mode) {
@ -975,7 +952,7 @@ void Room::OutputDebugLog()
a8::UdpLog::Instance()->Debug("roomid:%d max_rundelay:%d frame_no:%d game_over:%d game_over_frameno:%d "
"elapsed_time:%d alive_count:%d current_uniid:%d "
"state:%d accountid_hash.size:%d moveable_hash_.size:%d "
"uniid_hash.size:%d human_hash.size:%d be_added_hash:%d",
"uniid_hash.size:%d human_hash.size:%d ",
{
room_uuid,
profile.max_rundelay,
@ -990,7 +967,6 @@ void Room::OutputDebugLog()
moveable_hash_.size(),
uniid_hash_.size(),
human_hash_.size(),
be_added_hash_.size()
});
{
int entity_num_arr[ET_MAX] = {0};

View File

@ -58,8 +58,7 @@ public:
void CollisionDetection(Entity* sender, int detection_flags, std::vector<Entity*>& objects);
void BuildingBoxBoundCollisionDetection(Entity* sender, std::vector<Entity*>& objects);
void AddDeletedObject(unsigned short obj_uniid, bool soft_delete);
void BeAddedObject(Entity* entity);
void RemoveObjectLater(Entity* entity);
void FetchBuilding(Human* hum);
void FillSMJoinedNotify(Player* self_hum, cs::SMJoinedNotify& msg);
@ -117,5 +116,4 @@ private:
std::map<unsigned short, Entity*> moveable_hash_;
std::map<unsigned short, Entity*> uniid_hash_;
std::map<unsigned short, Human*> human_hash_;
std::map<unsigned short, Entity*> be_added_hash_;
};