Exemple #1
0
    DiDataStreamPtr DiK2Configs::GetDataStream(const DiString& relPath, K2ResourceType type)
    {
#ifdef _K2_RECORD_USED_RESOURCE
        sUsedResources.insert(relPath);
#endif

        DiString full = GetK2MediaPath(relPath, type == K2_RES_TEXTURE);

        if (RESOURCE_PACK)
        {
            DiDataStreamPtr data = RESOURCE_PACK->Open(full);
            return data;
        }
        else
        {
            // now we just simply using OS's file system
            FILE* fp = fopen(full.c_str(), type == K2_RES_XML ? "r" : "rb");
            if (!fp)
            {
                DI_WARNING("Cannot open the file: %s", full.c_str());
                return nullptr;
            }
            DiDataStreamPtr data(DI_NEW DiFileHandleDataStream(fp));
            return data;
        }
    }
Exemple #2
0
 void DiMeshSerializer::ExportMesh( const DiMeshPtr pMesh, const DiString& filename )
 {
     FILE* fp = fopen(filename.c_str(),"wb");
     DiDataStreamPtr ds(DI_NEW DiFileHandleDataStream(fp,DiDataStream::WRITE));
     ExportMesh(pMesh,ds);
 }
Exemple #3
0
    DiTexturePtr DiK2Configs::GetTexture(const DiString& relPath)
    {
        DiString baseName = relPath.ExtractFileName();
        if (baseName.empty() || baseName[0] == '$')
            return DiK2Configs::GetSpecialTexture(baseName);

        DiTexturePtr ret = DiAssetManager::GetInstance().FindAsset<DiTexture>(relPath);
        if (ret)
            return ret;
        
        bool needprefix = !TEXTURE_PACK_PREFIX_FOLDER.empty();
        if(DiString::StartsWith(relPath, TEXTURE_PACK_PREFIX_FOLDER))
        {
            needprefix = false;
        }

        DiString full = GetK2MediaPath(relPath, true);
        if(full.empty())
        {
            DI_WARNING("Empty texture file!, using default texture instead");
            return DiTexture::GetDefaultTexture();
        }
        
#if 0
        if (TEXTURE_PACK && full[0] != '\\' && full[0] != '/')
        {
            full = "/"+full;
        }
#endif

        DiString tgaExt = ".tga";
#if DEMI_PLATFORM == DEMI_PLATFORM_IOS
        DiString compExt = ".pvr";
#else
        DiString compExt = ".dds";
#endif

        DiString tgaFile = full + tgaExt;
        DiString ddsFile = full + compExt;
        bool useTga = false;

        if (TEXTURE_PACK)
        {
            DiDataStreamPtr data;
            
            /// TODO read the descriptor file
            if(needprefix)
            {
                tgaFile = DiK2Configs::TEXTURE_PACK_PREFIX_FOLDER + tgaFile;
                ddsFile = DiK2Configs::TEXTURE_PACK_PREFIX_FOLDER + ddsFile;
            }

            if (TEXTURE_PACK->HasFile(ddsFile))
                data = TEXTURE_PACK->Open(ddsFile);
            else
            {
                data = TEXTURE_PACK->Open(tgaFile);
                useTga = true;
            }

            if (!data)
            {
                DI_WARNING("Cannot open the texture file: %s, using default texture", ddsFile.c_str());
                return DiTexture::GetDefaultTexture();
            }

#ifdef _K2_RECORD_USED_RESOURCE
            sUsedResources.insert(relPath + (useTga ? tgaExt : compExt));
#endif
            ret = DiAssetManager::GetInstance().CreateOrReplaceAsset<DiTexture>(relPath);
            ret->Load(data);
            return ret;
        }
        else
        {
            FILE* fp = nullptr;

            // try dds
            fp = fopen(ddsFile.c_str(), "rb");

            // try tga
            if (!fp)
            {
                fp = fopen(tgaFile.c_str(), "rb");
                useTga = true;
            }

            if (!fp)
            {
                DI_WARNING("Cannot open the texture file: %s, using default texture", ddsFile.c_str());
                return DiTexture::GetDefaultTexture();
            }

#ifdef _K2_RECORD_USED_RESOURCE
            sUsedResources.insert(relPath + (useTga ? tgaExt : compExt));
#endif
            DiDataStreamPtr texData(DI_NEW DiFileHandleDataStream(relPath, fp));

            ret = DiAssetManager::GetInstance().CreateOrReplaceAsset<DiTexture>(relPath);
            ret->Load(texData);
            return ret;
        }
    }