merge master

This commit is contained in:
aozhiwei 2019-04-11 11:03:49 +08:00
commit db9819dab8
9 changed files with 99 additions and 64 deletions

View File

@ -219,8 +219,8 @@ void App::QuickExecute(int delta_time)
{ {
ProcessIMMsg(); ProcessIMMsg();
DispatchMsg(); DispatchMsg();
a8::Timer::Instance()->Update();
RoomMgr::Instance()->Update(delta_time); RoomMgr::Instance()->Update(delta_time);
a8::Timer::Instance()->Update();
} }
void App::SlowerExecute(int delta_time) void App::SlowerExecute(int delta_time)

View File

@ -93,7 +93,7 @@ void Bullet::OnHit(std::vector<Entity*>& objects)
obstacle->dead_frameno = room->frame_no; obstacle->dead_frameno = room->frame_no;
if (obstacle->dead) { if (obstacle->dead) {
obstacle->ClearColliders(); obstacle->ClearColliders();
room->ProcDrop(obstacle->pos, obstacle->meta->i->drop()); room->ScatterDrop(obstacle->pos, obstacle->meta->i->drop());
} }
room->TouchPlayerList(a8::XParams() room->TouchPlayerList(a8::XParams()
.SetSender(obstacle), .SetSender(obstacle),

View File

@ -7,7 +7,7 @@ struct RoomFrameData
std::set<unsigned short> deleted_objects; std::set<unsigned short> deleted_objects;
std::map<long long, ::google::protobuf::RepeatedPtrField<::cs::MFExplosion>> explosions_hash; std::map<long long, ::google::protobuf::RepeatedPtrField<::cs::MFExplosion>> explosions_hash;
std::map<long long, ::google::protobuf::RepeatedPtrField<::cs::MFSmoke>> smokes_hash; std::map<long long, ::google::protobuf::RepeatedPtrField<::cs::MFSmoke>> smokes_hash;
::google::protobuf::RepeatedPtrField<::cs::MFEmote> emotes; std::map<long long, ::google::protobuf::RepeatedPtrField<::cs::MFEmote>> emotes_hash;
::google::protobuf::RepeatedPtrField<::cs::MFBullet> bullets; ::google::protobuf::RepeatedPtrField<::cs::MFBullet> bullets;
::google::protobuf::RepeatedPtrField<::cs::MFShot> shots; ::google::protobuf::RepeatedPtrField<::cs::MFShot> shots;
}; };

View File

