42 #ifndef _GLS_RUNTIME_UTIL_H
43 #define _GLS_RUNTIME_UTIL_H
67 #include <android/asset_manager.h>
72 #pragma warning (disable:4786)
75 const int DIALOG_MAX_DIRECTORY_LENGTH = 1024;
95 #define strcasecmp(x,y) _stricmp(x,y)
103 #define PARSER_CLEARSTRING_DELIMETER_START "#$STRING_START$#"
104 #define PARSER_CLEARSTRING_DELIMETER_END "#$STRING_END$#"
107 #define M_PI 3.14159265358979323846
112 #define DEG_TO_RAD (M_PI/180.0)
115 #define RAD_TO_DEG (180.0/M_PI)
117 #define HIT_TOLERANCE 5.0
121 #define BETWEEN(x,x1,x2) ((((x) >= (x1)) && ((x) <= (x2))) || \
122 (((x) >= (x2)) && ((x) <= (x1))))
125 #define IS_NEGATIVE(x) ((fabs(x) > 0.0001)?(x < 0.0):0)
128 #define IS_POSITIVE(x) ((fabs(x) > 0.0001)?(x > 0.0):0)
131 #define CloseToZero(x) (fabs((x)) < 0.1)
134 #define VeryCloseToZero(x) (fabs((x)) < 0.0001)
137 #define IS_ZERO(x) (fabs((x)) < 0.001)
141 #define MIN(A,B) ((A) < (B) ? (A) : (B))
146 #define MAX(A,B) ((A) > (B) ? (A) : (B))
155 GLS_EXPORT
bool gltIsExtSupported(
const char *extension);
160 # define GLSTUDIO_CLAMP_TO_EDGE ( OpenGLVersion() >= 1.2f ? 0x812F : GL_CLAMP)
162 # define GLSTUDIO_CLAMP_TO_EDGE GL_CLAMP_TO_EDGE
195 if ((index <0) || (index >= GLS_COLOR_MAX))
196 return glsDefinedColors[0];
198 return glsDefinedColors[index];
209 if ((index >= 0) && (index < GLS_COLOR_MAX))
211 glsDefinedColors[index][0] = red;
212 glsDefinedColors[index][1] = green;
213 glsDefinedColors[index][2] = blue;
214 glsDefinedColors[index][3] = alpha;
230 template<
class T1,
class T2>
231 bool Equal(T1 x, T2 y,
float precision = 0.001f)
233 return (x - precision) <= y && y <= (x + precision);
242 const T&
Min(
const T& x,
const T& y)
244 return x < y ? x : y;
253 const T&
Max(
const T& x,
const T& y)
255 return x < y ? y : x;
263 template<
class T,
class Pred>
264 const T&
Min(
const T& x,
const T& y, Pred pr)
266 return pr(x, y) ? x : y;
274 template<
class T,
class Pred>
275 const T&
Max(
const T& x,
const T& y, Pred pr)
277 return pr(x, y) ? y : x;
316 template <
class T,
bool TypeIsSimple>
322 unsigned int size() {
return array.
Count(); }
324 void push(
const T& item)
326 array[array.
Count()] = item;
332 return array[array.
Count()-1];
337 if(array.
Count() > 0)
371 rotation_scaling(0,0) = new_i.x; rotation_scaling(0,1) = new_j.x; rotation_scaling(0,2) = new_k.x;
372 rotation_scaling(1,0) = new_i.y; rotation_scaling(1,1) = new_j.y; rotation_scaling(1,2) = new_k.y;
373 rotation_scaling(2,0) = new_i.z; rotation_scaling(2,1) = new_j.z; rotation_scaling(2,2) = new_k.z;
376 rotation_scaling.
Invert();
379 return rotation_scaling * transform;
386 GlsMatrixAffine<T> transform;
387 GlsMatrixAffine<T> rotation_scaling;
391 transform.Translate(-new_origin);
395 rotation_scaling(0,0) = new_i.x; rotation_scaling(0,1) = new_j.x; rotation_scaling(0,2) = new_k.x;
396 rotation_scaling(1,0) = new_i.y; rotation_scaling(1,1) = new_j.y; rotation_scaling(1,2) = new_k.y;
397 rotation_scaling(2,0) = new_i.z; rotation_scaling(2,1) = new_j.z; rotation_scaling(2,2) = new_k.z;
400 rotation_scaling.Invert();
403 result = rotation_scaling * transform;
470 int& index1,
int& index2,
int& index3,
471 bool isVectorArray =
true);
494 GLS_EXPORT
int EncodeString(
char* dest,
const char* src,
const int dest_str_length );
500 GLS_EXPORT std::string
EncodeString(
const std::string& src);
513 GLS_EXPORT
int C_EncodeString(
char *dest,
const char *src,
const int dest_str_length );
527 GLS_EXPORT
int DecodeString(
char *dest,
const char *src,
const int dest_str_length);
533 GLS_EXPORT std::string
DecodeString(
const std::string& src);
542 unsigned char *pixels;
545 GLS_EXPORT
char *MakeRelativePath(
const char *originalPath,
const char *relativePath);
546 GLS_EXPORT
void ConvertBackslashToSlash(
char *str);
547 GLS_EXPORT
void ConvertBackslashToSlash(std::string &str);
565 GLS_EXPORT
int range_check(
int num,
double val,...);
574 GLS_EXPORT
int Safe_fopen(
const char *filename,
char *flags,FILE **f);
576 GLS_EXPORT
int Safe_fopen(
const char *filename,
char *flags,std::fstream &outstr);
585 GLS_EXPORT
void EnableDirectAssetLoading(
bool enableDirectAssetLoading);
593 GLS_EXPORT
bool HasAssetExtension(
const char *filename);
601 GLS_EXPORT
bool AssetExists(
const char *filename);
608 GLS_EXPORT
void SetAssetManager(AAssetManager *assetManager);
611 #if defined(ANDROID) || ( defined(LINUX) && defined(GLES) )
617 GLS_EXPORT std::string
ResolvePath(
const char* filename_);
623 GLS_EXPORT
void SetResourcePath(
const char *resourcePath);
634 GLS_EXPORT FILE *
gls_fopen(
const char *filename,
const char *flags);
659 GLS_EXPORT std::string
ResolvePath(
const char *path);
662 inline std::string
ResolvePath(
const std::string& path )
673 GLS_EXPORT FILE *
gls_fopen(
const char *filename,
const char *flags);
683 GLS_EXPORT std::string GetAbsolutePathAndFileNameInDefaultResourceBundle(
const char* fileName);
696 GLS_EXPORT
bool FileExists(
const char *filename);
697 GLS_EXPORT
bool FileExists(
const std::string &filename);
702 GLS_EXPORT
bool IsDirectory(
const char* filename );
703 GLS_EXPORT
bool IsDirectory(
const std::string& filename );
708 GLS_EXPORT std::string
FileExtension(
const std::string& filepath);
713 GLS_EXPORT std::string
FileName(
const std::string& filepath);
719 GLS_EXPORT std::string
FilePath(
const std::string& filepath);
725 GLS_EXPORT
const char *
GetFilePath(
const char *name);
749 GLS_EXPORT
char *
PathToOS(
const char *path);
756 GLS_EXPORT std::string
GetExtension(
const std::string &filename);
762 GLS_EXPORT
const char*
GetBaseName(
const char* path);
791 GLS_EXPORT
bool ContainsNonBlank(
const std::string& val );
793 GLS_EXPORT
bool GetNoSpaces(FILE *f,
char *result,
int maxLen);
794 GLS_EXPORT
bool GetToEnd(std::istream &instr, std::string &result,
bool decode);
795 GLS_EXPORT
bool GetVertex(std::istream &instr, Vertex* vert,
bool getColor);
800 GLS_EXPORT
bool GetComponentClassNames(
const char* dllFileName, DynamicArray<std::string,false>& nameList,
const char* createClassTag =
"CreateComponent_" );
817 GLS_EXPORT
bool OpenFileDialog(Fl_Window *win,
char *filePath,
unsigned int filePathSize,
818 char *directory = NULL,
const char *filterStr = NULL,
819 const char *defaultExt = NULL,
const char *title = NULL,
820 bool multiSelect =
false,
bool createFile =
false,
821 bool fileMustExist =
false,
bool pathMustExist =
false,
822 bool noChangeDirectory =
false);
824 GLS_EXPORT
bool SaveFileDialog(Fl_Window *win,
char *filePath,
unsigned int filePathSize,
825 char *directory = NULL,
const char *filterStr = NULL,
826 const char *defaultExt = NULL,
const char *title = NULL,
827 bool createFile =
false,
828 bool fileMustExist =
false,
bool pathMustExist =
false,
829 bool noChangeDirectory =
false);
831 GLS_EXPORT
void CheckGLError(
void);
841 GLS_EXPORT std::string
Uppercase(
const std::string& str);
843 GLS_EXPORT std::string ReplaceEnvironmentVariables(
const char* originalPath);
854 GLS_EXPORT
void ReadCommandLine(
int argc,
char **argv );
855 GLS_EXPORT
void Usage();
860 bool SilentMode(
void) {
return _silentMode; }
862 static GLS_EXPORT glsCommandLine* Instance();
863 static glsCommandLine *_instance;
877 GLS_EXPORT InterfaceDescriptionClass(
const InterfaceDescriptionClass& source);
879 GLS_EXPORT ~InterfaceDescriptionClass();
881 GLS_EXPORT InterfaceDescriptionClass(
const char* code,
const char* usage,
const char* comment);
883 GLS_EXPORT
void operator=(
const InterfaceDescriptionClass& source);
884 GLS_EXPORT
void Code(
const char*);
885 GLS_EXPORT
const char* Code()
const;
886 GLS_EXPORT
void Usage(
const char*);
887 GLS_EXPORT
const char* Usage()
const;
888 GLS_EXPORT
void Comment(
const char*);
889 GLS_EXPORT
const char* Comment()
const;
901 typedef std::ostream ostreamType;
902 typedef std::istream istreamType;
904 virtual void StreamOut(ostreamType & outstr)
const = 0;
905 virtual void StreamIn(istreamType & instr) = 0;
940 if (
typeid(T2) !=
typeid(
void*)) _numVals++;
else return;
941 if (
typeid(T3) !=
typeid(
void*)) _numVals++;
else return;
942 if (
typeid(T4) !=
typeid(
void*)) _numVals++;
else return;
943 if (
typeid(T5) !=
typeid(
void*)) _numVals++;
else return;
944 if (
typeid(T6) !=
typeid(
void*)) _numVals++;
else return;
945 if (
typeid(T7) !=
typeid(
void*)) _numVals++;
else return;
946 if (
typeid(T8) !=
typeid(
void*)) _numVals++;
else return;
947 if (
typeid(T9) !=
typeid(
void*)) _numVals++;
else return;
948 if (
typeid(T10) !=
typeid(
void*)) _numVals++;
else return;
1015 const T2& val2 = T2(),
1016 const T3& val3 = T3(),
1017 const T4& val4 = T4(),
1018 const T5& val5 = T5(),
1019 const T6& val6 = T6(),
1020 const T7& val7 = T7(),
1021 const T8& val8 = T8(),
1022 const T9& val9 = T9(),
1023 const T10& val10 = T10() ) :
1046 case 10: rval &= (_val10 == val._val10);
1047 case 9: rval &= (_val9 == val._val9);
1048 case 8: rval &= (_val8 == val._val8);
1049 case 7: rval &= (_val7 == val._val7);
1050 case 6: rval &= (_val6 == val._val6);
1051 case 5: rval &= (_val5 == val._val5);
1052 case 4: rval &= (_val4 == val._val4);
1053 case 3: rval &= (_val3 == val._val3);
1054 case 2: rval &= (_val2 == val._val2);
1055 case 1: rval &= (_val1 == val._val1);
1066 return !( *
this == val );
1079 outstr <<
" " <<_val2;
1081 outstr <<
" " <<_val3;
1083 outstr <<
" " <<_val4;
1085 outstr <<
" " <<_val5;
1087 outstr <<
" " <<_val6;
1089 outstr <<
" " <<_val7;
1091 outstr <<
" " <<_val8;
1093 outstr <<
" " <<_val9;
1095 outstr <<
" " <<_val10;
1155 GLS_EXPORT std::ostream & operator<<(std::ostream & outstr,
const GlsMultiValBase & multiVal);
1156 GLS_EXPORT std::istream & operator>>(std::istream & instr, GlsMultiValBase & multiVal);
1168 std::string _string;
1194 operator std::string()
const
1211 return str1._string == str2._string;
1217 return !(str1 == str2 );
1221 inline std::ostream & operator<<(std::ostream & outstr,
const GlsPropString & str)
1226 inline std::istream & operator>>(std::istream & instr, GlsPropString & str)
1229 disti::GetToEnd(instr, temp,
false);
1242 std::string _string;
1265 operator std::string()
const
1269 std::string& String()
1275 return str._string == _string;
1278 inline std::ostream & operator<<(std::ostream & outstr,
const GlsPropStringQuoted & str)
1283 inline std::istream & operator>>(std::istream & instr, GlsPropStringQuoted & str)
1290 if (instr.peek() !=
'\"')
1292 disti::GetToEnd(instr, temp,
false);
1302 while (instr.good())
1304 lastChar = currChar;
1305 currChar = instr.get();
1308 if (currChar ==
'\"' && lastChar !=
'\\')
1310 temp += (char)currChar;
1321 void SpawnBrowser(
const char *url);
1331 GLS_EXPORT
bool CheckDistiLicense(
const char* licenseGroupName,
const char *feature,
const char *version,
bool quiet);
1365 T Clamp(
const T& val,
const T& min,
const T& max )
1367 return std::min( max, std::max( min, val ) );
1380 inline void Split(
const std::string& s,
const char delim, std::vector<std::string>& elems,
const std::size_t maxElems = 0 )
1382 std::istringstream ss( s );
1384 while( std::getline( ss, item, delim ) )
1386 elems.push_back( DISTI_RVAL_MOVE( item ) );
1387 if( elems.size() == maxElems )
1392 if( elems.size() == maxElems && ss.good() && maxElems > 0 )
1394 std::string remainder;
1395 std::getline( ss, remainder,
'\0' );
1396 elems.back() += delim + remainder;
1410 inline std::vector<std::string> Split(
const std::string& s,
const char delim,
const std::size_t maxElems = 0 )
1412 std::vector<std::string> elems;
1413 Split( s, delim, elems, maxElems );
1414 return DISTI_RVAL_MOVE( elems );
1418 inline std::string MakeString(
const char*
const cStr )
1420 return ( cStr ? cStr :
"" );
1427 GLS_EXPORT
void glsPerspective(
double fovy,
double aspect,
double zNear,
double zFar);
1430 #ifdef MATRIX_TYPE_FLOAT
1431 GLS_EXPORT
bool glsProject(
double objx,
double objy,
double objz,
1432 const float modelMatrix[16],
1433 const float projMatrix[16],
1434 const int viewport[4],
1435 double *winx,
double *winy,
double *winz);
1437 GLS_EXPORT
bool glsUnProject(
double winx,
double winy,
double winz,
1438 const float modelMatrix[16],
1439 const float projMatrix[16],
1440 const int viewport[4],
1441 double *objx,
double *objy,
double *objz);
1443 GLS_EXPORT
bool glsProject(
double objx,
double objy,
double objz,
1444 const double modelMatrix[16],
1445 const double projMatrix[16],
1446 const int viewport[4],
1447 double *winx,
double *winy,
double *winz);
1449 GLS_EXPORT
bool glsUnProject(
double winx,
double winy,
double winz,
1450 const double modelMatrix[16],
1451 const double projMatrix[16],
1452 const int viewport[4],
1453 double *objx,
double *objy,
double *objz);
The DistiUnhideGlobalsDummyClass class.
const T & Min(const T &x, const T &y)
Definition: util.h:242
int EncodedStringMinLength()
GlsPropStringQuoted(const std::string &str)
Definition: util.h:1253
virtual void StreamOut(ostreamType &outstr) const
Definition: util.h:1075
std::string GetExtension(const std::string &filename)
GlsDefinedColorEnum
Definition: util.h:168
const int INLINE_TEXTURE_LINE_LENGTH
Definition: util.h:100
std::string & String()
Definition: util.h:1203
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:1190
unsigned char glsDefinedColors[GLS_COLOR_MAX][4]
virtual bool operator!=(const GlsMultiVal &val) const
Definition: util.h:1064
Definition: dynamic_array.h:63
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:281
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)
void RemoveDoubleSlashes(char *path, char slash= '/')
bool CheckDistiLicense(const char *licenseGroupName, const char *feature, const char *version, bool quiet)
std::string GetQualifiedInstanceName(const DisplayFrame *topFrame, const DisplayObject *obj)
std::string GetDefaultComponentClassName(const char *dllFileName)
GlsMultiVal()
Definition: util.h:971
char * PathToOS(const char *path)
const T & Max(const T &x, const T &y)
Definition: util.h:253
virtual bool operator==(const GlsMultiVal &val) const
Definition: util.h:1039
GlsPropStringQuoted(const char *str)
Definition: util.h:1262
A file for all GL Studio files to include.
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:203
GlsPropString()
Definition: util.h:1171
VertexNoColor Vector
Definition: gls_font_base.h:68
GlsMatrixAffine< T > FindCoordinateTransformation(const Vector &new_origin, const Vector &new_i, const Vector &new_j, const Vector &new_k)
Definition: util.h:360
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:120
bool CalculateTexPointsFromTexCoords(DisplayObject *object)
friend bool operator!=(const GlsPropString &str1, const GlsPropString &str2)
Definition: util.h:1215
GlsMultiVal(const GlsMultiVal &src)
Definition: util.h:984
void PushResourcePath(const char *resourcePath)
void Translate(Type x, Type y, Type z)
Definition: gls_matrix_affine.h:197
bool FileExists(const char *filename)
int C_EncodeString(char *dest, const char *src, const int dest_str_length)
virtual void StreamIn(istreamType &instr)
Definition: util.h:1104
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:1013
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)
bool Equal(T1 x, T2 y, float precision=0.001f)
Definition: util.h:231
char * GetFileName(const char *name)
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 &))
std::string ResolvePath(const char *path)
friend bool operator==(const GlsPropString &str1, const GlsPropString &str2)
Definition: util.h:1209
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:1180
int Safe_fopen(const char *filename, char *flags, FILE **f)
unsigned char * GlsDefinedColor(GlsDefinedColorEnum index)
Definition: util.h:192
Definition: bmpimage.h:46
GlsPropStringQuoted()
Definition: util.h:1244