aboutsummaryrefslogtreecommitdiff
path: root/engines/drascula
diff options
context:
space:
mode:
authorFilippos Karapetis2008-12-03 17:35:37 +0000
committerFilippos Karapetis2008-12-03 17:35:37 +0000
commit157e0512807a77ea13376cedb97274ab3829a68f (patch)
tree8143539be2200ec5a02934ecbfa652c348b22126 /engines/drascula
parentb471aab57d6bfbed72071b6605c1c1231c7315da (diff)
downloadscummvm-rg350-157e0512807a77ea13376cedb97274ab3829a68f.tar.gz
scummvm-rg350-157e0512807a77ea13376cedb97274ab3829a68f.tar.bz2
scummvm-rg350-157e0512807a77ea13376cedb97274ab3829a68f.zip
Applied wjpalenstijn's patch to fix bug #2111826 - "DRASCULA: Inserting save game names lags"
svn-id: r35221
Diffstat (limited to 'engines/drascula')
-rw-r--r--engines/drascula/drascula.cpp26
-rw-r--r--engines/drascula/drascula.h10
-rw-r--r--engines/drascula/interface.cpp16
3 files changed, 34 insertions, 18 deletions
diff --git a/engines/drascula/drascula.cpp b/engines/drascula/drascula.cpp
index 83dc16f8f0..62a758bf9f 100644
--- a/engines/drascula/drascula.cpp
+++ b/engines/drascula/drascula.cpp
@@ -66,6 +66,8 @@ DrasculaEngine::DrasculaEngine(OSystem *syst, const DrasculaGameDescription *gam
_system->openCD(cd_num);
_lang = kEnglish;
+
+ _keyBufferHead = _keyBufferTail = 0;
}
DrasculaEngine::~DrasculaEngine() {
@@ -702,8 +704,27 @@ bool DrasculaEngine::verify2() {
Common::KeyCode DrasculaEngine::getScan() {
updateEvents();
+ if (_keyBufferHead == _keyBufferTail) return Common::KEYCODE_INVALID;
+
+ Common::KeyCode key = _keyBuffer[_keyBufferTail].keycode;
+ _keyBufferTail = (_keyBufferTail + 1) % KEYBUFSIZE;
+
+ return key;
+}
+
+void DrasculaEngine::addKeyToBuffer(Common::KeyState& key) {
+ if ((_keyBufferHead + 1) % KEYBUFSIZE == _keyBufferTail) {
+ warning("key buffer overflow");
+ return;
+ }
- return _keyPressed.keycode;
+ _keyBuffer[_keyBufferHead] = key;
+ _keyBufferHead = (_keyBufferHead + 1) % KEYBUFSIZE;
+}
+
+void DrasculaEngine::flushKeyBuffer() {
+ updateEvents();
+ _keyBufferHead = _keyBufferTail = 0;
}
void DrasculaEngine::updateEvents() {
@@ -719,10 +740,9 @@ void DrasculaEngine::updateEvents() {
#endif
switch (event.type) {
case Common::EVENT_KEYDOWN:
- _keyPressed = event.kbd;
+ addKeyToBuffer(event.kbd);
break;
case Common::EVENT_KEYUP:
- _keyPressed.keycode = Common::KEYCODE_INVALID;
break;
case Common::EVENT_MOUSEMOVE:
mouseX = event.mouse.x;
diff --git a/engines/drascula/drascula.h b/engines/drascula/drascula.h
index a03e5c16da..be9eb697fd 100644
--- a/engines/drascula/drascula.h
+++ b/engines/drascula/drascula.h
@@ -268,12 +268,12 @@ struct CharInfo {
#define COMPLETE_PAL 256
#define HALF_PAL 128
+#define KEYBUFSIZE 16
+
static const int interf_x[] ={ 1, 65, 129, 193, 1, 65, 129 };
static const int interf_y[] ={ 51, 51, 51, 51, 83, 83, 83 };
class DrasculaEngine : public ::Engine {
- Common::KeyState _keyPressed;
-
protected:
// Engine APIs
virtual Common::Error init();
@@ -426,6 +426,10 @@ public:
int leftMouseButton;
int rightMouseButton;
+ Common::KeyState _keyBuffer[KEYBUFSIZE];
+ int _keyBufferHead;
+ int _keyBufferTail;
+
bool loadDrasculaDat();
bool runCurrentChapter();
@@ -448,6 +452,8 @@ public:
bool verify1();
bool verify2();
Common::KeyCode getScan();
+ void addKeyToBuffer(Common::KeyState& key);
+ void flushKeyBuffer();
void selectVerb(int);
void updateVolume(Audio::Mixer::SoundType soundType, int prevVolume);
void volumeControls();
diff --git a/engines/drascula/interface.cpp b/engines/drascula/interface.cpp
index 32f07fce73..8294ddfbad 100644
--- a/engines/drascula/interface.cpp
+++ b/engines/drascula/interface.cpp
@@ -146,7 +146,8 @@ void DrasculaEngine::clearMenu() {
}
void DrasculaEngine::enterName() {
- Common::KeyCode key, prevkey = Common::KEYCODE_INVALID;
+ Common::KeyCode key;
+ flushKeyBuffer();
int counter = 0;
int v = 0, h = 0;
char select2[23];
@@ -156,21 +157,10 @@ void DrasculaEngine::enterName() {
copyBackground(115, 14, 115, 14, 176, 9, bgSurface, screenSurface);
print_abc(select2, 117, 15);
updateScreen();
- _system->delayMillis(100);
key = getScan();
- // Artifically decrease repeat rate.
- // Part of bug fix#2017432 DRASCULA: Typing is slow when you save a game
- // Alternative is to roll our own event loop
- if (key == prevkey)
- if (++counter == 3) {
- counter = 0;
- prevkey = Common::KEYCODE_INVALID;
- }
-
- if (key != 0 && key != prevkey) {
- prevkey = key;
+ if (key != 0) {
if (key >= 0 && key <= 0xFF && isalpha(key))
select2[v] = tolower(key);
else if ((key >= Common::KEYCODE_0 && key <= Common::KEYCODE_9) || key == Common::KEYCODE_SPACE)