Browse Source

Clean up naming of event handler

pull/4952/head
Anders Jenbo 4 years ago
parent
commit
a7be622aa3
  1. 2
      Source/controls/touch/renderers.cpp
  2. 9
      Source/diablo.cpp
  3. 2
      Source/diablo.h
  4. 8
      Source/gamemenu.cpp
  5. 12
      Source/init.cpp
  6. 6
      Source/init.h
  7. 7
      Source/interfac.cpp
  8. 4
      Source/miniwin/misc_msg.cpp
  9. 21
      Source/multi.cpp

2
Source/controls/touch/renderers.cpp

@ -247,7 +247,7 @@ void VirtualDirectionPadRenderer::LoadArt(SDL_Renderer *renderer)
void VirtualGamepadRenderer::Render(RenderFunction renderFunction) void VirtualGamepadRenderer::Render(RenderFunction renderFunction)
{ {
if (CurrentProc == DisableInputWndProc) if (CurrentEventHandler == DisableInputEventHandler)
return; return;
primaryActionButtonRenderer.Render(renderFunction, buttonArt); primaryActionButtonRenderer.Render(renderFunction, buttonArt);

9
Source/diablo.cpp

@ -715,13 +715,12 @@ void RunGameLoop(interface_mode uMsg)
{ {
demo::NotifyGameLoopStart(); demo::NotifyGameLoopStart();
WNDPROC saveProc;
tagMSG msg; tagMSG msg;
nthread_ignore_mutex(true); nthread_ignore_mutex(true);
StartGame(uMsg); StartGame(uMsg);
assert(ghMainWnd); assert(ghMainWnd);
saveProc = SetWindowProc(GameEventHandler); EventHandler previousHandler = SetEventHandler(GameEventHandler);
run_delta_info(); run_delta_info();
gbRunGame = true; gbRunGame = true;
gbProcessPlayers = true; gbProcessPlayers = true;
@ -804,8 +803,8 @@ void RunGameLoop(interface_mode uMsg)
ClearScreenBuffer(); ClearScreenBuffer();
force_redraw = 255; force_redraw = 255;
scrollrt_draw_game_screen(); scrollrt_draw_game_screen();
saveProc = SetWindowProc(saveProc); previousHandler = SetEventHandler(previousHandler);
assert(saveProc == GameEventHandler); assert(previousHandler == GameEventHandler);
FreeGame(); FreeGame();
if (cineflag) { if (cineflag) {
@ -2037,7 +2036,7 @@ bool PressEscKey()
return rv; 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) { switch (uMsg) {
case DVL_WM_KEYDOWN: case DVL_WM_KEYDOWN:

2
Source/diablo.h

@ -92,7 +92,7 @@ bool diablo_is_focused();
void diablo_focus_pause(); void diablo_focus_pause();
void diablo_focus_unpause(); void diablo_focus_unpause();
bool PressEscKey(); 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); void LoadGameLevel(bool firstflag, lvl_entry lvldir);
/** /**

8
Source/gamemenu.cpp

@ -287,7 +287,7 @@ void gamemenu_quit_game(bool bActivate)
void gamemenu_load_game(bool /*bActivate*/) void gamemenu_load_game(bool /*bActivate*/)
{ {
WNDPROC saveProc = SetWindowProc(DisableInputWndProc); EventHandler saveProc = SetEventHandler(DisableInputEventHandler);
gamemenu_off(); gamemenu_off();
NewCursor(CURSOR_NONE); NewCursor(CURSOR_NONE);
InitDiabloMsg(EMSG_LOADING); InitDiabloMsg(EMSG_LOADING);
@ -304,7 +304,7 @@ void gamemenu_load_game(bool /*bActivate*/)
PaletteFadeIn(8); PaletteFadeIn(8);
NewCursor(CURSOR_HAND); NewCursor(CURSOR_HAND);
interface_msg_pump(); interface_msg_pump();
SetWindowProc(saveProc); SetEventHandler(saveProc);
} }
void gamemenu_save_game(bool /*bActivate*/) void gamemenu_save_game(bool /*bActivate*/)
@ -318,7 +318,7 @@ void gamemenu_save_game(bool /*bActivate*/)
return; return;
} }
WNDPROC saveProc = SetWindowProc(DisableInputWndProc); EventHandler saveProc = SetEventHandler(DisableInputEventHandler);
NewCursor(CURSOR_NONE); NewCursor(CURSOR_NONE);
gamemenu_off(); gamemenu_off();
InitDiabloMsg(EMSG_SAVING); InitDiabloMsg(EMSG_SAVING);
@ -333,7 +333,7 @@ void gamemenu_save_game(bool /*bActivate*/)
SaveOptions(); SaveOptions();
} }
interface_msg_pump(); interface_msg_pump();
SetWindowProc(saveProc); SetEventHandler(saveProc);
} }
void gamemenu_on() void gamemenu_on()

12
Source/init.cpp

