WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit a53485a

Browse files
committed
Merge branch 'master' into for-0.56.0/sync
2 parents 319da78 + 5ab62e7 commit a53485a

File tree

10 files changed

+539
-138
lines changed

10 files changed

+539
-138
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,8 @@ if (BUILD_CLIENT)
929929

930930
# Generate GLSL include files.
931931
daemon_embed_files("EngineShaders" "${GLSL_EMBED_DIR}" "${GLSL_EMBED_LIST}" "TEXT" "client-objects")
932+
933+
daemon_embed_files(ConsoleFont "${CMAKE_CURRENT_SOURCE_DIR}/libs/unifont" unifont.otf BINARY client-objects)
932934
endif()
933935

934936
if (BUILD_SERVER)

libs/unifont/LICENSE.txt

Lines changed: 476 additions & 0 deletions
Large diffs are not rendered by default.

libs/unifont/unifont.otf

5.07 MB
Binary file not shown.
-6.06 KB
Binary file not shown.

pkg/daemon_src.dpkdir/scripts/engine.shader

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,3 @@ white
77
rgbgen vertex
88
}
99
}
10-
11-
// console font fallback
12-
gfx/2d/bigchars
13-
{
14-
nopicmip
15-
nomipmaps
16-
{
17-
map gfx/2d/bigchars
18-
blendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
19-
rgbgen vertex
20-
}
21-
}

src/engine/client/cl_main.cpp

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2093,50 +2093,47 @@ bool CL_InitRenderer()
20932093
return false;
20942094
}
20952095

2096-
fileHandle_t f;
2097-
20982096
// this sets up the renderer and calls R_Init
20992097
if ( !re.BeginRegistration( &cls.windowConfig ) )
21002098
{
21012099
return false;
21022100
}
21032101

2104-
cl_consoleFont = Cvar_Get( "cl_consoleFont", "fonts/unifont.ttf", CVAR_LATCH );
2102+
cl_consoleFont = Cvar_Get( "cl_consoleFont", "", CVAR_LATCH );
21052103
cl_consoleFontSize = Cvar_Get( "cl_consoleFontSize", "16", CVAR_LATCH );
21062104
cl_consoleFontScaling = Cvar_Get( "cl_consoleFontScaling", "1", CVAR_LATCH );
21072105

2108-
// load character sets
2109-
cls.charSetShader = re.RegisterShader( "gfx/2d/bigchars", RSF_2D );
2110-
cls.useLegacyConsoleFont = cls.useLegacyConsoleFace = true;
2106+
// Register console font specified by cl_consoleFont. Empty string means use the embbed Unifont
2107+
2108+
int fontSize = cl_consoleFontSize->integer;
21112109

2112-
// Register console font specified by cl_consoleFont, if any
2113-
// filehandle is unused but forces FS_FOpenFileRead() to heed purecheck because it does not when filehandle is nullptr
2114-
if ( cl_consoleFont->string[0] )
2110+
if ( cl_consoleFontScaling->integer )
21152111
{
2116-
if ( FS_FOpenFileRead( cl_consoleFont->string, &f ) >= 0 )
2117-
{
2118-
if ( cl_consoleFontScaling->value == 0 )
2119-
{
2120-
cls.consoleFont = re.RegisterFont( cl_consoleFont->string, cl_consoleFontSize->integer );
2121-
}
2122-
else
2123-
{
2124-
// This gets 12px on 1920×1080 screen, which is libRocket default for 1em
2125-
int fontScale = std::min(cls.windowConfig.vidWidth, cls.windowConfig.vidHeight) / 90;
2112+
// This gets 12px on 1920×1080 screen, which is libRocket default for 1em
2113+
int fontScale = std::min(cls.windowConfig.vidWidth, cls.windowConfig.vidHeight) / 90;
21262114

2127-
// fontScale / 12px gets 1px on 1920×1080 screen
2128-
cls.consoleFont = re.RegisterFont( cl_consoleFont->string, cl_consoleFontSize->integer * fontScale / 12 );
2129-
}
2115+
// fontScale / 12px gets 1px on 1920×1080 screen
2116+
fontSize = cl_consoleFontSize->integer * fontScale / 12;
2117+
}
21302118

2131-
if ( cls.consoleFont != nullptr )
2132-
cls.useLegacyConsoleFont = false;
2133-
}
2134-
else
2119+
if ( cl_consoleFont->string[ 0 ] )
2120+
{
2121+
cls.consoleFont = re.RegisterFont( cl_consoleFont->string, fontSize );
2122+
if ( cls.consoleFont == nullptr )
21352123
{
2136-
Log::Warn("Font file '%s' not found", cl_consoleFont->string);
2124+
Log::Warn( "Couldn't load font file '%s', falling back to default console font",
2125+
cl_consoleFont->string );
21372126
}
2127+
}
21382128

