Skip to content

Commit 3a62d46

Browse files
committed
Migrate remaining in-game console (con_*) cvars
Usually I try to get rid of code that modifies cvars when the user didn't ask, but in this case there is a lot of it with complex logic so I left that in this time. Using migration script.
1 parent e9faabc commit 3a62d46

1 file changed

Lines changed: 36 additions & 56 deletions

File tree

src/engine/client/cl_console.cpp

Lines changed: 36 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,20 @@ Cvar::Range<Cvar::Cvar<int>> con_scrollLock("con_scrollLock",
6666

6767
Cvar::Cvar<std::string> con_prompt("con_prompt", "text at start of console input line", Cvar::NONE, "^3->");
6868

69-
cvar_t *con_borderWidth;
70-
cvar_t *con_borderColorAlpha;
71-
cvar_t *con_borderColorRed;
72-
cvar_t *con_borderColorBlue;
73-
cvar_t *con_borderColorGreen;
69+
Cvar::Cvar<int> con_borderWidth("con_borderWidth", "thickness of console border and scrollbar", Cvar::NONE, 1);
70+
Cvar::Range<Cvar::Cvar<float>> con_borderColorAlpha("con_borderColorAlpha", "alpha component of console border color", Cvar::NONE, 0.2, 0.0, 1.0);
71+
Cvar::Range<Cvar::Cvar<float>> con_borderColorRed("con_borderColorRed", "red component of console border color", Cvar::NONE, 1, 0.0, 1.0);
72+
Cvar::Range<Cvar::Cvar<float>> con_borderColorBlue("con_borderColorBlue", "blue component of console border color", Cvar::NONE, 1, 0.0, 1.0);
73+
Cvar::Range<Cvar::Cvar<float>> con_borderColorGreen("con_borderColorGreen", "green component of console border color", Cvar::NONE, 1, 0.0, 1.0);
7474

75-
cvar_t *con_margin;
76-
cvar_t *con_horizontalPadding;
75+
Cvar::Cvar<float> con_margin("con_margin", "distance between console and screen edges (sides only if negative)", Cvar::NONE, 10);
76+
Cvar::Cvar<float> con_horizontalPadding("con_horizontalPadding", "space between console edges and text (auto if 0)", Cvar::NONE, 0);
7777

78-
cvar_t *con_height;
79-
cvar_t *con_colorAlpha;
80-
cvar_t *con_colorRed;
81-
cvar_t *con_colorBlue;
82-
cvar_t *con_colorGreen;
78+
Cvar::Range<Cvar::Cvar<float>> con_height("con_height", "console height as percent of screen", Cvar::NONE, 55, 1, 100);
79+
Cvar::Range<Cvar::Cvar<float>> con_colorAlpha("con_colorAlpha", "alpha component of console background color", Cvar::NONE, 0.5, 0.0, 1.0);
80+
Cvar::Range<Cvar::Cvar<float>> con_colorRed("con_colorRed", "red component of console background color", Cvar::NONE, 0, 0.0, 1.0);
81+
Cvar::Range<Cvar::Cvar<float>> con_colorBlue("con_colorBlue", "blue component of console background color", Cvar::NONE, 0.3, 0.0, 1.0);
82+
Cvar::Range<Cvar::Cvar<float>> con_colorGreen("con_colorGreen", "green component of console background color", Cvar::NONE, 0.18, 0.0, 1.0);
8383

8484
/**
8585
* allows for debugging the console without using the consoles scrollback,
@@ -394,21 +394,6 @@ Con_Init
394394
void Con_Init()
395395
{
396396

397-
con_height = Cvar_Get( "con_height", "55", 0 );
398-
con_colorRed = Cvar_Get( "con_colorRed", "0", 0 );
399-
con_colorBlue = Cvar_Get( "con_colorBlue", "0.3", 0 );
400-
con_colorGreen = Cvar_Get( "con_colorGreen", "0.18", 0 );
401-
con_colorAlpha = Cvar_Get( "con_colorAlpha", "0.5", 0 );
402-
403-
con_margin = Cvar_Get( "con_margin", "10", 0 );
404-
con_horizontalPadding = Cvar_Get( "con_horizontalPadding", "0", 0 );
405-
406-
con_borderWidth = Cvar_Get( "con_borderWidth", "1", 0 );
407-
con_borderColorRed = Cvar_Get( "con_borderColorRed", "1", 0 );
408-
con_borderColorBlue = Cvar_Get( "con_borderColorBlue", "1", 0 );
409-
con_borderColorGreen = Cvar_Get( "con_borderColorGreen", "1", 0 );
410-
con_borderColorAlpha = Cvar_Get( "con_borderColorAlpha", "0.2", 0 );
411-
412397
// Done defining cvars for console colors
413398

414399
if ( !con_persistOnMapChange.Get() ) {
@@ -585,23 +570,23 @@ void Con_DrawBackground()
585570

586571
// draw the background
587572
Color::Color color (
588-
con_colorRed->value,
589-
con_colorGreen->value,
590-
con_colorBlue->value,
591-
con_colorAlpha->value * consoleState.currentAlphaFactor
573+
con_colorRed.Get(),
574+
con_colorGreen.Get(),
575+
con_colorBlue.Get(),
576+
con_colorAlpha.Get() * consoleState.currentAlphaFactor
592577
);
593578

594579
SCR_FillRect( consoleState.margin.sides, consoleState.margin.top, consoleWidth, consoleState.height, color );
595580

596581
// draw the backgrounds borders
597582
Color::Color borderColor (
598-
con_borderColorRed->value,
599-
con_borderColorGreen->value,
600-
con_borderColorBlue->value,
601-
con_borderColorAlpha->value * consoleState.currentAlphaFactor
583+
con_borderColorRed.Get(),
584+
con_borderColorGreen.Get(),
585+
con_borderColorBlue.Get(),
586+
con_borderColorAlpha.Get() * consoleState.currentAlphaFactor
602587
);
603588

604-
if ( con_margin->integer )
589+
if ( con_margin.Get() != 0 )
605590
{
606591
//top border
607592
SCR_FillRect( consoleState.margin.sides - consoleState.border.sides,
@@ -967,15 +952,15 @@ void Con_UpdateConsoleState()
967952
* different widths for horizontal and vertical borders due to different resolution-ratios
968953
* since that isn't as nice looking as with areas
969954
*/
970-
consoleState.border.bottom = std::max( 0, con_borderWidth->integer );
955+
consoleState.border.bottom = std::max( 0, con_borderWidth.Get() );
971956

972-
if(con_margin->value > 0) {
973-
horizontalMargin = con_margin->value;
974-
verticalMargin = con_margin->value;
957+
if(con_margin.Get() > 0) {
958+
horizontalMargin = con_margin.Get();
959+
verticalMargin = con_margin.Get();
975960
consoleState.border.sides = consoleState.border.bottom;
976961
consoleState.border.top = consoleState.border.bottom;
977962
} else {
978-
horizontalMargin = - con_margin->value;
963+
horizontalMargin = - con_margin.Get();
979964
verticalMargin = 0;
980965
consoleState.border.sides = 0;
981966
consoleState.border.top = 0;
@@ -994,9 +979,9 @@ void Con_UpdateConsoleState()
994979
consoleState.padding.bottom = std::max( 3, consoleState.padding.top );
995980

996981
// on wide screens, this will lead to somewhat of a centering of the text
997-
if(con_horizontalPadding->integer)
982+
if(con_horizontalPadding.Get() > 0)
998983
{
999-
float horizontalVidPadding = con_horizontalPadding->value;
984+
float horizontalVidPadding = con_horizontalPadding.Get();
1000985
SCR_AdjustFrom640( &horizontalVidPadding, nullptr, nullptr, nullptr );
1001986
consoleState.padding.sides = horizontalVidPadding;
1002987
}
@@ -1014,7 +999,7 @@ void Con_UpdateConsoleState()
1014999
/*
10151000
* calculate current console height
10161001
*/
1017-
consoleState.height = con_height->integer * 0.01f * (cls.windowConfig.vidHeight
1002+
consoleState.height = con_height.Get() * 0.01f * (cls.windowConfig.vidHeight
10181003
- consoleState.margin.top - consoleState.margin.bottom
10191004
- consoleState.border.top - consoleState.border.bottom
10201005
);
@@ -1058,30 +1043,25 @@ void Con_RunAnimatedConsole()
10581043
{
10591044
int consoleVidWidth;
10601045

1061-
if (con_height->value > 100.0f || con_height->value < 1.0f )
1062-
{
1063-
Cvar_Reset(con_height->name);
1064-
}
1065-
10661046
Con_UpdateConsoleState( );
10671047

10681048
//now check everything that is depending on the consolestate
1069-
if (con_height->value < con_margin->value || ( consoleState.visibleAmountOfLines < 1 && consoleState.currentAnimationFraction == 1.0f ) )
1049+
if (con_height.Get() < con_margin.Get() || ( consoleState.visibleAmountOfLines < 1 && consoleState.currentAnimationFraction == 1.0f ) )
10701050
{
1071-
Cvar_Reset(con_height->name);
1072-
Cvar_Reset(con_margin->name);
1051+
con_height.Reset();
1052+
con_margin.Reset();
10731053
Con_UpdateConsoleState( ); //recalculate
10741054
}
10751055

10761056
consoleVidWidth = cls.windowConfig.vidWidth - 2 * (consoleState.margin.sides + consoleState.padding.sides );
10771057

1078-
if( 2 * con_horizontalPadding->value >= consoleVidWidth )
1058+
if( 2 * con_horizontalPadding.Get() >= consoleVidWidth )
10791059
{
1080-
Cvar_Reset(con_horizontalPadding->name);
1060+
con_horizontalPadding.Reset();
10811061

10821062
//to be sure, its not the caus of this happening and resulting in a loop
1083-
Cvar_Reset(con_borderWidth->name);
1084-
Cvar_Reset(con_margin->name);
1063+
con_borderWidth.Reset();
1064+
con_margin.Reset();
10851065
Con_UpdateConsoleState( ); //recalculate
10861066
}
10871067

0 commit comments

Comments
 (0)