完成room重构

This commit is contained in:
aozhiwei 2019-04-10 20:25:05 +08:00
parent b814b2af96
commit 8384d56771
7 changed files with 31 additions and 56 deletions

View File

@ -113,7 +113,6 @@ void Human::Shot(Vector2D& target_dir)
if (!curr_weapon->meta) {
return;
}
{
cs::MFShot* shot = room->frame_data.shots.Add();
shot->set_player_id(entity_uniid);
@ -130,20 +129,7 @@ void Human::Shot(Vector2D& target_dir)
bullet->set_bulletskin(10001);
bullet->set_gun_id(curr_weapon->meta->i->id());
}
{
Bullet* bullet = new Bullet();
bullet->player = this;
bullet->room = room;
bullet->gun_meta = curr_weapon->meta;
bullet->meta = MetaMgr::Instance()->GetEquip(curr_weapon->meta->i->use_bullet());
bullet->pos = pos;
bullet->dir = target_dir;
bullet->born_pos = pos;
bullet->born_dir = target_dir;
bullet->entity_uniid = bullet->room->AllocUniid();
bullet->Initialize();
room->AddBullet(bullet);
}
room->CreateBullet(this, curr_weapon->meta, pos, target_dir, 0);
}
void Human::RecalcSelfCollider()

View File

@ -300,21 +300,7 @@ void Player::Shot()
bullet->set_gun_id(curr_weapon->meta->i->id());
bullet->set_fly_distance(fly_distance);
}
{
Bullet* bullet = new Bullet();
bullet->player = this;
bullet->room = room;
bullet->gun_meta = curr_weapon->meta;
bullet->meta = MetaMgr::Instance()->GetEquip(curr_weapon->meta->i->use_bullet());
bullet->pos = bullet_born_pos;
bullet->dir = attack_dir;
bullet->born_pos = bullet_born_pos;
bullet->born_dir = attack_dir;
bullet->fly_distance = fly_distance;
bullet->entity_uniid = bullet->room->AllocUniid();
bullet->Initialize();
room->AddBullet(bullet);
}
room->CreateBullet(this, curr_weapon->meta, bullet_born_pos, attack_dir, fly_distance);
}
--curr_weapon->ammo;
int slot_id = curr_weapon->meta->i->_inventory_slot();

View File

@ -6,17 +6,10 @@
void PlayerMgr::Init()
{
}
void PlayerMgr::UnInit()
{
}
void PlayerMgr::Update()
{
}
Player* PlayerMgr::GetPlayerBySocket(int socket)
@ -25,10 +18,10 @@ Player* PlayerMgr::GetPlayerBySocket(int socket)
return itr != socket_hash_.end() ? itr->second : nullptr;
}
Player* PlayerMgr::CreatePlayerByCMJoin(int socket, unsigned short obj_uniid, const cs::CMJoin& msg)
Player* PlayerMgr::CreatePlayerByCMJoin(int socket, const cs::CMJoin& msg)
{
Player* hum = new Player();
hum->entity_uniid = obj_uniid;
hum->socket_handle = socket;
hum->account_id = msg.account_id();
hum->name = msg.name();
hum->health = 100;
@ -39,10 +32,10 @@ Player* PlayerMgr::CreatePlayerByCMJoin(int socket, unsigned short obj_uniid, co
hum->use_touch = msg.use_touch();
hum->avatar_url = msg.avatar_url();
hum->energy_shield = msg.energy_shield();
socket_hash_[socket] = hum;
// hum->baseskin = msg.baseskin();
// hum->basemelee = msg.basemelee();
// hum->elo_score = msg.elo_score();
// hum->gmode = msg.gmode();
socket_hash_[socket] = hum;
return hum;
}

View File

@ -18,10 +18,9 @@ class PlayerMgr : public a8::Singleton<PlayerMgr>
public:
void Init();
void UnInit();
void Update();
Player* GetPlayerBySocket(int socket);
Player* CreatePlayerByCMJoin(int socket, unsigned short obj_uniid, const cs::CMJoin& msg);
Player* CreatePlayerByCMJoin(int socket, const cs::CMJoin& msg);
private:
std::map<int, Player*> socket_hash_;

View File

@ -104,7 +104,9 @@ void Room::AddPlayer(Player* hum)
hum->attack_dir.Normalize();
hum->attack_dir.Rotate(a8::RandAngle());
}
hum->entity_uniid = AllocUniid();
hum->room = this;
hum->Initialize();
uniid_hash_[hum->entity_uniid] = hum;
moveable_hash_[hum->entity_uniid] = hum;
accountid_hash_[hum->account_id] = hum;
@ -213,11 +215,6 @@ Human* Room::FindEnemy(Human* hum)
return !enemys.empty() ? enemys[0] : nullptr;
}
void Room::AddBullet(Bullet* bullet)
{
be_added_hash_[bullet->entity_uniid] = bullet;
}
void Room::CollisionDetection(Entity* sender, int detection_flags, std::vector<Entity*>& objects)
{
assert(uniid_hash_.size() < 1000);
@ -488,6 +485,24 @@ void Room::CreateLoot(int equip_id, Vector2D pos, int count)
}
}
void Room::CreateBullet(Human* hum, MetaData::Equip* gun_meta,
Vector2D pos, Vector2D dir, float fly_distance)
{
Bullet* bullet = new Bullet();
bullet->player = hum;
bullet->room = this;
bullet->gun_meta = gun_meta;
bullet->meta = MetaMgr::Instance()->GetEquip(gun_meta->i->use_bullet());
bullet->pos = pos;
bullet->dir = dir;
bullet->born_pos = pos;
bullet->born_dir = dir;
bullet->fly_distance = fly_distance;
bullet->entity_uniid = AllocUniid();
bullet->Initialize();
be_added_hash_[bullet->entity_uniid] = bullet;
}
void Room::FetchBuilding(Human* hum)
{
for (auto& pair : uniid_hash_) {

View File

@ -31,15 +31,12 @@ public:
Player* GetPlayerByUniId(unsigned short uniid);
Entity* GetEntityByUniId(unsigned short uniid);
void AddPlayer(Player* hum);
void AddBullet(Bullet* bullet);
unsigned short AllocUniid();
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 FillSMJoinedNotify(Player* self_hum, cs::SMJoinedNotify& msg);
void ResetFrameData();
void TouchPlayerList(a8::XParams param,
std::function<void (Player*, a8::XParams&)> func);
void TouchHumanList(a8::XParams param,
@ -52,10 +49,14 @@ public:
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 ResetFrameData();
void ClearDeletedObjects();
void ProcAddedObjects();
void UpdateGas();

View File

@ -12,12 +12,10 @@
void RoomMgr::Init()
{
}
void RoomMgr::UnInit()
{
}
void RoomMgr::Update(int delta_time)
@ -46,11 +44,8 @@ void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg)
room->ShuaAndroid();
room_hash_[room->room_uuid] = room;
}
unsigned short new_uniid = room->AllocUniid();
Player* hum = PlayerMgr::Instance()->CreatePlayerByCMJoin(hdr.socket_handle, new_uniid, msg);
Player* hum = PlayerMgr::Instance()->CreatePlayerByCMJoin(hdr.socket_handle, msg);
hum->meta = hum_meta;
hum->socket_handle = hdr.socket_handle;
hum->Initialize();
room->AddPlayer(hum);
room->CreateThings();