Skip to content

Commit 92f8d91

Browse files
committed
Merged pull request "Sync with Q2PRO: Input things ": #371
2 parents 6d8a013 + f872959 commit 92f8d91

File tree

5 files changed

+131
-80
lines changed

5 files changed

+131
-80
lines changed

src/client/console.c

+68-5
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,8 @@ static void Con_CheckTop(void)
413413
{
414414
int top = con.current - CON_TOTALLINES + 1;
415415

416-
if (top < 1) {
417-
top = 1;
416+
if (top < 0) {
417+
top = 0;
418418
}
419419
if (con.display < top) {
420420
con.display = top;
@@ -713,6 +713,8 @@ static int Con_DrawLine(int v, int row, float alpha)
713713
s += line->ts_len;
714714
w -= line->ts_len;
715715
}
716+
if (w < 1)
717+
return x;
716718

717719
switch (line->color) {
718720
case COLOR_ALT:
@@ -1158,16 +1160,67 @@ static void Con_Paste(char *(*func)(void))
11581160
IF_CharEvent(&con.prompt.inputLine, ' ');
11591161
break;
11601162
default:
1161-
if (Q_isprint(c)) {
1162-
IF_CharEvent(&con.prompt.inputLine, c);
1163+
if (!Q_isprint(c)) {
1164+
c = '?';
11631165
}
1166+
IF_CharEvent(&con.prompt.inputLine, c);
11641167
break;
11651168
}
11661169
}
11671170

11681171
Z_Free(cbd);
11691172
}
11701173

1174+
// console lines are not necessarily NUL-terminated
1175+
static void Con_ClearLine(char *buf, int row)
1176+
{
1177+
consoleLine_t *line = &con.text[row & CON_TOTALLINES_MASK];
1178+
char *s = line->text + line->ts_len;
1179+
int w = con.linewidth - line->ts_len;
1180+
1181+
while (w-- > 0 && *s)
1182+
*buf++ = *s++ & 127;
1183+
*buf = 0;
1184+
}
1185+
1186+
static void Con_SearchUp(void)
1187+
{
1188+
char buf[CON_LINEWIDTH + 1];
1189+
char *s = con.prompt.inputLine.text;
1190+
int top = con.current - CON_TOTALLINES + 1;
1191+
1192+
if (top < 0)
1193+
top = 0;
1194+
1195+
if (!*s)
1196+
return;
1197+
1198+
for (int row = con.display - 1; row >= top; row--) {
1199+
Con_ClearLine(buf, row);
1200+
if (Q_stristr(buf, s)) {
1201+
con.display = row;
1202+
break;
1203+
}
1204+
}
1205+
}
1206+
1207+
static void Con_SearchDown(void)
1208+
{
1209+
char buf[CON_LINEWIDTH + 1];
1210+
char *s = con.prompt.inputLine.text;
1211+
1212+
if (!*s)
1213+
return;
1214+
1215+
for (int row = con.display + 1; row <= con.current; row++) {
1216+
Con_ClearLine(buf, row);
1217+
if (Q_stristr(buf, s)) {
1218+
con.display = row;
1219+
break;
1220+
}
1221+
}
1222+
}
1223+
11711224
/*
11721225
====================
11731226
Key_Console
@@ -1219,6 +1272,16 @@ void Key_Console(int key)
12191272
goto scroll;
12201273
}
12211274

1275+
if (key == K_UPARROW && Key_IsDown(K_CTRL)) {
1276+
Con_SearchUp();
1277+
return;
1278+
}
1279+
1280+
if (key == K_DOWNARROW && Key_IsDown(K_CTRL)) {
1281+
Con_SearchDown();
1282+
return;
1283+
}
1284+
12221285
if (key == K_UPARROW || (key == 'p' && Key_IsDown(K_CTRL))) {
12231286
Prompt_HistoryUp(&con.prompt);
12241287
goto scroll;
@@ -1252,7 +1315,7 @@ void Key_Console(int key)
12521315
}
12531316

12541317
if (key == K_HOME && Key_IsDown(K_CTRL)) {
1255-
con.display = 1;
1318+
con.display = 0;
12561319
Con_CheckTop();
12571320
return;
12581321
}

src/client/input.c

+40-37
Original file line numberDiff line numberDiff line change
@@ -643,50 +643,53 @@ static void m_autosens_changed(cvar_t *self)
643643
autosens_y = 1.0f / V_CalcFov(fov, 4, 3);
644644
}
645645

646+
static const cmdreg_t c_input[] = {
647+
{ "centerview", IN_CenterView },
648+
{ "+moveup", IN_UpDown },
649+
{ "-moveup", IN_UpUp },
650+
{ "+movedown", IN_DownDown },
651+
{ "-movedown", IN_DownUp },
652+
{ "+left", IN_LeftDown },
653+
{ "-left", IN_LeftUp },
654+
{ "+right", IN_RightDown },
655+
{ "-right", IN_RightUp },
656+
{ "+forward", IN_ForwardDown },
657+
{ "-forward", IN_ForwardUp },
658+
{ "+back", IN_BackDown },
659+
{ "-back", IN_BackUp },
660+
{ "+lookup", IN_LookupDown },
661+
{ "-lookup", IN_LookupUp },
662+
{ "+lookdown", IN_LookdownDown },
663+
{ "-lookdown", IN_LookdownUp },
664+
{ "+strafe", IN_StrafeDown },
665+
{ "-strafe", IN_StrafeUp },
666+
{ "+moveleft", IN_MoveleftDown },
667+
{ "-moveleft", IN_MoveleftUp },
668+
{ "+moveright", IN_MoverightDown },
669+
{ "-moveright", IN_MoverightUp },
670+
{ "+speed", IN_SpeedDown },
671+
{ "-speed", IN_SpeedUp },
672+
{ "+attack", IN_AttackDown },
673+
{ "-attack", IN_AttackUp },
674+
{ "+use", IN_UseDown },
675+
{ "-use", IN_UseUp },
676+
{ "impulse", IN_Impulse },
677+
{ "+klook", IN_KLookDown },
678+
{ "-klook", IN_KLookUp },
679+
{ "+mlook", IN_MLookDown },
680+
{ "-mlook", IN_MLookUp },
681+
{ "in_restart", IN_Restart_f },
682+
{ NULL }
683+
};
684+
646685
/*
647686
============
648687
CL_RegisterInput
649688
============
650689
*/
651690
void CL_RegisterInput(void)
652691
{
653-
Cmd_AddCommand("centerview", IN_CenterView);
654-
655-
Cmd_AddCommand("+moveup", IN_UpDown);
656-
Cmd_AddCommand("-moveup", IN_UpUp);
657-
Cmd_AddCommand("+movedown", IN_DownDown);
658-
Cmd_AddCommand("-movedown", IN_DownUp);
659-
Cmd_AddCommand("+left", IN_LeftDown);
660-
Cmd_AddCommand("-left", IN_LeftUp);
661-
Cmd_AddCommand("+right", IN_RightDown);
662-
Cmd_AddCommand("-right", IN_RightUp);
663-
Cmd_AddCommand("+forward", IN_ForwardDown);
664-
Cmd_AddCommand("-forward", IN_ForwardUp);
665-
Cmd_AddCommand("+back", IN_BackDown);
666-
Cmd_AddCommand("-back", IN_BackUp);
667-
Cmd_AddCommand("+lookup", IN_LookupDown);
668-
Cmd_AddCommand("-lookup", IN_LookupUp);
669-
Cmd_AddCommand("+lookdown", IN_LookdownDown);
670-
Cmd_AddCommand("-lookdown", IN_LookdownUp);
671-
Cmd_AddCommand("+strafe", IN_StrafeDown);
672-
Cmd_AddCommand("-strafe", IN_StrafeUp);
673-
Cmd_AddCommand("+moveleft", IN_MoveleftDown);
674-
Cmd_AddCommand("-moveleft", IN_MoveleftUp);
675-
Cmd_AddCommand("+moveright", IN_MoverightDown);
676-
Cmd_AddCommand("-moveright", IN_MoverightUp);
677-
Cmd_AddCommand("+speed", IN_SpeedDown);
678-
Cmd_AddCommand("-speed", IN_SpeedUp);
679-
Cmd_AddCommand("+attack", IN_AttackDown);
680-
Cmd_AddCommand("-attack", IN_AttackUp);
681-
Cmd_AddCommand("+use", IN_UseDown);
682-
Cmd_AddCommand("-use", IN_UseUp);
683-
Cmd_AddCommand("impulse", IN_Impulse);
684-
Cmd_AddCommand("+klook", IN_KLookDown);
685-
Cmd_AddCommand("-klook", IN_KLookUp);
686-
Cmd_AddCommand("+mlook", IN_MLookDown);
687-
Cmd_AddCommand("-mlook", IN_MLookUp);
688-
689-
Cmd_AddCommand("in_restart", IN_Restart_f);
692+
Cmd_Register(c_input);
690693

691694
cl_nodelta = Cvar_Get("cl_nodelta", "0", 0);
692695
cl_maxpackets = Cvar_Get("cl_maxpackets", "30", 0);

src/client/keys.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ void Key_SetDest(keydest_t dest)
192192
IN_Activate();
193193
CL_CheckForPause();
194194
}
195+
196+
if (dest == KEY_GAME) {
197+
anykeydown = 0;
198+
}
195199
}
196200

