refactor(Tools): restyle tools with astyle (#3465)

This commit is contained in:
Kargatum
2020-10-06 16:31:28 +07:00
committed by GitHub
parent be09e03756
commit b00a86f6ab
51 changed files with 1004 additions and 936 deletions

View File

@@ -11,7 +11,7 @@
#include <string>
ChunkedData::ChunkedData( FILE* stream, uint32 maxLength, uint32 chunksHint /*= 300*/ ) :
Stream(stream)
Stream(stream)
{
if (!Stream)
return;

View File

@@ -14,7 +14,7 @@ class ChunkedData
{
public:
ChunkedData(FILE* stream, uint32 maxLength, uint32 chunksHint = 300);
ChunkedData(const std::string &file, uint32 chunksHint = 300);
ChunkedData(const std::string& file, uint32 chunksHint = 300);
~ChunkedData();
int GetFirstIndex(const std::string& name);

View File

@@ -23,13 +23,13 @@ private:
ContinentBuilder* cBuilder;
public:
BuilderThread(ContinentBuilder* _cBuilder, dtNavMeshParams& params) : Params(params), cBuilder(_cBuilder), Free(true) {}
void SetData(int x, int y, int map, const 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()
@@ -116,13 +116,13 @@ void ContinentBuilder::Build()
CalculateTileBounds();
dtNavMeshParams params;
std::vector<BuilderThread*> Threads;
if (TileMap->IsGlobalModel)
{
printf("Map %s ( %u ) is a WMO. Building with 1 thread.\n", Continent.c_str(), MapId);
TileBuilder* builder = new TileBuilder(this, Continent, 0, 0, MapId);
builder->AddGeometry(TileMap->Model, TileMap->ModelDefinition);
uint8* nav = builder->BuildInstance(params);

View File

@@ -16,7 +16,7 @@ public:
ContinentBuilder(std::string continent, uint32 mapId, WDT* wdt, uint32 tn) :
Continent(continent), TileMap(wdt), MapId(mapId),
NumberOfThreads(tn), tileXMin(64), tileYMin(64), tileXMax(0), tileYMax(0)
{}
{}
void Build();
void getTileBounds(uint32 tileX, uint32 tileY, float* verts, int vertCount, float* bmin, float* bmax);

View File

@@ -58,7 +58,7 @@ std::string DBC::GetStringByOffset( int offset )
break;
}
}
char* d = new char[len+1];
char* d = new char[len + 1];
strcpy(d, (const char*)(StringBlock + offset));
d[len] = '\0';
std::string val = std::string(d);

View File

@@ -10,7 +10,7 @@
#include "Model.h"
#include "G3D/Matrix4.h"
DoodadHandler::DoodadHandler( ADT* adt ) :
DoodadHandler::DoodadHandler( ADT* adt ) :
ObjectDataHandler(adt), _definitions(nullptr), _paths(nullptr)
{
Chunk* mddf = adt->ObjectData->GetChunkByName("MDDF");
@@ -27,7 +27,7 @@ void DoodadHandler::ProcessInternal( MapChunk* mcnk )
{
if (!IsSane())
return;
uint32 refCount = mcnk->Header.DoodadRefs;
FILE* stream = mcnk->Source->GetStream();
fseek(stream, mcnk->Source->Offset + mcnk->Header.OffsetMCRF, SEEK_SET);
@@ -100,7 +100,7 @@ void DoodadHandler::ReadDoodadPaths( Chunk* id, Chunk* data )
void DoodadHandler::InsertModelGeometry(const DoodadDefinition& def, Model* model)
{
uint32 vertOffset = Vertices.size();
for (std::vector<Vector3>::iterator itr = model->Vertices.begin(); itr != model->Vertices.end(); ++itr)
Vertices.push_back(Utils::TransformDoodadVertex(def, *itr)); // Vertices have to be converted based on the information from the DoodadDefinition struct

View File

@@ -100,7 +100,7 @@ void LiquidHandler::HandleNewLiquid()
Vertices.push_back(Vector3(location.x, location.y - Constants::UnitSize, location.z));
Vertices.push_back(Vector3(location.x - Constants::UnitSize, location.y - Constants::UnitSize, location.z));
Triangles.push_back(Triangle<uint32>(Constants::TRIANGLE_TYPE_WATER, vertOffset, vertOffset+2, vertOffset + 1));
Triangles.push_back(Triangle<uint32>(Constants::TRIANGLE_TYPE_WATER, vertOffset, vertOffset + 2, vertOffset + 1));
Triangles.push_back(Triangle<uint32>(Constants::TRIANGLE_TYPE_WATER, vertOffset + 2, vertOffset + 3, vertOffset + 1));
}
}

View File

@@ -46,9 +46,9 @@ void MPQArchive::close()
}
MPQFile::MPQFile(const char* filename):
eof(false), buffer(0), pointer(0), size(0)
eof(false), buffer(0), pointer(0), size(0)
{
for (std::deque<MPQArchive*>::iterator i = MPQHandler->Archives.begin(); i != MPQHandler->Archives.end();++i)
for (std::deque<MPQArchive*>::iterator i = MPQHandler->Archives.begin(); i != MPQHandler->Archives.end(); ++i)
{
mpq_archive* mpq_a = (*i)->mpq_a;
@@ -59,7 +59,8 @@ eof(false), buffer(0), pointer(0), size(0)
libmpq__file_unpacked_size(mpq_a, filenum, &size);
// HACK: in patch.mpq some files don't want to open and give 1 for filesize
if (size<=1) {
if (size <= 1)
{
// printf("warning: file %s has size %d; cannot Read.\n", filename, size);
eof = true;
buffer = 0;
@@ -83,7 +84,8 @@ size_t MPQFile::Read(void* dest, size_t bytes)
return 0;
size_t rpos = pointer + bytes;
if (rpos > size_t(size)) {
if (rpos > size_t(size))
{
bytes = size - pointer;
eof = true;
}

View File

@@ -18,52 +18,52 @@
class MPQArchive
{
public:
mpq_archive_s *mpq_a;
std::vector<std::string> Files;
MPQArchive(const char* filename);
void close();
void GetFileListTo(std::vector<std::string>& filelist)
public:
mpq_archive_s* mpq_a;
std::vector<std::string> Files;
MPQArchive(const char* filename);
void close();
void GetFileListTo(std::vector<std::string>& filelist)
{
uint32_t filenum;
if(libmpq__file_number(mpq_a, "(listfile)", &filenum)) return;
libmpq__off_t size, transferred;
libmpq__file_unpacked_size(mpq_a, filenum, &size);
char* buffer = new char[size + 1];
buffer[size] = '\0';
libmpq__file_read(mpq_a, filenum, (unsigned char*)buffer, size, &transferred);
char seps[] = "\n";
char* token;
token = strtok( buffer, seps );
uint32 counter = 0;
while ((token != nullptr) && (counter < size))
{
uint32_t filenum;
if(libmpq__file_number(mpq_a, "(listfile)", &filenum)) return;
libmpq__off_t size, transferred;
libmpq__file_unpacked_size(mpq_a, filenum, &size);
char* buffer = new char[size + 1];
buffer[size] = '\0';
libmpq__file_read(mpq_a, filenum, (unsigned char*)buffer, size, &transferred);
char seps[] = "\n";
char* token;
token = strtok( buffer, seps );
uint32 counter = 0;
while ((token != nullptr) && (counter < size))
{
//cout << token << endl;
token[strlen(token) - 1] = 0;
std::string s = token;
filelist.push_back(s);
counter += strlen(token) + 2;
token = strtok(nullptr, seps);
}
delete[] buffer;
//cout << token << endl;
token[strlen(token) - 1] = 0;
std::string s = token;
filelist.push_back(s);
counter += strlen(token) + 2;
token = strtok(nullptr, seps);
}
delete[] buffer;
}
};
class MPQFile
{
//MPQHANDLE handle;
bool eof;
char *buffer;
libmpq__off_t pointer,size;
char* buffer;
libmpq__off_t pointer, size;
// disable copying
MPQFile(const MPQFile& /*f*/) {}
@@ -84,15 +84,15 @@ public:
void close();
};
inline void flipcc(char *fcc)
inline void flipcc(char* fcc)
{
char t;
t=fcc[0];
fcc[0]=fcc[3];
fcc[3]=t;
t=fcc[1];
fcc[1]=fcc[2];
fcc[2]=t;
t = fcc[0];
fcc[0] = fcc[3];
fcc[3] = t;
t = fcc[1];
fcc[1] = fcc[2];
fcc[2] = t;
}
#endif

View File

@@ -9,7 +9,8 @@
#include "DBC.h"
#include "Utils.h"
char const* MPQManager::Files[] = {
char const* MPQManager::Files[] =
{
"common.MPQ",
"common-2.MPQ",
"expansion.MPQ",

View File

@@ -38,9 +38,9 @@ void MapChunk::GenerateTriangles()
{
MCNKLiquidData& data = Adt->_LiquidHandler->MCNKData[Index];
float maxHeight = std::max(
std::max(
std::max(std::max(Vertices[topLeft].z, Vertices[topRight].z), Vertices[bottomLeft].z),
Vertices[bottomRight].z), Vertices[center].z);
std::max(
std::max(std::max(Vertices[topLeft].z, Vertices[topRight].z), Vertices[bottomLeft].z),
Vertices[bottomRight].z), Vertices[center].z);
if (data.IsWater(x, y, maxHeight))
triangleType = Constants::TRIANGLE_TYPE_WATER;
}

View File

@@ -137,7 +137,7 @@ void ExtractGameobjectModels()
fwrite(&numVerts, sizeof(uint32), 1, output);
uint32 numGroups = 1;
fwrite(&numGroups, sizeof(uint32), 1, output);
fwrite(Nop, 4 * 3 , 1, output); // rootwmoid, flags, groupid
fwrite(Nop, 4 * 3, 1, output); // rootwmoid, flags, groupid
fwrite(Nop, sizeof(float), 3 * 2, output);//bbox, only needed for WMO currently
fwrite(Nop, 4, 1, output);// liquidflags
fwrite("GRP ", 4, 1, output);
@@ -171,7 +171,7 @@ void ExtractGameobjectModels()
wsize = sizeof(int) + sizeof(float) * 3 * numVerts;
fwrite(&wsize, sizeof(int), 1, output);
fwrite(&numVerts, sizeof(int), 1, output);
float* vertices = new float[numVerts*3];
float* vertices = new float[numVerts * 3];
if (numVerts > 0)
{
@@ -213,7 +213,7 @@ void ExtractGameobjectModels()
fwrite(&model.Header.CountGroups, sizeof(uint32), 1, output);
fwrite(&model.Header.WmoId, sizeof(uint32), 1, output);
const char grp[] = { 'G' , 'R' , 'P', ' ' };
const char grp[] = { 'G', 'R', 'P', ' ' };
for (std::vector<WorldModelGroup>::iterator itr2 = model.Groups.begin(); itr2 != model.Groups.end(); ++itr2)
{
const WMOGroupHeader& header = itr2->Header;
@@ -227,7 +227,7 @@ void ExtractGameobjectModels()
fwrite(grp, sizeof(char), sizeof(grp), output);
uint32 k = 0;
uint32 mobaBatch = itr2->MOBALength / 12;
uint32* MobaEx = new uint32[mobaBatch*4];
uint32* MobaEx = new uint32[mobaBatch * 4];
for(uint32 i = 8; i < itr2->MOBALength; i += 12)
MobaEx[k++] = itr2->MOBA[i];
@@ -279,7 +279,7 @@ bool HandleArgs(int argc, char** argv, uint32& threads, std::set<uint32>& mapLis
mapList.insert(atoi(token));
token = strtok(nullptr, ",");
}
free(copy);
printf("Extracting only provided list of maps (%u).\n", uint32(mapList.size()));
@@ -437,7 +437,7 @@ int main(int argc, char* argv[])
LoadTile(navMesh, buff);
}
}
navMeshQuery->init(navMesh, 2048);
float nearestPt[3];
@@ -454,9 +454,9 @@ int main(int argc, char* argv[])
int hops;
dtPolyRef* hopBuffer = new dtPolyRef[8192];
dtStatus status = navMeshQuery->findPath(m_startRef, m_endRef, m_spos, m_epos, &m_filter, hopBuffer, &hops, 8192);
int resultHopCount;
float* straightPath = new float[2048*3];
float* straightPath = new float[2048 * 3];
unsigned char* pathFlags = new unsigned char[2048];
dtPolyRef* pathRefs = new dtPolyRef[2048];

View File

@@ -18,7 +18,7 @@ Model::Model( std::string path ) : IsCollidable(false), IsBad(false)
}
Header.Read(Stream);
if (Header.OffsetBoundingNormals > 0 && Header.OffsetBoundingVertices > 0 &&
Header.OffsetBoundingTriangles > 0 && Header.BoundingRadius > 0.0f)
Header.OffsetBoundingTriangles > 0 && Header.BoundingRadius > 0.0f)
{
IsCollidable = true;
ReadVertices();

View File

@@ -244,7 +244,7 @@ uint8* TileBuilder::BuildTiled(dtNavMeshParams& navMeshParams)
}
OutputDebugVertices();
uint32 numVerts = _Geometry->Vertices.size();
uint32 numTris = _Geometry->Triangles.size();
float* vertices;

View File

@@ -12,13 +12,13 @@
#include "G3D/Quat.h"
#ifdef _WIN32
#include "direct.h"
#include "direct.h"
#else
#include <sys/stat.h>
#include <unistd.h>
#include <sys/stat.h>
#include <unistd.h>
#endif
const float Constants::TileSize = 533.0f + (1/3.0f);
const float Constants::TileSize = 533.0f + (1 / 3.0f);
const float Constants::MaxXY = 32.0f * Constants::TileSize;
const float Constants::ChunkSize = Constants::TileSize / 16.0f;
const float Constants::UnitSize = Constants::ChunkSize / 8.0f;
@@ -45,11 +45,11 @@ void Utils::CreateDir( const std::string& Path )
void Utils::Reverse(char word[])
{
int len = strlen(word);
for (int i = 0;i < len / 2; i++)
for (int i = 0; i < len / 2; i++)
{
word[i] ^= word[len-i-1];
word[len-i-1] ^= word[i];
word[i] ^= word[len-i-1];
word[i] ^= word[len - i - 1];
word[len - i - 1] ^= word[i];
word[i] ^= word[len - i - 1];
}
}
@@ -159,7 +159,7 @@ Vector3 Utils::GetLiquidVert(const IDefinition& def, Vector3 basePosition, float
float Utils::Distance( float x, float y )
{
return sqrt(x*x + y*y);
return sqrt(x * x + y * y);
}
std::string Utils::Replace( std::string str, const std::string& oldStr, const std::string& newStr )
@@ -194,7 +194,7 @@ void Utils::SaveToDisk( FILE* stream, const std::string& path )
fclose(stream);
return;
}
// And write it in the file
size_t wrote = fwrite(data, size, 1, disk);
if (wrote != 1)
@@ -224,7 +224,7 @@ std::string Utils::GetExtension( std::string path )
std::string extension = "";
if(idx != std::string::npos)
extension = path.substr(idx+1);
extension = path.substr(idx + 1);
return extension;
}
@@ -260,7 +260,7 @@ void MapChunkHeader::Read(FILE* stream)
count += fread(&OffsetMCCV, sizeof(uint32), 1, stream);
if (count != 27)
printf("MapChunkHeader::Read: Failed to read some data expected 27, read %d\n", count);
printf("MapChunkHeader::Read: Failed to read some data expected 27, read %d\n", count);
}
void MHDR::Read(FILE* stream)
@@ -281,7 +281,7 @@ void MHDR::Read(FILE* stream)
count += fread(&OffsetMTFX, sizeof(uint32), 1, stream);
if (count != 12)
printf("MHDR::Read: Failed to read some data expected 12, read %d\n", count);
printf("MHDR::Read: Failed to read some data expected 12, read %d\n", count);
}
void ModelHeader::Read(FILE* stream)
@@ -343,7 +343,7 @@ void ModelHeader::Read(FILE* stream)
count += fread(&OffsetBoundingNormals, sizeof(uint32), 1, stream);
if (count != 51)
printf("ModelHeader::Read: Failed to read some data expected 51, read %d\n", count);
printf("ModelHeader::Read: Failed to read some data expected 51, read %d\n", count);
}
@@ -366,7 +366,7 @@ WorldModelHeader WorldModelHeader::Read(FILE* stream)
count += fread(&ret.LiquidTypeRelated, sizeof(uint32), 1, stream);
if (count != 10)
printf("WorldModelHeader::Read: Failed to read some data expected 10, read %d\n", count);
printf("WorldModelHeader::Read: Failed to read some data expected 10, read %d\n", count);
return ret;
}
@@ -386,7 +386,7 @@ DoodadInstance DoodadInstance::Read(FILE* stream)
count += fread(&ret.LightColor, sizeof(uint32), 1, stream);
if (count != 7)
printf("DoodadInstance::Read: Failed to read some data expected 7, read %d\n", count);
printf("DoodadInstance::Read: Failed to read some data expected 7, read %d\n", count);
return ret;
}
@@ -405,7 +405,7 @@ DoodadSet DoodadSet::Read(FILE* stream)
count += fread(&ret.UnknownZero, sizeof(uint32), 1, stream);
if (count != 23)
printf("DoodadSet::Read: Failed to read some data expected 23, read %d\n", count);
printf("DoodadSet::Read: Failed to read some data expected 23, read %d\n", count);
return ret;
}
@@ -422,7 +422,7 @@ LiquidHeader LiquidHeader::Read(FILE* stream)
count += fread(&ret.MaterialId, sizeof(uint16), 1, stream);
if (count != 5)
printf("LiquidHeader::Read: Failed to read some data expected 5, read %d\n", count);
printf("LiquidHeader::Read: Failed to read some data expected 5, read %d\n", count);
return ret;
}
@@ -445,7 +445,7 @@ LiquidData LiquidData::Read(FILE* stream, LiquidHeader& header)
uint32 discard;
float tmp;
if (fread(&discard, sizeof(uint32), 1, stream) == 1 &&
fread(&tmp, sizeof(float), 1, stream) == 1)
fread(&tmp, sizeof(float), 1, stream) == 1)
{
ret.HeightMap[x][y] = tmp;
}

