PageRenderTime 31ms CodeModel.GetById 19ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 24
 25ServiceImpLgc::ServiceImpLgc()
 26:m_wpSvcDB(NULL),
 27m_wpSvcHost(NULL),
 28m_pEttMgrWorld(NULL),
 29m_pEttMgrLogin(NULL),
 30m_pScnMgr(NULL),
 31m_pMsgHandler(NULL),
 32m_pScnDataMgr(NULL)
 33{
 34	
 35}
 36
 37ServiceImpLgc::~ServiceImpLgc()
 38{
 39	if(m_pMsgHandler)
 40	{
 41		delete m_pMsgHandler;
 42		m_pMsgHandler = NULL;
 43	}
 44}
 45
 46void
 47ServiceImpLgc::init(ServiceData& data)
 48{
 49	ServiceDataSMS* pSvcData = dynamic_cast<ServiceDataSMS*>(&data);
 50	if (pSvcData)
 51	{
 52		m_wpSvcDB = pSvcData->m_wpSvcDB;
 53		m_wpSvcHost = pSvcData->m_wpSvcHost;
 54	}
 55}
 56
 57void
 58ServiceImpLgc::onStart()
 59{
 60	m_pEttMgrWorld = new EntityManager;
 61
 62	m_pEttMgrLogin = new EntityManager(false);
 63
 64	m_pScnMgr = new SceneManagerSvr;
 65
 66	m_pScnDataMgr = new DataManagerImp;
 67
 68	ProgressLua::libaray(Lua::instance()->state());
 69	DataLua::libaray(Lua::instance()->state());
 70	DataManagerLua::libaray(Lua::instance()->state());
 71	MainLua::libaray(Lua::instance()->state());
 72	EntityLua::libaray(Lua::instance()->state());
 73	CombatLua::libaray(Lua::instance()->state());
 74	SceneLua::libaray(Lua::instance()->state());
 75	SceneManagerLua::libaray(Lua::instance()->state());
 76
 77	//
 78	//	initalize main lua script
 79	Lua::instance()->call("dofile('main.lua')");
 80
 81	//
 82	//	initialize scene data manager from lua
 83	//DataManagerLua::push(Lua::instance()->state(), m_pScnDataMgr);
 84	//Lua::instance()->call("onLoadDataManagerPoint", 1, 0);
 85
 86	initMsgHandler();
 87
 88	__super::onStart();
 89}
 90
 91void
 92ServiceImpLgc::onStop()
 93{
 94	__super::onStop();
 95}
 96
 97void
 98ServiceImpLgc::onTimer()
 99{
100	//LOG_DEBUG(" Timeout, Logic Thread!!!");
101
102	__super::onTimer();
103}
104
105Service* ServiceImpLgc::getSvcDB() const
106{
107	return m_wpSvcDB;
108}
109
110Service* ServiceImpLgc::getSvcHost() const
111{
112	return m_wpSvcHost;
113}
114
115
116void
117ServiceImpLgc::onDispatchMsg(IMsg* pMsg)
118{
119	//LOG_DEBUG(" Dispatch Message, Logic Thread!!!");
120	
121	if(m_pMsgHandler)
122	{
123		m_pMsgHandler->handleMsg(pMsg);
124	}
125}
126
127/////////////////////////////////////////////////////
128
129
130void 
131ServiceImpLgc::setMsgHandler(int msgCate, IMsgHandler* pHandler)
132{
133	if(!m_pMsgHandler)
134	{
135		m_pMsgHandler = new MsgHandlerDispatchByCate;
136	}
137
138	m_pMsgHandler->addSubHandler(msgCate, 0,  pHandler);
139}
140
141
142void 
143ServiceImpLgc::initMsgHandler()
144{
145	MsgHandlerInitDataLgc initData(m_wpSvcHost, this, m_wpSvcDB);
146	initData.wpEttMgrL = m_pEttMgrLogin;
147	initData.wpEttMgrW = m_pEttMgrWorld;
148	initData.wpScnMgr = m_pScnMgr;
149	initData.wpPlayerDataMgr = &m_playerDataMgr;
150
151	LoginMsgHandler* pLMH = new LoginMsgHandler;
152	if(pLMH)
153	{
154		pLMH->initialize(&initData);
155		setMsgHandler(Msg::MC_Login, pLMH);
156		setMsgHandler(Msg::MC_DB_Player, pLMH);
157	}
158
159	PlayerMsgHandler* pPMH = new PlayerMsgHandler;
160	if(pPMH)
161	{
162		pPMH->initialize(&initData);
163		setMsgHandler(Msg::MC_Player, pPMH);
164		setMsgHandler(Msg::MC_DB_Role, pPMH);
165		setMsgHandler(Msg::MC_DB_Item, pPMH);
166		setMsgHandler(Msg::MC_DB_Form, pPMH);
167		setMsgHandler(Msg::MC_DB_CoolDown, pPMH);
168		setMsgHandler(Msg::MC_DB_Progress, pPMH);
169	}
170
171	SceneMsgHandler* pSMH = new SceneMsgHandler;
172	if (pSMH)
173	{
174		pSMH->initialize(&initData);
175	
176		setMsgHandler(Msg::MC_Scene, pSMH);
177	}
178}
179
180
181