Skip to content

Commit 2420205

Browse files
committed
Ultra wide screen restriction code refactoring and improvements:
1. Refactored ultra-wide screen mouse restriction code: Moved the main detection logic to asw_hud_master::OnThink() and reduced cpu load. Moved drawing code to asw_hud_master::Paint(). 2. Add two new CVARs: 2.1 rd_draw_restricted_rectangles_coop (FCVAR_ARCHIVE | FCVAR_REPLICATED | FCVAR_NOTIFY) 2.2 rd_draw_restricted_rectangles_dm (FCVAR_ARCHIVE | FCVAR_REPLICATED | FCVAR_CHEAT | FCVAR_NOTIFY) 2.3 Purpose: Fill extra side FOVs with black on ultra-wide resolutions in coop / DM mode. 3. Move marine / weapon icons into the 16:9 area. 4. Move mission objectives into the 16:9 area. 5. Adapt 3D marine labels for ultra-wide screens accroding to different CVAR settings.
1 parent 3f55ae9 commit 2420205

6 files changed

Lines changed: 90 additions & 50 deletions

File tree

reactivedrop/resource/challenges/rd_first_person.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66

77
"convars" {
88
"asw_controls" "0"
9+
"rd_draw_restricted_rectangles_coop" "0"
910
}
1011
}

reactivedrop/resource/challenges/rd_third_person.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66

77
"convars" {
88
"asw_controls" "2"
9+
"rd_draw_restricted_rectangles_coop" "0"
910
}
1011
}

src/game/client/swarm/asw_in_mouse.cpp

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@
1515
// memdbgon must be the last include file in a .cpp file!!!
1616
#include "tier0/memdbgon.h"
1717

18-
bool g_ultra_wide_screen = false;
19-
Rect_t g_clamp_area = {};
18+
// restricted area variables
19+
extern int g_nRestrictedAreaLeft;
20+
extern int g_nRestrictedAreaRight;
21+
extern int g_nScreenAreaWidth;
22+
extern int g_nScreenAreaHeight;
23+
extern bool g_bUltraWideScreen;
2024

