1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-05 10:17:46 +00:00

fix more style

This commit is contained in:
NotAdam 2019-01-26 19:43:42 +11:00
parent e5f612bc43
commit 29edf87924
4 changed files with 432 additions and 374 deletions

View file

@ -63,11 +63,15 @@ static void calcExtends(const BoundsItem* items, const int /*nitems*/,
for( int i = imin + 1; i < imax; ++i ) for( int i = imin + 1; i < imax; ++i )
{ {
const BoundsItem& it = items[ i ]; const BoundsItem& it = items[ i ];
if (it.bmin[0] < bmin[0]) bmin[0] = it.bmin[0]; if( it.bmin[ 0 ] < bmin[ 0 ] )
if (it.bmin[1] < bmin[1]) bmin[1] = it.bmin[1]; bmin[ 0 ] = it.bmin[ 0 ];
if( it.bmin[ 1 ] < bmin[ 1 ] )
bmin[ 1 ] = it.bmin[ 1 ];
if (it.bmax[0] > bmax[0]) bmax[0] = it.bmax[0]; if( it.bmax[ 0 ] > bmax[ 0 ] )
if (it.bmax[1] > bmax[1]) bmax[1] = it.bmax[1]; bmax[ 0 ] = it.bmax[ 0 ];
if( it.bmax[ 1 ] > bmax[ 1 ] )
bmax[ 1 ] = it.bmax[ 1 ];
} }
} }
@ -170,11 +174,15 @@ bool rcCreateChunkyTriMesh(const float* verts, const int* tris, int ntris,
for( int j = 1; j < 3; ++j ) for( int j = 1; j < 3; ++j )
{ {
const float* v = &verts[ t[ j ] * 3 ]; const float* v = &verts[ t[ j ] * 3 ];
if (v[0] < it.bmin[0]) it.bmin[0] = v[0]; if( v[ 0 ] < it.bmin[ 0 ] )
if (v[2] < it.bmin[1]) it.bmin[1] = v[2]; it.bmin[ 0 ] = v[ 0 ];
if( v[ 2 ] < it.bmin[ 1 ] )
it.bmin[ 1 ] = v[ 2 ];
if (v[0] > it.bmax[0]) it.bmax[0] = v[0]; if( v[ 0 ] > it.bmax[ 0 ] )
if (v[2] > it.bmax[1]) it.bmax[1] = v[2]; it.bmax[ 0 ] = v[ 0 ];
if( v[ 2 ] > it.bmax[ 1 ] )
it.bmax[ 1 ] = v[ 2 ];
} }
} }
@ -192,7 +200,8 @@ bool rcCreateChunkyTriMesh(const float* verts, const int* tris, int ntris,
{ {
rcChunkyTriMeshNode& node = cm->nodes[ i ]; rcChunkyTriMeshNode& node = cm->nodes[ i ];
const bool isLeaf = node.i >= 0; const bool isLeaf = node.i >= 0;
if (!isLeaf) continue; if( !isLeaf )
continue;
if( node.n > cm->maxTrisPerChunk ) if( node.n > cm->maxTrisPerChunk )
cm->maxTrisPerChunk = node.n; cm->maxTrisPerChunk = node.n;
} }
@ -245,7 +254,6 @@ int rcGetChunksOverlappingRect(const rcChunkyTriMesh* cm,
} }
static bool checkOverlapSegment( const float p[2], const float q[2], static bool checkOverlapSegment( const float p[2], const float q[2],
const float bmin[2], const float bmax[2] ) const float bmin[2], const float bmax[2] )
{ {
@ -271,10 +279,18 @@ static bool checkOverlapSegment(const float p[2], const float q[2],
float ood = 1.0f / d[ i ]; float ood = 1.0f / d[ i ];
float t1 = ( bmin[ i ] - p[ i ] ) * ood; float t1 = ( bmin[ i ] - p[ i ] ) * ood;
float t2 = ( bmax[ i ] - p[ i ] ) * ood; float t2 = ( bmax[ i ] - p[ i ] ) * ood;
if (t1 > t2) { float tmp = t1; t1 = t2; t2 = tmp; } if( t1 > t2 )
if (t1 > tmin) tmin = t1; {
if (t2 < tmax) tmax = t2; float tmp = t1;
if (tmin > tmax) return false; t1 = t2;
t2 = tmp;
}
if( t1 > tmin )
tmin = t1;
if( t2 < tmax )
tmax = t2;
if( tmin > tmax )
return false;
} }
} }
return true; return true;

View file

