完成room重构
This commit is contained in:
parent
24cacccbb5
commit
d1e2cc438f
@ -278,9 +278,11 @@ void Human::UpdatePoisoning()
|
||||
|
||||
void Human::SyncAroundPlayers()
|
||||
{
|
||||
for (auto& pair : room->human_hash_) {
|
||||
pair.second->new_objects.insert(this);
|
||||
}
|
||||
room->TouchHumanList(a8::XParams(),
|
||||
[this] (Human* hum, a8::XParams& param)
|
||||
{
|
||||
hum->new_objects.insert(this);
|
||||
});
|
||||
}
|
||||
|
||||
void Human::AutoLoadingBullet(bool manual)
|
||||
@ -359,7 +361,7 @@ void Human::BeKill(int killer_id, const std::string& killer_name)
|
||||
health = 0.0f;
|
||||
dead_frameno = room->frame_no;
|
||||
send_gameover = true;
|
||||
--room->alive_count_;
|
||||
room->OnHumanDie(this);
|
||||
SyncAroundPlayers();
|
||||
}
|
||||
}
|
||||
|
@ -138,9 +138,7 @@ void Player::UpdateSelectWeapon()
|
||||
curr_weapon = weapon;
|
||||
ResetAction();
|
||||
need_sync_active_player = true;
|
||||
for (auto& pair : room->human_hash_) {
|
||||
pair.second->new_objects.insert(this);
|
||||
}
|
||||
SyncAroundPlayers();
|
||||
AutoLoadingBullet();
|
||||
}
|
||||
}
|
||||
@ -404,15 +402,17 @@ void Player::ObstacleInteraction(Obstacle* entity)
|
||||
entity->building->pos.y + entity->door_state0->y() - entity->building->meta->i->tileheight() / 2.0);
|
||||
}
|
||||
entity->RecalcSelfCollider();
|
||||
for (auto& pair : room->human_hash_) {
|
||||
pair.second->new_objects.insert(entity);
|
||||
pair.second->part_objects.insert(entity);
|
||||
if (entity->TestCollision(pair.second)) {
|
||||
pair.second->last_collision_door = entity;
|
||||
} else if (pair.second->last_collision_door == entity) {
|
||||
pair.second->last_collision_door = nullptr;
|
||||
}
|
||||
}
|
||||
room->TouchHumanList(a8::XParams(),
|
||||
[entity] (Human* hum, a8::XParams& param)
|
||||
{
|
||||
hum->new_objects.insert(entity);
|
||||
hum->part_objects.insert(entity);
|
||||
if (entity->TestCollision(hum)) {
|
||||
hum->last_collision_door = entity;
|
||||
} else if (hum->last_collision_door == entity) {
|
||||
hum->last_collision_door = nullptr;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
}
|
||||
}
|
||||
@ -445,9 +445,7 @@ void Player::LootInteraction(Loot* entity)
|
||||
need_sync_active_player = true;
|
||||
}
|
||||
need_sync_active_player = true;
|
||||
for (auto& pair : room->human_hash_) {
|
||||
pair.second->new_objects.insert(this);
|
||||
}
|
||||
SyncAroundPlayers();
|
||||
} else {
|
||||
Weapon* weapon = nullptr;
|
||||
if (weapons[GUN_SLOT1].weapon_id == 0) {
|
||||
@ -475,9 +473,7 @@ void Player::LootInteraction(Loot* entity)
|
||||
weapon->meta = item_meta;
|
||||
AutoLoadingBullet();
|
||||
need_sync_active_player = true;
|
||||
for (auto& pair : room->human_hash_) {
|
||||
pair.second->new_objects.insert(this);
|
||||
}
|
||||
SyncAroundPlayers();
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -688,9 +684,7 @@ void Player::UpdateDropWeapon()
|
||||
room->CreateLoot(weapon_id, pos + dir * (25 + rand() % 50), std::max(1, weapon_ammo));
|
||||
}
|
||||
need_sync_active_player = true;
|
||||
for (auto& pair : room->human_hash_) {
|
||||
pair.second->new_objects.insert(this);
|
||||
}
|
||||
SyncAroundPlayers();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -810,11 +804,7 @@ void Player::MakeUpdateMsg()
|
||||
}
|
||||
}
|
||||
if (updated_times == 0) {
|
||||
for (auto& pair : room->uniid_hash_) {
|
||||
if (pair.second->entity_type == ET_Building) {
|
||||
new_objects.insert(pair.second);
|
||||
}
|
||||
}
|
||||
room->FetchBuilding(this);
|
||||
}
|
||||
for (auto& itr : new_objects) {
|
||||
itr->FillMFObjectFull(update_msg->add_full_objects());
|
||||
|
@ -488,6 +488,20 @@ void Room::CreateLoot(int equip_id, Vector2D pos, int count)
|
||||
}
|
||||
}
|
||||
|
||||
void Room::FetchBuilding(Human* hum)
|
||||
{
|
||||
for (auto& pair : uniid_hash_) {
|
||||
if (pair.second->entity_type == ET_Building) {
|
||||
hum->new_objects.insert(pair.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Room::OnHumanDie(Human* hum)
|
||||
{
|
||||
--alive_count_;
|
||||
}
|
||||
|
||||
void Room::ClearDeletedObjects()
|
||||
{
|
||||
for (auto& obj_uniid : frame_data.deleted_objects) {
|
||||
@ -519,6 +533,19 @@ void Room::TouchPlayerList(a8::XParams param,
|
||||
}
|
||||
}
|
||||
|
||||
void Room::TouchHumanList(a8::XParams param,
|
||||
std::function<void (Human*, a8::XParams&)> func)
|
||||
{
|
||||
if (!func) {
|
||||
return;
|
||||
}
|
||||
for (auto& pair : human_hash_) {
|
||||
if (pair.second) {
|
||||
func(pair.second, param);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Room::ProcAddedObjects()
|
||||
{
|
||||
if (!be_added_hash_.empty()) {
|
||||
@ -647,11 +674,7 @@ void Room::UpdateGas()
|
||||
continue;
|
||||
}
|
||||
bool b1 = CircleContainCircle(gas_data.pos_old,
|
||||
#if 1
|
||||
gas_data.gas_progress,
|
||||
#else
|
||||
gas_data.rad_old,
|
||||
#endif
|
||||
pair.second->pos,
|
||||
pair.second->GetRadius()
|
||||
);
|
||||
|
@ -59,6 +59,8 @@ public:
|
||||
void ResetFrameData();
|
||||
void TouchPlayerList(a8::XParams param,
|
||||
std::function<void (Player*, a8::XParams&)> func);
|
||||
void TouchHumanList(a8::XParams param,
|
||||
std::function<void (Human*, a8::XParams&)> func);
|
||||
void BeAddedObject(Entity* entity);
|
||||
void ProcDrop(Vector2D center, int drop_id);
|
||||
void CreateThings();
|
||||
@ -67,6 +69,8 @@ public:
|
||||
void CreateDoor(Building* building, int door_idx);
|
||||
void CreateHouseObstacle(Building* building, int id, float x, float y);
|
||||
void CreateLoot(int equip_id, Vector2D pos, int count);
|
||||
void FetchBuilding(Human* hum);
|
||||
void OnHumanDie(Human* hum);
|
||||
|
||||
private:
|
||||
void ClearDeletedObjects();
|
||||
@ -75,15 +79,16 @@ private:
|
||||
bool GenSmallCircle(Vector2D big_circle_pos, float big_circle_rad, float small_circle_rad,
|
||||
Vector2D& out_pos);
|
||||
|
||||
public:
|
||||
unsigned short current_uniid = 0;
|
||||
RoomState_e state_ = RS_Inactive;
|
||||
private:
|
||||
int elapsed_time_ = 0;
|
||||
int alive_count_ = 0;
|
||||
|
||||
unsigned short current_uniid = 0;
|
||||
RoomState_e state_ = RS_Inactive;
|
||||
|
||||
std::map<std::string, Player*> accountid_hash_;
|
||||
std::map<unsigned short, Entity*> uniid_hash_;
|
||||
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_;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user