This commit is contained in:
aozhiwei 2023-11-04 10:59:27 +08:00
parent 08e64375a8
commit 0fef2ada52
9 changed files with 95 additions and 98 deletions

View File

@ -154,9 +154,9 @@ bool App::Init(int argc, char* argv[])
debug_mode
});
loop_mutex_ = new std::mutex();
loop_cond_ = new std::condition_variable();
msg_mutex_ = new std::mutex();
loop_mutex_ = std::make_shared<std::mutex>();
loop_cond_ = std::make_shared<std::condition_variable>();
msg_mutex_ = std::make_shared<std::mutex>();
srand(time(nullptr));
InitLog();
@ -252,9 +252,9 @@ void App::UnInit()
UnInitLog();
FreeSocketMsgQueue();
A8_SAFE_DELETE(msg_mutex_);
A8_SAFE_DELETE(loop_cond_);
A8_SAFE_DELETE(loop_mutex_);
msg_mutex_ = nullptr;
loop_cond_ = nullptr;
loop_mutex_ = nullptr;
}
int App::Run()

View File

@ -88,10 +88,10 @@ private:
a8::uuid::SnowFlake uuid_;
long long last_run_tick_ = 0;
std::mutex *loop_mutex_ = nullptr;
std::condition_variable *loop_cond_ = nullptr;
std::shared_ptr<std::mutex> loop_mutex_;
std::shared_ptr<std::condition_variable> loop_cond_;
std::mutex *msg_mutex_ = nullptr;
std::shared_ptr<std::mutex> msg_mutex_;
MsgNode* top_node_ = nullptr;
MsgNode* bot_node_ = nullptr;
MsgNode* work_node_ = nullptr;

View File

@ -93,36 +93,34 @@ void FrameMaker::Debug_OutObject(Human* hum)
cs::SMUpdate* FrameMaker::MakeUpdateMsg(Human* hum)
{
FrameData* framedata = &hum->GetFrameData();
cs::SMUpdate* msg = new cs::SMUpdate;
auto msg = std::make_shared<cs::SMUpdate>();
Room* room = hum->room;
PreProcess(msg, room, hum, framedata);
SerializeLootObjects(msg, room, hum, framedata);
SerializeNewObjects(msg, room, hum, framedata);
SerializeImageObjects(msg, room, hum, framedata);
SerializePartObjects(msg, room, hum, framedata);
SerializeDelObjects(msg, room, hum, framedata);
SerializeOutObjects(msg, room, hum, framedata);
SerializeShots(msg, room, hum, framedata);
SerializeEmotes(msg, room, hum, framedata);
SerializeBullets(msg, room, hum, framedata);
SerializePlaySkills(msg, room, hum, framedata);
SerializeExplosions(msg, room, hum, framedata);
SerializeChgedBuffs(msg, room, hum, framedata);
SerializeChgedEffects(msg, room, hum, framedata);
SerializeChgedBulletNums(msg, room, hum, framedata);
SerializeChgedHps(msg, room, hum, framedata);
SerializeChgedSkillCds(msg, room, hum, framedata);
SerializeChgedSkillCurrTimes(msg, room, hum, framedata);
SerializeChgedItems(msg, room, hum, framedata);
SerializeChgedWeaponAmmo(msg, room, hum, framedata);
SerializeDeadAliveObjs(msg, room, hum, framedata);
SerializeChgedCars(msg, room, hum, framedata);
SerializeChgedProps(msg, room, hum, framedata);
SerializeDelBullets(msg, room, hum, framedata);
PostProcess(msg, room, hum, framedata);
return msg;
PreProcess(msg.get(), room, hum, framedata);
SerializeLootObjects(msg.get(), room, hum, framedata);
SerializeNewObjects(msg.get(), room, hum, framedata);
SerializeImageObjects(msg.get(), room, hum, framedata);
SerializePartObjects(msg.get(), room, hum, framedata);
SerializeDelObjects(msg.get(), room, hum, framedata);
SerializeOutObjects(msg.get(), room, hum, framedata);
SerializeShots(msg.get(), room, hum, framedata);
SerializeEmotes(msg.get(), room, hum, framedata);
SerializeBullets(msg.get(), room, hum, framedata);
SerializePlaySkills(msg.get(), room, hum, framedata);
SerializeExplosions(msg.get(), room, hum, framedata);
SerializeChgedBuffs(msg.get(), room, hum, framedata);
SerializeChgedEffects(msg.get(), room, hum, framedata);
SerializeChgedBulletNums(msg.get(), room, hum, framedata);
SerializeChgedHps(msg.get(), room, hum, framedata);
SerializeChgedSkillCds(msg.get(), room, hum, framedata);
SerializeChgedSkillCurrTimes(msg.get(), room, hum, framedata);
SerializeChgedItems(msg.get(), room, hum, framedata);
SerializeChgedWeaponAmmo(msg.get(), room, hum, framedata);
SerializeDeadAliveObjs(msg.get(), room, hum, framedata);
SerializeChgedCars(msg.get(), room, hum, framedata);
SerializeChgedProps(msg.get(), room, hum, framedata);
SerializeDelBullets(msg.get(), room, hum, framedata);
PostProcess(msg.get(), room, hum, framedata);
}
void FrameMaker::PreProcess(cs::SMUpdate* msg, Room* room, Human* hum, FrameData* framedata)

