Skip to content

Commit

Permalink
Add and use helper class for hud rendering. Small cleanup. Fix bug fo…
Browse files Browse the repository at this point in the history
…r mapHUDSorted.
  • Loading branch information
intorr committed Feb 10, 2018
1 parent 9ab3eae commit 6b1a747
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 79 deletions.
114 changes: 40 additions & 74 deletions src/Layers/xrRender/r__dsgraph_render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,28 +342,52 @@ void D3DXRenderBase::r_dsgraph_render_graph(u32 _priority)
BasicStats.Primitives.End();
}

/*
Предназначен для установки режима отрисовки HUD и возврата оригинального после отрисовки.
*/
class hud_transform_helper
{
Fmatrix Pold;
Fmatrix FTold;

public:
hud_transform_helper()
{
extern ENGINE_API float psHUD_FOV;

// Change projection
Pold = Device.mProject;
FTold = Device.mFullTransform;
Device.mProject.build_projection(deg2rad(psHUD_FOV * Device.fFOV /* *Device.fASPECT*/), Device.fASPECT,
VIEWPORT_NEAR, g_pGamePersistent->Environment().CurrentEnv->far_plane);

Device.mFullTransform.mul(Device.mProject, Device.mView);
RCache.set_xform_project(Device.mProject);

RImplementation.rmNear();
}

~hud_transform_helper()
{
RImplementation.rmNormal();

// Restore projection
Device.mProject = Pold;
Device.mFullTransform = FTold;
RCache.set_xform_project(Device.mProject);
}
};

template <class T> IC bool cmp_first_l(const T &lhs, const T &rhs) { return (lhs.first < rhs.first); }
template <class T> IC bool cmp_first_h(const T &lhs, const T &rhs) { return (lhs.first > rhs.first); }
//////////////////////////////////////////////////////////////////////////
// HUD render
void D3DXRenderBase::r_dsgraph_render_hud()
{
extern ENGINE_API float psHUD_FOV;

PIX_EVENT(r_dsgraph_render_hud);

// Change projection
Fmatrix Pold = Device.mProject;
Fmatrix FTold = Device.mFullTransform;
Device.mProject.build_projection(deg2rad(psHUD_FOV * Device.fFOV /* *Device.fASPECT*/), Device.fASPECT,
VIEWPORT_NEAR, g_pGamePersistent->Environment().CurrentEnv->far_plane);

Device.mFullTransform.mul(Device.mProject, Device.mView);
RCache.set_xform_project(Device.mProject);
hud_transform_helper helper;

// Rendering
rmNear();
std::sort(mapHUD.begin(), mapHUD.end(), cmp_first_l<R_dsgraph::mapHUD_T::value_type>); // front-to-back
for (auto &i : mapHUD)
sorted_L1(i);
Expand All @@ -373,13 +397,6 @@ void D3DXRenderBase::r_dsgraph_render_hud()
if (g_hud && g_hud->RenderActiveItemUIQuery())
r_dsgraph_render_hud_ui(); // hud ui
#endif

rmNormal();

// Restore projection
Device.mProject = Pold;
Device.mFullTransform = FTold;
RCache.set_xform_project(Device.mProject);
}

void D3DXRenderBase::r_dsgraph_render_hud_ui()
Expand All @@ -388,16 +405,7 @@ void D3DXRenderBase::r_dsgraph_render_hud_ui()

PIX_EVENT(r_dsgraph_render_hud_ui);

extern ENGINE_API float psHUD_FOV;

// Change projection
Fmatrix Pold = Device.mProject;
Fmatrix FTold = Device.mFullTransform;
Device.mProject.build_projection(deg2rad(psHUD_FOV * Device.fFOV /* *Device.fASPECT*/), Device.fASPECT,
VIEWPORT_NEAR, g_pGamePersistent->Environment().CurrentEnv->far_plane);

Device.mFullTransform.mul(Device.mProject, Device.mView);
RCache.set_xform_project(Device.mProject);
hud_transform_helper helper;

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

rmNear();
g_hud->RenderActiveItemUI();
rmNormal();

// Restore projection
Device.mProject = Pold;
Device.mFullTransform = FTold;
RCache.set_xform_project(Device.mProject);
}

