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
3 changes: 0 additions & 3 deletions src/game/client/c_baseplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,6 @@ class C_BasePlayer : public C_BaseCombatCharacter, public CGameEventListener
virtual void Weapon_SetLast( C_BaseCombatWeapon *pWeapon );
virtual bool Weapon_ShouldSetLast( C_BaseCombatWeapon *pOldWeapon, C_BaseCombatWeapon *pNewWeapon ) { return true; }
virtual bool Weapon_ShouldSelectItem( C_BaseCombatWeapon *pWeapon );
#ifdef NEO
void UpdateMuzzleFlashProperties( C_BaseCombatWeapon* pWeapon );
#endif
virtual bool Weapon_Switch( C_BaseCombatWeapon *pWeapon, int viewmodelindex = 0 ); // Switch to given weapon if has ammo (false if failed)
virtual C_BaseCombatWeapon *GetLastWeapon( void ) { return m_hLastWeapon.Get(); }
void ResetAutoaim( void );
Expand Down
3 changes: 0 additions & 3 deletions src/game/server/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,6 @@ class CBasePlayer : public CBaseCombatCharacter
virtual bool Weapon_CanUse( CBaseCombatWeapon *pWeapon );
virtual void Weapon_Equip( CBaseCombatWeapon *pWeapon );
virtual void Weapon_Drop( CBaseCombatWeapon *pWeapon, const Vector *pvecTarget /* = NULL */, const Vector *pVelocity /* = NULL */ );
#ifdef NEO
void UpdateMuzzleFlashProperties( CBaseCombatWeapon* pWeapon );
#endif
virtual bool Weapon_Switch( CBaseCombatWeapon *pWeapon, int viewmodelindex = 0 ); // Switch to given weapon if has ammo (false if failed)
virtual void Weapon_SetLast( CBaseCombatWeapon *pWeapon );
virtual bool Weapon_ShouldSetLast( CBaseCombatWeapon *pOldWeapon, CBaseCombatWeapon *pNewWeapon ) { return true; }
Expand Down
69 changes: 2 additions & 67 deletions src/game/shared/baseplayer_shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -877,65 +877,6 @@ void CBasePlayer::Weapon_SetLast( CBaseCombatWeapon *pWeapon )
m_hLastWeapon = pWeapon;
}

#ifdef NEO
void CBasePlayer::UpdateMuzzleFlashProperties(CBaseCombatWeapon* pWeapon)
{
auto neoWep = static_cast<CNEOBaseCombatWeapon*>(pWeapon);
if (!neoWep)
return;

auto* neoViewModelMuzzleflash = static_cast<CNEOPredictedViewModelMuzzleFlash*>(m_hViewModel[MUZZLE_FLASH_VIEW_MODEL_INDEX].Get());
if (!neoViewModelMuzzleflash)
return;

const auto neoWepBits = neoWep->GetNeoWepBits();
if (neoWepBits & (NEO_WEP_THROWABLE | NEO_WEP_GHOST | NEO_WEP_KNIFE | NEO_WEP_SUPPRESSED))
{
neoViewModelMuzzleflash->m_bActive = false;
}
else if (neoWepBits & (NEO_WEP_PZ | NEO_WEP_TACHI | NEO_WEP_KYLA))
{
neoViewModelMuzzleflash->m_bActive = true;
neoViewModelMuzzleflash->m_nSkin = 1;
neoViewModelMuzzleflash->m_iAngleZ = 0;
neoViewModelMuzzleflash->m_iAngleZIncrement = -100;
neoViewModelMuzzleflash->SetModelScale(0.75);
}
else if (neoWepBits & NEO_WEP_SUPA7)
{
neoViewModelMuzzleflash->m_bActive = true;
neoViewModelMuzzleflash->m_nSkin = 1;
neoViewModelMuzzleflash->m_iAngleZ = 0;
neoViewModelMuzzleflash->m_iAngleZIncrement = -90;
neoViewModelMuzzleflash->SetModelScale(2);
}
else if (neoWepBits & (NEO_WEP_SRM | NEO_WEP_JITTE))
{
neoViewModelMuzzleflash->m_bActive = true;
neoViewModelMuzzleflash->m_nSkin = 0;
neoViewModelMuzzleflash->m_iAngleZ = 0;
neoViewModelMuzzleflash->m_iAngleZIncrement = -90;
neoViewModelMuzzleflash->SetModelScale(0.75);
}
else if (neoWepBits & (NEO_WEP_MX | NEO_WEP_AA13))
{
neoViewModelMuzzleflash->m_bActive = true;
neoViewModelMuzzleflash->m_nSkin = 0;
neoViewModelMuzzleflash->m_iAngleZ = 0;
neoViewModelMuzzleflash->m_iAngleZIncrement = -100;
neoViewModelMuzzleflash->SetModelScale(0.6);
}
else
{
neoViewModelMuzzleflash->m_bActive = true;
neoViewModelMuzzleflash->m_nSkin = 0;
neoViewModelMuzzleflash->m_iAngleZ = 0;
neoViewModelMuzzleflash->m_iAngleZIncrement = -90;
neoViewModelMuzzleflash->SetModelScale(0.75);
}
}
#endif // NEO