View File

@ -1460,7 +1460,7 @@ void Human::SendBattleReport()
""
});
}
Room* room = RoomMgr::Instance()->GetRoomByUuid(room_uuid);
auto room = RoomMgr::Instance()->GetRoomByUuid(room_uuid);
if (!room) {
return;
}

View File

@ -1670,7 +1670,7 @@ void Human::SendBattleSettlement()
[room_uuid, tmp_account_id, data]
(bool ok, a8::XObject* rsp_obj, f8::HttpContext* ctx)
{
Room* room = RoomMgr::Instance()->GetRoomByUuid(room_uuid);
auto room = RoomMgr::Instance()->GetRoomByUuid(room_uuid);
if (!room) {
return;
}

View File

@ -1332,7 +1332,7 @@ void Player::_CMRevive(f8::MsgHdr& hdr, const cs::CMRevive& msg)
[room_uuid, account_id = account_id, target_uniid]
(bool ok, a8::XObject* rsp_obj, f8::HttpContext* ctx)
{
Room* room = RoomMgr::Instance()->GetRoomByUuid(room_uuid);
auto room = RoomMgr::Instance()->GetRoomByUuid(room_uuid);
if (!room) {
return;
}

View File

@ -85,19 +85,19 @@ void RoomMgr::UnInit()
{
for (auto& pair : room_hash_) {
pair.second->UnInit();
delete pair.second;
}
for (auto& pair : over_room_hash_) {
pair.second->UnInit();
delete pair.second;
}
room_hash_.clear();
over_room_hash_.clear();
}
void RoomMgr::Update(int delta_time)
{
long long real_alive_count = 0;
for (auto& pair : room_hash_) {
Room* room = pair.second;
auto& room = pair.second;
room->Update(delta_time);
real_alive_count += room->RealAliveCount();
}
@ -160,7 +160,7 @@ void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg)
time_t register_time = f8::ExtractRegisterTimeFromSessionId(msg.session_id());
int proto_version = msg.proto_version();
int channel = f8::ExtractChannelIdFromAccountId(msg.account_id());
Room* room = RoomMgr::Instance()->GetJoinableRoom
std::shared_ptr<Room> room = RoomMgr::Instance()->GetJoinableRoom
(
msg,
self_room_type,
@ -194,7 +194,7 @@ void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg)
if (!hum->meta) {
hum->meta = mt::Param::s().human_meta;
}
hum->room = room;
hum->room = room.get();
hum->SetBattleContext(results.at(0));
hum->GetBattleContext()->Init(hum);
{
@ -235,7 +235,7 @@ void RoomMgr::_CMReconnect(f8::MsgHdr& hdr, const cs::CMReconnect& msg)
);
};
Room* room = GetRoomByUuid(a8::XValue(msg.room_uuid()));
auto room = GetRoomByUuid(a8::XValue(msg.room_uuid()));
if (!room) {
send_reconnect_failed(hdr.socket_handle, 1,
TEXT("battle_server_reconnect_failreason_room_destoryed", "房间已销毁"));
@ -278,20 +278,20 @@ int RoomMgr::OverRoomNum()
return over_room_hash_.size();
}
Room* RoomMgr::GetJoinableRoom(const cs::CMJoin& msg,
const RoomType_e self_room_type,
int game_times,
int creator_register_time,
int proto_version,
int channel
)
std::shared_ptr<Room> RoomMgr::GetJoinableRoom(const cs::CMJoin& msg,
const RoomType_e self_room_type,
int game_times,
int creator_register_time,
int proto_version,
int channel
)
{
std::vector<std::vector<Room*>> group_rooms;
std::vector<std::vector<std::shared_ptr<Room>>> group_rooms;
for (int i = 0; i < RoomType_Max; ++i) {
group_rooms.push_back(std::vector<Room*>());
group_rooms.push_back(std::vector<std::shared_ptr<Room>>());
}
for (auto& pair : inactive_room_hash_) {
Room* room = pair.second;
auto& room = pair.second;
if (!room->GetCustomBattle() &&
room->CanJoin(msg.account_id(),
self_room_type,
@ -338,10 +338,10 @@ Room* RoomMgr::GetJoinableRoom(const cs::CMJoin& msg,
nullptr);
}
Room* RoomMgr::GetJoinableRoom(MatchTeam* team)
std::shared_ptr<Room> RoomMgr::GetJoinableRoom(MatchTeam* team)
{
for (auto& pair : inactive_room_hash_) {
Room* room = pair.second;
auto room = pair.second;
if (room->CanJoin(team)) {
return room;
}
@ -362,13 +362,13 @@ Room* RoomMgr::GetJoinableRoom(MatchTeam* team)
nullptr);
}
Room* RoomMgr::GetRoomByUuid(long long room_uuid)
std::shared_ptr<Room> RoomMgr::GetRoomByUuid(long long room_uuid)
{
auto itr = room_hash_.find(room_uuid);
return itr != room_hash_.end() ? itr->second : nullptr;
}
Room* RoomMgr::GetRoomByIdx(int room_idx)
std::shared_ptr<Room> RoomMgr::GetRoomByIdx(int room_idx)
{
auto itr = room_idx_hash_.find(room_idx);
return itr != room_idx_hash_.end() ? itr->second : nullptr;
@ -380,7 +380,7 @@ void RoomMgr::AddOverRoom(long long room_uuid)
[room_uuid] (int event, const a8::Args* args)
{
if (a8::TIMER_EXEC_EVENT == event) {
Room* room = RoomMgr::Instance()->GetRoomByUuid(room_uuid);
auto room = RoomMgr::Instance()->GetRoomByUuid(room_uuid);
if (room) {
RoomMgr::Instance()->room_hash_.erase(room->GetRoomUuid());
RoomMgr::Instance()->over_room_hash_[room->GetRoomUuid()] = room;
@ -390,7 +390,7 @@ void RoomMgr::AddOverRoom(long long room_uuid)
};
inactive_room_hash_.erase(room_uuid);
Room* room = GetRoomByUuid(room_uuid);
auto room = GetRoomByUuid(room_uuid);
if (room) {
room->added_to_over_room = true;
f8::Timer::Instance()->SetIntervalEx
@ -474,7 +474,6 @@ void RoomMgr::FreeOverRoom(long long room_uuid)
--PerfMonitor::Instance()->room_num[itr->second->GetRoomType()];
itr->second->UnInit();
room_idx_hash_.erase(itr->second->GetRoomIdx());
delete itr->second;
over_room_hash_.erase(itr);
}
}
@ -528,14 +527,14 @@ int RoomMgr::AllocRoomIdx()
return current_room_idx_;
}
Room* RoomMgr::CreateRoom(const cs::CMJoin& msg,
RoomType_e room_type,
int game_times,
int creator_register_time,
int creator_proto_version,
int creator_channel,
int map_id,
std::shared_ptr<CustomBattle> custom_battle)
std::shared_ptr<Room> RoomMgr::CreateRoom(const cs::CMJoin& msg,
RoomType_e room_type,
int game_times,
int creator_register_time,
int creator_proto_version,
int creator_channel,
int map_id,
std::shared_ptr<CustomBattle> custom_battle)
{
int room_idx = AllocRoomIdx();
if (room_idx < 1) {
@ -563,8 +562,8 @@ Room* RoomMgr::CreateRoom(const cs::CMJoin& msg,
A8_ABORT();
}
}
Room* room = new Room();
MapMgr::Instance()->AttachRoom(room, init_info);
auto room = std::make_shared<Room>();
MapMgr::Instance()->AttachRoom(room.get(), init_info);
room->InitData(init_info);
room->Init();
inactive_room_hash_[room->GetRoomUuid()] = room;
@ -619,7 +618,7 @@ bool RoomMgr::IsGM(const std::string& account_id)
void RoomMgr::JoinTeam(MatchTeam* team)
{
Room* room = GetJoinableRoom(team);
auto room = GetJoinableRoom(team);
if (!room) {
return;
}
@ -959,7 +958,7 @@ void RoomMgr::_CMJoinCustomBattle(f8::MsgHdr& hdr, const cs::CMJoin& msg)
time_t register_time = f8::ExtractRegisterTimeFromSessionId(msg.session_id());
int proto_version = msg.proto_version();
int channel = f8::ExtractChannelIdFromAccountId(msg.account_id());
Room* room = RoomMgr::Instance()->CreateRoom
auto room = RoomMgr::Instance()->CreateRoom
(*join_msg,
self_room_type,
game_times,
@ -968,7 +967,7 @@ void RoomMgr::_CMJoinCustomBattle(f8::MsgHdr& hdr, const cs::CMJoin& msg)
channel,
msg.mapid(),
p);
p->SetRoom(room);
p->SetRoom(room.get());
}
Player* hum = p->GetRoom()->NewPlayer();
hum->room = p->GetRoom();

View File

@ -78,7 +78,7 @@ class RoomMgr : public a8::Singleton<RoomMgr>
void ActiveRoom(long long room_uuid);
int RoomNum();
int OverRoomNum();
Room* GetRoomByUuid(long long uuid);
std::shared_ptr<Room> GetRoomByUuid(long long uuid);
void AddOverRoom(long long room_uuid);
bool IsGM(const std::string& account_id);
void JoinTeam(MatchTeam* team);
@ -91,27 +91,27 @@ class RoomMgr : public a8::Singleton<RoomMgr>
private:
void InstallReportStateTimer();
Room* GetRoomByIdx(int room_idx);
Room* GetJoinableRoom(const cs::CMJoin& msg,
const RoomType_e self_room_type,
int game_times,
int creator_register_time,
int proto_version,
int channel);
Room* GetJoinableRoom(MatchTeam* team);
std::shared_ptr<Room> GetRoomByIdx(int room_idx);
std::shared_ptr<Room> GetJoinableRoom(const cs::CMJoin& msg,
const RoomType_e self_room_type,
int game_times,
int creator_register_time,
int proto_version,
int channel);
std::shared_ptr<Room> GetJoinableRoom(MatchTeam* team);
void ReportServerState(int instance_id, const std::string& host, int port);
void FreeOverRoom(long long room_uuid);
bool IsLimitJoin();
int AllocRoomIdx();
Room* CreateRoom(const cs::CMJoin& msg,
RoomType_e room_type,
int game_times,
int creator_register_time,
int creator_proto_version,
int creator_channel,
int map_id,
std::shared_ptr<CustomBattle> custom_battle);
std::shared_ptr<Room> CreateRoom(const cs::CMJoin& msg,
RoomType_e room_type,
int game_times,
int creator_register_time,
int creator_proto_version,
int creator_channel,
int map_id,
std::shared_ptr<CustomBattle> custom_battle);
void JoinErrorHandle(const cs::CMJoin& msg, int error_code, int socket_handle);
std::string GenTeamHashData(const std::string& team_uuid, std::map<std::string, long long>* team_hash);
void OnJoinRoomOk(const cs::CMJoin& msg, Player* hum);
@ -127,10 +127,10 @@ class RoomMgr : public a8::Singleton<RoomMgr>
int current_room_idx_ = 0;
int match_mode_ = 0;
std::map<long long, Room*> inactive_room_hash_;
std::map<long long, Room*> room_hash_;
std::map<int, Room*> room_idx_hash_;
std::map<long long, Room*> over_room_hash_;
std::map<long long, std::shared_ptr<Room>> inactive_room_hash_;
std::map<long long, std::shared_ptr<Room>> room_hash_;
std::map<int, std::shared_ptr<Room>> room_idx_hash_;
std::map<long long, std::shared_ptr<Room>> over_room_hash_;
f8::Attacher reportstate_timer_attacher_;
std::map<std::string, int> gm_hash_;
std::map<std::string, std::map<std::string, long long>> team_room_hash_;

View File

@ -252,7 +252,7 @@ void Team::SendTeamBattleReport(Human* sender)
[room_uuid, team_id]
(bool ok, a8::XObject* rsp_obj, f8::HttpContext* ctx)
{
Room* room = RoomMgr::Instance()->GetRoomByUuid(room_uuid);
auto room = RoomMgr::Instance()->GetRoomByUuid(room_uuid);
if (room) {
Team* team = room->GetTeam(team_id);
if (team) {