重构 new_objects part_objects
This commit is contained in:
parent
101ea940b3
commit
b3a44a888e
@ -95,7 +95,7 @@ void Bullet::OnHit(std::vector<Entity*>& objects)
|
||||
[] (Player* hum, a8::XParams& param)
|
||||
{
|
||||
Obstacle* obstacle = (Obstacle*)param.sender.GetUserData();
|
||||
hum->new_objects.insert(obstacle);
|
||||
hum->AddToNewObjects(obstacle);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -478,3 +478,23 @@ void Human::DecHP(float dec_hp, int killer_id, const std::string& killer_name)
|
||||
}
|
||||
SyncAroundPlayers();
|
||||
}
|
||||
|
||||
void Human::AddToNewObjects(Entity* entity)
|
||||
{
|
||||
new_objects.insert(entity);
|
||||
}
|
||||
|
||||
void Human::AddToPartObjects(Entity* entity)
|
||||
{
|
||||
part_objects.insert(entity);
|
||||
}
|
||||
|
||||
void Human::RemoveNewObjects(Entity* entity)
|
||||
{
|
||||
new_objects.erase(entity);
|
||||
}
|
||||
|
||||
void Human::RemovePartObjects(Entity* entity)
|
||||
{
|
||||
part_objects.erase(entity);
|
||||
}
|
||||
|
@ -63,9 +63,6 @@ class Human : public Entity
|
||||
|
||||
bool send_gameover = false;
|
||||
|
||||
std::set<Entity*> new_objects;
|
||||
std::set<Entity*> part_objects;
|
||||
|
||||
Human();
|
||||
virtual ~Human() override;
|
||||
virtual void Initialize() override;
|
||||
@ -92,9 +89,16 @@ class Human : public Entity
|
||||
void FillSMGameOver(cs::SMGameOver& msg);
|
||||
void BeKill(int killer_id, const std::string& killer_name);
|
||||
void DecHP(float dec_hp, int killer_id, const std::string& killer_name);
|
||||
void AddToNewObjects(Entity* entity);
|
||||
void AddToPartObjects(Entity* entity);
|
||||
void RemoveNewObjects(Entity* entity);
|
||||
void RemovePartObjects(Entity* entity);
|
||||
|
||||
protected:
|
||||
long long last_shot_frameno_ = 0;
|
||||
std::set<Entity*> new_objects;
|
||||
std::set<Entity*> part_objects;
|
||||
|
||||
private:
|
||||
CircleCollider* self_collider_ = nullptr;
|
||||
|
||||
|
@ -440,8 +440,7 @@ void Player::ObstacleInteraction(Obstacle* entity)
|
||||
room->TouchHumanList(a8::XParams(),
|
||||
[entity] (Human* hum, a8::XParams& param)
|
||||
{
|
||||
hum->new_objects.insert(entity);
|
||||
hum->part_objects.insert(entity);
|
||||
hum->AddToNewObjects(entity);
|
||||
if (entity->TestCollision(hum)) {
|
||||
hum->last_collision_door = entity;
|
||||
} else if (hum->last_collision_door == entity) {
|
||||
|
@ -224,14 +224,14 @@ void Room::AddPlayer(Player* hum)
|
||||
accountid_hash_[hum->account_id] = hum;
|
||||
human_hash_[hum->entity_uniid] = hum;
|
||||
++alive_count_;
|
||||
hum->new_objects.insert(hum);
|
||||
hum->part_objects.insert(hum);
|
||||
hum->AddToNewObjects(hum);
|
||||
hum->AddToPartObjects(hum);
|
||||
for (auto& pair : human_hash_) {
|
||||
if (pair.second != hum) {
|
||||
pair.second->new_objects.insert(hum);
|
||||
pair.second->part_objects.insert(hum);
|
||||
hum->new_objects.insert(pair.second);
|
||||
hum->part_objects.insert(pair.second);
|
||||
pair.second->AddToNewObjects(hum);
|
||||
pair.second->AddToPartObjects(hum);
|
||||
hum->AddToNewObjects(pair.second);
|
||||
hum->AddToPartObjects(pair.second);
|
||||
}
|
||||
}
|
||||
for (auto& pair : uniid_hash_) {
|
||||
@ -239,8 +239,7 @@ void Room::AddPlayer(Player* hum)
|
||||
case ET_Building:
|
||||
case ET_Obstacle:
|
||||
{
|
||||
hum->new_objects.insert(pair.second);
|
||||
hum->part_objects.insert(pair.second);
|
||||
hum->AddToNewObjects(pair.second);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -288,10 +287,10 @@ void Room::ShuaAndroid()
|
||||
|
||||
for (auto& pair : human_hash_) {
|
||||
if (pair.second != hum) {
|
||||
pair.second->new_objects.insert(hum);
|
||||
pair.second->part_objects.insert(hum);
|
||||
hum->new_objects.insert(pair.second);
|
||||
hum->part_objects.insert(pair.second);
|
||||
pair.second->AddToNewObjects(hum);
|
||||
pair.second->AddToPartObjects(hum);
|
||||
hum->AddToNewObjects(pair.second);
|
||||
hum->AddToPartObjects(pair.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -492,8 +491,7 @@ void Room::DropItem(Vector2D pos, int item_id, int item_count)
|
||||
entity->Initialize();
|
||||
uniid_hash_[entity->entity_uniid] = entity;
|
||||
for (auto& pair : human_hash_) {
|
||||
pair.second->new_objects.insert(entity);
|
||||
pair.second->part_objects.insert(entity);
|
||||
pair.second->AddToNewObjects(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -520,8 +518,7 @@ void Room::CreateDoor(Building* building, int door_idx)
|
||||
entity->Initialize();
|
||||
uniid_hash_[entity->entity_uniid] = entity;
|
||||
for (auto& pair : human_hash_) {
|
||||
pair.second->new_objects.insert(entity);
|
||||
pair.second->part_objects.insert(entity);
|
||||
pair.second->AddToNewObjects(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -541,8 +538,7 @@ void Room::CreateHouseObstacle(Building* building, int id, float x, float y)
|
||||
entity->Initialize();
|
||||
uniid_hash_[entity->entity_uniid] = entity;
|
||||
for (auto& pair : human_hash_) {
|
||||
pair.second->new_objects.insert(entity);
|
||||
pair.second->part_objects.insert(entity);
|
||||
pair.second->AddToNewObjects(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -561,8 +557,7 @@ void Room::CreateLoot(int equip_id, Vector2D pos, int count)
|
||||
entity->Initialize();
|
||||
uniid_hash_[entity->entity_uniid] = entity;
|
||||
for (auto& pair : human_hash_) {
|
||||
pair.second->new_objects.insert(entity);
|
||||
pair.second->part_objects.insert(entity);
|
||||
pair.second->AddToNewObjects(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -589,7 +584,7 @@ void Room::FetchBuilding(Human* hum)
|
||||
{
|
||||
for (auto& pair : uniid_hash_) {
|
||||
if (pair.second->entity_type == ET_Building) {
|
||||
hum->new_objects.insert(pair.second);
|
||||
hum->AddToNewObjects(pair.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -610,8 +605,8 @@ void Room::ClearDeletedObjects()
|
||||
moveable_hash_.erase(entity->entity_uniid);
|
||||
}
|
||||
for (auto& pair : human_hash_) {
|
||||
pair.second->new_objects.erase(entity);
|
||||
pair.second->part_objects.erase(entity);
|
||||
pair.second->RemoveNewObjects(entity);
|
||||
pair.second->RemovePartObjects(entity);
|
||||
}
|
||||
delete entity;
|
||||
}
|
||||
@ -627,8 +622,8 @@ void Room::ClearDeletedObjects()
|
||||
moveable_hash_.erase(entity->entity_uniid);
|
||||
}
|
||||
for (auto& pair : human_hash_) {
|
||||
pair.second->new_objects.erase(entity);
|
||||
pair.second->part_objects.erase(entity);
|
||||
pair.second->RemoveNewObjects(entity);
|
||||
pair.second->RemovePartObjects(entity);
|
||||
}
|
||||
delete entity;
|
||||
}
|
||||
@ -677,7 +672,7 @@ void Room::ProcAddedObjects()
|
||||
case ET_Smoke:
|
||||
{
|
||||
for (auto& pair : human_hash_) {
|
||||
pair.second->new_objects.insert(pair.second);
|
||||
pair.second->RemoveNewObjects(pair.second);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user