RoomMgr 重构

This commit is contained in:
aozhiwei 2019-06-20 10:05:57 +08:00
parent 5d72dbdae6
commit 70c630575d
5 changed files with 32 additions and 108 deletions

View File

@ -73,7 +73,7 @@ private:
3: battleReport环境 3: battleReport环境
4: 4:
5: 5:
6: over room 6:
7: 7:
*/ */
std::set<int> flags; std::set<int> flags;

View File

@ -393,37 +393,6 @@ void Room::CreateThings()
} }
} }
void Room::FillSMMapInfo(cs::SMMapInfo& map_info)
{
for (auto& pair :uniid_hash_) {
switch (pair.second->entity_type) {
case ET_Obstacle:
{
Obstacle* entity = (Obstacle*)pair.second;
if (!entity->building) {
cs::MFMapObject* p = map_info.add_objects();
p->set_object_id(entity->meta->i->thing_id());
entity->pos.ToPB(p->mutable_pos());
}
}
break;
case ET_Building:
{
Building* entity = (Building*)pair.second;
cs::MFMapObject* p = map_info.add_objects();
p->set_object_id(entity->building_id);
entity->pos.ToPB(p->mutable_pos());
}
break;
default:
{
}
break;
}
}
}
void Room::DropItem(Vector2D pos, int item_id, int item_count, int item_lv) void Room::DropItem(Vector2D pos, int item_id, int item_count, int item_lv)
{ {
#if 0 #if 0

View File

@ -67,7 +67,6 @@ public:
void FetchBuilding(Human* hum); 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);

View File

@ -63,51 +63,13 @@ void RoomMgr::Update(int delta_time)
void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg) void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg)
{ {
MetaData::Player* hum_meta = MetaMgr::Instance()->GetPlayer(40001); MetaData::Player* hum_meta = MetaMgr::Instance()->GetPlayer(40001);
assert(hum_meta);
if (!hum_meta) { if (!hum_meta) {
abort(); abort();
} }
if (App::Instance()->is_test_mode) {
for (int i = 0; i < App::Instance()->test_param; ++i) {
Room* room = GetJoinableRoom(msg.account_id()); Room* room = GetJoinableRoom(msg.account_id());
if (!room) { if (!room) {
room = new Room(); room = new Room();
room->room_uuid = App::Instance()->NewUuid(); room->room_uuid = App::Instance()->NewUuid();
assert(!GetRoomByUuid(room->room_uuid));
if (GetRoomByUuid(room->room_uuid)) {
abort();
}
room->map_meta = MetaMgr::Instance()->GetMap(1001);
room->Init();
inactive_room_hash_[room->room_uuid] = room;
room_hash_[room->room_uuid] = room;
}
if (i == 0) {
{
Player* hum = PlayerMgr::Instance()->CreatePlayerByCMJoin(hdr.ip_saddr, hdr.socket_handle, msg);
hum->meta = hum_meta;
room->AddPlayer(hum);
hum->ProcPrepareItems(msg.prepare_items());
cs::SMJoinedNotify notifymsg;
notifymsg.set_error_code(0);
room->FillSMJoinedNotify(hum, notifymsg);
GGListener::Instance()->SendToClient(hdr.socket_handle, hdr.seqid, notifymsg);
}
{
cs::SMMapInfo notifymsg;
notifymsg.set_map_id(room->map_meta->i->map_id());
room->FillSMMapInfo(notifymsg);
GGListener::Instance()->SendToClient(hdr.socket_handle, hdr.seqid, notifymsg);
}
}
}
} else {
Room* room = GetJoinableRoom(msg.account_id());
if (!room) {
room = new Room();
room->room_uuid = App::Instance()->NewUuid();
assert(!GetRoomByUuid(room->room_uuid));
if (GetRoomByUuid(room->room_uuid)) { if (GetRoomByUuid(room->room_uuid)) {
abort(); abort();
} }
@ -130,11 +92,9 @@ void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg)
{ {
cs::SMMapInfo notifymsg; cs::SMMapInfo notifymsg;
notifymsg.set_map_id(room->map_meta->i->map_id()); notifymsg.set_map_id(room->map_meta->i->map_id());
room->FillSMMapInfo(notifymsg);
GGListener::Instance()->SendToClient(hdr.socket_handle, hdr.seqid, notifymsg); GGListener::Instance()->SendToClient(hdr.socket_handle, hdr.seqid, notifymsg);
} }
} }
}
int RoomMgr::RoomNum() int RoomMgr::RoomNum()
{ {
@ -250,7 +210,6 @@ void RoomMgr::ReportServerState(int instance_id, const std::string& host, int po
void RoomMgr::FreeOverRoom(long long room_uuid) void RoomMgr::FreeOverRoom(long long room_uuid)
{ {
if (App::Instance()->HasFlag(6)) {
auto itr = over_room_hash_.find(room_uuid); auto itr = over_room_hash_.find(room_uuid);
if (itr != over_room_hash_.end()) { if (itr != over_room_hash_.end()) {
itr->second->UnInit(); itr->second->UnInit();
@ -258,4 +217,3 @@ void RoomMgr::FreeOverRoom(long long room_uuid)
over_room_hash_.erase(itr); over_room_hash_.erase(itr);
} }
} }
}

View File

@ -684,7 +684,6 @@ message SMJoinedNotify
optional int32 team_mode = 1; // 0: 1: optional int32 team_mode = 1; // 0: 1:
optional int32 player_id = 2; //id() optional int32 player_id = 2; //id()
optional bool started = 3; // optional bool started = 3; //
//repeated MFPlayerInfo player_infos = 4; //
optional int32 map_type = 5; // optional int32 map_type = 5; //
optional bool elo_start = 6; // optional bool elo_start = 6; //
@ -726,7 +725,6 @@ message SMUpdate
repeated MFEmote emotes = 23; // repeated MFEmote emotes = 23; //
optional MFAirDrop airdrop = 26; // optional MFAirDrop airdrop = 26; //
optional MFPlane plane = 27; // optional MFPlane plane = 27; //
optional int32 ack = 24; //req id
} }
// //