Skip to content

Commit 3bcd481

Browse files
committed
Separate crosshair for pistol+shotgun and hipfire
Removed hipfire convar and now part of crosshair bit-flag in serialization. Separate crosshair for secondary/pistols and shotguns, the others (SMGs, rifles, and machine guns) only for default crosshair. Grenades, knife, and snipers never gets the normal crosshair. DONE: * Compress non-default by default crosshair * Run-length encode multiple empty ;;;;... * Maybe more general enum for weapon types * Check longest possible serialization string CURRENT: * Unit test serialization cross versions + compression, and some functions * fixes #661
1 parent 8809532 commit 3bcd481

49 files changed

Lines changed: 2470 additions & 458 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ out
99

1010
/src/CMakeSettings.json
1111

12+
# ctest
13+
/src/Testing
14+
1215
# Possible symlink for fixing tools that hardcode "game/mod_hl2mp" - we use "game/neo".
1316
/game/mod_hl2mp
1417

src/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,3 +602,6 @@ if(NEO_EXTRA_ASSETS)
602602
"${neo_assets_SOURCE_DIR}/neo"
603603
"${CMAKE_SOURCE_DIR}/../game/neo")
604604
endif()
605+
606+
add_subdirectory(tests)
607+

src/game/client/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,6 +1656,8 @@ target_sources_grouped(
16561656
${CMAKE_SOURCE_DIR}/game/shared/neo/neo_enums.h
16571657
${CMAKE_SOURCE_DIR}/game/shared/neo/neo_crosshair.cpp
16581658
${CMAKE_SOURCE_DIR}/game/shared/neo/neo_crosshair.h
1659+
${CMAKE_SOURCE_DIR}/game/shared/neo/neo_serial.cpp
1660+
${CMAKE_SOURCE_DIR}/game/shared/neo/neo_serial.h
16591661
)
16601662

16611663
target_sources_grouped(
@@ -1725,6 +1727,7 @@ target_sources_grouped(
17251727
${CMAKE_SOURCE_DIR}/game/shared/neo/weapons/weapon_zr68l.h
17261728
${CMAKE_SOURCE_DIR}/game/shared/neo/weapons/weapon_zr68s.cpp
17271729
${CMAKE_SOURCE_DIR}/game/shared/neo/weapons/weapon_zr68s.h
1730+
${CMAKE_SOURCE_DIR}/game/shared/neo/weapons/neo_weapon_types.h
17281731
)
17291732

17301733
if(NEO_BUILD_WEAPON_PBK56S)

src/game/client/hud_crosshair.cpp

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,6 @@ void CVGlobal_NeoClCrosshair(IConVar *var, [[maybe_unused]] const char *pOldStri
6262
}
6363
}
6464

65-
ConVar cl_neo_crosshair_hip_fire("cl_neo_crosshair_hip_fire", "0", FCVAR_ARCHIVE, "Show the crosshair when not aiming", true, 0, true, 1,
66-
[]([[maybe_unused]] IConVar* var, [[maybe_unused]] const char* pOldString, [[maybe_unused]] float flOldValue)->void{
67-
CHudCrosshair *crosshair = GET_HUDELEMENT(CHudCrosshair);
68-
if (crosshair)
69-
{
70-
crosshair->SetHiddenBits(HIDEHUD_PLAYERDEAD | (cl_neo_crosshair_hip_fire.GetBool() ? 0 : HIDEHUD_CROSSHAIR));
71-
}
72-
});
7365
ConVar cl_neo_crosshair_scope_inaccuracy("cl_neo_crosshair_scope_inaccuracy", "1", FCVAR_ARCHIVE, "Show the player's inaccuracy when scoped", true, 0, true, 1);
7466
ConVar cl_neo_crosshair_friendly_fire_warning("cl_neo_crosshair_friendly_fire_warning", "1", FCVAR_ARCHIVE, "Replace crosshair with friendly fire warning where applicable", true, 0, true, 1);
7567
#endif
@@ -116,7 +108,7 @@ CHudCrosshair::CHudCrosshair( const char *pElementName ) :
116108
surface()->DrawSetTextureFile(m_hCrosshairLight, "vgui/hud/scopes/scope03-1", 1, false);
117109
surface()->DrawGetTextureSize(m_hCrosshairLight, m_iCrosshairLightWidth, m_iCrosshairLightHeight);
118110

