This commit is contained in:
aozhiwei 2022-12-17 15:25:05 +08:00
parent 83178c9b9e
commit c144c7a803
13 changed files with 123 additions and 118 deletions

View File

@ -7,7 +7,6 @@
#include <condition_variable>
#include <regex>
#include <a8/timer.h>
#include <a8/uuid.h>
#include <a8/collision.h>
@ -34,6 +33,7 @@
#include "f8/tglog.h"
#include "f8/httpclientpool.h"
#include "f8/btmgr.h"
#include <f8/timer.h>
#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)

View File

@ -1,6 +1,6 @@
#include "precompile.h"
#include <a8/timer.h>
#include <f8/timer.h>
#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
);
}

View File

@ -17,7 +17,7 @@ class MatchMgr : public a8::Singleton<MatchMgr>
friend class a8::Singleton<MatchMgr>;
public:
a8::TimerAttacher timer_attacher;
f8::Attacher timer_attacher;
void Init();
void UnInit();

View File

@ -1,6 +1,6 @@
#include "precompile.h"
#include <a8/timer.h>
#include <f8/timer.h>
#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()

View File

@ -34,7 +34,7 @@ private:
void Update();
private:
a8::TimerAttacher timer_attacher_;
f8::Attacher timer_attacher_;
std::map<std::string, MatchTeamNew*> team_hash_;
std::map<int, std::tuple<std::string, MatchTeamNew*>> socket_hash_;

View File

@ -1,6 +1,6 @@
#include "precompile.h"
#include <a8/timer.h>
#include <f8/timer.h>
#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;

View File

@ -1,5 +1,7 @@
#pragma once
#include <f8/timer.h>
#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);

View File

@ -3,12 +3,12 @@
#include <random>
#include <a8/mutable_xobject.h>
#include <a8/timer.h>
#include <a8/collision.h>
#include <a8/vec2.h>
#include <f8/udplog.h>
#include <f8/utils.h>
#include <f8/timer.h>
#include "playermgr.h"
#include "player.h"

View File

@ -1,6 +1,7 @@
#pragma once
#include <a8/xtimer.h>
#include <f8/timer.h>
#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;

View File

@ -1,6 +1,5 @@
#include "precompile.h"
#include <a8/timer.h>
#include <a8/mutable_xobject.h>
#include "roommgr.h"
@ -23,6 +22,7 @@
#include <f8/httpclientpool.h>
#include <f8/utils.h>
#include <f8/udplog.h>
#include <f8/timer.h>
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 {

View File

@ -4,6 +4,7 @@
#include <a8/timer_attacher.h>
#include <f8/protoutils.h>
#include <f8/timer.h>
#include "battledatacontext.h"
namespace cs
@ -120,7 +121,7 @@ class RoomMgr : public a8::Singleton<RoomMgr>
std::map<long long, Room*> room_hash_;
std::map<int, Room*> room_idx_hash_;
std::map<long long, Room*> over_room_hash_;
a8::TimerAttacher reportstate_timer_attacher_;
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_;
};

2
third_party/a8 vendored

@ -1 +1 @@
Subproject commit 3fca06a9bc76debe03458c1c6a3482b69f815549
Subproject commit 6c4e6fd4e0f4b658f49f3b01df6f6bf6ae3af9f7

2
third_party/f8 vendored

@ -1 +1 @@
Subproject commit db10c37c68a30f1e9d6cbddafa8721e4bccb9676
Subproject commit 6ca822b2c7f6c50f6d6dbb2aae22892846740e0d