Adaptations to changes in corelib

This commit is contained in:
Emmanuel BENOîT 2017-11-08 09:09:21 +01:00
parent 14288e3c87
commit c093ba2213
7 changed files with 53 additions and 195 deletions

2
ebcl

@ -1 +1 @@
Subproject commit 3adfdadd119f2783877865a8365a29d4b567911f Subproject commit 0bc11d32d746f1075a41137adff51819007d5275

32
main.cc
View file

@ -54,7 +54,7 @@ void T_Main::mainLoop( )
{ {
auto& p( Globals::Profiler( ) ); auto& p( Globals::Profiler( ) );
while ( !done ) { while ( !done ) {
if ( demo.present( ) ) { if ( demo ) {
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;
@ -67,7 +67,7 @@ void T_Main::mainLoop( )
demo.clear( ); demo.clear( );
} }
} }
if ( !demo.present( ) ) { if ( !demo ) {
initDemo( ); initDemo( );
} }
@ -100,7 +100,7 @@ T_Main::~T_Main( )
void T_Main::initDemo( ) void T_Main::initDemo( )
{ {
assert( !demo.present( ) ); assert( !demo );
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;
@ -108,7 +108,7 @@ void T_Main::initDemo( )
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.setNew( dspSize.x , dspSize.y ); demo.setNew( dspSize.x , dspSize.y );
if ( ((T_Demo&)demo).initialise( ) ) { if ( demo->initialise( ) ) {
Globals::Profiler( ).clear( ); Globals::Profiler( ).clear( );
} else { } else {
demo.clear( ); demo.clear( );
@ -155,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.present( ) ) { if ( demo ) {
demo.target( )->handleDND( mouseMove , ctrl , shift , lmb ); demo->handleDND( mouseMove , ctrl , shift , lmb );
} }
} else if ( appCanGrab && mb ) { } else if ( appCanGrab && mb ) {
capture = true; capture = true;
@ -166,8 +166,8 @@ void T_Main::handleCapture( )
ImGui::SetMouseCursor( ImGuiMouseCursor_Move ); ImGui::SetMouseCursor( ImGuiMouseCursor_Move );
} }
if ( ( appCanGrab || capture ) && io.MouseWheel && demo.present( ) ) { if ( ( appCanGrab || capture ) && io.MouseWheel && demo ) {
demo.target( )->handleWheel( io.MouseWheel , ctrl , shift ); demo->handleWheel( io.MouseWheel , ctrl , shift );
} }
} }
@ -183,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.present( ) ) { if ( demo ) {
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.target( )->playing = demo.target( )->playing && ! sync.finished( ); demo->playing = demo->playing && ! sync.finished( );
} }
ImGui::SameLine( ); ImGui::SameLine( );
if ( ImGui::Button( demo.target( )->playing ? "Stop" : "Play" ) ) { if ( ImGui::Button( demo->playing ? "Stop" : "Play" ) ) {
demo.target( )->playing = !demo.target( )->playing; demo->playing = !demo->playing;
} }
} }
ImGui::End( ); ImGui::End( );
if ( demo.present( ) && demoCtrl_ ) { if ( demo && demoCtrl_ ) {
demo.target( )->makeUI( ); demo->makeUI( );
} }
Globals::Profiler( ).makeUI( ); Globals::Profiler( ).makeUI( );
@ -211,9 +211,9 @@ void T_Main::makeUI( )
void T_Main::render( ) void T_Main::render( )
{ {
if ( demo.present( ) ) { if ( demo ) {
Globals::Profiler( ).start( "Render" ); Globals::Profiler( ).start( "Render" );
demo.target( )->render( ); demo->render( );
glFinish( ); Globals::Profiler( ).end( "Render" ); glFinish( ); Globals::Profiler( ).end( "Render" );
Globals::Profiler( ).start( "Debug" ); Globals::Profiler( ).start( "Debug" );

View file

@ -491,7 +491,7 @@ void T_ParserImpl_::parseFunction(
fn->location( ) = fw.location( ); fn->location( ) = fw.location( );
const auto af( root->addFunction( fn ) ); const auto af( root->addFunction( fn ) );
if ( af.dupLocation.present( ) ) { if ( af.dupLocation ) {
T_StringBuilder esb( "duplicate " ); T_StringBuilder esb( "duplicate " );
switch ( fn->type( ) ) { switch ( fn->type( ) ) {
case A_Node::DECL_FN: case A_Node::DECL_FN:
@ -505,7 +505,7 @@ void T_ParserImpl_::parseFunction(
break; break;
default: std::abort( ); default: std::abort( );
} }
esb << "; previous declaration: " << *af.dupLocation.target( ); esb << "; previous declaration: " << *af.dupLocation;
errors.addNew( std::move( esb ) , fw.location( ) ); errors.addNew( std::move( esb ) , fw.location( ) );
} }
@ -527,10 +527,10 @@ void T_ParserImpl_::parseFunctionArguments(
} }
const auto rv( function.addArgument( token ) ); const auto rv( function.addArgument( token ) );
if ( rv.present( ) ) { if ( rv ) {
T_StringBuilder esb; T_StringBuilder esb;
esb << "duplicate argument '" << token.stringValue( ) esb << "duplicate argument '" << token.stringValue( )
<< "'; previous declaration: " << *rv.target( ); << "'; previous declaration: " << *rv;
errors.addNew( std::move( esb ) , token.location( ) ); errors.addNew( std::move( esb ) , token.location( ) );
} }
} }
@ -708,10 +708,9 @@ M_INSTR_( Pipeline )
continue; continue;
} }
const auto dup( pipeline.addProgram( tok ) ); const auto dup( pipeline.addProgram( tok ) );
if ( dup.present( ) ) { if ( dup ) {
T_StringBuilder esb; T_StringBuilder esb;
esb << "duplicate program identifier; previous use: " esb << "duplicate program identifier; previous use: " << *dup;
<< *dup.target( );
errors.addNew( std::move( esb ) , tok.location( ) ); errors.addNew( std::move( esb ) , tok.location( ) );
} }
} }

