Browse Source

Fonts can be changed on-the-fly

Thomas Buck 9 years ago
parent
commit
874680e731
19 changed files with 320 additions and 436 deletions
  1. 3
    0
      ChangeLog.md
  2. 13
    22
      include/Font.h
  3. 0
    50
      include/FontManager.h
  4. 10
    20
      include/FontSDL.h
  5. 14
    130
      include/FontTRLE.h
  6. 6
    0
      include/RunTime.h
  7. 0
    6
      include/global.h
  8. 0
    1
      src/CMakeLists.txt
  9. 72
    4
      src/Font.cpp
  10. 0
    86
      src/FontManager.cpp
  11. 34
    27
      src/FontSDL.cpp
  12. 129
    17
      src/FontTRLE.cpp
  13. 12
    12
      src/Menu.cpp
  14. 3
    3
      src/MenuFolder.cpp
  15. 3
    1
      src/commands/CommandSet.cpp
  16. 18
    17
      src/main.cpp
  17. 0
    11
      test/CMakeLists.txt
  18. 0
    27
      test/Folder.cpp
  19. 3
    2
      test/Script.cpp

+ 3
- 0
ChangeLog.md View File

@@ -8,6 +8,9 @@
8 8
     * Fixed Bug in new GLUT implementation: Console now working properly
9 9
     * Fixed Bug where the debug overlay was flashing for a frame if it’s key is used in
10 10
       combination with a modifier (in this case CMD + Q to quit)
11
+    * All Font interfaces are now static-methods only
12
+    * The used Font can now be changed on the fly (even between different Font types)
13
+    * Removed FontManager, moved functionality into Font
11 14
 
12 15
     [ 20141007 ]
13 16
     * Set all RunTime vars to sensible defaults, so OpenRaider can try to start

+ 13
- 22
include/Font.h View File

@@ -8,43 +8,34 @@
8 8
 #ifndef _FONT_H_
9 9
 #define _FONT_H_
10 10
 
11
-#include  <string>
11
+#include <string>
12 12
 
13 13
 /*!
14 14
  * \brief Font interface
15 15
  */
