diff --git a/bloom.cc b/bloom.cc index 6791373..d58b9a1 100644 --- a/bloom.cc +++ b/bloom.cc @@ -5,7 +5,7 @@ #include "odbg.hh" namespace { - static const std::string Name_( "BLOOOOM!" ); + static char const* const Name_( "BLOOOOM!" ); } #define PSTART() Globals::Profiler( ).start( Name_ ) @@ -28,8 +28,8 @@ T_BloomPass::T_BloomPass( Globals::ODbg( ).registerTexture( txBlur0_ , E_ODbgMode::HDR , "Bloom" ); for ( auto i = 0u ; i < BloomLevels ; i ++ ) { - rtBlur0_.push_back( T_RendertargetSetup( ).add( txBlur0_ , i ).create( ) ); - rtBlur1_.push_back( T_RendertargetSetup( ).add( txBlur1_ , i ).create( ) ); + rtBlur0_.add( T_RendertargetSetup( ).add( txBlur0_ , i ).create( ) ); + rtBlur1_.add( T_RendertargetSetup( ).add( txBlur1_ , i ).create( ) ); } auto& sm( Globals::Shaders( ) ); diff --git a/bloom.hh b/bloom.hh index 9038a83..c031fdd 100644 --- a/bloom.hh +++ b/bloom.hh @@ -31,7 +31,7 @@ struct T_BloomPass T_TextureSampler sampler_; T_Texture txBlur0_ , txBlur1_; - std::vector< T_Rendertarget > rtBlur0_ , rtBlur1_; + T_AutoArray< T_Rendertarget , BloomLevels > rtBlur0_ , rtBlur1_; float filterParams_[ 3 ]; float blurWeights_[ 4 ]; diff --git a/camera.cc b/camera.cc index eacb5d2..25d424b 100644 --- a/camera.cc +++ b/camera.cc @@ -6,10 +6,10 @@ /*= T_Camera =================================================================*/ void T_Camera::handleDND( - __rd__ ImVec2 const& move , - __rd__ const bool hasCtrl , - __rd__ const bool hasShift , - __rd__ const bool lmb // Left mouse button + ImVec2 const& move , + const bool hasCtrl , + const bool hasShift , + const bool lmb // Left mouse button ) { if ( move.x == 0 || move.y == 0 ) { @@ -35,9 +35,9 @@ void T_Camera::handleDND( } void T_Camera::handleWheel( - __rd__ const float wheel , - __rd__ const bool hasCtrl , - __rd__ const bool hasShift + const float wheel , + const bool hasCtrl , + const bool hasShift ) { const float delta( wheel * ( hasCtrl ? 1.f : .1f) ); diff --git a/camera.hh b/camera.hh index 895a66d..da8f658 100644 --- a/camera.hh +++ b/camera.hh @@ -23,15 +23,15 @@ struct T_Camera { update( ); } void handleDND( - __rd__ ImVec2 const& move , - __rd__ const bool hasCtrl , - __rd__ const bool hasShift , - __rd__ const bool lmb // Left mouse button + ImVec2 const& move , + const bool hasCtrl , + const bool hasShift , + const bool lmb // Left mouse button ); void handleWheel( - __rd__ const float wheel , - __rd__ const bool hasCtrl , - __rd__ const bool hasShift + const float wheel , + const bool hasCtrl , + const bool hasShift ); void makeUI( ); diff --git a/combine.cc b/combine.cc index a1262df..9b5efe5 100644 --- a/combine.cc +++ b/combine.cc @@ -6,7 +6,7 @@ #include "globals.hh" namespace { - static const std::string Name_( "Combine" ); + static char const* const Name_( "Combine" ); } #define PSTART() Globals::Profiler( ).start( Name_ ) @@ -14,8 +14,8 @@ namespace { T_CombinePass::T_CombinePass( - __rw__ T_Texture& image , - __rw__ T_Texture& bloom ) + T_Texture& image , + T_Texture& bloom ) : txImage_( image ) , txBloom_( bloom ) , txOutput_( image.width( ) , image.height( ) , E_TexType::RGBA8 ) , rtOutput_( T_RendertargetSetup( ).add( txOutput_ ).create( ) ) , diff --git a/combine.hh b/combine.hh index ce5dac5..a201fec 100644 --- a/combine.hh +++ b/combine.hh @@ -10,8 +10,8 @@ struct T_CombinePass T_CombinePass( T_CombinePass const& ) = delete; T_CombinePass( T_CombinePass&& ) = delete; - T_CombinePass( __rw__ T_Texture& image , - __rw__ T_Texture& bloom ); + T_CombinePass( T_Texture& image , + T_Texture& bloom ); void render( ); void makeUI( ); diff --git a/control.cc b/control.cc index bfd2e23..eda72d8 100644 --- a/control.cc +++ b/control.cc @@ -18,51 +18,47 @@ void cops::Execute( } T_Operations& T_Program::function( - std::string const& name , + T_String const& name , const uint32_t args ) { - const auto p( functions.find( name ) ); - if ( p == functions.end( ) ) { - return functions.emplace( name , T_Function{ name , args } ).first->second.operations; + T_Function* op( functions.get( name ) ); + if ( !op ) { + functions.add( T_Function{ name , args } ); + op = functions.get( name ); } - assert( p->second.arguments == args ); - return p->second.operations; + assert( op->arguments == args ); + return op->operations; } /*= X_OpFailure ==============================================================*/ X_OpFailure::X_OpFailure( - std::string const& source , + T_String const& source , uint32_t line , - std::string const& error ) noexcept + T_String&& error ) noexcept : std::exception( ) , source_( source ) , line_( line ) , - error_( error ) + error_( std::move( error ) ) { - std::ostringstream oss; - oss << "Program error (" << source << ", l. " << line << "): " << error; - fullMessage_ = oss.str( ); + ebcl::T_StringBuilder sb; + sb << "Program error (" << source << ", l. " << line << "): " << error + << '\0'; + fullMessage_ = std::move( sb ); } char const* X_OpFailure::what( ) const noexcept { - return fullMessage_.c_str( ); + return fullMessage_.data( ); } /*= T_Context ================================================================*/ T_Context& T_Context::store( - std::string const& name , + T_String const& name , const float value ) { - const auto vPos( varPos.find( name ) ); - if ( vPos == varPos.end( ) ) { - varPos.emplace( name , varValues.size( ) ); - varValues.push_back( value ); - } else { - varValues[ vPos->second ] = value; - } + vars.set( name , value ); return *this; } @@ -77,9 +73,15 @@ T_Op::~T_Op( ) { } X_OpFailure T_Op::error( - std::string const& message ) const noexcept + ebcl::T_StringBuilder& message ) const noexcept { - return X_OpFailure( source , line , message ); + return X_OpFailure( source , line , std::move( message ) ); +} + +X_OpFailure T_Op::error( + T_String const& message ) const noexcept +{ + return X_OpFailure( source , line , T_String( message ) ); } @@ -93,25 +95,27 @@ OPLoadConstant::OPLoadConstant( void OPLoadConstant::execute( T_Context& ctx ) const { - ctx.opStack.push_back( constant ); + ctx.opStack.add( constant ); } /*= OPLoadVariable ===========================================================*/ OPLoadVariable::OPLoadVariable( - std::string const& variable ) + T_String const& variable ) : T_Op( OP_LOAD_VARIABLE ) , variable( variable ) { } void OPLoadVariable::execute( T_Context& ctx ) const { - const auto vPos( ctx.varPos.find( variable ) ); - if ( vPos == ctx.varPos.end( ) ) { - throw error( "variable '" + variable + "' not found" ); + auto const* v( ctx.vars.get( variable ) ); + if ( !v ) { + ebcl::T_StringBuilder sb; + sb << "variable '" << variable << "' not found" << '\0'; + throw error( sb ); } - ctx.opStack.push_back( ctx.varValues[ vPos->second ] ); + ctx.opStack.add( *v ); } @@ -126,14 +130,14 @@ void OPLoadInput::execute( T_Context& ctx ) const { const auto i( Globals::Sync( ).inputPos( input.c_str( ) ) ); - ctx.opStack.push_back( Globals::Sync( ).inputs( )[ i ] ); + ctx.opStack.add( Globals::Sync( ).inputs( )[ i ] ); } /*= OPStoreVariable ==========================================================*/ OPStoreVariable::OPStoreVariable( - std::string const& variable ) + T_String const& variable ) : T_Op( OP_LOAD_VARIABLE ) , variable( variable ) { } @@ -144,8 +148,8 @@ void OPStoreVariable::execute( throw error( "stack is empty" ); } - ctx.store( variable , ctx.opStack.back( ) ); - ctx.opStack.pop_back( ); + ctx.store( variable , ctx.opStack.last( ) ); + ctx.opStack.removeLast( ); } @@ -157,9 +161,9 @@ void OPAdd::execute( if ( ctx.opStack.size( ) < 2 ) { throw error( "missing operands in stack" ); } - const float v( ctx.opStack.back( ) ); - ctx.opStack.pop_back( ); - ctx.opStack.back( ) += v; + const float v( ctx.opStack.last( ) ); + ctx.opStack.removeLast( ); + ctx.opStack.last( ) += v; } void OPMul::execute( @@ -168,9 +172,9 @@ void OPMul::execute( if ( ctx.opStack.size( ) < 2 ) { throw error( "missing operands in stack" ); } - const float v( ctx.opStack.back( ) ); - ctx.opStack.pop_back( ); - ctx.opStack.back( ) *= v; + const float v( ctx.opStack.last( ) ); + ctx.opStack.removeLast( ); + ctx.opStack.last( ) *= v; } void OPNeg::execute( @@ -179,16 +183,16 @@ void OPNeg::execute( if ( ctx.opStack.empty( ) ) { throw error( "missing operand in stack" ); } - ctx.opStack.back( ) = -ctx.opStack.back( ); + ctx.opStack.last( ) = -ctx.opStack.last( ); } void OPInv::execute( T_Context& ctx ) const { - if ( ctx.opStack.empty( ) || ctx.opStack.back( ) == 0 ) { + if ( ctx.opStack.empty( ) || ctx.opStack.last( ) == 0 ) { throw error( "missing operand in stack" ); } - ctx.opStack.back( ) = 1.0f / ctx.opStack.back( ); + ctx.opStack.last( ) = 1.0f / ctx.opStack.last( ); } @@ -202,12 +206,12 @@ void OPDup::execute( T_Context& ctx ) const { if ( ctx.opStack.size( ) <= stackIndex ) { - std::ostringstream oss; - oss << "stack does not have " << ( stackIndex + 1 ) + ebcl::T_StringBuilder sb; + sb << "stack does not have " << ( stackIndex + 1 ) << " items (only " << ctx.opStack.size( ) << ")"; - throw error( oss.str( ) ); + throw error( sb ); } - ctx.opStack.push_back( *( ctx.opStack.end( ) - stackIndex - 1 ) ); + ctx.opStack.add( *( ctx.opStack.end( ) - stackIndex - 1 ) ); } /*----------------------------------------------------------------------------*/ @@ -220,10 +224,9 @@ void OPXchg::execute( T_Context& ctx ) const { if ( ctx.opStack.size( ) <= stackIndex ) { - std::string err( "stack does not have " ); - err += stackIndex + 1; - err += " items"; - throw error( err ); + ebcl::T_StringBuilder sb( "stack does not have " ); + sb << ( stackIndex + 1 ) << " items"; + throw error( sb ); } if ( stackIndex ) { std::swap( *( ctx.opStack.end( ) - 1 ) , *( ctx.opStack.end( ) - stackIndex - 1 ) ); @@ -247,10 +250,9 @@ void OPSetUniform::execute( T_Context& ctx ) const { if ( count == 0 || ctx.opStack.size( ) < count + 2 ) { - std::string err( "stack does not have " ); - err += count + 2; - err += " items"; - throw error( err ); + ebcl::T_StringBuilder sb( "stack does not have " ); + sb << ( count + 2 ) << " items"; + throw error( sb ); } typedef void (*F_SetUniform_)( int , int , int , void* ); @@ -260,17 +262,17 @@ void OPSetUniform::execute( }; const F_SetUniform_ func{ *(F_SetUniform_*) funcs[ count + ( integer ? 4 : 0 ) - 1 ] }; - const GLuint program( ctx.opStack.back( ) ); - ctx.opStack.pop_back( ); - const GLuint uniform( ctx.opStack.back( ) ); - ctx.opStack.pop_back( ); + const GLuint program( ctx.opStack.last( ) ); + ctx.opStack.removeLast( ); + const GLuint uniform( ctx.opStack.last( ) ); + ctx.opStack.removeLast( ); if ( integer ) { int values[ count ]; auto i = count; while ( i != 0 ) { - values[ count - i ] = int( ctx.opStack.back( ) ); - ctx.opStack.pop_back( ); + values[ count - i ] = int( ctx.opStack.last( ) ); + ctx.opStack.removeLast( ); i --; } func( program , uniform , 1 , values ); @@ -278,8 +280,8 @@ void OPSetUniform::execute( float values[ count ]; auto i = count; while ( i != 0 ) { - values[ count - i ] = ctx.opStack.back( ); - ctx.opStack.pop_back( ); + values[ count - i ] = ctx.opStack.last( ); + ctx.opStack.removeLast( ); i --; } func( program , uniform , 1 , values ); @@ -388,32 +390,34 @@ void OPFullscreen::execute( /*= Flow control =============================================================*/ OPCall::OPCall( - std::string const& function ) + T_String const& function ) : T_Op( OP_CALL ) , function( function ) { } void OPCall::execute( T_Context& ctx ) const { - auto fp( ctx.program->functions.find( function ) ); - if ( fp == ctx.program->functions.end( ) ) { - throw error( "function '" + function + "' not found" ); + auto const* fp( ctx.program->functions.get( function ) ); + if ( !fp ) { + ebcl::T_StringBuilder sb( "function '" ); + sb << function << "' not found" << '\0'; + throw error( sb ); } - auto const& func( fp->second ); + auto const& func( *fp ); const auto ssz( ctx.opStack.size( ) ); if ( ssz < func.arguments ) { - std::string err; - err = "function '" + function + "' requires "; - err += func.arguments; - err += " argument"; - err += ( func.arguments > 1 ? "s" : "" ); - throw error( err ); + ebcl::T_StringBuilder sb( "function '" ); + sb << function << "' requires " << func.arguments << " argument" + << ( func.arguments > 1 ? "s" : "" ) << '\0'; + throw error( sb ); } Execute( func.operations , ctx ); if ( ctx.opStack.size( ) < ssz ) { - throw error( "function '" + function + "' ate the stack" ); + ebcl::T_StringBuilder sb( "function '" ); + sb << function << "' ate the stack" << '\0'; + throw error( sb ); } ctx.opStack.resize( ssz - func.arguments ); } diff --git a/control.hh b/control.hh index a66bac6..002824e 100644 --- a/control.hh +++ b/control.hh @@ -16,14 +16,13 @@ namespace cops { float const* time; T_SyncData const* sync; - std::vector< float > varValues; - std::map< std::string , uint32_t > varPos; + T_KeyValueTable< T_String , float > vars; - std::vector< float > opStack; + T_Array< float > opStack; T_Context& store( - __rd__ std::string const& name , - __rd__ const float value ); + T_String const& name , + const float value ); }; class X_OpFailure : public std::exception @@ -34,24 +33,24 @@ namespace cops { DEF_MOVE( X_OpFailure ); X_OpFailure( - __rd__ std::string const& source , - __rd__ uint32_t line , - __rd__ std::string const& error ) noexcept; + T_String const& source , + uint32_t line , + T_String&& error ) noexcept; - std::string const& source( ) const noexcept + T_String const& source( ) const noexcept { return source_; } uint32_t line( ) const noexcept { return line_; } - std::string const& error( ) const noexcept + T_String const& error( ) const noexcept { return error_; } char const* what( ) const noexcept override; private: - std::string source_; + T_String source_; uint32_t line_; - std::string error_; - std::string fullMessage_; + T_String error_; + T_String fullMessage_; }; /*--------------------------------------------------------------------*/ @@ -83,51 +82,53 @@ namespace cops { struct T_Op { explicit T_Op( - __rd__ const E_Op op ); + const E_Op op ); virtual ~T_Op( ) = 0; E_Op op( ) const noexcept { return op_; } virtual void execute( - __rw__ T_Context& ctx ) const = 0; + T_Context& ctx ) const = 0; - std::string source{}; + T_String source{}; uint32_t line{0}; protected: X_OpFailure error( - __rd__ std::string const& message ) const noexcept; + ebcl::T_StringBuilder& message ) const noexcept; + X_OpFailure error( + T_String const& message ) const noexcept; private: E_Op op_; }; - using P_Op = std::unique_ptr< T_Op >; - using T_Operations = std::vector< P_Op >; + using P_Op = T_OwnPtr< T_Op >; + using T_Operations = T_Array< P_Op >; template< typename T > inline T_Operations& operator <<( - __rw__ T_Operations& ops , - __rw__ T&& item ) + T_Operations& ops , + T&& item ) { - ops.emplace_back( new T( std::move( item ) ) ); + ops.add( NewOwned< T >( std::move( item ) ) ); return ops; } void Execute( - __rd__ T_Operations const& operations , - __rw__ T_Context& context ); + T_Operations const& operations , + T_Context& context ); /*--------------------------------------------------------------------*/ struct T_Function { - std::string name; + T_String name; uint32_t arguments; T_Operations operations; - T_Function( __rd__ std::string const& name , - __rd__ const uint32_t arguments ) + T_Function( T_String const& name , + const uint32_t arguments ) : name( name ) , arguments( arguments ) { } DEF_COPY( T_Function ); @@ -136,14 +137,20 @@ namespace cops { struct T_Program { - std::map< std::string , T_Function > functions; + T_ObjectTable< T_String , T_Function > functions; T_Operations main; - T_Operations& function( - __rd__ std::string const& name , - __rd__ const uint32_t args ); + T_Program( ) + : functions( []( T_Function const& f ) -> T_String { + return f.name; + } ) + { } - void execute( __rw__ T_Context& context ) + T_Operations& function( + T_String const& name , + const uint32_t args ); + + void execute( T_Context& context ) { context.program = this; Execute( main , context ); @@ -155,37 +162,37 @@ namespace cops { struct OPLoadConstant : public T_Op { explicit OPLoadConstant( - __rd__ const float constant ); + const float constant ); void execute( - __rw__ T_Context& ctx ) const override; + T_Context& ctx ) const override; float constant; }; struct OPLoadVariable : public T_Op { explicit OPLoadVariable( - __rd__ std::string const& variable ); + T_String const& variable ); void execute( - __rw__ T_Context& ctx ) const override; - std::string variable; + T_Context& ctx ) const override; + T_String variable; }; struct OPLoadInput : public T_Op { explicit OPLoadInput( - __rd__ std::string const& input ); + std::string const& input ); void execute( - __rw__ T_Context& ctx ) const override; + T_Context& ctx ) const override; std::string input; }; struct OPStoreVariable : public T_Op { explicit OPStoreVariable( - __rd__ std::string const& variable ); + T_String const& variable ); void execute( - __rw__ T_Context& ctx ) const override; - std::string variable; + T_Context& ctx ) const override; + T_String variable; }; /*--------------------------------------------------------------------*/ @@ -194,28 +201,28 @@ namespace cops { { OPAdd( ) : T_Op( OP_ADD ) {} void execute( - __rw__ T_Context& ctx ) const override; + T_Context& ctx ) const override; }; struct OPMul : public T_Op { OPMul( ) : T_Op( OP_MUL ) {} void execute( - __rw__ T_Context& ctx ) const override; + T_Context& ctx ) const override; }; struct OPNeg : public T_Op { OPNeg( ) : T_Op( OP_NEG ) {} void execute( - __rw__ T_Context& ctx ) const override; + T_Context& ctx ) const override; }; struct OPInv : public T_Op { OPInv( ) : T_Op( OP_INV ) {} void execute( - __rw__ T_Context& ctx ) const override; + T_Context& ctx ) const override; }; /*--------------------------------------------------------------------*/ @@ -224,7 +231,7 @@ namespace cops { { explicit OPDup( uint32_t stackIndex = 0 ); void execute( - __rw__ T_Context& ctx ) const override; + T_Context& ctx ) const override; uint32_t stackIndex; }; @@ -232,7 +239,7 @@ namespace cops { { explicit OPXchg( uint32_t stackIndex = 1 ); void execute( - __rw__ T_Context& ctx ) const override; + T_Context& ctx ) const override; uint32_t stackIndex; }; @@ -241,10 +248,10 @@ namespace cops { struct OPSetUniform : public T_Op { OPSetUniform( - __rd__ const uint32_t count , - __rd__ const bool integer ); + const uint32_t count , + const bool integer ); void execute( - __rw__ T_Context& ctx ) const override; + T_Context& ctx ) const override; uint32_t count; bool integer; @@ -253,9 +260,9 @@ namespace cops { struct OPUsePipeline : public T_Op { explicit OPUsePipeline( - __rd__ const uint32_t index ); + const uint32_t index ); void execute( - __rw__ T_Context& ctx ) const override; + T_Context& ctx ) const override; uint32_t pipeline; }; @@ -263,11 +270,11 @@ namespace cops { struct OPUseTexture : public T_Op { OPUseTexture( - __rd__ const uint32_t binding , - __rd__ const uint32_t texture , - __rd__ const uint32_t sampler = 0 ); + const uint32_t binding , + const uint32_t texture , + const uint32_t sampler = 0 ); void execute( - __rw__ T_Context& ctx ) const override; + T_Context& ctx ) const override; uint32_t binding; uint32_t texture; @@ -277,9 +284,9 @@ namespace cops { struct OPUseFramebuffer : public T_Op { explicit OPUseFramebuffer( - __rd__ const uint32_t framebuffer ); + const uint32_t framebuffer ); void execute( - __rw__ T_Context& ctx ) const override; + T_Context& ctx ) const override; uint32_t framebuffer; }; @@ -288,7 +295,7 @@ namespace cops { { OPSetViewport( ) : T_Op( OP_SET_VIEWPORT ) { } void execute( - __rw__ T_Context& ctx ) const override; + T_Context& ctx ) const override; }; /*--------------------------------------------------------------------*/ @@ -297,14 +304,14 @@ namespace cops { { OPClear( ) : T_Op( OP_CLEAR ) { } void execute( - __rw__ T_Context& ctx ) const override; + T_Context& ctx ) const override; }; struct OPFullscreen : public T_Op { OPFullscreen( ) : T_Op( OP_FULLSCREEN ) { } void execute( - __rw__ T_Context& ctx ) const override; + T_Context& ctx ) const override; }; /*--------------------------------------------------------------------*/ @@ -312,11 +319,11 @@ namespace cops { struct OPCall : public T_Op { explicit OPCall( - __rd__ std::string const& function ); + T_String const& function ); void execute( - __rw__ T_Context& ctx ) const override; + T_Context& ctx ) const override; - std::string function; + T_String function; }; } // namespace cops diff --git a/dof.cc b/dof.cc index a5165b0..123e5ac 100644 --- a/dof.cc +++ b/dof.cc @@ -7,7 +7,7 @@ namespace { - static const std::string Name_( "DoF" ); + static char const* const Name_( "DoF" ); } #define PSTART() Globals::Profiler( ).start( Name_ ) diff --git a/ebcl b/ebcl index 90048ad..3745631 160000 --- a/ebcl +++ b/ebcl @@ -1 +1 @@ -Subproject commit 90048ad3cc4bd8ce777672149a0c69eb9c8115e0 +Subproject commit 3745631e023e250c8d3b9267689fc5e596cc3e7a diff --git a/fxaa.cc b/fxaa.cc index dbf8cd6..93aeced 100644 --- a/fxaa.cc +++ b/fxaa.cc @@ -4,7 +4,7 @@ #include "globals.hh" namespace { - static const std::string Name_( "FXAA" ); + static char const* const Name_( "FXAA" ); } #define PSTART() Globals::Profiler( ).start( Name_ ) diff --git a/profiling.cc b/profiling.cc index 5089041..d59add4 100644 --- a/profiling.cc +++ b/profiling.cc @@ -27,8 +27,8 @@ void T_Profiler::endFrame( ) { const auto n( sections_.size( ) ); while ( secDurations_.size( ) < n ) { - secDurations_.push_back( 0 ); - secStarts_.push_back( 0 ); + secDurations_.add( 0 ); + secStarts_.add( 0 ); } for ( auto i = 0u ; i < n ; i ++ ) { @@ -48,16 +48,16 @@ void T_Profiler::endFrame( ) } void T_Profiler::start( - __rd__ std::string const& section ) + T_String const& section ) { const auto n( sections_.size( ) ); const auto pos( find( section ) ); if ( pos == n ) { - sections_.push_back( section ); - samples_.push_back( T_SamplesList_{ } ); - starts_.push_back( 0u ); - chain_.push_back( Invalid ); - parents_.push_back( Invalid ); + sections_.add( section ); + samples_.add( T_SamplesList_{ } ); + starts_.add( 0u ); + chain_.add( Invalid ); + parents_.add( Invalid ); } chain_[ pos ] = previous_; @@ -75,7 +75,7 @@ void T_Profiler::start( } void T_Profiler::end( - __rd__ std::string const& section ) + T_String const& section ) { const auto pos( find( section ) ); const auto n( sections_.size( ) ); @@ -91,7 +91,8 @@ void T_Profiler::end( auto& samples( samples_[ pos ] ); if ( samples.size( ) == 0 || ( samples.size( ) < History && samples[ 0 ].nSamples == Samples ) ) { - samples.insert( samples.begin( ) , T_ProfilerSamples{ 0 , 0 } ); + samples.insert( 0 , T_ProfilerSamples{ 0 , 0 } ); + } else if ( samples.size( ) == History && samples[ 0 ].nSamples == Samples ) { for ( auto i = 1u ; i < History ; i ++ ) { samples[ i ] = samples[ i - 1 ]; @@ -127,7 +128,7 @@ void T_Profiler::makeUI( ) float angle( 0 ); for ( auto i = 0u ; i < n ; i ++ ) { if ( displayed_.size( ) == i ) { - displayed_.push_back( true ); + displayed_.add( true ); } angle = fmod( angle + 137 , 360 ); ImVec4 color( 0 , 0 , 0 , 1 ); @@ -135,11 +136,11 @@ void T_Profiler::makeUI( ) color.x , color.y , color.z ); ImGui::PushStyleColor( ImGuiCol_Text , color ); - std::ostringstream str; - str << sections_[ i ] << " (" + ebcl::T_StringBuilder sb; + sb << sections_[ i ] << " (" << int( round( secDurations_[ i ] ) ) - << "ms)"; - ImGui::Checkbox( str.str( ).c_str( ) , (bool*) &displayed_[ i ] ); + << "ms)" << '\0'; + ImGui::Checkbox( sb.data( ) , (bool*) &displayed_[ i ] ); ImGui::PopStyleColor( ); } ImGui::EndChild( ); @@ -208,7 +209,7 @@ void T_Profiler::makeUI( ) } float T_Profiler::computeDuration( - __rd__ const uint32_t section ) const + const uint32_t section ) const { auto const& samples( samples_[ section ] ); float total = 0; @@ -221,7 +222,7 @@ float T_Profiler::computeDuration( } uint32_t T_Profiler::find( - __rd__ std::string const& section ) const + T_String const& section ) const { const auto n( sections_.size( ) ); auto pos( 0u ); diff --git a/profiling.hh b/profiling.hh index 63a42bf..c4ff1df 100644 --- a/profiling.hh +++ b/profiling.hh @@ -18,46 +18,46 @@ struct T_Profiler void clear( ); void startFrame( ); - void start( __rd__ std::string const& section ); - void end( __rd__ std::string const& section ); + void start( T_String const& section ); + void end( T_String const& section ); void endFrame( ); uint32_t sections( ) const noexcept { return sections_.size( ); } - std::string const& nameOf( - __rd__ const uint32_t section ) const + T_String const& nameOf( + const uint32_t section ) const { return sections_[ section ]; } - float durationOf( __rd__ const uint32_t section ) const + float durationOf( const uint32_t section ) const { return secDurations_[ section ]; } - float startOf( __rd__ const uint32_t section ) const + float startOf( const uint32_t section ) const { return secStarts_[ section ]; } void makeUI( ); bool& uiEnabled( ) { return uiEnabled_; } private: - using T_SamplesList_ = std::vector< T_ProfilerSamples >; - using T_Data_ = std::vector< T_SamplesList_ >; + using T_SamplesList_ = T_Array< T_ProfilerSamples >; + using T_Data_ = T_Array< T_SamplesList_ >; - uint32_t find( __rd__ std::string const& section ) const; + uint32_t find( T_String const& section ) const; float computeDuration( - __rd__ const uint32_t section ) const; + const uint32_t section ) const; uint32_t previous_; uint32_t current_; - std::vector< std::string > sections_; - std::vector< uint32_t > chain_; - std::vector< uint32_t > parents_; + T_Array< T_String > sections_; + T_Array< uint32_t > chain_; + T_Array< uint32_t > parents_; T_Data_ samples_; - std::vector< uint64_t > starts_; + T_Array< uint64_t > starts_; - std::vector< float > secDurations_; - std::vector< float > secStarts_; + T_Array< float > secDurations_; + T_Array< float > secStarts_; bool uiEnabled_ = false; - std::vector< int > displayed_; + T_Array< int > displayed_; }; diff --git a/raymarcher.cc b/raymarcher.cc index 91c445d..d57be17 100644 --- a/raymarcher.cc +++ b/raymarcher.cc @@ -6,7 +6,7 @@ namespace { - static const std::string Name_( "Raymarcher" ); + static char const* const Name_( "Raymarcher" ); } #define PSTART() Globals::Profiler( ).start( Name_ )