Skip to content

Commit 6eb0c7d

Browse files
committed
review key repeating again
In build.c's original keyhandler(), the single-interrupt keys were repeat-suppressed and double-interrupt keys (e.g. arrow keys) were not. My change to make all keys non-repeating in b7633cf means the editor file selector and tile chooser would not repeat the arrow keys when navigating. This change isn't exactly like the DOS behaviour in that keystatus[] remains non-repeating and reflects the pressed-or-not state (unless the game modifies the key), but repeating is added to keyfifo[] (and releases also reported), and build.c is adapted to read from the fifo. And any of the keys in those cases will repeat whether they used to or not.
1 parent 8b24c04 commit 6eb0c7d

File tree

3 files changed

+45
-49
lines changed

3 files changed

+45
-49
lines changed

src/build.c

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2470,7 +2470,8 @@ int gettile(int tilenum)
24702470
topleft = ((tilenum/(xtiles<<gettilezoom))*(xtiles<<gettilezoom))-(xtiles<<gettilezoom);
24712471
if (topleft < 0) topleft = 0;
24722472
if (topleft > MAXTILES-(tottiles<<(gettilezoom<<1))) topleft = MAXTILES-(tottiles<<(gettilezoom<<1));
2473-
while ((keystatus[0x1c]|keystatus[1]) == 0)
2473+
bflushkeys();
2474+
while (1)
24742475
{
24752476
drawtilescreen(topleft,tilenum);
24762477
OSD_Draw();
@@ -2479,47 +2480,49 @@ int gettile(int tilenum)
24792480
if (handleevents()) {
24802481
if (quitevent) quitevent = 0;
24812482
}
2483+
ch = bgetkey();
2484+
if (ch == 0x1c || ch == 0x1) break;
24822485

24832486
synctics = totalclock-lockclock;
24842487
lockclock += synctics;
24852488

2486-
if ((keystatus[0x37] > 0) && (gettilezoom < 2))
2489+
if ((ch == 0x37) && (gettilezoom < 2))
24872490
{
24882491
gettilezoom++;
24892492
topleft = ((tilenum/(xtiles<<gettilezoom))*(xtiles<<gettilezoom))-(xtiles<<gettilezoom);
24902493
if (topleft < 0) topleft = 0;
24912494
if (topleft > MAXTILES-(tottiles<<(gettilezoom<<1))) topleft = MAXTILES-(tottiles<<(gettilezoom<<1));
24922495
keystatus[0x37] = 0;
24932496
}
2494-
if ((keystatus[0xb5] > 0) && (gettilezoom > 0))
2497+
if ((ch == 0xb5) && (gettilezoom > 0))
24952498
{
24962499
gettilezoom--;
24972500
topleft = ((tilenum/(xtiles<<gettilezoom))*(xtiles<<gettilezoom))-(xtiles<<gettilezoom);
24982501
if (topleft < 0) topleft = 0;
24992502
if (topleft > MAXTILES-(tottiles<<(gettilezoom<<1))) topleft = MAXTILES-(tottiles<<(gettilezoom<<1));
25002503
keystatus[0xb5] = 0;
25012504
}
2502-
if ((keystatus[0xcb] > 0) && (tilenum > 0))
2505+
if ((ch == 0xcb) && (tilenum > 0))
25032506
tilenum--, keystatus[0xcb] = 0;
2504-
if ((keystatus[0xcd] > 0) && (tilenum < MAXTILES-1))
2507+
if ((ch == 0xcd) && (tilenum < MAXTILES-1))
25052508
tilenum++, keystatus[0xcd] = 0;
2506-
if ((keystatus[0xc8] > 0) && (tilenum >= (xtiles<<gettilezoom)))
2509+
if ((ch == 0xc8) && (tilenum >= (xtiles<<gettilezoom)))
25072510
tilenum-=(xtiles<<gettilezoom), keystatus[0xc8] = 0;
2508-
if ((keystatus[0xd0] > 0) && (tilenum < MAXTILES-(xtiles<<gettilezoom)))
2511+
if ((ch == 0xd0) && (tilenum < MAXTILES-(xtiles<<gettilezoom)))
25092512
tilenum+=(xtiles<<gettilezoom), keystatus[0xd0] = 0;
2510-
if ((keystatus[0xc9] > 0) && (tilenum >= (xtiles<<gettilezoom)))
2513+
if ((ch == 0xc9) && (tilenum >= (xtiles<<gettilezoom)))
25112514
{
25122515
tilenum-=(tottiles<<(gettilezoom<<1));
25132516
if (tilenum < 0) tilenum = 0;
25142517
keystatus[0xc9] = 0;
25152518
}
2516-
if ((keystatus[0xd1] > 0) && (tilenum < MAXTILES-(xtiles<<gettilezoom)))
2519+
if ((ch == 0xd1) && (tilenum < MAXTILES-(xtiles<<gettilezoom)))
25172520
{
25182521
tilenum+=(tottiles<<(gettilezoom<<1));
25192522
if (tilenum >= MAXTILES) tilenum = MAXTILES-1;
25202523
keystatus[0xd1] = 0;
25212524
}
2522-
if (keystatus[0x2f] > 0) //V
2525+
if (ch == 0x2f) //V
25232526
{
25242527
keystatus[0x2f] = 0;
25252528
if (tilenum < localartlookupnum)
@@ -2530,7 +2533,7 @@ int gettile(int tilenum)
25302533
for(i=0;i<MAXTILES;i++)
25312534
localartlookup[i] = i;
25322535
}
2533-
if (keystatus[0x22] > 0) //G (goto)
2536+
if (ch == 0x22) //G (goto)
25342537
{
25352538
if (tilenum < localartlookupnum) //Automatically press 'V'
25362539
tilenum = localartlookup[tilenum];
@@ -2567,15 +2570,17 @@ int gettile(int tilenum)
25672570
break;
25682571
}
25692572
}
2573+
ch = 0;
25702574
clearkeys();
2575+
bflushkeys();
25712576
}
25722577
while (tilenum < topleft) topleft -= (xtiles<<gettilezoom);
25732578
while (tilenum >= topleft+(tottiles<<(gettilezoom<<1))) topleft += (xtiles<<gettilezoom);
25742579
if (topleft < 0) topleft = 0;
25752580
if (topleft > MAXTILES-(tottiles<<(gettilezoom<<1))) topleft = MAXTILES-(tottiles<<(gettilezoom<<1));
25762581
}
25772582

