aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChaplain <aionthefirst@gmail.com>2013-09-28 15:47:23 +0300
committerChaplain <aionthefirst@gmail.com>2013-09-28 15:47:23 +0300
commit42ae39bf9798323d6da7275a76c65adb586940be (patch)
tree293b7f649d28acd498529345d639c68e8bdedaa5 /src
parentcde2e4d6c96614d1d34a3578a77a369e38fc677c (diff)
Tools/MeshExtractor: Cleanup using static analyzing tool
*printf format fixed *method arguments changed to const where needed *removed not needed strlen() from cycles *other minor changes
Diffstat (limited to 'src')
-rw-r--r--src/tools/mesh_extractor/ChunkedData.cpp6
-rw-r--r--src/tools/mesh_extractor/ChunkedData.h6
-rw-r--r--src/tools/mesh_extractor/ContinentBuilder.cpp8
-rw-r--r--src/tools/mesh_extractor/DoodadHandler.cpp3
-rw-r--r--src/tools/mesh_extractor/MPQManager.cpp6
-rw-r--r--src/tools/mesh_extractor/MPQManager.h6
-rw-r--r--src/tools/mesh_extractor/MeshExtractor.cpp20
-rw-r--r--src/tools/mesh_extractor/TileBuilder.cpp10
-rw-r--r--src/tools/mesh_extractor/Utils.cpp23
-rw-r--r--src/tools/mesh_extractor/Utils.h20
-rw-r--r--src/tools/mesh_extractor/WorldModelHandler.cpp26
11 files changed, 75 insertions, 59 deletions
diff --git a/src/tools/mesh_extractor/ChunkedData.cpp b/src/tools/mesh_extractor/ChunkedData.cpp
index e0db12a6be7..f273ef946dd 100644
--- a/src/tools/mesh_extractor/ChunkedData.cpp
+++ b/src/tools/mesh_extractor/ChunkedData.cpp
@@ -12,7 +12,7 @@ Stream(stream)
Load(maxLength, chunksHint);
}
-ChunkedData::ChunkedData( std::string file, uint32 chunksHint /*= 300*/ )
+ChunkedData::ChunkedData( const std::string& file, uint32 chunksHint /*= 300*/ )
{
Stream = MPQHandler->GetFile(file);
if (!Stream)
@@ -47,7 +47,7 @@ void ChunkedData::Load( uint32 maxLength, uint32 chunksHint )
}
}
-int ChunkedData::GetFirstIndex( std::string name )
+int ChunkedData::GetFirstIndex( const std::string& name )
{
for (uint32 i = 0; i < Chunks.size(); ++i)
if (Chunks[i]->Name == name)
@@ -55,7 +55,7 @@ int ChunkedData::GetFirstIndex( std::string name )
return -1;
}
-Chunk* ChunkedData::GetChunkByName( std::string name )
+Chunk* ChunkedData::GetChunkByName( const std::string& name )
{
for (uint32 i = 0; i < Chunks.size(); ++i)
if (Chunks[i]->Name == name)
diff --git a/src/tools/mesh_extractor/ChunkedData.h b/src/tools/mesh_extractor/ChunkedData.h
index e23648c845e..1e1cb17749e 100644
--- a/src/tools/mesh_extractor/ChunkedData.h
+++ b/src/tools/mesh_extractor/ChunkedData.h
@@ -8,11 +8,11 @@ class ChunkedData
{
public:
ChunkedData(FILE* stream, uint32 maxLength, uint32 chunksHint = 300);
- ChunkedData(std::string file, uint32 chunksHint = 300);
+ ChunkedData(const std::string &file, uint32 chunksHint = 300);
~ChunkedData();
- int GetFirstIndex(std::string name);
- Chunk* GetChunkByName(std::string name);
+ int GetFirstIndex(const std::string& name);
+ Chunk* GetChunkByName(const std::string& name);
void Load(uint32 maxLength, uint32 chunksHint);
std::vector<Chunk*> Chunks;
diff --git a/src/tools/mesh_extractor/ContinentBuilder.cpp b/src/tools/mesh_extractor/ContinentBuilder.cpp
index d6125bdd8e2..a6b4e3763a0 100644
--- a/src/tools/mesh_extractor/ContinentBuilder.cpp
+++ b/src/tools/mesh_extractor/ContinentBuilder.cpp
@@ -17,7 +17,7 @@ private:
ContinentBuilder* cBuilder;
public:
BuilderThread(ContinentBuilder* _cBuilder, bool deb, dtNavMeshParams& params) : debug(deb), Params(params), cBuilder(_cBuilder), Free(true) {}
- void SetData(int x, int y, int map, std::string cont) { X = x; Y = y; MapId = map; Continent = cont; }
+ void SetData(int x, int y, int map, const std::string& cont) { X = x; Y = y; MapId = map; Continent = cont; }
int svc()
{
@@ -25,7 +25,7 @@ public:
printf("[%02i,%02i] Building tile\n", X, Y);
TileBuilder builder(cBuilder, Continent, X, Y, MapId);
char buff[100];
- sprintf(buff, "mmaps/%03u%02u%02u.mmtile", MapId, Y, X);
+ sprintf(buff, "mmaps/%03u%02i%02i.mmtile", MapId, Y, X);
FILE* f = fopen(buff, "r");
if (f) // Check if file already exists.
{
@@ -50,7 +50,7 @@ public:
fclose(f);
}
dtFree(nav);
- printf("[%02u,%02u] Tile Built!\n", X, Y);
+ printf("[%02i,%02i] Tile Built!\n", X, Y);
Free = true;
return 0;
}
@@ -113,7 +113,7 @@ void ContinentBuilder::Build(bool debug)
std::vector<BuilderThread*> Threads;
for (uint32 i = 0; i < NumberOfThreads; ++i)
Threads.push_back(new BuilderThread(this, debug, params));
- printf("Map %s ( %i ) has %u tiles. Building them with %i threads\n", Continent.c_str(), MapId, uint32(TileMap->TileTable.size()), NumberOfThreads);
+ printf("Map %s ( %u ) has %u tiles. Building them with %u threads\n", Continent.c_str(), MapId, uint32(TileMap->TileTable.size()), NumberOfThreads);
for (std::vector<TilePos>::iterator itr = TileMap->TileTable.begin(); itr != TileMap->TileTable.end(); ++itr)
{
bool next = false;
diff --git a/src/tools/mesh_extractor/DoodadHandler.cpp b/src/tools/mesh_extractor/DoodadHandler.cpp
index 56c2a7986f8..ed683d70520 100644
--- a/src/tools/mesh_extractor/DoodadHandler.cpp
+++ b/src/tools/mesh_extractor/DoodadHandler.cpp
@@ -30,7 +30,8 @@ void DoodadHandler::ProcessInternal( ChunkedData* subChunks )
for (uint32 i = 0; i < refCount; i++)
{
int32 index;
- if (int count = fread(&index, sizeof(int32), 1, stream) != 1)
+ int32 count;
+ if ((count = fread(&index, sizeof(int32), 1, stream)) != 1)
printf("DoodadHandler::ProcessInternal: Failed to read some data expected 1, read %d\n", count);
if (index < 0 || uint32(index) >= _definitions->size())
continue;
diff --git a/src/tools/mesh_extractor/MPQManager.cpp b/src/tools/mesh_extractor/MPQManager.cpp
index 91b9c121c89..c95179f2680 100644
--- a/src/tools/mesh_extractor/MPQManager.cpp
+++ b/src/tools/mesh_extractor/MPQManager.cpp
@@ -64,7 +64,7 @@ void MPQManager::InitializeDBC()
printf("Using default locale: %s\n", Languages[BaseLocale]);
}
-FILE* MPQManager::GetFile( std::string path )
+FILE* MPQManager::GetFile(const std::string& path )
{
ACE_GUARD_RETURN(ACE_Thread_Mutex, g, mutex, NULL);
MPQFile file(path.c_str());
@@ -73,13 +73,13 @@ FILE* MPQManager::GetFile( std::string path )
return file.GetFileStream();
}
-DBC* MPQManager::GetDBC( std::string name )
+DBC* MPQManager::GetDBC(const std::string& name )
{
std::string path = "DBFilesClient\\" + name + ".dbc";
return new DBC(GetFile(path));
}
-FILE* MPQManager::GetFileFrom( std::string path, MPQArchive* file )
+FILE* MPQManager::GetFileFrom(const std::string& path, MPQArchive* file )
{
ACE_GUARD_RETURN(ACE_Thread_Mutex, g, mutex, NULL);
mpq_archive* mpq_a = file->mpq_a;
diff --git a/src/tools/mesh_extractor/MPQManager.h b/src/tools/mesh_extractor/MPQManager.h
index 2f49ad258a5..7f9d675c4d4 100644
--- a/src/tools/mesh_extractor/MPQManager.h
+++ b/src/tools/mesh_extractor/MPQManager.h
@@ -14,9 +14,9 @@ public:
~MPQManager() {}
void Initialize();
- FILE* GetFile(std::string path);
- FILE* GetFileFrom(std::string path, MPQArchive* file);
- DBC* GetDBC(std::string name);
+ FILE* GetFile(const std::string& path);
+ FILE* GetFileFrom(const std::string& path, MPQArchive* file);
+ DBC* GetDBC(const std::string& name);
std::vector<std::string> GetAllFiles(std::string extension);
std::deque<MPQArchive*> Archives;
diff --git a/src/tools/mesh_extractor/MeshExtractor.cpp b/src/tools/mesh_extractor/MeshExtractor.cpp
index 89bc65866b4..e2550eec25a 100644
--- a/src/tools/mesh_extractor/MeshExtractor.cpp
+++ b/src/tools/mesh_extractor/MeshExtractor.cpp
@@ -53,10 +53,12 @@ void ExtractDBCs()
// Populate list of DBC files
std::set<std::string> DBCFiles;
+ const size_t extLen = strlen(".dbc");
for (std::vector<std::string>::iterator itr = MPQHandler->LocaleFiles[MPQHandler->BaseLocale]->Files.begin(); itr != MPQHandler->LocaleFiles[MPQHandler->BaseLocale]->Files.end(); ++itr)
- if (itr->rfind(".dbc") == itr->length() - strlen(".dbc"))
+ if (itr->rfind(".dbc") == itr->length() - extLen)
DBCFiles.insert(*itr);
+ const size_t folderLen = strlen("DBFilesClient\\");
// Iterate over all available locales
for (std::set<uint32>::iterator itr = MPQHandler->AvailableLocales.begin(); itr != MPQHandler->AvailableLocales.end(); ++itr)
{
@@ -73,7 +75,7 @@ void ExtractDBCs()
Utils::SaveToDisk(MPQHandler->GetFile(component), path + component);
// Extract the DBC files for the given locale
for (std::set<std::string>::iterator itr2 = DBCFiles.begin(); itr2 != DBCFiles.end(); ++itr2)
- Utils::SaveToDisk(MPQHandler->GetFileFrom(*itr2, MPQHandler->LocaleFiles[*itr]), path + (itr2->c_str() + strlen("DBFilesClient\\")));
+ Utils::SaveToDisk(MPQHandler->GetFileFrom(*itr2, MPQHandler->LocaleFiles[*itr]), path + (itr2->c_str() + folderLen));
}
printf("DBC extraction finished!\n");
}
@@ -201,16 +203,18 @@ void ExtractGameobjectModels()
fwrite(&model.Header.CountGroups, sizeof(uint32), 1, output);
fwrite(&model.Header.WmoId, sizeof(uint32), 1, output);
+ const char grp[] = { 'G' , 'R' , 'P', ' ' };
for (std::vector<WorldModelGroup>::iterator itr2 = model.Groups.begin(); itr2 != model.Groups.end(); ++itr2)
{
- fwrite(&itr2->Header.Flags, sizeof(uint32), 1, output);
- fwrite(&itr2->Header.WmoId, sizeof(uint32), 1, output);
- fwrite(&itr2->Header.BoundingBox[0], sizeof(uint32), 1, output);
- fwrite(&itr2->Header.BoundingBox[1], sizeof(uint32), 1, output);
+ const WMOGroupHeader& header = itr2->Header;
+ fwrite(&header.Flags, sizeof(uint32), 1, output);
+ fwrite(&header.WmoId, sizeof(uint32), 1, output);
+ fwrite(&header.BoundingBox[0], sizeof(uint32), 1, output);
+ fwrite(&header.BoundingBox[1], sizeof(uint32), 1, output);
uint32 LiquidFlags = itr2->HasLiquidData ? 1 : 0;
fwrite(&LiquidFlags, sizeof(uint32), 1, output);
- fwrite("GRP ", sizeof(char), 4, output);
+ fwrite(grp, sizeof(char), sizeof(grp), output);
uint32 k = 0;
uint32 mobaBatch = itr2->MOBALength / 12;
uint32* MobaEx = new uint32[mobaBatch*4];
@@ -250,7 +254,7 @@ bool HandleArgs(int argc, char** argv, uint32& threads, std::set<uint32>& mapLis
return false;
threads = atoi(param);
- printf("Using %i threads\n", threads);
+ printf("Using %u threads\n", threads);
}
else if (strcmp(argv[i], "--maps") == 0)
{
diff --git a/src/tools/mesh_extractor/TileBuilder.cpp b/src/tools/mesh_extractor/TileBuilder.cpp
index c52c4a04fc4..fa50b85caaf 100644
--- a/src/tools/mesh_extractor/TileBuilder.cpp
+++ b/src/tools/mesh_extractor/TileBuilder.cpp
@@ -113,9 +113,15 @@ uint8* TileBuilder::Build(bool dbg, dtNavMeshParams& navMeshParams)
sprintf(buff, "mmaps/%s_%02u%02u.obj", World.c_str(), Y, X);
FILE* debug = fopen(buff, "wb");
for (uint32 i = 0; i < _Geometry->Vertices.size(); ++i)
- fprintf(debug, "v %f %f %f\n", _Geometry->Vertices[i].x, _Geometry->Vertices[i].y, _Geometry->Vertices[i].z);
+ {
+ const Vector3& vector = _Geometry->Vertices[i];
+ fprintf(debug, "v %f %f %f\n", vector.x, vector.y, vector.z);
+ }
for (uint32 i = 0; i < _Geometry->Triangles.size(); ++i)
- fprintf(debug, "f %i %i %i\n", _Geometry->Triangles[i].V0 + 1, _Geometry->Triangles[i].V1 + 1, _Geometry->Triangles[i].V2 + 1);
+ {
+ const Triangle<uint32>& triangle = _Geometry->Triangles[i];
+ fprintf(debug, "f %u %u %u\n", triangle.V0 + 1, triangle.V1 + 1, triangle.V2 + 1);
+ }
fclose(debug);
}
diff --git a/src/tools/mesh_extractor/Utils.cpp b/src/tools/mesh_extractor/Utils.cpp
index 33c30d7522c..49df7e20eba 100644
--- a/src/tools/mesh_extractor/Utils.cpp
+++ b/src/tools/mesh_extractor/Utils.cpp
@@ -72,17 +72,17 @@ uint32 Utils::Size( FILE* file )
return size;
}
-Vector3 Utils::ToRecast( Vector3 val )
+Vector3 Utils::ToRecast(const Vector3& val )
{
return Vector3(-val.y, val.z, -val.x);
}
-std::string Utils::GetAdtPath( std::string world, int x, int y )
+std::string Utils::GetAdtPath(const std::string& world, int x, int y )
{
return "World\\Maps\\" + world + "\\" + world + "_" + Utils::ToString(x) + "_" + Utils::ToString(y) + ".adt";
}
-std::string Utils::FixModelPath( std::string path )
+std::string Utils::FixModelPath(const std::string& path )
{
return Utils::GetPathBase(path) + ".M2";
}
@@ -99,7 +99,7 @@ G3D::Matrix4 Utils::RotationX(float angle)
return ret;
}
-G3D::Matrix4 Utils::GetTransformation(IDefinition def)
+G3D::Matrix4 Utils::GetTransformation(const IDefinition& def)
{
G3D::Matrix4 translation;
if (def.Position.x == 0.0f && def.Position.y == 0.0f && def.Position.z == 0.0f)
@@ -143,7 +143,7 @@ float Utils::ToRadians( float degrees )
return Constants::PI * degrees / 180.0f;
}
-Vector3 Utils::VectorTransform( Vector3 vec, G3D::Matrix4 matrix )
+Vector3 Utils::VectorTransform(const Vector3& vec, const G3D::Matrix4& matrix )
{
Vector3 ret;
ret.x = vec.x * matrix[1][1] + vec.y * matrix[2][1] + vec.z * matrix[3][1] + matrix[4][1];
@@ -152,7 +152,7 @@ Vector3 Utils::VectorTransform( Vector3 vec, G3D::Matrix4 matrix )
return ret;
}
-std::string Utils::GetPathBase( std::string path )
+std::string Utils::GetPathBase(const std::string& path )
{
size_t lastIndex = path.find_last_of(".");
if (lastIndex != std::string::npos)
@@ -168,7 +168,7 @@ Vector3 Vector3::Read( FILE* file )
return ret;
}
-Vector3 Utils::GetLiquidVert(G3D::Matrix4 transformation, Vector3 basePosition, float height, int /*x*/, int /*y*/)
+Vector3 Utils::GetLiquidVert(const G3D::Matrix4& transformation, Vector3 basePosition, float height, int /*x*/, int /*y*/)
{
if (Utils::Distance(height, 0.0f) > 0.5f)
basePosition.z = 0.0f;
@@ -191,7 +191,7 @@ std::string Utils::Replace( std::string str, const std::string& oldStr, const st
return str;
}
-G3D::Matrix4 Utils::GetWmoDoodadTransformation( DoodadInstance inst, WorldModelDefinition root )
+G3D::Matrix4 Utils::GetWmoDoodadTransformation(const DoodadInstance& inst, const WorldModelDefinition& root )
{
G3D::Matrix4 rootTransformation = Utils::GetTransformation(root);
G3D::Matrix4 translation = G3D::Matrix4::translation(inst.Position.x, inst.Position.y, inst.Position.z);
@@ -203,7 +203,7 @@ G3D::Matrix4 Utils::GetWmoDoodadTransformation( DoodadInstance inst, WorldModelD
return scale * rotation * quatRotation ** translation * rootTransformation;
}
-void Utils::SaveToDisk( FILE* stream, std::string path )
+void Utils::SaveToDisk( FILE* stream, const std::string& path )
{
FILE* disk = fopen(path.c_str(), "wb");
if (!disk)
@@ -229,7 +229,7 @@ void Utils::SaveToDisk( FILE* stream, std::string path )
delete [] data;
}
-Vector3 Utils::ToWoWCoords( Vector3 vec )
+Vector3 Utils::ToWoWCoords(const Vector3& vec )
{
return Vector3(vec.x, -vec.z, vec.y);
}
@@ -484,7 +484,8 @@ LiquidData LiquidData::Read(FILE* stream, LiquidHeader& header)
H2ORenderMask H2ORenderMask::Read(FILE* stream)
{
H2ORenderMask ret;
- if (int count = fread(&ret.Mask, sizeof(uint8), 8, stream) != 8)
+ int32 count;
+ if ((count = fread(&ret.Mask, sizeof(uint8), 8, stream)) != 8)
printf("H2OHeader::Read: Failed to read some data expected 8, read %d\n", count);
return ret;
}
diff --git a/src/tools/mesh_extractor/Utils.h b/src/tools/mesh_extractor/Utils.h
index 64fb1bb35ba..e6bb6a59bda 100644
--- a/src/tools/mesh_extractor/Utils.h
+++ b/src/tools/mesh_extractor/Utils.h
@@ -342,10 +342,10 @@ public:
static void Reverse(char word[]);
static std::string ReadString(FILE* file);
static uint32 Size(FILE* file);
- static Vector3 ToRecast( Vector3 val );
- static std::string GetAdtPath(std::string world, int x, int y);
- static std::string FixModelPath(std::string path);
- static G3D::Matrix4 GetTransformation(IDefinition def);
+ static Vector3 ToRecast(const Vector3& val );
+ static std::string GetAdtPath(const std::string& world, int x, int y);
+ static std::string FixModelPath(const std::string& path);
+ static G3D::Matrix4 GetTransformation(const IDefinition& def);
/// They say its better to declare template functions in the header files.
template <typename T>
static std::string ToString(T val)
@@ -358,9 +358,9 @@ public:
static G3D::Matrix4 RotationY(float angle);
static G3D::Matrix4 RotationZ(float angle);
static float ToRadians(float degrees);
- static Vector3 VectorTransform(Vector3 vec, G3D::Matrix4 matrix);
- static std::string GetPathBase(std::string path);
- static Vector3 GetLiquidVert(G3D::Matrix4 transformation, Vector3 basePosition, float height, int x, int y);
+ static Vector3 VectorTransform(const Vector3& vec, const G3D::Matrix4& matrix);
+ static std::string GetPathBase(const std::string& path);
+ static Vector3 GetLiquidVert(const G3D::Matrix4& transformation, Vector3 basePosition, float height, int x, int y);
static float Distance(float x, float y);
template<typename T>
static bool IsAllZero(T* arr, uint32 size)
@@ -371,10 +371,10 @@ public:
return true;
}
static std::string Replace( std::string str, const std::string& oldStr, const std::string& newStr );
- static G3D::Matrix4 GetWmoDoodadTransformation( DoodadInstance inst, WorldModelDefinition root );
+ static G3D::Matrix4 GetWmoDoodadTransformation(const DoodadInstance& inst, const WorldModelDefinition& root );
static void CreateDir( const std::string& Path );
- static void SaveToDisk(FILE* stream, std::string path);
- static Vector3 ToWoWCoords( Vector3 vec );
+ static void SaveToDisk(FILE* stream, const std::string& path);
+ static Vector3 ToWoWCoords(const Vector3& vec );
static std::string GetExtension( std::string path );
static char* GetPlainName(const char* FileName);
};
diff --git a/src/tools/mesh_extractor/WorldModelHandler.cpp b/src/tools/mesh_extractor/WorldModelHandler.cpp
index ecfff4e97d4..cc011b298eb 100644
--- a/src/tools/mesh_extractor/WorldModelHandler.cpp
+++ b/src/tools/mesh_extractor/WorldModelHandler.cpp
@@ -133,22 +133,26 @@ void WorldModelHandler::InsertModelGeometry( std::vector<Vector3>& verts, std::v
if (!group->HasLiquidData)
continue;
- for (uint32 y = 0; y < group->LiquidDataHeader.Height; y++)
+ const LiquidHeader& liquidHeader = group->LiquidDataHeader;
+ LiquidData& liquidDataGeometry = group->LiquidDataGeometry;
+
+ for (uint32 y = 0; y < liquidHeader.Height; y++)
{
- for (uint32 x = 0; x < group->LiquidDataHeader.Width; x++)
+ for (uint32 x = 0; x < liquidHeader.Width; x++)
{
- if (!group->LiquidDataGeometry.ShouldRender(x, y))
+
+ if (!liquidDataGeometry.ShouldRender(x, y))
continue;
uint32 vertOffset = verts.size();
- verts.push_back(Utils::GetLiquidVert(transformation, group->LiquidDataHeader.BaseLocation,
- group->LiquidDataGeometry.HeightMap[x][y], x, y));
- verts.push_back(Utils::GetLiquidVert(transformation, group->LiquidDataHeader.BaseLocation,
- group->LiquidDataGeometry.HeightMap[x + 1][y], x + 1, y));
- verts.push_back(Utils::GetLiquidVert(transformation, group->LiquidDataHeader.BaseLocation,
- group->LiquidDataGeometry.HeightMap[x][y + 1], x, y + 1));
- verts.push_back(Utils::GetLiquidVert(transformation, group->LiquidDataHeader.BaseLocation,
- group->LiquidDataGeometry.HeightMap[x + 1][y + 1], x + 1, y + 1));
+ verts.push_back(Utils::GetLiquidVert(transformation, liquidHeader.BaseLocation,
+ liquidDataGeometry.HeightMap[x][y], x, y));
+ verts.push_back(Utils::GetLiquidVert(transformation, liquidHeader.BaseLocation,
+ liquidDataGeometry.HeightMap[x + 1][y], x + 1, y));
+ verts.push_back(Utils::GetLiquidVert(transformation, liquidHeader.BaseLocation,
+ liquidDataGeometry.HeightMap[x][y + 1], x, y + 1));
+ verts.push_back(Utils::GetLiquidVert(transformation, liquidHeader.BaseLocation,
+ liquidDataGeometry.HeightMap[x + 1][y + 1], x + 1, y + 1));
tris.push_back(Triangle<uint32>(Constants::TRIANGLE_TYPE_WATER, vertOffset, vertOffset + 2, vertOffset + 1));
tris.push_back(Triangle<uint32>(Constants::TRIANGLE_TYPE_WATER, vertOffset + 2, vertOffset + 3, vertOffset + 1));