framedata ok

This commit is contained in:
aozhiwei 2019-04-23 16:07:45 +08:00
parent 94a49baddb
commit 92ba3d95b9
8 changed files with 160 additions and 157 deletions

View File

@ -117,51 +117,15 @@ void Bullet::ProcBomb()
case 5:
{
//手雷
::google::protobuf::RepeatedPtrField<::cs::MFExplosion>* explosions = nullptr;
{
auto itr = room->frame_data.explosions_hash.find(room->frame_no);
if (itr == room->frame_data.explosions_hash.end()) {
room->frame_data.explosions_hash[room->frame_no] = ::google::protobuf::RepeatedPtrField<::cs::MFExplosion>();
itr = room->frame_data.explosions_hash.find(room->frame_no);
}
explosions = &itr->second;
}
#if 1
Vector2D bomb_pos = pos;
#else
float distance = (pos - born_pos).Norm();
Vector2D bomb_pos = born_pos + born_dir * distance;
#endif
cs::MFExplosion* explosion = explosions->Add();
explosion->set_item_id(meta->i->id());
bomb_pos.ToPB(explosion->mutable_pos());
explosion->set_player_id(player->entity_uniid);
room->frame_event.AddExplosion(this, meta->i->id(), bomb_pos);
}
break;
case 6:
{
//烟雾弹
::google::protobuf::RepeatedPtrField<::cs::MFSmoke>* smokes = nullptr;
{
auto itr = room->frame_data.smokes_hash.find(room->frame_no);
if (itr == room->frame_data.smokes_hash.end()) {
room->frame_data.smokes_hash[room->frame_no] = ::google::protobuf::RepeatedPtrField<::cs::MFSmoke>();
itr = room->frame_data.smokes_hash.find(room->frame_no);
}
smokes = &itr->second;
}
#if 1
Vector2D bomb_pos = pos;
#else
float distance = (pos - born_pos).Norm();
Vector2D bomb_pos = born_pos + born_dir * distance;
#endif
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);
room->frame_event.AddSmoke(this, meta->i->id(), bomb_pos);
}
break;
}

View File

@ -0,0 +1,131 @@
#include "precompile.h"
#include "framedata.h"
void FrameEvent::AddAirDrop(int appear_time, int box_id, Vector2D box_pos)
{
#if 0
::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_box_id(box_id);
box_pos.ToPB(airdrop->mutable_pos());
#endif
}
void FrameEvent::AddEmote(Human* hum, int emote_id)
{
#if 0
::google::protobuf::RepeatedPtrField<::cs::MFEmote>* emotes = nullptr;
{
auto itr = room->frame_data.emotes_hash.find(room->frame_no);
if (itr == room->frame_data.emotes_hash.end()) {
room->frame_data.emotes_hash[room->frame_no] = ::google::protobuf::RepeatedPtrField<::cs::MFEmote>();
itr = room->frame_data.emotes_hash.find(room->frame_no);
}
emotes = &itr->second;
}
{
cs::MFEmote* p = emotes->Add();
p->set_emote_id(emote_id);
p->set_player_id(entity_uniid);
}
#endif
}
void FrameEvent::AddShot(Human* hum)
{
#if 0
{
::google::protobuf::RepeatedPtrField<::cs::MFShot>* shots = nullptr;
{
{
auto itr = room->frame_data.shots_hash.find(room->frame_no);
if (itr == room->frame_data.shots_hash.end()) {
room->frame_data.shots_hash[room->frame_no] = ::google::protobuf::RepeatedPtrField<::cs::MFShot>();
itr = room->frame_data.shots_hash.find(room->frame_no);
}
shots = &itr->second;
}
}
cs::MFShot* shot = shots->Add();
shot->set_player_id(entity_uniid);
curr_weapon->ToPB(shot->mutable_weapon());
shot->set_offhand(true);
shot->set_bullskin(10001);
}
#endif
}
void FrameEvent::AddBullet()
{
#if 0
::google::protobuf::RepeatedPtrField<::cs::MFBullet>* bullets = nullptr;
{
{
auto itr = room->frame_data.bullets_hash.find(room->frame_no);
if (itr == room->frame_data.bullets_hash.end()) {
room->frame_data.bullets_hash[room->frame_no] = ::google::protobuf::RepeatedPtrField<::cs::MFBullet>();
itr = room->frame_data.bullets_hash.find(room->frame_no);
}
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)
{
#if 0
Vector2D bomb_pos = pos;
room->AddExplosion(Human *hum, meta->i->id(), bomb_pos)
cs::MFExplosion* explosion = explosions->Add();
explosion->set_item_id(meta->i->id());
bomb_pos.ToPB(explosion->mutable_pos());
explosion->set_player_id(player->entity_uniid);
#endif
}
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_hash.find(room->frame_no);
if (itr == room->frame_data.smokes_hash.end()) {
room->frame_data.smokes_hash[room->frame_no] = ::google::protobuf::RepeatedPtrField<::cs::MFSmoke>();
itr = room->frame_data.smokes_hash.find(room->frame_no);
}
smokes = &itr->second;
}
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
}

