Skip to content

Commit ddcd208

Browse files
committed
Handle MDA tags
1 parent 1f82591 commit ddcd208

File tree

1 file changed

+34
-9
lines changed

1 file changed

+34
-9
lines changed

engine/renderer/ref_gl/gl_model.cpp

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ int modfilelen;
2727

2828
void Mod_LoadSpriteModel( model_t *mod, void *buffer );
2929
void Mod_LoadBrushModel( model_t *mod, void *buffer );
30-
void Mod_LoadMDAModel( model_t *mod, void *buffer );
30+
void Mod_LoadMDAModel( model_t *mod, void *buffer, const std::string &tag );
3131
void Mod_LoadAliasModel( model_t *mod, void *buffer );
3232

3333
static byte mod_novis[ MAX_MAP_LEAFS / 8 ];
@@ -179,13 +179,38 @@ model_t *Mod_ForName( const char *name, bool crash )
179179
return &mod_inline[ i ];
180180
}
181181

182-
//
182+
// now filename is just string without the tag
183+
std::string tag = {};
184+
std::string filename = name;
185+
186+
// some models have a special tag at the end, for MDAs, these denote the skin
187+
const size_t pos = filename.find_last_of( '!' );
188+
if ( pos != std::string::npos )
189+
{
190+
if ( pos == filename.length() - 1 )
191+
{
192+
Com_Printf( "Encountered a model with an invalid tag (%s)!\n", filename.c_str() );
193+
}
194+
else
195+
{
196+
tag = filename.substr( pos + 1 );
197+
}
198+
199+
filename.erase( pos );
200+
}
201+
183202
// search the currently loaded models
184-
//
185203
for ( i = 0, mod = mod_known; i < mod_numknown; i++, mod++ )
186204
{
187-
if ( !mod->name[ 0 ] ) continue;
188-
if ( !strcmp( mod->name, name ) ) return mod;
205+
if ( !mod->name[ 0 ] )
206+
{
207+
continue;
208+
}
209+
210+
if ( filename == mod->name )
211+
{
212+
return mod;
213+
}
189214
}
190215

191216
//
@@ -201,7 +226,7 @@ model_t *Mod_ForName( const char *name, bool crash )
201226
Com_Error( ERR_DROP, "mod_numknown == MAX_MOD_KNOWN" );
202227
mod_numknown++;
203228
}
204-
strcpy( mod->name, name );
229+
strcpy( mod->name, filename.c_str() );
205230

206231
//
207232
// load the file
@@ -212,7 +237,7 @@ model_t *Mod_ForName( const char *name, bool crash )
212237
if ( crash )
213238
Com_Error( ERR_DROP, "Mod_NumForName: %s not found", mod->name );
214239
memset( mod->name, 0, sizeof( mod->name ) );
215-
return NULL;
240+
return nullptr;
216241
}
217242

218243
loadmodel = mod;
@@ -226,7 +251,7 @@ model_t *Mod_ForName( const char *name, bool crash )
226251
switch ( LittleLong( *( unsigned * ) buf ) )
227252
{
228253
case IDMDAHEADER:
229-
Mod_LoadMDAModel( mod, buf );
254+
Mod_LoadMDAModel( mod, buf, tag );
230255
break;
231256

232257
case IDALIASHEADER:
@@ -907,7 +932,7 @@ ALIAS MODELS
907932
* should be rendered in the scene along with some
908933
* additional data we need.
909934
*/
910-
void Mod_LoadMDAModel( model_t *mod, void *buffer )
935+
void Mod_LoadMDAModel( model_t *mod, void *buffer, const std::string &tag )
911936
{
912937
// + 4 as we're skipping the magic id
913938
const char *pos = ( const char * ) ( ( byte * ) buffer + 4 );

0 commit comments

Comments
 (0)