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)
{
if (CurrentProc == DisableInputWndProc)
if (CurrentEventHandler == DisableInputEventHandler)
return;
primaryActionButtonRenderer.Render(renderFunction, buttonArt);

9
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:

2
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);
/**

8
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()

12
Source/init.cpp

@ -37,7 +37,7 @@ bool gbActive;
/** A handle to an hellfire.mpq archive. */
std::optional<MpqArchive> hellfire_mpq;
/** The current input handler function */
WNDPROC CurrentProc;
EventHandler CurrentEventHandler;
/** A handle to the spawn.mpq archive. */
std::optional<MpqArchive> 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

6
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<MpqArchive> hellfire_mpq;
extern WNDPROC CurrentProc;
extern EventHandler CurrentEventHandler;
extern std::optional<MpqArchive> spawn_mpq;
extern std::optional<MpqArchive> 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

7
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);

4
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)

21
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);

Loading…
Cancel
Save