Skip to content

Commit

Permalink
Merge pull request ValveSoftware#213 from samisalreadytaken/vscript_v…
Browse files Browse the repository at this point in the history
…gui-patch

vscript vgui HUD visibility control
  • Loading branch information
Blixibon authored Nov 21, 2022
2 parents f5cf90d + 1ca7558 commit 4cc1816
Show file tree
Hide file tree
Showing 12 changed files with 337 additions and 350 deletions.
13 changes: 0 additions & 13 deletions sp/src/game/client/hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -947,11 +947,6 @@ float CHud::GetFOVSensitivityAdjust()
{
return m_flFOVSensitivityAdjust;
}

#ifdef MAPBASE_VSCRIPT
extern int g_iVScriptHideHUD;
#endif

//-----------------------------------------------------------------------------
// Purpose: Return true if the passed in sections of the HUD shouldn't be drawn
//-----------------------------------------------------------------------------
Expand All @@ -973,14 +968,6 @@ bool CHud::IsHidden( int iHudFlags )
iHideHud = hidehud.GetInt();
}

#ifdef MAPBASE_VSCRIPT
// Hide elements hidden by scripts
if ( g_iVScriptHideHUD )
{
iHideHud |= g_iVScriptHideHUD;
}
#endif

// Everything hidden?
if ( iHideHud & HIDEHUD_ALL )
return true;
Expand Down
3 changes: 3 additions & 0 deletions sp/src/game/client/hudelement.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class CHudElement : public CGameEventListener
// Hidden bits.
// HIDEHUD_ flags that note when this element should be hidden in the HUD
virtual void SetHiddenBits( int iBits );
#ifdef MAPBASE_VSCRIPT
int GetHiddenBits() const { return m_iHiddenBits; }
#endif

bool IsParentedToClientDLLRootPanel() const;
void SetParentedToClientDLLRootPanel( bool parented );
Expand Down
90 changes: 17 additions & 73 deletions sp/src/game/client/mapbase/c_func_fake_worldportal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,70 +58,11 @@ bool C_FuncFakeWorldPortal::ShouldDraw()
}


//-----------------------------------------------------------------------------
// Do we have a fake world portal in view?
//-----------------------------------------------------------------------------
C_FuncFakeWorldPortal *IsFakeWorldPortalInView( const CViewSetup& view, cplane_t &plane )
{
// Early out if no cameras
C_FuncFakeWorldPortal *pReflectiveGlass = GetFakeWorldPortalList();
if ( !pReflectiveGlass )
return NULL;

Frustum_t frustum;
GeneratePerspectiveFrustum( view.origin, view.angles, view.zNear, view.zFar, view.fov, view.m_flAspectRatio, frustum );

cplane_t localPlane;
Vector vecOrigin, vecWorld, vecDelta, vecForward;
AngleVectors( view.angles, &vecForward, NULL, NULL );

for ( ; pReflectiveGlass != NULL; pReflectiveGlass = pReflectiveGlass->m_pNext )
{
if ( pReflectiveGlass->IsDormant() )
continue;

if ( pReflectiveGlass->m_iViewHideFlags & (1 << CurrentViewID()) )
continue;

Vector vecMins, vecMaxs;
pReflectiveGlass->GetRenderBoundsWorldspace( vecMins, vecMaxs );
if ( R_CullBox( vecMins, vecMaxs, frustum ) )
continue;

const model_t *pModel = pReflectiveGlass->GetModel();
const matrix3x4_t& mat = pReflectiveGlass->EntityToWorldTransform();

int nCount = modelinfo->GetBrushModelPlaneCount( pModel );
for ( int i = 0; i < nCount; ++i )
{
modelinfo->GetBrushModelPlane( pModel, i, localPlane, &vecOrigin );

MatrixTransformPlane( mat, localPlane, plane ); // Transform to world space
VectorTransform( vecOrigin, mat, vecWorld );

if ( view.origin.Dot( plane.normal ) <= plane.dist ) // Check for view behind plane
continue;

VectorSubtract( vecWorld, view.origin, vecDelta ); // Backface cull
if ( vecDelta.Dot( plane.normal ) >= 0 )
continue;

// Must have valid plane
if ( !pReflectiveGlass->m_hTargetPlane )
continue;

return pReflectiveGlass;
}
}

return NULL;
}

