Thomas Buck 10 anni fa
parent
commit
48b2985506
13 ha cambiato i file con 155 aggiunte e 77 eliminazioni
  1. 4
    0
      ChangeLog.md
  2. 4
    2
      README.md
  3. 4
    0
      TODO.md
  4. 2
    1
      include/Font.h
  5. 42
    0
      include/FontManager.h
  6. 0
    5
      include/FontSDL.h
  7. 0
    4
      include/FontTRLE.h
  8. 10
    12
      src/CMakeLists.txt
  9. 22
    0
      src/Font.cpp
  10. 65
    0
      src/FontManager.cpp
  11. 0
    22
      src/FontSDL.cpp
  12. 0
    21
      src/FontTRLE.cpp
  13. 2
    10
      src/main.cpp

+ 4
- 0
ChangeLog.md Vedi File

@@ -2,6 +2,10 @@
2 2
 
3 3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
4 4
 
5
+    [ 20140615 ]
6
+    * Added FontManager, selecting Font library to use depending on
7
+      the file extension of the font file specified in the config.
8
+
5 9
     [ 20140614 ]
6 10
     * Implemented TRLE Font loader
7 11
 

+ 4
- 2
README.md Vedi File

@@ -117,9 +117,11 @@ Every available command should be listed in the in-game help. Just type `help` i
117 117
 
118 118
 ### Tomb Raider Level Editor Font support
119 119
 
120
-OpenRaider can read Font.pc files used by the TRLE. If the fonts glyph positions match the TR4 defaults, only a Font.pc file is required. If the positions differ, you also need a [Leikkuri/Cutter](http://trep.trlevel.de/en/downloads.html) preset file (.lps).
120
+OpenRaider can read Font.pc files used by the TRLE. If the fonts glyph positions match the TR4 defaults, only a Font.pc file is required. If the positions differ, you also need a [Leikkuri/Cutter](http://trep.trlevel.de/en/downloads.html) preset file (`.lps`).
121 121
 
122
-TRLE Font support will automatically be built if SDL2-TTF is not available. Just change the font file path in your config file.
122
+TRLE Font support will automatically be built and used when selecting a font in your config file ending with `.pc`.
123
+
124
+If a `.lps` is required, give it the same name as your font file.
123 125
 
124 126
 I’ve made [a small writeup on my website](http://xythobuz.de/2014_06_14_trle_font.html) about this.
125 127
 

+ 4
- 0
TODO.md Vedi File

@@ -26,6 +26,10 @@ There are these DebugModel, DebugMap flags...?
26 26
 * Support SSE with other compilers than Clang (src/CMakeLists.txt)
27 27
 * Visual C++ compiler flags? (CMakeLists.txt)
28 28
 
29
+## Bugs
30
+
31
+* Menu Header “OpenRaider” not visible when using FontSDL?
32
+
29 33
 ## Future Features
30 34
 
31 35
 * Use only assets from old TR games, not even depending on a font file?

+ 2
- 1
include/Font.h Vedi File

@@ -36,11 +36,12 @@ public:
36 36
     virtual void writeString(FontString &s) = 0;
37 37
 
38 38
     virtual void drawText(unsigned int x, unsigned int y, float scale, const float color[4], const char *s, ...)
39
-        __attribute__((format(printf, 6, 0))) = 0;
39
+        __attribute__((format(printf, 6, 0)));
40 40
 
41 41
 protected:
42 42
     bool mFontInit;
43 43
     char *mFontName;
44
+    FontString tempText;
44 45
 };
45 46
 
46 47
 Font &getFont();

+ 42
- 0
include/FontManager.h Vedi File

@@ -0,0 +1,42 @@
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 void writeString(FontString &s);
31
+
32
+private:
33
+
34
+    void add(Font *f, const char *e);
35
+
36
+    int font;
37
+    std::vector<Font *> fonts;
38
+    std::vector<const char *> extensions;
39
+};
40
+
41
+#endif
42
+

+ 0
- 5
include/FontSDL.h Vedi File

@@ -32,14 +32,9 @@ public:
32 32
 
33 33
     virtual void writeString(FontString &s);
34 34
 
35
-    virtual void drawText(unsigned int x, unsigned int y, float scale, const float color[4], const char *s, ...)
36
-        __attribute__((format(printf, 6, 0)));
37
-
38 35
 private:
39 36
     TTF_Font *mFont;
40 37
     unsigned int mFontTexture;
41
-
42
-    FontString tempText;
43 38
 };
44 39
 
45 40
 #endif

+ 0
- 4
include/FontTRLE.h Vedi File

@@ -31,16 +31,12 @@ public:
31 31
 
32 32
     virtual void writeString(FontString &s);
33 33
 
34
-    virtual void drawText(unsigned int x, unsigned int y, float scale, const float color[4], const char *s, ...)
35
-        __attribute__((format(printf, 6, 0)));
36
-
37 34
 private:
38 35
 
39 36
     void loadLPS(const char *f);
