bool TmxFile2D::BeginLoad(Deserializer& source) { if (GetName().Empty()) SetName(source.GetName()); loadXMLFile_ = new XMLFile(context_); if (!loadXMLFile_->Load(source)) { URHO3D_LOGERROR("Load XML failed " + source.GetName()); loadXMLFile_.Reset(); return false; } XMLElement rootElem = loadXMLFile_->GetRoot("map"); if (!rootElem) { URHO3D_LOGERROR("Invalid tmx file " + source.GetName()); loadXMLFile_.Reset(); return false; } // If we're async loading, request the texture now. Finish during EndLoad(). if (GetAsyncLoadState() == ASYNC_LOADING) { for (XMLElement tileSetElem = rootElem.GetChild("tileset"); tileSetElem; tileSetElem = tileSetElem.GetNext("tileset")) { // Tile set defined in TSX file if (tileSetElem.HasAttribute("source")) { String source = tileSetElem.GetAttribute("source"); SharedPtr<XMLFile> tsxXMLFile = LoadTSXFile(source); if (!tsxXMLFile) return false; tsxXMLFiles_[source] = tsxXMLFile; String textureFilePath = GetParentPath(GetName()) + tsxXMLFile->GetRoot("tileset").GetChild("image").GetAttribute("source"); GetSubsystem<ResourceCache>()->BackgroundLoadResource<Texture2D>(textureFilePath, true, this); } else { String textureFilePath = GetParentPath(GetName()) + tileSetElem.GetChild("image").GetAttribute("source"); GetSubsystem<ResourceCache>()->BackgroundLoadResource<Texture2D>(textureFilePath, true, this); } } for (XMLElement imageLayerElem = rootElem.GetChild("imagelayer"); imageLayerElem; imageLayerElem = imageLayerElem.GetNext("imagelayer")) { String textureFilePath = GetParentPath(GetName()) + imageLayerElem.GetChild("image").GetAttribute("source"); GetSubsystem<ResourceCache>()->BackgroundLoadResource<Texture2D>(textureFilePath, true, this); } } return true; }
bool SpriteSheet2D::BeginLoadFromXMLFile(Deserializer& source) { loadXMLFile_ = new XMLFile(context_); if (!loadXMLFile_->Load(source)) { URHO3D_LOGERROR("Could not load sprite sheet"); loadXMLFile_.Reset(); return false; } SetMemoryUse(source.GetSize()); XMLElement rootElem = loadXMLFile_->GetRoot("TextureAtlas"); if (!rootElem) { URHO3D_LOGERROR("Invalid sprite sheet"); loadXMLFile_.Reset(); return false; } // If we're async loading, request the texture now. Finish during EndLoad(). loadTextureName_ = GetParentPath(GetName()) + rootElem.GetAttribute("imagePath"); if (GetAsyncLoadState() == ASYNC_LOADING) GetSubsystem<ResourceCache>()->BackgroundLoadResource<Texture2D>(loadTextureName_, true, this); return true; }
bool TmxImageLayer2D::Load(const XMLElement& element, const TileMapInfo2D& info) { LoadInfo(element); XMLElement imageElem = element.GetChild("image"); if (!imageElem) return false; position_ = Vector2(0.0f, info.GetMapHeight()); source_ = imageElem.GetAttribute("source"); String textureFilePath = GetParentPath(tmxFile_->GetName()) + source_; ResourceCache* cache = tmxFile_->GetSubsystem<ResourceCache>(); SharedPtr<Texture2D> texture(cache->GetResource<Texture2D>(textureFilePath)); if (!texture) { URHO3D_LOGERROR("Could not load texture " + textureFilePath); return false; } sprite_ = new Sprite2D(tmxFile_->GetContext()); sprite_->SetTexture(texture); sprite_->SetRectangle(IntRect(0, 0, texture->GetWidth(), texture->GetHeight())); // Set image hot spot at left top sprite_->SetHotSpot(Vector2(0.0f, 1.0f)); if (element.HasChild("properties")) LoadPropertySet(element.GetChild("properties")); return true; }
static int Atomic_GetParentPath(duk_context* ctx) { String path = duk_require_string(ctx, 0); duk_push_string(ctx, GetParentPath(path).CString()); return 1; }
std::string CDirectoryHistory::RemoveParentPath(bool filter /* = false */) { if (m_vecPathHistory.empty()) return ""; std::string strParent = GetParentPath(filter); m_vecPathHistory.pop_back(); return strParent; }
bool FileSystem::FileMove(const String& source, const String& dest) const { String destFolder = GetParentPath(dest); if (!IsFolderExist(destFolder)) FolderCreate(destFolder); return MoveFileA(source.Data(), dest.Data()) == TRUE; }
//初始化连接对象 int Trade_Init(const char *cfgfile, tagTradeCallBackFunc * callbackflist, const char *logpath, char *errmsg, int len) { if (ptrConfig != NULL) { YTConn_DelConfig(ptrConfig); } ptrConfig = YTConn_NewConfig(); if (YTConn_LoadConfig(ptrConfig, cfgfile) < 0) { YTConn_DelConfig(ptrConfig); sprintf_s(errmsg,len,"加载配置文件:%s失败!",cfgfile); return -1; } static tagYTConnCallBackFunc callbackflist1 = {CallBackDataAllRet,CallBackDataPartRet,CallBackTimeOut,CallBackClose}; char path[1021]; memset(path,0,1021); GetParentPath(cfgfile,path); if (YTConn_Init(path,&callbackflist1,logpath) < 0) { YTConn_Release(); return -4; } if (callbackflist == NULL) { strcpy_s(errmsg,len,"没有注册回调函数!"); return -2; } //记录客户注册的回调函数 pFuncList = callbackflist; /*m_mapFuncList.insert(std::make_pair(0,callbackflist->Func_TradeCallBackStatus)); m_mapFuncList.insert(std::make_pair(LOGIN,callbackflist->Func_TradeAnsLogin)); m_mapFuncList.insert(std::make_pair(QURELATED,callbackflist->Func_TradeAnsQuRelated)); m_mapFuncList.insert(std::make_pair(QUAMOUNT,callbackflist->Func_TradeAnsQuAmount)); m_mapFuncList.insert(std::make_pair(QUUNFINISHENTRUST, callbackflist->Func_TradeAnsQuUnFinishEntrust)); m_mapFuncList.insert(std::make_pair(QULOG,callbackflist->Func_TradeAnsQuLog)); m_mapFuncList.insert(std::make_pair(QUPOSITION,callbackflist->Func_TradeAnsQuPosition)); m_mapFuncList.insert(std::make_pair(QUBARGAIN,callbackflist->Func_TradeAnsQuBargain)); m_mapFuncList.insert(std::make_pair(QUCOLLECTBARGAIN,callbackflist->Func_TradeAnsQuCollectBargain)); m_mapFuncList.insert(std::make_pair(ENTRUST,callbackflist->Func_TradeAnsEntrust)); m_mapFuncList.insert(std::make_pair(DISENTRUST,callbackflist->Func_TradeAnsDisEntrust)); m_mapFuncList.insert(std::make_pair(DISLASTENTRUST,callbackflist->Func_TradeAnsDisLastEntrust)); m_mapFuncList.insert(std::make_pair(DISALLENTRUST,callbackflist->Func_TradeAnsDisAllEntrust));*/ //YTConn_CallBackDataAllRet(CallBackDataAllRet); //YTConn_CallBackDataPartRet(CallBackDataPartRet); //YTConn_CallBackTimeOut(CallBackTimeOut); //YTConn_CallBackClose(CallBackClose); InitializeCriticalSection(&secLock ); return 0; }
void CDlgController::OpenFile(const std::wstring& wstrFilename) { if (IOReadBase::Exists(ws2s(wstrFilename))) { OpenPath(GetParentPath(wstrFilename),s2ws(CRenderNodeMgr::getInstance().getDataPlugsMgr().getAllExtensions())); //m_ListBoxFolder.SetSelec() //GetFilename(wstrFilename) CMainRoot::getInstance().getMainDialog().getModelDisplay().LoadModel(ws2s(wstrFilename)); CMainRoot::getInstance().getMainDialog().getDlgModelController().OnUpdate(); } }
SharedPtr<XMLFile> TmxFile2D::LoadTSXFile(const String& source) { String tsxFilePath = GetParentPath(GetName()) + source; SharedPtr<File> tsxFile = GetSubsystem<ResourceCache>()->GetFile(tsxFilePath); SharedPtr<XMLFile> tsxXMLFile(new XMLFile(context_)); if (!tsxFile || !tsxXMLFile->Load(*tsxFile)) { URHO3D_LOGERROR("Load TSX file failed " + tsxFilePath); return SharedPtr<XMLFile>(); } return tsxXMLFile; }
//--------------------------------------------------------------------- // UpdateFileSystemObjectName(): //--------------------------------------------------------------------- void WPDIRECTORY::UpdateFileSystemObjectName(char *szNewTitle) { char szFullPath[_MAX_PATH+1]; // Create new path using this directory's parent and the new name. sprintf(szFullPath,"%s\\%s",GetParentPath(),szNewTitle); // Change the program's name to the newly specified one. SetPath(szFullPath); // If directory folder is currently open,... if (isOpen()) // "Reopen" again since this will refresh the file list again with new path. Open(); }
bool C4ScriptHost::ReloadScript(const char *szPath, const char *szLanguage) { // this? if (SEqualNoCase(szPath, ComponentHost.GetFilePath()) || (stringTable && SEqualNoCase(szPath, stringTable->GetFilePath()))) { // try reload char szParentPath[_MAX_PATH + 1]; C4Group ParentGrp; if (GetParentPath(szPath, szParentPath)) if (ParentGrp.Open(szParentPath)) if (Load(ParentGrp, NULL, szLanguage, stringTable)) return true; } return false; }
bool IOReadPak::Open(const std::string& strFilename, const std::string& strArchive) { Close(); std::string strPak; std::string strFile = GetFilename(strFilename); std::string strPakFilename = GetParentPath(strFilename); while (strPakFilename.length()>0) { std::string strPakName = GetFilename(strPakFilename); strPakFilename = GetParentPath(strPakFilename); strPak = strPakFilename+strPakName+".pak"; if (openPak(strPak)) { if (openFile(strFile)) { return true; } Close(); } strFile.insert(0,strPakName+"\\"); } return false; }
void GreenChrome() { // exe路径 wchar_t exePath[MAX_PATH]; GetModuleFileNameW(NULL, exePath, MAX_PATH); // exe所在文件夹 wchar_t exeFolder[MAX_PATH]; wcscpy(exeFolder, exePath); PathRemoveFileSpecW(exeFolder); // 生成默认ini文件 wchar_t iniPath[MAX_PATH]; ReleaseIni(exeFolder, iniPath); // 读取配置 ReadConfig(iniPath); // 启动单次功能 bool first_run = OnceFeature(iniPath); // 自定义用户数据目录 CustomUserData(iniPath); // 打造便携版chrome MakePortable(iniPath); // 给resources.pak打补丁 PatchResourcesPak(iniPath); // 标签页,书签,地址栏增强 TabBookmark(); // 父进程不是Chrome,则需要启动追加参数功能 wchar_t parentPath[MAX_PATH]; if (GetParentPath(parentPath)) { if (PathFileExistsW(parentPath) && _wcsicmp(parentPath, exePath) != 0) { CustomCommand(iniPath, exeFolder, exePath, first_run); } } else { DebugLog(L"GetParentPath failed"); } }
bool C4Shader::Refresh(const char *szWhat, const char **szUniforms) { // Find a slice where the source file has updated ShaderSliceList::iterator pSlice; for (pSlice = FragmentSlices.begin(); pSlice != FragmentSlices.end(); pSlice++) if (pSlice->Source.getLength() && FileExists(pSlice->Source.getData()) && FileTime(pSlice->Source.getData()) > pSlice->SourceTime) break; if (pSlice == FragmentSlices.end()) return true; StdCopyStrBuf Source = pSlice->Source; // Okay, remove all slices that came from this file ShaderSliceList::iterator pNext; for (; pSlice != FragmentSlices.end(); pSlice = pNext) { pNext = pSlice; pNext++; if (SEqual(pSlice->Source.getData(), Source.getData())) FragmentSlices.erase(pSlice); } // Load new shader char szParentPath[_MAX_PATH+1]; C4Group Group; StdStrBuf Shader; GetParentPath(Source.getData(),szParentPath); if(!Group.Open(szParentPath) || !Group.LoadEntryString(GetFilename(Source.getData()),&Shader) || !Group.Close()) { ShaderLogF(" gl: Failed to refresh %s shader from %s!", szWhat, Source.getData()); return Refresh(szWhat, szUniforms); } // Load slices int iSourceTime = FileTime(Source.getData()); StdStrBuf WhatSrc = FormatString("file %s", Config.AtRelativePath(Source.getData())); AddFragmentSlices(WhatSrc.getData(), Shader.getData(), Source.getData(), iSourceTime); // Reinitialise if (!Init(szWhat, szUniforms)) return false; // Retry return Refresh(szWhat, szUniforms); }
STDMETHOD(Open)(THIS_ D3DXINCLUDE_TYPE IncludeType, LPCSTR pFileName, LPCVOID pParentData, LPCVOID *ppData, UINT *pBytes) { std::string strFilename = GetParentPath(m_strParentFilename)+pFileName; IOReadBase* pRead = IOReadBase::autoOpen(strFilename); if (pRead) { size_t uFilesize = pRead->GetSize(); char* pBuf = new char[uFilesize]; if (pBuf) { pRead->Read(pBuf, uFilesize); *ppData = pBuf; *pBytes = uFilesize; } IOReadBase::autoClose(pRead); } return S_OK; }
void C4PortraitSelDlg::ListItem::Load() { if (sFilename) { // safety fLoaded = false; // load image file C4Group SrcGrp; StdStrBuf sParentPath; GetParentPath(sFilename.getData(), &sParentPath); bool fLoadError = true; if (SrcGrp.Open(sParentPath.getData())) if (fctLoadedImage.Load(SrcGrp, ::GetFilename(sFilename.getData()))) { // image loaded. Can only be put into facet by main thread, because // those operations aren't thread safe fLoaded = true; fLoadError = false; } SrcGrp.Close(); fError = fLoadError; } }
String ResourceCache::GetPreferredResourceDir(const String& path) const { String fixedPath = AddTrailingSlash(path); bool pathHasKnownDirs = false; bool parentHasKnownDirs = false; FileSystem* fileSystem = GetSubsystem<FileSystem>(); // If no filesystem, can not check directory existence, so just return the original path if (!fileSystem) return fixedPath; for (unsigned i = 0; !checkDirs[i].Empty(); ++i) { if (fileSystem->DirExists(fixedPath + checkDirs[i])) { pathHasKnownDirs = true; break; } } if (!pathHasKnownDirs) { String parentPath = GetParentPath(fixedPath); for (unsigned i = 0; !checkDirs[i].Empty(); ++i) { if (fileSystem->DirExists(parentPath + checkDirs[i])) { parentHasKnownDirs = true; break; } } // If path does not have known subdirectories, but the parent path has, use the parent instead if (parentHasKnownDirs) fixedPath = parentPath; } return fixedPath; }
void CDlgController::OnListBoxFolderItemDblClk() { std::wstring wstrFolder = m_ListBoxFolder.GetSelectedItem()->wstrText; if (wstrFolder.length()>0&&wstrFolder[0]==L'\\') { if (L"\\.."==wstrFolder) { OpenPath(GetParentPath(m_wstrPath),m_wstrFileType); } else { OpenPath(m_wstrPath+wstrFolder.substr(1)+L'\\',m_wstrFileType); } } else { // write the recent path to reg. SetRegStr(L"software\\rpgsky\\modelview\\",L"recentpath",m_wstrPath.c_str()); std::string strFilename = ws2s(m_wstrPath+m_ListBoxFolder.GetSelectedItem()->wstrText); CMainRoot::getInstance().getMainDialog().getModelDisplay().LoadModel( strFilename ); CMainRoot::getInstance().getMainDialog().getDlgModelController().OnUpdate(); } }
bool SpriteSheet2D::BeginLoadFromPListFile(Deserializer& source) { loadPListFile_ = new PListFile(context_); if (!loadPListFile_->Load(source)) { URHO3D_LOGERROR("Could not load sprite sheet"); loadPListFile_.Reset(); return false; } SetMemoryUse(source.GetSize()); const PListValueMap& root = loadPListFile_->GetRoot(); const PListValueMap& metadata = root["metadata"]->GetValueMap(); const String& textureFileName = metadata["realTextureFileName"]->GetString(); // If we're async loading, request the texture now. Finish during EndLoad(). loadTextureName_ = GetParentPath(GetName()) + textureFileName; if (GetAsyncLoadState() == ASYNC_LOADING) GetSubsystem<ResourceCache>()->BackgroundLoadResource<Texture2D>(loadTextureName_, true, this); return true; }
bool CMyPlug::importSceneTerrainData(iRenderNode* pRenderNode, iSceneData* pSceneData, const char* szFilename) { importTerrainData(pSceneData,szFilename); const char* szTerrainMaterial[30][2]={ {"TileGrass01.ozj","terrainTileX4"}, {"TileGrass02.ozj","terrainTileX2"}, {"TileGround01.ozj","terrainTileX4"}, {"TileGround02.ozj","terrainTileX2"}, {"TileGround03.ozj","terrainTileX2"}, {"TileWater01.ozj","terrainWater"}, {"TileWood01.ozj","terrainTileX2"}, {"TileRock01.ozj","terrainTileX2"}, {"TileRock02.ozj","terrainTileX2"}, {"TileRock03.ozj","terrainTileX2"}, {"TileRock04.ozj","terrainTileX2"}, {"TileRock05.ozj","terrainTileX2"}, {"TileRock06.ozj","terrainTileX2"}, {"TileRock07.ozj","terrainTileX2"}, {"TileRock08.ozj","terrainTileX2"}, {"TileGrass01.ozj","terrainTileAlphaX4"}, {"TileGrass02.ozj","terrainTileAlphaX2"}, {"TileGround01.ozj","terrainTileAlphaX4"}, {"TileGround02.ozj","terrainTileAlphaX2"}, {"TileGround03.ozj","terrainTileAlphaX2"}, {"TileWater01.ozj","terrainWaterAlpha"}, {"TileWood01.ozj","terrainTileAlphaX2"}, {"TileRock01.ozj","terrainTileAlphaX2"}, {"TileRock02.ozj","terrainTileAlphaX2"}, {"TileRock03.ozj","terrainTileAlphaX2"}, {"TileRock04.ozj","terrainTileAlphaX2"}, {"TileRock05.ozj","terrainTileAlphaX2"}, {"TileRock06.ozj","terrainTileAlphaX2"}, {"TileRock07.ozj","terrainTileAlphaX2"}, {"TileRock08.ozj","terrainTileAlphaX2"} }; CMaterial mat; // ---- // # Create Grasses // ---- for (int startY=0; startY<pSceneData->getHeight(); startY+=16) { for (int startX=0; startX<pSceneData->getWidth(); startX+=16) { int nWidth = min(pSceneData->getWidth()-startX,16); int nHeight = min(pSceneData->getHeight()-startY,16); int nEndX = startX+nWidth; int nEndY = startY+nHeight; char szMeshName[256]; // sprintf(szMeshName,"%s_%d_%d",szFilename,startX,startY); iMeshData* pMesh = (iMeshData*)m_pRenderNodeMgr->createRenderData("mesh",szMeshName); BBox bbox; std::vector<RigidNolightVertex>& setVertices = pMesh->getRigidNolightVertices(); // ---- // # Ground // ---- for (int y=startY; y<=nEndY; ++y) { for (int grassX=startX; grassX<=nEndX; ++grassX) { RigidNolightVertex vertex; float fHeight = pSceneData->getVertexHeight(grassX,y); Vec3D vNormal = pSceneData->getVertexNormal(grassX,y); Color32 color = pSceneData->getVertexColor(grassX,y); bbox.vMin.y = min(fHeight,bbox.vMin.y); bbox.vMax.y = max(fHeight,bbox.vMax.y); /*Vec3D vBinormal = vertex.n.cross(Vec3D(0,0,1)).normalize(); Vec3D vTangent = Vec3D(1,0,0).cross(vertex.n).normalize(); Matrix mTangent; mTangent.Zero(); mTangent._11=vBinormal.x; mTangent._21=vBinormal.y; mTangent._31=vBinormal.z; mTangent._12=vertex.n.x; mTangent._22=vertex.n.y; mTangent._32=vertex.n.z; mTangent._13=vTangent.x; mTangent._23=vTangent.y; mTangent._33=vTangent.z; vertex.n = mTangent*GetLightDir(); vertex.n=vertex.n.normalize();*/ vertex.p.set( (float)grassX, fHeight, (float)y ); vertex.n = vNormal; vertex.c = color; vertex.uv.set( (float)grassX,(float)y ); setVertices.push_back(vertex); } } // ---- std::map<unsigned char,std::vector<int>> mapLayer[2]; int i=0; for (int y=startY; y<nEndY; ++y) { for (int grassX=startX; grassX<nEndX; ++grassX) { unsigned char title0 = pSceneData->getCellTileID(grassX,y,0); unsigned char title1 = pSceneData->getCellTileID(grassX,y,1); //TerrainCell& cell = *m_pTerrainData->getCell(x,y); //if ((cell.uAttribute&0x8)==0)// ͸Ã÷ if (title0!=0xFF)// ͸Ã÷ { mapLayer[0][title0].push_back(i); } if (title1!=0xFF)// ͸Ã÷ { mapLayer[1][title1].push_back(i); } i++; } i++; } // ---- IndexedSubset subset; for (int nLayer=0;nLayer<2;++nLayer) { for (auto it= mapLayer[nLayer].begin(); it!=mapLayer[nLayer].end(); ++it) { // ---- // # Subset // ---- subset.vstart = 0; subset.vbase = 0; subset.istart += subset.icount; subset.vcount = setVertices.size(); subset.icount = it->second.size()*6; pMesh->getSubsets().push_back(subset); // ---- // # Material // ---- char szTexture[256]; sprintf(szTexture,"%s%s",GetParentPath(szFilename).c_str(),szTerrainMaterial[it->first+nLayer*15][0]); mat.strTexture[0] = szTexture; mat.strShader = szTerrainMaterial[it->first+nLayer*15][1]; pMesh->getMaterials().resize(pMesh->getSubsets().size()); pMesh->getMaterials()[pMesh->getSubsets().size()-1].push_back(mat); // ---- // # Indices // ---- for (auto it2=it->second.begin(); it2!=it->second.end(); ++it2) { // 1 2 // *---* // | / | // *---* // 0 3 int i = *it2; pMesh->getIndices().push_back(i); pMesh->getIndices().push_back(i+nWidth+1); pMesh->getIndices().push_back(i+nWidth+2); pMesh->getIndices().push_back(i); pMesh->getIndices().push_back(i+nWidth+2); pMesh->getIndices().push_back(i+1); } } } // ---- // # Grass // ---- for (int y=startY; y<nEndY; ++y) { for (int x=startX; x<nEndX; ++x) { if (pSceneData->hasGrass(x,y)) { float fHeight1 = pSceneData->getVertexHeight(x,y); float fHeight2 = pSceneData->getVertexHeight(x+1,y+1); Vec3D vNormal1 = pSceneData->getVertexNormal(x,y); Vec3D vNormal2 = pSceneData->getVertexNormal(x+1,y+1); Color32 color1 = pSceneData->getVertexColor(x,y); Color32 color2 = pSceneData->getVertexColor(x+1,y+1); int nRand = (((y*(pSceneData->getWidth()+1)+x+x*y)*214013L+2531011L)>>16)&0x7fff; float fTexU = (nRand%4)*0.25f; RigidNolightVertex vertex; vertex.p.set( (float)x, fHeight1, (float)y ); vertex.n = vNormal1; vertex.c = color1; vertex.uv.set( (float)fTexU,1.0f ); setVertices.push_back(vertex); vertex.p.set( (float)x, fHeight1+1.5f, (float)y ); vertex.n = vNormal1; vertex.c = color1; vertex.uv.set( (float)fTexU,0.0f ); setVertices.push_back(vertex); vertex.p.set( (float)(x+1), fHeight2+1.5f, (float)(y+1) ); vertex.n = vNormal2; vertex.c = color2; vertex.uv.set( (float)fTexU+0.25f,0.0f ); setVertices.push_back(vertex); vertex.p.set( (float)(x+1), fHeight2, (float)(y+1) ); vertex.n = vNormal2; vertex.c = color2; vertex.uv.set( (float)fTexU+0.25f,1.0f ); setVertices.push_back(vertex); bbox.vMin.x = min((float)x,bbox.vMin.x); bbox.vMin.y = min(fHeight1,bbox.vMin.y); bbox.vMin.z = min((float)y,bbox.vMin.z); bbox.vMax.x = max((float)(x+1),bbox.vMax.x); bbox.vMax.y = max(fHeight2+1.5f,bbox.vMax.y); bbox.vMax.z = max((float)(y+1),bbox.vMax.z); // 1 2 // *---* // | / | // *---* // 0 3 int i = setVertices.size()-4; pMesh->getIndices().push_back(i); pMesh->getIndices().push_back(i+1); pMesh->getIndices().push_back(i+2); pMesh->getIndices().push_back(i); pMesh->getIndices().push_back(i+2); pMesh->getIndices().push_back(i+3); } } } // ---- // # Subset // ---- subset.vstart = 0; subset.vbase = 0; subset.istart += subset.icount; subset.vcount = setVertices.size(); subset.icount = pMesh->getIndices().size()-subset.istart; pMesh->getSubsets().push_back(subset); // ---- // # Material // ---- char szGrassTexture[256]; sprintf(szGrassTexture,"%s%s",GetParentPath(szFilename).c_str(),"TileGrass01.OZT"); mat.strTexture[0] = szGrassTexture; mat.strShader = "terrainGrass"; pMesh->getMaterials().resize(pMesh->getSubsets().size()); pMesh->getMaterials()[pMesh->getSubsets().size()-1].push_back(mat); // ---- // # Box // ---- bbox.vMin.x = (float)startX; bbox.vMin.z = (float)startY; bbox.vMax.x = (float)(nEndX); bbox.vMax.z = (float)(nEndY); pMesh->setBBox(bbox); iRenderNode* pMeshNode = m_pRenderNodeMgr->createRenderNode("mesh"); if (pMeshNode) { pMeshNode->setLocalBBox(bbox); pMeshNode->setData(pMesh); pRenderNode->addChild(pMeshNode); } //---- } }
bool TmxFile2D::LoadTileSet(const XMLElement& element) { int firstgid = element.GetInt("firstgid"); XMLElement tileSetElem; if (element.HasAttribute("source")) { String source = element.GetAttribute("source"); HashMap<String, SharedPtr<XMLFile> >::Iterator i = tsxXMLFiles_.Find(source); if (i == tsxXMLFiles_.End()) { SharedPtr<XMLFile> tsxXMLFile = LoadTSXFile(source); if (!tsxXMLFile) return false; // Add to napping to avoid release tsxXMLFiles_[source] = tsxXMLFile; tileSetElem = tsxXMLFile->GetRoot("tileset"); } else tileSetElem = i->second_->GetRoot("tileset"); } else tileSetElem = element; XMLElement imageElem = tileSetElem.GetChild("image"); String textureFilePath = GetParentPath(GetName()) + imageElem.GetAttribute("source"); ResourceCache* cache = GetSubsystem<ResourceCache>(); SharedPtr<Texture2D> texture(cache->GetResource<Texture2D>(textureFilePath)); if (!texture) { URHO3D_LOGERROR("Could not load texture " + textureFilePath); return false; } tileSetTextures_.Push(texture); int tileWidth = tileSetElem.GetInt("tilewidth"); int tileHeight = tileSetElem.GetInt("tileheight"); int spacing = tileSetElem.GetInt("spacing"); int margin = tileSetElem.GetInt("margin"); int imageWidth = imageElem.GetInt("width"); int imageHeight = imageElem.GetInt("height"); // Set hot spot at left bottom Vector2 hotSpot(0.0f, 0.0f); if (tileSetElem.HasChild("tileoffset")) { XMLElement offsetElem = tileSetElem.GetChild("tileoffset"); hotSpot.x_ += offsetElem.GetFloat("x") / (float)tileWidth; hotSpot.y_ += offsetElem.GetFloat("y") / (float)tileHeight; } int gid = firstgid; for (int y = margin; y + tileHeight <= imageHeight - margin; y += tileHeight + spacing) { for (int x = margin; x + tileWidth <= imageWidth - margin; x += tileWidth + spacing) { SharedPtr<Sprite2D> sprite(new Sprite2D(context_)); sprite->SetTexture(texture); sprite->SetRectangle(IntRect(x, y, x + tileWidth, y + tileHeight)); sprite->SetHotSpot(hotSpot); gidToSpriteMapping_[gid++] = sprite; } } for (XMLElement tileElem = tileSetElem.GetChild("tile"); tileElem; tileElem = tileElem.GetNext("tile")) { if (tileElem.HasChild("properties")) { SharedPtr<PropertySet2D> propertySet(new PropertySet2D()); propertySet->Load(tileElem.GetChild("properties")); gidToPropertySetMapping_[firstgid + tileElem.GetInt("id")] = propertySet; } } return true; }
bool CMyPlug::importData(iModelData * pModelData, const std::string& strFilename) { assert(pModelData); // Loading the mesh. IOReadBase* pRead = IOReadBase::autoOpen(strFilename); if (!pRead) { return false; } // header readHeader(pRead); // mesh if (!pRead->IsEof()) { unsigned short streamID; unsigned int uLength; pRead->Read(&streamID,sizeof(unsigned short)); pRead->Read(&uLength,sizeof(unsigned int)); switch (streamID) { case M_MESH: { readMesh(pRead,pModelData); break; } } } // close file IOReadBase::autoClose(pRead); // Loading the materials. if (!readMaterial(pModelData,ChangeExtension(strFilename,".material"))) { std::string strMatFilename = GetParentPath(strFilename); strMatFilename=strMatFilename+GetFilename(strMatFilename)+".material"; if (!readMaterial(pModelData,strMatFilename)) { strMatFilename=ChangeExtension(strMatFilename,"_tileset.material"); readMaterial(pModelData,strMatFilename); } } // mesh update pModelData->getMesh().update(); // //m_bbox = mesh.getBBox(); // std::string strMyPath ="Data\\"+GetFilename(GetParentPath(strFilename))+"\\"; // std::string strMatFilename = ChangeExtension(strFilename,".mat.csv"); // std::string strParFilename = ChangeExtension(strFilename,".par.csv"); // if (!IOReadBase::Exists(strMatFilename)) // { // strMatFilename=strMyPath+ChangeExtension(GetFilename(strFilename),".mat.csv"); // } // if (!IOReadBase::Exists(strParFilename)) // { // strParFilename=strMyPath+ChangeExtension(GetFilename(strFilename),".par.csv"); // } // // pModelData->loadMaterial(strMatFilename); // pModelData->loadParticleEmitters(strParFilename); return true; }
bool readMaterialTexture(CMaterial& material, IOReadBase* pRead, const std::string& strFilename) { std::string strCommand; std::vector<std::string> setWords; strCommand = getLineCommand(pRead,setWords); if ("{"!=strCommand) { return false; } std::string strTexture; bool bAdd = false; while (!pRead->IsEof()) { strCommand = getLineCommand(pRead,setWords); if ("texture"==strCommand) { if (setWords.size()>0) { strTexture=GetParentPath(strFilename)+setWords[0]; strTexture = ChangeExtension(strTexture,".dds"); } } else if ("colour_op"==strCommand) { if (setWords.size()>0) { if ("add"==setWords[0]) { bAdd = true; } } } else if ("scroll_anim"==strCommand) { if (setWords.size()==2) { material.vTexAnim.x=atof(setWords[0].c_str()); material.vTexAnim.y=atof(setWords[1].c_str()); } } else if ("}"==strCommand) { break; } else { MessageBoxA(NULL,strCommand.c_str(),"Unknon in texture_unit!",0); } } if (strTexture.length()>0) { if (bAdd) { //material.setEmissive(strTexture); material.setTexture(0,strTexture.c_str()); } else { material.setTexture(0,strTexture.c_str()); } } return true; }
bool CMyPlug::importTerrainData(iSceneData * pSceneData, const std::string& strFilename) { pSceneData->clear(); if (pSceneData->resize(253,253)) { // EncTerrain IOReadBase* pRead = IOReadBase::autoOpen(strFilename); if (pRead) { if (MAP_FILE_SIZE==pRead->GetSize()) { char buffer[MAP_FILE_SIZE]; pRead->Read(buffer,MAP_FILE_SIZE); decrypt(buffer,MAP_FILE_SIZE); char* p = buffer; unsigned short uMuFlgMap = *((unsigned short*)p); p+=2; for (int y=0; y<253; ++y) { for (int x=0; x<253; ++x) { pSceneData->setCellTileID(x,y,*p,0); p++; } p+=3; } p+=256*3; for (int y=0; y<253; ++y) { for (int x=0; x<253; ++x) { pSceneData->setCellTileID(x,y,*p,1); p++; } p+=3; } p+=256*3; for (int y=0; y<254; ++y) { for (int x=0; x<254; ++x) { pSceneData->setVertexColor(x,y,Color32(*p,255,255,255)); p++; } p+=2; } } IOReadBase::autoClose(pRead); } // EncTerrain.att pRead = IOReadBase::autoOpen(ChangeExtension(strFilename,".att")); if (pRead) { if (ATT_FILE_129KB_SIZE==pRead->GetSize()) { char buffer[ATT_FILE_129KB_SIZE]; pRead->Read(buffer,ATT_FILE_129KB_SIZE); decrypt(buffer,ATT_FILE_129KB_SIZE); decrypt2(buffer,ATT_FILE_129KB_SIZE); char* p = buffer; unsigned long uMuFlgAtt = *((unsigned long*)p); p+=4; for (int y=0; y<253; ++y) { for (int x=0; x<253; ++x) { pSceneData->setCellAttribute(x,y,*p); p+=2; } p+=6; } } else if (ATT_FILE_65KB_SIZE==pRead->GetSize()) { char buffer[ATT_FILE_65KB_SIZE]; pRead->Read(buffer,ATT_FILE_65KB_SIZE); decrypt(buffer,ATT_FILE_65KB_SIZE); decrypt2(buffer,ATT_FILE_65KB_SIZE); char* p = buffer; unsigned long uMuFlgAtt = *((unsigned long*)p); p+=4; for (int y=0; y<253; ++y) { for (int x=0; x<253; ++x) { pSceneData->setCellAttribute(x,y,*p); p++; } p+=3; } } IOReadBase::autoClose(pRead); } // TerrainHeight std::string strHeightFilename = GetParentPath(strFilename)+"TerrainHeight.ozb"; pRead = IOReadBase::autoOpen(strHeightFilename); if (pRead) { if (HEIGHT_HEAD_SIZE+HEIGHT_BUFFER_SIZE<=pRead->GetSize()) { pRead->Move(HEIGHT_HEAD_SIZE); for (int y=0; y<254; ++y) { pRead->Move(2); for (int x=0; x<254; ++x) { unsigned char uVal; pRead->Read(&uVal,1); pSceneData->setVertexHeight(x,y,uVal*0.015f); } } } IOReadBase::autoClose(pRead); } } return true; }
bool SpriteSheet2D::Load(Deserializer& source) { spriteMapping_.Clear(); SharedPtr<XMLFile> xmlFile(new XMLFile(context_)); if(!xmlFile->Load(source)) { LOGERROR("Could not load sprite sheet"); return false; } SetMemoryUse(source.GetSize()); XMLElement rootElem = xmlFile->GetRoot(); if (!rootElem) { LOGERROR("Invalid sprite sheet"); return false; } if (rootElem.GetName() == "spritesheet") { ResourceCache* cache = GetSubsystem<ResourceCache>(); String textureFileName = rootElem.GetAttribute("texture"); texture_ = cache->GetResource<Texture2D>(textureFileName, false); // If texture not found, try get in current directory if (!texture_) texture_ = cache->GetResource<Texture2D>(GetParentPath(GetName()) + textureFileName); if (!texture_) { LOGERROR("Cound not load texture"); return false; } XMLElement spriteElem = rootElem.GetChild("sprite"); while (spriteElem) { String name = spriteElem.GetAttribute("name"); IntRect rectangle = spriteElem.GetIntRect("rectangle"); Vector2 hotSpot(0.5f, 0.5f); if (spriteElem.HasAttribute("hotspot")) hotSpot = spriteElem.GetVector2("hotspot"); DefineSprite(name, rectangle, hotSpot); spriteElem = spriteElem.GetNext("sprite"); } } // Sparrow Starling texture atlas else if (rootElem.GetName() == "TextureAtlas") { String textureFileName = rootElem.GetAttribute("imagePath"); ResourceCache* cache = GetSubsystem<ResourceCache>(); texture_ = cache->GetResource<Texture2D>(textureFileName, false); // If texture not found, try get in current directory if (!texture_) texture_ = cache->GetResource<Texture2D>(GetParentPath(GetName()) + textureFileName); if (!texture_) { LOGERROR("Cound not load texture"); return false; } XMLElement subTextureElem = rootElem.GetChild("SubTexture"); while (subTextureElem) { String name = subTextureElem.GetAttribute("name"); int x = subTextureElem.GetInt("x"); int y = subTextureElem.GetInt("y"); int width = subTextureElem.GetInt("width"); int height = subTextureElem.GetInt("height"); IntRect rectangle(x, y, x + width, y + height); Vector2 hotSpot(0.5f, 0.5f); if (subTextureElem.HasAttribute("frameWidth") && subTextureElem.HasAttribute("frameHeight")) { int frameX = subTextureElem.GetInt("frameX"); int frameY = subTextureElem.GetInt("frameY"); int frameWidth = subTextureElem.GetInt("frameWidth"); int frameHeight = subTextureElem.GetInt("frameHeight"); hotSpot.x_ = ((float)frameX + frameWidth / 2) / width; hotSpot.y_ = 1.0f - ((float)frameY + frameHeight / 2) / height; } DefineSprite(name, rectangle, hotSpot); subTextureElem = subTextureElem.GetNext("SubTexture"); } } else { LOGERROR("Invalid sprite sheet file"); return false; } return true; }
CMsArchiveImpl(CArchiveObject* newobj, CMsArchiveImpl* parent) : m_obj(newobj) { m_pPath = parent->m_pPath; m_ParentPath = GetParentPath(); }
C4Group *C4GroupSet::RegisterParentFolders(const char *szScenFilename) { // the scenario filename may be a scenario or directly a group folder C4Group *pParentGroup=nullptr; bool fParentC4F; char szParentfolder[_MAX_PATH+1]; if (SEqualNoCase(GetExtension(szScenFilename), "ocf")) { fParentC4F = true; SCopy(szScenFilename, szParentfolder, _MAX_PATH); } else { GetParentPath(szScenFilename,szParentfolder); fParentC4F = SEqualNoCase(GetExtension(szParentfolder), "ocf"); } if (fParentC4F) { // replace all (back)slashes with zero-fields int32_t iOriginalLen=SLen(szParentfolder); for (int32_t i=0; i<iOriginalLen; ++i) if (szParentfolder[i]==DirectorySeparator || szParentfolder[i]=='/') szParentfolder[i]=0; // trace back until the file extension is no more .ocf int32_t iPos=iOriginalLen-1; while (iPos) { // ignore additional zero fields (double-backslashes) while (iPos && !szParentfolder[iPos]) --iPos; // break if end has been reached if (!iPos) break; // trace back until next zero field while (iPos && szParentfolder[iPos]) --iPos; // check extension of this folder if (!SEqualNoCase(GetExtension(szParentfolder+iPos+1), "ocf", 3)) break; // continue } // trace backwards, putting the (back)slashes in place again if (iPos) { szParentfolder[iPos+1+SLen(szParentfolder+iPos+1)]=szParentfolder[iPos]=DirectorySeparator; while (iPos--) if (!szParentfolder[iPos]) szParentfolder[iPos]=DirectorySeparator; ++iPos; } // trace forward again, opening all folders (iPos is 0 again) int32_t iGroupIndex=0; while (iPos<iOriginalLen) { // ignore additional zero-fields while (iPos<iOriginalLen && !szParentfolder[iPos]) ++iPos; // break if end has been reached if (iPos>=iOriginalLen) break; // open this folder C4Group *pGroup = new C4Group(); if (pParentGroup) { if (!pGroup->OpenAsChild(pParentGroup, szParentfolder+iPos)) { LogFatal(FormatString("%s: %s", LoadResStr("IDS_PRC_FILENOTFOUND"), szParentfolder+iPos).getData()); delete pGroup; return nullptr; } } else if (!Reloc.Open(*pGroup, szParentfolder+iPos)) { LogFatal(FormatString("%s: %s", LoadResStr("IDS_PRC_FILENOTFOUND"), szParentfolder+iPos).getData()); delete pGroup; return nullptr; } // set this group as new parent pParentGroup=pGroup; // add to group set, if this is a true scenario folder int32_t iContentsMask; if (WildcardMatch(C4CFN_FolderFiles, pParentGroup->GetName())) iContentsMask = C4GSCnt_Folder; else iContentsMask = C4GSCnt_Directory; if (!RegisterGroup(*pParentGroup, true, C4GSPrio_Folder+iGroupIndex++, iContentsMask)) { delete pParentGroup; LogFatal ("RegGrp: internal error"); return nullptr; } // advance by file name length iPos+=SLen(szParentfolder+iPos); } } return pParentGroup; }
bool ParticleEffect2D::BeginLoad(Deserializer& source) { loadSpriteName_.Clear(); XMLFile xmlFile(context_); if (!xmlFile.Load(source)) return false; XMLElement rootElem = xmlFile.GetRoot("particleEmitterConfig"); if (!rootElem) return false; String texture = rootElem.GetChild("texture").GetAttribute("name"); loadSpriteName_ = GetParentPath(GetName()) + texture; // If async loading, request the sprite beforehand if (GetAsyncLoadState() == ASYNC_LOADING) GetSubsystem<ResourceCache>()->BackgroundLoadResource<Sprite2D>(loadSpriteName_, true, this); sourcePositionVariance_ = ReadVector2(rootElem, "sourcePositionVariance"); speed_ = ReadFloat(rootElem, "speed"); speedVariance_ = ReadFloat(rootElem, "speedVariance"); particleLifeSpan_ = Max(0.01f, ReadFloat(rootElem, "particleLifeSpan")); particleLifespanVariance_ = ReadFloat(rootElem, "particleLifespanVariance"); angle_ = ReadFloat(rootElem, "angle"); angleVariance_ = ReadFloat(rootElem, "angleVariance"); gravity_ = ReadVector2(rootElem, "gravity"); radialAcceleration_ = ReadFloat(rootElem, "radialAcceleration"); tangentialAcceleration_ = ReadFloat(rootElem, "tangentialAcceleration"); radialAccelVariance_ = ReadFloat(rootElem, "radialAccelVariance"); tangentialAccelVariance_ = ReadFloat(rootElem, "tangentialAccelVariance"); startColor_ = ReadColor(rootElem, "startColor"); startColorVariance_ = ReadColor(rootElem, "startColorVariance"); finishColor_ = ReadColor(rootElem, "finishColor"); finishColorVariance_ = ReadColor(rootElem, "finishColorVariance"); maxParticles_ = ReadInt(rootElem, "maxParticles"); startParticleSize_ = ReadFloat(rootElem, "startParticleSize"); startParticleSizeVariance_ = ReadFloat(rootElem, "startParticleSizeVariance"); finishParticleSize_ = ReadFloat(rootElem, "finishParticleSize"); // Typo in pex file FinishParticleSizeVariance_ = ReadFloat(rootElem, "FinishParticleSizeVariance"); duration_ = M_INFINITY; if (rootElem.HasChild("duration")) { float duration = ReadFloat(rootElem, "duration"); if (duration > 0.0f) duration_ = duration; } emitterType_ = (EmitterType2D)ReadInt(rootElem, "emitterType"); maxRadius_ = ReadFloat(rootElem, "maxRadius"); maxRadiusVariance_ = ReadFloat(rootElem, "maxRadiusVariance"); minRadius_ = ReadFloat(rootElem, "minRadius"); minRadiusVariance_ = ReadFloat(rootElem, "minRadiusVariance"); rotatePerSecond_ = ReadFloat(rootElem, "rotatePerSecond"); rotatePerSecondVariance_ = ReadFloat(rootElem, "rotatePerSecondVariance"); int blendFuncSource = ReadInt(rootElem, "blendFuncSource"); int blendFuncDestination = ReadInt(rootElem, "blendFuncDestination"); blendMode_ = BLEND_ALPHA; for (int i = 0; i < MAX_BLENDMODES; ++i) { if (blendFuncSource == srcBlendFuncs[i] && blendFuncDestination == destBlendFuncs[i]) { blendMode_ = (BlendMode)i; break; } } rotationStart_ = ReadFloat(rootElem, "rotationStart"); rotationStartVariance_ = ReadFloat(rootElem, "rotationStartVariance"); rotationEnd_ = ReadFloat(rootElem, "rotationEnd"); rotationEndVariance_ = ReadFloat(rootElem, "rotationEndVariance"); return true; }
bool ParticleEffect2D::Load(Deserializer& source) { XMLFile xmlFile(context_); if (!xmlFile.Load(source)) return false; XMLElement rootElem = xmlFile.GetRoot("particleEmitterConfig"); if (!rootElem) return false; String texture = rootElem.GetChild("texture").GetAttribute("name"); ResourceCache* cache = GetSubsystem<ResourceCache>(); sprite_= cache->GetResource<Sprite2D>(texture, false); // If sprite not found, try get in current directory if (!sprite_) sprite_= cache->GetResource<Sprite2D>(GetParentPath(GetName()) + texture); if (!sprite_) return false; sourcePositionVariance_ = ReadVector2(rootElem.GetChild("sourcePositionVariance")); speed_ = rootElem.GetChild("speed").GetFloat("value"); speedVariance_ = rootElem.GetChild("speedVariance").GetFloat("value"); particleLifeSpan_ = Max(0.01f, rootElem.GetChild("particleLifeSpan").GetFloat("value")); particleLifespanVariance_ = rootElem.GetChild("particleLifespanVariance").GetFloat("value"); angle_ = rootElem.GetChild("angle").GetFloat("value"); angleVariance_ = rootElem.GetChild("angleVariance").GetFloat("value"); gravity_ = ReadVector2(rootElem.GetChild("gravity")); radialAcceleration_ = rootElem.GetChild("radialAcceleration").GetFloat("value"); tangentialAcceleration_ = rootElem.GetChild("tangentialAcceleration").GetFloat("value"); radialAccelVariance_ = rootElem.GetChild("radialAccelVariance").GetFloat("value"); tangentialAccelVariance_ = rootElem.GetChild("tangentialAccelVariance").GetFloat("value"); startColor_ = ReadColor(rootElem.GetChild("startColor")); startColorVariance_ = ReadColor(rootElem.GetChild("startColorVariance")); finishColor_ = ReadColor(rootElem.GetChild("finishColor")); finishColorVariance_ = ReadColor(rootElem.GetChild("finishColorVariance")); maxParticles_ = rootElem.GetChild("maxParticles").GetInt("value"); startParticleSize_ = rootElem.GetChild("startParticleSize").GetFloat("value"); startParticleSizeVariance_ = rootElem.GetChild("startParticleSizeVariance").GetFloat("value"); finishParticleSize_ = rootElem.GetChild("finishParticleSize").GetFloat("value"); FinishParticleSizeVariance_ = rootElem.GetChild("FinishParticleSizeVariance").GetFloat("value"); duration_ = M_INFINITY; if (rootElem.HasChild("duration")) { float duration = rootElem.GetChild("duration").GetFloat("value"); if (duration > 0.0f) duration_ = duration; } emitterType_ = (EmitterType2D)rootElem.GetChild("emitterType").GetInt("value"); maxRadius_ = rootElem.GetChild("maxRadius").GetFloat("value"); maxRadiusVariance_ = rootElem.GetChild("maxRadiusVariance").GetFloat("value"); minRadius_ = rootElem.GetChild("minRadius").GetFloat("value"); rotatePerSecond_ = rootElem.GetChild("rotatePerSecond").GetFloat("value"); rotatePerSecondVariance_ = rootElem.GetChild("rotatePerSecondVariance").GetFloat("value"); int blendFuncSource = rootElem.GetChild("blendFuncSource").GetInt("value"); int blendFuncDestination = rootElem.GetChild("blendFuncDestination").GetInt("value"); blendMode_ = BLEND_ALPHA; for (int i = 0; i < MAX_BLENDMODES; ++i) { if (blendFuncSource == srcBlendFuncs[i] && blendFuncDestination == destBlendFuncs[i]) { blendMode_ = (BlendMode)i; break; } } rotationStart_ = rootElem.GetChild("rotationStart").GetFloat("value"); rotationStartVariance_ = rootElem.GetChild("rotationStartVariance").GetFloat("value"); rotationEnd_ = rootElem.GetChild("rotationEnd").GetFloat("value"); rotationEndVariance_ = rootElem.GetChild("rotationEndVariance").GetFloat("value"); return true; }
bool Animation2D::Load(Deserializer& source) { frameEndTimes_.Clear(); frameSprites_.Clear(); SharedPtr<XMLFile> xmlFile(new XMLFile(context_)); if(!xmlFile->Load(source)) { LOGERROR("Could not load animation"); return false; } SetMemoryUse(source.GetSize()); XMLElement rootElem = xmlFile->GetRoot("animation"); if (!rootElem) { LOGERROR("Invalid animation"); return false; } ResourceCache* cache = GetSubsystem<ResourceCache>(); XMLElement keyFrameElem = rootElem.GetChild("frame"); if (!keyFrameElem) { LOGERROR("Could not found key frame"); return false; } float endTime = 0.0f; while (keyFrameElem) { endTime += keyFrameElem.GetFloat("duration"); frameEndTimes_.Push(endTime); SharedPtr<Sprite2D> sprite; Vector<String> names = keyFrameElem.GetAttribute("sprite").Split('@'); if (names.Size() == 1) sprite = cache->GetResource<Sprite2D>(names[0]); else if (names.Size() == 2) { SpriteSheet2D* spriteSheet = cache->GetResource<SpriteSheet2D>(names[0], false); // If sprite sheet not found, try get in current directory if (!spriteSheet) spriteSheet = cache->GetResource<SpriteSheet2D>(GetParentPath(GetName()) + names[0]); if (!spriteSheet) { LOGERROR("Could not get sprite speet"); return false; } sprite = spriteSheet->GetSprite(names[1]); } if (!sprite) { LOGERROR("Could not get sprite"); return false; } frameSprites_.Push(sprite); keyFrameElem = keyFrameElem.GetNext("frame"); } return true; }