airdrops ok

This commit is contained in:
aozhiwei 2019-04-25 11:07:20 +08:00
parent efc81d40e1
commit 30c2d8255c
4 changed files with 57 additions and 59 deletions

View File

@ -4,23 +4,10 @@
void FrameEvent::AddAirDrop(int appear_time, int box_id, Vector2D box_pos) void FrameEvent::AddAirDrop(int appear_time, int box_id, Vector2D box_pos)
{ {
#if 0 cs::MFAirDrop* airdrop = airdrops_.Add();
::google::protobuf::RepeatedPtrField<::cs::MFAirDrop>* airdrops = nullptr;
{
{
auto itr = frame_data.airdrops_hash.find(frame_no);
if (itr == frame_data.airdrops_hash.end()) {
frame_data.airdrops_hash[frame_no] = ::google::protobuf::RepeatedPtrField<::cs::MFAirDrop>();
itr = frame_data.airdrops_hash.find(frame_no);
}
airdrops = &itr->second;
}
}
cs::MFAirDrop* airdrop = airdrops->Add();
airdrop->set_appear_time(appear_time); airdrop->set_appear_time(appear_time);
airdrop->set_box_id(box_id); airdrop->set_box_id(box_id);
box_pos.ToPB(airdrop->mutable_pos()); box_pos.ToPB(airdrop->mutable_pos());
#endif
} }
void FrameEvent::AddEmote(Human* hum, int emote_id) void FrameEvent::AddEmote(Human* hum, int emote_id)
@ -28,10 +15,10 @@ void FrameEvent::AddEmote(Human* hum, int emote_id)
#if 0 #if 0
::google::protobuf::RepeatedPtrField<::cs::MFEmote>* emotes = nullptr; ::google::protobuf::RepeatedPtrField<::cs::MFEmote>* emotes = nullptr;
{ {
auto itr = room->frame_data.emotes_hash.find(room->frame_no); auto itr = room->frame_data.emotes_.find(room->frame_no);
if (itr == room->frame_data.emotes_hash.end()) { if (itr == room->frame_data.emotes_.end()) {
room->frame_data.emotes_hash[room->frame_no] = ::google::protobuf::RepeatedPtrField<::cs::MFEmote>(); room->frame_data.emotes_[room->frame_no] = ::google::protobuf::RepeatedPtrField<::cs::MFEmote>();
itr = room->frame_data.emotes_hash.find(room->frame_no); itr = room->frame_data.emotes_.find(room->frame_no);
} }
emotes = &itr->second; emotes = &itr->second;
} }
@ -51,10 +38,10 @@ void FrameEvent::AddShot(Human* hum)
::google::protobuf::RepeatedPtrField<::cs::MFShot>* shots = nullptr; ::google::protobuf::RepeatedPtrField<::cs::MFShot>* shots = nullptr;
{ {
{ {
auto itr = room->frame_data.shots_hash.find(room->frame_no); auto itr = room->frame_data.shots_.find(room->frame_no);
if (itr == room->frame_data.shots_hash.end()) { if (itr == room->frame_data.shots_.end()) {
room->frame_data.shots_hash[room->frame_no] = ::google::protobuf::RepeatedPtrField<::cs::MFShot>(); room->frame_data.shots_[room->frame_no] = ::google::protobuf::RepeatedPtrField<::cs::MFShot>();
itr = room->frame_data.shots_hash.find(room->frame_no); itr = room->frame_data.shots_.find(room->frame_no);
} }
shots = &itr->second; shots = &itr->second;
} }
@ -75,10 +62,10 @@ void FrameEvent::AddBullet()
::google::protobuf::RepeatedPtrField<::cs::MFBullet>* bullets = nullptr; ::google::protobuf::RepeatedPtrField<::cs::MFBullet>* bullets = nullptr;
{ {
{ {
auto itr = room->frame_data.bullets_hash.find(room->frame_no); auto itr = room->frame_data.bullets_.find(room->frame_no);
if (itr == room->frame_data.bullets_hash.end()) { if (itr == room->frame_data.bullets_.end()) {
room->frame_data.bullets_hash[room->frame_no] = ::google::protobuf::RepeatedPtrField<::cs::MFBullet>(); room->frame_data.bullets_[room->frame_no] = ::google::protobuf::RepeatedPtrField<::cs::MFBullet>();
itr = room->frame_data.bullets_hash.find(room->frame_no); itr = room->frame_data.bullets_.find(room->frame_no);
} }
bullets = &itr->second; bullets = &itr->second;
} }
@ -113,10 +100,10 @@ void FrameEvent::AddSmoke(Bullet* bullet, int item_id, Vector2D pos)
#if 0 #if 0
::google::protobuf::RepeatedPtrField<::cs::MFSmoke>* smokes = nullptr; ::google::protobuf::RepeatedPtrField<::cs::MFSmoke>* smokes = nullptr;
{ {
auto itr = room->frame_data.smokes_hash.find(room->frame_no); auto itr = room->frame_data.smokes_.find(room->frame_no);
if (itr == room->frame_data.smokes_hash.end()) { if (itr == room->frame_data.smokes_.end()) {
room->frame_data.smokes_hash[room->frame_no] = ::google::protobuf::RepeatedPtrField<::cs::MFSmoke>(); room->frame_data.smokes_[room->frame_no] = ::google::protobuf::RepeatedPtrField<::cs::MFSmoke>();
itr = room->frame_data.smokes_hash.find(room->frame_no); itr = room->frame_data.smokes_.find(room->frame_no);
} }
smokes = &itr->second; smokes = &itr->second;
} }
@ -129,3 +116,24 @@ void FrameEvent::AddSmoke(Bullet* bullet, int item_id, Vector2D pos)
#endif #endif
} }
void FrameEvent::Clear()
{
if (explosions_.size() > 0) {
explosions_.Clear();
}
if (smokes_.size() > 0) {
smokes_.Clear();
}
if (emotes_.size() > 0) {
emotes_.Clear();
}
if (bullets_.size() > 0) {
bullets_.Clear();
}
if (shots_.size() > 0) {
shots_.Clear();
}
if (airdrops_.size() > 0) {
airdrops_.Clear();
}
}

View File

@ -14,13 +14,14 @@ public:
void AddExplosion(Bullet* bullet, int item_id, Vector2D bomb_pos); void AddExplosion(Bullet* bullet, int item_id, Vector2D bomb_pos);
void AddSmoke(Bullet* bullet, int item_id, Vector2D pos); void AddSmoke(Bullet* bullet, int item_id, Vector2D pos);
void Clear();
private: private:
std::map<long long, std::set<unsigned short>> deleted_objects_hash; ::google::protobuf::RepeatedPtrField<::cs::MFExplosion> explosions_;
std::map<long long, std::set<unsigned short>> softdeleted_objects_hash; ::google::protobuf::RepeatedPtrField<::cs::MFSmoke> smokes_;
std::map<long long, ::google::protobuf::RepeatedPtrField<::cs::MFExplosion>> explosions_hash; ::google::protobuf::RepeatedPtrField<::cs::MFEmote> emotes_;
std::map<long long, ::google::protobuf::RepeatedPtrField<::cs::MFSmoke>> smokes_hash; ::google::protobuf::RepeatedPtrField<::cs::MFBullet> bullets_;
std::map<long long, ::google::protobuf::RepeatedPtrField<::cs::MFEmote>> emotes_hash; ::google::protobuf::RepeatedPtrField<::cs::MFShot> shots_;
std::map<long long, ::google::protobuf::RepeatedPtrField<::cs::MFBullet>> bullets_hash; ::google::protobuf::RepeatedPtrField<::cs::MFAirDrop> airdrops_;
std::map<long long, ::google::protobuf::RepeatedPtrField<::cs::MFShot>> shots_hash;
std::map<long long, ::google::protobuf::RepeatedPtrField<::cs::MFAirDrop>> airdrops_hash; friend class FrameMaker;
}; };