2578-
if (keystatus[0x1c] == 0)
2583+
if (ch == 0x1)
25792584
{
25802585
tilenum = otilenum;
25812586
}
@@ -6184,8 +6189,8 @@ char *findfilename(char *path)
61846189
int menuselect(int newpathmode)
61856190
{
61866191
int listsize;
6187-
int i;
6188-
char ch, buffer[90];
6192+
int i, ch;
6193+
char buffer[90];
61896194
CACHE1D_FIND_REC *dir;
61906195

61916196
int bakpathsearchmode = pathsearchmode;
@@ -6255,14 +6260,8 @@ int menuselect(int newpathmode)
62556260
}
62566261
showframe();
62576262

6258-
keystatus[0xcb] = 0;
6259-
keystatus[0xcd] = 0;
6260-
keystatus[0xc8] = 0;
6261-
keystatus[0xd0] = 0;
6262-
keystatus[0x1c] = 0; //enter
6263-
keystatus[0xf] = 0; //tab
6264-
keystatus[1] = 0; //esc
6265-
ch = 0; //Interesting fakery of ch = getch()
6263+
bflushkeys();
6264+
ch = 0;
62666265
while (ch == 0)
62676266
{
62686267
if (handleevents()) {
@@ -6271,43 +6270,38 @@ int menuselect(int newpathmode)
62716270
quitevent = 0;
62726271
}
62736272
}
6274-
ch = bgetchar();
6275-
if (keystatus[0xcb] > 0) ch = 9; // left arr
6276-
if (keystatus[0xcd] > 0) ch = 9; // right arr
6277-
if (keystatus[0xc8] > 0) ch = 72; // up arr
6278-
if (keystatus[0xd0] > 0) ch = 80; // down arr
6279-
6273+
ch = bgetkey();
62806274
}
62816275

