diff --git a/src/game/shared/neo/neo_predicted_viewmodel_muzzleflash.cpp b/src/game/shared/neo/neo_predicted_viewmodel_muzzleflash.cpp index d37e4765be..bd4c194eee 100644 --- a/src/game/shared/neo/neo_predicted_viewmodel_muzzleflash.cpp +++ b/src/game/shared/neo/neo_predicted_viewmodel_muzzleflash.cpp @@ -29,14 +29,10 @@ BEGIN_NETWORK_TABLE(CNEOPredictedViewModelMuzzleFlash, DT_NEOPredictedViewModelM #ifndef CLIENT_DLL SendPropEHandle(SENDINFO_NAME(m_hMoveParent, moveparent)), SendPropBool(SENDINFO(m_bActive)), -SendPropInt(SENDINFO(m_iAngleZ)), -SendPropInt(SENDINFO(m_iAngleZIncrement)), SendPropBool(SENDINFO(m_bScaleChangeFlag)) #else RecvPropInt(RECVINFO_NAME(m_hNetworkMoveParent, moveparent), 0, RecvProxy_IntToMoveParent), RecvPropBool(RECVINFO(m_bActive)), -RecvPropInt(RECVINFO(m_iAngleZ)), -RecvPropInt(RECVINFO(m_iAngleZIncrement)), RecvPropEHandle(RECVINFO(m_bScaleChangeFlag), RecvProxy_ScaleChangeFlag) #endif END_NETWORK_TABLE() @@ -45,8 +41,6 @@ END_NETWORK_TABLE() BEGIN_PREDICTION_DATA(CNEOPredictedViewModelMuzzleFlash) DEFINE_PRED_FIELD(m_hNetworkMoveParent, FIELD_EHANDLE, FTYPEDESC_INSENDTABLE), DEFINE_PRED_FIELD(m_bActive, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE), -DEFINE_PRED_FIELD(m_iAngleZ, FIELD_INTEGER, FTYPEDESC_INSENDTABLE), -DEFINE_PRED_FIELD(m_iAngleZIncrement, FIELD_INTEGER, FTYPEDESC_INSENDTABLE), DEFINE_PRED_FIELD(m_bScaleChangeFlag, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE), END_PREDICTION_DATA() #endif @@ -58,8 +52,10 @@ constexpr const char* MUZZLE_FLASH_ENTITY_MODEL = "models/effect/fpmf/fpmf01.mdl CNEOPredictedViewModelMuzzleFlash::CNEOPredictedViewModelMuzzleFlash() { m_bActive = true; +#ifdef CLIENT_DLL m_iAngleZ = 0; m_iAngleZIncrement = -5; +#endif // CLIENT_DLL m_flTimeSwitchOffMuzzleFlash = gpGlobals->curtime; m_bScaleChangeFlag = false; } @@ -93,28 +89,11 @@ void CNEOPredictedViewModelMuzzleFlash::Spawn(void) #ifdef CLIENT_DLL int CNEOPredictedViewModelMuzzleFlash::DrawModel(int flags) { - if (m_flTimeSwitchOffMuzzleFlash > gpGlobals->curtime && m_bActive) + if (!m_bActive || m_flTimeSwitchOffMuzzleFlash <= gpGlobals->curtime && m_bActive) { - CBasePlayer* pOwner = ToBasePlayer(GetOwner()); - if (pOwner == NULL) { return -1; } - CBaseViewModel* vm = pOwner->GetViewModel(0, false); - if (vm == NULL || !vm->IsVisible()) { return -1; } - - int iAttachment = vm->LookupAttachment("muzzle"); - if (iAttachment < 0) { return -1; } - - Vector localOrigin; - QAngle localAngle; - vm->GetAttachment(iAttachment, localOrigin, localAngle); - UncorrectViewModelAttachment(localOrigin); // Need position of muzzle without fov modifications & viewmodel offset - m_iAngleZ = (m_iAngleZ + m_iAngleZIncrement) % 360; // NEOTODO (Adam) ? Speed of rotation depends on how often DrawModel() is called. Should this be tied to global time? - localAngle.z = m_iAngleZ; - SetAbsOrigin(localOrigin); - SetAbsAngles(localAngle); - - return BaseClass::DrawModel(flags); + return -1; } - return -1; + return BaseClass::DrawModel(flags); } void CNEOPredictedViewModelMuzzleFlash::ClientThink() @@ -130,6 +109,31 @@ void CNEOPredictedViewModelMuzzleFlash::ClientThink() #endif //CLIENT_DLL +void CNEOPredictedViewModelMuzzleFlash::CalcViewModelView(CBasePlayer* pOwner, + const Vector& eyePosition, const QAngle& eyeAngles) +{ +#ifdef CLIENT_DLL + auto vm = static_cast(GetMoveParent()); + if (!vm) + { + return; + } + + int iAttachment = vm->LookupAttachment("muzzle"); + if (iAttachment < 0) { + return; + } + + Vector localOrigin; + QAngle localAngle; + vm->GetAttachment(iAttachment, localOrigin, localAngle); + UncorrectViewModelAttachment(localOrigin); // Need position of muzzle without fov modifications & viewmodel offset + localAngle.z += m_iAngleZ; + SetAbsOrigin(localOrigin); + SetAbsAngles(localAngle); +#endif //CLIENT_DLL +} + void CNEOPredictedViewModelMuzzleFlash::UpdateMuzzleFlashProperties(CBaseCombatWeapon* pWeapon, bool repeat) { auto neoWep = static_cast(pWeapon); @@ -145,6 +149,9 @@ void CNEOPredictedViewModelMuzzleFlash::UpdateMuzzleFlashProperties(CBaseCombatW return; } +#ifdef CLIENT_DLL + m_iAngleZ = 0; +#endif // CLIENT_DLL const auto neoWepBits = neoWep->GetNeoWepBits(); if (neoWepBits & (NEO_WEP_THROWABLE | NEO_WEP_GHOST | NEO_WEP_KNIFE | NEO_WEP_SUPPRESSED)) { @@ -154,8 +161,9 @@ void CNEOPredictedViewModelMuzzleFlash::UpdateMuzzleFlashProperties(CBaseCombatW { m_bActive = true; m_nSkin = 1; - m_iAngleZ = 0; +#ifdef CLIENT_DLL m_iAngleZIncrement = -100; +#endif SetModelScale(0.75); m_bScaleChangeFlag = !m_bScaleChangeFlag; } @@ -163,8 +171,9 @@ void CNEOPredictedViewModelMuzzleFlash::UpdateMuzzleFlashProperties(CBaseCombatW { m_bActive = true; m_nSkin = 1; - m_iAngleZ = 0; +#ifdef CLIENT_DLL m_iAngleZIncrement = -90; +#endif SetModelScale(2); m_bScaleChangeFlag = !m_bScaleChangeFlag; } @@ -172,8 +181,9 @@ void CNEOPredictedViewModelMuzzleFlash::UpdateMuzzleFlashProperties(CBaseCombatW { m_bActive = true; m_nSkin = 0; - m_iAngleZ = 0; +#ifdef CLIENT_DLL m_iAngleZIncrement = -90; +#endif SetModelScale(0.75); m_bScaleChangeFlag = !m_bScaleChangeFlag; } @@ -181,8 +191,9 @@ void CNEOPredictedViewModelMuzzleFlash::UpdateMuzzleFlashProperties(CBaseCombatW { m_bActive = true; m_nSkin = 0; - m_iAngleZ = 0; +#ifdef CLIENT_DLL m_iAngleZIncrement = -100; +#endif SetModelScale(0.6); m_bScaleChangeFlag = !m_bScaleChangeFlag; } @@ -190,8 +201,9 @@ void CNEOPredictedViewModelMuzzleFlash::UpdateMuzzleFlashProperties(CBaseCombatW { m_bActive = true; m_nSkin = 0; - m_iAngleZ = 0; +#ifdef CLIENT_DLL m_iAngleZIncrement = -90; +#endif SetModelScale(0.75); m_bScaleChangeFlag = !m_bScaleChangeFlag; } diff --git a/src/game/shared/neo/neo_predicted_viewmodel_muzzleflash.h b/src/game/shared/neo/neo_predicted_viewmodel_muzzleflash.h index a5ecd45551..1a940b2757 100644 --- a/src/game/shared/neo/neo_predicted_viewmodel_muzzleflash.h +++ b/src/game/shared/neo/neo_predicted_viewmodel_muzzleflash.h @@ -20,6 +20,7 @@ class CNEOPredictedViewModelMuzzleFlash : public CPredictedViewModel DECLARE_PREDICTABLE(); CNEOPredictedViewModelMuzzleFlash(); virtual ~CNEOPredictedViewModelMuzzleFlash(); + virtual void CalcViewModelView(CBasePlayer* pOwner, const Vector& eyePosition, const QAngle& eyeAngles) override; void UpdateMuzzleFlashProperties(CBaseCombatWeapon* pWeapon, bool repeat = true); virtual void Spawn(void) override; virtual void Precache(void) override; @@ -31,6 +32,7 @@ class CNEOPredictedViewModelMuzzleFlash : public CPredictedViewModel { if (!m_bActive) return; + m_iAngleZ = (m_iAngleZ + m_iAngleZIncrement) % 360; m_flTimeSwitchOffMuzzleFlash = gpGlobals->curtime + 0.01f; BaseClass::ProcessMuzzleFlashEvent(); } @@ -44,8 +46,6 @@ class CNEOPredictedViewModelMuzzleFlash : public CPredictedViewModel bool m_bScaleChangeFlag; #else CNetworkVar(bool, m_bActive); - CNetworkVar(int, m_iAngleZ); - CNetworkVar(int, m_iAngleZIncrement); CNetworkVar(bool, m_bScaleChangeFlag); #endif // CLIENT_DLL float m_flTimeSwitchOffMuzzleFlash; diff --git a/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp b/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp index 76ecaf71d6..6e0fdbeb2d 100644 --- a/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp +++ b/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp @@ -961,9 +961,18 @@ bool CNEOBaseCombatWeapon::CanBePickedUpByClass(int classId) #ifdef CLIENT_DLL void CNEOBaseCombatWeapon::ProcessMuzzleFlashEvent() { - if (GetPlayerOwner() == NULL) + C_BasePlayer *owner = GetPlayerOwner(); + if (!owner) return; // If using a view model in first person, muzzle flashes are not processed until the player drops their weapon. In that case, do not play a muzzle flash effect. Need to change how this is calculated if we want to allow dropped weapons to cook off for example + C_BasePlayer *localPlayer = UTIL_PlayerByIndex(GetLocalPlayerIndex()); + if (!localPlayer) + return; + + // bIsVisible in function calling ProcessMuzzleFlashEvent is set to true even though this weapon may not be drawn? Probably same reason for the same check in C_BaseCombatWeapon::DrawModel + if (localPlayer->IsObserver() && localPlayer->GetObserverMode() == OBS_MODE_IN_EYE && localPlayer->GetObserverTarget() == owner) + return; + if ((GetNeoWepBits() & NEO_WEP_SUPPRESSED)) return; @@ -996,7 +1005,7 @@ void CNEOBaseCombatWeapon::ProcessMuzzleFlashEvent() el->color.exponent = 5; // Muzzle flash particle - DispatchMuzzleParticleEffect(iAttachment); + ParticleProp()->Create("ntr_muzzle_source", PATTACH_POINT_FOLLOW, iAttachment); } void CNEOBaseCombatWeapon::DrawCrosshair() @@ -1029,27 +1038,6 @@ void CNEOBaseCombatWeapon::DrawCrosshair() } } -void CNEOBaseCombatWeapon::DispatchMuzzleParticleEffect(int iAttachment) { - static constexpr char particleName[] = "ntr_muzzle_source"; - constexpr bool resetAllParticlesOnEntity = false; - const ParticleAttachment_t iAttachType = ParticleAttachment_t::PATTACH_POINT_FOLLOW; - - CEffectData data; - - data.m_nHitBox = GetParticleSystemIndex(particleName); - data.m_hEntity = this; - data.m_fFlags |= PARTICLE_DISPATCH_FROM_ENTITY; - data.m_vOrigin = GetAbsOrigin(); - data.m_nDamageType = iAttachType; - data.m_nAttachmentIndex = iAttachment; - - if (resetAllParticlesOnEntity) - data.m_fFlags |= PARTICLE_DISPATCH_RESET_PARTICLES; - - CSingleUserRecipientFilter filter(UTIL_PlayerByIndex(GetLocalPlayerIndex())); - te->DispatchEffect(filter, 0.0, data.m_vOrigin, "ParticleEffect", data); -} - static inline bool ShouldDrawLocalPlayerViewModel(void) { return !C_BasePlayer::ShouldDrawLocalPlayer(); diff --git a/src/game/shared/neo/weapons/weapon_neobasecombatweapon.h b/src/game/shared/neo/weapons/weapon_neobasecombatweapon.h index 4f717060e7..fdb6a3fadb 100644 --- a/src/game/shared/neo/weapons/weapon_neobasecombatweapon.h +++ b/src/game/shared/neo/weapons/weapon_neobasecombatweapon.h @@ -195,7 +195,6 @@ class CNEOBaseCombatWeapon : public CBaseHL2MPCombatWeapon virtual Activity GetPrimaryAttackActivity(void) override; #ifdef CLIENT_DLL - void DispatchMuzzleParticleEffect(int iAttachment); virtual void ProcessMuzzleFlashEvent(void) override; void DrawCrosshair() override; #endif