//////////////////////////////////////////////////////////////////////////
Expand All @@ -436,28 +437,12 @@ void D3DXRenderBase::r_dsgraph_render_sorted()
sorted_L1(i);
mapSorted.clear();

extern ENGINE_API float psHUD_FOV;

// Change projection
Fmatrix Pold = Device.mProject;
Fmatrix FTold = Device.mFullTransform;
Device.mProject.build_projection(deg2rad(psHUD_FOV * Device.fFOV /* *Device.fASPECT*/), Device.fASPECT,
VIEWPORT_NEAR, g_pGamePersistent->Environment().CurrentEnv->far_plane);
hud_transform_helper helper;

Device.mFullTransform.mul(Device.mProject, Device.mView);
RCache.set_xform_project(Device.mProject);

// Rendering
rmNear();
std::sort(mapHUDSorted.begin(), mapHUDSorted.end(), cmp_first_h<R_dsgraph::mapSorted_T::value_type>); // back-to-front
for (auto &i : mapHUDSorted)
sorted_L1(i);
rmNormal();

// Restore projection
Device.mProject = Pold;
Device.mFullTransform = FTold;
RCache.set_xform_project(Device.mProject);
mapHUDSorted.clear();
}

//////////////////////////////////////////////////////////////////////////
Expand All @@ -471,31 +456,12 @@ void D3DXRenderBase::r_dsgraph_render_emissive()
sorted_L1(i);
mapEmissive.clear();

// HACK: Calculate this only once

extern ENGINE_API float psHUD_FOV;
hud_transform_helper helper;

// Change projection
Fmatrix Pold = Device.mProject;
Fmatrix FTold = Device.mFullTransform;
Device.mProject.build_projection(deg2rad(psHUD_FOV * Device.fFOV /* *Device.fASPECT*/), Device.fASPECT,
VIEWPORT_NEAR, g_pGamePersistent->Environment().CurrentEnv->far_plane);

Device.mFullTransform.mul(Device.mProject, Device.mView);
RCache.set_xform_project(Device.mProject);

// Rendering
rmNear();
std::sort(mapHUDEmissive.begin(), mapHUDEmissive.end(), cmp_first_l<R_dsgraph::mapSorted_T::value_type>); // front-to-back
for (auto &i : mapHUDEmissive)
sorted_L1(i);
mapHUDEmissive.clear();
rmNormal();

// Restore projection
Device.mProject = Pold;
Device.mFullTransform = FTold;
RCache.set_xform_project(Device.mProject);
#endif
}

Expand Down
1 change: 0 additions & 1 deletion src/xrEngine/Environment_render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ const u32 v_clouds_fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_SPECULAR;
//-----------------------------------------------------------------------------
// Environment render
//-----------------------------------------------------------------------------
extern ENGINE_API float psHUD_FOV;
// BOOL bNeed_re_create_env = FALSE;
void CEnvironment::RenderSky()
{
Expand Down
4 changes: 2 additions & 2 deletions src/xrGame/Actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1619,14 +1619,14 @@ void CActor::ForceTransform(const Fmatrix& m)
character_physics_support()->movement()->BlockDamageSet(u64(block_damage_time_seconds / fixed_step));
}

ENGINE_API extern float psHUD_FOV;
//ENGINE_API extern float psHUD_FOV;
float CActor::Radius() const
{
float R = inherited::Radius();
CWeapon* W = smart_cast<CWeapon*>(inventory().ActiveItem());
if (W)
R += W->Radius();
// if (HUDview()) R *= 1.f/psHUD_FOV;
//if (HUDview()) R *= 1.f/psHUD_FOV;
return R;
}

Expand Down
2 changes: 0 additions & 2 deletions src/xrGame/HUDManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@ void CHUDManager::OnFrame()
}
//--------------------------------------------------------------------

ENGINE_API extern float psHUD_FOV;

void CHUDManager::Render_First()
{
if (!psHUD_Flags.is(HUD_WEAPON | HUD_WEAPON_RT | HUD_WEAPON_RT2 | HUD_DRAW_RT2))
Expand Down

0 comments on commit 6b1a747

Please sign in to comment.