@ -37,7 +37,7 @@ bool gbActive;
/** A handle to an hellfire.mpq archive. */ /** A handle to an hellfire.mpq archive. */
std::optional<MpqArchive> hellfire_mpq; std::optional<MpqArchive> hellfire_mpq;
/** The current input handler function */ /** The current input handler function */
WNDPROC CurrentProc; EventHandler CurrentEventHandler;
/** A handle to the spawn.mpq archive. */ /** A handle to the spawn.mpq archive. */
std::optional<MpqArchive> spawn_mpq; std::optional<MpqArchive> spawn_mpq;
/** A handle to the diabdat.mpq archive. */ /** 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; EventHandler previousHandler = CurrentEventHandler;
CurrentEventHandler = eventHandler;
oldProc = CurrentProc; return previousHandler;
CurrentProc = newProc;
return oldProc;
} }
} // namespace devilution } // namespace devilution

6
Source/init.h

@ -10,11 +10,11 @@
namespace devilution { namespace devilution {
typedef void (*WNDPROC)(uint32_t, int32_t, int32_t); typedef void (*EventHandler)(uint32_t, int32_t, int32_t);
extern bool gbActive; extern bool gbActive;
extern std::optional<MpqArchive> hellfire_mpq; extern std::optional<MpqArchive> hellfire_mpq;
extern WNDPROC CurrentProc; extern EventHandler CurrentEventHandler;
extern std::optional<MpqArchive> spawn_mpq; extern std::optional<MpqArchive> spawn_mpq;
extern std::optional<MpqArchive> diabdat_mpq; extern std::optional<MpqArchive> diabdat_mpq;
extern DVL_API_FOR_TEST bool gbIsSpawn; extern DVL_API_FOR_TEST bool gbIsSpawn;
@ -36,6 +36,6 @@ void LoadLanguageArchive();
void LoadGameArchives(); void LoadGameArchives();
void init_create_window(); void init_create_window();
void MainWndProc(uint32_t Msg); void MainWndProc(uint32_t Msg);
WNDPROC SetWindowProc(WNDPROC NewProc); EventHandler SetEventHandler(EventHandler NewProc);
} // namespace devilution } // namespace devilution

7
Source/interfac.cpp

@ -230,14 +230,13 @@ bool IncProgress()
void ShowProgress(interface_mode uMsg) void ShowProgress(interface_mode uMsg)
{ {
WNDPROC saveProc;
IsProgress = true; IsProgress = true;
gbSomebodyWonGameKludge = false; gbSomebodyWonGameKludge = false;
plrmsg_delay(true); plrmsg_delay(true);
assert(ghMainWnd); assert(ghMainWnd);
saveProc = SetWindowProc(DisableInputWndProc); EventHandler previousHandler = SetEventHandler(DisableInputEventHandler);
interface_msg_pump(); interface_msg_pump();
ClearScreenBuffer(); ClearScreenBuffer();
@ -416,8 +415,8 @@ void ShowProgress(interface_mode uMsg)
PaletteFadeOut(8); PaletteFadeOut(8);
saveProc = SetWindowProc(saveProc); previousHandler = SetEventHandler(previousHandler);
assert(saveProc == DisableInputWndProc); assert(previousHandler == DisableInputEventHandler);
IsProgress = false; IsProgress = false;
NetSendCmdLocParam2(true, CMD_PLAYER_JOINLEVEL, myPlayer.position.tile, myPlayer.plrlevel, myPlayer.plrIsOnSetLevel ? 1 : 0); NetSendCmdLocParam2(true, CMD_PLAYER_JOINLEVEL, myPlayer.position.tile, myPlayer.plrlevel, myPlayer.plrIsOnSetLevel ? 1 : 0);

4
Source/miniwin/misc_msg.cpp

@ -829,9 +829,9 @@ bool GetAsyncKeyState(int vKey)
void PushMessage(const tagMSG *lpMsg) 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) bool PostMessage(uint32_t type, int32_t wParam, int32_t lParam)

21
Source/multi.cpp

@ -400,19 +400,22 @@ void HandleEvents(_SNETEVENT *pEvt)
} }
} }
void EventHandler(bool add) void RegisterNetEventHandlers()
{ {
for (auto eventType : EventTypes) { for (auto eventType : EventTypes) {
if (add) { if (!SNetRegisterEventHandler(eventType, HandleEvents)) {
if (!SNetRegisterEventHandler(eventType, HandleEvents)) { app_fatal(StrCat("SNetRegisterEventHandler:\n", SDL_GetError()));
app_fatal(StrCat("SNetRegisterEventHandler:\n", SDL_GetError()));
}
} else {
SNetUnregisterEventHandler(eventType);
} }
} }
} }
void UnregisterNetEventHandlers()
{
for (auto eventType : EventTypes) {
SNetUnregisterEventHandler(eventType);
}
}
bool InitSingle(GameData *gameData) bool InitSingle(GameData *gameData)
{ {
if (!SNetInitializeProvider(SELCONN_LOOPBACK, gameData)) { if (!SNetInitializeProvider(SELCONN_LOOPBACK, gameData)) {
@ -442,7 +445,7 @@ bool InitMulti(GameData *gameData)
return false; return false;
} }
EventHandler(true); RegisterNetEventHandlers();
if (UiSelectGame(gameData, &playerId)) if (UiSelectGame(gameData, &playerId))
break; break;
@ -701,7 +704,7 @@ void NetClose()
nthread_cleanup(); nthread_cleanup();
DThreadCleanup(); DThreadCleanup();
tmsg_cleanup(); tmsg_cleanup();
EventHandler(false); UnregisterNetEventHandlers();
SNetLeaveGame(3); SNetLeaveGame(3);
if (gbIsMultiplayer) if (gbIsMultiplayer)
SDL_Delay(2000); SDL_Delay(2000);

Loading…
Cancel
Save