Skip to content

Commit

Permalink
Merge pull request #1184 from Daggolin/qol_console
Browse files Browse the repository at this point in the history
Improve console and font handling
  • Loading branch information
Razish committed Feb 8, 2024
2 parents 58ad339 + 97c7291 commit 01697e6
Show file tree
Hide file tree
Showing 21 changed files with 1,118 additions and 433 deletions.
503 changes: 333 additions & 170 deletions code/client/cl_console.cpp

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions code/client/cl_keys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,8 @@ Handles horizontal scrolling and cursor blinking
x, y, amd width are in pixels
===================
*/
void Field_VariableSizeDraw( field_t *edit, int x, int y, int width, int size, qboolean showCursor, qboolean noColorEscape ) {
extern console_t con;
void Field_VariableSizeDraw( field_t *edit, int x, int y, int size, qboolean showCursor, qboolean noColorEscape ) {
int len;
int drawLen;
int prestep;
Expand Down Expand Up @@ -434,7 +435,7 @@ void Field_VariableSizeDraw( field_t *edit, int x, int y, int width, int size, q
str[ drawLen ] = 0;

// draw it
if ( size == SMALLCHAR_WIDTH ) {
if ( size == con.charWidth ) {
float color[4];

color[0] = color[1] = color[2] = color[3] = 1.0;
Expand All @@ -458,7 +459,7 @@ void Field_VariableSizeDraw( field_t *edit, int x, int y, int width, int size, q

i = drawLen - strlen( str );

if ( size == SMALLCHAR_WIDTH ) {
if ( size == con.charWidth ) {
SCR_DrawSmallChar( x + ( edit->cursor - prestep - i ) * size, y, cursorChar );
} else {
str[0] = cursorChar;
Expand All @@ -468,14 +469,14 @@ void Field_VariableSizeDraw( field_t *edit, int x, int y, int width, int size, q
}
}

void Field_Draw( field_t *edit, int x, int y, int width, qboolean showCursor, qboolean noColorEscape )
void Field_Draw( field_t *edit, int x, int y, qboolean showCursor, qboolean noColorEscape )
{
Field_VariableSizeDraw( edit, x, y, width, SMALLCHAR_WIDTH, showCursor, noColorEscape );
Field_VariableSizeDraw( edit, x, y, con.charWidth, showCursor, noColorEscape );
}

void Field_BigDraw( field_t *edit, int x, int y, int width, qboolean showCursor, qboolean noColorEscape )
void Field_BigDraw( field_t *edit, int x, int y, qboolean showCursor, qboolean noColorEscape )
{
Field_VariableSizeDraw( edit, x, y, width, BIGCHAR_WIDTH, showCursor, noColorEscape );
Field_VariableSizeDraw( edit, x, y, BIGCHAR_WIDTH, showCursor, noColorEscape );
}

/*
Expand Down
3 changes: 3 additions & 0 deletions code/client/cl_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ cvar_t *cl_inGameVideo;

cvar_t *cl_consoleKeys;
cvar_t *cl_consoleUseScanCode;
cvar_t *cl_consoleShiftRequirement;

clientActive_t cl;
clientConnection_t clc;
Expand Down Expand Up @@ -934,6 +935,7 @@ void CL_InitRenderer( void ) {

// load character sets
cls.charSetShader = re.RegisterShaderNoMip("gfx/2d/charsgrid_med");
cls.consoleFont = re.RegisterFont( "ocr_a" );
cls.whiteShader = re.RegisterShader( "white" );
cls.consoleShader = re.RegisterShader( "console" );
g_console_field_width = cls.glconfig.vidWidth / SMALLCHAR_WIDTH - 2;
Expand Down Expand Up @@ -1279,6 +1281,7 @@ void CL_Init( void ) {
// ~ and `, as keys and characters
cl_consoleKeys = Cvar_Get( "cl_consoleKeys", "~ ` 0x7e 0x60 0xb2", CVAR_ARCHIVE);
cl_consoleUseScanCode = Cvar_Get( "cl_consoleUseScanCode", "1", CVAR_ARCHIVE );
cl_consoleShiftRequirement = Cvar_Get( "cl_consoleShiftRequirement", "0", CVAR_ARCHIVE );

// userinfo
#ifdef JK2_MODE
Expand Down
8 changes: 4 additions & 4 deletions code/client/cl_scrn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void SCR_DrawSmallChar( int x, int y, int ch ) {
return;
}

if ( y < -SMALLCHAR_HEIGHT ) {
if ( y < -con.charHeight ) {
return;
}

Expand All @@ -162,7 +162,7 @@ void SCR_DrawSmallChar( int x, int y, int ch ) {
fcol = col*0.0625;
size = 0.0625;
re.DrawStretchPic( x, y, SMALLCHAR_WIDTH, SMALLCHAR_HEIGHT,
re.DrawStretchPic( x, y, con.charWidth, con.charHeight,
fcol, frow,
fcol + size, frow + size,
cls.charSetShader );
Expand All @@ -176,7 +176,7 @@ void SCR_DrawSmallChar( int x, int y, int ch ) {
size2 = 0.0625;

re.DrawStretchPic( x * con.xadjust, y * con.yadjust,
SMALLCHAR_WIDTH * con.xadjust, SMALLCHAR_HEIGHT * con.yadjust,
con.charWidth * con.xadjust, con.charHeight * con.yadjust,
fcol, frow,
fcol + size, frow + size2,
cls.charSetShader );
Expand Down Expand Up @@ -284,7 +284,7 @@ void SCR_DrawSmallStringExt( int x, int y, const char *string, float *setColor,
}
}
SCR_DrawSmallChar( xx, y, *s );
xx += SMALLCHAR_WIDTH;
xx += con.charWidth;
s++;
}
re.SetColor( NULL );
Expand Down
16 changes: 15 additions & 1 deletion code/client/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,22 +206,35 @@ typedef struct {
qhandle_t charSetShader;
qhandle_t whiteShader;
qhandle_t consoleShader;
int consoleFont;
} clientStatic_t;

#define CON_TEXTSIZE 0x30000 //was 32768
#define NUM_CON_TIMES 4

typedef union {
struct {
unsigned char color;
char character;
} f;
unsigned short compare;
} conChar_t;

typedef struct {
qboolean initialized;

short text[CON_TEXTSIZE];
conChar_t text[CON_TEXTSIZE];
int current; // line where next message will be printed
int x; // offset in current line for next print
int display; // bottom of console displays this line

int linewidth; // characters across screen
int rowwidth; // timestamp, text and line wrap character
int totallines; // total lines in console scrollback

int charWidth; // Scaled console character width
int charHeight; // Scaled console character height

float xadjust; // for wide aspect screens
float yadjust;

Expand Down Expand Up @@ -279,6 +292,7 @@ extern cvar_t *cl_activeAction;

extern cvar_t *cl_consoleKeys;
extern cvar_t *cl_consoleUseScanCode;
extern cvar_t *cl_consoleShiftRequirement;

//=================================================

Expand Down
4 changes: 2 additions & 2 deletions code/client/keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ extern field_t historyEditLines[COMMAND_HISTORY];

void Field_KeyDownEvent ( field_t *edit, int key );
void Field_CharEvent ( field_t *edit, int ch );
void Field_Draw ( field_t *edit, int x, int y, int width, qboolean showCursor, qboolean noColorEscape );
void Field_BigDraw ( field_t *edit, int x, int y, int width, qboolean showCursor, qboolean noColorEscape );
void Field_Draw ( field_t *edit, int x, int y, qboolean showCursor, qboolean noColorEscape );
void Field_BigDraw ( field_t *edit, int x, int y, qboolean showCursor, qboolean noColorEscape );

void Key_SetBinding ( int keynum, const char *binding );
const char *Key_GetBinding ( int keynum );
Expand Down
60 changes: 46 additions & 14 deletions code/qcommon/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ cvar_t *com_G2Report;

cvar_t *com_affinity;

cvar_t *com_timestamps;

// com_speeds times
int time_game;
int time_frontend; // renderer frontend time
Expand Down Expand Up @@ -137,6 +139,7 @@ A raw string should NEVER be passed as fmt, because of "%f" type crashers.
void QDECL Com_Printf( const char *fmt, ... ) {
va_list argptr;
char msg[MAXPRINTMSG];
const char *p;

va_start (argptr,fmt);
Q_vsnprintf (msg, sizeof(msg), fmt, argptr);
Expand All @@ -153,26 +156,53 @@ void QDECL Com_Printf( const char *fmt, ... ) {

CL_ConsolePrint( msg );

// echo to dedicated console and early console
Sys_Print( msg );
p = msg;
while (*p) {
static qboolean newLine = qtrue;
char line[MAXPRINTMSG];
size_t lineLen;

if (newLine && com_timestamps && com_timestamps->integer) {
time_t t = time( NULL );
struct tm *tms = localtime( &t );
Com_sprintf(line, sizeof(line), "%04i-%02i-%02i %02i:%02i:%02i ",
1900 + tms->tm_year, 1 + tms->tm_mon, tms->tm_mday, tms->tm_hour, tms->tm_min, tms->tm_sec);
lineLen = strlen(line);
newLine = qfalse;
} else {
if (const char *s = strchr(p, '\n')) {
lineLen = (size_t)(s - p + 1);
newLine = qtrue;
} else {
lineLen = strlen(p);
}

Com_Memcpy(line, p, lineLen);
line[lineLen] = '\0';
p += lineLen;
}

// echo to dedicated console and early console
Sys_Print( line );


#ifdef OUTPUT_TO_BUILD_WINDOW
OutputDebugString(msg);
OutputDebugString(line);
#endif

// logfile
if ( com_logfile && com_logfile->integer ) {
if ( !logfile && FS_Initialized() ) {
logfile = FS_FOpenFileWrite( "qconsole.log" );
if ( com_logfile->integer > 1 ) {
// force it to not buffer so we get valid
// data even if we are crashing
FS_ForceFlush(logfile);
// logfile
if ( com_logfile && com_logfile->integer ) {
if ( !logfile && FS_Initialized() ) {
logfile = FS_FOpenFileWrite( "qconsole.log" );
if ( com_logfile->integer > 1 ) {
// force it to not buffer so we get valid
// data even if we are crashing
FS_ForceFlush(logfile);
}
}
if ( logfile ) {
FS_Write(line, strlen(line), logfile);
}
}
if ( logfile ) {
FS_Write(msg, strlen(msg), logfile);
}
}
}
Expand Down Expand Up @@ -1121,6 +1151,8 @@ void Com_Init( char *commandLine ) {

com_bootlogo = Cvar_Get( "com_bootlogo", "1", CVAR_ARCHIVE_ND );

com_timestamps = Cvar_Get( "com_timestamps", "1", CVAR_ARCHIVE_ND );

if ( com_developer && com_developer->integer ) {
Cmd_AddCommand ("error", Com_Error_f);
Cmd_AddCommand ("crash", Com_Crash_f );
Expand Down
2 changes: 1 addition & 1 deletion code/qcommon/qcommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ void CL_JoystickEvent( int axis, int value, int time );

void CL_PacketEvent( netadr_t from, msg_t *msg );

void CL_ConsolePrint( char *text );
void CL_ConsolePrint( const char *text );

void CL_MapLoading( void );
// do a screen update before starting to load a map
Expand Down

0 comments on commit 01697e6

Please sign in to comment.