40 37
     void writeChar(unsigned int index, unsigned int xDraw, FontString &s);
41 38
 
42 39
     unsigned int mFontTexture;
43
-    FontString tempText;
44 40
 
45 41
     // 106 entries: (x, y, w, h, offset)
46 42
     int offsets[106][5] = {

+ 10
- 12
src/CMakeLists.txt Vedi File

@@ -44,6 +44,8 @@ set (SRCS ${SRCS} "Command.cpp")
44 44
 set (SRCS ${SRCS} "Console.cpp")
45 45
 set (SRCS ${SRCS} "Entity.cpp")
46 46
 set (SRCS ${SRCS} "Font.cpp")
47
+set (SRCS ${SRCS} "FontManager.cpp")
48
+set (SRCS ${SRCS} "FontTRLE.cpp")
47 49
 set (SRCS ${SRCS} "Game.cpp")
48 50
 set (SRCS ${SRCS} "main.cpp")
49 51
 set (SRCS ${SRCS} "Menu.cpp")
@@ -73,20 +75,16 @@ else (OPENAL_FOUND AND ALUT_FOUND AND ENABLE_AUDIO)
73 75
 endif (OPENAL_FOUND AND ALUT_FOUND AND ENABLE_AUDIO)
74 76
 
75 77
 # Select available Windowing library
76
-if (SDL2_FOUND AND SDL2TTF_FOUND)
78
+if (SDL2_FOUND)
77 79
     set (SRCS ${SRCS} "WindowSDL.cpp")
78
-    set (SRCS ${SRCS} "FontSDL.cpp")
79 80
     set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} -DUSING_SDL")
80
-else (SDL2_FOUND AND SDL2TTF_FOUND)
81
-    if (SDL2_FOUND)
82
-        set (SRCS ${SRCS} "WindowSDL.cpp")
83
-        set (SRCS ${SRCS} "FontTRLE.cpp")
84
-        set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} -DUSING_SDL")
85
-        set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} -DUSING_TRLE")
86
-    else (SDL2_FOUND)
87
-        message (FATAL_ERROR "SDL2 is required at the moment!")
88
-    endif (SDL2_FOUND)
89
-endif (SDL2_FOUND AND SDL2TTF_FOUND)
81
+    if (SDL2TTF_FOUND)
82
+        set (SRCS ${SRCS} "FontSDL.cpp")
83
+        set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} -DUSING_SDL_FONT")
84
+    endif (SDL2TTF_FOUND)
85
+else (SDL2_FOUND)
86
+    message (FATAL_ERROR "SDL2 is required at the moment!")
87
+endif (SDL2_FOUND)
90 88
 
91 89
 #################################################################
92 90
 

+ 22
- 0
src/Font.cpp Vedi File

@@ -12,6 +12,9 @@
12 12
 Font::~Font() {
13 13
     delete [] mFontName;
14 14
     mFontName = NULL;
15
+
16
+    delete [] tempText.text;
17
+    tempText.text = NULL;
15 18
 }
16 19
 