197201
/*
@@ -664,7 +668,7 @@ void Key_Event(unsigned key, bool down, unsigned time)
664668

665669
if (cls.key_dest == KEY_GAME &&
666670
cl.frame.ps.stats[STAT_LAYOUTS] &&
667-
cls.demo.playback == false) {
671+
!cls.demo.playback) {
668672
if (keydown[key] == 2) {
669673
// force main menu if escape is held
670674
UI_OpenMenu(UIMENU_GAME);
@@ -771,9 +775,6 @@ void Key_Event(unsigned key, bool down, unsigned time)
771775
return;
772776
}
773777

774-
if (cls.key_dest == KEY_GAME)
775-
return;
776-
777778
if (!down) {
778779
if (cls.key_dest & KEY_MENU)
779780
UI_KeyEvent(key, down);

src/client/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2852,7 +2852,7 @@ CL_Activate
28522852
void CL_Activate(active_t active)
28532853
{
28542854
if (cls.active != active) {
2855-
Com_DDDPrintf("%s: %u\n", __func__, active);
2855+
Com_DDPrintf("%s: %u\n", __func__, active);
28562856
cls.active = active;
28572857
cls.disable_screen = 0;
28582858
Key_ClearStates();

src/common/prompt.c

+17-33
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,22 @@ with this program; if not, write to the Free Software Foundation, Inc.,
3030
static cvar_t *com_completion_mode;
3131
static cvar_t *com_completion_treshold;
3232

33-
static void Prompt_ShowMatches(commandPrompt_t *prompt, char **matches,
34-
int start, int end)
33+
static void Prompt_ShowMatches(commandPrompt_t *prompt, char **matches, int count)
3534
{
36-
int count = end - start;
3735
int numCols = 7, numLines;
3836
int i, j, k;
3937
size_t maxlen, len, total;
4038
size_t colwidths[6];
41-
char *match;
4239

4340
// determine number of columns needed
4441
do {
4542
numCols--;
4643
numLines = (count + numCols - 1) / numCols;
4744
total = 0;
4845
for (i = 0; i < numCols; i++) {
49-
k = start + numLines * i;
50-
if (k >= end) {
51-
break;
52-
}
5346
maxlen = 0;
54-
for (j = k; j < k + numLines && j < end; j++) {
47+
k = min((i + 1) * numLines, count);
48+
for (j = i * numLines; j < k; j++) {
5549
len = strlen(matches[j]);
5650
maxlen = max(maxlen, len);
5751
}
@@ -67,19 +61,11 @@ static void Prompt_ShowMatches(commandPrompt_t *prompt, char **matches,
6761

6862
for (i = 0; i < numLines; i++) {
6963
for (j = 0; j < numCols; j++) {
70-
k = start + j * numLines + i;
71-
if (k >= end) {
64+
k = j * numLines + i;
65+
if (k >= count) {
7266
break;
7367
}
74-
match = matches[k];
75-
prompt->printf("%s", match);
76-
len = strlen(match);
77-
if (len < colwidths[j]) {
78-
// pad with spaces
79-
for (k = 0; k < colwidths[j] - len; k++) {
80-
prompt->printf(" ");
81-
}
82-
}
68+
prompt->printf("%*s", -(int)colwidths[j], matches[k]);
8369
}
8470
prompt->printf("\n");
8571
}
@@ -92,36 +78,34 @@ static void Prompt_ShowIndividualMatches(
9278
int numAliases,
9379
int numCvars)
9480
{
95-
int offset = 0;
96-
9781
if (numCommands) {
98-
qsort(matches + offset, numCommands, sizeof(matches[0]), SortStrcmp);
82+
qsort(matches, numCommands, sizeof(matches[0]), SortStrcmp);
9983

10084
prompt->printf("\n%i possible command%s:\n",
10185
numCommands, numCommands != 1 ? "s" : "");
10286

103-
Prompt_ShowMatches(prompt, matches, offset, offset + numCommands);
104-
offset += numCommands;
87+
Prompt_ShowMatches(prompt, matches, numCommands);
88+
matches += numCommands;
10589
}
10690

10791
if (numCvars) {
108-
qsort(matches + offset, numCvars, sizeof(matches[0]), SortStrcmp);
92+
qsort(matches, numCvars, sizeof(matches[0]), SortStrcmp);
10993

11094
prompt->printf("\n%i possible variable%s:\n",
11195
numCvars, numCvars != 1 ? "s" : "");
11296

113-
Prompt_ShowMatches(prompt, matches, offset, offset + numCvars);
114-
offset += numCvars;
97+
Prompt_ShowMatches(prompt, matches, numCvars);
98+
matches += numCvars;
11599
}
116100

117101
if (numAliases) {
118-
qsort(matches + offset, numAliases, sizeof(matches[0]), SortStrcmp);
102+
qsort(matches, numAliases, sizeof(matches[0]), SortStrcmp);
119103

120104
prompt->printf("\n%i possible alias%s:\n",
121105
numAliases, numAliases != 1 ? "es" : "");
122106

123-
Prompt_ShowMatches(prompt, matches, offset, offset + numAliases);
124-
offset += numAliases;
107+
Prompt_ShowMatches(prompt, matches, numAliases);
108+
matches += numAliases;
125109
}
126110
}
127111

@@ -340,7 +324,7 @@ void Prompt_CompleteCommand(commandPrompt_t *prompt, bool backslash)
340324
case 1:
341325
multi:
342326
// print in multiple columns
343-
Prompt_ShowMatches(prompt, sorted, 0, ctx.count);
327+
Prompt_ShowMatches(prompt, sorted, ctx.count);
344328
break;
345329
case 2:
346330
default:
@@ -549,7 +533,7 @@ void Prompt_SaveHistory(commandPrompt_t *prompt, const char *filename, int lines
549533
}
550534
for (; i < prompt->inputLineNum; i++) {
551535
s = prompt->history[i & HISTORY_MASK];
552-
if (s) {
536+
if (s && *s) {
553537
FS_FPrintf(f, "%s\n", s);
554538
}
555539
}

0 commit comments

Comments
 (0)