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

View File

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

View File

@ -521,8 +521,7 @@ void Player::UpdateJump()
if (a8::TIMER_EXEC_EVENT == event) {
room->TraverseHumanList
(
a8::XParams(),
[] (Human* hum, a8::XParams& param) -> bool
[] (Human* hum) -> bool
{
if (hum->HasBuffEffect(kBET_Fly) && hum->IsAndroid()) {
hum->DoJump();
@ -1129,14 +1128,11 @@ void Player::_CMVoice(f8::MsgHdr& hdr, const cs::CMVoice& msg)
cs::SMVoiceNotify notifymsg;
notifymsg.set_account_id(account_id);
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(*msg);
hum->SendNotifyMsg(notifymsg);
};
room->TraversePlayerList(a8::XParams()
.SetSender(&notifymsg),
send_func);
room->TraversePlayerList(send_func);
}
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) {
room->TraverseHumanList
(
a8::XParams(),
[] (Human* hum, a8::XParams& param) -> bool
[] (Human* hum) -> bool
{
hum->stats.pve_kill_boss = true;
return true;
@ -87,8 +86,7 @@ void PveData::OnBeKill(Hero* hero)
int win_score = room->pve_mode_meta->round_score[GetWave()];
room->TraverseHumanList
(
a8::XParams(),
[this, win_score] (Human* hum, a8::XParams& param)
[this, win_score] (Human* hum)
{
if (!hum->dead) {
#ifdef DEBUG
@ -137,8 +135,7 @@ void PveData::FlyDoor(Room* room, a8::Vec2& point, int radius)
if (a8::TIMER_EXEC_EVENT == event) {
room->TraverseHumanList
(
a8::XParams(),
[room, &point, radius] (Human* hum, a8::XParams& param)
[room, &point, radius] (Human* hum)
{
a8::Vec2 dir = a8::Vec2::UP;
dir.Rotate(a8::RandAngle());

View File

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

View File

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

View File

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

View File

@ -20,8 +20,8 @@ void SmokeMiTask::Check()
}
}
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 (!hum->HasBuffEffect(kBET_HunLuan)) {