View File

@ -2,8 +2,19 @@
#include "cs_proto.pb.h"
struct RoomFrameData
class Bullet;
class Human;
struct FrameEvent
{
public:
void AddAirDrop(int appear_time, int box_id, Vector2D box_pos);
void AddEmote(Human* hum, int emote_id);
void AddShot(Human* hum);
void AddBullet();
void AddExplosion(Bullet* bullet, int item_id, Vector2D bomb_pos);
void AddSmoke(Bullet* bullet, int item_id, Vector2D pos);
private:
std::map<long long, std::set<unsigned short>> deleted_objects_hash;
std::map<long long, std::set<unsigned short>> softdeleted_objects_hash;
std::map<long long, ::google::protobuf::RepeatedPtrField<::cs::MFExplosion>> explosions_hash;
@ -13,7 +24,3 @@ struct RoomFrameData
std::map<long long, ::google::protobuf::RepeatedPtrField<::cs::MFShot>> shots_hash;
std::map<long long, ::google::protobuf::RepeatedPtrField<::cs::MFAirDrop>> airdrops_hash;
};
struct HumanFrameData
{
};

View File

@ -175,50 +175,12 @@ void Human::Shot(Vector2D& target_dir)
#if 1
float fly_distance = 5;
#endif
{
::google::protobuf::RepeatedPtrField<::cs::MFShot>* shots = nullptr;
{
{
auto itr = room->frame_data.shots_hash.find(room->frame_no);
if (itr == room->frame_data.shots_hash.end()) {
room->frame_data.shots_hash[room->frame_no] = ::google::protobuf::RepeatedPtrField<::cs::MFShot>();
itr = room->frame_data.shots_hash.find(room->frame_no);
}
shots = &itr->second;
}
}
cs::MFShot* shot = shots->Add();
shot->set_player_id(entity_uniid);
curr_weapon->ToPB(shot->mutable_weapon());
shot->set_offhand(true);
shot->set_bullskin(10001);
}
room->frame_event.AddShot(this);
for (auto& tuple : curr_weapon->meta->bullet_born_offset) {
Vector2D bullet_born_offset = Vector2D(std::get<0>(tuple), std::get<1>(tuple));
bullet_born_offset.Rotate(attack_dir.CalcAngle(Vector2D::UP));
Vector2D bullet_born_pos = pos + bullet_born_offset;
::google::protobuf::RepeatedPtrField<::cs::MFBullet>* bullets = nullptr;
{
{
auto itr = room->frame_data.bullets_hash.find(room->frame_no);
if (itr == room->frame_data.bullets_hash.end()) {
room->frame_data.bullets_hash[room->frame_no] = ::google::protobuf::RepeatedPtrField<::cs::MFBullet>();
itr = room->frame_data.bullets_hash.find(room->frame_no);
}
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);
}
room->frame_event.AddBullet();
room->CreateBullet(this, curr_weapon->meta, bullet_born_pos, attack_dir, fly_distance);
}
--curr_weapon->ammo;

View File

@ -71,7 +71,6 @@ class Human : public Entity
bool need_sync_teammate_data = false;
bool need_sync_active_player = false;
HumanFrameData frame_data;
PlayerStats stats;
bool send_gameover = false;

View File

