Merge branch 'console_sanity' into 'master'

Console Sanity

Closes #517

See merge request KartKrew/Kart!1344
This commit is contained in:
James R 2023-07-19 22:17:10 +00:00
commit 7c3d3282f0
6 changed files with 102 additions and 106 deletions

View file

@ -78,6 +78,7 @@ CV_PossibleValue_t CV_OnOff[] = {{0, "Off"}, {1, "On"}, {0, NULL}};
CV_PossibleValue_t CV_YesNo[] = {{0, "No"}, {1, "Yes"}, {0, NULL}}; CV_PossibleValue_t CV_YesNo[] = {{0, "No"}, {1, "Yes"}, {0, NULL}};
CV_PossibleValue_t CV_Unsigned[] = {{0, "MIN"}, {999999999, "MAX"}, {0, NULL}}; CV_PossibleValue_t CV_Unsigned[] = {{0, "MIN"}, {999999999, "MAX"}, {0, NULL}};
CV_PossibleValue_t CV_Natural[] = {{1, "MIN"}, {999999999, "MAX"}, {0, NULL}}; CV_PossibleValue_t CV_Natural[] = {{1, "MIN"}, {999999999, "MAX"}, {0, NULL}};
CV_PossibleValue_t CV_TrueFalse[] = {{0, "False"}, {1, "True"}, {0, NULL}};
// Cheats // Cheats
#ifdef DEVELOP #ifdef DEVELOP
@ -909,9 +910,11 @@ static void COM_Help_f(void)
{ {
CONS_Printf(" Possible values:\n"); CONS_Printf(" Possible values:\n");
if (cvar->PossibleValue == CV_YesNo) if (cvar->PossibleValue == CV_YesNo)
CONS_Printf(" Yes or No (On or Off, 1 or 0)\n"); CONS_Printf(" Yes or No (On or Off, True or False, 1 or 0)\n");
else if (cvar->PossibleValue == CV_OnOff) else if (cvar->PossibleValue == CV_OnOff)
CONS_Printf(" On or Off (Yes or No, 1 or 0)\n"); CONS_Printf(" On or Off (Yes or No, True or False, 1 or 0)\n");
else if (cvar->PossibleValue == CV_TrueFalse)
CONS_Printf(" True or False (On or Off, Yes or No, 1 or 0)\n");
else if (cvar->PossibleValue == Color_cons_t || cvar->PossibleValue == Followercolor_cons_t) else if (cvar->PossibleValue == Color_cons_t || cvar->PossibleValue == Followercolor_cons_t)
{ {
boolean follower = (cvar->PossibleValue == Followercolor_cons_t); boolean follower = (cvar->PossibleValue == Followercolor_cons_t);
@ -1565,12 +1568,12 @@ boolean CV_CompleteValue(consvar_t *var, const char **valstrp, INT32 *intval)
goto found; goto found;
} }
// Not found ... but wait, there's hope! // Not found ... but wait, there's hope!
if (var->PossibleValue == CV_OnOff || var->PossibleValue == CV_YesNo) if (var->PossibleValue == CV_OnOff || var->PossibleValue == CV_YesNo || var->PossibleValue == CV_TrueFalse)
{ {
overrideval = -1; overrideval = -1;
if (!stricmp(valstr, "on") || !stricmp(valstr, "yes")) if (!stricmp(valstr, "on") || !stricmp(valstr, "yes") || !stricmp(valstr, "true"))
overrideval = 1; overrideval = 1;
else if (!stricmp(valstr, "off") || !stricmp(valstr, "no")) else if (!stricmp(valstr, "off") || !stricmp(valstr, "no") || !stricmp(valstr, "false"))
overrideval = 0; overrideval = 0;
if (overrideval != -1) if (overrideval != -1)

View file

@ -172,6 +172,7 @@ extern CV_PossibleValue_t CV_OnOff[];
extern CV_PossibleValue_t CV_YesNo[]; extern CV_PossibleValue_t CV_YesNo[];
extern CV_PossibleValue_t CV_Unsigned[]; extern CV_PossibleValue_t CV_Unsigned[];
extern CV_PossibleValue_t CV_Natural[]; extern CV_PossibleValue_t CV_Natural[];
extern CV_PossibleValue_t CV_TrueFalse[];
// SRB2kart // SRB2kart
// the KARTSPEED and KARTGP were previously defined here, but moved to doomstat to avoid circular dependencies // the KARTSPEED and KARTGP were previously defined here, but moved to doomstat to avoid circular dependencies

View file

@ -59,7 +59,7 @@ static boolean con_started = false; // console has been initialised
static boolean con_forcepic = true; // at startup toggle console translucency when first off static boolean con_forcepic = true; // at startup toggle console translucency when first off
boolean con_recalc; // set true when screen size has changed boolean con_recalc; // set true when screen size has changed
static tic_t con_tick; // console ticker for anim or blinking prompt cursor static tic_t con_tick; // console ticker for blinking prompt cursor
// con_scrollup should use time (currenttime - lasttime).. // con_scrollup should use time (currenttime - lasttime)..
static boolean consoletoggle; // true when console key pushed, ticker will handle static boolean consoletoggle; // true when console key pushed, ticker will handle
@ -70,8 +70,8 @@ static INT32 con_curlines; // vid lines currently used by console
INT32 con_clipviewtop; // (useless) INT32 con_clipviewtop; // (useless)
static INT32 con_hudlines; // number of console heads up message lines static UINT8 con_hudlines; // number of console heads up message lines
static INT32 con_hudtime[MAXHUDLINES]; // remaining time of display for hud msg lines static UINT32 con_hudtime[MAXHUDLINES]; // remaining time of display for hud msg lines
INT32 con_clearlines; // top screen lines to refresh when view reduced INT32 con_clearlines; // top screen lines to refresh when view reduced
boolean con_hudupdate; // when messages scroll, we need a backgrnd refresh boolean con_hudupdate; // when messages scroll, we need a backgrnd refresh
@ -108,6 +108,7 @@ static void CON_RecalcSize(void);
static void CON_ChangeHeight(void); static void CON_ChangeHeight(void);
static void CON_DrawBackpic(void); static void CON_DrawBackpic(void);
static void CONS_height_Change(void);
static void CONS_hudlines_Change(void); static void CONS_hudlines_Change(void);
static void CONS_backcolor_Change(void); static void CONS_backcolor_Change(void);
@ -123,10 +124,13 @@ static void CONS_backcolor_Change(void);
static char con_buffer[CON_BUFFERSIZE]; static char con_buffer[CON_BUFFERSIZE];
// how many seconds the hud messages lasts on the screen // how many seconds the hud messages lasts on the screen
static consvar_t cons_msgtimeout = CVAR_INIT ("con_hudtime", "5", CV_SAVE, CV_Unsigned, NULL); // CV_Unsigned can overflow when multiplied by TICRATE later, so let's use a 3-year limit instead
static CV_PossibleValue_t hudtime_cons_t[] = {{0, "MIN"}, {99999999, "MAX"}, {0, NULL}};
static consvar_t cons_hudtime = CVAR_INIT ("con_hudtime", "5", CV_SAVE, hudtime_cons_t, NULL);
// number of lines displayed on the HUD // number of lines displayed on the HUD
static consvar_t cons_hudlines = CVAR_INIT ("con_hudlines", "5", CV_CALL|CV_SAVE, CV_Unsigned, CONS_hudlines_Change); static CV_PossibleValue_t hudlines_cons_t[] = {{0, "MIN"}, {MAXHUDLINES, "MAX"}, {0, NULL}};
static consvar_t cons_hudlines = CVAR_INIT ("con_hudlines", "5", CV_CALL|CV_SAVE, hudlines_cons_t, CONS_hudlines_Change);
// number of lines console move per frame // number of lines console move per frame
// (con_speed needs a limit, apparently) // (con_speed needs a limit, apparently)
@ -134,7 +138,7 @@ static CV_PossibleValue_t speed_cons_t[] = {{0, "MIN"}, {64, "MAX"}, {0, NULL}};
static consvar_t cons_speed = CVAR_INIT ("con_speed", "8", CV_SAVE, speed_cons_t, NULL); static consvar_t cons_speed = CVAR_INIT ("con_speed", "8", CV_SAVE, speed_cons_t, NULL);
// percentage of screen height to use for console // percentage of screen height to use for console
static consvar_t cons_height = CVAR_INIT ("con_height", "50", CV_SAVE, CV_Unsigned, NULL); static consvar_t cons_height = CVAR_INIT ("con_height", "50", CV_CALL|CV_SAVE, CV_Unsigned, CONS_height_Change);
static CV_PossibleValue_t backpic_cons_t[] = {{0, "translucent"}, {1, "picture"}, {0, NULL}}; static CV_PossibleValue_t backpic_cons_t[] = {{0, "translucent"}, {1, "picture"}, {0, NULL}};
// whether to use console background picture, or translucent mode // whether to use console background picture, or translucent mode
@ -152,6 +156,18 @@ consvar_t cons_backcolor = CVAR_INIT ("con_backcolor", "Black", CV_CALL|CV_SAVE,
static void CON_Print(char *msg); static void CON_Print(char *msg);
// Change the console height on demand
//
static void CONS_height_Change(void)
{
Lock_state();
if (con_destlines > 0 && !con_startup) // If the console is open (as in, not using "bind")...
CON_ChangeHeight(); // ...update its height now, not only when it's closed and re-opened
Unlock_state();
}
// //
// //
static void CONS_hudlines_Change(void) static void CONS_hudlines_Change(void)
@ -164,11 +180,6 @@ static void CONS_hudlines_Change(void)
for (i = 0; i < con_hudlines; i++) for (i = 0; i < con_hudlines; i++)
con_hudtime[i] = 0; con_hudtime[i] = 0;
if (cons_hudlines.value < 1)
cons_hudlines.value = 1;
else if (cons_hudlines.value > MAXHUDLINES)
cons_hudlines.value = MAXHUDLINES;
con_hudlines = cons_hudlines.value; con_hudlines = cons_hudlines.value;
Unlock_state(); Unlock_state();
@ -449,7 +460,7 @@ void CON_Init(void)
Unlock_state(); Unlock_state();
CV_RegisterVar(&cons_msgtimeout); CV_RegisterVar(&cons_hudtime);
CV_RegisterVar(&cons_hudlines); CV_RegisterVar(&cons_hudlines);
CV_RegisterVar(&cons_speed); CV_RegisterVar(&cons_speed);
CV_RegisterVar(&cons_height); CV_RegisterVar(&cons_height);
@ -614,33 +625,39 @@ static void CON_ChangeHeight(void)
// //
static void CON_MoveConsole(void) static void CON_MoveConsole(void)
{ {
fixed_t conspeed; static fixed_t fracmovement = 0;
Lock_state(); Lock_state();
conspeed = FixedDiv(cons_speed.value*vid.fdupy, FRACUNIT);
// instant // instant
if (!cons_speed.value) if (!cons_speed.value)
{ {
con_curlines = con_destlines; con_curlines = con_destlines;
Unlock_state();
return; return;
} }
// up/down move to dest // Not instant - Increment fracmovement fractionally
if (con_curlines < con_destlines) fracmovement += FixedMul(cons_speed.value*vid.fdupy, renderdeltatics);
if (con_curlines < con_destlines) // Move the console downwards
{ {
con_curlines += FixedInt(conspeed); con_curlines += FixedInt(fracmovement); // Move by fracmovement's integer value
if (con_curlines > con_destlines) if (con_curlines > con_destlines) // If we surpassed the destination...
con_curlines = con_destlines; con_curlines = con_destlines; // ...clamp to it!
} }
else if (con_curlines > con_destlines) else // Move the console upwards
{ {
con_curlines -= FixedInt(conspeed); con_curlines -= FixedInt(fracmovement);
if (con_curlines < con_destlines) if (con_curlines < con_destlines)
con_curlines = con_destlines; con_curlines = con_destlines;
if (con_destlines == 0) // If the console is being closed, not just moved up...
con_tick = 0; // ...don't show the blinking cursor
} }
fracmovement %= FRACUNIT; // Reset fracmovement's integer value, but keep the fraction
Unlock_state(); Unlock_state();
} }
@ -759,10 +776,6 @@ void CON_Ticker(void)
CON_ChangeHeight(); CON_ChangeHeight();
} }
// console movement
if (con_destlines != con_curlines)
CON_MoveConsole();
// clip the view, so that the part under the console is not drawn // clip the view, so that the part under the console is not drawn
con_clipviewtop = -1; con_clipviewtop = -1;
if (cons_backpic.value) // clip only when using an opaque background if (cons_backpic.value) // clip only when using an opaque background
@ -784,9 +797,8 @@ void CON_Ticker(void)
// make overlay messages disappear after a while // make overlay messages disappear after a while
for (i = 0; i < con_hudlines; i++) for (i = 0; i < con_hudlines; i++)
{ {
con_hudtime[i]--; if (con_hudtime[i])
if (con_hudtime[i] < 0) con_hudtime[i]--;
con_hudtime[i] = 0;
} }
Unlock_state(); Unlock_state();
@ -1334,7 +1346,8 @@ boolean CON_Responder(event_t *ev)
static void CON_Linefeed(void) static void CON_Linefeed(void)
{ {
// set time for heads up messages // set time for heads up messages
con_hudtime[con_cy%con_hudlines] = cons_msgtimeout.value*TICRATE; if (con_hudlines)
con_hudtime[con_cy%con_hudlines] = cons_hudtime.value*TICRATE;
con_cy++; con_cy++;
con_cx = 0; con_cx = 0;
@ -1674,7 +1687,7 @@ static void CON_DrawHudlines(void)
INT32 charwidth = 8 * con_scalefactor; INT32 charwidth = 8 * con_scalefactor;
INT32 charheight = 8 * con_scalefactor; INT32 charheight = 8 * con_scalefactor;
if (con_hudlines <= 0) if (!con_hudlines)
return; return;
if (chat_on && OLDCHAT) if (chat_on && OLDCHAT)
@ -1682,7 +1695,7 @@ static void CON_DrawHudlines(void)
else else
y = 0; y = 0;
for (i = con_cy - con_hudlines+1; i <= con_cy; i++) for (i = con_cy - con_hudlines; i <= con_cy; i++)
{ {
size_t c; size_t c;
INT32 x; INT32 x;
@ -1799,41 +1812,41 @@ static void CON_DrawConsole(void)
} }
// draw console text lines from top to bottom // draw console text lines from top to bottom
if (con_curlines < minheight) if (con_curlines >= minheight)
return;
i = con_cy - con_scrollup;
// skip the last empty line due to the cursor being at the start of a new line
i--;
i -= (con_curlines - minheight) / charheight;
if (rendermode == render_none) return;
for (y = (con_curlines-minheight) % charheight; y <= con_curlines-minheight; y += charheight, i++)
{ {
INT32 x; i = con_cy - con_scrollup;
size_t c;
p = (UINT8 *)&con_buffer[((i > 0 ? i : 0)%con_totallines)*con_width]; // skip the last empty line due to the cursor being at the start of a new line
i--;
for (c = 0, x = charwidth; c < con_width; c++, x += charwidth, p++) i -= (con_curlines - minheight) / charheight;
if (rendermode == render_none) return;
for (y = (con_curlines-minheight) % charheight; y <= con_curlines-minheight; y += charheight, i++)
{ {
while (*p & 0x80) INT32 x;
size_t c;
p = (UINT8 *)&con_buffer[((i > 0 ? i : 0)%con_totallines)*con_width];
for (c = 0, x = charwidth; c < con_width; c++, x += charwidth, p++)
{ {
charflags = (*p & 0x7f) << V_CHARCOLORSHIFT; while (*p & 0x80)
p++; {
c++; charflags = (*p & 0x7f) << V_CHARCOLORSHIFT;
p++;
c++;
}
if (c >= con_width)
break;
V_DrawCharacter(x, y, (INT32)(*p) | charflags | cv_constextsize.value | V_NOSCALESTART, true);
} }
if (c >= con_width)
break;
V_DrawCharacter(x, y, (INT32)(*p) | charflags | cv_constextsize.value | V_NOSCALESTART, true);
} }
} }
// draw prompt if enough place (not while game startup) // draw prompt if enough place (not while game startup)
if ((con_curlines == con_destlines) && (con_curlines >= minheight) && !con_startup) if ((con_curlines >= (minheight-charheight)) && !con_startup)
CON_DrawInput(); CON_DrawInput();
} }
@ -1875,6 +1888,10 @@ void CON_Drawer(void)
CON_ClearHUD(); CON_ClearHUD();
} }
// console movement
if (con_curlines != con_destlines)
CON_MoveConsole();
if (con_curlines > 0) if (con_curlines > 0)
CON_DrawConsole(); CON_DrawConsole();
else if (CON_GamestateDrawHudLines() == true) else if (CON_GamestateDrawHudLines() == true)

View file

@ -430,7 +430,7 @@ static CV_PossibleValue_t kartbot_cons_t[] = {
{13,"Lv.MAX"}, {13,"Lv.MAX"},
{0, NULL} {0, NULL}
}; };
consvar_t cv_kartbot = CVAR_INIT ("bots", "0", CV_NETVAR, kartbot_cons_t, NULL); consvar_t cv_kartbot = CVAR_INIT ("bots", "Off", CV_NETVAR, kartbot_cons_t, NULL);
consvar_t cv_karteliminatelast = CVAR_INIT ("eliminatelast", "Yes", CV_NETVAR|CV_CALL, CV_YesNo, KartEliminateLast_OnChange); consvar_t cv_karteliminatelast = CVAR_INIT ("eliminatelast", "Yes", CV_NETVAR|CV_CALL, CV_YesNo, KartEliminateLast_OnChange);

