Skip to content

Commit

Permalink
Оптимизации и упрощение кода
Browse files Browse the repository at this point in the history
  • Loading branch information
xrSimpodin committed Mar 14, 2024
1 parent f830248 commit 79e5283
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 34 deletions.
2 changes: 1 addition & 1 deletion ogsr_engine/xrGame/ShootingObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ void CShootingObject::FireBullet(const Fvector& pos, const Fvector& shot_dir, fl
bool aim_bullet;
if (m_bUseAimBullet)
{
if (ParentMayHaveAimBullet())
if (ParentIsActor())
{
if (m_fPredBulletTime == 0.0)
{
Expand Down
3 changes: 1 addition & 2 deletions ogsr_engine/xrGame/ShootingObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ class CShootingObject

public:
IC BOOL IsWorking() const { return bWorking; }
virtual BOOL ParentMayHaveAimBullet() { return FALSE; }
virtual BOOL ParentIsActor() { return FALSE; }
virtual bool ParentIsActor() const { return false; }

protected:
// Weapon fires now
Expand Down
42 changes: 15 additions & 27 deletions ogsr_engine/xrGame/Weapon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ void CWeapon::UpdateXForm()
{
dwXF_Frame = Device.dwFrame;

if (0 == H_Parent())
return;

// Get access to entity and its visual
CEntityAlive* E = smart_cast<CEntityAlive*>(H_Parent());

Expand All @@ -112,7 +109,6 @@ void CWeapon::UpdateXForm()
if (parent->attached(this))
return;

R_ASSERT(E);
IKinematics* V = smart_cast<IKinematics*>(E->Visual());
VERIFY(V);

Expand All @@ -128,12 +124,19 @@ void CWeapon::UpdateXForm()
if (boneL == BI_NONE || boneR == BI_NONE)
return;

// от mortan:
// https://www.gameru.net/forum/index.php?s=&showtopic=23443&view=findpost&p=1677678
V->CalculateBones_Invalidate();
V->CalculateBones(true); // V->CalculateBones ();
Fmatrix& mL = V->LL_GetTransform(u16(boneL));
Fmatrix& mR = V->LL_GetTransform(u16(boneR));
if (auto pActor = smart_cast<CActor*>(H_Parent()); pActor && pActor->cam_Active() != pActor->cam_FirstEye())
{
// https://www.gameru.net/forum/index.php?s=&showtopic=23443&view=findpost&p=1677678
V->CalculateBones_Invalidate();
V->CalculateBones(true);
}
else
{
V->CalculateBones();
}

const Fmatrix& mL = V->LL_GetTransform(u16(boneL));
const Fmatrix& mR = V->LL_GetTransform(u16(boneR));
// Calculate
Fmatrix mRes;
Fvector R, D, N;
Expand Down Expand Up @@ -2041,24 +2044,9 @@ float CWeapon::GetConditionToShow() const
return (GetCondition()); // powf(GetCondition(),4.0f));
}

BOOL CWeapon::ParentMayHaveAimBullet()
bool CWeapon::ParentIsActor() const
{
CObject* O = H_Parent();
if (!O)
return FALSE;
CEntityAlive* EA = smart_cast<CEntityAlive*>(O);
return EA->cast_actor() != 0;
}

BOOL CWeapon::ParentIsActor()
{
CObject* O = H_Parent();
if (!O)
return FALSE;
CEntityAlive* EA = smart_cast<CEntityAlive*>(O);
if (!EA)
return FALSE;
return EA->cast_actor() != 0;
return smart_cast<const CActor*>(H_Parent()) != nullptr;
}

const float& CWeapon::hit_probability() const
Expand Down
3 changes: 1 addition & 2 deletions ogsr_engine/xrGame/Weapon.h
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,7 @@ class CWeapon : public CHudItemObject, public CShootingObject
virtual bool use_crosshair() const { return true; }
bool show_crosshair();
bool show_indicators();
virtual BOOL ParentMayHaveAimBullet();
virtual BOOL ParentIsActor();
virtual bool ParentIsActor() const override;

private:
float m_hit_probability[egdCount];
Expand Down
4 changes: 2 additions & 2 deletions ogsr_engine/xrGame/ai/stalker/ai_stalker_fire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,10 +674,10 @@ float CAI_Stalker::pick_distance()

void CAI_Stalker::update_can_kill_info()
{
if (m_pick_frame_id == Device.dwFrame)
if (m_pick_frame_id > Device.dwFrame)
return;

m_pick_frame_id = Device.dwFrame;
m_pick_frame_id = Device.dwFrame + 10;
m_can_kill_member = false;
m_can_kill_enemy = false;

Expand Down

0 comments on commit 79e5283

Please sign in to comment.