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