Browse Source

Clean up event handeling

pull/484/head^2
Anders Jenbo 6 years ago
parent
commit
e847108b78
  1. 69
      Source/diablo.cpp
  2. 2
      Source/interfac.cpp
  3. 2
      Source/movie.cpp
  4. 4
      SourceS/miniwin/misc.h
  5. 26
      SourceX/DiabloUI/diabloui.cpp
  6. 2
      SourceX/DiabloUI/diabloui.h
  7. 2
      SourceX/DiabloUI/dialogs.cpp
  8. 5
      SourceX/DiabloUI/progress.cpp
  9. 2
      SourceX/DiabloUI/title.cpp
  10. 21
      SourceX/miniwin/misc_msg.cpp

69
Source/diablo.cpp

@ -167,28 +167,23 @@ void run_game_loop(unsigned int uMsg)
nthread_ignore_mutex(FALSE); nthread_ignore_mutex(FALSE);
while (gbRunGame) { while (gbRunGame) {
diablo_color_cyc_logic(); while (PeekMessage(&msg)) {
if (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) { if (msg.message == WM_QUIT) {
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL); gbRunGameResult = FALSE;
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { gbRunGame = FALSE;
if (msg.message == WM_QUIT) { break;
gbRunGameResult = FALSE;
gbRunGame = FALSE;
break;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
bLoop = gbRunGame && nthread_has_500ms_passed(FALSE);
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL);
if (!bLoop) {
continue;
} }
} else if (!nthread_has_500ms_passed(FALSE)) { TranslateMessage(&msg);
DispatchMessage(&msg);
}
if (!gbRunGame)
break;
if (!nthread_has_500ms_passed(FALSE)) {
ProcessInput(); ProcessInput();
DrawAndBlit(); DrawAndBlit();
continue; continue;
} }
diablo_color_cyc_logic();
multi_process_network_packets(); multi_process_network_packets();
game_loop(gbGameLoopStartup); game_loop(gbGameLoopStartup);
gbGameLoopStartup = FALSE; gbGameLoopStartup = FALSE;
@ -1692,25 +1687,7 @@ extern void plrctrls_after_game_logic();
void game_logic() void game_logic()
{ {
if (PauseMode == 2) { ProcessInput();
return;
}
if (PauseMode == 1) {
PauseMode = 2;
}
if (gbMaxPlayers == 1 && gmenu_exception()) {
force_redraw |= 1;
return;
}
if (!gmenu_exception() && sgnTimeoutCurs == 0) {
#ifndef USE_SDL1
finish_simulated_mouse_clicks(MouseX, MouseY);
#endif
CheckCursMove();
plrctrls_after_check_curs_move();
track_process();
}
if (gbProcessPlayers) { if (gbProcessPlayers) {
ProcessPlayers(); ProcessPlayers();
} }
@ -1766,19 +1743,13 @@ void timeout_cursor(BOOL bTimeout)
void diablo_color_cyc_logic() void diablo_color_cyc_logic()
{ {
DWORD tc; if (!palette_get_colour_cycling())
return;
tc = GetTickCount();
if (tc - color_cycle_timer >= 50) { if (leveltype == DTYPE_HELL) {
color_cycle_timer = tc; lighting_color_cycling();
if (palette_get_colour_cycling()) { } else if (leveltype == DTYPE_CAVES) {
if (leveltype == DTYPE_HELL) { palette_update_caves();
lighting_color_cycling();
} else if (leveltype == DTYPE_CAVES) {
//if (fullscreen)
palette_update_caves();
}
}
} }
} }

2
Source/interfac.cpp

@ -13,7 +13,7 @@ void interface_msg_pump()
{ {
MSG Msg; MSG Msg;
while (PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE)) { while (PeekMessage(&Msg)) {
if (Msg.message != WM_QUIT) { if (Msg.message != WM_QUIT) {
TranslateMessage(&Msg); TranslateMessage(&Msg);
DispatchMessage(&Msg); DispatchMessage(&Msg);

2
Source/movie.cpp

@ -18,7 +18,7 @@ void play_movie(char *pszMovie, BOOL user_can_close)
SVidPlayBegin(pszMovie, 0, 0, 0, 0, loop_movie ? 0x100C0808 : 0x10280808, &video_stream); SVidPlayBegin(pszMovie, 0, 0, 0, 0, loop_movie ? 0x100C0808 : 0x10280808, &video_stream);
MSG Msg; MSG Msg;
while (video_stream && movie_playing) { while (video_stream && movie_playing) {
while (movie_playing && PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE)) { while (movie_playing && PeekMessage(&Msg)) {
TranslateMessage(&Msg); TranslateMessage(&Msg);
switch (Msg.message) { switch (Msg.message) {
case WM_KEYDOWN: case WM_KEYDOWN:

4
SourceS/miniwin/misc.h

@ -195,7 +195,7 @@ void FocusOnCharInfo();
SHORT WINAPI GetAsyncKeyState(int vKey); SHORT WINAPI GetAsyncKeyState(int vKey);
WINBOOL WINAPI PeekMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax, UINT wRemoveMsg); WINBOOL WINAPI PeekMessageA(LPMSG lpMsg);
WINBOOL WINAPI TranslateMessage(const MSG *lpMsg); WINBOOL WINAPI TranslateMessage(const MSG *lpMsg);
LRESULT WINAPI DispatchMessageA(const MSG *lpMsg); LRESULT WINAPI DispatchMessageA(const MSG *lpMsg);
@ -464,8 +464,6 @@ constexpr auto DVL_FILE_BEGIN = 0;
constexpr auto DVL_FILE_CURRENT = 1; constexpr auto DVL_FILE_CURRENT = 1;
constexpr auto DVL_ERROR_FILE_NOT_FOUND = 2; constexpr auto DVL_ERROR_FILE_NOT_FOUND = 2;
constexpr auto DVL_PM_NOREMOVE = 0x0000;
constexpr auto DVL_PM_REMOVE = 0x0001;
constexpr auto DVL_WM_QUIT = 0x0012; constexpr auto DVL_WM_QUIT = 0x0012;
constexpr auto DVL_INFINITE = 0xFFFFFFFF; constexpr auto DVL_INFINITE = 0xFFFFFFFF;

26
SourceX/DiabloUI/diabloui.cpp

@ -186,32 +186,32 @@ void selhero_CatToName(char *in_buf, char *out_buf, int cnt)
strncat(out_buf, output.c_str(), cnt - strlen(out_buf)); strncat(out_buf, output.c_str(), cnt - strlen(out_buf));
} }
bool UiFocusNavigation(SDL_Event *event) void UiFocusNavigation(SDL_Event *event)
{ {
switch (GetMenuAction(*event)) { switch (GetMenuAction(*event)) {
case MenuAction::SELECT: case MenuAction::SELECT:
UiFocusNavigationSelect(); UiFocusNavigationSelect();
return true; return;
case MenuAction::UP: case MenuAction::UP:
UiFocus(SelectedItem - 1, UiItemsWraps); UiFocus(SelectedItem - 1, UiItemsWraps);
return true; return;
case MenuAction::DOWN: case MenuAction::DOWN:
UiFocus(SelectedItem + 1, UiItemsWraps); UiFocus(SelectedItem + 1, UiItemsWraps);
return true; return;
case MenuAction::PAGE_UP: case MenuAction::PAGE_UP:
UiFocusPageUp(); UiFocusPageUp();
return true; return;
case MenuAction::PAGE_DOWN: case MenuAction::PAGE_DOWN:
UiFocusPageDown(); UiFocusPageDown();
return true; return;
case MenuAction::DELETE: case MenuAction::DELETE:
UiFocusNavigationYesNo(); UiFocusNavigationYesNo();
return true; return;
case MenuAction::BACK: case MenuAction::BACK:
if (!gfnListEsc) if (!gfnListEsc)
break; break;
UiFocusNavigationEsc(); UiFocusNavigationEsc();
return true; return;
default: default:
break; break;
} }
@ -252,7 +252,7 @@ bool UiFocusNavigation(SDL_Event *event)
selhero_CatToName(clipboard, UiTextInput, UiTextInputLen); selhero_CatToName(clipboard, UiTextInput, UiTextInputLen);
} }
} }
return true; return;
#endif #endif
case SDLK_BACKSPACE: case SDLK_BACKSPACE:
case SDLK_LEFT: { case SDLK_LEFT: {
@ -260,7 +260,7 @@ bool UiFocusNavigation(SDL_Event *event)
if (nameLen > 0) { if (nameLen > 0) {
UiTextInput[nameLen - 1] = '\0'; UiTextInput[nameLen - 1] = '\0';
} }
return true; return;
} }
default: default:
break; break;
@ -281,7 +281,7 @@ bool UiFocusNavigation(SDL_Event *event)
#ifndef USE_SDL1 #ifndef USE_SDL1
case SDL_TEXTINPUT: case SDL_TEXTINPUT:
selhero_CatToName(event->text.text, UiTextInput, UiTextInputLen); selhero_CatToName(event->text.text, UiTextInput, UiTextInputLen);
return true; return;
#endif #endif
default: default:
break; break;
@ -294,10 +294,8 @@ bool UiFocusNavigation(SDL_Event *event)
OutputToLogical(&event->button.x, &event->button.y); OutputToLogical(&event->button.x, &event->button.y);
#endif #endif
if (UiItemMouseEvents(event, gUiItems, gUiItemCnt)) if (UiItemMouseEvents(event, gUiItems, gUiItemCnt))
return true; return;
} }
return false;
} }
void UiHandleEvents(SDL_Event *event) void UiHandleEvents(SDL_Event *event)

2
SourceX/DiabloUI/diabloui.h

@ -40,7 +40,7 @@ extern void (*gfnSoundFunction)(char *file);
bool IsInsideRect(const SDL_Event &event, const SDL_Rect &rect); bool IsInsideRect(const SDL_Event &event, const SDL_Rect &rect);
void UiFadeIn(); void UiFadeIn();
bool UiFocusNavigation(SDL_Event *event); void UiFocusNavigation(SDL_Event *event);
void UiHandleEvents(SDL_Event *event); void UiHandleEvents(SDL_Event *event);
bool UiItemMouseEvents(SDL_Event *event, UiItem *items, std::size_t size); bool UiItemMouseEvents(SDL_Event *event, UiItem *items, std::size_t size);
int GetCenterOffset(int w, int bw = 0); int GetCenterOffset(int w, int bw = 0);

2
SourceX/DiabloUI/dialogs.cpp

@ -54,7 +54,7 @@ UiItem OK_DIALOG[] = {
UiItem OK_DIALOG_WITH_CAPTION[] = { UiItem OK_DIALOG_WITH_CAPTION[] = {
DIALOG_ART_L, DIALOG_ART_L,
UiText(dialogText, SDL_Color { 255, 255, 0, 0 }, { 147, 110, 345, 20 }, UIS_CENTER), UiText(dialogText, SDL_Color{ 255, 255, 0, 0 }, { 147, 110, 345, 20 }, UIS_CENTER),
UiText(dialogCaption, { 147, 141, 345, 190 }, UIS_CENTER), UiText(dialogCaption, { 147, 141, 345, 190 }, UIS_CENTER),
MakeSmlButton("OK", &DialogActionOK, 264, 335), MakeSmlButton("OK", &DialogActionOK, 264, 335),
}; };

5
SourceX/DiabloUI/progress.cpp

@ -65,7 +65,8 @@ void progress_Render(BYTE progress)
SDL_Rect dsc_rect = { SDL_Rect dsc_rect = {
static_cast<decltype(SDL_Rect().x)>(SCREEN_X + x + 50), static_cast<decltype(SDL_Rect().x)>(SCREEN_X + x + 50),
static_cast<decltype(SDL_Rect().y)>(SCREEN_Y + y + 8), static_cast<decltype(SDL_Rect().y)>(SCREEN_Y + y + 8),
SCREEN_WIDTH, SCREEN_HEIGHT }; SCREEN_WIDTH, SCREEN_HEIGHT
};
if (SDL_BlitSurface(msgSurface, NULL, pal_surface, &dsc_rect) <= -1) { if (SDL_BlitSurface(msgSurface, NULL, pal_surface, &dsc_rect) <= -1) {
ErrSdl(); ErrSdl();
} }
@ -118,4 +119,4 @@ BOOL UiProgressDialog(HWND window, char *msg, int enable, int (*fnfunc)(), int r
return progress == 100; return progress == 100;
} }
} } // namespace dvl

2
SourceX/DiabloUI/title.cpp

@ -64,4 +64,4 @@ void UiSetSpawned(BOOL bSpawned)
gbSpawned = bSpawned; gbSpawned = bSpawned;
} }
} } // namespace dvl

