GL Studio API
util.h
Go to the documentation of this file.
1 /*! \file
2  \brief Generally useful defines, macros, enumerations and function
3  prototypes.
4 
5  \par Copyright Information
6 
7  Copyright (c) 2015 by The DiSTI Corporation.<br>
8  11301 Corporate Blvd; Suite 100<br>
9  Orlando, Florida 32817<br>
10  USA<br>
11  <br>
12  All rights reserved.<br>
13 
14  This Software contains proprietary trade secrets of DiSTI and may not be
15 reproduced, in whole or part, in any form, or by any means of electronic,
16 mechanical, or otherwise, without the written permission of DiSTI. Said
17 permission may be derived through the purchase of applicable DiSTI product
18 licenses which detail the distribution rights of this content and any
19 Derivative Works based on this or other copyrighted DiSTI Software.
20 
21  NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
22 AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
23 PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
24 AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
25 IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
26 PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
27 
28  LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
29 IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
30 INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
31 DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
32 INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
33 INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
34 OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
35 EXCEED FIVE DOLLARS (US$5.00).
36 
37  The aforementioned terms and restrictions are governed by the laws of the
38 State of Florida and the United States of America.
39 
40 */
41 
42 #ifndef _GLS_RUNTIME_UTIL_H
43 #define _GLS_RUNTIME_UTIL_H
44 
45 #include "gls_include.h"
46 
47 #ifdef _WIN32
48 # include <direct.h>
49 #else
50 # include <unistd.h>
51 #endif
52 
53 #include "disti_assert.h"
54 #include "dynamic_array.h"
55 #include "gls_cpp_lang_support.h"
56 #include "gls_matrix_affine.h"
57 #include "unhide_globals.h"
58 #include <iostream>
59 #include <math.h>
60 #include <sstream>
61 #include <stdio.h>
62 #include <string>
63 #include <typeinfo>
64 #include <vector>
65 
66 #if (defined(LINUX) || defined(SUNOS) || defined(SGI)) && !defined(ANDROID) && !defined(NOSOUND)
67 #include <audiofile.h>
68 #endif
69 
70 #ifdef ANDROID
71 #include <android/asset_manager.h>
72 #endif
73 
74 #if defined(_MSC_VER)
75 // Hide std template warnings
76 #pragma warning (disable:4786)
77 #endif
78 
79 const int DIALOG_MAX_DIRECTORY_LENGTH = 1024; // Limited by FLTK FileBrowser
80 
81 class Fl_Window;
82 
83 namespace disti
84 {
85 
86 class Vertex;
87 class DisplayObject;
88 class DisplayFrame;
89 
90 #ifndef TRUE
91 #define TRUE 1
92 #endif
93 
94 #ifndef FALSE
95 #define FALSE 0
96 #endif
97 
98 #ifdef _WIN32
99 #define strcasecmp(x,y) _stricmp(x,y)
100 #endif
101 
102 /** Used to generate inline textures. The writing and reading
103  * of the lines need to know the length. */
105 
106 /* Used for parsing lines of clear text */
107 #define PARSER_CLEARSTRING_DELIMETER_START "#$STRING_START$#"
108 #define PARSER_CLEARSTRING_DELIMETER_END "#$STRING_END$#"
109 
110 #ifndef M_PI
111 #define M_PI 3.14159265358979323846
112 #endif
113 
114 /* DEG_TO_RAD Converts degrees to radians */
115 
116 #define DEG_TO_RAD (M_PI/180.0)
117 
118 /* RAD_TO_DEG Converts radians to degrees */
119 #define RAD_TO_DEG (180.0/M_PI)
120 
121 #define HIT_TOLERANCE 5.0
122 
123 /* BETWEEN(x,x1,x2) Determines if x is included in the range
124  x1 to x2 */
125 #define BETWEEN(x,x1,x2) ((((x) >= (x1)) && ((x) <= (x2))) || \
126  (((x) >= (x2)) && ((x) <= (x1))))
127 
128 /* IS_NEGATIVE(x) Determines if the argument is negative */
129 #define IS_NEGATIVE(x) ((fabs(x) > 0.0001)?(x < 0.0):0)
130 
131 /* IS_POSITIVE(x) Determines if the argument is positive */
132 #define IS_POSITIVE(x) ((fabs(x) > 0.0001)?(x > 0.0):0)
133 
134 /* CloseToZero(x) Determines if the argument is small (< 10E-1) */
135 #define CloseToZero(x) (fabs((x)) < 0.1)
136 
137 /* VeryCloseToZero(x) Determines if the argument is extremely small (< 10E-4) */
138 #define VeryCloseToZero(x) (fabs((x)) < 0.0001)
139 
140 /* IS_ZERO(x) Determines if the argument is very small (< 10E-3) */
141 #define IS_ZERO(x) (fabs((x)) < 0.001)
142 
143 /* MIN(A,B) Determines which argument is smallest */
144 #ifndef MIN
145 #define MIN(A,B) ((A) < (B) ? (A) : (B))
146 #endif
147 
148 /* MIN(A,B) Determines which argument is largest */
149 #ifndef MAX
150 #define MAX(A,B) ((A) > (B) ? (A) : (B))
151 #endif
152 
153 /** Use for determining the current OpenGL version available in the current
154  * runtime environment.
155  * It may not be valid until called after a valid rendering context has been assigned.
156  */
157 GLS_EXPORT float OpenGLVersion();
158 
159 GLS_EXPORT bool gltIsExtSupported(const char *extension);
160 
161 // Additional #defines
162 //From glext.h Available at http://oss.sgi.com/projects/ogl-sample/registry/ */
163 #ifndef GLES
164 #ifndef SGI
165 # define GLSTUDIO_CLAMP_TO_EDGE ( OpenGLVersion() >= 1.2f ? 0x812F : GL_CLAMP)
166 #else
167 # define GLSTUDIO_CLAMP_TO_EDGE GL_CLAMP_TO_EDGE
168 #endif
169 #else
170 # define GLSTUDIO_CLAMP_TO_EDGE GL_CLAMP_TO_EDGE
171 #endif
172 
173 /** GL Studio color defines
174  */
175 // \enum color enumerations for use with GlsDefinedColor methods
177 {
178  GLS_COLOR_WHITE,
179  GLS_COLOR_CYAN,
180  GLS_COLOR_RED,
181  GLS_COLOR_AMBER,
182  GLS_COLOR_GREEN,
183  GLS_COLOR_YELLOW,
184  GLS_COLOR_MAGENTA,
185  GLS_COLOR_BLACK,
186  GLS_COLOR_BLUE,
187  GLS_COLOR_MAX
188 };
189 
190 /**
191 * \param GLS specific color index
192 * \return An RGBA color value
193 */
194 GLS_EXPORT extern unsigned char glsDefinedColors[GLS_COLOR_MAX][4];
195 
196 /**
197 * \param index of defined color
198 * \return an unsigned char array of the specified index
199 */
200 inline unsigned char *GlsDefinedColor(GlsDefinedColorEnum index)
201 {
202 
203  if ((index <0) || (index >= GLS_COLOR_MAX))
204  return glsDefinedColors[0];
205  else
206  return glsDefinedColors[index];
207 }
208 /**
209  * Allows the user to change the predefined colors
210  */
212  unsigned char red,
213  unsigned char green,
214  unsigned char blue,
215  unsigned char alpha)
216 {
217  if ((index >= 0) && (index < GLS_COLOR_MAX))
218  {
219  glsDefinedColors[index][0] = red;
220  glsDefinedColors[index][1] = green;
221  glsDefinedColors[index][2] = blue;
222  glsDefinedColors[index][3] = alpha;
223  }
224 }
225 
226 //---------------------------------------------------------------------------
227 /**
228 * Return whether two numbers are "equal" to eachother taking into account
229 * a certain precision. You can use this method on any numeric types and
230 * even mix types as the parameters. Eg. you can compare integers with
231 * floating point types or compare floats and doubles without casting.
232 *
233 * \param x first number to use in the comparison which determines the range
234 * \param y number to check if within the range determined by x and precision
235 * \param precision number that is added to and subtracted from x to
236 * determine the range to check y against.
237 */
238 template<class T1, class T2>
239 bool Equal(T1 x, T2 y, float precision = 0.001f)
240 {
241  return (x - precision) <= y && y <= (x + precision);
242 }
243 
244 //---------------------------------------------------------------------------
245 /**
246 * Return the minimum of two objects. The class T must have the < operator
247 * defined.
248 */
249 template<class T>
250 const T& Min(const T& x, const T& y)
251 {
252  return x < y ? x : y;
253 }
254 
255 //---------------------------------------------------------------------------
256 /**
257 * Return the maximum of two objects. The class T must have the < operator
258 * defined.
259 */
260 template<class T>
261 const T& Max(const T& x, const T& y)
262 {
263  return x < y ? y : x;
264 }
265 
266 //---------------------------------------------------------------------------
267 /**
268 * Return the minimum of two objects determined by a predicate.
269 * If pr(x, y) is true, x is returned else y.
270 */
271 template<class T, class Pred>
272 const T& Min(const T& x, const T& y, Pred pr)
273 {
274  return pr(x, y) ? x : y;
275 }
276 
277 //---------------------------------------------------------------------------
278 /**
279 * Return the maximum of two objects determined by a predicate.
280 * If pr(x, y) is true, y is returned else x.
281 */
282 template<class T, class Pred>
283 const T& Max(const T& x, const T& y, Pred pr)
284 {
285  return pr(x, y) ? y : x;
286 }
287 
288 /** \brief Class to contain current OpenGL view, projection and draw matrices */
290 {
291 private:
292  bool _needsDelete;
293 public:
294  int* viewMatrix;
295  GlsMatrixType* projMatrix;
296  GlsMatrixType* modelMatrix;
297 
298  /** Default constructor
299  * Keeps everything NULL */
300  GLS_EXPORT OpenGLMatrices();
301 
302  /** Copy constructor
303  * Pointers are copied as-is, copies of the
304  * data are NOT made. */
305  GLS_EXPORT OpenGLMatrices(const OpenGLMatrices& src);
306 
307  /** Another constructor.
308  * Pointers are copied as-is, copies of the
309  * data are NOT made. */
310  GLS_EXPORT OpenGLMatrices(int* view,
311  GlsMatrixType* proj,
312  GlsMatrixType* model);
313 
314  /** Destructor */
315  GLS_EXPORT ~OpenGLMatrices();
316 
317  /** Retrieves the current OpenGL Matrices from the
318  * OpenGL Subsystem */
319  GLS_EXPORT void GetCurrent();
320 };
321 
322 /** Stack class that uses DynamicArray
323  */
324 template <class T, bool TypeIsSimple>
326 {
327 private:
329 public:
330  unsigned int size() { return array.Count(); }
331 
332  void push(const T& item)
333  {
334  array[array.Count()] = item;
335  }
336 
337  T& top()
338  {
339  // This returns garbage if size < 1
340  return array[array.Count()-1];
341  }
342 
343  void pop()
344  {
345  if(array.Count() > 0)
346  {
347  array.Count(array.Count()-1);
348  }
349  }
350 };
351 
352 /** Find a transformation that will convert to a new coordinate
353  * system defined by the given origin and basis vectors (i,j,k).
354  * \note The new i,j,k vectors are in respect to the current origin.
355  * (i.e. for transformation that moves the origin
356  * along the x axis by 5 units you should pass in
357  * (Vector(5,0,0), Vector(1,0,0), Vector(0,1,0) , Vector(0,0,1))
358  * NOT (Vector(5,0,0), Vector(6,0,0), Vector(5,1,0) , Vector(5,0,1))
359  * Template argument is either double or float.
360  * \param new_origin Vector to the new coordinate system origin.
361  * \param new_i Vector parallel to the new x-axis with magnitude equal to one unit in the new coordinate system.
362  * \param new_j Vector parallel to the new y-axis with magnitude equal to one unit in the new coordinate system.
363  * \param new_k Vector parallel to the new z-axis with magnitude equal to one unit in the new coordinate system.
364  *
365  * \returns transformation matrix to the new coordinate system
366  */
367 template < class T >
368 GlsMatrixAffine<T> FindCoordinateTransformation(const Vector& new_origin, const Vector& new_i, const Vector& new_j, const Vector& new_k)
369 {
370  GlsMatrixAffine<T> transform;
371  GlsMatrixAffine<T> rotation_scaling;
372 
373  // First translate to the new origin
374 
375  transform.Translate(-new_origin);
376 
377  // Build a matrix taking the standard basis vectors to the new basis vectors
378 
379  rotation_scaling(0,0) = new_i.x; rotation_scaling(0,1) = new_j.x; rotation_scaling(0,2) = new_k.x;
380  rotation_scaling(1,0) = new_i.y; rotation_scaling(1,1) = new_j.y; rotation_scaling(1,2) = new_k.y;
381  rotation_scaling(2,0) = new_i.z; rotation_scaling(2,1) = new_j.z; rotation_scaling(2,2) = new_k.z;
382 
383  // Invert because we want the new basis vectors to become the standard basis vectors
384  rotation_scaling.Invert();
385 
386  // Combine the translation and rotation to produce the complete transformation
387  return rotation_scaling * transform;
388 
389 }
390 
391 template < class T >
392 void FindCoordinateTransformation(const Vector& new_origin, const Vector& new_i, const Vector& new_j, const Vector& new_k,GlsMatrixAffine<T> &result)
393 {
394  GlsMatrixAffine<T> transform;
395  GlsMatrixAffine<T> rotation_scaling;
396 
397  // First translate to the new origin
398 
399  transform.Translate(-new_origin);
400 
401  // Build a matrix taking the standard basis vectors to the new basis vectors
402 
403  rotation_scaling(0,0) = new_i.x; rotation_scaling(0,1) = new_j.x; rotation_scaling(0,2) = new_k.x;
404  rotation_scaling(1,0) = new_i.y; rotation_scaling(1,1) = new_j.y; rotation_scaling(1,2) = new_k.y;
405  rotation_scaling(2,0) = new_i.z; rotation_scaling(2,1) = new_j.z; rotation_scaling(2,2) = new_k.z;
406 
407  // Invert because we want the new basis vectors to become the standard basis vectors
408  rotation_scaling.Invert();
409 
410  // Combine the translation and rotation to produce the complete transformation
411  result = rotation_scaling * transform;
412 }
413 
414 /** Gets the transformation from one DisplayObject's object coordinates to another's
415  * Note: This method uses a screen-space transformation (DisplayObject::ModelMatrix). This requires that the two objects have been PreDrawn with the same view, but they do not need to be part of the same object heirarchy.
416  * Use GetObjectCoordinatesTransform unless GetObjectCoordinatesTransformSameView is required.
417  *
418  * \sa GetObjectCoordinatesTransform
419  *
420  * \param from The DisplayObject to start at
421  * \param to The DisplayObject to end at
422  * \param outTransform Out parameter - If the function returns true, this will contain the resulting transformation.
423  * \returns true on success, false if there was an error
424  */
425 GLS_EXPORT bool GetObjectCoordinatesTransformSameView( DisplayObject* from, DisplayObject* to, GlsMatrixType* outTransform);
426 
427 /** Gets the transformation from one DisplayObject's object coordinates to another's (if possible)
428  * This is the preferred method for determining the coordinate space relationship between two objects that have DynamicTransforms applied.
429  * Note: This method requires that the two objects are part of the same object heirarchy.
430  * Consider using GetObjectCoordinatesTransformSameView if your situation does not meet this requirement.
431  *
432  * \code
433  * // Example: Move objB to be in the same location as objA (including all DynamicTransforms)
434  * // Change Location of objB so that it's RotationPoint aligns with the RotationPoint of objA
435  * GlsMatrixType transform;
436  * if( GetObjectCoordinatesTransform( objA, objB, &transform ) )
437  * {
438  * Vector objA_rotationPoint_transformed = transform * (objA->Location() + objA->RotationPoint());
439  * objB->Location( objA_rotationPoint_transformed - objB->RotationPoint() );
440  * }
441  * else
442  * {
443  * // Error: objects are not in the same heirarchy
444  * }
445  * \endcode
446  *
447  * \sa GetObjectCoordinatesTransform
448  *
449  * \param from The DisplayObject to start at
450  * \param to The DisplayObject to end at
451  * \param outTransform Out parameter - If the function returns true, this will contain the resulting transformation.
452  * \returns true on success, false if the objects are not in the same heirarchy.
453  */
454 GLS_EXPORT bool GetObjectCoordinatesTransform( DisplayObject* from, DisplayObject* to, GlsMatrixType* outTransform);
455 
456 /** Test if the given points are not colinear (they are not in a line)
457  * \return true if the points are not colinear
458  * \return false if the points are colinear
459  */
460 GLS_EXPORT bool NotColinear(const Vector& a, const Vector& b, const Vector& c);
461 
462 /** Search the given Vertex array for the first three
463  * non-colinear vertices.
464  *
465  * \param arraySize The size of vertex_array
466  * \param array The Vertex array
467  * \param index1 variable to receive 1st array index
468  * \param index2 variable to receive 2nd array index
469  * \param index3 variable to receive 3rd array index
470  * \param isVectorArray true if array points to a Vector array, false if it
471  * points to a Vertex array
472  *
473  * \return true If the vertices were found
474  * \returns false If there are not three non-colinear vertices in the array
475  * if this occurs, the index values are undefined
476  */
477 GLS_EXPORT bool FindNonColinearVertices(int arraySize, Vector array[],
478  int& index1, int& index2, int& index3,
479  bool isVectorArray = true);
480 
481 /** Vertex version of FindNonColinearVertices */
482 inline bool FindNonColinearVertices(int arraySize, Vertex array[], int& index1, int& index2, int& index3)
483 {
484  return FindNonColinearVertices(arraySize, array, index1, index2, index3, false);
485 }
486 
487 /** Recalculate the texture points of a given DisplayObject
488  * based on its valid texture coordinates
489  *
490  * \return true On success
491  * \return false If the texture points could not be calculated.
492  * (The object doesn't have three non-colinear vertices or doesn't have texture coordinates.)
493  */
494 GLS_EXPORT bool CalculateTexPointsFromTexCoords(DisplayObject* object);
495 
496 /** Encodes a string such that if it contains newlines, it will be wrapped with the "#$STRING_START$#" and "#$STRING_END$#" delimiters.
497  * \param dest Destination string
498  * \param src Source string
499  * \param dest_str_length Size of the destination buffer
500  * \return The length of the encoded string.
501  */
502 GLS_EXPORT int EncodeString( char* dest, const char* src, const int dest_str_length );
503 
504 /** Encodes a std::string such that there are no whitespace characters in the string
505  * \param src Source string
506  * \return The encoded string
507  */
508 GLS_EXPORT std::string EncodeString(const std::string& src);
509 
510 /** Returns a minimum length for a call to EncodeString.
511  * This is based on the clear text delimeters
512  */
513 GLS_EXPORT int EncodedStringMinLength();
514 
515 /** Encodes a string using C language encoding
516  * \param dest Destination string
517  * \param src Source string
518  * \param dest_str_length Size of the destination buffer
519  * \return The length of the encoded string
520  */
521 GLS_EXPORT int C_EncodeString( char *dest, const char *src, const int dest_str_length );
522 
523 /** Returns and encoded std::string using C language encoding
524  * \param src Source string
525  * \return The encoded string
526  */
527 GLS_EXPORT std::string C_EncodeString(const std::string& src);
528 
529 /** Decodes a string that was encoded using EncodeString
530  * \param dest Destination string
531  * \param src Source string
532  * \param dest_str_length Size of the destination buffer
533  * \return The length of the encoded string
534  */
535 GLS_EXPORT int DecodeString(char *dest,const char *src, const int dest_str_length);
536 
537 /** Decodes a std::string that was encoded using EncodeString
538  * \param src Encoded Source string
539  * \return The decoded string
540  */
541 GLS_EXPORT std::string DecodeString(const std::string& src);
542 
543 /** The InlinePixmap structure
544  */
545 typedef struct
546 {
547  int width;
548  int height;
549  int comprSize;
550  unsigned char *pixels;
551 } InlinePixmap;
552 
553 GLS_EXPORT char *MakeRelativePath(const char *originalPath, const char *relativePath);
554 GLS_EXPORT void ConvertBackslashToSlash(char *str);
555 GLS_EXPORT void ConvertBackslashToSlash(std::string &str);
556 
557 /** Determines if the given value falls in any of the ranges passed in.
558 
559  range_check(int number_of_ranges, double test_value,
560  int index_0,double range_0_min,double range_0_max,
561 
562  ...
563 
564  int index_n,double range_n_min,double range_n_max);
565 
566  For example, to return 1 for values 0-10 and 2 for values 10-20:
567 
568  index = range_check(2,val,
569  1, 0.0, 10.0,
570  2, 10.0, 20.0);
571 */
572 
573 GLS_EXPORT int range_check(int num,double val,...);
574 
575 /** Attempts to open the given file. Pops up an error message box if the
576  * attempt fails
577  * \param filename The name of the file to open
578  * \param flags fopen style file arguments (e.g. "r")
579  * \param f Contains file pointer on success
580  * \return True if the operation was successful
581  */
582 GLS_EXPORT int Safe_fopen(const char *filename,char *flags,FILE **f);
583 /** Stream version */
584 GLS_EXPORT int Safe_fopen(const char *filename,char *flags,std::fstream &outstr);
585 
586 #ifdef ANDROID
587 /** Sets if assets should be loaded directly from the apk (default true).
588  * This only affects Android builds.
589  * \param enableDirectAssetLoading true to allow assets to be loaded directly from the apk
590  * false to force assets to be read from the resource directory (\see SetResourcePath)
591  * \post HasAssetExtension returns false for all filetypes if direct asset loading was disabled
592  */
593 GLS_EXPORT void EnableDirectAssetLoading(bool enableDirectAssetLoading);
594 
595 /** Returns if the filetype is one that can be loaded directly from the apk assets.
596  * This only affects Android builds.
597  * \param filename The filename with extension to check
598  * \return True if the filetype can be loaded directly from the apk assets,
599  * False if the file is loaded from internal or external storage
600  */
601 GLS_EXPORT bool HasAssetExtension(const char *filename);
602 
603 /** Returns if the file exists in the apk assets.
604  * This only affects Android builds.
605  * \param filename The name of the file
606  * \return True if the file is an asset that can be opened.
607  * Returns false if no asset exists with filename or the pointer to the AAssetManager, set with SetAssetManager, is null.
608  */
609 GLS_EXPORT bool AssetExists(const char *filename);
610 
611 /** Sets the Android Asset Manager to use.
612  * When the assetManager is null, apk assets cannot be loaded.
613  * This only affects Android builds.
614  * \param assetManager The pointer to the AAssetManager
615  */
616 GLS_EXPORT void SetAssetManager(AAssetManager *assetManager);
617 #endif
618 
619 #if defined(ANDROID) || ( defined(LINUX) && defined(GLES) )
620 /** Prepends the resource path to a file name.
621  * \param[in] filename_ The name of the file
622  * \return string containing ResourcePath+filename_, with OS specific path.
623  * On Android, apk asset files are not prepended with a path.
624  */
625 GLS_EXPORT std::string ResolvePath(const char* filename_);
626 
627 /** Sets the path for locating resource files.
628  * On Android, this is the location where resources outside of apk assets are found.
629  * \param resourcePath The path where application resources will be found
630  */
631 GLS_EXPORT void SetResourcePath(const char *resourcePath);
632 
633 /** Attempts to open the given file. Prepends the filename with the path from SetResourcePath
634  * for non-absolute paths.
635  * On Android, filenames that match an apk asset are opened. Opened assets should be closed
636  * with fclose to free resources, not with the Android Asset Manager close function (AAsset_close)
637  * \param filename The name of the file to open
638  * \param flags fopen style file arguments (e.g. "r")
639  * \pre On Android, Asset Manager != NULL, set with SetAssetManager, when opening an apk asset
640  * \return FILE pointer or NULL otherwise
641  */
642 GLS_EXPORT FILE *gls_fopen(const char *filename,const char *flags);
643 #else
644 /** Pushes a resource search path onto the stack. The CWD is always
645  * implicitly searched first. The resource search paths are local to
646  * the calling thread only. This function should be called from the same
647  * thread as the resources are loaded from.
648  * \param resourcePath The directory path to add to the search paths
649  */
650 GLS_EXPORT void PushResourcePath(const char *resourcePath);
651 
652 /** Remove the first search path from the stack. The resource search paths
653  * are local to the calling thread only. This function should be called from
654  * the same thread as the matching PushResourcePath.
655  */
656 GLS_EXPORT void PopResourcePath();
657 
658 /** Pushes a function that can locate resources. The Resources finders are applied after the resource paths are searched
659  * \param resourcePath The directory path to add to the search paths
660  */
661 GLS_EXPORT void PushResourceFinder( std::string (*finder)( const std::string&) );
662 
663 /** Resolves the given path searching the resource path list. The
664  * CWD is always implicity searched first.
665  * \param path The relative path to resolve
666  */
667 GLS_EXPORT std::string ResolvePath(const char *path);
668 
669 // helper method taking a std::string
670 inline std::string ResolvePath( const std::string& path )
671 {
672  return ResolvePath( path.c_str() );
673 }
674 
675 /** Attempts to open the given file. Relative file paths
676  * are resolved using ResolvePath.
677  * \param filename The name of the file to open
678  * \param flags fopen style file arguments (e.g. "r")
679  * \return FILE pointer or NULL otherwise
680  */
681 GLS_EXPORT FILE *gls_fopen(const char *filename,const char *flags);
682 #endif
683 
684 #if !defined(NOSOUND)
685 #if (defined(LINUX) || defined(SUNOS) || defined(SGI)) && !defined(ANDROID)
686 GLS_EXPORT AFfilehandle gls_afOpenFile(const char *path,const char *mode,AFfilesetup setup);
687 #endif
688 #endif
689 
690 #ifdef __APPLE__
691 /** \return a string indicating the location of a specific file in the default resource bundle.
692  * This method is designed for runtime platforms that have a pre-defined bundle
693  * location that is not immediately known to the application until runtime.
694  * in iOS, this returns the path to the main application bundle with the file name appended.
695  * \param fileName A string referring to the file without a path.
696  */
697  GLS_EXPORT std::string GetAbsolutePathAndFileNameInDefaultResourceBundle(const char* fileName);
698 #endif
699 
700 /** Prepends the resource path to a file name.
701  * \param[in] fileName The name of the file
702  * \return string containing ResourcePath + fileName, with OS specific path.
703  * On Android, apk asset files are not prepended with a path.
704  */
705 GLS_EXPORT std::string ResolveRuntimeResourcePath( const char* fileName );
706 
707 /** \return true if the file exists, false otherwise
708  * \param filename The filename to check
709  */
710 GLS_EXPORT bool FileExists(const char *filename);
711 GLS_EXPORT bool FileExists(const std::string &filename);
712 
713 /** \return true if the file exists and is a directory, false otherwise
714  * \param filename The filename to check
715  */
716 GLS_EXPORT bool IsDirectory( const char* filename );
717 GLS_EXPORT bool IsDirectory( const std::string& filename );
718 
719 /** \return The file extension for a filepath
720  * \param filepath Filepath to get extension from
721  */
722 GLS_EXPORT std::string FileExtension(const std::string& filepath);
723 
724 /** \return The filename from a file path by stripping off anything to the left of a slash
725  * \param filepath
726  */
727 GLS_EXPORT std::string FileName(const std::string& filepath);
728 
729 /** \return a string containing the path portion of a filename
730  * by stripping off everything to the right of the rightmost slash
731  * \param filepath A string containing a file with a path
732  */
733 GLS_EXPORT std::string FilePath(const std::string& filepath);
734 
735 /** \return a pointer to the string containing the path portion of a filename
736  * by stripping off everything to the right of the rightmost slash
737  * \param name A string containing a file with a path
738  */
739 GLS_EXPORT const char *GetFilePath(const char *name);
740 
741 /** \return The filename from a file path by stripping off anything to the left of a slash
742  * \param name A string containing just the file name without a path
743  */
744 GLS_EXPORT char *GetFileName(const char *name);
745 
746 /** Appends a trailing slash to a path string, if one isn't there already
747  * \param s File path
748  */
749 GLS_EXPORT void AppendTrailingSlash(char *s);
750 
751 /** Appends a trailing slash to a path string, if one isn't there already
752  * \param s File path
753  */
754 GLS_EXPORT void AppendTrailingSlash(std::string &s);
755 
756 /** Convert a directory path to have the correct OS
757  * slashes /, or \. Also make sure that the path ends in a \, or /.
758  * So you always have the form <name 1>\\<name 2>...<name n>\\\, or <name 1>/<name 2>...<name n>/
759  * \param path A path to convert
760  * \return a "new-ed" string which may be longer than the original.
761  * It is the calling functions responsibility to free the memory.
762  */
763 GLS_EXPORT char *PathToOS(const char *path);
764 
765 /** \return The file extension for a filename
766  * \param filename Filename to get extension from
767  * No longer allocates memory, you can let the returned string
768  * be colected as it falls out of scope
769  */
770 GLS_EXPORT const std::string GetExtension(const std::string &filename);
771 
772 /** Gets the file name from a filename with path
773  * It does not allocate new memory, but rather just returns
774  * a pointer inside the original string
775  */
776 GLS_EXPORT char *GetBaseName(char* basename);
777 
778 /** Removes and double slashes from a path.
779  * It will look for the specified type of slash.
780  * It will modify path, but since it can only shrink,
781  * no allocation is done.
782  * \param path The path to operate on.
783  * \param slash The type of slash to search for.
784  */
785 GLS_EXPORT void RemoveDoubleSlashes(char* path, char slash = '/');
786 
787 /** \return The minimum angular distance between angle1 and angle2 in degrees
788  * \param angle1 First angle
789  * \param angle2 Second angle
790  */
791 GLS_EXPORT float AngularDistanceDeg(float angle1, float angle2);
792 
793 /** \return The minimum angular distance between angle1 and angle2 in radians
794  * \param angle1 First angle
795  * \param angle2 Second angle
796  */
797 GLS_EXPORT float AngularDistanceRad(float angle1, float angle2);
798 
799 GLS_EXPORT bool ContainsNonBlank( const std::string& val );
800 
801 GLS_EXPORT bool GetNoSpaces(FILE *f, char *result, int maxLen);
802 GLS_EXPORT bool GetToEnd(std::istream &instr, std::string &result, bool decode);
803 GLS_EXPORT bool GetVertex(std::istream &instr, Vertex* vert, bool getColor);
804 
805 /** Searches the specified binary file for the specified tag, and adds what immediatly follows the tag to the nameList.
806  * Returns true if at least one is found, false otherwise.
807  */
808 GLS_EXPORT bool GetComponentClassNames(const char* dllFileName, DynamicArray<std::string,false>& nameList, const char* createClassTag = "CreateComponent_" );
809 
810 /** Opens the DLL and attempts to run GlsDefaultClassName(), if found.
811  * Returns an empty string if not found. */
812 GLS_EXPORT std::string GetDefaultComponentClassName(const char* dllFileName);
813 
814 /** Returns the qualified instance name of an object that is
815  * contained within given DisplayFrame. (e.g "cockpit.altimeter.needle")
816  * Note that names are only added for each DisplayFrame (not every Group)
817  * and the name of the topFrame is not included in the qualified name.
818  * \param topFrame The frame in which the qualification will make sense.
819  * \param obj The object which is a direct child or located somewhere below topFrame.
820  * \returns The qualified instance name or an empty string if the qualified
821  * instance name could not be determined. */
822 GLS_EXPORT std::string GetQualifiedInstanceName(const DisplayFrame* topFrame, const DisplayObject* obj);
823 
824 #ifndef GLES
825 GLS_EXPORT bool OpenFileDialog(Fl_Window *win, char *filePath, unsigned int filePathSize,
826  char *directory = NULL, const char *filterStr = NULL,
827  const char *defaultExt = NULL, const char *title = NULL,
828  bool multiSelect = false, bool createFile = false,
829  bool fileMustExist = false, bool pathMustExist = false,
830  bool noChangeDirectory = false);
831 
832 GLS_EXPORT bool SaveFileDialog(Fl_Window *win, char *filePath, unsigned int filePathSize,
833  char *directory = NULL, const char *filterStr = NULL,
834  const char *defaultExt = NULL, const char *title = NULL,
835  bool createFile = false,
836  bool fileMustExist = false, bool pathMustExist = false,
837  bool noChangeDirectory = false);
838 #endif
839 GLS_EXPORT void CheckGLError(void);
840 
841 //---------------------------------------------------------------------------
842 /**
843 * Returns a string which is the uppercase version of the passed parameter.
844 *
845 * \param str original string to convert to Uppercase
846 *
847 * \return a string copy of the original but in all caps.
848 */
849 GLS_EXPORT std::string Uppercase(const std::string& str);
850 
851 GLS_EXPORT std::string ReplaceEnvironmentVariables(const char* originalPath);
852 
853 /** A singleton used for accessing the command line arguments in generated code
854  */
856 {
857 
858  bool _silentMode; /** Whether or not the app should run in silent mode */
859 
860 public:
861  GLS_EXPORT glsCommandLine(void);
862  GLS_EXPORT void ReadCommandLine(int argc, char **argv );
863  GLS_EXPORT void Usage();
864 
865  int _argc;
866  char **_argv;
867 
868  bool SilentMode(void) { return _silentMode; }
869 
870  static GLS_EXPORT glsCommandLine* Instance();
871  static glsCommandLine *_instance;
872 };
873 
874 /** Used to make interface information visible to the user at design time*/
876 {
877 protected:
878  char* _code; // e.g. "DynamicRotate("
879  char* _usage; // e.g. "void DynamicRotate(float angle, int axis)"
880  char* _comment; // e.g. "Sets dynamic rotation in degrees for the specified axis"
881 public:
882  // Default constructor
883  GLS_EXPORT InterfaceDescriptionClass();
884  // Copy constructor
885  GLS_EXPORT InterfaceDescriptionClass(const InterfaceDescriptionClass& source);
886  // Destructor
887  GLS_EXPORT ~InterfaceDescriptionClass();
888  // Copy operator
889  GLS_EXPORT InterfaceDescriptionClass(const char* code, const char* usage, const char* comment);
890 
891  GLS_EXPORT void operator=(const InterfaceDescriptionClass& source);
892  GLS_EXPORT void Code(const char*);
893  GLS_EXPORT const char* Code() const;
894  GLS_EXPORT void Usage(const char*);
895  GLS_EXPORT const char* Usage() const;
896  GLS_EXPORT void Comment(const char*);
897  GLS_EXPORT const char* Comment() const;
898 };
900 
901 /** Base class for GlsMultiVal template
902  */
904 {
905 public:
906  virtual ~GlsMultiValBase() {}
907 
908  //These are used to avoid template problems with VC6.0
909  typedef std::ostream ostreamType;
910  typedef std::istream istreamType;
911 
912  virtual void StreamOut(ostreamType & outstr) const = 0;
913  virtual void StreamIn(istreamType & instr) = 0;
914 };
915 
916 
917 /** GlsMultiVal is used to effectivly create a structure containing up
918  * to 10 values of varying types. An instance of the class is capable
919  * of streaming itself to and from a text stream. The individual values
920  * will be separated by spaces when written and read from the stream.
921  * The types have to follow some rules:
922  * - They must themselves have the << and >> stream operators defined.
923  * - operator>> must read all data written by operator<< and must not consume spaces or other characters that follow it
924  * - They must have a default constructor
925  * - They must have a copy constructor
926  * - They shall not be void* (it is used for determining the end of the desired types).
927  * - If a GlsPropString is used, there must be only one, and it *must* be the
928  * last entry in the GlsMultiVal instance.
929  * - A GlsPropStringQuoted will work in any position.
930  * This is intended primarily for the GL Studio end user to use as a Class Property type.
931  */
932 template < class T1,
933  class T2 = void*,
934  class T3 = void*,
935  class T4 = void*,
936  class T5 = void*,
937  class T6 = void*,
938  class T7 = void*,
939  class T8 = void*,
940  class T9 = void*,
941  class T10 = void*>
943 {
944  int _numVals;
945  void CalcNumVals()
946  {
947  _numVals = 1;
948  if (typeid(T2) != typeid(void*)) _numVals++; else return;
949  if (typeid(T3) != typeid(void*)) _numVals++; else return;
950  if (typeid(T4) != typeid(void*)) _numVals++; else return;
951  if (typeid(T5) != typeid(void*)) _numVals++; else return;
952  if (typeid(T6) != typeid(void*)) _numVals++; else return;
953  if (typeid(T7) != typeid(void*)) _numVals++; else return;
954  if (typeid(T8) != typeid(void*)) _numVals++; else return;
955  if (typeid(T9) != typeid(void*)) _numVals++; else return;
956  if (typeid(T10) != typeid(void*)) _numVals++; else return;
957 
958  }
959 public:
960 
961 
962  T1 _val1;
963  T2 _val2;
964  T3 _val3;
965  T4 _val4;
966  T5 _val5;
967  T6 _val6;
968  T7 _val7;
969  T8 _val8;
970  T9 _val9;
971  T10 _val10;
972 
973 
974  /**
975  Default constructor.
976 
977  The _val member types must have default constructors.
978  */
980  {
981  CalcNumVals();
982  }
983 
984  /**
985  Copy constructor.
986 
987  This GlsMultiVal will copy values from the src GlsMultiVal.
988 
989  \param src GlsMultiVal object to use for initialization.
990  \return
991  */
992  GlsMultiVal(const GlsMultiVal& src) :
993  _val1(src._val1),
994  _val2(src._val2),
995  _val3(src._val3),
996  _val4(src._val4),
997  _val5(src._val5),
998  _val6(src._val6),
999  _val7(src._val7),
1000  _val8(src._val8),
1001  _val9(src._val9),
1002  _val10(src._val10)
1003  {
1004  CalcNumVals();
1005  }
1006  /**
1007  Full constructor. Creates a GlsMultiVal object with the provided data.
1008 
1009  \param val1 First value to use for intialization of type T1.
1010  \param val2 First value to use for intialization of type T2.
1011  \param val3 First value to use for intialization of type T3.
1012  \param val4 First value to use for intialization of type T4.
1013  \param val5 First value to use for intialization of type T5.
1014  \param val6 First value to use for intialization of type T6.
1015  \param val7 First value to use for intialization of type T7.
1016  \param val8 First value to use for intialization of type T8.
1017  \param val9 First value to use for intialization of type T9.
1018  \param val10 First value to use for intialization of type T10.
1019  \return
1020  */
1022  const T1& val1,
1023  const T2& val2 = T2(),
1024  const T3& val3 = T3(),
1025  const T4& val4 = T4(),
1026  const T5& val5 = T5(),
1027  const T6& val6 = T6(),
1028  const T7& val7 = T7(),
1029  const T8& val8 = T8(),
1030  const T9& val9 = T9(),
1031  const T10& val10 = T10() ) :
1032  _val1(val1),
1033  _val2(val2),
1034  _val3(val3),
1035  _val4(val4),
1036  _val5(val5),
1037  _val6(val6),
1038  _val7(val7),
1039  _val8(val8),
1040  _val9(val9),
1041  _val10(val10)
1042  {
1043  CalcNumVals();
1044  }
1045 
1046  /** Compares two multival objects for equality */
1047  virtual bool operator==(const GlsMultiVal& val) const
1048  {
1049  bool rval = true;
1050  // Only compare the number of used values.
1051  switch (_numVals)
1052  {
1053  // No breaks is intentional
1054  case 10: rval &= (_val10 == val._val10);
1055  case 9: rval &= (_val9 == val._val9);
1056  case 8: rval &= (_val8 == val._val8);
1057  case 7: rval &= (_val7 == val._val7);
1058  case 6: rval &= (_val6 == val._val6);
1059  case 5: rval &= (_val5 == val._val5);
1060  case 4: rval &= (_val4 == val._val4);
1061  case 3: rval &= (_val3 == val._val3);
1062  case 2: rval &= (_val2 == val._val2);
1063  case 1: rval &= (_val1 == val._val1);
1064  break;
1065  default:
1066  rval = false;
1067  }
1068  return rval;
1069  }
1070 
1071  /** Inverse of equality */
1072  virtual bool operator!=( const GlsMultiVal& val ) const
1073  {
1074  return !( *this == val );
1075  }
1076 
1077  /**
1078  StreamOut(). This function serializes itself into the provided stream object.
1079 
1080  \param outstr This is the object used by the GlsMultiVal class to serialize itself onto.
1081  \return
1082  */
1083  virtual void StreamOut(ostreamType & outstr) const
1084  {
1085  outstr << _val1;
1086  if (_numVals >= 2)
1087  outstr << " " <<_val2;
1088  if (_numVals >= 3)
1089  outstr << " " <<_val3;
1090  if (_numVals >= 4)
1091  outstr << " " <<_val4;
1092  if (_numVals >= 5)
1093  outstr << " " <<_val5;
1094  if (_numVals >= 6)
1095  outstr << " " <<_val6;
1096  if (_numVals >= 7)
1097  outstr << " " <<_val7;
1098  if (_numVals >= 8)
1099  outstr << " " <<_val8;
1100  if (_numVals >= 9)
1101  outstr << " " <<_val9;
1102  if (_numVals >= 10)
1103  outstr << " " <<_val10;
1104  }
1105 
1106  /**
1107  StreamIn(). Uses the provided istream object to populate the current GlsMultiVal object
1108 
1109  \param instr This is the stream object used by the GlsMultiVal instance to populate itself.
1110  \return
1111  */
1112  virtual void StreamIn(istreamType & instr)
1113  {
1114  instr >> _val1;
1115  if (_numVals >= 2)
1116  {
1117  instr.get(); // The separating space
1118  instr >> _val2;
1119  }
1120  if (_numVals >= 3)
1121  {
1122  instr.get();
1123  instr >> _val3;
1124  }
1125  if (_numVals >= 4)
1126  {
1127  instr.get();
1128  instr >> _val4;
1129  }
1130  if (_numVals >= 5)
1131  {
1132  instr.get();
1133  instr >> _val5;
1134  }
1135  if (_numVals >= 6)
1136  {
1137  instr.get();
1138  instr >> _val6;
1139  }
1140  if (_numVals >= 7)
1141  {
1142  instr.get();
1143  instr >> _val7;
1144  }
1145  if (_numVals >= 8)
1146  {
1147  instr.get();
1148  instr >> _val8;
1149  }
1150  if (_numVals >= 9)
1151  {
1152  instr.get();
1153  instr >> _val9;
1154  }
1155  if (_numVals >= 10)
1156  {
1157  instr.get();
1158  instr >> _val10;
1159  }
1160  }
1161 };
1162 
1163 GLS_EXPORT std::ostream & operator<<(std::ostream & outstr, const GlsMultiValBase & multiVal);
1164 GLS_EXPORT std::istream & operator>>(std::istream & instr, GlsMultiValBase & multiVal);
1165 
1166 /** GlsPropString is designed to be used as a string in GL Studio Class Properties.
1167  * It writes itself out as a single line, and will read in up to the next newline.
1168  * It will attempt to convert itself to and from std::strings.
1169  * If it is used in a GlsMultiVal, there must be only one, and it *must* be the
1170  * last entry in the GlsMultiVal instance.
1171  * See GlsPropStringQuoted for more usefulness in GlsMultiVal.
1172  */
1174 {
1175 public:
1176  std::string _string;
1177 
1178  /** Default constructor Creates an empty GlsPropString. */
1179  GlsPropString() : _string( "" )
1180  {
1181  }
1182  /**
1183  Create a new GlsPropString using the provided std string.
1184 
1185  \param str std::string to use to create the GlsPropString
1186  \return
1187  */
1188  GlsPropString(const std::string& str) : _string( str )
1189  {
1190  }
1191 
1192  /**
1193  Create a new GlsPropString using the provided c-style string.
1194 
1195  \param str c-style string to use to create the GlsPropString.
1196  \return
1197  */
1198  GlsPropString( const char* str ) : _string( str ? str : "" )
1199  {
1200  }
1201 
1202  operator std::string() const
1203  {
1204  return _string;
1205  }
1206 
1207  /**
1208  Get the string value for this object.
1209  \return std::string containing the string value for this object.
1210  */
1211  std::string& String()
1212  {
1213  return _string;
1214  }
1215 
1216  /** Checks lexicographic equality of the two arguments */
1217  friend inline bool operator==( const GlsPropString& str1, const GlsPropString& str2 )
1218  {
1219  return str1._string == str2._string;
1220  }
1221 
1222  /** Checks lexicographic inequality of the two arguments */
1223  friend inline bool operator!=( const GlsPropString& str1, const GlsPropString& str2 )
1224  {
1225  return !(str1 == str2 );
1226  }
1227 };
1228 
1229 inline std::ostream & operator<<(std::ostream & outstr, const GlsPropString & str)
1230 {
1231  outstr << disti::C_EncodeString(str._string);
1232  return outstr;
1233 }
1234 inline std::istream & operator>>(std::istream & instr, GlsPropString & str)
1235 {
1236  std::string temp;
1237  disti::GetToEnd(instr, temp, false);
1238  str._string = disti::DecodeString(temp);
1239 
1240  return instr;
1241 }
1242 /** GlsPropStringQuoted is designed to be used as a string in GL Studio Class Properties.
1243  * It writes itself out as a single line surrounded with quotes (""), and will read in up to the next un-escaped quote.
1244  * It will attempt to convert itself to and from std::strings.
1245  * Use of GlsPropStringQuoted is preferred over GlsPropString for use in a GlsMultiVal.
1246  */
1248 {
1249 public:
1250  std::string _string;
1251  /** Default constructor, create an empty GlsPropStringQuoted object. */
1253  {
1254  }
1255  /**
1256  Constructor, create a new GlsPropStringQuoted object using the provided std::string object
1257 
1258  \param str std::string object to use to create the GlsPropStringQuoted object
1259  \return
1260  */
1261  GlsPropStringQuoted(const std::string& str) : _string(str)
1262  {
1263  }
1264  /**
1265  Constructor, create a new GlsPropStringQuoted object using the provided c-style string
1266 
1267  \param str c-style string to use to create the GlsPropStringQuoted object
1268  \return
1269  */
1270  GlsPropStringQuoted(const char* str) : _string(str)
1271  {
1272  }
1273  operator std::string() const
1274  {
1275  return _string;
1276  }
1277  std::string& String()
1278  {
1279  return _string;
1280  }
1281  bool operator == (const GlsPropStringQuoted& str) const
1282  {
1283  return str._string == _string;
1284  }
1285 };
1286 inline std::ostream & operator<<(std::ostream & outstr, const GlsPropStringQuoted & str)
1287 {
1288  outstr << '\"' <<disti::C_EncodeString(str._string) <<'\"';
1289  return outstr;
1290 }
1291 inline std::istream & operator>>(std::istream & instr, GlsPropStringQuoted & str)
1292 {
1293  std::string temp;
1294  str._string = "";
1295 
1296  // The next character should be a quote.
1297  // If it is not, we will attempt to do something useful anyway.
1298  if (instr.peek() != '\"')
1299  {
1300  disti::GetToEnd(instr, temp, false);
1301  }
1302  else // Starts with quote
1303  {
1304  // Go ahead and consume the quote
1305  instr.get();
1306 
1307  int lastChar = 0;
1308  int currChar = 0;
1309  // Loop until we find an un-escaped quote or we run out of stream.
1310  while (instr.good())
1311  {
1312  lastChar = currChar;
1313  currChar = instr.get();
1314  if (currChar != -1)
1315  {
1316  if (currChar == '\"' && lastChar != '\\')
1317  break; // We found the trailing quote
1318  temp += (char)currChar;
1319  }
1320  }
1321  }
1322 
1323  str._string = disti::DecodeString(temp);
1324 
1325  return instr;
1326 }
1327 
1328 #ifndef WIN32
1329 void SpawnBrowser(const char *url);
1330 #endif
1331 
1332 /** Call this to check for the availability of a DiSTI conrolled license.
1333  It does not hold the license. It only checks it out and checks it back in.
1334  \param licenseGroupName A name for what this license allows. i.e. "GL Studio Runtime".
1335  \param feature The specific feature that will be checked out.
1336  \param version The specific version that will be checked out.
1337  \param quiet When true, no popup will occur upon missing license.
1338  */
1339 GLS_EXPORT bool CheckDistiLicense(const char* licenseGroupName, const char *feature, const char *version, bool quiet);
1340 
1341 /** This will set the m parameter to an orthographic projection.
1342  * The current value of m is ignored.
1343  * This does NOT make any OpenGL calls.
1344  */
1345 GLS_EXPORT void GlsGetOrtho(GlsMatrixType& m,
1346  double left,
1347  double right,
1348  double bottom,
1349  double top,
1350  double zNear,
1351  double zFar);
1352 
1353 /** This will set the m parameter to a perspective projection.
1354  * The current value of m is ignored
1355  * This does NOT make any OpenGL calls.
1356  */
1357 GLS_EXPORT void GlsGetPerspective(GlsMatrixType& m,
1358  double fovy,
1359  double aspect,
1360  double zNear,
1361  double zFar);
1362 
1363 // using a namespace to help avoid collisions with user code. Future functionality should prefer to go here
1364 namespace Util
1365 {
1366  ////////////////////////////////////////////////////////////////////////////////
1367  /// Clamps a value to the range [min, max]
1368  /// \param val The value to clamp
1369  /// \param min The minimum value in the range
1370  /// \param max The maximum value in the range
1371  ////////////////////////////////////////////////////////////////////////////////
1372  template<class T>
1373  T Clamp( const T& val, const T& min, const T& max )
1374  {
1375  return std::min( max, std::max( min, val ) );
1376  }
1377 
1378  ////////////////////////////////////////////////////////////////////////////////
1379  /// Split a string and add to existing vector of elements with delimeters removed.
1380  /// \param s The string to split
1381  /// \param delim The delimiter to split the string on.
1382  /// \param elems The vector of elements to append each split string to.
1383  /// \param maxElems The maximum number of elements to split. Remaining elements
1384  /// are appended unsplit as the last value. If 0, it does not
1385  /// have a maximum.
1386  /// \note Adapted from http://stackoverflow.com/questions/236129/split-a-string-in-c
1387  ////////////////////////////////////////////////////////////////////////////////
1388  inline void Split( const std::string& s, const char delim, std::vector<std::string>& elems, const std::size_t maxElems = 0 )
1389  {
1390  std::istringstream ss( s );
1391  std::string item;
1392  while( std::getline( ss, item, delim ) )
1393  {
1394  elems.push_back( DISTI_RVAL_MOVE( item ) );
1395  if( elems.size() == maxElems )
1396  {
1397  break;
1398  }
1399  }
1400  if( elems.size() == maxElems && ss.good() && maxElems > 0 )
1401  {
1402  std::string remainder;
1403  std::getline( ss, remainder, '\0' );
1404  elems.back() += delim + remainder;
1405  }
1406  }
1407 
1408  ////////////////////////////////////////////////////////////////////////////////
1409  /// Split a string return a vector of the elements with delimeters removed.
1410  /// \param s The string to split
1411  /// \param delim The delimiter to split the string on.
1412  /// \param maxElems The maximum number of elements to split. Remaining elements
1413  /// are appended unsplit as the last value. If 0, it does not
1414  /// have a maximum.
1415  /// \return The vector of split elements.
1416  /// \note Adapted from http://stackoverflow.com/questions/236129/split-a-string-in-c
1417  ////////////////////////////////////////////////////////////////////////////////
1418  inline std::vector<std::string> Split( const std::string& s, const char delim, const std::size_t maxElems = 0 )
1419  {
1420  std::vector<std::string> elems;
1421  Split( s, delim, elems, maxElems );
1422  return DISTI_RVAL_MOVE( elems );
1423  }
1424 
1425  /// Passing null to std::string is not well-defined. Create a string safely.
1426  inline std::string MakeString( const char* const cStr )
1427  {
1428  return ( cStr ? cStr : "" );
1429  }
1430 } // namespace Util
1431 
1432 } // namespace disti
1433 
1434 // Our own local versions of a few glu methods to avoid needing to include the GL Utility library
1435 GLS_EXPORT void glsPerspective(double fovy, double aspect, double zNear, double zFar);
1436 
1437 
1438 #ifdef MATRIX_TYPE_FLOAT
1439 GLS_EXPORT bool glsProject(double objx, double objy, double objz,
1440  const float modelMatrix[16],
1441  const float projMatrix[16],
1442  const int viewport[4],
1443  double *winx, double *winy, double *winz);
1444 
1445 GLS_EXPORT bool glsUnProject(double winx, double winy, double winz,
1446  const float modelMatrix[16],
1447  const float projMatrix[16],
1448  const int viewport[4],
1449  double *objx, double *objy, double *objz);
1450 #else
1451 GLS_EXPORT bool glsProject(double objx, double objy, double objz,
1452  const double modelMatrix[16],
1453  const double projMatrix[16],
1454  const int viewport[4],
1455  double *winx, double *winy, double *winz);
1456 
1457 GLS_EXPORT bool glsUnProject(double winx, double winy, double winz,
1458  const double modelMatrix[16],
1459  const double projMatrix[16],
1460  const int viewport[4],
1461  double *objx, double *objy, double *objz);
1462 #endif
1463 
1464 
1465 #endif
The DistiUnhideGlobalsDummyClass class.
char * GetBaseName(char *basename)
const T & Min(const T &x, const T &y)
Definition: util.h:250
int EncodedStringMinLength()
GlsPropStringQuoted(const std::string &str)
Definition: util.h:1261
virtual void StreamOut(ostreamType &outstr) const
Definition: util.h:1083
Definition: vertex.h:365
GlsDefinedColorEnum
Definition: util.h:176
const int INLINE_TEXTURE_LINE_LENGTH
Definition: util.h:104
Definition: util.h:1247
std::string & String()
Definition: util.h:1211
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:1198
unsigned char glsDefinedColors[GLS_COLOR_MAX][4]
virtual bool operator!=(const GlsMultiVal &val) const
Definition: util.h:1072
Definition: dynamic_array.h:63
const std::string GetExtension(const std::string &filename)
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:289
std::string FileName(const std::string &filepath)
int EncodeString(char *dest, const char *src, const int dest_str_length)
The GlsMatrixAffine class.
Definition: util.h:855
void AppendTrailingSlash(char *s)
Definition: util.h:942
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)
Definition: util.h:903
GlsMultiVal()
Definition: util.h:979
char * PathToOS(const char *path)
float OpenGLVersion()
Definition: util.h:325
const T & Max(const T &x, const T &y)
Definition: util.h:261
virtual bool operator==(const GlsMultiVal &val) const
Definition: util.h:1047
GlsPropStringQuoted(const char *str)
Definition: util.h:1270
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:211
GlsPropString()
Definition: util.h:1179
void PopResourcePath()
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:368
bool FindNonColinearVertices(int arraySize, Vector array[], int &index1, int &index2, int &index3, bool isVectorArray=true)
Definition: util.h:1173
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:1223
Definition: util.h:545
GlsMultiVal(const GlsMultiVal &src)
Definition: util.h:992
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:1112
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:1021
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:239
char * GetFileName(const char *name)
bool NotColinear(const Vector &a, const Vector &b, const Vector &c)
const char * GetFilePath(const char *name)
Definition: vertex.h:84
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:1217
Contains the DistiAssert macro.
Definition: util.h:875
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:1188
int Safe_fopen(const char *filename, char *flags, FILE **f)
unsigned char * GlsDefinedColor(GlsDefinedColorEnum index)
Definition: util.h:200
Definition: bmpimage.h:46
GlsPropStringQuoted()
Definition: util.h:1252