2023-11-11 13:39:55 +00:00

78 lines
1.8 KiB
C++

#pragma once
#include <a8/singleton.h>
#include <f8/app.h>
namespace a8
{
struct UdpPacket;
}
struct MsgNode;
struct UdpMsgNode;
class App : public a8::Singleton<App>, public f8::UserApp
{
private:
App() {};
friend class a8::Singleton<App>;
public:
virtual const std::string GetPkgName() override;
virtual void Init() override;
virtual void UnInit() override;
virtual void Update() override;
virtual bool HasTask() override;
void AddSocketMsg(SocketFrom_e sockfrom,
int sockhandle,
long ip_saddr,
unsigned short msgid,
unsigned int seqid,
const char *msgbody,
int bodylen,
int tag = ST_Tcp);
void AddUdpMsg(a8::UdpPacket* pkt);
PerfMonitor& GetPerf() { return perf_; }
int GetMsgNodeSize() { return msgnode_size_;}
int GetUdpMsgNodeSize() { return udp_msgnode_size_;}
int GetGameId() const;
private:
void QuickExecute();
void SlowerExecute();
void DispatchMsg();
void DispatchUdpMsg();
void ProcessClientMsg(f8::MsgHdr& hdr, int tag);
void ProcessMasterServerMsg(f8::MsgHdr& hdr, int tag);
void ProcessTargetServerMsg(f8::MsgHdr& hdr, int tag);
void FreeSocketMsgQueue();
void FreeUdpMsgQueue();
private:
PerfMonitor perf_;
std::mutex* msg_mutex_ = nullptr;
MsgNode* top_node_ = nullptr;
MsgNode* bot_node_ = nullptr;
MsgNode* work_node_ = nullptr;
std::mutex* udp_msg_mutex_ = nullptr;
UdpMsgNode* udp_top_node_ = nullptr;
UdpMsgNode* udp_bot_node_ = nullptr;
UdpMsgNode* udp_work_node_ = nullptr;
int msgnode_size_ = 0 ;
int udp_msgnode_size_ = 0 ;
int working_msgnode_size_ = 0;
int udp_working_msgnode_size_ = 0;
};