Skip to content

Commit 3729a95

Browse files
committed
Support for Nvidia Ansel
1 parent 8132471 commit 3729a95

22 files changed

+409
-23
lines changed

src/xrEngine/CameraBase.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,11 @@ SCamEffectorInfo::SCamEffectorInfo()
8383
n.set(0, 1, 0);
8484

8585
fFov = 90.0f;
86+
fNear = VIEWPORT_NEAR;
8687
fFar = 100.0f;
8788
fAspect = 1.f;
89+
offsetX = 0.f;
90+
offsetY = 0.f;
8891
dont_apply = false;
8992
affected_on_hud = true;
9093
}

src/xrEngine/CameraDefs.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ struct ENGINE_API SCamEffectorInfo
1919
Fvector n;
2020
Fvector r;
2121
float fFov;
22+
float fNear;
2223
float fFar;
2324
float fAspect;
25+
float offsetX; // Required for Nvidia Ansel
26+
float offsetY; // Required for Nvidia Ansel
2427
bool dont_apply;
2528
bool affected_on_hud;
2629
SCamEffectorInfo();
@@ -31,8 +34,11 @@ struct ENGINE_API SCamEffectorInfo
3134
n = other.n;
3235
r = other.r;
3336
fFov = other.fFov;
37+
fNear = other.fNear;
3438
fFar = other.fFar;
3539
fAspect = other.fAspect;
40+
offsetX = other.offsetX;
41+
offsetY = other.offsetY;
3642
dont_apply = other.dont_apply;
3743
affected_on_hud = other.affected_on_hud;
3844
return *this;
@@ -52,6 +58,7 @@ enum ECameraStyle
5258
enum ECamEffectorType
5359
{
5460
cefDemo = 0,
61+
cefAnsel,
5562
cefNext
5663
};
5764

src/xrEngine/CameraManager.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ void CCameraManager::Update(const Fvector& P, const Fvector& D, const Fvector& N
206206
clamp(src, 0.f, 1.f);
207207
float dst = 1 - src;
208208
m_cam_info.fFov = m_cam_info.fFov * dst + fFOV_Dest * src;
209+
m_cam_info.fNear = VIEWPORT_NEAR;
209210
m_cam_info.fFar = m_cam_info.fFar * dst + fFAR_Dest * src;
210211
m_cam_info.fAspect = m_cam_info.fAspect * dst + (fASPECT_Dest * aspect) * src;
211212
m_cam_info.dont_apply = false;
@@ -214,8 +215,8 @@ void CCameraManager::Update(const Fvector& P, const Fvector& D, const Fvector& N
214215

215216
UpdatePPEffectors();
216217

217-
if (false == m_cam_info.dont_apply && m_bAutoApply)
218-
ApplyDevice(VIEWPORT_NEAR);
218+
if (!m_cam_info.dont_apply && m_bAutoApply)
219+
ApplyDevice();
219220

220221
UpdateDeffered();
221222
}
@@ -313,7 +314,7 @@ void CCameraManager::UpdatePPEffectors()
313314
pp_affected.validate("after applying pp");
314315
}
315316

316-
void CCameraManager::ApplyDevice(float _viewport_near)
317+
void CCameraManager::ApplyDevice()
317318
{
318319
// Device params
319320
Device.mView.build_camera_dir(m_cam_info.p, m_cam_info.d, m_cam_info.n);
@@ -329,7 +330,7 @@ void CCameraManager::ApplyDevice(float _viewport_near)
329330

330331
//--#SM+# Begin-- +SecondVP+
331332
// Пересчитываем FOV для второго вьюпорта [Recalculate scene FOV for SecondVP frame]
332-
if (Device.m_SecondViewport.IsSVPFrame())
333+
if (Device.m_SecondViewport.IsSVPFrame() && !Device.IsAnselActive)
333334
{
334335
// Для второго вьюпорта FOV выставляем здесь
335336
Device.fFOV *= g_pGamePersistent->m_pGShaderConstants->hud_params.y;
@@ -339,10 +340,14 @@ void CCameraManager::ApplyDevice(float _viewport_near)
339340
}
340341
else
341342
Device.m_SecondViewport.isCamReady = false;
342-
343-
Device.mProject.build_projection(deg2rad(Device.fFOV), m_cam_info.fAspect, _viewport_near, m_cam_info.fFar);
344343
//--#SM+# End--
345344

345+
Device.mProject.build_projection(deg2rad(Device.fFOV), m_cam_info.fAspect, m_cam_info.fNear, m_cam_info.fFar);
346+
347+
// Apply offset required for Nvidia Ansel
348+
Device.mProject._31 = -m_cam_info.offsetX;
349+
Device.mProject._32 = -m_cam_info.offsetY;
350+
346351
if (g_pGamePersistent && g_pGamePersistent->m_pMainMenu->IsActive())
347352
ResetPP();
348353
else

src/xrEngine/CameraManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class ENGINE_API CCameraManager
6262
float fFAR_Dest, u32 flags);
6363
void UpdateFromCamera(const CCameraBase* C);
6464

