Skip to content

Commit 6b1a747

Browse files
committed
Add and use helper class for hud rendering. Small cleanup. Fix bug for mapHUDSorted.
1 parent 9ab3eae commit 6b1a747

File tree

4 files changed

+42
-79
lines changed

4 files changed

+42
-79
lines changed

src/Layers/xrRender/r__dsgraph_render.cpp

Lines changed: 40 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -342,28 +342,52 @@ void D3DXRenderBase::r_dsgraph_render_graph(u32 _priority)
342342
BasicStats.Primitives.End();
343343
}
344344

345+
/*
346+
Предназначен для установки режима отрисовки HUD и возврата оригинального после отрисовки.
347+
*/
348+
class hud_transform_helper
349+
{
350+
Fmatrix Pold;
351+
Fmatrix FTold;
352+
353+
public:
354+
hud_transform_helper()
355+
{
356+
extern ENGINE_API float psHUD_FOV;
357+
358+
// Change projection
359+
Pold = Device.mProject;
360+
FTold = Device.mFullTransform;
361+
Device.mProject.build_projection(deg2rad(psHUD_FOV * Device.fFOV /* *Device.fASPECT*/), Device.fASPECT,
362+
VIEWPORT_NEAR, g_pGamePersistent->Environment().CurrentEnv->far_plane);
363+
364+
Device.mFullTransform.mul(Device.mProject, Device.mView);
365+
RCache.set_xform_project(Device.mProject);
366+
367+
RImplementation.rmNear();
368+
}
369+
370+
~hud_transform_helper()
371+
{
372+
RImplementation.rmNormal();
373+
374+
// Restore projection
375+
Device.mProject = Pold;
376+
Device.mFullTransform = FTold;
377+
RCache.set_xform_project(Device.mProject);
378+
}
379+
};
345380

346381
template <class T> IC bool cmp_first_l(const T &lhs, const T &rhs) { return (lhs.first < rhs.first); }
347382
template <class T> IC bool cmp_first_h(const T &lhs, const T &rhs) { return (lhs.first > rhs.first); }
348383
//////////////////////////////////////////////////////////////////////////
349384
// HUD render
350385
void D3DXRenderBase::r_dsgraph_render_hud()
351386
{
352-
extern ENGINE_API float psHUD_FOV;
353-
354387
PIX_EVENT(r_dsgraph_render_hud);
355388

356-
// Change projection
357-
Fmatrix Pold = Device.mProject;
358-
Fmatrix FTold = Device.mFullTransform;
359-
Device.mProject.build_projection(deg2rad(psHUD_FOV * Device.fFOV /* *Device.fASPECT*/), Device.fASPECT,
360-
VIEWPORT_NEAR, g_pGamePersistent->Environment().CurrentEnv->far_plane);
361-
362-
Device.mFullTransform.mul(Device.mProject, Device.mView);
363-
RCache.set_xform_project(Device.mProject);
389+
hud_transform_helper helper;
364390

365-
// Rendering
366-
rmNear();
367391
std::sort(mapHUD.begin(), mapHUD.end(), cmp_first_l<R_dsgraph::mapHUD_T::value_type>); // front-to-back
368392
for (auto &i : mapHUD)
369393
sorted_L1(i);
@@ -373,13 +397,6 @@ void D3DXRenderBase::r_dsgraph_render_hud()
373397
if (g_hud && g_hud->RenderActiveItemUIQuery())
374398
r_dsgraph_render_hud_ui(); // hud ui
375399
#endif
376-
377-
rmNormal();
378-
379-
// Restore projection
380-
Device.mProject = Pold;
381-
Device.mFullTransform = FTold;
382-
RCache.set_xform_project(Device.mProject);
383400
}
384401

385402
void D3DXRenderBase::r_dsgraph_render_hud_ui()
@@ -388,16 +405,7 @@ void D3DXRenderBase::r_dsgraph_render_hud_ui()
388405

389406
PIX_EVENT(r_dsgraph_render_hud_ui);
390407

391-
extern ENGINE_API float psHUD_FOV;
392-
393-
// Change projection
394-
Fmatrix Pold = Device.mProject;
395-
Fmatrix FTold = Device.mFullTransform;
396-
Device.mProject.build_projection(deg2rad(psHUD_FOV * Device.fFOV /* *Device.fASPECT*/), Device.fASPECT,
397-
VIEWPORT_NEAR, g_pGamePersistent->Environment().CurrentEnv->far_plane);
398-
399-
Device.mFullTransform.mul(Device.mProject, Device.mView);
400-
RCache.set_xform_project(Device.mProject);
408+
hud_transform_helper helper;
401409

402410
#if RENDER != R_R1
403411
// Targets, use accumulator for temporary storage
@@ -416,14 +424,7 @@ void D3DXRenderBase::r_dsgraph_render_hud_ui()
416424
rt_null, rt_null, zb);
417425
#endif // RENDER!=R_R1
418426

