[Scummvm-cvs-logs] SF.net SVN: scummvm:[35221] scummvm/trunk/engines/drascula

thebluegr at users.sourceforge.net thebluegr at users.sourceforge.net
Wed Dec 3 18:35:38 CET 2008


Revision: 35221
          http://scummvm.svn.sourceforge.net/scummvm/?rev=35221&view=rev
Author:   thebluegr
Date:     2008-12-03 17:35:37 +0000 (Wed, 03 Dec 2008)

Log Message:
-----------
Applied wjpalenstijn's patch to fix bug #2111826 - "DRASCULA: Inserting save game names lags"

Modified Paths:
--------------
    scummvm/trunk/engines/drascula/drascula.cpp
    scummvm/trunk/engines/drascula/drascula.h
    scummvm/trunk/engines/drascula/interface.cpp

Modified: scummvm/trunk/engines/drascula/drascula.cpp
===================================================================
--- scummvm/trunk/engines/drascula/drascula.cpp	2008-12-03 16:44:46 UTC (rev 35220)
+++ scummvm/trunk/engines/drascula/drascula.cpp	2008-12-03 17:35:37 UTC (rev 35221)
@@ -66,6 +66,8 @@
 		_system->openCD(cd_num);
 
 	_lang = kEnglish;
+
+	_keyBufferHead = _keyBufferTail = 0;
 }
 
 DrasculaEngine::~DrasculaEngine() {
@@ -702,10 +704,29 @@
 
 Common::KeyCode DrasculaEngine::getScan() {
 	updateEvents();
+	if (_keyBufferHead == _keyBufferTail) return Common::KEYCODE_INVALID;
 
-	return _keyPressed.keycode;
+	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;
+	}
+
+	_keyBuffer[_keyBufferHead] = key;
+	_keyBufferHead = (_keyBufferHead + 1) % KEYBUFSIZE;
+}
+
+void DrasculaEngine::flushKeyBuffer() {
+	updateEvents();
+	_keyBufferHead = _keyBufferTail = 0;
+}
+
 void DrasculaEngine::updateEvents() {
 	Common::Event event;
 	Common::EventManager *eventMan = _system->getEventManager();
@@ -719,10 +740,9 @@
 #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;

Modified: scummvm/trunk/engines/drascula/drascula.h
===================================================================
--- scummvm/trunk/engines/drascula/drascula.h	2008-12-03 16:44:46 UTC (rev 35220)
+++ scummvm/trunk/engines/drascula/drascula.h	2008-12-03 17:35:37 UTC (rev 35221)
@@ -268,12 +268,12 @@
 #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 @@
 	int leftMouseButton;
 	int rightMouseButton;
 
+	Common::KeyState _keyBuffer[KEYBUFSIZE];
+	int _keyBufferHead;
+	int _keyBufferTail;
+
 	bool loadDrasculaDat();
 
 	bool runCurrentChapter();
@@ -448,6 +452,8 @@
 	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();

Modified: scummvm/trunk/engines/drascula/interface.cpp
===================================================================
--- scummvm/trunk/engines/drascula/interface.cpp	2008-12-03 16:44:46 UTC (rev 35220)
+++ scummvm/trunk/engines/drascula/interface.cpp	2008-12-03 17:35:37 UTC (rev 35221)
@@ -146,7 +146,8 @@
 }
 
 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 @@
 		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)


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list