コード例 #1
0
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;
}
コード例 #2
0
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;
}