@ -29,8 +29,16 @@ struct rcChunkyTriMeshNode
struct rcChunkyTriMesh struct rcChunkyTriMesh
{ {
inline rcChunkyTriMesh() : nodes(0), nnodes(0), tris(0), ntris(0), maxTrisPerChunk(0) {}; inline rcChunkyTriMesh() :
inline ~rcChunkyTriMesh() { delete [] nodes; delete [] tris; } nodes( 0 ), nnodes( 0 ), tris( 0 ), ntris( 0 ), maxTrisPerChunk( 0 )
{
};
inline ~rcChunkyTriMesh()
{
delete[] nodes;
delete[] tris;
}
rcChunkyTriMeshNode* nodes; rcChunkyTriMeshNode* nodes;
int nnodes; int nnodes;
@ -41,6 +49,7 @@ struct rcChunkyTriMesh
private: private:
// Explicitly disabled copy constructor and copy assignment operator. // Explicitly disabled copy constructor and copy assignment operator.
rcChunkyTriMesh( const rcChunkyTriMesh& ); rcChunkyTriMesh( const rcChunkyTriMesh& );
rcChunkyTriMesh& operator=( const rcChunkyTriMesh& ); rcChunkyTriMesh& operator=( const rcChunkyTriMesh& );
}; };

View file

@ -20,7 +20,9 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <cstring> #include <cstring>
#define _USE_MATH_DEFINES #define _USE_MATH_DEFINES
#include <math.h> #include <math.h>
rcMeshLoaderObj::rcMeshLoaderObj() : rcMeshLoaderObj::rcMeshLoaderObj() :
@ -91,14 +93,16 @@ static char* parseRow(char* buf, char* bufEnd, char* row, int len)
case '\\': case '\\':
break; break;
case '\n': case '\n':
if (start) break; if( start )
break;
done = true; done = true;
break; break;
case '\r': case '\r':
break; break;
case '\t': case '\t':
case ' ': case ' ':
if (start) break; if( start )
break;
// else falls through // else falls through
default: default:
start = false; start = false;
@ -124,14 +128,16 @@ static int parseFace(char* row, int* data, int n, int vcnt)
// Find vertex delimiter and terminated the string there for conversion. // Find vertex delimiter and terminated the string there for conversion.
while( *row != '\0' && *row != ' ' && *row != '\t' ) while( *row != '\0' && *row != ' ' && *row != '\t' )
{ {
if (*row == '/') *row = '\0'; if( *row == '/' )
*row = '\0';
row++; row++;
} }
if( *s == '\0' ) if( *s == '\0' )
continue; continue;
int vi = atoi( s ); int vi = atoi( s );
data[ j++ ] = vi < 0 ? vi + vcnt : vi - 1; data[ j++ ] = vi < 0 ? vi + vcnt : vi - 1;
if (j >= n) return j; if( j >= n )
return j;
} }
return j; return j;
} }
@ -188,7 +194,8 @@ bool rcMeshLoaderObj::load(const std::string& filename)
row[ 0 ] = '\0'; row[ 0 ] = '\0';
src = parseRow( src, srcEnd, row, sizeof( row ) / sizeof( char ) ); src = parseRow( src, srcEnd, row, sizeof( row ) / sizeof( char ) );
// Skip comments // Skip comments
if (row[0] == '#') continue; if( row[ 0 ] == '#' )
continue;
if( row[ 0 ] == 'v' && row[ 1 ] != 'n' && row[ 1 ] != 't' ) if( row[ 0 ] == 'v' && row[ 1 ] != 'n' && row[ 1 ] != 't' )
{ {
// Vertex pos // Vertex pos

View file

@ -25,23 +25,49 @@ class rcMeshLoaderObj
{ {
public: public:
rcMeshLoaderObj(); rcMeshLoaderObj();
~rcMeshLoaderObj(); ~rcMeshLoaderObj();
bool load( const std::string& fileName ); bool load( const std::string& fileName );
const float* getVerts() const { return m_verts; } const float* getVerts() const
const float* getNormals() const { return m_normals; } {
const int* getTris() const { return m_tris; } return m_verts;
int getVertCount() const { return m_vertCount; } }
int getTriCount() const { return m_triCount; }
const std::string& getFileName() const { return m_filename; } const float* getNormals() const
{
return m_normals;
}
const int* getTris() const
{
return m_tris;
}
int getVertCount() const
{
return m_vertCount;
}
int getTriCount() const
{
return m_triCount;
}
const std::string& getFileName() const
{
return m_filename;
}
private: private:
// Explicitly disabled copy constructor and copy assignment operator. // Explicitly disabled copy constructor and copy assignment operator.
rcMeshLoaderObj( const rcMeshLoaderObj& ); rcMeshLoaderObj( const rcMeshLoaderObj& );
rcMeshLoaderObj& operator=( const rcMeshLoaderObj& ); rcMeshLoaderObj& operator=( const rcMeshLoaderObj& );
void addVertex( float x, float y, float z, int& cap ); void addVertex( float x, float y, float z, int& cap );
void addTriangle( int a, int b, int c, int& cap ); void addTriangle( int a, int b, int c, int& cap );
std::string m_filename; std::string m_filename;