This commit is contained in:
aozhiwei 2022-12-18 11:26:18 +08:00
parent 0fabc2b174
commit 163f69fbdd
10 changed files with 43 additions and 74 deletions

View File

@ -167,8 +167,7 @@ void Entity::RemoveFromAroundPlayers(Room* room)
#if 1 #if 1
room->TraverseHumanList room->TraverseHumanList
( (
a8::XParams(), [this] (Human* hum) -> bool
[this] (Human* hum, a8::XParams& param) -> bool
{ {
hum->RemovePartObjects(this); hum->RemovePartObjects(this);
return true; return true;

View File

@ -49,8 +49,8 @@ static double TopXFunc (Human* sender, std::function<int (Human*, Human*)> cmpFu
{ {
std::vector<std::vector<Human*>> rank_list; std::vector<std::vector<Human*>> rank_list;
sender->room->TraverseHumanList sender->room->TraverseHumanList
(a8::XParams(), (
[cmpFunc, &rank_list] (Human* hum, a8::XParams& param) -> bool [cmpFunc, &rank_list] (Human* hum) -> bool
{ {
bool found = false; bool found = false;
for (auto& list : rank_list) { for (auto& list : rank_list) {
@ -2138,8 +2138,8 @@ void Human::GenBattleReportData(a8::MutableXObject* params)
int rank = 0; int rank = 0;
{ {
std::vector<Human*> human_list; std::vector<Human*> human_list;
room->TraverseHumanList(a8::XParams(), room->TraverseHumanList(
[&human_list] (Human* hum, a8::XParams& param) -> bool [&human_list] (Human* hum) -> bool
{ {
human_list.push_back(hum); human_list.push_back(hum);
return true; return true;
@ -3214,12 +3214,9 @@ void Human::RemoveFromScene()
room->grid_service->DeatchHuman(this); room->grid_service->DeatchHuman(this);
room->TraverseHumanList room->TraverseHumanList
( (
a8::XParams() [this] (Human* hum)
.SetSender(this),
[] (Human* hum, a8::XParams& param)
{ {
Human* target = (Human*)param.sender.GetUserData(); hum->RemovePartObjects(this);
hum->RemovePartObjects(target);
return true; return true;
}); });
} }

View File

@ -117,8 +117,7 @@ void Incubator::RecycleAndroid(Human* hum)
float distance = 10000000; float distance = 10000000;
room->TraverseAlivePlayers room->TraverseAlivePlayers
( (
a8::XParams(), [&nearest_hum, target, &distance] (Human* hum) -> bool
[&nearest_hum, target, &distance] (Human* hum, a8::XParams& param) -> bool
{ {
float tmp_distance = hum->GetPos().ManhattanDistance2D(target->GetPos()); float tmp_distance = hum->GetPos().ManhattanDistance2D(target->GetPos());
if (tmp_distance < distance) { if (tmp_distance < distance) {
@ -166,8 +165,7 @@ bool Incubator::CanSee(Human* hum, Human* exclude_hum)
bool can_see = true; bool can_see = true;
room->TraverseAlivePlayers room->TraverseAlivePlayers
( (
a8::XParams(), [target, exclude_hum, &can_see] (Human* hum) -> bool
[target, exclude_hum, &can_see] (Human* hum, a8::XParams& param) -> bool
{ {
if (hum != exclude_hum) { if (hum != exclude_hum) {
if (target->GetPos().ManhattanDistance2D(hum->GetPos()) < if (target->GetPos().ManhattanDistance2D(hum->GetPos()) <
@ -421,8 +419,7 @@ void Incubator::NextWave()
#if 1 #if 1
room->TraversePlayerList room->TraversePlayerList
( (
a8::XParams(), [this] (Player* hum)
[this] (Player* hum, a8::XParams& param)
{ {
cs::SMPvePassWave notify_msg; cs::SMPvePassWave notify_msg;
int next_wave = hum->room->pve_data.GetWave() + 1 + 1; int next_wave = hum->room->pve_data.GetWave() + 1 + 1;

View File

@ -220,9 +220,9 @@ void KillMgr::BoradcastRollMsgCb(Human* dead_hum,
std::shared_ptr<cs::SMRollMsg> pb_msg) std::shared_ptr<cs::SMRollMsg> pb_msg)
{ {
dead_hum->room->TraversePlayerList dead_hum->room->TraversePlayerList
(a8::XParams(), (
[dead_hum, info, &pb_msg, killer_team_id] [dead_hum, info, &pb_msg, killer_team_id]
(Player* hum, a8::XParams& param) -> bool (Player* hum) -> bool
{ {
for (int i = 0; i < pb_msg->elements_size(); ++i) { for (int i = 0; i < pb_msg->elements_size(); ++i) {
auto element = pb_msg->mutable_elements(i); auto element = pb_msg->mutable_elements(i);

View File

@ -521,8 +521,7 @@ void Player::UpdateJump()
if (a8::TIMER_EXEC_EVENT == event) { if (a8::TIMER_EXEC_EVENT == event) {
room->TraverseHumanList room->TraverseHumanList
( (
a8::XParams(), [] (Human* hum) -> bool
[] (Human* hum, a8::XParams& param) -> bool
{ {
if (hum->HasBuffEffect(kBET_Fly) && hum->IsAndroid()) { if (hum->HasBuffEffect(kBET_Fly) && hum->IsAndroid()) {
hum->DoJump(); hum->DoJump();
@ -1129,14 +1128,11 @@ void Player::_CMVoice(f8::MsgHdr& hdr, const cs::CMVoice& msg)
cs::SMVoiceNotify notifymsg; cs::SMVoiceNotify notifymsg;
notifymsg.set_account_id(account_id); notifymsg.set_account_id(account_id);
notifymsg.set_download_url(msg.download_url()); notifymsg.set_download_url(msg.download_url());
auto send_func = [] (Player* hum, a8::XParams& param) auto send_func = [&notifymsg] (Player* hum)
{ {
cs::SMVoiceNotify* msg = (cs::SMVoiceNotify*)param.sender.GetUserData(); hum->SendNotifyMsg(notifymsg);
hum->SendNotifyMsg(*msg);
}; };
room->TraversePlayerList(a8::XParams() room->TraversePlayerList(send_func);
.SetSender(&notifymsg),
send_func);
} }
void Player::_CMGameOver(f8::MsgHdr& hdr, const cs::CMGameOver& msg) void Player::_CMGameOver(f8::MsgHdr& hdr, const cs::CMGameOver& msg)

View File

@ -58,8 +58,7 @@ void PveData::OnBeKill(Hero* hero)
if (hero->is_pve_boss) { if (hero->is_pve_boss) {
room->TraverseHumanList room->TraverseHumanList
( (
a8::XParams(), [] (Human* hum) -> bool
[] (Human* hum, a8::XParams& param) -> bool
{ {
hum->stats.pve_kill_boss = true; hum->stats.pve_kill_boss = true;
return true; return true;
@ -87,8 +86,7 @@ void PveData::OnBeKill(Hero* hero)
int win_score = room->pve_mode_meta->round_score[GetWave()]; int win_score = room->pve_mode_meta->round_score[GetWave()];
room->TraverseHumanList room->TraverseHumanList
( (
a8::XParams(), [this, win_score] (Human* hum)
[this, win_score] (Human* hum, a8::XParams& param)
{ {
if (!hum->dead) { if (!hum->dead) {
#ifdef DEBUG #ifdef DEBUG
@ -137,8 +135,7 @@ void PveData::FlyDoor(Room* room, a8::Vec2& point, int radius)
if (a8::TIMER_EXEC_EVENT == event) { if (a8::TIMER_EXEC_EVENT == event) {
room->TraverseHumanList room->TraverseHumanList
( (
a8::XParams(), [room, &point, radius] (Human* hum)
[room, &point, radius] (Human* hum, a8::XParams& param)
{ {
a8::Vec2 dir = a8::Vec2::UP; a8::Vec2 dir = a8::Vec2::UP;
dir.Rotate(a8::RandAngle()); dir.Rotate(a8::RandAngle());

View File

@ -391,8 +391,7 @@ Human* Room::FindEnemy(Human* hum, float range)
float last_distance = range + 1; float last_distance = range + 1;
TraverseHumanList TraverseHumanList
( (
a8::XParams(), [&target, myself, range, &last_distance] (Human* hum)
[&target, myself, range, &last_distance] (Human* hum, a8::XParams& param)
{ {
if (!hum->dead && if (!hum->dead &&
hum->team_id != myself->team_id) { hum->team_id != myself->team_id) {
@ -1102,54 +1101,50 @@ Team* Room::NewTeam()
return team; return team;
} }
void Room::TraversePlayerList(a8::XParams param, void Room::TraversePlayerList(std::function<void (Player*)> func)
std::function<void (Player*, a8::XParams&)> func)
{ {
if (!func) { if (!func) {
return; return;
} }
for (auto& pair : accountid_hash_) { for (auto& pair : accountid_hash_) {
if (pair.second) { if (pair.second) {
func(pair.second, param); func(pair.second);
} }
} }
} }
void Room::TraverseHumanList(a8::XParams param, void Room::TraverseHumanList(std::function<bool (Human*)> func)
std::function<bool (Human*, a8::XParams&)> func)
{ {
if (!func) { if (!func) {
return; return;
} }
for (auto& pair : human_hash_) { for (auto& pair : human_hash_) {
if (pair.second) { if (pair.second) {
if (!func(pair.second, param)) { if (!func(pair.second)) {
break; break;
} }
} }
} }
} }
void Room::TraverseEntityList(a8::XParams param, void Room::TraverseEntityList(std::function<bool (Entity*)> func)
std::function<bool (Entity*, a8::XParams&)> func)
{ {
if (!func) { if (!func) {
return; return;
} }
for (auto& pair : uniid_hash_) { for (auto& pair : uniid_hash_) {
if (pair.second) { if (pair.second) {
if (!func(pair.second, param)) { if (!func(pair.second)) {
break; break;
} }
} }
} }
} }
void Room::TraverseAlivePlayers(a8::XParams param, void Room::TraverseAlivePlayers(std::function<bool (Human*)> func)
std::function<bool (Human*, a8::XParams&)> func)
{ {
for (auto& pair : alive_player_hash_) { for (auto& pair : alive_player_hash_) {
if (!func(pair.second, param)) { if (!func(pair.second)) {
break; break;
} }
} }
@ -1160,11 +1155,9 @@ void Room::BroadcastDebugMsg(const std::string& debug_msg)
#ifdef DEBUG #ifdef DEBUG
TraverseHumanList TraverseHumanList
( (
a8::XParams() [debug_msg] (Human* hum) -> bool
.SetParam1(debug_msg),
[] (Human* hum, a8::XParams& param) -> bool
{ {
hum->SendDebugMsg(param.param1); hum->SendDebugMsg(debug_msg);
return true; return true;
}); });
#endif #endif
@ -1288,9 +1281,7 @@ void Room::UpdateGasInactivePvp()
for (int i = 0; i < jump_num; ++i) { for (int i = 0; i < jump_num; ++i) {
TraverseHumanList TraverseHumanList
( (
a8::XParams() [] (Human* hum) -> bool
.SetSender(this),
[] (Human* hum, a8::XParams& param) -> bool
{ {
if (hum->HasBuffEffect(kBET_Fly) && if (hum->HasBuffEffect(kBET_Fly) &&
hum->GetEntitySubType() != EST_Player) { hum->GetEntitySubType() != EST_Player) {
@ -1408,8 +1399,7 @@ void Room::UpdateGasJump()
plane.curr_pos = plane.start_point + len_vec; plane.curr_pos = plane.start_point + len_vec;
if ((plane.end_point - plane.start_point).Norm() <= len_vec.Norm()) { if ((plane.end_point - plane.start_point).Norm() <= len_vec.Norm()) {
TraverseHumanList( TraverseHumanList(
a8::XParams(), [] (Human* hum) -> bool
[] (Human* hum, a8::XParams& param) -> bool
{ {
if (hum->HasBuffEffect(kBET_Fly)) { if (hum->HasBuffEffect(kBET_Fly)) {
hum->DoJump(); hum->DoJump();
@ -1988,8 +1978,8 @@ void Room::NotifyUiUpdate()
[this] (int event, const a8::Args* args) [this] (int event, const a8::Args* args)
{ {
if (a8::TIMER_EXEC_EVENT == event) { if (a8::TIMER_EXEC_EVENT == event) {
TraversePlayerList(a8::XParams(), TraversePlayerList(
[] (Player * hum, a8::XParams & param) [] (Player * hum)
{ {
hum->SendUIUpdate(); hum->SendUIUpdate();
}); });
@ -3460,8 +3450,7 @@ void Room::GetPartObjectWatchList(Entity* entity, std::vector<Human*>& watch_lis
{ {
TraverseHumanList TraverseHumanList
( (
a8::XParams(), [&watch_list, entity] (Human* hum) -> bool
[&watch_list, entity] (Human* hum, a8::XParams& param) -> bool
{ {
if (hum->InPartObjects(entity)) { if (hum->InPartObjects(entity)) {
watch_list.push_back(hum); watch_list.push_back(hum);
@ -3794,8 +3783,7 @@ bool Room::IsAllRealDead()
bool is_all_dead = true; bool is_all_dead = true;
TraverseHumanList TraverseHumanList
( (
a8::XParams(), [&is_all_dead] (Human* hum)
[&is_all_dead] (Human* hum, a8::XParams& param)
{ {
if (!hum->real_dead) { if (!hum->real_dead) {
is_all_dead = false; is_all_dead = false;

View File

@ -126,14 +126,10 @@ public:
void FillSMJoinedNotify(Player* self_hum, cs::SMJoinedNotify& msg); void FillSMJoinedNotify(Player* self_hum, cs::SMJoinedNotify& msg);
void TraversePlayerList(a8::XParams param, void TraversePlayerList(std::function<void (Player*)> func);
std::function<void (Player*, a8::XParams&)> func); void TraverseHumanList(std::function<bool (Human*)> func);
void TraverseHumanList(a8::XParams param, void TraverseEntityList(std::function<bool (Entity*)> func);
std::function<bool (Human*, a8::XParams&)> func); void TraverseAlivePlayers(std::function<bool (Human*)> func);
void TraverseEntityList(a8::XParams param,
std::function<bool (Entity*, a8::XParams&)> func);
void TraverseAlivePlayers(a8::XParams param,
std::function<bool (Human*, a8::XParams&)> func);
void BroadcastDebugMsg(const std::string& debug_msg); void BroadcastDebugMsg(const std::string& debug_msg);
void ScatterDrop(Position center, int drop_id); void ScatterDrop(Position center, int drop_id);

View File

@ -963,8 +963,7 @@ void RoomObstacle::ProcPortal()
bool ready = true; bool ready = true;
room->TraverseHumanList room->TraverseHumanList
( (
a8::XParams(), [this, &ready] (Human* hum)
[this, &ready] (Human* hum, a8::XParams& param)
{ {
if (!a8::IntersectCircleCircle if (!a8::IntersectCircleCircle
( (

View File

@ -20,8 +20,8 @@ void SmokeMiTask::Check()
} }
} }
room->TraversePlayerList room->TraversePlayerList
(a8::XParams(), (
[this] (Player* hum, a8::XParams&) -> bool [this] (Player* hum) -> bool
{ {
if (bomb_pos.Distance2D2(hum->GetPos()) < gun_meta->float_param1 + hum->meta->pb->radius()) { if (bomb_pos.Distance2D2(hum->GetPos()) < gun_meta->float_param1 + hum->meta->pb->radius()) {
if (!hum->HasBuffEffect(kBET_HunLuan)) { if (!hum->HasBuffEffect(kBET_HunLuan)) {