Sfoglia il codice sorgente

Added time utils, docLocalFull target

Thomas Buck 10 anni fa
parent
commit
ed83ad86ba
9 ha cambiato i file con 113 aggiunte e 173 eliminazioni
  1. 10
    0
      CMakeLists.txt
  2. 1
    0
      ChangeLog
  3. 0
    9
      include/System.h
  4. 32
    0
      include/utils/time.h
  5. 0
    18
      src/SDLSystem.cpp
  6. 35
    145
      src/System.cpp
  7. 1
    0
      src/utils/CMakeLists.txt
  8. 33
    0
      src/utils/time.cpp
  9. 1
    1
      test/math.cpp

+ 10
- 0
CMakeLists.txt Vedi File

@@ -67,6 +67,16 @@ if (DOXYGEN_FOUND)
67 67
         COMMAND cp -R doc/html/* ${PROJECT_SOURCE_DIR}/../apache/
68 68
         COMMAND sed -i '' "s/HAVE_DOT               = NO/HAVE_DOT               = YES/g" Doxyfile
69 69
         SOURCES ${PROJECT_BINARY_DIR}/Doxyfile)
70
+
71
+    # Add custom target to create local documentation with call and caller graphs
72
+    add_custom_target (docLocalFull
73
+        COMMAND sed -i '' "s/CALL_GRAPH             = NO/CALL_GRAPH             = YES/g" Doxyfile
74
+        COMMAND sed -i '' "s/CALLER_GRAPH           = NO/CALLER_GRAPH           = YES/g" Doxyfile
75
+        COMMAND ${DOXYGEN_EXECUTABLE} ${PROJECT_BINARY_DIR}/Doxyfile
76
+        COMMAND cp -R doc/html/* ${PROJECT_SOURCE_DIR}/../apache/
77
+        COMMAND sed -i '' "s/CALL_GRAPH             = YES/CALL_GRAPH             = NO/g" Doxyfile
78
+        COMMAND sed -i '' "s/CALLER_GRAPH           = YES/CALLER_GRAPH           = NO/g" Doxyfile
79
+        SOURCES ${PROJECT_BINARY_DIR}/Doxyfile)
70 80
 endif (DOXYGEN_FOUND)
71 81
 
72 82
 # Clean doc files

+ 1
- 0
ChangeLog Vedi File

@@ -8,6 +8,7 @@
8 8
 	[ 20140307 ]
9 9
 	* Removed duplicated GL initialization code
10 10
 	* Removed duplicated TGA writing code from Texture
11
+	* Moved system_timer into time utilities, changed its API
11 12
 
12 13
 	[ 20140306 ]
13 14
 	* Created utility library

+ 0
- 9
include/System.h Vedi File

@@ -179,13 +179,4 @@ protected:
179 179
     unsigned int mConsoleKey;          //!< Console toggle event now handled lower
180 180
 };
181 181
 
182
-//! \todo Could make these static methods later, depends on API evolution
183
-
184
-/*!
185
- * \brief Sets timer state and returns number of ticks
186
- * \param state 0 - reset, 1 - get number of ticks
187
- * \returns number of ticks
188
- */
189
-unsigned int system_timer(int state);
190
-
191 182
 #endif

+ 32
- 0
include/utils/time.h Vedi File

@@ -0,0 +1,32 @@
1
+/*!
2
+ * \file include/utils/time.h
3
+ * \brief Time handling utilities
4
+ *
5
+ * \author xythobuz
6
+ * \author Mongoose
7
+ */
8
+
9
+#ifndef _UTILS_TIME_H_
10
+#define _UTILS_TIME_H_
11
+
12
+#if defined(linux) || defined(__APPLE__)
13
+#include <time.h>
14
+#include <sys/time.h>
15
+#endif
16
+
17
+extern struct timeval system_timer_start; //!< System timer start time
18
+extern struct timeval system_timer_stop; //!< System timer last read time
19
+extern struct timezone system_timer_tz; //!< System timer timezone info
20
+
21
+/*!
22
+ * \brief Read the system timer
23
+ * \returns number of ticks
24
+ */
25
+unsigned int system_timer();
26
+
27
+/*!
28
+ * \brief Reset the system timer
29
+ */
30
+void system_timer_reset();
31
+
32
+#endif

+ 0
- 18
src/SDLSystem.cpp Vedi File

