Przeglądaj źródła

Added time utils, docLocalFull target

Thomas Buck 11 lat temu
rodzic
commit
ed83ad86ba
9 zmienionych plików z 113 dodań i 173 usunięć
  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 Wyświetl plik

67
         COMMAND cp -R doc/html/* ${PROJECT_SOURCE_DIR}/../apache/
67
         COMMAND cp -R doc/html/* ${PROJECT_SOURCE_DIR}/../apache/
68
         COMMAND sed -i '' "s/HAVE_DOT               = NO/HAVE_DOT               = YES/g" Doxyfile
68
         COMMAND sed -i '' "s/HAVE_DOT               = NO/HAVE_DOT               = YES/g" Doxyfile
69
         SOURCES ${PROJECT_BINARY_DIR}/Doxyfile)
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
 endif (DOXYGEN_FOUND)
80
 endif (DOXYGEN_FOUND)
71
 
81
 
72
 # Clean doc files
82
 # Clean doc files

+ 1
- 0
ChangeLog Wyświetl plik

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

+ 0
- 9
include/System.h Wyświetl plik

179
     unsigned int mConsoleKey;          //!< Console toggle event now handled lower
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
 #endif
182
 #endif

+ 32
- 0
include/utils/time.h Wyświetl plik

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 Wyświetl plik

104
     m_width = width;
104
     m_width = width;
105
     m_height = height;
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
     // Resize context
107
     // Resize context
126
     resizeGL(width, height);
108
     resizeGL(width, height);
127
 }
109
 }

+ 35
- 145
src/System.cpp Wyświetl plik

23
 #include <GL/glu.h>
23
 #include <GL/glu.h>
24
 #endif
24
 #endif
25
 
25
 
26
-#if defined(linux) || defined(__APPLE__)
27
-#include <time.h>
28
-#include <sys/time.h>
29
-#endif
30
-
31
 #include "utils/math.h"
26
 #include "utils/math.h"
27
+#include "utils/time.h"
32
 #include "System.h"
28
 #include "System.h"
33
 
29
 
34
-////////////////////////////////////////////////////////////
35
-// Constructors
36
-////////////////////////////////////////////////////////////
37
-
38
-System::System()
39
-{
30
+System::System() {
40
     m_width = 800;
31
     m_width = 800;
41
     m_height = 600;
32
     m_height = 600;
42
 
33
 
43
-    m_driver = 0x0;
34
+    m_driver = NULL;
44
 
35
 
45
     m_clipFar  = 4000.0f;
36
     m_clipFar  = 4000.0f;
46
     m_clipNear = 4.0f;
37
     m_clipNear = 4.0f;
63
 #endif
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
 #ifdef WIN32
69
 #ifdef WIN32
86
     return _mkdir(path);
70
     return _mkdir(path);
87
 #else
71
 #else
89
 #endif
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
         mCmdModes.pushBack(command);
78
         mCmdModes.pushBack(command);
102
         return (mCmdModes.size() - 1);
79
         return (mCmdModes.size() - 1);
103
-    }
104
-    else
105
-    {
80
+    } else {
106
         return 0;
81
         return 0;
107
     }
82
     }
108
 }
83
 }
109
 
84
 
110
 //! \fixme Modifer support later
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
     printf("Bound command '%s' -> event %i (0x%x key)\n", cmd, event, key);
87
     printf("Bound command '%s' -> event %i (0x%x key)\n", cmd, event, key);
114
     mKeyEvents[key] = event;
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
     bool modeFound = false;
92
     bool modeFound = false;
121
     char *cmdbuf;
93
     char *cmdbuf;
122
 
94
 
123
-
124
     if (!cmd || !cmd[0]) // Null command string
95
     if (!cmd || !cmd[0]) // Null command string
125
         return;
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
                 mCommandMode = mCmdModes.getCurrentIndex();
101
                 mCommandMode = mCmdModes.getCurrentIndex();
134
                 modeFound = true;
102
                 modeFound = true;
135
             }
103
             }
136
         }
104
         }
137
 
105
 
138
-        if (!modeFound)
139
-        {
106
+        if (!modeFound) {
140
             //  mCommandMode = 0;
107
             //  mCommandMode = 0;
141
             printf("Command> Unknown mode '%s'\n", cmd);
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
         cmdbuf = new char[strlen(cmd) + 1];
111
         cmdbuf = new char[strlen(cmd) + 1];
147
         strncpy(cmdbuf, cmd, strlen(cmd) + 1);
112
         strncpy(cmdbuf, cmd, strlen(cmd) + 1);
148
         handleCommand(cmdbuf, mCommandMode);
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
     char buffer[256];
118
     char buffer[256];
156
     bool line_comment = false;
119
     bool line_comment = false;
157
     FILE *f;
120
     FILE *f;
158
     char c;
121
     char c;
159
     int i, j;
122
     int i, j;
160
 
123
 
161
-
162
     f = fopen(filename, "r");
124
     f = fopen(filename, "r");
163
 
125
 
164
-    if (!f)
165
-    {
126
+    if (!f) {
166
         perror(filename);
127
         perror(filename);
167
         return -1;
128
         return -1;
168
     }
129
     }
173
     buffer[0] = 0;
134
     buffer[0] = 0;
174
 
135
 
175
     // Strip out whitespace and comments
136
     // Strip out whitespace and comments
176
-    while (fscanf(f, "%c", &c) != EOF)
177
-    {
137
+    while (fscanf(f, "%c", &c) != EOF) {
178
         if (line_comment && c != '\n')
138
         if (line_comment && c != '\n')
179
             continue;
139
             continue;
180
 
140
 
181
-        if (i > 254)
182
-        {
141
+        if (i > 254) {
183
             printf("loadResourceFile> Overflow handled\n");
142
             printf("loadResourceFile> Overflow handled\n");
184
             i = 254;
143
             i = 254;
185
         }
144
         }
186
 
145
 
187
-        switch (c)
188
-        {
146
+        switch (c) {
189
             case '\v':
147
             case '\v':
190
             case '\t':
148
             case '\t':
191
                 break;
149
                 break;
195
                 break;
153
                 break;
196
             case '\n':
154
             case '\n':
197
                 if (line_comment)
155
                 if (line_comment)
198
-                {
199
                     line_comment = false;
156
                     line_comment = false;
200
-                }
201
 
157
 
202
-                if (buffer[0] == 0)
203
-                {
158
+                if (buffer[0] == 0) {
204
                     i = 0;
159
                     i = 0;
205
                     continue;
160
                     continue;
206
                 }
161
                 }
209
                 //printf("'%s'\n", buffer);
164
                 //printf("'%s'\n", buffer);
210
 
165
 
211
                 // 'Preprocessor' commands
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
                             buffer[j-9] = buffer[j];
170
                             buffer[j-9] = buffer[j];
219
                             buffer[j-8] = 0;
171
                             buffer[j-8] = 0;
220
                         }
172
                         }
223
 
175
 
224
                         loadResourceFile(fullPath(buffer, 0));
176
                         loadResourceFile(fullPath(buffer, 0));
225
                     }
177
                     }
226
-                }
227
-                else
228
-                {
178
+                } else {
229
                     command(buffer);
179
                     command(buffer);
230
                 }
180
                 }
231
 
181
 
242
     return 0;
192
     return 0;
243
 }
193
 }
244
 
194
 
245
-
246
-void System::setDriverGL(const char *driver)
247
-{
195
+void System::setDriverGL(const char *driver) {
248
     unsigned int len;
196
     unsigned int len;
249
 
197
 
250
-
251
     if (m_driver)
198
     if (m_driver)
252
-    {
253
         delete [] m_driver;
199
         delete [] m_driver;
254
-    }
255
 
200
 
256
-    if (driver && driver[0])
257
-    {
201
+    if (driver && driver[0]) {
258
         len = strlen(driver);
202
         len = strlen(driver);
259
         m_driver = new char[len+1];
203
         m_driver = new char[len+1];
260
         strncpy(m_driver, driver, len);
204
         strncpy(m_driver, driver, len);
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
         printf("resizeGL> ERROR assertions 'w > 0', 'h > 0' failed\n");
211
         printf("resizeGL> ERROR assertions 'w > 0', 'h > 0' failed\n");
277
         return;
212
         return;
278
     }
213
     }
290
     glFrustum(-fW, fW, -fH, fH, m_clipNear, m_clipFar);
225
     glFrustum(-fW, fW, -fH, fH, m_clipNear, m_clipFar);
291
 
226
 
292
     glMatrixMode(GL_MODELVIEW);
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 Wyświetl plik

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

+ 33
- 0
src/utils/time.cpp Wyświetl plik

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 Wyświetl plik

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

Ładowanie…
Anuluj
Zapisz