smupdate ok

This commit is contained in:
aozhiwei 2019-04-25 14:17:23 +08:00
parent d1c2e91058
commit 7a95ca7c51
6 changed files with 146 additions and 119 deletions

View File

@ -2,6 +2,8 @@
#include "frameevent.h" #include "frameevent.h"
#include "human.h" #include "human.h"
#include "bullet.h"
#include "metamgr.h"
void FrameEvent::AddAirDrop(int appear_time, int box_id, Vector2D box_pos) void FrameEvent::AddAirDrop(int appear_time, int box_id, Vector2D box_pos)
{ {
@ -13,116 +15,126 @@ void FrameEvent::AddAirDrop(int appear_time, int box_id, Vector2D box_pos)
void FrameEvent::AddEmote(Human* hum, int emote_id) void FrameEvent::AddEmote(Human* hum, int emote_id)
{ {
#if 0
::google::protobuf::RepeatedPtrField<::cs::MFEmote>* emotes = nullptr;
{ {
auto itr = room->frame_data.emotes_.find(room->frame_no); auto& tuple = a8::FastAppend(emotes_);
if (itr == room->frame_data.emotes_.end()) { std::get<0>(tuple) = hum;
room->frame_data.emotes_[room->frame_no] = ::google::protobuf::RepeatedPtrField<::cs::MFEmote>(); auto& p = std::get<1>(tuple);
itr = room->frame_data.emotes_.find(room->frame_no);
}
emotes = &itr->second;
}
{ p.set_emote_id(emote_id);
cs::MFEmote* p = emotes->Add(); p.set_player_id(hum->entity_uniid);
p->set_emote_id(emote_id); }
p->set_player_id(entity_uniid); {
int emote_idx = emotes_.size() - 1;
for (auto& cell : hum->grid_list) {
for (auto& hum : cell->human_list) {
hum->emotes_.push_back(emote_idx);
}
}
} }
#endif
} }
void FrameEvent::AddShot(Human* hum) void FrameEvent::AddShot(Human* hum)
{ {
auto& tuple = a8::FastAppend(shots_); {
std::get<0>(tuple) = hum; auto& tuple = a8::FastAppend(shots_);
auto& shot = std::get<1>(tuple); std::get<0>(tuple) = hum;
shot.set_player_id(hum->entity_uniid); auto& p = std::get<1>(tuple);
hum->curr_weapon->ToPB(shot.mutable_weapon());
shot.set_offhand(true);
shot.set_bullskin(10001);
int shot_idx = shots_.size() - 1; p.set_player_id(hum->entity_uniid);
for (auto& cell : hum->grid_list) { hum->curr_weapon->ToPB(p.mutable_weapon());
for (auto& hum : cell->human_list) { p.set_offhand(true);
hum->shots_.push_back(shot_idx); p.set_bullskin(10001);
}
{
int shot_idx = shots_.size() - 1;
for (auto& cell : hum->grid_list) {
for (auto& hum : cell->human_list) {
hum->shots_.push_back(shot_idx);
}
} }
} }
} }
void FrameEvent::AddBullet() void FrameEvent::AddBullet(Human* hum, Vector2D born_pos, float fly_distance)
{ {
#if 0
::google::protobuf::RepeatedPtrField<::cs::MFBullet>* bullets = nullptr;
{ {
{ auto& tuple = a8::FastAppend(bullets_);
auto itr = room->frame_data.bullets_.find(room->frame_no); std::get<0>(tuple) = hum;
if (itr == room->frame_data.bullets_.end()) { auto& p = std::get<1>(tuple);
room->frame_data.bullets_[room->frame_no] = ::google::protobuf::RepeatedPtrField<::cs::MFBullet>();
itr = room->frame_data.bullets_.find(room->frame_no); p.set_player_id(hum->entity_uniid);
p.set_bullet_id(hum->curr_weapon->meta->i->use_bullet());
born_pos.ToPB(p.mutable_pos());
hum->attack_dir.ToPB(p.mutable_dir());
p.set_bulletskin(10001);
p.set_gun_id(hum->curr_weapon->meta->i->id());
p.set_fly_distance(fly_distance);
}
{
int bullet_idx = bullets_.size() - 1;
for (auto& cell : hum->grid_list) {
for (auto& hum : cell->human_list) {
hum->bullets_.push_back(bullet_idx);
} }
bullets = &itr->second;
} }
} }
{
cs::MFBullet* bullet = bullets->Add();
bullet->set_player_id(entity_uniid);
bullet->set_bullet_id(curr_weapon->meta->i->use_bullet());
bullet_born_pos.ToPB(bullet->mutable_pos());
attack_dir.ToPB(bullet->mutable_dir());
bullet->set_bulletskin(10001);
bullet->set_gun_id(curr_weapon->meta->i->id());
bullet->set_fly_distance(fly_distance);
}
#endif
} }
void FrameEvent::AddExplosion(Bullet* bullet, int item_id, Vector2D bomb_pos) void FrameEvent::AddExplosion(Bullet* bullet, int item_id, Vector2D bomb_pos)
{ {
#if 0 {
Vector2D bomb_pos = pos; auto& tuple = a8::FastAppend(explosions_);
room->AddExplosion(Human *hum, meta->i->id(), bomb_pos) std::get<0>(tuple) = bullet->player;
cs::MFExplosion* explosion = explosions->Add(); auto& p = std::get<1>(tuple);
explosion->set_item_id(meta->i->id());
bomb_pos.ToPB(explosion->mutable_pos()); p.set_item_id(item_id);
explosion->set_player_id(player->entity_uniid); bomb_pos.ToPB(p.mutable_pos());
#endif p.set_player_id(bullet->player->entity_uniid);
}
{
int explosion_idx = explosions_.size() - 1;
for (auto& cell : bullet->player->grid_list) {
for (auto& hum : cell->human_list) {
hum->explosions_.push_back(explosion_idx);
}
}
}
} }
void FrameEvent::AddSmoke(Bullet* bullet, int item_id, Vector2D pos) void FrameEvent::AddSmoke(Bullet* bullet, int item_id, Vector2D pos)
{ {
#if 0
::google::protobuf::RepeatedPtrField<::cs::MFSmoke>* smokes = nullptr;
{ {
auto itr = room->frame_data.smokes_.find(room->frame_no); auto& tuple = a8::FastAppend(explosions_);
if (itr == room->frame_data.smokes_.end()) { std::get<0>(tuple) = bullet->player;
room->frame_data.smokes_[room->frame_no] = ::google::protobuf::RepeatedPtrField<::cs::MFSmoke>(); auto& p = std::get<1>(tuple);
itr = room->frame_data.smokes_.find(room->frame_no);
} p.set_item_id(item_id);
smokes = &itr->second; pos.ToPB(p.mutable_pos());
p.set_player_id(bullet->player->entity_uniid);
}
{
int explosion_idx = smokes_.size() - 1;
for (auto& cell : bullet->player->grid_list) {
for (auto& hum : cell->human_list) {
hum->explosions_.push_back(explosion_idx);
}
}
} }
cs::MFSmoke* smoke = smokes->Add();
smoke->set_item_id(meta->i->id());
bomb_pos.ToPB(smoke->mutable_pos());
smoke->set_player_id(player->entity_uniid);
#endif
} }
void FrameEvent::Clear() void FrameEvent::Clear()
{ {
if (explosions_.size() > 0) { if (!explosions_.empty()) {
explosions_.Clear(); explosions_.clear();
} }
if (smokes_.size() > 0) { if (!smokes_.empty()) {
smokes_.Clear(); smokes_.clear();
} }
if (emotes_.size() > 0) { if (!emotes_.empty()) {
emotes_.Clear(); emotes_.clear();
} }
if (bullets_.size() > 0) { if (!bullets_.empty()) {
bullets_.Clear(); bullets_.clear();
} }
if (!shots_.empty()) { if (!shots_.empty()) {
shots_.clear(); shots_.clear();

View File

@ -10,18 +10,18 @@ public:
void AddAirDrop(int appear_time, int box_id, Vector2D box_pos); void AddAirDrop(int appear_time, int box_id, Vector2D box_pos);
void AddEmote(Human* hum, int emote_id); void AddEmote(Human* hum, int emote_id);
void AddShot(Human* hum); void AddShot(Human* hum);
void AddBullet(); void AddBullet(Human* hum, Vector2D born_pos, float fly_distance);
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(); void Clear();
private: private:
::google::protobuf::RepeatedPtrField<::cs::MFExplosion> explosions_;
::google::protobuf::RepeatedPtrField<::cs::MFSmoke> smokes_;
::google::protobuf::RepeatedPtrField<::cs::MFEmote> emotes_;
::google::protobuf::RepeatedPtrField<::cs::MFBullet> bullets_;
::google::protobuf::RepeatedPtrField<::cs::MFAirDrop> airdrops_; ::google::protobuf::RepeatedPtrField<::cs::MFAirDrop> airdrops_;
std::vector<std::tuple<Human*, ::cs::MFShot>> shots_; std::vector<std::tuple<Human*, ::cs::MFShot>> shots_;
std::vector<std::tuple<Human*, ::cs::MFBullet>> bullets_;
std::vector<std::tuple<Human*, ::cs::MFExplosion>> explosions_;
std::vector<std::tuple<Human*, ::cs::MFSmoke>> smokes_;
std::vector<std::tuple<Human*, ::cs::MFEmote>> emotes_;
friend class FrameMaker; friend class FrameMaker;
}; };

View File

@ -4,39 +4,6 @@
#include "human.h" #include "human.h"
#include "room.h" #include "room.h"
#if 0
{
for (auto& pair : room->frame_data.bullets_hash) {
if (pair.first <= room->frame_no) {
for (auto& itr : pair.second) {
*msg->add_bullets() = itr;
}
}
}
for (auto& pair : room->frame_data.explosions_hash) {
if (pair.first <= room->frame_no) {
for (auto& itr : pair.second) {
*msg->add_explosions() = itr;
}
}
}
for (auto& pair : room->frame_data.smokes_hash) {
if (pair.first <= room->frame_no) {
for (auto& itr : pair.second) {
*msg->add_smokes() = itr;
}
}
}
for (auto& pair : room->frame_data.emotes_hash) {
if (pair.first <= room->frame_no) {
for (auto& itr : pair.second) {
*msg->add_emotes() = itr;
}
}
}
}
#endif
cs::SMUpdate* FrameMaker::MakeUpdateMsg(Human* hum) cs::SMUpdate* FrameMaker::MakeUpdateMsg(Human* hum)
{ {
cs::SMUpdate* msg = new cs::SMUpdate; cs::SMUpdate* msg = new cs::SMUpdate;
@ -70,14 +37,46 @@ cs::SMUpdate* FrameMaker::MakeUpdateMsg(Human* hum)
hum->part_objects.erase(entity); hum->part_objects.erase(entity);
} }
} }
for (int shot_idx : hum->shots_) { for (int idx : hum->shots_) {
if (shot_idx < room->frame_event.shots_.size()) { if (idx < room->frame_event.shots_.size()) {
auto& tuple = room->frame_event.shots_[shot_idx]; auto& tuple = room->frame_event.shots_[idx];
if (hum->CanSee(std::get<0>(tuple))) { if (hum->CanSee(std::get<0>(tuple))) {
*msg->add_shots() = std::get<1>(tuple); *msg->add_shots() = std::get<1>(tuple);
} }
} }
} }
for (int idx : hum->bullets_) {
if (idx < room->frame_event.bullets_.size()) {
auto& tuple = room->frame_event.bullets_[idx];
if (hum->CanSee(std::get<0>(tuple))) {
*msg->add_bullets() = std::get<1>(tuple);
}
}
}
for (int idx : hum->explosions_) {
if (idx < room->frame_event.explosions_.size()) {
auto& tuple = room->frame_event.explosions_[idx];
if (hum->CanSee(std::get<0>(tuple))) {
*msg->add_explosions() = std::get<1>(tuple);
}
}
}
for (int idx : hum->smokes_) {
if (idx < room->frame_event.smokes_.size()) {
auto& tuple = room->frame_event.smokes_[idx];
if (hum->CanSee(std::get<0>(tuple))) {
*msg->add_smokes() = std::get<1>(tuple);
}
}
}
for (int idx : hum->emotes_) {
if (idx < room->frame_event.emotes_.size()) {
auto& tuple = room->frame_event.emotes_[idx];
if (hum->CanSee(std::get<0>(tuple))) {
*msg->add_emotes() = std::get<1>(tuple);
}
}
}
if (room->frame_event.airdrops_.size() > 0) { if (room->frame_event.airdrops_.size() > 0) {
*msg->mutable_airdrop() = room->frame_event.airdrops_.Get(0); *msg->mutable_airdrop() = room->frame_event.airdrops_.Get(0);
} }
@ -105,6 +104,18 @@ cs::SMUpdate* FrameMaker::MakeUpdateMsg(Human* hum)
if (!hum->shots_.empty()) { if (!hum->shots_.empty()) {
hum->shots_.clear(); hum->shots_.clear();
} }
if (!hum->bullets_.empty()) {
hum->bullets_.clear();
}
if (!hum->explosions_.empty()) {
hum->explosions_.clear();
}
if (!hum->smokes_.empty()) {
hum->smokes_.clear();
}
if (!hum->emotes_.empty()) {
hum->emotes_.clear();
}
++hum->send_msg_times; ++hum->send_msg_times;
return msg; return msg;
} }

