网上流传天龙 Server代码分析笔记 -01
2014-08-30 23:30
447 查看
g_Server全局Server对象。 main() { //初始化配置文件模块 g_Server.InitConfig(); //时间模块需要最开始的时候设置 g_pTimeManager->Init(); //日志模块初始化需要最开始设置 g_pLog->Init( ); g_pTimeManager->SetTime() ; //==>获取当前时间 年月日 ==>{ time( &m_SetTime ) ; tm* ptm = localtime( &m_SetTime ) ; m_TM = *ptm ; } //-------------下面就是核心部分----- g_Server.InitServer( ) ; g_Server.Loop( ) ; g_Server.ExitServer( ) ; } 一、初始化 Server::InitServer() { //分配内存 NewStaticServer( ); ==>{ g_pMonsterPool = new MonsterPool ; g_pPetPool = new PetPool ; g_pSceneManager = new SceneManager ; g_pPlayerPool = new PlayerPool ; g_pPacketFactoryManager = new PacketFactoryManager ; g_pServerManager = new ServerManager ; g_pWorldManager = new WorldManager ; g_pMachineManager = new MachineManager ; g_pGUIDManager = new GUIDManager ; g_pPlayerShopPool = new PlayerShopPool; g_pItemBoxPool = new ItemBoxPool; g_pPlatformPool = new PlatformPool; g_pSpecialPool = new SpecialPool; g_pAbilityManager = new AbilityManager; g_pStaticShopManager = new StaticShopManager; g_pCopySceneManager = new CopySceneManager; //副本场景管理器 g_pItemManager = new ItemManager; g_pDaemonThread = new DaemonThread; // 后台线程 g_pDiePenaltyManager = new DiePenaltyManager; // 死亡惩罚数据 g_pPerformanceManager = new PerformanceManager; // 数据监控管理器 //---最后两个 是重点 g_pThreadManager = new ThreadManager ; //[线程管理器] ==>{ m_pThreadPool = new ThreadPool ; //-->此线程池只容纳所有 场景线程 m_pServerThread = new ServerThread ; //-->服务器线程(m_Active = TRUE ;) m_nThreads = 0 ; } g_pClientManager = new ClientManager ; //[客户端管理器] ==>{ if( !g_pIncomingPlayerManager ) //-->[连接的玩家管理] { g_pIncomingPlayerManager = new IncomingPlayerManager ; //客户端网络层链接和数据 /**★因为重要,提前粗略介绍下 有ProcessInputs和ProcessOutputs函数 ProcessOutputs==>负责接收新连接和客户端的数据 ProcessOutputs==>负责将GS数据发送给Client */ } m_Active = FALSE ; } } //初始化各个模块 InitStaticServer( ); ==>{ //①初始化共享内存数据 g_HumanSMUPool.Init(); // --玩家数据共享内存 g_PlayerShopSMUPool(); // --玩家商店共享内存 g_ItemSerialSMUPool(); // --物品序列化共享内存 //②表格 g_ItemTable.Init(); // --物品表初始化 g_TableInit.Init(); // --表格初始化 //后逻辑模块数据 g_pMonsterPool->Init(g_Config.m_ConfigInfo.m_MaxMonster); g_pPetPool->Init(g_Config.m_ConfigInfo.m_MaxPet); g_pPlayerPool->Init(MAX_POOL_SIZE); g_pPacketFactoryManager->Init( ); //包 工厂管理{CG & GC} g_pWorldManager->Init(); //世界管理器 g_pMachineManager->Init(); //服务器机器 g_pGUIDManager->Init(); //全局唯一标识管理器 g_pItemBoxPool->Init(); //物品盒池 g_pPlayerShopPool->Init(g_Config.m_ConfigInfo.m_MaxPlayerShopNum); //玩家商店池初始化 //...各种容器、管理器初始化 //--最后 g_pServerManager->Init(); //服务器管理 ==>{ } g_pThreadManager->Init(); //线程管理(之前说过,是主要管理所有场景线程的) g_pClientManager->Init(); //客户端管理 g_pDaemonThread->Init(); //后台线程管理 } } 二、Server循环 Server::Loop( ) { g_pThreadManager->Start( ) ; ==>{ m_pServerThread->start(); //服务器线程启动 ==>{//--线程执行函数 ServerThread::run() ==>{ while(1){ g_pServerManager->Tick(); // } } } MySleep( 500 ); m_pThreadPool->Start(); //线程池启动 ==>{ while(1) m_apScene[i]->Tick(); // } } //主线程调度资源分给ClientManager来执行; g_pClientManager->start( ) ; ==>{ ClientManager::run();// ==>{ g_pIncomingPlayerManager->Select( ) ; g_pIncomingPlayerManager->ProcessExceptions( ) ; g_pIncomingPlayerManager->ProcessInputs( ) ; g_pIncomingPlayerManager->ProcessOutputs( ) ; g_pIncomingPlayerManager->ProcessCommands(); g_pIncomingPlayerManager->ProcessCacheCommands(); g_pIncomingPlayerManager->HeartBeat(); } } g_pDaemonThread->Loop( ) ; ==>{ //定时器初始化{Work,FlushLog} //日志刷入文件 //副本场景管理管理器的逻辑调用 g_pCopySceneManager->HeartBeat( uTime ); //数据监控逻辑调用 g_pPerformanceManager->HeartBeat( uTime ) g_ShareMemNotifyer.HeartBeat(uTime); //定时关闭服务器处理 g_Server.Stop(); } } 三、退出Server Server::ExitServer( ) { //①等待各线程退出
<span style="white-space:pre"> </span>//②释放内存 }
//--
相关文章推荐
- (转)网上流传的天龙源码框架分析之一 --- 客户端简单介绍
- (转)网上流传的天龙源码框架分析之一 --- 客户端简单介绍
- 恶意代码分析实战(7-01实验学习笔记)
- 网上流传的天龙源码框架分析之一 --- 客户端简单介绍
- linux 2.6源代码情景分析笔记之进程3
- linux 2.6源代码情景分析笔记之进程4
- linux 2.6源代码情景分析笔记之内存2
- linux 2.6源代码情景分析笔记之内存3
- [hyddd安全性测试笔记2]浅淡静态代码分析工具
- linux 2.6源代码情景分析笔记之中断与异常1
- linux 2.6源代码情景分析笔记之进程2
- linux 2.6源代码情景分析笔记之内存4
- linux 2.6源代码情景分析笔记之中断与异常3
- linux 2.6源代码情景分析笔记之进程9
- linux 2.6源代码情景分析笔记之进程10
- linux 2.6源代码情景分析笔记之进程5
- Equalizer中eq::Server/eq::Node的代码分析
- EasyARM2200开发板学习笔记:启动代码分析
- linux 2.6源代码情景分析笔记之内存5
- linux 2.6源代码情景分析笔记之进程7