Skip to content

Commit 67dbfe3

Browse files
committed
Some tidying.
1 parent ecd9ef8 commit 67dbfe3

File tree

5 files changed

+86
-70
lines changed

5 files changed

+86
-70
lines changed

engine/model/model_mda.cpp

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,13 @@ bool chr::MDAModel::Parse( const std::string &buf )
159159
}
160160

161161
Profile profile;
162-
if ( !ParseProfile( profile, ss ) )
162+
if ( !profile.Parse( ss ) )
163163
{
164164
Com_Printf( "Failed to parse MDA profile (%s)!\n", tag.c_str() );
165165
return false;
166166
}
167167

168-
profiles.insert( std::make_pair( tag, Profile() ) );
168+
profiles.insert( std::make_pair( tag, profile ) );
169169
}
170170
else if ( token == "headtri" )
171171
{
@@ -197,7 +197,7 @@ bool chr::MDAModel::Parse( const std::string &buf )
197197
return true;
198198
}
199199

200-
bool chr::MDAModel::ParseProfile( Profile &profile, std::stringstream &ss )
200+
bool chr::MDAModel::Profile::Parse( std::stringstream &ss )
201201
{
202202
std::string token;
203203
while ( ss >> token )
@@ -219,9 +219,9 @@ bool chr::MDAModel::ParseProfile( Profile &profile, std::stringstream &ss )
219219
return false;
220220
}
221221

222-
profile.evaluation = token;
223-
profile.evaluation.erase( std::remove( profile.evaluation.begin(), profile.evaluation.end(), '\"' ),
224-
profile.evaluation.end() );
222+
evaluation = token;
223+
evaluation.erase( std::remove( evaluation.begin(), evaluation.end(), '\"' ),
224+
evaluation.end() );
225225
}
226226
else if ( token == "skin" )
227227
{
@@ -232,21 +232,21 @@ bool chr::MDAModel::ParseProfile( Profile &profile, std::stringstream &ss )
232232
}
233233

234234
Skin skin;
235-
if ( !ParseSkin( skin, ss ) )
235+
if ( !skin.Parse( ss ) )
236236
{
237237
Com_Printf( "Failed to parse MDA skin!\n" );
238238
return false;
239239
}
240240

241-
profile.skins.push_back( skin );
241+
skins.push_back( skin );
242242
}
243243
else
244244
{
245245
Com_Printf( "Unknown token (%s), ignoring!\n", token.c_str() );
246246
}
247247
}
248248

249-
if ( profile.skins.empty() )
249+
if ( skins.empty() )
250250
{
251251
Com_Printf( "Encountered an empty profile!\n" );
252252
return false;
@@ -255,7 +255,7 @@ bool chr::MDAModel::ParseProfile( Profile &profile, std::stringstream &ss )
255255
return true;
256256
}
257257

258-
bool chr::MDAModel::ParseSkin( Skin &skin, std::stringstream &ss )
258+
bool chr::MDAModel::Skin::Parse( std::stringstream &ss )
259259
{
260260
std::string token;
261261
while ( ss >> token )
@@ -278,13 +278,13 @@ bool chr::MDAModel::ParseSkin( Skin &skin, std::stringstream &ss )
278278
}
279279

280280
Pass pass;
281-
if ( !ParsePass( pass, ss ) )
281+
if ( !pass.Parse( ss ) )
282282
{
283283
Com_Printf( "Failed to parse MDA pass!\n" );
284284
return false;
285285
}
286286

287-
skin.passes.push_back( pass );
287+
passes.push_back( pass );
288288
}
289289
else
290290
{
@@ -295,7 +295,7 @@ bool chr::MDAModel::ParseSkin( Skin &skin, std::stringstream &ss )
295295
return false;
296296
}
297297

298-
bool chr::MDAModel::ParsePass( Pass &pass, std::stringstream &ss )
298+
bool chr::MDAModel::Pass::Parse( std::stringstream &ss )
299299
{
300300
std::string token;
301301
while ( ss >> token )
@@ -325,7 +325,7 @@ bool chr::MDAModel::ParsePass( Pass &pass, std::stringstream &ss )
325325
token += ".tga";
326326
}
327327

