Skip to content

Commit

Permalink
Allow game to be active when window is inactive (configurable)
Browse files Browse the repository at this point in the history
Also fixed some issues with cursor manipulation
  • Loading branch information
Xottab-DUTY committed Feb 10, 2018
1 parent dacfb31 commit cfafdfd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/xrEngine/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "xrSASH.h"
#include "IGame_Persistent.h"
#include "xrScriptEngine/ScriptExporter.hpp"
#include "xr_input.h"

ENGINE_API CRenderDevice Device;
ENGINE_API CLoadScreenRenderer load_screen_renderer;
Expand Down Expand Up @@ -444,23 +445,35 @@ BOOL CRenderDevice::Paused() { return g_pauseMngr()->Paused(); }
void CRenderDevice::OnWM_Activate(WPARAM wParam, LPARAM /*lParam*/)
{
u16 fActive = LOWORD(wParam);
BOOL fMinimized = (BOOL)HIWORD(wParam);
BOOL bActive = ((fActive != WA_INACTIVE) && (!fMinimized)) ? TRUE : FALSE;
if (bActive != Device.b_is_Active)
const BOOL fMinimized = (BOOL)HIWORD(wParam);

const BOOL isWndActive = (fActive != WA_INACTIVE && !fMinimized) ? TRUE : FALSE;
if (!editor() && !GEnv.isDedicatedServer && isWndActive)
{
pInput->ClipCursor(true);
ShowCursor(FALSE);
}
else
{
pInput->ClipCursor(false);
ShowCursor(TRUE);
}

extern int ps_always_active;
const BOOL isGameActive = ps_always_active || isWndActive;

if (isGameActive != Device.b_is_Active)
{
Device.b_is_Active = bActive;
Device.b_is_Active = isGameActive;
if (Device.b_is_Active)
{
Device.seqAppActivate.Process(rp_AppActivate);
app_inactive_time += TimerMM.GetElapsed_ms() - app_inactive_time_start;
if (!editor() && !GEnv.isDedicatedServer)
ShowCursor(FALSE);
}
else
{
app_inactive_time_start = TimerMM.GetElapsed_ms();
Device.seqAppDeactivate.Process(rp_AppDeactivate);
ShowCursor(TRUE);
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/xrEngine/xr_ioc_cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,8 @@ extern Flags32 psEnvFlags;

extern int g_ErrorLineCount;

ENGINE_API int ps_always_active = 0;

ENGINE_API int ps_r__Supersample = 1;
void CCC_Register()
{
Expand Down Expand Up @@ -734,6 +736,8 @@ void CCC_Register()
CMD2(CCC_Float, "cam_inert", &psCamInert);
CMD2(CCC_Float, "cam_slide_inert", &psCamSlideInert);

CMD4(CCC_Integer, "always_active", &ps_always_active, 0, 1);

CMD1(CCC_r2, "renderer");

if (!GEnv.isDedicatedServer)
Expand Down

0 comments on commit cfafdfd

Please sign in to comment.