Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 43 additions & 31 deletions src/game/shared/neo/neo_predicted_viewmodel_muzzleflash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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;
}
Expand Down Expand Up @@ -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()
Expand All @@ -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<CNEOPredictedViewModel*>(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<CNEOBaseCombatWeapon*>(pWeapon);
Expand All @@ -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))
{
Expand All @@ -154,44 +161,49 @@ 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;
}
else if (neoWepBits & NEO_WEP_SUPA7)
{
m_bActive = true;
m_nSkin = 1;
m_iAngleZ = 0;
#ifdef CLIENT_DLL
m_iAngleZIncrement = -90;
#endif
SetModelScale(2);
m_bScaleChangeFlag = !m_bScaleChangeFlag;
}
else if (neoWepBits & (NEO_WEP_SRM | NEO_WEP_JITTE))
{
m_bActive = true;
m_nSkin = 0;
m_iAngleZ = 0;
#ifdef CLIENT_DLL
m_iAngleZIncrement = -90;
#endif
SetModelScale(0.75);
m_bScaleChangeFlag = !m_bScaleChangeFlag;
}
else if (neoWepBits & (NEO_WEP_MX | NEO_WEP_AA13))
{
m_bActive = true;
m_nSkin = 0;
m_iAngleZ = 0;
#ifdef CLIENT_DLL
m_iAngleZIncrement = -100;
#endif
SetModelScale(0.6);
m_bScaleChangeFlag = !m_bScaleChangeFlag;
}
else
{
m_bActive = true;
m_nSkin = 0;
m_iAngleZ = 0;
#ifdef CLIENT_DLL
m_iAngleZIncrement = -90;
#endif
SetModelScale(0.75);
m_bScaleChangeFlag = !m_bScaleChangeFlag;
}
Expand Down
4 changes: 2 additions & 2 deletions src/game/shared/neo/neo_predicted_viewmodel_muzzleflash.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
Expand All @@ -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;
Expand Down
34 changes: 11 additions & 23 deletions src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion src/game/shared/neo/weapons/weapon_neobasecombatweapon.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down