195 lines
4.1 KiB
C++
195 lines
4.1 KiB
C++
#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 );
|
|
}
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
// 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;
|
|
};
|
|
|
|
|
|
/*= T_ShaderCode =============================================================*/
|
|
|
|
struct T_ShaderCode
|
|
{
|
|
T_ShaderCode( ) = delete;
|
|
T_ShaderCode( T_ShaderCode const& ) = delete;
|
|
T_ShaderCode( T_ShaderCode&& ) = delete;
|
|
|
|
explicit T_ShaderCode( __rd__ const int nparts );
|
|
~T_ShaderCode( );
|
|
|
|
void setPart(
|
|
__rd__ const int index ,
|
|
__rd__ char const* const string );
|
|
void setPart(
|
|
__rd__ const int index ,
|
|
__rd__ void const* const data ,
|
|
__rd__ const int size );
|
|
bool loadPart(
|
|
__rd__ const int index ,
|
|
__rd__ std::string const& source ,
|
|
__rw__ std::vector< std::string >& errors );
|
|
|
|
GLuint createProgram(
|
|
__rd__ GLenum type ,
|
|
__rw__ std::vector< std::string >& errors ) const;
|
|
|
|
private:
|
|
std::vector< char* > code;
|
|
};
|
|
|
|
struct T_ShaderProgram
|
|
{
|
|
T_ShaderProgram( ) = delete;
|
|
T_ShaderProgram( T_ShaderProgram const& ) = delete;
|
|
T_ShaderProgram( T_ShaderProgram&& ) = delete;
|
|
|
|
T_ShaderProgram(
|
|
__rd__ GLenum programType ,
|
|
__rw__ T_FilesWatcher& watcher );
|
|
~T_ShaderProgram( );
|
|
|
|
void addChunk( __rd__ std::string const& string );
|
|
void addFile( __rd__ std::string const& source );
|
|
|
|
void load( );
|
|
bool activate( ) const;
|
|
|
|
private:
|
|
T_WatchedFiles files_;
|
|
|
|
std::vector< bool > chunksOrFiles_;
|
|
std::vector< std::string > parts_;
|
|
|
|
std::vector< std::string > errors_;
|
|
|
|
GLenum programType_;
|
|
GLuint program_;
|
|
};
|
|
|
|
|
|
/*= T_Camera =================================================================*/
|
|
|
|
struct T_Camera
|
|
{
|
|
glm::vec3 lookAt;
|
|
glm::vec3 angles;
|
|
float distance = 10;
|
|
float fov = 90;
|
|
|
|
// Everything below is updated by update()
|
|
glm::vec3 dir;
|
|
glm::vec3 up;
|
|
glm::vec3 pos;
|
|
float np;
|
|
|
|
T_Camera()
|
|
{ update( ); }
|
|
|
|
void handleDND(
|
|
__rd__ ImVec2 const& move ,
|
|
__rd__ const bool hasCtrl ,
|
|
__rd__ const bool hasShift ,
|
|
__rd__ const bool lmb // Left mouse button
|
|
);
|
|
void handleWheel(
|
|
__rd__ const float wheel ,
|
|
__rd__ const bool hasCtrl ,
|
|
__rd__ const bool hasShift
|
|
);
|
|
|
|
void makeUI( );
|
|
|
|
private:
|
|
glm::mat3x3 rotMat;
|
|
float rotationMatrix[ 9 ];
|
|
void update( );
|
|
};
|