//-----------------------------------------------------------------------------
// Purpose: Override base class so player can reset autoaim
// Input :
Expand All @@ -959,19 +900,13 @@ bool CBasePlayer::Weapon_Switch( CBaseCombatWeapon *pWeapon, int viewmodelindex
ResetAutoaim( );

#ifdef NEO
UpdateMuzzleFlashProperties(pWeapon);
CNEOPredictedViewModelMuzzleFlash* pNeoViewModel = static_cast<CNEOPredictedViewModelMuzzleFlash*>(GetViewModel(MUZZLE_FLASH_VIEW_MODEL_INDEX));
pNeoViewModel->UpdateMuzzleFlashProperties(pWeapon);
#endif // NEO

return true;
}

#ifdef NEO
if (IsAlive() == false)
{
// Active weapon was probably updated, update muzzle flash properties regardless
UpdateMuzzleFlashProperties(pWeapon);
}
#endif // NEO
return false;
}

Expand Down
125 changes: 121 additions & 4 deletions src/game/shared/neo/neo_predicted_viewmodel_muzzleflash.cpp
Original file line number Diff line number Diff line change
@@ -1,34 +1,73 @@
#include "cbase.h"
#include "neo_predicted_viewmodel_muzzleflash.h"
#include "model_types.h"

#ifdef GAME_DLL
#include "baseanimating.h"
#endif

#include "neo_predicted_viewmodel_muzzleflash.h"
#include "weapon_neobasecombatweapon.h"

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
#ifdef CLIENT_DLL
static void RecvProxy_ScaleChangeFlag(const CRecvProxyData* pData, void* pStruct, void* pOut)
{
CNEOPredictedViewModelMuzzleFlash* pViewModel = ((CNEOPredictedViewModelMuzzleFlash*)pStruct);
if (pData->m_Value.m_Int != pViewModel->m_bScaleChangeFlag)
{ // Client side value for m_flModelScale will not be updated correctly, work out the correct scale clientside
pViewModel->UpdateMuzzleFlashProperties(GetActiveWeapon());
}
// Chain through to the default recieve proxy ...
RecvProxy_IntToEHandle(pData, pStruct, pOut);
}
#endif // CLIENT_DLL

IMPLEMENT_NETWORKCLASS_ALIASED(NEOPredictedViewModelMuzzleFlash, DT_NEOPredictedViewModelMuzzleFlash)

BEGIN_NETWORK_TABLE(CNEOPredictedViewModelMuzzleFlash, DT_NEOPredictedViewModelMuzzleFlash)
#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()

#ifdef CLIENT_DLL
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

LINK_ENTITY_TO_CLASS(neo_predicted_viewmodel_muzzleflash, CNEOPredictedViewModelMuzzleFlash);

constexpr const char* MUZZLE_FLASH_ENTITY_MODEL = "models/effect/fpmf/fpmf01.mdl";

CNEOPredictedViewModelMuzzleFlash::CNEOPredictedViewModelMuzzleFlash()
{
m_bActive = true;
m_iAngleZ = 0;
m_iAngleZIncrement = -5;
m_flTimeSwitchOffMuzzleFlash = gpGlobals->curtime;
m_bScaleChangeFlag = false;
}

CNEOPredictedViewModelMuzzleFlash::~CNEOPredictedViewModelMuzzleFlash()
{
}

//-----------------------------------------------------------------------------
// Purpose: Precache assets used by the entity
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -59,8 +98,7 @@ int CNEOPredictedViewModelMuzzleFlash::DrawModel(int flags)
CBasePlayer* pOwner = ToBasePlayer(GetOwner());
if (pOwner == NULL) { return -1; }
CBaseViewModel* vm = pOwner->GetViewModel(0, false);
if (vm == NULL) { return -1; }
if (!vm->IsVisible()) { return -1; }
if (vm == NULL || !vm->IsVisible()) { return -1; }

int iAttachment = vm->LookupAttachment("muzzle");
if (iAttachment < 0) { return -1; }
Expand All @@ -78,4 +116,83 @@ int CNEOPredictedViewModelMuzzleFlash::DrawModel(int flags)
}
return -1;
}
#endif