View file

@ -2,6 +2,7 @@
#include "opast.hh" #include "opast.hh"
#include <ebcl/Files.hh> #include <ebcl/Files.hh>
#include <ebcl/SRDText.hh> #include <ebcl/SRDText.hh>
#include <ebcl/Algorithms.hh>
using namespace ebcl; using namespace ebcl;
using namespace opast; using namespace opast;
@ -36,148 +37,6 @@ void WriteSRDError(
/*============================================================================*/ /*============================================================================*/
// FIXME TESTING, MOVE THIS LATER // FIXME TESTING, MOVE THIS LATER
template<
typename Enum ,
typename Storage = uint32_t
> class T_Flags
{
private:
Storage flags_;
public:
constexpr T_Flags( ) noexcept
: flags_( 0 ) {}
constexpr T_Flags( T_Flags const& other ) noexcept
: flags_( other.flags_ ) { }
constexpr T_Flags( const Enum flag ) noexcept
: flags_( 1 << int( flag ) ) {}
constexpr T_Flags( std::initializer_list< Enum > flags ) noexcept
: flags_( 0 )
{
for ( auto f : flags ) {
flags_ |= ( 1 << int( f ) );
}
}
explicit constexpr T_Flags( const Storage flags ) noexcept
: flags_( flags ) { }
constexpr T_Flags operator |=( T_Flags other ) noexcept
{ flags_ |= other.flags_; return *this; }
constexpr T_Flags operator &=( T_Flags other ) noexcept
{ flags_ &= other.flags_; return *this; }
constexpr T_Flags operator ^=( T_Flags other ) noexcept
{ flags_ ^= other.flags_; return *this; }
constexpr T_Flags operator ~( ) const noexcept
{ return T_Flags( ~flags_ ); }
constexpr T_Flags operator &( T_Flags other ) const noexcept
{ return T_Flags( flags_ & other.flags_ ); }
constexpr T_Flags operator |( T_Flags other ) const noexcept
{ return T_Flags( flags_ & other.flags_ ); }
constexpr T_Flags operator ^( T_Flags other ) const noexcept
{ return T_Flags( flags_ ^ other.flags_ ); }
constexpr operator bool( ) const noexcept
{ return flags_ != 0; }
constexpr bool operator!( ) const noexcept
{ return flags_ == 0; }
explicit constexpr operator Storage( ) const noexcept
{ return flags_; }
constexpr bool operator ==( const T_Flags other ) const noexcept
{ return flags_ == other.flags_; }
constexpr bool operator !=( const T_Flags other ) const noexcept
{ return flags_ != other.flags_; }
constexpr bool isSet( const T_Flags value ) const noexcept
{ return ( *this & value ) == value; }
constexpr bool isClear( const T_Flags value ) const noexcept
{ return !( *this & value ); }
};
template< typename NodeType >
class T_Visitor
{
public:
using T_Node = NodeType;
// Node browser. Returns the Nth child of the specified node, or null
// if there are no children left.
using F_NodeBrowser = std::function< T_Node*( T_Node& , uint32_t ) >;
// Node action. Second parameter indicates whether the action is
// being called before (false) or after (true) visiting the children.
using F_NodeAction = std::function< bool( T_Node& , bool ) >;
private:
enum E_State_ {
BEFORE , CHILDREN , AFTER
};
struct T_NodeRef_ {
T_Node* node;
uint32_t child;
E_State_ state{ BEFORE };
explicit T_NodeRef_( T_Node* node )
: node( node ) , child( 0 ) {}
explicit T_NodeRef_( T_Node* node , uint32_t child )
: node( node ) , child( child ) {}
};
F_NodeBrowser nodeBrowser_;
T_Array< T_NodeRef_ > stack_;
public:
T_Visitor( ) = delete;
T_Visitor( T_Visitor const& ) = default;
T_Visitor( T_Visitor&& ) noexcept = default;
explicit T_Visitor( F_NodeBrowser browser ) noexcept;
void visit( T_Node& root , F_NodeAction action );
};
template< typename T >
inline T_Visitor< T >::T_Visitor(
F_NodeBrowser browser ) noexcept
: nodeBrowser_( std::move( browser ) )
{ }
template< typename T >
inline void T_Visitor< T >::visit(
T_Node& root ,
F_NodeAction action )
{
stack_.addNew( &root , 0 );
while ( !stack_.empty( ) ) {
auto& n( stack_.last( ) );
switch ( n.state ) {
case BEFORE:
n.state = action( *n.node , false ) ? CHILDREN : AFTER;
break;
case CHILDREN: {
T_Node* child( nodeBrowser_( *n.node , n.child ++ ) );
if ( child ) {
stack_.addNew( child , 0 );
} else {
n.state = AFTER;
}
break;
}
case AFTER:
action( *n.node , true );
stack_.removeLast( );
break;
}
}
}
A_Node* OpASTBrowser( A_Node* OpASTBrowser(
A_Node& node , A_Node& node ,
const uint32_t child ) const uint32_t child )
@ -372,13 +231,13 @@ bool checkCalls( T_RootNode& root )
return false; return false;
} }
T_Visitor< uint32_t > callGraphVisitor( T_Visitor< uint32_t , uint32_t > callGraphVisitor(
[&]( uint32_t& v , uint32_t child ) -> uint32_t* { [&]( uint32_t v , uint32_t child ) -> T_Optional< uint32_t > {
const uint32_t nc( calls.sizeOf( v ) ); const uint32_t nc( calls.sizeOf( v ) );
if ( child < nc ) { if ( child < nc ) {
return &calls.get( v , child ); return calls.get( v , child );
} }
return nullptr; return {};
} ); } );
enum class E_CallInfo_ { enum class E_CallInfo_ {
INIT_CHECKED , FRAME_CHECKED , INIT_CHECKED , FRAME_CHECKED ,
@ -387,16 +246,16 @@ bool checkCalls( T_RootNode& root )
using T_CallInfo_ = T_Flags< E_CallInfo_ , uint8_t >; using T_CallInfo_ = T_Flags< E_CallInfo_ , uint8_t >;
T_CallInfo_ callInfo[ calls.size( ) ]; T_CallInfo_ callInfo[ calls.size( ) ];
uint32_t initId( root.functionIndex( "*init*" ) ); callGraphVisitor.visit( root.functionIndex( "*init*" ) ,
callGraphVisitor.visit( initId , [&]( uint32_t& id , const bool exit ) -> bool { [&]( uint32_t id , const bool exit ) -> bool {
if ( exit || callInfo[ id ] & E_CallInfo_::INIT_CALLED ) { if ( exit || callInfo[ id ] & E_CallInfo_::INIT_CALLED ) {
return false; return false;
} }
callInfo[ id ] |= E_CallInfo_::INIT_CALLED; callInfo[ id ] |= E_CallInfo_::INIT_CALLED;
return true; return true;
} ); } );
uint32_t frameId( root.functionIndex( "*frame*" ) ); callGraphVisitor.visit( root.functionIndex( "*frame*" ) ,
callGraphVisitor.visit( frameId , [&]( uint32_t& id , const bool exit ) -> bool { [&]( uint32_t id , const bool exit ) -> bool {
if ( exit || callInfo[ id ] & E_CallInfo_::FRAME_CALLED ) { if ( exit || callInfo[ id ] & E_CallInfo_::FRAME_CALLED ) {
return false; return false;
} }

View file

@ -19,7 +19,7 @@ T_RendertargetSetup& T_RendertargetSetup::add(
T_RendertargetSetup& T_RendertargetSetup::depth( T_RendertargetSetup& T_RendertargetSetup::depth(
__rw__ T_Texture& texture ) __rw__ T_Texture& texture )
{ {
assert( !depthAttachment_.present( ) ); assert( !depthAttachment_ );
checkAttachment( texture , 0 ); checkAttachment( texture , 0 );
depthAttachment_.setNew( texture , 0 ); depthAttachment_.setNew( texture , 0 );
return *this; return *this;
@ -65,8 +65,8 @@ T_Rendertarget T_RendertargetSetup::create( )
colorAttachments_[ i ].texture->id( ) , colorAttachments_[ i ].texture->id( ) ,
colorAttachments_[ i ].level ); colorAttachments_[ i ].level );
} }
if ( depthAttachment_.present( ) ) { if ( depthAttachment_ ) {
T_Attachment_ const& de( depthAttachment_ ); T_Attachment_ const& de( *depthAttachment_ );
glFramebufferTexture( GL_FRAMEBUFFER , glFramebufferTexture( GL_FRAMEBUFFER ,
GL_DEPTH_ATTACHMENT , GL_DEPTH_ATTACHMENT ,
de.texture->id( ) , de.texture->id( ) ,

View file

@ -949,8 +949,8 @@ void T_ShaderManager::programUpdated(
void T_ShaderManager::resetProgram( void T_ShaderManager::resetProgram(
T_Program_& program ) T_Program_& program )
{ {
if ( program.watch.present( ) ) { if ( program.watch ) {
program.watch.clear( ); program.watch->clear( );
} }
if ( program.id != 0 ) { if ( program.id != 0 ) {
glDeleteProgram( program.id ); glDeleteProgram( program.id );

View file

@ -99,8 +99,8 @@ bool CPSegmentVD_( T_SRDParserData const& data )
{ {
auto const& input( *data.input ); auto const& input( *data.input );
const auto ev( data.config.enumValue( "segment-type" , input[ 1 ].stringValue( ) ) ); const auto ev( data.config.enumValue( "segment-type" , input[ 1 ].stringValue( ) ) );
assert( ev.present( ) ); assert( ev );
CPHandleSegment_( (T_SyncSegment::E_SegmentType) *ev.target( ) , CPHandleSegment_( (T_SyncSegment::E_SegmentType) *ev ,
input[ 2 ].list( ) , input[ 3 ].list( ) , input[ 2 ].list( ) , input[ 3 ].list( ) ,
data.errors , data.targetData->value< T_SyncCurve >( ) ); data.errors , data.targetData->value< T_SyncCurve >( ) );
return true; return true;
@ -110,8 +110,8 @@ bool CPSegmentDV_( T_SRDParserData const& data )
{ {
auto const& input( *data.input ); auto const& input( *data.input );
const auto ev( data.config.enumValue( "segment-type" , input[ 1 ].stringValue( ) ) ); const auto ev( data.config.enumValue( "segment-type" , input[ 1 ].stringValue( ) ) );
assert( ev.present( ) ); assert( ev );
CPHandleSegment_( (T_SyncSegment::E_SegmentType) *ev.target( ) , CPHandleSegment_( (T_SyncSegment::E_SegmentType) *ev ,
input[ 3 ].list( ) , input[ 2 ].list( ) , input[ 3 ].list( ) , input[ 2 ].list( ) ,
data.errors , data.targetData->value< T_SyncCurve >( ) ); data.errors , data.targetData->value< T_SyncCurve >( ) );
return true; return true;