65-
void ApplyDevice(float _viewport_near);
65+
void ApplyDevice();
6666
static void ResetPP();
6767

6868
CCameraManager(bool bApplyOnUpdate);

src/xrEngine/FDemoRecord.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ void CDemoRecord::IR_OnKeyboardPress(int dik)
423423
if (dik == SDL_SCANCODE_ESCAPE)
424424
fLifeTime = -1;
425425

426-
#ifdef DEBUG // ndef MASTER_GOLD // Xottab_DUTY: Teleport to demo cam in Debug configuration
426+
#ifndef MASTER_GOLD
427427
if (dik == SDL_SCANCODE_RETURN)
428428
{
429429
if (g_pGameLevel->CurrentEntity())
@@ -527,12 +527,12 @@ void CDemoRecord::IR_OnMouseHold(int btn)
527527
return;
528528
}
529529
Fvector vT_delta = Fvector().set(0, 0, 0);
530-
switch (btn)
530+
switch (MouseButtonToKey[btn])
531531
{
532-
case 0:
532+
case MOUSE_1:
533533
vT_delta.z += 1.0f;
534534
break; // Move Backward
535-
case 1:
535+
case MOUSE_2:
536536
vT_delta.z -= 1.0f;
537537
break; // Move Forward
538538
}

src/xrEngine/Stats.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static optimizer vtune;
6868
//////////////////////////////////////////////////////////////////////
6969
// Construction/Destruction
7070
//////////////////////////////////////////////////////////////////////
71-
BOOL g_bDisableRedText = FALSE;
71+
ENGINE_API BOOL g_bDisableRedText = FALSE;
7272
CStats::CStats()
7373
{
7474
statsFont = nullptr;

src/xrEngine/device.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ void CRenderDevice::on_idle()
266266
vCameraRight.crossproduct(vCameraTop, vCameraDirection);
267267
mView.build_camera_dir(vCameraPosition, vCameraDirection, vCameraTop);
268268
}
269+
269270
// Matrices
270271
mFullTransform.mul(mProject, mView);
271272
GEnv.Render->SetCacheXform(mView, mProject);
@@ -520,9 +521,10 @@ void CRenderDevice::Pause(BOOL bOn, BOOL bTimer, BOOL bSound, LPCSTR reason)
520521
{
521522
if (!Paused())
522523
{
523-
bShowPauseString = editor() ? FALSE : TRUE;
524+
if (bShowPauseString && editor())
525+
bShowPauseString = FALSE;
524526
#ifdef DEBUG
525-
if (xr_strcmp(reason, "li_pause_key_no_clip") == 0)
527+
else if (xr_strcmp(reason, "li_pause_key_no_clip") == 0)
526528
bShowPauseString = FALSE;
527529
#endif
528530
}

src/xrEngine/device.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class ENGINE_API CRenderDeviceData
7171
u32 dwPrecacheFrame;
7272
BOOL b_is_Ready;
7373
BOOL b_is_Active;
74+
bool IsAnselActive;
7475

7576
// Engine flow-control
7677
u32 dwFrame;
@@ -313,6 +314,7 @@ class ENGINE_API CRenderDevice : public CRenderDeviceBase
313314
using finalize_function_ptr = XRay::Editor::finalize_function_ptr;
314315

315316
XRay::Module m_editor_module;
317+
316318
initialize_function_ptr m_editor_initialize;
317319
finalize_function_ptr m_editor_finalize;
318320
XRay::Editor::ide_base* m_editor;

src/xrEngine/xr_input.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,15 @@ void CInput::OnFrame(void)
333333
stats.FrameTime.Begin();
334334
dwCurTime = RDEVICE.TimerAsync_MMT();
335335

336-
if (Device.dwPrecacheFrame == 0)
336+
if (Device.dwPrecacheFrame == 0 && !Device.IsAnselActive)
337337
{
338338
KeyUpdate();
339339
MouseUpdate();
340340
}
341+
else
342+
{
343+
SDL_FlushEvents(SDL_KEYDOWN, SDL_MOUSEWHEEL);
344+
}
341345

342346
stats.FrameTime.End();
343347
stats.FrameEnd();

src/xrGame/ActorCameras.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,10 @@ void CActor::cam_Update(float dt, float fFOV)
395395
if (Level().CurrentEntity() == this)
396396
{
397397
Level().Cameras().UpdateFromCamera(C);
398-
if (eacFirstEye == cam_active && !Level().Cameras().GetCamEffector(cefDemo))
398+
const bool allow = !Level().Cameras().GetCamEffector(cefDemo) && !Level().Cameras().GetCamEffector(cefAnsel);
399+
if (eacFirstEye == cam_active && allow)
399400
{
400-
Cameras().ApplyDevice(_viewport_near);
401+
Cameras().ApplyDevice();
401402
}
402403
}
403404
}

0 commit comments

Comments
 (0)