2139-
FS_FCloseFile( f );
2129+
if ( cls.consoleFont == nullptr )
2130+
{
2131+
cls.consoleFont = re.RegisterFont( "", fontSize );
2132+
2133+
if ( cls.consoleFont == nullptr )
2134+
{
2135+
Sys::Error( "Failed to load built-in console font" );
2136+
}
21402137
}
21412138

21422139
cls.whiteShader = re.RegisterShader( "white", RSF_NOMIP );

src/engine/client/cl_scrn.cpp

Lines changed: 3 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,6 @@ static glyphInfo_t *Glyph( int ch )
107107

108108
void SCR_DrawConsoleFontUnichar( float x, float y, int ch )
109109
{
110-
if ( cls.useLegacyConsoleFont )
111-
{
112-
SCR_DrawSmallUnichar( ( int ) x, ( int ) y, ch );
113-
return;
114-
}
115-
116110
if ( ch != ' ' )
117111
{
118112
glyphInfo_t *glyph = Glyph( ch );
@@ -126,53 +120,6 @@ void SCR_DrawConsoleFontUnichar( float x, float y, int ch )
126120
}
127121
}
128122

129-
/*
130-
** SCR_DrawSmallUnichar
131-
** small chars are drawn at native screen resolution
132-
*/
133-
void SCR_DrawSmallUnichar( int x, int y, int ch )
134-
{
135-
int row, col;
136-
float frow, fcol;
137-
float size;
138-
139-
if ( ch < 0x100 || cls.useLegacyConsoleFont )
140-
{
141-
if ( ch == ' ' ) {
142-
return;
143-
}
144-
145-
if ( y < -SMALLCHAR_HEIGHT ) {
146-
return;
147-
}
148-
149-
if ( ch >= 0x100 ) { ch = 0; }
150-
151-
row = ch>>4;
152-
col = ch&15;
153-
154-
frow = row*0.0625;
155-
fcol = col*0.0625;
156-
size = 0.0625;
157-
158-
// adjust for baseline
159-
re.DrawStretchPic( x, y - (int)( SMALLCHAR_HEIGHT / ( CONSOLE_FONT_VPADDING + 1 ) ),
160-
SMALLCHAR_WIDTH, SMALLCHAR_HEIGHT,
161-
fcol, frow,
162-
fcol + size, frow + size,
163-
cls.charSetShader );
164-
} else {
165-
glyphInfo_t *glyph = Glyph( ch );
166-
167-
re.DrawStretchPic( x, y, SMALLCHAR_WIDTH, glyph->imageHeight,
168-
glyph->s,
169-
glyph->t,
170-
glyph->s2,
171-
glyph->t2,
172-
glyph->glyph );
173-
}
174-
}
175-
176123
/*
177124
==================
178125
SCR_DrawSmallString[Color]
@@ -335,9 +282,7 @@ void SCR_UpdateScreen()
335282

336283
float SCR_ConsoleFontUnicharWidth( int ch )
337284
{
338-
return cls.useLegacyConsoleFont
339-
? SMALLCHAR_WIDTH
340-
: Glyph( ch )->xSkip + cl_consoleFontKerning->value;
285+
return Glyph( ch )->xSkip + cl_consoleFontKerning->value;
341286
}
342287

343288
float SCR_ConsoleFontCharWidth( const char *s )
@@ -347,44 +292,18 @@ float SCR_ConsoleFontCharWidth( const char *s )
347292

348293
float SCR_ConsoleFontCharHeight()
349294
{
350-
return cls.useLegacyConsoleFont
351-
? SMALLCHAR_HEIGHT
352-
: cls.consoleFont->glyphBlock[0][(unsigned)'I'].imageHeight + CONSOLE_FONT_VPADDING * cl_consoleFontSize->value;
295+
return cls.consoleFont->glyphBlock[0][(unsigned)'I'].imageHeight + CONSOLE_FONT_VPADDING * cl_consoleFontSize->value;
353296
}
354297

355298
float SCR_ConsoleFontCharVPadding()
356299
{
357-
return cls.useLegacyConsoleFont
358-
? 0
359-
: std::max( 0, -cls.consoleFont->glyphBlock[0][(unsigned)'g'].bottom >> 6);
300+
return std::max( 0, -cls.consoleFont->glyphBlock[0][(unsigned)'g'].bottom >> 6);
360301
}
361302

362303
float SCR_ConsoleFontStringWidth( const char* s, int len )
363304
{
364305
float width = 0;
365306

366-
if( cls.useLegacyConsoleFont )
367-
{
368-
if( cls.useLegacyConsoleFace )
369-
{
370-
return len * SMALLCHAR_WIDTH;
371-
}
372-
else
373-
{
374-
int l = 0;
375-
const char *str = s;
376-
377-
while( *str && len > 0 )
378-
{
379-
l++;
380-
str += Q_UTF8_Width( str );
381-
len--;
382-
}
383-
384-
return l * SMALLCHAR_WIDTH;
385-
}
386-
}
387-
388307
while( *s && len > 0 )
389308
{
390309
width += SCR_ConsoleFontCharWidth( s );

src/engine/client/client.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,7 @@ struct clientStatic_t
306306

307307
// rendering info
308308
WindowConfig windowConfig;
309-
qhandle_t charSetShader;
310309
qhandle_t whiteShader;
311-
bool useLegacyConsoleFont;
312-
bool useLegacyConsoleFace;
313310
fontInfo_t *consoleFont;
314311

315312
// www downloading
@@ -641,7 +638,6 @@ void SCR_AdjustFrom640( float *x, float *y, float *w, float *h );
641638
void SCR_FillRect( float x, float y, float width, float height, const Color::Color& color );
642639

643640
void SCR_DrawSmallStringExt( int x, int y, const char *string, const Color::Color& setColor, bool forceColor, bool noColorEscape );
644-
void SCR_DrawSmallUnichar( int x, int y, int ch );
645641
void SCR_DrawConsoleFontUnichar( float x, float y, int ch );
646642
float SCR_ConsoleFontCharWidth( const char *s );
647643
float SCR_ConsoleFontUnicharWidth( int ch );

src/engine/null/null_renderer.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ qhandle_t RE_RegisterShader( const char *, int )
5252
}
5353
fontInfo_t* RE_RegisterFont( const char *, int )
5454
{
55-
return nullptr;
55+
return new fontInfo_t{};
56+
}
57+
void RE_UnregisterFont( fontInfo_t* p )
58+
{
59+
delete p;
5660
}
5761
void RE_GlyphChar( fontInfo_t *, int, glyphInfo_t *glyph )
5862
{
@@ -70,7 +74,6 @@ void RE_GlyphChar( fontInfo_t *, int, glyphInfo_t *glyph )
7074
glyph->glyph = 1;
7175
glyph->shaderName[0] = '\0';
7276
}
73-
void RE_UnregisterFont( fontInfo_t* ) { }
7477
void RE_LoadWorldMap( const char * ) { }
7578
void RE_SetWorldVisData( const byte * ) { }
7679
void RE_EndRegistration() { }

src/engine/renderer/tr_font.cpp

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ Maryland 20850 USA.
3939
#include "qcommon/qcommon.h"
4040
#include "qcommon/q_unicode.h"
4141

42+
#include "DaemonEmbeddedFiles/ConsoleFont.h"
43+
4244
#include <ft2build.h>
4345
#include FT_FREETYPE_H
4446
#include FT_ERRORS_H
@@ -417,28 +419,46 @@ void RE_RenderChunk( fontInfo_t *font, const int chunk )
417419

418420
static int RE_LoadFontFile( const char *name, void **buffer )
419421
{
420-
void *tmp;
421-
int length = ri.FS_ReadFile( name, &tmp );
422+
if ( !*name )
423+
{
424+
*buffer = (void *)( ConsoleFont::unifont_otf.data );
425+
return ConsoleFont::unifont_otf.size;
426+
}
427+
428+
std::string tmp;
429+
430+
try
431+
{
432+
tmp = FS::HomePath::OpenRead( name ).ReadAll();
433+
}
434+
catch ( const std::system_error &exc )
435+
{
436+
Log::Warn( "Failed to read font file: %s", exc.what() );
437+
return 0;
438+
}
422439

423-
if ( length <= 0 )
440+
if ( tmp.size() > 1000 * 1000 * 1000 )
424441
{
425442
return 0;
426443
}
427444

428-
void *data = Z_AllocUninit( length );
445+
void *data = Z_AllocUninit( tmp.size() );
429446
*buffer = data;
430447

431-
memcpy( data, tmp, length );
432-
ri.FS_FreeFile( tmp );
448+
memcpy( data, tmp.data(), tmp.size() );
433449

434-
return length;
450+
return tmp.size();
435451
}
436452

437453
static void RE_FreeFontFile( void *data )
438454
{
439-
Z_Free( data );
455+
if ( data != ConsoleFont::unifont_otf.data )
456+
{
457+
Z_Free( data );
458+
}
440459
}
441460

461+
// If name is the empty string, load the embedded Unifont
442462
fontInfo_t* RE_RegisterFont( const char *fontName, int pointSize )
443463
{
444464
FT_Face face;

0 commit comments

Comments
 (0)