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

View file

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

View file

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

44
main.cc
View file

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

View file

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

View file

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

View file

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

View file

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

144
sync.cc
View file

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

138
sync.hh
View file

@ -10,13 +10,13 @@ struct T_SyncTime
float time = 0;
void setDuration(
__rd__ const float uDuration ,
__rd__ const uint32_t iDuration );
const float uDuration ,
const uint32_t iDuration );
float duration( ) const noexcept
{ 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( ) ) ); }
};
@ -35,15 +35,25 @@ struct T_SyncSegment
uint32_t nPoints;
E_SegmentType type;
std::vector< float > values; // nPoints items
std::vector< uint32_t > durations; // nPoints - 1 items
T_Array< float > values; // nPoints items
T_Array< uint32_t > durations; // nPoints - 1 items
};
// An input curve
struct T_SyncCurve
{
std::string name;
std::vector< T_SyncSegment > segments;
T_String name;
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
@ -53,16 +63,23 @@ struct T_SyncCurve
struct T_SyncCurves
{
std::vector< T_SyncCurve > curves;
std::map< std::string , int32_t > positions;
T_ObjectTable< T_String , T_SyncCurve > curves;
T_SyncCurves( )
: curves( []( T_SyncCurve const& c ) -> T_String { return c.name; } )
{ }
void clear( );
// Returns true on success, false on duplicate
void setCurve( __rd__ T_SyncCurve curve );
void setCurve( T_SyncCurve curve );
// 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 >;
uint32_t curve;
std::vector< T_SegRef > segRefs;
std::vector< float > segStarts;
std::vector< float > segEnds;
T_Array< T_SegRef > segRefs;
T_Array< float > segStarts;
T_Array< float > segEnds;
uint32_t curPos;
T_SyncCurveCache(
__rd__ T_SyncTime const& time ,
__rd__ T_SyncCurves const& curves ,
__rd__ const uint32_t curve ) noexcept;
T_SyncTime const& time ,
T_SyncCurves const& curves ,
const uint32_t curve ) noexcept;
// Find the index of the segment for the specified time
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
// curPos.
float valueAt(
__rd__ T_SyncTime const& time ,
__rd__ T_SyncCurves const& curves ,
__rd__ const float position ) const noexcept;
T_SyncTime const& time ,
T_SyncCurves const& curves ,
const float position ) const noexcept;
// Compute the value of the curve at the current time, using and
// updating curPos as necessary.
float value(
__rd__ T_SyncTime const& time ,
__rd__ T_SyncCurves const& curves ) noexcept;
T_SyncTime const& time ,
T_SyncCurves const& curves ) noexcept;
float segmentValue(
__rd__ float time ,
__rd__ uint32_t segIndex ,
__rd__ std::vector< T_SyncSegment > const& segments ) const noexcept;
float time ,
uint32_t segIndex ,
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.
struct T_SyncValues
{
std::vector< std::string > identifiers;
std::vector< float > values;
std::vector< bool > overriden;
std::unordered_map< std::string , uint32_t > positions;
T_HashIndex index;
T_Array< T_String > identifiers;
T_Array< float > values;
T_Array< bool > overriden;
T_SyncValues( );
void clear( );
// Returns true on success, false on duplicate
bool addValue(
__rd__ std::string const& name ,
__rd__ const float initial = 0.f );
T_String const& name ,
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
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
void setDuration(
__rd__ const float uDuration ,
__rd__ const uint32_t iDuration );
const float uDuration ,
const uint32_t iDuration );
float duration( ) const noexcept
{ return time_.duration( ); }
void setTime( __rd__ const float time );
void timeDelta( __rd__ const float delta )
void setTime( const float time );
void timeDelta( const float delta )
{ setTime( time_.time + delta ); }
float time( ) const noexcept
{ return time_.time; }
@ -160,13 +184,13 @@ struct T_SyncManager
void clearInputs( )
{ values_.clear( ); }
bool addInput( __rd__ std::string const& name ,
__rd__ const float initial = 0.f ) noexcept
{ return values_.addValue( name , initial ); }
bool addInput( std::string const& name ,
const float initial = 0.f ) noexcept
{ 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 ); }
std::vector< float > const& inputs( ) const noexcept
T_Array< float > const& inputs( ) const noexcept
{ return values_.values; }
// ---------------------------------------------------------------------
@ -174,18 +198,18 @@ struct T_SyncManager
void checkCurveFile( );
void clearCurves( );
void setCurve( __rd__ T_SyncCurve curve );
void setCurve( T_SyncCurve curve );
private:
void curvesChanged_( );
bool loadCurves_( __wr__ bool& missing );
bool loadCurves_( bool& missing );
bool loadCurvesData_(
__wr__ T_SyncCurves& curves ,
__rd__ picojson::value const& root );
T_SyncCurves& curves ,
picojson::value const& root );
bool loadSegmentData_(
__wr__ T_SyncSegment& segment ,
__rd__ std::string const& curve ,
__rd__ T_JSONObject const& sd );
T_SyncSegment& segment ,
std::string const& curve ,
T_JSONObject const& sd );
// ---------------------------------------------------------------------
// Update
@ -199,7 +223,7 @@ struct T_SyncManager
T_SyncTime time_;
T_SyncValues values_;
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( ),
max = std::numeric_limits< float >::infinity( );
T_SyncInputDfn( __rd__ std::string const& identifier ,
__rd__ const float min ,
__rd__ const float max ) noexcept
T_SyncInputDfn( std::string const& identifier ,
const float min ,
const float max ) noexcept
: identifier( identifier ) , min( min ) , max( max )
{ }
};
@ -291,9 +315,9 @@ struct T_SyncManager
private:
void displayOvSections(
__rw__ T_SyncUISections& sections ,
__rd__ const bool topLevel = false );
T_SyncUISections& sections ,
const bool topLevel = false );
void displayOvControls(
__rw__ T_SyncUIOverrides& overrides );
T_SyncUIOverrides& overrides );
};
#endif

