From e0c6dfd73d5dd00e77630a00a1ef378ce2d72597 Mon Sep 17 00:00:00 2001 From: a1batross Date: Fri, 15 Apr 2016 23:50:47 +0300 Subject: [PATCH] New cvar: fastsprites. Wind simulation for wallpuff, some optimizations --- cl_dll/events/ev_cs16.cpp | 104 ++++++++++++++++++++++++++-- cl_dll/events/event_createsmoke.cpp | 2 +- cl_dll/hud/hud.cpp | 3 + cl_dll/include/hud/hud.h | 4 +- mainui/menu_gameoptions.cpp | 6 +- 5 files changed, 108 insertions(+), 11 deletions(-) diff --git a/cl_dll/events/ev_cs16.cpp b/cl_dll/events/ev_cs16.cpp index 3543949..00cb584 100644 --- a/cl_dll/events/ev_cs16.cpp +++ b/cl_dll/events/ev_cs16.cpp @@ -338,6 +338,84 @@ void EV_HLDM_GunshotDecalTrace( pmtrace_t *pTrace, char *decalName, char chTextu } } + +void EV_WallPuff_Wind( struct tempent_s *te, float frametime, float currenttime ) +{ + static bool xWindDirection = true; + static bool yWindDirection = true; + static float xWindMagnitude; + static float yWindMagnitude; + + if ( te->entity.curstate.frame > 7.0 ) + { + te->entity.baseline.origin.x = 0.97 * te->entity.baseline.origin.x; + te->entity.baseline.origin.y = 0.97 * te->entity.baseline.origin.y; + te->entity.baseline.origin.z = 0.97 * te->entity.baseline.origin.z + 0.7; + if ( te->entity.baseline.origin.z > 70.0 ) + te->entity.baseline.origin.z = 70.0; + } + + if ( te->entity.curstate.frame > 6.0 ) + { + xWindMagnitude += 0.075; + if ( xWindMagnitude > 5.0 ) + xWindMagnitude = 5.0; + + yWindMagnitude += 0.075; + if ( yWindMagnitude > 5.0 ) + yWindMagnitude = 5.0; + + if( xWindDirection ) + te->entity.baseline.origin.x += xWindMagnitude; + else + te->entity.baseline.origin.x -= xWindMagnitude; + + if( yWindDirection ) + te->entity.baseline.origin.y += yWindMagnitude; + else + te->entity.baseline.origin.y -= yWindMagnitude; + + if ( !gEngfuncs.pfnRandomLong(0, 10) && yWindMagnitude > 3.0 ) + { + yWindMagnitude = 0; + yWindDirection = !yWindDirection; + } + if ( !gEngfuncs.pfnRandomLong(0, 10) && xWindMagnitude > 3.0 ) + { + xWindMagnitude = 0; + xWindDirection = !xWindDirection; + } + } +} + +void EV_HugWalls(TEMPENTITY *te, pmtrace_s *ptr) +{ + Vector norm = te->entity.baseline.origin.Normalize(); + float len = te->entity.baseline.origin.Length(); + + Vector v = + { + ptr->plane.normal.y * norm.x - norm.y * ptr->plane.normal.x, + ptr->plane.normal.x * norm.z - norm.x * ptr->plane.normal.z, + ptr->plane.normal.z * norm.y - norm.z * ptr->plane.normal.y + }; + Vector v2 = + { + ptr->plane.normal.y * v.z - v.y * ptr->plane.normal.x, + ptr->plane.normal.x * v.x - v.z * ptr->plane.normal.z, + ptr->plane.normal.z * v.y - v.x * ptr->plane.normal.y + }; + + if( len <= 2000.0f ) + len *= 1.5; + else len = 3000.0f; + + te->entity.baseline.origin.x = v2.z * len * 1.5; + te->entity.baseline.origin.y = v2.y * len * 1.5; + te->entity.baseline.origin.z = v2.x * len * 1.5; +} + + void EV_HLDM_DecalGunshot(pmtrace_t *pTrace, int iBulletType, float scale, int r, int g, int b, bool bCreateWallPuff, bool bCreateSparks, char cTextureType) { physent_t *pe; @@ -359,18 +437,32 @@ void EV_HLDM_DecalGunshot(pmtrace_t *pTrace, int iBulletType, float scale, int r if( bCreateWallPuff ) { - TEMPENTITY *te = gEngfuncs.pEfxAPI->R_DefaultSprite( pTrace->endpos, - gEngfuncs.pEventAPI->EV_FindModelIndex("sprites/wall_puff1.spr"), 30.0f ); + TEMPENTITY *te = NULL; + if( gHUD.fastsprites && !gHUD.fastsprites->value ) + { + char path[] = "sprites/wall_puff1.spr"; + + path[17] += gEngfuncs.pfnRandomLong(0, 3); + te = gEngfuncs.pEfxAPI->R_DefaultSprite( pTrace->endpos, + gEngfuncs.pEventAPI->EV_FindModelIndex(path), 30.0f ); + } + else + { + te = gEngfuncs.pEfxAPI->R_DefaultSprite( pTrace->endpos, + gEngfuncs.pEventAPI->EV_FindModelIndex("sprites/fast_wallpuff1.spr"), 30.0f ); + } if( te ) { - te->flags = FTENT_SPRANIMATE | FTENT_FADEOUT; + te->callback = EV_WallPuff_Wind; + te->hitcallback = EV_HugWalls; + te->flags |= FTENT_COLLIDEALL | FTENT_CLIENTCUSTOM; te->entity.curstate.rendermode = kRenderTransAdd; te->entity.curstate.rendercolor.r = r; te->entity.curstate.rendercolor.g = g; te->entity.curstate.rendercolor.b = b; - te->entity.curstate.renderamt = 255; - te->entity.curstate.scale = 0.33; - te->entity.baseline.origin = 20 * pTrace->plane.normal; + te->entity.curstate.renderamt = gEngfuncs.pfnRandomLong( 100, 180 ); + te->entity.curstate.scale = 0.5; + te->entity.baseline.origin = (25 + gEngfuncs.pfnRandomLong( 0, 4 ) ) * pTrace->plane.normal; } } } diff --git a/cl_dll/events/event_createsmoke.cpp b/cl_dll/events/event_createsmoke.cpp index a38d42b..1139fe2 100644 --- a/cl_dll/events/event_createsmoke.cpp +++ b/cl_dll/events/event_createsmoke.cpp @@ -48,7 +48,7 @@ void EV_CreateSmoke(event_args_s *args) if( !args->bparam2 ) //first explosion { - const model_t *pGasModel = gEngfuncs.GetSpritePointer(SPR_Load("sprites/gas_puff_01.spr")); + const model_t *pGasModel = gEngfuncs.GetSpritePointer(gHUD.m_hGasPuff); for( int i = 0; i < SMOKE_CLOUDS; i++ ) { diff --git a/cl_dll/hud/hud.cpp b/cl_dll/hud/hud.cpp index 230a447..a8763b5 100644 --- a/cl_dll/hud/hud.cpp +++ b/cl_dll/hud/hud.cpp @@ -123,6 +123,7 @@ void CHud :: Init( void ) default_fov = CVAR_CREATE( "default_fov", "90", 0 ); m_pCvarStealMouse = CVAR_CREATE( "hud_capturemouse", "1", FCVAR_ARCHIVE ); m_pCvarDraw = CVAR_CREATE( "hud_draw", "1", FCVAR_ARCHIVE ); + fastsprites = CVAR_CREATE( "fastsprites", "0", FCVAR_ARCHIVE ); @@ -345,6 +346,8 @@ void CHud :: VidInit( void ) m_iFontHeight = m_rgrcRects[m_HUD_number_0].bottom - m_rgrcRects[m_HUD_number_0].top; + m_hGasPuff = SPR_Load("sprites/gas_puff_01.spr"); + m_Ammo.VidInit(); m_Health.VidInit(); m_Spectator.VidInit(); diff --git a/cl_dll/include/hud/hud.h b/cl_dll/include/hud/hud.h index b642287..4450963 100644 --- a/cl_dll/include/hud/hud.h +++ b/cl_dll/include/hud/hud.h @@ -883,11 +883,13 @@ public: int m_iFOV; int m_Teamplay; int m_iRes; - int RealSize; float m_flScale; cvar_t *m_pCvarStealMouse; cvar_t *m_pCvarDraw; cvar_t *cl_shadows; + cvar_t *fastsprites; + + HSPRITE m_hGasPuff; int m_iFontHeight; CHudAmmo m_Ammo; diff --git a/mainui/menu_gameoptions.cpp b/mainui/menu_gameoptions.cpp index 90bfd1b..ba61a1a 100644 --- a/mainui/menu_gameoptions.cpp +++ b/mainui/menu_gameoptions.cpp @@ -116,7 +116,7 @@ static void UI_GameOptions_UpdateConfig( void ) CVAR_SET_FLOAT( "mp_decals", uiGameOptions.mp_decals.curValue ); //CVAR_SET_FLOAT( "") maxshells //CVAR_SET_FLOAT( "") max_smoke_puffs; - CVAR_SET_FLOAT( "cl_fastsmoke", uiGameOptions.fast_smoke_gas.enabled ); + CVAR_SET_FLOAT( "fastsprites", uiGameOptions.fast_smoke_gas.enabled ); CVAR_SET_FLOAT( "_vgui_menus", !uiGameOptions.oldstylemenu.enabled ); CVAR_SET_FLOAT( "_extended_menus", uiGameOptions.extendedmenus.enabled ); CVAR_SET_FLOAT( "_cl_autowepswitch", uiGameOptions.cl_autowepswitch.enabled ); @@ -140,7 +140,7 @@ static void UI_GameOptions_DiscardChanges( void ) CVAR_SET_FLOAT( "mp_decals", uiGameInitial.mp_decals ); //CVAR_SET_FLOAT( "") maxshells //CVAR_SET_FLOAT( "") max_smoke_puffs; - CVAR_SET_FLOAT( "cl_fastsmoke", uiGameInitial.fast_smoke_gas ); + CVAR_SET_FLOAT( "fastsprites", uiGameInitial.fast_smoke_gas ); CVAR_SET_FLOAT( "_vgui_menus", !uiGameInitial.oldstylemenu ); CVAR_SET_FLOAT( "_extended_menus", uiGameInitial.extendedmenus ); CVAR_SET_FLOAT( "_cl_autowepswitch", uiGameInitial.cl_autowepswitch ); @@ -180,7 +180,7 @@ static void UI_GameOptions_GetConfig( void ) uiGameInitial.hand = uiGameOptions.hand.enabled = !CVAR_GET_FLOAT( "hand" ); uiGameInitial.oldstylemenu = uiGameOptions.oldstylemenu.enabled = !CVAR_GET_FLOAT( "_vgui_menus" ); - if( CVAR_GET_FLOAT( "cl_fastsmoke" )) + if( CVAR_GET_FLOAT( "fastsprites" )) uiGameInitial.fast_smoke_gas = uiGameOptions.fast_smoke_gas.enabled = true; if( CVAR_GET_FLOAT( "_extended_menus" )) uiGameInitial.extendedmenus = uiGameOptions.extendedmenus.enabled = true;