the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#pragma once
2
3#include <unordered_map>
4
5using namespace std;
6
7#define _DEBUG_BLOCK_CHARS 0
8
9// For hardcoded font data.
10struct SFontData
11{
12public:
13 static const unsigned short FONTCOLS = 23;
14 static const unsigned short FONTROWS = 20;
15
16 static const unsigned short FONTSIZE = FONTCOLS * FONTROWS;
17
18public:
19 // Font name.
20 string m_strFontName;
21
22 // Filename of the glyph archive.
23 wstring m_wstrFilename;
24
25 // Number of glyphs in the archive.
26 unsigned int m_uiGlyphCount;
27
28 // Unicode values of each glyph.
29 unsigned short *m_arrCodepoints;
30
31 // X resolution of glyph archive.
32 unsigned int m_uiGlyphMapX;
33
34 // Y resolution of glyph archive.
35 unsigned int m_uiGlyphMapY;
36
37 // Number of columns in the glyph archive.
38 unsigned int m_uiGlyphMapCols;
39
40 // Number of rows in the glyph archive.
41 unsigned int m_uiGlyphMapRows;
42
43 // Width of each glyph.
44 unsigned int m_uiGlyphWidth;
45
46 // Height of each glyph.
47 unsigned int m_uiGlyphHeight;
48
49 // Ascent of each glyph above the baseline (units?).
50 float m_fAscent;
51
52 // Descent of each glyph below the baseline (units?).
53 float m_fDescent;
54
55 // How much to advance for each pixel wide the glyph is.
56 float m_fAdvPerPixel;
57
58 // How many pixels wide any whitespace characters are.
59 unsigned int m_uiWhitespaceWidth;
60
61public:
62 static unsigned short Codepoints[FONTSIZE];
63 static SFontData Mojangles_7;
64 static SFontData Mojangles_11;
65};
66
67// Provides a common interface for dealing with font data.
68class CFontData
69{
70public:
71 CFontData();
72
73 // pbRawImage consumed by constructor.
74 CFontData(SFontData &sFontData, int *pbRawImage);
75
76 // Release memory.
77 void release();
78
79protected:
80
81 // Hardcoded font data.
82 SFontData *m_sFontData;
83
84 // Map Unicodepoints to glyph ids.
85 unordered_map<unsigned int, unsigned short> m_unicodeMap;
86
87 // Kerning value for each glyph.
88 unsigned short *m_kerningTable;
89
90 // Binary blob of the archive image.
91 unsigned char *m_pbRawImage;
92
93 // Total advance of each character.
94 float *m_pfAdvanceTable;
95
96public:
97
98 // Accessor for the font name in the internal SFontData.
99 const string getFontName();
100
101 // Accessor for the hardcoded internal font data.
102 SFontData *getFontData();
103
104 // Get the glyph id corresponding to a unicode point.
105 unsigned short getGlyphId(unsigned int unicodepoint);
106
107 // Get the unicodepoint corresponding to a glyph id.
108 unsigned int getUnicode(unsigned short glyphId);
109
110 // Get a pointer to the top left pixel of a row/column in the raw image.
111 unsigned char *topLeftPixel(int row, int col);
112
113 // Get the row and column where a glyph appears in the archive.
114 void getPos(unsigned short gyphId, int &row, int &col);
115
116 // Get the advance of this character (units?).
117 float getAdvance(unsigned short glyphId);
118
119 // Get the width (in pixels) of a given character.
120 int getWidth(unsigned short glyphId);
121
122 // Returns true if this glyph is whitespace.
123 bool glyphIsWhitespace(unsigned short glyphId);
124
125 // Returns true if this unicodepoint is whitespace
126 bool unicodeIsWhitespace(unsigned int unicodepoint);
127
128private:
129
130 // Move a pointer in an image dx pixels right and dy pixels down, wrap around in either dimension leads to unknown behaviour.
131 void moveCursor(unsigned char *&cursor, unsigned int dx, unsigned int dy);
132};
133