tweak StringOutputStream use

auto str = StringOutputStream()(bla) use form was not doing copy elision or move, but copy
This commit is contained in:
Garux
2024-01-29 16:54:08 +06:00
parent b4e44bc8ed
commit df02774ff5
122 changed files with 984 additions and 1204 deletions
+1 -1
View File
@@ -92,7 +92,7 @@ public:
PakFileSystem::entry_type& file = m_filesystem[entry.filename];
if ( !file.is_directory() ) {
globalWarningStream() << "Warning: pak archive " << makeQuoted( m_name ) << " contains duplicated file: " << makeQuoted( entry.filename ) << "\n";
globalWarningStream() << "Warning: pak archive " << makeQuoted( m_name ) << " contains duplicated file: " << makeQuoted( entry.filename ) << '\n';
}
else
{
+1 -1
View File
@@ -161,7 +161,7 @@ class ZipArchive final : public Archive
{
ZipFileSystem::entry_type& file = m_filesystem[filename.data()];
if ( !file.is_directory() ) {
globalWarningStream() << "Warning: zip archive " << makeQuoted( m_name ) << " contains duplicated file: " << makeQuoted( filename.data() ) << "\n";
globalWarningStream() << "Warning: zip archive " << makeQuoted( m_name ) << " contains duplicated file: " << makeQuoted( filename.data() ) << '\n';
}
else
{
+9 -9
View File
@@ -223,7 +223,7 @@ private:
aiString matname = material->GetName();
#ifdef _DEBUG
globalOutputStream() << "matname: " << matname.C_Str() << "\n";
globalOutputStream() << "matname: " << matname.C_Str() << '\n';
#endif
if( aiString texname;
aiReturn_SUCCESS == material->Get( AI_MATKEY_TEXTURE_DIFFUSE(0), texname )
@@ -233,18 +233,18 @@ private:
&& !string_equal_prefix_nocase( matname.C_Str(), "models/" )
&& !string_equal_prefix_nocase( matname.C_Str(), "models\\" ) ){
#ifdef _DEBUG
globalOutputStream() << "texname: " << texname.C_Str() << "\n";
globalOutputStream() << "texname: " << texname.C_Str() << '\n';
#endif
m_shader = StringOutputStream()( PathCleaned( PathExtensionless( texname.C_Str() ) ) );
m_shader = StringStream<64>( PathCleaned( PathExtensionless( texname.C_Str() ) ) );
}
else{
m_shader = StringOutputStream()( PathCleaned( PathExtensionless( matname.C_Str() ) ) );
m_shader = StringStream<64>( PathCleaned( PathExtensionless( matname.C_Str() ) ) );
}
const CopiedString oldShader( m_shader );
if( strchr( m_shader.c_str(), '/' ) == nullptr ){ /* texture is likely in the folder, where model is */
m_shader = StringOutputStream()( scene.m_rootPath, m_shader );
m_shader = StringStream<64>( scene.m_rootPath, m_shader );
}
else{
const char *name = m_shader.c_str();
@@ -255,13 +255,13 @@ private:
m_shader = p + 1;
}
else{
m_shader = StringOutputStream()( scene.m_rootPath, path_get_filename_start( name ) );
m_shader = StringStream<64>( scene.m_rootPath, path_get_filename_start( name ) );
}
}
}
if( oldShader != m_shader )
globalOutputStream() << "substituting: " << oldShader << " -> " << m_shader << "\n";
globalOutputStream() << "substituting: " << oldShader << " -> " << m_shader << '\n';
}
m_vertices.resize( mesh->mNumVertices );
@@ -688,8 +688,8 @@ scene::Node& loadPicoModel( Assimp::Importer& importer, ArchiveFile& file ){
if( scene != nullptr ){
if( scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE )
globalWarningStream() << "AI_SCENE_FLAGS_INCOMPLETE\n";
const auto rootPath = StringOutputStream()( PathFilenameless( file.getName() ) );
const auto matName = StringOutputStream()( PathExtensionless( file.getName() ) );
const auto rootPath = StringStream<64>( PathFilenameless( file.getName() ) );
const auto matName = StringStream<64>( PathExtensionless( file.getName() ) );
return ( new PicoModelNode( AssScene{ scene, rootPath, path_extension_is( file.getName(), "mdl" )? matName.c_str() : nullptr } ) )->node();
}
else{
+10 -10
View File
@@ -62,24 +62,24 @@ class AssLogger : public Assimp::Logger
public:
void OnDebug( const char* message ) override {
#ifdef _DEBUG
globalOutputStream() << message << "\n";
globalOutputStream() << message << '\n';
#endif
}
void OnVerboseDebug( const char *message ) override {
#ifdef _DEBUG
globalOutputStream() << message << "\n";
globalOutputStream() << message << '\n';
#endif
}
void OnInfo( const char* message ) override {
#ifdef _DEBUG
globalOutputStream() << message << "\n";
globalOutputStream() << message << '\n';
#endif
}
void OnWarn( const char* message ) override {
globalWarningStream() << message << "\n";
globalWarningStream() << message << '\n';
}
void OnError( const char* message ) override {
globalErrorStream() << message << "\n";
globalErrorStream() << message << '\n';
}
bool attachStream( Assimp::LogStream *pStream, unsigned int severity ) override {
@@ -102,7 +102,7 @@ public:
*/
bool Exists( const char* pFile ) const override {
if( strchr( pFile, '\\' ) != nullptr ){
globalWarningStream() << "AssIOSystem::Exists " << pFile << "\n";
globalWarningStream() << "AssIOSystem::Exists " << pFile << '\n';
return false;
}
@@ -139,7 +139,7 @@ public:
*/
Assimp::IOStream* Open( const char* pFile, const char* pMode = "rb" ) override {
if( strchr( pFile, '\\' ) != nullptr ){
globalWarningStream() << "AssIOSystem::Open " << pFile << "\n";
globalWarningStream() << "AssIOSystem::Open " << pFile << '\n';
return nullptr;
}
@@ -238,7 +238,7 @@ public:
typedef ModelLoader Type;
ModelPicoAPI( const char* extension ){
GlobalFiletypesModule::getTable().addType( Type::Name, extension, filetype_t( StringOutputStream()( extension, " model" ), StringOutputStream()( "*.", extension ) ) );
GlobalFiletypesModule::getTable().addType( Type::Name, extension, filetype_t( StringStream<32>( extension, " model" ), StringStream<16>( "*.", extension ) ) );
}
ModelLoader* getTable(){
return &m_modelLoader;
@@ -307,7 +307,7 @@ extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules( ModuleServer& server
s_assImporter->GetExtensionList( extensions ); // "*.3ds;*.obj;*.dae"
const char *c = extensions.C_Str();
while( !string_empty( c ) ){
StringOutputStream ext;
StringOutputStream ext( 16 );
do{
if( *c == '*' && *( c + 1 ) == '.' ){
c += 2;
@@ -326,7 +326,7 @@ extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules( ModuleServer& server
g_PicoModelModules.push_back( PicoModelModule( PicoModelAPIConstructor( ext ) ) );
g_PicoModelModules.back().selfRegister();
// globalOutputStream() << ext << "\n";
// globalOutputStream() << ext << '\n';
}
g_ImageMDLModule.selfRegister();
+8 -8
View File
@@ -51,16 +51,16 @@ inline void plotBasisFunction( std::size_t numSegments, int point, int degree ){
globalOutputStream() << "plotBasisFunction point " << point << " of 4, knot vector:";
for ( Knots::iterator i = knots.begin(); i != knots.end(); ++i )
{
globalOutputStream() << " " << *i;
globalOutputStream() << ' ' << *i;
}
globalOutputStream() << "\n";
globalOutputStream() << "t=0 basis=" << BSpline_basis( knots, point, degree, 0.0 ) << "\n";
globalOutputStream() << '\n';
globalOutputStream() << "t=0 basis=" << BSpline_basis( knots, point, degree, 0.0 ) << '\n';
for ( std::size_t i = 1; i < numSegments; ++i )
{
double t = ( 1.0 / double(numSegments) ) * double(i);
globalOutputStream() << "t=" << t << " basis=" << BSpline_basis( knots, point, degree, t ) << "\n";
globalOutputStream() << "t=" << t << " basis=" << BSpline_basis( knots, point, degree, t ) << '\n';
}
globalOutputStream() << "t=1 basis=" << BSpline_basis( knots, point, degree, 1.0 ) << "\n";
globalOutputStream() << "t=1 basis=" << BSpline_basis( knots, point, degree, 1.0 ) << '\n';
}
inline bool ControlPoints_parse( ControlPoints& controlPoints, const char* value ){
@@ -97,9 +97,9 @@ inline void ControlPoints_write( const ControlPoints& controlPoints, StringOutpu
value << controlPoints.size() << " (";
for ( ControlPoints::const_iterator i = controlPoints.begin(); i != controlPoints.end(); ++i )
{
value << " " << ( *i ).x() << " " << ( *i ).y() << " " << ( *i ).z() << " ";
value << ' ' << ( *i ).x() << ' ' << ( *i ).y() << ' ' << ( *i ).z() << ' ';
}
value << ")";
value << ')';
}
inline void ControlPoint_testSelect( const Vector3& point, ObservedSelectable& selectable, Selector& selector, SelectionTest& test ){
@@ -166,7 +166,7 @@ inline void ControlPoints_write( ControlPoints& controlPoints, const char* key,
if ( !controlPoints.empty() ) {
ControlPoints_write( controlPoints, value );
}
entity.setKeyValue( key, value.c_str() );
entity.setKeyValue( key, value );
}
class CurveEdit
+10 -16
View File
@@ -132,15 +132,13 @@ public:
ConnectEntities( Entity* e1, Entity* e2, int index ) : m_e1( e1 ), m_e2( e2 ), m_index( index ){
}
const char *keyname(){
StringOutputStream key( 16 );
if ( m_index <= 0 ) {
return "target";
}
if ( m_index == 1 ) {
return "killtarget";
}
key << "target" << m_index;
return key.c_str();
return StringStream<16>( "target", m_index );
}
void connect( const char* name ){
m_e1->setKeyValue( keyname(), name );
@@ -189,26 +187,24 @@ public:
if ( g_gameType == eGameTypeDoom3 ) {
StringOutputStream key( 16 );
if ( index >= 0 ) {
key << "target";
key( "target" );
if ( index != 0 ) {
key << index;
}
e1->setKeyValue( key.c_str(), e2->getKeyValue( "name" ) );
key.clear();
e1->setKeyValue( key, e2->getKeyValue( "name" ) );
}
else
{
for ( unsigned int i = 0; ; ++i )
{
key << "target";
key( "target" );
if ( i != 0 ) {
key << i;
}
if ( !e1->hasKeyValue( key.c_str() ) ) {
e1->setKeyValue( key.c_str(), e2->getKeyValue( "name" ) );
if ( !e1->hasKeyValue( key ) ) {
e1->setKeyValue( key, e2->getKeyValue( "name" ) );
break;
}
key.clear();
}
}
}
@@ -227,9 +223,8 @@ public:
if ( string_empty( type ) ) {
type = "t";
}
StringOutputStream key( 64 );
key << type << "1";
GlobalNamespace().makeUnique( key.c_str(), ConnectEntities::ConnectCaller( connector ) );
const auto key = StringStream<64>( type, '1' );
GlobalNamespace().makeUnique( key, ConnectEntities::ConnectCaller( connector ) );
}
}
//normal connect
@@ -250,9 +245,8 @@ public:
if ( string_empty( type ) ) {
type = "t";
}
StringOutputStream key( 64 );
key << type << "1";
GlobalNamespace().makeUnique( key.c_str(), ConnectEntities::ConnectCaller( connector ) );
const auto key = StringStream<64>( type, '1' );
GlobalNamespace().makeUnique( key, ConnectEntities::ConnectCaller( connector ) );
}
}
}
+2 -2
View File
@@ -846,7 +846,7 @@ public:
r[2] = r[0] / sqrt( 255.f );
}
}
// globalOutputStream() << r[0] << " " << r[1] << " " << r[2] << " m_radii_transformed\n";
// globalOutputStream() << r[0] << ' ' << r[1] << ' ' << r[2] << " m_radii_transformed\n";
}
float calculateIntensityFromRadii() const {
return std::copysign( spawnflags_linear( m_flags ) // keep intensity sign, while adjusting it via radii
@@ -1935,7 +1935,7 @@ public:
}
else
{
//globalOutputStream() << getTranslation() << "\n";
//globalOutputStream() << getTranslation() << '\n';
if ( g_lightType == LIGHTTYPE_DOOM3 ) {
m_dragPlanes.m_bounds = m_contained.aabb();
m_contained.setLightRadius( m_dragPlanes.evaluateResize( getTranslation(), rotation() ) );
+1 -1
View File
@@ -67,7 +67,7 @@ class RemapKeysObserver : public Entity::Observer, public ModelSkin
const char* split = strchr( value, ';' );
if( split != nullptr ){
m_from = { value, split };
m_to = StringOutputStream( 64 )( PathCleaned( split + 1 ) ).c_str();
m_to = StringStream<64>( PathCleaned( split + 1 ) );
}
else{
m_from = "";
+1 -3
View File
@@ -58,10 +58,8 @@ public:
}
void modelChanged( const char* value ){
StringOutputStream cleaned( string_length( value ) );
cleaned << PathCleaned( value );
m_resource.detach( *this );
m_resource.setName( cleaned.c_str() );
m_resource.setName( StringOutputStream( string_length( value ) + 1 )( PathCleaned( value ) ) );
m_resource.attach( *this );
m_modelChanged();
}
+1 -1
View File
@@ -30,7 +30,7 @@
#include "traverselib.h"
inline void parseTextureName( CopiedString& name, const char* token ){
name = StringOutputStream( 256 )( PathCleaned( PathExtensionless( token ) ) ).c_str(); // remove extension
name = StringStream( PathCleaned( PathExtensionless( token ) ) ); // remove extension
}
class ModelSkinKey : public ModuleObserver
+2 -2
View File
@@ -141,9 +141,9 @@ public:
// globalOutputStream() << position << " Projection division\n";
matrix4_transform_vector4( volume.GetViewport(), position );
// globalOutputStream() << position << " Viewport\n";
// globalOutputStream() << volume.GetViewport()[0] << " " << volume.GetViewport()[5] << " Viewport size\n";
// globalOutputStream() << volume.GetViewport()[0] << ' ' << volume.GetViewport()[5] << " Viewport size\n";
m_label.screenPos = position.vec3().vec2();
// globalOutputStream() << m_label.screenPos << "\n";
// globalOutputStream() << m_label.screenPos << '\n';
renderer.PushState();
+2 -2
View File
@@ -60,13 +60,13 @@ class NameKeys : public Entity::Observer, public Namespaced
void insertName( const char* key, EntityKeyValue& value ){
if ( m_namespace != 0 && m_keyIsName( key ) ) {
//globalOutputStream() << "insert " << key << "\n";
//globalOutputStream() << "insert " << key << '\n';
m_namespace->attach( KeyValueAssignCaller( value ), KeyValueAttachCaller( value ) );
}
}
void eraseName( const char* key, EntityKeyValue& value ){
if ( m_namespace != 0 && m_keyIsName( key ) ) {
//globalOutputStream() << "erase " << key << "\n";
//globalOutputStream() << "erase " << key << '\n';
m_namespace->detach( KeyValueAssignCaller( value ), KeyValueDetachCaller( value ) );
}
}
+11 -11
View File
@@ -57,17 +57,17 @@ inline void write_rotation( const Float9 rotation, Entity* entity, const char* k
}
else
{
StringOutputStream value( 256 );
value << rotation[0] << ' '
<< rotation[1] << ' '
<< rotation[2] << ' '
<< rotation[3] << ' '
<< rotation[4] << ' '
<< rotation[5] << ' '
<< rotation[6] << ' '
<< rotation[7] << ' '
<< rotation[8];
entity->setKeyValue( key, value.c_str() );
const auto value = StringStream(
rotation[0], ' ',
rotation[1], ' ',
rotation[2], ' ',
rotation[3], ' ',
rotation[4], ' ',
rotation[5], ' ',
rotation[6], ' ',
rotation[7], ' ',
rotation[8] );
entity->setKeyValue( key, value );
}
}
inline void read_rotation( Float9 rotation, const char* value ){
+4 -6
View File
@@ -38,7 +38,7 @@
#include "stringio.h"
void parseShaderName( CopiedString& name, const char* token ){
name = StringOutputStream( 256 )( PathCleaned( token ) ).c_str();
name = StringStream( PathCleaned( token ) );
}
class Doom3ModelSkin
@@ -136,11 +136,9 @@ public:
}
void parseFile( const char* name ){
StringOutputStream relativeName( 64 );
relativeName << "skins/" << name;
ArchiveTextFile* file = GlobalFileSystem().openTextFile( relativeName.c_str() );
ArchiveTextFile* file = GlobalFileSystem().openTextFile( StringStream<64>( "skins/", name ) );
if ( file != 0 ) {
globalOutputStream() << "parsing skins from " << makeQuoted( name ) << "\n";
globalOutputStream() << "parsing skins from " << makeQuoted( name ) << '\n';
{
Tokeniser& tokeniser = GlobalScriptLibrary().m_pfnNewSimpleTokeniser( file->getInputStream() );
parseTokens( tokeniser );
@@ -150,7 +148,7 @@ public:
}
else
{
globalErrorStream() << "failed to open " << makeQuoted( name ) << "\n";
globalErrorStream() << "failed to open " << makeQuoted( name ) << '\n';
}
}
+1 -1
View File
@@ -356,7 +356,7 @@ static Image* LoadJPGBuff_( const void *src_buffer, int src_size ){
jerr.pub.error_exit = my_jpeg_error_exit;
if ( setjmp( jerr.setjmp_buffer ) ) { //< TODO: use c++ exceptions instead of setjmp/longjmp to handle errors
globalWarningStream() << "WARNING: JPEG library error: " << errormsg << "\n";
globalWarningStream() << "WARNING: JPEG library error: " << errormsg << '\n';
jpeg_destroy_decompress( &cinfo );
return 0;
}
+2 -2
View File
@@ -371,7 +371,7 @@ Image* LoadKTXBuff( PointerInputStream& istream ){
}
if ( !decoder ) {
globalErrorStream() << "LoadKTX: Image has an unsupported pixel type " << type << " or format " << format << "\n";
globalErrorStream() << "LoadKTX: Image has an unsupported pixel type " << type << " or format " << format << '\n';
image->release();
return 0;
}
@@ -400,7 +400,7 @@ Image* LoadKTXBuff( PointerInputStream& istream ){
KTX_DecodeETC1( istream, *image );
break;
default:
globalErrorStream() << "LoadKTX: Image has an unsupported compressed format " << format << "\n";
globalErrorStream() << "LoadKTX: Image has an unsupported compressed format " << format << '\n';
image->release();
return 0;
}
+2 -2
View File
@@ -34,11 +34,11 @@
#include <cstdlib>
void user_warning_fn( png_structp png_ptr, png_const_charp warning_msg ){
globalWarningStream() << "libpng warning: " << warning_msg << "\n";
globalWarningStream() << "libpng warning: " << warning_msg << '\n';
}
void user_error_fn( png_structp png_ptr, png_const_charp error_msg ){
globalErrorStream() << "libpng error: " << error_msg << "\n";
globalErrorStream() << "libpng error: " << error_msg << '\n';
longjmp( png_jmpbuf(png_ptr), 0 );
}
+1 -1
View File
@@ -93,7 +93,7 @@ NodeSmartReference Entity_parseTokens( Tokeniser& tokeniser, EntityCreator& enti
}
else
{
globalErrorStream() << "entity " << index << ": type " << classname << ": discarding brush " << count_primitives << "\n";
globalErrorStream() << "entity " << index << ": type " << classname << ": discarding brush " << count_primitives << '\n';
}
++count_primitives;
}
+2 -2
View File
@@ -111,7 +111,7 @@ public:
return;
}
if ( version != MapVersion ) {
globalErrorStream() << "Doom 3 map version " << MapVersion << " supported, version is " << version << "\n";
globalErrorStream() << "Doom 3 map version " << MapVersion << " supported, version is " << version << '\n';
return;
}
tokeniser.nextLine();
@@ -182,7 +182,7 @@ public:
return;
}
if ( version != MapVersion ) {
globalErrorStream() << "Quake 4 map version " << MapVersion << " supported, version is " << version << "\n";
globalErrorStream() << "Quake 4 map version " << MapVersion << " supported, version is " << version << '\n';
return;
}
tokeniser.nextLine();
+1 -1
View File
@@ -72,7 +72,7 @@ public:
if ( entity != 0 ) {
if( entity->isContainer() && Node_getTraversable( node )->empty() && !string_equal( entity->getClassName(), "worldspawn" )
&& !entity->hasKeyValue( "origin" ) ){
globalErrorStream() << "discarding empty group entity: # = " << g_count_entities << "; classname = " << entity->getClassName() << "\n";
globalErrorStream() << "discarding empty group entity: # = " << g_count_entities << "; classname = " << entity->getClassName() << '\n';
return false;
}
m_writer.writeToken( "//" );
+2 -2
View File
@@ -250,9 +250,9 @@ void MD2Surface_read( Model& model, const byte* buffer, ArchiveFile& file ){
}
path[i] = '\0';
}
// globalErrorStream() << "modified skinname: " << path << " (path) and " << skinnameRelative << " (texture)" << "\n";
// globalErrorStream() << "modified skinname: " << path << " (path) and " << skinnameRelative << " (texture)" << '\n';
snprintf( skinname, MD2_MAX_SKINNAME, "%s%s", path, &skinnameRelative[1] );
// globalErrorStream() << skinname << "\n";
// globalErrorStream() << skinname << '\n';
}
else
{
+1 -1
View File
@@ -65,7 +65,7 @@ inline VertexPointer vertexpointer_arbitrarymeshvertex( const ArbitraryMeshVerte
}
inline void parseTextureName( CopiedString& name, const char* token ){
name = StringOutputStream( 256 )( PathCleaned( PathExtensionless( token ) ) ).c_str(); // remove extension
name = StringStream<64>( PathCleaned( PathExtensionless( token ) ) ); // remove extension
}
// generic renderable triangle surface
+7 -8
View File
@@ -53,23 +53,23 @@ void PicoPrintFunc( int level, const char *str ){
switch ( level )
{
case PICO_NORMAL:
globalOutputStream() << str << "\n";
globalOutputStream() << str << '\n';
break;
case PICO_VERBOSE:
//globalOutputStream() << "PICO_VERBOSE: " << str << "\n";
//globalOutputStream() << "PICO_VERBOSE: " << str << '\n';
break;
case PICO_WARNING:
globalWarningStream() << "PICO_WARNING: " << str << "\n";
globalWarningStream() << "PICO_WARNING: " << str << '\n';
break;
case PICO_ERROR:
globalErrorStream() << "PICO_ERROR: " << str << "\n";
globalErrorStream() << "PICO_ERROR: " << str << '\n';
break;
case PICO_FATAL:
globalErrorStream() << "PICO_FATAL: " << str << "\n";
globalErrorStream() << "PICO_FATAL: " << str << '\n';
break;
}
}
@@ -122,9 +122,8 @@ public:
ModelPicoAPI( const char* extension, const picoModule_t* module ) :
m_modelLoader( module ){
StringOutputStream filter( 128 );
filter << "*." << extension;
GlobalFiletypesModule::getTable().addType( Type::Name, extension, filetype_t( module->displayName, filter.c_str() ) );
const auto filter = StringStream<16>( "*.", extension );
GlobalFiletypesModule::getTable().addType( Type::Name, extension, filetype_t( module->displayName, filter ) );
}
ModelLoader* getTable(){
return &m_modelLoader;
+37 -55
View File
@@ -202,9 +202,7 @@ Image* loadHeightmap( void* environment, const char* name ){
Image* loadSpecial( void* environment, const char* name ){
if ( *name == '_' ) { // special image
StringOutputStream bitmapName( 256 );
bitmapName << GlobalRadiant().getAppPath() << "bitmaps/" << name + 1 << ".png";
Image* image = loadBitmap( environment, bitmapName.c_str() );
Image* image = loadBitmap( environment, StringStream( GlobalRadiant().getAppPath(), "bitmaps/", name + 1, ".png" ) );
if ( image != 0 ) {
return image;
}
@@ -228,7 +226,7 @@ typedef CopiedString TextureExpression;
//++timo FIXME: we need to put code somewhere to detect when two shaders that are case insensitive equal are present
template<typename StringType>
void parseTextureName( StringType& name, const char* token ){
name = StringOutputStream( 256 )( PathCleaned( PathExtensionless( token ) ) ).c_str(); // remove extension
name = StringStream<64>( PathCleaned( PathExtensionless( token ) ) ).c_str(); // remove extension
}
bool Tokeniser_parseTextureName( Tokeniser& tokeniser, TextureExpression& name ){
@@ -705,7 +703,7 @@ bool parseTemplateInstance( Tokeniser& tokeniser, const char* filename ){
const char* templateName = tokeniser.getToken();
ShaderTemplate* shaderTemplate = findTemplate( templateName );
if ( shaderTemplate == 0 ) {
globalErrorStream() << "shader instance: " << makeQuoted( name ) << ": shader template not found: " << makeQuoted( templateName ) << "\n";
globalErrorStream() << "shader instance: " << makeQuoted( name ) << ": shader template not found: " << makeQuoted( templateName ) << '\n';
}
ShaderArguments args;
@@ -772,14 +770,14 @@ qtexture_t* evaluateTexture( const TextureExpression& texture, const ShaderParam
}
result << expression;
}
return GlobalTexturesCache().capture( loader, result.c_str() );
return GlobalTexturesCache().capture( loader, result );
}
float evaluateFloat( const ShaderValue& value, const ShaderParameters& params, const ShaderArguments& args ){
const char* result = evaluateShaderValue( value.c_str(), params, args );
float f;
if ( !string_parse_float( result, f ) ) {
globalErrorStream() << "parsing float value failed: " << makeQuoted( result ) << "\n";
globalErrorStream() << "parsing float value failed: " << makeQuoted( result ) << '\n';
return 1.f;
}
return f;
@@ -822,7 +820,7 @@ BlendFactor evaluateBlendFactor( const ShaderValue& value, const ShaderParameter
return BLEND_SRC_ALPHA_SATURATE;
}
globalErrorStream() << "parsing blend-factor value failed: " << makeQuoted( result ) << "\n";
globalErrorStream() << "parsing blend-factor value failed: " << makeQuoted( result ) << '\n';
return BLEND_ZERO;
}
@@ -957,11 +955,8 @@ public:
if ( m_pTexture->texture_number == 0 ) {
m_notfound = m_pTexture;
{
StringOutputStream name( 256 );
name << GlobalRadiant().getAppPath() << "bitmaps/" << ( IsDefault() ? "notex.png" : "shadernotex.png" );
m_pTexture = GlobalTexturesCache().capture( LoadImageCallback( 0, loadBitmap ), name.c_str() );
}
const auto name = StringStream( GlobalRadiant().getAppPath(), "bitmaps/", ( IsDefault() ? "notex.png" : "shadernotex.png" ) );
m_pTexture = GlobalTexturesCache().capture( LoadImageCallback( 0, loadBitmap ), name );
}
realiseLighting();
@@ -1021,7 +1016,7 @@ public:
}
else
{
globalErrorStream() << "parsing blend value failed: " << makeQuoted( blend ) << "\n";
globalErrorStream() << "parsing blend value failed: " << makeQuoted( blend ) << '\n';
}
}
}
@@ -1402,7 +1397,7 @@ void ParseShaderFile( Tokeniser& tokeniser, const char* filename ){
}
else
{
globalErrorStream() << "Error parsing shader " << shaderTemplate->getName() << "\n";
globalErrorStream() << "Error parsing shader " << shaderTemplate->getName() << '\n';
return;
}
}
@@ -1452,7 +1447,7 @@ void LoadShaderFile( const char* filename ){
ArchiveTextFile* file = GlobalFileSystem().openTextFile( filename );
if ( file != 0 ) {
globalOutputStream() << "Parsing shaderfile " << filename << "\n";
globalOutputStream() << "Parsing shaderfile " << filename << '\n';
Tokeniser& tokeniser = GlobalScriptLibrary().m_pfnNewScriptTokeniser( file->getInputStream() );
@@ -1463,7 +1458,7 @@ void LoadShaderFile( const char* filename ){
}
else
{
globalWarningStream() << "Unable to read shaderfile " << filename << "\n";
globalWarningStream() << "Unable to read shaderfile " << filename << '\n';
}
}
@@ -1471,23 +1466,22 @@ typedef FreeCaller1<const char*, LoadShaderFile> LoadShaderFileCaller;
void loadGuideFile( const char* filename ){
StringOutputStream fullname( 256 );
fullname << "guides/" << filename;
ArchiveTextFile* file = GlobalFileSystem().openTextFile( fullname.c_str() );
const auto fullname = StringStream( "guides/", filename );
ArchiveTextFile* file = GlobalFileSystem().openTextFile( fullname );
if ( file != 0 ) {
globalOutputStream() << "Parsing guide file " << fullname.c_str() << "\n";
globalOutputStream() << "Parsing guide file " << fullname << '\n';
Tokeniser& tokeniser = GlobalScriptLibrary().m_pfnNewScriptTokeniser( file->getInputStream() );
parseGuideFile( tokeniser, fullname.c_str() );
parseGuideFile( tokeniser, fullname );
tokeniser.release();
file->release();
}
else
{
globalWarningStream() << "Unable to read guide file " << fullname.c_str() << "\n";
globalWarningStream() << "Unable to read guide file " << fullname << '\n';
}
}
@@ -1561,7 +1555,7 @@ void IfFound_dumpUnreferencedShader( bool& bFound, const char* filename ){
bFound = true;
globalOutputStream() << "Following shader files are not referenced in any shaderlist.txt:\n";
}
globalOutputStream() << "\t" << filename << "\n";
globalOutputStream() << '\t' << filename << '\n';
}
}
typedef ReferenceCaller1<bool, const char*, IfFound_dumpUnreferencedShader> IfFoundDumpUnreferencedShaderCaller;
@@ -1599,22 +1593,15 @@ typedef FreeCaller1<const char*, ShaderList_addShaderFile> AddShaderFileCaller;
*/
void BuildShaderList( TextInputStream& shaderlist ){
Tokeniser& tokeniser = GlobalScriptLibrary().m_pfnNewSimpleTokeniser( shaderlist );
tokeniser.nextLine();
const char* token = tokeniser.getToken();
StringOutputStream shaderFile( 64 );
while ( token != 0 )
for( const char* token; tokeniser.nextLine(), token = tokeniser.getToken(); )
{
// each token should be a shader filename
shaderFile << token;
shaderFile( token );
if( !path_extension_is( token, g_shadersExtension ) )
shaderFile << "." << g_shadersExtension;
shaderFile << '.' << g_shadersExtension;
ShaderList_addShaderFile( shaderFile.c_str() );
tokeniser.nextLine();
token = tokeniser.getToken();
shaderFile.clear();
ShaderList_addShaderFile( shaderFile );
}
tokeniser.release();
}
@@ -1627,9 +1614,9 @@ void ShaderList_addFromArchive( const char *archivename ){
Archive *archive = GlobalFileSystem().getArchive( archivename, false );
if ( archive ) {
ArchiveTextFile *file = archive->openTextFile( StringOutputStream( 64 )( DirectoryCleaned( shaderpath ), "shaderlist.txt" ).c_str() );
ArchiveTextFile *file = archive->openTextFile( StringStream<64>( DirectoryCleaned( shaderpath ), "shaderlist.txt" ) );
if ( file ) {
globalOutputStream() << "Found shaderlist.txt in " << archivename << "\n";
globalOutputStream() << "Found shaderlist.txt in " << archivename << '\n';
BuildShaderList( file->getInputStream() );
file->release();
}
@@ -1641,23 +1628,20 @@ typedef FreeCaller1<const char *, ShaderList_addFromArchive> AddShaderListFromAr
#include "stream/filestream.h"
bool shaderlist_findOrInstall( const char* enginePath, const char* toolsPath, const char* shaderPath, const char* gamename ){
StringOutputStream absShaderList( 256 );
absShaderList << enginePath << gamename << '/' << shaderPath << "shaderlist.txt";
if ( file_exists( absShaderList.c_str() ) ) {
const auto absShaderList = StringStream( enginePath, gamename, '/', shaderPath, "shaderlist.txt" );
if ( file_exists( absShaderList ) ) {
return true;
}
{
StringOutputStream directory( 256 );
directory << enginePath << gamename << '/' << shaderPath;
if ( !file_exists( directory.c_str() ) && !Q_mkdir( directory.c_str() ) ) {
const auto directory = StringStream( enginePath, gamename, '/', shaderPath );
if ( !file_exists( directory ) && !Q_mkdir( directory ) ) {
return false;
}
}
{
StringOutputStream defaultShaderList( 256 );
defaultShaderList << toolsPath << gamename << '/' << "default_shaderlist.txt";
if ( file_exists( defaultShaderList.c_str() ) ) {
return file_copy( defaultShaderList.c_str(), absShaderList.c_str() );
const auto defaultShaderList = StringStream( toolsPath, gamename, '/', "default_shaderlist.txt" );
if ( file_exists( defaultShaderList ) ) {
return file_copy( defaultShaderList, absShaderList );
}
}
return false;
@@ -1670,7 +1654,7 @@ void Shaders_Load(){
const char* shaderPath = GlobalRadiant().getGameDescriptionKeyValue( "shaderpath" );
if ( !string_empty( shaderPath ) ) {
const auto path = StringOutputStream( 64 )( DirectoryCleaned( shaderPath ) );
const auto path = StringStream<64>( DirectoryCleaned( shaderPath ) );
if ( g_useShaderList ) {
// preload shader files that have been listed in shaderlist.txt
@@ -1681,9 +1665,9 @@ void Shaders_Load(){
bool isMod = !string_equal( basegame, gamename );
if ( !isMod || !shaderlist_findOrInstall( enginePath, toolsPath, path.c_str(), gamename ) ) {
if ( !isMod || !shaderlist_findOrInstall( enginePath, toolsPath, path, gamename ) ) {
gamename = basegame;
shaderlist_findOrInstall( enginePath, toolsPath, path.c_str(), gamename );
shaderlist_findOrInstall( enginePath, toolsPath, path, gamename );
}
GlobalFileSystem().forEachArchive( AddShaderListFromArchiveCaller(), false, true );
@@ -1692,20 +1676,18 @@ void Shaders_Load(){
}
else{
globalOutputStream() << "No shaderlist.txt found: loading all shaders\n";
GlobalFileSystem().forEachFile( path.c_str(), g_shadersExtension, AddShaderFileCaller(), 1 );
GlobalFileSystem().forEachFile( path, g_shadersExtension, AddShaderFileCaller(), 1 );
}
}
else
{
GlobalFileSystem().forEachFile( path.c_str(), g_shadersExtension, AddShaderFileCaller(), 0 );
GlobalFileSystem().forEachFile( path, g_shadersExtension, AddShaderFileCaller(), 0 );
}
StringOutputStream shadername( 256 );
for( const CopiedString& sh : l_shaderfiles )
{
shadername << path.c_str() << sh;
LoadShaderFile( shadername.c_str() );
shadername.clear();
LoadShaderFile( shadername( path, sh ) );
}
}
+10 -16
View File
@@ -105,7 +105,7 @@ static void AddSlash( char *str ){
std::size_t n = strlen( str );
if ( n > 0 ) {
if ( str[n - 1] != '\\' && str[n - 1] != '/' ) {
globalWarningStream() << "WARNING: directory path does not end with separator: " << str << "\n";
globalWarningStream() << "WARNING: directory path does not end with separator: " << str << '\n';
strcat( str, "/" );
}
}
@@ -116,7 +116,7 @@ static void FixDOSName( char *src ){
return;
}
globalWarningStream() << "WARNING: invalid path separator '\\': " << src << "\n";
globalWarningStream() << "WARNING: invalid path separator '\\': " << src << '\n';
while ( *src )
{
@@ -130,16 +130,14 @@ static void FixDOSName( char *src ){
const _QERArchiveTable* GetArchiveTable( ArchiveModules& archiveModules, const char* ext ){
StringOutputStream tmp( 16 );
tmp << LowerCase( ext );
return archiveModules.findModule( tmp.c_str() );
return archiveModules.findModule( StringStream<16>( LowerCase( ext ) ) );
}
static void InitPakFile( ArchiveModules& archiveModules, const char *filename ){
const _QERArchiveTable* table = GetArchiveTable( archiveModules, path_get_extension( filename ) );
if ( table != 0 ) {
g_archives.push_back( archive_entry_t{ filename, table->m_pfnOpenArchive( filename ), true } );
globalOutputStream() << " pak file: " << filename << "\n";
globalOutputStream() << " pak file: " << filename << '\n';
}
}
@@ -287,15 +285,13 @@ void InitDirectory( const char* directory, ArchiveModules& archiveModules ){
g_numDirs++;
{
g_archives.push_back( archive_entry_t{ path, OpenArchive( path ), false } );
}
g_archives.push_back( archive_entry_t{ path, OpenArchive( path ), false } );
if ( g_bUsePak ) {
GDir* dir = g_dir_open( path, 0, 0 );
if ( dir != 0 ) {
globalOutputStream() << "vfs directory: " << path << "\n";
globalOutputStream() << "vfs directory: " << path << '\n';
const char* ignore_prefix = "";
const char* override_prefix = "";
@@ -347,9 +343,7 @@ void InitDirectory( const char* directory, ArchiveModules& archiveModules ){
AddSlash( g_strDirs[g_numDirs] );
g_numDirs++;
{
g_archives.push_back( archive_entry_t{ g_strDirs[g_numDirs - 1], OpenArchive( g_strDirs[g_numDirs - 1] ), false } );
}
g_archives.push_back( archive_entry_t{ g_strDirs[g_numDirs - 1], OpenArchive( g_strDirs[g_numDirs - 1] ), false } );
}
if ( ( ext == 0 ) || *( ++ext ) == '\0' || GetArchiveTable( archiveModules, ext ) == 0 ) {
@@ -388,7 +382,7 @@ void InitDirectory( const char* directory, ArchiveModules& archiveModules ){
}
else
{
globalErrorStream() << "vfs directory not found: " << path << "\n";
globalErrorStream() << "vfs directory not found: " << path << '\n';
}
}
}
@@ -436,7 +430,7 @@ int GetFileCount( const char *filename, int flag ){
}
ArchiveFile* OpenFile( const char* filename ){
ASSERT_MESSAGE( strchr( filename, '\\' ) == 0, "path contains invalid separator '\\': \"" << filename << "\"" );
ASSERT_MESSAGE( strchr( filename, '\\' ) == 0, "path contains invalid separator '\\': " << makeQuoted( filename ) );
for ( archive_entry_t& arch : g_archives )
{
ArchiveFile* file = arch.archive->openFile( filename );
@@ -449,7 +443,7 @@ ArchiveFile* OpenFile( const char* filename ){
}
ArchiveTextFile* OpenTextFile( const char* filename ){
ASSERT_MESSAGE( strchr( filename, '\\' ) == 0, "path contains invalid separator '\\': \"" << filename << "\"" );
ASSERT_MESSAGE( strchr( filename, '\\' ) == 0, "path contains invalid separator '\\': " << makeQuoted( filename ) );
for ( archive_entry_t& arch : g_archives )
{
ArchiveTextFile* file = arch.archive->openTextFile( filename );