View file

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

View file

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

View file

@ -12,16 +12,16 @@ void disableButton( )
/*----------------------------------------------------------------------------*/
void updateAngle(
__rw__ float& initial ,
__rd__ const float delta
float& initial ,
const float delta
)
{
initial = fmod( initial + delta + 540 , 360 ) - 180;
}
void anglesToMatrix(
__rd__ float const* angles ,
__wr__ float* matrix )
float const* angles ,
float* matrix )
{
float c[3] , s[3];
for ( int i = 0 ; i < 3 ; i ++ ) {
@ -42,31 +42,30 @@ void anglesToMatrix(
/*----------------------------------------------------------------------------*/
std::string GetAbsolutePath(
__rd__ std::string const& path )
T_String GetAbsolutePath(
T_String const& path )
{
char* const rp( realpath( path.c_str( ) , nullptr ) );
char* const rp( realpath( (char*) path.toOSString( ).data( ) , nullptr ) );
if ( !rp ) {
return {};
}
const std::string rv( rp );
const T_String rv( rp );
free( rp );
return rv;
}
std::string GetParentPath(
__rd__ std::string const& path )
T_String GetParentPath(
T_String const& path )
{
char buffer[ path.length( ) + 1 ];
strcpy( buffer , path.c_str( ) );
auto buffer( path.toOSString( ) );
char* const rp( realpath( dirname( buffer ) , nullptr ) );
char* const rp( realpath( dirname( (char*) buffer.data( ) ) , nullptr ) );
if ( !rp ) {
return {};
}
const std::string rv( rp );
const T_String rv( rp );
free( rp );
return rv;
}
@ -75,27 +74,27 @@ std::string GetParentPath(
/*= JSON =====================================================================*/
template void jsonAdd< double >(
__rw__ T_JSONObject& object ,
__rd__ std::string const& key ,
__rd__ double const& v );
T_JSONObject& object ,
std::string const& key ,
double const& v );
template void jsonAdd< T_JSONObject >(
__rw__ T_JSONObject& object ,
__rd__ std::string const& key ,
__rd__ T_JSONObject const& v );
T_JSONObject& object ,
std::string const& key ,
T_JSONObject const& v );
template void jsonAdd< T_JSONArray >(
__rw__ T_JSONObject& object ,
__rd__ std::string const& key ,
__rd__ T_JSONArray const& v );
T_JSONObject& object ,
std::string const& key ,
T_JSONArray const& v );
template void jsonAdd< std::string >(
__rw__ T_JSONObject& object ,
__rd__ std::string const& key ,
__rd__ std::string const& v );
T_JSONObject& object ,
std::string const& key ,
std::string const& v );
template< >
void jsonAdd< picojson::value >(
__rw__ T_JSONObject& object ,
__rd__ std::string const& key ,
__rd__ picojson::value const& v )
T_JSONObject& object ,
std::string const& key ,
picojson::value const& v )
{
using T_Entry = std::pair< std::string , picojson::value >;
object.insert( T_Entry( key , v ) );
@ -103,9 +102,9 @@ void jsonAdd< picojson::value >(
template< >
void jsonAdd< int >(
__rw__ T_JSONObject& object ,
__rd__ std::string const& key ,
__rd__ int const& v )
T_JSONObject& object ,
std::string const& key ,
int const& v )
{
using T_Entry = std::pair< std::string , picojson::value >;
object.insert( T_Entry( key , picojson::value( double( v ) ) ) );
@ -113,9 +112,9 @@ void jsonAdd< int >(
template< >
void jsonAdd< unsigned >(
__rw__ T_JSONObject& object ,
__rd__ std::string const& key ,
__rd__ unsigned const& v )
T_JSONObject& object ,
std::string const& key ,
unsigned const& v )
{
using T_Entry = std::pair< std::string , picojson::value >;
object.insert( T_Entry( key , picojson::value( double( v ) ) ) );
@ -136,10 +135,10 @@ picojson::value jsonVector( float const* vector , const int nComponents )
/*----------------------------------------------------------------------------*/
void jsonGetVectorOpt(
__wr__ float* vector ,
__rd__ const size_t size ,
__rd__ T_JSONObject const& object ,
__rd__ char const* key )
float* vector ,
const size_t size ,
T_JSONObject const& object ,
char const* key )
{
using namespace picojson;
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]
void updateAngle(
__rw__ float& initial ,
__rd__ const float delta
float& initial ,
const float delta
);
// Make a rotation matrix from three YPR angles (in degrees)
void anglesToMatrix(
__rd__ float const* angles ,
__wr__ float* matrix );
float const* angles ,
float* matrix );
/*----------------------------------------------------------------------------*/
// Helpers for finding entries in collections
template< typename T , typename I >
inline auto find(
__rd__ T const& collection ,
__rd__ I const& item )
T const& collection ,
I const& item )
{
return std::find( collection.begin( ) , collection.end( ) , item );
}
template< typename T , typename I >
inline auto find(
__rw__ T& collection ,
__rd__ I const& item )
T& collection ,
I const& item )
{
return std::find( collection.begin( ) , collection.end( ) , item );
}
template< typename T , typename I >
inline bool Contains(
__rd__ T const& collection ,
__rd__ I const& item )
T const& collection ,
I const& item )
{
return std::find( collection.begin( ) , collection.end( ) , item ) != collection.end( );
}
@ -71,11 +71,11 @@ inline bool Contains(
// Get the absolute path
std::string GetAbsolutePath(
__rd__ std::string const& path );
std::string const& path );
// Get the absolute parent path for a (possibly relative) path
std::string GetParentPath(
__rd__ std::string const& path );
std::string const& path );
/*= JSON utilities ===========================================================*/
@ -85,12 +85,12 @@ using T_JSONArray = picojson::value::array;
// Convert a vector to a JSON array
picojson::value jsonVector(
__rd__ float const* vector ,
__rd__ const int nComponents );
float const* vector ,
const int nComponents );
// Convert a GLM vec3 to a JSON array
inline picojson::value jsonVector(
__rd__ glm::vec3 const& vector )
glm::vec3 const& vector )
{
return jsonVector( &vector.x , 3 );
}
@ -98,46 +98,46 @@ inline picojson::value jsonVector(
// Add an entry to a JSON object
template< typename T >
inline void jsonAdd(
__rw__ T_JSONObject& object ,
__rd__ std::string const& key ,
__rd__ T const& v )
T_JSONObject& object ,
std::string const& key ,
T const& v )
{
using T_Entry = std::pair< std::string , picojson::value >;
object.insert( T_Entry( key , picojson::value( v ) ) );
}
extern template void jsonAdd< double >(
__rw__ T_JSONObject& object ,
__rd__ std::string const& key ,
__rd__ double const& v );
T_JSONObject& object ,
std::string const& key ,
double const& v );
extern template void jsonAdd< T_JSONObject >(
__rw__ T_JSONObject& object ,
__rd__ std::string const& key ,
__rd__ T_JSONObject const& v );
T_JSONObject& object ,
std::string const& key ,
T_JSONObject const& v );
extern template void jsonAdd< T_JSONArray >(
__rw__ T_JSONObject& object ,
__rd__ std::string const& key ,
__rd__ T_JSONArray const& v );
T_JSONObject& object ,
std::string const& key ,
T_JSONArray const& v );
extern template void jsonAdd< std::string >(
__rw__ T_JSONObject& object ,
__rd__ std::string const& key ,
__rd__ std::string const& v );
T_JSONObject& object ,
std::string const& key ,
std::string const& v );
template< >
void jsonAdd< picojson::value >(
__rw__ T_JSONObject& object ,
__rd__ std::string const& key ,
__rd__ picojson::value const& v );
T_JSONObject& object ,
std::string const& key ,
picojson::value const& v );
template< >
void jsonAdd< int >(
__rw__ T_JSONObject& object ,
__rd__ std::string const& key ,
__rd__ int const& v );
T_JSONObject& object ,
std::string const& key ,
int const& v );
template< >
void jsonAdd< unsigned >(
__rw__ T_JSONObject& object ,
__rd__ std::string const& key ,
__rd__ unsigned const& v );
T_JSONObject& object ,
std::string const& key ,
unsigned const& v );
/*----------------------------------------------------------------------------*/
@ -148,8 +148,8 @@ class X_JsonGetFailed : public std::exception { };
// if the field is missing.
template< typename T >
inline T const& jsonGet(
__rd__ T_JSONObject const& object ,
__rd__ char const* const key )
T_JSONObject const& object ,
char const* const key )
{
const std::string k( key );
if ( object.find( k ) == object.end( ) ) {
@ -167,8 +167,8 @@ inline T const& jsonGet(
// Throws X_JsonGetFailed if the type is incorrect.
template< typename T >
inline T const* jsonGetOpt(
__rd__ T_JSONObject const& object ,
__rd__ char const* const key )
T_JSONObject const& object ,
char const* const key )
{
const std::string k( key );
if ( object.find( k ) == object.end( ) ) {
@ -186,9 +186,9 @@ inline T const* jsonGetOpt(
// X_JsonGetFailed if the type is wrong
template< typename T >
inline bool jsonSetFromOpt(
__wr__ T& out ,
__rd__ T_JSONObject const& object ,
__rd__ char const* const key )
T& out ,
T_JSONObject const& object ,
char const* const key )
{
T const* ptr( jsonGetOpt< T >( object , key ) );
if ( ptr ) {
@ -200,9 +200,9 @@ inline bool jsonSetFromOpt(
// Integer specialization of the above
template< >
inline bool jsonSetFromOpt< int >(
__wr__ int& out ,
__rd__ T_JSONObject const& object ,
__rd__ char const* const key )
int& out ,
T_JSONObject const& object ,
char const* const key )
{
double const* ptr( jsonGetOpt< double >( object , key ) );
if ( ptr ) {
@ -214,9 +214,9 @@ inline bool jsonSetFromOpt< int >(
// Unsigned integer specialization of the above
template< >
inline bool jsonSetFromOpt< unsigned >(
__wr__ unsigned& out ,
__rd__ T_JSONObject const& object ,
__rd__ char const* const key )
unsigned& out ,
T_JSONObject const& object ,
char const* const key )
{
double const* ptr( jsonGetOpt< double >( object , key ) );
if ( ptr ) {
@ -228,9 +228,9 @@ inline bool jsonSetFromOpt< unsigned >(
// 32-bit float specialization of the above
template< >
inline bool jsonSetFromOpt< float >(
__wr__ float& out ,
__rd__ T_JSONObject const& object ,
__rd__ char const* const key )
float& out ,
T_JSONObject const& object ,
char const* const key )
{
double const* ptr( jsonGetOpt< double >( object , key ) );
if ( ptr ) {
@ -241,16 +241,16 @@ inline bool jsonSetFromOpt< float >(
// Read a vector from a JSON array of numbers
void jsonGetVectorOpt(
__wr__ float* vector ,
__rd__ const size_t size ,
__rd__ T_JSONObject const& object ,
__rd__ char const* key );
float* vector ,
const size_t size ,
T_JSONObject const& object ,
char const* key );
// Read a GLM vec3 from a JSON array of numbers
inline void jsonGetVectorOpt(
__wr__ glm::vec3& vector ,
__rd__ T_JSONObject const& object ,
__rd__ char const* key )
glm::vec3& vector ,
T_JSONObject const& object ,
char const* 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.
template< typename T >
inline bool jsonLoadOpt(
__rw__ T& out ,
__rd__ T_JSONObject const& object ,
__rd__ char const* key )
T& out ,
T_JSONObject const& object ,
char const* key )
{
try {
auto const* sub( jsonGetOpt< T_JSONObject >( object , key ) );

View file

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

View file

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