예제 #1
0
//------------------------------------------------------------------------
bool TGameEngine::CreateModules()
{
  int cntThread = mVecVecStrModule.size();
  for( int iThread = 0; iThread < cntThread ; iThread++ )
  {
    // создать поток и поместить в него модули
    int cntModule = mVecVecStrModule[iThread].size();
    TVecStr& vecStrModule = mVecVecStrModule[iThread];

    TVecPtrModule vecPtrModule;
    for( int iModule = 0 ; iModule < cntModule ; iModule++ )
    {
      IModule* pModule = mDevTool->GetModuleByName(vecStrModule[iModule].data());
      if(pModule!=NULL)
      {
        vecPtrModule.push_back(pModule);
        mMapName_IDModule.insert(TMapStrIntVT(pModule->GetName(), pModule->GetID()));
      }
      else
        Event(nsGameEngine::eModuleNotMade, vecStrModule[iModule].data());
    }
    if(vecPtrModule.size())
      mVecVecModule.push_back(vecPtrModule);
  }

	Event(nsGameEngine::eAfterCreateModules);

  if(mVecVecStrModule.size()==0)
    return false;

  return true;
}
예제 #2
0
bool Logicmgr::Initialize() {
    const sModuleConfig * pConfig = Configmgr::getInstance()->GetModuleConfig();
    TASSERT(pConfig, "can't load module config");

    vector<string>::const_iterator itor = pConfig->vctModules.begin();
    vector<string>::const_iterator iend = pConfig->vctModules.end();
    while (itor != iend) {
        char path[512] = {0};
#ifdef linux
        SafeSprintf(path, sizeof (path), "%s/%slib%s.so",
                tools::GetAppPath(), pConfig->strModulePath.c_str(), (*itor).c_str());

        void * handle = dlopen(path, RTLD_LAZY);
        TASSERT(handle, "open %s error %d", path, errno);

        GetModuleFun fun = (GetModuleFun) dlsym(handle, "GetLogicModule");
        TASSERT(fun, "get function:GetLogicModule error");
#endif //linux

#ifdef WIN32
        SafeSprintf(path, sizeof (path), "%s/%s/%s.dll",
            tools::GetAppPath(), pConfig->strModulePath.c_str(), (*itor).c_str());

        HINSTANCE hinst = ::LoadLibrary(path);
        GetModuleFun fun = (GetModuleFun)::GetProcAddress(hinst, NAME_OF_GET_LOGIC_FUN);
        TASSERT(fun, "get function:GetLogicModule error");
#endif //WIN32

        IModule * plogic = fun();
        TASSERT(plogic, "can't get module from lig%s.so", (*itor).c_str());

        while (plogic) {
            const char * pName = plogic->GetName();
            map<string, IModule *>::iterator mitor = m_mapModules.find(pName);
            if (mitor != m_mapModules.end()) {
                TASSERT(false, "LogicModule Name %s is exists", pName);
                return false;
            }

            m_vctModules.push_back(plogic);
            m_mapModules.insert(make_pair(pName, plogic));
            plogic = plogic->GetNext();
        }

        itor++;
    }

	{
		vector<IModule *>::iterator vitor = m_vctModules.begin();
		vector<IModule *>::iterator viend = m_vctModules.end();
		while (vitor != viend) {
			(*vitor)->Initialize(Kernel::getInstance());

			vitor ++;
		}

		vitor = m_vctModules.begin();
		while(vitor != viend) {
			(*vitor)->Launched(Kernel::getInstance());
			vitor++;
		}
	}

    return true;
}