Skip to content

Commit cfafdfd

Browse files
committed
Allow game to be active when window is inactive (configurable)
Also fixed some issues with cursor manipulation
1 parent dacfb31 commit cfafdfd

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

src/xrEngine/device.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "xrSASH.h"
2626
#include "IGame_Persistent.h"
2727
#include "xrScriptEngine/ScriptExporter.hpp"
28+
#include "xr_input.h"
2829

2930
ENGINE_API CRenderDevice Device;
3031
ENGINE_API CLoadScreenRenderer load_screen_renderer;
@@ -444,23 +445,35 @@ BOOL CRenderDevice::Paused() { return g_pauseMngr()->Paused(); }
444445
void CRenderDevice::OnWM_Activate(WPARAM wParam, LPARAM /*lParam*/)
445446
{
446447
u16 fActive = LOWORD(wParam);
447-
BOOL fMinimized = (BOOL)HIWORD(wParam);
448-
BOOL bActive = ((fActive != WA_INACTIVE) && (!fMinimized)) ? TRUE : FALSE;
449-
if (bActive != Device.b_is_Active)
448+
const BOOL fMinimized = (BOOL)HIWORD(wParam);
449+
450+
const BOOL isWndActive = (fActive != WA_INACTIVE && !fMinimized) ? TRUE : FALSE;
451+
if (!editor() && !GEnv.isDedicatedServer && isWndActive)
452+
{
453+
pInput->ClipCursor(true);
454+
ShowCursor(FALSE);
455+
}
456+
else
457+
{
458+
pInput->ClipCursor(false);
459+
ShowCursor(TRUE);
460+
}
461+
462+
extern int ps_always_active;
463+
const BOOL isGameActive = ps_always_active || isWndActive;
464+
465+
if (isGameActive != Device.b_is_Active)
450466
{
451-
Device.b_is_Active = bActive;
467+
Device.b_is_Active = isGameActive;
452468
if (Device.b_is_Active)
453469
{
454470
Device.seqAppActivate.Process(rp_AppActivate);
455471
app_inactive_time += TimerMM.GetElapsed_ms() - app_inactive_time_start;
456-
if (!editor() && !GEnv.isDedicatedServer)
457-
ShowCursor(FALSE);
458472
}
459473
else
460474
{
461475
app_inactive_time_start = TimerMM.GetElapsed_ms();
462476
Device.seqAppDeactivate.Process(rp_AppDeactivate);
463-
ShowCursor(TRUE);
464477
}
465478
}
466479
}

src/xrEngine/xr_ioc_cmd.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,8 @@ extern Flags32 psEnvFlags;
627627

628628
extern int g_ErrorLineCount;
629629

630+
ENGINE_API int ps_always_active = 0;
631+
630632
ENGINE_API int ps_r__Supersample = 1;
631633
void CCC_Register()
632634
{
@@ -734,6 +736,8 @@ void CCC_Register()
734736
CMD2(CCC_Float, "cam_inert", &psCamInert);
735737
CMD2(CCC_Float, "cam_slide_inert", &psCamSlideInert);
736738

739+
CMD4(CCC_Integer, "always_active", &ps_always_active, 0, 1);
740+
737741
CMD1(CCC_r2, "renderer");
738742

739743
if (!GEnv.isDedicatedServer)

0 commit comments

Comments
 (0)