@ -381,22 +381,7 @@ void Player::UpdateEmote()
emote_id = 0;
return;
}
::google::protobuf::RepeatedPtrField<::cs::MFEmote>* emotes = nullptr;
{
auto itr = room->frame_data.emotes_hash.find(room->frame_no);
if (itr == room->frame_data.emotes_hash.end()) {
room->frame_data.emotes_hash[room->frame_no] = ::google::protobuf::RepeatedPtrField<::cs::MFEmote>();
itr = room->frame_data.emotes_hash.find(room->frame_no);
}
emotes = &itr->second;
}
{
cs::MFEmote* p = emotes->Add();
p->set_emote_id(emote_id);
p->set_player_id(entity_uniid);
}
room->frame_event.AddEmote(this, emote_id);
emote = false;
emote_id = 0;
}
@ -442,25 +427,7 @@ void Player::Shot()
return;
}
{
::google::protobuf::RepeatedPtrField<::cs::MFShot>* shots = nullptr;
{
{
auto itr = room->frame_data.shots_hash.find(room->frame_no);
if (itr == room->frame_data.shots_hash.end()) {
room->frame_data.shots_hash[room->frame_no] = ::google::protobuf::RepeatedPtrField<::cs::MFShot>();
itr = room->frame_data.shots_hash.find(room->frame_no);
}
shots = &itr->second;
}
}
cs::MFShot* shot = shots->Add();
shot->set_player_id(entity_uniid);
curr_weapon->ToPB(shot->mutable_weapon());
shot->set_offhand(true);
shot->set_bullskin(10001);
}
room->frame_event.AddShot(this);
if (room->gas_data.gas_mode != GasInactive &&
!a8::HasBitFlag(status, HS_Fly) &&
!a8::HasBitFlag(status, HS_Jump)
@ -469,27 +436,7 @@ void Player::Shot()
Vector2D bullet_born_offset = Vector2D(std::get<0>(tuple), std::get<1>(tuple));
bullet_born_offset.Rotate(attack_dir.CalcAngle(Vector2D::UP));
Vector2D bullet_born_pos = pos + bullet_born_offset;
::google::protobuf::RepeatedPtrField<::cs::MFBullet>* bullets = nullptr;
{
{
auto itr = room->frame_data.bullets_hash.find(room->frame_no);
if (itr == room->frame_data.bullets_hash.end()) {
room->frame_data.bullets_hash[room->frame_no] = ::google::protobuf::RepeatedPtrField<::cs::MFBullet>();
itr = room->frame_data.bullets_hash.find(room->frame_no);
}
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);
}
room->frame_event.AddBullet();
room->CreateBullet(this, curr_weapon->meta, bullet_born_pos, attack_dir, fly_distance);
}
}
@ -1047,6 +994,7 @@ void Player::MakeUpdateMsg()
update_msg->Clear();
{
update_msg->set_ack(last_seq_id);
#if 0
{
for (auto& pair : room->frame_data.deleted_objects_hash) {
if (pair.first <= room->frame_no) {
@ -1099,6 +1047,7 @@ void Player::MakeUpdateMsg()
}
}
}
#endif
if (team_members) {
for (auto& itr : *team_members) {
if (itr != this) {

View File

@ -109,6 +109,7 @@ void Room::Update(int delta_time)
}
ClearDeletedObjects();
ProcAddedObjects();
#if 0
{
{
std::vector<long long> del_ids;
@ -199,6 +200,7 @@ void Room::Update(int delta_time)
}
}
}
#endif
}
++frame_no;
elapsed_time_ -= 50;
@ -426,6 +428,7 @@ void Room::BuildingBoxBoundCollisionDetection(Entity* sender, std::vector<Entity
void Room::AddDeletedObject(unsigned short obj_uniid, bool soft_delete)
{
#if 0
std::set<unsigned short>* deleted_objects = nullptr;
if (soft_delete) {
auto itr = frame_data.softdeleted_objects_hash.find(frame_no);
@ -443,6 +446,7 @@ void Room::AddDeletedObject(unsigned short obj_uniid, bool soft_delete)
deleted_objects = &itr->second;
}
deleted_objects->insert(obj_uniid);
#endif
}
void Room::FillSMJoinedNotify(Player* self_hum, cs::SMJoinedNotify& msg)
@ -698,6 +702,7 @@ int Room::NewTeam()
void Room::ClearDeletedObjects()
{
#if 0
for (auto& pair : frame_data.deleted_objects_hash) {
for (auto& obj_uniid : pair.second) {
Entity* entity = GetEntityByUniId(obj_uniid);
@ -731,6 +736,7 @@ void Room::ClearDeletedObjects()
}
}
}
#endif
}
void Room::TouchPlayerList(a8::XParams param,
@ -1103,22 +1109,7 @@ void Room::AirDrop(int appear_time, int box_id)
});
#endif
Vector2D box_pos = gas_data.pos_new + dir * (500 + rand() % 300);
::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_box_id(box_id);
box_pos.ToPB(airdrop->mutable_pos());
frame_event.AddAirDrop(appear_time, box_id, box_pos);
xtimer.AddDeadLineTimerAndAttach(SERVER_FRAME_RATE * appear_time / 1000.f,
a8::XParams()
.SetSender(this)

View File

@ -29,7 +29,7 @@ class Room
public:
long long room_uuid = 0;
MetaData::Map* map_meta = nullptr;
RoomFrameData frame_data;
FrameEvent frame_event;
long long frame_no = 0;
GasData gas_data;
bool game_over = false;