@ -75,6 +75,9 @@ void Player::Update(int delta_time)
if (spectate) { if (spectate) {
UpdateSpectate(); UpdateSpectate();
} }
if (emote) {
UpdateEmote();
}
MakeUpdateMsg(); MakeUpdateMsg();
SendNotifyMsg(*update_msg); SendNotifyMsg(*update_msg);
if (send_gameover) { if (send_gameover) {
@ -267,6 +270,26 @@ void Player::UpdateGameOver()
send_gameover = false; send_gameover = false;
} }
void Player::UpdateEmote()
{
::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* emote = emotes->Add();
emote->set_emote_id(emote_id);
emote->set_player_id(entity_uniid);
emote = false;
emote_id = 0;
}
void Player::Shot() void Player::Shot()
{ {
if (!curr_weapon->meta) { if (!curr_weapon->meta) {
@ -599,6 +622,10 @@ void Player::_CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg)
if (msg.has_spectate()) { if (msg.has_spectate()) {
spectate = true; spectate = true;
} }
if (msg.has_emote()) {
emote = true;
emote_id = msg.emote();
}
} }
void Player::UpdateDropWeapon() void Player::UpdateDropWeapon()
@ -788,6 +815,13 @@ void Player::MakeUpdateMsg()
} }
} }
} }
for (auto& pair : room->frame_data.emotes_hash) {
if (pair.first <= room->frame_no) {
for (auto& itr : pair.second) {
*update_msg->add_emotes() = itr;
}
}
}
} }
if (updated_times == 0) { if (updated_times == 0) {
room->FetchBuilding(this); room->FetchBuilding(this);

View File

@ -55,6 +55,9 @@ class Player : public Human
bool spectate = false; bool spectate = false;
bool emote = false;
int emote_id = 0;
::google::protobuf::RepeatedField< ::google::protobuf::int32 > interaction_objids; ::google::protobuf::RepeatedField< ::google::protobuf::int32 > interaction_objids;
template <typename T> template <typename T>
@ -78,6 +81,7 @@ class Player : public Human
void UpdateUseItemIdx(); void UpdateUseItemIdx();
void UpdateSpectate(); void UpdateSpectate();
void UpdateGameOver(); void UpdateGameOver();
void UpdateEmote();
void Shot(); void Shot();
void ProcInteraction(); void ProcInteraction();
void ObstacleInteraction(Obstacle* entity); void ObstacleInteraction(Obstacle* entity);

View File

@ -1,5 +1,7 @@
#include "precompile.h" #include "precompile.h"
#include <a8/timer.h>
#include "playermgr.h" #include "playermgr.h"
#include "player.h" #include "player.h"
#include "cs_proto.pb.h" #include "cs_proto.pb.h"
@ -22,6 +24,21 @@ const int ANDROID_NUM = 0;
const int ANDROID_NUM = 10; const int ANDROID_NUM = 10;
#endif #endif
void Room::Initialize()
{
ShuaAndroid();
#if 0
a8::Timer::Instance()->AddRepeatTimer(
1000 * 5,
a8::XParams(),
[] (const a8::XParams& param)
{
}
);
#endif
}
void Room::Update(int delta_time) void Room::Update(int delta_time)
{ {
elapsed_time_ += delta_time; elapsed_time_ += delta_time;
@ -60,6 +77,17 @@ void Room::Update(int delta_time)
frame_data.smokes_hash.erase(id); frame_data.smokes_hash.erase(id);
} }
} }
{
std::vector<long long> del_ids;
for (auto& pair : frame_data.emotes_hash) {
if (pair.first < frame_no) {
del_ids.push_back(pair.first);
}
}
for (long long id : del_ids) {
frame_data.emotes_hash.erase(id);
}
}
} }
} }
++frame_no; ++frame_no;
@ -174,33 +202,6 @@ void Room::ShuaAndroid()
} }
} }
bool Room::RandomPos(Human* hum, float distance, Vector2D& out_pos)
{
Vector2D dir = hum->pos;
dir.Rotate(a8::RandAngle());
dir.Normalize();
CircleCollider collider;
collider.owner = hum;
collider.pos = dir * distance;
collider.rad = hum->meta->i->radius();
for (auto& pair : uniid_hash_) {
if (pair.second->entity_type == ET_Player ||
pair.second->entity_type == ET_Bullet
) {
continue;
} else {
for (auto& itr : pair.second->colliders) {
if (collider.Intersect(itr)) {
return false;
}
}
}
}
out_pos = hum->pos + collider.pos;
return true;
}
Human* Room::FindEnemy(Human* hum) Human* Room::FindEnemy(Human* hum)
{ {
std::vector<Human*> enemys; std::vector<Human*> enemys;
@ -283,40 +284,23 @@ void Room::ResetFrameData()
{ {
frame_data.explosions_hash.clear(); frame_data.explosions_hash.clear();
frame_data.smokes_hash.clear(); frame_data.smokes_hash.clear();
frame_data.emotes_hash.Clear();
} }
#endif #endif
frame_data.bullets.Clear(); frame_data.bullets.Clear();
frame_data.shots.Clear(); frame_data.shots.Clear();
frame_data.emotes.Clear();
} }
void Room::ProcDrop(Vector2D center, int drop_id) void Room::ScatterDrop(Vector2D center, int drop_id)
{ {
MetaData::Drop* drop_meta = MetaMgr::Instance()->GetDrop(drop_id); MetaData::Drop* drop_meta = MetaMgr::Instance()->GetDrop(drop_id);
if (drop_meta) { if (drop_meta) {
std::vector<std::tuple<int, int>> drop_items; std::vector<std::tuple<int, int>> drop_items;
drop_meta->RandItems(drop_items); drop_meta->RandItems(drop_items);
for (auto& item : drop_items) { for (auto& item : drop_items) {
MetaData::Equip* equip_meta = MetaMgr::Instance()->GetEquip(std::get<0>(item)); Vector2D dir = Vector2D::UP;
if (equip_meta) { dir.Rotate(a8::RandAngle());
Loot* entity = new Loot(); DropItem(center + dir * (5 + rand() % 50), std::get<0>(item));
entity->room = this;
entity->meta = equip_meta;
entity->entity_uniid = AllocUniid();
{
Vector2D dir = Vector2D::UP;
dir.Rotate(a8::RandAngle());
entity->pos = center + dir * (5 + rand() % 50);
}
entity->item_id = std::get<0>(item);
entity->count = std::get<1>(item);
entity->Initialize();
uniid_hash_[entity->entity_uniid] = entity;
for (auto& pair : human_hash_) {
pair.second->new_objects.insert(entity);
pair.second->part_objects.insert(entity);
}
}
} }
} }
} }
@ -729,3 +713,8 @@ bool Room::GenSmallCircle(Vector2D big_circle_pos, float big_circle_rad, float s
out_pos = big_circle_pos + dir * rad; out_pos = big_circle_pos + dir * rad;
return true; return true;
} }
void Room::OutputDebugLog()
{
}

View File

