diff --git a/Source/controls/touch/renderers.cpp b/Source/controls/touch/renderers.cpp index 0ee4d9976..cebe9e211 100644 --- a/Source/controls/touch/renderers.cpp +++ b/Source/controls/touch/renderers.cpp @@ -247,7 +247,7 @@ void VirtualDirectionPadRenderer::LoadArt(SDL_Renderer *renderer) void VirtualGamepadRenderer::Render(RenderFunction renderFunction) { - if (CurrentProc == DisableInputWndProc) + if (CurrentEventHandler == DisableInputEventHandler) return; primaryActionButtonRenderer.Render(renderFunction, buttonArt); diff --git a/Source/diablo.cpp b/Source/diablo.cpp index fa5fb6f1c..2e8f8ae63 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -715,13 +715,12 @@ void RunGameLoop(interface_mode uMsg) { demo::NotifyGameLoopStart(); - WNDPROC saveProc; tagMSG msg; nthread_ignore_mutex(true); StartGame(uMsg); assert(ghMainWnd); - saveProc = SetWindowProc(GameEventHandler); + EventHandler previousHandler = SetEventHandler(GameEventHandler); run_delta_info(); gbRunGame = true; gbProcessPlayers = true; @@ -804,8 +803,8 @@ void RunGameLoop(interface_mode uMsg) ClearScreenBuffer(); force_redraw = 255; scrollrt_draw_game_screen(); - saveProc = SetWindowProc(saveProc); - assert(saveProc == GameEventHandler); + previousHandler = SetEventHandler(previousHandler); + assert(previousHandler == GameEventHandler); FreeGame(); if (cineflag) { @@ -2037,7 +2036,7 @@ bool PressEscKey() return rv; } -void DisableInputWndProc(uint32_t uMsg, int32_t /*wParam*/, int32_t lParam) +void DisableInputEventHandler(uint32_t uMsg, int32_t /*wParam*/, int32_t lParam) { switch (uMsg) { case DVL_WM_KEYDOWN: diff --git a/Source/diablo.h b/Source/diablo.h index 3b7dbe68f..9188e6b4d 100644 --- a/Source/diablo.h +++ b/Source/diablo.h @@ -92,7 +92,7 @@ bool diablo_is_focused(); void diablo_focus_pause(); void diablo_focus_unpause(); bool PressEscKey(); -void DisableInputWndProc(uint32_t uMsg, int32_t wParam, int32_t lParam); +void DisableInputEventHandler(uint32_t uMsg, int32_t wParam, int32_t lParam); void LoadGameLevel(bool firstflag, lvl_entry lvldir); /** diff --git a/Source/gamemenu.cpp b/Source/gamemenu.cpp index b34c6611a..f639ab67f 100644 --- a/Source/gamemenu.cpp +++ b/Source/gamemenu.cpp @@ -287,7 +287,7 @@ void gamemenu_quit_game(bool bActivate) void gamemenu_load_game(bool /*bActivate*/) { - WNDPROC saveProc = SetWindowProc(DisableInputWndProc); + EventHandler saveProc = SetEventHandler(DisableInputEventHandler); gamemenu_off(); NewCursor(CURSOR_NONE); InitDiabloMsg(EMSG_LOADING); @@ -304,7 +304,7 @@ void gamemenu_load_game(bool /*bActivate*/) PaletteFadeIn(8); NewCursor(CURSOR_HAND); interface_msg_pump(); - SetWindowProc(saveProc); + SetEventHandler(saveProc); } void gamemenu_save_game(bool /*bActivate*/) @@ -318,7 +318,7 @@ void gamemenu_save_game(bool /*bActivate*/) return; } - WNDPROC saveProc = SetWindowProc(DisableInputWndProc); + EventHandler saveProc = SetEventHandler(DisableInputEventHandler); NewCursor(CURSOR_NONE); gamemenu_off(); InitDiabloMsg(EMSG_SAVING); @@ -333,7 +333,7 @@ void gamemenu_save_game(bool /*bActivate*/) SaveOptions(); } interface_msg_pump(); - SetWindowProc(saveProc); + SetEventHandler(saveProc); } void gamemenu_on() diff --git a/Source/init.cpp b/Source/init.cpp index a785e248c..baef39f7f 100644 --- a/Source/init.cpp +++ b/Source/init.cpp @@ -37,7 +37,7 @@ bool gbActive; /** A handle to an hellfire.mpq archive. */ std::optional hellfire_mpq; /** The current input handler function */ -WNDPROC CurrentProc; +EventHandler CurrentEventHandler; /** A handle to the spawn.mpq archive. */ std::optional spawn_mpq; /** A handle to the diabdat.mpq archive. */ @@ -238,13 +238,11 @@ void MainWndProc(uint32_t msg) } } -WNDPROC SetWindowProc(WNDPROC newProc) +EventHandler SetEventHandler(EventHandler eventHandler) { - WNDPROC oldProc; - - oldProc = CurrentProc; - CurrentProc = newProc; - return oldProc; + EventHandler previousHandler = CurrentEventHandler; + CurrentEventHandler = eventHandler; + return previousHandler; } } // namespace devilution diff --git a/Source/init.h b/Source/init.h index aec33d9e1..7a05ffd61 100644 --- a/Source/init.h +++ b/Source/init.h @@ -10,11 +10,11 @@ namespace devilution { -typedef void (*WNDPROC)(uint32_t, int32_t, int32_t); +typedef void (*EventHandler)(uint32_t, int32_t, int32_t); extern bool gbActive; extern std::optional hellfire_mpq; -extern WNDPROC CurrentProc; +extern EventHandler CurrentEventHandler; extern std::optional spawn_mpq; extern std::optional diabdat_mpq; extern DVL_API_FOR_TEST bool gbIsSpawn; @@ -36,6 +36,6 @@ void LoadLanguageArchive(); void LoadGameArchives(); void init_create_window(); void MainWndProc(uint32_t Msg); -WNDPROC SetWindowProc(WNDPROC NewProc); +EventHandler SetEventHandler(EventHandler NewProc); } // namespace devilution diff --git a/Source/interfac.cpp b/Source/interfac.cpp index f6c9cbe70..923342725 100644 --- a/Source/interfac.cpp +++ b/Source/interfac.cpp @@ -230,14 +230,13 @@ bool IncProgress() void ShowProgress(interface_mode uMsg) { - WNDPROC saveProc; IsProgress = true; gbSomebodyWonGameKludge = false; plrmsg_delay(true); assert(ghMainWnd); - saveProc = SetWindowProc(DisableInputWndProc); + EventHandler previousHandler = SetEventHandler(DisableInputEventHandler); interface_msg_pump(); ClearScreenBuffer(); @@ -416,8 +415,8 @@ void ShowProgress(interface_mode uMsg) PaletteFadeOut(8); - saveProc = SetWindowProc(saveProc); - assert(saveProc == DisableInputWndProc); + previousHandler = SetEventHandler(previousHandler); + assert(previousHandler == DisableInputEventHandler); IsProgress = false; NetSendCmdLocParam2(true, CMD_PLAYER_JOINLEVEL, myPlayer.position.tile, myPlayer.plrlevel, myPlayer.plrIsOnSetLevel ? 1 : 0); diff --git a/Source/miniwin/misc_msg.cpp b/Source/miniwin/misc_msg.cpp index d6b96637e..b050ddc85 100644 --- a/Source/miniwin/misc_msg.cpp +++ b/Source/miniwin/misc_msg.cpp @@ -829,9 +829,9 @@ bool GetAsyncKeyState(int vKey) void PushMessage(const tagMSG *lpMsg) { - assert(CurrentProc); + assert(CurrentEventHandler != nullptr); - CurrentProc(lpMsg->message, lpMsg->wParam, lpMsg->lParam); + CurrentEventHandler(lpMsg->message, lpMsg->wParam, lpMsg->lParam); } bool PostMessage(uint32_t type, int32_t wParam, int32_t lParam) diff --git a/Source/multi.cpp b/Source/multi.cpp index 7c48a6964..5d585b56c 100644 --- a/Source/multi.cpp +++ b/Source/multi.cpp @@ -400,19 +400,22 @@ void HandleEvents(_SNETEVENT *pEvt) } } -void EventHandler(bool add) +void RegisterNetEventHandlers() { for (auto eventType : EventTypes) { - if (add) { - if (!SNetRegisterEventHandler(eventType, HandleEvents)) { - app_fatal(StrCat("SNetRegisterEventHandler:\n", SDL_GetError())); - } - } else { - SNetUnregisterEventHandler(eventType); + if (!SNetRegisterEventHandler(eventType, HandleEvents)) { + app_fatal(StrCat("SNetRegisterEventHandler:\n", SDL_GetError())); } } } +void UnregisterNetEventHandlers() +{ + for (auto eventType : EventTypes) { + SNetUnregisterEventHandler(eventType); + } +} + bool InitSingle(GameData *gameData) { if (!SNetInitializeProvider(SELCONN_LOOPBACK, gameData)) { @@ -442,7 +445,7 @@ bool InitMulti(GameData *gameData) return false; } - EventHandler(true); + RegisterNetEventHandlers(); if (UiSelectGame(gameData, &playerId)) break; @@ -701,7 +704,7 @@ void NetClose() nthread_cleanup(); DThreadCleanup(); tmsg_cleanup(); - EventHandler(false); + UnregisterNetEventHandlers(); SNetLeaveGame(3); if (gbIsMultiplayer) SDL_Delay(2000);