对应room hash对象优化
This commit is contained in:
parent
9dc9ae6cde
commit
0d06f71e09
@ -222,7 +222,8 @@ void Room::ShowAndroid(Human* target, int num)
|
||||
int i = 0;
|
||||
for (auto& pair : human_hash_) {
|
||||
Human* hum = pair.second;
|
||||
if (a8::HasBitFlag(hum->status, HS_Disable)) {
|
||||
if (hum->IsAndroid() &&
|
||||
a8::HasBitFlag(hum->status, HS_Disable)) {
|
||||
if (hum->born_point) {
|
||||
DecBornPointHumanNum(hum->born_point, hum);
|
||||
}
|
||||
@ -337,7 +338,9 @@ void Room::ScatterDrop(a8::Vec2 center, int drop_id)
|
||||
for (auto& item : drop_items) {
|
||||
a8::Vec2 dir = a8::Vec2::UP;
|
||||
dir.Rotate(a8::RandAngle());
|
||||
DropItem(center + dir * (5 + rand() % 50), std::get<0>(item), std::get<1>(item), std::get<1>(item));
|
||||
DropItem(center + dir * (5 + rand() % 50),
|
||||
std::get<0>(item), std::get<1>(item),
|
||||
std::get<1>(item));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -406,7 +409,7 @@ int Room::CreateLoot(int equip_id, a8::Vec2 pos, int count, int equip_lv)
|
||||
entity->count = count;
|
||||
entity->item_level = equip_lv;
|
||||
entity->Initialize();
|
||||
uniid_hash_[entity->entity_uniid] = entity;
|
||||
AddToEntityHash(entity);
|
||||
grid_service->AddRoomEntity(this, entity);
|
||||
entity->BroadcastFullState(this);
|
||||
return entity->entity_uniid;
|
||||
@ -446,7 +449,7 @@ void Room::RemoveObjectLater(RoomEntity* entity)
|
||||
switch (entity->entity_type) {
|
||||
case ET_Bullet:
|
||||
{
|
||||
entity->room->moveable_hash_.erase(entity->entity_uniid);
|
||||
entity->room->RemoveFromMoveableHash((Bullet*)entity);
|
||||
entity->room->grid_service->DelBullet((Bullet*)entity);
|
||||
}
|
||||
break;
|
||||
@ -458,8 +461,8 @@ void Room::RemoveObjectLater(RoomEntity* entity)
|
||||
break;
|
||||
case ET_Player:
|
||||
{
|
||||
entity->room->moveable_hash_.erase(entity->entity_uniid);
|
||||
entity->room->human_hash_.erase(entity->entity_uniid);
|
||||
entity->room->RemoveFromMoveableHash((Human*)entity);
|
||||
entity->room->RemoveFromHuamnHash((Human*)entity);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -468,7 +471,7 @@ void Room::RemoveObjectLater(RoomEntity* entity)
|
||||
}
|
||||
break;
|
||||
}
|
||||
entity->room->uniid_hash_.erase(entity->entity_uniid);
|
||||
entity->room->RemoveFromEntityHash(entity);
|
||||
delete entity;
|
||||
};
|
||||
xtimer.AddDeadLineTimerAndAttach(0,
|
||||
@ -482,7 +485,7 @@ void Room::OnHumanDie(Human* hum)
|
||||
{
|
||||
--alive_count_;
|
||||
--App::Instance()->perf.alive_count;
|
||||
alive_human_hash_.erase(hum->entity_uniid);
|
||||
RemoveFromAliveHumanHash(hum);
|
||||
NotifyUiUpdate();
|
||||
}
|
||||
|
||||
@ -1228,7 +1231,7 @@ RoomObstacle* Room::InternalCreateObstacle(int id, float x, float y,
|
||||
if (on_precreate) {
|
||||
on_precreate(entity);
|
||||
}
|
||||
uniid_hash_[entity->entity_uniid] = entity;
|
||||
AddToEntityHash(entity);
|
||||
grid_service->AddRoomEntity(this, entity);
|
||||
return entity;
|
||||
}
|
||||
@ -1242,12 +1245,12 @@ void Room::AddObjectLater(RoomEntity* entity)
|
||||
RoomEntity* entity = (RoomEntity*)param.sender.GetUserData();
|
||||
if (entity->entity_type == ET_Bullet) {
|
||||
MoveableEntity* moveableentity = (MoveableEntity*)entity;
|
||||
entity->room->moveable_hash_[entity->entity_uniid] = moveableentity;
|
||||
entity->room->AddToMoveableHash(moveableentity);
|
||||
}
|
||||
entity->room->uniid_hash_[entity->entity_uniid] = entity;
|
||||
entity->room->later_add_hash_.erase(entity->entity_uniid);
|
||||
entity->room->AddToEntityHash(entity);
|
||||
entity->room->RemoveFromLaterAddHash(entity);
|
||||
};
|
||||
later_add_hash_[entity->entity_uniid] = entity;
|
||||
AddToLaterAddHash(entity);
|
||||
xtimer.AddDeadLineTimerAndAttach(0,
|
||||
a8::XParams()
|
||||
.SetSender(entity),
|
||||
@ -1715,12 +1718,12 @@ void Room::EnableHuman(Human* target)
|
||||
a8::UnSetBitFlag(target->status, HS_Disable);
|
||||
target->OnEnable();
|
||||
target->enable_frameno = GetFrameNo();
|
||||
moveable_hash_[target->entity_uniid] = target;
|
||||
AddToMoveableHash(target);
|
||||
grid_service->AddHuman(target);
|
||||
target->FindLocation();
|
||||
target->RefreshView();
|
||||
if (!target->real_dead) {
|
||||
alive_human_hash_[target->entity_uniid] = target;
|
||||
AddToAliveHumanHash(target);
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG
|
||||
@ -1743,8 +1746,8 @@ void Room::DisableHuman(Human* target)
|
||||
#endif
|
||||
if (!a8::HasBitFlag(target->status, HS_Disable)) {
|
||||
a8::SetBitFlag(target->status, HS_Disable);
|
||||
moveable_hash_.erase(target->entity_uniid);
|
||||
alive_human_hash_.erase(target->entity_uniid);
|
||||
RemoveFromMoveableHash(target);
|
||||
RemoveFromAliveHumanHash(target);
|
||||
for (auto& cell : target->grid_list) {
|
||||
bool has_target = false;
|
||||
for (Human* hum : cell->human_list[room_idx_]) {
|
||||
@ -2359,6 +2362,16 @@ void Room::AddToAccountHash(Player* hum)
|
||||
accountid_hash_[hum->account_id] = hum;
|
||||
}
|
||||
|
||||
void Room::AddToLaterAddHash(RoomEntity* entity)
|
||||
{
|
||||
later_add_hash_[entity->entity_uniid] = entity;
|
||||
}
|
||||
|
||||
void Room::AddToRemovedRobotHash(Human* hum)
|
||||
{
|
||||
removed_robot_hash_[hum->entity_uniid] = hum;
|
||||
}
|
||||
|
||||
void Room::AddPlayerPostProc(Player* hum)
|
||||
{
|
||||
if (room_type_ == RT_NewBrid) {
|
||||
@ -2414,12 +2427,22 @@ void Room::RemoveFromEntityHash(Entity* entity)
|
||||
uniid_hash_.erase(entity->entity_uniid);
|
||||
}
|
||||
|
||||
void Room::RemoveFromMoveableHash(Human* hum)
|
||||
void Room::RemoveFromMoveableHash(MoveableEntity* entity)
|
||||
{
|
||||
moveable_hash_.erase(hum->entity_uniid);
|
||||
moveable_hash_.erase(entity->entity_uniid);
|
||||
}
|
||||
|
||||
void Room::RemoveFromHuamnHash(Human* hum)
|
||||
{
|
||||
human_hash_.erase(hum->entity_uniid);
|
||||
}
|
||||
|
||||
void Room::RemoveFromAliveHumanHash(Human* hum)
|
||||
{
|
||||
alive_human_hash_.erase(hum->entity_uniid);
|
||||
}
|
||||
|
||||
void Room::RemoveFromLaterAddHash(RoomEntity* entity)
|
||||
{
|
||||
later_add_hash_.erase(entity->entity_uniid);
|
||||
}
|
||||
|
@ -167,9 +167,13 @@ private:
|
||||
void AddToAliveHumanHash(Human* hum);
|
||||
void AddToMoveableHash(MoveableEntity* entity);
|
||||
void AddToAccountHash(Player* hum);
|
||||
void AddToLaterAddHash(RoomEntity* entity);
|
||||
void AddToRemovedRobotHash(Human* hum);
|
||||
void RemoveFromEntityHash(Entity* entity);
|
||||
void RemoveFromMoveableHash(Human* hum);
|
||||
void RemoveFromMoveableHash(MoveableEntity* entity);
|
||||
void RemoveFromHuamnHash(Human* hum);
|
||||
void RemoveFromAliveHumanHash(Human* hum);
|
||||
void RemoveFromLaterAddHash(RoomEntity* entity);
|
||||
|
||||
void AddPlayerPostProc(Player* hum);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user