|
11 | 11 |
|
12 | 12 | #include <eh.h> |
13 | 13 |
|
14 | | -#if defined __MINGW32__ |
15 | | -# define _set_se_translator(x) ((void)0) |
16 | | -#endif |
17 | | - |
18 | 14 | // ====== |
19 | 15 | // Locals |
20 | 16 | // ====== |
@@ -639,63 +635,17 @@ LRESULT __stdcall sys_main_c::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM |
639 | 635 | return DefWindowProc(hwnd, msg, wParam, lParam); |
640 | 636 | } |
641 | 637 |
|
642 | | -int sys_main_c::RunMessages(HWND hwnd, bool slurp, unsigned timeout) |
| 638 | +void sys_main_c::RunMessages(HWND hwnd) |
643 | 639 | { |
| 640 | + // Flush message queue |
644 | 641 | MSG msg; |
645 | | - unsigned ret; |
646 | | - unsigned nmsg = 0; |
647 | | - |
648 | | - if (timeout == 0) |
649 | | - timeout = 250; |
650 | | - |
651 | | - for (;;) |
652 | | - { |
653 | | - // take care of non-blocking, blocking, and block+timeout message reads |
654 | | - if (slurp) |
655 | | - { |
656 | | - if (PeekMessage(&msg, hwnd, 0, 0, PM_NOREMOVE)) |
657 | | - { |
658 | | - ret = GetMessage(&msg, hwnd, 0, 0); |
659 | | - } |
660 | | - else |
661 | | - break; |
662 | | - } |
663 | | - else |
664 | | - { |
665 | | - static const UINT_PTR TIMER_ID = 1042; |
666 | | - UINT_PTR id = hwnd ? TIMER_ID : 0; |
667 | | - id = SetTimer(hwnd, id, timeout, NULL); |
668 | | - ret = GetMessage(&msg, hwnd, 0, 0); |
669 | | - (void) KillTimer(hwnd, id); |
670 | | - if (ret != unsigned(-1) && ret != 0) |
671 | | - { |
672 | | - if (msg.message == WM_TIMER && msg.wParam == id) |
673 | | - break; |
674 | | - } |
675 | | - } |
676 | | - |
677 | | - // deal error, window destruction, and valid messages respectively |
678 | | - if (ret == unsigned(-1)) |
679 | | - break; |
680 | | - else if (ret == 0) |
681 | | - { |
682 | | - nmsg++; |
| 642 | + while (PeekMessage(&msg, hwnd, 0, 0, PM_NOREMOVE)) { |
| 643 | + if (GetMessage(&msg, hwnd, 0, 0) == 0) { |
683 | 644 | Exit(); |
684 | | - break; |
685 | 645 | } |
686 | | - else |
687 | | - { |
688 | | - nmsg++; |
689 | | - TranslateMessage(&msg); |
690 | | - DispatchMessage(&msg); |
691 | | - } |
692 | | - |
693 | | - // one message is enough in case of blocking reads |
694 | | - if (!slurp && !PeekMessage(&msg, hwnd, 0, 0, PM_NOREMOVE)) |
695 | | - break; |
| 646 | + TranslateMessage(&msg); |
| 647 | + DispatchMessage(&msg); |
696 | 648 | } |
697 | | - |
698 | | - return nmsg; |
699 | 649 | } |
700 | 650 |
|
701 | 651 | // ============================== |
@@ -729,8 +679,8 @@ void sys_main_c::Error(char *fmt, ...) |
729 | 679 |
|
730 | 680 | exitFlag = false; |
731 | 681 | while (exitFlag == false) { |
732 | | - RunMessages(NULL, false, 1000); |
733 | | - //Sleep(50); |
| 682 | + RunMessages(); |
| 683 | + Sleep(50); |
734 | 684 | } |
735 | 685 |
|
736 | 686 | #ifdef _MEMTRAK_H |
@@ -813,20 +763,21 @@ bool sys_main_c::Run(int argc, char** argv) |
813 | 763 | con->Printf("\n"); |
814 | 764 |
|
815 | 765 | initialised = true; |
| 766 | + |
816 | 767 | try { |
817 | 768 | // Enable translation to catch C exceptions if debugger is not present |
818 | 769 | if ( !debuggerRunning ) { |
819 | 770 | _set_se_translator(SE_ErrorTrans); |
820 | 771 | } |
| 772 | + |
821 | 773 | // Initialise engine |
822 | 774 | core->Init(argc, argv); |
| 775 | + |
823 | 776 | // Run frame loop |
824 | 777 | while (exitFlag == false) { |
825 | | - int nsubscript = core->SubScriptCount(); |
826 | | - int nmsg = RunMessages(NULL, false); |
| 778 | + RunMessages(); |
827 | 779 |
|
828 | | - if (nsubscript || nmsg) |
829 | | - core->Frame(); |
| 780 | + core->Frame(); |
830 | 781 |
|
831 | 782 | if (threadError) { |
832 | 783 | Error(threadError); |
@@ -862,8 +813,8 @@ bool sys_main_c::Run(int argc, char** argv) |
862 | 813 | exitMsg = NULL; |
863 | 814 | } |
864 | 815 | while (exitFlag == false) { |
865 | | - RunMessages(NULL, false); |
866 | | - //Sleep(50); |
| 816 | + RunMessages(); |
| 817 | + Sleep(50); |
867 | 818 | } |
868 | 819 | } |
869 | 820 |
|
|
0 commit comments