SDL: factor out 2x repeated code into keyascfifo_{isfull,insert}.

git-svn-id: https://svn.eduke32.com/eduke32@4116 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2013-10-27 21:12:13 +00:00
parent e3157f6c5e
commit 70f0100ac2
2 changed files with 17 additions and 15 deletions

View file

@ -127,6 +127,17 @@ const char *getjoyname(int32_t what, int32_t num); // what: 0=axis, 1=button, 2=
char bgetchar(void); char bgetchar(void);
#define bkbhit() (keyasciififoplc != keyasciififoend) #define bkbhit() (keyasciififoplc != keyasciififoend)
static inline int keyascfifo_isfull(void)
{
return ((keyasciififoend+1)&(KEYFIFOSIZ-1)) == keyasciififoplc;
}
static inline void keyascfifo_insert(char code)
{
keyasciififo[keyasciififoend] = code;
keyasciififoend = ((keyasciififoend+1)&(KEYFIFOSIZ-1));
}
void bflushchars(void); void bflushchars(void);
int32_t initmouse(void); int32_t initmouse(void);

View file

@ -2027,13 +2027,10 @@ int32_t handleevents(void)
{ {
code = ev.text.text[j]; code = ev.text.text[j];
if (code != scantoasc[OSD_OSDKey()] && ((keyasciififoend+1)&(KEYFIFOSIZ-1)) != keyasciififoplc) if (code != scantoasc[OSD_OSDKey()] && !keyascfifo_isfull())
{ {
if (OSD_HandleChar(code)) if (OSD_HandleChar(code))
{ keyascfifo_insert(code);
keyasciififo[keyasciififoend] = code;
keyasciififoend = ((keyasciififoend+1)&(KEYFIFOSIZ-1));
}
} }
} }
while (j < SDL_TEXTINPUTEVENT_TEXT_SIZE && ev.text.text[++j]); while (j < SDL_TEXTINPUTEVENT_TEXT_SIZE && ev.text.text[++j]);
@ -2048,7 +2045,7 @@ int32_t handleevents(void)
ev.key.keysym.scancode == SDL_SCANCODE_KP_ENTER || ev.key.keysym.scancode == SDL_SCANCODE_KP_ENTER ||
ev.key.keysym.scancode == SDL_SCANCODE_BACKSPACE || ev.key.keysym.scancode == SDL_SCANCODE_BACKSPACE ||
ev.key.keysym.scancode == SDL_SCANCODE_TAB) && ev.key.keysym.scancode == SDL_SCANCODE_TAB) &&
((keyasciififoend+1)&(KEYFIFOSIZ-1)) != keyasciififoplc) !keyascfifo_isfull())
{ {
char keyvalue; char keyvalue;
switch (ev.key.keysym.scancode) switch (ev.key.keysym.scancode)
@ -2059,10 +2056,7 @@ int32_t handleevents(void)
default: keyvalue = 0; break; default: keyvalue = 0; break;
} }
if (OSD_HandleChar(keyvalue)) if (OSD_HandleChar(keyvalue))
{ keyascfifo_insert(keyvalue);
keyasciififo[keyasciififoend] = keyvalue;
keyasciififoend = ((keyasciififoend+1)&(KEYFIFOSIZ-1));
}
} }
// printf("got key %d, %d\n",ev.key.keysym.scancode,code); // printf("got key %d, %d\n",ev.key.keysym.scancode,code);
@ -2150,13 +2144,10 @@ int32_t handleevents(void)
# endif # endif
if (code != OSD_OSDKey() && ev.key.keysym.unicode != 0 && ev.key.type == SDL_KEYDOWN && if (code != OSD_OSDKey() && ev.key.keysym.unicode != 0 && ev.key.type == SDL_KEYDOWN &&
(ev.key.keysym.unicode & 0xff80) == 0 && (ev.key.keysym.unicode & 0xff80) == 0 &&
((keyasciififoend+1)&(KEYFIFOSIZ-1)) != keyasciififoplc) !keyascfifo_isfull())
{ {
if (OSD_HandleChar(ev.key.keysym.unicode & 0x7f)) if (OSD_HandleChar(ev.key.keysym.unicode & 0x7f))
{ keyascfifo_insert(ev.key.keysym.unicode & 0x7f);
keyasciififo[keyasciififoend] = ev.key.keysym.unicode & 0x7f;
keyasciififoend = ((keyasciififoend+1)&(KEYFIFOSIZ-1));
}
} }
// hook in the osd // hook in the osd