1
This commit is contained in:
parent
92a052b074
commit
f0109274ca
@ -245,10 +245,6 @@ void App::UnInit()
|
||||
#ifdef MYDEBUG
|
||||
TraceMgr::Instance()->UnInit();
|
||||
#endif
|
||||
UnInitLog();
|
||||
|
||||
FreeSocketMsgQueue();
|
||||
msg_mutex_ = nullptr;
|
||||
}
|
||||
|
||||
#if 0
|
||||
@ -274,84 +270,9 @@ int App::Run()
|
||||
}
|
||||
#endif
|
||||
|
||||
void App::QuickExecute(int delta_time)
|
||||
{
|
||||
f8::MsgQueue::Instance()->Update();
|
||||
DispatchMsg();
|
||||
RoomMgr::Instance()->Update(delta_time);
|
||||
f8::Timer::Instance()->Update();
|
||||
}
|
||||
|
||||
void App::SlowerExecute(int delta_time)
|
||||
{
|
||||
}
|
||||
|
||||
bool App::HasTask()
|
||||
{
|
||||
{
|
||||
if (!work_node_) {
|
||||
msg_mutex_->lock();
|
||||
if (!work_node_ && top_node_) {
|
||||
work_node_ = top_node_;
|
||||
top_node_ = nullptr;
|
||||
bot_node_ = nullptr;
|
||||
}
|
||||
msg_mutex_->unlock();
|
||||
}
|
||||
if (work_node_) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void App::DispatchMsg()
|
||||
{
|
||||
long long begin_tick = a8::XGetTickCount();
|
||||
if (!work_node_ && top_node_) {
|
||||
msg_mutex_->lock();
|
||||
work_node_ = top_node_;
|
||||
top_node_ = nullptr;
|
||||
bot_node_ = nullptr;
|
||||
working_msgnode_size_ = msgnode_size_;
|
||||
msg_mutex_->unlock();
|
||||
}
|
||||
|
||||
f8::MsgHdr hdr;
|
||||
while (work_node_) {
|
||||
MsgNode *pdelnode = work_node_;
|
||||
work_node_ = pdelnode->next;
|
||||
hdr.msgid = pdelnode->msgid;
|
||||
hdr.seqid = pdelnode->seqid;
|
||||
hdr.socket_handle = pdelnode->sockhandle;
|
||||
hdr.buf = pdelnode->buf;
|
||||
hdr.buflen = pdelnode->buflen;
|
||||
hdr.offset = 0;
|
||||
hdr.ip_saddr = pdelnode->ip_saddr;
|
||||
switch (pdelnode->sockfrom) {
|
||||
case SF_GameGate:
|
||||
{
|
||||
ProcessGameGateMsg(&hdr);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (pdelnode->buf) {
|
||||
free(pdelnode->buf);
|
||||
}
|
||||
free(pdelnode);
|
||||
working_msgnode_size_--;
|
||||
if (a8::XGetTickCount() - begin_tick > 200) {
|
||||
break;
|
||||
}
|
||||
}//end while
|
||||
|
||||
if (!work_node_) {
|
||||
working_msgnode_size_ = 0;
|
||||
}
|
||||
a8::tick_t end_tick = a8::XGetTickCount();
|
||||
if (end_tick - begin_tick > PerfMonitor::Instance()->max_dispatchmsg_time) {
|
||||
PerfMonitor::Instance()->max_dispatchmsg_time = end_tick - begin_tick;
|
||||
}
|
||||
return RoomMgr::Instance()->RoomNum() > 0;
|
||||
}
|
||||
|
||||
void App::ProcessGameGateMsg(f8::MsgHdr* hdr)
|
||||
@ -392,54 +313,6 @@ void App::ProcessGameGateMsg(f8::MsgHdr* hdr)
|
||||
}
|
||||
}
|
||||
|
||||
void App::InitLog()
|
||||
{
|
||||
std::string filename_fmt = PROJ_LOG_FILENAME_FMT;
|
||||
a8::ReplaceString(filename_fmt, "$pid", a8::XValue(getpid()));
|
||||
|
||||
std::string proj_root_dir = a8::Format(PROJ_ROOT_FMT, {a8::Format(PROJ_NAME_FMT,{GAME_ID})});
|
||||
std::string proj_log_root_dir = a8::Format(PROJ_LOG_ROOT_FMT, {a8::Format(PROJ_NAME_FMT, {GAME_ID})});
|
||||
std::string log_file_name = a8::Format(PROJ_LOG_ROOT_FMT,
|
||||
{a8::Format(PROJ_NAME_FMT, {GAME_ID})}) + "/" + filename_fmt;
|
||||
|
||||
a8::MkDir(proj_root_dir);
|
||||
a8::MkDir(proj_log_root_dir);
|
||||
f8::UdpLog::Instance()->SetLogFileName(log_file_name);
|
||||
f8::UdpLog::Instance()->Init();
|
||||
f8::UdpLog::Instance()->Info("proj_root_dir:%s", {proj_root_dir});
|
||||
f8::UdpLog::Instance()->Info("proj_log_root_dir:%s", {proj_log_root_dir});
|
||||
f8::UdpLog::Instance()->Info("log_file_name:%s", {log_file_name});
|
||||
}
|
||||
|
||||
void App::UnInitLog()
|
||||
{
|
||||
f8::UdpLog::Instance()->UnInit();
|
||||
}
|
||||
|
||||
void App::FreeSocketMsgQueue()
|
||||
{
|
||||
msg_mutex_->lock();
|
||||
if (!work_node_) {
|
||||
work_node_ = top_node_;
|
||||
top_node_ = nullptr;
|
||||
bot_node_ = nullptr;
|
||||
}
|
||||
while (work_node_) {
|
||||
MsgNode* pdelnode = work_node_;
|
||||
work_node_ = work_node_->next;
|
||||
if (pdelnode->buf) {
|
||||
free(pdelnode->buf);
|
||||
}
|
||||
free(pdelnode);
|
||||
if (!work_node_) {
|
||||
work_node_ = top_node_;
|
||||
top_node_ = nullptr;
|
||||
bot_node_ = nullptr;
|
||||
}
|
||||
}
|
||||
msg_mutex_->unlock();
|
||||
}
|
||||
|
||||
long long App::AllocTempHeroUniId()
|
||||
{
|
||||
if (curr_uniid_ < 1000) {
|
||||
@ -486,12 +359,18 @@ const std::string App::GetPkgName()
|
||||
return a8::Format("gameserver2006", {});
|
||||
}
|
||||
|
||||
void App::Update()
|
||||
void App::Update(int delta_time)
|
||||
{
|
||||
|
||||
RoomMgr::Instance()->Update(delta_time);
|
||||
}
|
||||
|
||||
void App::DispatchSocketMsg(f8::MsgHdr* hdr)
|
||||
{
|
||||
|
||||
switch (hdr->sockfrom) {
|
||||
case SF_GameGate:
|
||||
{
|
||||
ProcessGameGateMsg(hdr);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <a8/uuid.h>
|
||||
#include <a8/singleton.h>
|
||||
|
||||
#include <f8/protoutils.h>
|
||||
#include <f8/app.h>
|
||||
|
||||
struct MsgNode;
|
||||
class App : public f8::UserApp, public a8::Singleton<App>
|
||||
{
|
||||
private:
|
||||
@ -18,7 +14,7 @@ public:
|
||||
virtual const std::string GetPkgName() override;
|
||||
virtual void Init() override;
|
||||
virtual void UnInit() override;
|
||||
virtual void Update() override;
|
||||
virtual void Update(int delta_time) override;
|
||||
virtual bool HasTask() override;
|
||||
virtual void DispatchSocketMsg(f8::MsgHdr* hdr) override;
|
||||
|
||||
@ -29,32 +25,12 @@ public:
|
||||
int GetVersion();
|
||||
|
||||
private:
|
||||
void QuickExecute(int delta_time);
|
||||
void SlowerExecute(int delta_time);
|
||||
|
||||
void DispatchMsg();
|
||||
|
||||
void ProcessGameGateMsg(f8::MsgHdr* hdr);
|
||||
|
||||
void InitLog();
|
||||
void UnInitLog();
|
||||
|
||||
void FreeSocketMsgQueue();
|
||||
|
||||
private:
|
||||
bool servicing_ = true;
|
||||
|
||||
std::shared_ptr<std::mutex> msg_mutex_;
|
||||
MsgNode* top_node_ = nullptr;
|
||||
MsgNode* bot_node_ = nullptr;
|
||||
MsgNode* work_node_ = nullptr;
|
||||
|
||||
long long curr_uniid_ = 0;
|
||||
|
||||
std::shared_ptr<int> version_;
|
||||
|
||||
public:
|
||||
int msgnode_size_ = 0 ;
|
||||
int working_msgnode_size_ = 0;
|
||||
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user