@@ -104,24 +104,6 @@ void SDLSystem::resize(unsigned int width, unsigned int height) {
104 104
     m_width = width;
105 105
     m_height = height;
106 106
 
107
-    glViewport(0, 0, width, height);
108
-
109
-    /* All this is already done in System::resizeGL() !?
110
-    GLfloat aspect = (GLfloat)width/(GLfloat)height;
111
-    glMatrixMode(GL_PROJECTION);
112
-    glLoadIdentity();
113
-
114
-    // gluPerspective is deprecated!
115
-    // gluPerspective(m_fovY, aspect, m_clipNear, m_clipFar);
116
-    // fix: http://stackoverflow.com/a/2417756
117
-    GLfloat fH = tanf(m_fovY * HEL_PI / 360.0f) * m_clipNear;
118
-    GLfloat fW = fH * aspect;
119
-    glFrustum(-fW, fW, -fH, fH, m_clipNear, m_clipFar);
120
-
121
-    glMatrixMode(GL_MODELVIEW);
122
-    glLoadIdentity();
123
-    */
124
-
125 107
     // Resize context
126 108
     resizeGL(width, height);
127 109
 }

+ 35
- 145
src/System.cpp Vedi File

@@ -23,24 +23,15 @@
23 23
 #include <GL/glu.h>
24 24
 #endif
25 25
 
26
-#if defined(linux) || defined(__APPLE__)
27
-#include <time.h>
28
-#include <sys/time.h>
29
-#endif
30
-
31 26
 #include "utils/math.h"
27
+#include "utils/time.h"
32 28
 #include "System.h"
33 29
 
