Skip to content

Commit

Permalink
deactivate game when alt-tabbed (fixes #1)
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Mar 29, 2021
1 parent 0f73743 commit e602e36
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/global/vars.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ void (*EffectRoutines[])(ITEM_INFO *item) = {
ChainBlock, Flicker,
};

int8_t IsGameWindowActive = 1;
int32_t NoInputCount = 0;
int32_t IDelay;
int32_t IDCount;
Expand Down
1 change: 1 addition & 0 deletions src/global/vars.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ extern KEYSTUFF* KeyData;
extern char *ATIUserSettingsPath;
extern char *T1MUserSettingsPath;

extern int8_t IsGameWindowActive;
extern double UITextScale;
extern double UIBarScale;

Expand Down
7 changes: 4 additions & 3 deletions src/specific/frontend.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "specific/smain.h"
#include "util.h"

#include <dinput.h>
#include <stdlib.h>

const char *FMVPaths[] = {
Expand Down Expand Up @@ -186,13 +187,13 @@ int32_t WinPlayFMV(int32_t sequence, int32_t mode)
WinSpinMessageLoop();

if (T1MConfig.fix_fmv_esc_key) {
if (KeyData->keymap[1]) {
if (KeyData->keymap[DIK_ESCAPE]) {
keypress = 1;
} else if (keypress && !KeyData->keymap[1]) {
} else if (keypress && !KeyData->keymap[DIK_ESCAPE]) {
break;
}
} else {
if (KeyData->keymap[1]) {
if (KeyData->keymap[DIK_ESCAPE]) {
break;
}
}
Expand Down
47 changes: 40 additions & 7 deletions src/specific/smain.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,16 @@ void ShowFatalError(const char *message)
int32_t WinSpinMessageLoop()
{
MSG msg;
while (PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE)) {
if (!GetMessageA(&msg, 0, 0, 0)) {
TerminateGame(0);
do {
while (PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE)) {
if (!GetMessageA(&msg, 0, 0, 0)) {
TerminateGame(0);
}

TranslateMessage(&msg);
DispatchMessageA(&msg);
}

TranslateMessage(&msg);
DispatchMessageA(&msg);
}
} while (!IsGameWindowActive);

int32_t time_ms = timeGetTime();
int32_t old_ticks = Ticks;
Expand Down Expand Up @@ -113,20 +115,48 @@ static LRESULT WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
case WM_CLOSE:
DestroyWindow(TombHWND);
return 0;

case WM_DESTROY:
PostQuitMessage(0);
return 0;

case WM_SIZE:
return 1;

case WM_MOVE:
return 0;

case WM_SETCURSOR:
SetCursor(0);
return 1;

case WM_ERASEBKGND:
return 1;

case WM_ACTIVATEAPP:
// mute the music when the game is not active
if (wParam && !IsGameWindowActive) {
if (OptionMusicVolume) {
S_MusicVolume(OptionMusicVolume * 25 + 5);
} else {
S_MusicVolume(0);
}
} else if (!wParam && IsGameWindowActive) {
S_MusicVolume(0);
}
if (wParam && !IsGameWindowActive) {
// TODO: remove this after switching to DInput
for (int i = 0; i < 256; i++) {
KeyData->keymap[i] = 0;
}
KeyData->keys_held = 0;
}
IsGameWindowActive = wParam != 0;
return 1;

case WM_NCPAINT:
return 0;

case WM_GETMINMAXINFO: {
MINMAXINFO *min_max_info = (MINMAXINFO *)lParam;
min_max_info->ptMinTrackSize.x = DDrawSurfaceWidth;
Expand All @@ -136,12 +166,15 @@ static LRESULT WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
return DefWindowProcA(
hWnd, WM_GETMINMAXINFO, wParam, (LPARAM)min_max_info);
}

case WM_MOVING:
GetWindowRect(TombHWND, (LPRECT)lParam);
return 1;

case MM_MCINOTIFY:
MusicPlayLooped();
return 0;

default:
return DefWindowProcA(hWnd, uMsg, wParam, lParam);
}
Expand Down

0 comments on commit e602e36

Please sign in to comment.