119-
SetHiddenBits( HIDEHUD_PLAYERDEAD | (cl_neo_crosshair_hip_fire.GetBool() ? 0 : HIDEHUD_CROSSHAIR) );
111+
SetHiddenBits( HIDEHUD_PLAYERDEAD );
120112
#else
121113
SetHiddenBits( HIDEHUD_PLAYERDEAD | HIDEHUD_CROSSHAIR );
122114
#endif // NEO
@@ -531,7 +523,21 @@ void CHudCrosshair::Paint( void )
531523
m_bRefreshCrosshair = false;
532524
}
533525
}
534-
const int iXHairStyle = pCrosshairInfo->iStyle;
526+
527+
bool bHideCrosshair = (NEORules() && NEORules()->GetHiddenHudElements() & NEO_HUD_ELEMENT_CROSSHAIR);
528+
529+
ENeoCrosshairWep eNeoXHairWep = CROSSHAIR_WEP_DEFAULT;
530+
if (pWeapon)
531+
{
532+
int iNeoXHairWep = MAP_WEAPON_TYPE_TO_XHAIR[NEO_WEAPON_TYPE[pWeapon->WeaponIndex()]];
533+
if (iNeoXHairWep >= CROSSHAIR_WEP_DEFAULT && false == pNeoPlayer->m_bInAim)
534+
{
535+
iNeoXHairWep += CROSSHAIR_WEP_DEFAULT_HIPFIRE;
536+
}
537+
eNeoXHairWep = static_cast<ENeoCrosshairWep>(
538+
UseCrosshairIndexFor(pCrosshairInfo, iNeoXHairWep, &bHideCrosshair));
539+
}
540+
CrosshairWepInfo *crh = &pCrosshairInfo->wep[eNeoXHairWep];
535541

536542
bool showFriendlyFireCrosshair = false;
537543
if (NEORules()->GetGameType() != NEO_GAME_TYPE_DM && cl_neo_crosshair_friendly_fire_warning.GetBool())
@@ -604,19 +610,19 @@ void CHudCrosshair::Paint( void )
604610
vgui::surface()->DrawSetColor(COLOR_RED);
605611
vgui::surface()->DrawTexturedRect(iX - iTexWide, iY - iTexTall, iX + iTexWide, iY + iTexTall);
606612
}
607-
else if (m_iTexXHId[iXHairStyle] > 0)
613+
else if (m_iTexXHId[crh->iStyle] > 0)
608614
{
609-
vgui::surface()->DrawSetTexture(m_iTexXHId[iXHairStyle]);
615+
vgui::surface()->DrawSetTexture(m_iTexXHId[crh->iStyle]);
610616
int iTexWide, iTexTall;
611-
vgui::surface()->DrawGetTextureSize(m_iTexXHId[iXHairStyle], iTexWide, iTexTall);
617+
vgui::surface()->DrawGetTextureSize(m_iTexXHId[crh->iStyle], iTexWide, iTexTall);
612618
iTexWide >>= 1;
613619
iTexTall >>= 1;
614-
vgui::surface()->DrawSetColor(pCrosshairInfo->color);
620+
vgui::surface()->DrawSetColor(crh->color);
615621
vgui::surface()->DrawTexturedRect(iX - iTexWide, iY - iTexTall, iX + iTexWide, iY + iTexTall);
616622
}
617-
else
623+
else if (!bHideCrosshair)
618624
{
619-
PaintCrosshair(*pCrosshairInfo, HalfInaccuracyConeInScreenPixels(pWeapon, m_iHalfScreenWidth), iX, iY);
625+
PaintCrosshair(crh, HalfInaccuracyConeInScreenPixels(pWeapon, m_iHalfScreenWidth), iX, iY);
620626
}
621627

622628
if (bIsScopedWep && pPlayer->m_bInAim)

0 commit comments

Comments
 (0)