Пример #1
0
bool TConstTraverser::visitAggregate(Visit visit, TIntermAggregate* node)
{
    if (!node->isConstructor() && node->getOp() != EOpComma) {
        TString buf;
        buf.append("'constructor' : assigning non-constant to ");
        buf.append(type.getCompleteString());
        infoSink.info.message(EPrefixError, node->getLine(), buf.c_str());
        error = true;
        return false;  
    }

    if (node->getSequence().size() == 0) {
        error = true;
        return false;
    }

    bool flag = node->getSequence().size() == 1 && node->getSequence()[0]->getAsTyped()->getAsConstantUnion();
    if (flag) 
    {
        singleConstantParam = true; 
        constructorType = node->getOp();
        size = node->getType().getObjectSize();

        if (node->getType().isMatrix()) {
            isMatrix = true;
            matrixSize = node->getType().getNominalSize();
        }
    }       

    for (TIntermSequence::iterator p = node->getSequence().begin(); 
                                   p != node->getSequence().end(); p++) {

        if (node->getOp() == EOpComma)
            index = 0;           

        (*p)->traverse(this);
    }   
    if (flag) 
    {
        singleConstantParam = false;   
        constructorType = EOpNull;
        size = 0;
        isMatrix = false;
        matrixSize = 0;
    }
    return false;
}
Пример #2
0
bool TConstTraverser::visitBinary(Visit visit, TIntermBinary* node)
{
    TQualifier qualifier = node->getType().getQualifier();
    
    if (qualifier != EvqConst) {
        TString buf;
        buf.append("'constructor' : assigning non-constant to ");
        buf.append(type.getCompleteString());
        infoSink.info.message(EPrefixError, node->getLine(), buf.c_str());
        error = true;
        return false;  
    }

   infoSink.info.message(EPrefixInternalError, node->getLine(), "Binary Node found in constant constructor");
    
    return false;
}
//============================================================================
//
// Default precision for fragment shaders.
//
//============================================================================
static TString DefaultPrecisionFragment()
{
    TString s;

    s.append(TString("precision mediump int;"));
    // No default precision for float in fragment shaders

    return s;
}
Пример #4
0
//Return the complete callstack in a continuous string
TString Stackage::GetString()
{
	vector<TCHAR*>::iterator it;
	TString stack;
	TString separator = TEXT(" -> ");

	//Build Stack String
	for(it=vStack.begin(); it!=vStack.end(); ++it)
	{
		stack.append(*it);
		stack.append(separator);
	}

	//Remove last separator
	if(stack.length() >= separator.length())
		stack.erase(stack.end() - separator.length(), stack.end());

	return stack;
}
//============================================================================
//
// Prototypes for built-in functions seen by vertex shaders only.
//
//============================================================================
static TString BuiltInFunctionsVertex(const ShBuiltInResources& resources)
{
    TString s;

    //
    // Geometric Functions.
    //
    //s.append(TString("vec4 ftransform();"));

    //
    // Texture Functions.
    //
    if (resources.MaxVertexTextureImageUnits > 0) {
        s.append(TString("vec4 texture2D(sampler2D sampler, vec2 coord);"));
        s.append(TString("vec4 texture2DProj(sampler2D sampler, vec3 coord);"));
        s.append(TString("vec4 texture2DProj(sampler2D sampler, vec4 coord);"));
        s.append(TString("vec4 textureCube(samplerCube sampler, vec3 coord);"));

        s.append(TString("vec4 texture2DLod(sampler2D sampler, vec2 coord, float lod);"));
        s.append(TString("vec4 texture2DProjLod(sampler2D sampler, vec3 coord, float lod);"));
        s.append(TString("vec4 texture2DProjLod(sampler2D sampler, vec4 coord, float lod);"));
        s.append(TString("vec4 textureCubeLod(samplerCube sampler, vec3 coord, float lod);"));
    }

    return s;
}
Пример #6
0
void CEnumStrGenerator::SaveCacheFile(const TCHAR* pszCacheFileName)
{
    CSerializer serializer;
    serializer << m_enumStrPool.size();
    std::map<TString, SEnumScanData*>::iterator iter = m_enumStrPool.begin();
    for (; iter != m_enumStrPool.end(); ++iter)
    {
        serializer << iter->first;
        serializer << iter->second->m_enumFilePath;
        serializer << iter->second->m_enumValue.size();
        for (uint32_t i = 0; i < iter->second->m_enumValue.size(); ++i)
        {
            serializer << iter->second->m_enumValue[i]->m_str;
            serializer << iter->second->m_enumValue[i]->m_value;
        }
    }
    TString fullPathStr = CFilePathTool::GetInstance()->ParentPath(CUtilityManager::GetInstance()->GetModuleFileName().c_str());
    fullPathStr.append(_T("/")).append(pszCacheFileName);
    serializer.Deserialize(fullPathStr.c_str());
}
//============================================================================
//
// Standard uniforms.
//
//============================================================================
static TString StandardUniforms()
{
    TString s;

    //
    // Depth range in window coordinates
    //
    s.append(TString("struct gl_DepthRangeParameters {"));
    s.append(TString("    highp float near;"));        // n
    s.append(TString("    highp float far;"));         // f
    s.append(TString("    highp float diff;"));        // f - n
    s.append(TString("};"));
    s.append(TString("uniform gl_DepthRangeParameters gl_DepthRange;"));

    return s;
}
Пример #8
0
void CLanguageManager::SaveLanguageListToFile()
{
    std::map<TString, std::map<ELanguageType, TString> >& languageMap = CLanguageManager::GetInstance()->GetLanguageMap();
    rapidxml::xml_document<> doc;
    rapidxml::xml_node<>* pLanguageRootNode = doc.allocate_node(rapidxml::node_element, "Language");
    doc.append_node(pLanguageRootNode);
    TCHAR szBuffer[256];
    _stprintf(szBuffer, "%d", languageMap.size());
    pLanguageRootNode->append_attribute(doc.allocate_attribute("Count", doc.allocate_string(szBuffer)));
    for (auto iter = languageMap.begin(); iter != languageMap.end(); ++iter)
    {
        rapidxml::xml_node<>* pLanguageNode = doc.allocate_node(rapidxml::node_element, "LanguageNode");
        pLanguageNode->append_attribute(doc.allocate_attribute("Enum", doc.allocate_string(iter->first.c_str())));
        TString strTagValue;
        if (m_languageTagMap.find(iter->first) != m_languageTagMap.end())
        {
            strTagValue = m_languageTagMap[iter->first];
        }
        pLanguageNode->append_attribute(doc.allocate_attribute("Tag", doc.allocate_string(strTagValue.c_str())));
        for (int nCounter = 0; nCounter < eLT_Count; ++nCounter)
        {
            auto subIter = iter->second.find((ELanguageType)nCounter);
            if (subIter != iter->second.end() && subIter->second.length() > 0)
            {
                rapidxml::xml_node<>* pLanguageTypeNode = doc.allocate_node(rapidxml::node_element, pszLanguageTypeString[nCounter]);
                pLanguageTypeNode->append_attribute(doc.allocate_attribute("Value", doc.allocate_string(subIter != iter->second.end() ? subIter->second.c_str() : "")));
                pLanguageNode->append_node(pLanguageTypeNode);
            }
        }
        pLanguageRootNode->append_node(pLanguageNode);
    }
    TString filePath = CResourceManager::GetInstance()->GetResourcePath(eRT_Resource);
    filePath.append(_T("/LanguageConfig.xml"));
    TString strOut;
    rapidxml::print(std::back_inserter(strOut), doc, 0);
    std::ofstream out(filePath.c_str());
    out << strOut;
    out.close();
}
Пример #9
0
void CSpyUserPanel::UpdateDirectoryCache(const SDirectory* pDirectory)
{
    BEATS_ASSERT(m_pRootDirectoryCache, _T("The cache mustn't be NULL!"));
    std::vector<TString> result;
    CStringHelper::GetInstance()->SplitString(pDirectory->m_szPath.c_str(), _T("/"), result, false);
    SDirectory* pCurCache = m_pRootDirectoryCache;
    TString strCurPath;
    for (uint32_t i = 0; i < result.size(); ++i)
    {
        strCurPath.append(result[i]).append(_T("/"));
        SDirectory* pChildDirectory = pCurCache->GetChild(strCurPath);
        if (pChildDirectory == NULL)
        {
            // Add a place holder directory to build the path.
            pChildDirectory = new SDirectory(NULL, strCurPath.c_str());
            pCurCache->m_pDirectories->push_back(pChildDirectory);
        }
        // if the cache is a place holder, reset the parent to indicate that it is updated.
        if (i == result.size() - 1 && pChildDirectory->m_pParent == NULL)
        {
            pChildDirectory->m_pParent = pCurCache;
        }
        pCurCache = pChildDirectory;
    }
    
    //1. Sync the child directories data.
    BEATS_ASSERT(pDirectory->m_szPath == pCurCache->m_szPath, _T("The cache path must be the same with it!"));
    for (uint32_t i = 0; i < pDirectory->m_pDirectories->size(); ++i)
    {
        SDirectory* pChildDirectory = pDirectory->m_pDirectories->at(i);
        SDirectory* pCacheChildDirectory = pCurCache->GetChild(pChildDirectory->m_szPath);
        if (pCacheChildDirectory == NULL)
        {
            // Add new child of the cache, which are also place holders.
            pCacheChildDirectory = new SDirectory(NULL, pChildDirectory->m_szPath.c_str());
            pCurCache->m_pDirectories->push_back(pCacheChildDirectory);
        }
        memcpy(&pCacheChildDirectory->m_data, &pChildDirectory->m_data, sizeof(WIN32_FIND_DATA));
    }
    // Delete the redundant child of the cache.
    if (pCurCache->m_pDirectories->size() > pDirectory->m_pDirectories->size())
    {
        for (std::vector<SDirectory*>::iterator iter = pCurCache->m_pDirectories->begin(); iter != pCurCache->m_pDirectories->end(); )
        {
            SDirectory* pChild = pDirectory->GetChild((*iter)->m_szPath);
            if (pChild == NULL)
            {
                BEATS_SAFE_DELETE(*iter);
                iter = pCurCache->m_pDirectories->erase(iter);
            }
            else
            {
                ++iter;
            }
        }
    }
    // 2. Sync the files data.
    int iSizeDelta = pCurCache->m_pFileList->size() - pDirectory->m_pFileList->size();
    for (int i = 0; i < iSizeDelta; ++i)
    {
        WIN32_FIND_DATA* pData = pCurCache->m_pFileList->back();
        BEATS_SAFE_DELETE(pData);
        pCurCache->m_pFileList->pop_back();
    }
    for (int i = 0; i < -iSizeDelta; ++i)
    {
        WIN32_FIND_DATA* pData = new WIN32_FIND_DATA;
        pCurCache->m_pFileList->push_back(pData);
    }
    BEATS_ASSERT(pCurCache->m_pFileList->size() == pDirectory->m_pFileList->size(), _T("The data size must be the same now!"));
    for (uint32_t i = 0; i < pCurCache->m_pFileList->size(); ++i)
    {
        memcpy(pCurCache->m_pFileList->at(i), pDirectory->m_pFileList->at(i), sizeof(WIN32_FIND_DATA));
    }
}
Пример #10
0
void CSpyUserPanel::OnSpySelectFileCtrlMenu(wxMenuEvent& event)
{
    switch (event.GetId())
    {
    case eSUPUIID_DownloadMenu:
        {
            TString strStorePath;
            if (CUtilityManager::GetInstance()->AcquireDirectory(this->GetHWND(), strStorePath, _T("选择保存的位置")))
            {
                typedef bool (*TDownloadFileFunc)(SOCKET sock, const std::vector<TString>& files, const TString& strStorePath, CFileFilter* pFilter);
                static TDownloadFileFunc pDownloadFunc = TDownloadFileFunc(GetProcAddress(m_hSpyDllHandle, "Spy_DownloadFiles"));
                BEATS_ASSERT(pDownloadFunc != NULL, _T("Get function address %s failed!"), _T("Spy_DownloadFiles"));
                if (pDownloadFunc != NULL)
                {
                    std::vector<TString> files;
                    uint32_t uSelectedCount = m_pRemoteFileCtrl->GetSelectedItemCount();
                    if (uSelectedCount == 0)
                    {
                        const TString& curPath = m_pRemoteFileCtrl->GetCurrentDirectoryPath();
                        if (curPath.length() > 0)
                        {
                            files.push_back(curPath);
                        }
                    }
                    else
                    {
                        uint32_t uCounter = 0;
                        long item = m_pRemoteFileCtrl->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
                        while ( item != -1 && uCounter++ < uSelectedCount )
                        {
                            TString curPath = m_pRemoteFileCtrl->GetCurrentDirectoryPath();
                            files.push_back(curPath.append(m_pRemoteFileCtrl->GetItemText(item)));
                            item = m_pRemoteFileCtrl->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
                        }
                    }
                    BEATS_ASSERT(files.size() > 0, _T("Can't start download with nothing!"));
                    if (files.size() > 0 && strStorePath.length() > 0)
                    {
                        pDownloadFunc(m_pSocketInfo->m_socket, files, strStorePath, NULL);
                    }
                }
            }
        }
        break;
    case eSUPUIID_UploadMenu:
        {
            std::vector<TString> strPath;
            bool bGetUploadFiles = CUtilityManager::GetInstance()->AcquireMuiltyFilePath(true, this->GetHWND(), strPath, _T("选择上传的文件"), NULL, NULL);
            if (bGetUploadFiles)
            {
                typedef bool (*TUploadFileFunc)(SOCKET sock, const std::vector<TString>& files, const TString& strStorePath, CFileFilter* pFilter);
                static TUploadFileFunc pUploadFunc = TUploadFileFunc(GetProcAddress(m_hSpyDllHandle, "Spy_UploadFiles"));
                BEATS_ASSERT(pUploadFunc != NULL, _T("Get function address %s failed!"), _T("Spy_DownloadFiles"));
                if (pUploadFunc != NULL)
                {
                    TString curPath = m_pRemoteFileCtrl->GetCurrentDirectoryPath();
                    BEATS_ASSERT(curPath.length() > 0 && strPath.size() > 0, _T("Upload failed! upload files size: %d store path: %s"), strPath.size(), curPath.c_str());
                    if (curPath.length() > 0 && strPath.size() > 0)
                    {
                        pUploadFunc(m_pSocketInfo->m_socket, strPath, curPath, NULL);
                    }
                    else
                    {
                        MessageBox(this->GetHWND(), _T("Current path is not valid!"), NULL, MB_OK);
                    }
                }
            }
        }
        break;
    default:
        BEATS_ASSERT(false, _T("Never Reach Here!"));
        break;
    }
}
Пример #11
0
//============================================================================
//
// Prototypes for built-in functions seen by fragment shaders only.
//
//============================================================================
static TString BuiltInFunctionsFragment(const ShBuiltInResources& resources)
{
    TString s;

    //
    // Texture Functions.
    //
    s.append(TString("vec4 texture2D(sampler2D sampler, vec2 coord);"));
    s.append(TString("vec4 texture2DProj(sampler2D sampler, vec3 coord);"));
    s.append(TString("vec4 texture2DProj(sampler2D sampler, vec4 coord);"));
    s.append(TString("vec4 textureCube(samplerCube sampler, vec3 coord);"));

    s.append(TString("vec4 texture2D(sampler2D sampler, vec2 coord, float bias);"));
    s.append(TString("vec4 texture2DProj(sampler2D sampler, vec3 coord, float bias);"));
    s.append(TString("vec4 texture2DProj(sampler2D sampler, vec4 coord, float bias);"));
    s.append(TString("vec4 textureCube(samplerCube sampler, vec3 coord, float bias);"));

    if (resources.OES_standard_derivatives) {
        s.append(TString("float dFdx(float p);"));
        s.append(TString("vec2  dFdx(vec2  p);"));
        s.append(TString("vec3  dFdx(vec3  p);"));
        s.append(TString("vec4  dFdx(vec4  p);"));

        s.append(TString("float dFdy(float p);"));
        s.append(TString("vec2  dFdy(vec2  p);"));
        s.append(TString("vec3  dFdy(vec3  p);"));
        s.append(TString("vec4  dFdy(vec4  p);"));

        s.append(TString("float fwidth(float p);"));
        s.append(TString("vec2  fwidth(vec2  p);"));
        s.append(TString("vec3  fwidth(vec3  p);"));
        s.append(TString("vec4  fwidth(vec4  p);"));
    }

    return s;
}
Пример #12
0
//============================================================================
//
// Prototypes for built-in functions seen by both vertex and fragment shaders.
//
//============================================================================
static TString BuiltInFunctionsCommon()
{
    TString s;

    //
    // Angle and Trigonometric Functions.
    //
    s.append(TString("float radians(float degrees);"));
    s.append(TString("vec2  radians(vec2  degrees);"));
    s.append(TString("vec3  radians(vec3  degrees);"));
    s.append(TString("vec4  radians(vec4  degrees);"));

    s.append(TString("float degrees(float radians);"));
    s.append(TString("vec2  degrees(vec2  radians);"));
    s.append(TString("vec3  degrees(vec3  radians);"));
    s.append(TString("vec4  degrees(vec4  radians);"));

    s.append(TString("float sin(float angle);"));
    s.append(TString("vec2  sin(vec2  angle);"));
    s.append(TString("vec3  sin(vec3  angle);"));
    s.append(TString("vec4  sin(vec4  angle);"));

    s.append(TString("float cos(float angle);"));
    s.append(TString("vec2  cos(vec2  angle);"));
    s.append(TString("vec3  cos(vec3  angle);"));
    s.append(TString("vec4  cos(vec4  angle);"));

    s.append(TString("float tan(float angle);"));
    s.append(TString("vec2  tan(vec2  angle);"));
    s.append(TString("vec3  tan(vec3  angle);"));
    s.append(TString("vec4  tan(vec4  angle);"));

    s.append(TString("float asin(float x);"));
    s.append(TString("vec2  asin(vec2  x);"));
    s.append(TString("vec3  asin(vec3  x);"));
    s.append(TString("vec4  asin(vec4  x);"));

    s.append(TString("float acos(float x);"));
    s.append(TString("vec2  acos(vec2  x);"));
    s.append(TString("vec3  acos(vec3  x);"));
    s.append(TString("vec4  acos(vec4  x);"));

    s.append(TString("float atan(float y, float x);"));
    s.append(TString("vec2  atan(vec2  y, vec2  x);"));
    s.append(TString("vec3  atan(vec3  y, vec3  x);"));
    s.append(TString("vec4  atan(vec4  y, vec4  x);"));

    s.append(TString("float atan(float y_over_x);"));
    s.append(TString("vec2  atan(vec2  y_over_x);"));
    s.append(TString("vec3  atan(vec3  y_over_x);"));
    s.append(TString("vec4  atan(vec4  y_over_x);"));

    //
    // Exponential Functions.
    //
    s.append(TString("float pow(float x, float y);"));
    s.append(TString("vec2  pow(vec2  x, vec2  y);"));
    s.append(TString("vec3  pow(vec3  x, vec3  y);"));
    s.append(TString("vec4  pow(vec4  x, vec4  y);"));

    s.append(TString("float exp(float x);"));
    s.append(TString("vec2  exp(vec2  x);"));
    s.append(TString("vec3  exp(vec3  x);"));
    s.append(TString("vec4  exp(vec4  x);"));

    s.append(TString("float log(float x);"));
    s.append(TString("vec2  log(vec2  x);"));
    s.append(TString("vec3  log(vec3  x);"));
    s.append(TString("vec4  log(vec4  x);"));

    s.append(TString("float exp2(float x);"));
    s.append(TString("vec2  exp2(vec2  x);"));
    s.append(TString("vec3  exp2(vec3  x);"));
    s.append(TString("vec4  exp2(vec4  x);"));

    s.append(TString("float log2(float x);"));
    s.append(TString("vec2  log2(vec2  x);"));
    s.append(TString("vec3  log2(vec3  x);"));
    s.append(TString("vec4  log2(vec4  x);"));

    s.append(TString("float sqrt(float x);"));
    s.append(TString("vec2  sqrt(vec2  x);"));
    s.append(TString("vec3  sqrt(vec3  x);"));
    s.append(TString("vec4  sqrt(vec4  x);"));

    s.append(TString("float inversesqrt(float x);"));
    s.append(TString("vec2  inversesqrt(vec2  x);"));
    s.append(TString("vec3  inversesqrt(vec3  x);"));
    s.append(TString("vec4  inversesqrt(vec4  x);"));

    //
    // Common Functions.
    //
    s.append(TString("float abs(float x);"));
    s.append(TString("vec2  abs(vec2  x);"));
    s.append(TString("vec3  abs(vec3  x);"));
    s.append(TString("vec4  abs(vec4  x);"));

    s.append(TString("float sign(float x);"));
    s.append(TString("vec2  sign(vec2  x);"));
    s.append(TString("vec3  sign(vec3  x);"));
    s.append(TString("vec4  sign(vec4  x);"));

    s.append(TString("float floor(float x);"));
    s.append(TString("vec2  floor(vec2  x);"));
    s.append(TString("vec3  floor(vec3  x);"));
    s.append(TString("vec4  floor(vec4  x);"));

    s.append(TString("float ceil(float x);"));
    s.append(TString("vec2  ceil(vec2  x);"));
    s.append(TString("vec3  ceil(vec3  x);"));
    s.append(TString("vec4  ceil(vec4  x);"));

    s.append(TString("float fract(float x);"));
    s.append(TString("vec2  fract(vec2  x);"));
    s.append(TString("vec3  fract(vec3  x);"));
    s.append(TString("vec4  fract(vec4  x);"));

    s.append(TString("float mod(float x, float y);"));
    s.append(TString("vec2  mod(vec2  x, float y);"));
    s.append(TString("vec3  mod(vec3  x, float y);"));
    s.append(TString("vec4  mod(vec4  x, float y);"));
    s.append(TString("vec2  mod(vec2  x, vec2  y);"));
    s.append(TString("vec3  mod(vec3  x, vec3  y);"));
    s.append(TString("vec4  mod(vec4  x, vec4  y);"));

    s.append(TString("float min(float x, float y);"));
    s.append(TString("vec2  min(vec2  x, float y);"));
    s.append(TString("vec3  min(vec3  x, float y);"));
    s.append(TString("vec4  min(vec4  x, float y);"));
    s.append(TString("vec2  min(vec2  x, vec2  y);"));
    s.append(TString("vec3  min(vec3  x, vec3  y);"));
    s.append(TString("vec4  min(vec4  x, vec4  y);"));

    s.append(TString("float max(float x, float y);"));
    s.append(TString("vec2  max(vec2  x, float y);"));
    s.append(TString("vec3  max(vec3  x, float y);"));
    s.append(TString("vec4  max(vec4  x, float y);"));
    s.append(TString("vec2  max(vec2  x, vec2  y);"));
    s.append(TString("vec3  max(vec3  x, vec3  y);"));
    s.append(TString("vec4  max(vec4  x, vec4  y);"));

    s.append(TString("float clamp(float x, float minVal, float maxVal);"));
    s.append(TString("vec2  clamp(vec2  x, float minVal, float maxVal);"));
    s.append(TString("vec3  clamp(vec3  x, float minVal, float maxVal);"));
    s.append(TString("vec4  clamp(vec4  x, float minVal, float maxVal);"));
    s.append(TString("vec2  clamp(vec2  x, vec2  minVal, vec2  maxVal);"));
    s.append(TString("vec3  clamp(vec3  x, vec3  minVal, vec3  maxVal);"));
    s.append(TString("vec4  clamp(vec4  x, vec4  minVal, vec4  maxVal);"));

    s.append(TString("float mix(float x, float y, float a);"));
    s.append(TString("vec2  mix(vec2  x, vec2  y, float a);"));
    s.append(TString("vec3  mix(vec3  x, vec3  y, float a);"));
    s.append(TString("vec4  mix(vec4  x, vec4  y, float a);"));
    s.append(TString("vec2  mix(vec2  x, vec2  y, vec2  a);"));
    s.append(TString("vec3  mix(vec3  x, vec3  y, vec3  a);"));
    s.append(TString("vec4  mix(vec4  x, vec4  y, vec4  a);"));

    s.append(TString("float step(float edge, float x);"));
    s.append(TString("vec2  step(vec2  edge, vec2  x);"));
    s.append(TString("vec3  step(vec3  edge, vec3  x);"));
    s.append(TString("vec4  step(vec4  edge, vec4  x);"));
    s.append(TString("vec2  step(float edge, vec2  x);"));
    s.append(TString("vec3  step(float edge, vec3  x);"));
    s.append(TString("vec4  step(float edge, vec4  x);"));

    s.append(TString("float smoothstep(float edge0, float edge1, float x);"));
    s.append(TString("vec2  smoothstep(vec2  edge0, vec2  edge1, vec2  x);"));
    s.append(TString("vec3  smoothstep(vec3  edge0, vec3  edge1, vec3  x);"));
    s.append(TString("vec4  smoothstep(vec4  edge0, vec4  edge1, vec4  x);"));
    s.append(TString("vec2  smoothstep(float edge0, float edge1, vec2  x);"));
    s.append(TString("vec3  smoothstep(float edge0, float edge1, vec3  x);"));
    s.append(TString("vec4  smoothstep(float edge0, float edge1, vec4  x);"));

    //
    // Geometric Functions.
    //
    s.append(TString("float length(float x);"));
    s.append(TString("float length(vec2  x);"));
    s.append(TString("float length(vec3  x);"));
    s.append(TString("float length(vec4  x);"));

    s.append(TString("float distance(float p0, float p1);"));
    s.append(TString("float distance(vec2  p0, vec2  p1);"));
    s.append(TString("float distance(vec3  p0, vec3  p1);"));
    s.append(TString("float distance(vec4  p0, vec4  p1);"));

    s.append(TString("float dot(float x, float y);"));
    s.append(TString("float dot(vec2  x, vec2  y);"));
    s.append(TString("float dot(vec3  x, vec3  y);"));
    s.append(TString("float dot(vec4  x, vec4  y);"));

    s.append(TString("vec3 cross(vec3 x, vec3 y);"));
    s.append(TString("float normalize(float x);"));
    s.append(TString("vec2  normalize(vec2  x);"));
    s.append(TString("vec3  normalize(vec3  x);"));
    s.append(TString("vec4  normalize(vec4  x);"));

    s.append(TString("float faceforward(float N, float I, float Nref);"));
    s.append(TString("vec2  faceforward(vec2  N, vec2  I, vec2  Nref);"));
    s.append(TString("vec3  faceforward(vec3  N, vec3  I, vec3  Nref);"));
    s.append(TString("vec4  faceforward(vec4  N, vec4  I, vec4  Nref);"));

    s.append(TString("float reflect(float I, float N);"));
    s.append(TString("vec2  reflect(vec2  I, vec2  N);"));
    s.append(TString("vec3  reflect(vec3  I, vec3  N);"));
    s.append(TString("vec4  reflect(vec4  I, vec4  N);"));

    s.append(TString("float refract(float I, float N, float eta);"));
    s.append(TString("vec2  refract(vec2  I, vec2  N, float eta);"));
    s.append(TString("vec3  refract(vec3  I, vec3  N, float eta);"));
    s.append(TString("vec4  refract(vec4  I, vec4  N, float eta);"));

    //
    // Matrix Functions.
    //
    s.append(TString("mat2 matrixCompMult(mat2 x, mat2 y);"));
    s.append(TString("mat3 matrixCompMult(mat3 x, mat3 y);"));
    s.append(TString("mat4 matrixCompMult(mat4 x, mat4 y);"));

    //
    // Vector relational functions.
    //
    s.append(TString("bvec2 lessThan(vec2 x, vec2 y);"));
    s.append(TString("bvec3 lessThan(vec3 x, vec3 y);"));
    s.append(TString("bvec4 lessThan(vec4 x, vec4 y);"));

    s.append(TString("bvec2 lessThan(ivec2 x, ivec2 y);"));
    s.append(TString("bvec3 lessThan(ivec3 x, ivec3 y);"));
    s.append(TString("bvec4 lessThan(ivec4 x, ivec4 y);"));

    s.append(TString("bvec2 lessThanEqual(vec2 x, vec2 y);"));
    s.append(TString("bvec3 lessThanEqual(vec3 x, vec3 y);"));
    s.append(TString("bvec4 lessThanEqual(vec4 x, vec4 y);"));

    s.append(TString("bvec2 lessThanEqual(ivec2 x, ivec2 y);"));
    s.append(TString("bvec3 lessThanEqual(ivec3 x, ivec3 y);"));
    s.append(TString("bvec4 lessThanEqual(ivec4 x, ivec4 y);"));

    s.append(TString("bvec2 greaterThan(vec2 x, vec2 y);"));
    s.append(TString("bvec3 greaterThan(vec3 x, vec3 y);"));
    s.append(TString("bvec4 greaterThan(vec4 x, vec4 y);"));

    s.append(TString("bvec2 greaterThan(ivec2 x, ivec2 y);"));
    s.append(TString("bvec3 greaterThan(ivec3 x, ivec3 y);"));
    s.append(TString("bvec4 greaterThan(ivec4 x, ivec4 y);"));

    s.append(TString("bvec2 greaterThanEqual(vec2 x, vec2 y);"));
    s.append(TString("bvec3 greaterThanEqual(vec3 x, vec3 y);"));
    s.append(TString("bvec4 greaterThanEqual(vec4 x, vec4 y);"));

    s.append(TString("bvec2 greaterThanEqual(ivec2 x, ivec2 y);"));
    s.append(TString("bvec3 greaterThanEqual(ivec3 x, ivec3 y);"));
    s.append(TString("bvec4 greaterThanEqual(ivec4 x, ivec4 y);"));

    s.append(TString("bvec2 equal(vec2 x, vec2 y);"));
    s.append(TString("bvec3 equal(vec3 x, vec3 y);"));
    s.append(TString("bvec4 equal(vec4 x, vec4 y);"));

    s.append(TString("bvec2 equal(ivec2 x, ivec2 y);"));
    s.append(TString("bvec3 equal(ivec3 x, ivec3 y);"));
    s.append(TString("bvec4 equal(ivec4 x, ivec4 y);"));

    s.append(TString("bvec2 equal(bvec2 x, bvec2 y);"));
    s.append(TString("bvec3 equal(bvec3 x, bvec3 y);"));
    s.append(TString("bvec4 equal(bvec4 x, bvec4 y);"));

    s.append(TString("bvec2 notEqual(vec2 x, vec2 y);"));
    s.append(TString("bvec3 notEqual(vec3 x, vec3 y);"));
    s.append(TString("bvec4 notEqual(vec4 x, vec4 y);"));

    s.append(TString("bvec2 notEqual(ivec2 x, ivec2 y);"));
    s.append(TString("bvec3 notEqual(ivec3 x, ivec3 y);"));
    s.append(TString("bvec4 notEqual(ivec4 x, ivec4 y);"));

    s.append(TString("bvec2 notEqual(bvec2 x, bvec2 y);"));
    s.append(TString("bvec3 notEqual(bvec3 x, bvec3 y);"));
    s.append(TString("bvec4 notEqual(bvec4 x, bvec4 y);"));

    s.append(TString("bool any(bvec2 x);"));
    s.append(TString("bool any(bvec3 x);"));
    s.append(TString("bool any(bvec4 x);"));

    s.append(TString("bool all(bvec2 x);"));
    s.append(TString("bool all(bvec3 x);"));
    s.append(TString("bool all(bvec4 x);"));

    s.append(TString("bvec2 not(bvec2 x);"));
    s.append(TString("bvec3 not(bvec3 x);"));
    s.append(TString("bvec4 not(bvec4 x);"));

    //
    // Noise functions.
    //
    //s.append(TString("float noise1(float x);"));
    //s.append(TString("float noise1(vec2  x);"));
    //s.append(TString("float noise1(vec3  x);"));
    //s.append(TString("float noise1(vec4  x);"));

    //s.append(TString("vec2 noise2(float x);"));
    //s.append(TString("vec2 noise2(vec2  x);"));
    //s.append(TString("vec2 noise2(vec3  x);"));
    //s.append(TString("vec2 noise2(vec4  x);"));

    //s.append(TString("vec3 noise3(float x);"));
    //s.append(TString("vec3 noise3(vec2  x);"));
    //s.append(TString("vec3 noise3(vec3  x);"));
    //s.append(TString("vec3 noise3(vec4  x);"));

    //s.append(TString("vec4 noise4(float x);"));
    //s.append(TString("vec4 noise4(vec2  x);"));
    //s.append(TString("vec4 noise4(vec3  x);"));
    //s.append(TString("vec4 noise4(vec4  x);"));

    return s;
}
Пример #13
0
// note - you may need to change the definition of the main function to
// be consistent with what your C++ compiler expects.
int main()
{
    ofstream outfile (pOutfileName, ios::out);
    if( !outfile.is_open() )
    {
        cout << "Error - unable to open output file: " << pOutfileName << endl;
        return 1;
    }

    //cout << "Writing output to " << pOutfileName << "... please wait" << endl;
    //ostream& outstream = outfile;  // uncomment to write to file
    ostream& outstream = cout;  // uncomment to write directly to cout

    const char *mp = 0;
    int step = 0;
    outstream << "----- simple String class test ----- (09/16/2010)" << endl << endl;

    // const checks  (compile tests)
	// If there are compile errors in this section, then there are probably const specifiers missing from your
	// class definition, e.g.  the length() member function should be defined as a const member function so
	// it can be invoked on a const TString object, as should all other member functions that don't change the
	// state of 'this'.
    {
        if (0 != 0)  // only a compilation check for these methods at this point (for const). Tested further below.
        {
            const TString s0(pHello); // create a const TString object
            int n = s0.length();
            bool f = s0.equalsIgnoreCase(pHello);
            f = s0.equals(pHello);
            const char *p = s0.asChar();
            n = s0.indexOf('h');
            const TString s1(s0);  // const String object parameter

            TString s2;
            s2.assign(s0);  // const String object parameter
            s2.append(s0);  // const String object parameter
        }
    }

    // Default ctor
    outstream << "\n----- Step " << ++step << " - default ctor -----" << endl;
    {
        TString s0;  // default arg value
        outstream << "s0 using default ctor with default arg = \"" << s0.asChar() << "\" (length = " << s0.length() << ")" << endl;
        mp = (0 == s0.length()) ? "OK: " : "ERROR: ";
        outstream << mp << "length = " << s0.length() << endl;
        mp = (0 != s0.asChar()) ? "OK: " : "ERROR: ";
        outstream << mp << "asChar() return value " << hex << "0x" << reinterpret_cast<const int *>(s0.asChar()) << dec << endl;
        mp = ('\0' == *(s0.asChar())) ? "OK: null byte " : "ERROR: null byte not ";
        outstream << mp << "at position 0" << endl;
    }
    {
        TString s0(copyToTemp(pHello));  // char * parameter
        clearTemp();
        outstream << endl << "s0 using default ctor with char* parameter = \"" << s0.asChar() << "\" (length = " << s0.length() << ")" << endl;
        mp = (s0.length() == strlen(pHello)) ? "OK: " : "ERROR: ";
        outstream << mp << "length = " << s0.length() << endl;
        mp = (0 == strcmp(s0.asChar(), pHello)) ? "OK: " : "ERROR: ";
        outstream << mp << "value is \"" << s0.asChar() << "\"" << endl;
        mp = (s0.asChar() != pHello) ? "OK: different " : "ERROR: same ";
        outstream << mp << "pointer value returned from asChar()" << endl;
        mp = (s0.asChar() == s0.asChar()) ? "OK: same " : "ERROR: different ";
        outstream << mp << "pointer value returned for successive calls of asChar()" << endl;
    }


    // Copy ctor
    outstream << "\n----- Step " << ++step << " - copy ctor -----" << endl;
    {
        TString s0(copyToTemp(pHiMom));
        clearTemp();
        TString s1(s0);  // copy ctor
        outstream << "s1 using copy ctor = \"" << s1.asChar() << "\" (length = " << s1.length() << ")" << endl;
        mp = (s1.length() == s0.length() && s1.length() == strlen(pHiMom)) ? "OK: " : "ERROR: ";
        outstream << mp << "length = " << s1.length() << endl;
        mp = (s1.asChar() != s0.asChar()) ? "OK: different " : "ERROR: same ";
        outstream << mp << "pointer value returned from asChar()" << endl;
        mp = (0 == strcmp(s1.asChar(), pHiMom)) ? "OK: " : "ERROR: ";
        outstream << mp << "value is \"" << s1.asChar() << "\"" << endl;
    }
    {
        // Check copy of empty string
        TString s0;
        TString s1(s0);
        outstream << "s1 using copy ctor = \"" << s1.asChar() << "\" (length = " << s1.length() << ")" << endl;
        mp = (0 == s1.length()) ? "OK: " : "ERROR: ";
        outstream << mp << "length = " << s1.length() << endl;
        mp = (0 != s1.asChar()) ? "OK: " : "ERROR: ";
        outstream << mp << "asChar() return value " << hex << "0x" << reinterpret_cast<const int *>(s1.asChar()) << dec << endl;
        mp = (s1.asChar() != s0.asChar()) ? "OK: different " : "ERROR: same ";
        outstream << mp << "pointer value returned from asChar()" << endl;
        mp = ('\0' == *(s0.asChar())) ? "OK: null byte " : "ERROR: null byte not ";
        outstream << mp << "at position 0" << endl;
    }


    // append
    outstream << "\n----- Step " << ++step << " - append -----" << endl;
    {
        TString s1(copyToTemp("Hello "));
        clearTemp();
        const char *p1 = s1.asChar();
        s1.append(copyToTemp("world "));
        clearTemp();
        mp = (s1.asChar() != p1) ? "OK: different " : "ERROR: same ";
        outstream << mp << "asChar() return value after append" << endl;
        s1.append(copyToTemp("from "));
        clearTemp();
        s1.append(copyToTemp("C++"));
        clearTemp();
        outstream << "s1 = \"" << s1.asChar() << "\" (length = " << s1.length() << ")" << endl;
        mp = (s1.equals(pHelloWorld)) ? "OK: matches " :  "ERROR: doesn't match ";
        outstream << mp << "\"" << pHelloWorld << "\"" << endl;
        mp = (s1.equalsIgnoreCase(pHelloLower)) ? "OK: matches ignore case " :  "ERROR: doesn't match ignore case ";
        outstream << mp << "\"" << pHelloLower << "\"" << endl;
        mp = (!s1.equals(pHiMom)) ? "OK: doesn't match " :  "ERROR: matches ";
        outstream << mp << "\"" << pHiMom << "\"" << endl;
    }
    {
        TString s1(copyToTemp(pHello));
        clearTemp();
        s1.append(s1);  // append to self
        s1.append(s1.asChar());  // append to self
        TString s2(copyToTemp(pHello));
        clearTemp();
        s2.append(copyToTemp(pHello));
        clearTemp();
        s2.append(copyToTemp(pHello));
        clearTemp();
        s2.append(copyToTemp(pHello));
        clearTemp();
        outstream << endl << "s1 appended to self = \"" << s1.asChar() << "\"" << endl;
        mp = (0 == strcmp(s1.asChar(), s2.asChar())) ? "OK: matches " : "ERROR: doesn't match ";
        outstream << mp << s2.asChar() << endl;
    }


    // assign
    outstream << "\n----- Step " << ++step << " - assign -----" << endl;
    {
        TString s0;
        s0.assign(copyToTemp(pHello));  // assign with char* parameter
        clearTemp();
        outstream << "s0 using assign with char* parameter = \"" << s0.asChar() << "\" (length = " << s0.length() << ")" << endl;
        mp = (s0.length() == strlen(pHello)) ? "OK: " : "ERROR: ";
        outstream << mp << "length = " << s0.length() << endl;
        mp = (0 == strcmp(s0.asChar(), pHello)) ? "OK: " : "ERROR: ";
        outstream << mp << "value is \"" << s0.asChar() << "\"" << endl;
        mp = (s0.asChar() != pHello) ? "OK: different " : "ERROR: same ";
        outstream << mp << "pointer value returned from asChar()" << endl;
    }
    {
        TString s0(copyToTemp(pHiMom));
        clearTemp();
        TString s1;
        s1.assign(s0);  // assign with String parameter
        outstream << endl << "s1 using assign with String parameter = \"" << s1.asChar() << "\" (length = " << s1.length() << ")" << endl;
        mp = (s1.length() == s0.length() && s1.length() == strlen(pHiMom)) ? "OK: " : "ERROR: ";
        outstream << mp << "length = " << s1.length() << endl;
        mp = (0 == strcmp(s1.asChar(), pHiMom)) ? "OK: " : "ERROR: ";
        outstream << mp << "value is \"" << s1.asChar() << "\"" << endl;
        mp = (s1.asChar() != s0.asChar()) ? "OK: different " : "ERROR: same ";
        outstream << mp << "pointer value returned from asChar()" << endl;
    }
    {
        TString s0(copyToTemp(pHelloWorld));
        clearTemp();
        TString s1(copyToTemp(pHi));
        clearTemp();
        s1.assign(s0);  // assign with String parameter
        outstream << endl << "s1 using assign with String parameter = \"" << s1.asChar() << "\" (length = " << s1.length() << ")" << endl;
        mp = (s1.length() == s0.length() && s1.length() == strlen(pHelloWorld)) ? "OK: " : "ERROR: ";
        outstream << mp << "length = " << s1.length() << endl;
        mp = (0 == strcmp(s1.asChar(), pHelloWorld)) ? "OK: " : "ERROR: ";
        outstream << mp << "value is \"" << s1.asChar() << "\"" << endl;
        mp = (s1.asChar() != s0.asChar()) ? "OK: different " : "ERROR: same ";
        outstream << mp << "pointer value returned from asChar()" << endl;
    }
    {
        TString s1(copyToTemp(pHello));
        clearTemp();
        outstream << endl << "s1 assign to self" << endl;
        const char* p1 = s1.asChar();
        s1.assign(s1);  // assign object to self
        mp = (s1.asChar() == p1) ? "OK: same " : "ERROR: different ";
        outstream << mp << " asChar() return value after String assign to self" << endl;
        p1 = s1.asChar();
        s1.assign(s1.asChar()); // assign char* array to self
        mp = (s1.asChar() == p1) ? "OK: same " : "ERROR: different ";
        outstream << mp << " asChar() return value after asChar() assign to self" << endl;
    }
    {
        TString s1(copyToTemp(pHello));
        clearTemp();
        outstream << endl << "s1 assign with char* parameter" << endl;
        s1.assign(copyToTemp(pHi));
        clearTemp();
        s1.append(copyToTemp(pMom));
        clearTemp();
        outstream << "s1 = \"" << s1.asChar() << "\" (length = " << s1.length() << ")" << endl;
        mp = (s1.equals(pHiMom)) ? "OK: matches " :  "ERROR: doesn't match ";
        outstream << mp << "\"" << pHiMom << "\"" << endl;
        mp = (!s1.equals(emptyString)) ? "OK: doesn't match " :  "ERROR: matches ";
        outstream << mp << "\"" << emptyString << "\"" << endl;
    }

    // Test null pointer and null string args
    outstream << "\n----- Step " << ++step << " - Null ptr and empty string -----" << endl;
    {
        TString s1;
        outstream << "Appending \"" << pHelloWorld << "\", empty string, and null pointer to s1 = \"" << s1.asChar() << "\"" << endl;
        s1.append(copyToTemp(pHelloWorld));
        clearTemp();
        s1.append(copyToTemp(""));
        clearTemp();
        s1.append(0);
        outstream << "s1 = \"" << s1.asChar() << "\" (length = " << s1.length() << ")" << endl;
        mp = (s1.equals(pHelloWorld)) ? "OK: matches " :  "ERROR: doesn't match ";
        outstream << mp << "\"" << pHelloWorld << "\"" << endl;
    }
    {
        TString s1(copyToTemp("not empty"));
        clearTemp();
        outstream << endl << "Assigning empty string to s1 = \"" << s1.asChar() << "\"" << endl;
        s1.assign(emptyString);
        outstream << "s1 = \"" << s1.asChar() << "\" (length = " << s1.length() << ")" << endl;
        mp = (s1.equals("")) ? "OK: matches " : "ERROR: doesn't match ";
        outstream << mp << "\"" << emptyString << "\"" << endl;
        mp = (0 == s1.length()) ? "OK: " : "ERROR: ";
        outstream << mp << "length = " << s1.length() << endl;
        mp = (0 != s1.asChar()) ? "OK: " : "ERROR: ";
        outstream << mp << "asChar() return value " << hex << "0x" << reinterpret_cast<const int *>(s1.asChar()) << dec << endl;
    }
    {
        TString s1(copyToTemp("still not empty"));
        clearTemp();
        outstream << endl << "Assigning null pointer to s1 = \"" << s1.asChar() << "\"" << endl;
        s1.assign(static_cast<const char *>(0));
        outstream << "s1 = \"" << s1.asChar() << "\" (length = " << s1.length() << ")" << endl;
        mp = (s1.equals("")) ? "OK: matches " : "ERROR: doesn't match ";
        outstream << mp << "\"" << emptyString << "\"" << endl;
        mp = (0 == s1.length()) ? "OK: " : "ERROR: ";
        outstream << mp << "length = " << s1.length() << endl;
        mp = (0 != s1.asChar()) ? "OK: " : "ERROR: ";
        outstream << mp << "asChar() return value " << hex << "0x" << reinterpret_cast<const int *>(s1.asChar()) << dec << endl;
    }

    // indexOf
    outstream << "\n----- Step " << ++step << " - indexOf -----" << endl;
    {
        TString s0(copyToTemp("Hi and hello"));
        clearTemp();
        int pos = s0.indexOf('H');
        mp = (0 == pos) ? "OK: 'H' found " : "ERROR: 'H' not found ";
        outstream << mp << " - indexOf = " << pos << endl;
        pos = s0.indexOf('h');
        mp = (7 == pos) ? "OK: 'h' found " : "ERROR: 'h' not found ";
        outstream << mp << " - indexOf = " << pos << endl;
        pos = s0.indexOf('o');
        mp = (11 == pos) ? "OK: 'o' found " : "ERROR: 'o' not found ";
        outstream << mp << " - indexOf = " << pos << endl;
        pos = s0.indexOf('z');
        mp = (-1 == pos) ? "OK: 'z' not found " : "ERROR: 'z' should return -1 ";
        outstream << mp << " - indexOf = " << pos << endl;
    }

    // Test many dynamic operations (this may take some time).
    // If the program aborts in this section, look at the code in the String ctors,
    // dtor, copy ctor, and assignment method to verify that dynamic memory
    // is managed correctly.
    outstream << "\n----- Step " << ++step << " - Heap memory use -----" << endl;
    outstream << "Heap use test (this could take a minute or two): " << endl;
    {
        TString s2;
        TString t1;
        for (int iter = 0; iter < 50; ++iter)
        {
            s2.assign(emptyString);
            TString t1(s2);
            for (int nc = 0; nc < 200; ++nc)
            {
                s2.append("x");
                s2.append(emptyString);
                s2.asChar();
                t1.append("yz");
                t1.append(static_cast<const char *>(0));
                t1.asChar();
            }
            TString t2;
            t2.assign(s2);
            t2.assign("vwq");
            t2.assign(t1);
            t2.assign(t2);
            t2.assign(static_cast<const char *>(0));
            t2.asChar();
            if (iter%100 == 0)
            {
                outstream << "." << flush;
            }
        }
        outstream << "completed" << endl;
    }

    // Testing dynamically allocated String objects. Uses the -> member selection operator for a
    // pointer to an object.
    outstream << "\n----- Step " << ++step << " - Heap Strings -----" << endl;
    {
        TString *sp = new TString;  // Create a heap based String object (sp points to it)
        sp->assign(copyToTemp(pHi));
        clearTemp();
        sp->append(copyToTemp(pMom));
        clearTemp();
        outstream << "sp = \"" << sp->asChar() << "\" (length = " << sp->length() << ")" << endl;
        mp = (sp->equals(pHiMom)) ? "OK: matches " :  "ERROR: doesn't match ";
        outstream << mp << "\"" << pHiMom << "\"" << endl;
        mp = (!sp->equals(emptyString)) ? "OK: doesn't match " :  "ERROR: matches ";
        outstream << mp << "\"" << emptyString << "\"" << endl;
        outstream << sp->asChar() << endl;

        const char* cp = sp->asChar();  // ptr to char array
        int cpLen = sp->length();
        delete sp;  // Free the heap based String object.
    }

    outstream << endl << "\nTest of simple String class completed" << endl << endl;

    outfile.close();
    return 0;
}
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+"));
}
Пример #15
0
void CLanguageManager::LoadFromFile(ELanguageType language)
{
#ifdef EDITOR_MODE
    BEYONDENGINE_UNUSED_PARAM(language);
    m_languageMap.clear();
    TString filePath = CResourceManager::GetInstance()->GetResourcePath(eRT_Resource);
    filePath.append(_T("/LanguageConfig.xml"));
    if (CFilePathTool::GetInstance()->Exists(filePath.c_str()))
    {
        rapidxml::file<> fdoc(filePath.c_str());
        rapidxml::xml_document<> doc;
        try
        {
            doc.parse<rapidxml::parse_default>(fdoc.data());
            doc.m_pszFilePath = filePath.c_str();
        }
        catch (rapidxml::parse_error &e)
        {
            TCHAR info[MAX_PATH];
            _stprintf(info, _T("Load file :%s Failed! error :%s"), filePath.c_str(), e.what());
            MessageBox(BEYONDENGINE_HWND, info, _T("Load File Failed"), MB_OK | MB_ICONERROR);
        }
        uint32_t uCounter = 0;
        rapidxml::xml_node<>* pRootNode = doc.first_node("Language");
        rapidxml::xml_node<>* pLanguageNode = pRootNode->first_node("LanguageNode");
        while (pLanguageNode != nullptr)
        {
            uCounter++;
            TString strEnum = pLanguageNode->first_attribute("Enum")->value();
            BEATS_ASSERT(!strEnum.empty());
            if (pLanguageNode->first_attribute("Tag"))
            {
                TString strTag = pLanguageNode->first_attribute("Tag")->value();
                m_languageTagMap[strEnum] = strTag;
            }
            BEATS_ASSERT(m_languageMap.find(strEnum) == m_languageMap.end());
            std::map<ELanguageType, TString>& curMap = m_languageMap[strEnum];
            rapidxml::xml_node<>* pLanguageValueNode = pLanguageNode->first_node();
            while (pLanguageValueNode != nullptr)
            {
                TString languageTypeStr = pLanguageValueNode->name();
                ELanguageType languageType = eLT_Count;
                for (int j = 0; j < eLT_Count; ++j)
                {
                    if (pszLanguageTypeString[j] == languageTypeStr)
                    {
                        languageType = (ELanguageType)j;
                        break;
                    }
                }
                BEATS_ASSERT(curMap.find(languageType) == curMap.end());
                const TCHAR* pszValue = pLanguageValueNode->first_attribute("Value")->value();
                BEATS_ASSERT(_tcslen(pszValue) > 0);
                curMap[languageType] = pszValue;
                pLanguageValueNode = pLanguageValueNode->next_sibling();
            }
            pLanguageNode = pLanguageNode->next_sibling();
        }
        BEATS_ASSERT((uint32_t)_ttoi(pRootNode->first_attribute("Count")->value()) == uCounter);
    }
#else
    TString filePath = CResourceManager::GetInstance()->GetResourcePath(eRT_Language);
    filePath.append(_T("/")).append(pszLanguageTypeString[language]).append(_T(".bin"));
    bool bFindLanguageFile = CFilePathTool::GetInstance()->Exists(filePath.c_str());
    BEATS_ASSERT(bFindLanguageFile, "Can't Find language file %s", filePath.c_str());
    if (bFindLanguageFile)
    {
        int count = 0;
        CSerializer tmp(filePath.c_str());
        tmp >> count;
        m_texts.clear();
        for (int i = 0; i < count; ++i)
        {
            ELanguageTextType textId = (ELanguageTextType)i;
            std::string strValue;
            tmp >> strValue;
            m_texts.emplace(textId, strValue);
        }
        tmp >> count;
        for (int i = 0; i < count; ++i)
        {
            uint32_t key;
            tmp >> key;
            BEATS_ASSERT(m_texts.find((ELanguageTextType)key) == m_texts.end());
            tmp >> m_texts[(ELanguageTextType)key];
        }
    }
#endif
}