21
SourceX/miniwin/misc_msg.cpp

@ -331,28 +331,12 @@ void BlurInventory()
FocusOnCharInfo(); FocusOnCharInfo();
} }
WINBOOL PeekMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax, UINT wRemoveMsg) WINBOOL PeekMessageA(LPMSG lpMsg)
{ {
#ifdef __SWITCH__ #ifdef __SWITCH__
HandleDocking(); HandleDocking();
#endif #endif
if (wMsgFilterMin != 0)
UNIMPLEMENTED();
if (wMsgFilterMax != 0)
UNIMPLEMENTED();
if (hWnd != NULL)
UNIMPLEMENTED();
if (wRemoveMsg == DVL_PM_NOREMOVE) {
// This does not actually fill out lpMsg, but this is ok
// since the engine never uses it in this case
return !message_queue.empty() || SDL_PollEvent(NULL);
}
if (wRemoveMsg != DVL_PM_REMOVE) {
UNIMPLEMENTED();
}
if (!message_queue.empty()) { if (!message_queue.empty()) {
*lpMsg = message_queue.front(); *lpMsg = message_queue.front();
message_queue.pop_front(); message_queue.pop_front();
@ -364,7 +348,6 @@ WINBOOL PeekMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilter
return false; return false;
} }
lpMsg->hwnd = hWnd;
lpMsg->message = 0; lpMsg->message = 0;
lpMsg->lParam = 0; lpMsg->lParam = 0;
lpMsg->wParam = 0; lpMsg->wParam = 0;
@ -602,7 +585,6 @@ WINBOOL PeekMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilter
WINBOOL TranslateMessage(const MSG *lpMsg) WINBOOL TranslateMessage(const MSG *lpMsg)
{ {
assert(lpMsg->hwnd == 0);
if (lpMsg->message == DVL_WM_KEYDOWN) { if (lpMsg->message == DVL_WM_KEYDOWN) {
int key = lpMsg->wParam; int key = lpMsg->wParam;
unsigned mod = (DWORD)lpMsg->lParam >> 16; unsigned mod = (DWORD)lpMsg->lParam >> 16;
@ -705,7 +687,6 @@ SHORT GetAsyncKeyState(int vKey)
LRESULT DispatchMessageA(const MSG *lpMsg) LRESULT DispatchMessageA(const MSG *lpMsg)
{ {
DUMMY_ONCE(); DUMMY_ONCE();
assert(lpMsg->hwnd == 0);
assert(CurrentProc); assert(CurrentProc);
// assert(CurrentProc == GM_Game); // assert(CurrentProc == GM_Game);

Loading…
Cancel
Save