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();
DispatchMsg();
a8::Timer::Instance()->Update();
RoomMgr::Instance()->Update(delta_time);
a8::Timer::Instance()->Update();
}
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;
if (obstacle->dead) {
obstacle->ClearColliders();
room->ProcDrop(obstacle->pos, obstacle->meta->i->drop());
room->ScatterDrop(obstacle->pos, obstacle->meta->i->drop());
}
room->TouchPlayerList(a8::XParams()
.SetSender(obstacle),

View File

@ -7,7 +7,7 @@ struct RoomFrameData
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::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::MFShot> shots;
};

View File

@ -75,6 +75,9 @@ void Player::Update(int delta_time)
if (spectate) {
UpdateSpectate();
}
if (emote) {
UpdateEmote();
}
MakeUpdateMsg();
SendNotifyMsg(*update_msg);
if (send_gameover) {
@ -267,6 +270,26 @@ void Player::UpdateGameOver()
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()
{
if (!curr_weapon->meta) {
@ -599,6 +622,10 @@ void Player::_CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg)
if (msg.has_spectate()) {
spectate = true;
}
if (msg.has_emote()) {
emote = true;
emote_id = msg.emote();
}
}
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) {
room->FetchBuilding(this);

View File

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

View File

@ -1,5 +1,7 @@
#include "precompile.h"
#include <a8/timer.h>
#include "playermgr.h"
#include "player.h"
#include "cs_proto.pb.h"
@ -22,6 +24,21 @@ const int ANDROID_NUM = 0;
const int ANDROID_NUM = 10;
#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)
{
elapsed_time_ += delta_time;
@ -60,6 +77,17 @@ void Room::Update(int delta_time)
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;
@ -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)
{
std::vector<Human*> enemys;
@ -283,40 +284,23 @@ void Room::ResetFrameData()
{
frame_data.explosions_hash.clear();
frame_data.smokes_hash.clear();
frame_data.emotes_hash.Clear();
}
#endif
frame_data.bullets.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);
if (drop_meta) {
std::vector<std::tuple<int, int>> drop_items;
drop_meta->RandItems(drop_items);
for (auto& item : drop_items) {
MetaData::Equip* equip_meta = MetaMgr::Instance()->GetEquip(std::get<0>(item));
if (equip_meta) {
Loot* entity = new Loot();
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);
}
}
Vector2D dir = Vector2D::UP;
dir.Rotate(a8::RandAngle());
DropItem(center + dir * (5 + rand() % 50), std::get<0>(item));
}
}
}
@ -729,3 +713,8 @@ bool Room::GenSmallCircle(Vector2D big_circle_pos, float big_circle_rad, float s
out_pos = big_circle_pos + dir * rad;
return true;
}
void Room::OutputDebugLog()
{
}

View File

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

View File

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

View File

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