View File

@ -41,14 +41,6 @@
} }
} }
} }
for (auto& pair : room->frame_data.airdrops_hash) {
if (pair.first <= room->frame_no) {
for (auto& itr : pair.second) {
*msg->mutable_airdrop() = itr;
break;
}
}
}
} }
#endif #endif
@ -85,6 +77,9 @@ cs::SMUpdate* FrameMaker::MakeUpdateMsg(Human* hum)
hum->part_objects.erase(entity); hum->part_objects.erase(entity);
} }
} }
if (room->frame_event.airdrops_.size() > 0) {
*msg->mutable_airdrop() = room->frame_event.airdrops_.Get(0);
}
if (hum->send_msg_times == 0 || hum->need_sync_active_player) { if (hum->send_msg_times == 0 || hum->need_sync_active_player) {
msg->set_active_player_id(hum->entity_uniid); msg->set_active_player_id(hum->entity_uniid);
hum->FillMFActivePlayerData(msg->mutable_active_player_data()); hum->FillMFActivePlayerData(msg->mutable_active_player_data());
@ -100,8 +95,12 @@ cs::SMUpdate* FrameMaker::MakeUpdateMsg(Human* hum)
} }
msg->set_alive_count(room->AliveCount()); msg->set_alive_count(room->AliveCount());
} }
hum->new_objects.clear(); if (!hum->new_objects.empty()) {
hum->del_objects.clear(); hum->new_objects.clear();
}
if (!hum->del_objects.empty()) {
hum->del_objects.clear();
}
++hum->send_msg_times; ++hum->send_msg_times;
return msg; return msg;
} }

View File

@ -107,6 +107,7 @@ void Room::Update(int delta_time)
for (auto& pair : accountid_hash_) { for (auto& pair : accountid_hash_) {
pair.second->SendUpdateMsg(); pair.second->SendUpdateMsg();
} }
frame_event.Clear();
} }
++frame_no; ++frame_no;
elapsed_time_ -= 50; elapsed_time_ -= 50;
@ -850,9 +851,6 @@ void Room::MatchTeam(Human* hum)
void Room::InitAirDrop() void Room::InitAirDrop()
{ {
std::list<MetaData::AirDrop>& air_drops = MetaMgr::Instance()->GetAirDrops(); std::list<MetaData::AirDrop>& air_drops = MetaMgr::Instance()->GetAirDrops();
#if 0
a8::XPrintf("InitAirdrop %d %d\n", {room_uuid, air_drops.size()});
#endif
for (auto& air_drop : air_drops) { for (auto& air_drop : air_drops) {
xtimer.AddDeadLineTimerAndAttach(SERVER_FRAME_RATE * air_drop.i->time(), xtimer.AddDeadLineTimerAndAttach(SERVER_FRAME_RATE * air_drop.i->time(),
a8::XParams() a8::XParams()
@ -864,14 +862,6 @@ void Room::InitAirDrop()
{ {
Room* room = (Room*)param.sender.GetUserData(); Room* room = (Room*)param.sender.GetUserData();
if (!room->game_over) { if (!room->game_over) {
#if 0
a8::XPrintf("airdrop %d %d %d\n",
{
param.param3,
param.param1,
param.param2
});
#endif
room->AirDrop(param.param1, param.param2); room->AirDrop(param.param1, param.param2);
} }
}, },