Fixed race condition and potential b/o in char input
git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2528 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
@@ -35,7 +35,8 @@
|
|||||||
static int kbdhead=0, kbdtail=0;
|
static int kbdhead=0, kbdtail=0;
|
||||||
static wchar_t kbdbuf[KBDBUFSIZE];
|
static wchar_t kbdbuf[KBDBUFSIZE];
|
||||||
static wchar_t lastchar;
|
static wchar_t lastchar;
|
||||||
static int kbdstate[SDLK_LAST];
|
static int kbdstate[SDLK_LAST + 1];
|
||||||
|
// +1 for tracking all yet unknown keys
|
||||||
|
|
||||||
static BOOLEAN InputInitialized = FALSE;
|
static BOOLEAN InputInitialized = FALSE;
|
||||||
|
|
||||||
@@ -315,24 +316,33 @@ ProcessInputEvent (const SDL_Event *Event)
|
|||||||
ProcessMouseEvent (Event);
|
ProcessMouseEvent (Event);
|
||||||
VControl_HandleEvent (Event);
|
VControl_HandleEvent (Event);
|
||||||
|
|
||||||
|
if (Event->type == SDL_KEYDOWN || Event->type == SDL_KEYUP)
|
||||||
{ // process character input event, if any
|
{ // process character input event, if any
|
||||||
SDLKey k = Event->key.keysym.sym;
|
SDLKey k = Event->key.keysym.sym;
|
||||||
wchar_t map_key = Event->key.keysym.unicode;
|
wchar_t map_key = Event->key.keysym.unicode;
|
||||||
|
|
||||||
|
if (k < 0 || k > SDLK_LAST)
|
||||||
|
k = SDLK_LAST; // for unknown keys
|
||||||
|
|
||||||
if (Event->type == SDL_KEYDOWN)
|
if (Event->type == SDL_KEYDOWN)
|
||||||
{
|
{
|
||||||
|
int newtail;
|
||||||
|
|
||||||
// dont care about the non-printable, non-char
|
// dont care about the non-printable, non-char
|
||||||
if (!map_key)
|
if (!map_key)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
kbdstate[k]++;
|
kbdstate[k]++;
|
||||||
ImmediateInputState.menu[KEY_MENU_ANY]++;
|
|
||||||
|
|
||||||
lastchar = map_key;
|
newtail = (kbdtail + 1) & (KBDBUFSIZE - 1);
|
||||||
kbdbuf[kbdtail] = map_key;
|
// ignore the char if the buffer is full
|
||||||
kbdtail = (kbdtail + 1) & (KBDBUFSIZE - 1);
|
if (newtail != kbdhead)
|
||||||
if (kbdtail == kbdhead)
|
{
|
||||||
kbdhead = (kbdhead + 1) & (KBDBUFSIZE - 1);
|
kbdbuf[kbdtail] = map_key;
|
||||||
|
kbdtail = newtail;
|
||||||
|
lastchar = map_key;
|
||||||
|
ImmediateInputState.menu[KEY_MENU_ANY]++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (Event->type == SDL_KEYUP)
|
else if (Event->type == SDL_KEYUP)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user