#pragma once #include struct MsgNode; struct IMMsgNode; class App : public a8::Singleton { private: App() {}; friend class a8::Singleton; public: #ifdef DEBUG std::map debug_params; #endif bool Init(int argc, char* argv[]); void UnInit(); int Run(); void AddSocketMsg(SocketFrom_e sockfrom, int sockhandle, long ip_saddr, unsigned short msgid, unsigned int seqid, const char *msgbody, int bodylen); void AddIMMsg(unsigned short imcmd, a8::XParams params); void NotifyLoopCond(); long long NewUuid(); a8::XParams* AddContext(long long context_id); void DelContext(long long context_id); a8::XParams* GetContext(long long context_id); bool HasFlag(int flag); void SetFlag(int flag); void UnSetFlag(int flag); private: void QuickExecute(int delta_time); void SlowerExecute(int delta_time); void Schedule(); bool HasTask(); void DispatchMsg(); void ProcessIMMsg(); void ProcessGameGateMsg(f8::MsgHdr& hdr); void InitLog(); void UnInitLog(); bool ParseOpt(); void FreeSocketMsgQueue(); void FreeIMMsgQueue(); public: int argc = 0; char** argv = nullptr; volatile bool terminated = false; a8::uuid::SnowFlake uuid; public: int instance_id = 0; int node_id = 0; bool is_test_mode = false; int test_param = 0; bool servicing = true; private: /* 1: 是否自动匹配机器人组队 2: 是否发布环境 3: battleReport环境 4: 打印性能日志 5: 压力测试 6: 7: 内存泄露测试 8: httpclientpool压力测试 */ std::set flags; private: long long last_run_tick_ = 0; std::mutex *loop_mutex_ = nullptr; std::condition_variable *loop_cond_ = nullptr; std::mutex *msg_mutex_ = nullptr; MsgNode* top_node_ = nullptr; MsgNode* bot_node_ = nullptr; MsgNode* work_node_ = nullptr; std::mutex* im_msg_mutex_ = nullptr; IMMsgNode* im_top_node_ = nullptr; IMMsgNode* im_bot_node_ = nullptr; IMMsgNode* im_work_node_ = nullptr; std::map context_hash_; public: int msgnode_size_ = 0 ; int working_msgnode_size_ = 0; };