2125
ConVar glow_outline_color_active( "glow_outline_color_active", "153 153 204", FCVAR_NONE );
2226
ConVar glow_outline_color_inactive( "glow_outline_color_inactive", "77 77 77", FCVAR_NONE );
@@ -89,33 +93,11 @@ void CASWInput::ApplyMouse( int nSlot, QAngle& viewangles, CUserCmd *cmd, float
8993
GetMousePos(current_posx, current_posy);
9094

9195
// restrict cursor to 16:9 area to prevent ultra-wide fov cheat
92-
g_ultra_wide_screen = false;
9396
C_ASW_Player* asw_player = C_ASW_Player::GetLocalASWPlayer();
9497

95-
if (asw_player && !asw_player->GetSpectatingNPC()) {
96-
int screen_w = ScreenWidth();
97-
int screen_h = ScreenHeight();
98-
float aspect = static_cast<float>(screen_w) / screen_h;
99-
100-
constexpr float ratio169 = 16.0f / 9.0f;
101-
102-
if (aspect > ratio169) {
103-
g_ultra_wide_screen = true;
104-
105-
int target_h = screen_h;
106-
int target_w = static_cast<int>(screen_h * ratio169);
107-
108-
int left = (screen_w - target_w) / 2;
109-
int top = 0;
110-
111-
g_clamp_area.x = left;
112-
g_clamp_area.y = top;
113-
g_clamp_area.width = left + target_w;
114-
g_clamp_area.height = top + target_h;
115-
116-
current_posx = clamp(current_posx, g_clamp_area.x, g_clamp_area.width);
117-
current_posy = clamp(current_posy, g_clamp_area.y, g_clamp_area.height);
118-
}
98+
if (asw_player && !asw_player->GetSpectatingNPC())
99+
{
100+
current_posx = clamp(current_posx, g_nRestrictedAreaLeft, g_nRestrictedAreaRight);
119101
}
120102

121103
if ( ASWInput()->ControllerModeActiveMouse() )

src/game/client/swarm/vgui/asw_hud_3dmarinenames.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@
4646
// memdbgon must be the last include file in a .cpp file!!!
4747
#include "tier0/memdbgon.h"
4848

49+
// restricted area variables and cvars
50+
extern int g_nRestrictedAreaLeft;
51+
extern bool g_bUltraWideScreen;
52+
extern ConVar rd_draw_restricted_rectangles_coop;
53+
extern ConVar rd_draw_restricted_rectangles_dm;
54+
4955
extern ConVar asw_draw_hud;
5056
extern ConVar asw_hud_alpha;
5157
extern ConVar asw_DebugAutoAim;
@@ -610,8 +616,14 @@ void CASWHud3DMarineNames::PaintMarineLabel( int iMyMarineNum, C_ASW_Marine *RES
610616
*/
611617
// the presence or absence and size of these elements depends on a variety of factors.
612618
// first, is the marine on screen?
613-
bool bMarineOnScreen = ( screenPos.x >= 0 ) && ( screenPos.x <= nMaxX ) &&
614-
( screenPos.y >= 0 ) && ( screenPos.y <= nMaxY );
619+
bool bMarineOnScreen = (screenPos.x >= 0) && (screenPos.x <= nMaxX) &&
620+
(screenPos.y >= 0) && (screenPos.y <= nMaxY);
621+
int nRestrictedAreaOffset = 0;
622+
if (g_bUltraWideScreen && ((rd_draw_restricted_rectangles_coop.GetBool() && !ASWDeathmatchMode()) || (rd_draw_restricted_rectangles_dm.GetBool() && ASWDeathmatchMode()))) {
623+
bMarineOnScreen = (screenPos.x >= g_nRestrictedAreaLeft) && (screenPos.x <= nMaxX - g_nRestrictedAreaLeft) &&
624+
(screenPos.y >= 0) && (screenPos.y <= nMaxY);
625+
nRestrictedAreaOffset = g_nRestrictedAreaLeft;
626+
}
615627

616628
// COPYPASTA: if the marine isn't on screen, compute an appropriate screen point to use
617629
// (don't just clip to screen coords, which makes direction change inappropriately)
@@ -720,14 +732,14 @@ void CASWHud3DMarineNames::PaintMarineLabel( int iMyMarineNum, C_ASW_Marine *RES
720732
int nBoxCenterY = screenPos.y + nTotalBoxHeight / 2;
721733

722734
// if off to the left, push to the right
723-
if ( nBoxCenterX - ( nTotalBoxWidth / 2 ) < nMinX )
735+
if ( nBoxCenterX - ( nTotalBoxWidth / 2 ) < nMinX + nRestrictedAreaOffset)
724736
{
725-
nBoxCenterX -= nBoxCenterX - ( nTotalBoxWidth / 2 ) - nMinX;
737+
nBoxCenterX -= nBoxCenterX - ( nTotalBoxWidth / 2 ) - nMinX - nRestrictedAreaOffset;
726738
}
727-
else if ( nBoxCenterX + ( nTotalBoxWidth / 2 ) >= nMaxX )
739+
else if ( nBoxCenterX + ( nTotalBoxWidth / 2 ) >= nMaxX - nRestrictedAreaOffset)
728740
// if off to the right, push to the left
729741
{
730-
nBoxCenterX -= nBoxCenterX + ( nTotalBoxWidth / 2 ) - nMaxX;
742+
nBoxCenterX -= nBoxCenterX + ( nTotalBoxWidth / 2 ) - nMaxX + nRestrictedAreaOffset;
731743
}
732744

733745
// if too high, push down
@@ -817,7 +829,7 @@ void CASWHud3DMarineNames::PaintMarineLabel( int iMyMarineNum, C_ASW_Marine *RES
817829
// actual text
818830
vgui::surface()->DrawSetTextColor( MarineNameColor1.r(), MarineNameColor1.g(), MarineNameColor1.b(), 200 );
819831
vgui::surface()->DrawSetTextPos( nTextPosX, nCursorY );
820-
vgui::surface()->DrawUnicodeString( wszName );
832+
vgui::surface()->DrawUnicodeString(wszName);
821833

822834
// advance cursor
823835
nCursorY += nMarineNameHeight + MAX( nLineSpacing, YRES( 2 ) );

src/game/client/swarm/vgui/asw_hud_master.cpp

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,17 @@ ConVar rd_draw_timer( "rd_draw_timer", "0", FCVAR_ARCHIVE, "Display the current
4545
ConVar rd_draw_timer_color( "rd_draw_timer_color", "255 255 255 255", FCVAR_ARCHIVE, "The color of the current mission time" );
4646
ConVar rd_draw_marine_health_counter( "rd_draw_marine_health_counter", "0", FCVAR_ARCHIVE, "Display a numeric counter for marine health on the HUD" );
4747

48+
// restricted area variables
49+
int g_nRestrictedAreaLeft;
50+
int g_nRestrictedAreaRight;
51+
int g_nScreenAreaWidth;
52+
int g_nScreenAreaHeight;
53+
bool g_bUltraWideScreen;
54+
// restricted area cvars
4855
ConVar rd_draw_restricted_borders( "rd_draw_restricted_borders", "1", FCVAR_ARCHIVE, "Display the restricted cursor area when using ultra-wide resolution" );
4956
ConVar rd_draw_restricted_borders_color("rd_draw_restricted_borders_color", "128 128 128 128", 0, "Color of the restricted cursor area borders");
57+
ConVar rd_draw_restricted_rectangles_coop("rd_draw_restricted_rectangles_coop", "1", FCVAR_ARCHIVE | FCVAR_REPLICATED | FCVAR_NOTIFY, "Fill extra side FOVs with black on ultra-wide resolution in coop mode.");
58+
ConVar rd_draw_restricted_rectangles_dm("rd_draw_restricted_rectangles_dm", "1", FCVAR_ARCHIVE | FCVAR_REPLICATED | FCVAR_CHEAT | FCVAR_NOTIFY, "Fill extra side FOVs with black on ultra-wide resolution in deathmatch mode.");
5059

5160
using namespace vgui;
5261

@@ -152,16 +161,18 @@ void CASW_Hud_Master::OnThink()
152161

153162
C_ASW_Player *pPlayer = C_ASW_Player::GetLocalASWPlayer();
154163

155-
if ( !pPlayer || !ASWGameResource() )
164+
if (!pPlayer || !ASWGameResource())
165+
{
156166
return;
167+
}
157168

158169
if ( ASWDeathmatchMode() )
159170
{
160171
int nFrags[ASW_MAX_MARINE_RESOURCES];
161-
for ( int i = 0; i < ASW_MAX_MARINE_RESOURCES; i++ )
172+
for (int i = 0; i < ASW_MAX_MARINE_RESOURCES; i++)
162173
{
163-
C_ASW_Marine_Resource *pMR = ASWGameResource()->GetMarineResource( i );
164-
nFrags[i] = pMR ? ASWDeathmatchMode()->GetFragCount( pMR ) : INT_MIN;
174+
C_ASW_Marine_Resource* pMR = ASWGameResource()->GetMarineResource(i);
175+
nFrags[i] = pMR ? ASWDeathmatchMode()->GetFragCount(pMR) : INT_MIN;
165176
}
166177

167178
for ( int i = 0; i < NELEMS( m_nMostFrags ); i++ )
@@ -198,7 +209,7 @@ void CASW_Hud_Master::OnThink()
198209
}
199210
}
200211

201-
if ( m_nMostFrags[i] == -1 )
212+
if (m_nMostFrags[i] == -1)
202213
{
203214
break;
204215
}
@@ -398,7 +409,6 @@ void CASW_Hud_Master::OnThink()
398409
m_SquadMateInfo[ nPosition ].nClips = 0;
399410
m_SquadMateInfo[ nPosition ].bClipsDoubled = false;
400411
m_SquadMateInfo[ nPosition ].flAmmoFraction = 0;
401-
//Msg( "Setting squadmate %d ammo to zero 2\n", nPosition );
402412
}
403413

404414
nPosition++;
@@ -434,6 +444,25 @@ void CASW_Hud_Master::OnThink()
434444
StopItemFX( pMarine, -1 );
435445
}
436446
}
447+
448+
g_nScreenAreaWidth = ScreenWidth();
449+
g_nScreenAreaHeight = ScreenHeight();
450+
int nStandardWidth = (int)(g_nScreenAreaHeight * 16.0f / 9.0f ) + 1;
451+
if (g_nScreenAreaWidth > nStandardWidth)
452+
{
453+
g_nRestrictedAreaLeft = nStandardWidth >> 1;
454+
g_nRestrictedAreaRight = g_nScreenAreaWidth - (nStandardWidth >> 1);
455+
g_bUltraWideScreen = true;
456+
m_nMarinePortrait_x = g_nRestrictedAreaLeft;
457+
}
458+
else
459+
{
460+
g_nRestrictedAreaLeft = 0;
461+
g_nRestrictedAreaRight = g_nScreenAreaWidth;
462+
g_bUltraWideScreen = false;
463+
m_nMarinePortrait_x = 0;
464+
}
465+
437466
}
438467

439468
void CASW_Hud_Master::Paint( void )
@@ -486,15 +515,27 @@ void CASW_Hud_Master::Paint( void )
486515

487516
if ( m_pLocalMarineResource )
488517
{
518+
// Block extra side FOVs
519+
if (g_bUltraWideScreen && ((rd_draw_restricted_rectangles_coop.GetBool() && !ASWDeathmatchMode()) || (rd_draw_restricted_rectangles_dm.GetBool() && ASWDeathmatchMode())) && !pPlayer->GetSpectatingNPC()) {
520+
// (0,0)-----(L,0) (R,0)-----(W,0)
521+
// |//////////| |/////////|
522+
// |//////////| |/////////|
523+
// (0,H)-----(L,H) (R,H)-----(W,H)
524+
surface()->DrawSetColor(Color(0, 0, 0, 255));
525+
surface()->DrawFilledRect(0, 0, g_nRestrictedAreaLeft, g_nScreenAreaHeight);
526+
surface()->DrawFilledRect(g_nRestrictedAreaRight, 0, g_nScreenAreaWidth, g_nScreenAreaHeight);
527+
//Msg("%d\t%d\n", x1, x2);
528+
}
529+
489530
// draw restricted borders for ultra-wide screen
490-
if (rd_draw_restricted_borders.GetBool() && g_ultra_wide_screen && !pPlayer->GetSpectatingNPC()) {
491-
// (x,y)-----------(w,y)
531+
if (g_bUltraWideScreen && rd_draw_restricted_borders.GetBool() && !pPlayer->GetSpectatingNPC()) {
532+
// (L,0)-----------(R,0)
492533
// | |
493534
// | |
494-
// (x,h)-----------(w,h)
535+
// (L,H)-----------(R,H)
495536
surface()->DrawSetColor(rd_draw_restricted_borders_color.GetColor());
496-
surface()->DrawLine(g_clamp_area.x, g_clamp_area.y, g_clamp_area.x, g_clamp_area.height);
497-
surface()->DrawLine(g_clamp_area.width, g_clamp_area.y, g_clamp_area.width, g_clamp_area.height);
537+
surface()->DrawLine(g_nRestrictedAreaLeft, 0, g_nRestrictedAreaLeft, g_nScreenAreaHeight);
538+
surface()->DrawLine(g_nRestrictedAreaRight, 0, g_nRestrictedAreaRight, g_nScreenAreaHeight);
498539
}
499540

500541
C_ASW_Marine_Resource *pMR = m_pLocalMarineResource;
@@ -1119,7 +1160,7 @@ void CASW_Hud_Master::PaintLocalMarineInventory()
11191160
surface()->DrawSetColor( 66, 142, 192, 255 ); // light blue
11201161
}
11211162
surface()->DrawSetTexture( pWeapon->GetUseIconTextureID() );
1122-
int x = YRES( pInfo->m_iHUDIconOffsetX );
1163+
int x = YRES( pInfo->m_iHUDIconOffsetX ) + m_nMarinePortrait_x;
11231164
int y = YRES( pInfo->m_iHUDIconOffsetY );
11241165
int w = m_nWeapon_w;
11251166
int t = m_nWeapon_t;

src/game/client/swarm/vgui/asw_hud_objective.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
// memdbgon must be the last include file in a .cpp file!!!
2929
#include "tier0/memdbgon.h"
3030

31+
// restricted area variables
32+
extern int g_nRestrictedAreaLeft;
33+
3134
extern ConVar asw_draw_hud;
3235
extern ConVar asw_hud_alpha;
3336
extern ConVar rd_points_delay;
@@ -42,7 +45,7 @@ using namespace vgui;
4245

4346
#define LETTER_INTERVAL 0.05f
4447

45-
DECLARE_HUDELEMENT( CASWHudObjective );
48+
DECLARE_HUDELEMENT_DEPTH( CASWHudObjective, 45 );
4649

4750

4851
static void MsgFunc_ShowObjectives( bf_read &msg )
@@ -185,7 +188,7 @@ void CASWHudObjective::Paint( void )
185188
m_pHeaderLabel->GetPos(tx, ty);
186189
float fScale = ScreenWidth() / 1024.0f;
187190
int width = 213 * fScale;
188-
int left_side = tx - 4.0f * fScale;
191+
int left_side = tx - 4.0f * fScale + g_nRestrictedAreaLeft;
189192
int top = ty - 4.0f * fScale;
190193
int height = th + 8.0f * fScale;
191194
vgui::Vertex_t points[4] =
@@ -247,7 +250,7 @@ void CASWHudObjective::Paint( void )
247250
BaseClass::Paint();
248251

249252
// allow custom painting
250-
int ob_x = 0;
253+
int ob_x = g_nRestrictedAreaLeft;
251254
int ob_y = 0;
252255
for (int i=0;i<ASW_MAX_OBJECTIVES;i++)
253256
{
@@ -452,7 +455,7 @@ void CASWHudObjective::LayoutObjectives()
452455
float fScale = (ScreenHeight() / 768.0f) * asw_hud_scale.GetFloat();
453456
int icon_size = 16.0f * fScale;
454457
int tick_size = 16.0f * fScale;
455-
int border = 14.0f * fScale;
458+
int border = 14.0f * fScale + g_nRestrictedAreaLeft;
456459
int label_x = border + tick_size + icon_size;
457460
int font_tall = vgui::surface()->GetFontTall(m_font);
458461
int header_y = 14.0f * fScale;

0 commit comments

Comments
 (0)