mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
keyboard input in place instead of global variables magic. (KUDr)
This commit is contained in:
parent
4a986e43d4
commit
3a03b70319
|
@ -282,7 +282,6 @@ VARDEF int32 _additional_cash_required;
|
||||||
|
|
||||||
VARDEF uint32 _decode_parameters[20];
|
VARDEF uint32 _decode_parameters[20];
|
||||||
|
|
||||||
VARDEF uint32 _pressed_key; // Low 8 bits = ASCII, High 16 bits = keycode
|
|
||||||
VARDEF bool _ctrl_pressed; // Is Ctrl pressed?
|
VARDEF bool _ctrl_pressed; // Is Ctrl pressed?
|
||||||
VARDEF bool _shift_pressed; // Is Shift pressed?
|
VARDEF bool _shift_pressed; // Is Shift pressed?
|
||||||
VARDEF byte _dirkeys; // 1 = left, 2 = up, 4 = right, 8 = down
|
VARDEF byte _dirkeys; // 1 = left, 2 = up, 4 = right, 8 = down
|
||||||
|
|
|
@ -347,8 +347,9 @@ static void QZ_KeyEvent(unsigned short keycode, unsigned short unicode, BOOL dow
|
||||||
}
|
}
|
||||||
|
|
||||||
if (down) {
|
if (down) {
|
||||||
_pressed_key = QZ_MapKey(keycode) | unicode;
|
uint32 pressed_key = QZ_MapKey(keycode) | unicode;
|
||||||
DEBUG(driver, 2)("cocoa_v: QZ_KeyEvent: %x (%x), down, mapping: %x", keycode, unicode, _pressed_key);
|
HandleKeypress(pressed_key);
|
||||||
|
DEBUG(driver, 2)("cocoa_v: QZ_KeyEvent: %x (%x), down, mapping: %x", keycode, unicode, pressed_key);
|
||||||
} else {
|
} else {
|
||||||
DEBUG(driver, 2)("cocoa_v: QZ_KeyEvent: %x (%x), up", keycode, unicode);
|
DEBUG(driver, 2)("cocoa_v: QZ_KeyEvent: %x (%x), up", keycode, unicode);
|
||||||
}
|
}
|
||||||
|
|
|
@ -380,9 +380,8 @@ static int PollEvent(void)
|
||||||
(ev.key.keysym.sym == SDLK_RETURN || ev.key.keysym.sym == SDLK_f)) {
|
(ev.key.keysym.sym == SDLK_RETURN || ev.key.keysym.sym == SDLK_f)) {
|
||||||
ToggleFullScreen(!_fullscreen);
|
ToggleFullScreen(!_fullscreen);
|
||||||
} else {
|
} else {
|
||||||
_pressed_key = ConvertSdlKeyIntoMy(&ev.key.keysym);
|
HandleKeypress(ConvertSdlKeyIntoMy(&ev.key.keysym));
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_VIDEORESIZE: {
|
case SDL_VIDEORESIZE: {
|
||||||
|
|
|
@ -346,23 +346,25 @@ static LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP
|
||||||
WORD w = 0;
|
WORD w = 0;
|
||||||
byte ks[256];
|
byte ks[256];
|
||||||
uint scancode;
|
uint scancode;
|
||||||
|
uint32 pressed_key;
|
||||||
|
|
||||||
GetKeyboardState(ks);
|
GetKeyboardState(ks);
|
||||||
if (ToAscii(wParam, 0, ks, &w, 0) == 0) {
|
if (ToAscii(wParam, 0, ks, &w, 0) == 0) {
|
||||||
w = 0; // no translation was possible
|
w = 0; // no translation was possible
|
||||||
}
|
}
|
||||||
|
|
||||||
_pressed_key = w | MapWindowsKey(wParam) << 16;
|
pressed_key = w | MapWindowsKey(wParam) << 16;
|
||||||
|
|
||||||
scancode = GB(lParam, 16, 8);
|
scancode = GB(lParam, 16, 8);
|
||||||
if (scancode == 41) _pressed_key = w | WKC_BACKQUOTE << 16;
|
if (scancode == 41) pressed_key = w | WKC_BACKQUOTE << 16;
|
||||||
|
|
||||||
if ((_pressed_key >> 16) == ('D' | WKC_CTRL) && !_wnd.fullscreen) {
|
if ((pressed_key >> 16) == ('D' | WKC_CTRL) && !_wnd.fullscreen) {
|
||||||
_double_size ^= 1;
|
_double_size ^= 1;
|
||||||
_wnd.double_size = _double_size;
|
_wnd.double_size = _double_size;
|
||||||
ClientSizeChanged(_wnd.width, _wnd.height);
|
ClientSizeChanged(_wnd.width, _wnd.height);
|
||||||
MarkWholeScreenDirty();
|
MarkWholeScreenDirty();
|
||||||
}
|
}
|
||||||
|
HandleKeypress(pressed_key);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -377,11 +379,11 @@ static LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP
|
||||||
return 0; // do nothing
|
return 0; // do nothing
|
||||||
|
|
||||||
case VK_F10: /* F10, ignore activation of menu */
|
case VK_F10: /* F10, ignore activation of menu */
|
||||||
_pressed_key = MapWindowsKey(wParam) << 16;
|
HandleKeypress(MapWindowsKey(wParam) << 16);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
default: /* ALT in combination with something else */
|
default: /* ALT in combination with something else */
|
||||||
_pressed_key = MapWindowsKey(wParam) << 16;
|
HandleKeypress(MapWindowsKey(wParam) << 16);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
22
window.c
22
window.c
|
@ -1397,7 +1397,10 @@ void SendWindowMessageClass(WindowClass wnd_class, uint msg, uint wparam, uint l
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void HandleKeypress(uint32 key)
|
/** Handle keyboard input.
|
||||||
|
* @param key Lower 8 bits contain the ASCII character, the higher
|
||||||
|
* 16 bits the keycode */
|
||||||
|
void HandleKeypress(uint32 key)
|
||||||
{
|
{
|
||||||
Window *w;
|
Window *w;
|
||||||
WindowEvent e;
|
WindowEvent e;
|
||||||
|
@ -1406,6 +1409,17 @@ static void HandleKeypress(uint32 key)
|
||||||
* to thein this main toolbar. */
|
* to thein this main toolbar. */
|
||||||
bool query_open = false;
|
bool query_open = false;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* During the generation of the world, there might be
|
||||||
|
* another thread that is currently building for example
|
||||||
|
* a road. To not interfere with those tasks, we should
|
||||||
|
* NOT change the _current_player here.
|
||||||
|
*
|
||||||
|
* This is not necessary either, as the only events that
|
||||||
|
* can be handled are the 'close application' events
|
||||||
|
*/
|
||||||
|
if (!IsGeneratingWorld()) _current_player = _local_player;
|
||||||
|
|
||||||
// Setup event
|
// Setup event
|
||||||
e.event = WE_KEYPRESS;
|
e.event = WE_KEYPRESS;
|
||||||
e.we.keypress.ascii = key & 0xFF;
|
e.we.keypress.ascii = key & 0xFF;
|
||||||
|
@ -1564,12 +1578,6 @@ void InputLoop(void)
|
||||||
*/
|
*/
|
||||||
if (!IsGeneratingWorld()) _current_player = _local_player;
|
if (!IsGeneratingWorld()) _current_player = _local_player;
|
||||||
|
|
||||||
// Handle pressed keys
|
|
||||||
if (_pressed_key != 0) {
|
|
||||||
HandleKeypress(_pressed_key);
|
|
||||||
_pressed_key = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mouse event?
|
// Mouse event?
|
||||||
click = 0;
|
click = 0;
|
||||||
if (_left_button_down && !_left_button_clicked) {
|
if (_left_button_down && !_left_button_clicked) {
|
||||||
|
|
1
window.h
1
window.h
|
@ -801,6 +801,7 @@ void UnInitWindowSystem(void);
|
||||||
void ResetWindowSystem(void);
|
void ResetWindowSystem(void);
|
||||||
int GetMenuItemIndex(const Window *w, int x, int y);
|
int GetMenuItemIndex(const Window *w, int x, int y);
|
||||||
void InputLoop(void);
|
void InputLoop(void);
|
||||||
|
void HandleKeypress(uint32 key);
|
||||||
void UpdateWindows(void);
|
void UpdateWindows(void);
|
||||||
void InvalidateWidget(const Window *w, byte widget_index);
|
void InvalidateWidget(const Window *w, byte widget_index);
|
||||||
void InvalidateThisWindowData(Window *w);
|
void InvalidateThisWindowData(Window *w);
|
||||||
|
|
Loading…
Reference in New Issue