17 20
 void Font::setFont(const char *font) {
@@ -22,3 +25,22 @@ void Font::setFont(const char *font) {
22 25
     mFontName = fullPath(font, 0);
23 26
 }
24 27
 
28
+void Font::drawText(unsigned int x, unsigned int y, float scale, const float color[4], const char *s, ...) {
29
+    va_list args;
30
+    va_start(args, s);
31
+    vsnprintf(tempText.text, 256, s, args);
32
+    tempText.text[255] = '\0';
33
+    va_end(args);
34
+
35
+    tempText.scale = scale;
36
+    tempText.x = x;
37
+    tempText.y = y;
38
+    if (color) {
39
+        tempText.color[0] = color[0];
40
+        tempText.color[1] = color[1];
41
+        tempText.color[2] = color[2];
42
+        tempText.color[3] = color[3];
43
+    }
44
+    writeString(tempText);
45
+}
46
+

+ 65
- 0
src/FontManager.cpp Vedi File

@@ -0,0 +1,65 @@
1
+/*!
2
+ * \file src/FontManager.cpp
3
+ * \brief SDL Font implementation
4
+ *
5
+ * \author xythobuz
6
+ */
7
+
8
+#include "global.h"
9
+#include "utils/strings.h"
10
+#include "FontManager.h"
11
+#include "Font.h"
12
+#include "FontSDL.h"
13
+#include "FontTRLE.h"
14
+
15
+FontManager::FontManager() {
16
+    add(new FontTRLE(), ".pc");
17
+
18
+#ifdef USING_SDL_FONT
19
+    add(new FontSDL(), ".ttf");
20
+#endif
21
+
22
+    font = -1;
23
+
24
+    tempText.text = new char[256];
25
+    tempText.color[0] = 0xFF;
26
+    tempText.color[1] = 0xFF;
27
+    tempText.color[2] = 0xFF;
28
+    tempText.color[3] = 0xFF;
29
+    tempText.scale = 1.2f;
30
+    tempText.w = 0;
31
+    tempText.h = 0;
32
+}
33
+
34
+FontManager::~FontManager() {
35
+    while (!fonts.empty()) {
36
+        delete fonts.back();
37
+        fonts.pop_back();
38
+    }
39
+}
40
+
41
+void FontManager::add(Font *f, const char *e) {
42
+    fonts.push_back(f);
43
+    extensions.push_back(e);
44
+}
45
+
46
+int FontManager::initialize() {
47
+    for (unsigned int i = 0; i < fonts.size(); i++) {
48
+        if (stringEndsWith(mFontName, extensions.at(i))) {
49
+            font = i;
50
+            break;
51
+        }
52
+    }
53
+
54
+    if (font == -1)
55
+        return -1;
56
+
57
+    fonts.at(font)->setFont(mFontName);
58
+    return fonts.at(font)->initialize();
59
+}
60
+
61
+void FontManager::writeString(FontString &s) {
62
+    assert(font != -1);
63
+    fonts.at(font)->writeString(s);
64
+}
65
+

+ 0
- 22
src/FontSDL.cpp Vedi File

@@ -30,9 +30,6 @@ FontSDL::~FontSDL() {
30 30
 
31 31
     if (mFontInit)
32 32
         TTF_Quit();
33
-
34
-    delete [] tempText.text;
35
-    tempText.text = NULL;
36 33
 }
37 34
 
38 35
 int FontSDL::initialize() {
@@ -118,22 +115,3 @@ void FontSDL::writeString(FontString &s) {
118 115
     SDL_FreeSurface(surface);
119 116
 }
120 117
 
121
-void FontSDL::drawText(unsigned int x, unsigned int y, float scale, const float color[4], const char *s, ...) {
122
-    va_list args;
123
-    va_start(args, s);
124
-    vsnprintf(tempText.text, 256, s, args);
125
-    tempText.text[255] = '\0';
126
-    va_end(args);
127
-
128
-    tempText.scale = scale;
129
-    tempText.x = x;
130
-    tempText.y = y;
131
-    if (color) {
132
-        tempText.color[0] = color[0];
133
-        tempText.color[1] = color[1];
134
-        tempText.color[2] = color[2];
135
-        tempText.color[3] = color[3];
136
-    }
137
-    writeString(tempText);
138
-}
139
-

+ 0
- 21
src/FontTRLE.cpp Vedi File

@@ -28,8 +28,6 @@ FontTRLE::FontTRLE() {
28 28
 }
29 29
 
30 30
 FontTRLE::~FontTRLE() {
31
-    delete [] tempText.text;
32
-    tempText.text = NULL;
33 31
 }
34 32
 
35 33
 int FontTRLE::initialize() {
@@ -167,22 +165,3 @@ void FontTRLE::writeString(FontString &s) {
167 165
 */
168 166
 }
169 167
 
170
-void FontTRLE::drawText(unsigned int x, unsigned int y, float scale, const float color[4], const char *s, ...) {
171
-    va_list args;
172
-    va_start(args, s);
173
-    vsnprintf(tempText.text, 256, s, args);
174
-    tempText.text[255] = '\0';
175
-    va_end(args);
176
-
177
-    tempText.scale = scale;
178
-    tempText.x = x;
179
-    tempText.y = y;
180
-    if (color) {
181
-        tempText.color[0] = color[0];
182
-        tempText.color[1] = color[1];
183
-        tempText.color[2] = color[2];
184
-        tempText.color[3] = color[3];
185
-    }
186
-    writeString(tempText);
187
-}
188
-

+ 2
- 10
src/main.cpp Vedi File

@@ -12,6 +12,7 @@
12 12
 #include "global.h"
13 13
 #include "Camera.h"
14 14
 #include "Console.h"
15
+#include "FontManager.h"
15 16
 #include "Game.h"
16 17
 #include "Menu.h"
17 18
 #include "OpenRaider.h"
@@ -28,17 +29,13 @@
28 29
 
29 30
 #ifdef USING_SDL
30 31
 #include "WindowSDL.h"
31
-#ifdef USING_TRLE
32
-#include "FontTRLE.h"
33
-#else
34
-#include "FontSDL.h"
35
-#endif
36 32
 #else
37 33
 #error No Windowing Library selected!
38 34
 #endif
39 35
 
40 36
 Camera gCamera;
41 37
 Console gConsole;
38
+FontManager gFont;
42 39
 Game gGame;
43 40
 Menu gMenu;
44 41
 OpenRaider gOpenRaider;
@@ -53,11 +50,6 @@ SoundNull gSound;
53 50
 
54 51
 #ifdef USING_SDL
55 52
 WindowSDL gWindow;
56
-#ifdef USING_TRLE
57
-FontTRLE gFont;
58
-#else
59
-FontSDL gFont;
60
-#endif
61 53
 #endif
62 54
 
63 55
 Camera &getCamera() {

Loading…
Annulla
Salva