6282-
if (ch == 'f' || ch == 'F') {
6276+
if (ch == 0x21) { //f
62836277
currentlist = 0;
62846278
pathsearchmode = 1-pathsearchmode;
62856279
if (pathsearchmode == PATHSEARCH_SYSTEM) {
62866280
strcpy(selectedboardfilename, "");
62876281
Bcanonicalisefilename(selectedboardfilename, 1);
62886282
} else strcpy(selectedboardfilename, "/");
62896283
getfilenames(selectedboardfilename, "*.map");
6290-
} else if (ch == 'g' || ch == 'G') {
6284+
} else if (ch == 0x22) { //g
62916285
if (pathsearchmode == PATHSEARCH_GAME) {
62926286
grponlymode = 1-grponlymode;
62936287
getfilenames(selectedboardfilename, "*.map");
62946288
}
6295-
} else if (ch == 9) {
6289+
} else if (ch == 0xf) { //tab
62966290
if ((currentlist == 0 && findfiles) || (currentlist == 1 && finddirs))
62976291
currentlist = 1-currentlist;
6298-
} else if ((ch == 75) || (ch == 72)) {
6292+
} else if ((ch == 0xcb) || (ch == 0xc8) || (ch == 75) || (ch == 72)) { //left,up arrow
62996293
if (currentlist == 0) {
63006294
if (finddirshigh && finddirshigh->prev) finddirshigh = finddirshigh->prev;
63016295
} else {
63026296
if (findfileshigh && findfileshigh->prev) findfileshigh = findfileshigh->prev;
63036297
}
6304-
} else if ((ch == 77) || (ch == 80)) {
6298+
} else if ((ch == 0xcd) || (ch == 0xd0) || (ch == 77) || (ch == 80)) { //right,down arrow
63056299
if (currentlist == 0) {
63066300
if (finddirshigh && finddirshigh->next) finddirshigh = finddirshigh->next;
63076301
} else {
63086302
if (findfileshigh && findfileshigh->next) findfileshigh = findfileshigh->next;
63096303
}
6310-
} else if ((ch == 13) && (currentlist == 0) && finddirshigh) {
6304+
} else if ((ch == 0x1c) && (currentlist == 0) && finddirshigh) { //enter
63116305
if (finddirshigh->type == CACHE1D_FIND_DRIVE) {
63126306
strcpy(selectedboardfilename, finddirshigh->name);
63136307
} else {
@@ -6327,10 +6321,10 @@ int menuselect(int newpathmode)
63276321
clearbuf((unsigned char *)frameplace, (bytesperline*ydim16) >> 2, 0l);
63286322
showframe();
63296323
}
6330-
if (ch == 13 && !findfileshigh) ch = 0;
6324+
if (ch == 0x1c && !findfileshigh) ch = 0;
63316325
}
6332-
while ((ch != 13) && (ch != 27));
6333-
if (ch == 13)
6326+
while ((ch != 0x1c) && (ch != 0x1));
6327+
if (ch == 0x1c)
63346328
{
63356329
Bstrcat(selectedboardfilename, findfileshigh->name);
63366330
//printf("Selected file: %s\n", selectedboardfilename);

src/sdlayer2.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,14 +1314,15 @@ int handleevents(void)
13141314
break;
13151315

13161316
if (ev.key.type == SDL_KEYDOWN) {
1317-
if (!keystatus[code] && !ev.key.repeat) {
1318-
keystatus[code] = 1;
1319-
keyfifo[keyfifoend] = code;
1320-
keyfifo[(keyfifoend+1)&(KEYFIFOSIZ-1)] = 1;
1321-
keyfifoend = ((keyfifoend+2)&(KEYFIFOSIZ-1));
1322-
}
1317+
if (!keystatus[code] && !ev.key.repeat) keystatus[code] = 1;
1318+
keyfifo[keyfifoend] = code;
1319+
keyfifo[(keyfifoend+1)&(KEYFIFOSIZ-1)] = 1;
1320+
keyfifoend = ((keyfifoend+2)&(KEYFIFOSIZ-1));
13231321
} else {
13241322
keystatus[code] = 0;
1323+
keyfifo[keyfifoend] = code;
1324+
keyfifo[(keyfifoend+1)&(KEYFIFOSIZ-1)] = 0;
1325+
keyfifoend = ((keyfifoend+2)&(KEYFIFOSIZ-1));
13251326
}
13261327
break;
13271328

src/winlayer.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,14 +2240,15 @@ static LRESULT CALLBACK WndProcCallback(HWND hWnd, UINT uMsg, WPARAM wParam, LPA
22402240
}
22412241
} else if (OSD_HandleKey(scan, press) != 0) {
22422242
if (press) {
2243-
if (!keystatus[scan] && !held) {
2244-
keystatus[scan] = 1;
2245-
keyfifo[keyfifoend] = scan;
2246-
keyfifo[(keyfifoend+1)&(KEYFIFOSIZ-1)] = 1;
2247-
keyfifoend = ((keyfifoend+2)&(KEYFIFOSIZ-1));
2248-
}
2243+
if (!keystatus[scan] && !held) keystatus[scan] = 1;
2244+
keyfifo[keyfifoend] = scan;
2245+
keyfifo[(keyfifoend+1)&(KEYFIFOSIZ-1)] = 1;
2246+
keyfifoend = ((keyfifoend+2)&(KEYFIFOSIZ-1));
22492247
} else {
22502248
keystatus[scan] = 0;
2249+
keyfifo[keyfifoend] = scan;
2250+
keyfifo[(keyfifoend+1)&(KEYFIFOSIZ-1)] = 0;
2251+
keyfifoend = ((keyfifoend+2)&(KEYFIFOSIZ-1));
22512252
}
22522253
}
22532254
}

0 commit comments

Comments
 (0)