diff --git a/libs/stream/stringstream.h b/libs/stream/stringstream.h index 386093fe..06b0e1ae 100644 --- a/libs/stream/stringstream.h +++ b/libs/stream/stringstream.h @@ -112,6 +112,14 @@ std::size_t write( const char* buffer, std::size_t length ){ return length; } +template +StringOutputStream& operator()( const Args& ... args ){ + clear(); + using expander = int[]; + (void)expander{ 0, ( (void)( *this << args ), 0 ) ... }; + return *this; +} + iterator begin(){ return m_string.begin(); } diff --git a/tools/quake3/q3map2/model.cpp b/tools/quake3/q3map2/model.cpp index 3bb81b5e..612e7975 100644 --- a/tools/quake3/q3map2/model.cpp +++ b/tools/quake3/q3map2/model.cpp @@ -224,7 +224,6 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap byte *color; picoIndex_t *indexes; skinfile_t *sf, *sf2; - char skinfilename[ MAX_QPATH ]; char *skinfilecontent; int skinfilesize; char *skinfileptr, *skinfilenextptr; @@ -246,14 +245,12 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap } /* load skin file */ - snprintf( skinfilename, sizeof( skinfilename ), "%s_%d.skin", name, skin ); - skinfilename[sizeof( skinfilename ) - 1] = 0; - skinfilesize = vfsLoadFile( skinfilename, (void**) &skinfilecontent, 0 ); + auto skinfilename = StringOutputStream(99)( StringRange( name, path_get_filename_base_end( name ) ), '_', skin, ".skin" ); + skinfilesize = vfsLoadFile( skinfilename.c_str(), (void**) &skinfilecontent, 0 ); if ( skinfilesize < 0 && skin != 0 ) { /* fallback to skin 0 if invalid */ - snprintf( skinfilename, sizeof( skinfilename ), "%s_0.skin", name ); - skinfilename[sizeof( skinfilename ) - 1] = 0; - skinfilesize = vfsLoadFile( skinfilename, (void**) &skinfilecontent, 0 ); + skinfilename( StringRange( name, path_get_filename_base_end( name ) ), "_0.skin" ); + skinfilesize = vfsLoadFile( skinfilename.c_str(), (void**) &skinfilecontent, 0 ); if ( skinfilesize >= 0 ) { Sys_Printf( "Skin %d of %s does not exist, using 0 instead\n", skin, name ); } diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index 530a7417..8ca44272 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -85,6 +85,7 @@ #include "md4.h" #include "stringfixedsize.h" +#include "stream/stringstream.h" #include #include