aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorTorbjörn Andersson2007-03-17 15:44:26 +0000
committerTorbjörn Andersson2007-03-17 15:44:26 +0000
commit53624376b4d614689695d1ea56c1052cd0e7ad12 (patch)
treec98fc0e637f6634d270ae0b6e5311852e3634811 /engines
parente72455c215a1deebe235d18e7efbe55f76d8f2da (diff)
downloadscummvm-rg350-53624376b4d614689695d1ea56c1052cd0e7ad12.tar.gz
scummvm-rg350-53624376b4d614689695d1ea56c1052cd0e7ad12.tar.bz2
scummvm-rg350-53624376b4d614689695d1ea56c1052cd0e7ad12.zip
Applied my re-revised patch #1487149 ("Simplified keyboard repeat"), with
Fingolfin's blessings. Keyboard repeat is now handled by the event manager, rather than by individual engines. Since this can cause problems with some engines (see the AGI engine), the extra "key down" events are marked as "synthetic", so that they can be ignored if necessary. svn-id: r26170
Diffstat (limited to 'engines')
-rw-r--r--engines/agi/agi.cpp24
-rw-r--r--engines/agos/agos.cpp2
-rw-r--r--engines/agos/agos.h2
-rw-r--r--engines/agos/event.cpp12
-rw-r--r--engines/kyra/gui.cpp26
-rw-r--r--engines/kyra/kyra.h8
-rw-r--r--engines/saga/input.cpp3
-rw-r--r--engines/saga/interface.cpp44
-rw-r--r--engines/saga/interface.h10
-rw-r--r--engines/sword1/control.cpp17
-rw-r--r--engines/sword1/control.h2
-rw-r--r--engines/sword2/sword2.cpp17
-rw-r--r--engines/sword2/sword2.h1
13 files changed, 27 insertions, 141 deletions
diff --git a/engines/agi/agi.cpp b/engines/agi/agi.cpp
index c15428e7c5..03b1615e85 100644
--- a/engines/agi/agi.cpp
+++ b/engines/agi/agi.cpp
@@ -113,35 +113,43 @@ void AgiEngine::processEvents() {
switch (key = event.kbd.keycode) {
case 256 + 20: // left arrow
case 260: // key pad 4
- key = KEY_LEFT;
+ if (!event.synthetic)
+ key = KEY_LEFT;
break;
case 256 + 19: // right arrow
case 262: // key pad 6
- key = KEY_RIGHT;
+ if (!event.synthetic)
+ key = KEY_RIGHT;
break;
case 256 + 17: // up arrow
case 264: // key pad 8
- key = KEY_UP;
+ if (!event.synthetic)
+ key = KEY_UP;
break;
case 256 + 18: // down arrow
case 258: // key pad 2
- key = KEY_DOWN;
+ if (!event.synthetic)
+ key = KEY_DOWN;
break;
case 256 + 24: // page up
case 265: // key pad 9
- key = KEY_UP_RIGHT;
+ if (!event.synthetic)
+ key = KEY_UP_RIGHT;
break;
case 256 + 25: // page down
case 259: // key pad 3
- key = KEY_DOWN_RIGHT;
+ if (!event.synthetic)
+ key = KEY_DOWN_RIGHT;
break;
case 256 + 22: // home
case 263: // key pad 7
- key = KEY_UP_LEFT;
+ if (!event.synthetic)
+ key = KEY_UP_LEFT;
break;
case 256 + 23: // end
case 257: // key pad 1
- key = KEY_DOWN_LEFT;
+ if (!event.synthetic)
+ key = KEY_DOWN_LEFT;
break;
case 261: // key pad 5
key = KEY_STATIONARY;
diff --git a/engines/agos/agos.cpp b/engines/agos/agos.cpp
index 851b089020..95727a6a6f 100644
--- a/engines/agos/agos.cpp
+++ b/engines/agos/agos.cpp
@@ -81,8 +81,6 @@ AGOSEngine::AGOSEngine(OSystem *syst)
_debugger = 0;
_keyPressed = 0;
- _keyRepeatKey = 0;
- _keyRepeatTime = 0;
_gameFile = 0;
diff --git a/engines/agos/agos.h b/engines/agos/agos.h
index 1bb2790fab..10fb0ddec5 100644
--- a/engines/agos/agos.h
+++ b/engines/agos/agos.h
@@ -200,8 +200,6 @@ protected:
const GameSpecificSettings *gss;
byte _keyPressed;
- byte _keyRepeatKey;
- uint32 _keyRepeatTime;
typedef enum {
FORMAT_NONE,
diff --git a/engines/agos/event.cpp b/engines/agos/event.cpp
index 7008d9a04e..4d8f8189ed 100644
--- a/engines/agos/event.cpp
+++ b/engines/agos/event.cpp
@@ -375,13 +375,6 @@ void AGOSEngine::delay(uint amount) {
_keyPressed = 8;
else
_keyPressed = (byte)event.kbd.ascii;
-
- _keyRepeatTime = _system->getMillis() + 400;
- _keyRepeatKey = _keyPressed;
- break;
- case OSystem::EVENT_KEYUP:
- _keyRepeatKey = 0;
- _keyRepeatTime = 0;
break;
case OSystem::EVENT_MOUSEMOVE:
_sdlMouseX = event.mouse.x;
@@ -435,11 +428,6 @@ void AGOSEngine::delay(uint amount) {
cur = _system->getMillis();
} while (cur < start + amount);
-
- if (_keyPressed == 0 && _keyRepeatKey != 0 && _keyRepeatTime != 0 && cur >= _keyRepeatTime) {
- _keyPressed = _keyRepeatKey;
- _keyRepeatTime = cur + 100;
- }
}
void AGOSEngine::timer_callback() {
diff --git a/engines/kyra/gui.cpp b/engines/kyra/gui.cpp
index 0ca9fd6be2..f68b38eec1 100644
--- a/engines/kyra/gui.cpp
+++ b/engines/kyra/gui.cpp
@@ -597,8 +597,7 @@ int KyraEngine::buttonMenuCallback(Button *caller) {
calcCoords(_menu[i]);
_menuRestoreScreen = true;
- _keyboardEvent.pending = 0;
- _keyboardEvent.repeat = 0;
+ _keyPressed = 0;
_mousePressFlag = false;
_toplevelMenu = 0;
@@ -835,12 +834,7 @@ void KyraEngine::gui_getInput() {
_mouseWheel = 1;
break;
case OSystem::EVENT_KEYDOWN:
- _keyboardEvent.pending = true;
- _keyboardEvent.repeat = now + 400;
- _keyboardEvent.ascii = event.kbd.ascii;
- break;
- case OSystem::EVENT_KEYUP:
- _keyboardEvent.repeat = 0;
+ _keyPressed = event.kbd.ascii;
break;
default:
break;
@@ -852,10 +846,6 @@ void KyraEngine::gui_getInput() {
lastScreenUpdate = now;
}
- if (!_keyboardEvent.pending && _keyboardEvent.repeat && now >= _keyboardEvent.repeat) {
- _keyboardEvent.pending = true;
- _keyboardEvent.repeat = now + 100;
- }
_system->delayMillis(3);
}
@@ -1020,26 +1010,26 @@ void KyraEngine::gui_redrawTextfield() {
void KyraEngine::gui_updateSavegameString() {
int length;
- if (_keyboardEvent.pending && _keyboardEvent.ascii) {
+ if (_keyPressed) {
length = strlen(_savegameName);
- if (_keyboardEvent.ascii > 31 && _keyboardEvent.ascii < 127) {
+ if (_keyPressed > 31 && _keyPressed < 127) {
if (length < 31) {
- _savegameName[length] = _keyboardEvent.ascii;
+ _savegameName[length] = _keyPressed;
_savegameName[length+1] = 0;
gui_redrawTextfield();
}
- } else if (_keyboardEvent.ascii == 8 ||_keyboardEvent.ascii == 127) {
+ } else if (_keyPressed == 8 ||_keyPressed == 127) {
if (length > 0) {
_savegameName[length-1] = 0;
gui_redrawTextfield();
}
- } else if (_keyboardEvent.ascii == 13) {
+ } else if (_keyPressed == 13) {
_displaySubMenu = false;
}
}
- _keyboardEvent.pending = false;
+ _keyPressed = 0;
}
int KyraEngine::gui_saveGame(Button *button) {
diff --git a/engines/kyra/kyra.h b/engines/kyra/kyra.h
index 6722f84f51..21d32988ef 100644
--- a/engines/kyra/kyra.h
+++ b/engines/kyra/kyra.h
@@ -227,12 +227,6 @@ struct Menu {
MenuItem item[6];
};
-struct KeyboardEvent {
- bool pending;
- uint32 repeat;
- uint8 ascii;
-};
-
class KyraEngine : public Engine {
friend class MusicPlayer;
friend class Debugger;
@@ -839,7 +833,7 @@ protected:
int _gameToLoad;
char _savegameName[31];
const char *_specialSavegameString;
- KeyboardEvent _keyboardEvent;
+ uint8 _keyPressed;
struct KyragemState {
uint16 nextOperation;
diff --git a/engines/saga/input.cpp b/engines/saga/input.cpp
index ae14a43b9b..fdac5c2fc0 100644
--- a/engines/saga/input.cpp
+++ b/engines/saga/input.cpp
@@ -121,9 +121,6 @@ int SagaEngine::processInput() {
break;
}
break;
- case OSystem::EVENT_KEYUP:
- _interface->processKeyUp(event.kbd.ascii);
- break;
case OSystem::EVENT_LBUTTONUP:
_leftMouseButtonPressed = false;
break;
diff --git a/engines/saga/interface.cpp b/engines/saga/interface.cpp
index 0ff1396a49..7c37126d59 100644
--- a/engines/saga/interface.cpp
+++ b/engines/saga/interface.cpp
@@ -212,7 +212,6 @@ Interface::Interface(SagaEngine *vm) : _vm(vm) {
error("Interface::Interface(): not enough memory");
}
- _textInputRepeatPhase = 0;
_textInput = false;
_statusTextInput = false;
_statusTextInputState = kStatusTextInputFirstRun;
@@ -316,7 +315,6 @@ void Interface::setMode(int mode) {
_textInput = true;
_textInputStringLength = strlen(_textInputString);
_textInputPos = _textInputStringLength + 1;
- _textInputRepeatPhase = 0;
break;
case kPanelMap:
mapPanelShow();
@@ -337,14 +335,13 @@ void Interface::setMode(int mode) {
_textInputString[0] = 0;
_textInputStringLength = 0;
_textInputPos = _textInputStringLength + 1;
- _textInputRepeatPhase = 0;
break;
}
draw();
}
-bool Interface::processAscii(uint16 ascii, bool synthetic) {
+bool Interface::processAscii(uint16 ascii) {
// TODO: Checking for Esc and Enter below is a bit hackish, and
// and probably only works with the English version. Maybe we should
// add a flag to the button so it can indicate if it's the default or
@@ -352,8 +349,6 @@ bool Interface::processAscii(uint16 ascii, bool synthetic) {
int i;
PanelButton *panelButton;
- if (!synthetic)
- _textInputRepeatPhase = 0;
if (_statusTextInput) {
processStatusTextInput(ascii);
return true;
@@ -536,40 +531,6 @@ bool Interface::processAscii(uint16 ascii, bool synthetic) {
return false;
}
-#define KEYBOARD_REPEAT_DELAY1 300000L
-#define KEYBOARD_REPEAT_DELAY2 50000L
-
-void Interface::textInputRepeatCallback(void *refCon) {
- ((Interface *)refCon)->textInputRepeat();
-}
-
-void Interface::textInputStartRepeat(uint16 ascii) {
- if (!_textInputRepeatPhase) {
- _textInputRepeatPhase = 1;
- _vm->_timer->removeTimerProc(&textInputRepeatCallback);
- _vm->_timer->installTimerProc(&textInputRepeatCallback, KEYBOARD_REPEAT_DELAY1, this);
- }
-
- _textInputRepeatChar = ascii;
-}
-
-void Interface::textInputRepeat() {
- if (_textInputRepeatPhase == 1) {
- _textInputRepeatPhase = 2;
- _vm->_timer->removeTimerProc(&textInputRepeatCallback);
- _vm->_timer->installTimerProc(&textInputRepeatCallback, KEYBOARD_REPEAT_DELAY2, this);
- } else if (_textInputRepeatPhase == 2) {
- processAscii(_textInputRepeatChar, true);
- }
-}
-
-void Interface::processKeyUp(uint16 ascii) {
- if (_textInputRepeatPhase) {
- _vm->_timer->removeTimerProc(&textInputRepeatCallback);
- _textInputRepeatPhase = 0;
- }
-}
-
void Interface::setStatusText(const char *text, int statusColor) {
assert(text != NULL);
assert(strlen(text) < STATUS_TEXT_LEN);
@@ -928,7 +889,6 @@ void Interface::setLoad(PanelButton *panelButton) {
void Interface::processStatusTextInput(uint16 ascii) {
- textInputStartRepeat(ascii);
switch (ascii) {
case 27: // esc
_statusTextInputState = kStatusTextInputAborted;
@@ -968,8 +928,6 @@ bool Interface::processTextInput(uint16 ascii) {
memset(tempString, 0, SAVE_TITLE_SIZE);
ch[1] = 0;
- textInputStartRepeat(ascii);
-
switch (ascii) {
case 13:
return false;
diff --git a/engines/saga/interface.h b/engines/saga/interface.h
index 5f8f0f61e3..6dfaaa4984 100644
--- a/engines/saga/interface.h
+++ b/engines/saga/interface.h
@@ -222,8 +222,7 @@ public:
void drawStatusBar();
void setVerbState(int verb, int state);
- bool processAscii(uint16 ascii, bool synthetic = false);
- void processKeyUp(uint16 ascii);
+ bool processAscii(uint16 ascii);
void keyBoss();
void keyBossExit();
@@ -243,8 +242,6 @@ public:
}
private:
- static void textInputRepeatCallback(void *refCon);
-
void drawInventory(Surface *backBuffer);
void updateInventory(int pos);
void inventoryChangePos(int chg);
@@ -343,8 +340,6 @@ private:
void calcOptionSaveSlider();
bool processTextInput(uint16 ascii);
void processStatusTextInput(uint16 ascii);
- void textInputStartRepeat(uint16 ascii);
- void textInputRepeat(void);
public:
void converseInit(void);
@@ -452,9 +447,6 @@ private:
uint _statusTextInputPos;
- int _textInputRepeatPhase;
- uint16 _textInputRepeatChar;
-
PalEntry _mapSavedPal[PAL_ENTRIES];
bool _mapPanelCrossHairState;
diff --git a/engines/sword1/control.cpp b/engines/sword1/control.cpp
index 9a4b2fe46a..ec612ce1fc 100644
--- a/engines/sword1/control.cpp
+++ b/engines/sword1/control.cpp
@@ -42,11 +42,6 @@
namespace Sword1 {
-enum {
- kKeyRepeatInitialDelay = 400,
- kKeyRepeatSustainDelay = 100
-};
-
enum LangStrings {
STR_PAUSED = 0,
STR_INSERT_CD_A,
@@ -171,8 +166,6 @@ Control::Control(Common::SaveFileManager *saveFileMan, ResMan *pResMan, ObjectMa
_music = pMusic;
_sound = pSound;
_lStrings = _languageStrings + SwordEngine::_systemVars.language * 20;
- _keyRepeat = 0;
- _keyRepeatTime = 0;
_selectedButton = 255;
}
@@ -1053,15 +1046,9 @@ void Control::delay(uint32 msecs) {
_keyPressed = 8;
else
_keyPressed = (byte)event.kbd.ascii;
- _keyRepeatTime = now + kKeyRepeatInitialDelay;
- _keyRepeat = _keyPressed;
// we skip the rest of the delay and return immediately
// to handle keyboard input
return;
- case OSystem::EVENT_KEYUP:
- _keyRepeatTime = 0;
- _keyRepeat = 0;
- break;
case OSystem::EVENT_MOUSEMOVE:
_mouseX = event.mouse.x;
_mouseY = event.mouse.y;
@@ -1093,10 +1080,6 @@ void Control::delay(uint32 msecs) {
break;
}
}
- if (_keyRepeatTime && now > _keyRepeatTime) {
- _keyRepeatTime += kKeyRepeatSustainDelay;
- _keyPressed = _keyRepeat;
- }
_system->updateScreen();
_system->delayMillis(10);
diff --git a/engines/sword1/control.h b/engines/sword1/control.h
index 686783012a..8cacbfb0b8 100644
--- a/engines/sword1/control.h
+++ b/engines/sword1/control.h
@@ -139,8 +139,6 @@ private:
uint8 *_font, *_redFont;
uint8 *_screenBuf;
uint8 _keyPressed;
- uint8 _keyRepeat;
- uint32 _keyRepeatTime;
void delay(uint32 msecs);
uint16 _mouseX, _mouseY, _mouseState;
bool _mouseDown;
diff --git a/engines/sword2/sword2.cpp b/engines/sword2/sword2.cpp
index d04cdadfa2..3e313fcdcc 100644
--- a/engines/sword2/sword2.cpp
+++ b/engines/sword2/sword2.cpp
@@ -187,7 +187,6 @@ Sword2Engine::Sword2Engine(OSystem *syst) : Engine(syst) {
_debugger = NULL;
_keyboardEvent.pending = false;
- _keyboardEvent.repeat = 0;
_mouseEvent.pending = false;
_wantSfxDebug = false;
@@ -377,10 +376,6 @@ int Sword2Engine::go() {
if (ke) {
if ((ke->modifiers == OSystem::KBD_CTRL && ke->keycode == 'd') || ke->ascii == '#' || ke->ascii == '~') {
- // HACK: We have to clear the 'repeat' flag, or
- // it will probably trigger a keyboard repeat
- // immediately after the debug console closes.
- _keyboardEvent.repeat = 0;
_debugger->attach();
} else if (ke->modifiers == 0 || ke->modifiers == OSystem::KBD_SHIFT) {
switch (ke->keycode) {
@@ -539,8 +534,6 @@ uint32 Sword2Engine::setInputEventFilter(uint32 filter) {
void Sword2Engine::parseInputEvents() {
OSystem::Event event;
- uint32 now = _system->getMillis();
-
Common::EventManager *eventMan = _system->getEventManager();
while (eventMan->pollEvent(event)) {
switch (event.type) {
@@ -555,15 +548,11 @@ void Sword2Engine::parseInputEvents() {
}
if (!(_inputEventFilter & RD_KEYDOWN)) {
_keyboardEvent.pending = true;
- _keyboardEvent.repeat = now + 400;
_keyboardEvent.ascii = event.kbd.ascii;
_keyboardEvent.keycode = event.kbd.keycode;
_keyboardEvent.modifiers = event.kbd.flags;
}
break;
- case OSystem::EVENT_KEYUP:
- _keyboardEvent.repeat = 0;
- break;
case OSystem::EVENT_MOUSEMOVE:
if (!(_inputEventFilter & RD_KEYDOWN)) {
_mouse->setPos(event.mouse.x, event.mouse.y - MENUDEEP);
@@ -612,12 +601,6 @@ void Sword2Engine::parseInputEvents() {
break;
}
}
-
- // Handle keyboard auto-repeat
- if (!_keyboardEvent.pending && _keyboardEvent.repeat && now >= _keyboardEvent.repeat) {
- _keyboardEvent.pending = true;
- _keyboardEvent.repeat = now + 100;
- }
}
void Sword2Engine::gameCycle() {
diff --git a/engines/sword2/sword2.h b/engines/sword2/sword2.h
index 3acdce0eeb..c3fc99268d 100644
--- a/engines/sword2/sword2.h
+++ b/engines/sword2/sword2.h
@@ -74,7 +74,6 @@ struct MouseEvent {
struct KeyboardEvent {
bool pending;
- uint32 repeat;
uint16 ascii;
int keycode;
int modifiers;