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