This commit is contained in:
aozhiwei 2019-04-28 19:57:06 +08:00
parent 5f5118905e
commit c25560e035
4 changed files with 52 additions and 40 deletions

View File

@ -1154,3 +1154,41 @@ void Human::SummonHero()
BroadcastFullState();
}
}
void Human::AddObserver(Human* observer)
{
observers_.insert(observer);
}
void Human::RemoveObserver(Human* observer)
{
observers_.erase(observer);
}
void Human::SendUpdateMsg()
{
if (!follow_) {
cs::SMUpdate* msg = room->frame_maker.MakeUpdateMsg(this);
if (msg) {
SendNotifyMsg(*msg);
delete msg;
msg = nullptr;
}
}
if (send_gameover) {
UpdateGameOver();
}
{
if (!new_objects.empty()) {
new_objects.clear();
}
}
}
void Human::UpdateGameOver()
{
cs::SMGameOver msg;
FillSMGameOver(msg);
SendNotifyMsg(msg);
send_gameover = false;
}

View File

@ -2,6 +2,7 @@
#include "entity.h"
#include "cs_proto.pb.h"
#include "GGListener.h"
namespace MetaData
{
@ -32,6 +33,7 @@ class Obstacle;
class Human : public Entity
{
public:
int socket_handle = 0;
int team_id = 0;
std::string account_id;
std::string team_uuid;
@ -152,6 +154,15 @@ class Human : public Entity
void RecoverHp(int inc_hp);
void FillBodyState(::google::protobuf::RepeatedPtrField<::cs::MFBodyState>* states);
void SummonHero();
void AddObserver(Human* observer);
void RemoveObserver(Human* observer);
void SendUpdateMsg();
template <typename T>
void SendNotifyMsg(T& msg)
{
GGListener::Instance()->SendToClient(socket_handle, 0, msg);
}
void UpdateGameOver();
protected:
long long last_shot_frameno_ = 0;
@ -175,7 +186,8 @@ protected:
std::vector<int> bullets_;
std::vector<int> smokes_;
std::vector<int> explosions_;
std::list<Human*> observers_;
std::set<Human*> observers_;
Human* follow_ = nullptr;
private:
CircleCollider* self_collider_ = nullptr;

View File

@ -378,14 +378,6 @@ void Player::UpdateSpectate()
spectate = false;
}
void Player::UpdateGameOver()
{
cs::SMGameOver msg;
FillSMGameOver(msg);
SendNotifyMsg(msg);
send_gameover = false;
}
void Player::UpdateEmote()
{
if (a8::HasBitFlag(status, HS_Fly)) {
@ -768,25 +760,6 @@ void Player::HumanInteraction(Human* hum)
);
}
void Player::SendUpdateMsg()
{
cs::SMUpdate* msg = room->frame_maker.MakeUpdateMsg(this);
if (msg) {
SendNotifyMsg(*msg);
delete msg;
msg = nullptr;
}
if (send_gameover) {
UpdateGameOver();
}
{
if (!new_objects.empty()) {
new_objects.clear();
}
}
++send_update_msg_times;
}
void Player::_CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg)
{
bool has_move_dir = msg.has_move_dir();

View File

@ -1,7 +1,6 @@
#pragma once
#include "human.h"
#include "GGListener.h"
namespace cs
{
@ -22,7 +21,6 @@ class Player : public Human
enum { HID = HID_Player };
public:
int socket_handle = 0;
int team_mode = 0;
int player_count = 0;
bool auto_fill = false;
@ -64,12 +62,6 @@ class Player : public Human
::google::protobuf::RepeatedField< ::google::protobuf::int32 > interaction_objids;
template <typename T>
void SendNotifyMsg(T& msg)
{
GGListener::Instance()->SendToClient(socket_handle, 0, msg);
}
Player();
virtual ~Player() override;
virtual void Initialize() override;
@ -84,7 +76,6 @@ class Player : public Human
void UpdateCancelAction();
void UpdateUseItemIdx();
void UpdateSpectate();
void UpdateGameOver();
void UpdateEmote();
void UpdateJump();
void UpdateUseSkill();
@ -93,11 +84,9 @@ class Player : public Human
void ObstacleInteraction(Obstacle* entity);
void LootInteraction(Loot* entity);
void HumanInteraction(Human* hum);
void SendUpdateMsg();
void _CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg);
void _CMEmote(f8::MsgHdr& hdr, const cs::CMEmote& msg);
void _CMVoice(f8::MsgHdr& hdr, const cs::CMVoice& msg);
private:
int send_update_msg_times = 0;
};