Browse Source

Finished TRLE font support, loading lps files

Thomas Buck 10 years ago
parent
commit
0d25be737e
10 changed files with 75 additions and 38 deletions
  1. 1
    1
      ChangeLog.md
  2. 12
    1
      README.md
  3. 1
    0
      cmake/setup.sh
  4. 1
    0
      cmake/setup_mac.sh
  5. 1
    0
      data/OpenRaider.ini
  6. BIN
      data/font.pc
  7. 2
    10
      include/FontTRLE.h
  8. 9
    3
      src/CMakeLists.txt
  9. 40
    23
      src/FontTRLE.cpp
  10. 8
    0
      src/main.cpp

+ 1
- 1
ChangeLog.md View File

@@ -3,7 +3,7 @@
3 3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
4 4
 
5 5
     [ 20140614 ]
6
-    * Started implementing TRLE Font loader
6
+    * Implemented TRLE Font loader
7 7
 
8 8
     [ 20140613 ]
9 9
     * Changed strange delete-guards

+ 12
- 1
README.md View File

@@ -29,7 +29,8 @@ A more or less recent [Doxygen documentation](http://xythobuz.github.io/OpenRaid
29 29
 Basically, OpenRaider depends on the following:
30 30
 
31 31
 * OpenGL
32
-* SDL2 & SDL2-TTF
32
+* SDL2
33
+* SDL2-TTF (if you want to use TTF fonts)
33 34
 * OpenAL & ALUT
34 35
 * zlib
35 36
 * cmake as build system
@@ -114,6 +115,14 @@ OpenRaider tries to load a `MAIN.SFX` from the same folder as the selected level
114 115
 
115 116
 Every available command should be listed in the in-game help. Just type `help` in the OpenRaider console, which can be activated by default with the backquote key.
116 117
 
118
+### Tomb Raider Level Editor Font support
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).
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.
123
+
124
+I’ve made [a small writeup on my website](http://xythobuz.de/2014_06_14_trle_font.html) about this.
125
+
117 126
 ### Wireframe mode colors
118 127
 
119 128
 * Red (thick) lines are portal outlines
@@ -139,6 +148,8 @@ Forked in December 2013 by xythobuz.
139 148
 
140 149
 The included example Font, [Droid Sans Mono](http://www.droidfonts.com/licensing/), was created by Steve Matteson and is licensed under the [Apache 2.0 License](http://www.apache.org/licenses/LICENSE-2.0).
141 150
 
151
+The included TRLE Font is from [Laras Levelbase](http://laraslevelbase.org/stuff/index.asp?id=1967).
152
+
142 153
 There are some included cmake scripts:
143 154
 
144 155
 * [FindALUT](https://github.com/rpavlik/cmake-modules/blob/master/FindALUT.cmake)

+ 1
- 0
cmake/setup.sh View File

@@ -9,4 +9,5 @@ mkdir -p ~/.OpenRaider/data
9 9
 mkdir -p ~/.OpenRaider/sshots
10 10
 cp data/*.tga ~/.OpenRaider/data
11 11
 cp data/*.ttf ~/.OpenRaider/data
12
+cp data/*.pc ~/.OpenRaider/data
12 13
 echo "DONE"

+ 1
- 0
cmake/setup_mac.sh View File

@@ -10,6 +10,7 @@ if [ ! -d "${HOME}/.OpenRaider" ]; then
10 10
     mkdir -p ~/.OpenRaider/sshots
11 11
     cp ../Resources/defaults/*.tga ~/.OpenRaider/data
12 12
     cp ../Resources/defaults/*.ttf ~/.OpenRaider/data
13
+    cp ../Resources/defaults/*.pc ~/.OpenRaider/data
13 14
     echo "DONE"
14 15
     osascript -e 'tell app "System Events" to display alert "Initial Configuration stored in ~/.OpenRaider\n\nView and edit OpenRaider.ini to your needs..."'
15 16
 fi

+ 1
- 0
data/OpenRaider.ini View File

@@ -6,6 +6,7 @@ set pakdir     "$(basedir)/paks"
6 6
 set audiodir   "$(basedir)/music"
7 7
 set datadir    "$(basedir)/data"
8 8
 set font       "$(datadir)/test.ttf"
9
+# set font       "$(datadir)/font.pc"
9 10
 
10 11
 # Not needed for Mac OS X
11 12
 set gldriver   "/usr/lib/libGL.so.1"

BIN
data/font.pc View File


+ 2
- 10
include/FontTRLE.h View File

@@ -36,20 +36,12 @@ public:
36 36
 
37 37
 private:
38 38
 
39
-    void loadLPS(const char *file);
39
+    void loadLPS(const char *f);
40 40
     void writeChar(unsigned int index, unsigned int xDraw, FontString &s);
41 41
 
42 42
     unsigned int mFontTexture;
43 43
     FontString tempText;
44 44
 
45
-    unsigned int resolution1;
46
-    unsigned int resolution2;
47
-    int ruler1;
48
-    int ruler2;
49
-    int baselineAbs; // always zero?
50
-    vec_t spacing;
51
-    vec_t squashedTextFactor;
52
-
53 45
     // 106 entries: (x, y, w, h, offset)
54 46
     int offsets[106][5] = {
55 47
         { 174,  52,   3,  12, -11 },
@@ -131,7 +123,7 @@ private:
131 123
         {  96,  26,  17,   8, -7  },
132 124
         { 152,  48,  11,   8, -7  },
133 125
         {  62,  51,   9,   8, -7  },
134
-        { 244,  15,   0,  12, -7  },
126
+        { 244,  15,  10,  12, -7  },
135 127
         {  52,  39,   9,  12, -7  },
136 128
         {  10,  52,   9,   8, -7  },
137 129
         { 190,  52,   8,   8, -7  },

+ 9
- 3
src/CMakeLists.txt View File

@@ -78,8 +78,14 @@ if (SDL2_FOUND AND SDL2TTF_FOUND)
78 78
     set (SRCS ${SRCS} "FontSDL.cpp")
79 79
     set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} -DUSING_SDL")
80 80
 else (SDL2_FOUND AND SDL2TTF_FOUND)
81
-    # Currently only SDL2 support
82
-    message (FATAL_ERROR "SDL2 and SDL2-TTF are required at the moment!")
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)
83 89
 endif (SDL2_FOUND AND SDL2TTF_FOUND)
84 90
 
85 91
 #################################################################
@@ -135,7 +141,7 @@ if (APPLE)
135 141
     set (SRCS ${SRCS} ${MAC_ICON})
136 142
 
137 143
     # Copy Data
138
-    set (MAC_DATA "../data/OpenRaider.ini" "../data/test.ttf" "../data/splash.tga")
144
+    set (MAC_DATA "../data/font.pc" "../data/OpenRaider.ini" "../data/test.ttf" "../data/splash.tga")
139 145
     set_source_files_properties (${MAC_DATA} PROPERTIES MACOSX_PACKAGE_LOCATION Resources/defaults)
140 146
     set (SRCS ${SRCS} ${MAC_DATA})
141 147
 endif (APPLE)

+ 40
- 23
src/FontTRLE.cpp View File

@@ -6,6 +6,7 @@
6 6
  */
7 7
 
8 8
 #include <fstream>
9
+#include <sstream>
9 10
 
10 11
 #include "global.h"
11 12
 #include "utils/strings.h"
@@ -16,16 +17,6 @@ FontTRLE::FontTRLE() {
16 17
     mFontName = NULL;
17 18
     mFontTexture = 0;
18 19
 
19
-    // TRLE defaults
20
-    resolution1 = 240;
21
-    resolution2 = 512;
22
-    ruler1 = -16;
23
-    ruler2 = -40;
24
-    baselineAbs = 0; // always zero?
25
-    spacing = 0.075f;
26
-    squashedTextFactor = 0.75f;
27
-    // offset table default is set in header
28
-
29 20
     tempText.text = new char[256];
30 21
     tempText.color[0] = 0xFF;
31 22
     tempText.color[1] = 0xFF;
@@ -42,14 +33,7 @@ FontTRLE::~FontTRLE() {
42 33
 }
43 34
 
44 35
 int FontTRLE::initialize() {
45
-    // TODO font coloring not working when .pc has color?!?!
46
-
47
-
48
-    // tmp debug
49
-    delete [] mFontName;
50
-    mFontName = bufferString("/Users/thomas/Downloads/TR Fonts/TR4 Official/Font.pc");
51
-    //mFontName = bufferString("/Users/thomas/Downloads/TR Fonts/TR2 Web/Font.pc");
52
-
36
+    //! \todo Font coloring not working when .pc has color?!?!
53 37
 
54 38
     assert(mFontInit == false);
55 39
     assert(mFontName != NULL);
@@ -81,11 +65,44 @@ int FontTRLE::initialize() {
81 65
     return 0;
82 66
 }
83 67
 
84
-void FontTRLE::loadLPS(const char *file) {
85
-    // TODO load lps file
86
-
87
-    // if baselineAbs != 0
88
-    //     all offset[4] + baselineAbs;
68
+void FontTRLE::loadLPS(const char *f) {
69
+    std::ifstream file(f);
70
+    if (!file)
71
+        return;
72
+
73
+    /*!
74
+     * \todo This is probably the worlds most unreliable parser...
75
+     */
76
+
77
+    for (std::string line; std::getline(file, line);) {
78
+        std::istringstream stream(line);
79
+        std::string tok1, tok2;
80
+        std::getline(stream, tok1, '=');
81
+        std::getline(stream, tok2);
82
+
83
+        // we are only interested in lines starting with
84
+        // xxx=
85
+        // Where xxx is a 3 digit number
86
+        try {
87
+            int index = std::stoi(tok1);
88
+            if ((index >= 0) && (index <= 105)) {
89
+                std::istringstream row(tok2);
90
+                std::string a, b, c, d, e;
91
+                std::getline(row, a, ',');
92
+                std::getline(row, b, ',');
93
+                std::getline(row, c, ',');
94
+                std::getline(row, d, ',');
95
+                std::getline(row, e);
96
+                offsets[index][0] = std::stoi(a);
97
+                offsets[index][1] = std::stoi(b);
98
+                offsets[index][2] = std::stoi(c);
99
+                offsets[index][3] = std::stoi(d);
100
+                offsets[index][4] = std::stoi(e);
101
+            }
102
+        } catch (std::invalid_argument) {
103
+
104
+        }
105
+    }
89 106
 }
90 107
 
91 108
 #define SCALING 2.0f

+ 8
- 0
src/main.cpp View File

@@ -28,7 +28,11 @@
28 28
 
29 29
 #ifdef USING_SDL
30 30
 #include "WindowSDL.h"
31
+#ifdef USING_TRLE
32
+#include "FontTRLE.h"
33
+#else
31 34
 #include "FontSDL.h"
35
+#endif
32 36
 #else
33 37
 #error No Windowing Library selected!
34 38
 #endif
@@ -49,8 +53,12 @@ SoundNull gSound;
49 53
 
50 54
 #ifdef USING_SDL
51 55
 WindowSDL gWindow;
56
+#ifdef USING_TRLE
57
+FontTRLE gFont;
58
+#else
52 59
 FontSDL gFont;
53 60
 #endif
61
+#endif
54 62
 
55 63
 Camera &getCamera() {
56 64
     return gCamera;

Loading…
Cancel
Save