优化AddPlayer
This commit is contained in:
parent
337648d008
commit
6320004441
@ -1316,3 +1316,20 @@ void Player::InternalAdOk()
|
|||||||
ad_timer_ = nullptr;
|
ad_timer_ = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Player::PushJoinRoomMsg()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
cs::SMJoinedNotify notifymsg;
|
||||||
|
notifymsg.set_error_code(0);
|
||||||
|
room->FillSMJoinedNotify(this, notifymsg);
|
||||||
|
GGListener::Instance()->SendToClient(socket_handle, 0, notifymsg);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
cs::SMMapInfo notifymsg;
|
||||||
|
notifymsg.set_map_id(room->GetMapMeta()->i->map_id());
|
||||||
|
notifymsg.set_map_width(room->GetMapMeta()->i->map_width());
|
||||||
|
notifymsg.set_map_height(room->GetMapMeta()->i->map_height());
|
||||||
|
GGListener::Instance()->SendToClient(socket_handle, 0, notifymsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -86,6 +86,7 @@ class Player : public Human
|
|||||||
prepare_items);
|
prepare_items);
|
||||||
void ProcPrepareItems2(const ::google::protobuf::RepeatedPtrField< cs::MFPair >&
|
void ProcPrepareItems2(const ::google::protobuf::RepeatedPtrField< cs::MFPair >&
|
||||||
prepare_items);
|
prepare_items);
|
||||||
|
void PushJoinRoomMsg();
|
||||||
|
|
||||||
void _CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg);
|
void _CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg);
|
||||||
void _CMEmote(f8::MsgHdr& hdr, const cs::CMEmote& msg);
|
void _CMEmote(f8::MsgHdr& hdr, const cs::CMEmote& msg);
|
||||||
|
@ -166,90 +166,21 @@ void Room::AddPlayer(Player* hum)
|
|||||||
hum->room = this;
|
hum->room = this;
|
||||||
hum->join_frameno = GetFrameNo();
|
hum->join_frameno = GetFrameNo();
|
||||||
hum->Initialize();
|
hum->Initialize();
|
||||||
{
|
|
||||||
cs::SMJoinedNotify notifymsg;
|
|
||||||
notifymsg.set_error_code(0);
|
|
||||||
FillSMJoinedNotify(hum, notifymsg);
|
|
||||||
GGListener::Instance()->SendToClient(hum->socket_handle, 0, notifymsg);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
cs::SMMapInfo notifymsg;
|
|
||||||
notifymsg.set_map_id(map_meta_->i->map_id());
|
|
||||||
notifymsg.set_map_width(map_meta_->i->map_width());
|
|
||||||
notifymsg.set_map_height(map_meta_->i->map_height());
|
|
||||||
GGListener::Instance()->SendToClient(hum->socket_handle, 0, notifymsg);
|
|
||||||
}
|
|
||||||
AddToEntityHash(hum);
|
AddToEntityHash(hum);
|
||||||
AddToMoveableHash(hum);
|
AddToMoveableHash(hum);
|
||||||
AddToAccountHash(hum);
|
AddToAccountHash(hum);
|
||||||
AddToHumanHash(hum);
|
AddToHumanHash(hum);
|
||||||
AddToAliveHumanHash(hum);
|
AddToAliveHumanHash(hum);
|
||||||
|
MatchTeam(hum);
|
||||||
|
hum->PushJoinRoomMsg();
|
||||||
++alive_count_;
|
++alive_count_;
|
||||||
++App::Instance()->perf.alive_count;
|
++App::Instance()->perf.alive_count;
|
||||||
MatchTeam(hum);
|
|
||||||
|
|
||||||
grid_service->AddHuman(hum);
|
grid_service->AddHuman(hum);
|
||||||
hum->FindLocation();
|
hum->FindLocation();
|
||||||
hum->RefreshView();
|
hum->RefreshView();
|
||||||
if (room_type_ == RT_NewBrid) {
|
AddPlayerPostProc(hum);
|
||||||
if (force_shua_android_times_ < 1) {
|
|
||||||
CreateAndroid(20 + rand() % 10);
|
|
||||||
++force_shua_android_times_;
|
|
||||||
}
|
|
||||||
xtimer.AddDeadLineTimerAndAttach(SERVER_FRAME_RATE * (1 + rand() % 3),
|
|
||||||
a8::XParams()
|
|
||||||
.SetSender(hum),
|
|
||||||
[] (const a8::XParams& param)
|
|
||||||
{
|
|
||||||
Human* hum = (Human*)param.sender.GetUserData();
|
|
||||||
hum->room->ShowAndroid(hum, 1 + rand() % 2);
|
|
||||||
},
|
|
||||||
&hum->xtimer_attacher.timer_list_);
|
|
||||||
}
|
|
||||||
if (room_type_ == RT_NewBrid || room_type_ == RT_MidBrid) {
|
|
||||||
for (int buff_id : MetaMgr::Instance()->newbie_buff_list) {
|
|
||||||
MetaData::Buff* buff_meta = MetaMgr::Instance()->GetBuff(buff_id);
|
|
||||||
if (buff_meta) {
|
|
||||||
hum->AddBuff(buff_meta, 1);
|
|
||||||
}
|
|
||||||
#ifdef DEBUG
|
|
||||||
a8::UdpLog::Instance()->Debug("room_idx:%d 添加新手buff %s %s %d",
|
|
||||||
{
|
|
||||||
GetRoomIdx(),
|
|
||||||
hum->account_id,
|
|
||||||
hum->name,
|
|
||||||
buff_id
|
|
||||||
});
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (human_hash_.size() > ROOM_MAX_PLAYER_NUM) {
|
|
||||||
RandRemoveAndroid();
|
|
||||||
}
|
|
||||||
NotifyUiUpdate();
|
NotifyUiUpdate();
|
||||||
#ifdef DEBUG
|
|
||||||
xtimer.AddRepeatTimerAndAttach
|
|
||||||
(SERVER_FRAME_RATE * 5,
|
|
||||||
a8::XParams()
|
|
||||||
.SetSender(hum),
|
|
||||||
[] (const a8::XParams& param)
|
|
||||||
{
|
|
||||||
Human* hum = (Human*)param.sender.GetUserData();
|
|
||||||
std::string debugmsg = a8::Format("weapon_id:%d weapon_lv:%d atk:%f fire_rate:%f "
|
|
||||||
"volume:%d maxhp:%f curr_hp:%f",
|
|
||||||
{
|
|
||||||
hum->curr_weapon->weapon_id,
|
|
||||||
hum->curr_weapon->weapon_lv,
|
|
||||||
hum->curr_weapon->GetAttrValue(kHAT_Atk),
|
|
||||||
hum->curr_weapon->GetAttrValue(kHAT_FireRate),
|
|
||||||
hum->curr_weapon->GetAttrValue(kHAT_Volume),
|
|
||||||
hum->curr_weapon->GetAttrValue(kHAT_MaxHp),
|
|
||||||
hum->GetHP()
|
|
||||||
});
|
|
||||||
hum->SendDebugMsg(debugmsg);
|
|
||||||
},
|
|
||||||
&hum->xtimer_attacher.timer_list_);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Room::AllocUniid()
|
int Room::AllocUniid()
|
||||||
@ -271,7 +202,6 @@ void Room::ShuaAndroid()
|
|||||||
MetaMgr::Instance()->refresh_robot_max_time);
|
MetaMgr::Instance()->refresh_robot_max_time);
|
||||||
if (robot_num > 0 && refresh_time > 0) {
|
if (robot_num > 0 && refresh_time > 0) {
|
||||||
CreateAndroid(robot_num);
|
CreateAndroid(robot_num);
|
||||||
NotifyUiUpdate();
|
|
||||||
xtimer.AddDeadLineTimerAndAttach(SERVER_FRAME_RATE * refresh_time,
|
xtimer.AddDeadLineTimerAndAttach(SERVER_FRAME_RATE * refresh_time,
|
||||||
a8::XParams()
|
a8::XParams()
|
||||||
.SetSender(this),
|
.SetSender(this),
|
||||||
@ -354,6 +284,7 @@ void Room::CreateAndroid(int robot_num)
|
|||||||
hum->RefreshView();
|
hum->RefreshView();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
NotifyUiUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
Human* Room::FindEnemy(Human* hum)
|
Human* Room::FindEnemy(Human* hum)
|
||||||
@ -2429,3 +2360,53 @@ void Room::AddToAccountHash(Player* hum)
|
|||||||
{
|
{
|
||||||
accountid_hash_[hum->account_id] = hum;
|
accountid_hash_[hum->account_id] = hum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Room::AddPlayerPostProc(Player* hum)
|
||||||
|
{
|
||||||
|
if (room_type_ == RT_NewBrid) {
|
||||||
|
CreateAndroid(20 + rand() % 10);
|
||||||
|
xtimer.AddDeadLineTimerAndAttach(SERVER_FRAME_RATE * (1 + rand() % 3),
|
||||||
|
a8::XParams()
|
||||||
|
.SetSender(hum),
|
||||||
|
[] (const a8::XParams& param)
|
||||||
|
{
|
||||||
|
Human* hum = (Human*)param.sender.GetUserData();
|
||||||
|
hum->room->ShowAndroid(hum, 1 + rand() % 2);
|
||||||
|
},
|
||||||
|
&hum->xtimer_attacher.timer_list_);
|
||||||
|
}
|
||||||
|
if (room_type_ == RT_NewBrid || room_type_ == RT_MidBrid) {
|
||||||
|
for (int buff_id : MetaMgr::Instance()->newbie_buff_list) {
|
||||||
|
MetaData::Buff* buff_meta = MetaMgr::Instance()->GetBuff(buff_id);
|
||||||
|
if (buff_meta) {
|
||||||
|
hum->AddBuff(buff_meta, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (human_hash_.size() > ROOM_MAX_PLAYER_NUM) {
|
||||||
|
RandRemoveAndroid();
|
||||||
|
}
|
||||||
|
#ifdef DEBUG
|
||||||
|
xtimer.AddRepeatTimerAndAttach
|
||||||
|
(SERVER_FRAME_RATE * 5,
|
||||||
|
a8::XParams()
|
||||||
|
.SetSender(hum),
|
||||||
|
[] (const a8::XParams& param)
|
||||||
|
{
|
||||||
|
Human* hum = (Human*)param.sender.GetUserData();
|
||||||
|
std::string debugmsg = a8::Format("weapon_id:%d weapon_lv:%d atk:%f fire_rate:%f "
|
||||||
|
"volume:%d maxhp:%f curr_hp:%f",
|
||||||
|
{
|
||||||
|
hum->curr_weapon->weapon_id,
|
||||||
|
hum->curr_weapon->weapon_lv,
|
||||||
|
hum->curr_weapon->GetAttrValue(kHAT_Atk),
|
||||||
|
hum->curr_weapon->GetAttrValue(kHAT_FireRate),
|
||||||
|
hum->curr_weapon->GetAttrValue(kHAT_Volume),
|
||||||
|
hum->curr_weapon->GetAttrValue(kHAT_MaxHp),
|
||||||
|
hum->GetHP()
|
||||||
|
});
|
||||||
|
hum->SendDebugMsg(debugmsg);
|
||||||
|
},
|
||||||
|
&hum->xtimer_attacher.timer_list_);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
@ -168,6 +168,8 @@ private:
|
|||||||
void AddToMoveableHash(MoveableEntity* entity);
|
void AddToMoveableHash(MoveableEntity* entity);
|
||||||
void AddToAccountHash(Player* hum);
|
void AddToAccountHash(Player* hum);
|
||||||
|
|
||||||
|
void AddPlayerPostProc(Player* hum);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
void InitDebugInfo();
|
void InitDebugInfo();
|
||||||
void UnInitDebugInfo();
|
void UnInitDebugInfo();
|
||||||
@ -193,7 +195,6 @@ private:
|
|||||||
long long game_over_frameno_ = 0;
|
long long game_over_frameno_ = 0;
|
||||||
int elapsed_time_ = 0;
|
int elapsed_time_ = 0;
|
||||||
int alive_count_ = 0;
|
int alive_count_ = 0;
|
||||||
int force_shua_android_times_ = 0;
|
|
||||||
MetaData::AirLine* airline_ = nullptr;
|
MetaData::AirLine* airline_ = nullptr;
|
||||||
a8::XTimerAttacher xtimer_attacher_;
|
a8::XTimerAttacher xtimer_attacher_;
|
||||||
size_t airdrop_times_ = 0;
|
size_t airdrop_times_ = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user