From dbceaf702e5d2c987440ee2fc17d17a6ac6628f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Thu, 25 May 2017 20:24:02 -0700 Subject: [PATCH] Cleanup. --- tools/geometryc/geometryc.cpp | 36 ++++++++++++++++----------------- tools/shaderc/shaderc.cpp | 12 +++++------ tools/shaderc/shaderc_hlsl.cpp | 2 +- tools/shaderc/shaderc_spirv.cpp | 2 +- tools/texturev/texturev.cpp | 17 +++++++++------- 5 files changed, 36 insertions(+), 33 deletions(-) diff --git a/tools/geometryc/geometryc.cpp b/tools/geometryc/geometryc.cpp index 75d89b9a5..a3c4717d6 100644 --- a/tools/geometryc/geometryc.cpp +++ b/tools/geometryc/geometryc.cpp @@ -136,7 +136,7 @@ void triangleReorder(uint16_t* _indices, uint32_t _numIndices, uint32_t _numVert { uint16_t* newIndexList = new uint16_t[_numIndices]; Forsyth::OptimizeFaces(_indices, _numIndices, _numVertices, newIndexList, _cacheSize); - memcpy(_indices, newIndexList, _numIndices*2); + bx::memCopy(_indices, newIndexList, _numIndices*2); delete [] newIndexList; } @@ -159,9 +159,9 @@ void triangleCompress(bx::WriterI* _writer, uint16_t* _indices, uint32_t _numInd { uint32_t remap = vertexRemap[ii]; remap = UINT32_MAX == remap ? ii : remap; - memcpy(&outVertexData[remap*_stride], &_vertexData[ii*_stride], _stride); + bx::memCopy(&outVertexData[remap*_stride], &_vertexData[ii*_stride], _stride); } - memcpy(_vertexData, outVertexData, _numVertices*_stride); + bx::memCopy(_vertexData, outVertexData, _numVertices*_stride); free(outVertexData); free(vertexRemap); @@ -184,7 +184,7 @@ void calcTangents(void* _vertices, uint16_t _numVertices, bgfx::VertexDecl _decl }; float* tangents = new float[6*_numVertices]; - memset(tangents, 0, 6*_numVertices*sizeof(float) ); + bx::memSet(tangents, 0, 6*_numVertices*sizeof(float) ); PosTexcoord v0; PosTexcoord v1; @@ -519,17 +519,17 @@ int main(int _argc, const char* _argv[]) next = bx::tokenizeCommandLine(next, commandLine, len, argc, argv, BX_COUNTOF(argv), '\n'); if (0 < argc) { - if (0 == strcmp(argv[0], "#") ) + if (0 == bx::strCmp(argv[0], "#") ) { if (2 < argc - && 0 == strcmp(argv[2], "polygons") ) + && 0 == bx::strCmp(argv[2], "polygons") ) { } } - else if (0 == strcmp(argv[0], "f") ) + else if (0 == bx::strCmp(argv[0], "f") ) { Triangle triangle; - memset(&triangle, 0, sizeof(Triangle) ); + bx::memSet(&triangle, 0, sizeof(Triangle) ); const int numNormals = (int)normals.size(); const int numTexcoords = (int)texcoords.size(); @@ -624,7 +624,7 @@ int main(int _argc, const char* _argv[]) } } } - else if (0 == strcmp(argv[0], "g") ) + else if (0 == bx::strCmp(argv[0], "g") ) { EXPECT(1 < argc); group.m_name = argv[1]; @@ -639,7 +639,7 @@ int main(int _argc, const char* _argv[]) group.m_numTriangles = 0; } - if (0 == strcmp(argv[0], "vn") ) + if (0 == bx::strCmp(argv[0], "vn") ) { Vector3 normal; normal.x = (float)atof(argv[1]); @@ -648,7 +648,7 @@ int main(int _argc, const char* _argv[]) normals.push_back(normal); } - else if (0 == strcmp(argv[0], "vp") ) + else if (0 == bx::strCmp(argv[0], "vp") ) { static bool once = true; if (once) @@ -657,7 +657,7 @@ int main(int _argc, const char* _argv[]) printf("warning: 'parameter space vertices' are unsupported.\n"); } } - else if (0 == strcmp(argv[0], "vt") ) + else if (0 == bx::strCmp(argv[0], "vt") ) { Vector3 texcoord; texcoord.x = (float)atof(argv[1]); @@ -702,7 +702,7 @@ int main(int _argc, const char* _argv[]) positions.push_back(pos); } } - else if (0 == strcmp(argv[0], "usemtl") ) + else if (0 == bx::strCmp(argv[0], "usemtl") ) { std::string material(argv[1]); @@ -720,13 +720,13 @@ int main(int _argc, const char* _argv[]) group.m_material = material; } // unsupported tags -// else if (0 == strcmp(argv[0], "mtllib") ) +// else if (0 == bx::strCmp(argv[0], "mtllib") ) // { // } -// else if (0 == strcmp(argv[0], "o") ) +// else if (0 == bx::strCmp(argv[0], "o") ) // { // } -// else if (0 == strcmp(argv[0], "s") ) +// else if (0 == bx::strCmp(argv[0], "s") ) // { // } } @@ -947,7 +947,7 @@ int main(int _argc, const char* _argv[]) index.m_vertexIndex = numVertices++; float* position = (float*)(vertices + positionOffset); - memcpy(position, &positions[index.m_position], 3*sizeof(float) ); + bx::memCopy(position, &positions[index.m_position], 3*sizeof(float) ); if (hasColor) { @@ -969,7 +969,7 @@ int main(int _argc, const char* _argv[]) if (hasTexcoord) { float uv[2]; - memcpy(uv, &texcoords[index.m_texcoord], 2*sizeof(float) ); + bx::memCopy(uv, &texcoords[index.m_texcoord], 2*sizeof(float) ); if (flipV) { diff --git a/tools/shaderc/shaderc.cpp b/tools/shaderc/shaderc.cpp index 93abc770b..d269ac20a 100644 --- a/tools/shaderc/shaderc.cpp +++ b/tools/shaderc/shaderc.cpp @@ -343,7 +343,7 @@ namespace bgfx && m_data[1] == '\xbb' && m_data[2] == '\xbf') { - memmove(m_data, &m_data[3], m_size-3); + bx::memMove(m_data, &m_data[3], m_size-3); m_size -= 3; } @@ -619,7 +619,7 @@ namespace bgfx char* scratch(const char* _str) { char* result = &m_scratch[m_scratchPos]; - strcpy(result, _str); + bx::strCopy(result, uint32_t(sizeof(m_scratch)-m_scratchPos), _str); m_scratchPos += (uint32_t)bx::strLen(_str)+1; return result; @@ -1179,14 +1179,14 @@ namespace bgfx && data[1] == '\xbb' && data[2] == '\xbf') { - memmove(data, &data[3], size-3); + bx::memMove(data, &data[3], size-3); size -= 3; } // Compiler generates "error X3000: syntax error: unexpected end of file" // if input doesn't have empty line at EOF. data[size] = '\n'; - memset(&data[size+1], 0, padding); + bx::memSet(&data[size+1], 0, padding); bx::close(&reader); if (!raw) @@ -1199,8 +1199,8 @@ namespace bgfx size = (uint32_t)preprocessor.m_preprocessed.size(); data = new char[size+padding+1]; - memcpy(data, preprocessor.m_preprocessed.c_str(), size); - memset(&data[size], 0, padding+1); + bx::memCopy(data, preprocessor.m_preprocessed.c_str(), size); + bx::memSet(&data[size], 0, padding+1); } strNormalizeEol(data); diff --git a/tools/shaderc/shaderc_hlsl.cpp b/tools/shaderc/shaderc_hlsl.cpp index 280625629..85eb74220 100644 --- a/tools/shaderc/shaderc_hlsl.cpp +++ b/tools/shaderc/shaderc_hlsl.cpp @@ -190,7 +190,7 @@ namespace bgfx { namespace hlsl for (uint32_t ii = 0; ii < bgfx::Attrib::Count; ++ii) { const RemapInputSemantic& ris = s_remapInputSemantic[ii]; - if (0 == strcmp(ris.m_name, _name) + if (0 == bx::strCmp(ris.m_name, _name) && ris.m_index == _index) { return ris; diff --git a/tools/shaderc/shaderc_spirv.cpp b/tools/shaderc/shaderc_spirv.cpp index e79e64008..e788db476 100644 --- a/tools/shaderc/shaderc_spirv.cpp +++ b/tools/shaderc/shaderc_spirv.cpp @@ -529,7 +529,7 @@ namespace bgfx { namespace spirv virtual int32_t write(const void* _data, int32_t _size, bx::Error*) BX_OVERRIDE { char* out = (char*)alloca(_size + 1); - memcpy(out, _data, _size); + bx::memCopy(out, _data, _size); out[_size] = '\0'; printf("%s", out); return _size; diff --git a/tools/texturev/texturev.cpp b/tools/texturev/texturev.cpp index 0123da21a..468ecc722 100644 --- a/tools/texturev/texturev.cpp +++ b/tools/texturev/texturev.cpp @@ -585,7 +585,7 @@ void associate() char temp[MAX_PATH]; GetTempPathA(MAX_PATH, temp); - strcat(temp, "\\texturev.reg"); + bx::strCat(temp, "\\texturev.reg"); bx::CrtFileWriter writer; bx::Error err; @@ -997,19 +997,22 @@ int _main_(int _argc, char** _argv) bgfx::dbgTextClear(); scale.set( - bx::fmin( float(width) / float(view.m_info.width) - , float(height) / float(view.m_info.height) + bx::fmin( float(width) / float(view.m_info.width) + , float(height) / float(view.m_info.height) ) , 0.1f ); zoom.set(view.m_zoom, transitionTime); - float ss = scale.getValue() * zoom.getValue(); + float ss = scale.getValue() + * zoom.getValue() + ; - screenQuad( int(width - view.m_info.width * ss)/2 + screenQuad( + int(width - view.m_info.width * ss)/2 , int(height - view.m_info.height * ss)/2 - , int(view.m_info.width * ss) - , int(view.m_info.height * ss) + , int( view.m_info.width * ss) + , int( view.m_info.height * ss) , view.m_abgr );