34
-////////////////////////////////////////////////////////////
35
-// Constructors
36
-////////////////////////////////////////////////////////////
37
-
38
-System::System()
39
-{
30
+System::System() {
40 31
     m_width = 800;
41 32
     m_height = 600;
42 33
 
43
-    m_driver = 0x0;
34
+    m_driver = NULL;
44 35
 
45 36
     m_clipFar  = 4000.0f;
46 37
     m_clipNear = 4.0f;
@@ -63,25 +54,18 @@ System::System()
63 54
 #endif
64 55
 }
65 56
 
66
-
67
-System::~System()
68
-{
57
+System::~System() {
69 58
 }
70 59
 
71
-
72
-////////////////////////////////////////////////////////////
73
-// Public Accessors
74
-////////////////////////////////////////////////////////////
75
-
76
-
77
-unsigned int System::getTicks()
78
-{
79
-    return system_timer(1);
60
+unsigned int System::getTicks() {
61
+    return system_timer();
80 62
 }
81 63
 
64
+void System::resetTicks() {
65
+    system_timer_reset();
66
+}
82 67
 
83
-int System::createDir(char *path)
84
-{
68
+int System::createDir(char *path) {
85 69
 #ifdef WIN32
86 70
     return _mkdir(path);
87 71
 #else
@@ -89,80 +73,57 @@ int System::createDir(char *path)
89 73
 #endif
90 74
 }
91 75
 
92
-
93
-////////////////////////////////////////////////////////////
94
-// Public Mutators
95
-////////////////////////////////////////////////////////////
96
-
97
-unsigned int System::addCommandMode(const char *command)
98
-{
99
-    if (command && command[0] == '[')
100
-    {
76
+unsigned int System::addCommandMode(const char *command) {
77
+    if (command && command[0] == '[') {
101 78
         mCmdModes.pushBack(command);
102 79
         return (mCmdModes.size() - 1);
103
-    }
104
-    else
105
-    {
80
+    } else {
106 81
         return 0;
107 82
     }
108 83
 }
109 84
 
110 85
 //! \fixme Modifer support later
111
-void System::bindKeyCommand(const char *cmd, unsigned int key, int event)
112
-{
86
+void System::bindKeyCommand(const char *cmd, unsigned int key, int event) {
113 87
     printf("Bound command '%s' -> event %i (0x%x key)\n", cmd, event, key);
114 88
     mKeyEvents[key] = event;
115 89
 }
116 90
 
117
-
118
-void System::command(const char *cmd)
119
-{
91
+void System::command(const char *cmd) {
120 92
     bool modeFound = false;
121 93
     char *cmdbuf;
122 94
 
123
-
124 95
     if (!cmd || !cmd[0]) // Null command string
125 96
         return;
126 97
 
127
-    if (cmd[0] == '[') // Set a mode, eg "[Engine.OpenGL.Driver]"
128
-    {
129
-        for (mCmdModes.start(); mCmdModes.forward(); mCmdModes.next())
130
-        {
131
-            if (strcmp(cmd, mCmdModes.current()) == 0)
132
-            {
98
+    if (cmd[0] == '[') { // Set a mode, eg "[Engine.OpenGL.Driver]"
99
+        for (mCmdModes.start(); mCmdModes.forward(); mCmdModes.next()) {
100
+            if (strcmp(cmd, mCmdModes.current()) == 0) {
133 101
                 mCommandMode = mCmdModes.getCurrentIndex();
134 102
                 modeFound = true;
135 103
             }
136 104
         }
137 105
 
138
-        if (!modeFound)
139
-        {
106
+        if (!modeFound) {
140 107
             //  mCommandMode = 0;
141 108
             printf("Command> Unknown mode '%s'\n", cmd);
142 109
         }
143
-    }
144
-    else // Execute a command in current mode, eg "stat fps"
145
-    {
110
+    } else { // Execute a command in current mode, eg "stat fps"
146 111
         cmdbuf = new char[strlen(cmd) + 1];
147 112
         strncpy(cmdbuf, cmd, strlen(cmd) + 1);
148 113
         handleCommand(cmdbuf, mCommandMode);
149 114
     }
150 115
 }
151 116
 
152
-
153
-int System::loadResourceFile(const char *filename)
154
-{
117
+int System::loadResourceFile(const char *filename) {
155 118
     char buffer[256];
156 119
     bool line_comment = false;
157 120
     FILE *f;
158 121
     char c;
159 122
     int i, j;
160 123
 
161
-
162 124
     f = fopen(filename, "r");
163 125
 
164
-    if (!f)
165
-    {
126
+    if (!f) {
166 127
         perror(filename);
167 128
         return -1;
168 129
     }
@@ -173,19 +134,16 @@ int System::loadResourceFile(const char *filename)
173 134
     buffer[0] = 0;
174 135
 
175 136
     // Strip out whitespace and comments
176
-    while (fscanf(f, "%c", &c) != EOF)
177
-    {
137
+    while (fscanf(f, "%c", &c) != EOF) {
178 138
         if (line_comment && c != '\n')
179 139
             continue;
180 140
 
181
-        if (i > 254)
182
-        {
141
+        if (i > 254) {
183 142
             printf("loadResourceFile> Overflow handled\n");
184 143
             i = 254;
185 144
         }
186 145
 
187
-        switch (c)
188
-        {
146
+        switch (c) {
189 147
             case '\v':
190 148
             case '\t':
191 149
                 break;
@@ -195,12 +153,9 @@ int System::loadResourceFile(const char *filename)
195 153
                 break;
196 154
             case '\n':
197 155
                 if (line_comment)
198
-                {
199 156
                     line_comment = false;
200
-                }
201 157
 
202
-                if (buffer[0] == 0)
203
-                {
158
+                if (buffer[0] == 0) {
204 159
                     i = 0;
205 160
                     continue;
206 161
                 }
@@ -209,12 +164,9 @@ int System::loadResourceFile(const char *filename)
209 164
                 //printf("'%s'\n", buffer);
210 165
 
211 166
                 // 'Preprocessor' commands
212
-                if (buffer[0] == '@')
213
-                {
214
-                    if (strncmp(buffer, "@include ", 9) == 0)
215
-                    {
216
-                        for (j = 9; j < i; ++j)
217
-                        {
167
+                if (buffer[0] == '@') {
168
+                    if (strncmp((buffer + 1), "include ", 8) == 0) {
169
+                        for (j = 9; j < i; ++j) {
218 170
                             buffer[j-9] = buffer[j];
219 171
                             buffer[j-8] = 0;
220 172
                         }
@@ -223,9 +175,7 @@ int System::loadResourceFile(const char *filename)
223 175
 
224 176
                         loadResourceFile(fullPath(buffer, 0));
225 177
                     }
226
-                }
227
-                else
228
-                {
178
+                } else {
229 179
                     command(buffer);
230 180
                 }
231 181
 
@@ -242,19 +192,13 @@ int System::loadResourceFile(const char *filename)
242 192
     return 0;
243 193
 }
244 194
 
245
-
246
-void System::setDriverGL(const char *driver)
247
-{
195
+void System::setDriverGL(const char *driver) {
248 196
     unsigned int len;
249 197
 
250
-
251 198
     if (m_driver)
252
-    {
253 199
         delete [] m_driver;
254
-    }
255 200
 
256
-    if (driver && driver[0])
257
-    {
201
+    if (driver && driver[0]) {
258 202
         len = strlen(driver);
259 203
         m_driver = new char[len+1];
260 204
         strncpy(m_driver, driver, len);
@@ -262,17 +206,8 @@ void System::setDriverGL(const char *driver)
262 206
     }
263 207
 }
264 208
 
265
-
266
-void System::resetTicks()
267
-{
268
-    system_timer(0);
269
-}
270
-
271
-
272
-void System::resizeGL(unsigned int w, unsigned int h)
273
-{
274
-    if (!w || !h)
275
-    {
209
+void System::resizeGL(unsigned int w, unsigned int h) {
210
+    if (!w || !h) {
276 211
         printf("resizeGL> ERROR assertions 'w > 0', 'h > 0' failed\n");
277 212
         return;
278 213
     }
@@ -290,51 +225,6 @@ void System::resizeGL(unsigned int w, unsigned int h)
290 225
     glFrustum(-fW, fW, -fH, fH, m_clipNear, m_clipFar);
291 226
 
292 227
     glMatrixMode(GL_MODELVIEW);
293
-}
294
-
295
-////////////////////////////////////////////////////////////
296
-// Private Accessors
297
-////////////////////////////////////////////////////////////
298
-
299
-
300
-////////////////////////////////////////////////////////////
301
-// Private Mutators
302
-////////////////////////////////////////////////////////////
303
-
304
-
305
-
306
-////////////////////////////////////////////////////////////
307
-// Gobal helper functions
308
-////////////////////////////////////////////////////////////
309
-
310
-
311
-unsigned int system_timer(int state)
312
-{
313
-    static struct timeval start;
314
-    static struct timeval stop;
315
-    static struct timezone tz;
316
-
317
-
318
-    switch (state)
319
-    {
320
-        case 0:
321
-            gettimeofday(&start, &tz);
322
-            break;
323
-        case 1:
324
-            gettimeofday(&stop, &tz);
325
-
326
-            if (start.tv_usec > stop.tv_usec)
327
-            {
328
-                stop.tv_usec += 1000000;
329
-                stop.tv_sec--;
330
-            }
331
-
332
-            stop.tv_usec -= start.tv_usec;
333
-            stop.tv_sec -= start.tv_sec;
334
-
335
-            return ((stop.tv_sec - start.tv_sec) * 1000) + ((stop.tv_usec - start.tv_usec) / 1000);
336
-    }
337
-
338
-    return 0;
228
+    glLoadIdentity();
339 229
 }
340 230
 

+ 1
- 0
src/utils/CMakeLists.txt Vedi File

@@ -2,6 +2,7 @@
2 2
 set (UTIL_SRCS ${UTIL_SRCS} "math.cpp")
3 3
 set (UTIL_SRCS ${UTIL_SRCS} "strings.cpp")
4 4
 set (UTIL_SRCS ${UTIL_SRCS} "tga.cpp")
5
+set (UTIL_SRCS ${UTIL_SRCS} "time.cpp")
5 6
 
6 7
 # Include directory
7 8
 include_directories ("${PROJECT_SOURCE_DIR}/include")

+ 33
- 0
src/utils/time.cpp Vedi File

@@ -0,0 +1,33 @@
1
+/*!
2
+ * \file include/utils/time.h
3
+ * \brief Time handling utilities
4
+ *
5
+ * \author xythobuz
6
+ * \author Mongoose
7
+ */
8
+
9
+#include "utils/time.h"
10
+
11
+struct timeval system_timer_start;
12
+struct timeval system_timer_stop;
13
+struct timezone system_timer_tz;
14
+
15
+unsigned int system_timer() {
16
+    gettimeofday(&system_timer_stop, &system_timer_tz);
17
+
18
+    if (system_timer_start.tv_usec > system_timer_stop.tv_usec) {
19
+        system_timer_stop.tv_usec += 1000000;
20
+        system_timer_stop.tv_sec--;
21
+    }
22
+
23
+    system_timer_stop.tv_usec -= system_timer_start.tv_usec;
24
+    system_timer_stop.tv_sec -= system_timer_start.tv_sec;
25
+
26
+    return ((system_timer_stop.tv_sec - system_timer_start.tv_sec) * 1000)
27
+        + ((system_timer_stop.tv_usec - system_timer_start.tv_usec) / 1000);
28
+}
29
+
30
+void system_timer_reset() {
31
+    gettimeofday(&system_timer_start, &system_timer_tz);
32
+}
33
+

+ 1
- 1
test/math.cpp Vedi File

@@ -1,5 +1,5 @@
1 1
 /*!
2
- * \file test/MatMath.cpp
2
+ * \file test/math.cpp
3 3
  * \brief Mat Math Unit Test
4 4
  *
5 5
  * \todo Also test the geometric methods (intersection, distance, midpoint)

Loading…
Annulla
Salva