328-
pass.map = GL_FindImage( token.c_str(), it_skin );
328+
map = GL_FindImage( token, it_skin );
329329
}
330330
else if ( token == "alphafunc" )
331331
{
@@ -335,9 +335,9 @@ bool chr::MDAModel::ParsePass( Pass &pass, std::stringstream &ss )
335335
return false;
336336
}
337337

338-
if ( token == "gt0" ) { pass.alpha = Pass::AlphaFunc::GT0; }
339-
else if ( token == "ge128" ) { pass.alpha = Pass::AlphaFunc::GE128; }
340-
else if ( token == "lt128" ) { pass.alpha = Pass::AlphaFunc::LT128; }
338+
if ( token == "gt0" ) { alpha = AlphaFunc::GT0; }
339+
else if ( token == "ge128" ) { alpha = AlphaFunc::GE128; }
340+
else if ( token == "lt128" ) { alpha = AlphaFunc::LT128; }
341341
else
342342
{
343343
Com_Printf( "Unknown alphafunc type (%s)!\n", token.c_str() );
@@ -351,10 +351,10 @@ bool chr::MDAModel::ParsePass( Pass &pass, std::stringstream &ss )
351351
return false;
352352
}
353353

354-
if ( token == "none" ) { pass.rgb = Pass::RGBGen::NONE; }
355-
else if ( token == "identity" ) { pass.rgb = Pass::RGBGen::IDENTITY; }
356-
else if ( token == "diffusezero" ) { pass.rgb = Pass::RGBGen::DIFFUSE_ZERO; }
357-
else if ( token == "ambient" ) { pass.rgb = Pass::RGBGen::AMBIENT; }
354+
if ( token == "none" ) { rgb = RGBGen::NONE; }
355+
else if ( token == "identity" ) { rgb = RGBGen::IDENTITY; }
356+
else if ( token == "diffusezero" ) { rgb = RGBGen::DIFFUSE_ZERO; }
357+
else if ( token == "ambient" ) { rgb = RGBGen::AMBIENT; }
358358
else
359359
{
360360
Com_Printf( "Unknown rgbgen type (%s)!\n", token.c_str() );
@@ -368,10 +368,10 @@ bool chr::MDAModel::ParsePass( Pass &pass, std::stringstream &ss )
368368
return false;
369369
}
370370

371-
if ( token == "none" ) { pass.blend = Pass::BlendMode::NONE; }
372-
else if ( token == "normal" ) { pass.blend = Pass::BlendMode::NORMAL; }
373-
else if ( token == "multiply" ) { pass.blend = Pass::BlendMode::MULTIPLY; }
374-
else if ( token == "add" ) { pass.blend = Pass::BlendMode::ADD; }
371+
if ( token == "none" ) { blend = BlendMode::NONE; }
372+
else if ( token == "normal" ) { blend = BlendMode::NORMAL; }
373+
else if ( token == "multiply" ) { blend = BlendMode::MULTIPLY; }
374+
else if ( token == "add" ) { blend = BlendMode::ADD; }
375375
else
376376
{
377377
Com_Printf( "Unknown blend mode (%s)!\n", token.c_str() );
@@ -385,9 +385,9 @@ bool chr::MDAModel::ParsePass( Pass &pass, std::stringstream &ss )
385385
return false;
386386
}
387387

388-
if ( token == "none" ) { pass.cull = Pass::CullMode::NONE; }
389-
else if ( token == "front" ) { pass.cull = Pass::CullMode::FRONT; }
390-
else if ( token == "back" ) { pass.cull = Pass::CullMode::BACK; }
388+
if ( token == "none" ) { cull = CullMode::NONE; }
389+
else if ( token == "front" ) { cull = CullMode::FRONT; }
390+
else if ( token == "back" ) { cull = CullMode::BACK; }
391391
else
392392
{
393393
Com_Printf( "Unknown cull mode (%s)!\n", token.c_str() );
@@ -401,7 +401,7 @@ bool chr::MDAModel::ParsePass( Pass &pass, std::stringstream &ss )
401401
return false;
402402
}
403403