View File

@@ -30,7 +30,7 @@ WorldModelDefinition WorldModelDefinition::Read( FILE* file )
count += fread(&discard, sizeof(uint32), 1, file);
if (count != 5)
printf("WorldModelDefinition::Read: Error reading data, expected 5, read %d\n", count);
printf("WorldModelDefinition::Read: Error reading data, expected 5, read %d\n", count);
return ret;
}
@@ -45,7 +45,7 @@ void WorldModelHandler::ProcessInternal( MapChunk* mcnk )
{
if (!IsSane())
return;
uint32 refCount = mcnk->Header.MapObjectRefs;
FILE* stream = mcnk->Source->GetStream();
fseek(stream, mcnk->Source->Offset + mcnk->Header.OffsetMCRF, SEEK_SET);
@@ -159,13 +159,13 @@ void WorldModelHandler::InsertModelGeometry( std::vector<Vector3>& verts, std::v
uint32 vertOffset = verts.size();
Vector3 v1 = Utils::GetLiquidVert(def, liquidHeader.BaseLocation,
liquidDataGeometry.HeightMap[x][y], x, y, translate);
liquidDataGeometry.HeightMap[x][y], x, y, translate);
Vector3 v2 = Utils::GetLiquidVert(def, liquidHeader.BaseLocation,
liquidDataGeometry.HeightMap[x + 1][y], x + 1, y, translate);
liquidDataGeometry.HeightMap[x + 1][y], x + 1, y, translate);
Vector3 v3 = Utils::GetLiquidVert(def, liquidHeader.BaseLocation,
liquidDataGeometry.HeightMap[x][y + 1], x, y + 1, translate);
liquidDataGeometry.HeightMap[x][y + 1], x, y + 1, translate);
Vector3 v4 = Utils::GetLiquidVert(def, liquidHeader.BaseLocation,
liquidDataGeometry.HeightMap[x + 1][y + 1], x + 1, y + 1, translate);
liquidDataGeometry.HeightMap[x + 1][y + 1], x + 1, y + 1, translate);
verts.push_back(translate ? v1 : Utils::ToRecast(v1));
verts.push_back(translate ? v2 : Utils::ToRecast(v2));