From 47e16ad042935ac8620806af2e1b3910b9d4ce56 Mon Sep 17 00:00:00 2001 From: a1batross Date: Sat, 11 Jun 2016 23:03:57 +0300 Subject: [PATCH] Fix crash in CHudAmmo::Draw." Fix twice decals drawing on lean(relatively) surfaces. Optimize also. Refactoring radar code Add new cvars to disable sparks and wallpuf --- cl_dll/events/ev_cs16.cpp | 34 ++++++++------------------ cl_dll/hud/ammo.cpp | 49 ++++++++++++++++++++++++-------------- cl_dll/hud/hud.cpp | 2 ++ cl_dll/hud/nvg.cpp | 2 +- cl_dll/hud/radar.cpp | 42 ++++++++++++++++---------------- cl_dll/include/hud/hud.h | 4 +++- cl_dll/include/hud/radar.h | 2 +- 7 files changed, 68 insertions(+), 67 deletions(-) diff --git a/cl_dll/events/ev_cs16.cpp b/cl_dll/events/ev_cs16.cpp index 00cb584..8fbe0e2 100644 --- a/cl_dll/events/ev_cs16.cpp +++ b/cl_dll/events/ev_cs16.cpp @@ -426,16 +426,16 @@ void EV_HLDM_DecalGunshot(pmtrace_t *pTrace, int iBulletType, float scale, int r { EV_HLDM_GunshotDecalTrace( pTrace, EV_HLDM_DamageDecal( pe ), cTextureType ); - if( bCreateSparks ) + if( gHUD.cl_weapon_sparks && gHUD.cl_weapon_sparks->value && bCreateSparks ) { Vector dir = pTrace->plane.normal; dir.x = dir.x * dir.x * gEngfuncs.pfnRandomFloat( 4.0f, 12.0f ); dir.y = dir.y * dir.y * gEngfuncs.pfnRandomFloat( 4.0f, 12.0f ); dir.z = dir.z * dir.z * gEngfuncs.pfnRandomFloat( 4.0f, 12.0f ); - gEngfuncs.pEfxAPI->R_StreakSplash( pTrace->endpos, dir, 4, gEngfuncs.pfnRandomLong( 15, 30 ), dir.z, -75.0f, 75.0f ); + gEngfuncs.pEfxAPI->R_StreakSplash( pTrace->endpos, dir, 4, gEngfuncs.pfnRandomLong( 5, 10 ), dir.z, -75.0f, 75.0f ); } - if( bCreateWallPuff ) + if( gHUD.cl_weapon_wallpuff && gHUD.cl_weapon_wallpuff->value && bCreateWallPuff ) { TEMPENTITY *te = NULL; if( gHUD.fastsprites && !gHUD.fastsprites->value ) @@ -451,6 +451,7 @@ void EV_HLDM_DecalGunshot(pmtrace_t *pTrace, int iBulletType, float scale, int r te = gEngfuncs.pEfxAPI->R_DefaultSprite( pTrace->endpos, gEngfuncs.pEventAPI->EV_FindModelIndex("sprites/fast_wallpuff1.spr"), 30.0f ); } + if( te ) { te->callback = EV_WallPuff_Wind; @@ -706,28 +707,13 @@ void EV_HLDM_FireBullets(int idx, vecEnd[i] = vecShotSrc[i] + flDistance * vecDir[i]; } - Vector vStartPos, vEndPos; + + // trace back, so we will have a decal on the other side of solid area pmtrace_t trOriginal; - int i; - for( i = 1; i <= iPenetrationPower; i++ ) - { - for( int j = 0; j < 3; j++ ) - { - vStartPos[j] = tr.endpos[j] + i * vecDir[j]; - vEndPos[j] = vecDir[j] + vStartPos[j]; - } - gEngfuncs.pEventAPI->EV_SetTraceHull( 2 ); - gEngfuncs.pEventAPI->EV_PlayerTrace(vStartPos, vEndPos, 0, -1, &trOriginal); - if ( trOriginal.startsolid && trOriginal.inopen ) - break; - } - if( i != iPenetrationPower ) - { - gEngfuncs.pEventAPI->EV_SetTraceHull( 2 ); - gEngfuncs.pEventAPI->EV_PlayerTrace(vEndPos, vStartPos, 0, -1, &trOriginal); - // draw wallpuff, only if start was been in non-solid area - EV_HLDM_DecalGunshot( &trOriginal, iBulletType, 0, r_smoke, g_smoke, b_smoke, !trOriginal.startsolid, bSparks, cTextureType ); - } + gEngfuncs.pEventAPI->EV_SetTraceHull( 2 ); + gEngfuncs.pEventAPI->EV_PlayerTrace(vecShotSrc, vecSrc, 0, -1, &trOriginal); + if( !trOriginal.startsolid ) + EV_HLDM_DecalGunshot( &trOriginal, iBulletType, 0, r_smoke, g_smoke, b_smoke, true, bSparks, cTextureType ); } gEngfuncs.pEventAPI->EV_PopPMStates(); } diff --git a/cl_dll/hud/ammo.cpp b/cl_dll/hud/ammo.cpp index f2a5285..55db952 100644 --- a/cl_dll/hud/ammo.cpp +++ b/cl_dll/hud/ammo.cpp @@ -1093,13 +1093,34 @@ void CHudAmmo::UserCmd_Rebuy() int CHudAmmo::Draw(float flTime) { - wrect_t nullrc = { 0, 0, 0, 0 }; + wrect_t nullrc = { 0 }; int a, x, y, r, g, b; int AmmoWidth; + static bool switchCrosshairType = false; if (!(gHUD.m_iWeaponBits & (1<<(WEAPON_SUIT)) )) return 1; + // place it here, so pretty dynamic crosshair will work even in spectator! + if( gHUD.m_iFOV > 40 ) + { + if( switchCrosshairType ) + { + gEngfuncs.pfnSetCrosshair( 0, nullrc, 0, 0, 0); + switchCrosshairType = false; + } + // draw a dynamic crosshair + DrawCrosshair(flTime); + } + else + { + if( !switchCrosshairType ) + { + SetCrosshair(m_pWeapon->hZoomedCrosshair, m_pWeapon->rcZoomedCrosshair, 255, 255, 255); + switchCrosshairType = true; + } + } + if ( (gHUD.m_iHideHUDDisplay & ( HIDEHUD_WEAPONS | HIDEHUD_ALL )) ) return 1; @@ -1115,16 +1136,6 @@ int CHudAmmo::Draw(float flTime) if (!m_pWeapon) return 0; - if( gHUD.m_iFOV > 40 ) - { - SetCrosshair( 0, nullrc, 0, 0, 0); - DrawCrosshair(flTime, m_pWeapon->iId); // draw a dynamic crosshair - } - else - { - SetCrosshair(m_pWeapon->hZoomedCrosshair, m_pWeapon->rcZoomedCrosshair, 255, 255, 255); - } - WEAPON *pw = m_pWeapon; // shorthand // SPR_Draw Ammo @@ -1140,9 +1151,9 @@ int CHudAmmo::Draw(float flTime) if (m_fFade > 0) m_fFade -= (gHUD.m_flTimeDelta * 20); - DrawUtils::DrawUtils::UnpackRGB(r,g,b, RGB_YELLOWISH); + DrawUtils::UnpackRGB(r,g,b, RGB_YELLOWISH); - DrawUtils::DrawUtils::ScaleColors(r, g, b, a ); + DrawUtils::ScaleColors(r, g, b, a ); // Does this weapon have a clip? y = ScreenHeight - gHUD.m_iFontHeight - gHUD.m_iFontHeight/2; @@ -1253,13 +1264,16 @@ int Distances[30][2] = { 7, 3 }, // 29 }; -void CHudAmmo::DrawCrosshair( float flTime, int weaponid ) +void CHudAmmo::DrawCrosshair( float flTime ) { - int flags; - int iDeltaDistance, iDistance; - int iLength; + int flags, iDeltaDistance, iDistance, iLength, weaponid; float flCrosshairDistance; + if( !m_pWeapon ) + return; + + weaponid = m_pWeapon->iId; + if( weaponid == WEAPON_AWP || weaponid == WEAPON_SCOUT || weaponid == WEAPON_SG550 || weaponid == WEAPON_G3SG1 ) return; @@ -1273,7 +1287,6 @@ void CHudAmmo::DrawCrosshair( float flTime, int weaponid ) } else { - // TODO: Get an info about crosshair for weapon iDistance = Distances[weaponid-1][0]; iDeltaDistance = Distances[weaponid-1][1]; } diff --git a/cl_dll/hud/hud.cpp b/cl_dll/hud/hud.cpp index fe1bddd..33ef42f 100644 --- a/cl_dll/hud/hud.cpp +++ b/cl_dll/hud/hud.cpp @@ -125,6 +125,8 @@ void CHud :: Init( void ) default_fov = CVAR_CREATE( "default_fov", "90", 0 ); m_pCvarDraw = CVAR_CREATE( "hud_draw", "1", FCVAR_ARCHIVE ); fastsprites = CVAR_CREATE( "fastsprites", "0", FCVAR_ARCHIVE ); + cl_weapon_sparks = CVAR_CREATE( "cl_weapon_sparks", "1", FCVAR_ARCHIVE ); + cl_weapon_wallpuff = CVAR_CREATE( "cl_weapon_wallpuff", "1", FCVAR_ARCHIVE ); m_iLogo = 0; m_iFOV = 0; diff --git a/cl_dll/hud/nvg.cpp b/cl_dll/hud/nvg.cpp index a40ba52..5d499dd 100644 --- a/cl_dll/hud/nvg.cpp +++ b/cl_dll/hud/nvg.cpp @@ -64,7 +64,7 @@ int CHudNVG::Draw(float flTime) dlight_t *dl = gEngfuncs.pEfxAPI->CL_AllocDlight ( 0 ); VectorCopy ( gHUD.m_vecOrigin, dl->origin ); dl->radius = gEngfuncs.pfnRandomFloat( 750, 800 ); - dl->die = flTime + 0.1; + dl->die = flTime + 0.1f; dl->color.r = 50; dl->color.g = 255; dl->color.b = 50; diff --git a/cl_dll/hud/radar.cpp b/cl_dll/hud/radar.cpp index 3dd5c29..7d2d306 100644 --- a/cl_dll/hud/radar.cpp +++ b/cl_dll/hud/radar.cpp @@ -137,13 +137,12 @@ int CHudRadar::Draw(float flTime) } // calc radar position - Vector2D pos = WorldToRadar(gHUD.m_vecOrigin, g_PlayerExtraInfo[i].origin, gHUD.m_vecAngles); + Vector pos = WorldToRadar(gHUD.m_vecOrigin, g_PlayerExtraInfo[i].origin, gHUD.m_vecAngles); - float zdiff = gHUD.m_vecOrigin.z - g_PlayerExtraInfo[i].origin.z; if( !g_PlayerExtraInfo[i].radarflashon ) { - if( zdiff < 20 && zdiff > -20 ) + if( pos.z < 20 && pos.z > -20 ) { DrawRadarDot( pos.x, pos.y, 4, r, g, b, 255 ); } @@ -173,7 +172,7 @@ int CHudRadar::Draw(float flTime) if( g_PlayerExtraInfo[i].nextflash ) { - if( zdiff < 20 && zdiff > -20 ) + if( pos.z < 20 && pos.z > -20 ) { DrawRadarDot( pos.x, pos.y, 4, r, g, b, 255 ); } @@ -192,7 +191,7 @@ int CHudRadar::Draw(float flTime) // Terrorist specific code( C4 Bomb ) if( g_PlayerExtraInfo[gHUD.m_Scoreboard.m_iPlayerNum].teamnumber == TEAM_TERRORIST && g_PlayerExtraInfo[33].radarflashon) { - Vector2D pos = WorldToRadar(gHUD.m_vecOrigin, g_PlayerExtraInfo[33].origin, gHUD.m_vecAngles); + Vector pos = WorldToRadar(gHUD.m_vecOrigin, g_PlayerExtraInfo[33].origin, gHUD.m_vecAngles); if( g_PlayerExtraInfo[33].radarflashes ) { float timer = (flTime - g_PlayerExtraInfo[33].radarflash); @@ -226,7 +225,7 @@ int CHudRadar::Draw(float flTime) if( !g_HostageInfo[i].radarflashon || g_HostageInfo[i].dead ) continue; - Vector2D pos = WorldToRadar(gHUD.m_vecOrigin, g_HostageInfo[i].origin, gHUD.m_vecAngles); + Vector pos = WorldToRadar(gHUD.m_vecOrigin, g_HostageInfo[i].origin, gHUD.m_vecAngles); if( g_HostageInfo[i].radarflashes ) { float timer = (flTime - g_HostageInfo[i].radarflash); @@ -280,38 +279,37 @@ void CHudRadar::DrawFlippedT(int x, int y, int size, int r, int g, int b, int a) FillRGBA( 62.5f + x - size, 62.5 + y + size, 3*size, size, r, g, b, a); } -Vector2D CHudRadar::WorldToRadar(const Vector vPlayerOrigin, const Vector vObjectOrigin, const Vector vAngles ) +Vector CHudRadar::WorldToRadar(const Vector vPlayerOrigin, const Vector vObjectOrigin, const Vector vAngles ) { - Vector2D diff = vObjectOrigin.Make2D() - vPlayerOrigin.Make2D(); + float xdiff = vObjectOrigin.x - vPlayerOrigin.x; + float ydiff = vObjectOrigin.y - vPlayerOrigin.y; // Supply epsilon values to avoid divide-by-zero - if(diff.x == 0) - diff.x = 0.00001f; - if(diff.y == 0) - diff.y = 0.00001f; + if(xdiff == 0) + xdiff = 0.00001f; + if(ydiff == 0) + ydiff = 0.00001f; int iMaxRadius = (m_hRadar.rect.right - m_hRadar.rect.left) / 2.0f; - float flOffset = atan(diff.y / diff.x) * 180.0f / M_PI; + float flOffset = atan(ydiff / xdiff) * 180.0f / M_PI; - if ((diff.x < 0) && (diff.y >= 0)) + if ((xdiff < 0) && (ydiff >= 0)) flOffset += 180; - else if ((diff.x < 0) && (diff.y < 0)) + else if ((xdiff < 0) && (ydiff < 0)) flOffset += 180; - else if ((diff.x >= 0) && (diff.y < 0)) + else if ((xdiff >= 0) && (ydiff < 0)) flOffset += 360; // this magic 32.0f just scales position on radar - float iRadius = -diff.Length() / 32.0f; + float iRadius = -( sqrt( xdiff*xdiff + ydiff*ydiff ) ) / 32.0f; if( -iRadius > iMaxRadius) iRadius = -iMaxRadius; flOffset = (vAngles.y - flOffset) * M_PI / 180.0f; // transform origin difference to radar source - Vector2D new_diff; - new_diff.x = -iRadius * sin(flOffset); - new_diff.y = iRadius * cos(flOffset); - - return new_diff; + return { -iRadius * sin(flOffset), + iRadius * cos(flOffset), + vPlayerOrigin.z - vObjectOrigin.z }; } diff --git a/cl_dll/include/hud/hud.h b/cl_dll/include/hud/hud.h index 5a45ba0..c4f5771 100644 --- a/cl_dll/include/hud/hud.h +++ b/cl_dll/include/hud/hud.h @@ -133,7 +133,7 @@ public: void Think(void); void Reset(void); - void DrawCrosshair( float flTime, int weaponId ); + void DrawCrosshair(float flTime); void CalcCrosshairSize(); void CalcCrosshairDrawMode(); void CalcCrosshairColor(); @@ -886,6 +886,8 @@ public: cvar_t *cl_shadows; cvar_t *fastsprites; cvar_t *cl_predict; + cvar_t *cl_weapon_wallpuff; + cvar_t *cl_weapon_sparks; HSPRITE m_hGasPuff; diff --git a/cl_dll/include/hud/radar.h b/cl_dll/include/hud/radar.h index 6ecb676..07dd924 100644 --- a/cl_dll/include/hud/radar.h +++ b/cl_dll/include/hud/radar.h @@ -32,7 +32,7 @@ private: void DrawCross(int x, int y, int size, int r, int g, int b, int a ); void DrawT( int x, int y, int size, int r, int g, int b, int a ); void DrawFlippedT( int x, int y, int size, int r, int g, int b, int a ); - Vector2D WorldToRadar(const Vector vPlayerOrigin, const Vector vObjectOrigin, const Vector vAngles ); + Vector WorldToRadar(const Vector vPlayerOrigin, const Vector vObjectOrigin, const Vector vAngles ); };