void CNEOPredictedViewModelMuzzleFlash::ClientThink()
{
// Client side entities can only have one think function. This think function will only run when the muzzle flash properties needs to be updated. If more functionality is
// inserted here consider adding a variable to CNEOPredictedviewModelMuzzleFlash that can be checked here so this is done only when necessary, and remove this comment
CBasePlayer* pOwner = ToBasePlayer(GetOwner());
if (pOwner)
{
UpdateMuzzleFlashProperties(pOwner->GetActiveWeapon(), false);
}
}

#endif //CLIENT_DLL

void CNEOPredictedViewModelMuzzleFlash::UpdateMuzzleFlashProperties(CBaseCombatWeapon* pWeapon, bool repeat)
{
auto neoWep = static_cast<CNEOBaseCombatWeapon*>(pWeapon);
if (!neoWep)
{
#ifdef CLIENT_DLL
// Server likely switched us to a weapon that doesn't yet exist, try updating the muzzle flash properties again next tick, but not recursively
if (repeat)
{
SetNextClientThink(gpGlobals->curtime + gpGlobals->interval_per_tick);
}
#endif //CLIENT_DLL
return;
}

const auto neoWepBits = neoWep->GetNeoWepBits();
if (neoWepBits & (NEO_WEP_THROWABLE | NEO_WEP_GHOST | NEO_WEP_KNIFE | NEO_WEP_SUPPRESSED))
{
m_bActive = false;
}
else if (neoWepBits & (NEO_WEP_PZ | NEO_WEP_TACHI | NEO_WEP_KYLA))
{
m_bActive = true;
m_nSkin = 1;
m_iAngleZ = 0;
m_iAngleZIncrement = -100;
SetModelScale(0.75);
m_bScaleChangeFlag = !m_bScaleChangeFlag;
}
else if (neoWepBits & NEO_WEP_SUPA7)
{
m_bActive = true;
m_nSkin = 1;
m_iAngleZ = 0;
m_iAngleZIncrement = -90;
SetModelScale(2);
m_bScaleChangeFlag = !m_bScaleChangeFlag;
}
else if (neoWepBits & (NEO_WEP_SRM | NEO_WEP_JITTE))
{
m_bActive = true;
m_nSkin = 0;
m_iAngleZ = 0;
m_iAngleZIncrement = -90;
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;
m_iAngleZIncrement = -100;
SetModelScale(0.6);
m_bScaleChangeFlag = !m_bScaleChangeFlag;
}
else
{
m_bActive = true;
m_nSkin = 0;
m_iAngleZ = 0;
m_iAngleZIncrement = -90;
SetModelScale(0.75);
m_bScaleChangeFlag = !m_bScaleChangeFlag;
}
}
26 changes: 15 additions & 11 deletions src/game/shared/neo/neo_predicted_viewmodel_muzzleflash.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@ class CNEOPredictedViewModelMuzzleFlash : public CPredictedViewModel
public:
DECLARE_NETWORKCLASS();
DECLARE_PREDICTABLE();
CNEOPredictedViewModelMuzzleFlash()
{
m_bActive = true;
m_iAngleZ = 0;
m_iAngleZIncrement = -5;
m_flTimeSwitchOffMuzzleFlash = gpGlobals->curtime;
}

CNEOPredictedViewModelMuzzleFlash();
virtual ~CNEOPredictedViewModelMuzzleFlash();
void UpdateMuzzleFlashProperties(CBaseCombatWeapon* pWeapon, bool repeat = true);
virtual void Spawn(void) override;
virtual void Precache(void) override;
#ifdef CLIENT_DLL
virtual ShadowType_t ShadowCastType() final override { return SHADOWS_NONE; };
virtual RenderGroup_t GetRenderGroup() final override { return RENDER_GROUP_VIEW_MODEL_TRANSLUCENT; };
Expand All @@ -37,14 +34,21 @@ class CNEOPredictedViewModelMuzzleFlash : public CPredictedViewModel
m_flTimeSwitchOffMuzzleFlash = gpGlobals->curtime + 0.01f;
BaseClass::ProcessMuzzleFlashEvent();
}
virtual void ClientThink() override;
#endif

virtual void Spawn(void) override;
virtual void Precache(void) override;
#ifdef CLIENT_DLL
bool m_bActive;
int m_iAngleZ;
int m_iAngleZIncrement;
float m_flTimeSwitchOffMuzzleFlash; // If the server can fire a user's weapon (maybe some kind of server triggered weapon cook off or something), this will need to be networked too.
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;
};

#endif // NEO_PREDICTED_VIEWMODEL_MUZZLEFLASH_H