OpenPolygon  1.0.0
OpenPolygon is a Rendering Engine
eutils.h
1 /*
2  Copyright (C) 2014 - 2016 Mutzii
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 */
18 #ifndef UTILS_H
19 #define UTILS_H
20 
21 #include "index.h"
22 #include "texture.h"
23 
24 namespace Engine
25 {
26  using EMutex = bool;
27 
29  {
30  int heap_usage; //kB
31  };
32 
34  {
35  bool input_thread;
36  bool logic_thread;
37  bool render_thread;
38  };
39 
40  struct ThreadTicks
41  {
42  float ticks_per_second;
43  float tick_timer;
44  int tick_counter;
45  };
46 
47  struct ThreadTimer
48  {
49  float cpu_time_used; //seconds
50  float cpu_timer;
51  };
52 
53  struct ObjectBox
54  {
55  float x,y;
56  float width,height;
57  };
58 
60  {
61  Vector2i terrain_size;
62  Vector2i texture_size;
63  Vector2f player_pos;
64  };
65 
66 
67  class Mutex
68  {
69  public:
70  Mutex(){}
71  ~Mutex() = default;
72 
73  /* Thread Sync with RenderLogic Process */
74  static void SyncLock(void);
75  static void SyncUnlock(void);
76 
77  /* Thread Close Sync with Input Process */
78  static void CloseLock(void);
79  static void CloseUnlock(void);
80 
81  private:
82  static EMutex SYNC_THREAD_MUTEX;
83  static EMutex CLOSE_THREAD_MUTEX;
84 
85  };
86 
87  class Utils
88  {
89  public:
90  Utils(){}
91  ~Utils() = default;
92 
93  static Vector3i getPixelData( Texture * texture , const Vector2i & pixel_coord );
94 
95  static Vector2i getPixelCoord( const Vector2f texture_coord , const Vector2f texture_size );
96  static Vector2i getPixelCoord( const PixelCoordData & data );
97 
98  static bool Simple2DCollision( const ObjectBox & first , const ObjectBox & second );
99 
100  static Vector2f ScreenPixelVector( int display_width , int display_height );
101 
102  static Strings StringSplit(const string &str, const string &delim);
103 
104  static string getExtension( const std::string & file );
105 
106  static const GLubyte * getOpenGLVersion(void);
107 
108  static const GLubyte * geShaderVersion(void);
109 
110  static const std::string getString( const GLubyte * bytes );
111 
112  static const std::string getString( const char * embedded_data[] , size_t array_size );
113 
114  static float getFloat( const GLubyte * bytes );
115 
116  static void calculateCPUTime( ThreadTimer * timer );
117 
118  static void calculateTicks( ThreadTicks * ticks );
119 
120  static void ThreadSleep(ThreadTimer * timer , float & update_rate_ms );
121 
122  static void processMemoryInfo( ProcessMemoryInfo * info );
123  };
124 
125 
126 }
127 #endif // UTILS_H
The Texture class.
Definition: texture.h:37
Definition: eutils.h:28
Definition: eutils.h:59
Definition: element.h:23
Definition: eutils.h:53
Definition: eutils.h:40
Definition: eutils.h:33
Definition: eutils.h:47
Definition: vector.h:55
Definition: eutils.h:67
Definition: eutils.h:87