00001 #ifndef GENUTILS_H
00002 #define GENUTILS_H
00003
00004 #include "glwxConfig.h"
00005 #include "XMLUtils.h"
00006 #include <iostream>
00007 #include <fstream>
00008 #include <vector>
00009
00010 #define deleteObject(A){ if(A){ delete A; A = NULL; } }
00011 #define deleteArray(A) { if(A){ delete[] A; A = NULL; } }
00012
00013 #define MAX_TEX_UNITS 8
00014
00015 class Logger
00016 {
00017 public:
00018 static void writeImmidiateInfoLog(const std::string &info);
00019 static void writeFatalErrorLog(const std::string &logString);
00020 static bool writeErrorLog(const std::string &error);
00021 static void writeInfoLog(const std::string &info);
00022 static void initialize(const char* logfilename = NULL);
00023 static void flush();
00024
00025 private:
00026 static vector<std::string> logStrings;
00027 static std::string logPath;
00028 };
00029
00030 class NamedObject
00031 {
00032
00033 protected:
00034 std::string name;
00035
00036 public:
00037 NamedObject(const char* argName = NULL);
00038 NamedObject(const std::string &argName);
00039 NamedObject(const NamedObject ©);
00040 ~NamedObject();
00041
00042 NamedObject &operator=(const NamedObject ©);
00043 void setName(const char *nameArg);
00044 void setName(const std::string &name);
00045
00046 const std::string &getName() const;
00047 const char* getCharName() const;
00048
00049 };
00050
00051 class Perlin
00052 {
00053 private:
00054 static void normalize2(double v[2]);
00055 static void normalize3(double v[3]);
00056
00057 public:
00058 static void setNoiseFrequency(int frequency);
00059 static int getNoiseFrequency();
00060
00061 static double noise1(double arg);
00062 static double noise2(double vec[2]);
00063 static double noise3(double vec[3]);
00064 static void initialize();
00065 static double noise1D(double x,double alpha,double beta,int n);
00066 static double noise2D(double x, double y, double alpha, double beta, int n);
00067 static double noise3D(double x, double y, double z, double alpha, double beta, int n);
00068 };
00069
00070 class MediaPathManager
00071 {
00072 public:
00073 static const std::string lookUpMediaPath(const std::string &path);
00074 static const std::string getPathAt(int index);
00075
00076 static bool registerPath(const TiXmlElement *MediaPathNode);
00077 static bool registerPath(const std::string &path);
00078
00079 static int getPathCount();
00080 static void printAllPaths();
00081
00082 private:
00083 static std::vector<std::string> dataPaths;
00084 };
00085
00086 template <class ODT>
00087 class DistanceObject
00088 {
00089 public:
00090 DistanceObject()
00091 {
00092 distance = 0.0f;
00093 }
00094
00095 DistanceObject(const ODT &objectArg)
00096 {
00097 distance = 0.0f;
00098 object = objectArg;
00099 }
00100
00101 DistanceObject(const DistanceObject ©)
00102 {
00103 operator=(copy);
00104 }
00105
00106 DistanceObject &operator =(const DistanceObject ©)
00107 {
00108 if(this != ©)
00109 {
00110 distance = copy.distance;
00111 object = copy.object;
00112 }
00113 return *this;
00114 }
00115
00116 bool operator ==(const DistanceObject ©)
00117 {
00118 return (distance == copy.distance);
00119 }
00120
00121 bool operator >=(const DistanceObject ©)
00122 {
00123 return (distance >= copy.distance);
00124 }
00125
00126 bool operator <=(const DistanceObject ©)
00127 {
00128 return (distance <= copy.distance);
00129 }
00130
00131 bool operator >(const DistanceObject ©)
00132 {
00133 return (distance > copy.distance);
00134 }
00135
00136 bool operator < (const DistanceObject ©)
00137 {
00138 return (distance < copy.distance);
00139 }
00140
00141 void setDistance(float dist)
00142 {
00143 distance = dist;
00144 }
00145
00146 float getDistance() const
00147 {
00148 return distance;
00149 }
00150
00151 void setObject(const ODT& objectArg)
00152 {
00153 object =objectArg;
00154 }
00155
00156 ODT &getObject()
00157 {
00158 return object;
00159 }
00160 private:
00161 float distance;
00162 ODT object;
00163
00164 };
00165
00166 #endif