Patch from wjp. Fix keyboard input.
svn-id: r17592
This commit is contained in:
parent
0f3ab2206a
commit
07ed5e40a5
2 changed files with 64 additions and 20 deletions
21
gob/game.cpp
21
gob/game.cpp
|
@ -463,6 +463,7 @@ int16 game_checkKeys(int16 *pMouseX, int16 *pMouseY, int16 *pButtons, char handl
|
||||||
|
|
||||||
if (*pButtons == 3)
|
if (*pButtons == 3)
|
||||||
*pButtons = 0;
|
*pButtons = 0;
|
||||||
|
|
||||||
return util_checkKey();
|
return util_checkKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -520,18 +521,28 @@ int16 game_checkCollisions(char handleMouse, int16 deltaTime, int16 *pResId,
|
||||||
draw_blitInvalidated();
|
draw_blitInvalidated();
|
||||||
}
|
}
|
||||||
|
|
||||||
key = game_checkKeys(&inter_mouseX, &inter_mouseY, &game_mouseButtons, handleMouse);
|
// NOTE: the original asm does the below game_checkKeys call
|
||||||
|
// _before_ this check. However, that can cause keypresses to get lost
|
||||||
|
// since there's a return statement in this check.
|
||||||
|
// Additionally, I added a 'deltaTime == -1' check there, since
|
||||||
|
// when this function is called with deltaTime == -1 in game_inputArea,
|
||||||
|
// and the return value is then discarded.
|
||||||
if (deltaTime < 0) {
|
if (deltaTime < 0) {
|
||||||
if (util_getTimeKey() + deltaTime > timeKey) {
|
uint32 curtime = util_getTimeKey();
|
||||||
|
if (deltaTime == -1 || curtime + deltaTime > timeKey) {
|
||||||
if (pResId != 0)
|
if (pResId != 0)
|
||||||
*pResId = 0;
|
*pResId = 0;
|
||||||
|
|
||||||
if (pResIndex != 0)
|
if (pResIndex != 0)
|
||||||
*pResIndex = 0;
|
*pResIndex = 0;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
key = game_checkKeys(&inter_mouseX, &inter_mouseY,
|
||||||
|
&game_mouseButtons, handleMouse);
|
||||||
|
|
||||||
if (handleMouse == 0 && game_mouseButtons != 0) {
|
if (handleMouse == 0 && game_mouseButtons != 0) {
|
||||||
util_waitMouseRelease(0);
|
util_waitMouseRelease(0);
|
||||||
key = 3;
|
key = 3;
|
||||||
|
@ -892,11 +903,15 @@ int16 game_inputArea(int16 xPos, int16 yPos, int16 width, int16 height, int16 ba
|
||||||
util_cutFromStr(str, strlen(str) - 1,
|
util_cutFromStr(str, strlen(str) - 1,
|
||||||
1);
|
1);
|
||||||
|
|
||||||
|
if (key >= 'a' && key <= 'z')
|
||||||
|
key += ('A' - 'a');
|
||||||
|
|
||||||
pos++;
|
pos++;
|
||||||
game_tempStr[0] = key;
|
game_tempStr[0] = key;
|
||||||
game_tempStr[1] = 0;
|
game_tempStr[1] = 0;
|
||||||
|
|
||||||
util_insertStr(game_tempStr, str, pos - 1);
|
util_insertStr(game_tempStr, str, pos - 1);
|
||||||
|
|
||||||
//strupr(str);
|
//strupr(str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
63
gob/util.cpp
63
gob/util.cpp
|
@ -28,17 +28,44 @@
|
||||||
|
|
||||||
namespace Gob {
|
namespace Gob {
|
||||||
|
|
||||||
static int16 _mouseX, _mouseY, _keyPressed, _mouseButtons;
|
static const int kKeyBufSize = 16;
|
||||||
|
|
||||||
|
static int16 _mouseX, _mouseY, _mouseButtons;
|
||||||
|
static int16 _keyBuffer[kKeyBufSize], _keyBufferHead, _keyBufferTail;
|
||||||
|
|
||||||
|
static void addKeyToBuffer(int16 key) {
|
||||||
|
if ((_keyBufferHead + 1) % kKeyBufSize == _keyBufferTail) {
|
||||||
|
warning("key buffer overflow!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_keyBuffer[_keyBufferHead] = key;
|
||||||
|
_keyBufferHead = (_keyBufferHead + 1) % kKeyBufSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool keyBufferEmpty() {
|
||||||
|
return (_keyBufferHead == _keyBufferTail);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool getKeyFromBuffer(int16& key) {
|
||||||
|
if (_keyBufferHead == _keyBufferTail) return false;
|
||||||
|
|
||||||
|
key = _keyBuffer[_keyBufferTail];
|
||||||
|
_keyBufferTail = (_keyBufferTail + 1) % kKeyBufSize;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void util_initInput(void) {
|
void util_initInput(void) {
|
||||||
_mouseX = _mouseY = _keyPressed = _mouseButtons = 0;
|
_mouseX = _mouseY = _mouseButtons = 0;
|
||||||
|
_keyBufferHead = _keyBufferTail = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void util_waitKey(void) {
|
void util_waitKey(void) {
|
||||||
while (_keyPressed) {
|
// FIXME: wrong function name? This functions clears the keyboard buffer.
|
||||||
util_processInput();
|
util_processInput();
|
||||||
g_system->delayMillis(10);
|
_keyBufferHead = _keyBufferTail = 0;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int16 util_translateKey(int16 key) {
|
int16 util_translateKey(int16 key) {
|
||||||
|
@ -71,26 +98,29 @@ int16 util_translateKey(int16 key) {
|
||||||
if (key == keys[i].from)
|
if (key == keys[i].from)
|
||||||
return keys[i].to;
|
return keys[i].to;
|
||||||
|
|
||||||
|
if (key < 32 || key >= 128)
|
||||||
|
return 0;
|
||||||
|
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
int16 util_getKey(void) {
|
int16 util_getKey(void) {
|
||||||
while (!_keyPressed) {
|
int16 key;
|
||||||
|
|
||||||
|
while (!getKeyFromBuffer(key)) {
|
||||||
util_processInput();
|
util_processInput();
|
||||||
|
|
||||||
if (_keyPressed)
|
if (keyBufferEmpty())
|
||||||
break;
|
g_system->delayMillis(10);
|
||||||
|
|
||||||
g_system->delayMillis(10);
|
|
||||||
}
|
}
|
||||||
return util_translateKey(_keyPressed);
|
return util_translateKey(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
int16 util_checkKey(void) {
|
int16 util_checkKey(void) {
|
||||||
int key = _keyPressed;
|
int16 key;
|
||||||
|
|
||||||
if (_keyPressed)
|
if (!getKeyFromBuffer(key))
|
||||||
_keyPressed = 0;
|
key = 0;
|
||||||
|
|
||||||
return util_translateKey(key);
|
return util_translateKey(key);
|
||||||
}
|
}
|
||||||
|
@ -120,10 +150,9 @@ void util_processInput() {
|
||||||
_mouseButtons &= ~2;
|
_mouseButtons &= ~2;
|
||||||
break;
|
break;
|
||||||
case OSystem::EVENT_KEYDOWN:
|
case OSystem::EVENT_KEYDOWN:
|
||||||
_keyPressed = event.kbd.keycode;
|
addKeyToBuffer(event.kbd.keycode);
|
||||||
break;
|
break;
|
||||||
case OSystem::EVENT_KEYUP:
|
case OSystem::EVENT_KEYUP:
|
||||||
_keyPressed = 0;
|
|
||||||
break;
|
break;
|
||||||
case OSystem::EVENT_QUIT:
|
case OSystem::EVENT_QUIT:
|
||||||
g_system->quit();
|
g_system->quit();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue