/TGame/TServerMS/Service/ServiceImpLgc.cpp

http://awoe.googlecode.com/ · C++ · 181 lines · 137 code · 35 blank · 9 comment · 7 complexity · 362a1ccacf8972f43d36ab5c79b1f21b MD5 · raw file

  1. #include "stdafx.h"
  2. #include "ServiceImpLgc.h"
  3. #include "Entity/EntityManager.h"
  4. #include "Entity/EntityBuilder.h"
  5. #include "Scene/SceneManagerSvr.h"
  6. #include "Scene/SceneMsgHandler.h"
  7. #include "Message/MsgCategory.h"
  8. #include "Message/MsgHandlerDispatchByCate.h"
  9. #include "Message/DBMessage.h"
  10. #include "login/LoginMsgHandler.h"
  11. #include "Player/PlayerMsgHandler.h"
  12. #include "Manager/DataManagerLua.h"
  13. #include "Manager/DataManagerImp.h"
  14. #include "Lua/LuaWrapper.h"
  15. #include "Data/DataLua.h"
  16. #include "Manager/DataManagerLua.h"
  17. #include "Entry/MainLua.h"
  18. #include "Entity/EntityLua.h"
  19. #include "Scene/SceneLua.h"
  20. #include "Scene/SceneManagerLua.h"
  21. #include "Combat/CombatLua.h"
  22. #include "Player/ProgressLua.h"
  23. ServiceImpLgc::ServiceImpLgc()
  24. :m_wpSvcDB(NULL),
  25. m_wpSvcHost(NULL),
  26. m_pEttMgrWorld(NULL),
  27. m_pEttMgrLogin(NULL),
  28. m_pScnMgr(NULL),
  29. m_pMsgHandler(NULL),
  30. m_pScnDataMgr(NULL)
  31. {
  32. }
  33. ServiceImpLgc::~ServiceImpLgc()
  34. {
  35. if(m_pMsgHandler)
  36. {
  37. delete m_pMsgHandler;
  38. m_pMsgHandler = NULL;
  39. }
  40. }
  41. void
  42. ServiceImpLgc::init(ServiceData& data)
  43. {
  44. ServiceDataSMS* pSvcData = dynamic_cast<ServiceDataSMS*>(&data);
  45. if (pSvcData)
  46. {
  47. m_wpSvcDB = pSvcData->m_wpSvcDB;
  48. m_wpSvcHost = pSvcData->m_wpSvcHost;
  49. }
  50. }
  51. void
  52. ServiceImpLgc::onStart()
  53. {
  54. m_pEttMgrWorld = new EntityManager;
  55. m_pEttMgrLogin = new EntityManager(false);
  56. m_pScnMgr = new SceneManagerSvr;
  57. m_pScnDataMgr = new DataManagerImp;
  58. ProgressLua::libaray(Lua::instance()->state());
  59. DataLua::libaray(Lua::instance()->state());
  60. DataManagerLua::libaray(Lua::instance()->state());
  61. MainLua::libaray(Lua::instance()->state());
  62. EntityLua::libaray(Lua::instance()->state());
  63. CombatLua::libaray(Lua::instance()->state());
  64. SceneLua::libaray(Lua::instance()->state());
  65. SceneManagerLua::libaray(Lua::instance()->state());
  66. //
  67. // initalize main lua script
  68. Lua::instance()->call("dofile('main.lua')");
  69. //
  70. // initialize scene data manager from lua
  71. //DataManagerLua::push(Lua::instance()->state(), m_pScnDataMgr);
  72. //Lua::instance()->call("onLoadDataManagerPoint", 1, 0);
  73. initMsgHandler();
  74. __super::onStart();
  75. }
  76. void
  77. ServiceImpLgc::onStop()
  78. {
  79. __super::onStop();
  80. }
  81. void
  82. ServiceImpLgc::onTimer()
  83. {
  84. //LOG_DEBUG(" Timeout, Logic Thread!!!");
  85. __super::onTimer();
  86. }
  87. Service* ServiceImpLgc::getSvcDB() const
  88. {
  89. return m_wpSvcDB;
  90. }
  91. Service* ServiceImpLgc::getSvcHost() const
  92. {
  93. return m_wpSvcHost;
  94. }
  95. void
  96. ServiceImpLgc::onDispatchMsg(IMsg* pMsg)
  97. {
  98. //LOG_DEBUG(" Dispatch Message, Logic Thread!!!");
  99. if(m_pMsgHandler)
  100. {
  101. m_pMsgHandler->handleMsg(pMsg);
  102. }
  103. }
  104. /////////////////////////////////////////////////////
  105. void
  106. ServiceImpLgc::setMsgHandler(int msgCate, IMsgHandler* pHandler)
  107. {
  108. if(!m_pMsgHandler)
  109. {
  110. m_pMsgHandler = new MsgHandlerDispatchByCate;
  111. }
  112. m_pMsgHandler->addSubHandler(msgCate, 0, pHandler);
  113. }
  114. void
  115. ServiceImpLgc::initMsgHandler()
  116. {
  117. MsgHandlerInitDataLgc initData(m_wpSvcHost, this, m_wpSvcDB);
  118. initData.wpEttMgrL = m_pEttMgrLogin;
  119. initData.wpEttMgrW = m_pEttMgrWorld;
  120. initData.wpScnMgr = m_pScnMgr;
  121. initData.wpPlayerDataMgr = &m_playerDataMgr;
  122. LoginMsgHandler* pLMH = new LoginMsgHandler;
  123. if(pLMH)
  124. {
  125. pLMH->initialize(&initData);
  126. setMsgHandler(Msg::MC_Login, pLMH);
  127. setMsgHandler(Msg::MC_DB_Player, pLMH);
  128. }
  129. PlayerMsgHandler* pPMH = new PlayerMsgHandler;
  130. if(pPMH)
  131. {
  132. pPMH->initialize(&initData);
  133. setMsgHandler(Msg::MC_Player, pPMH);
  134. setMsgHandler(Msg::MC_DB_Role, pPMH);
  135. setMsgHandler(Msg::MC_DB_Item, pPMH);
  136. setMsgHandler(Msg::MC_DB_Form, pPMH);
  137. setMsgHandler(Msg::MC_DB_CoolDown, pPMH);
  138. setMsgHandler(Msg::MC_DB_Progress, pPMH);
  139. }
  140. SceneMsgHandler* pSMH = new SceneMsgHandler;
  141. if (pSMH)
  142. {
  143. pSMH->initialize(&initData);
  144. setMsgHandler(Msg::MC_Scene, pSMH);
  145. }
  146. }