//-----------------------------------------------------------------------------
// Iterates through fake world portals instead of just picking one
//-----------------------------------------------------------------------------
C_FuncFakeWorldPortal *NextFakeWorldPortal( C_FuncFakeWorldPortal *pStart, const CViewSetup& view,
cplane_t &plane, Vector &vecPlaneOrigin, const Frustum_t &frustum )
Vector &vecAbsPlaneNormal, float &flLocalPlaneDist, const Frustum_t &frustum )
{
// Early out if no cameras
C_FuncFakeWorldPortal *pReflectiveGlass = NULL;
Expand All @@ -130,8 +71,9 @@ C_FuncFakeWorldPortal *NextFakeWorldPortal( C_FuncFakeWorldPortal *pStart, const
else
pReflectiveGlass = pStart->m_pNext;

cplane_t localPlane;
Vector vecOrigin, vecWorld, vecDelta;
cplane_t localPlane, worldPlane;
Vector vecMins, vecMaxs, vecLocalOrigin, vecAbsOrigin, vecDelta;

for ( ; pReflectiveGlass != NULL; pReflectiveGlass = pReflectiveGlass->m_pNext )
{
if ( pReflectiveGlass->IsDormant() )
Expand All @@ -140,7 +82,10 @@ C_FuncFakeWorldPortal *NextFakeWorldPortal( C_FuncFakeWorldPortal *pStart, const
if ( pReflectiveGlass->m_iViewHideFlags & (1 << CurrentViewID()) )
continue;

Vector vecMins, vecMaxs;
// Must have valid plane
if ( !pReflectiveGlass->m_hTargetPlane )
continue;

pReflectiveGlass->GetRenderBoundsWorldspace( vecMins, vecMaxs );
if ( R_CullBox( vecMins, vecMaxs, frustum ) )
continue;
Expand All @@ -151,23 +96,22 @@ C_FuncFakeWorldPortal *NextFakeWorldPortal( C_FuncFakeWorldPortal *pStart, const
int nCount = modelinfo->GetBrushModelPlaneCount( pModel );
for ( int i = 0; i < nCount; ++i )
{
modelinfo->GetBrushModelPlane( pModel, i, localPlane, &vecOrigin );
modelinfo->GetBrushModelPlane( pModel, i, localPlane, &vecLocalOrigin );

MatrixTransformPlane( mat, localPlane, plane ); // Transform to world space
VectorTransform( vecOrigin, mat, vecWorld );
MatrixTransformPlane( mat, localPlane, worldPlane ); // Transform to world space

if ( view.origin.Dot( plane.normal ) <= plane.dist ) // Check for view behind plane
if ( view.origin.Dot( worldPlane.normal ) <= worldPlane.dist ) // Check for view behind plane
continue;

VectorSubtract( vecWorld, view.origin, vecDelta ); // Backface cull
if ( vecDelta.Dot( plane.normal ) >= 0 )
continue;
VectorTransform( vecLocalOrigin, mat, vecAbsOrigin );
VectorSubtract( vecAbsOrigin, view.origin, vecDelta );

// Must have valid plane
if ( !pReflectiveGlass->m_hTargetPlane )
if ( vecDelta.Dot( worldPlane.normal ) >= 0 ) // Backface cull
continue;

vecPlaneOrigin = vecOrigin;
flLocalPlaneDist = localPlane.dist;
vecAbsPlaneNormal = worldPlane.normal;

return pReflectiveGlass;
}
}
Expand Down
4 changes: 1 addition & 3 deletions sp/src/game/client/mapbase/c_func_fake_worldportal.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,8 @@ class C_FuncFakeWorldPortal : public C_BaseEntity
//-----------------------------------------------------------------------------
// Do we have reflective glass in view? If so, what's the reflection plane?
//-----------------------------------------------------------------------------
C_FuncFakeWorldPortal *IsFakeWorldPortalInView( const CViewSetup& view, cplane_t &plane );

C_FuncFakeWorldPortal *NextFakeWorldPortal( C_FuncFakeWorldPortal *pStart, const CViewSetup& view,
cplane_t &plane, Vector &vecPlaneOrigin, const Frustum_t &frustum );
Vector &vecAbsPlaneNormal, float &flLocalPlaneDist, const Frustum_t &frustum );


#endif // C_FUNC_FAKE_WORLDPORTAL
Expand Down
Loading

0 comments on commit 4cc1816

Please sign in to comment.