diff --git a/server/gameserver/app.cc b/server/gameserver/app.cc index 0b322ead..9df5aae5 100644 --- a/server/gameserver/app.cc +++ b/server/gameserver/app.cc @@ -7,7 +7,6 @@ #include #include -#include #include #include @@ -34,6 +33,7 @@ #include "f8/tglog.h" #include "f8/httpclientpool.h" #include "f8/btmgr.h" +#include #include "collider.h" @@ -217,7 +217,7 @@ bool App::Init(int argc, char* argv[]) #endif PerfMonitor::Instance()->Init(); HandlerMgr::Instance()->Init(); - a8::Timer::Instance()->Init(); + f8::Timer::Instance()->Init(); f8::MsgQueue::Instance()->Init(); f8::TGLog::Instance()->Init(a8::Format(PROJ_NAME_FMT, {GAME_ID}), false, 0); f8::HttpClientPool::Instance()->Init(MAX_ALL_HTTP_NUM, MAX_SYS_HTTP_NUM, MAX_USER_HTTP_NUM); @@ -247,22 +247,26 @@ bool App::Init(int argc, char* argv[]) }); { int perf_log_time = 1000 * 30; - a8::Timer::Instance()->AddRepeatTimer(perf_log_time, - a8::XParams(), - [] (const a8::XParams& param) - { - SavePerfLog(); - }); + f8::Timer::Instance()->SetInterval + (perf_log_time, + [] (int event, const a8::Args* args) + { + if (a8::TIMER_EXEC_EVENT == event) { + SavePerfLog(); + } + }); } if (HasFlag(7)) { - a8::Timer::Instance()->AddDeadLineTimer( - 1000 * 60 * 1, - a8::XParams(), - [] (const a8::XParams& param) - { - App::Instance()->terminated = true; - } - ); + f8::Timer::Instance()->SetTimeout + ( + 1000 * 60 * 1, + [] (int event, const a8::Args* args) + { + if (a8::TIMER_EXEC_EVENT == event) { + App::Instance()->terminated = true; + } + } + ); } return true; } @@ -282,7 +286,7 @@ void App::UnInit() f8::BtMgr::Instance()->UnInit(); f8::HttpClientPool::Instance()->UnInit(); f8::MsgQueue::Instance()->UnInit(); - a8::Timer::Instance()->UnInit(); + f8::Timer::Instance()->UnInit(); HandlerMgr::Instance()->UnInit(); PerfMonitor::Instance()->UnInit(); f8::TGLog::Instance()->UnInit(); @@ -357,7 +361,7 @@ void App::QuickExecute(int delta_time) f8::MsgQueue::Instance()->Update(); DispatchMsg(); RoomMgr::Instance()->Update(delta_time); - a8::Timer::Instance()->Update(); + f8::Timer::Instance()->Update(); } void App::SlowerExecute(int delta_time) diff --git a/server/gameserver/matchmgr.cc b/server/gameserver/matchmgr.cc index c45d7a03..34c1ab2a 100644 --- a/server/gameserver/matchmgr.cc +++ b/server/gameserver/matchmgr.cc @@ -1,6 +1,6 @@ #include "precompile.h" -#include +#include #include "cs_proto.pb.h" #include "matchmgr.h" @@ -11,18 +11,15 @@ void MatchMgr::Init() { - a8::Timer::Instance()->AddRepeatTimerAndAttach + f8::Timer::Instance()->SetIntervalEx (1000, - a8::XParams() - .SetSender(this), - [] (const a8::XParams& param) + [] (int event, const a8::Args* args) { - MatchMgr::Instance()->Output(); + if (a8::TIMER_EXEC_EVENT == event) { + MatchMgr::Instance()->Output(); + } }, - &timer_attacher.timer_list_, - [] (const a8::XParams& param) - { - } + &timer_attacher ); } diff --git a/server/gameserver/matchmgr.h b/server/gameserver/matchmgr.h index 05819bb5..6e6d5e70 100644 --- a/server/gameserver/matchmgr.h +++ b/server/gameserver/matchmgr.h @@ -17,7 +17,7 @@ class MatchMgr : public a8::Singleton friend class a8::Singleton; public: - a8::TimerAttacher timer_attacher; + f8::Attacher timer_attacher; void Init(); void UnInit(); diff --git a/server/gameserver/matchpool.cc b/server/gameserver/matchpool.cc index df35bbac..20d4e4e6 100644 --- a/server/gameserver/matchpool.cc +++ b/server/gameserver/matchpool.cc @@ -1,6 +1,6 @@ #include "precompile.h" -#include +#include #include "cs_proto.pb.h" #include "matchpool.h" @@ -9,19 +9,15 @@ void MatchPool::Init() { - a8::Timer::Instance()->AddRepeatTimerAndAttach + f8::Timer::Instance()->SetIntervalEx (1000, - a8::XParams() - .SetSender(this), - [] (const a8::XParams& param) + [] (int event, const a8::Args* args) { - MatchPool::Instance()->Update(); + if (a8::TIMER_EXEC_EVENT == event) { + MatchPool::Instance()->Update(); + } }, - &timer_attacher_.timer_list_, - [] (const a8::XParams& param) - { - } - ); + &timer_attacher_); } void MatchPool::UnInit() diff --git a/server/gameserver/matchpool.h b/server/gameserver/matchpool.h index bbb224e8..a96d5a78 100644 --- a/server/gameserver/matchpool.h +++ b/server/gameserver/matchpool.h @@ -34,7 +34,7 @@ private: void Update(); private: - a8::TimerAttacher timer_attacher_; + f8::Attacher timer_attacher_; std::map team_hash_; std::map> socket_hash_; diff --git a/server/gameserver/matchteam.cc b/server/gameserver/matchteam.cc index 5fc69ea4..fcd76be2 100644 --- a/server/gameserver/matchteam.cc +++ b/server/gameserver/matchteam.cc @@ -1,6 +1,6 @@ #include "precompile.h" -#include +#include #include "matchteam.h" #include "matchmgr.h" @@ -70,17 +70,15 @@ void MatchTeam::Init(f8::MsgHdr& hdr, const cs::CMJoin& msg) { master_team_ = this; create_tick_ = a8::XGetTickCount(); - a8::Timer::Instance()->AddRepeatTimerAndAttach + f8::Timer::Instance()->SetIntervalEx (1000, - a8::XParams() - .SetSender(this), - [] (const a8::XParams& param) + [this] (int event, const a8::Args* args) { - MatchTeam* team = (MatchTeam*)param.sender.GetUserData(); - team->Update(); + if (a8::TIMER_EXEC_EVENT == event) { + Update(); + } }, - &timer_attacher.timer_list_ - ); + &timer_attacher); phase_= kMatchCombining; phase_start_tick_ = a8::XGetTickCount(); countdown_ = Config::Instance()->match_team_time; diff --git a/server/gameserver/matchteam.h b/server/gameserver/matchteam.h index 1a2537cd..b9d8b2c4 100644 --- a/server/gameserver/matchteam.h +++ b/server/gameserver/matchteam.h @@ -1,5 +1,7 @@ #pragma once +#include + #include "cs_proto.pb.h" #include "battledatacontext.h" @@ -56,7 +58,7 @@ class MatchTeam enum { HID = HID_MatchTeam }; public: - a8::TimerAttacher timer_attacher; + f8::Attacher timer_attacher; ~MatchTeam(); void Init(f8::MsgHdr& hdr, const cs::CMJoin& msg); diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index 90abf309..0f556cb2 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -3,12 +3,12 @@ #include #include -#include #include #include #include #include +#include #include "playermgr.h" #include "player.h" diff --git a/server/gameserver/room.h b/server/gameserver/room.h index 489836cc..9eba8f07 100644 --- a/server/gameserver/room.h +++ b/server/gameserver/room.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include "frameevent.h" #include "framemaker.h" @@ -61,7 +62,7 @@ public: FrameMaker frame_maker; a8::XTimer xtimer; Plane plane; - a8::TimerAttacher timer_attacher; + f8::Attacher timer_attacher; a8::Attacher xtimer_attacher_; GridService* grid_service = nullptr; MapService* map_service = nullptr; diff --git a/server/gameserver/roommgr.cc b/server/gameserver/roommgr.cc index 5f52e3d5..3f72a5b9 100644 --- a/server/gameserver/roommgr.cc +++ b/server/gameserver/roommgr.cc @@ -1,6 +1,5 @@ #include "precompile.h" -#include #include #include "roommgr.h" @@ -23,6 +22,7 @@ #include #include #include +#include const int ROOM_NUM_UP_LIMIT = 1000; const int HUM_NUM_DOWN_LIMIT = 2500; @@ -237,14 +237,14 @@ void RoomMgr::_CMReconnect(f8::MsgHdr& hdr, const cs::CMReconnect& msg) respmsg.set_errcode(errcode); respmsg.set_errmsg(errmsg); GGListener::Instance()->SendToClient(socket_handle, 0, respmsg); - a8::Timer::Instance()->AddDeadLineTimer + f8::Timer::Instance()->SetTimeout ( 1000 * 3, - a8::XParams() - .SetSender(socket_handle), - [] (const a8::XParams& param) + [socket_handle] (int event, const a8::Args* args) { - GGListener::Instance()->ForceCloseChildSocket(param.sender); + if (a8::TIMER_EXEC_EVENT == event) { + GGListener::Instance()->ForceCloseChildSocket(socket_handle); + } } ); }; @@ -393,13 +393,15 @@ Room* RoomMgr::GetRoomByIdx(int room_idx) void RoomMgr::AddOverRoom(long long room_uuid) { auto callback = - [] (const a8::XParams& param) + [room_uuid] (int event, const a8::Args* args) { - Room* room = RoomMgr::Instance()->GetRoomByUuid(param.sender); - if (room) { - RoomMgr::Instance()->room_hash_.erase(room->GetRoomUuid()); - RoomMgr::Instance()->over_room_hash_[room->GetRoomUuid()] = room; - RoomMgr::Instance()->FreeOverRoom(param.sender); + if (a8::TIMER_EXEC_EVENT == event) { + Room* room = RoomMgr::Instance()->GetRoomByUuid(room_uuid); + if (room) { + RoomMgr::Instance()->room_hash_.erase(room->GetRoomUuid()); + RoomMgr::Instance()->over_room_hash_[room->GetRoomUuid()] = room; + RoomMgr::Instance()->FreeOverRoom(room_uuid); + } } }; @@ -407,12 +409,10 @@ void RoomMgr::AddOverRoom(long long room_uuid) Room* room = GetRoomByUuid(room_uuid); if (room) { room->added_to_over_room = true; - a8::Timer::Instance()->AddRepeatTimerAndAttach + f8::Timer::Instance()->SetIntervalEx (1000 * 5, - a8::XParams() - .SetSender(room_uuid), callback, - &room->timer_attacher.timer_list_); + &room->timer_attacher); } } @@ -426,40 +426,45 @@ void RoomMgr::ReportServerState(int instance_id, const std::string& host, int po auto on_ok = [] (a8::XParams& param, a8::XObject& data) { - a8::Timer::Instance()->AddDeadLineTimerAndAttach + int instance_id = param.sender; + std::string host = param.param1.GetString(); + int port = param.param2; + f8::Timer::Instance()->SetTimeoutEx (1000, - a8::XParams() - .SetSender(param.sender) - .SetParam1(param.param1) - .SetParam2(param.param2), - [] (const a8::XParams& param) + [instance_id, host, port] (int event, const a8::Args* args) { - RoomMgr::Instance()->ReportServerState( - param.sender, - param.param1, - param.param2 - ); + if (a8::TIMER_EXEC_EVENT == event) { + RoomMgr::Instance()->ReportServerState( + instance_id, + host, + port + ); + } }, - &RoomMgr::Instance()->reportstate_timer_attacher_.timer_list_); + &RoomMgr::Instance()->reportstate_timer_attacher_); }; auto on_error = [] (a8::XParams& param, const std::string& response) { - a8::Timer::Instance()->AddDeadLineTimerAndAttach + int instance_id = param.sender; + std::string host = param.param1.GetString(); + int port = param.param2; + + f8::Timer::Instance()->SetTimeoutEx (1000, - a8::XParams() - .SetSender(param.sender) - .SetParam1(param.param1) - .SetParam2(param.param2), - [] (const a8::XParams& param) + [instance_id, host, port] + (int event, const a8::Args* args) { - RoomMgr::Instance()->ReportServerState( - param.sender, - param.param1, - param.param2 - ); + if (a8::TIMER_EXEC_EVENT == event) { + RoomMgr::Instance()->ReportServerState + ( + instance_id, + host, + port + ); + } }, - &RoomMgr::Instance()->reportstate_timer_attacher_.timer_list_); + &RoomMgr::Instance()->reportstate_timer_attacher_); }; std::string url = a8::Format("http://%s:%d/webapp/index.php?c=GS&a=report&", { @@ -511,21 +516,21 @@ void RoomMgr::InstallReportStateTimer() std::string remote_ip = master_svr_conf->At("ip")->AsXValue(); int remote_port = master_svr_conf->At("listen_port")->AsXValue(); - a8::Timer::Instance()->AddDeadLineTimerAndAttach + f8::Timer::Instance()->SetTimeoutEx (1000 + (i + 1), - a8::XParams() - .SetSender(instance_id) - .SetParam1(remote_ip) - .SetParam2(remote_port), - [] (const a8::XParams& param) + [instance_id, remote_ip, remote_port] + (int event, const a8::Args* args) { - RoomMgr::Instance()->ReportServerState( - param.sender, - param.param1, - param.param2 - ); + if (a8::TIMER_EXEC_EVENT == event) { + RoomMgr::Instance()->ReportServerState + ( + instance_id, + remote_ip, + remote_port + ); + } }, - &reportstate_timer_attacher_.timer_list_); + &reportstate_timer_attacher_); } } @@ -612,13 +617,13 @@ void RoomMgr::JoinErrorHandle(const cs::CMJoin& msg, int error_code, int socket_ GGListener::Instance()->SendToClient(socket_handle, 0, notifymsg); } { - a8::Timer::Instance()->AddDeadLineTimer + f8::Timer::Instance()->SetTimeout (1000 * 2, - a8::XParams() - .SetSender(socket_handle), - [] (const a8::XParams& param) + [socket_handle] (int event, const a8::Args* args) { - GGListener::Instance()->ForceCloseChildSocket(param.sender); + if (a8::TIMER_EXEC_EVENT == event) { + GGListener::Instance()->ForceCloseChildSocket(socket_handle); + } }); } f8::UdpLog::Instance()->Warning @@ -673,13 +678,14 @@ void RoomMgr::OnJoinRoomOk(const cs::CMJoin& msg, Player* hum) for (auto& team_member : msg.team_members()) { team_hash->insert(std::make_pair(team_member.account_id(), 0)); } - a8::Timer::Instance()->AddDeadLineTimer + std::string team_uuid = msg.team_uuid(); + f8::Timer::Instance()->SetTimeout (1000 * 60, - a8::XParams() - .SetSender(msg.team_uuid()), - [] (const a8::XParams& params) + [team_uuid] (int event, const a8::Args* args) { - RoomMgr::Instance()->TeamRoomTimeOut(params.sender); + if (a8::TIMER_EXEC_EVENT == event) { + RoomMgr::Instance()->TeamRoomTimeOut(team_uuid); + } } ); } else { diff --git a/server/gameserver/roommgr.h b/server/gameserver/roommgr.h index 1ab37202..6a1f7a6a 100644 --- a/server/gameserver/roommgr.h +++ b/server/gameserver/roommgr.h @@ -4,6 +4,7 @@ #include #include +#include #include "battledatacontext.h" namespace cs @@ -120,7 +121,7 @@ class RoomMgr : public a8::Singleton std::map room_hash_; std::map room_idx_hash_; std::map over_room_hash_; - a8::TimerAttacher reportstate_timer_attacher_; + f8::Attacher reportstate_timer_attacher_; std::map gm_hash_; std::map> team_room_hash_; }; diff --git a/third_party/a8 b/third_party/a8 index 3fca06a9..6c4e6fd4 160000 --- a/third_party/a8 +++ b/third_party/a8 @@ -1 +1 @@ -Subproject commit 3fca06a9bc76debe03458c1c6a3482b69f815549 +Subproject commit 6c4e6fd4e0f4b658f49f3b01df6f6bf6ae3af9f7 diff --git a/third_party/f8 b/third_party/f8 index db10c37c..6ca822b2 160000 --- a/third_party/f8 +++ b/third_party/f8 @@ -1 +1 @@ -Subproject commit db10c37c68a30f1e9d6cbddafa8721e4bccb9676 +Subproject commit 6ca822b2c7f6c50f6d6dbb2aae22892846740e0d