demotool/utilities.hh

111 lines
2.5 KiB
C++
Raw Normal View History

2017-09-30 10:37:45 +02:00
#pragma once
#ifndef REAL_BUILD
# include "externals.hh"
#endif
/*= Utilities ================================================================*/
// Disable next ImGui button(s)
void disableButton( );
// Re-enable ImGui buttons
inline void reenableButtons( )
{
ImGui::PopStyleColor( 3 );
}
/*----------------------------------------------------------------------------*/
2017-10-02 13:51:08 +02:00
#define GL_CHECK( FAIL ) \
2017-10-01 18:51:02 +02:00
do { \
auto err_( glGetError( ) ); \
2017-10-02 13:51:08 +02:00
if ( err_ != GL_NO_ERROR ) FAIL; \
2017-10-01 18:51:02 +02:00
} while ( 0 )
2017-10-02 13:51:08 +02:00
#define GL_ASSERT( ) \
GL_CHECK({ \
fprintf( stderr , "GL error %x in %s:%d\n" , \
err_ , __FILE__ , __LINE__ ); \
abort( ); \
})
2017-10-01 18:51:02 +02:00
/*----------------------------------------------------------------------------*/
2017-09-30 10:37:45 +02:00
// Add some value to an angle, keeping it in [-180;180]
void updateAngle(
__rw__ float& initial ,
__rd__ const float delta
);
// Make a rotation matrix from three YPR angles (in degrees)
void anglesToMatrix(
__rd__ float const* angles ,
__wr__ float* matrix );
/*----------------------------------------------------------------------------*/
// Helpers for finding entries in collections
template< typename T , typename I >
inline auto find(
__rd__ T const& collection ,
__rd__ 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 )
{
return std::find( collection.begin( ) , collection.end( ) , item );
}
/*= T_FilesWatcher / T_WatchedFiles ==========================================*/
struct T_FilesWatcher;
struct T_WatchedFiles;
using F_OnFileChanges = std::function< void( void ) >;
struct T_FilesWatcher
{
friend struct T_WatchedFiles;
T_FilesWatcher( T_FilesWatcher const& ) = delete;
T_FilesWatcher( );
T_FilesWatcher( T_FilesWatcher&& ) noexcept;
~T_FilesWatcher( );
void check( );
private:
int fd;
std::vector< T_WatchedFiles* > watched;
};
/*----------------------------------------------------------------------------*/
struct T_WatchedFiles
{
friend struct T_FilesWatcher;
T_WatchedFiles( ) = delete;
T_WatchedFiles( T_WatchedFiles const& ) = delete;
T_WatchedFiles( T_WatchedFiles&& ) noexcept;
T_WatchedFiles(
__rw__ T_FilesWatcher& watcher ,
__rd__ const F_OnFileChanges callback );
~T_WatchedFiles( );
void clear( );
bool watch( __rd__ std::string const& file );
private:
T_FilesWatcher* watcher;
const F_OnFileChanges callback;
bool triggered;
std::vector< int > identifiers;
};