diff --git a/polymer/eduke32/build/include/baselayer.h b/polymer/eduke32/build/include/baselayer.h index 8efd3e612..cf8bc9a89 100644 --- a/polymer/eduke32/build/include/baselayer.h +++ b/polymer/eduke32/build/include/baselayer.h @@ -127,6 +127,17 @@ const char *getjoyname(int32_t what, int32_t num); // what: 0=axis, 1=button, 2= char bgetchar(void); #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); int32_t initmouse(void); diff --git a/polymer/eduke32/build/src/sdlayer.c b/polymer/eduke32/build/src/sdlayer.c index 781811799..657b36604 100644 --- a/polymer/eduke32/build/src/sdlayer.c +++ b/polymer/eduke32/build/src/sdlayer.c @@ -2027,13 +2027,10 @@ int32_t handleevents(void) { 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)) - { - keyasciififo[keyasciififoend] = code; - keyasciififoend = ((keyasciififoend+1)&(KEYFIFOSIZ-1)); - } + keyascfifo_insert(code); } } 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_BACKSPACE || ev.key.keysym.scancode == SDL_SCANCODE_TAB) && - ((keyasciififoend+1)&(KEYFIFOSIZ-1)) != keyasciififoplc) + !keyascfifo_isfull()) { char keyvalue; switch (ev.key.keysym.scancode) @@ -2059,10 +2056,7 @@ int32_t handleevents(void) default: keyvalue = 0; break; } if (OSD_HandleChar(keyvalue)) - { - keyasciififo[keyasciififoend] = keyvalue; - keyasciififoend = ((keyasciififoend+1)&(KEYFIFOSIZ-1)); - } + keyascfifo_insert(keyvalue); } // printf("got key %d, %d\n",ev.key.keysym.scancode,code); @@ -2150,13 +2144,10 @@ int32_t handleevents(void) # endif if (code != OSD_OSDKey() && ev.key.keysym.unicode != 0 && ev.key.type == SDL_KEYDOWN && (ev.key.keysym.unicode & 0xff80) == 0 && - ((keyasciififoend+1)&(KEYFIFOSIZ-1)) != keyasciififoplc) + !keyascfifo_isfull()) { if (OSD_HandleChar(ev.key.keysym.unicode & 0x7f)) - { - keyasciififo[keyasciififoend] = ev.key.keysym.unicode & 0x7f; - keyasciififoend = ((keyasciififoend+1)&(KEYFIFOSIZ-1)); - } + keyascfifo_insert(ev.key.keysym.unicode & 0x7f); } // hook in the osd