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

@@ -72,11 +72,11 @@ namespace MMAP
char const* MAP_VERSION_MAGIC = "v1.8";
TerrainBuilder::TerrainBuilder(bool skipLiquid) : m_skipLiquid (skipLiquid){ }
TerrainBuilder::TerrainBuilder(bool skipLiquid) : m_skipLiquid (skipLiquid) { }
TerrainBuilder::~TerrainBuilder() { }
/**************************************************************************/
void TerrainBuilder::getLoopVars(Spot portion, int &loopStart, int &loopEnd, int &loopInc)
void TerrainBuilder::getLoopVars(Spot portion, int& loopStart, int& loopEnd, int& loopInc)
{
switch (portion)
{
@@ -109,19 +109,19 @@ namespace MMAP
}
/**************************************************************************/
void TerrainBuilder::loadMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData)
void TerrainBuilder::loadMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData& meshData)
{
if (loadMap(mapID, tileX, tileY, meshData, ENTIRE))
{
loadMap(mapID, tileX+1, tileY, meshData, LEFT);
loadMap(mapID, tileX-1, tileY, meshData, RIGHT);
loadMap(mapID, tileX, tileY+1, meshData, TOP);
loadMap(mapID, tileX, tileY-1, meshData, BOTTOM);
loadMap(mapID, tileX + 1, tileY, meshData, LEFT);
loadMap(mapID, tileX - 1, tileY, meshData, RIGHT);
loadMap(mapID, tileX, tileY + 1, meshData, TOP);
loadMap(mapID, tileX, tileY - 1, meshData, BOTTOM);
}
}
/**************************************************************************/
bool TerrainBuilder::loadMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData, Spot portion)
bool TerrainBuilder::loadMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData& meshData, Spot portion)
{
char mapFileName[255];
sprintf(mapFileName, "maps/%03u%02u%02u.map", mapID, tileY, tileX);
@@ -132,7 +132,7 @@ namespace MMAP
map_fileheader fheader;
if (fread(&fheader, sizeof(map_fileheader), 1, mapFile) != 1 ||
fheader.versionMagic != *((uint32 const*)(MAP_VERSION_MAGIC)))
fheader.versionMagic != *((uint32 const*)(MAP_VERSION_MAGIC)))
{
fclose(mapFile);
printf("%s is the wrong version, please extract new .map files\n", mapFileName);
@@ -185,10 +185,10 @@ namespace MMAP
heightMultiplier = (hheader.gridMaxHeight - hheader.gridHeight) / 255;
for (int i = 0; i < V9_SIZE_SQ; ++i)
V9[i] = (float)v9[i]*heightMultiplier + hheader.gridHeight;
V9[i] = (float)v9[i] * heightMultiplier + hheader.gridHeight;
for (int i = 0; i < V8_SIZE_SQ; ++i)
V8[i] = (float)v8[i]*heightMultiplier + hheader.gridHeight;
V8[i] = (float)v8[i] * heightMultiplier + hheader.gridHeight;
}
else if (hheader.flags & MAP_HEIGHT_AS_INT16)
{
@@ -203,10 +203,10 @@ namespace MMAP
heightMultiplier = (hheader.gridMaxHeight - hheader.gridHeight) / 65535;
for (int i = 0; i < V9_SIZE_SQ; ++i)
V9[i] = (float)v9[i]*heightMultiplier + hheader.gridHeight;
V9[i] = (float)v9[i] * heightMultiplier + hheader.gridHeight;
for (int i = 0; i < V8_SIZE_SQ; ++i)
V8[i] = (float)v8[i]*heightMultiplier + hheader.gridHeight;
V8[i] = (float)v8[i] * heightMultiplier + hheader.gridHeight;
}
else
{
@@ -227,8 +227,8 @@ namespace MMAP
}
int count = meshData.solidVerts.size() / 3;
float xoffset = (float(tileX)-32)*GRID_SIZE;
float yoffset = (float(tileY)-32)*GRID_SIZE;
float xoffset = (float(tileX) - 32) * GRID_SIZE;
float yoffset = (float(tileY) - 32) * GRID_SIZE;
float coord[3];
@@ -251,8 +251,8 @@ namespace MMAP
int indices[] = { 0, 0, 0 };
int loopStart = 0, loopEnd = 0, loopInc = 0;
getLoopVars(portion, loopStart, loopEnd, loopInc);
for (int i = loopStart; i < loopEnd; i+=loopInc)
for (int j = TOP; j <= BOTTOM; j+=1)
for (int i = loopStart; i < loopEnd; i += loopInc)
for (int j = TOP; j <= BOTTOM; j += 1)
{
getHeightTriangle(i, Spot(j), indices);
ttriangles.append(indices[2] + count);
@@ -287,8 +287,8 @@ namespace MMAP
if (liquid_map)
{
int count = meshData.liquidVerts.size() / 3;
float xoffset = (float(tileX)-32)*GRID_SIZE;
float yoffset = (float(tileY)-32)*GRID_SIZE;
float xoffset = (float(tileX) - 32) * GRID_SIZE;
float yoffset = (float(tileY) - 32) * GRID_SIZE;
float coord[3];
int row, col;
@@ -303,10 +303,10 @@ namespace MMAP
col = i % V9_SIZE;
if (row < lheader.offsetY || row >= lheader.offsetY + lheader.height ||
col < lheader.offsetX || col >= lheader.offsetX + lheader.width)
col < lheader.offsetX || col >= lheader.offsetX + lheader.width)
{
// dummy vert using invalid height
meshData.liquidVerts.append((xoffset+col*GRID_PART_SIZE)*-1, INVALID_MAP_LIQ_HEIGHT, (yoffset+row*GRID_PART_SIZE)*-1);
meshData.liquidVerts.append((xoffset + col * GRID_PART_SIZE) * -1, INVALID_MAP_LIQ_HEIGHT, (yoffset + row * GRID_PART_SIZE) * -1);
continue;
}
@@ -323,19 +323,19 @@ namespace MMAP
{
row = i / V9_SIZE;
col = i % V9_SIZE;
meshData.liquidVerts.append((xoffset+col*GRID_PART_SIZE)*-1, lheader.liquidLevel, (yoffset+row*GRID_PART_SIZE)*-1);
meshData.liquidVerts.append((xoffset + col * GRID_PART_SIZE) * -1, lheader.liquidLevel, (yoffset + row * GRID_PART_SIZE) * -1);
}
}
delete [] liquid_map;
int indices[] = { 0, 0, 0 };
int loopStart = 0, loopEnd = 0, loopInc = 0, triInc = BOTTOM-TOP;
int loopStart = 0, loopEnd = 0, loopInc = 0, triInc = BOTTOM - TOP;
getLoopVars(portion, loopStart, loopEnd, loopInc);
// generate triangles
for (int i = loopStart; i < loopEnd; i+=loopInc)
for (int j = TOP; j <= BOTTOM; j+= triInc)
for (int i = loopStart; i < loopEnd; i += loopInc)
for (int j = TOP; j <= BOTTOM; j += triInc)
{
getHeightTriangle(i, Spot(j), indices, true);
ltriangles.append(indices[2] + count);
@@ -371,7 +371,7 @@ namespace MMAP
}
getLoopVars(portion, loopStart, loopEnd, loopInc);
for (int i = loopStart; i < loopEnd; i+=loopInc)
for (int i = loopStart; i < loopEnd; i += loopInc)
{
for (int j = 0; j < 2; ++j)
{
@@ -423,7 +423,7 @@ namespace MMAP
uint32 validCount = 0;
for(uint32 idx = 0; idx < 3; idx++)
{
float h = lverts_copy[ltris[idx]*3 + 1];
float h = lverts_copy[ltris[idx] * 3 + 1];
if (h != INVALID_MAP_LIQ_HEIGHT && h < INVALID_MAP_LIQ_HEIGHT_MAX)
{
quadHeight += h;
@@ -437,9 +437,9 @@ namespace MMAP
quadHeight /= validCount;
for(uint32 idx = 0; idx < 3; idx++)
{
float h = lverts[ltris[idx]*3 + 1];
float h = lverts[ltris[idx] * 3 + 1];
if (h == INVALID_MAP_LIQ_HEIGHT || h > INVALID_MAP_LIQ_HEIGHT_MAX)
lverts[ltris[idx]*3 + 1] = quadHeight;
lverts[ltris[idx] * 3 + 1] = quadHeight;
}
}
@@ -459,7 +459,7 @@ namespace MMAP
float maxLLevel = INVALID_MAP_LIQ_HEIGHT;
for(uint32 x = 0; x < 3; x++)
{
float h = lverts[ltris[x]*3 + 1];
float h = lverts[ltris[x] * 3 + 1];
if (minLLevel > h)
minLLevel = h;
@@ -471,7 +471,7 @@ namespace MMAP
float minTLevel = INVALID_MAP_LIQ_HEIGHT_MAX;
for(uint32 x = 0; x < 6; x++)
{
float h = tverts[ttris[x]*3 + 1];
float h = tverts[ttris[x] * 3 + 1];
if (maxTLevel < h)
maxTLevel = h;
@@ -497,12 +497,12 @@ namespace MMAP
}
if (useTerrain)
for (int k = 0; k < 3*tTriCount/2; ++k)
for (int k = 0; k < 3 * tTriCount / 2; ++k)
meshData.solidTris.append(ttris[k]);
// advance to next set of triangles
ltris += 3;
ttris += 3*tTriCount/2;
ttris += 3 * tTriCount / 2;
}
}
@@ -519,63 +519,81 @@ namespace MMAP
// coord is mirroed about the horizontal axes
switch (grid)
{
case GRID_V9:
coord[0] = (xOffset + index%(V9_SIZE)*GRID_PART_SIZE) * -1.f;
coord[1] = (yOffset + (int)(index/(V9_SIZE))*GRID_PART_SIZE) * -1.f;
coord[2] = v[index];
break;
case GRID_V8:
coord[0] = (xOffset + index%(V8_SIZE)*GRID_PART_SIZE + GRID_PART_SIZE/2.f) * -1.f;
coord[1] = (yOffset + (int)(index/(V8_SIZE))*GRID_PART_SIZE + GRID_PART_SIZE/2.f) * -1.f;
coord[2] = v[index];
break;
case GRID_V9:
coord[0] = (xOffset + index % (V9_SIZE) * GRID_PART_SIZE) * -1.f;
coord[1] = (yOffset + (int)(index / (V9_SIZE)) * GRID_PART_SIZE) * -1.f;
coord[2] = v[index];
break;
case GRID_V8:
coord[0] = (xOffset + index % (V8_SIZE) * GRID_PART_SIZE + GRID_PART_SIZE / 2.f) * -1.f;
coord[1] = (yOffset + (int)(index / (V8_SIZE)) * GRID_PART_SIZE + GRID_PART_SIZE / 2.f) * -1.f;
coord[2] = v[index];
break;
}
}
/**************************************************************************/
void TerrainBuilder::getHeightTriangle(int square, Spot triangle, int* indices, bool liquid/* = false*/)
{
int rowOffset = square/V8_SIZE;
int rowOffset = square / V8_SIZE;
if (!liquid)
switch (triangle)
{
case TOP:
indices[0] = square+rowOffset; // 0-----1 .... 128
indices[1] = square+1+rowOffset; // |\ T /|
indices[2] = (V9_SIZE_SQ)+square; // | \ / |
break; // |L 0 R| .. 127
case LEFT: // | / \ |
indices[0] = square+rowOffset; // |/ B \|
indices[1] = (V9_SIZE_SQ)+square; // 129---130 ... 386
indices[2] = square+V9_SIZE+rowOffset; // |\ /|
break; // | \ / |
case RIGHT: // | 128 | .. 255
indices[0] = square+1+rowOffset; // | / \ |
indices[1] = square+V9_SIZE+1+rowOffset; // |/ \|
indices[2] = (V9_SIZE_SQ)+square; // 258---259 ... 515
break;
case BOTTOM:
indices[0] = (V9_SIZE_SQ)+square;
indices[1] = square+V9_SIZE+1+rowOffset;
indices[2] = square+V9_SIZE+rowOffset;
break;
default: break;
}
{
case TOP:
indices[0] = square + rowOffset; // 0-----1 .... 128
indices[1] = square + 1 + rowOffset; // |\ T /|
indices[2] = (V9_SIZE_SQ) + square; // | \ / |
break; // |L 0 R| .. 127
case LEFT: // | / \ |
indices[0] = square + rowOffset; // |/ B \|
indices[1] = (V9_SIZE_SQ) + square; // 129---130 ... 386
indices[2] = square + V9_SIZE + rowOffset; // |\ /|
break; // | \ / |
case RIGHT: // | 128 | .. 255
indices[0] = square + 1 + rowOffset; // | / \ |
indices[1] = square + V9_SIZE + 1 + rowOffset; // |/ \|
indices[2] = (V9_SIZE_SQ) + square; // 258---259 ... 515
break;
case BOTTOM:
indices[0] = (V9_SIZE_SQ) + square;
indices[1] = square + V9_SIZE + 1 + rowOffset;
indices[2] = square + V9_SIZE + rowOffset;
break;
default:
break;
}
else
switch (triangle)
{ // 0-----1 .... 128
case TOP: // |\ |
indices[0] = square+rowOffset; // | \ T |
indices[1] = square+1+rowOffset; // | \ |
indices[2] = square+V9_SIZE+1+rowOffset; // | B \ |
break; // | \|
case BOTTOM: // 129---130 ... 386
indices[0] = square+rowOffset; // |\ |
indices[1] = square+V9_SIZE+1+rowOffset; // | \ |
indices[2] = square+V9_SIZE+rowOffset; // | \ |
break; // | \ |
default: break; // | \|
} // 258---259 ... 515
{
case TOP:
indices[0] = square + rowOffset;
indices[1] = square + 1 + rowOffset;
indices[2] = square + V9_SIZE + 1 + rowOffset;
break;
case BOTTOM:
indices[0] = square + rowOffset;
indices[1] = square + V9_SIZE + 1 + rowOffset;
indices[2] = square + V9_SIZE + rowOffset;
break;
default:
break;
}
/*
0-----1 .... 128
|\ |
| \ T |
| \ |
| B \ |
| \|
129---130 ... 386
|\ |
| \ |
| \ |
| \ |
| \|
258---259 ... 515
*/
}
@@ -584,8 +602,8 @@ namespace MMAP
{
// wow coords: x, y, height
// coord is mirroed about the horizontal axes
coord[0] = (xOffset + index%(V9_SIZE)*GRID_PART_SIZE) * -1.f;
coord[1] = (yOffset + (int)(index/(V9_SIZE))*GRID_PART_SIZE) * -1.f;
coord[0] = (xOffset + index % (V9_SIZE) * GRID_PART_SIZE) * -1.f;
coord[1] = (yOffset + (int)(index / (V9_SIZE)) * GRID_PART_SIZE) * -1.f;
coord[2] = v[index2];
}
@@ -619,7 +637,7 @@ namespace MMAP
}
/**************************************************************************/
bool TerrainBuilder::loadVMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData)
bool TerrainBuilder::loadVMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData& meshData)
{
IVMapManager* vmapManager = new VMapManager2();
int result = vmapManager->loadMap("vmaps", mapID, tileX, tileY);
@@ -663,10 +681,10 @@ namespace MMAP
// transform data
float scale = instance.iScale;
G3D::Matrix3 rotation = G3D::Matrix3::fromEulerAnglesXYZ(G3D::pi()*instance.iRot.z/-180.f, G3D::pi()*instance.iRot.x/-180.f, G3D::pi()*instance.iRot.y/-180.f);
G3D::Matrix3 rotation = G3D::Matrix3::fromEulerAnglesXYZ(G3D::pi() * instance.iRot.z / -180.f, G3D::pi() * instance.iRot.x / -180.f, G3D::pi() * instance.iRot.y / -180.f);
G3D::Vector3 position = instance.iPos;
position.x -= 32*GRID_SIZE;
position.y -= 32*GRID_SIZE;
position.x -= 32 * GRID_SIZE;
position.y -= 32 * GRID_SIZE;
for (std::vector<GroupModel>::iterator it = groupModels.begin(); it != groupModels.end(); ++it)
{
@@ -702,16 +720,16 @@ namespace MMAP
// convert liquid type to NavTerrain
switch (liquid->GetType() & 3)
{
case 0:
case 1:
type = NAV_WATER;
break;
case 2:
type = NAV_MAGMA;
break;
case 3:
type = NAV_SLIME;
break;
case 0:
case 1:
type = NAV_WATER;
break;
case 2:
type = NAV_MAGMA;
break;
case 3:
type = NAV_SLIME;
break;
}
// indexing is weird...
@@ -725,7 +743,7 @@ namespace MMAP
{
for (uint32 y = 0; y < vertsY; ++y)
{
vert = G3D::Vector3(corner.x + x * GRID_PART_SIZE, corner.y + y * GRID_PART_SIZE, data[y*vertsX + x]);
vert = G3D::Vector3(corner.x + x * GRID_PART_SIZE, corner.y + y * GRID_PART_SIZE, data[y * vertsX + x]);
vert = vert * rotation * scale + position;
vert.x *= -1.f;
vert.y *= -1.f;
@@ -767,14 +785,13 @@ namespace MMAP
for (uint32 j = 0; j < liqTris.size() / 3; ++j)
{
meshData.liquidTris.append(liqTris[j*3+1] + liqOffset, liqTris[j*3+2] + liqOffset, liqTris[j*3] + liqOffset);
meshData.liquidTris.append(liqTris[j * 3 + 1] + liqOffset, liqTris[j * 3 + 2] + liqOffset, liqTris[j * 3] + liqOffset);
meshData.liquidType.append(type);
}
}
}
}
}
while (false);
} while (false);
vmapManager->unloadMap(mapID, tileX, tileY);
delete vmapManager;
@@ -783,7 +800,7 @@ namespace MMAP
}
/**************************************************************************/
void TerrainBuilder::transform(std::vector<G3D::Vector3> &source, std::vector<G3D::Vector3> &transformedVertices, float scale, G3D::Matrix3 &rotation, G3D::Vector3 &position)
void TerrainBuilder::transform(std::vector<G3D::Vector3>& source, std::vector<G3D::Vector3>& transformedVertices, float scale, G3D::Matrix3& rotation, G3D::Vector3& position)
{
for (std::vector<G3D::Vector3>::iterator it = source.begin(); it != source.end(); ++it)
{
@@ -796,7 +813,7 @@ namespace MMAP
}
/**************************************************************************/
void TerrainBuilder::copyVertices(std::vector<G3D::Vector3> &source, G3D::Array<float> &dest)
void TerrainBuilder::copyVertices(std::vector<G3D::Vector3>& source, G3D::Array<float>& dest)
{
for (std::vector<G3D::Vector3>::iterator it = source.begin(); it != source.end(); ++it)
{
@@ -807,30 +824,30 @@ namespace MMAP
}
/**************************************************************************/
void TerrainBuilder::copyIndices(std::vector<MeshTriangle> &source, G3D::Array<int> &dest, int offset, bool flip)
void TerrainBuilder::copyIndices(std::vector<MeshTriangle>& source, G3D::Array<int>& dest, int offset, bool flip)
{
if (flip)
{
for (std::vector<MeshTriangle>::iterator it = source.begin(); it != source.end(); ++it)
{
dest.push_back((*it).idx2+offset);
dest.push_back((*it).idx1+offset);
dest.push_back((*it).idx0+offset);
dest.push_back((*it).idx2 + offset);
dest.push_back((*it).idx1 + offset);
dest.push_back((*it).idx0 + offset);
}
}
else
{
for (std::vector<MeshTriangle>::iterator it = source.begin(); it != source.end(); ++it)
{
dest.push_back((*it).idx0+offset);
dest.push_back((*it).idx1+offset);
dest.push_back((*it).idx2+offset);
dest.push_back((*it).idx0 + offset);
dest.push_back((*it).idx1 + offset);
dest.push_back((*it).idx2 + offset);
}
}
}
/**************************************************************************/
void TerrainBuilder::copyIndices(G3D::Array<int> &source, G3D::Array<int> &dest, int offset)
void TerrainBuilder::copyIndices(G3D::Array<int>& source, G3D::Array<int>& dest, int offset)
{
int* src = source.getCArray();
for (int32 i = 0; i < source.size(); ++i)
@@ -838,7 +855,7 @@ namespace MMAP
}
/**************************************************************************/
void TerrainBuilder::cleanVertices(G3D::Array<float> &verts, G3D::Array<int> &tris)
void TerrainBuilder::cleanVertices(G3D::Array<float>& verts, G3D::Array<int>& tris)
{
std::map<int, int> vertMap;
@@ -881,7 +898,7 @@ namespace MMAP
}
/**************************************************************************/
void TerrainBuilder::loadOffMeshConnections(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData, const char* offMeshFilePath)
void TerrainBuilder::loadOffMeshConnections(uint32 mapID, uint32 tileX, uint32 tileY, MeshData& meshData, const char* offMeshFilePath)
{
// no meshfile input given?
if (offMeshFilePath == nullptr)
@@ -903,7 +920,7 @@ namespace MMAP
uint32 mid, tx, ty;
float size;
if (sscanf(buf, "%u %u,%u (%f %f %f) (%f %f %f) %f", &mid, &tx, &ty,
&p0[0], &p0[1], &p0[2], &p1[0], &p1[1], &p1[2], &size) != 10)
&p0[0], &p0[1], &p0[2], &p1[0], &p1[1], &p1[2], &size) != 10)
continue;
if (mapID == mid && tileX == tx && tileY == ty)