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);
while (gbRunGame) {
diablo_color_cyc_logic();
if (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) {
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL);
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
if (msg.message == WM_QUIT) {
gbRunGameResult = FALSE;
gbRunGame = FALSE;
break;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
bLoop = gbRunGame && nthread_has_500ms_passed(FALSE);
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL);
if (!bLoop) {
continue;
while (PeekMessage(&msg)) {
if (msg.message == WM_QUIT) {
gbRunGameResult = FALSE;
gbRunGame = FALSE;
break;
}
} else if (!nthread_has_500ms_passed(FALSE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
if (!gbRunGame)
break;
if (!nthread_has_500ms_passed(FALSE)) {
ProcessInput();
DrawAndBlit();
continue;
}
diablo_color_cyc_logic();
multi_process_network_packets();
game_loop(gbGameLoopStartup);
gbGameLoopStartup = FALSE;
@ -1692,25 +1687,7 @@ extern void plrctrls_after_game_logic();
void game_logic()
{
if (PauseMode == 2) {
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();
}
ProcessInput();
if (gbProcessPlayers) {
ProcessPlayers();
}
@ -1766,19 +1743,13 @@ void timeout_cursor(BOOL bTimeout)
void diablo_color_cyc_logic()
{
DWORD tc;
tc = GetTickCount();
if (tc - color_cycle_timer >= 50) {
color_cycle_timer = tc;
if (palette_get_colour_cycling()) {
if (leveltype == DTYPE_HELL) {
lighting_color_cycling();
} else if (leveltype == DTYPE_CAVES) {
//if (fullscreen)
palette_update_caves();
}
}
if (!palette_get_colour_cycling())
return;
if (leveltype == DTYPE_HELL) {
lighting_color_cycling();
} else if (leveltype == DTYPE_CAVES) {
palette_update_caves();
}
}

2
Source/interfac.cpp

@ -13,7 +13,7 @@ void interface_msg_pump()
{
MSG Msg;
while (PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE)) {
while (PeekMessage(&Msg)) {
if (Msg.message != WM_QUIT) {
TranslateMessage(&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);
MSG Msg;
while (video_stream && movie_playing) {
while (movie_playing && PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE)) {
while (movie_playing && PeekMessage(&Msg)) {
TranslateMessage(&Msg);
switch (Msg.message) {
case WM_KEYDOWN:

4
SourceS/miniwin/misc.h

@ -195,7 +195,7 @@ void FocusOnCharInfo();
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);
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_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_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));
}
bool UiFocusNavigation(SDL_Event *event)
void UiFocusNavigation(SDL_Event *event)
{
switch (GetMenuAction(*event)) {
case MenuAction::SELECT:
UiFocusNavigationSelect();
return true;
return;
case MenuAction::UP:
UiFocus(SelectedItem - 1, UiItemsWraps);
return true;
return;
case MenuAction::DOWN:
UiFocus(SelectedItem + 1, UiItemsWraps);
return true;
return;
case MenuAction::PAGE_UP:
UiFocusPageUp();
return true;
return;
case MenuAction::PAGE_DOWN:
UiFocusPageDown();
return true;
return;
case MenuAction::DELETE:
UiFocusNavigationYesNo();
return true;
return;
case MenuAction::BACK:
if (!gfnListEsc)
break;
UiFocusNavigationEsc();
return true;
return;
default:
break;
}
@ -252,7 +252,7 @@ bool UiFocusNavigation(SDL_Event *event)
selhero_CatToName(clipboard, UiTextInput, UiTextInputLen);
}
}
return true;
return;
#endif
case SDLK_BACKSPACE:
case SDLK_LEFT: {
@ -260,7 +260,7 @@ bool UiFocusNavigation(SDL_Event *event)
if (nameLen > 0) {
UiTextInput[nameLen - 1] = '\0';
}
return true;
return;
}
default:
break;
@ -281,7 +281,7 @@ bool UiFocusNavigation(SDL_Event *event)
#ifndef USE_SDL1
case SDL_TEXTINPUT:
selhero_CatToName(event->text.text, UiTextInput, UiTextInputLen);
return true;
return;
#endif
default:
break;
@ -294,10 +294,8 @@ bool UiFocusNavigation(SDL_Event *event)
OutputToLogical(&event->button.x, &event->button.y);
#endif
if (UiItemMouseEvents(event, gUiItems, gUiItemCnt))
return true;
return;
}
return false;
}
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);
void UiFadeIn();
bool UiFocusNavigation(SDL_Event *event);
void UiFocusNavigation(SDL_Event *event);
void UiHandleEvents(SDL_Event *event);
bool UiItemMouseEvents(SDL_Event *event, UiItem *items, std::size_t size);
int GetCenterOffset(int w, int bw = 0);

2
SourceX/DiabloUI/dialogs.cpp

@ -54,7 +54,7 @@ UiItem OK_DIALOG[] = {
UiItem OK_DIALOG_WITH_CAPTION[] = {
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),
MakeSmlButton("OK", &DialogActionOK, 264, 335),
};

5
SourceX/DiabloUI/progress.cpp

@ -65,7 +65,8 @@ void progress_Render(BYTE progress)
SDL_Rect dsc_rect = {
static_cast<decltype(SDL_Rect().x)>(SCREEN_X + x + 50),
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) {
ErrSdl();
}
@ -118,4 +119,4 @@ BOOL UiProgressDialog(HWND window, char *msg, int enable, int (*fnfunc)(), int r
return progress == 100;
}
}
} // namespace dvl

2
SourceX/DiabloUI/title.cpp

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

21
SourceX/miniwin/misc_msg.cpp

@ -331,28 +331,12 @@ void BlurInventory()
FocusOnCharInfo();
}
WINBOOL PeekMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax, UINT wRemoveMsg)
WINBOOL PeekMessageA(LPMSG lpMsg)
{
#ifdef __SWITCH__
HandleDocking();
#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()) {
*lpMsg = message_queue.front();
message_queue.pop_front();
@ -364,7 +348,6 @@ WINBOOL PeekMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilter
return false;
}
lpMsg->hwnd = hWnd;
lpMsg->message = 0;
lpMsg->lParam = 0;
lpMsg->wParam = 0;
@ -602,7 +585,6 @@ WINBOOL PeekMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilter
WINBOOL TranslateMessage(const MSG *lpMsg)
{
assert(lpMsg->hwnd == 0);
if (lpMsg->message == DVL_WM_KEYDOWN) {
int key = lpMsg->wParam;
unsigned mod = (DWORD)lpMsg->lParam >> 16;
@ -705,7 +687,6 @@ SHORT GetAsyncKeyState(int vKey)
LRESULT DispatchMessageA(const MSG *lpMsg)
{
DUMMY_ONCE();
assert(lpMsg->hwnd == 0);
assert(CurrentProc);
// assert(CurrentProc == GM_Game);

Loading…
Cancel
Save