View file

@ -341,7 +341,7 @@ static int lib_cvRegisterVar(lua_State *L)
} else if (i == 4 || (k && fasticmp(k, "PossibleValue"))) { } else if (i == 4 || (k && fasticmp(k, "PossibleValue"))) {
if (lua_islightuserdata(L, 4)) { if (lua_islightuserdata(L, 4)) {
CV_PossibleValue_t *pv = lua_touserdata(L, 4); CV_PossibleValue_t *pv = lua_touserdata(L, 4);
if (pv == CV_OnOff || pv == CV_YesNo || pv == CV_Unsigned || pv == CV_Natural) if (pv == CV_OnOff || pv == CV_YesNo || pv == CV_Unsigned || pv == CV_Natural || pv == CV_TrueFalse)
cvar->PossibleValue = pv; cvar->PossibleValue = pv;
else else
FIELDERROR("PossibleValue", "CV_PossibleValue_t expected, got unrecognised pointer") FIELDERROR("PossibleValue", "CV_PossibleValue_t expected, got unrecognised pointer")
@ -577,6 +577,8 @@ int LUA_ConsoleLib(lua_State *L)
lua_setglobal(L, "CV_Unsigned"); lua_setglobal(L, "CV_Unsigned");
lua_pushlightuserdata(L, CV_Natural); lua_pushlightuserdata(L, CV_Natural);
lua_setglobal(L, "CV_Natural"); lua_setglobal(L, "CV_Natural");
lua_pushlightuserdata(L, CV_TrueFalse);
lua_setglobal(L, "CV_TrueFalse");
// Set global functions // Set global functions
lua_pushvalue(L, LUA_GLOBALSINDEX); lua_pushvalue(L, LUA_GLOBALSINDEX);

View file

@ -1083,8 +1083,6 @@ void V_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 c)
.done(); .done();
} }
#ifdef HWRENDER
// This is now a function since it's otherwise repeated 2 times and honestly looks retarded:
static UINT32 V_GetHWConsBackColor(void) static UINT32 V_GetHWConsBackColor(void)
{ {
UINT32 hwcolor; UINT32 hwcolor;
@ -1095,26 +1093,25 @@ static UINT32 V_GetHWConsBackColor(void)
case 2: hwcolor = 0xdeb88700; break; // Sepia case 2: hwcolor = 0xdeb88700; break; // Sepia
case 3: hwcolor = 0x40201000; break; // Brown case 3: hwcolor = 0x40201000; break; // Brown
case 4: hwcolor = 0xfa807200; break; // Pink case 4: hwcolor = 0xfa807200; break; // Pink
case 5: hwcolor = 0xff69b400; break; // Raspberry case 5: hwcolor = 0xff000000; break; // Red
case 6: hwcolor = 0xff000000; break; // Red case 6: hwcolor = 0xff800000; break; // Orange
case 7: hwcolor = 0xffd68300; break; // Creamsicle case 7: hwcolor = 0xdaa52000; break; // Gold
case 8: hwcolor = 0xff800000; break; // Orange case 8: hwcolor = 0xffdd0000; break; // Yellow
case 9: hwcolor = 0xdaa52000; break; // Gold case 9: hwcolor = 0xc5e80000; break; // Peridot
case 10: hwcolor = 0x80800000; break; // Yellow case 10: hwcolor = 0x00800000; break; // Green
case 11: hwcolor = 0x00ff0000; break; // Emerald case 11: hwcolor = 0x15f2b000; break; // Aquamarine
case 12: hwcolor = 0x00800000; break; // Green case 12: hwcolor = 0x00ffff00; break; // Cyan
case 13: hwcolor = 0x4080ff00; break; // Cyan case 13: hwcolor = 0x4682b400; break; // Steel
case 14: hwcolor = 0x4682b400; break; // Steel case 14: hwcolor = 0x0000ff00; break; // Blue
case 15: hwcolor = 0x1e90ff00; break; // Periwinkle case 15: hwcolor = 0x9844ff00; break; // Purple
case 16: hwcolor = 0x0000ff00; break; // Blue case 16: hwcolor = 0xff00ff00; break; // Magenta
case 17: hwcolor = 0xff00ff00; break; // Purple case 17: hwcolor = 0xee82ee00; break; // Lavender
case 18: hwcolor = 0xee82ee00; break; // Lavender case 18: hwcolor = 0xf570a500; break; // Rose
// Default green // Default green
default: hwcolor = 0x00800000; break; default: hwcolor = 0x00800000; break;
} }
return hwcolor; return hwcolor;
} }
#endif
// THANK YOU MPC!!! // THANK YOU MPC!!!
// and thanks toaster for cleaning it up. // and thanks toaster for cleaning it up.
@ -1674,31 +1671,7 @@ void V_DrawPromptBack(INT32 boxheight, INT32 color)
if (color == INT32_MAX) if (color == INT32_MAX)
color = cons_backcolor.value; color = cons_backcolor.value;
UINT32 hwcolor; UINT32 hwcolor = V_GetHWConsBackColor();
switch (color)
{
case 0: hwcolor = 0xffffff00; break; // White
case 1: hwcolor = 0x00000000; break; // Black // Note this is different from V_DrawFadeConsBack
case 2: hwcolor = 0xdeb88700; break; // Sepia
case 3: hwcolor = 0x40201000; break; // Brown
case 4: hwcolor = 0xfa807200; break; // Pink
case 5: hwcolor = 0xff69b400; break; // Raspberry
case 6: hwcolor = 0xff000000; break; // Red
case 7: hwcolor = 0xffd68300; break; // Creamsicle
case 8: hwcolor = 0xff800000; break; // Orange
case 9: hwcolor = 0xdaa52000; break; // Gold
case 10: hwcolor = 0x80800000; break; // Yellow
case 11: hwcolor = 0x00ff0000; break; // Emerald
case 12: hwcolor = 0x00800000; break; // Green
case 13: hwcolor = 0x4080ff00; break; // Cyan
case 14: hwcolor = 0x4682b400; break; // Steel
case 15: hwcolor = 0x1e90ff00; break; // Periwinkle
case 16: hwcolor = 0x0000ff00; break; // Blue
case 17: hwcolor = 0xff00ff00; break; // Purple
case 18: hwcolor = 0xee82ee00; break; // Lavender
// Default green
default: hwcolor = 0x00800000; break;
}
#ifdef HWRENDER #ifdef HWRENDER
if (rendermode == render_opengl) if (rendermode == render_opengl)