Progress on de-std::-ifying the code

This commit is contained in:
Emmanuel BENOîT 2017-11-03 09:08:19 +01:00
parent 792c09b06f
commit 69d80c910a
18 changed files with 465 additions and 423 deletions

View file

@ -9,8 +9,8 @@ using namespace cops;
/*= Command execution ========================================================*/ /*= Command execution ========================================================*/
void cops::Execute( void cops::Execute(
__rd__ T_Operations const& operations , T_Operations const& operations ,
__rw__ T_Context& context ) T_Context& context )
{ {
for ( auto const& op : operations ) { for ( auto const& op : operations ) {
op->execute( context ); op->execute( context );
@ -18,8 +18,8 @@ void cops::Execute(
} }
T_Operations& T_Program::function( T_Operations& T_Program::function(
__rd__ std::string const& name , std::string const& name ,
__rd__ const uint32_t args ) const uint32_t args )
{ {
const auto p( functions.find( name ) ); const auto p( functions.find( name ) );
if ( p == functions.end( ) ) { if ( p == functions.end( ) ) {
@ -33,9 +33,9 @@ T_Operations& T_Program::function(
/*= X_OpFailure ==============================================================*/ /*= X_OpFailure ==============================================================*/
X_OpFailure::X_OpFailure( X_OpFailure::X_OpFailure(
__rd__ std::string const& source , std::string const& source ,
__rd__ uint32_t line , uint32_t line ,
__rd__ std::string const& error ) noexcept std::string const& error ) noexcept
: std::exception( ) , source_( source ) , line_( line ) , : std::exception( ) , source_( source ) , line_( line ) ,
error_( error ) error_( error )
{ {
@ -53,8 +53,8 @@ char const* X_OpFailure::what( ) const noexcept
/*= T_Context ================================================================*/ /*= T_Context ================================================================*/
T_Context& T_Context::store( T_Context& T_Context::store(
__rd__ std::string const& name , std::string const& name ,
__rd__ const float value ) const float value )
{ {
const auto vPos( varPos.find( name ) ); const auto vPos( varPos.find( name ) );
if ( vPos == varPos.end( ) ) { if ( vPos == varPos.end( ) ) {
@ -69,7 +69,7 @@ T_Context& T_Context::store(
/*= T_Op =====================================================================*/ /*= T_Op =====================================================================*/
T_Op::T_Op( __rd__ const E_Op op ) T_Op::T_Op( const E_Op op )
: op_( op ) : op_( op )
{ } { }
@ -77,7 +77,7 @@ T_Op::~T_Op( ) { }
X_OpFailure T_Op::error( X_OpFailure T_Op::error(
__rd__ std::string const& message ) const noexcept std::string const& message ) const noexcept
{ {
return X_OpFailure( source , line , message ); return X_OpFailure( source , line , message );
} }
@ -86,12 +86,12 @@ X_OpFailure T_Op::error(
/*= OPLoadConstant ===========================================================*/ /*= OPLoadConstant ===========================================================*/
OPLoadConstant::OPLoadConstant( OPLoadConstant::OPLoadConstant(
__rd__ const float constant ) const float constant )
: T_Op( OP_LOAD_CONSTANT ) , constant( constant ) : T_Op( OP_LOAD_CONSTANT ) , constant( constant )
{ } { }
void OPLoadConstant::execute( void OPLoadConstant::execute(
__rw__ T_Context& ctx ) const T_Context& ctx ) const
{ {
ctx.opStack.push_back( constant ); ctx.opStack.push_back( constant );
} }
@ -100,12 +100,12 @@ void OPLoadConstant::execute(
/*= OPLoadVariable ===========================================================*/ /*= OPLoadVariable ===========================================================*/
OPLoadVariable::OPLoadVariable( OPLoadVariable::OPLoadVariable(
__rd__ std::string const& variable ) std::string const& variable )
: T_Op( OP_LOAD_VARIABLE ) , variable( variable ) : T_Op( OP_LOAD_VARIABLE ) , variable( variable )
{ } { }
void OPLoadVariable::execute( void OPLoadVariable::execute(
__rw__ T_Context& ctx ) const T_Context& ctx ) const
{ {
const auto vPos( ctx.varPos.find( variable ) ); const auto vPos( ctx.varPos.find( variable ) );
if ( vPos == ctx.varPos.end( ) ) { if ( vPos == ctx.varPos.end( ) ) {
@ -118,14 +118,14 @@ void OPLoadVariable::execute(
/*= OPLoadInput ==============================================================*/ /*= OPLoadInput ==============================================================*/
OPLoadInput::OPLoadInput( OPLoadInput::OPLoadInput(
__rd__ std::string const& input ) std::string const& input )
: T_Op( OP_LOAD_VARIABLE ) , input( input ) : T_Op( OP_LOAD_VARIABLE ) , input( input )
{ } { }
void OPLoadInput::execute( void OPLoadInput::execute(
__rw__ T_Context& ctx ) const T_Context& ctx ) const
{ {
const auto i( Globals::Sync( ).inputPos( input ) ); const auto i( Globals::Sync( ).inputPos( input.c_str( ) ) );
ctx.opStack.push_back( Globals::Sync( ).inputs( )[ i ] ); ctx.opStack.push_back( Globals::Sync( ).inputs( )[ i ] );
} }
@ -133,12 +133,12 @@ void OPLoadInput::execute(
/*= OPStoreVariable ==========================================================*/ /*= OPStoreVariable ==========================================================*/
OPStoreVariable::OPStoreVariable( OPStoreVariable::OPStoreVariable(
__rd__ std::string const& variable ) std::string const& variable )
: T_Op( OP_LOAD_VARIABLE ) , variable( variable ) : T_Op( OP_LOAD_VARIABLE ) , variable( variable )
{ } { }
void OPStoreVariable::execute( void OPStoreVariable::execute(
__rw__ T_Context& ctx ) const T_Context& ctx ) const
{ {
if ( ctx.opStack.empty( ) ) { if ( ctx.opStack.empty( ) ) {
throw error( "stack is empty" ); throw error( "stack is empty" );
@ -152,7 +152,7 @@ void OPStoreVariable::execute(
/*= Arithmetic operators =====================================================*/ /*= Arithmetic operators =====================================================*/
void OPAdd::execute( void OPAdd::execute(
__rw__ T_Context& ctx ) const T_Context& ctx ) const
{ {
if ( ctx.opStack.size( ) < 2 ) { if ( ctx.opStack.size( ) < 2 ) {
throw error( "missing operands in stack" ); throw error( "missing operands in stack" );
@ -163,7 +163,7 @@ void OPAdd::execute(
} }
void OPMul::execute( void OPMul::execute(
__rw__ T_Context& ctx ) const T_Context& ctx ) const
{ {
if ( ctx.opStack.size( ) < 2 ) { if ( ctx.opStack.size( ) < 2 ) {
throw error( "missing operands in stack" ); throw error( "missing operands in stack" );
@ -174,7 +174,7 @@ void OPMul::execute(
} }
void OPNeg::execute( void OPNeg::execute(
__rw__ T_Context& ctx ) const T_Context& ctx ) const
{ {
if ( ctx.opStack.empty( ) ) { if ( ctx.opStack.empty( ) ) {
throw error( "missing operand in stack" ); throw error( "missing operand in stack" );
@ -183,7 +183,7 @@ void OPNeg::execute(
} }
void OPInv::execute( void OPInv::execute(
__rw__ T_Context& ctx ) const T_Context& ctx ) const
{ {
if ( ctx.opStack.empty( ) || ctx.opStack.back( ) == 0 ) { if ( ctx.opStack.empty( ) || ctx.opStack.back( ) == 0 ) {
throw error( "missing operand in stack" ); throw error( "missing operand in stack" );
@ -194,12 +194,12 @@ void OPInv::execute(
/*= Stack operations =========================================================*/ /*= Stack operations =========================================================*/
OPDup::OPDup( __rd__ const uint32_t stackIndex ) OPDup::OPDup( const uint32_t stackIndex )
: T_Op( OP_DUP ) , stackIndex( stackIndex ) : T_Op( OP_DUP ) , stackIndex( stackIndex )
{ } { }
void OPDup::execute( void OPDup::execute(
__rw__ T_Context& ctx ) const T_Context& ctx ) const
{ {
if ( ctx.opStack.size( ) <= stackIndex ) { if ( ctx.opStack.size( ) <= stackIndex ) {
std::ostringstream oss; std::ostringstream oss;
@ -212,12 +212,12 @@ void OPDup::execute(
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
OPXchg::OPXchg( __rd__ const uint32_t stackIndex ) OPXchg::OPXchg( const uint32_t stackIndex )
: T_Op( OP_XCHG ) , stackIndex( stackIndex ) : T_Op( OP_XCHG ) , stackIndex( stackIndex )
{ } { }
void OPXchg::execute( void OPXchg::execute(
__rw__ T_Context& ctx ) const T_Context& ctx ) const
{ {
if ( ctx.opStack.size( ) <= stackIndex ) { if ( ctx.opStack.size( ) <= stackIndex ) {
std::string err( "stack does not have " ); std::string err( "stack does not have " );
@ -238,13 +238,13 @@ void OPXchg::execute(
// or, you know, a program name // or, you know, a program name
OPSetUniform::OPSetUniform( OPSetUniform::OPSetUniform(
__rd__ const uint32_t count , const uint32_t count ,
__rd__ const bool integer ) const bool integer )
: T_Op( OP_SET_UNIFORM ) , count( count ) , integer( integer ) : T_Op( OP_SET_UNIFORM ) , count( count ) , integer( integer )
{ } { }
void OPSetUniform::execute( void OPSetUniform::execute(
__rw__ T_Context& ctx ) const T_Context& ctx ) const
{ {
if ( count == 0 || ctx.opStack.size( ) < count + 2 ) { if ( count == 0 || ctx.opStack.size( ) < count + 2 ) {
std::string err( "stack does not have " ); std::string err( "stack does not have " );
@ -294,12 +294,12 @@ void OPSetUniform::execute(
// or, you know, a program name // or, you know, a program name
OPUsePipeline::OPUsePipeline( OPUsePipeline::OPUsePipeline(
__rd__ const uint32_t index ) const uint32_t index )
: T_Op( OP_USE_PIPELINE ) , pipeline( index ) : T_Op( OP_USE_PIPELINE ) , pipeline( index )
{ } { }
void OPUsePipeline::execute( void OPUsePipeline::execute(
__rw__ T_Context& ) const T_Context& ) const
{ {
glBindProgramPipeline( pipeline ); glBindProgramPipeline( pipeline );
} }
@ -311,15 +311,15 @@ void OPUsePipeline::execute(
// texture & sampler identifiers should be entries in a table // texture & sampler identifiers should be entries in a table
OPUseTexture::OPUseTexture( OPUseTexture::OPUseTexture(
__rd__ const uint32_t binding , const uint32_t binding ,
__rd__ const uint32_t texture , const uint32_t texture ,
__rd__ const uint32_t sampler ) const uint32_t sampler )
: T_Op( OP_USE_TEXTURE ) , binding( binding ) , : T_Op( OP_USE_TEXTURE ) , binding( binding ) ,
texture( texture ) , sampler( sampler ) texture( texture ) , sampler( sampler )
{ } { }
void OPUseTexture::execute( void OPUseTexture::execute(
__rw__ T_Context& ) const T_Context& ) const
{ {
glBindTextureUnit( binding , texture ); glBindTextureUnit( binding , texture );
glBindSampler( binding , sampler ); glBindSampler( binding , sampler );
@ -332,12 +332,12 @@ void OPUseTexture::execute(
// framebuffer identifier should be an entry in a table // framebuffer identifier should be an entry in a table
OPUseFramebuffer::OPUseFramebuffer( OPUseFramebuffer::OPUseFramebuffer(
__rd__ const uint32_t framebuffer ) const uint32_t framebuffer )
: T_Op( OP_USE_FRAMEBUFFER ) , framebuffer( framebuffer ) : T_Op( OP_USE_FRAMEBUFFER ) , framebuffer( framebuffer )
{ } { }
void OPUseFramebuffer::execute( void OPUseFramebuffer::execute(
__rw__ T_Context& ) const T_Context& ) const
{ {
glBindFramebuffer( GL_FRAMEBUFFER , framebuffer ); glBindFramebuffer( GL_FRAMEBUFFER , framebuffer );
} }
@ -346,7 +346,7 @@ void OPUseFramebuffer::execute(
/*= OPSetViewport ============================================================*/ /*= OPSetViewport ============================================================*/
void OPSetViewport::execute( void OPSetViewport::execute(
__rw__ T_Context& ctx ) const T_Context& ctx ) const
{ {
if ( ctx.opStack.size( ) < 4 ) { if ( ctx.opStack.size( ) < 4 ) {
throw error( "stack does not have 4 items" ); throw error( "stack does not have 4 items" );
@ -363,7 +363,7 @@ void OPSetViewport::execute(
/*= Draw commands ============================================================*/ /*= Draw commands ============================================================*/
void OPClear::execute( void OPClear::execute(
__rw__ T_Context& ctx ) const T_Context& ctx ) const
{ {
if ( ctx.opStack.size( ) < 4 ) { if ( ctx.opStack.size( ) < 4 ) {
throw error( "stack does not have 4 items" ); throw error( "stack does not have 4 items" );
@ -378,7 +378,7 @@ void OPClear::execute(
} }
void OPFullscreen::execute( void OPFullscreen::execute(
__rw__ T_Context& ) const T_Context& ) const
{ {
glBindVertexArray( 0 ); glBindVertexArray( 0 );
glDrawArrays( GL_TRIANGLE_STRIP , 0 , 4 ); glDrawArrays( GL_TRIANGLE_STRIP , 0 , 4 );
@ -388,12 +388,12 @@ void OPFullscreen::execute(
/*= Flow control =============================================================*/ /*= Flow control =============================================================*/
OPCall::OPCall( OPCall::OPCall(
__rd__ std::string const& function ) std::string const& function )
: T_Op( OP_CALL ) , function( function ) : T_Op( OP_CALL ) , function( function )
{ } { }
void OPCall::execute( void OPCall::execute(
__rw__ T_Context& ctx ) const T_Context& ctx ) const
{ {
auto fp( ctx.program->functions.find( function ) ); auto fp( ctx.program->functions.find( function ) );
if ( fp == ctx.program->functions.end( ) ) { if ( fp == ctx.program->functions.end( ) ) {

2
ebcl

@ -1 +1 @@
Subproject commit 9e753565090c7a7bc8285f72f24af797ebd0a19e Subproject commit 90048ad3cc4bd8ce777672149a0c69eb9c8115e0

View file

@ -23,6 +23,7 @@
#include <set> #include <set>
#include <regex> #include <regex>
#include <unordered_map> #include <unordered_map>
using std::swap;
// ImGui // ImGui
#include <imgui.h> #include <imgui.h>
@ -34,6 +35,22 @@
// PicoJSON // PicoJSON
#include <picojson.h> #include <picojson.h>
// EBCL
#include <ebcl/Arrays.hh>
#include <ebcl/Strings.hh>
#include <ebcl/HashTables.hh>
using ebcl::T_OwnPtr;
using ebcl::NewOwned;
using ebcl::T_SharedPtr;
using ebcl::NewShared;
using ebcl::T_Array;
using ebcl::T_AutoArray;
using ebcl::T_String;
using ebcl::T_HashIndex;
using ebcl::T_ObjectTable;
using ebcl::T_KeyValueTable;
// Silly decoration macros I use everywhere // Silly decoration macros I use everywhere
#define __rd__ #define __rd__
#define __wr__ #define __wr__

View file

@ -10,32 +10,32 @@
#include "sync.hh" #include "sync.hh"
std::unique_ptr< T_FilesWatcher > Globals::watcher_; T_OwnPtr< T_FilesWatcher > Globals::watcher_;
std::unique_ptr< T_Window > Globals::window_; T_OwnPtr< T_Window > Globals::window_;
std::unique_ptr< T_Profiler > Globals::profiler_; T_OwnPtr< T_Profiler > Globals::profiler_;
std::unique_ptr< T_SyncManager > Globals::sync_; T_OwnPtr< T_SyncManager > Globals::sync_;
std::unique_ptr< T_TextureManager > Globals::textures_; T_OwnPtr< T_TextureManager > Globals::textures_;
std::unique_ptr< T_ShaderManager > Globals::shaders_; T_OwnPtr< T_ShaderManager > Globals::shaders_;
std::unique_ptr< T_OutputDebugger > Globals::odbg_; T_OwnPtr< T_OutputDebugger > Globals::odbg_;
void Globals::Init( ) void Globals::Init( )
{ {
watcher_ = std::make_unique< T_FilesWatcher >( ); watcher_ = NewOwned< T_FilesWatcher >( );
window_ = std::make_unique< T_Window >( ); window_ = NewOwned< T_Window >( );
profiler_ = std::make_unique< T_Profiler >( ); profiler_ = NewOwned< T_Profiler >( );
sync_ = std::make_unique< T_SyncManager >( ); sync_ = NewOwned< T_SyncManager >( );
textures_ = std::make_unique< T_TextureManager >( ); textures_ = NewOwned< T_TextureManager >( );
shaders_ = std::make_unique< T_ShaderManager >( ); shaders_ = NewOwned< T_ShaderManager >( );
odbg_ = std::make_unique< T_OutputDebugger >( ); odbg_ = NewOwned< T_OutputDebugger >( );
} }
void Globals::Shutdown( ) void Globals::Shutdown( )
{ {
odbg_.reset( ); odbg_.clear( );
shaders_.reset( ); shaders_.clear( );
textures_.reset( ); textures_.clear( );
profiler_.reset( ); profiler_.clear( );
window_.reset( ); window_.clear( );
watcher_.reset( ); watcher_.clear( );
} }

View file

@ -27,11 +27,11 @@ struct Globals
static T_OutputDebugger& ODbg( ) { return *odbg_; } static T_OutputDebugger& ODbg( ) { return *odbg_; }
private: private:
static std::unique_ptr< T_FilesWatcher > watcher_; static ebcl::T_OwnPtr< T_FilesWatcher > watcher_;
static std::unique_ptr< T_Window > window_; static ebcl::T_OwnPtr< T_Window > window_;
static std::unique_ptr< T_Profiler > profiler_; static ebcl::T_OwnPtr< T_Profiler > profiler_;
static std::unique_ptr< T_SyncManager > sync_; static ebcl::T_OwnPtr< T_SyncManager > sync_;
static std::unique_ptr< T_ShaderManager > shaders_; static ebcl::T_OwnPtr< T_ShaderManager > shaders_;
static std::unique_ptr< T_TextureManager > textures_; static ebcl::T_OwnPtr< T_TextureManager > textures_;
static std::unique_ptr< T_OutputDebugger > odbg_; static ebcl::T_OwnPtr< T_OutputDebugger > odbg_;
}; };

44
main.cc
View file

@ -8,6 +8,8 @@
#include "shaders.hh" #include "shaders.hh"
#include "odbg.hh" #include "odbg.hh"
using ebcl::T_Optional;
/*= T_Main ===================================================================*/ /*= T_Main ===================================================================*/
@ -30,7 +32,7 @@ struct T_Main
ImVec2 prevSize; ImVec2 prevSize;
bool demoCtrl_ = false; bool demoCtrl_ = false;
std::unique_ptr< T_Demo > demo; T_Optional< T_Demo > demo;
void initDemo( ); void initDemo( );
@ -52,7 +54,7 @@ void T_Main::mainLoop( )
{ {
auto& p( Globals::Profiler( ) ); auto& p( Globals::Profiler( ) );
while ( !done ) { while ( !done ) {
if ( demo ) { if ( demo.present( ) ) {
auto const& dspSize( ImGui::GetIO( ).DisplaySize ); auto const& dspSize( ImGui::GetIO( ).DisplaySize );
if ( prevSize.x != dspSize.x || prevSize.y != dspSize.y ) { if ( prevSize.x != dspSize.x || prevSize.y != dspSize.y ) {
stopResize = ResizeDelay; stopResize = ResizeDelay;
@ -62,10 +64,10 @@ void T_Main::mainLoop( )
if ( stopResize > 0 ) { if ( stopResize > 0 ) {
stopResize --; stopResize --;
if ( stopResize == 0 ) { if ( stopResize == 0 ) {
demo.reset( ); demo.clear( );
} }
} }
if ( !demo ) { if ( !demo.present( ) ) {
initDemo( ); initDemo( );
} }
@ -90,7 +92,7 @@ void T_Main::mainLoop( )
T_Main::~T_Main( ) T_Main::~T_Main( )
{ {
demo.reset( ); demo.clear( );
Globals::Shutdown( ); Globals::Shutdown( );
} }
@ -98,18 +100,18 @@ T_Main::~T_Main( )
void T_Main::initDemo( ) void T_Main::initDemo( )
{ {
assert( !demo ); assert( !demo.present( ) );
auto const& dspSize( ImGui::GetIO( ).DisplaySize ); auto const& dspSize( ImGui::GetIO( ).DisplaySize );
if ( dspSize.x < 0 || dspSize.y < 0 ) { if ( dspSize.x < 0 || dspSize.y < 0 ) {
return; return;
} }
printf( "init w/ dspsize %dx%d\n" , int( dspSize.x ) , int( dspSize.y ) ); printf( "init w/ dspsize %dx%d\n" , int( dspSize.x ) , int( dspSize.y ) );
demo = std::make_unique< T_Demo >( dspSize.x , dspSize.y ); demo.setNew( dspSize.x , dspSize.y );
if ( demo->initialise( ) ) { if ( ((T_Demo&)demo).initialise( ) ) {
Globals::Profiler( ).clear( ); Globals::Profiler( ).clear( );
} else { } else {
demo.reset( ); demo.clear( );
} }
} }
@ -153,8 +155,8 @@ void T_Main::handleCapture( )
ImGui::SetMouseCursor( ImGuiMouseCursor_Arrow ); ImGui::SetMouseCursor( ImGuiMouseCursor_Arrow );
} else if ( capture ) { } else if ( capture ) {
ImGui::SetMouseCursor( ImGuiMouseCursor_Move ); ImGui::SetMouseCursor( ImGuiMouseCursor_Move );
if ( demo ) { if ( demo.present( ) ) {
demo->handleDND( mouseMove , ctrl , shift , lmb ); demo.target( )->handleDND( mouseMove , ctrl , shift , lmb );
} }
} else if ( appCanGrab && mb ) { } else if ( appCanGrab && mb ) {
capture = true; capture = true;
@ -164,8 +166,8 @@ void T_Main::handleCapture( )
ImGui::SetMouseCursor( ImGuiMouseCursor_Move ); ImGui::SetMouseCursor( ImGuiMouseCursor_Move );
} }
if ( ( appCanGrab || capture ) && io.MouseWheel && demo ) { if ( ( appCanGrab || capture ) && io.MouseWheel && demo.present( ) ) {
demo->handleWheel( io.MouseWheel , ctrl , shift ); demo.target( )->handleWheel( io.MouseWheel , ctrl , shift );
} }
} }
@ -181,25 +183,25 @@ void T_Main::makeUI( )
ImGui::Checkbox( "Profiler" , &Globals::Profiler( ).uiEnabled( ) ); ImGui::Checkbox( "Profiler" , &Globals::Profiler( ).uiEnabled( ) );
ImGui::Checkbox( "Shaders" , &Globals::Shaders( ).uiEnabled( ) ); ImGui::Checkbox( "Shaders" , &Globals::Shaders( ).uiEnabled( ) );
if ( demo ) { if ( demo.present( ) ) {
ImGui::Separator( ); ImGui::Separator( );
auto& sync( Globals::Sync( ) ); auto& sync( Globals::Sync( ) );
const float duration( sync.duration( ) ); const float duration( sync.duration( ) );
float time( sync.time( ) ); float time( sync.time( ) );
if ( ImGui::SliderFloat( "" , &time , 0 , duration , "%.1fs" ) ) { if ( ImGui::SliderFloat( "" , &time , 0 , duration , "%.1fs" ) ) {
sync.setTime( time ); sync.setTime( time );
demo->playing = demo->playing && ! sync.finished( ); demo.target( )->playing = demo.target( )->playing && ! sync.finished( );
} }
ImGui::SameLine( ); ImGui::SameLine( );
if ( ImGui::Button( demo->playing ? "Stop" : "Play" ) ) { if ( ImGui::Button( demo.target( )->playing ? "Stop" : "Play" ) ) {
demo->playing = !demo->playing; demo.target( )->playing = !demo.target( )->playing;
} }
} }
ImGui::End( ); ImGui::End( );
if ( demo && demoCtrl_ ) { if ( demo.present( ) && demoCtrl_ ) {
demo->makeUI( ); demo.target( )->makeUI( );
} }
Globals::Profiler( ).makeUI( ); Globals::Profiler( ).makeUI( );
@ -209,9 +211,9 @@ void T_Main::makeUI( )
void T_Main::render( ) void T_Main::render( )
{ {
if ( demo ) { if ( demo.present( ) ) {
Globals::Profiler( ).start( "Render" ); Globals::Profiler( ).start( "Render" );
demo->render( ); demo.target( )->render( );
glFinish( ); Globals::Profiler( ).end( "Render" ); glFinish( ); Globals::Profiler( ).end( "Render" );
Globals::Profiler( ).start( "Debug" ); Globals::Profiler( ).start( "Debug" );

View file

@ -14,6 +14,7 @@ namespace {
T_OutputDebugger::T_OutputDebugger( ) T_OutputDebugger::T_OutputDebugger( )
: selectorItems_( nullptr ) : selectorItems_( nullptr )
{ {
using namespace ebcl;
registerSubmode( E_ODbgMode::LDR , "Colors" , "copy" ); registerSubmode( E_ODbgMode::LDR , "Colors" , "copy" );
registerSubmode( E_ODbgMode::LDR_ALPHA , "Colors" , "copy" ); registerSubmode( E_ODbgMode::LDR_ALPHA , "Colors" , "copy" );
registerSubmode( E_ODbgMode::LDR_ALPHA , "Alpha channel" , "alpha-channel" ); registerSubmode( E_ODbgMode::LDR_ALPHA , "Alpha channel" , "alpha-channel" );
@ -133,7 +134,7 @@ void T_OutputDebugger::registerSubmode(
__rd__ F_SubmodeSetup setup ) __rd__ F_SubmodeSetup setup )
{ {
assert( mode != E_ODbgMode::__COUNT__ ); assert( mode != E_ODbgMode::__COUNT__ );
submodes_[ int( mode ) ].push_back( T_Submode_{ submodes_[ int( mode ) ].add( T_Submode_{
name , name ,
Globals::Shaders( ).pipeline({ Globals::Shaders( ).pipeline({
"fullscreen.v.glsl" , "debug/" + shader + ".glsl" }) , "fullscreen.v.glsl" , "debug/" + shader + ".glsl" }) ,
@ -180,7 +181,7 @@ int32_t T_OutputDebugger::registerTexture(
return i; return i;
} }
} }
outputs_.push_back( T_Texture_{ id , levels , mode , name , 0 , 0 } ); outputs_.add( T_Texture_{ id , levels , mode , name , 0 , 0 } );
return n; return n;
} }
@ -211,12 +212,12 @@ void T_OutputDebugger::makeSelectorItems( )
{ {
size_t requiredSize = 2 + NormalOutput_.length( ); size_t requiredSize = 2 + NormalOutput_.length( );
uint32_t nrLeft = nRegistered_, i = 0; uint32_t nrLeft = nRegistered_, i = 0;
selectorMapping_.push_back( -1 ); selectorMapping_.add( -1 );
while ( nrLeft ) { while ( nrLeft ) {
assert( i < outputs_.size( ) ); assert( i < outputs_.size( ) );
if ( outputs_[ i ].id != 0 ) { if ( outputs_[ i ].id != 0 ) {
requiredSize += 1 + outputs_[ i ].name.length( ); requiredSize += 1 + outputs_[ i ].name.length( );
selectorMapping_.push_back( i ); selectorMapping_.add( i );
nrLeft --; nrLeft --;
} }
i ++; i ++;

View file

@ -56,13 +56,13 @@ struct T_OutputDebugger
bool enabled_ = false; bool enabled_ = false;
uint32_t nRegistered_ = 0; uint32_t nRegistered_ = 0;
std::vector< T_Texture_ > outputs_; T_Array< T_Texture_ > outputs_;
std::vector< T_Submode_ > submodes_[ int( E_ODbgMode::__COUNT__ ) ]; T_Array< T_Submode_ > submodes_[ int( E_ODbgMode::__COUNT__ ) ];
char* smCombo_[ int( E_ODbgMode::__COUNT__ ) ]; char* smCombo_[ int( E_ODbgMode::__COUNT__ ) ];
int32_t selected_ = -1; int32_t selected_ = -1;
char* selectorItems_; char* selectorItems_;
std::vector< int32_t > selectorMapping_; T_Array< int32_t > selectorMapping_;
void registerSubmode( void registerSubmode(
__rd__ const E_ODbgMode mode , __rd__ const E_ODbgMode mode ,

View file

@ -100,16 +100,16 @@ T_Rendertarget::T_Rendertarget(
: id_( 0 ) , nCats_( other.nCats_ ) , width_( other.width_ ) , : id_( 0 ) , nCats_( other.nCats_ ) , width_( other.width_ ) ,
height_( other.height_ ) height_( other.height_ )
{ {
std::swap( id_ , other.id_ ); swap( id_ , other.id_ );
} }
T_Rendertarget& T_Rendertarget::operator =( T_Rendertarget& T_Rendertarget::operator =(
__rw__ T_Rendertarget&& other ) noexcept __rw__ T_Rendertarget&& other ) noexcept
{ {
std::swap( id_ , other.id_ ); swap( id_ , other.id_ );
std::swap( nCats_ , other.nCats_ ); swap( nCats_ , other.nCats_ );
std::swap( width_ , other.width_ ); swap( width_ , other.width_ );
std::swap( height_ , other.height_ ); swap( height_ , other.height_ );
return *this; return *this;
} }

View file

@ -15,10 +15,10 @@ struct T_RendertargetSetup
T_RendertargetSetup( ); T_RendertargetSetup( );
T_RendertargetSetup& add( T_RendertargetSetup& add(
__rw__ T_Texture& texture , T_Texture& texture ,
__rd__ const uint32_t level = 0 ); const uint32_t level = 0 );
T_RendertargetSetup& depth( T_RendertargetSetup& depth(
__rw__ T_Texture& texture ); T_Texture& texture );
T_Rendertarget create( ); T_Rendertarget create( );
@ -28,16 +28,16 @@ struct T_RendertargetSetup
uint32_t level; uint32_t level;
T_Attachment_( T_Attachment_(
__rw__ T_Texture& texture , T_Texture& texture ,
__rd__ const uint32_t level ) const uint32_t level )
: texture( &texture ) , level( level ) : texture( &texture ) , level( level )
{} {}
}; };
using T_Attachments_ = ebcl::T_AutoArray< T_Attachment_ , 8 >; using T_Attachments_ = ebcl::T_AutoArray< T_Attachment_ , 8 >;
void checkAttachment( void checkAttachment(
__rw__ T_Texture const& texture , T_Texture const& texture ,
__rd__ const uint32_t level ); const uint32_t level );
bool hasAttachments_; bool hasAttachments_;
uint32_t width_ , height_; uint32_t width_ , height_;
@ -53,14 +53,14 @@ struct T_Rendertarget
T_Rendertarget( T_Rendertarget const& ) = delete; T_Rendertarget( T_Rendertarget const& ) = delete;
T_Rendertarget( T_Rendertarget(
__rd__ const GLuint id , const GLuint id ,
__rd__ const uint32_t nCats , const uint32_t nCats ,
__rd__ const uint32_t width , const uint32_t width ,
__rd__ const uint32_t height ); const uint32_t height );
T_Rendertarget( __rw__ T_Rendertarget&& other ) noexcept; T_Rendertarget( T_Rendertarget&& other ) noexcept;
T_Rendertarget& operator =( T_Rendertarget& operator =(
__rw__ T_Rendertarget&& ) noexcept; T_Rendertarget&& ) noexcept;
~T_Rendertarget( ); ~T_Rendertarget( );

144
sync.cc
View file

@ -18,8 +18,8 @@ const std::map< std::string , T_SyncSegment::E_SegmentType > SegmentTypes_( ([]
/*= T_SyncTime ===============================================================*/ /*= T_SyncTime ===============================================================*/
void T_SyncTime::setDuration( void T_SyncTime::setDuration(
__rd__ const float uDuration , const float uDuration ,
__rd__ const uint32_t iDuration ) const uint32_t iDuration )
{ {
this->uDuration = std::max( 1e-3f , uDuration ); this->uDuration = std::max( 1e-3f , uDuration );
this->iDuration = std::max( 1u , iDuration ); this->iDuration = std::max( 1u , iDuration );
@ -32,33 +32,28 @@ void T_SyncTime::setDuration(
void T_SyncCurves::clear( ) void T_SyncCurves::clear( )
{ {
curves.clear( ); curves.clear( );
positions.clear( );
} }
void T_SyncCurves::setCurve( __rd__ T_SyncCurve curve ) void T_SyncCurves::setCurve(
T_SyncCurve curve )
{ {
const auto p( positions.find( curve.name ) ); curves.set( std::move( curve ) );
if ( p == positions.end( ) ) {
positions.emplace( curve.name , curves.size( ) );
curves.emplace_back( std::move( curve ) );
} else {
curves[ p->second ] = std::move( curve );
}
} }
int32_t T_SyncCurves::indexOf( __rd__ std::string const& name ) int32_t T_SyncCurves::indexOf(
T_String const& name ) noexcept
{ {
const auto p( positions.find( name ) ); const auto idx( curves.indexOf( name ) );
return p == positions.end( ) ? -1 : p->second; return idx == ebcl::T_HashIndex::INVALID_INDEX ? -1 : int32_t( idx );
} }
/*= T_SyncCurveCache =========================================================*/ /*= T_SyncCurveCache =========================================================*/
T_SyncCurveCache::T_SyncCurveCache( T_SyncCurveCache::T_SyncCurveCache(
__rd__ T_SyncTime const& time , T_SyncTime const& time ,
__rd__ T_SyncCurves const& curves , T_SyncCurves const& curves ,
__rd__ const uint32_t curve ) noexcept const uint32_t curve ) noexcept
: curve( curve ) , curPos( 0 ) : curve( curve ) , curPos( 0 )
{ {
auto const& c( curves.curves[ curve ] ); auto const& c( curves.curves[ curve ] );
@ -77,10 +72,10 @@ T_SyncCurveCache::T_SyncCurveCache(
if ( time.time >= sStart ) { if ( time.time >= sStart ) {
curPos = segStarts.size( ); curPos = segStarts.size( );
} }
segStarts.push_back( sStart ); segStarts.add( sStart );
segRefs.push_back( std::make_pair( i , j ) ); segRefs.add( std::make_pair( i , j ) );
s += v.durations[ j ]; s += v.durations[ j ];
segEnds.push_back( std::min( s , time.iDuration ) * time.uDuration ); segEnds.add( std::min( s , time.iDuration ) * time.uDuration );
if ( s > time.iDuration ) { if ( s > time.iDuration ) {
return; return;
} }
@ -91,7 +86,7 @@ T_SyncCurveCache::T_SyncCurveCache(
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
uint32_t T_SyncCurveCache::findSegment( uint32_t T_SyncCurveCache::findSegment(
__rd__ const float time ) const noexcept const float time ) const noexcept
{ {
const auto ns( segStarts.size( ) ); const auto ns( segStarts.size( ) );
for ( auto i = 0u ; i < ns ; i ++ ) { for ( auto i = 0u ; i < ns ; i ++ ) {
@ -105,17 +100,17 @@ uint32_t T_SyncCurveCache::findSegment(
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
float T_SyncCurveCache::valueAt( float T_SyncCurveCache::valueAt(
__rd__ T_SyncTime const& time , T_SyncTime const& time ,
__rd__ T_SyncCurves const& curves , T_SyncCurves const& curves ,
__rd__ const float position ) const noexcept const float position ) const noexcept
{ {
return segmentValue( time.time , findSegment( position ) , return segmentValue( time.time , findSegment( position ) ,
curves.curves[ curve ].segments ); curves.curves[ curve ].segments );
} }
float T_SyncCurveCache::value( float T_SyncCurveCache::value(
__rd__ T_SyncTime const& time , T_SyncTime const& time ,
__rd__ T_SyncCurves const& curves ) noexcept T_SyncCurves const& curves ) noexcept
{ {
const auto t( time.time ); const auto t( time.time );
@ -138,9 +133,9 @@ float T_SyncCurveCache::value(
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
float T_SyncCurveCache::segmentValue( float T_SyncCurveCache::segmentValue(
__rd__ float time , float time ,
__rd__ uint32_t segIndex , uint32_t segIndex ,
__rd__ std::vector< T_SyncSegment > const& segments ) const noexcept T_Array< T_SyncSegment > const& segments ) const noexcept
{ {
const auto sss( segStarts.size( ) ); const auto sss( segStarts.size( ) );
if ( segIndex >= sss ) { if ( segIndex >= sss ) {
@ -179,61 +174,69 @@ float T_SyncCurveCache::segmentValue(
T_SyncValues::T_SyncValues( ) T_SyncValues::T_SyncValues( )
{ {
values.push_back( 0 ); values.add( 0 );
} }
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
void T_SyncValues::clear( ) void T_SyncValues::clear( )
{ {
index.clear( );
identifiers.clear( ); identifiers.clear( );
values.clear( ); values.clear( );
overriden.clear( ); overriden.clear( );
positions.clear( ); values.add( 0 );
values.push_back( 0 );
} }
bool T_SyncValues::addValue( bool T_SyncValues::addValue(
__rd__ std::string const& name , T_String const& name ,
__rd__ const float initial ) const float initial ) noexcept
{ {
const auto np( positions.find( name ) ); const uint32_t hash{ ComputeHash( name ) };
if ( np != positions.end( ) ) { uint32_t existing{ index.first( hash ) };
while ( existing != T_HashIndex::INVALID_INDEX ) {
if ( name == identifiers[ existing ] ) {
return false; return false;
} }
const auto li( values.size( ) - 1 ); existing = index.next( existing );
positions.emplace( name , li ); }
identifiers.push_back( name );
values.push_back( initial ); const auto li( values.size( ) );
std::swap( values[ li ] , values[ li + 1 ] ); index.add( hash );
overriden.push_back( false ); identifiers.add( name );
values.add( initial );
std::swap( values[ li ] , values[ li - 1 ] );
overriden.add( false );
return true; return true;
} }
uint32_t T_SyncValues::indexOf( uint32_t T_SyncValues::indexOf(
__rd__ std::string const& name ) const T_String const& name ) const noexcept
{ {
const auto np( positions.find( name ) ); const uint32_t hash{ ComputeHash( name ) };
if ( np == positions.end( ) ) { uint32_t existing{ index.first( hash ) };
return values.size( ) - 1; while ( existing != T_HashIndex::INVALID_INDEX ) {
} else { if ( name == identifiers[ existing ] ) {
return np->second; return existing;
} }
existing = index.next( existing );
}
return values.size( ) - 1;
} }
/*= T_SyncManager ============================================================*/ /*= T_SyncManager ============================================================*/
void T_SyncManager::setDuration( void T_SyncManager::setDuration(
__rd__ const float uDuration , const float uDuration ,
__rd__ const uint32_t iDuration ) const uint32_t iDuration )
{ {
time_.setDuration( uDuration , iDuration ); time_.setDuration( uDuration , iDuration );
updateCurveCaches( ); updateCurveCaches( );
} }
void T_SyncManager::setTime( void T_SyncManager::setTime(
__rd__ const float time ) const float time )
{ {
time_.setTime( time ); time_.setTime( time );
updateValues( ); updateValues( );
@ -265,7 +268,7 @@ void T_SyncManager::clearCurves( )
} }
void T_SyncManager::setCurve( void T_SyncManager::setCurve(
__rd__ T_SyncCurve curve ) T_SyncCurve curve )
{ {
curves_.setCurve( curve ); curves_.setCurve( curve );
updateCurveCaches( ); updateCurveCaches( );
@ -280,7 +283,7 @@ void T_SyncManager::curvesChanged_( )
} }
bool T_SyncManager::loadCurves_( bool T_SyncManager::loadCurves_(
__wr__ bool& missing ) bool& missing )
{ {
using T_STI_ = std::istream_iterator< char >; using T_STI_ = std::istream_iterator< char >;
std::ifstream file( "curves.json" ); std::ifstream file( "curves.json" );
@ -313,8 +316,8 @@ bool T_SyncManager::loadCurves_(
} }
bool T_SyncManager::loadCurvesData_( bool T_SyncManager::loadCurvesData_(
__wr__ T_SyncCurves& curves , T_SyncCurves& curves ,
__rd__ picojson::value const& root ) picojson::value const& root )
{ {
if ( !root.is< T_JSONObject >( ) ) { if ( !root.is< T_JSONObject >( ) ) {
printf( "Curves data: root is not a JSON object\n" ); printf( "Curves data: root is not a JSON object\n" );
@ -324,7 +327,7 @@ bool T_SyncManager::loadCurvesData_(
auto const& r( root.get< T_JSONObject >( ) ); auto const& r( root.get< T_JSONObject >( ) );
bool ok( true ); bool ok( true );
for ( auto const& item : r ) { for ( auto const& item : r ) {
if ( curves.indexOf( item.first ) != -1 ) { if ( curves.indexOf( item.first.c_str( ) ) != -1 ) {
printf( "Curves data: duplicate curve '%s'\n" , printf( "Curves data: duplicate curve '%s'\n" ,
item.first.c_str( ) ); item.first.c_str( ) );
ok = false; ok = false;
@ -337,8 +340,7 @@ bool T_SyncManager::loadCurvesData_(
continue; continue;
} }
T_SyncCurve nsc; T_SyncCurve nsc{ item.first.c_str( ) };
nsc.name = item.first;
bool segsOk( true ); bool segsOk( true );
for ( auto const& v : item.second.get< T_JSONArray >( ) ) { for ( auto const& v : item.second.get< T_JSONArray >( ) ) {
@ -351,7 +353,7 @@ bool T_SyncManager::loadCurvesData_(
T_SyncSegment segment; T_SyncSegment segment;
try { try {
if ( !loadSegmentData_( segment , nsc.name , if ( !loadSegmentData_( segment , (char*) nsc.name.toOSString( ).data( ) ,
v.get< T_JSONObject >( ) ) ) { v.get< T_JSONObject >( ) ) ) {
segsOk = false; segsOk = false;
continue; continue;
@ -362,11 +364,11 @@ bool T_SyncManager::loadCurvesData_(
segsOk = false; segsOk = false;
continue; continue;
} }
nsc.segments.emplace_back( std::move( segment ) ); nsc.segments.add( std::move( segment ) );
} }
ok = ok && segsOk; ok = ok && segsOk;
if ( nsc.segments.empty( ) && segsOk ) { if ( nsc.segments.size( ) == 0 && segsOk ) {
printf( "Curves data: curve '%s': no segments\n" , printf( "Curves data: curve '%s': no segments\n" ,
item.first.c_str( ) ); item.first.c_str( ) );
ok = false; ok = false;
@ -378,9 +380,9 @@ bool T_SyncManager::loadCurvesData_(
} }
bool T_SyncManager::loadSegmentData_( bool T_SyncManager::loadSegmentData_(
__wr__ T_SyncSegment& segment , T_SyncSegment& segment ,
__rd__ std::string const& curve , std::string const& curve ,
__rd__ T_JSONObject const& sd ) T_JSONObject const& sd )
{ {
auto const& sType( jsonGet< std::string >( sd , "type" ) ); auto const& sType( jsonGet< std::string >( sd , "type" ) );
@ -412,7 +414,7 @@ bool T_SyncManager::loadSegmentData_(
curve.c_str( ) ); curve.c_str( ) );
return false; return false;
} }
segment.values.push_back( float( vv.get< double >( ) ) ); segment.values.add( vv.get< double >( ) );
} }
for ( auto const& dv : dList ) { for ( auto const& dv : dList ) {
@ -428,7 +430,7 @@ bool T_SyncManager::loadSegmentData_(
curve.c_str( ) , dvn ); curve.c_str( ) , dvn );
return false; return false;
} }
segment.durations.push_back( uint32_t( dvn ) ); segment.durations.add( dvn );
} }
segment.nPoints = segment.values.size( ); segment.nPoints = segment.values.size( );
@ -445,9 +447,9 @@ void T_SyncManager::updateCurveCaches( )
auto const& id( values_.identifiers[ i ] ); auto const& id( values_.identifiers[ i ] );
const auto cp( curves_.indexOf( id ) ); const auto cp( curves_.indexOf( id ) );
if ( cp < 0 ) { if ( cp < 0 ) {
curveCaches_.emplace_back( ); curveCaches_.addNew( );
} else { } else {
curveCaches_.emplace_back( new T_SyncCurveCache( curveCaches_.add( NewOwned< T_SyncCurveCache >(
time_ , curves_ , cp time_ , curves_ , cp
) ); ) );
} }
@ -496,8 +498,8 @@ void T_SyncManager::makeUI( )
} }
void T_SyncManager::displayOvSections( void T_SyncManager::displayOvSections(
__rw__ T_SyncUISections& sections , T_SyncUISections& sections ,
__rd__ const bool topLevel ) const bool topLevel )
{ {
for ( auto& s : sections ) { for ( auto& s : sections ) {
const bool display( topLevel const bool display( topLevel
@ -518,7 +520,7 @@ void T_SyncManager::displayOvSections(
} }
void T_SyncManager::displayOvControls( void T_SyncManager::displayOvControls(
__rw__ T_SyncUIOverrides& overrides ) T_SyncUIOverrides& overrides )
{ {
for ( auto& o : overrides ) { for ( auto& o : overrides ) {
// XXX enable override checkbox should be selected and disabled // XXX enable override checkbox should be selected and disabled

138
sync.hh
View file

@ -10,13 +10,13 @@ struct T_SyncTime
float time = 0; float time = 0;
void setDuration( void setDuration(
__rd__ const float uDuration , const float uDuration ,
__rd__ const uint32_t iDuration ); const uint32_t iDuration );
float duration( ) const noexcept float duration( ) const noexcept
{ return uDuration * iDuration; } { return uDuration * iDuration; }
void setTime( __rd__ const float t ) noexcept void setTime( const float t ) noexcept
{ time = std::max( 0.f , std::min( t , duration( ) ) ); } { time = std::max( 0.f , std::min( t , duration( ) ) ); }
}; };
@ -35,15 +35,25 @@ struct T_SyncSegment
uint32_t nPoints; uint32_t nPoints;
E_SegmentType type; E_SegmentType type;
std::vector< float > values; // nPoints items T_Array< float > values; // nPoints items
std::vector< uint32_t > durations; // nPoints - 1 items T_Array< uint32_t > durations; // nPoints - 1 items
}; };
// An input curve // An input curve
struct T_SyncCurve struct T_SyncCurve
{ {
std::string name; T_String name;
std::vector< T_SyncSegment > segments; T_Array< T_SyncSegment > segments;
T_SyncCurve( ) noexcept { }
T_SyncCurve( T_String const& name ) noexcept
: name( name )
{ }
T_SyncCurve( char const* name ) noexcept
: name( T_String( name ).usePool( ) )
{ }
}; };
// All configured curves. Some may not actually correspond to an input and may // All configured curves. Some may not actually correspond to an input and may
@ -53,16 +63,23 @@ struct T_SyncCurve
struct T_SyncCurves struct T_SyncCurves
{ {
std::vector< T_SyncCurve > curves; T_ObjectTable< T_String , T_SyncCurve > curves;
std::map< std::string , int32_t > positions;
T_SyncCurves( )
: curves( []( T_SyncCurve const& c ) -> T_String { return c.name; } )
{ }
void clear( ); void clear( );
// Returns true on success, false on duplicate // Returns true on success, false on duplicate
void setCurve( __rd__ T_SyncCurve curve ); void setCurve( T_SyncCurve curve );
// Returns -1 on lookup failure // Returns -1 on lookup failure
int32_t indexOf( __rd__ std::string const& name ); int32_t indexOf( T_String const& name ) noexcept;
int32_t indexOf( char const* name ) noexcept
{
return indexOf( T_String( name ) );
}
}; };
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
@ -73,39 +90,39 @@ struct T_SyncCurveCache
using T_SegRef = std::pair< uint32_t , uint32_t >; using T_SegRef = std::pair< uint32_t , uint32_t >;
uint32_t curve; uint32_t curve;
std::vector< T_SegRef > segRefs; T_Array< T_SegRef > segRefs;
std::vector< float > segStarts; T_Array< float > segStarts;
std::vector< float > segEnds; T_Array< float > segEnds;
uint32_t curPos; uint32_t curPos;
T_SyncCurveCache( T_SyncCurveCache(
__rd__ T_SyncTime const& time , T_SyncTime const& time ,
__rd__ T_SyncCurves const& curves , T_SyncCurves const& curves ,
__rd__ const uint32_t curve ) noexcept; const uint32_t curve ) noexcept;
// Find the index of the segment for the specified time // Find the index of the segment for the specified time
uint32_t findSegment( uint32_t findSegment(
__rd__ const float time ) const noexcept; const float time ) const noexcept;
// Compute the value of the curve at the specified location, ignoring // Compute the value of the curve at the specified location, ignoring
// curPos. // curPos.
float valueAt( float valueAt(
__rd__ T_SyncTime const& time , T_SyncTime const& time ,
__rd__ T_SyncCurves const& curves , T_SyncCurves const& curves ,
__rd__ const float position ) const noexcept; const float position ) const noexcept;
// Compute the value of the curve at the current time, using and // Compute the value of the curve at the current time, using and
// updating curPos as necessary. // updating curPos as necessary.
float value( float value(
__rd__ T_SyncTime const& time , T_SyncTime const& time ,
__rd__ T_SyncCurves const& curves ) noexcept; T_SyncCurves const& curves ) noexcept;
float segmentValue( float segmentValue(
__rd__ float time , float time ,
__rd__ uint32_t segIndex , uint32_t segIndex ,
__rd__ std::vector< T_SyncSegment > const& segments ) const noexcept; T_Array< T_SyncSegment > const& segments ) const noexcept;
}; };
using P_SyncCurveCache = std::unique_ptr< T_SyncCurveCache >; using P_SyncCurveCache = T_OwnPtr< T_SyncCurveCache >;
/*============================================================================*/ /*============================================================================*/
@ -113,22 +130,29 @@ using P_SyncCurveCache = std::unique_ptr< T_SyncCurveCache >;
// used for missing inputs. // used for missing inputs.
struct T_SyncValues struct T_SyncValues
{ {
std::vector< std::string > identifiers; T_HashIndex index;
std::vector< float > values; T_Array< T_String > identifiers;
std::vector< bool > overriden; T_Array< float > values;
std::unordered_map< std::string , uint32_t > positions; T_Array< bool > overriden;
T_SyncValues( ); T_SyncValues( );
void clear( ); void clear( );
// Returns true on success, false on duplicate // Returns true on success, false on duplicate
bool addValue( bool addValue(
__rd__ std::string const& name , T_String const& name ,
__rd__ const float initial = 0.f ); const float initial = 0.f ) noexcept;
bool addValue(
char const* name ,
const float initial = 0.f ) noexcept
{
return addValue( T_String( name ) , initial );
}
// If the name isn't found, the last entry of values[] is returned // If the name isn't found, the last entry of values[] is returned
uint32_t indexOf( uint32_t indexOf(
__rd__ std::string const& name ) const; T_String const& name ) const noexcept;
}; };
/*============================================================================*/ /*============================================================================*/
@ -141,13 +165,13 @@ struct T_SyncManager
// Duration & time controls // Duration & time controls
void setDuration( void setDuration(
__rd__ const float uDuration , const float uDuration ,
__rd__ const uint32_t iDuration ); const uint32_t iDuration );
float duration( ) const noexcept float duration( ) const noexcept
{ return time_.duration( ); } { return time_.duration( ); }
void setTime( __rd__ const float time ); void setTime( const float time );
void timeDelta( __rd__ const float delta ) void timeDelta( const float delta )
{ setTime( time_.time + delta ); } { setTime( time_.time + delta ); }
float time( ) const noexcept float time( ) const noexcept
{ return time_.time; } { return time_.time; }
@ -160,13 +184,13 @@ struct T_SyncManager
void clearInputs( ) void clearInputs( )
{ values_.clear( ); } { values_.clear( ); }
bool addInput( __rd__ std::string const& name , bool addInput( std::string const& name ,
__rd__ const float initial = 0.f ) noexcept const float initial = 0.f ) noexcept
{ return values_.addValue( name , initial ); } { return values_.addValue( name.c_str( ) , initial ); }
uint32_t inputPos( __rd__ std::string const& name ) const noexcept uint32_t inputPos( T_String const& name ) const noexcept
{ return values_.indexOf( name ); } { return values_.indexOf( name ); }
std::vector< float > const& inputs( ) const noexcept T_Array< float > const& inputs( ) const noexcept
{ return values_.values; } { return values_.values; }
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
@ -174,18 +198,18 @@ struct T_SyncManager
void checkCurveFile( ); void checkCurveFile( );
void clearCurves( ); void clearCurves( );
void setCurve( __rd__ T_SyncCurve curve ); void setCurve( T_SyncCurve curve );
private: private:
void curvesChanged_( ); void curvesChanged_( );
bool loadCurves_( __wr__ bool& missing ); bool loadCurves_( bool& missing );
bool loadCurvesData_( bool loadCurvesData_(
__wr__ T_SyncCurves& curves , T_SyncCurves& curves ,
__rd__ picojson::value const& root ); picojson::value const& root );
bool loadSegmentData_( bool loadSegmentData_(
__wr__ T_SyncSegment& segment , T_SyncSegment& segment ,
__rd__ std::string const& curve , std::string const& curve ,
__rd__ T_JSONObject const& sd ); T_JSONObject const& sd );
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// Update // Update
@ -199,7 +223,7 @@ struct T_SyncManager
T_SyncTime time_; T_SyncTime time_;
T_SyncValues values_; T_SyncValues values_;
T_SyncCurves curves_; T_SyncCurves curves_;
std::vector< P_SyncCurveCache > curveCaches_; T_Array< P_SyncCurveCache > curveCaches_;
}; };
@ -215,9 +239,9 @@ struct T_SyncInputDfn
float min = -std::numeric_limits< float >::infinity( ), float min = -std::numeric_limits< float >::infinity( ),
max = std::numeric_limits< float >::infinity( ); max = std::numeric_limits< float >::infinity( );
T_SyncInputDfn( __rd__ std::string const& identifier , T_SyncInputDfn( std::string const& identifier ,
__rd__ const float min , const float min ,
__rd__ const float max ) noexcept const float max ) noexcept
: identifier( identifier ) , min( min ) , max( max ) : identifier( identifier ) , min( min ) , max( max )
{ } { }
}; };
@ -291,9 +315,9 @@ struct T_SyncManager
private: private:
void displayOvSections( void displayOvSections(
__rw__ T_SyncUISections& sections , T_SyncUISections& sections ,
__rd__ const bool topLevel = false ); const bool topLevel = false );
void displayOvControls( void displayOvControls(
__rw__ T_SyncUIOverrides& overrides ); T_SyncUIOverrides& overrides );
}; };
#endif #endif

View file

@ -8,10 +8,10 @@
/*==============================================================================*/ /*==============================================================================*/
T_Texture::T_Texture( T_Texture::T_Texture(
__rd__ const uint32_t width , const uint32_t width ,
__rd__ const uint32_t height , const uint32_t height ,
__rd__ const E_TexType type , const E_TexType type ,
__rd__ const uint32_t levels ) const uint32_t levels )
: levels_( levels ) , width_( width ) , height_( height ) , : levels_( levels ) , width_( width ) , height_( height ) ,
debugIndex_( -1 ) debugIndex_( -1 )
{ {
@ -95,7 +95,7 @@ T_Texture::~T_Texture( )
T_Texture& T_Texture::samplingMode( T_Texture& T_Texture::samplingMode(
__rd__ const E_TexSampling mode ) const E_TexSampling mode )
{ {
glBindTexture( GL_TEXTURE_2D , id_ ); glBindTexture( GL_TEXTURE_2D , id_ );
@ -117,7 +117,7 @@ T_Texture& T_Texture::samplingMode(
} }
T_Texture& T_Texture::wrap( T_Texture& T_Texture::wrap(
__rd__ const E_TexWrap mode ) const E_TexWrap mode )
{ {
GLenum gm; GLenum gm;
switch ( mode ) { switch ( mode ) {
@ -145,22 +145,22 @@ T_TextureSampler::T_TextureSampler( )
} }
T_TextureSampler::T_TextureSampler( T_TextureSampler::T_TextureSampler(
__rw__ T_TextureSampler&& other ) noexcept T_TextureSampler&& other ) noexcept
{ {
std::swap( id_ , other.id_ ); swap( id_ , other.id_ );
std::swap( sampling_ , other.sampling_ ); swap( sampling_ , other.sampling_ );
std::swap( lodSampling_ , other.lodSampling_ ); swap( lodSampling_ , other.lodSampling_ );
std::swap( hasLOD_ , other.hasLOD_ ); swap( hasLOD_ , other.hasLOD_ );
setSamplingMode( ); setSamplingMode( );
} }
T_TextureSampler& T_TextureSampler::operator =( T_TextureSampler& T_TextureSampler::operator =(
__rw__ T_TextureSampler&& other ) noexcept T_TextureSampler&& other ) noexcept
{ {
std::swap( id_ , other.id_ ); swap( id_ , other.id_ );
std::swap( sampling_ , other.sampling_ ); swap( sampling_ , other.sampling_ );
std::swap( lodSampling_ , other.lodSampling_ ); swap( lodSampling_ , other.lodSampling_ );
std::swap( hasLOD_ , other.hasLOD_ ); swap( hasLOD_ , other.hasLOD_ );
return *this; return *this;
} }
@ -174,7 +174,7 @@ T_TextureSampler::~T_TextureSampler( )
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
T_TextureSampler& T_TextureSampler::sampling( T_TextureSampler& T_TextureSampler::sampling(
__rd__ const E_TexSampling mode ) const E_TexSampling mode )
{ {
sampling_ = mode; sampling_ = mode;
setSamplingMode( ); setSamplingMode( );
@ -189,7 +189,7 @@ T_TextureSampler& T_TextureSampler::noMipmap( )
} }
T_TextureSampler& T_TextureSampler::mipmap( T_TextureSampler& T_TextureSampler::mipmap(
__rd__ const E_TexSampling mode ) const E_TexSampling mode )
{ {
hasLOD_ = true; hasLOD_ = true;
lodSampling_ = mode; lodSampling_ = mode;
@ -198,7 +198,7 @@ T_TextureSampler& T_TextureSampler::mipmap(
} }
T_TextureSampler& T_TextureSampler::wrap( T_TextureSampler& T_TextureSampler::wrap(
__rd__ const E_TexWrap mode ) const E_TexWrap mode )
{ {
GLenum gm; GLenum gm;
switch ( mode ) { switch ( mode ) {
@ -219,8 +219,8 @@ T_TextureSampler& T_TextureSampler::wrap(
} }
T_TextureSampler& T_TextureSampler::lod( T_TextureSampler& T_TextureSampler::lod(
__rd__ const float min , const float min ,
__rd__ const float max ) const float max )
{ {
glSamplerParameterf( id_ , GL_TEXTURE_MIN_LOD , min ); glSamplerParameterf( id_ , GL_TEXTURE_MIN_LOD , min );
glSamplerParameterf( id_ , GL_TEXTURE_MAX_LOD , max ); glSamplerParameterf( id_ , GL_TEXTURE_MAX_LOD , max );
@ -271,38 +271,35 @@ constexpr uint32_t T_TextureManager::MaxUnits;
T_TextureManager::T_TextureManager( ) T_TextureManager::T_TextureManager( )
{ {
std::shared_ptr< T_TextureSampler > tsam; T_SharedPtr< T_TextureSampler > tsam;
tsam = std::make_shared< T_TextureSampler >( ); tsam = NewShared< T_TextureSampler >( );
tsam->wrap( E_TexWrap::CLAMP_EDGE ).sampling( E_TexSampling::NEAREST ); tsam->wrap( E_TexWrap::CLAMP_EDGE ).sampling( E_TexSampling::NEAREST );
samplers_[ "nearest-edge" ] = tsam; samplers_.add( T_String::Pooled( "nearest-edge" ) , std::move( tsam ) );
tsam = std::make_shared< T_TextureSampler >( ); tsam = NewShared< T_TextureSampler >( );
tsam->wrap( E_TexWrap::CLAMP_EDGE ).sampling( E_TexSampling::LINEAR ); tsam->wrap( E_TexWrap::CLAMP_EDGE ).sampling( E_TexSampling::LINEAR );
samplers_[ "linear-edge" ] = tsam; samplers_.add( T_String::Pooled( "linear-edge" ) , std::move( tsam ) );
tsam = std::make_shared< T_TextureSampler >( ); tsam = NewShared< T_TextureSampler >( );
tsam->wrap( E_TexWrap::CLAMP_BORDER ).sampling( E_TexSampling::NEAREST ); tsam->wrap( E_TexWrap::CLAMP_BORDER ).sampling( E_TexSampling::NEAREST );
samplers_[ "nearest-border" ] = tsam; samplers_.add( T_String::Pooled( "nearest-border" ) , std::move( tsam ) );
tsam = std::make_shared< T_TextureSampler >( ); tsam = NewShared< T_TextureSampler >( );
tsam->wrap( E_TexWrap::CLAMP_BORDER ).sampling( E_TexSampling::LINEAR ); tsam->wrap( E_TexWrap::CLAMP_BORDER ).sampling( E_TexSampling::LINEAR );
samplers_[ "linear-border" ] = tsam; samplers_.add( T_String::Pooled( "linear-border" ) , std::move( tsam ) );
} }
T_TextureSampler const* T_TextureManager::sampler( T_TextureSampler const* T_TextureManager::sampler(
__rd__ std::string const& name ) const T_String const& name ) const
{ {
auto pos( samplers_.find( name ) ); auto const* t( samplers_.get( name ) );
if ( pos == samplers_.end( ) ) { return t ? ( (T_TextureSampler const*) *t ) : nullptr;
return nullptr;
}
return (*pos).second.get( );
} }
void T_TextureManager::bind( void T_TextureManager::bind(
__rd__ const uint32_t unit , const uint32_t unit ,
__rd__ T_Texture const& texture ) T_Texture const& texture )
{ {
assert( unit < MaxUnits ); assert( unit < MaxUnits );
auto& u( bindings_[ unit ] ); auto& u( bindings_[ unit ] );
@ -316,9 +313,9 @@ void T_TextureManager::bind(
} }
void T_TextureManager::bind( void T_TextureManager::bind(
__rd__ const uint32_t unit , const uint32_t unit ,
__rd__ T_Texture const& texture , T_Texture const& texture ,
__rd__ T_TextureSampler const& sampler ) T_TextureSampler const& sampler )
{ {
assert( unit < MaxUnits ); assert( unit < MaxUnits );
auto& u( bindings_[ unit ] ); auto& u( bindings_[ unit ] );

View file

@ -38,16 +38,16 @@ struct T_Texture
T_Texture( T_Texture&& ) = delete; T_Texture( T_Texture&& ) = delete;
T_Texture( T_Texture(
__rd__ const uint32_t width , const uint32_t width ,
__rd__ const uint32_t height , const uint32_t height ,
__rd__ const E_TexType type , const E_TexType type ,
__rd__ const uint32_t levels = 1 ); const uint32_t levels = 1 );
~T_Texture( ); ~T_Texture( );
T_Texture& samplingMode( T_Texture& samplingMode(
__rd__ const E_TexSampling mode ); const E_TexSampling mode );
T_Texture& wrap( T_Texture& wrap(
__rd__ const E_TexWrap mode ); const E_TexWrap mode );
GLuint id( ) const noexcept { return id_; } GLuint id( ) const noexcept { return id_; }
uint32_t levels( ) const noexcept { return levels_; } uint32_t levels( ) const noexcept { return levels_; }
@ -70,37 +70,33 @@ struct T_TextureSampler
T_TextureSampler( ); T_TextureSampler( );
T_TextureSampler( T_TextureSampler(
__rw__ T_TextureSampler&& other ) noexcept; T_TextureSampler&& other ) noexcept;
T_TextureSampler& operator=( T_TextureSampler& operator=(
__rw__ T_TextureSampler&& other ) noexcept; T_TextureSampler&& other ) noexcept;
~T_TextureSampler( ); ~T_TextureSampler( );
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// Configuration // Configuration
T_TextureSampler& sampling( T_TextureSampler& sampling(
__rd__ const E_TexSampling mode ); const E_TexSampling mode );
T_TextureSampler& noMipmap( ); T_TextureSampler& noMipmap( );
T_TextureSampler& mipmap( T_TextureSampler& mipmap(
__rd__ const E_TexSampling mode ); const E_TexSampling mode );
T_TextureSampler& wrap( T_TextureSampler& wrap(
__rd__ const E_TexWrap mode ); const E_TexWrap mode );
T_TextureSampler& lod( T_TextureSampler& lod(
__rd__ const float min , const float min ,
__rd__ const float max ); const float max );
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// Usage // Usage
GLuint id( ) const noexcept { return id_; } GLuint id( ) const noexcept { return id_; }
// unused
void bind( __rd__ const GLuint unit )
{ glBindSampler( unit , id_ ); }
private: private:
void setSamplingMode( ) const; void setSamplingMode( ) const;
@ -121,14 +117,18 @@ struct T_TextureManager
NO_MOVE( T_TextureManager ); NO_MOVE( T_TextureManager );
void reset( ); void reset( );
T_TextureSampler const* sampler(
__rd__ std::string const& name ) const;
void bind( __rd__ const uint32_t unit , T_TextureSampler const* sampler(
__rd__ T_Texture const& texture ); T_String const& name ) const;
void bind( __rd__ const uint32_t unit , T_TextureSampler const* sampler(
__rd__ T_Texture const& texture , char const* name ) const
__rd__ T_TextureSampler const& sampler ); { return sampler( T_String::Pooled( name ) ); }
void bind( const uint32_t unit ,
T_Texture const& texture );
void bind( const uint32_t unit ,
T_Texture const& texture ,
T_TextureSampler const& sampler );
private: private:
struct T_Binding_ struct T_Binding_
@ -137,6 +137,6 @@ struct T_TextureManager
GLuint sampler = 0; GLuint sampler = 0;
}; };
std::map< std::string , std::shared_ptr< T_TextureSampler > > samplers_; T_KeyValueTable< T_String , T_SharedPtr< T_TextureSampler > > samplers_;
T_Binding_ bindings_[ MaxUnits ]; T_Binding_ bindings_[ MaxUnits ];
}; };

View file

@ -12,16 +12,16 @@ void disableButton( )
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
void updateAngle( void updateAngle(
__rw__ float& initial , float& initial ,
__rd__ const float delta const float delta
) )
{ {
initial = fmod( initial + delta + 540 , 360 ) - 180; initial = fmod( initial + delta + 540 , 360 ) - 180;
} }
void anglesToMatrix( void anglesToMatrix(
__rd__ float const* angles , float const* angles ,
__wr__ float* matrix ) float* matrix )
{ {
float c[3] , s[3]; float c[3] , s[3];
for ( int i = 0 ; i < 3 ; i ++ ) { for ( int i = 0 ; i < 3 ; i ++ ) {
@ -42,31 +42,30 @@ void anglesToMatrix(
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
std::string GetAbsolutePath( T_String GetAbsolutePath(
__rd__ std::string const& path ) T_String const& path )
{ {
char* const rp( realpath( path.c_str( ) , nullptr ) ); char* const rp( realpath( (char*) path.toOSString( ).data( ) , nullptr ) );
if ( !rp ) { if ( !rp ) {
return {}; return {};
} }
const std::string rv( rp ); const T_String rv( rp );
free( rp ); free( rp );
return rv; return rv;
} }
std::string GetParentPath( T_String GetParentPath(
__rd__ std::string const& path ) T_String const& path )
{ {
char buffer[ path.length( ) + 1 ]; auto buffer( path.toOSString( ) );
strcpy( buffer , path.c_str( ) );
char* const rp( realpath( dirname( buffer ) , nullptr ) ); char* const rp( realpath( dirname( (char*) buffer.data( ) ) , nullptr ) );
if ( !rp ) { if ( !rp ) {
return {}; return {};
} }
const std::string rv( rp ); const T_String rv( rp );
free( rp ); free( rp );
return rv; return rv;
} }
@ -75,27 +74,27 @@ std::string GetParentPath(
/*= JSON =====================================================================*/ /*= JSON =====================================================================*/
template void jsonAdd< double >( template void jsonAdd< double >(
__rw__ T_JSONObject& object , T_JSONObject& object ,
__rd__ std::string const& key , std::string const& key ,
__rd__ double const& v ); double const& v );
template void jsonAdd< T_JSONObject >( template void jsonAdd< T_JSONObject >(
__rw__ T_JSONObject& object , T_JSONObject& object ,
__rd__ std::string const& key , std::string const& key ,
__rd__ T_JSONObject const& v ); T_JSONObject const& v );
template void jsonAdd< T_JSONArray >( template void jsonAdd< T_JSONArray >(
__rw__ T_JSONObject& object , T_JSONObject& object ,
__rd__ std::string const& key , std::string const& key ,
__rd__ T_JSONArray const& v ); T_JSONArray const& v );
template void jsonAdd< std::string >( template void jsonAdd< std::string >(
__rw__ T_JSONObject& object , T_JSONObject& object ,
__rd__ std::string const& key , std::string const& key ,
__rd__ std::string const& v ); std::string const& v );
template< > template< >
void jsonAdd< picojson::value >( void jsonAdd< picojson::value >(
__rw__ T_JSONObject& object , T_JSONObject& object ,
__rd__ std::string const& key , std::string const& key ,
__rd__ picojson::value const& v ) picojson::value const& v )
{ {
using T_Entry = std::pair< std::string , picojson::value >; using T_Entry = std::pair< std::string , picojson::value >;
object.insert( T_Entry( key , v ) ); object.insert( T_Entry( key , v ) );
@ -103,9 +102,9 @@ void jsonAdd< picojson::value >(
template< > template< >
void jsonAdd< int >( void jsonAdd< int >(
__rw__ T_JSONObject& object , T_JSONObject& object ,
__rd__ std::string const& key , std::string const& key ,
__rd__ int const& v ) int const& v )
{ {
using T_Entry = std::pair< std::string , picojson::value >; using T_Entry = std::pair< std::string , picojson::value >;
object.insert( T_Entry( key , picojson::value( double( v ) ) ) ); object.insert( T_Entry( key , picojson::value( double( v ) ) ) );
@ -113,9 +112,9 @@ void jsonAdd< int >(
template< > template< >
void jsonAdd< unsigned >( void jsonAdd< unsigned >(
__rw__ T_JSONObject& object , T_JSONObject& object ,
__rd__ std::string const& key , std::string const& key ,
__rd__ unsigned const& v ) unsigned const& v )
{ {
using T_Entry = std::pair< std::string , picojson::value >; using T_Entry = std::pair< std::string , picojson::value >;
object.insert( T_Entry( key , picojson::value( double( v ) ) ) ); object.insert( T_Entry( key , picojson::value( double( v ) ) ) );
@ -136,10 +135,10 @@ picojson::value jsonVector( float const* vector , const int nComponents )
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
void jsonGetVectorOpt( void jsonGetVectorOpt(
__wr__ float* vector , float* vector ,
__rd__ const size_t size , const size_t size ,
__rd__ T_JSONObject const& object , T_JSONObject const& object ,
__rd__ char const* key ) char const* key )
{ {
using namespace picojson; using namespace picojson;
auto const* ptr( jsonGetOpt< array >( object , key ) ); auto const* ptr( jsonGetOpt< array >( object , key ) );

View file

@ -32,37 +32,37 @@ inline void reenableButtons( )
// Add some value to an angle, keeping it in [-180;180] // Add some value to an angle, keeping it in [-180;180]
void updateAngle( void updateAngle(
__rw__ float& initial , float& initial ,
__rd__ const float delta const float delta
); );
// Make a rotation matrix from three YPR angles (in degrees) // Make a rotation matrix from three YPR angles (in degrees)
void anglesToMatrix( void anglesToMatrix(
__rd__ float const* angles , float const* angles ,
__wr__ float* matrix ); float* matrix );
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
// Helpers for finding entries in collections // Helpers for finding entries in collections
template< typename T , typename I > template< typename T , typename I >
inline auto find( inline auto find(
__rd__ T const& collection , T const& collection ,
__rd__ I const& item ) I const& item )
{ {
return std::find( collection.begin( ) , collection.end( ) , item ); return std::find( collection.begin( ) , collection.end( ) , item );
} }
template< typename T , typename I > template< typename T , typename I >
inline auto find( inline auto find(
__rw__ T& collection , T& collection ,
__rd__ I const& item ) I const& item )
{ {
return std::find( collection.begin( ) , collection.end( ) , item ); return std::find( collection.begin( ) , collection.end( ) , item );
} }
template< typename T , typename I > template< typename T , typename I >
inline bool Contains( inline bool Contains(
__rd__ T const& collection , T const& collection ,
__rd__ I const& item ) I const& item )
{ {
return std::find( collection.begin( ) , collection.end( ) , item ) != collection.end( ); return std::find( collection.begin( ) , collection.end( ) , item ) != collection.end( );
} }
@ -71,11 +71,11 @@ inline bool Contains(
// Get the absolute path // Get the absolute path
std::string GetAbsolutePath( std::string GetAbsolutePath(
__rd__ std::string const& path ); std::string const& path );
// Get the absolute parent path for a (possibly relative) path // Get the absolute parent path for a (possibly relative) path
std::string GetParentPath( std::string GetParentPath(
__rd__ std::string const& path ); std::string const& path );
/*= JSON utilities ===========================================================*/ /*= JSON utilities ===========================================================*/
@ -85,12 +85,12 @@ using T_JSONArray = picojson::value::array;
// Convert a vector to a JSON array // Convert a vector to a JSON array
picojson::value jsonVector( picojson::value jsonVector(
__rd__ float const* vector , float const* vector ,
__rd__ const int nComponents ); const int nComponents );
// Convert a GLM vec3 to a JSON array // Convert a GLM vec3 to a JSON array
inline picojson::value jsonVector( inline picojson::value jsonVector(
__rd__ glm::vec3 const& vector ) glm::vec3 const& vector )
{ {
return jsonVector( &vector.x , 3 ); return jsonVector( &vector.x , 3 );
} }
@ -98,46 +98,46 @@ inline picojson::value jsonVector(
// Add an entry to a JSON object // Add an entry to a JSON object
template< typename T > template< typename T >
inline void jsonAdd( inline void jsonAdd(
__rw__ T_JSONObject& object , T_JSONObject& object ,
__rd__ std::string const& key , std::string const& key ,
__rd__ T const& v ) T const& v )
{ {
using T_Entry = std::pair< std::string , picojson::value >; using T_Entry = std::pair< std::string , picojson::value >;
object.insert( T_Entry( key , picojson::value( v ) ) ); object.insert( T_Entry( key , picojson::value( v ) ) );
} }
extern template void jsonAdd< double >( extern template void jsonAdd< double >(
__rw__ T_JSONObject& object , T_JSONObject& object ,
__rd__ std::string const& key , std::string const& key ,
__rd__ double const& v ); double const& v );
extern template void jsonAdd< T_JSONObject >( extern template void jsonAdd< T_JSONObject >(
__rw__ T_JSONObject& object , T_JSONObject& object ,
__rd__ std::string const& key , std::string const& key ,
__rd__ T_JSONObject const& v ); T_JSONObject const& v );
extern template void jsonAdd< T_JSONArray >( extern template void jsonAdd< T_JSONArray >(
__rw__ T_JSONObject& object , T_JSONObject& object ,
__rd__ std::string const& key , std::string const& key ,
__rd__ T_JSONArray const& v ); T_JSONArray const& v );
extern template void jsonAdd< std::string >( extern template void jsonAdd< std::string >(
__rw__ T_JSONObject& object , T_JSONObject& object ,
__rd__ std::string const& key , std::string const& key ,
__rd__ std::string const& v ); std::string const& v );
template< > template< >
void jsonAdd< picojson::value >( void jsonAdd< picojson::value >(
__rw__ T_JSONObject& object , T_JSONObject& object ,
__rd__ std::string const& key , std::string const& key ,
__rd__ picojson::value const& v ); picojson::value const& v );
template< > template< >
void jsonAdd< int >( void jsonAdd< int >(
__rw__ T_JSONObject& object , T_JSONObject& object ,
__rd__ std::string const& key , std::string const& key ,
__rd__ int const& v ); int const& v );
template< > template< >
void jsonAdd< unsigned >( void jsonAdd< unsigned >(
__rw__ T_JSONObject& object , T_JSONObject& object ,
__rd__ std::string const& key , std::string const& key ,
__rd__ unsigned const& v ); unsigned const& v );
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
@ -148,8 +148,8 @@ class X_JsonGetFailed : public std::exception { };
// if the field is missing. // if the field is missing.
template< typename T > template< typename T >
inline T const& jsonGet( inline T const& jsonGet(
__rd__ T_JSONObject const& object , T_JSONObject const& object ,
__rd__ char const* const key ) char const* const key )
{ {
const std::string k( key ); const std::string k( key );
if ( object.find( k ) == object.end( ) ) { if ( object.find( k ) == object.end( ) ) {
@ -167,8 +167,8 @@ inline T const& jsonGet(
// Throws X_JsonGetFailed if the type is incorrect. // Throws X_JsonGetFailed if the type is incorrect.
template< typename T > template< typename T >
inline T const* jsonGetOpt( inline T const* jsonGetOpt(
__rd__ T_JSONObject const& object , T_JSONObject const& object ,
__rd__ char const* const key ) char const* const key )
{ {
const std::string k( key ); const std::string k( key );
if ( object.find( k ) == object.end( ) ) { if ( object.find( k ) == object.end( ) ) {
@ -186,9 +186,9 @@ inline T const* jsonGetOpt(
// X_JsonGetFailed if the type is wrong // X_JsonGetFailed if the type is wrong
template< typename T > template< typename T >
inline bool jsonSetFromOpt( inline bool jsonSetFromOpt(
__wr__ T& out , T& out ,
__rd__ T_JSONObject const& object , T_JSONObject const& object ,
__rd__ char const* const key ) char const* const key )
{ {
T const* ptr( jsonGetOpt< T >( object , key ) ); T const* ptr( jsonGetOpt< T >( object , key ) );
if ( ptr ) { if ( ptr ) {
@ -200,9 +200,9 @@ inline bool jsonSetFromOpt(
// Integer specialization of the above // Integer specialization of the above
template< > template< >
inline bool jsonSetFromOpt< int >( inline bool jsonSetFromOpt< int >(
__wr__ int& out , int& out ,
__rd__ T_JSONObject const& object , T_JSONObject const& object ,
__rd__ char const* const key ) char const* const key )
{ {
double const* ptr( jsonGetOpt< double >( object , key ) ); double const* ptr( jsonGetOpt< double >( object , key ) );
if ( ptr ) { if ( ptr ) {
@ -214,9 +214,9 @@ inline bool jsonSetFromOpt< int >(
// Unsigned integer specialization of the above // Unsigned integer specialization of the above
template< > template< >
inline bool jsonSetFromOpt< unsigned >( inline bool jsonSetFromOpt< unsigned >(
__wr__ unsigned& out , unsigned& out ,
__rd__ T_JSONObject const& object , T_JSONObject const& object ,
__rd__ char const* const key ) char const* const key )
{ {
double const* ptr( jsonGetOpt< double >( object , key ) ); double const* ptr( jsonGetOpt< double >( object , key ) );
if ( ptr ) { if ( ptr ) {
@ -228,9 +228,9 @@ inline bool jsonSetFromOpt< unsigned >(
// 32-bit float specialization of the above // 32-bit float specialization of the above
template< > template< >
inline bool jsonSetFromOpt< float >( inline bool jsonSetFromOpt< float >(
__wr__ float& out , float& out ,
__rd__ T_JSONObject const& object , T_JSONObject const& object ,
__rd__ char const* const key ) char const* const key )
{ {
double const* ptr( jsonGetOpt< double >( object , key ) ); double const* ptr( jsonGetOpt< double >( object , key ) );
if ( ptr ) { if ( ptr ) {
@ -241,16 +241,16 @@ inline bool jsonSetFromOpt< float >(
// Read a vector from a JSON array of numbers // Read a vector from a JSON array of numbers
void jsonGetVectorOpt( void jsonGetVectorOpt(
__wr__ float* vector , float* vector ,
__rd__ const size_t size , const size_t size ,
__rd__ T_JSONObject const& object , T_JSONObject const& object ,
__rd__ char const* key ); char const* key );
// Read a GLM vec3 from a JSON array of numbers // Read a GLM vec3 from a JSON array of numbers
inline void jsonGetVectorOpt( inline void jsonGetVectorOpt(
__wr__ glm::vec3& vector , glm::vec3& vector ,
__rd__ T_JSONObject const& object , T_JSONObject const& object ,
__rd__ char const* key ) char const* key )
{ {
jsonGetVectorOpt( &vector.x , 3 , object , key ); jsonGetVectorOpt( &vector.x , 3 , object , key );
} }
@ -258,9 +258,9 @@ inline void jsonGetVectorOpt(
// Try to load some object using its "bool load( jsonobject )" method. // Try to load some object using its "bool load( jsonobject )" method.
template< typename T > template< typename T >
inline bool jsonLoadOpt( inline bool jsonLoadOpt(
__rw__ T& out , T& out ,
__rd__ T_JSONObject const& object , T_JSONObject const& object ,
__rd__ char const* key ) char const* key )
{ {
try { try {
auto const* sub( jsonGetOpt< T_JSONObject >( object , key ) ); auto const* sub( jsonGetOpt< T_JSONObject >( object , key ) );

View file

@ -38,14 +38,14 @@ T_Window::~T_Window( )
} }
void T_Window::startFrame( void T_Window::startFrame(
__rd__ const bool capture , const bool capture ,
__rd__ ImVec2 const& mouseInitial ) const ImVec2 const& mouseInitial ) const
{ {
ImGui_ImplSdl_NewFrame( window , capture , mouseInitial ); ImGui_ImplSdl_NewFrame( window , capture , mouseInitial );
} }
void T_Window::warpMouse( void T_Window::warpMouse(
__rd__ ImVec2 const& pos ) const ImVec2 const& pos ) const
{ {
SDL_WarpMouseInWindow( window , pos.x , pos.y ); SDL_WarpMouseInWindow( window , pos.x , pos.y );
} }

View file

@ -9,9 +9,9 @@ struct T_Window
T_Window( ); T_Window( );
~T_Window( ); ~T_Window( );
void startFrame( __rd__ const bool capture , void startFrame( const bool capture ,
__rd__ ImVec2 const& mouseInitial ) const; ImVec2 const& mouseInitial ) const;
void warpMouse( __rd__ ImVec2 const& pos ) const; void warpMouse( ImVec2 const& pos ) const;
void swap( ) const; void swap( ) const;