View File

@ -180,7 +180,7 @@ void Human::Shot(Vector2D& target_dir)
Vector2D bullet_born_offset = Vector2D(std::get<0>(tuple), std::get<1>(tuple)); Vector2D bullet_born_offset = Vector2D(std::get<0>(tuple), std::get<1>(tuple));
bullet_born_offset.Rotate(attack_dir.CalcAngle(Vector2D::UP)); bullet_born_offset.Rotate(attack_dir.CalcAngle(Vector2D::UP));
Vector2D bullet_born_pos = pos + bullet_born_offset; Vector2D bullet_born_pos = pos + bullet_born_offset;
room->frame_event.AddBullet(); room->frame_event.AddBullet(this, bullet_born_pos, fly_distance);
room->CreateBullet(this, curr_weapon->meta, bullet_born_pos, attack_dir, fly_distance); room->CreateBullet(this, curr_weapon->meta, bullet_born_pos, attack_dir, fly_distance);
} }
--curr_weapon->ammo; --curr_weapon->ammo;

View File

@ -136,6 +136,10 @@ protected:
std::set<Entity*> part_objects; std::set<Entity*> part_objects;
std::set<int> del_objects; std::set<int> del_objects;
std::vector<int> shots_; std::vector<int> shots_;
std::vector<int> emotes_;
std::vector<int> bullets_;
std::vector<int> smokes_;
std::vector<int> explosions_;
private: private:
CircleCollider* self_collider_ = nullptr; CircleCollider* self_collider_ = nullptr;

View File

@ -439,7 +439,7 @@ void Player::Shot()
Vector2D bullet_born_offset = Vector2D(std::get<0>(tuple), std::get<1>(tuple)); Vector2D bullet_born_offset = Vector2D(std::get<0>(tuple), std::get<1>(tuple));
bullet_born_offset.Rotate(attack_dir.CalcAngle(Vector2D::UP)); bullet_born_offset.Rotate(attack_dir.CalcAngle(Vector2D::UP));
Vector2D bullet_born_pos = pos + bullet_born_offset; Vector2D bullet_born_pos = pos + bullet_born_offset;
room->frame_event.AddBullet(); room->frame_event.AddBullet(this, bullet_born_pos, fly_distance);
room->CreateBullet(this, curr_weapon->meta, bullet_born_pos, attack_dir, fly_distance); room->CreateBullet(this, curr_weapon->meta, bullet_born_pos, attack_dir, fly_distance);
} }
} }