aboutsummaryrefslogtreecommitdiff
path: root/gob
diff options
context:
space:
mode:
authorEugene Sandulenko2005-04-13 20:53:36 +0000
committerEugene Sandulenko2005-04-13 20:53:36 +0000
commit07ed5e40a5ff9e11ee716ff2f7a89104c4949f6f (patch)
tree67774fcd573935636210d8e42ab5f0077dad4317 /gob
parent0f3ab2206ae3ed22ed190fb3e46bbccc54e432bf (diff)
downloadscummvm-rg350-07ed5e40a5ff9e11ee716ff2f7a89104c4949f6f.tar.gz
scummvm-rg350-07ed5e40a5ff9e11ee716ff2f7a89104c4949f6f.tar.bz2
scummvm-rg350-07ed5e40a5ff9e11ee716ff2f7a89104c4949f6f.zip
Patch from wjp. Fix keyboard input.
svn-id: r17592
Diffstat (limited to 'gob')
-rw-r--r--gob/game.cpp21
-rw-r--r--gob/util.cpp63
2 files changed, 64 insertions, 20 deletions
diff --git a/gob/game.cpp b/gob/game.cpp
index 599564eaa4..8c05d4b0ea 100644
--- a/gob/game.cpp
+++ b/gob/game.cpp
@@ -463,6 +463,7 @@ int16 game_checkKeys(int16 *pMouseX, int16 *pMouseY, int16 *pButtons, char handl
if (*pButtons == 3)
*pButtons = 0;
+
return util_checkKey();
}
@@ -520,18 +521,28 @@ int16 game_checkCollisions(char handleMouse, int16 deltaTime, int16 *pResId,
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 (util_getTimeKey() + deltaTime > timeKey) {
+ uint32 curtime = util_getTimeKey();
+ if (deltaTime == -1 || curtime + deltaTime > timeKey) {
if (pResId != 0)
*pResId = 0;
-
+
if (pResIndex != 0)
*pResIndex = 0;
+
return 0;
}
}
+ key = game_checkKeys(&inter_mouseX, &inter_mouseY,
+ &game_mouseButtons, handleMouse);
+
if (handleMouse == 0 && game_mouseButtons != 0) {
util_waitMouseRelease(0);
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,
1);
+ if (key >= 'a' && key <= 'z')
+ key += ('A' - 'a');
+
pos++;
game_tempStr[0] = key;
game_tempStr[1] = 0;
util_insertStr(game_tempStr, str, pos - 1);
+
//strupr(str);
}
}
diff --git a/gob/util.cpp b/gob/util.cpp
index be69882977..d0410d1649 100644
--- a/gob/util.cpp
+++ b/gob/util.cpp
@@ -28,17 +28,44 @@
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) {
- _mouseX = _mouseY = _keyPressed = _mouseButtons = 0;
+ _mouseX = _mouseY = _mouseButtons = 0;
+ _keyBufferHead = _keyBufferTail = 0;
}
void util_waitKey(void) {
- while (_keyPressed) {
- util_processInput();
- g_system->delayMillis(10);
- }
+ // FIXME: wrong function name? This functions clears the keyboard buffer.
+ util_processInput();
+ _keyBufferHead = _keyBufferTail = 0;
}
int16 util_translateKey(int16 key) {
@@ -71,26 +98,29 @@ int16 util_translateKey(int16 key) {
if (key == keys[i].from)
return keys[i].to;
+ if (key < 32 || key >= 128)
+ return 0;
+
return key;
}
int16 util_getKey(void) {
- while (!_keyPressed) {
- util_processInput();
+ int16 key;
- if (_keyPressed)
- break;
+ while (!getKeyFromBuffer(key)) {
+ util_processInput();
- g_system->delayMillis(10);
+ if (keyBufferEmpty())
+ g_system->delayMillis(10);
}
- return util_translateKey(_keyPressed);
+ return util_translateKey(key);
}
int16 util_checkKey(void) {
- int key = _keyPressed;
+ int16 key;
- if (_keyPressed)
- _keyPressed = 0;
+ if (!getKeyFromBuffer(key))
+ key = 0;
return util_translateKey(key);
}
@@ -120,10 +150,9 @@ void util_processInput() {
_mouseButtons &= ~2;
break;
case OSystem::EVENT_KEYDOWN:
- _keyPressed = event.kbd.keycode;
+ addKeyToBuffer(event.kbd.keycode);
break;
case OSystem::EVENT_KEYUP:
- _keyPressed = 0;
break;
case OSystem::EVENT_QUIT:
g_system->quit();