404-
if ( token == "sphere" ) { pass.uvgen = Pass::UVGen::SPHERE; }
404+
if ( token == "sphere" ) { uvgen = UVGen::SPHERE; }
405405
else
406406
{
407407
Com_Printf( "Unknown uvgen mode (%s)!\n", token.c_str() );
@@ -417,8 +417,8 @@ bool chr::MDAModel::ParsePass( Pass &pass, std::stringstream &ss )
417417

418418
if ( token == "scroll" )
419419
{
420-
pass.uvMod = Pass::UVMod::SCROLL;
421-
if ( !( ss >> pass.uvModScroll.x >> pass.uvModScroll.y ) )
420+
uvMod = UVMod::SCROLL;
421+
if ( !( ss >> uvModScroll.x >> uvModScroll.y ) )
422422
{
423423
Com_Printf( "Expected 'x y' after 'scroll'!\n" );
424424
return false;
@@ -437,9 +437,9 @@ bool chr::MDAModel::ParsePass( Pass &pass, std::stringstream &ss )
437437
return false;
438438
}
439439

440-
if ( token == "none" ) { pass.depth = Pass::DepthFunc::NONE; }
441-
else if ( token == "equal" ) { pass.depth = Pass::DepthFunc::EQUAL; }
442-
else if ( token == "less" ) { pass.depth = Pass::DepthFunc::LESS; }
440+
if ( token == "none" ) { depth = DepthFunc::NONE; }
441+
else if ( token == "equal" ) { depth = DepthFunc::EQUAL; }
442+
else if ( token == "less" ) { depth = DepthFunc::LESS; }
443443
else
444444
{
445445
Com_Printf( "Unknown depthfunc mode (%s)!\n", token.c_str() );
@@ -453,8 +453,8 @@ bool chr::MDAModel::ParsePass( Pass &pass, std::stringstream &ss )
453453
return false;
454454
}
455455

456-
if ( token == "1" ) { pass.depthWrite = true; }
457-
else if ( token == "0" ) { pass.depthWrite = false; }
456+
if ( token == "1" ) { depthWrite = true; }
457+
else if ( token == "0" ) { depthWrite = false; }
458458
else
459459
{
460460
Com_Printf( "Unknown depthwrite mode (%s)!\n", token.c_str() );

engine/model/model_mda.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,15 @@ namespace chr
9595
AlphaFunc alpha{ AlphaFunc::NONE };
9696

9797
image_t *map{};
98+
99+
bool Parse( std::stringstream &ss );
98100
};
99101

100102
struct Skin
101103
{
102-
std::vector< Pass > passes;
104+
std::vector< Pass > passes{};
105+
106+
bool Parse( std::stringstream &ss );
103107
};
104108

105109
struct Profile
@@ -108,11 +112,9 @@ namespace chr
108112
std::string evaluation;
109113

110114
std::vector< Skin > skins;
111-
};
112115

113-
static bool ParseProfile( Profile &profile, std::stringstream &ss );
114-
static bool ParseSkin( Skin &skin, std::stringstream &ss );
115-
static bool ParsePass( Pass &pass, std::stringstream &ss );
116+
bool Parse( std::stringstream &ss );
117+
};
116118

117119
std::map< std::string, Profile > profiles;
118120

engine/renderer/ref_gl/gl_model.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ model_t *Mod_ForName( const char *name, bool crash )
186186
std::string tag = {};
187187
std::string filename = name;
188188

189-
// some models have a special tag at the end, for MDAs, these denote the skin
189+
// some models have a special tag at the end, for MDAs, these denote the profile
190190
const size_t pos = filename.find_last_of( '!' );
191191
if ( pos != std::string::npos )
192192
{
@@ -974,7 +974,7 @@ void Mod_LoadAliasModel( model_t *mod, void *buffer )
974974
{
975975
char skinPath[ MAX_QPATH ];
976976
snprintf( skinPath, sizeof( skinPath ), "%s", mod->name );
977-
strcpy( strrchr( skinPath, '/' ) + 1, skins[ i ].c_str() );
977+
strcpy( strrchr( skinPath, '/' ) + 1, skins[ i ].name.c_str() );
978978
mod->skins[ i ] = GL_FindImage( skinPath, it_skin );
979979
}
980980
}

game/g_spawn.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929
// As provided by entity.dat
3030
struct EntityCustomClassDeclaration
3131
{
32-
char className[ 64 ]{ '\0' };
33-
char modelPath[ MAX_QPATH ]{ '\0' };
32+
char className[ 64 ]{};
33+
char modelPath[ MAX_QPATH ]{};
3434

3535
vec3_t scale{ 0.0f, 0.0f, 0.0f };
3636

37-
char entityType[ 64 ]{ '\0' };
37+
char entityType[ 64 ]{};
3838

3939
vec3_t bbMins{ 0.0f, 0.0f, 0.0f };
4040
vec3_t bbMaxs{ 0.0f, 0.0f, 0.0f };
@@ -48,11 +48,11 @@ struct EntityCustomClassDeclaration
4848
float speed{ 0.0f };
4949

5050
unsigned int lighting{ 0 }, blending{ 0 };
51-
char targetSequence[ 64 ]{ '\0' };
51+
char targetSequence[ 64 ]{};
5252
int miscValue{ 0 };
5353
bool noMip{ false };
54-
char spawnSequence[ 64 ]{ '\0' };
55-
char description[ 64 ]{ '\0' };
54+
char spawnSequence[ 64 ]{};
55+
char description[ 64 ]{};
5656
};
5757
static std::map< std::string, EntityCustomClassDeclaration > entityCustomClasses;
5858

qcommon/include/qcommon/math_vector.h

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020

2121
#pragma once
2222

23+
typedef float vec_t;
24+
typedef vec_t vec2_t[ 2 ];
25+
typedef vec_t vec3_t[ 3 ];
26+
typedef vec_t vec4_t[ 4 ];
27+
2328
namespace chr
2429
{
2530
struct Vector2
@@ -32,6 +37,11 @@ namespace chr
3237
assert( i < 2 );
3338
return *( ( &x ) + i );
3439
}
40+
virtual float operator[]( const uint i ) const
41+
{
42+
assert( i < 3 );
43+
return *( ( &x ) + i );
44+
}
3545

3646
virtual inline void Zero()
3747
{
@@ -41,13 +51,31 @@ namespace chr
4151

4252
struct Vector3 : Vector2
4353
{
54+
Vector3() = default;
55+
Vector3( float x, float y, float z )
56+
{
57+
this->x = x;
58+
this->y = y;
59+
this->z = z;
60+
}
61+
4462
float z{ 0.0f };
4563

4664
inline float &operator[]( const uint i ) override
4765
{
4866
assert( i < 3 );
4967
return *( ( &x ) + i );
5068
}
69+
float operator[]( const uint i ) const override
70+
{
71+
assert( i < 3 );
72+
return *( ( &x ) + i );
73+
}
74+
75+
Vector3 operator+( const Vector3 &v ) const
76+
{
77+
return Vector3( this->x + v.x, this->y + v.y, this->z + v.z );
78+
}
5179

5280
inline float Length() const
5381
{
@@ -83,30 +111,16 @@ namespace chr
83111
assert( i < 4 );
84112
return *( ( &x ) + i );
85113
}
114+
float operator[]( const uint i ) const override
115+
{
116+
assert( i < 4 );
117+
return *( ( &x ) + i );
118+
}
86119
};
87-
}// namespace nox
120+
}// namespace chr
88121

89122
// Everything below will eventually be nixed
90123

91-
#define OLD_VECTOR_TYPES
92-
93-
typedef float vec_t;
94-
#ifdef OLD_VECTOR_TYPES
95-
typedef vec_t vec2_t[ 2 ];
96-
#else
97-
typedef nox::Vector2 vec2_t;
98-
#endif
99-
#ifdef OLD_VECTOR_TYPES
100-
typedef vec_t vec3_t[ 3 ];
101-
#else
102-
typedef nox::Vector3 vec3_t;
103-
#endif
104-
#ifdef OLD_VECTOR_TYPES
105-
typedef vec_t vec4_t[ 4 ];
106-
#else
107-
typedef nox::Vector4 vec4_t;
108-
#endif
109-
110124
extern vec3_t vec3_origin;
111125
extern vec4_t vec4_origin;
112126

@@ -153,7 +167,7 @@ static inline void ClearBounds( vec3_t mins, vec3_t maxs )
153167
}
154168

155169
void AddPointToBounds( vec3_t v, vec3_t mins, vec3_t maxs );
156-
int VectorCompare( vec3_t v1, vec3_t v2 );
170+
int VectorCompare( vec3_t v1, vec3_t v2 );
157171

158172
static inline vec_t VectorLength( const vec3_t v )
159173
{

0 commit comments

Comments
 (0)