예제 #1
0
파일: Skin.cpp 프로젝트: nobitalwm/FCEngine
bool CSkin::Load()
{
    bool bRet = false;
    BEATS_ASSERT(!IsLoaded(), _T("Can't Load a skin which is already loaded!"));

    // Load From File
    CSerializer serializer(_T("..\\Resource\\skin\\org.skin"));
    CSerializer tmpVerticesBufferPos, tmpVerticesBufferUV;
    CSerializer indexBuffer;
    size_t uVertexCount = 0;
    serializer >> uVertexCount;
    m_uVertexCount = uVertexCount;
    m_vertices = new CVertexPTB[uVertexCount];
    float x, y, z;
    float u,v;

    for (size_t i = 0; i < uVertexCount; ++i)
    {
        ESkeletonBoneType bone, bone1, bone2, bone3;
        float weight, weight1, weight2,weight3;
        serializer >> x >> y >> z >> u >> v;
        serializer >> bone;
        serializer >> weight;
        serializer >> bone1;
        serializer >> weight1;
        serializer >> bone2;
        serializer >> weight2;
        serializer >> bone3;
        serializer >> weight3;

        CVertexPTB &vertex = m_vertices[i];
        kmVec3Fill(&vertex.position,x,y,z);
        vertex.tex = CTex(u,v);
        vertex.bones = CIVector4(bone, bone1, bone2, bone3);
        kmVec4Fill(&vertex.weights,weight,weight1,weight2,weight3);

#ifdef _DEBUG
        float sum = weight + weight1 + weight2+weight3;
        BEATS_ASSERT(sum < 1.01F, _T("Weight can't be greater than 1.01F, cur Value : %f!"), sum);
        BEATS_WARNING(sum > 0.99F, _T("Weight can't be smaller than 0.99F, cur Value : %f!"), sum);
#endif
    }
    
    for (size_t i = 0; i < uVertexCount; ++i)
    {
        indexBuffer << (short)i;
    }

    CRenderer* pRenderer = CRenderer::GetInstance();
    pRenderer->GenVertexArrays(1, &m_uVAO);
    pRenderer->GenBuffers(2, m_uVBO);

#ifndef SW_SKEL_ANIM
    buildVBOVertex(m_vertices, m_uVertexCount*sizeof(CVertexPTB));
    BEATS_SAFE_DELETE_ARRAY(m_vertices);
#endif
    buildVBOIndex(indexBuffer.GetBuffer(), indexBuffer.GetWritePos());
    buildVAO();

    SetLoadedFlag(true);

    return bRet;
}
void ExportLanguage()
{
    std::map<uint32_t, std::map<ELanguageType, TString> > languageServerErrCodeMap;
    ReadServerErrCodeFile(languageServerErrCodeMap);
    std::map<TString, std::map<ELanguageType, TString> >& languageMap = CLanguageManager::GetInstance()->GetLanguageMap();
    // 1. Export Bin File.
    CSerializer fileData;
    for (int i = 0; i < eLT_Count; ++i)
    {
        fileData << languageMap.size();
        for (auto iter = languageMap.begin(); iter != languageMap.end(); ++iter)
        {
            auto subIter = iter->second.find((ELanguageType)i);
            if (subIter != iter->second.end())
            {
                fileData << subIter->second;
            }
            else
            {
                fileData << iter->first;
            }
        }
        bool bRet = false;
        for (auto iter : languageServerErrCodeMap)
        {
            auto subIter = iter.second.find((ELanguageType)i);
            if (subIter != iter.second.end())
            {
                if (!bRet)
                {
                    fileData << languageServerErrCodeMap.size();
                    bRet = true;
                }
                fileData << iter.first;
                fileData << iter.second[(ELanguageType)i];
            }
        }
        TString strFilePath = CResourceManager::GetInstance()->GetResourcePath(eRT_Language);
        strFilePath.append(_T("/")).append(pszLanguageTypeString[i]).append(_T(".bin"));
        fileData.Deserialize(strFilePath.c_str(), _T("wb+"));
        fileData.Reset();
    }
    //2. Export enum file.
    std::string content;
    content.append("#ifndef BEYONDENGINEEDITOR_LANGUAGEENUM_H__INCLUDE\n#define BEYONDENGINEEDITOR_LANGUAGEENUM_H__INCLUDE\n").append("\nenum ELanguageTextType\n{\n");
    for (auto iter = languageMap.begin(); iter != languageMap.end(); iter++)
    {
        content.append("    ").append(iter->first.c_str()).append(",\n");
    }
    content.append("\n    eL_Count,\n").append("    eL_Force32Bit = 0xFFFFFFFF\n};\n");
    content.append("#define LUA_LANGUAGE_MAP(LM)\\\n");
    int32_t nCounter = 0;
    for (auto iter = languageMap.begin(); iter != languageMap.end(); ++iter)
    {
        TCHAR szValueBuffer[32];
        _stprintf(szValueBuffer, "%d", nCounter++);
        content.append("    ").append("LM(").append(iter->first.c_str()).append(",").append(szValueBuffer).append(")\\\n");
    }
    content.append("\n#endif");
    fileData.Reset();
    fileData << content;
    fileData.SetWritePos(fileData.GetWritePos() - 1);// back scape the 0 in the string end.
    bool bFileTheSame = false;
    const TString strHeaderFilePath = CResourceManager::GetInstance()->GetResourcePath(eRT_SourceCode) + _T("/Language/Language.h");
    if (CFilePathTool::GetInstance()->Exists(strHeaderFilePath.c_str()))
    {
        CSerializer tmpData(strHeaderFilePath.c_str(), "rb");
        if (tmpData.GetWritePos() == fileData.GetWritePos())
        {
            CMD5 tmpMD5(tmpData.GetBuffer(), tmpData.GetWritePos());
            CMD5 currentMD5(fileData.GetBuffer(), fileData.GetWritePos());
            bFileTheSame = tmpMD5 == currentMD5;
        }
    }
    if (!bFileTheSame)
    {
        fileData.Deserialize(strHeaderFilePath.c_str(), _T("wb+"));
    }

    //3. Export txt file.
    for (int i = 0; i < eLT_Count; ++i)
    {
        bool bHasData = false;
        fileData.Reset();
        for (auto iter = languageMap.begin(); iter != languageMap.end(); ++iter)
        {
            auto subIter = iter->second.find((ELanguageType)i);
            if (subIter != iter->second.end())
            {
                TString strData = (TString)(wxString::FromUTF8(subIter->second.c_str()));
                if (!bHasData && !strData.empty())
                {
                    bHasData = true;
                }
                fileData << strData;
                fileData.SetWritePos(fileData.GetWritePos() - 1);
            }
            fileData << "\n";
            fileData.SetWritePos(fileData.GetWritePos() - 1);
        }
        if (bHasData)
        {
            TString strFilePath = CResourceManager::GetInstance()->GetResourcePath(eRT_Resource);
            strFilePath.append(_T("/")).append(pszLanguageTypeString[i]).append(_T(".txt"));
            fileData.Deserialize(strFilePath.c_str(), _T("wt+"));
        }
    }
    fileData.Reset();
    const std::map<TString, TString>& languageTagMap = CLanguageManager::GetInstance()->GetLanguageTagMap();
    for (auto iter = languageTagMap.begin(); iter != languageTagMap.end(); ++iter)
    {
        TString strData = (TString)(wxString::FromUTF8(iter->second.c_str()));
        fileData << strData;
        fileData.SetWritePos(fileData.GetWritePos() - 1);
        fileData << "\n";
        fileData.SetWritePos(fileData.GetWritePos() - 1);
    }
    TString strFilePath = CResourceManager::GetInstance()->GetResourcePath(eRT_Resource);
    strFilePath.append(_T("/")).append("Tag").append(_T(".txt"));
    fileData.Deserialize(strFilePath.c_str(), _T("wt+"));

    fileData.Reset();
    for (auto iter = languageMap.begin(); iter != languageMap.end(); ++iter)
    {
        TString strData = (TString)(wxString::FromUTF8(iter->first.c_str()));
        fileData << strData;
        fileData.SetWritePos(fileData.GetWritePos() - 1);
        fileData << "\n";
        fileData.SetWritePos(fileData.GetWritePos() - 1);
    }
    strFilePath = CResourceManager::GetInstance()->GetResourcePath(eRT_Resource);
    strFilePath.append(_T("/")).append(_T("Enum.txt"));
    fileData.Deserialize(strFilePath.c_str(), _T("wt+"));
}