419-
rmNear();
420427
g_hud->RenderActiveItemUI();
421-
rmNormal();
422-
423-
// Restore projection
424-
Device.mProject = Pold;
425-
Device.mFullTransform = FTold;
426-
RCache.set_xform_project(Device.mProject);
427428
}
428429

429430
//////////////////////////////////////////////////////////////////////////
@@ -436,28 +437,12 @@ void D3DXRenderBase::r_dsgraph_render_sorted()
436437
sorted_L1(i);
437438
mapSorted.clear();
438439

439-
extern ENGINE_API float psHUD_FOV;
440-
441-
// Change projection
442-
Fmatrix Pold = Device.mProject;
443-
Fmatrix FTold = Device.mFullTransform;
444-
Device.mProject.build_projection(deg2rad(psHUD_FOV * Device.fFOV /* *Device.fASPECT*/), Device.fASPECT,
445-
VIEWPORT_NEAR, g_pGamePersistent->Environment().CurrentEnv->far_plane);
440+
hud_transform_helper helper;
446441

447-
Device.mFullTransform.mul(Device.mProject, Device.mView);
448-
RCache.set_xform_project(Device.mProject);
449-
450-
// Rendering
451-
rmNear();
452442
std::sort(mapHUDSorted.begin(), mapHUDSorted.end(), cmp_first_h<R_dsgraph::mapSorted_T::value_type>); // back-to-front
453443
for (auto &i : mapHUDSorted)
454444
sorted_L1(i);
455-
rmNormal();
456-
457-
// Restore projection
458-
Device.mProject = Pold;
459-
Device.mFullTransform = FTold;
460-
RCache.set_xform_project(Device.mProject);
445+
mapHUDSorted.clear();
461446
}
462447

463448
//////////////////////////////////////////////////////////////////////////
@@ -471,31 +456,12 @@ void D3DXRenderBase::r_dsgraph_render_emissive()
471456
sorted_L1(i);
472457
mapEmissive.clear();
473458

474-
// HACK: Calculate this only once
475-
476-
extern ENGINE_API float psHUD_FOV;
459+
hud_transform_helper helper;
477460

478-
// Change projection
479-
Fmatrix Pold = Device.mProject;
480-
Fmatrix FTold = Device.mFullTransform;
481-
Device.mProject.build_projection(deg2rad(psHUD_FOV * Device.fFOV /* *Device.fASPECT*/), Device.fASPECT,
482-
VIEWPORT_NEAR, g_pGamePersistent->Environment().CurrentEnv->far_plane);
483-
484-
Device.mFullTransform.mul(Device.mProject, Device.mView);
485-
RCache.set_xform_project(Device.mProject);
486-
487-
// Rendering
488-
rmNear();
489461
std::sort(mapHUDEmissive.begin(), mapHUDEmissive.end(), cmp_first_l<R_dsgraph::mapSorted_T::value_type>); // front-to-back
490462
for (auto &i : mapHUDEmissive)
491463
sorted_L1(i);
492464
mapHUDEmissive.clear();
493-
rmNormal();
494-
495-
// Restore projection
496-
Device.mProject = Pold;
497-
Device.mFullTransform = FTold;
498-
RCache.set_xform_project(Device.mProject);
499465
#endif
500466
}
501467

src/xrEngine/Environment_render.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ const u32 v_clouds_fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_SPECULAR;
8787
//-----------------------------------------------------------------------------
8888
// Environment render
8989
//-----------------------------------------------------------------------------
90-
extern ENGINE_API float psHUD_FOV;
9190
// BOOL bNeed_re_create_env = FALSE;
9291
void CEnvironment::RenderSky()
9392
{

src/xrGame/Actor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,14 +1619,14 @@ void CActor::ForceTransform(const Fmatrix& m)
16191619
character_physics_support()->movement()->BlockDamageSet(u64(block_damage_time_seconds / fixed_step));
16201620
}
16211621

1622-
ENGINE_API extern float psHUD_FOV;
1622+
//ENGINE_API extern float psHUD_FOV;
16231623
float CActor::Radius() const
16241624
{
16251625
float R = inherited::Radius();
16261626
CWeapon* W = smart_cast<CWeapon*>(inventory().ActiveItem());
16271627
if (W)
16281628
R += W->Radius();
1629-
// if (HUDview()) R *= 1.f/psHUD_FOV;
1629+
//if (HUDview()) R *= 1.f/psHUD_FOV;
16301630
return R;
16311631
}
16321632

src/xrGame/HUDManager.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,6 @@ void CHUDManager::OnFrame()
153153
}
154154
//--------------------------------------------------------------------
155155

156-
ENGINE_API extern float psHUD_FOV;
157-
158156
void CHUDManager::Render_First()
159157
{
160158
if (!psHUD_Flags.is(HUD_WEAPON | HUD_WEAPON_RT | HUD_WEAPON_RT2 | HUD_DRAW_RT2))

0 commit comments

Comments
 (0)