42 #ifndef INCLUDED_GLS_RUNTIME_UTIL_H
43 #define INCLUDED_GLS_RUNTIME_UTIL_H
69 #if defined( LINUX ) || defined( __VXWORKS__ ) || defined( __APPLE__ ) || defined( QNX )
74 # include <android/asset_manager.h>
77 #if defined( _MSC_VER )
79 # pragma warning( disable : 4786 )
82 const int DIALOG_MAX_DIRECTORY_LENGTH = 1024;
101 # define strcasecmp( x, y ) _stricmp( x, y )
108 #define PARSER_CLEARSTRING_DELIMETER_START "#$STRING_START$#"
109 #define PARSER_CLEARSTRING_DELIMETER_END "#$STRING_END$#"
112 # define M_PI 3.14159265358979323846
116 #define DEG_TO_RAD ( M_PI / 180.0 )
119 #define RAD_TO_DEG ( 180.0 / M_PI )
121 #define HIT_TOLERANCE 5.0
124 #define BETWEEN( x, x1, x2 ) ( ( ( ( x ) >= ( x1 ) ) && ( ( x ) <= ( x2 ) ) ) || ( ( ( x ) >= ( x2 ) ) && ( ( x ) <= ( x1 ) ) ) )
127 #define IS_NEGATIVE( x ) ( ( fabs( x ) > 0.0001 ) ? ( x < 0.0 ) : 0 )
130 #define IS_POSITIVE( x ) ( ( fabs( x ) > 0.0001 ) ? ( x > 0.0 ) : 0 )
133 #define CloseToZero( x ) ( fabs( ( x ) ) < 0.1 )
136 #define VeryCloseToZero( x ) ( fabs( ( x ) ) < 0.0001 )
139 #define IS_ZERO( x ) ( fabs( ( x ) ) < 0.001 )
143 # define MIN( A, B ) ( ( A ) < ( B ) ? ( A ) : ( B ) )
148 # define MAX( A, B ) ( ( A ) > ( B ) ? ( A ) : ( B ) )
157 GLS_EXPORT
bool gltIsExtSupported(
const char* extension );
162 # define GLSTUDIO_CLAMP_TO_EDGE ( OpenGLVersion() >= 1.2f ? 0x812F : GL_CLAMP )
164 # define GLSTUDIO_CLAMP_TO_EDGE GL_CLAMP_TO_EDGE
192 if( ( index < 0 ) || ( index >= GLS_COLOR_MAX ) )
193 return glsDefinedColors[ 0 ];
195 return glsDefinedColors[ index ];
202 unsigned char alpha )
204 if( ( index >= 0 ) && ( index < GLS_COLOR_MAX ) )
206 glsDefinedColors[ index ][ 0 ] = red;
207 glsDefinedColors[ index ][ 1 ] = green;
208 glsDefinedColors[ index ][ 2 ] = blue;
209 glsDefinedColors[ index ][ 3 ] = alpha;
225 template<
class T1,
class T2>
226 bool Equal( T1 x, T2 y,
float precision = 0.001f )
228 return ( x - precision ) <= y && y <= ( x + precision );
237 const T&
Min(
const T& x,
const T& y )
239 return x < y ? x : y;
248 const T&
Max(
const T& x,
const T& y )
250 return x < y ? y : x;
258 template<
class T,
class Pred>
259 const T&
Min(
const T& x,
const T& y, Pred pr )
261 return pr( x, y ) ? x : y;
269 template<
class T,
class Pred>
270 const T&
Max(
const T& x,
const T& y, Pred pr )
272 return pr( x, y ) ? y : x;
311 template<
class T,
bool TypeIsSimple>
318 unsigned int size() {
return array.
Count(); }
320 void push(
const T& item )
322 array[ array.
Count() ] = item;
328 return array[ array.
Count() - 1 ];
333 if( array.
Count() > 0 )
367 rotation_scaling( 0, 0 ) = new_i.x;
368 rotation_scaling( 0, 1 ) = new_j.x;
369 rotation_scaling( 0, 2 ) = new_k.x;
370 rotation_scaling( 1, 0 ) = new_i.y;
371 rotation_scaling( 1, 1 ) = new_j.y;
372 rotation_scaling( 1, 2 ) = new_k.y;
373 rotation_scaling( 2, 0 ) = new_i.z;
374 rotation_scaling( 2, 1 ) = new_j.z;
375 rotation_scaling( 2, 2 ) = new_k.z;
378 rotation_scaling.
Invert();
381 return rotation_scaling * transform;
387 GlsMatrixAffine<T> transform;
388 GlsMatrixAffine<T> rotation_scaling;
392 transform.Translate( -new_origin );
396 rotation_scaling( 0, 0 ) = new_i.x;
397 rotation_scaling( 0, 1 ) = new_j.x;
398 rotation_scaling( 0, 2 ) = new_k.x;
399 rotation_scaling( 1, 0 ) = new_i.y;
400 rotation_scaling( 1, 1 ) = new_j.y;
401 rotation_scaling( 1, 2 ) = new_k.y;
402 rotation_scaling( 2, 0 ) = new_i.z;
403 rotation_scaling( 2, 1 ) = new_j.z;
404 rotation_scaling( 2, 2 ) = new_k.z;
407 rotation_scaling.Invert();
410 result = rotation_scaling * transform;
475 int& index1,
int& index2,
int& index3,
476 bool isVectorArray =
true );
499 GLS_EXPORT
int EncodeString(
char* dest,
const char* src,
const int dest_str_length );
505 GLS_EXPORT std::string
EncodeString(
const std::string& src );
518 GLS_EXPORT
int C_EncodeString(
char* dest,
const char* src,
const int dest_str_length );
532 GLS_EXPORT
int DecodeString(
char* dest,
const char* src,
const int dest_str_length );
538 GLS_EXPORT std::string
DecodeString(
const std::string& src );
546 unsigned char* pixels;
549 GLS_EXPORT
char* MakeRelativePath(
const char* originalPath,
const char* relativePath );
550 GLS_EXPORT
void ConvertBackslashToSlash(
char* str );
551 GLS_EXPORT
void ConvertBackslashToSlash( std::string& str );
568 GLS_EXPORT
int range_check(
int num,
double val, ... );
577 GLS_EXPORT
int Safe_fopen(
const char* filename,
char* flags, FILE** f );
579 GLS_EXPORT
int Safe_fopen(
const char* filename,
char* flags, std::fstream& outstr );
588 GLS_EXPORT
void EnableDirectAssetLoading(
bool enableDirectAssetLoading );
596 GLS_EXPORT
bool HasAssetExtension(
const char* filename );
604 GLS_EXPORT
bool AssetExists(
const char* filename );
611 GLS_EXPORT
void SetAssetManager( AAssetManager* assetManager );
614 #if defined( ANDROID ) || defined( __APPLE__ ) || ( defined( LINUX ) && defined( GLES ) ) || defined( QNX ) || defined( INTEGRITY )
620 GLS_EXPORT std::string
ResolvePath(
const char* filename_ );
626 GLS_EXPORT
void SetResourcePath(
const char* resourcePath );
637 GLS_EXPORT FILE*
gls_fopen(
const char* filename,
const char* flags );
662 GLS_EXPORT std::string
ResolvePath(
const char* path );
665 inline std::string
ResolvePath(
const std::string& path )
676 GLS_EXPORT FILE*
gls_fopen(
const char* filename,
const char* flags );
686 GLS_EXPORT std::string GetAbsolutePathAndFileNameInDefaultResourceBundle(
const char* fileName );
699 GLS_EXPORT
bool FileExists(
const char* filename );
700 GLS_EXPORT
bool FileExists(
const std::string& filename );
705 GLS_EXPORT
bool IsDirectory(
const char* filename );
706 GLS_EXPORT
bool IsDirectory(
const std::string& filename );
711 GLS_EXPORT std::string
FileExtension(
const std::string& filepath );
716 GLS_EXPORT std::string
FileName(
const std::string& filepath );
722 GLS_EXPORT std::string
FilePath(
const std::string& filepath );
730 GLS_EXPORT
const char*
GetFilePath(
const char* name );
756 GLS_EXPORT
char*
PathToOS(
const char* path );
763 GLS_EXPORT std::string
GetExtension(
const std::string& filename );
769 GLS_EXPORT
const char*
GetBaseName(
const char* path );
803 GLS_EXPORT
bool ContainsNonBlank(
const std::string& val );
805 GLS_EXPORT
bool GetNoSpaces( FILE* f,
char* result,
int maxLen );
806 GLS_EXPORT
bool GetToEnd( std::istream& instr, std::string& result,
bool decode );
807 GLS_EXPORT
bool GetVertex( std::istream& instr, Vertex* vert,
bool getColor );
812 GLS_EXPORT
bool GetComponentClassNames(
const char* dllFileName, DynamicArray<std::string, false>& nameList,
const char* createClassTag =
"CreateComponent_" );
828 #if !defined( GLES ) || defined( GLES_ANGLE )
829 GLS_EXPORT
bool OpenFileDialog( Fl_Window* win,
char* filePath,
unsigned int filePathSize,
830 char* directory = NULL,
const char* filterStr = NULL,
831 const char* defaultExt = NULL,
const char* title = NULL,
832 bool multiSelect =
false,
bool createFile =
false,
833 bool fileMustExist =
false,
bool pathMustExist =
false,
834 bool noChangeDirectory =
false );
836 GLS_EXPORT
bool SaveFileDialog( Fl_Window* win,
char* filePath,
unsigned int filePathSize,
837 char* directory = NULL,
const char* filterStr = NULL,
838 const char* defaultExt = NULL,
const char* title = NULL,
839 bool createFile =
false,
840 bool fileMustExist =
false,
bool pathMustExist =
false,
841 bool noChangeDirectory =
false );
843 GLS_EXPORT
void CheckGLError(
void );
853 GLS_EXPORT std::string
Uppercase(
const std::string& str );
855 GLS_EXPORT std::string ReplaceEnvironmentVariables(
const char* originalPath );
864 GLS_EXPORT
void ReadCommandLine(
int argc,
char** argv );
865 GLS_EXPORT
void Usage();
870 bool SilentMode(
void ) {
return _silentMode; }
872 static GLS_EXPORT glsCommandLine* Instance();
873 static glsCommandLine* _instance;
887 GLS_EXPORT InterfaceDescriptionClass(
const InterfaceDescriptionClass& source );
889 GLS_EXPORT ~InterfaceDescriptionClass();
891 GLS_EXPORT InterfaceDescriptionClass(
const char* code,
const char* usage,
const char* comment );
893 GLS_EXPORT
void operator=(
const InterfaceDescriptionClass& source );
894 GLS_EXPORT
void Code(
const char* );
895 GLS_EXPORT
const char* Code()
const;
896 GLS_EXPORT
void Usage(
const char* );
897 GLS_EXPORT
const char* Usage()
const;
898 GLS_EXPORT
void Comment(
const char* );
899 GLS_EXPORT
const char* Comment()
const;
911 typedef std::ostream ostreamType;
912 typedef std::istream istreamType;
914 virtual void StreamOut( ostreamType& outstr )
const = 0;
915 virtual void StreamIn( istreamType& instr ) = 0;
949 if(
typeid( T2 ) !=
typeid(
void* ) )
953 if(
typeid( T3 ) !=
typeid(
void* ) )
957 if(
typeid( T4 ) !=
typeid(
void* ) )
961 if(
typeid( T5 ) !=
typeid(
void* ) )
965 if(
typeid( T6 ) !=
typeid(
void* ) )
969 if(
typeid( T7 ) !=
typeid(
void* ) )
973 if(
typeid( T8 ) !=
typeid(
void* ) )
977 if(
typeid( T9 ) !=
typeid(
void* ) )
981 if(
typeid( T10 ) !=
typeid(
void* ) )
1013 : _val1( src._val1 )
1014 , _val2( src._val2 )
1015 , _val3( src._val3 )
1016 , _val4( src._val4 )
1017 , _val5( src._val5 )
1018 , _val6( src._val6 )
1019 , _val7( src._val7 )
1020 , _val8( src._val8 )
1021 , _val9( src._val9 )
1022 , _val10( src._val10 )
1041 const T2& val2 = T2(),
1042 const T3& val3 = T3(),
1043 const T4& val4 = T4(),
1044 const T5& val5 = T5(),
1045 const T6& val6 = T6(),
1046 const T7& val7 = T7(),
1047 const T8& val8 = T8(),
1048 const T9& val9 = T9(),
1049 const T10& val10 = T10() )
1072 case 10: rval &= ( _val10 == val._val10 );
1073 case 9: rval &= ( _val9 == val._val9 );
1074 case 8: rval &= ( _val8 == val._val8 );
1075 case 7: rval &= ( _val7 == val._val7 );
1076 case 6: rval &= ( _val6 == val._val6 );
1077 case 5: rval &= ( _val5 == val._val5 );
1078 case 4: rval &= ( _val4 == val._val4 );
1079 case 3: rval &= ( _val3 == val._val3 );
1080 case 2: rval &= ( _val2 == val._val2 );
1082 rval &= ( _val1 == val._val1 );
1093 return !( *
this == val );
1104 outstr <<
" " << _val2;
1106 outstr <<
" " << _val3;
1108 outstr <<
" " << _val4;
1110 outstr <<
" " << _val5;
1112 outstr <<
" " << _val6;
1114 outstr <<
" " << _val7;
1116 outstr <<
" " << _val8;
1118 outstr <<
" " << _val9;
1119 if( _numVals >= 10 )
1120 outstr <<
" " << _val10;
1170 if( _numVals >= 10 )
1178 GLS_EXPORT std::ostream& operator<<( std::ostream& outstr,
const GlsMultiValBase& multiVal );
1179 GLS_EXPORT std::istream& operator>>( std::istream& instr, GlsMultiValBase& multiVal );
1191 std::string _string;
1212 : _string( str ? str :
"" )
1216 operator std::string()
const
1232 return str1._string == str2._string;
1238 return !( str1 == str2 );
1242 inline std::ostream& operator<<( std::ostream& outstr,
const GlsPropString& str )
1247 inline std::istream& operator>>( std::istream& instr, GlsPropString& str )
1250 disti::GetToEnd( instr, temp,
false );
1263 std::string _string;
1286 operator std::string()
const
1291 std::string& String()
1298 return str._string == _string;
1302 inline std::ostream& operator<<( std::ostream& outstr,
const GlsPropStringQuoted& str )
1308 inline std::istream& operator>>( std::istream& instr, GlsPropStringQuoted& str )
1315 if( instr.peek() !=
'\"' )
1317 disti::GetToEnd( instr, temp,
false );
1327 while( instr.good() )
1329 lastChar = currChar;
1330 currChar = instr.get();
1331 if( currChar != -1 )
1333 if( currChar ==
'\"' && lastChar !=
'\\' )
1335 temp += (char)currChar;
1346 void SpawnBrowser(
const char* url );
1356 GLS_EXPORT
bool CheckDistiLicense(
const char* licenseGroupName,
const char* feature,
const char* version,
bool quiet );
1390 T Clamp(
const T& val,
const T& min,
const T& max )
1392 return std::min( max, std::max( min, val ) );
1405 inline void Split(
const std::string& s,
const char delim, std::vector<std::string>& elems,
const std::size_t maxElems = 0 )
1407 std::istringstream ss( s );
1409 while( std::getline( ss, item, delim ) )
1411 elems.push_back( DISTI_RVAL_MOVE( item ) );
1412 if( elems.size() == maxElems )
1417 if( elems.size() == maxElems && ss.good() && maxElems > 0 )
1419 std::string remainder;
1420 std::getline( ss, remainder,
'\0' );
1421 elems.back() += delim + remainder;
1435 inline std::vector<std::string> Split(
const std::string& s,
const char delim,
const std::size_t maxElems = 0 )
1437 std::vector<std::string> elems;
1438 Split( s, delim, elems, maxElems );
1439 return DISTI_RVAL_MOVE( elems );
1443 inline std::string MakeString(
const char*
const cStr )
1445 return ( cStr ? cStr :
"" );
1452 class IGlsStateManager;
1455 class TextureLoaderList;
1489 void operator=(
const GlsGlobals& ) DISTI_SPECIAL_MEM_FUN_DELETE;
1495 GLS_EXPORT
void glsPerspective(
double fovy,
double aspect,
double zNear,
double zFar );
1497 #ifdef MATRIX_TYPE_FLOAT
1498 GLS_EXPORT
bool glsProject(
double objx,
double objy,
double objz,
1499 const float modelMatrix[ 16 ],
1500 const float projMatrix[ 16 ],
1501 const int viewport[ 4 ],
1502 double* winx,
double* winy,
double* winz );
1504 GLS_EXPORT
bool glsUnProject(
double winx,
double winy,
double winz,
1505 const float modelMatrix[ 16 ],
1506 const float projMatrix[ 16 ],
1507 const int viewport[ 4 ],
1508 double* objx,
double* objy,
double* objz );
1510 GLS_EXPORT
bool glsProject(
double objx,
double objy,
double objz,
1511 const double modelMatrix[ 16 ],
1512 const double projMatrix[ 16 ],
1513 const int viewport[ 4 ],
1514 double* winx,
double* winy,
double* winz );
1516 GLS_EXPORT
bool glsUnProject(
double winx,
double winy,
double winz,
1517 const double modelMatrix[ 16 ],
1518 const double projMatrix[ 16 ],
1519 const int viewport[ 4 ],
1520 double* objx,
double* objy,
double* objz );
The DistiUnhideGlobalsDummyClass class.
const T & Min(const T &x, const T &y)
Definition: util.h:237
int EncodedStringMinLength()
GlsPropStringQuoted(const std::string &str)
Definition: util.h:1273
virtual void StreamOut(ostreamType &outstr) const
Definition: util.h:1100
std::string GetExtension(const std::string &filename)
GlsDefinedColorEnum
Definition: util.h:169
const int INLINE_TEXTURE_LINE_LENGTH
Definition: util.h:105
std::string & String()
Definition: util.h:1224
std::string FileExtension(const std::string &filepath)
void GlsGetPerspective(GlsMatrixType &m, double fovy, double aspect, double zNear, double zFar)
GlsPropString(const char *str)
Definition: util.h:1211
unsigned char glsDefinedColors[GLS_COLOR_MAX][4]
virtual bool operator!=(const GlsMultiVal &val) const
Definition: util.h:1091
Definition: dynamic_array.h:62
The disti::DynamicArray class. A templated array of objects capable of dynamically growing...
Class to contain current OpenGL view, projection and draw matrices.
Definition: util.h:276
std::string FileName(const std::string &filepath)
const char * GetBaseName(const char *path)
int EncodeString(char *dest, const char *src, const int dest_str_length)
The GlsMatrixAffine class.
void AppendTrailingSlash(char *s)
GlsFontMan & GetFontMan()
Gets the global font manager.
void RemoveDoubleSlashes(char *path, char slash= '/')
Definition: texture_loader.h:55
bool CheckDistiLicense(const char *licenseGroupName, const char *feature, const char *version, bool quiet)
std::string GetQualifiedInstanceName(const DisplayFrame *topFrame, const DisplayObject *obj)
Hold global objects so we can control order of destruction.
Definition: util.h:1458
std::string GetDefaultComponentClassName(const char *dllFileName)
GlsMultiVal()
Definition: util.h:1002
char * PathToOS(const char *path)
Definition: gls_state_manager_interface.h:67
void RemoveSpaces(std::string &entry)
const T & Max(const T &x, const T &y)
Definition: util.h:248
virtual bool operator==(const GlsMultiVal &val) const
Definition: util.h:1065
GlsPropStringQuoted(const char *str)
Definition: util.h:1281
A file for all GL Studio files to include.
Mutex & GetImageListMutex()
Gets the mutex for protecting the image list.
int range_check(int num, double val,...)
bool GetObjectCoordinatesTransformSameView(DisplayObject *from, DisplayObject *to, GlsMatrixType *outTransform)
float AngularDistanceRad(float angle1, float angle2)
std::string Uppercase(const std::string &str)
void ChangeGlsDefinedColor(GlsDefinedColorEnum index, unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha)
Definition: util.h:198
Definition: scoped_ptr.h:53
GlsPropString()
Definition: util.h:1194
VertexNoColor Vector
Definition: gls_font_base.h:66
GlsMatrixAffine< T > FindCoordinateTransformation(const Vector &new_origin, const Vector &new_i, const Vector &new_j, const Vector &new_k)
Definition: util.h:356
bool FindNonColinearVertices(int arraySize, Vector array[], int &index1, int &index2, int &index3, bool isVectorArray=true)
bool GetObjectCoordinatesTransform(DisplayObject *from, DisplayObject *to, GlsMatrixType *outTransform)
int DecodeString(char *dest, const char *src, const int dest_str_length)
bool GetComponentClassNames(const char *dllFileName, DynamicArray< std::string, false > &nameList, const char *createClassTag="CreateComponent_")
void Count(const unsigned int count)
Definition: dynamic_array.h:115
bool CalculateTexPointsFromTexCoords(DisplayObject *object)
TextureLoaderList & GetTextureLoaders()
Gets the global list of texture loaders.
Definition: gls_mutex.h:52
friend bool operator!=(const GlsPropString &str1, const GlsPropString &str2)
Definition: util.h:1236
GlsMultiVal(const GlsMultiVal &src)
Definition: util.h:1012
void PushResourcePath(const char *resourcePath)
IGlsStateManager & GetStateManager()
Gets the global state manager instance.
void Translate(Type x, Type y, Type z)
Definition: gls_matrix_affine.h:196
bool FileExists(const char *filename)
int C_EncodeString(char *dest, const char *src, const int dest_str_length)
static GlsGlobals & Instance()
Singleton instance.
virtual void StreamIn(istreamType &instr)
Definition: util.h:1127
GlsMultiVal(const T1 &val1, const T2 &val2=T2(), const T3 &val3=T3(), const T4 &val4=T4(), const T5 &val5=T5(), const T6 &val6=T6(), const T7 &val7=T7(), const T8 &val8=T8(), const T9 &val9=T9(), const T10 &val10=T10())
Definition: util.h:1039
FILE * gls_fopen(const char *filename, const char *flags)
bool IsDirectory(const char *filename)
float AngularDistanceDeg(float angle1, float angle2)
std::string FilePath(const std::string &filepath)
Definition: gls_font_man.h:59
bool Equal(T1 x, T2 y, float precision=0.001f)
Definition: util.h:226
char * GetFileName(const char *name)
List_c & GetImageList()
Gets the image list.
bool NotColinear(const Vector &a, const Vector &b, const Vector &c)
const char * GetFilePath(const char *name)
std::string ResolveRuntimeResourcePath(const char *fileName)
void PushResourceFinder(std::string(*finder)(const std::string &))
A smart pointer with unique ownership – poor man's std::unique_ptr.
std::string ResolvePath(const char *path)
friend bool operator==(const GlsPropString &str1, const GlsPropString &str2)
Definition: util.h:1230
Contains the DistiAssert macro.
Macros and helper code to determine what subset of C++11/14/17 is available.
void GlsGetOrtho(GlsMatrixType &m, double left, double right, double bottom, double top, double zNear, double zFar)
GlsPropString(const std::string &str)
Definition: util.h:1202
int Safe_fopen(const char *filename, char *flags, FILE **f)
unsigned char * GlsDefinedColor(GlsDefinedColorEnum index)
Definition: util.h:190
Definition: bmpimage.h:46
GlsPropStringQuoted()
Definition: util.h:1266