@ -23,6 +23,7 @@ public:
long long frame_no = 0; long long frame_no = 0;
GasData gas_data; GasData gas_data;
void Initialize();
void Update(int delta_time); void Update(int delta_time);
bool IsFull(); bool IsFull();
int GetPlayerNum(); int GetPlayerNum();
@ -30,40 +31,48 @@ public:
Player* GetPlayerByAccountId(const std::string& accountid); Player* GetPlayerByAccountId(const std::string& accountid);
Player* GetPlayerByUniId(unsigned short uniid); Player* GetPlayerByUniId(unsigned short uniid);
Entity* GetEntityByUniId(unsigned short uniid); Entity* GetEntityByUniId(unsigned short uniid);
void AddPlayer(Player* hum); void AddPlayer(Player* hum);
void ShuaAndroid();
bool RandomPos(Human* hum, float distance, Vector2D& out_pos);
Human* FindEnemy(Human* hum); Human* FindEnemy(Human* hum);
void CollisionDetection(Entity* sender, int detection_flags, std::vector<Entity*>& objects); void CollisionDetection(Entity* sender, int detection_flags, std::vector<Entity*>& objects);
void AddDeletedObject(unsigned short obj_uniid); void AddDeletedObject(unsigned short obj_uniid);
void BeAddedObject(Entity* entity);
void FetchBuilding(Human* hum);
void FillSMJoinedNotify(Player* self_hum, cs::SMJoinedNotify& msg); void FillSMJoinedNotify(Player* self_hum, cs::SMJoinedNotify& msg);
void FillSMMapInfo(cs::SMMapInfo& map_info);
void TouchPlayerList(a8::XParams param, void TouchPlayerList(a8::XParams param,
std::function<void (Player*, a8::XParams&)> func); std::function<void (Player*, a8::XParams&)> func);
void TouchHumanList(a8::XParams param, void TouchHumanList(a8::XParams param,
std::function<void (Human*, a8::XParams&)> func); std::function<void (Human*, a8::XParams&)> func);
void BeAddedObject(Entity* entity);
void ProcDrop(Vector2D center, int drop_id); void ScatterDrop(Vector2D center, int drop_id);
void CreateThings();
void FillSMMapInfo(cs::SMMapInfo& map_info);
void DropItem(Vector2D pos, int item_id); void DropItem(Vector2D pos, int item_id);
void CreateThings();
void CreateDoor(Building* building, int door_idx); void CreateDoor(Building* building, int door_idx);
void CreateHouseObstacle(Building* building, int id, float x, float y); void CreateHouseObstacle(Building* building, int id, float x, float y);
void CreateLoot(int equip_id, Vector2D pos, int count); void CreateLoot(int equip_id, Vector2D pos, int count);
void CreateBullet(Human* hum, MetaData::Equip* gun_meta, void CreateBullet(Human* hum, MetaData::Equip* gun_meta,
Vector2D pos, Vector2D dir, float fly_distance); Vector2D pos, Vector2D dir, float fly_distance);
void FetchBuilding(Human* hum);
void OnHumanDie(Human* hum); void OnHumanDie(Human* hum);
private: private:
unsigned short AllocUniid(); unsigned short AllocUniid();
void ShuaAndroid();
void ResetFrameData(); void ResetFrameData();
void ClearDeletedObjects(); void ClearDeletedObjects();
void ProcAddedObjects(); void ProcAddedObjects();
void UpdateGas(); void UpdateGas();
bool GenSmallCircle(Vector2D big_circle_pos, float big_circle_rad, float small_circle_rad, bool GenSmallCircle(Vector2D big_circle_pos, float big_circle_rad, float small_circle_rad,
Vector2D& out_pos); Vector2D& out_pos);
void OutputDebugLog();
private: private:
a8::TimerAttacher timer_attacher_;
int elapsed_time_ = 0; int elapsed_time_ = 0;
int alive_count_ = 0; int alive_count_ = 0;

View File

@ -41,8 +41,7 @@ void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg)
abort(); abort();
} }
room->map_meta = MetaMgr::Instance()->GetMap(1001); room->map_meta = MetaMgr::Instance()->GetMap(1001);
room->ShuaAndroid(); room->Initialize();
inactive_room_hash_[room->room_uuid] = room;
room_hash_[room->room_uuid] = room; room_hash_[room->room_uuid] = room;
} }
Player* hum = PlayerMgr::Instance()->CreatePlayerByCMJoin(hdr.socket_handle, msg); Player* hum = PlayerMgr::Instance()->CreatePlayerByCMJoin(hdr.socket_handle, msg);

View File

@ -462,10 +462,8 @@ message MFSmoke
// //
message MFEmote message MFEmote
{ {
optional int32 type = 1; optional int32 emote_id = 1; //id
optional int32 is_ping = 2;
optional int32 player_id = 3; //id optional int32 player_id = 3; //id
optional MFVector2D pos = 4; //
optional string msg = 5; optional string msg = 5;
} }
@ -545,6 +543,8 @@ message CMMove
repeated int32 interaction_objids = 23; //id列表 repeated int32 interaction_objids = 23; //id列表
optional bool spectate = 30; // optional bool spectate = 30; //
optional int32 emote = 31; //id
} }
// //