16 16
 class Font {
17 17
 public:
18
+    static void shutdown();
18 19
 
19
-    /*!
20
-     * \brief Deconstructs an object of Font
21
-     */
22
-    virtual ~Font();
20
+    static int initialize(std::string font);
23 21
 
24
-    virtual void setFont(std::string font);
22
+    static unsigned int widthText(float scale, std::string s);
25 23
 
26
-    virtual int initialize() = 0;
24
+    static unsigned int heightText(float scale, unsigned int maxWidth, std::string s);
27 25
 
28
-    virtual unsigned int widthText(float scale, std::string s) = 0;
26
+    static void drawText(unsigned int x, unsigned int y, float scale,
27
+            const unsigned char color[4], std::string s);
29 28
 
30
-    virtual void drawText(unsigned int x, unsigned int y, float scale,
31
-            const unsigned char color[4], std::string s) = 0;
29
+    static void drawTextWrapped(unsigned int x, unsigned int y, float scale,
30
+            const unsigned char color[4], unsigned int maxWidth, std::string s);
32 31
 
33
-    virtual unsigned int heightText(float scale, unsigned int maxWidth, std::string s) = 0;
34
-
35
-    virtual void drawTextWrapped(unsigned int x, unsigned int y, float scale,
36
-            const unsigned char color[4], unsigned int maxWidth, std::string s) = 0;
37
-
38
-    // Implemented in Font.cpp using widthText & drawText
39
-    virtual void drawTextCentered(unsigned int x, unsigned int y, float scale,
32
+    static void drawTextCentered(unsigned int x, unsigned int y, float scale,
40 33
             const unsigned char color[4], unsigned int width, std::string s);
41 34
 
42
-protected:
43
-    bool mFontInit;
44
-    std::string mFontName;
35
+private:
36
+    static bool isInit;
37
+    static std::string fontName;
45 38
 };
46 39
 
47
-Font &getFont();
48
-
49 40
 #endif
50 41
 

+ 0
- 50
include/FontManager.h View File

@@ -1,50 +0,0 @@
1
-/*!
2
- * \file include/FontManager.h
3
- * \brief Font manager
4
- *
5
- * \author xythobuz
6
- */
7
-
8
-#ifndef _FONT_MANAGER_H_
9
-#define _FONT_MANAGER_H_
10
-
11
-#include <vector>
12
-
13
-#include "Font.h"
14
-
15
-class FontManager : public Font {
16
-public:
17
-
18
-    /*!
19
-     * \brief Constructs an object of FontManager
20
-     */
21
-    FontManager();
22
-
23
-    /*!
24
-     * \brief Deconstructs an object of FontManager
25
-     */
26
-    virtual ~FontManager();
27
-
28
-    virtual int initialize();
29
-
30
-    virtual unsigned int widthText(float scale, std::string s);
31
-
32
-    virtual void drawText(unsigned int x, unsigned int y, float scale,
33
-            const unsigned char color[4], std::string s);
34
-
35
-    virtual unsigned int heightText(float scale, unsigned int maxWidth, std::string s);
36
-
37
-    virtual void drawTextWrapped(unsigned int x, unsigned int y, float scale,
38
-            const unsigned char color[4], unsigned int maxWidth, std::string s);
39
-
40
-private:
41
-
42
-    void add(Font *f, std::string e);
43
-
44
-    int font;
45
-    std::vector<Font *> fonts;
46
-    std::vector<std::string> extensions;
47
-};
48
-
49
-#endif
50
-

+ 10
- 20
include/FontSDL.h View File

@@ -10,39 +10,29 @@
10 10
 
11 11
 #include "SDL_ttf.h"
12 12
 
13
-#include "Font.h"
14
-
15 13
 /*!
16 14
  * \brief SDL Font implementation
17 15
  */
18
-class FontSDL : public Font {
16
+class FontSDL {
19 17
 public:
18
+    static void shutdown();
20 19
 
21
-    /*!
22
-     * \brief Constructs an object of FontSDL
23
-     */
24
-    FontSDL();
25
-
26
-    /*!
27
-     * \brief Deconstructs an object of FontSDL
28
-     */
29
-    virtual ~FontSDL();
20
+    static int initialize(std::string font);
30 21
 
31
-    virtual int initialize();
22
+    static unsigned int widthText(float scale, std::string s);
32 23
 
33
-    virtual unsigned int widthText(float scale, std::string s);
24
+    static unsigned int heightText(float scale, unsigned int maxWidth, std::string s);
34 25
 
35
-    virtual void drawText(unsigned int x, unsigned int y, float scale,
26
+    static void drawText(unsigned int x, unsigned int y, float scale,
36 27
             const unsigned char color[4], std::string s);
37 28
 
38
-    virtual unsigned int heightText(float scale, unsigned int maxWidth, std::string s);
39
-
40
-    virtual void drawTextWrapped(unsigned int x, unsigned int y, float scale,
29
+    static void drawTextWrapped(unsigned int x, unsigned int y, float scale,
41 30
             const unsigned char color[4], unsigned int maxWidth, std::string s);
42 31
 
43 32
 private:
44
-    TTF_Font *mFont;
45
-    unsigned int mFontTexture;
33
+    static bool mFontInit;
34
+    static TTF_Font *mFont;
35
+    static unsigned int mFontTexture;
46 36
 };
47 37
 
48 38
 #endif

+ 14
- 130
include/FontTRLE.h View File

@@ -8,153 +8,37 @@
8 8
 #ifndef _FONT_TRLE_H_
9 9
 #define _FONT_TRLE_H_
10 10
 
11
-#include "Font.h"
12
-
13 11
 /*!
14 12
  * \brief Tomb Raider Level Editor Font loader
15 13
  */
16
-class FontTRLE : public Font {
14
+class FontTRLE {
17 15
 public:
16
+    static void shutdown();
18 17
 
19
-    /*!
20
-     * \brief Constructs an object of FontTRLE
21
-     */
22
-    FontTRLE();
23
-
24
-    /*!
25
-     * \brief Deconstructs an object of FontTRLE
26
-     */
27
-    virtual ~FontTRLE();
18
+    static int initialize(std::string font);
28 19
 
29
-    virtual int initialize();
20
+    static unsigned int widthText(float scale, std::string s);
30 21
 
31
-    virtual unsigned int widthText(float scale, std::string s);
22
+    static unsigned int heightText(float scale, unsigned int maxWidth, std::string s);
32 23
 
33
-    virtual void drawText(unsigned int x, unsigned int y, float scale,
24
+    static void drawText(unsigned int x, unsigned int y, float scale,
34 25
             const unsigned char color[4], std::string s);
35 26
 
36
-    virtual unsigned int heightText(float scale, unsigned int maxWidth, std::string s);
37
-
38
-    virtual void drawTextWrapped(unsigned int x, unsigned int y, float scale,
27
+    static void drawTextWrapped(unsigned int x, unsigned int y, float scale,
39 28
             const unsigned char color[4], unsigned int maxWidth, std::string s);
40 29
 
41 30
 private:
42
-
43
-    void loadLPS(std::string f);
44
-    void writeChar(unsigned int index, unsigned int xDraw, unsigned int yDraw,
31
+    static void setDefaultOffsets();
32
+    static void loadLPS(std::string f);
33
+    static void writeChar(unsigned int index, unsigned int xDraw, unsigned int yDraw,
45 34
             float scale, const unsigned char color[4]);
46 35
 
47
-    unsigned int mFontTexture;
36
+    static bool mFontInit;
37
+    static unsigned int mFontTexture;
48 38
 
49 39
     // 106 entries: (x, y, w, h, offset)
50
-    int offsets[106][5] = {
51
-        { 174,  52,   3,  12, -11 },
52
-        {  98,  58,   6,   4, -10 },
53
-        {  82,  26,  13,  11, -10 },
54
-        {  78,  38,   9,  13, -10 },
55
-        { 214,  13,  14,  11, -9  },
56
-        {  40,  26,  13,  11, -10 },
57
-        { 157,  57,   5,   6, -11 },
58
-        { 204,  39,   5,  15, -12 },
59
-        {  34,  40,   5,  15, -12 },
60
-        { 184,  59,   4,   4, -11 },
61
-        {  22,  40,  10,  10, -9  },
62
-        { 178,  59,   4,   4, -2  },
63
-        { 106,  60,   7,   2, -4  },
64
-        { 114,  60,   4,   3, -2  },
65
-        { 212,  38,   8,  14, -12 },
66
-        {  88,  49,   9,   9, -8  },
67
-        { 200,  55,   5,   9, -8  },
68
-        {  46,  52,   8,   9, -8  },
69
-        {  88,  38,   7,  10, -8  },
70
-        {  62,  40,  10,  10, -8  },
71
-        { 142,  48,   8,  11, -9  },
72
-        { 232,  50,   8,  10, -9  },
73
-        { 120,  47,   8,  11, -9  },
74
-        {  22,  51,   8,  10, -9  },
75
-        { 110,  49,   8,  10, -8  },
76
-        { 152,  57,   4,   7, -7  },
77
-        { 136,  57,   4,   9, -7  },
78
-        { 178,  40,  11,   9, -8  },
79
-        { 210,  53,  10,   6, -7  },
80
-        { 240,  40,  11,   9, -7  },
81
-        {  12,  39,   9,  12, -11 },
82
-        {  66,  13,  15,  13, -10 },
83
-        { 130,  13,  13,  12, -11 },
84
-        { 214,  25,  12,  12, -11 },
85
-        { 132,  35,  10,  12, -11 },
86
-        {   0,  26,  12,  12, -11 },
87
-        {  14,  26,  12,  12, -11 },
88
-        {  66,  27,  11,  12, -11 },
89
-        { 182,  27,  11,  12, -11 },
90
-        { 200,  13,  13,  12, -11 },
91
-        { 222,  54,   4,  12, -11 },
92
-        {  56,  52,   4,  15, -11 },
93
-        { 230,  15,  12,  12, -11 },
94
-        { 144,  35,  10,  12, -11 },
95
-        {  48,  13,  17,  12, -11 },
96
-        { 144,  13,  13,  12, -11 },
97
-        {  54,  26,  11,  12, -11 },
98
-        { 200,  26,  11,  12, -11 },
99
-        { 240,   0,  13,  14, -11 },
100
-        { 158,  13,  13,  12, -11 },
101
-        { 156,  35,  10,  12, -11 },
102
-        { 172,  13,  13,  12, -11 },
103
-        {  98,  13,  14,  12, -11 },
104
-        {  82,  13,  14,  12, -11 },
105
-        {  24,  13,  22,  12, -11 },
106
-        { 186,  13,  12,  13, -11 },
107
-        { 114,  13,  14,  12, -11 },
108
-        { 228,  28,  11,  12, -11 },
109
-        {  62,  60,   5,   3, -4  },
110
-        { 248,  59,   5,   3, -4  },
111
-        {  88,  59,   7,   3, -4  },
112
-        { 142,  60,   6,   2, -3  },
113
-        { 120,  59,   7,   3, -4  },
114
-        { 242,  59,   4,   4, -11 },
115
-        {  98,  49,  10,   8, -7  },
116
-        {  96,  35,  10,  13, -12 },
117
-        {  72,  52,   8,   8, -7  },
118
-        {   0,  39,  10,  11, -10 },
119
-        { 164,  52,   8,   8, -7  },
120
-        { 168,  38,   9,  13, -12 },
121
-        { 120,  35,  11,  11, -7  },
122
-        { 108,  35,  10,  13, -12 },
123
-        { 194,  27,   5,  11, -10 },
124
-        {  40,  51,   5,  15, -10 },
125
-        {  28,  26,  11,  13, -12 },
126
-        {  82,  52,   5,  12, -11 },
127
-        {  96,  26,  17,   8, -7  },
128
-        { 152,  48,  11,   8, -7  },
129
-        {  62,  51,   9,   8, -7  },
130
-        { 244,  15,  10,  12, -7  },
131
-        {  52,  39,   9,  12, -7  },
132
-        {  10,  52,   9,   8, -7  },
133
-        { 190,  52,   8,   8, -7  },
134
-        {   0,  51,   8,  10, -9  },
135
-        { 178,  50,  10,   8, -7  },
136
-        { 130,  48,  11,   8, -7  },
137
-        { 132,  26,  17,   8, -7  },
138
-        { 242,  50,  10,   8, -7  },
139
-        {  40,  38,  10,  12, -7  },
140
-        { 232,  41,   7,   8, -7  },
141
-        { 222,  41,   8,  12, -7  },
142
-        { 130,  57,   5,   8, -7  },
143
-        { 194,  39,   9,  12, -10 },
144
-        {  32,  56,   4,  11, -10 },
145
-        {   1,  14,  22,  11, -10 },
146
-        { 192,   0,  23,  13, -10 },
147
-        { 168,   0,  23,  12, -10 },
148
-        { 216,   0,  23,  12, -10 },
149
-        { 150,  26,  17,   8, -8  },
150
-        { 168,  26,  11,  11, -9  },
151
-        { 114,  26,  17,   8, -8  },
152
-        { 240,  28,  12,  11, -9  },
153
-        {   0,   0,  40,  12, -10 },
154
-        {  84,   0,  39,  11, -10 },
155
-        {  42,   0,  39,  11, -10 },
156
-        { 126,   0,  39,  11, -10 },
157
-    };
40
+    static int offsets[106][5];
41
+    static int defaultOffsets[106][5];
158 42
 };
159 43
 
160 44
 #endif

+ 6
- 0
include/RunTime.h View File

@@ -10,6 +10,12 @@
10 10
 
11 11
 #include <string>
12 12
 
13
+// Defaults
14
+#define DEFAULT_CONFIG_PATH "~/.OpenRaider"
15
+#define DEFAULT_CONFIG_FILE "OpenRaider.ini"
16
+#define DEFAULT_WIDTH 1280
17
+#define DEFAULT_HEIGHT 720
18
+
13 19
 /*!
14 20
  * \brief Main Game Singleton
15 21
  */

+ 0
- 6
include/global.h View File

@@ -9,12 +9,6 @@
9 9
 
10 10
 #include "config.h"
11 11
 
12
-// Defaults
13
-#define DEFAULT_CONFIG_PATH "~/.OpenRaider"
14
-#define DEFAULT_CONFIG_FILE "OpenRaider.ini"
15
-#define DEFAULT_WIDTH 640
16
-#define DEFAULT_HEIGHT 480
17
-
18 12
 void renderFrame();
19 13
 
20 14
 // Supported pixelmap color formats

+ 0
- 1
src/CMakeLists.txt View File

@@ -63,7 +63,6 @@ set (SRCS ${SRCS} "Console.cpp")
63 63
 set (SRCS ${SRCS} "Entity.cpp")
64 64
 set (SRCS ${SRCS} "Exception.cpp")
65 65
 set (SRCS ${SRCS} "Font.cpp")
66
-set (SRCS ${SRCS} "FontManager.cpp")
67 66
 set (SRCS ${SRCS} "FontTRLE.cpp")
68 67
 set (SRCS ${SRCS} "Game.cpp")
69 68
 set (SRCS ${SRCS} "Log.cpp")

+ 72
- 4
src/Font.cpp View File

@@ -6,16 +6,84 @@
6 6
  */
7 7
 
8 8
 #include "global.h"
9
+#include "Log.h"
9 10
 #include "utils/strings.h"
10 11
 #include "Window.h"
11 12
 #include "Font.h"
13
+#include "FontTRLE.h"
12 14
 
13
-Font::~Font() {
15
+#ifdef USING_SDL_FONT
16
+#include "FontSDL.h"
17
+#endif
18
+
19
+bool Font::isInit = false;
20
+std::string Font::fontName;
21
+
22
+void Font::shutdown() {
23
+    FontTRLE::shutdown();
24
+#ifdef USING_SDL_FONT
25
+    FontSDL::shutdown();
26
+#endif
27
+}
28
+
29
+int Font::initialize(std::string font) {
30
+    fontName = font;
31
+    if (stringEndsWith(fontName, ".pc")) {
32
+        return FontTRLE::initialize(fontName);
33
+#ifdef USING_SDL_FONT
34
+    } else if (stringEndsWith(fontName, ".ttf")) {
35
+        return FontSDL::initialize(fontName);
36
+#endif
37
+    }
38
+
39
+    getLog() << "Unknown font file format: " << font << Log::endl;
40
+    return -1;
41
+}
42
+
43
+unsigned int Font::widthText(float scale, std::string s) {
44
+    if (stringEndsWith(fontName, ".pc")) {
45
+        return FontTRLE::widthText(scale, s);
46
+#ifdef USING_SDL_FONT
47
+    } else if (stringEndsWith(fontName, ".ttf")) {
48
+        return FontSDL::widthText(scale, s);
49
+#endif
50
+    }
51
+
52
+    return 0;
53
+}
54
+
55
+unsigned int Font::heightText(float scale, unsigned int maxWidth, std::string s) {
56
+    if (stringEndsWith(fontName, ".pc")) {
57
+        return FontTRLE::heightText(scale, maxWidth, s);
58
+#ifdef USING_SDL_FONT
59
+    } else if (stringEndsWith(fontName, ".ttf")) {
60
+        return FontSDL::heightText(scale, maxWidth, s);
61
+#endif
62
+    }
63
+
64
+    return 0;
65
+}
66
+
67
+void Font::drawText(unsigned int x, unsigned int y, float scale,
68
+        const unsigned char color[4], std::string s) {
69
+    if (stringEndsWith(fontName, ".pc")) {
70
+        FontTRLE::drawText(x, y, scale, color, s);
71
+#ifdef USING_SDL_FONT
72
+    } else if (stringEndsWith(fontName, ".ttf")) {
73
+        FontSDL::drawText(x, y, scale, color, s);
74
+#endif
75
+    }
14 76
 }
15 77
 
16
-void Font::setFont(std::string font) {
17
-    assert(mFontInit == false);
18
-    mFontName = font;
78
+void Font::drawTextWrapped(unsigned int x, unsigned int y, float scale,
79
+        const unsigned char color[4], unsigned int maxWidth, std::string s) {
80
+    if (stringEndsWith(fontName, ".pc")) {
81
+        FontTRLE::drawTextWrapped(x, y, scale, color, maxWidth, s);
82
+#ifdef USING_SDL_FONT
83
+    } else if (stringEndsWith(fontName, ".ttf")) {
84
+        FontSDL::drawTextWrapped(x, y, scale, color, maxWidth, s);
85
+#endif
86
+    }
19 87
 }
20 88
 
21 89
 void Font::drawTextCentered(unsigned int x, unsigned int y, float scale,

+ 0
- 86
src/FontManager.cpp View File

@@ -1,86 +0,0 @@
1
-/*!
2
- * \file src/FontManager.cpp
3
- * \brief Font Manager
4
- *
5
- * \author xythobuz
6
- */
7
-
8
-#include "global.h"
9
-#include "utils/strings.h"
10
-#include "RunTime.h"
11
-#include "FontManager.h"
12
-#include "Font.h"
13
-#include "FontTRLE.h"
14
-
15
-#ifdef USING_SDL_FONT
16
-#include "FontSDL.h"
17
-#endif
18
-
19
-FontManager::FontManager() {
20
-    add(new FontTRLE(), ".pc");
21
-
22
-#ifdef USING_SDL_FONT
23
-    add(new FontSDL(), ".ttf");
24
-#endif
25
-
26
-    mFontInit = false;
27
-    font = -1;
28
-
29
-    // Default font path
30
-#ifdef USING_SDL_FONT
31
-    setFont(getRunTime().getDataDir() + "/test.ttf");
32
-#else
33
-    setFont(getRunTime().getDataDir() + "/font.pc");
34
-#endif
35
-}
36
-
37
-FontManager::~FontManager() {
38
-    while (!fonts.empty()) {
39
-        delete fonts.back();
40
-        fonts.pop_back();
41
-    }
42
-}
43
-
44
-void FontManager::add(Font *f, std::string e) {
45
-    fonts.push_back(f);
46
-    extensions.push_back(e);
47
-}
48
-
49
-int FontManager::initialize() {
50
-    for (unsigned int i = 0; i < fonts.size(); i++) {
51
-        if (stringEndsWith(mFontName, extensions.at(i))) {
52
-            font = i;
53
-            break;
54
-        }
55
-    }
56
-
57
-    if (font == -1)
58
-        return -1;
59
-
60
-    mFontInit = true;
61
-    fonts.at(font)->setFont(mFontName);
62
-    return fonts.at(font)->initialize();
63
-}
64
-
65
-unsigned int FontManager::widthText(float scale, std::string s) {
66
-    assert(font != -1);
67
-    return fonts.at(font)->widthText(scale, s);
68
-}
69
-
70
-void FontManager::drawText(unsigned int x, unsigned int y, float scale,
71
-        const unsigned char color[4], std::string s) {
72
-    assert(font != -1);
73
-    fonts.at(font)->drawText(x, y, scale, color, s);
74
-}
75
-
76
-unsigned int FontManager::heightText(float scale, unsigned int maxWidth, std::string s) {
77
-    assert(font != -1);
78
-    return fonts.at(font)->heightText(scale, maxWidth, s);
79
-}
80
-
81
-void FontManager::drawTextWrapped(unsigned int x, unsigned int y, float scale,
82
-        const unsigned char color[4], unsigned int maxWidth, std::string s) {
83
-    assert(font != -1);
84
-    fonts.at(font)->drawTextWrapped(x, y, scale, color, maxWidth, s);
85
-}
86
-

+ 34
- 27
src/FontSDL.cpp View File

@@ -5,53 +5,57 @@
5 5
  * \author xythobuz
6 6
  */
7 7
 
8
-#include <stdio.h>
8
+#include <iostream>
9 9
 
10 10
 #include "global.h"
11 11
 #include "FontSDL.h"
12 12
 
13
-FontSDL::FontSDL() {
14
-    mFont = NULL;
15
-    mFontInit = false;
16
-    mFontTexture = 0;
17
-}
13
+bool FontSDL::mFontInit = false;
14
+TTF_Font* FontSDL::mFont = nullptr;
15
+unsigned int FontSDL::mFontTexture = 0;
18 16
 
19
-FontSDL::~FontSDL() {
20
-    if (mFont)
17
+void FontSDL::shutdown() {
18
+    if (mFont != nullptr)
21 19
         TTF_CloseFont(mFont);
20
+    mFont = nullptr;
22 21
 
23 22
     if (mFontInit) {
24 23
         TTF_Quit();
25 24
         glDeleteTextures(1, &mFontTexture);
25
+        mFontInit = false;
26 26
     }
27 27
 }
28 28
 
29
-int FontSDL::initialize() {
30
-    assert(mFontInit == false);
29
+int FontSDL::initialize(std::string font) {
30
+    if (!mFontInit) {
31
+        if (TTF_Init() != 0) {
32
+            std::cout << "Could not initialize SDL-TTF!" << std::endl;
33
+            return -1;
34
+        }
31 35
 
32
-    if (TTF_Init() != 0) {
33
-        printf("Could not initialize SDL-TTF!\n");
34
-        return -1;
36
+        glGenTextures(1, &mFontTexture);
37
+        mFontInit = true;
35 38
     }
36 39
 
37
-    mFont = TTF_OpenFont(mFontName.c_str(), 24);
38
-    if (mFont == NULL) {
39
-        printf("TTF_OpenFont Error: %s\n", TTF_GetError());
40
+    if (mFont != nullptr)
41
+        TTF_CloseFont(mFont);
42
+
43
+    mFont = TTF_OpenFont(font.c_str(), 24);
44
+    if (mFont == nullptr) {
45
+        std::cout << "TTF_OpenFont Error: " << TTF_GetError() << std::endl;
40 46
         return -2;
41 47
     }
42 48
 
43
-    glGenTextures(1, &mFontTexture);
44
-
45
-    mFontInit = true;
46 49
     return 0;
47 50
 }
48 51
 
49 52
 unsigned int FontSDL::widthText(float scale, std::string s) {
50 53
     assert(mFontInit == true);
54
+    assert(mFont != nullptr);
51 55
 
52 56
     int w;
53
-    if (TTF_SizeUTF8(mFont, s.c_str(), &w, NULL) != 0) {
54
-        printf("TTF_SizeUTF8 Error: %s\n", TTF_GetError());
57
+    if (TTF_SizeUTF8(mFont, s.c_str(), &w, nullptr) != 0) {
58
+        std::cout << "TTF_SizeUTF8 Error: " << TTF_GetError() << std::endl;
55 59
         return s.length() * 15 * scale;
56 60
     }
57 61
     return w * scale;
@@ -60,6 +64,7 @@ unsigned int FontSDL::widthText(float scale, std::string s) {
60 64
 void FontSDL::drawText(unsigned int x, unsigned int y, float scale,
61 65
         const unsigned char color[4], std::string s) {
62 66
     assert(mFontInit == true);
67
+    assert(mFont != nullptr);
63 68
     assert(s.length() > 0);
64 69
 
65 70
     SDL_Color col;
@@ -69,8 +74,8 @@ void FontSDL::drawText(unsigned int x, unsigned int y, float scale,
69 74
     col.a = color[3];
70 75
 
71 76
     SDL_Surface *surface = TTF_RenderUTF8_Blended(mFont, s.c_str(), col);
72
-    if (surface == NULL) {
73
-        printf("TTF_RenderUTF8_Blended Error: %s\n", TTF_GetError());
77
+    if (surface == nullptr) {
78
+        std::cout << "TTF_RenderUTF8_Blended Error: " << TTF_GetError() << std::endl;
74 79
         return;
75 80
     }
76 81
 
@@ -120,13 +125,14 @@ void FontSDL::drawText(unsigned int x, unsigned int y, float scale,
120 125
 
121 126
 unsigned int FontSDL::heightText(float scale, unsigned int maxWidth, std::string s) {
122 127
     assert(mFontInit == true);
128
+    assert(mFont != nullptr);
123 129
     assert(s.length() > 0);
124 130
     assert(maxWidth > 0);
125 131
 
126 132
     SDL_Color col;
127 133
     SDL_Surface *surface = TTF_RenderUTF8_Blended_Wrapped(mFont, s.c_str(), col, maxWidth);
128
-    if (surface == NULL) {
129
-        printf("TTF_RenderUTF8_Blended_Wrapped Error: %s\n", TTF_GetError());
134
+    if (surface == nullptr) {
135
+        std::cout << "TTF_RenderUTF8_Blended_Wrapped Error: " << TTF_GetError() << std::endl;
130 136
         return 0;
131 137
     }
132 138
     int h = surface->h * scale;
@@ -137,6 +143,7 @@ unsigned int FontSDL::heightText(float scale, unsigned int maxWidth, std::string
137 143
 void FontSDL::drawTextWrapped(unsigned int x, unsigned int y, float scale,
138 144
         const unsigned char color[4], unsigned int maxWidth, std::string s) {
139 145
     assert(mFontInit == true);
146
+    assert(mFont != nullptr);
140 147
     assert(s.length() > 0);
141 148
     assert(maxWidth > 0);
142 149
 
@@ -147,8 +154,8 @@ void FontSDL::drawTextWrapped(unsigned int x, unsigned int y, float scale,
147 154
     col.a = color[3];
148 155
 
149 156
     SDL_Surface *surface = TTF_RenderUTF8_Blended_Wrapped(mFont, s.c_str(), col, maxWidth);
150
-    if (surface == NULL) {
151
-        printf("TTF_RenderUTF8_Blended_Wrapped Error: %s\n", TTF_GetError());
157
+    if (surface == nullptr) {
158
+        std::cout << "TTF_RenderUTF8_Blended_Wrapped Error: " << TTF_GetError() << std::endl;
152 159
         return;
153 160
     }
154 161
 

+ 129
- 17
src/FontTRLE.cpp View File

@@ -5,6 +5,7 @@
5 5
  * \author xythobuz
6 6
  */
7 7
 
8
+#include <algorithm>
8 9
 #include <fstream>
9 10
 #include <sstream>
10 11
 #include <stdexcept>
@@ -13,20 +14,24 @@
13 14
 #include "utils/strings.h"
14 15
 #include "FontTRLE.h"
15 16
 
16
-FontTRLE::FontTRLE() {
17
-    mFontInit = false;
18
-    mFontTexture = 0;
19
-}
17
+#define SCALING 2.0f
20 18
 
21
-FontTRLE::~FontTRLE() {
19
+bool FontTRLE::mFontInit = false;
20
+unsigned int FontTRLE::mFontTexture = 0;
21
+int FontTRLE::offsets[106][5];
22
+
23
+void FontTRLE::shutdown() {
24
+    if (mFontInit)
25
+        glDeleteTextures(1, &mFontTexture);
22 26
 }
23 27
 
24
-int FontTRLE::initialize() {
25
-    assert(mFontInit == false);
26
-    assert(stringEndsWith(mFontName, ".pc") == true);
28
+int FontTRLE::initialize(std::string font) {
29
+    assert(stringEndsWith(font, ".pc") == true);
30
+
31
+    shutdown();
27 32
 
28 33
     // Load .pc file...
29
-    std::ifstream file(mFontName, std::ios::in | std::ios::binary);
34
+    std::ifstream file(font, std::ios::in | std::ios::binary);
30 35
     unsigned char *pixels = new unsigned char[256 * 256 * 4];
31 36
     if (!file.read((char *)pixels, 256 * 256 * 4)) {
32 37
         delete [] pixels;
@@ -49,8 +54,8 @@ int FontTRLE::initialize() {
49 54
     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 256, 256, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, pixels);
50 55
     delete [] pixels;
51 56
 
52
-    // Try to load .lps file, overwriting default glyph positions
53
-    std::string lpsFile = findAndReplace(mFontName, ".pc", ".lps");
57
+    // Try to load .lps file or use default glyph positions
58
+    std::string lpsFile = findAndReplace(font, ".pc", ".lps");
54 59
     loadLPS(lpsFile);
55 60
 
56 61
     mFontInit = true;
@@ -59,12 +64,12 @@ int FontTRLE::initialize() {
59 64
 
60 65
 void FontTRLE::loadLPS(std::string f) {
61 66
     std::ifstream file(f);
62
-    if (!file)
67
+    if (!file) {
68
+        std::copy(&defaultOffsets[0][0], &defaultOffsets[0][0] + (106 * 5), &offsets[0][0]);
63 69
         return;
70
+    }
64 71
 
65
-    /*!
66
-     * \todo This is probably the worlds most unreliable parser...
67
-     */
72
+    //! \todo This is probably the worlds most unreliable parser...
68 73
 
69 74
     for (std::string line; std::getline(file, line);) {
70 75
         std::istringstream stream(line);
@@ -88,8 +93,6 @@ void FontTRLE::loadLPS(std::string f) {
88 93
     }
89 94
 }
90 95
 
91
-#define SCALING 2.0f
92
-
93 96
 void FontTRLE::writeChar(unsigned int index, unsigned int xDraw, unsigned int yDraw,
94 97
         float scale, const unsigned char color[4]) {
95 98
     assert(mFontInit == true);
@@ -235,3 +238,112 @@ void FontTRLE::drawTextWrapped(unsigned int x, unsigned int y, float scale,
235 238
     }
236 239
 }
237 240
 
241
+int FontTRLE::defaultOffsets[106][5] = {
242
+    { 174,  52,   3,  12, -11 },
243
+    {  98,  58,   6,   4, -10 },
244
+    {  82,  26,  13,  11, -10 },
245
+    {  78,  38,   9,  13, -10 },
246
+    { 214,  13,  14,  11, -9  },
247
+    {  40,  26,  13,  11, -10 },
248
+    { 157,  57,   5,   6, -11 },
249
+    { 204,  39,   5,  15, -12 },
250
+    {  34,  40,   5,  15, -12 },
251
+    { 184,  59,   4,   4, -11 },
252
+    {  22,  40,  10,  10, -9  },
253
+    { 178,  59,   4,   4, -2  },
254
+    { 106,  60,   7,   2, -4  },
255
+    { 114,  60,   4,   3, -2  },
256
+    { 212,  38,   8,  14, -12 },
257
+    {  88,  49,   9,   9, -8  },
258
+    { 200,  55,   5,   9, -8  },
259
+    {  46,  52,   8,   9, -8  },
260
+    {  88,  38,   7,  10, -8  },
261
+    {  62,  40,  10,  10, -8  },
262
+    { 142,  48,   8,  11, -9  },
263
+    { 232,  50,   8,  10, -9  },
264
+    { 120,  47,   8,  11, -9  },
265
+    {  22,  51,   8,  10, -9  },
266
+    { 110,  49,   8,  10, -8  },
267
+    { 152,  57,   4,   7, -7  },
268
+    { 136,  57,   4,   9, -7  },
269
+    { 178,  40,  11,   9, -8  },
270
+    { 210,  53,  10,   6, -7  },
271
+    { 240,  40,  11,   9, -7  },
272
+    {  12,  39,   9,  12, -11 },
273
+    {  66,  13,  15,  13, -10 },
274
+    { 130,  13,  13,  12, -11 },
275
+    { 214,  25,  12,  12, -11 },
276
+    { 132,  35,  10,  12, -11 },
277
+    {   0,  26,  12,  12, -11 },
278
+    {  14,  26,  12,  12, -11 },
279
+    {  66,  27,  11,  12, -11 },
280
+    { 182,  27,  11,  12, -11 },
281
+    { 200,  13,  13,  12, -11 },
282
+    { 222,  54,   4,  12, -11 },
283
+    {  56,  52,   4,  15, -11 },
284
+    { 230,  15,  12,  12, -11 },
285
+    { 144,  35,  10,  12, -11 },
286
+    {  48,  13,  17,  12, -11 },
287
+    { 144,  13,  13,  12, -11 },
288
+    {  54,  26,  11,  12, -11 },
289
+    { 200,  26,  11,  12, -11 },
290
+    { 240,   0,  13,  14, -11 },
291
+    { 158,  13,  13,  12, -11 },
292
+    { 156,  35,  10,  12, -11 },
293
+    { 172,  13,  13,  12, -11 },
294
+    {  98,  13,  14,  12, -11 },
295
+    {  82,  13,  14,  12, -11 },
296
+    {  24,  13,  22,  12, -11 },
297
+    { 186,  13,  12,  13, -11 },
298
+    { 114,  13,  14,  12, -11 },
299
+    { 228,  28,  11,  12, -11 },
300
+    {  62,  60,   5,   3, -4  },
301
+    { 248,  59,   5,   3, -4  },
302
+    {  88,  59,   7,   3, -4  },
303
+    { 142,  60,   6,   2, -3  },
304
+    { 120,  59,   7,   3, -4  },
305
+    { 242,  59,   4,   4, -11 },
306
+    {  98,  49,  10,   8, -7  },
307
+    {  96,  35,  10,  13, -12 },
308
+    {  72,  52,   8,   8, -7  },
309
+    {   0,  39,  10,  11, -10 },
310
+    { 164,  52,   8,   8, -7  },
311
+    { 168,  38,   9,  13, -12 },
312
+    { 120,  35,  11,  11, -7  },
313
+    { 108,  35,  10,  13, -12 },
314
+    { 194,  27,   5,  11, -10 },
315
+    {  40,  51,   5,  15, -10 },
316
+    {  28,  26,  11,  13, -12 },
317
+    {  82,  52,   5,  12, -11 },
318
+    {  96,  26,  17,   8, -7  },
319
+    { 152,  48,  11,   8, -7  },
320
+    {  62,  51,   9,   8, -7  },
321
+    { 244,  15,  10,  12, -7  },
322
+    {  52,  39,   9,  12, -7  },
323
+    {  10,  52,   9,   8, -7  },
324
+    { 190,  52,   8,   8, -7  },
325
+    {   0,  51,   8,  10, -9  },
326
+    { 178,  50,  10,   8, -7  },
327
+    { 130,  48,  11,   8, -7  },
328
+    { 132,  26,  17,   8, -7  },
329
+    { 242,  50,  10,   8, -7  },
330
+    {  40,  38,  10,  12, -7  },
331
+    { 232,  41,   7,   8, -7  },
332
+    { 222,  41,   8,  12, -7  },
333
+    { 130,  57,   5,   8, -7  },
334
+    { 194,  39,   9,  12, -10 },
335
+    {  32,  56,   4,  11, -10 },
336
+    {   1,  14,  22,  11, -10 },
337
+    { 192,   0,  23,  13, -10 },
338
+    { 168,   0,  23,  12, -10 },
339
+    { 216,   0,  23,  12, -10 },
340
+    { 150,  26,  17,   8, -8  },
341
+    { 168,  26,  11,  11, -9  },
342
+    { 114,  26,  17,   8, -8  },
343
+    { 240,  28,  12,  11, -9  },
344
+    {   0,   0,  40,  12, -10 },
345
+    {  84,   0,  39,  11, -10 },
346
+    {  42,   0,  39,  11, -10 },
347
+    { 126,   0,  39,  11, -10 },
348
+};
349
+

+ 12
- 12
src/Menu.cpp View File

@@ -89,25 +89,25 @@ void Menu::displayDialog() {
89 89
     if (dialogText.length() > 0) {
90 90
         unsigned int wMax = ((unsigned int)(::getWindow().getWidth() * 0.66f));
91 91
 
92
-        unsigned int w0 = getFont().widthText(1.0f, dialogText) + 20;
92
+        unsigned int w0 = Font::widthText(1.0f, dialogText) + 20;
93 93
         if (w0 > wMax)
94 94
             w0 = wMax;
95
-        unsigned int h0 =  getFont().heightText(1.0f, w0, dialogText) + 10;
95
+        unsigned int h0 =  Font::heightText(1.0f, w0, dialogText) + 10;
96 96
 
97 97
         assert(dialogButton1.length() > 0);
98
-        unsigned int w1 = getFont().widthText(1.0f, dialogButton1) + 20;
98
+        unsigned int w1 = Font::widthText(1.0f, dialogButton1) + 20;
99 99
         if (w1 > wMax)
100 100
             w1 = wMax;
101
-        unsigned int h1 = getFont().heightText(1.0f, w1, dialogButton1) + 10;
101
+        unsigned int h1 = Font::heightText(1.0f, w1, dialogButton1) + 10;
102 102
 
103 103
         unsigned int wOverlay = wMax, hOverlay, w2 = 0, h2 = 0;
104 104
 
105 105
         if (dialogButton2.length() > 0) {
106 106
             // Show text and two buttons
107
-            w2 = getFont().widthText(1.0f, dialogButton2) + 20;
107
+            w2 = Font::widthText(1.0f, dialogButton2) + 20;
108 108
             if (w2 > wMax)
109 109
                 w2 = wMax;
110
-            h2 = getFont().heightText(1.0f, w2, dialogButton2) + 10;
110
+            h2 = Font::heightText(1.0f, w2, dialogButton2) + 10;
111 111
 
112 112
             if (w0 > (w1 + w2)) {
113 113
                 if (w0 < wMax) {
@@ -147,21 +147,21 @@ void Menu::displayDialog() {
147 147
         glRecti(xOverlay, yOverlay, xOverlay + wOverlay, yOverlay + hOverlay);
148 148
         glEnable(GL_TEXTURE_2D);
149 149
 
150
-        getFont().drawTextWrapped(xOverlay + 10, yOverlay + 5, 1.0f, BLUE, w0, dialogText);
150
+        Font::drawTextWrapped(xOverlay + 10, yOverlay + 5, 1.0f, BLUE, w0, dialogText);
151 151
         if (dialogButton2.length() > 0) {
152 152
             if ((w1 + w2) <= wMax) {
153
-                getFont().drawTextWrapped(xOverlay + 10, yOverlay + 10 + h0, 1.0f,
153
+                Font::drawTextWrapped(xOverlay + 10, yOverlay + 10 + h0, 1.0f,
154 154
                     dialogState ? BLUE : RED, w1, dialogButton1);
155
-                getFont().drawTextWrapped(xOverlay + 10 + w1, yOverlay + 10 + h0,
155
+                Font::drawTextWrapped(xOverlay + 10 + w1, yOverlay + 10 + h0,
156 156
                     1.0f, dialogState ? RED : BLUE, w2, dialogButton2);
157 157
             } else {
158
-                getFont().drawTextWrapped((::getWindow().getWidth() - w1) / 2,
158
+                Font::drawTextWrapped((::getWindow().getWidth() - w1) / 2,
159 159
                     yOverlay + 10 + h0, 1.0f, dialogState ? BLUE : RED, w1, dialogButton1);
160
-                getFont().drawTextWrapped((::getWindow().getWidth() - w2) / 2,
160
+                Font::drawTextWrapped((::getWindow().getWidth() - w2) / 2,
161 161
                     yOverlay + 10 + h0 + h1, 1.0f, dialogState ? RED : BLUE, w2, dialogButton2);
162 162
             }
163 163
         } else {
164
-            getFont().drawTextWrapped((::getWindow().getWidth() - w1) / 2,
164
+            Font::drawTextWrapped((::getWindow().getWidth() - w1) / 2,
165 165
                     yOverlay + 10 + h0, 1.0f, RED, w1, dialogButton1);
166 166
         }
167 167
     }

+ 3
- 3
src/MenuFolder.cpp View File

@@ -85,7 +85,7 @@ void MenuFolder::display() {
85 85
     glEnable(GL_TEXTURE_2D);
86 86
 
87 87
     // Draw heading
88
-    getFont().drawTextCentered(0, 10, 1.2f, BLUE, ::getWindow().getWidth(), VERSION);
88
+    Font::drawTextCentered(0, 10, 1.2f, BLUE, ::getWindow().getWidth(), VERSION);
89 89
 
90 90
     // Estimate displayable number of items
91 91
     int items = (::getWindow().getHeight() - 60) / 25;
@@ -94,9 +94,9 @@ void MenuFolder::display() {
94 94
     for (long i = mMin; (i < (mMin + items))
95 95
                 && (i < (mapFolder->folderCount() + mapFolder->fileCount() + 1)); i++) {
96 96
         if (i == 0) {
97
-            getFont().drawText(25, 50, 0.75f, (mCursor == i) ? RED : BLUE, "..");
97
+            Font::drawText(25, 50, 0.75f, (mCursor == i) ? RED : BLUE, "..");
98 98
         } else {
99
-            getFont().drawText(25, (unsigned int)(50 + (25 * (i - mMin))), 0.75f,
99
+            Font::drawText(25, (unsigned int)(50 + (25 * (i - mMin))), 0.75f,
100 100
                 (mCursor == i) ? RED : BLUE,
101 101
                 ((i - 1) < mapFolder->folderCount()) ?
102 102
                     (mapFolder->getFolder(i - 1).getName() + "/")

+ 3
- 1
src/commands/CommandSet.cpp View File

@@ -137,7 +137,9 @@ int CommandSet::execute(std::istream& args) {
137 137
     } else if (var.compare("font") == 0) {
138 138
         std::string temp;
139 139
         args >> temp;
140
-        getFont().setFont(expandNames(temp).c_str());
140
+        int error = Font::initialize(expandNames(temp));
141
+        if (error != 0)
142
+            getLog() << "Error initializing font: " << expandNames(temp) << "(" << error << ")" << Log::endl;
141 143
     } else {
142 144
         getLog() << "set-Error: Unknown variable (" << var.c_str() << ")" << Log::endl;
143 145
         return -1;

+ 18
- 17
src/main.cpp View File

@@ -18,7 +18,7 @@
18 18
 #ifndef UNIT_TEST
19 19
 
20 20
 #include "Camera.h"
21
-#include "FontManager.h"
21
+#include "Font.h"
22 22
 #include "Game.h"
23 23
 #include "Log.h"
24 24
 #include "MenuFolder.h"
@@ -46,7 +46,6 @@
46 46
 static std::string configFileToUse;
47 47
 
48 48
 static std::shared_ptr<Camera> gCamera;
49
-static std::shared_ptr<FontManager> gFont;
50 49
 static std::shared_ptr<Game> gGame;
51 50
 static std::shared_ptr<Log> gLog;
52 51
 static std::shared_ptr<MenuFolder> gMenu;
@@ -61,10 +60,6 @@ Camera &getCamera() {
61 60
     return *gCamera;
62 61
 }
63 62
 
64
-Font &getFont() {
65
-    return *gFont;
66
-}
67
-
68 63
 Game &getGame() {
69 64
     return *gGame;
70 65
 }
@@ -115,7 +110,6 @@ int main(int argc, char* argv[]) {
115 110
     gRunTime.reset(new RunTime());
116 111
 
117 112
     gCamera.reset(new Camera());
118
-    gFont.reset(new FontManager());
119 113
     gGame.reset(new Game());
120 114
     gLog.reset(new Log());
121 115
     gMenu.reset(new MenuFolder());
@@ -137,14 +131,6 @@ int main(int argc, char* argv[]) {
137 131
 
138 132
     Command::fillCommandList();
139 133
 
140
-    if (configFileToUse == "") {
141
-        if (Command::executeFile(DEFAULT_CONFIG_FILE) != 0) {
142
-            Command::executeFile(DEFAULT_CONFIG_PATH "/" DEFAULT_CONFIG_FILE);
143
-        }
144
-    } else {
145
-        Command::executeFile(configFileToUse);
146
-    }
147
-
148 134
     getLog() << "Initializing " << VERSION << Log::endl;
149 135
 
150 136
     // Initialize Windowing
@@ -161,8 +147,22 @@ int main(int argc, char* argv[]) {
161 147
         return -2;
162 148
     }
163 149
 
150
+    // Font initialization requires GL context, but is called from config file
151
+    // So we need to initialize some things before executing the config
152
+    if (configFileToUse == "") {
153
+        if (Command::executeFile(DEFAULT_CONFIG_FILE) != 0) {
154
+            Command::executeFile(DEFAULT_CONFIG_PATH "/" DEFAULT_CONFIG_FILE);
155
+        }
156
+    } else {
157
+        Command::executeFile(configFileToUse);
158
+    }
159
+
164 160
     // Initialize Font
165
-    error = getFont().initialize();
161
+#ifdef USING_SDL_FONT
162
+    error = Font::initialize(getRunTime().getDataDir() + "/test.ttf");
163
+#else
164
+    error = Font::initialize(getRunTime().getDataDir() + "/font.pc");
165
+#endif
166 166
     if (error != 0) {
167 167
         std::cout << "Could not initialize Font (" << error << ")!" << std::endl;
168 168
         return -3;
@@ -214,6 +214,7 @@ int main(int argc, char* argv[]) {
214 214
     }
215 215
 
216 216
     UI::shutdown();
217
+    Font::shutdown();
217 218
 
218 219
 #ifdef DEBUG
219 220
     std::cout << std::endl;
@@ -242,7 +243,7 @@ void renderFrame() {
242 243
         std::ostringstream s;
243 244
         s << fps << "FPS";
244 245
         getWindow().glEnter2D();
245
-        getFont().drawText(10, getWindow().getHeight() - 25, 0.6f, BLUE, s.str());
246
+        Font::drawText(10, getWindow().getHeight() - 25, 0.6f, BLUE, s.str());
246 247
         getWindow().glExit2D();
247 248
     }
248 249
 

+ 0
- 11
test/CMakeLists.txt View File

@@ -15,17 +15,6 @@ add_test (NAME test_binary COMMAND tester_binary)
15 15
 
16 16
 #################################################################
17 17
 
18
-add_executable (tester_folder EXCLUDE_FROM_ALL
19
-    "Folder.cpp" "../src/utils/filesystem.cpp"
20
-    "../src/utils/Folder.cpp" "../src/utils/File.cpp"
21
-    "../src/Exception.cpp" "../src/main.cpp"
22
-)
23
-
24
-add_dependencies (check tester_folder)
25
-#add_test (NAME test_folder COMMAND tester_folder)
26
-
27
-#################################################################
28
-
29 18
 add_executable (tester_script EXCLUDE_FROM_ALL
30 19
     "Script.cpp" "../src/Script.cpp" "../src/main.cpp"
31 20
     "../src/utils/binary.cpp" "../src/Exception.cpp"

+ 0
- 27
test/Folder.cpp View File

@@ -1,27 +0,0 @@
1
-/*!
2
- * \file test/Folder.cpp
3
- * \brief File system utils unit test
4
- *
5
- * \author xythobuz
6
- */
7
-
8
-#include <iostream>
9
-
10
-#include "global.h"
11
-#include "utils/File.h"
12
-#include "utils/Folder.h"
13
-
14
-int main() {
15
-    Folder f(".");
16
-
17
-    std::cout << f.folderCount() << " folders:" << std::endl;
18
-    for (unsigned long i = 0; i < f.folderCount(); i++)
19
-        std::cout << "\t" << f.getFolder(i).getName() << std::endl;
20
-
21
-    std::cout << f.fileCount() << " files:" << std::endl;
22
-    for (unsigned long i = 0; i < f.fileCount(); i++)
23
-        std::cout << "\t" << f.getFile(i).getName() << std::endl;
24
-
25
-    return 0;
26
-}
27
-

+ 3
- 2
test/Script.cpp View File

@@ -206,7 +206,8 @@ int main(int argc, char *argv[]) {
206 206
                 printData = false;
207 207
             }
208 208
             assert(testPayloadCount < 10);
209
-            if ((argv[2][0] >= '0') && ((unsigned int)argv[2][0] <= (testPayloadCount + '0'))) {
209
+            if ((argv[2][0] >= '0')
210
+                    && (static_cast<unsigned int>(argv[2][0]) <= (testPayloadCount + '0'))) {
210 211
                 whichFile = argv[2][0] - '0';
211 212
             }
212 213
         } else {
@@ -231,7 +232,7 @@ int main(int argc, char *argv[]) {
231 232
             return printDataScript(s, printData);
232 233
         } else {
233 234
             // From payload
234
-            return runForPayload((unsigned int)whichFile, true, printData);
235
+            return runForPayload(static_cast<unsigned int>(whichFile), true, printData);
235 236
         }
236 237
     } else {
237 238
         // Run test on all scripts in payload

Loading…
Cancel
Save