|
13 | 13 | #ifndef WM_INPUT |
14 | 14 | #define WM_INPUT 0x00FF |
15 | 15 | #endif |
16 | | -#ifndef WM_QUIT |
17 | | -#define WM_QUIT 0x0012 |
18 | | -#endif |
19 | 16 |
|
20 | | -static const int MAX_MSG_PER_FRAME = 5; |
| 17 | +static const int MAX_MSG_PER_FRAME = 10; |
21 | 18 |
|
22 | 19 | static void QuitPath(); |
23 | 20 | static void SV_Shutdown(char*, int); |
| 21 | +static unsigned* SysMsgTimePtr(); |
| 22 | + |
| 23 | + |
| 24 | +static void DispatchOneMsg(MSG* m, bool from_winmain) { |
| 25 | + if (m->message == WM_QUIT) { |
| 26 | + if (from_winmain) { |
| 27 | + SV_Shutdown(nullptr, 0); |
| 28 | + } |
| 29 | + QuitPath(); |
| 30 | + } |
| 31 | + *SysMsgTimePtr() = static_cast<unsigned>(m->time); |
| 32 | + TranslateMessage(m); |
| 33 | + DispatchMessageA(m); |
| 34 | +} |
24 | 35 |
|
25 | 36 | void PumpWindowMessagesCapped(bool from_winmain) { |
26 | 37 | MSG msg; |
| 38 | + MSG low_msg; |
| 39 | + MSG high_msg; |
27 | 40 | int processed = 0; |
| 41 | + /* WM_INPUT is never removed (avoids high-frequency peel cost). When it sits at |
| 42 | + * the queue head, PeekMessage with ID bands skips it and removes the next matching |
| 43 | + * message. When the head is not WM_INPUT, GetMessage preserves strict FIFO. |
| 44 | + * If both bands have a candidate (WM_INPUT at head, or interleaved), msg.time |
| 45 | + * picks the earlier; tie-break prefers high band (mouse / client-area messages). */ |
28 | 46 | while (processed < MAX_MSG_PER_FRAME && |
29 | | - PeekMessageA(&msg, nullptr, 0, WM_INPUT - 1, PM_REMOVE)) { |
30 | | - if (msg.message == WM_QUIT) { if (from_winmain) SV_Shutdown(nullptr, 0); QuitPath(); } |
31 | | - TranslateMessage(&msg); |
32 | | - DispatchMessageA(&msg); |
33 | | - ++processed; |
34 | | - } |
35 | | - while (processed < MAX_MSG_PER_FRAME && |
36 | | - PeekMessageA(&msg, nullptr, WM_INPUT + 1, 0xFFFFFFFF, PM_REMOVE)) { |
37 | | - if (msg.message == WM_QUIT) { if (from_winmain) SV_Shutdown(nullptr, 0); QuitPath(); } |
38 | | - TranslateMessage(&msg); |
39 | | - DispatchMessageA(&msg); |
| 47 | + PeekMessageA(&msg, nullptr, 0, 0, PM_NOREMOVE)) { |
| 48 | + if (msg.message != WM_INPUT) { |
| 49 | + if (!GetMessageA(&msg, nullptr, 0, 0)) { |
| 50 | + if (from_winmain) { |
| 51 | + SV_Shutdown(nullptr, 0); |
| 52 | + } |
| 53 | + QuitPath(); |
| 54 | + } |
| 55 | + DispatchOneMsg(&msg, from_winmain); |
| 56 | + ++processed; |
| 57 | + continue; |
| 58 | + } |
| 59 | + |
| 60 | + const BOOL has_low = |
| 61 | + PeekMessageA(&low_msg, nullptr, 0, WM_INPUT - 1, PM_NOREMOVE); |
| 62 | + const BOOL has_high = PeekMessageA(&high_msg, nullptr, WM_INPUT + 1, 0xFFFFFFFF, |
| 63 | + PM_NOREMOVE); |
| 64 | + if (!has_low && !has_high) { |
| 65 | + break; |
| 66 | + } |
| 67 | + if (has_low && !has_high) { |
| 68 | + if (!PeekMessageA(&msg, nullptr, 0, WM_INPUT - 1, PM_REMOVE)) { |
| 69 | + break; |
| 70 | + } |
| 71 | + } else if (!has_low && has_high) { |
| 72 | + if (!PeekMessageA(&msg, nullptr, WM_INPUT + 1, 0xFFFFFFFF, PM_REMOVE)) { |
| 73 | + break; |
| 74 | + } |
| 75 | + } else { |
| 76 | + const DWORD t_low = low_msg.time; |
| 77 | + const DWORD t_high = high_msg.time; |
| 78 | + if (t_low < t_high) { |
| 79 | + if (!PeekMessageA(&msg, nullptr, 0, WM_INPUT - 1, PM_REMOVE)) { |
| 80 | + break; |
| 81 | + } |
| 82 | + } else if (t_high < t_low) { |
| 83 | + if (!PeekMessageA(&msg, nullptr, WM_INPUT + 1, 0xFFFFFFFF, PM_REMOVE)) { |
| 84 | + break; |
| 85 | + } |
| 86 | + } else { |
| 87 | + if (!PeekMessageA(&msg, nullptr, WM_INPUT + 1, 0xFFFFFFFF, PM_REMOVE)) { |
| 88 | + break; |
| 89 | + } |
| 90 | + } |
| 91 | + } |
| 92 | + DispatchOneMsg(&msg, from_winmain); |
40 | 93 | ++processed; |
41 | 94 | } |
42 | 95 | } |
|
0 commit comments