diff --git a/Makefile b/Makefile index 80e936f..4434f8b 100644 --- a/Makefile +++ b/Makefile @@ -42,7 +42,7 @@ DEMO = \ IMGUI_OBJS = $(addprefix $(OUTDIR)/, $(addsuffix .o, $(basename $(IMGUI)))) DEMO_OBJS = $(addprefix $(OUTDIR)/, $(addsuffix .o, $(basename $(DEMO)))) OBJS = $(IMGUI_OBJS) $(DEMO_OBJS) -LIBEBCL = $(OUTDIR)/libebcorelib.a +LIBEBCL = $(OUTDIR)/ebcl/libebcorelib.a PCH=externals.hh.gch DEMO_DEPS = $(DEMO_OBJS:$(OUTDIR)/%.o=$(OUTDIR)/%.d) diff --git a/control.cc b/control.cc index eda72d8..3a354fb 100644 --- a/control.cc +++ b/control.cc @@ -122,14 +122,14 @@ void OPLoadVariable::execute( /*= OPLoadInput ==============================================================*/ OPLoadInput::OPLoadInput( - std::string const& input ) + T_String const& input ) : T_Op( OP_LOAD_VARIABLE ) , input( input ) { } void OPLoadInput::execute( T_Context& ctx ) const { - const auto i( Globals::Sync( ).inputPos( input.c_str( ) ) ); + const auto i( Globals::Sync( ).inputPos( input ) ); ctx.opStack.add( Globals::Sync( ).inputs( )[ i ] ); } diff --git a/control.hh b/control.hh index 002824e..e5a9272 100644 --- a/control.hh +++ b/control.hh @@ -180,10 +180,10 @@ namespace cops { struct OPLoadInput : public T_Op { explicit OPLoadInput( - std::string const& input ); + T_String const& input ); void execute( T_Context& ctx ) const override; - std::string input; + T_String input; }; struct OPStoreVariable : public T_Op diff --git a/ebcl-config b/ebcl-config index 561a76a..c1f8a13 100644 --- a/ebcl-config +++ b/ebcl-config @@ -6,7 +6,7 @@ DEBUG = n OPTIMIZE = y BUILD_TESTS = n -OUTDIR = ../output +OUTDIR = ../output/ebcl export BUILD_STATIC_LIB BUILD_DYNAMIC_LIB DEBUG OPTIMIZE BUILD_TESTS export OUTDIR diff --git a/filewatcher.cc b/filewatcher.cc index 683e7fb..03f60d6 100644 --- a/filewatcher.cc +++ b/filewatcher.cc @@ -43,28 +43,29 @@ void T_FilesWatcher::check( ) // Handle events from inotify inotify_event ie; while ( read( fd , &ie , sizeof( ie ) ) == sizeof( ie ) ) { - printf( "inotify wd %d / evt %x\n" , ie.wd , ie.mask ); fflush( stdout ); +// printf( "inotify wd %d / evt %x\n" , ie.wd , ie.mask ); fflush( stdout ); if ( ( ie.mask & ( IN_CLOSE_WRITE | IN_DELETE_SELF ) ) == 0 ) { - printf( " -> skipping this event\n" ); +// printf( " -> skipping this event\n" ); continue; } - const auto pos( inotify_.find( ie.wd ) ); - if ( pos == inotify_.end( ) ) { - printf( " -> no matching file\n" ); fflush( stdout ); + T_String const* name( inotify_.get( ie.wd ) ); + if ( !name ) { +// printf( " -> no matching file\n" ); fflush( stdout ); continue; } - printf( " -> file '%s'\n" , pos->second.c_str( ) ); + printf( " -> file '%s'\n" , name->toOSString( ).data( ) ); - auto& entry( fileWatchers_.find( pos->second )->second ); - entry.trigger( ); + auto* entry( fileWatchers_.get( *name ) ); + assert( entry ); + entry->trigger( ); if ( ( ie.mask & IN_DELETE_SELF ) != 0 ) { - printf( " -> deleted, added as missing\n" ); fflush( stdout ); - inotify_rm_watch( fd , entry.wd ); - missing_.push_back( pos->second ); - entry.wd = -2; - inotify_.erase( entry.wd ); + //printf( " -> deleted, added as missing\n" ); fflush( stdout ); + inotify_rm_watch( fd , entry->wd ); + missing_.add( *name ); + inotify_.remove( entry->wd ); + entry->wd = -2; } } @@ -72,15 +73,16 @@ void T_FilesWatcher::check( ) for ( auto it = missing_.begin( ) ; it < missing_.end( ) ; ++it ) { auto const& path( *it ); //printf( "Checking missing file '%s'\n" , path.c_str( ) ); fflush( stdout ); - const auto p( fileWatchers_.find( path ) ); + auto* const p( fileWatchers_.get( path ) ); //printf( " -> found? %c\n" , p != fileWatchers_.end( ) ? 'Y' : 'N' ); - assert( p != fileWatchers_.end( ) ); + assert( p ); //printf( " -> wd = %d\n" , p->second.wd ); - assert( p->second.wd < 0 ); - auto& we( p->second ); + assert( p->wd < 0 ); + auto& we( *p ); - const auto nwd( inotify_add_watch( fd , path.c_str( ) , - IN_CLOSE_WRITE | IN_DELETE_SELF ) ); + const auto nwd( inotify_add_watch( fd , + (char*) path.toOSString( ).data( ) , + IN_CLOSE_WRITE | IN_DELETE_SELF ) ); //printf( " -> inotify add watch %d\n" , nwd ); fflush( stdout ); if ( nwd < 0 ) { //printf( " -> still missing\n" ); fflush( stdout ); @@ -96,8 +98,9 @@ void T_FilesWatcher::check( ) // Update cache we.wd = nwd; - missing_.erase( it ); - inotify_.emplace( nwd , path ); + inotify_.add( nwd , path ); + missing_.remove( it.pos( ) ); + it --; } } @@ -114,55 +117,61 @@ void T_FilesWatcher::T_File_::trigger( ) } void T_FilesWatcher::watchFile( - __rd__ std::string const& path , - __rd__ T_WatchedFiles* const watcher ) + T_String const& path , + T_WatchedFiles* const watcher ) { //printf( "creating watch on '%s' for watcher %p\n" , path.c_str( ) , watcher ); fflush( stdout ); - auto const exFilePos( fileWatchers_.find( path ) ); - if ( exFilePos != fileWatchers_.end( ) ) { + auto* const exFilePos( fileWatchers_.get( path ) ); + if ( exFilePos ) { //printf( " -> existing\n" ); fflush( stdout ); - auto& wl( exFilePos->second.watchers ); - if ( !Contains( wl , watcher ) ) { - wl.push_back( watcher ); + auto& wl( exFilePos->watchers ); + if ( !wl.contains( watcher ) ) { + wl.add( watcher ); } } else { T_File_ f; - f.wd = inotify_add_watch( fd , path.c_str( ) , + f.wd = inotify_add_watch( fd , (char*) path.toOSString( ).data( ) , IN_CLOSE_WRITE | IN_DELETE_SELF ); //printf( " -> inotify wd %d\n" , f.wd ); fflush( stdout ); if ( f.wd == -1 ) { - missing_.push_back( path ); + missing_.add( path ); //printf( " -> missing\n" ); fflush( stdout ); } else { - inotify_.emplace( f.wd , path ); + inotify_.add( f.wd , path ); //printf( " -> found\n" ); fflush( stdout ); } - f.watchers.push_back( watcher ); - fileWatchers_.emplace( path , std::move( f ) ); + f.watchers.add( watcher ); + fileWatchers_.add( path , std::move( f ) ); } } void T_FilesWatcher::unwatchAll( - __rd__ T_WatchedFiles* const watcher ) + T_WatchedFiles* const watcher ) { - for ( auto& entry : fileWatchers_ ) { - auto& wl( entry.second.watchers ); - const auto pos( find( wl , watcher ) ); - if ( pos == wl.end( ) ) { + for ( auto i = 0u ; i < fileWatchers_.size( ) ; ) { + auto const& path( fileWatchers_.keys( )[ i ] ); + auto& fw( *fileWatchers_.get( path ) ); + auto& wl( fw.watchers ); + const auto pos( wl.indexOf( watcher ) ); + if ( pos == -1 ) { + i ++; continue; } - wl.erase( pos ); + + wl.remove( pos ); if ( wl.empty( ) ) { - const auto wd( entry.second.wd ); + const auto wd( fw.wd ); if ( wd < 0 ) { - auto const pos( find( missing_ , entry.first ) ); - assert( pos != missing_.end( ) ); - missing_.erase( pos ); + auto const pos( missing_.indexOf( path ) ); + assert( pos != -1 ); + missing_.remove( pos ); } else { inotify_rm_watch( fd , wd ); - inotify_.erase( wd ); + inotify_.remove( wd ); } - fileWatchers_.erase( entry.first ); + fileWatchers_.remove( path ); + } else { + i ++; } } } @@ -181,18 +190,18 @@ T_WatchedFiles::T_WatchedFiles( T_WatchedFiles&& other ) noexcept } T_WatchedFiles::T_WatchedFiles( - __rw__ T_FilesWatcher& watcher , - __rd__ const F_OnFileChanges callback ) + T_FilesWatcher& watcher , + const F_OnFileChanges callback ) : watcher( &watcher ) , callback( callback ) , triggered( false ) { - watcher.watched_.push_back( this ); + watcher.watched_.add( this ); } T_WatchedFiles::~T_WatchedFiles( ) { if ( watcher ) { watcher->unwatchAll( this ); - watcher->watched_.erase( find( watcher->watched_ , this ) ); + watcher->watched_.remove( watcher->watched_.indexOf( this ) ); } } @@ -204,7 +213,7 @@ void T_WatchedFiles::clear( ) } bool T_WatchedFiles::watch( - __rd__ std::string const& file ) + T_String const& file ) { if ( !watcher ) { return false; diff --git a/filewatcher.hh b/filewatcher.hh index 18f32e3..de87294 100644 --- a/filewatcher.hh +++ b/filewatcher.hh @@ -32,19 +32,19 @@ struct T_FilesWatcher private: struct T_File_ { int wd; - std::vector< T_WatchedFiles* > watchers; + T_Array< T_WatchedFiles* > watchers; void trigger( ); }; int fd; - std::map< std::string , T_File_ > fileWatchers_; - std::map< int , std::string > inotify_; - std::vector< std::string > missing_; - std::vector< T_WatchedFiles* > watched_; + T_KeyValueTable< T_String , T_File_ > fileWatchers_; + T_KeyValueTable< int , T_String > inotify_; + T_Array< T_String > missing_; + T_Array< T_WatchedFiles* > watched_; - void watchFile( __rd__ std::string const& path , - __rd__ T_WatchedFiles* const watcher ); - void unwatchAll( __rd__ T_WatchedFiles* const watcher ); + void watchFile( T_String const& path , + T_WatchedFiles* const watcher ); + void unwatchAll( T_WatchedFiles* const watcher ); }; /*----------------------------------------------------------------------------*/ @@ -58,17 +58,17 @@ struct T_WatchedFiles T_WatchedFiles( T_WatchedFiles&& ) noexcept; T_WatchedFiles( - __rw__ T_FilesWatcher& watcher , - __rd__ const F_OnFileChanges callback ); + T_FilesWatcher& watcher , + const F_OnFileChanges callback ); ~T_WatchedFiles( ); void clear( ); - bool watch( __rd__ std::string const& file ); + bool watch( T_String const& file ); private: T_FilesWatcher* watcher; const F_OnFileChanges callback; bool triggered; }; -using P_WatchedFiles = std::unique_ptr< T_WatchedFiles >; +using P_WatchedFiles = T_OwnPtr< T_WatchedFiles >; diff --git a/shaders.cc b/shaders.cc index 3ecbe77..7f59eae 100644 --- a/shaders.cc +++ b/shaders.cc @@ -823,7 +823,9 @@ void T_ShaderManager::initProgram( } ); for ( auto entry : code.files ) { if ( entry.second ) { - program.watch->watch( "shaders/" + entry.first ); + ebcl::T_StringBuilder sb( "shaders/" ); + sb << entry.first.c_str( ); + program.watch->watch( std::move( sb ) ); } else { missing_[ entry.first ].insert( name ); } diff --git a/sync.cc b/sync.cc index b05e4f0..6df752a 100644 --- a/sync.cc +++ b/sync.cc @@ -253,7 +253,7 @@ void T_SyncManager::checkCurveFile( ) printf( "CURVE INIT\n" ); bool missing; if ( loadCurves_( missing ) || !missing ) { - watcher_ = std::make_unique< T_WatchedFiles >( + watcher_ = NewOwned< T_WatchedFiles >( Globals::Watcher( ) , [this] { curvesChanged_( ); } ); watcher_->watch( "curves.json" ); @@ -278,7 +278,7 @@ void T_SyncManager::curvesChanged_( ) { bool missing; if ( !loadCurves_( missing ) && missing ) { - watcher_.reset( ); + watcher_.clear( ); } } @@ -381,7 +381,7 @@ bool T_SyncManager::loadCurvesData_( bool T_SyncManager::loadSegmentData_( T_SyncSegment& segment , - std::string const& curve , + T_String const& curve , T_JSONObject const& sd ) { auto const& sType( jsonGet< std::string >( sd , "type" ) ); @@ -389,7 +389,7 @@ bool T_SyncManager::loadSegmentData_( const auto p( SegmentTypes_.find( sType ) ); if ( p == SegmentTypes_.end( ) ) { printf( "Curves data: curve '%s': invalid segment type '%s'\n" , - curve.c_str( ) , sType.c_str( ) ); + curve.toOSString( ).data( ) , sType.c_str( ) ); return false; } segment.type = p->second; @@ -399,19 +399,19 @@ bool T_SyncManager::loadSegmentData_( if ( vList.size( ) < 2 ) { printf( "Curves data: curve '%s': segment doesn't have enough values\n" , - curve.c_str( ) ); + curve.toOSString( ).data( ) ); return false; } if ( vList.size( ) != dList.size( ) + 1 ) { printf( "Curves data: curve '%s': segment values / durations count mismatch\n" , - curve.c_str( ) ); + curve.toOSString( ).data( ) ); return false; } for ( auto const& vv : vList ) { if ( !vv.is< double >( ) ) { printf( "Curves data: curve '%s': non-numeric entry in segment values\n" , - curve.c_str( ) ); + curve.toOSString( ).data( ) ); return false; } segment.values.add( vv.get< double >( ) ); @@ -420,14 +420,14 @@ bool T_SyncManager::loadSegmentData_( for ( auto const& dv : dList ) { if ( !dv.is< double >( ) ) { printf( "Curves data: curve '%s': non-numeric entry in segment durations\n" , - curve.c_str( ) ); + curve.toOSString( ).data( ) ); return false; } const double dvn( dv.get< double >( ) ); if ( fmod( dvn , 1.0 ) != 0.0 || dvn <= 0 ) { printf( "Curves data: curve '%s': invalid segment duration %f\n" , - curve.c_str( ) , dvn ); + curve.toOSString( ).data( ) , dvn ); return false; } segment.durations.add( dvn ); diff --git a/sync.hh b/sync.hh index 8dce18a..cf7b16d 100644 --- a/sync.hh +++ b/sync.hh @@ -184,9 +184,9 @@ struct T_SyncManager void clearInputs( ) { values_.clear( ); } - bool addInput( std::string const& name , + bool addInput( T_String const& name , const float initial = 0.f ) noexcept - { return values_.addValue( name.c_str( ) , initial ); } + { return values_.addValue( name , initial ); } uint32_t inputPos( T_String const& name ) const noexcept { return values_.indexOf( name ); } @@ -208,7 +208,7 @@ struct T_SyncManager picojson::value const& root ); bool loadSegmentData_( T_SyncSegment& segment , - std::string const& curve , + T_String const& curve , T_JSONObject const& sd ); // ---------------------------------------------------------------------