shorten some StringOutputStream uses

This commit is contained in:
Garux 2021-02-08 13:48:49 +03:00
parent b013f9954c
commit 02874bebee
6 changed files with 51 additions and 97 deletions

View File

@ -256,15 +256,12 @@ void Pointfile_Parse( CPointfile& pointfile ){
const char* mapname = Map_Name( g_map );
StringOutputStream name( 256 );
name << PathExtensionless( mapname ) << ".lin";
size = LoadFile( name.c_str(), (void**)&data );
size = LoadFile( name( PathExtensionless( mapname ), ".lin" ), (void**)&data );
if ( size == -1 ) {
globalErrorStream() << "Pointfile " << name.c_str() << " not found\n";
/* try .pts (q1) */
name.clear();
name << PathExtensionless( mapname ) << ".pts";
size = LoadFile( name.c_str(), (void**)&data );
size = LoadFile( name( PathExtensionless( mapname ), ".pts" ), (void**)&data );
if ( size == -1 ) {
globalErrorStream() << "Pointfile " << name.c_str() << " not found\n";
return;

View File

@ -362,9 +362,8 @@ void CGameDialog::Reset(){
if ( !g_Preferences.m_global_rc_path ) {
InitGlobalPrefPath();
}
StringOutputStream strGlobalPref( 256 );
strGlobalPref << g_Preferences.m_global_rc_path->str << "global.pref";
file_remove( strGlobalPref.c_str() );
file_remove( StringOutputStream( 256 )( g_Preferences.m_global_rc_path->str, "global.pref" ) );
}
void CGameDialog::Init(){

View File

@ -86,35 +86,28 @@ void QE_InitVFS(){
if( !string_empty( extrapath ) )
GlobalFileSystem().initDirectory( extrapath );
StringOutputStream str( 256 );
// if we have a mod dir
if ( !string_equal( gamename, basegame ) ) {
// ~/.<gameprefix>/<fs_game>
if ( userRoot && !string_equal( globalRoot, userRoot ) ) {
StringOutputStream userGamePath( 256 );
userGamePath << userRoot << gamename << '/';
GlobalFileSystem().initDirectory( userGamePath.c_str() );
if ( !string_equal( globalRoot, userRoot ) ) {
GlobalFileSystem().initDirectory( str( userRoot, gamename, '/' ) ); // userGamePath
}
// <fs_basepath>/<fs_game>
{
StringOutputStream globalGamePath( 256 );
globalGamePath << globalRoot << gamename << '/';
GlobalFileSystem().initDirectory( globalGamePath.c_str() );
GlobalFileSystem().initDirectory( str( globalRoot, gamename, '/' ) ); // globalGamePath
}
}
// ~/.<gameprefix>/<fs_main>
if ( userRoot && !string_equal( globalRoot, userRoot ) ) {
StringOutputStream userBasePath( 256 );
userBasePath << userRoot << basegame << '/';
GlobalFileSystem().initDirectory( userBasePath.c_str() );
if ( !string_equal( globalRoot, userRoot ) ) {
GlobalFileSystem().initDirectory( str( userRoot, basegame, '/' ) ); // userBasePath
}
// <fs_basepath>/<fs_main>
{
StringOutputStream globalBasePath( 256 );
globalBasePath << globalRoot << basegame << '/';
GlobalFileSystem().initDirectory( globalBasePath.c_str() );
GlobalFileSystem().initDirectory( str( globalRoot, basegame, '/' ) ); // globalBasePath
}
}
@ -172,19 +165,20 @@ void bsp_init(){
build_set_variable( "GameName", gamename_get() );
const char* mapname = Map_Name( g_map );
StringOutputStream stream( 256 );
{
build_set_variable( "BspFile", StringOutputStream( 256 )( PathExtensionless( mapname ), ".bsp" ).c_str() );
build_set_variable( "BspFile", stream( PathExtensionless( mapname ), ".bsp" ) );
}
if( g_region_active ){
build_set_variable( "MapFile", StringOutputStream( 256 )( PathExtensionless( mapname ), ".reg" ).c_str() );
build_set_variable( "MapFile", stream( PathExtensionless( mapname ), ".reg" ) );
}
else{
build_set_variable( "MapFile", mapname );
}
{
build_set_variable( "MapName", StringOutputStream( 64 )( PathFilename( mapname ) ).c_str() );
build_set_variable( "MapName", stream( PathFilename( mapname ) ) );
}
}

View File

@ -226,11 +226,8 @@ void create(){
// create shader
{
StringOutputStream filename( 256 );
filename << GlobalRadiant().getAppPath() << "gl/lighting_DBS_omni_vp.glsl";
createShader( m_program, filename.c_str(), GL_VERTEX_SHADER_ARB );
filename.clear();
filename << GlobalRadiant().getAppPath() << "gl/lighting_DBS_omni_fp.glsl";
createShader( m_program, filename.c_str(), GL_FRAGMENT_SHADER_ARB );
createShader( m_program, filename( GlobalRadiant().getAppPath(), "gl/lighting_DBS_omni_vp.glsl" ), GL_VERTEX_SHADER_ARB );
createShader( m_program, filename( GlobalRadiant().getAppPath(), "gl/lighting_DBS_omni_fp.glsl" ), GL_FRAGMENT_SHADER_ARB );
}
GLSLProgram_link( m_program );
@ -335,11 +332,8 @@ void create(){
// create shader
{
StringOutputStream filename( 256 );
filename << GlobalRadiant().getAppPath() << "gl/zfill_vp.glsl";
createShader( m_program, filename.c_str(), GL_VERTEX_SHADER_ARB );
filename.clear();
filename << GlobalRadiant().getAppPath() << "gl/zfill_fp.glsl";
createShader( m_program, filename.c_str(), GL_FRAGMENT_SHADER_ARB );
createShader( m_program, filename( GlobalRadiant().getAppPath(), "gl/zfill_vp.glsl" ), GL_VERTEX_SHADER_ARB );
createShader( m_program, filename( GlobalRadiant().getAppPath(), "gl/zfill_fp.glsl" ), GL_FRAGMENT_SHADER_ARB );
}
GLSLProgram_link( m_program );
@ -407,14 +401,11 @@ void create(){
glGenProgramsARB( 1, &m_vertex_program );
glBindProgramARB( GL_VERTEX_PROGRAM_ARB, m_vertex_program );
StringOutputStream filename( 256 );
filename << GlobalRadiant().getAppPath() << "gl/lighting_DBS_omni_vp.glp";
createProgram( filename.c_str(), GL_VERTEX_PROGRAM_ARB );
createProgram( filename( GlobalRadiant().getAppPath(), "gl/lighting_DBS_omni_vp.glp" ), GL_VERTEX_PROGRAM_ARB );
glGenProgramsARB( 1, &m_fragment_program );
glBindProgramARB( GL_FRAGMENT_PROGRAM_ARB, m_fragment_program );
filename.clear();
filename << GlobalRadiant().getAppPath() << "gl/lighting_DBS_omni_fp.glp";
createProgram( filename.c_str(), GL_FRAGMENT_PROGRAM_ARB );
createProgram( filename( GlobalRadiant().getAppPath(), "gl/lighting_DBS_omni_fp.glp" ), GL_FRAGMENT_PROGRAM_ARB );
}
glDisable( GL_VERTEX_PROGRAM_ARB );
@ -509,14 +500,11 @@ void create(){
glGenProgramsARB( 1, &m_vertex_program );
glBindProgramARB( GL_VERTEX_PROGRAM_ARB, m_vertex_program );
StringOutputStream filename( 256 );
filename << GlobalRadiant().getAppPath() << "gl/zfill_vp.glp";
createProgram( filename.c_str(), GL_VERTEX_PROGRAM_ARB );
createProgram( filename( GlobalRadiant().getAppPath(), "gl/zfill_vp.glp" ), GL_VERTEX_PROGRAM_ARB );
glGenProgramsARB( 1, &m_fragment_program );
glBindProgramARB( GL_FRAGMENT_PROGRAM_ARB, m_fragment_program );
filename.clear();
filename << GlobalRadiant().getAppPath() << "gl/zfill_fp.glp";
createProgram( filename.c_str(), GL_FRAGMENT_PROGRAM_ARB );
createProgram( filename( GlobalRadiant().getAppPath(), "gl/zfill_fp.glp" ), GL_FRAGMENT_PROGRAM_ARB );
}
glDisable( GL_VERTEX_PROGRAM_ARB );

View File

@ -661,34 +661,24 @@ typedef ReferenceCaller1<TextureBrowser, bool, TextureBrowser_importShowScrollba
==============
*/
bool endswith( const char *haystack, const char *needle ){
size_t lh = strlen( haystack );
size_t ln = strlen( needle );
if ( lh < ln ) {
return false;
}
return !memcmp( haystack + ( lh - ln ), needle, ln );
}
bool texture_name_ignore( const char* name ){
StringOutputStream strTemp( string_length( name ) );
strTemp << LowerCase( name );
auto temp = StringOutputStream( 64 )( LowerCase( name ) );
return
endswith( strTemp.c_str(), ".specular" ) ||
endswith( strTemp.c_str(), ".glow" ) ||
endswith( strTemp.c_str(), ".bump" ) ||
endswith( strTemp.c_str(), ".diffuse" ) ||
endswith( strTemp.c_str(), ".blend" ) ||
endswith( strTemp.c_str(), ".alpha" ) ||
endswith( strTemp.c_str(), "_norm" ) ||
endswith( strTemp.c_str(), "_bump" ) ||
endswith( strTemp.c_str(), "_glow" ) ||
endswith( strTemp.c_str(), "_gloss" ) ||
endswith( strTemp.c_str(), "_pants" ) ||
endswith( strTemp.c_str(), "_shirt" ) ||
endswith( strTemp.c_str(), "_reflect" ) ||
endswith( strTemp.c_str(), "_alpha" ) ||
string_equal_suffix( temp, ".specular" ) ||
string_equal_suffix( temp, ".glow" ) ||
string_equal_suffix( temp, ".bump" ) ||
string_equal_suffix( temp, ".diffuse" ) ||
string_equal_suffix( temp, ".blend" ) ||
string_equal_suffix( temp, ".alpha" ) ||
string_equal_suffix( temp, "_norm" ) ||
string_equal_suffix( temp, "_bump" ) ||
string_equal_suffix( temp, "_glow" ) ||
string_equal_suffix( temp, "_gloss" ) ||
string_equal_suffix( temp, "_pants" ) ||
string_equal_suffix( temp, "_shirt" ) ||
string_equal_suffix( temp, "_reflect" ) ||
string_equal_suffix( temp, "_alpha" ) ||
0;
}
@ -1966,38 +1956,31 @@ void TextureBrowser_constructSearchButton(){
void TextureBrowser_checkTagFile(){
const char SHADERTAG_FILE[] = "shadertags.xml";
CopiedString default_filename, rc_filename;
StringOutputStream stream( 256 );
stream << LocalRcPath_get();
stream << SHADERTAG_FILE;
rc_filename = stream.c_str();
auto rc_filename = StringOutputStream( 256 )( LocalRcPath_get(), SHADERTAG_FILE );
if ( file_exists( rc_filename.c_str() ) ) {
g_TextureBrowser.m_tags = TagBuilder.OpenXmlDoc( rc_filename.c_str() );
if ( file_exists( rc_filename ) ) {
g_TextureBrowser.m_tags = TagBuilder.OpenXmlDoc( rc_filename );
if ( g_TextureBrowser.m_tags ) {
globalOutputStream() << "Loading tag file " << rc_filename.c_str() << ".\n";
globalOutputStream() << "Loading tag file " << rc_filename << ".\n";
}
}
else
{
// load default tagfile
stream.clear();
stream << g_pGameDescription->mGameToolsPath.c_str();
stream << SHADERTAG_FILE;
default_filename = stream.c_str();
auto default_filename = StringOutputStream( 256 )( g_pGameDescription->mGameToolsPath.c_str(), SHADERTAG_FILE );
if ( file_exists( default_filename.c_str() ) ) {
g_TextureBrowser.m_tags = TagBuilder.OpenXmlDoc( default_filename.c_str(), rc_filename.c_str() );
if ( file_exists( default_filename ) ) {
g_TextureBrowser.m_tags = TagBuilder.OpenXmlDoc( default_filename, rc_filename );
if ( g_TextureBrowser.m_tags ) {
globalOutputStream() << "Loading default tag file " << default_filename.c_str() << ".\n";
globalOutputStream() << "Loading default tag file " << default_filename << ".\n";
}
}
else
{
globalWarningStream() << "Unable to find default tag file " << default_filename.c_str() << ". No tag support. Plugins -> ShaderPlug -> Create tag file: to start using texture tags\n";
globalWarningStream() << "Unable to find default tag file " << default_filename << ". No tag support. Plugins -> ShaderPlug -> Create tag file: to start using texture tags\n";
}
}
}

View File

@ -1820,22 +1820,17 @@ void XYWnd::PaintSizeInfo( const int nDim1, const int nDim2 ){
v[nDim1] = mid[nDim1];
v[nDim2] = min[nDim2] - ( 10 + 2 + fontHeight ) / m_fScale;
glRasterPos3fv( vector3_to_array( v ) );
dimensions << dimStrings[nDim1] << size[nDim1];
GlobalOpenGL().drawString( dimensions.c_str() );
dimensions.clear();
GlobalOpenGL().drawString( dimensions( dimStrings[nDim1], size[nDim1] ) );
v[nDim1] = max[nDim1] + 16.f / m_fScale;
v[nDim2] = mid[nDim2] - fontHeight / m_fScale / 2;
glRasterPos3fv( vector3_to_array( v ) );
dimensions << dimStrings[nDim2] << size[nDim2];
GlobalOpenGL().drawString( dimensions.c_str() );
dimensions.clear();
GlobalOpenGL().drawString( dimensions( dimStrings[nDim2], size[nDim2] ) );
v[nDim1] = min[nDim1] + 4.f;
v[nDim2] = max[nDim2] + 5.f / m_fScale;
glRasterPos3fv( vector3_to_array( v ) );
dimensions << "(" << dimStrings[nDim1] << min[nDim1] << " " << dimStrings[nDim2] << max[nDim2] << ")";
GlobalOpenGL().drawString( dimensions.c_str() );
GlobalOpenGL().drawString( dimensions( "(", dimStrings[nDim1], min[nDim1], " ", dimStrings[nDim2], max[nDim2], ")" ) );
}
class XYRenderer : public Renderer
@ -2123,9 +2118,7 @@ void XYWnd::XY_Draw(){
glRasterPos3f( 2.f, 0.f, 0.0f );
extern const char* Renderer_GetStats();
StringOutputStream stream;
stream << Renderer_GetStats() << " | f2f: " << m_render_time.elapsed_msec();
GlobalOpenGL().drawString( stream.c_str() );
GlobalOpenGL().drawString( StringOutputStream( 64 )( Renderer_GetStats(), " | f2f: ", m_render_time.elapsed_msec() ) );
m_render_time.start();
}