bool NFCTileModule::AddBuilding(const NFGUID & self, const int nX, const int nY, const NFGUID & id, const std::string & strCnfID) { NF_SHARE_PTR<TileData> xTileData = mxTileData.GetElement(self); if (!xTileData) { xTileData = NF_SHARE_PTR<TileData>(NF_NEW TileData()); mxTileData.AddElement(self, xTileData); } NF_SHARE_PTR<NFMapEx<int, TileBuilding>> xStateDataMap = xTileData->mxTileBuilding.GetElement(nX); if (!xStateDataMap) { xStateDataMap = NF_SHARE_PTR<NFMapEx<int, TileBuilding>>(NF_NEW NFMapEx<int, TileBuilding>()); xTileData->mxTileBuilding.AddElement(nX, xStateDataMap); } NF_SHARE_PTR<TileBuilding> xTileBuilding = xStateDataMap->GetElement(nY); if (!xTileBuilding) { xTileBuilding = NF_SHARE_PTR<TileBuilding>(NF_NEW TileBuilding()); xStateDataMap->AddElement(nY, xTileBuilding); } xTileBuilding->x = nX; xTileBuilding->y = nY; xTileBuilding->configID = strCnfID; xTileBuilding->ID = id; //save //SaveTileData(self); return true; }
bool NFCTileModule::AddNPC(const NFGUID & self, const int nX, const int nY, const NFGUID & id, const std::string & strCnfID) { NF_SHARE_PTR<TileData> xTileData = mxTileData.GetElement(self); if (!xTileData) { xTileData = NF_SHARE_PTR<TileData>(NF_NEW TileData()); mxTileData.AddElement(self, xTileData); } NF_SHARE_PTR<NFMapEx<int, TileNPC>> xStateDataMap = xTileData->mxTileNPC.GetElement(nX); if (!xStateDataMap) { xStateDataMap = NF_SHARE_PTR<NFMapEx<int, TileNPC>>(NF_NEW NFMapEx<int, TileNPC>()); xTileData->mxTileNPC.AddElement(nX, xStateDataMap); } NF_SHARE_PTR<TileNPC> xTileNPC = xStateDataMap->GetElement(nY); if (!xTileNPC) { xTileNPC = NF_SHARE_PTR<TileNPC>(NF_NEW TileNPC()); xStateDataMap->AddElement(nY, xTileNPC); } xTileNPC->x = nX; xTileNPC->y = nY; xTileNPC->configID = strCnfID; xTileNPC->ID = id; return true; }
void NFCPropertyConfigModule::Load() { NF_SHARE_PTR<NFIClass> xLogicClass = m_pClassModule->GetElement(NFrame::InitProperty::ThisName()); if (xLogicClass) { const std::vector<std::string>& strIdList = xLogicClass->GetIDList(); for (int i = 0; i < strIdList.size(); ++i) { const std::string& strId = strIdList[i]; NF_SHARE_PTR<NFIPropertyManager> pPropertyManager = m_pElementModule->GetPropertyManager(strId); if (pPropertyManager) { int nJob = m_pElementModule->GetPropertyInt32(strId, NFrame::InitProperty::Job()); int nLevel = m_pElementModule->GetPropertyInt32(strId, NFrame::InitProperty::Level()); std::string strEffectData = m_pElementModule->GetPropertyString(strId, NFrame::InitProperty::EffectData()); NF_SHARE_PTR <NFMapEx<int, std::string> > xPropertyMap = mhtCoefficienData.GetElement(nJob); if (!xPropertyMap) { xPropertyMap = NF_SHARE_PTR<NFMapEx<int, std::string>>(NF_NEW NFMapEx<int, std::string>()); mhtCoefficienData.AddElement(nJob, xPropertyMap); } NF_SHARE_PTR<std::string> xRefPropertyIDName = xPropertyMap->GetElement(nLevel); if (!xRefPropertyIDName) { xRefPropertyIDName = NF_SHARE_PTR<std::string>(NF_NEW std::string(strEffectData)); } xPropertyMap->AddElement(nLevel, xRefPropertyIDName); } } } }
bool NFCEventProcessModule::AddAsyncEventCallBack( const NFIDENTID& objectID, const int nEventID, const EVENT_ASYNC_PROCESS_BEGIN_FUNCTOR_PTR& cb, const EVENT_ASYNC_PROCESS_END_FUNCTOR_PTR& cb_end ) { NF_SHARE_PTR<NFCObjectAsyncEventInfo> pObjectSyncEventInfo = mObjectSyncEventInfoMapEx.GetElement(objectID); if (nullptr == pObjectSyncEventInfo) { pObjectSyncEventInfo = NF_SHARE_PTR<NFCObjectAsyncEventInfo>(NF_NEW NFCObjectAsyncEventInfo()); mObjectSyncEventInfoMapEx.AddElement(objectID, pObjectSyncEventInfo); } assert(NULL != pObjectSyncEventInfo); NF_SHARE_PTR<NFAsyncEventFunc> pSyncEventInfo = pObjectSyncEventInfo->GetElement(nEventID); if (nullptr == pSyncEventInfo) { pSyncEventInfo = NF_SHARE_PTR<NFAsyncEventFunc>(NF_NEW NFAsyncEventFunc()); pObjectSyncEventInfo->AddElement(nEventID, pSyncEventInfo); } assert(NULL != pSyncEventInfo); pSyncEventInfo->xBeginFuncptr = cb; pSyncEventInfo->xEndFuncptr = cb_end; return true; }
bool NFCSceneProcessModule::LoadSceneResource( const int nSceneID ) { char szSceneIDName[MAX_PATH] = { 0 }; sprintf( szSceneIDName, "%d", nSceneID ); const std::string& strSceneFilePath = m_pElementInfoModule->GetPropertyString( szSceneIDName, NFrame::Scene::FilePath() ); const int nCanClone = m_pElementInfoModule->GetPropertyInt( szSceneIDName, NFrame::Scene::CanClone() ); //场景对应资源 NF_SHARE_PTR<NFMapEx<std::string, SceneSeedResource>> pSceneResourceMap = mtSceneResourceConfig.GetElement( nSceneID ); if ( !pSceneResourceMap.get() ) { pSceneResourceMap = NF_SHARE_PTR<NFMapEx<std::string, SceneSeedResource>>(NF_NEW NFMapEx<std::string, SceneSeedResource>()); mtSceneResourceConfig.AddElement( nSceneID, pSceneResourceMap ); } rapidxml::file<> xFileSource( strSceneFilePath.c_str() ); rapidxml::xml_document<> xFileDoc; xFileDoc.parse<0>( xFileSource.data() ); //资源文件列表 rapidxml::xml_node<>* pSeedFileRoot = xFileDoc.first_node(); for ( rapidxml::xml_node<>* pSeedFileNode = pSeedFileRoot->first_node(); pSeedFileNode; pSeedFileNode = pSeedFileNode->next_sibling() ) { //种子具体信息 std::string strSeedID = pSeedFileNode->first_attribute( "ID" )->value(); std::string strConfigID = pSeedFileNode->first_attribute( "NPCConfigID" )->value(); float fSeedX = lexical_cast<float>(pSeedFileNode->first_attribute( "SeedX" )->value()); float fSeedY = lexical_cast<float>(pSeedFileNode->first_attribute( "SeedY" )->value()); float fSeedZ = lexical_cast<float>(pSeedFileNode->first_attribute( "SeedZ" )->value()); if (!m_pElementInfoModule->ExistElement(strConfigID)) { assert(0); } NF_SHARE_PTR<SceneSeedResource> pSeedResource = pSceneResourceMap->GetElement(strSeedID); if ( !pSeedResource.get() ) { pSeedResource = NF_SHARE_PTR<SceneSeedResource>(NF_NEW SceneSeedResource()); pSceneResourceMap->AddElement( strSeedID, pSeedResource ); } pSeedResource->strSeedID = strSeedID; pSeedResource->strConfigID = strConfigID; pSeedResource->fSeedX = fSeedX; pSeedResource->fSeedY = fSeedY; pSeedResource->fSeedZ = fSeedZ; } return true; }
bool NFCTileModule::AddTile(const NFGUID & self, const int nX, const int nY, const int nOpr) { NF_SHARE_PTR<TileData> xTileData = mxTileData.GetElement(self); if (!xTileData) { xTileData = NF_SHARE_PTR<TileData>(NF_NEW TileData()); mxTileData.AddElement(self, xTileData); } NF_SHARE_PTR<NFMapEx<int, TileState>> xStateDataMap = xTileData->mxTileState.GetElement(nX); if (!xStateDataMap) { xStateDataMap = NF_SHARE_PTR<NFMapEx<int, TileState>>(NF_NEW NFMapEx<int, TileState>()); xTileData->mxTileState.AddElement(nX, xStateDataMap); } NF_SHARE_PTR<TileState> xTileState = xStateDataMap->GetElement(nY); if (!xTileState) { xTileState = NF_SHARE_PTR<TileState>(NF_NEW TileState()); xStateDataMap->AddElement(nY, xTileState); } else { if (nOpr == xTileState->state) { //has be deleted return false; } } xTileState->x = nX; xTileState->y = nY; xTileState->state = nOpr; //save //SaveTileData(self); return true; }
bool NFCEventProcessModule::AddEventCallBack(const NFIDENTID& objectID, const int nEventID, const EVENT_PROCESS_FUNCTOR_PTR& cb) { NF_SHARE_PTR<NFCObjectEventInfo> pObjectEventInfo = mObjectEventInfoMapEx.GetElement(objectID); if (!pObjectEventInfo.get()) { pObjectEventInfo = NF_SHARE_PTR<NFCObjectEventInfo>(NF_NEW NFCObjectEventInfo()); mObjectEventInfoMapEx.AddElement(objectID, pObjectEventInfo); } assert(nullptr != pObjectEventInfo); NF_SHARE_PTR<NFEventList> pEventInfo = pObjectEventInfo->GetElement(nEventID); if (!pEventInfo) { pEventInfo = NF_SHARE_PTR<NFEventList>(NF_NEW NFEventList()); pObjectEventInfo->AddElement(nEventID, pEventInfo); } assert(nullptr != pEventInfo); pEventInfo->Add(cb); return true; }
bool NFCSceneProcessModule::LoadInitFileResource( const int& nContainerID ) { char szSceneIDName[MAX_PATH] = { 0 }; sprintf( szSceneIDName, "%d", nContainerID ); const std::string& strSceneFilePath = m_pElementInfoModule->GetPropertyString( szSceneIDName, "FilePath" ); const int nCanClone = m_pElementInfoModule->GetPropertyInt( szSceneIDName, "CanClone" ); //场景对应资源 NF_SHARE_PTR<NFMapEx<std::string, SceneGroupResource>> pSceneResourceMap = mtSceneResourceConfig.GetElement( nContainerID ); if ( !pSceneResourceMap.get() ) { pSceneResourceMap = NF_SHARE_PTR<NFMapEx<std::string, SceneGroupResource>>(NF_NEW NFMapEx<std::string, SceneGroupResource>()); mtSceneResourceConfig.AddElement( nContainerID, pSceneResourceMap ); } if ( !strSceneFilePath.empty() ) { std::string strFilePathName( strSceneFilePath ); strFilePathName.append( "File.xml" ); NF_SHARE_PTR<SceneGroupResource> pSceneGroupResource = pSceneResourceMap->GetElement( "File.xml" ); if ( !pSceneGroupResource.get() ) { pSceneGroupResource = NF_SHARE_PTR<SceneGroupResource>(NF_NEW SceneGroupResource()); pSceneGroupResource->bCanClone = (nCanClone > 0 ? true : false); pSceneResourceMap->AddElement( "File.xml", pSceneGroupResource ); } rapidxml::file<> xFileSource( strFilePathName.c_str() ); rapidxml::xml_document<> xFileDoc; xFileDoc.parse<0>( xFileSource.data() ); //资源文件列表 rapidxml::xml_node<>* pSeedFileRoot = xFileDoc.first_node(); for ( rapidxml::xml_node<>* pSeedFileNode = pSeedFileRoot->first_node(); pSeedFileNode; pSeedFileNode = pSeedFileNode->next_sibling() ) { std::string strSeedFileName = pSeedFileNode->first_attribute( "ID" )->value(); //资源对应种子列表 NF_SHARE_PTR<NFMapEx<std::string, SceneSeedResource>> pSeedResourceList = pSceneGroupResource->xSceneGroupResource.GetElement(strSeedFileName); if ( !pSeedResourceList.get() ) { pSeedResourceList = NF_SHARE_PTR<NFMapEx<std::string, SceneSeedResource>>(NF_NEW NFMapEx<std::string, SceneSeedResource>()); pSceneGroupResource->xSceneGroupResource.AddElement( strSeedFileName, pSeedResourceList ); } std::string strObjectFileName( strSceneFilePath ); strObjectFileName.append( strSeedFileName ); strObjectFileName.append( ".xml" ); rapidxml::file<> xSeedListSource( strObjectFileName.c_str() ); rapidxml::xml_document<> xFileDoc; xFileDoc.parse<0>( xSeedListSource.data() ); rapidxml::xml_node<>* pSeedObjectRoot = xFileDoc.first_node(); for ( rapidxml::xml_node<>* pSeedObjectNode = pSeedObjectRoot->first_node(); pSeedObjectNode; pSeedObjectNode = pSeedObjectNode->next_sibling() ) { //种子具体信息 std::string strSeedName = pSeedObjectNode->first_attribute( "ID" )->value(); std::string strConfigID = pSeedObjectNode->first_attribute( "NPCConfigID" )->value(); if (!m_pElementInfoModule->ExistElement(strConfigID)) { assert(0); } NF_SHARE_PTR<SceneSeedResource> pSeedResource = pSeedResourceList->GetElement(strSeedName); if ( !pSeedResource.get() ) { pSeedResource = NF_SHARE_PTR<SceneSeedResource>(NF_NEW SceneSeedResource()); pSeedResourceList->AddElement( strSeedName, pSeedResource ); } pSeedResource->strSeedID = strSeedName; pSeedResource->strConfigID = strConfigID; pSeedResource->fSeedX = boost::lexical_cast<float>(pSeedObjectNode->first_attribute( "SeedX" )->value()); pSeedResource->fSeedY = boost::lexical_cast<float>(pSeedObjectNode->first_attribute( "SeedY" )->value()); pSeedResource->fSeedZ = boost::lexical_cast<float>(pSeedObjectNode->first_attribute( "SeedZ" )->value()); } } } return true; }
bool NFCCommonConfigModule::LoadConfig(const std::string& strFile) { try { rapidxml::file<> xFile(strFile.c_str()); rapidxml::xml_document<> xDoc; xDoc.parse<0>(xFile.data()); rapidxml::xml_node<>* pRoot = xDoc.first_node(); if (NULL == pRoot) { return false; } for (rapidxml::xml_node<>* pRootNode = pRoot->first_node(); pRootNode; pRootNode = pRootNode->next_sibling()) { if (pRootNode) { rapidxml::xml_attribute<>* pNameAttribute = pRootNode->first_attribute("Name"); if (NULL == pNameAttribute) { //foreach continue; } std::string strName = pNameAttribute->value(); NF_SHARE_PTR<CStructInfo> pAppSDKConfigInfo = mmData.GetElement(strName); if (!pAppSDKConfigInfo) { pAppSDKConfigInfo = NF_SHARE_PTR<CStructInfo>(NF_NEW CStructInfo()); mmData.AddElement(strName, pAppSDKConfigInfo); } for (rapidxml::xml_attribute<>* pAttribute = pRootNode->first_attribute(); pAttribute; pAttribute = pAttribute->next_attribute()) { if (pAttribute) { const char* pstrConfigName = pAttribute->name(); const char* pstrConfigValue = pAttribute->value(); pAppSDKConfigInfo->mmStructAttribute.AddElement(pstrConfigName, NF_SHARE_PTR<std::string>(NF_NEW std::string(pstrConfigValue))); } } for (rapidxml::xml_node<>* pSDKInterfaceNode = pRootNode->first_node(); pSDKInterfaceNode; pSDKInterfaceNode = pSDKInterfaceNode->next_sibling()) { if (pSDKInterfaceNode) { if (pSDKInterfaceNode->first_attribute("Name") != NULL) { std::string strStructItemName = pSDKInterfaceNode->first_attribute("Name")->value(); NF_SHARE_PTR<CAttributeList> pConfigData = pAppSDKConfigInfo->GetElement(strStructItemName); if (!pConfigData) { pConfigData = NF_SHARE_PTR<CAttributeList>(NF_NEW CAttributeList()); pAppSDKConfigInfo->AddElement(strStructItemName, pConfigData); } for (rapidxml::xml_attribute<>* pAttribute = pSDKInterfaceNode->first_attribute(); pAttribute; pAttribute = pAttribute->next_attribute()) { if (pAttribute) { const char* pstrConfigName = pAttribute->name(); const char* pstrConfigValue = pAttribute->value(); pConfigData->AddElement(pstrConfigName, NF_SHARE_PTR<std::string>(NF_NEW std::string(pstrConfigValue))); } } } } } } } } catch(...) { return false; } return true; }
const bool NFCObjectSaveModule::LoadDataFormNoSql( const NFIDENTID& self , const std::string& strClassName) { NF_SHARE_PTR<NFIPropertyManager> pProManager = m_pLogicClassModule->GetClassPropertyManager(strClassName); NF_SHARE_PTR<NFIRecordManager> pRecordManager = m_pLogicClassModule->GetClassRecordManager(strClassName); if (!pProManager || !pRecordManager) { return false; } std::vector<std::string> vFieldVec; std::vector<std::string> vValueVec; int nIndex = 0; std::string strName; std::map<std::string, int> xDataIndex; //witch Property Need Load NF_SHARE_PTR<NFIProperty> xProperty = pProManager->First(strName); while (xProperty) { if (xProperty->GetSave()) { vFieldVec.push_back(strName); xDataIndex.insert(std::make_pair(strName, nIndex)); nIndex ++; } strName.clear(); xProperty = pProManager->Next(strName); } //witch Record Need Load NF_SHARE_PTR<NFIRecord> xRecord = pRecordManager->First(strName); while (xRecord) { if (xRecord->GetSave()) { vFieldVec.push_back(strName); xDataIndex.insert(std::make_pair(strName, nIndex)); nIndex ++; } strName.clear(); xRecord = pRecordManager->Next(strName); } if(!m_pClusterSQLModule->Query(strClassName, self.ToString(), vFieldVec, vValueVec)) { return false; } if (vFieldVec.size() != vValueVec.size()) { return false; } NF_SHARE_PTR<NFMapEx<std::string, std::string> > pSelf = mtObjectCache.GetElement(self); if (!pSelf) { pSelf = NF_SHARE_PTR< NFMapEx<std::string, std::string> > (NF_NEW NFMapEx<std::string, std::string>()); if (!mtObjectCache.AddElement(self, pSelf)) { return false; } } for (int i = 0; i< vValueVec.size(); i++) { const std::string& strName = vFieldVec[i]; const std::string& strValue = vValueVec[i]; pSelf->AddElement(strName, NF_SHARE_PTR<std::string>(NF_NEW std::string(strValue))); } return true; }
bool NFCScheduleModule::Execute() { //execute every schedule NF_SHARE_PTR<NFMapEx <std::string, NFCScheduleElement >> xObjectSchedule = mObjectScheduleMap.First(); while (xObjectSchedule) { std::string str; NF_SHARE_PTR<NFCScheduleElement> pSchedule = xObjectSchedule->First(); while (pSchedule) { NFINT64 nNow = NFGetTime(); if (nNow > pSchedule->mnNextTriggerTime) { std::map<NFGUID, std::string>::iterator itRet = mObjectRemoveList.find(pSchedule->self); if (itRet != mObjectRemoveList.end()) { if (itRet->second != pSchedule->mstrScheduleName) { if (pSchedule->mnRemainCount > 0 || pSchedule->mbForever == true) { pSchedule->mnRemainCount--; pSchedule->DoHeartBeatEvent(); if (pSchedule->mnRemainCount <= 0 && pSchedule->mbForever == false) { mObjectRemoveList.insert(std::map<NFGUID, std::string>::value_type(pSchedule->self, pSchedule->mstrScheduleName)); } else { NFINT64 nNextCostTime = NFINT64(pSchedule->mfIntervalTime * 1000) * (pSchedule->mnAllCount - pSchedule->mnRemainCount); pSchedule->mnNextTriggerTime = pSchedule->mnStartTime + nNextCostTime; } } } } } pSchedule = xObjectSchedule->Next(); } xObjectSchedule = mObjectScheduleMap.Next(); } //remove schedule for (std::map<NFGUID, std::string>::iterator it = mObjectRemoveList.begin(); it != mObjectRemoveList.end(); ++it) { NFGUID self = it->first; std::string scheduleName = it->second; auto findIter = mObjectScheduleMap.GetElement(self); if (NULL != findIter) { findIter->RemoveElement(scheduleName); if (findIter->Count() == 0) { mObjectScheduleMap.RemoveElement(self); } } } mObjectRemoveList.clear(); //add schedule for (std::list<NFCScheduleElement>::iterator iter = mObjectAddList.begin(); iter != mObjectAddList.end(); ++iter) { NF_SHARE_PTR< NFMapEx <std::string, NFCScheduleElement >> xObjectScheduleMap = mObjectScheduleMap.GetElement(iter->self); if (NULL == xObjectScheduleMap) { xObjectScheduleMap = NF_SHARE_PTR< NFMapEx <std::string, NFCScheduleElement >>(NF_NEW NFMapEx <std::string, NFCScheduleElement >()); mObjectScheduleMap.AddElement(iter->self, xObjectScheduleMap); } NF_SHARE_PTR<NFCScheduleElement> xScheduleElement = xObjectScheduleMap->GetElement(iter->mstrScheduleName); if (NULL == xScheduleElement) { xScheduleElement = NF_SHARE_PTR<NFCScheduleElement>(NF_NEW NFCScheduleElement()); *xScheduleElement = *iter; xObjectScheduleMap->AddElement(iter->mstrScheduleName, xScheduleElement); } } mObjectAddList.clear(); //////////////////////////////////////////// //execute every schedule NF_SHARE_PTR< NFCScheduleElement > xModuleSchedule = mModuleScheduleMap.First(); while (xModuleSchedule) { NFINT64 nNow = NFGetTime(); if (nNow > xModuleSchedule->mnNextTriggerTime) { if (xModuleSchedule->mnRemainCount > 0 || xModuleSchedule->mbForever == true) { xModuleSchedule->mnRemainCount--; xModuleSchedule->DoHeartBeatEvent(); if (xModuleSchedule->mnRemainCount <= 0 && xModuleSchedule->mbForever == false) { mModuleRemoveList.push_back(xModuleSchedule->mstrScheduleName); } else { NFINT64 nNextCostTime = NFINT64(xModuleSchedule->mfIntervalTime * 1000) * (xModuleSchedule->mnAllCount - xModuleSchedule->mnRemainCount); xModuleSchedule->mnNextTriggerTime = xModuleSchedule->mnStartTime + nNextCostTime; } } } xModuleSchedule = mModuleScheduleMap.Next(); } //remove schedule for (std::list<std::string>::iterator it = mModuleRemoveList.begin(); it != mModuleRemoveList.end(); ++it) { const std::string& strSheduleName = *it;; auto findIter = mModuleScheduleMap.GetElement(strSheduleName); if (NULL != findIter) { mModuleScheduleMap.RemoveElement(strSheduleName); } } mModuleRemoveList.clear(); //add schedule for (std::list<NFCScheduleElement>::iterator iter = mModuleAddList.begin(); iter != mModuleAddList.end(); ++iter) { NF_SHARE_PTR< NFCScheduleElement > xModuleScheduleMap = mModuleScheduleMap.GetElement(iter->mstrScheduleName); if (NULL == xModuleScheduleMap) { xModuleScheduleMap = NF_SHARE_PTR< NFCScheduleElement >(NF_NEW NFCScheduleElement()); mModuleScheduleMap.AddElement(iter->mstrScheduleName, xModuleScheduleMap); } *xModuleScheduleMap = *iter; } mModuleAddList.clear(); return true; }