完成room重构
This commit is contained in:
parent
b814b2af96
commit
8384d56771
@ -113,7 +113,6 @@ void Human::Shot(Vector2D& target_dir)
|
|||||||
if (!curr_weapon->meta) {
|
if (!curr_weapon->meta) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
cs::MFShot* shot = room->frame_data.shots.Add();
|
cs::MFShot* shot = room->frame_data.shots.Add();
|
||||||
shot->set_player_id(entity_uniid);
|
shot->set_player_id(entity_uniid);
|
||||||
@ -130,20 +129,7 @@ void Human::Shot(Vector2D& target_dir)
|
|||||||
bullet->set_bulletskin(10001);
|
bullet->set_bulletskin(10001);
|
||||||
bullet->set_gun_id(curr_weapon->meta->i->id());
|
bullet->set_gun_id(curr_weapon->meta->i->id());
|
||||||
}
|
}
|
||||||
{
|
room->CreateBullet(this, curr_weapon->meta, pos, target_dir, 0);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Human::RecalcSelfCollider()
|
void Human::RecalcSelfCollider()
|
||||||
|
@ -300,21 +300,7 @@ void Player::Shot()
|
|||||||
bullet->set_gun_id(curr_weapon->meta->i->id());
|
bullet->set_gun_id(curr_weapon->meta->i->id());
|
||||||
bullet->set_fly_distance(fly_distance);
|
bullet->set_fly_distance(fly_distance);
|
||||||
}
|
}
|
||||||
{
|
room->CreateBullet(this, curr_weapon->meta, bullet_born_pos, attack_dir, 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
--curr_weapon->ammo;
|
--curr_weapon->ammo;
|
||||||
int slot_id = curr_weapon->meta->i->_inventory_slot();
|
int slot_id = curr_weapon->meta->i->_inventory_slot();
|
||||||
|
@ -6,17 +6,10 @@
|
|||||||
|
|
||||||
void PlayerMgr::Init()
|
void PlayerMgr::Init()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerMgr::UnInit()
|
void PlayerMgr::UnInit()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void PlayerMgr::Update()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Player* PlayerMgr::GetPlayerBySocket(int socket)
|
Player* PlayerMgr::GetPlayerBySocket(int socket)
|
||||||
@ -25,10 +18,10 @@ Player* PlayerMgr::GetPlayerBySocket(int socket)
|
|||||||
return itr != socket_hash_.end() ? itr->second : nullptr;
|
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();
|
Player* hum = new Player();
|
||||||
hum->entity_uniid = obj_uniid;
|
hum->socket_handle = socket;
|
||||||
hum->account_id = msg.account_id();
|
hum->account_id = msg.account_id();
|
||||||
hum->name = msg.name();
|
hum->name = msg.name();
|
||||||
hum->health = 100;
|
hum->health = 100;
|
||||||
@ -39,10 +32,10 @@ Player* PlayerMgr::CreatePlayerByCMJoin(int socket, unsigned short obj_uniid, co
|
|||||||
hum->use_touch = msg.use_touch();
|
hum->use_touch = msg.use_touch();
|
||||||
hum->avatar_url = msg.avatar_url();
|
hum->avatar_url = msg.avatar_url();
|
||||||
hum->energy_shield = msg.energy_shield();
|
hum->energy_shield = msg.energy_shield();
|
||||||
socket_hash_[socket] = hum;
|
|
||||||
// hum->baseskin = msg.baseskin();
|
// hum->baseskin = msg.baseskin();
|
||||||
// hum->basemelee = msg.basemelee();
|
// hum->basemelee = msg.basemelee();
|
||||||
// hum->elo_score = msg.elo_score();
|
// hum->elo_score = msg.elo_score();
|
||||||
// hum->gmode = msg.gmode();
|
// hum->gmode = msg.gmode();
|
||||||
|
socket_hash_[socket] = hum;
|
||||||
return hum;
|
return hum;
|
||||||
}
|
}
|
||||||
|
@ -18,10 +18,9 @@ class PlayerMgr : public a8::Singleton<PlayerMgr>
|
|||||||
public:
|
public:
|
||||||
void Init();
|
void Init();
|
||||||
void UnInit();
|
void UnInit();
|
||||||
void Update();
|
|
||||||
|
|
||||||
Player* GetPlayerBySocket(int socket);
|
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:
|
private:
|
||||||
std::map<int, Player*> socket_hash_;
|
std::map<int, Player*> socket_hash_;
|
||||||
|
@ -104,7 +104,9 @@ void Room::AddPlayer(Player* hum)
|
|||||||
hum->attack_dir.Normalize();
|
hum->attack_dir.Normalize();
|
||||||
hum->attack_dir.Rotate(a8::RandAngle());
|
hum->attack_dir.Rotate(a8::RandAngle());
|
||||||
}
|
}
|
||||||
|
hum->entity_uniid = AllocUniid();
|
||||||
hum->room = this;
|
hum->room = this;
|
||||||
|
hum->Initialize();
|
||||||
uniid_hash_[hum->entity_uniid] = hum;
|
uniid_hash_[hum->entity_uniid] = hum;
|
||||||
moveable_hash_[hum->entity_uniid] = hum;
|
moveable_hash_[hum->entity_uniid] = hum;
|
||||||
accountid_hash_[hum->account_id] = hum;
|
accountid_hash_[hum->account_id] = hum;
|
||||||
@ -213,11 +215,6 @@ Human* Room::FindEnemy(Human* hum)
|
|||||||
return !enemys.empty() ? enemys[0] : nullptr;
|
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)
|
void Room::CollisionDetection(Entity* sender, int detection_flags, std::vector<Entity*>& objects)
|
||||||
{
|
{
|
||||||
assert(uniid_hash_.size() < 1000);
|
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)
|
void Room::FetchBuilding(Human* hum)
|
||||||
{
|
{
|
||||||
for (auto& pair : uniid_hash_) {
|
for (auto& pair : uniid_hash_) {
|
||||||
|
@ -31,15 +31,12 @@ public:
|
|||||||
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 AddBullet(Bullet* bullet);
|
|
||||||
unsigned short AllocUniid();
|
|
||||||
void ShuaAndroid();
|
void ShuaAndroid();
|
||||||
bool RandomPos(Human* hum, float distance, Vector2D& out_pos);
|
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 FillSMJoinedNotify(Player* self_hum, cs::SMJoinedNotify& msg);
|
void FillSMJoinedNotify(Player* self_hum, cs::SMJoinedNotify& msg);
|
||||||
void ResetFrameData();
|
|
||||||
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,
|
||||||
@ -52,10 +49,14 @@ public:
|
|||||||
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,
|
||||||
|
Vector2D pos, Vector2D dir, float fly_distance);
|
||||||
void FetchBuilding(Human* hum);
|
void FetchBuilding(Human* hum);
|
||||||
void OnHumanDie(Human* hum);
|
void OnHumanDie(Human* hum);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
unsigned short AllocUniid();
|
||||||
|
void ResetFrameData();
|
||||||
void ClearDeletedObjects();
|
void ClearDeletedObjects();
|
||||||
void ProcAddedObjects();
|
void ProcAddedObjects();
|
||||||
void UpdateGas();
|
void UpdateGas();
|
||||||
|
@ -12,12 +12,10 @@
|
|||||||
|
|
||||||
void RoomMgr::Init()
|
void RoomMgr::Init()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RoomMgr::UnInit()
|
void RoomMgr::UnInit()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RoomMgr::Update(int delta_time)
|
void RoomMgr::Update(int delta_time)
|
||||||
@ -46,11 +44,8 @@ void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg)
|
|||||||
room->ShuaAndroid();
|
room->ShuaAndroid();
|
||||||
room_hash_[room->room_uuid] = room;
|
room_hash_[room->room_uuid] = room;
|
||||||
}
|
}
|
||||||
unsigned short new_uniid = room->AllocUniid();
|
Player* hum = PlayerMgr::Instance()->CreatePlayerByCMJoin(hdr.socket_handle, msg);
|
||||||
Player* hum = PlayerMgr::Instance()->CreatePlayerByCMJoin(hdr.socket_handle, new_uniid, msg);
|
|
||||||
hum->meta = hum_meta;
|
hum->meta = hum_meta;
|
||||||
hum->socket_handle = hdr.socket_handle;
|
|
||||||
hum->Initialize();
|
|
||||||
room->AddPlayer(hum);
|
room->AddPlayer(hum);
|
||||||
room->CreateThings();
|
room->CreateThings();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user